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
;
1329 descr
->dw_loc_frame_offset
= -1;
1331 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1332 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1333 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1334 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1335 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1336 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1341 /* Return a pointer to a newly allocated location description for
1344 static inline dw_loc_descr_ref
1345 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1348 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1351 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1354 /* Add a location description term to a location description expression. */
1357 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1359 dw_loc_descr_ref
*d
;
1361 /* Find the end of the chain. */
1362 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1368 /* Compare two location operands for exact equality. */
1371 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1373 if (a
->val_class
!= b
->val_class
)
1375 switch (a
->val_class
)
1377 case dw_val_class_none
:
1379 case dw_val_class_addr
:
1380 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1382 case dw_val_class_offset
:
1383 case dw_val_class_unsigned_const
:
1384 case dw_val_class_const
:
1385 case dw_val_class_range_list
:
1386 case dw_val_class_lineptr
:
1387 case dw_val_class_macptr
:
1388 /* These are all HOST_WIDE_INT, signed or unsigned. */
1389 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1391 case dw_val_class_loc
:
1392 return a
->v
.val_loc
== b
->v
.val_loc
;
1393 case dw_val_class_loc_list
:
1394 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1395 case dw_val_class_die_ref
:
1396 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1397 case dw_val_class_fde_ref
:
1398 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1399 case dw_val_class_lbl_id
:
1400 case dw_val_class_high_pc
:
1401 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1402 case dw_val_class_str
:
1403 return a
->v
.val_str
== b
->v
.val_str
;
1404 case dw_val_class_flag
:
1405 return a
->v
.val_flag
== b
->v
.val_flag
;
1406 case dw_val_class_file
:
1407 return a
->v
.val_file
== b
->v
.val_file
;
1408 case dw_val_class_decl_ref
:
1409 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1411 case dw_val_class_const_double
:
1412 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1413 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1415 case dw_val_class_wide_int
:
1416 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1418 case dw_val_class_vec
:
1420 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1421 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1423 return (a_len
== b_len
1424 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1427 case dw_val_class_data8
:
1428 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1430 case dw_val_class_vms_delta
:
1431 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1432 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1434 case dw_val_class_discr_value
:
1435 return (a
->v
.val_discr_value
.pos
== b
->v
.val_discr_value
.pos
1436 && a
->v
.val_discr_value
.v
.uval
== b
->v
.val_discr_value
.v
.uval
);
1437 case dw_val_class_discr_list
:
1438 /* It makes no sense comparing two discriminant value lists. */
1444 /* Compare two location atoms for exact equality. */
1447 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1449 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1452 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1453 address size, but since we always allocate cleared storage it
1454 should be zero for other types of locations. */
1455 if (a
->dtprel
!= b
->dtprel
)
1458 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1459 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1462 /* Compare two complete location expressions for exact equality. */
1465 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1471 if (a
== NULL
|| b
== NULL
)
1473 if (!loc_descr_equal_p_1 (a
, b
))
1482 /* Add a constant OFFSET to a location expression. */
1485 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1487 dw_loc_descr_ref loc
;
1490 gcc_assert (*list_head
!= NULL
);
1495 /* Find the end of the chain. */
1496 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1500 if (loc
->dw_loc_opc
== DW_OP_fbreg
1501 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1502 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1503 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1504 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1506 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1507 offset. Don't optimize if an signed integer overflow would happen. */
1509 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1510 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1513 else if (offset
> 0)
1514 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1518 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1519 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1523 /* Add a constant OFFSET to a location list. */
1526 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1529 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1530 loc_descr_plus_const (&d
->expr
, offset
);
1533 #define DWARF_REF_SIZE \
1534 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1536 static unsigned long int get_base_type_offset (dw_die_ref
);
1538 /* Return the size of a location descriptor. */
1540 static unsigned long
1541 size_of_loc_descr (dw_loc_descr_ref loc
)
1543 unsigned long size
= 1;
1545 switch (loc
->dw_loc_opc
)
1548 size
+= DWARF2_ADDR_SIZE
;
1550 case DW_OP_GNU_addr_index
:
1551 case DW_OP_GNU_const_index
:
1552 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1553 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1572 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1575 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1580 case DW_OP_plus_uconst
:
1581 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1619 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1622 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1625 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1628 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1629 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1632 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1634 case DW_OP_bit_piece
:
1635 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1636 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1638 case DW_OP_deref_size
:
1639 case DW_OP_xderef_size
:
1648 case DW_OP_call_ref
:
1649 size
+= DWARF_REF_SIZE
;
1651 case DW_OP_implicit_value
:
1652 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1653 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1655 case DW_OP_GNU_implicit_pointer
:
1656 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1658 case DW_OP_GNU_entry_value
:
1660 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1661 size
+= size_of_uleb128 (op_size
) + op_size
;
1664 case DW_OP_GNU_const_type
:
1667 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1668 size
+= size_of_uleb128 (o
) + 1;
1669 switch (loc
->dw_loc_oprnd2
.val_class
)
1671 case dw_val_class_vec
:
1672 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1673 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1675 case dw_val_class_const
:
1676 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1678 case dw_val_class_const_double
:
1679 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1681 case dw_val_class_wide_int
:
1682 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1683 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1690 case DW_OP_GNU_regval_type
:
1693 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1694 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1695 + size_of_uleb128 (o
);
1698 case DW_OP_GNU_deref_type
:
1701 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1702 size
+= 1 + size_of_uleb128 (o
);
1705 case DW_OP_GNU_convert
:
1706 case DW_OP_GNU_reinterpret
:
1707 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1708 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1712 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1713 size
+= size_of_uleb128 (o
);
1716 case DW_OP_GNU_parameter_ref
:
1726 /* Return the size of a series of location descriptors. */
1729 size_of_locs (dw_loc_descr_ref loc
)
1734 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1735 field, to avoid writing to a PCH file. */
1736 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1738 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1740 size
+= size_of_loc_descr (l
);
1745 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1747 l
->dw_loc_addr
= size
;
1748 size
+= size_of_loc_descr (l
);
1754 /* Return the size of the value in a DW_AT_discr_value attribute. */
1757 size_of_discr_value (dw_discr_value
*discr_value
)
1759 if (discr_value
->pos
)
1760 return size_of_uleb128 (discr_value
->v
.uval
);
1762 return size_of_sleb128 (discr_value
->v
.sval
);
1765 /* Return the size of the value in a DW_discr_list attribute. */
1768 size_of_discr_list (dw_discr_list_ref discr_list
)
1772 for (dw_discr_list_ref list
= discr_list
;
1774 list
= list
->dw_discr_next
)
1776 /* One byte for the discriminant value descriptor, and then one or two
1777 LEB128 numbers, depending on whether it's a single case label or a
1780 size
+= size_of_discr_value (&list
->dw_discr_lower_bound
);
1781 if (list
->dw_discr_range
!= 0)
1782 size
+= size_of_discr_value (&list
->dw_discr_upper_bound
);
1787 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1788 static void get_ref_die_offset_label (char *, dw_die_ref
);
1789 static unsigned long int get_ref_die_offset (dw_die_ref
);
1791 /* Output location description stack opcode's operands (if any).
1792 The for_eh_or_skip parameter controls whether register numbers are
1793 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1794 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1795 info). This should be suppressed for the cases that have not been converted
1796 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1799 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1801 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1802 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1804 switch (loc
->dw_loc_opc
)
1806 #ifdef DWARF2_DEBUGGING_INFO
1809 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1814 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1815 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1817 fputc ('\n', asm_out_file
);
1822 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1827 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1828 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1830 fputc ('\n', asm_out_file
);
1835 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1836 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1843 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1844 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1846 dw2_asm_output_data (2, offset
, NULL
);
1849 case DW_OP_implicit_value
:
1850 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1851 switch (val2
->val_class
)
1853 case dw_val_class_const
:
1854 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1856 case dw_val_class_vec
:
1858 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1859 unsigned int len
= val2
->v
.val_vec
.length
;
1863 if (elt_size
> sizeof (HOST_WIDE_INT
))
1868 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1871 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1872 "fp or vector constant word %u", i
);
1875 case dw_val_class_const_double
:
1877 unsigned HOST_WIDE_INT first
, second
;
1879 if (WORDS_BIG_ENDIAN
)
1881 first
= val2
->v
.val_double
.high
;
1882 second
= val2
->v
.val_double
.low
;
1886 first
= val2
->v
.val_double
.low
;
1887 second
= val2
->v
.val_double
.high
;
1889 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1891 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1895 case dw_val_class_wide_int
:
1898 int len
= get_full_len (*val2
->v
.val_wide
);
1899 if (WORDS_BIG_ENDIAN
)
1900 for (i
= len
- 1; i
>= 0; --i
)
1901 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1902 val2
->v
.val_wide
->elt (i
), NULL
);
1904 for (i
= 0; i
< len
; ++i
)
1905 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1906 val2
->v
.val_wide
->elt (i
), NULL
);
1909 case dw_val_class_addr
:
1910 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1911 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1926 case DW_OP_implicit_value
:
1927 /* We currently don't make any attempt to make sure these are
1928 aligned properly like we do for the main unwind info, so
1929 don't support emitting things larger than a byte if we're
1930 only doing unwinding. */
1935 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1938 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1941 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1944 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1946 case DW_OP_plus_uconst
:
1947 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1981 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1985 unsigned r
= val1
->v
.val_unsigned
;
1986 if (for_eh_or_skip
>= 0)
1987 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1988 gcc_assert (size_of_uleb128 (r
)
1989 == size_of_uleb128 (val1
->v
.val_unsigned
));
1990 dw2_asm_output_data_uleb128 (r
, NULL
);
1994 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1998 unsigned r
= val1
->v
.val_unsigned
;
1999 if (for_eh_or_skip
>= 0)
2000 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2001 gcc_assert (size_of_uleb128 (r
)
2002 == size_of_uleb128 (val1
->v
.val_unsigned
));
2003 dw2_asm_output_data_uleb128 (r
, NULL
);
2004 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2008 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2010 case DW_OP_bit_piece
:
2011 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2012 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
2014 case DW_OP_deref_size
:
2015 case DW_OP_xderef_size
:
2016 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2022 if (targetm
.asm_out
.output_dwarf_dtprel
)
2024 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
2027 fputc ('\n', asm_out_file
);
2034 #ifdef DWARF2_DEBUGGING_INFO
2035 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
2042 case DW_OP_GNU_addr_index
:
2043 case DW_OP_GNU_const_index
:
2044 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2045 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2046 "(index into .debug_addr)");
2052 unsigned long die_offset
2053 = get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2054 /* Make sure the offset has been computed and that we can encode it as
2056 gcc_assert (die_offset
> 0
2057 && die_offset
<= (loc
->dw_loc_opc
== DW_OP_call2
)
2060 dw2_asm_output_data ((loc
->dw_loc_opc
== DW_OP_call2
) ? 2 : 4,
2065 case DW_OP_GNU_implicit_pointer
:
2067 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2068 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2069 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2070 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2071 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2072 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2076 case DW_OP_GNU_entry_value
:
2077 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2078 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2081 case DW_OP_GNU_const_type
:
2083 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2085 dw2_asm_output_data_uleb128 (o
, NULL
);
2086 switch (val2
->val_class
)
2088 case dw_val_class_const
:
2089 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2090 dw2_asm_output_data (1, l
, NULL
);
2091 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2093 case dw_val_class_vec
:
2095 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2096 unsigned int len
= val2
->v
.val_vec
.length
;
2101 dw2_asm_output_data (1, l
, NULL
);
2102 if (elt_size
> sizeof (HOST_WIDE_INT
))
2107 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2110 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2111 "fp or vector constant word %u", i
);
2114 case dw_val_class_const_double
:
2116 unsigned HOST_WIDE_INT first
, second
;
2117 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2119 dw2_asm_output_data (1, 2 * l
, NULL
);
2120 if (WORDS_BIG_ENDIAN
)
2122 first
= val2
->v
.val_double
.high
;
2123 second
= val2
->v
.val_double
.low
;
2127 first
= val2
->v
.val_double
.low
;
2128 second
= val2
->v
.val_double
.high
;
2130 dw2_asm_output_data (l
, first
, NULL
);
2131 dw2_asm_output_data (l
, second
, NULL
);
2134 case dw_val_class_wide_int
:
2137 int len
= get_full_len (*val2
->v
.val_wide
);
2138 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2140 dw2_asm_output_data (1, len
* l
, NULL
);
2141 if (WORDS_BIG_ENDIAN
)
2142 for (i
= len
- 1; i
>= 0; --i
)
2143 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2145 for (i
= 0; i
< len
; ++i
)
2146 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2154 case DW_OP_GNU_regval_type
:
2156 unsigned r
= val1
->v
.val_unsigned
;
2157 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2159 if (for_eh_or_skip
>= 0)
2161 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2162 gcc_assert (size_of_uleb128 (r
)
2163 == size_of_uleb128 (val1
->v
.val_unsigned
));
2165 dw2_asm_output_data_uleb128 (r
, NULL
);
2166 dw2_asm_output_data_uleb128 (o
, NULL
);
2169 case DW_OP_GNU_deref_type
:
2171 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2173 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2174 dw2_asm_output_data_uleb128 (o
, NULL
);
2177 case DW_OP_GNU_convert
:
2178 case DW_OP_GNU_reinterpret
:
2179 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2180 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2183 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2185 dw2_asm_output_data_uleb128 (o
, NULL
);
2189 case DW_OP_GNU_parameter_ref
:
2192 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2193 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2194 dw2_asm_output_data (4, o
, NULL
);
2199 /* Other codes have no operands. */
2204 /* Output a sequence of location operations.
2205 The for_eh_or_skip parameter controls whether register numbers are
2206 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2207 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2208 info). This should be suppressed for the cases that have not been converted
2209 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2212 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2214 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2216 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2217 /* Output the opcode. */
2218 if (for_eh_or_skip
>= 0
2219 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2221 unsigned r
= (opc
- DW_OP_breg0
);
2222 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2223 gcc_assert (r
<= 31);
2224 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2226 else if (for_eh_or_skip
>= 0
2227 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2229 unsigned r
= (opc
- DW_OP_reg0
);
2230 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2231 gcc_assert (r
<= 31);
2232 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2235 dw2_asm_output_data (1, opc
,
2236 "%s", dwarf_stack_op_name (opc
));
2238 /* Output the operand(s) (if any). */
2239 output_loc_operands (loc
, for_eh_or_skip
);
2243 /* Output location description stack opcode's operands (if any).
2244 The output is single bytes on a line, suitable for .cfi_escape. */
2247 output_loc_operands_raw (dw_loc_descr_ref loc
)
2249 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2250 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2252 switch (loc
->dw_loc_opc
)
2255 case DW_OP_GNU_addr_index
:
2256 case DW_OP_GNU_const_index
:
2257 case DW_OP_implicit_value
:
2258 /* We cannot output addresses in .cfi_escape, only bytes. */
2264 case DW_OP_deref_size
:
2265 case DW_OP_xderef_size
:
2266 fputc (',', asm_out_file
);
2267 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2272 fputc (',', asm_out_file
);
2273 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2278 fputc (',', asm_out_file
);
2279 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2284 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2285 fputc (',', asm_out_file
);
2286 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2294 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2295 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2297 fputc (',', asm_out_file
);
2298 dw2_asm_output_data_raw (2, offset
);
2304 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2305 gcc_assert (size_of_uleb128 (r
)
2306 == size_of_uleb128 (val1
->v
.val_unsigned
));
2307 fputc (',', asm_out_file
);
2308 dw2_asm_output_data_uleb128_raw (r
);
2313 case DW_OP_plus_uconst
:
2315 fputc (',', asm_out_file
);
2316 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2319 case DW_OP_bit_piece
:
2320 fputc (',', asm_out_file
);
2321 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2322 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2359 fputc (',', asm_out_file
);
2360 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2365 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2366 gcc_assert (size_of_uleb128 (r
)
2367 == size_of_uleb128 (val1
->v
.val_unsigned
));
2368 fputc (',', asm_out_file
);
2369 dw2_asm_output_data_uleb128_raw (r
);
2370 fputc (',', asm_out_file
);
2371 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2375 case DW_OP_GNU_implicit_pointer
:
2376 case DW_OP_GNU_entry_value
:
2377 case DW_OP_GNU_const_type
:
2378 case DW_OP_GNU_regval_type
:
2379 case DW_OP_GNU_deref_type
:
2380 case DW_OP_GNU_convert
:
2381 case DW_OP_GNU_reinterpret
:
2382 case DW_OP_GNU_parameter_ref
:
2387 /* Other codes have no operands. */
2393 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2397 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2398 /* Output the opcode. */
2399 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2401 unsigned r
= (opc
- DW_OP_breg0
);
2402 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2403 gcc_assert (r
<= 31);
2404 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2406 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2408 unsigned r
= (opc
- DW_OP_reg0
);
2409 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2410 gcc_assert (r
<= 31);
2411 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2413 /* Output the opcode. */
2414 fprintf (asm_out_file
, "%#x", opc
);
2415 output_loc_operands_raw (loc
);
2417 if (!loc
->dw_loc_next
)
2419 loc
= loc
->dw_loc_next
;
2421 fputc (',', asm_out_file
);
2425 /* This function builds a dwarf location descriptor sequence from a
2426 dw_cfa_location, adding the given OFFSET to the result of the
2429 struct dw_loc_descr_node
*
2430 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2432 struct dw_loc_descr_node
*head
, *tmp
;
2434 offset
+= cfa
->offset
;
2438 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2439 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2440 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2441 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2442 add_loc_descr (&head
, tmp
);
2445 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2446 add_loc_descr (&head
, tmp
);
2450 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2455 /* This function builds a dwarf location descriptor sequence for
2456 the address at OFFSET from the CFA when stack is aligned to
2459 struct dw_loc_descr_node
*
2460 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2461 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2463 struct dw_loc_descr_node
*head
;
2464 unsigned int dwarf_fp
2465 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2467 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2468 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2470 head
= new_reg_loc_descr (dwarf_fp
, 0);
2471 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2472 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2473 loc_descr_plus_const (&head
, offset
);
2476 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2480 /* And now, the support for symbolic debugging information. */
2482 /* .debug_str support. */
2484 static void dwarf2out_init (const char *);
2485 static void dwarf2out_finish (const char *);
2486 static void dwarf2out_early_finish (void);
2487 static void dwarf2out_assembly_start (void);
2488 static void dwarf2out_define (unsigned int, const char *);
2489 static void dwarf2out_undef (unsigned int, const char *);
2490 static void dwarf2out_start_source_file (unsigned, const char *);
2491 static void dwarf2out_end_source_file (unsigned);
2492 static void dwarf2out_function_decl (tree
);
2493 static void dwarf2out_begin_block (unsigned, unsigned);
2494 static void dwarf2out_end_block (unsigned, unsigned);
2495 static bool dwarf2out_ignore_block (const_tree
);
2496 static void dwarf2out_early_global_decl (tree
);
2497 static void dwarf2out_late_global_decl (tree
);
2498 static void dwarf2out_type_decl (tree
, int);
2499 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2500 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2502 static void dwarf2out_abstract_function (tree
);
2503 static void dwarf2out_var_location (rtx_insn
*);
2504 static void dwarf2out_size_function (tree
);
2505 static void dwarf2out_begin_function (tree
);
2506 static void dwarf2out_end_function (unsigned int);
2507 static void dwarf2out_register_main_translation_unit (tree unit
);
2508 static void dwarf2out_set_name (tree
, tree
);
2510 /* The debug hooks structure. */
2512 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2516 dwarf2out_early_finish
,
2517 dwarf2out_assembly_start
,
2520 dwarf2out_start_source_file
,
2521 dwarf2out_end_source_file
,
2522 dwarf2out_begin_block
,
2523 dwarf2out_end_block
,
2524 dwarf2out_ignore_block
,
2525 dwarf2out_source_line
,
2526 dwarf2out_begin_prologue
,
2527 #if VMS_DEBUGGING_INFO
2528 dwarf2out_vms_end_prologue
,
2529 dwarf2out_vms_begin_epilogue
,
2531 debug_nothing_int_charstar
,
2532 debug_nothing_int_charstar
,
2534 dwarf2out_end_epilogue
,
2535 dwarf2out_begin_function
,
2536 dwarf2out_end_function
, /* end_function */
2537 dwarf2out_register_main_translation_unit
,
2538 dwarf2out_function_decl
, /* function_decl */
2539 dwarf2out_early_global_decl
,
2540 dwarf2out_late_global_decl
,
2541 dwarf2out_type_decl
, /* type_decl */
2542 dwarf2out_imported_module_or_decl
,
2543 debug_nothing_tree
, /* deferred_inline_function */
2544 /* The DWARF 2 backend tries to reduce debugging bloat by not
2545 emitting the abstract description of inline functions until
2546 something tries to reference them. */
2547 dwarf2out_abstract_function
, /* outlining_inline_function */
2548 debug_nothing_rtx_code_label
, /* label */
2549 debug_nothing_int
, /* handle_pch */
2550 dwarf2out_var_location
,
2551 dwarf2out_size_function
, /* size_function */
2552 dwarf2out_switch_text_section
,
2554 1, /* start_end_main_source_file */
2555 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2558 const struct gcc_debug_hooks dwarf2_lineno_debug_hooks
=
2561 debug_nothing_charstar
,
2564 debug_nothing_int_charstar
,
2565 debug_nothing_int_charstar
,
2566 debug_nothing_int_charstar
,
2568 debug_nothing_int_int
, /* begin_block */
2569 debug_nothing_int_int
, /* end_block */
2570 debug_true_const_tree
, /* ignore_block */
2571 dwarf2out_source_line
, /* source_line */
2572 debug_nothing_int_charstar
, /* begin_prologue */
2573 debug_nothing_int_charstar
, /* end_prologue */
2574 debug_nothing_int_charstar
, /* begin_epilogue */
2575 debug_nothing_int_charstar
, /* end_epilogue */
2576 debug_nothing_tree
, /* begin_function */
2577 debug_nothing_int
, /* end_function */
2578 debug_nothing_tree
, /* register_main_translation_unit */
2579 debug_nothing_tree
, /* function_decl */
2580 debug_nothing_tree
, /* early_global_decl */
2581 debug_nothing_tree
, /* late_global_decl */
2582 debug_nothing_tree_int
, /* type_decl */
2583 debug_nothing_tree_tree_tree_bool
, /* imported_module_or_decl */
2584 debug_nothing_tree
, /* deferred_inline_function */
2585 debug_nothing_tree
, /* outlining_inline_function */
2586 debug_nothing_rtx_code_label
, /* label */
2587 debug_nothing_int
, /* handle_pch */
2588 debug_nothing_rtx_insn
, /* var_location */
2589 debug_nothing_tree
, /* size_function */
2590 debug_nothing_void
, /* switch_text_section */
2591 debug_nothing_tree_tree
, /* set_name */
2592 0, /* start_end_main_source_file */
2593 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2596 /* NOTE: In the comments in this file, many references are made to
2597 "Debugging Information Entries". This term is abbreviated as `DIE'
2598 throughout the remainder of this file. */
2600 /* An internal representation of the DWARF output is built, and then
2601 walked to generate the DWARF debugging info. The walk of the internal
2602 representation is done after the entire program has been compiled.
2603 The types below are used to describe the internal representation. */
2605 /* Whether to put type DIEs into their own section .debug_types instead
2606 of making them part of the .debug_info section. Only supported for
2607 Dwarf V4 or higher and the user didn't disable them through
2608 -fno-debug-types-section. It is more efficient to put them in a
2609 separate comdat sections since the linker will then be able to
2610 remove duplicates. But not all tools support .debug_types sections
2613 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2615 /* Various DIE's use offsets relative to the beginning of the
2616 .debug_info section to refer to each other. */
2618 typedef long int dw_offset
;
2620 struct comdat_type_node
;
2622 /* The entries in the line_info table more-or-less mirror the opcodes
2623 that are used in the real dwarf line table. Arrays of these entries
2624 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2627 enum dw_line_info_opcode
{
2628 /* Emit DW_LNE_set_address; the operand is the label index. */
2631 /* Emit a row to the matrix with the given line. This may be done
2632 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2636 /* Emit a DW_LNS_set_file. */
2639 /* Emit a DW_LNS_set_column. */
2642 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2645 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2646 LI_set_prologue_end
,
2647 LI_set_epilogue_begin
,
2649 /* Emit a DW_LNE_set_discriminator. */
2650 LI_set_discriminator
2653 typedef struct GTY(()) dw_line_info_struct
{
2654 enum dw_line_info_opcode opcode
;
2656 } dw_line_info_entry
;
2659 struct GTY(()) dw_line_info_table
{
2660 /* The label that marks the end of this section. */
2661 const char *end_label
;
2663 /* The values for the last row of the matrix, as collected in the table.
2664 These are used to minimize the changes to the next row. */
2665 unsigned int file_num
;
2666 unsigned int line_num
;
2667 unsigned int column_num
;
2672 vec
<dw_line_info_entry
, va_gc
> *entries
;
2676 /* Each DIE attribute has a field specifying the attribute kind,
2677 a link to the next attribute in the chain, and an attribute value.
2678 Attributes are typically linked below the DIE they modify. */
2680 typedef struct GTY(()) dw_attr_struct
{
2681 enum dwarf_attribute dw_attr
;
2682 dw_val_node dw_attr_val
;
2687 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2688 The children of each node form a circular list linked by
2689 die_sib. die_child points to the node *before* the "first" child node. */
2691 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2692 union die_symbol_or_type_node
2694 const char * GTY ((tag ("0"))) die_symbol
;
2695 comdat_type_node
*GTY ((tag ("1"))) die_type_node
;
2697 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2698 vec
<dw_attr_node
, va_gc
> *die_attr
;
2699 dw_die_ref die_parent
;
2700 dw_die_ref die_child
;
2702 dw_die_ref die_definition
; /* ref from a specification to its definition */
2703 dw_offset die_offset
;
2704 unsigned long die_abbrev
;
2706 unsigned int decl_id
;
2707 enum dwarf_tag die_tag
;
2708 /* Die is used and must not be pruned as unused. */
2709 BOOL_BITFIELD die_perennial_p
: 1;
2710 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2711 /* Lots of spare bits. */
2715 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2716 static bool early_dwarf
;
2717 struct set_early_dwarf
{
2719 set_early_dwarf () : saved(early_dwarf
) { early_dwarf
= true; }
2720 ~set_early_dwarf () { early_dwarf
= saved
; }
2723 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2724 #define FOR_EACH_CHILD(die, c, expr) do { \
2725 c = die->die_child; \
2729 } while (c != die->die_child); \
2732 /* The pubname structure */
2734 typedef struct GTY(()) pubname_struct
{
2741 struct GTY(()) dw_ranges
{
2742 /* If this is positive, it's a block number, otherwise it's a
2743 bitwise-negated index into dw_ranges_by_label. */
2747 /* A structure to hold a macinfo entry. */
2749 typedef struct GTY(()) macinfo_struct
{
2751 unsigned HOST_WIDE_INT lineno
;
2757 struct GTY(()) dw_ranges_by_label
{
2762 /* The comdat type node structure. */
2763 struct GTY(()) comdat_type_node
2765 dw_die_ref root_die
;
2766 dw_die_ref type_die
;
2767 dw_die_ref skeleton_die
;
2768 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2769 comdat_type_node
*next
;
2772 /* A list of DIEs for which we can't determine ancestry (parent_die
2773 field) just yet. Later in dwarf2out_finish we will fill in the
2775 typedef struct GTY(()) limbo_die_struct
{
2777 /* The tree for which this DIE was created. We use this to
2778 determine ancestry later. */
2780 struct limbo_die_struct
*next
;
2784 typedef struct skeleton_chain_struct
2788 struct skeleton_chain_struct
*parent
;
2790 skeleton_chain_node
;
2792 /* Define a macro which returns nonzero for a TYPE_DECL which was
2793 implicitly generated for a type.
2795 Note that, unlike the C front-end (which generates a NULL named
2796 TYPE_DECL node for each complete tagged type, each array type,
2797 and each function type node created) the C++ front-end generates
2798 a _named_ TYPE_DECL node for each tagged type node created.
2799 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2800 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2801 front-end, but for each type, tagged or not. */
2803 #define TYPE_DECL_IS_STUB(decl) \
2804 (DECL_NAME (decl) == NULL_TREE \
2805 || (DECL_ARTIFICIAL (decl) \
2806 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2807 /* This is necessary for stub decls that \
2808 appear in nested inline functions. */ \
2809 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2810 && (decl_ultimate_origin (decl) \
2811 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2813 /* Information concerning the compilation unit's programming
2814 language, and compiler version. */
2816 /* Fixed size portion of the DWARF compilation unit header. */
2817 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2818 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2820 /* Fixed size portion of the DWARF comdat type unit header. */
2821 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2822 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2823 + DWARF_OFFSET_SIZE)
2825 /* Fixed size portion of public names info. */
2826 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2828 /* Fixed size portion of the address range info. */
2829 #define DWARF_ARANGES_HEADER_SIZE \
2830 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2831 DWARF2_ADDR_SIZE * 2) \
2832 - DWARF_INITIAL_LENGTH_SIZE)
2834 /* Size of padding portion in the address range info. It must be
2835 aligned to twice the pointer size. */
2836 #define DWARF_ARANGES_PAD_SIZE \
2837 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2838 DWARF2_ADDR_SIZE * 2) \
2839 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2841 /* Use assembler line directives if available. */
2842 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2843 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2844 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2846 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2850 /* Minimum line offset in a special line info. opcode.
2851 This value was chosen to give a reasonable range of values. */
2852 #define DWARF_LINE_BASE -10
2854 /* First special line opcode - leave room for the standard opcodes. */
2855 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2857 /* Range of line offsets in a special line info. opcode. */
2858 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2860 /* Flag that indicates the initial value of the is_stmt_start flag.
2861 In the present implementation, we do not mark any lines as
2862 the beginning of a source statement, because that information
2863 is not made available by the GCC front-end. */
2864 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2866 /* Maximum number of operations per instruction bundle. */
2867 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2868 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2871 /* This location is used by calc_die_sizes() to keep track
2872 the offset of each DIE within the .debug_info section. */
2873 static unsigned long next_die_offset
;
2875 /* Record the root of the DIE's built for the current compilation unit. */
2876 static GTY(()) dw_die_ref single_comp_unit_die
;
2878 /* A list of type DIEs that have been separated into comdat sections. */
2879 static GTY(()) comdat_type_node
*comdat_type_list
;
2881 /* A list of DIEs with a NULL parent waiting to be relocated. */
2882 static GTY(()) limbo_die_node
*limbo_die_list
;
2884 /* A list of DIEs for which we may have to generate
2885 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2886 static GTY(()) limbo_die_node
*deferred_asm_name
;
2888 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
2890 typedef const char *compare_type
;
2892 static hashval_t
hash (dwarf_file_data
*);
2893 static bool equal (dwarf_file_data
*, const char *);
2896 /* Filenames referenced by this compilation unit. */
2897 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
2899 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
2901 typedef tree compare_type
;
2903 static hashval_t
hash (die_node
*);
2904 static bool equal (die_node
*, tree
);
2906 /* A hash table of references to DIE's that describe declarations.
2907 The key is a DECL_UID() which is a unique number identifying each decl. */
2908 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
2910 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
2912 static hashval_t
hash (die_struct
*);
2913 static bool equal (die_struct
*, die_struct
*);
2916 /* A hash table of references to DIE's that describe COMMON blocks.
2917 The key is DECL_UID() ^ die_parent. */
2918 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
2920 typedef struct GTY(()) die_arg_entry_struct
{
2926 /* Node of the variable location list. */
2927 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2928 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2929 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2930 in mode of the EXPR_LIST node and first EXPR_LIST operand
2931 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2932 location or NULL for padding. For larger bitsizes,
2933 mode is 0 and first operand is a CONCAT with bitsize
2934 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2935 NULL as second operand. */
2937 const char * GTY (()) label
;
2938 struct var_loc_node
* GTY (()) next
;
2941 /* Variable location list. */
2942 struct GTY ((for_user
)) var_loc_list_def
{
2943 struct var_loc_node
* GTY (()) first
;
2945 /* Pointer to the last but one or last element of the
2946 chained list. If the list is empty, both first and
2947 last are NULL, if the list contains just one node
2948 or the last node certainly is not redundant, it points
2949 to the last node, otherwise points to the last but one.
2950 Do not mark it for GC because it is marked through the chain. */
2951 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2953 /* Pointer to the last element before section switch,
2954 if NULL, either sections weren't switched or first
2955 is after section switch. */
2956 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2958 /* DECL_UID of the variable decl. */
2959 unsigned int decl_id
;
2961 typedef struct var_loc_list_def var_loc_list
;
2963 /* Call argument location list. */
2964 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2965 rtx
GTY (()) call_arg_loc_note
;
2966 const char * GTY (()) label
;
2967 tree
GTY (()) block
;
2969 rtx
GTY (()) symbol_ref
;
2970 struct call_arg_loc_node
* GTY (()) next
;
2974 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
2976 typedef const_tree compare_type
;
2978 static hashval_t
hash (var_loc_list
*);
2979 static bool equal (var_loc_list
*, const_tree
);
2982 /* Table of decl location linked lists. */
2983 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
2985 /* Head and tail of call_arg_loc chain. */
2986 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2987 static struct call_arg_loc_node
*call_arg_loc_last
;
2989 /* Number of call sites in the current function. */
2990 static int call_site_count
= -1;
2991 /* Number of tail call sites in the current function. */
2992 static int tail_call_site_count
= -1;
2994 /* A cached location list. */
2995 struct GTY ((for_user
)) cached_dw_loc_list_def
{
2996 /* The DECL_UID of the decl that this entry describes. */
2997 unsigned int decl_id
;
2999 /* The cached location list. */
3000 dw_loc_list_ref loc_list
;
3002 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
3004 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
3007 typedef const_tree compare_type
;
3009 static hashval_t
hash (cached_dw_loc_list
*);
3010 static bool equal (cached_dw_loc_list
*, const_tree
);
3013 /* Table of cached location lists. */
3014 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
3016 /* A pointer to the base of a list of references to DIE's that
3017 are uniquely identified by their tag, presence/absence of
3018 children DIE's, and list of attribute/value pairs. */
3019 static GTY((length ("abbrev_die_table_allocated")))
3020 dw_die_ref
*abbrev_die_table
;
3022 /* Number of elements currently allocated for abbrev_die_table. */
3023 static GTY(()) unsigned abbrev_die_table_allocated
;
3025 /* Number of elements in abbrev_die_table currently in use. */
3026 static GTY(()) unsigned abbrev_die_table_in_use
;
3028 /* A hash map to remember the stack usage for DWARF procedures. The value
3029 stored is the stack size difference between before the DWARF procedure
3030 invokation and after it returned. In other words, for a DWARF procedure
3031 that consumes N stack slots and that pushes M ones, this stores M - N. */
3032 static hash_map
<dw_die_ref
, int> *dwarf_proc_stack_usage_map
;
3034 /* Size (in elements) of increments by which we may expand the
3035 abbrev_die_table. */
3036 #define ABBREV_DIE_TABLE_INCREMENT 256
3038 /* A global counter for generating labels for line number data. */
3039 static unsigned int line_info_label_num
;
3041 /* The current table to which we should emit line number information
3042 for the current function. This will be set up at the beginning of
3043 assembly for the function. */
3044 static dw_line_info_table
*cur_line_info_table
;
3046 /* The two default tables of line number info. */
3047 static GTY(()) dw_line_info_table
*text_section_line_info
;
3048 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
3050 /* The set of all non-default tables of line number info. */
3051 static GTY(()) vec
<dw_line_info_table
*, va_gc
> *separate_line_info
;
3053 /* A flag to tell pubnames/types export if there is an info section to
3055 static bool info_section_emitted
;
3057 /* A pointer to the base of a table that contains a list of publicly
3058 accessible names. */
3059 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
3061 /* A pointer to the base of a table that contains a list of publicly
3062 accessible types. */
3063 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
3065 /* A pointer to the base of a table that contains a list of macro
3066 defines/undefines (and file start/end markers). */
3067 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
3069 /* True if .debug_macinfo or .debug_macros section is going to be
3071 #define have_macinfo \
3072 ((!XCOFF_DEBUGGING_INFO || HAVE_XCOFF_DWARF_EXTRAS) \
3073 && debug_info_level >= DINFO_LEVEL_VERBOSE \
3074 && !macinfo_table->is_empty ())
3076 /* Array of dies for which we should generate .debug_ranges info. */
3077 static GTY ((length ("ranges_table_allocated"))) dw_ranges
*ranges_table
;
3079 /* Number of elements currently allocated for ranges_table. */
3080 static GTY(()) unsigned ranges_table_allocated
;
3082 /* Number of elements in ranges_table currently in use. */
3083 static GTY(()) unsigned ranges_table_in_use
;
3085 /* Array of pairs of labels referenced in ranges_table. */
3086 static GTY ((length ("ranges_by_label_allocated")))
3087 dw_ranges_by_label
*ranges_by_label
;
3089 /* Number of elements currently allocated for ranges_by_label. */
3090 static GTY(()) unsigned ranges_by_label_allocated
;
3092 /* Number of elements in ranges_by_label currently in use. */
3093 static GTY(()) unsigned ranges_by_label_in_use
;
3095 /* Size (in elements) of increments by which we may expand the
3097 #define RANGES_TABLE_INCREMENT 64
3099 /* Whether we have location lists that need outputting */
3100 static GTY(()) bool have_location_lists
;
3102 /* Unique label counter. */
3103 static GTY(()) unsigned int loclabel_num
;
3105 /* Unique label counter for point-of-call tables. */
3106 static GTY(()) unsigned int poc_label_num
;
3108 /* The last file entry emitted by maybe_emit_file(). */
3109 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3111 /* Number of internal labels generated by gen_internal_sym(). */
3112 static GTY(()) int label_num
;
3114 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3116 /* Instances of generic types for which we need to generate debug
3117 info that describe their generic parameters and arguments. That
3118 generation needs to happen once all types are properly laid out so
3119 we do it at the end of compilation. */
3120 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3122 /* Offset from the "steady-state frame pointer" to the frame base,
3123 within the current function. */
3124 static HOST_WIDE_INT frame_pointer_fb_offset
;
3125 static bool frame_pointer_fb_offset_valid
;
3127 static vec
<dw_die_ref
> base_types
;
3129 /* Pointer to vector of DW_TAG_string_type DIEs that need finalization
3130 once all arguments are parsed. */
3131 static vec
<dw_die_ref
> *string_types
;
3133 /* Flags to represent a set of attribute classes for attributes that represent
3134 a scalar value (bounds, pointers, ...). */
3137 dw_scalar_form_constant
= 0x01,
3138 dw_scalar_form_exprloc
= 0x02,
3139 dw_scalar_form_reference
= 0x04
3142 /* Forward declarations for functions defined in this file. */
3144 static int is_pseudo_reg (const_rtx
);
3145 static tree
type_main_variant (tree
);
3146 static int is_tagged_type (const_tree
);
3147 static const char *dwarf_tag_name (unsigned);
3148 static const char *dwarf_attr_name (unsigned);
3149 static const char *dwarf_form_name (unsigned);
3150 static tree
decl_ultimate_origin (const_tree
);
3151 static tree
decl_class_context (tree
);
3152 static void add_dwarf_attr (dw_die_ref
, dw_attr_node
*);
3153 static inline enum dw_val_class
AT_class (dw_attr_node
*);
3154 static inline unsigned int AT_index (dw_attr_node
*);
3155 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3156 static inline unsigned AT_flag (dw_attr_node
*);
3157 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3158 static inline HOST_WIDE_INT
AT_int (dw_attr_node
*);
3159 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3160 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_node
*);
3161 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3162 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3163 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3164 unsigned int, unsigned char *);
3165 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3166 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3167 static inline const char *AT_string (dw_attr_node
*);
3168 static enum dwarf_form
AT_string_form (dw_attr_node
*);
3169 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3170 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3171 static inline dw_die_ref
AT_ref (dw_attr_node
*);
3172 static inline int AT_ref_external (dw_attr_node
*);
3173 static inline void set_AT_ref_external (dw_attr_node
*, int);
3174 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3175 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3176 static inline dw_loc_descr_ref
AT_loc (dw_attr_node
*);
3177 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3179 static inline dw_loc_list_ref
AT_loc_list (dw_attr_node
*);
3180 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3181 static void remove_addr_table_entry (addr_table_entry
*);
3182 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3183 static inline rtx
AT_addr (dw_attr_node
*);
3184 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3185 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3186 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3187 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3188 unsigned HOST_WIDE_INT
);
3189 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3190 unsigned long, bool);
3191 static inline const char *AT_lbl (dw_attr_node
*);
3192 static dw_attr_node
*get_AT (dw_die_ref
, enum dwarf_attribute
);
3193 static const char *get_AT_low_pc (dw_die_ref
);
3194 static const char *get_AT_hi_pc (dw_die_ref
);
3195 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3196 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3197 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3198 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3199 static bool is_cxx (void);
3200 static bool is_fortran (void);
3201 static bool is_ada (void);
3202 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3203 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3204 static void add_child_die (dw_die_ref
, dw_die_ref
);
3205 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3206 static dw_die_ref
lookup_type_die (tree
);
3207 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3208 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3209 static void equate_type_number_to_die (tree
, dw_die_ref
);
3210 static dw_die_ref
lookup_decl_die (tree
);
3211 static var_loc_list
*lookup_decl_loc (const_tree
);
3212 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3213 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3214 static void print_spaces (FILE *);
3215 static void print_die (dw_die_ref
, FILE *);
3216 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3217 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3218 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3219 static void attr_checksum (dw_attr_node
*, struct md5_ctx
*, int *);
3220 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3221 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3222 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3223 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3224 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_node
*,
3225 struct md5_ctx
*, int *);
3226 struct checksum_attributes
;
3227 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3228 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3229 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3230 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3231 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3232 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3233 static int same_attr_p (dw_attr_node
*, dw_attr_node
*, int *);
3234 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3235 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3236 static void compute_section_prefix (dw_die_ref
);
3237 static int is_type_die (dw_die_ref
);
3238 static int is_comdat_die (dw_die_ref
);
3239 static int is_symbol_die (dw_die_ref
);
3240 static inline bool is_template_instantiation (dw_die_ref
);
3241 static void assign_symbol_names (dw_die_ref
);
3242 static void break_out_includes (dw_die_ref
);
3243 static int is_declaration_die (dw_die_ref
);
3244 static int should_move_die_to_comdat (dw_die_ref
);
3245 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3246 static dw_die_ref
clone_die (dw_die_ref
);
3247 static dw_die_ref
clone_tree (dw_die_ref
);
3248 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3249 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3250 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3251 static dw_die_ref
generate_skeleton (dw_die_ref
);
3252 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3255 static void break_out_comdat_types (dw_die_ref
);
3256 static void copy_decls_for_unworthy_types (dw_die_ref
);
3258 static void add_sibling_attributes (dw_die_ref
);
3259 static void output_location_lists (dw_die_ref
);
3260 static int constant_size (unsigned HOST_WIDE_INT
);
3261 static unsigned long size_of_die (dw_die_ref
);
3262 static void calc_die_sizes (dw_die_ref
);
3263 static void calc_base_type_die_sizes (void);
3264 static void mark_dies (dw_die_ref
);
3265 static void unmark_dies (dw_die_ref
);
3266 static void unmark_all_dies (dw_die_ref
);
3267 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3268 static unsigned long size_of_aranges (void);
3269 static enum dwarf_form
value_format (dw_attr_node
*);
3270 static void output_value_format (dw_attr_node
*);
3271 static void output_abbrev_section (void);
3272 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3273 static void output_die_symbol (dw_die_ref
);
3274 static void output_die (dw_die_ref
);
3275 static void output_compilation_unit_header (void);
3276 static void output_comp_unit (dw_die_ref
, int);
3277 static void output_comdat_type_unit (comdat_type_node
*);
3278 static const char *dwarf2_name (tree
, int);
3279 static void add_pubname (tree
, dw_die_ref
);
3280 static void add_enumerator_pubname (const char *, dw_die_ref
);
3281 static void add_pubname_string (const char *, dw_die_ref
);
3282 static void add_pubtype (tree
, dw_die_ref
);
3283 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3284 static void output_aranges (void);
3285 static unsigned int add_ranges_num (int);
3286 static unsigned int add_ranges (const_tree
);
3287 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3289 static void output_ranges (void);
3290 static dw_line_info_table
*new_line_info_table (void);
3291 static void output_line_info (bool);
3292 static void output_file_names (void);
3293 static dw_die_ref
base_type_die (tree
, bool);
3294 static int is_base_type (tree
);
3295 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, tree
, dw_die_ref
);
3296 static int decl_quals (const_tree
);
3297 static dw_die_ref
modified_type_die (tree
, int, bool, dw_die_ref
);
3298 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3299 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3300 static int type_is_enum (const_tree
);
3301 static unsigned int dbx_reg_number (const_rtx
);
3302 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3303 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3304 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3305 enum var_init_status
);
3306 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3307 enum var_init_status
);
3308 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3309 enum var_init_status
);
3310 static int is_based_loc (const_rtx
);
3311 static bool resolve_one_addr (rtx
*);
3312 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3313 enum var_init_status
);
3314 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3315 enum var_init_status
);
3316 struct loc_descr_context
;
3317 static void add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
);
3318 static void add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
);
3319 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3320 const struct loc_descr_context
*);
3321 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3322 const struct loc_descr_context
*);
3323 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3324 static tree
field_type (const_tree
);
3325 static unsigned int simple_type_align_in_bits (const_tree
);
3326 static unsigned int simple_decl_align_in_bits (const_tree
);
3327 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3329 static dw_loc_descr_ref
field_byte_offset (const_tree
, struct vlr_context
*,
3331 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3333 static void add_data_member_location_attribute (dw_die_ref
, tree
,
3334 struct vlr_context
*);
3335 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3336 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3337 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3338 static void insert_float (const_rtx
, unsigned char *);
3339 static rtx
rtl_for_decl_location (tree
);
3340 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool);
3341 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3342 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3343 static void add_name_attribute (dw_die_ref
, const char *);
3344 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3345 static void add_comp_dir_attribute (dw_die_ref
);
3346 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3347 const struct loc_descr_context
*);
3348 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3349 const struct loc_descr_context
*);
3350 static void add_subscript_info (dw_die_ref
, tree
, bool);
3351 static void add_byte_size_attribute (dw_die_ref
, tree
);
3352 static inline void add_bit_offset_attribute (dw_die_ref
, tree
,
3353 struct vlr_context
*);
3354 static void add_bit_size_attribute (dw_die_ref
, tree
);
3355 static void add_prototyped_attribute (dw_die_ref
, tree
);
3356 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3357 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3358 static void add_src_coords_attributes (dw_die_ref
, tree
);
3359 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3360 static void add_discr_value (dw_die_ref
, dw_discr_value
*);
3361 static void add_discr_list (dw_die_ref
, dw_discr_list_ref
);
3362 static inline dw_discr_list_ref
AT_discr_list (dw_attr_node
*);
3363 static void push_decl_scope (tree
);
3364 static void pop_decl_scope (void);
3365 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3366 static inline int local_scope_p (dw_die_ref
);
3367 static inline int class_scope_p (dw_die_ref
);
3368 static inline int class_or_namespace_scope_p (dw_die_ref
);
3369 static void add_type_attribute (dw_die_ref
, tree
, int, bool, dw_die_ref
);
3370 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3371 static const char *type_tag (const_tree
);
3372 static tree
member_declared_type (const_tree
);
3374 static const char *decl_start_label (tree
);
3376 static void gen_array_type_die (tree
, dw_die_ref
);
3377 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3379 static void gen_entry_point_die (tree
, dw_die_ref
);
3381 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3382 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3383 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3384 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3385 static void gen_formal_types_die (tree
, dw_die_ref
);
3386 static void gen_subprogram_die (tree
, dw_die_ref
);
3387 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3388 static void gen_const_die (tree
, dw_die_ref
);
3389 static void gen_label_die (tree
, dw_die_ref
);
3390 static void gen_lexical_block_die (tree
, dw_die_ref
);
3391 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3392 static void gen_field_die (tree
, struct vlr_context
*, dw_die_ref
);
3393 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3394 static dw_die_ref
gen_compile_unit_die (const char *);
3395 static void gen_inheritance_die (tree
, tree
, tree
, dw_die_ref
);
3396 static void gen_member_die (tree
, dw_die_ref
);
3397 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3398 enum debug_info_usage
);
3399 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3400 static void gen_typedef_die (tree
, dw_die_ref
);
3401 static void gen_type_die (tree
, dw_die_ref
);
3402 static void gen_block_die (tree
, dw_die_ref
);
3403 static void decls_for_scope (tree
, dw_die_ref
);
3404 static bool is_naming_typedef_decl (const_tree
);
3405 static inline dw_die_ref
get_context_die (tree
);
3406 static void gen_namespace_die (tree
, dw_die_ref
);
3407 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3408 static dw_die_ref
gen_decl_die (tree
, tree
, struct vlr_context
*, dw_die_ref
);
3409 static dw_die_ref
force_decl_die (tree
);
3410 static dw_die_ref
force_type_die (tree
);
3411 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3412 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3413 static struct dwarf_file_data
* lookup_filename (const char *);
3414 static void retry_incomplete_types (void);
3415 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3416 static void gen_generic_params_dies (tree
);
3417 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3418 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3419 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3420 static int file_info_cmp (const void *, const void *);
3421 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3422 const char *, const char *);
3423 static void output_loc_list (dw_loc_list_ref
);
3424 static char *gen_internal_sym (const char *);
3425 static bool want_pubnames (void);
3427 static void prune_unmark_dies (dw_die_ref
);
3428 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3429 static void prune_unused_types_mark (dw_die_ref
, int);
3430 static void prune_unused_types_walk (dw_die_ref
);
3431 static void prune_unused_types_walk_attribs (dw_die_ref
);
3432 static void prune_unused_types_prune (dw_die_ref
);
3433 static void prune_unused_types (void);
3434 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3435 static inline const char *AT_vms_delta1 (dw_attr_node
*);
3436 static inline const char *AT_vms_delta2 (dw_attr_node
*);
3437 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3438 const char *, const char *);
3439 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3440 static void gen_remaining_tmpl_value_param_die_attribute (void);
3441 static bool generic_type_p (tree
);
3442 static void schedule_generic_params_dies_gen (tree t
);
3443 static void gen_scheduled_generic_parms_dies (void);
3445 static const char *comp_dir_string (void);
3447 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3449 /* enum for tracking thread-local variables whose address is really an offset
3450 relative to the TLS pointer, which will need link-time relocation, but will
3451 not need relocation by the DWARF consumer. */
3459 /* Return the operator to use for an address of a variable. For dtprel_true, we
3460 use DW_OP_const*. For regular variables, which need both link-time
3461 relocation and consumer-level relocation (e.g., to account for shared objects
3462 loaded at a random address), we use DW_OP_addr*. */
3464 static inline enum dwarf_location_atom
3465 dw_addr_op (enum dtprel_bool dtprel
)
3467 if (dtprel
== dtprel_true
)
3468 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3469 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3471 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3474 /* Return a pointer to a newly allocated address location description. If
3475 dwarf_split_debug_info is true, then record the address with the appropriate
3477 static inline dw_loc_descr_ref
3478 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3480 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3482 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3483 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3484 ref
->dtprel
= dtprel
;
3485 if (dwarf_split_debug_info
)
3486 ref
->dw_loc_oprnd1
.val_entry
3487 = add_addr_table_entry (addr
,
3488 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3490 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3495 /* Section names used to hold DWARF debugging information. */
3497 #ifndef DEBUG_INFO_SECTION
3498 #define DEBUG_INFO_SECTION ".debug_info"
3500 #ifndef DEBUG_DWO_INFO_SECTION
3501 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3503 #ifndef DEBUG_ABBREV_SECTION
3504 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3506 #ifndef DEBUG_DWO_ABBREV_SECTION
3507 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3509 #ifndef DEBUG_ARANGES_SECTION
3510 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3512 #ifndef DEBUG_ADDR_SECTION
3513 #define DEBUG_ADDR_SECTION ".debug_addr"
3515 #ifndef DEBUG_NORM_MACINFO_SECTION
3516 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3518 #ifndef DEBUG_DWO_MACINFO_SECTION
3519 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3521 #ifndef DEBUG_MACINFO_SECTION
3522 #define DEBUG_MACINFO_SECTION \
3523 (!dwarf_split_debug_info \
3524 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3526 #ifndef DEBUG_NORM_MACRO_SECTION
3527 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3529 #ifndef DEBUG_DWO_MACRO_SECTION
3530 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3532 #ifndef DEBUG_MACRO_SECTION
3533 #define DEBUG_MACRO_SECTION \
3534 (!dwarf_split_debug_info \
3535 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3537 #ifndef DEBUG_LINE_SECTION
3538 #define DEBUG_LINE_SECTION ".debug_line"
3540 #ifndef DEBUG_DWO_LINE_SECTION
3541 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3543 #ifndef DEBUG_LOC_SECTION
3544 #define DEBUG_LOC_SECTION ".debug_loc"
3546 #ifndef DEBUG_DWO_LOC_SECTION
3547 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3549 #ifndef DEBUG_PUBNAMES_SECTION
3550 #define DEBUG_PUBNAMES_SECTION \
3551 ((debug_generate_pub_sections == 2) \
3552 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3554 #ifndef DEBUG_PUBTYPES_SECTION
3555 #define DEBUG_PUBTYPES_SECTION \
3556 ((debug_generate_pub_sections == 2) \
3557 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3559 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3560 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3561 #ifndef DEBUG_STR_OFFSETS_SECTION
3562 #define DEBUG_STR_OFFSETS_SECTION \
3563 (!dwarf_split_debug_info \
3564 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3566 #ifndef DEBUG_STR_DWO_SECTION
3567 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3569 #ifndef DEBUG_STR_SECTION
3570 #define DEBUG_STR_SECTION ".debug_str"
3572 #ifndef DEBUG_RANGES_SECTION
3573 #define DEBUG_RANGES_SECTION ".debug_ranges"
3576 /* Standard ELF section names for compiled code and data. */
3577 #ifndef TEXT_SECTION_NAME
3578 #define TEXT_SECTION_NAME ".text"
3581 /* Section flags for .debug_macinfo/.debug_macro section. */
3582 #define DEBUG_MACRO_SECTION_FLAGS \
3583 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3585 /* Section flags for .debug_str section. */
3586 #define DEBUG_STR_SECTION_FLAGS \
3587 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3588 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3591 /* Section flags for .debug_str.dwo section. */
3592 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3594 /* Labels we insert at beginning sections we can reference instead of
3595 the section names themselves. */
3597 #ifndef TEXT_SECTION_LABEL
3598 #define TEXT_SECTION_LABEL "Ltext"
3600 #ifndef COLD_TEXT_SECTION_LABEL
3601 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3603 #ifndef DEBUG_LINE_SECTION_LABEL
3604 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3606 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3607 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3609 #ifndef DEBUG_INFO_SECTION_LABEL
3610 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3612 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3613 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3615 #ifndef DEBUG_ABBREV_SECTION_LABEL
3616 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3618 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3619 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3621 #ifndef DEBUG_ADDR_SECTION_LABEL
3622 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3624 #ifndef DEBUG_LOC_SECTION_LABEL
3625 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3627 #ifndef DEBUG_RANGES_SECTION_LABEL
3628 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3630 #ifndef DEBUG_MACINFO_SECTION_LABEL
3631 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3633 #ifndef DEBUG_MACRO_SECTION_LABEL
3634 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3636 #define SKELETON_COMP_DIE_ABBREV 1
3637 #define SKELETON_TYPE_DIE_ABBREV 2
3639 /* Definitions of defaults for formats and names of various special
3640 (artificial) labels which may be generated within this file (when the -g
3641 options is used and DWARF2_DEBUGGING_INFO is in effect.
3642 If necessary, these may be overridden from within the tm.h file, but
3643 typically, overriding these defaults is unnecessary. */
3645 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3646 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3647 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3648 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3649 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3650 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3651 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3652 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3653 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3654 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3655 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3656 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3657 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3658 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3660 #ifndef TEXT_END_LABEL
3661 #define TEXT_END_LABEL "Letext"
3663 #ifndef COLD_END_LABEL
3664 #define COLD_END_LABEL "Letext_cold"
3666 #ifndef BLOCK_BEGIN_LABEL
3667 #define BLOCK_BEGIN_LABEL "LBB"
3669 #ifndef BLOCK_END_LABEL
3670 #define BLOCK_END_LABEL "LBE"
3672 #ifndef LINE_CODE_LABEL
3673 #define LINE_CODE_LABEL "LM"
3677 /* Return the root of the DIE's built for the current compilation unit. */
3679 comp_unit_die (void)
3681 if (!single_comp_unit_die
)
3682 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3683 return single_comp_unit_die
;
3686 /* We allow a language front-end to designate a function that is to be
3687 called to "demangle" any name before it is put into a DIE. */
3689 static const char *(*demangle_name_func
) (const char *);
3692 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3694 demangle_name_func
= func
;
3697 /* Test if rtl node points to a pseudo register. */
3700 is_pseudo_reg (const_rtx rtl
)
3702 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3703 || (GET_CODE (rtl
) == SUBREG
3704 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3707 /* Return a reference to a type, with its const and volatile qualifiers
3711 type_main_variant (tree type
)
3713 type
= TYPE_MAIN_VARIANT (type
);
3715 /* ??? There really should be only one main variant among any group of
3716 variants of a given type (and all of the MAIN_VARIANT values for all
3717 members of the group should point to that one type) but sometimes the C
3718 front-end messes this up for array types, so we work around that bug
3720 if (TREE_CODE (type
) == ARRAY_TYPE
)
3721 while (type
!= TYPE_MAIN_VARIANT (type
))
3722 type
= TYPE_MAIN_VARIANT (type
);
3727 /* Return nonzero if the given type node represents a tagged type. */
3730 is_tagged_type (const_tree type
)
3732 enum tree_code code
= TREE_CODE (type
);
3734 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3735 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3738 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3741 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3743 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3746 /* Return die_offset of a DIE reference to a base type. */
3748 static unsigned long int
3749 get_base_type_offset (dw_die_ref ref
)
3751 if (ref
->die_offset
)
3752 return ref
->die_offset
;
3753 if (comp_unit_die ()->die_abbrev
)
3755 calc_base_type_die_sizes ();
3756 gcc_assert (ref
->die_offset
);
3758 return ref
->die_offset
;
3761 /* Return die_offset of a DIE reference other than base type. */
3763 static unsigned long int
3764 get_ref_die_offset (dw_die_ref ref
)
3766 gcc_assert (ref
->die_offset
);
3767 return ref
->die_offset
;
3770 /* Convert a DIE tag into its string name. */
3773 dwarf_tag_name (unsigned int tag
)
3775 const char *name
= get_DW_TAG_name (tag
);
3780 return "DW_TAG_<unknown>";
3783 /* Convert a DWARF attribute code into its string name. */
3786 dwarf_attr_name (unsigned int attr
)
3792 #if VMS_DEBUGGING_INFO
3793 case DW_AT_HP_prologue
:
3794 return "DW_AT_HP_prologue";
3796 case DW_AT_MIPS_loop_unroll_factor
:
3797 return "DW_AT_MIPS_loop_unroll_factor";
3800 #if VMS_DEBUGGING_INFO
3801 case DW_AT_HP_epilogue
:
3802 return "DW_AT_HP_epilogue";
3804 case DW_AT_MIPS_stride
:
3805 return "DW_AT_MIPS_stride";
3809 name
= get_DW_AT_name (attr
);
3814 return "DW_AT_<unknown>";
3817 /* Convert a DWARF value form code into its string name. */
3820 dwarf_form_name (unsigned int form
)
3822 const char *name
= get_DW_FORM_name (form
);
3827 return "DW_FORM_<unknown>";
3830 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3831 instance of an inlined instance of a decl which is local to an inline
3832 function, so we have to trace all of the way back through the origin chain
3833 to find out what sort of node actually served as the original seed for the
3837 decl_ultimate_origin (const_tree decl
)
3839 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3842 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3843 we're trying to output the abstract instance of this function. */
3844 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3847 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3848 most distant ancestor, this should never happen. */
3849 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3851 return DECL_ABSTRACT_ORIGIN (decl
);
3854 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3855 of a virtual function may refer to a base class, so we check the 'this'
3859 decl_class_context (tree decl
)
3861 tree context
= NULL_TREE
;
3863 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3864 context
= DECL_CONTEXT (decl
);
3866 context
= TYPE_MAIN_VARIANT
3867 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3869 if (context
&& !TYPE_P (context
))
3870 context
= NULL_TREE
;
3875 /* Add an attribute/value pair to a DIE. */
3878 add_dwarf_attr (dw_die_ref die
, dw_attr_node
*attr
)
3880 /* Maybe this should be an assert? */
3884 vec_safe_reserve (die
->die_attr
, 1);
3885 vec_safe_push (die
->die_attr
, *attr
);
3888 static inline enum dw_val_class
3889 AT_class (dw_attr_node
*a
)
3891 return a
->dw_attr_val
.val_class
;
3894 /* Return the index for any attribute that will be referenced with a
3895 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3896 are stored in dw_attr_val.v.val_str for reference counting
3899 static inline unsigned int
3900 AT_index (dw_attr_node
*a
)
3902 if (AT_class (a
) == dw_val_class_str
)
3903 return a
->dw_attr_val
.v
.val_str
->index
;
3904 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3905 return a
->dw_attr_val
.val_entry
->index
;
3909 /* Add a flag value attribute to a DIE. */
3912 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3916 attr
.dw_attr
= attr_kind
;
3917 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3918 attr
.dw_attr_val
.val_entry
= NULL
;
3919 attr
.dw_attr_val
.v
.val_flag
= flag
;
3920 add_dwarf_attr (die
, &attr
);
3923 static inline unsigned
3924 AT_flag (dw_attr_node
*a
)
3926 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3927 return a
->dw_attr_val
.v
.val_flag
;
3930 /* Add a signed integer attribute value to a DIE. */
3933 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3937 attr
.dw_attr
= attr_kind
;
3938 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3939 attr
.dw_attr_val
.val_entry
= NULL
;
3940 attr
.dw_attr_val
.v
.val_int
= int_val
;
3941 add_dwarf_attr (die
, &attr
);
3944 static inline HOST_WIDE_INT
3945 AT_int (dw_attr_node
*a
)
3947 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3948 return a
->dw_attr_val
.v
.val_int
;
3951 /* Add an unsigned integer attribute value to a DIE. */
3954 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3955 unsigned HOST_WIDE_INT unsigned_val
)
3959 attr
.dw_attr
= attr_kind
;
3960 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3961 attr
.dw_attr_val
.val_entry
= NULL
;
3962 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3963 add_dwarf_attr (die
, &attr
);
3966 static inline unsigned HOST_WIDE_INT
3967 AT_unsigned (dw_attr_node
*a
)
3969 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3970 return a
->dw_attr_val
.v
.val_unsigned
;
3973 /* Add an unsigned wide integer attribute value to a DIE. */
3976 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3981 attr
.dw_attr
= attr_kind
;
3982 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
3983 attr
.dw_attr_val
.val_entry
= NULL
;
3984 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
3985 *attr
.dw_attr_val
.v
.val_wide
= w
;
3986 add_dwarf_attr (die
, &attr
);
3989 /* Add an unsigned double integer attribute value to a DIE. */
3992 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3993 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3997 attr
.dw_attr
= attr_kind
;
3998 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3999 attr
.dw_attr_val
.val_entry
= NULL
;
4000 attr
.dw_attr_val
.v
.val_double
.high
= high
;
4001 attr
.dw_attr_val
.v
.val_double
.low
= low
;
4002 add_dwarf_attr (die
, &attr
);
4005 /* Add a floating point attribute value to a DIE and return it. */
4008 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4009 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
4013 attr
.dw_attr
= attr_kind
;
4014 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
4015 attr
.dw_attr_val
.val_entry
= NULL
;
4016 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
4017 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
4018 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
4019 add_dwarf_attr (die
, &attr
);
4022 /* Add an 8-byte data attribute value to a DIE. */
4025 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4026 unsigned char data8
[8])
4030 attr
.dw_attr
= attr_kind
;
4031 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
4032 attr
.dw_attr_val
.val_entry
= NULL
;
4033 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
4034 add_dwarf_attr (die
, &attr
);
4037 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
4038 dwarf_split_debug_info, address attributes in dies destined for the
4039 final executable have force_direct set to avoid using indexed
4043 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
4049 lbl_id
= xstrdup (lbl_low
);
4050 attr
.dw_attr
= DW_AT_low_pc
;
4051 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4052 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4053 if (dwarf_split_debug_info
&& !force_direct
)
4054 attr
.dw_attr_val
.val_entry
4055 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4057 attr
.dw_attr_val
.val_entry
= NULL
;
4058 add_dwarf_attr (die
, &attr
);
4060 attr
.dw_attr
= DW_AT_high_pc
;
4061 if (dwarf_version
< 4)
4062 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4064 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
4065 lbl_id
= xstrdup (lbl_high
);
4066 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
4067 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
4068 && dwarf_split_debug_info
&& !force_direct
)
4069 attr
.dw_attr_val
.val_entry
4070 = add_addr_table_entry (lbl_id
, ate_kind_label
);
4072 attr
.dw_attr_val
.val_entry
= NULL
;
4073 add_dwarf_attr (die
, &attr
);
4076 /* Hash and equality functions for debug_str_hash. */
4079 indirect_string_hasher::hash (indirect_string_node
*x
)
4081 return htab_hash_string (x
->str
);
4085 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
4087 return strcmp (x1
->str
, x2
) == 0;
4090 /* Add STR to the given string hash table. */
4092 static struct indirect_string_node
*
4093 find_AT_string_in_table (const char *str
,
4094 hash_table
<indirect_string_hasher
> *table
)
4096 struct indirect_string_node
*node
;
4098 indirect_string_node
**slot
4099 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
4102 node
= ggc_cleared_alloc
<indirect_string_node
> ();
4103 node
->str
= ggc_strdup (str
);
4113 /* Add STR to the indirect string hash table. */
4115 static struct indirect_string_node
*
4116 find_AT_string (const char *str
)
4118 if (! debug_str_hash
)
4119 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4121 return find_AT_string_in_table (str
, debug_str_hash
);
4124 /* Add a string attribute value to a DIE. */
4127 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4130 struct indirect_string_node
*node
;
4132 node
= find_AT_string (str
);
4134 attr
.dw_attr
= attr_kind
;
4135 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4136 attr
.dw_attr_val
.val_entry
= NULL
;
4137 attr
.dw_attr_val
.v
.val_str
= node
;
4138 add_dwarf_attr (die
, &attr
);
4141 static inline const char *
4142 AT_string (dw_attr_node
*a
)
4144 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4145 return a
->dw_attr_val
.v
.val_str
->str
;
4148 /* Call this function directly to bypass AT_string_form's logic to put
4149 the string inline in the die. */
4152 set_indirect_string (struct indirect_string_node
*node
)
4155 /* Already indirect is a no op. */
4156 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4158 gcc_assert (node
->label
);
4161 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4162 ++dw2_string_counter
;
4163 node
->label
= xstrdup (label
);
4165 if (!dwarf_split_debug_info
)
4167 node
->form
= DW_FORM_strp
;
4168 node
->index
= NOT_INDEXED
;
4172 node
->form
= DW_FORM_GNU_str_index
;
4173 node
->index
= NO_INDEX_ASSIGNED
;
4177 /* Find out whether a string should be output inline in DIE
4178 or out-of-line in .debug_str section. */
4180 static enum dwarf_form
4181 find_string_form (struct indirect_string_node
*node
)
4188 len
= strlen (node
->str
) + 1;
4190 /* If the string is shorter or equal to the size of the reference, it is
4191 always better to put it inline. */
4192 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4193 return node
->form
= DW_FORM_string
;
4195 /* If we cannot expect the linker to merge strings in .debug_str
4196 section, only put it into .debug_str if it is worth even in this
4198 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4199 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4200 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4201 return node
->form
= DW_FORM_string
;
4203 set_indirect_string (node
);
4208 /* Find out whether the string referenced from the attribute should be
4209 output inline in DIE or out-of-line in .debug_str section. */
4211 static enum dwarf_form
4212 AT_string_form (dw_attr_node
*a
)
4214 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4215 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4218 /* Add a DIE reference attribute value to a DIE. */
4221 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4224 gcc_checking_assert (targ_die
!= NULL
);
4226 /* With LTO we can end up trying to reference something we didn't create
4227 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4228 if (targ_die
== NULL
)
4231 attr
.dw_attr
= attr_kind
;
4232 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4233 attr
.dw_attr_val
.val_entry
= NULL
;
4234 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4235 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4236 add_dwarf_attr (die
, &attr
);
4239 /* Change DIE reference REF to point to NEW_DIE instead. */
4242 change_AT_die_ref (dw_attr_node
*ref
, dw_die_ref new_die
)
4244 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4245 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4246 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4249 /* Add an AT_specification attribute to a DIE, and also make the back
4250 pointer from the specification to the definition. */
4253 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4255 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4256 gcc_assert (!targ_die
->die_definition
);
4257 targ_die
->die_definition
= die
;
4260 static inline dw_die_ref
4261 AT_ref (dw_attr_node
*a
)
4263 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4264 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4268 AT_ref_external (dw_attr_node
*a
)
4270 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4271 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4277 set_AT_ref_external (dw_attr_node
*a
, int i
)
4279 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4280 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4283 /* Add an FDE reference attribute value to a DIE. */
4286 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4290 attr
.dw_attr
= attr_kind
;
4291 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4292 attr
.dw_attr_val
.val_entry
= NULL
;
4293 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4294 add_dwarf_attr (die
, &attr
);
4297 /* Add a location description attribute value to a DIE. */
4300 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4304 attr
.dw_attr
= attr_kind
;
4305 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4306 attr
.dw_attr_val
.val_entry
= NULL
;
4307 attr
.dw_attr_val
.v
.val_loc
= loc
;
4308 add_dwarf_attr (die
, &attr
);
4311 static inline dw_loc_descr_ref
4312 AT_loc (dw_attr_node
*a
)
4314 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4315 return a
->dw_attr_val
.v
.val_loc
;
4319 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4323 if (XCOFF_DEBUGGING_INFO
&& !HAVE_XCOFF_DWARF_EXTRAS
)
4326 attr
.dw_attr
= attr_kind
;
4327 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4328 attr
.dw_attr_val
.val_entry
= NULL
;
4329 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4330 add_dwarf_attr (die
, &attr
);
4331 have_location_lists
= true;
4334 static inline dw_loc_list_ref
4335 AT_loc_list (dw_attr_node
*a
)
4337 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4338 return a
->dw_attr_val
.v
.val_loc_list
;
4341 static inline dw_loc_list_ref
*
4342 AT_loc_list_ptr (dw_attr_node
*a
)
4344 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4345 return &a
->dw_attr_val
.v
.val_loc_list
;
4348 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4350 static hashval_t
hash (addr_table_entry
*);
4351 static bool equal (addr_table_entry
*, addr_table_entry
*);
4354 /* Table of entries into the .debug_addr section. */
4356 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4358 /* Hash an address_table_entry. */
4361 addr_hasher::hash (addr_table_entry
*a
)
4363 inchash::hash hstate
;
4369 case ate_kind_rtx_dtprel
:
4372 case ate_kind_label
:
4373 return htab_hash_string (a
->addr
.label
);
4377 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4378 return hstate
.end ();
4381 /* Determine equality for two address_table_entries. */
4384 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4386 if (a1
->kind
!= a2
->kind
)
4391 case ate_kind_rtx_dtprel
:
4392 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4393 case ate_kind_label
:
4394 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4400 /* Initialize an addr_table_entry. */
4403 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4409 case ate_kind_rtx_dtprel
:
4410 e
->addr
.rtl
= (rtx
) addr
;
4412 case ate_kind_label
:
4413 e
->addr
.label
= (char *) addr
;
4417 e
->index
= NO_INDEX_ASSIGNED
;
4420 /* Add attr to the address table entry to the table. Defer setting an
4421 index until output time. */
4423 static addr_table_entry
*
4424 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4426 addr_table_entry
*node
;
4427 addr_table_entry finder
;
4429 gcc_assert (dwarf_split_debug_info
);
4430 if (! addr_index_table
)
4431 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4432 init_addr_table_entry (&finder
, kind
, addr
);
4433 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4435 if (*slot
== HTAB_EMPTY_ENTRY
)
4437 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4438 init_addr_table_entry (node
, kind
, addr
);
4448 /* Remove an entry from the addr table by decrementing its refcount.
4449 Strictly, decrementing the refcount would be enough, but the
4450 assertion that the entry is actually in the table has found
4454 remove_addr_table_entry (addr_table_entry
*entry
)
4456 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4457 /* After an index is assigned, the table is frozen. */
4458 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4462 /* Given a location list, remove all addresses it refers to from the
4466 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4468 for (; descr
; descr
= descr
->dw_loc_next
)
4469 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4471 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4472 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4476 /* A helper function for dwarf2out_finish called through
4477 htab_traverse. Assign an addr_table_entry its index. All entries
4478 must be collected into the table when this function is called,
4479 because the indexing code relies on htab_traverse to traverse nodes
4480 in the same order for each run. */
4483 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4485 addr_table_entry
*node
= *h
;
4487 /* Don't index unreferenced nodes. */
4488 if (node
->refcount
== 0)
4491 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4492 node
->index
= *index
;
4498 /* Add an address constant attribute value to a DIE. When using
4499 dwarf_split_debug_info, address attributes in dies destined for the
4500 final executable should be direct references--setting the parameter
4501 force_direct ensures this behavior. */
4504 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4509 attr
.dw_attr
= attr_kind
;
4510 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4511 attr
.dw_attr_val
.v
.val_addr
= addr
;
4512 if (dwarf_split_debug_info
&& !force_direct
)
4513 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4515 attr
.dw_attr_val
.val_entry
= NULL
;
4516 add_dwarf_attr (die
, &attr
);
4519 /* Get the RTX from to an address DIE attribute. */
4522 AT_addr (dw_attr_node
*a
)
4524 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4525 return a
->dw_attr_val
.v
.val_addr
;
4528 /* Add a file attribute value to a DIE. */
4531 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4532 struct dwarf_file_data
*fd
)
4536 attr
.dw_attr
= attr_kind
;
4537 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4538 attr
.dw_attr_val
.val_entry
= NULL
;
4539 attr
.dw_attr_val
.v
.val_file
= fd
;
4540 add_dwarf_attr (die
, &attr
);
4543 /* Get the dwarf_file_data from a file DIE attribute. */
4545 static inline struct dwarf_file_data
*
4546 AT_file (dw_attr_node
*a
)
4548 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4549 return a
->dw_attr_val
.v
.val_file
;
4552 /* Add a vms delta attribute value to a DIE. */
4555 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4556 const char *lbl1
, const char *lbl2
)
4560 attr
.dw_attr
= attr_kind
;
4561 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4562 attr
.dw_attr_val
.val_entry
= NULL
;
4563 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4564 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4565 add_dwarf_attr (die
, &attr
);
4568 /* Add a label identifier attribute value to a DIE. */
4571 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4576 attr
.dw_attr
= attr_kind
;
4577 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4578 attr
.dw_attr_val
.val_entry
= NULL
;
4579 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4580 if (dwarf_split_debug_info
)
4581 attr
.dw_attr_val
.val_entry
4582 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4584 add_dwarf_attr (die
, &attr
);
4587 /* Add a section offset attribute value to a DIE, an offset into the
4588 debug_line section. */
4591 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4596 attr
.dw_attr
= attr_kind
;
4597 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4598 attr
.dw_attr_val
.val_entry
= NULL
;
4599 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4600 add_dwarf_attr (die
, &attr
);
4603 /* Add a section offset attribute value to a DIE, an offset into the
4604 debug_macinfo section. */
4607 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4612 attr
.dw_attr
= attr_kind
;
4613 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4614 attr
.dw_attr_val
.val_entry
= NULL
;
4615 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4616 add_dwarf_attr (die
, &attr
);
4619 /* Add an offset attribute value to a DIE. */
4622 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4623 unsigned HOST_WIDE_INT offset
)
4627 attr
.dw_attr
= attr_kind
;
4628 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4629 attr
.dw_attr_val
.val_entry
= NULL
;
4630 attr
.dw_attr_val
.v
.val_offset
= offset
;
4631 add_dwarf_attr (die
, &attr
);
4634 /* Add a range_list attribute value to a DIE. When using
4635 dwarf_split_debug_info, address attributes in dies destined for the
4636 final executable should be direct references--setting the parameter
4637 force_direct ensures this behavior. */
4639 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4640 #define RELOCATED_OFFSET (NULL)
4643 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4644 long unsigned int offset
, bool force_direct
)
4648 attr
.dw_attr
= attr_kind
;
4649 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4650 /* For the range_list attribute, use val_entry to store whether the
4651 offset should follow split-debug-info or normal semantics. This
4652 value is read in output_range_list_offset. */
4653 if (dwarf_split_debug_info
&& !force_direct
)
4654 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4656 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4657 attr
.dw_attr_val
.v
.val_offset
= offset
;
4658 add_dwarf_attr (die
, &attr
);
4661 /* Return the start label of a delta attribute. */
4663 static inline const char *
4664 AT_vms_delta1 (dw_attr_node
*a
)
4666 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4667 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4670 /* Return the end label of a delta attribute. */
4672 static inline const char *
4673 AT_vms_delta2 (dw_attr_node
*a
)
4675 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4676 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4679 static inline const char *
4680 AT_lbl (dw_attr_node
*a
)
4682 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4683 || AT_class (a
) == dw_val_class_lineptr
4684 || AT_class (a
) == dw_val_class_macptr
4685 || AT_class (a
) == dw_val_class_high_pc
));
4686 return a
->dw_attr_val
.v
.val_lbl_id
;
4689 /* Get the attribute of type attr_kind. */
4691 static dw_attr_node
*
4692 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4696 dw_die_ref spec
= NULL
;
4701 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4702 if (a
->dw_attr
== attr_kind
)
4704 else if (a
->dw_attr
== DW_AT_specification
4705 || a
->dw_attr
== DW_AT_abstract_origin
)
4709 return get_AT (spec
, attr_kind
);
4714 /* Returns the parent of the declaration of DIE. */
4717 get_die_parent (dw_die_ref die
)
4724 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4725 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4728 return die
->die_parent
;
4731 /* Return the "low pc" attribute value, typically associated with a subprogram
4732 DIE. Return null if the "low pc" attribute is either not present, or if it
4733 cannot be represented as an assembler label identifier. */
4735 static inline const char *
4736 get_AT_low_pc (dw_die_ref die
)
4738 dw_attr_node
*a
= get_AT (die
, DW_AT_low_pc
);
4740 return a
? AT_lbl (a
) : NULL
;
4743 /* Return the "high pc" attribute value, typically associated with a subprogram
4744 DIE. Return null if the "high pc" attribute is either not present, or if it
4745 cannot be represented as an assembler label identifier. */
4747 static inline const char *
4748 get_AT_hi_pc (dw_die_ref die
)
4750 dw_attr_node
*a
= get_AT (die
, DW_AT_high_pc
);
4752 return a
? AT_lbl (a
) : NULL
;
4755 /* Return the value of the string attribute designated by ATTR_KIND, or
4756 NULL if it is not present. */
4758 static inline const char *
4759 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4761 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4763 return a
? AT_string (a
) : NULL
;
4766 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4767 if it is not present. */
4770 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4772 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4774 return a
? AT_flag (a
) : 0;
4777 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4778 if it is not present. */
4780 static inline unsigned
4781 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4783 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4785 return a
? AT_unsigned (a
) : 0;
4788 static inline dw_die_ref
4789 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4791 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4793 return a
? AT_ref (a
) : NULL
;
4796 static inline struct dwarf_file_data
*
4797 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4799 dw_attr_node
*a
= get_AT (die
, attr_kind
);
4801 return a
? AT_file (a
) : NULL
;
4804 /* Return TRUE if the language is C++. */
4809 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4811 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
4812 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
4815 /* Return TRUE if the language is Java. */
4820 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4822 return lang
== DW_LANG_Java
;
4825 /* Return TRUE if the language is Fortran. */
4830 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4832 return (lang
== DW_LANG_Fortran77
4833 || lang
== DW_LANG_Fortran90
4834 || lang
== DW_LANG_Fortran95
4835 || lang
== DW_LANG_Fortran03
4836 || lang
== DW_LANG_Fortran08
);
4839 /* Return TRUE if the language is Ada. */
4844 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4846 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4849 /* Remove the specified attribute if present. Return TRUE if removal
4853 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4861 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4862 if (a
->dw_attr
== attr_kind
)
4864 if (AT_class (a
) == dw_val_class_str
)
4865 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4866 a
->dw_attr_val
.v
.val_str
->refcount
--;
4868 /* vec::ordered_remove should help reduce the number of abbrevs
4870 die
->die_attr
->ordered_remove (ix
);
4876 /* Remove CHILD from its parent. PREV must have the property that
4877 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4880 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4882 gcc_assert (child
->die_parent
== prev
->die_parent
);
4883 gcc_assert (prev
->die_sib
== child
);
4886 gcc_assert (child
->die_parent
->die_child
== child
);
4890 prev
->die_sib
= child
->die_sib
;
4891 if (child
->die_parent
->die_child
== child
)
4892 child
->die_parent
->die_child
= prev
;
4895 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4896 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4899 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4901 dw_die_ref parent
= old_child
->die_parent
;
4903 gcc_assert (parent
== prev
->die_parent
);
4904 gcc_assert (prev
->die_sib
== old_child
);
4906 new_child
->die_parent
= parent
;
4907 if (prev
== old_child
)
4909 gcc_assert (parent
->die_child
== old_child
);
4910 new_child
->die_sib
= new_child
;
4914 prev
->die_sib
= new_child
;
4915 new_child
->die_sib
= old_child
->die_sib
;
4917 if (old_child
->die_parent
->die_child
== old_child
)
4918 old_child
->die_parent
->die_child
= new_child
;
4921 /* Move all children from OLD_PARENT to NEW_PARENT. */
4924 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4927 new_parent
->die_child
= old_parent
->die_child
;
4928 old_parent
->die_child
= NULL
;
4929 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4932 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4936 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4942 dw_die_ref prev
= c
;
4944 while (c
->die_tag
== tag
)
4946 remove_child_with_prev (c
, prev
);
4947 c
->die_parent
= NULL
;
4948 /* Might have removed every child. */
4949 if (c
== c
->die_sib
)
4953 } while (c
!= die
->die_child
);
4956 /* Add a CHILD_DIE as the last child of DIE. */
4959 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4961 /* FIXME this should probably be an assert. */
4962 if (! die
|| ! child_die
)
4964 gcc_assert (die
!= child_die
);
4966 child_die
->die_parent
= die
;
4969 child_die
->die_sib
= die
->die_child
->die_sib
;
4970 die
->die_child
->die_sib
= child_die
;
4973 child_die
->die_sib
= child_die
;
4974 die
->die_child
= child_die
;
4977 /* Like add_child_die, but put CHILD_DIE after AFTER_DIE. */
4980 add_child_die_after (dw_die_ref die
, dw_die_ref child_die
,
4981 dw_die_ref after_die
)
4987 && die
!= child_die
);
4989 child_die
->die_parent
= die
;
4990 child_die
->die_sib
= after_die
->die_sib
;
4991 after_die
->die_sib
= child_die
;
4992 if (die
->die_child
== after_die
)
4993 die
->die_child
= child_die
;
4996 /* Unassociate CHILD from its parent, and make its parent be
5000 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
5002 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
5003 if (p
->die_sib
== child
)
5005 remove_child_with_prev (child
, p
);
5008 add_child_die (new_parent
, child
);
5011 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
5012 is the specification, to the end of PARENT's list of children.
5013 This is done by removing and re-adding it. */
5016 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
5018 /* We want the declaration DIE from inside the class, not the
5019 specification DIE at toplevel. */
5020 if (child
->die_parent
!= parent
)
5022 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
5028 gcc_assert (child
->die_parent
== parent
5029 || (child
->die_parent
5030 == get_AT_ref (parent
, DW_AT_specification
)));
5032 reparent_child (child
, parent
);
5035 /* Create and return a new die with a parent of PARENT_DIE. If
5036 PARENT_DIE is NULL, the new DIE is placed in limbo and an
5037 associated tree T must be supplied to determine parenthood
5040 static inline dw_die_ref
5041 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
5043 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
5045 die
->die_tag
= tag_value
;
5047 if (parent_die
!= NULL
)
5048 add_child_die (parent_die
, die
);
5051 limbo_die_node
*limbo_node
;
5053 /* No DIEs created after early dwarf should end up in limbo,
5054 because the limbo list should not persist past LTO
5056 if (tag_value
!= DW_TAG_compile_unit
5057 /* These are allowed because they're generated while
5058 breaking out COMDAT units late. */
5059 && tag_value
!= DW_TAG_type_unit
5061 /* Allow nested functions to live in limbo because they will
5062 only temporarily live there, as decls_for_scope will fix
5064 && (TREE_CODE (t
) != FUNCTION_DECL
5065 || !decl_function_context (t
))
5066 /* Same as nested functions above but for types. Types that
5067 are local to a function will be fixed in
5069 && (!RECORD_OR_UNION_TYPE_P (t
)
5070 || !TYPE_CONTEXT (t
)
5071 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
5072 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
5073 especially in the ltrans stage, but once we implement LTO
5074 dwarf streaming, we should remove this exception. */
5077 fprintf (stderr
, "symbol ended up in limbo too late:");
5078 debug_generic_stmt (t
);
5082 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
5083 limbo_node
->die
= die
;
5084 limbo_node
->created_for
= t
;
5085 limbo_node
->next
= limbo_die_list
;
5086 limbo_die_list
= limbo_node
;
5092 /* Return the DIE associated with the given type specifier. */
5094 static inline dw_die_ref
5095 lookup_type_die (tree type
)
5097 return TYPE_SYMTAB_DIE (type
);
5100 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
5101 anonymous type named by the typedef TYPE_DIE, return the DIE of the
5102 anonymous type instead the one of the naming typedef. */
5104 static inline dw_die_ref
5105 strip_naming_typedef (tree type
, dw_die_ref type_die
)
5108 && TREE_CODE (type
) == RECORD_TYPE
5110 && type_die
->die_tag
== DW_TAG_typedef
5111 && is_naming_typedef_decl (TYPE_NAME (type
)))
5112 type_die
= get_AT_ref (type_die
, DW_AT_type
);
5116 /* Like lookup_type_die, but if type is an anonymous type named by a
5117 typedef[1], return the DIE of the anonymous type instead the one of
5118 the naming typedef. This is because in gen_typedef_die, we did
5119 equate the anonymous struct named by the typedef with the DIE of
5120 the naming typedef. So by default, lookup_type_die on an anonymous
5121 struct yields the DIE of the naming typedef.
5123 [1]: Read the comment of is_naming_typedef_decl to learn about what
5124 a naming typedef is. */
5126 static inline dw_die_ref
5127 lookup_type_die_strip_naming_typedef (tree type
)
5129 dw_die_ref die
= lookup_type_die (type
);
5130 return strip_naming_typedef (type
, die
);
5133 /* Equate a DIE to a given type specifier. */
5136 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5138 TYPE_SYMTAB_DIE (type
) = type_die
;
5141 /* Returns a hash value for X (which really is a die_struct). */
5144 decl_die_hasher::hash (die_node
*x
)
5146 return (hashval_t
) x
->decl_id
;
5149 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5152 decl_die_hasher::equal (die_node
*x
, tree y
)
5154 return (x
->decl_id
== DECL_UID (y
));
5157 /* Return the DIE associated with a given declaration. */
5159 static inline dw_die_ref
5160 lookup_decl_die (tree decl
)
5162 return decl_die_table
->find_with_hash (decl
, DECL_UID (decl
));
5165 /* Returns a hash value for X (which really is a var_loc_list). */
5168 decl_loc_hasher::hash (var_loc_list
*x
)
5170 return (hashval_t
) x
->decl_id
;
5173 /* Return nonzero if decl_id of var_loc_list X is the same as
5177 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5179 return (x
->decl_id
== DECL_UID (y
));
5182 /* Return the var_loc list associated with a given declaration. */
5184 static inline var_loc_list
*
5185 lookup_decl_loc (const_tree decl
)
5187 if (!decl_loc_table
)
5189 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5192 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5195 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5197 return (hashval_t
) x
->decl_id
;
5200 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5204 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5206 return (x
->decl_id
== DECL_UID (y
));
5209 /* Equate a DIE to a particular declaration. */
5212 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5214 unsigned int decl_id
= DECL_UID (decl
);
5216 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5217 decl_die
->decl_id
= decl_id
;
5220 /* Return how many bits covers PIECE EXPR_LIST. */
5222 static HOST_WIDE_INT
5223 decl_piece_bitsize (rtx piece
)
5225 int ret
= (int) GET_MODE (piece
);
5228 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5229 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5230 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5233 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5236 decl_piece_varloc_ptr (rtx piece
)
5238 if ((int) GET_MODE (piece
))
5239 return &XEXP (piece
, 0);
5241 return &XEXP (XEXP (piece
, 0), 1);
5244 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5245 Next is the chain of following piece nodes. */
5247 static rtx_expr_list
*
5248 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5250 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5251 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5253 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5258 /* Return rtx that should be stored into loc field for
5259 LOC_NOTE and BITPOS/BITSIZE. */
5262 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5263 HOST_WIDE_INT bitsize
)
5267 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5269 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5274 /* This function either modifies location piece list *DEST in
5275 place (if SRC and INNER is NULL), or copies location piece list
5276 *SRC to *DEST while modifying it. Location BITPOS is modified
5277 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5278 not copied and if needed some padding around it is added.
5279 When modifying in place, DEST should point to EXPR_LIST where
5280 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5281 to the start of the whole list and INNER points to the EXPR_LIST
5282 where earlier pieces cover PIECE_BITPOS bits. */
5285 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5286 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5287 HOST_WIDE_INT bitsize
, rtx loc_note
)
5290 bool copy
= inner
!= NULL
;
5294 /* First copy all nodes preceding the current bitpos. */
5295 while (src
!= inner
)
5297 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5298 decl_piece_bitsize (*src
), NULL_RTX
);
5299 dest
= &XEXP (*dest
, 1);
5300 src
= &XEXP (*src
, 1);
5303 /* Add padding if needed. */
5304 if (bitpos
!= piece_bitpos
)
5306 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5307 copy
? NULL_RTX
: *dest
);
5308 dest
= &XEXP (*dest
, 1);
5310 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5313 /* A piece with correct bitpos and bitsize already exist,
5314 just update the location for it and return. */
5315 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5318 /* Add the piece that changed. */
5319 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5320 dest
= &XEXP (*dest
, 1);
5321 /* Skip over pieces that overlap it. */
5322 diff
= bitpos
- piece_bitpos
+ bitsize
;
5325 while (diff
> 0 && *src
)
5328 diff
-= decl_piece_bitsize (piece
);
5330 src
= &XEXP (piece
, 1);
5333 *src
= XEXP (piece
, 1);
5334 free_EXPR_LIST_node (piece
);
5337 /* Add padding if needed. */
5338 if (diff
< 0 && *src
)
5342 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5343 dest
= &XEXP (*dest
, 1);
5347 /* Finally copy all nodes following it. */
5350 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5351 decl_piece_bitsize (*src
), NULL_RTX
);
5352 dest
= &XEXP (*dest
, 1);
5353 src
= &XEXP (*src
, 1);
5357 /* Add a variable location node to the linked list for DECL. */
5359 static struct var_loc_node
*
5360 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5362 unsigned int decl_id
;
5364 struct var_loc_node
*loc
= NULL
;
5365 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5367 if (TREE_CODE (decl
) == VAR_DECL
5368 && DECL_HAS_DEBUG_EXPR_P (decl
))
5370 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5371 if (handled_component_p (realdecl
)
5372 || (TREE_CODE (realdecl
) == MEM_REF
5373 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5375 HOST_WIDE_INT maxsize
;
5378 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
,
5380 if (!DECL_P (innerdecl
)
5381 || DECL_IGNORED_P (innerdecl
)
5382 || TREE_STATIC (innerdecl
)
5384 || bitpos
+ bitsize
> 256
5385 || bitsize
!= maxsize
)
5391 decl_id
= DECL_UID (decl
);
5393 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5396 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5397 temp
->decl_id
= decl_id
;
5403 /* For PARM_DECLs try to keep around the original incoming value,
5404 even if that means we'll emit a zero-range .debug_loc entry. */
5406 && temp
->first
== temp
->last
5407 && TREE_CODE (decl
) == PARM_DECL
5408 && NOTE_P (temp
->first
->loc
)
5409 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5410 && DECL_INCOMING_RTL (decl
)
5411 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5412 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5413 == GET_CODE (DECL_INCOMING_RTL (decl
))
5414 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5416 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5417 NOTE_VAR_LOCATION_LOC (loc_note
))
5418 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5419 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5421 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5422 temp
->first
->next
= loc
;
5424 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5426 else if (temp
->last
)
5428 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5429 rtx
*piece_loc
= NULL
, last_loc_note
;
5430 HOST_WIDE_INT piece_bitpos
= 0;
5434 gcc_assert (last
->next
== NULL
);
5436 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5438 piece_loc
= &last
->loc
;
5441 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5442 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5444 piece_bitpos
+= cur_bitsize
;
5445 piece_loc
= &XEXP (*piece_loc
, 1);
5449 /* TEMP->LAST here is either pointer to the last but one or
5450 last element in the chained list, LAST is pointer to the
5452 if (label
&& strcmp (last
->label
, label
) == 0)
5454 /* For SRA optimized variables if there weren't any real
5455 insns since last note, just modify the last node. */
5456 if (piece_loc
!= NULL
)
5458 adjust_piece_list (piece_loc
, NULL
, NULL
,
5459 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5462 /* If the last note doesn't cover any instructions, remove it. */
5463 if (temp
->last
!= last
)
5465 temp
->last
->next
= NULL
;
5468 gcc_assert (strcmp (last
->label
, label
) != 0);
5472 gcc_assert (temp
->first
== temp
->last
5473 || (temp
->first
->next
== temp
->last
5474 && TREE_CODE (decl
) == PARM_DECL
));
5475 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5476 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5480 if (bitsize
== -1 && NOTE_P (last
->loc
))
5481 last_loc_note
= last
->loc
;
5482 else if (piece_loc
!= NULL
5483 && *piece_loc
!= NULL_RTX
5484 && piece_bitpos
== bitpos
5485 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5486 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5488 last_loc_note
= NULL_RTX
;
5489 /* If the current location is the same as the end of the list,
5490 and either both or neither of the locations is uninitialized,
5491 we have nothing to do. */
5492 if (last_loc_note
== NULL_RTX
5493 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5494 NOTE_VAR_LOCATION_LOC (loc_note
)))
5495 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5496 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5497 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5498 == VAR_INIT_STATUS_UNINITIALIZED
)
5499 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5500 == VAR_INIT_STATUS_UNINITIALIZED
))))
5502 /* Add LOC to the end of list and update LAST. If the last
5503 element of the list has been removed above, reuse its
5504 memory for the new node, otherwise allocate a new one. */
5508 memset (loc
, '\0', sizeof (*loc
));
5511 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5512 if (bitsize
== -1 || piece_loc
== NULL
)
5513 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5515 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5516 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5518 /* Ensure TEMP->LAST will point either to the new last but one
5519 element of the chain, or to the last element in it. */
5520 if (last
!= temp
->last
)
5528 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5531 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5536 /* Keep track of the number of spaces used to indent the
5537 output of the debugging routines that print the structure of
5538 the DIE internal representation. */
5539 static int print_indent
;
5541 /* Indent the line the number of spaces given by print_indent. */
5544 print_spaces (FILE *outfile
)
5546 fprintf (outfile
, "%*s", print_indent
, "");
5549 /* Print a type signature in hex. */
5552 print_signature (FILE *outfile
, char *sig
)
5556 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5557 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5561 print_discr_value (FILE *outfile
, dw_discr_value
*discr_value
)
5563 if (discr_value
->pos
)
5564 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, discr_value
->v
.sval
);
5566 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, discr_value
->v
.uval
);
5569 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
5571 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5572 RECURSE, output location descriptor operations. */
5575 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
5577 switch (val
->val_class
)
5579 case dw_val_class_addr
:
5580 fprintf (outfile
, "address");
5582 case dw_val_class_offset
:
5583 fprintf (outfile
, "offset");
5585 case dw_val_class_loc
:
5586 fprintf (outfile
, "location descriptor");
5587 if (val
->v
.val_loc
== NULL
)
5588 fprintf (outfile
, " -> <null>\n");
5591 fprintf (outfile
, ":\n");
5593 print_loc_descr (val
->v
.val_loc
, outfile
);
5597 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
5599 case dw_val_class_loc_list
:
5600 fprintf (outfile
, "location list -> label:%s",
5601 val
->v
.val_loc_list
->ll_symbol
);
5603 case dw_val_class_range_list
:
5604 fprintf (outfile
, "range list");
5606 case dw_val_class_const
:
5607 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
5609 case dw_val_class_unsigned_const
:
5610 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
5612 case dw_val_class_const_double
:
5613 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
5614 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5615 val
->v
.val_double
.high
,
5616 val
->v
.val_double
.low
);
5618 case dw_val_class_wide_int
:
5620 int i
= val
->v
.val_wide
->get_len ();
5621 fprintf (outfile
, "constant (");
5623 if (val
->v
.val_wide
->elt (i
- 1) == 0)
5624 fprintf (outfile
, "0x");
5625 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5626 val
->v
.val_wide
->elt (--i
));
5628 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5629 val
->v
.val_wide
->elt (i
));
5630 fprintf (outfile
, ")");
5633 case dw_val_class_vec
:
5634 fprintf (outfile
, "floating-point or vector constant");
5636 case dw_val_class_flag
:
5637 fprintf (outfile
, "%u", val
->v
.val_flag
);
5639 case dw_val_class_die_ref
:
5640 if (val
->v
.val_die_ref
.die
!= NULL
)
5642 dw_die_ref die
= val
->v
.val_die_ref
.die
;
5644 if (die
->comdat_type_p
)
5646 fprintf (outfile
, "die -> signature: ");
5647 print_signature (outfile
,
5648 die
->die_id
.die_type_node
->signature
);
5650 else if (die
->die_id
.die_symbol
)
5651 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
5653 fprintf (outfile
, "die -> %ld", die
->die_offset
);
5654 fprintf (outfile
, " (%p)", (void *) die
);
5657 fprintf (outfile
, "die -> <null>");
5659 case dw_val_class_vms_delta
:
5660 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5661 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
5663 case dw_val_class_lbl_id
:
5664 case dw_val_class_lineptr
:
5665 case dw_val_class_macptr
:
5666 case dw_val_class_high_pc
:
5667 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
5669 case dw_val_class_str
:
5670 if (val
->v
.val_str
->str
!= NULL
)
5671 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
5673 fprintf (outfile
, "<null>");
5675 case dw_val_class_file
:
5676 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
5677 val
->v
.val_file
->emitted_number
);
5679 case dw_val_class_data8
:
5683 for (i
= 0; i
< 8; i
++)
5684 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
5687 case dw_val_class_discr_value
:
5688 print_discr_value (outfile
, &val
->v
.val_discr_value
);
5690 case dw_val_class_discr_list
:
5691 for (dw_discr_list_ref node
= val
->v
.val_discr_list
;
5693 node
= node
->dw_discr_next
)
5695 if (node
->dw_discr_range
)
5697 fprintf (outfile
, " .. ");
5698 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5699 print_discr_value (outfile
, &node
->dw_discr_upper_bound
);
5702 print_discr_value (outfile
, &node
->dw_discr_lower_bound
);
5704 if (node
->dw_discr_next
!= NULL
)
5705 fprintf (outfile
, " | ");
5712 /* Likewise, for a DIE attribute. */
5715 print_attribute (dw_attr_node
*a
, bool recurse
, FILE *outfile
)
5717 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
5721 /* Print the list of operands in the LOC location description to OUTFILE. This
5722 routine is a debugging aid only. */
5725 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
5727 dw_loc_descr_ref l
= loc
;
5731 print_spaces (outfile
);
5732 fprintf (outfile
, "<null>\n");
5736 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5738 print_spaces (outfile
);
5739 fprintf (outfile
, "(%p) %s",
5741 dwarf_stack_op_name (l
->dw_loc_opc
));
5742 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
5744 fprintf (outfile
, " ");
5745 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
5747 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
5749 fprintf (outfile
, ", ");
5750 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
5752 fprintf (outfile
, "\n");
5756 /* Print the information associated with a given DIE, and its children.
5757 This routine is a debugging aid only. */
5760 print_die (dw_die_ref die
, FILE *outfile
)
5766 print_spaces (outfile
);
5767 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5768 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5770 print_spaces (outfile
);
5771 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5772 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5773 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5775 if (die
->comdat_type_p
)
5777 print_spaces (outfile
);
5778 fprintf (outfile
, " signature: ");
5779 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5780 fprintf (outfile
, "\n");
5783 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5785 print_spaces (outfile
);
5786 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5788 print_attribute (a
, true, outfile
);
5789 fprintf (outfile
, "\n");
5792 if (die
->die_child
!= NULL
)
5795 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5798 if (print_indent
== 0)
5799 fprintf (outfile
, "\n");
5802 /* Print the list of operations in the LOC location description. */
5805 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
5807 print_loc_descr (loc
, stderr
);
5810 /* Print the information collected for a given DIE. */
5813 debug_dwarf_die (dw_die_ref die
)
5815 print_die (die
, stderr
);
5819 debug (die_struct
&ref
)
5821 print_die (&ref
, stderr
);
5825 debug (die_struct
*ptr
)
5830 fprintf (stderr
, "<nil>\n");
5834 /* Print all DWARF information collected for the compilation unit.
5835 This routine is a debugging aid only. */
5841 print_die (comp_unit_die (), stderr
);
5844 /* Sanity checks on DIEs. */
5847 check_die (dw_die_ref die
)
5851 bool inline_found
= false;
5852 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
5853 int n_decl_line
= 0, n_decl_file
= 0;
5854 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5859 if (a
->dw_attr_val
.v
.val_unsigned
)
5860 inline_found
= true;
5862 case DW_AT_location
:
5871 case DW_AT_artificial
:
5874 case DW_AT_decl_line
:
5877 case DW_AT_decl_file
:
5884 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
5885 || n_decl_line
> 1 || n_decl_file
> 1)
5887 fprintf (stderr
, "Duplicate attributes in DIE:\n");
5888 debug_dwarf_die (die
);
5893 /* A debugging information entry that is a member of an abstract
5894 instance tree [that has DW_AT_inline] should not contain any
5895 attributes which describe aspects of the subroutine which vary
5896 between distinct inlined expansions or distinct out-of-line
5898 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5899 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
5900 && a
->dw_attr
!= DW_AT_high_pc
5901 && a
->dw_attr
!= DW_AT_location
5902 && a
->dw_attr
!= DW_AT_frame_base
5903 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
5907 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5908 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5909 DIE that marks the start of the DIEs for this include file. */
5912 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5914 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5915 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5917 new_unit
->die_sib
= old_unit
;
5921 /* Close an include-file CU and reopen the enclosing one. */
5924 pop_compile_unit (dw_die_ref old_unit
)
5926 dw_die_ref new_unit
= old_unit
->die_sib
;
5928 old_unit
->die_sib
= NULL
;
5932 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5933 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5934 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5936 /* Calculate the checksum of a location expression. */
5939 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5942 inchash::hash hstate
;
5945 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5947 hash_loc_operands (loc
, hstate
);
5948 hash
= hstate
.end();
5952 /* Calculate the checksum of an attribute. */
5955 attr_checksum (dw_attr_node
*at
, struct md5_ctx
*ctx
, int *mark
)
5957 dw_loc_descr_ref loc
;
5960 CHECKSUM (at
->dw_attr
);
5962 /* We don't care that this was compiled with a different compiler
5963 snapshot; if the output is the same, that's what matters. */
5964 if (at
->dw_attr
== DW_AT_producer
)
5967 switch (AT_class (at
))
5969 case dw_val_class_const
:
5970 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5972 case dw_val_class_unsigned_const
:
5973 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5975 case dw_val_class_const_double
:
5976 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5978 case dw_val_class_wide_int
:
5979 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
5980 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
5981 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
5983 case dw_val_class_vec
:
5984 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5985 (at
->dw_attr_val
.v
.val_vec
.length
5986 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5988 case dw_val_class_flag
:
5989 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5991 case dw_val_class_str
:
5992 CHECKSUM_STRING (AT_string (at
));
5995 case dw_val_class_addr
:
5997 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5998 CHECKSUM_STRING (XSTR (r
, 0));
6001 case dw_val_class_offset
:
6002 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
6005 case dw_val_class_loc
:
6006 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6007 loc_checksum (loc
, ctx
);
6010 case dw_val_class_die_ref
:
6011 die_checksum (AT_ref (at
), ctx
, mark
);
6014 case dw_val_class_fde_ref
:
6015 case dw_val_class_vms_delta
:
6016 case dw_val_class_lbl_id
:
6017 case dw_val_class_lineptr
:
6018 case dw_val_class_macptr
:
6019 case dw_val_class_high_pc
:
6022 case dw_val_class_file
:
6023 CHECKSUM_STRING (AT_file (at
)->filename
);
6026 case dw_val_class_data8
:
6027 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6035 /* Calculate the checksum of a DIE. */
6038 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6044 /* To avoid infinite recursion. */
6047 CHECKSUM (die
->die_mark
);
6050 die
->die_mark
= ++(*mark
);
6052 CHECKSUM (die
->die_tag
);
6054 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6055 attr_checksum (a
, ctx
, mark
);
6057 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
6061 #undef CHECKSUM_BLOCK
6062 #undef CHECKSUM_STRING
6064 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
6065 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
6066 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
6067 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
6068 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
6069 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
6070 #define CHECKSUM_ATTR(FOO) \
6071 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
6073 /* Calculate the checksum of a number in signed LEB128 format. */
6076 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6083 byte
= (value
& 0x7f);
6085 more
= !((value
== 0 && (byte
& 0x40) == 0)
6086 || (value
== -1 && (byte
& 0x40) != 0));
6095 /* Calculate the checksum of a number in unsigned LEB128 format. */
6098 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
6102 unsigned char byte
= (value
& 0x7f);
6105 /* More bytes to follow. */
6113 /* Checksum the context of the DIE. This adds the names of any
6114 surrounding namespaces or structures to the checksum. */
6117 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
6121 int tag
= die
->die_tag
;
6123 if (tag
!= DW_TAG_namespace
6124 && tag
!= DW_TAG_structure_type
6125 && tag
!= DW_TAG_class_type
)
6128 name
= get_AT_string (die
, DW_AT_name
);
6130 spec
= get_AT_ref (die
, DW_AT_specification
);
6134 if (die
->die_parent
!= NULL
)
6135 checksum_die_context (die
->die_parent
, ctx
);
6137 CHECKSUM_ULEB128 ('C');
6138 CHECKSUM_ULEB128 (tag
);
6140 CHECKSUM_STRING (name
);
6143 /* Calculate the checksum of a location expression. */
6146 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
6148 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
6149 were emitted as a DW_FORM_sdata instead of a location expression. */
6150 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
6152 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6153 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6157 /* Otherwise, just checksum the raw location expression. */
6160 inchash::hash hstate
;
6163 CHECKSUM_ULEB128 (loc
->dtprel
);
6164 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6165 hash_loc_operands (loc
, hstate
);
6166 hash
= hstate
.end ();
6168 loc
= loc
->dw_loc_next
;
6172 /* Calculate the checksum of an attribute. */
6175 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_node
*at
,
6176 struct md5_ctx
*ctx
, int *mark
)
6178 dw_loc_descr_ref loc
;
6181 if (AT_class (at
) == dw_val_class_die_ref
)
6183 dw_die_ref target_die
= AT_ref (at
);
6185 /* For pointer and reference types, we checksum only the (qualified)
6186 name of the target type (if there is a name). For friend entries,
6187 we checksum only the (qualified) name of the target type or function.
6188 This allows the checksum to remain the same whether the target type
6189 is complete or not. */
6190 if ((at
->dw_attr
== DW_AT_type
6191 && (tag
== DW_TAG_pointer_type
6192 || tag
== DW_TAG_reference_type
6193 || tag
== DW_TAG_rvalue_reference_type
6194 || tag
== DW_TAG_ptr_to_member_type
))
6195 || (at
->dw_attr
== DW_AT_friend
6196 && tag
== DW_TAG_friend
))
6198 dw_attr_node
*name_attr
= get_AT (target_die
, DW_AT_name
);
6200 if (name_attr
!= NULL
)
6202 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6206 CHECKSUM_ULEB128 ('N');
6207 CHECKSUM_ULEB128 (at
->dw_attr
);
6208 if (decl
->die_parent
!= NULL
)
6209 checksum_die_context (decl
->die_parent
, ctx
);
6210 CHECKSUM_ULEB128 ('E');
6211 CHECKSUM_STRING (AT_string (name_attr
));
6216 /* For all other references to another DIE, we check to see if the
6217 target DIE has already been visited. If it has, we emit a
6218 backward reference; if not, we descend recursively. */
6219 if (target_die
->die_mark
> 0)
6221 CHECKSUM_ULEB128 ('R');
6222 CHECKSUM_ULEB128 (at
->dw_attr
);
6223 CHECKSUM_ULEB128 (target_die
->die_mark
);
6227 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6231 target_die
->die_mark
= ++(*mark
);
6232 CHECKSUM_ULEB128 ('T');
6233 CHECKSUM_ULEB128 (at
->dw_attr
);
6234 if (decl
->die_parent
!= NULL
)
6235 checksum_die_context (decl
->die_parent
, ctx
);
6236 die_checksum_ordered (target_die
, ctx
, mark
);
6241 CHECKSUM_ULEB128 ('A');
6242 CHECKSUM_ULEB128 (at
->dw_attr
);
6244 switch (AT_class (at
))
6246 case dw_val_class_const
:
6247 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6248 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6251 case dw_val_class_unsigned_const
:
6252 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6253 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6256 case dw_val_class_const_double
:
6257 CHECKSUM_ULEB128 (DW_FORM_block
);
6258 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6259 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6262 case dw_val_class_wide_int
:
6263 CHECKSUM_ULEB128 (DW_FORM_block
);
6264 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6265 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6266 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6267 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6268 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6271 case dw_val_class_vec
:
6272 CHECKSUM_ULEB128 (DW_FORM_block
);
6273 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6274 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6275 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6276 (at
->dw_attr_val
.v
.val_vec
.length
6277 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6280 case dw_val_class_flag
:
6281 CHECKSUM_ULEB128 (DW_FORM_flag
);
6282 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6285 case dw_val_class_str
:
6286 CHECKSUM_ULEB128 (DW_FORM_string
);
6287 CHECKSUM_STRING (AT_string (at
));
6290 case dw_val_class_addr
:
6292 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6293 CHECKSUM_ULEB128 (DW_FORM_string
);
6294 CHECKSUM_STRING (XSTR (r
, 0));
6297 case dw_val_class_offset
:
6298 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6299 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6302 case dw_val_class_loc
:
6303 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6304 loc_checksum_ordered (loc
, ctx
);
6307 case dw_val_class_fde_ref
:
6308 case dw_val_class_lbl_id
:
6309 case dw_val_class_lineptr
:
6310 case dw_val_class_macptr
:
6311 case dw_val_class_high_pc
:
6314 case dw_val_class_file
:
6315 CHECKSUM_ULEB128 (DW_FORM_string
);
6316 CHECKSUM_STRING (AT_file (at
)->filename
);
6319 case dw_val_class_data8
:
6320 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6328 struct checksum_attributes
6330 dw_attr_node
*at_name
;
6331 dw_attr_node
*at_type
;
6332 dw_attr_node
*at_friend
;
6333 dw_attr_node
*at_accessibility
;
6334 dw_attr_node
*at_address_class
;
6335 dw_attr_node
*at_allocated
;
6336 dw_attr_node
*at_artificial
;
6337 dw_attr_node
*at_associated
;
6338 dw_attr_node
*at_binary_scale
;
6339 dw_attr_node
*at_bit_offset
;
6340 dw_attr_node
*at_bit_size
;
6341 dw_attr_node
*at_bit_stride
;
6342 dw_attr_node
*at_byte_size
;
6343 dw_attr_node
*at_byte_stride
;
6344 dw_attr_node
*at_const_value
;
6345 dw_attr_node
*at_containing_type
;
6346 dw_attr_node
*at_count
;
6347 dw_attr_node
*at_data_location
;
6348 dw_attr_node
*at_data_member_location
;
6349 dw_attr_node
*at_decimal_scale
;
6350 dw_attr_node
*at_decimal_sign
;
6351 dw_attr_node
*at_default_value
;
6352 dw_attr_node
*at_digit_count
;
6353 dw_attr_node
*at_discr
;
6354 dw_attr_node
*at_discr_list
;
6355 dw_attr_node
*at_discr_value
;
6356 dw_attr_node
*at_encoding
;
6357 dw_attr_node
*at_endianity
;
6358 dw_attr_node
*at_explicit
;
6359 dw_attr_node
*at_is_optional
;
6360 dw_attr_node
*at_location
;
6361 dw_attr_node
*at_lower_bound
;
6362 dw_attr_node
*at_mutable
;
6363 dw_attr_node
*at_ordering
;
6364 dw_attr_node
*at_picture_string
;
6365 dw_attr_node
*at_prototyped
;
6366 dw_attr_node
*at_small
;
6367 dw_attr_node
*at_segment
;
6368 dw_attr_node
*at_string_length
;
6369 dw_attr_node
*at_threads_scaled
;
6370 dw_attr_node
*at_upper_bound
;
6371 dw_attr_node
*at_use_location
;
6372 dw_attr_node
*at_use_UTF8
;
6373 dw_attr_node
*at_variable_parameter
;
6374 dw_attr_node
*at_virtuality
;
6375 dw_attr_node
*at_visibility
;
6376 dw_attr_node
*at_vtable_elem_location
;
6379 /* Collect the attributes that we will want to use for the checksum. */
6382 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6387 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6398 attrs
->at_friend
= a
;
6400 case DW_AT_accessibility
:
6401 attrs
->at_accessibility
= a
;
6403 case DW_AT_address_class
:
6404 attrs
->at_address_class
= a
;
6406 case DW_AT_allocated
:
6407 attrs
->at_allocated
= a
;
6409 case DW_AT_artificial
:
6410 attrs
->at_artificial
= a
;
6412 case DW_AT_associated
:
6413 attrs
->at_associated
= a
;
6415 case DW_AT_binary_scale
:
6416 attrs
->at_binary_scale
= a
;
6418 case DW_AT_bit_offset
:
6419 attrs
->at_bit_offset
= a
;
6421 case DW_AT_bit_size
:
6422 attrs
->at_bit_size
= a
;
6424 case DW_AT_bit_stride
:
6425 attrs
->at_bit_stride
= a
;
6427 case DW_AT_byte_size
:
6428 attrs
->at_byte_size
= a
;
6430 case DW_AT_byte_stride
:
6431 attrs
->at_byte_stride
= a
;
6433 case DW_AT_const_value
:
6434 attrs
->at_const_value
= a
;
6436 case DW_AT_containing_type
:
6437 attrs
->at_containing_type
= a
;
6440 attrs
->at_count
= a
;
6442 case DW_AT_data_location
:
6443 attrs
->at_data_location
= a
;
6445 case DW_AT_data_member_location
:
6446 attrs
->at_data_member_location
= a
;
6448 case DW_AT_decimal_scale
:
6449 attrs
->at_decimal_scale
= a
;
6451 case DW_AT_decimal_sign
:
6452 attrs
->at_decimal_sign
= a
;
6454 case DW_AT_default_value
:
6455 attrs
->at_default_value
= a
;
6457 case DW_AT_digit_count
:
6458 attrs
->at_digit_count
= a
;
6461 attrs
->at_discr
= a
;
6463 case DW_AT_discr_list
:
6464 attrs
->at_discr_list
= a
;
6466 case DW_AT_discr_value
:
6467 attrs
->at_discr_value
= a
;
6469 case DW_AT_encoding
:
6470 attrs
->at_encoding
= a
;
6472 case DW_AT_endianity
:
6473 attrs
->at_endianity
= a
;
6475 case DW_AT_explicit
:
6476 attrs
->at_explicit
= a
;
6478 case DW_AT_is_optional
:
6479 attrs
->at_is_optional
= a
;
6481 case DW_AT_location
:
6482 attrs
->at_location
= a
;
6484 case DW_AT_lower_bound
:
6485 attrs
->at_lower_bound
= a
;
6488 attrs
->at_mutable
= a
;
6490 case DW_AT_ordering
:
6491 attrs
->at_ordering
= a
;
6493 case DW_AT_picture_string
:
6494 attrs
->at_picture_string
= a
;
6496 case DW_AT_prototyped
:
6497 attrs
->at_prototyped
= a
;
6500 attrs
->at_small
= a
;
6503 attrs
->at_segment
= a
;
6505 case DW_AT_string_length
:
6506 attrs
->at_string_length
= a
;
6508 case DW_AT_threads_scaled
:
6509 attrs
->at_threads_scaled
= a
;
6511 case DW_AT_upper_bound
:
6512 attrs
->at_upper_bound
= a
;
6514 case DW_AT_use_location
:
6515 attrs
->at_use_location
= a
;
6517 case DW_AT_use_UTF8
:
6518 attrs
->at_use_UTF8
= a
;
6520 case DW_AT_variable_parameter
:
6521 attrs
->at_variable_parameter
= a
;
6523 case DW_AT_virtuality
:
6524 attrs
->at_virtuality
= a
;
6526 case DW_AT_visibility
:
6527 attrs
->at_visibility
= a
;
6529 case DW_AT_vtable_elem_location
:
6530 attrs
->at_vtable_elem_location
= a
;
6538 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6541 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6545 struct checksum_attributes attrs
;
6547 CHECKSUM_ULEB128 ('D');
6548 CHECKSUM_ULEB128 (die
->die_tag
);
6550 memset (&attrs
, 0, sizeof (attrs
));
6552 decl
= get_AT_ref (die
, DW_AT_specification
);
6554 collect_checksum_attributes (&attrs
, decl
);
6555 collect_checksum_attributes (&attrs
, die
);
6557 CHECKSUM_ATTR (attrs
.at_name
);
6558 CHECKSUM_ATTR (attrs
.at_accessibility
);
6559 CHECKSUM_ATTR (attrs
.at_address_class
);
6560 CHECKSUM_ATTR (attrs
.at_allocated
);
6561 CHECKSUM_ATTR (attrs
.at_artificial
);
6562 CHECKSUM_ATTR (attrs
.at_associated
);
6563 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6564 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6565 CHECKSUM_ATTR (attrs
.at_bit_size
);
6566 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6567 CHECKSUM_ATTR (attrs
.at_byte_size
);
6568 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6569 CHECKSUM_ATTR (attrs
.at_const_value
);
6570 CHECKSUM_ATTR (attrs
.at_containing_type
);
6571 CHECKSUM_ATTR (attrs
.at_count
);
6572 CHECKSUM_ATTR (attrs
.at_data_location
);
6573 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6574 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6575 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6576 CHECKSUM_ATTR (attrs
.at_default_value
);
6577 CHECKSUM_ATTR (attrs
.at_digit_count
);
6578 CHECKSUM_ATTR (attrs
.at_discr
);
6579 CHECKSUM_ATTR (attrs
.at_discr_list
);
6580 CHECKSUM_ATTR (attrs
.at_discr_value
);
6581 CHECKSUM_ATTR (attrs
.at_encoding
);
6582 CHECKSUM_ATTR (attrs
.at_endianity
);
6583 CHECKSUM_ATTR (attrs
.at_explicit
);
6584 CHECKSUM_ATTR (attrs
.at_is_optional
);
6585 CHECKSUM_ATTR (attrs
.at_location
);
6586 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6587 CHECKSUM_ATTR (attrs
.at_mutable
);
6588 CHECKSUM_ATTR (attrs
.at_ordering
);
6589 CHECKSUM_ATTR (attrs
.at_picture_string
);
6590 CHECKSUM_ATTR (attrs
.at_prototyped
);
6591 CHECKSUM_ATTR (attrs
.at_small
);
6592 CHECKSUM_ATTR (attrs
.at_segment
);
6593 CHECKSUM_ATTR (attrs
.at_string_length
);
6594 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6595 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6596 CHECKSUM_ATTR (attrs
.at_use_location
);
6597 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6598 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6599 CHECKSUM_ATTR (attrs
.at_virtuality
);
6600 CHECKSUM_ATTR (attrs
.at_visibility
);
6601 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6602 CHECKSUM_ATTR (attrs
.at_type
);
6603 CHECKSUM_ATTR (attrs
.at_friend
);
6605 /* Checksum the child DIEs. */
6608 dw_attr_node
*name_attr
;
6611 name_attr
= get_AT (c
, DW_AT_name
);
6612 if (is_template_instantiation (c
))
6614 /* Ignore instantiations of member type and function templates. */
6616 else if (name_attr
!= NULL
6617 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6619 /* Use a shallow checksum for named nested types and member
6621 CHECKSUM_ULEB128 ('S');
6622 CHECKSUM_ULEB128 (c
->die_tag
);
6623 CHECKSUM_STRING (AT_string (name_attr
));
6627 /* Use a deep checksum for other children. */
6628 /* Mark this DIE so it gets processed when unmarking. */
6629 if (c
->die_mark
== 0)
6631 die_checksum_ordered (c
, ctx
, mark
);
6633 } while (c
!= die
->die_child
);
6635 CHECKSUM_ULEB128 (0);
6638 /* Add a type name and tag to a hash. */
6640 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6642 CHECKSUM_ULEB128 (tag
);
6643 CHECKSUM_STRING (name
);
6647 #undef CHECKSUM_STRING
6648 #undef CHECKSUM_ATTR
6649 #undef CHECKSUM_LEB128
6650 #undef CHECKSUM_ULEB128
6652 /* Generate the type signature for DIE. This is computed by generating an
6653 MD5 checksum over the DIE's tag, its relevant attributes, and its
6654 children. Attributes that are references to other DIEs are processed
6655 by recursion, using the MARK field to prevent infinite recursion.
6656 If the DIE is nested inside a namespace or another type, we also
6657 need to include that context in the signature. The lower 64 bits
6658 of the resulting MD5 checksum comprise the signature. */
6661 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6665 unsigned char checksum
[16];
6670 name
= get_AT_string (die
, DW_AT_name
);
6671 decl
= get_AT_ref (die
, DW_AT_specification
);
6672 parent
= get_die_parent (die
);
6674 /* First, compute a signature for just the type name (and its surrounding
6675 context, if any. This is stored in the type unit DIE for link-time
6676 ODR (one-definition rule) checking. */
6678 if (is_cxx () && name
!= NULL
)
6680 md5_init_ctx (&ctx
);
6682 /* Checksum the names of surrounding namespaces and structures. */
6684 checksum_die_context (parent
, &ctx
);
6686 /* Checksum the current DIE. */
6687 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6688 md5_finish_ctx (&ctx
, checksum
);
6690 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6693 /* Next, compute the complete type signature. */
6695 md5_init_ctx (&ctx
);
6697 die
->die_mark
= mark
;
6699 /* Checksum the names of surrounding namespaces and structures. */
6701 checksum_die_context (parent
, &ctx
);
6703 /* Checksum the DIE and its children. */
6704 die_checksum_ordered (die
, &ctx
, &mark
);
6705 unmark_all_dies (die
);
6706 md5_finish_ctx (&ctx
, checksum
);
6708 /* Store the signature in the type node and link the type DIE and the
6709 type node together. */
6710 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6711 DWARF_TYPE_SIGNATURE_SIZE
);
6712 die
->comdat_type_p
= true;
6713 die
->die_id
.die_type_node
= type_node
;
6714 type_node
->type_die
= die
;
6716 /* If the DIE is a specification, link its declaration to the type node
6720 decl
->comdat_type_p
= true;
6721 decl
->die_id
.die_type_node
= type_node
;
6725 /* Do the location expressions look same? */
6727 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6729 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6730 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6731 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6734 /* Do the values look the same? */
6736 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6738 dw_loc_descr_ref loc1
, loc2
;
6741 if (v1
->val_class
!= v2
->val_class
)
6744 switch (v1
->val_class
)
6746 case dw_val_class_const
:
6747 return v1
->v
.val_int
== v2
->v
.val_int
;
6748 case dw_val_class_unsigned_const
:
6749 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6750 case dw_val_class_const_double
:
6751 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6752 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6753 case dw_val_class_wide_int
:
6754 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
6755 case dw_val_class_vec
:
6756 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6757 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6759 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6760 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6763 case dw_val_class_flag
:
6764 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6765 case dw_val_class_str
:
6766 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6768 case dw_val_class_addr
:
6769 r1
= v1
->v
.val_addr
;
6770 r2
= v2
->v
.val_addr
;
6771 if (GET_CODE (r1
) != GET_CODE (r2
))
6773 return !rtx_equal_p (r1
, r2
);
6775 case dw_val_class_offset
:
6776 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6778 case dw_val_class_loc
:
6779 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6781 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6782 if (!same_loc_p (loc1
, loc2
, mark
))
6784 return !loc1
&& !loc2
;
6786 case dw_val_class_die_ref
:
6787 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6789 case dw_val_class_fde_ref
:
6790 case dw_val_class_vms_delta
:
6791 case dw_val_class_lbl_id
:
6792 case dw_val_class_lineptr
:
6793 case dw_val_class_macptr
:
6794 case dw_val_class_high_pc
:
6797 case dw_val_class_file
:
6798 return v1
->v
.val_file
== v2
->v
.val_file
;
6800 case dw_val_class_data8
:
6801 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6808 /* Do the attributes look the same? */
6811 same_attr_p (dw_attr_node
*at1
, dw_attr_node
*at2
, int *mark
)
6813 if (at1
->dw_attr
!= at2
->dw_attr
)
6816 /* We don't care that this was compiled with a different compiler
6817 snapshot; if the output is the same, that's what matters. */
6818 if (at1
->dw_attr
== DW_AT_producer
)
6821 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6824 /* Do the dies look the same? */
6827 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6833 /* To avoid infinite recursion. */
6835 return die1
->die_mark
== die2
->die_mark
;
6836 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6838 if (die1
->die_tag
!= die2
->die_tag
)
6841 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6844 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6845 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6848 c1
= die1
->die_child
;
6849 c2
= die2
->die_child
;
6858 if (!same_die_p (c1
, c2
, mark
))
6862 if (c1
== die1
->die_child
)
6864 if (c2
== die2
->die_child
)
6874 /* Do the dies look the same? Wrapper around same_die_p. */
6877 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6880 int ret
= same_die_p (die1
, die2
, &mark
);
6882 unmark_all_dies (die1
);
6883 unmark_all_dies (die2
);
6888 /* The prefix to attach to symbols on DIEs in the current comdat debug
6890 static const char *comdat_symbol_id
;
6892 /* The index of the current symbol within the current comdat CU. */
6893 static unsigned int comdat_symbol_number
;
6895 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6896 children, and set comdat_symbol_id accordingly. */
6899 compute_section_prefix (dw_die_ref unit_die
)
6901 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6902 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6903 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6906 unsigned char checksum
[16];
6909 /* Compute the checksum of the DIE, then append part of it as hex digits to
6910 the name filename of the unit. */
6912 md5_init_ctx (&ctx
);
6914 die_checksum (unit_die
, &ctx
, &mark
);
6915 unmark_all_dies (unit_die
);
6916 md5_finish_ctx (&ctx
, checksum
);
6918 sprintf (name
, "%s.", base
);
6919 clean_symbol_name (name
);
6921 p
= name
+ strlen (name
);
6922 for (i
= 0; i
< 4; i
++)
6924 sprintf (p
, "%.2x", checksum
[i
]);
6928 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6929 comdat_symbol_number
= 0;
6932 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6935 is_type_die (dw_die_ref die
)
6937 switch (die
->die_tag
)
6939 case DW_TAG_array_type
:
6940 case DW_TAG_class_type
:
6941 case DW_TAG_interface_type
:
6942 case DW_TAG_enumeration_type
:
6943 case DW_TAG_pointer_type
:
6944 case DW_TAG_reference_type
:
6945 case DW_TAG_rvalue_reference_type
:
6946 case DW_TAG_string_type
:
6947 case DW_TAG_structure_type
:
6948 case DW_TAG_subroutine_type
:
6949 case DW_TAG_union_type
:
6950 case DW_TAG_ptr_to_member_type
:
6951 case DW_TAG_set_type
:
6952 case DW_TAG_subrange_type
:
6953 case DW_TAG_base_type
:
6954 case DW_TAG_const_type
:
6955 case DW_TAG_file_type
:
6956 case DW_TAG_packed_type
:
6957 case DW_TAG_volatile_type
:
6958 case DW_TAG_typedef
:
6965 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6966 Basically, we want to choose the bits that are likely to be shared between
6967 compilations (types) and leave out the bits that are specific to individual
6968 compilations (functions). */
6971 is_comdat_die (dw_die_ref c
)
6973 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6974 we do for stabs. The advantage is a greater likelihood of sharing between
6975 objects that don't include headers in the same order (and therefore would
6976 put the base types in a different comdat). jason 8/28/00 */
6978 if (c
->die_tag
== DW_TAG_base_type
)
6981 if (c
->die_tag
== DW_TAG_pointer_type
6982 || c
->die_tag
== DW_TAG_reference_type
6983 || c
->die_tag
== DW_TAG_rvalue_reference_type
6984 || c
->die_tag
== DW_TAG_const_type
6985 || c
->die_tag
== DW_TAG_volatile_type
)
6987 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6989 return t
? is_comdat_die (t
) : 0;
6992 return is_type_die (c
);
6995 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6996 compilation unit. */
6999 is_symbol_die (dw_die_ref c
)
7001 return (is_type_die (c
)
7002 || is_declaration_die (c
)
7003 || c
->die_tag
== DW_TAG_namespace
7004 || c
->die_tag
== DW_TAG_module
);
7007 /* Returns true iff C is a compile-unit DIE. */
7010 is_cu_die (dw_die_ref c
)
7012 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
7015 /* Returns true iff C is a unit DIE of some sort. */
7018 is_unit_die (dw_die_ref c
)
7020 return c
&& (c
->die_tag
== DW_TAG_compile_unit
7021 || c
->die_tag
== DW_TAG_partial_unit
7022 || c
->die_tag
== DW_TAG_type_unit
);
7025 /* Returns true iff C is a namespace DIE. */
7028 is_namespace_die (dw_die_ref c
)
7030 return c
&& c
->die_tag
== DW_TAG_namespace
;
7033 /* Returns true iff C is a class or structure DIE. */
7036 is_class_die (dw_die_ref c
)
7038 return c
&& (c
->die_tag
== DW_TAG_class_type
7039 || c
->die_tag
== DW_TAG_structure_type
);
7042 /* Return non-zero if this DIE is a template parameter. */
7045 is_template_parameter (dw_die_ref die
)
7047 switch (die
->die_tag
)
7049 case DW_TAG_template_type_param
:
7050 case DW_TAG_template_value_param
:
7051 case DW_TAG_GNU_template_template_param
:
7052 case DW_TAG_GNU_template_parameter_pack
:
7059 /* Return non-zero if this DIE represents a template instantiation. */
7062 is_template_instantiation (dw_die_ref die
)
7066 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
7068 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
7073 gen_internal_sym (const char *prefix
)
7077 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
7078 return xstrdup (buf
);
7081 /* Assign symbols to all worthy DIEs under DIE. */
7084 assign_symbol_names (dw_die_ref die
)
7088 if (is_symbol_die (die
) && !die
->comdat_type_p
)
7090 if (comdat_symbol_id
)
7092 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
7094 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
7095 comdat_symbol_id
, comdat_symbol_number
++);
7096 die
->die_id
.die_symbol
= xstrdup (p
);
7099 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
7102 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
7105 struct cu_hash_table_entry
7108 unsigned min_comdat_num
, max_comdat_num
;
7109 struct cu_hash_table_entry
*next
;
7112 /* Helpers to manipulate hash table of CUs. */
7114 struct cu_hash_table_entry_hasher
: pointer_hash
<cu_hash_table_entry
>
7116 typedef die_struct
*compare_type
;
7117 static inline hashval_t
hash (const cu_hash_table_entry
*);
7118 static inline bool equal (const cu_hash_table_entry
*, const die_struct
*);
7119 static inline void remove (cu_hash_table_entry
*);
7123 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry
*entry
)
7125 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
7129 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry
*entry1
,
7130 const die_struct
*entry2
)
7132 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
7136 cu_hash_table_entry_hasher::remove (cu_hash_table_entry
*entry
)
7138 struct cu_hash_table_entry
*next
;
7148 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
7150 /* Check whether we have already seen this CU and set up SYM_NUM
7153 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
7155 struct cu_hash_table_entry dummy
;
7156 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7158 dummy
.max_comdat_num
= 0;
7160 slot
= htable
->find_slot_with_hash (cu
,
7161 htab_hash_string (cu
->die_id
.die_symbol
),
7165 for (; entry
; last
= entry
, entry
= entry
->next
)
7167 if (same_die_p_wrap (cu
, entry
->cu
))
7173 *sym_num
= entry
->min_comdat_num
;
7177 entry
= XCNEW (struct cu_hash_table_entry
);
7179 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7180 entry
->next
= *slot
;
7186 /* Record SYM_NUM to record of CU in HTABLE. */
7188 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
7189 unsigned int sym_num
)
7191 struct cu_hash_table_entry
**slot
, *entry
;
7193 slot
= htable
->find_slot_with_hash (cu
,
7194 htab_hash_string (cu
->die_id
.die_symbol
),
7198 entry
->max_comdat_num
= sym_num
;
7201 /* Traverse the DIE (which is always comp_unit_die), and set up
7202 additional compilation units for each of the include files we see
7203 bracketed by BINCL/EINCL. */
7206 break_out_includes (dw_die_ref die
)
7209 dw_die_ref unit
= NULL
;
7210 limbo_die_node
*node
, **pnode
;
7214 dw_die_ref prev
= c
;
7216 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7217 || (unit
&& is_comdat_die (c
)))
7219 dw_die_ref next
= c
->die_sib
;
7221 /* This DIE is for a secondary CU; remove it from the main one. */
7222 remove_child_with_prev (c
, prev
);
7224 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7225 unit
= push_new_compile_unit (unit
, c
);
7226 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7227 unit
= pop_compile_unit (unit
);
7229 add_child_die (unit
, c
);
7231 if (c
== die
->die_child
)
7234 } while (c
!= die
->die_child
);
7237 /* We can only use this in debugging, since the frontend doesn't check
7238 to make sure that we leave every include file we enter. */
7242 assign_symbol_names (die
);
7243 cu_hash_type
cu_hash_table (10);
7244 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7250 compute_section_prefix (node
->die
);
7251 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
7252 &comdat_symbol_number
);
7253 assign_symbol_names (node
->die
);
7255 *pnode
= node
->next
;
7258 pnode
= &node
->next
;
7259 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
7260 comdat_symbol_number
);
7265 /* Return non-zero if this DIE is a declaration. */
7268 is_declaration_die (dw_die_ref die
)
7273 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7274 if (a
->dw_attr
== DW_AT_declaration
)
7280 /* Return non-zero if this DIE is nested inside a subprogram. */
7283 is_nested_in_subprogram (dw_die_ref die
)
7285 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7289 return local_scope_p (decl
);
7292 /* Return non-zero if this DIE contains a defining declaration of a
7296 contains_subprogram_definition (dw_die_ref die
)
7300 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7302 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7306 /* Return non-zero if this is a type DIE that should be moved to a
7307 COMDAT .debug_types section. */
7310 should_move_die_to_comdat (dw_die_ref die
)
7312 switch (die
->die_tag
)
7314 case DW_TAG_class_type
:
7315 case DW_TAG_structure_type
:
7316 case DW_TAG_enumeration_type
:
7317 case DW_TAG_union_type
:
7318 /* Don't move declarations, inlined instances, types nested in a
7319 subprogram, or types that contain subprogram definitions. */
7320 if (is_declaration_die (die
)
7321 || get_AT (die
, DW_AT_abstract_origin
)
7322 || is_nested_in_subprogram (die
)
7323 || contains_subprogram_definition (die
))
7326 case DW_TAG_array_type
:
7327 case DW_TAG_interface_type
:
7328 case DW_TAG_pointer_type
:
7329 case DW_TAG_reference_type
:
7330 case DW_TAG_rvalue_reference_type
:
7331 case DW_TAG_string_type
:
7332 case DW_TAG_subroutine_type
:
7333 case DW_TAG_ptr_to_member_type
:
7334 case DW_TAG_set_type
:
7335 case DW_TAG_subrange_type
:
7336 case DW_TAG_base_type
:
7337 case DW_TAG_const_type
:
7338 case DW_TAG_file_type
:
7339 case DW_TAG_packed_type
:
7340 case DW_TAG_volatile_type
:
7341 case DW_TAG_typedef
:
7347 /* Make a clone of DIE. */
7350 clone_die (dw_die_ref die
)
7356 clone
= ggc_cleared_alloc
<die_node
> ();
7357 clone
->die_tag
= die
->die_tag
;
7359 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7360 add_dwarf_attr (clone
, a
);
7365 /* Make a clone of the tree rooted at DIE. */
7368 clone_tree (dw_die_ref die
)
7371 dw_die_ref clone
= clone_die (die
);
7373 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7378 /* Make a clone of DIE as a declaration. */
7381 clone_as_declaration (dw_die_ref die
)
7388 /* If the DIE is already a declaration, just clone it. */
7389 if (is_declaration_die (die
))
7390 return clone_die (die
);
7392 /* If the DIE is a specification, just clone its declaration DIE. */
7393 decl
= get_AT_ref (die
, DW_AT_specification
);
7396 clone
= clone_die (decl
);
7397 if (die
->comdat_type_p
)
7398 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7402 clone
= ggc_cleared_alloc
<die_node
> ();
7403 clone
->die_tag
= die
->die_tag
;
7405 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7407 /* We don't want to copy over all attributes.
7408 For example we don't want DW_AT_byte_size because otherwise we will no
7409 longer have a declaration and GDB will treat it as a definition. */
7413 case DW_AT_abstract_origin
:
7414 case DW_AT_artificial
:
7415 case DW_AT_containing_type
:
7416 case DW_AT_external
:
7419 case DW_AT_virtuality
:
7420 case DW_AT_linkage_name
:
7421 case DW_AT_MIPS_linkage_name
:
7422 add_dwarf_attr (clone
, a
);
7424 case DW_AT_byte_size
:
7430 if (die
->comdat_type_p
)
7431 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7433 add_AT_flag (clone
, DW_AT_declaration
, 1);
7438 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7440 struct decl_table_entry
7446 /* Helpers to manipulate hash table of copied declarations. */
7448 /* Hashtable helpers. */
7450 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7452 typedef die_struct
*compare_type
;
7453 static inline hashval_t
hash (const decl_table_entry
*);
7454 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7458 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7460 return htab_hash_pointer (entry
->orig
);
7464 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7465 const die_struct
*entry2
)
7467 return entry1
->orig
== entry2
;
7470 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7472 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7473 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7474 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7475 to check if the ancestor has already been copied into UNIT. */
7478 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7479 decl_hash_type
*decl_table
)
7481 dw_die_ref parent
= die
->die_parent
;
7482 dw_die_ref new_parent
= unit
;
7484 decl_table_entry
**slot
= NULL
;
7485 struct decl_table_entry
*entry
= NULL
;
7489 /* Check if the entry has already been copied to UNIT. */
7490 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7492 if (*slot
!= HTAB_EMPTY_ENTRY
)
7498 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7499 entry
= XCNEW (struct decl_table_entry
);
7507 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7510 if (!is_unit_die (parent
))
7511 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7514 copy
= clone_as_declaration (die
);
7515 add_child_die (new_parent
, copy
);
7519 /* Record the pointer to the copy. */
7525 /* Copy the declaration context to the new type unit DIE. This includes
7526 any surrounding namespace or type declarations. If the DIE has an
7527 AT_specification attribute, it also includes attributes and children
7528 attached to the specification, and returns a pointer to the original
7529 parent of the declaration DIE. Returns NULL otherwise. */
7532 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7535 dw_die_ref new_decl
;
7536 dw_die_ref orig_parent
= NULL
;
7538 decl
= get_AT_ref (die
, DW_AT_specification
);
7547 /* The original DIE will be changed to a declaration, and must
7548 be moved to be a child of the original declaration DIE. */
7549 orig_parent
= decl
->die_parent
;
7551 /* Copy the type node pointer from the new DIE to the original
7552 declaration DIE so we can forward references later. */
7553 decl
->comdat_type_p
= true;
7554 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7556 remove_AT (die
, DW_AT_specification
);
7558 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7560 if (a
->dw_attr
!= DW_AT_name
7561 && a
->dw_attr
!= DW_AT_declaration
7562 && a
->dw_attr
!= DW_AT_external
)
7563 add_dwarf_attr (die
, a
);
7566 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7569 if (decl
->die_parent
!= NULL
7570 && !is_unit_die (decl
->die_parent
))
7572 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7573 if (new_decl
!= NULL
)
7575 remove_AT (new_decl
, DW_AT_signature
);
7576 add_AT_specification (die
, new_decl
);
7583 /* Generate the skeleton ancestor tree for the given NODE, then clone
7584 the DIE and add the clone into the tree. */
7587 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7589 if (node
->new_die
!= NULL
)
7592 node
->new_die
= clone_as_declaration (node
->old_die
);
7594 if (node
->parent
!= NULL
)
7596 generate_skeleton_ancestor_tree (node
->parent
);
7597 add_child_die (node
->parent
->new_die
, node
->new_die
);
7601 /* Generate a skeleton tree of DIEs containing any declarations that are
7602 found in the original tree. We traverse the tree looking for declaration
7603 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7606 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7608 skeleton_chain_node node
;
7611 dw_die_ref prev
= NULL
;
7612 dw_die_ref next
= NULL
;
7614 node
.parent
= parent
;
7616 first
= c
= parent
->old_die
->die_child
;
7620 if (prev
== NULL
|| prev
->die_sib
== c
)
7623 next
= (c
== first
? NULL
: c
->die_sib
);
7625 node
.new_die
= NULL
;
7626 if (is_declaration_die (c
))
7628 if (is_template_instantiation (c
))
7630 /* Instantiated templates do not need to be cloned into the
7631 type unit. Just move the DIE and its children back to
7632 the skeleton tree (in the main CU). */
7633 remove_child_with_prev (c
, prev
);
7634 add_child_die (parent
->new_die
, c
);
7639 /* Clone the existing DIE, move the original to the skeleton
7640 tree (which is in the main CU), and put the clone, with
7641 all the original's children, where the original came from
7642 (which is about to be moved to the type unit). */
7643 dw_die_ref clone
= clone_die (c
);
7644 move_all_children (c
, clone
);
7646 /* If the original has a DW_AT_object_pointer attribute,
7647 it would now point to a child DIE just moved to the
7648 cloned tree, so we need to remove that attribute from
7650 remove_AT (c
, DW_AT_object_pointer
);
7652 replace_child (c
, clone
, prev
);
7653 generate_skeleton_ancestor_tree (parent
);
7654 add_child_die (parent
->new_die
, c
);
7659 generate_skeleton_bottom_up (&node
);
7660 } while (next
!= NULL
);
7663 /* Wrapper function for generate_skeleton_bottom_up. */
7666 generate_skeleton (dw_die_ref die
)
7668 skeleton_chain_node node
;
7671 node
.new_die
= NULL
;
7674 /* If this type definition is nested inside another type,
7675 and is not an instantiation of a template, always leave
7676 at least a declaration in its place. */
7677 if (die
->die_parent
!= NULL
7678 && is_type_die (die
->die_parent
)
7679 && !is_template_instantiation (die
))
7680 node
.new_die
= clone_as_declaration (die
);
7682 generate_skeleton_bottom_up (&node
);
7683 return node
.new_die
;
7686 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7687 declaration. The original DIE is moved to a new compile unit so that
7688 existing references to it follow it to the new location. If any of the
7689 original DIE's descendants is a declaration, we need to replace the
7690 original DIE with a skeleton tree and move the declarations back into the
7694 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7697 dw_die_ref skeleton
, orig_parent
;
7699 /* Copy the declaration context to the type unit DIE. If the returned
7700 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7702 orig_parent
= copy_declaration_context (unit
, child
);
7704 skeleton
= generate_skeleton (child
);
7705 if (skeleton
== NULL
)
7706 remove_child_with_prev (child
, prev
);
7709 skeleton
->comdat_type_p
= true;
7710 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7712 /* If the original DIE was a specification, we need to put
7713 the skeleton under the parent DIE of the declaration.
7714 This leaves the original declaration in the tree, but
7715 it will be pruned later since there are no longer any
7716 references to it. */
7717 if (orig_parent
!= NULL
)
7719 remove_child_with_prev (child
, prev
);
7720 add_child_die (orig_parent
, skeleton
);
7723 replace_child (child
, skeleton
, prev
);
7730 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
7731 comdat_type_node
*type_node
,
7732 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
);
7734 /* Helper for copy_dwarf_procs_ref_in_dies. Make a copy of the DIE DWARF
7735 procedure, put it under TYPE_NODE and return the copy. Continue looking for
7736 DWARF procedure references in the DW_AT_location attribute. */
7739 copy_dwarf_procedure (dw_die_ref die
,
7740 comdat_type_node
*type_node
,
7741 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
7743 /* We do this for COMDAT section, which is DWARFv4 specific, so
7744 DWARF procedure are always DW_TAG_dwarf_procedure DIEs (unlike
7745 DW_TAG_variable in DWARFv3). */
7746 gcc_assert (die
->die_tag
== DW_TAG_dwarf_procedure
);
7748 /* DWARF procedures are not supposed to have children... */
7749 gcc_assert (die
->die_child
== NULL
);
7751 /* ... and they are supposed to have only one attribute: DW_AT_location. */
7752 gcc_assert (vec_safe_length (die
->die_attr
) == 1
7753 && ((*die
->die_attr
)[0].dw_attr
== DW_AT_location
));
7755 /* Do not copy more than once DWARF procedures. */
7757 dw_die_ref
&die_copy
= copied_dwarf_procs
.get_or_insert (die
, &existed
);
7761 die_copy
= clone_die (die
);
7762 add_child_die (type_node
->root_die
, die_copy
);
7763 copy_dwarf_procs_ref_in_attrs (die_copy
, type_node
, copied_dwarf_procs
);
7767 /* Helper for copy_dwarf_procs_ref_in_dies. Look for references to DWARF
7768 procedures in DIE's attributes. */
7771 copy_dwarf_procs_ref_in_attrs (dw_die_ref die
,
7772 comdat_type_node
*type_node
,
7773 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
7778 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, i
, a
)
7780 dw_loc_descr_ref loc
;
7782 if (a
->dw_attr_val
.val_class
!= dw_val_class_loc
)
7785 for (loc
= a
->dw_attr_val
.v
.val_loc
; loc
!= NULL
; loc
= loc
->dw_loc_next
)
7787 switch (loc
->dw_loc_opc
)
7791 case DW_OP_call_ref
:
7792 gcc_assert (loc
->dw_loc_oprnd1
.val_class
7793 == dw_val_class_die_ref
);
7794 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
7795 = copy_dwarf_procedure (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
,
7797 copied_dwarf_procs
);
7806 /* Copy DWARF procedures that are referenced by the DIE tree to TREE_NODE and
7807 rewrite references to point to the copies.
7809 References are looked for in DIE's attributes and recursively in all its
7810 children attributes that are location descriptions. COPIED_DWARF_PROCS is a
7811 mapping from old DWARF procedures to their copy. It is used not to copy
7812 twice the same DWARF procedure under TYPE_NODE. */
7815 copy_dwarf_procs_ref_in_dies (dw_die_ref die
,
7816 comdat_type_node
*type_node
,
7817 hash_map
<dw_die_ref
, dw_die_ref
> &copied_dwarf_procs
)
7821 copy_dwarf_procs_ref_in_attrs (die
, type_node
, copied_dwarf_procs
);
7822 FOR_EACH_CHILD (die
, c
, copy_dwarf_procs_ref_in_dies (c
,
7824 copied_dwarf_procs
));
7827 /* Traverse the DIE and set up additional .debug_types sections for each
7828 type worthy of being placed in a COMDAT section. */
7831 break_out_comdat_types (dw_die_ref die
)
7835 dw_die_ref prev
= NULL
;
7836 dw_die_ref next
= NULL
;
7837 dw_die_ref unit
= NULL
;
7839 first
= c
= die
->die_child
;
7843 if (prev
== NULL
|| prev
->die_sib
== c
)
7846 next
= (c
== first
? NULL
: c
->die_sib
);
7847 if (should_move_die_to_comdat (c
))
7849 dw_die_ref replacement
;
7850 comdat_type_node
*type_node
;
7852 /* Break out nested types into their own type units. */
7853 break_out_comdat_types (c
);
7855 /* Create a new type unit DIE as the root for the new tree, and
7856 add it to the list of comdat types. */
7857 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7858 add_AT_unsigned (unit
, DW_AT_language
,
7859 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7860 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
7861 type_node
->root_die
= unit
;
7862 type_node
->next
= comdat_type_list
;
7863 comdat_type_list
= type_node
;
7865 /* Generate the type signature. */
7866 generate_type_signature (c
, type_node
);
7868 /* Copy the declaration context, attributes, and children of the
7869 declaration into the new type unit DIE, then remove this DIE
7870 from the main CU (or replace it with a skeleton if necessary). */
7871 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7872 type_node
->skeleton_die
= replacement
;
7874 /* Add the DIE to the new compunit. */
7875 add_child_die (unit
, c
);
7877 /* Types can reference DWARF procedures for type size or data location
7878 expressions. Calls in DWARF expressions cannot target procedures
7879 that are not in the same section. So we must copy DWARF procedures
7880 along with this type and then rewrite references to them. */
7881 hash_map
<dw_die_ref
, dw_die_ref
> copied_dwarf_procs
;
7882 copy_dwarf_procs_ref_in_dies (c
, type_node
, copied_dwarf_procs
);
7884 if (replacement
!= NULL
)
7887 else if (c
->die_tag
== DW_TAG_namespace
7888 || c
->die_tag
== DW_TAG_class_type
7889 || c
->die_tag
== DW_TAG_structure_type
7890 || c
->die_tag
== DW_TAG_union_type
)
7892 /* Look for nested types that can be broken out. */
7893 break_out_comdat_types (c
);
7895 } while (next
!= NULL
);
7898 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7899 Enter all the cloned children into the hash table decl_table. */
7902 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
7906 struct decl_table_entry
*entry
;
7907 decl_table_entry
**slot
;
7909 if (die
->die_tag
== DW_TAG_subprogram
)
7910 clone
= clone_as_declaration (die
);
7912 clone
= clone_die (die
);
7914 slot
= decl_table
->find_slot_with_hash (die
,
7915 htab_hash_pointer (die
), INSERT
);
7917 /* Assert that DIE isn't in the hash table yet. If it would be there
7918 before, the ancestors would be necessarily there as well, therefore
7919 clone_tree_partial wouldn't be called. */
7920 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7922 entry
= XCNEW (struct decl_table_entry
);
7924 entry
->copy
= clone
;
7927 if (die
->die_tag
!= DW_TAG_subprogram
)
7928 FOR_EACH_CHILD (die
, c
,
7929 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7934 /* Walk the DIE and its children, looking for references to incomplete
7935 or trivial types that are unmarked (i.e., that are not in the current
7939 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
7945 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7947 if (AT_class (a
) == dw_val_class_die_ref
)
7949 dw_die_ref targ
= AT_ref (a
);
7950 decl_table_entry
**slot
;
7951 struct decl_table_entry
*entry
;
7953 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7956 slot
= decl_table
->find_slot_with_hash (targ
,
7957 htab_hash_pointer (targ
),
7960 if (*slot
!= HTAB_EMPTY_ENTRY
)
7962 /* TARG has already been copied, so we just need to
7963 modify the reference to point to the copy. */
7965 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7969 dw_die_ref parent
= unit
;
7970 dw_die_ref copy
= clone_die (targ
);
7972 /* Record in DECL_TABLE that TARG has been copied.
7973 Need to do this now, before the recursive call,
7974 because DECL_TABLE may be expanded and SLOT
7975 would no longer be a valid pointer. */
7976 entry
= XCNEW (struct decl_table_entry
);
7981 /* If TARG is not a declaration DIE, we need to copy its
7983 if (!is_declaration_die (targ
))
7987 add_child_die (copy
,
7988 clone_tree_partial (c
, decl_table
)));
7991 /* Make sure the cloned tree is marked as part of the
7995 /* If TARG has surrounding context, copy its ancestor tree
7996 into the new type unit. */
7997 if (targ
->die_parent
!= NULL
7998 && !is_unit_die (targ
->die_parent
))
7999 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
8002 add_child_die (parent
, copy
);
8003 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
8005 /* Make sure the newly-copied DIE is walked. If it was
8006 installed in a previously-added context, it won't
8007 get visited otherwise. */
8010 /* Find the highest point of the newly-added tree,
8011 mark each node along the way, and walk from there. */
8012 parent
->die_mark
= 1;
8013 while (parent
->die_parent
8014 && parent
->die_parent
->die_mark
== 0)
8016 parent
= parent
->die_parent
;
8017 parent
->die_mark
= 1;
8019 copy_decls_walk (unit
, parent
, decl_table
);
8025 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
8028 /* Copy declarations for "unworthy" types into the new comdat section.
8029 Incomplete types, modified types, and certain other types aren't broken
8030 out into comdat sections of their own, so they don't have a signature,
8031 and we need to copy the declaration into the same section so that we
8032 don't have an external reference. */
8035 copy_decls_for_unworthy_types (dw_die_ref unit
)
8038 decl_hash_type
decl_table (10);
8039 copy_decls_walk (unit
, unit
, &decl_table
);
8043 /* Traverse the DIE and add a sibling attribute if it may have the
8044 effect of speeding up access to siblings. To save some space,
8045 avoid generating sibling attributes for DIE's without children. */
8048 add_sibling_attributes (dw_die_ref die
)
8052 if (! die
->die_child
)
8055 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
8056 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
8058 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
8061 /* Output all location lists for the DIE and its children. */
8064 output_location_lists (dw_die_ref die
)
8070 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8071 if (AT_class (a
) == dw_val_class_loc_list
)
8072 output_loc_list (AT_loc_list (a
));
8074 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
8077 /* We want to limit the number of external references, because they are
8078 larger than local references: a relocation takes multiple words, and
8079 even a sig8 reference is always eight bytes, whereas a local reference
8080 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
8081 So if we encounter multiple external references to the same type DIE, we
8082 make a local typedef stub for it and redirect all references there.
8084 This is the element of the hash table for keeping track of these
8094 /* Hashtable helpers. */
8096 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
8098 static inline hashval_t
hash (const external_ref
*);
8099 static inline bool equal (const external_ref
*, const external_ref
*);
8103 external_ref_hasher::hash (const external_ref
*r
)
8105 dw_die_ref die
= r
->type
;
8108 /* We can't use the address of the DIE for hashing, because
8109 that will make the order of the stub DIEs non-deterministic. */
8110 if (! die
->comdat_type_p
)
8111 /* We have a symbol; use it to compute a hash. */
8112 h
= htab_hash_string (die
->die_id
.die_symbol
);
8115 /* We have a type signature; use a subset of the bits as the hash.
8116 The 8-byte signature is at least as large as hashval_t. */
8117 comdat_type_node
*type_node
= die
->die_id
.die_type_node
;
8118 memcpy (&h
, type_node
->signature
, sizeof (h
));
8124 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
8126 return r1
->type
== r2
->type
;
8129 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
8131 /* Return a pointer to the external_ref for references to DIE. */
8133 static struct external_ref
*
8134 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
8136 struct external_ref ref
, *ref_p
;
8137 external_ref
**slot
;
8140 slot
= map
->find_slot (&ref
, INSERT
);
8141 if (*slot
!= HTAB_EMPTY_ENTRY
)
8144 ref_p
= XCNEW (struct external_ref
);
8150 /* Subroutine of optimize_external_refs, below.
8152 If we see a type skeleton, record it as our stub. If we see external
8153 references, remember how many we've seen. */
8156 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
8161 struct external_ref
*ref_p
;
8163 if (is_type_die (die
)
8164 && (c
= get_AT_ref (die
, DW_AT_signature
)))
8166 /* This is a local skeleton; use it for local references. */
8167 ref_p
= lookup_external_ref (map
, c
);
8171 /* Scan the DIE references, and remember any that refer to DIEs from
8172 other CUs (i.e. those which are not marked). */
8173 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8174 if (AT_class (a
) == dw_val_class_die_ref
8175 && (c
= AT_ref (a
))->die_mark
== 0
8178 ref_p
= lookup_external_ref (map
, c
);
8182 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
8185 /* htab_traverse callback function for optimize_external_refs, below. SLOT
8186 points to an external_ref, DATA is the CU we're processing. If we don't
8187 already have a local stub, and we have multiple refs, build a stub. */
8190 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
8192 struct external_ref
*ref_p
= *slot
;
8194 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
8196 /* We have multiple references to this type, so build a small stub.
8197 Both of these forms are a bit dodgy from the perspective of the
8198 DWARF standard, since technically they should have names. */
8199 dw_die_ref cu
= data
;
8200 dw_die_ref type
= ref_p
->type
;
8201 dw_die_ref stub
= NULL
;
8203 if (type
->comdat_type_p
)
8205 /* If we refer to this type via sig8, use AT_signature. */
8206 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
8207 add_AT_die_ref (stub
, DW_AT_signature
, type
);
8211 /* Otherwise, use a typedef with no name. */
8212 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
8213 add_AT_die_ref (stub
, DW_AT_type
, type
);
8222 /* DIE is a unit; look through all the DIE references to see if there are
8223 any external references to types, and if so, create local stubs for
8224 them which will be applied in build_abbrev_table. This is useful because
8225 references to local DIEs are smaller. */
8227 static external_ref_hash_type
*
8228 optimize_external_refs (dw_die_ref die
)
8230 external_ref_hash_type
*map
= new external_ref_hash_type (10);
8231 optimize_external_refs_1 (die
, map
);
8232 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
8236 /* The format of each DIE (and its attribute value pairs) is encoded in an
8237 abbreviation table. This routine builds the abbreviation table and assigns
8238 a unique abbreviation id for each abbreviation entry. The children of each
8239 die are visited recursively. */
8242 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
8244 unsigned long abbrev_id
;
8245 unsigned int n_alloc
;
8250 /* Scan the DIE references, and replace any that refer to
8251 DIEs from other CUs (i.e. those which are not marked) with
8252 the local stubs we built in optimize_external_refs. */
8253 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8254 if (AT_class (a
) == dw_val_class_die_ref
8255 && (c
= AT_ref (a
))->die_mark
== 0)
8257 struct external_ref
*ref_p
;
8258 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
8260 ref_p
= lookup_external_ref (extern_map
, c
);
8261 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8262 change_AT_die_ref (a
, ref_p
->stub
);
8264 /* We aren't changing this reference, so mark it external. */
8265 set_AT_ref_external (a
, 1);
8268 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8270 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
8271 dw_attr_node
*die_a
, *abbrev_a
;
8275 if (abbrev
->die_tag
!= die
->die_tag
)
8277 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8280 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8283 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8285 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8286 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8287 || (value_format (abbrev_a
) != value_format (die_a
)))
8297 if (abbrev_id
>= abbrev_die_table_in_use
)
8299 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
8301 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
8302 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
8305 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
8306 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
8307 abbrev_die_table_allocated
= n_alloc
;
8310 ++abbrev_die_table_in_use
;
8311 abbrev_die_table
[abbrev_id
] = die
;
8314 die
->die_abbrev
= abbrev_id
;
8315 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8318 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8321 constant_size (unsigned HOST_WIDE_INT value
)
8328 log
= floor_log2 (value
);
8331 log
= 1 << (floor_log2 (log
) + 1);
8336 /* Return the size of a DIE as it is represented in the
8337 .debug_info section. */
8339 static unsigned long
8340 size_of_die (dw_die_ref die
)
8342 unsigned long size
= 0;
8345 enum dwarf_form form
;
8347 size
+= size_of_uleb128 (die
->die_abbrev
);
8348 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8350 switch (AT_class (a
))
8352 case dw_val_class_addr
:
8353 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8355 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8356 size
+= size_of_uleb128 (AT_index (a
));
8359 size
+= DWARF2_ADDR_SIZE
;
8361 case dw_val_class_offset
:
8362 size
+= DWARF_OFFSET_SIZE
;
8364 case dw_val_class_loc
:
8366 unsigned long lsize
= size_of_locs (AT_loc (a
));
8369 if (dwarf_version
>= 4)
8370 size
+= size_of_uleb128 (lsize
);
8372 size
+= constant_size (lsize
);
8376 case dw_val_class_loc_list
:
8377 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8379 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8380 size
+= size_of_uleb128 (AT_index (a
));
8383 size
+= DWARF_OFFSET_SIZE
;
8385 case dw_val_class_range_list
:
8386 size
+= DWARF_OFFSET_SIZE
;
8388 case dw_val_class_const
:
8389 size
+= size_of_sleb128 (AT_int (a
));
8391 case dw_val_class_unsigned_const
:
8393 int csize
= constant_size (AT_unsigned (a
));
8394 if (dwarf_version
== 3
8395 && a
->dw_attr
== DW_AT_data_member_location
8397 size
+= size_of_uleb128 (AT_unsigned (a
));
8402 case dw_val_class_const_double
:
8403 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
8404 if (HOST_BITS_PER_WIDE_INT
>= 64)
8407 case dw_val_class_wide_int
:
8408 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8409 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
8410 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
8414 case dw_val_class_vec
:
8415 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
8416 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
8417 + a
->dw_attr_val
.v
.val_vec
.length
8418 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
8420 case dw_val_class_flag
:
8421 if (dwarf_version
>= 4)
8422 /* Currently all add_AT_flag calls pass in 1 as last argument,
8423 so DW_FORM_flag_present can be used. If that ever changes,
8424 we'll need to use DW_FORM_flag and have some optimization
8425 in build_abbrev_table that will change those to
8426 DW_FORM_flag_present if it is set to 1 in all DIEs using
8427 the same abbrev entry. */
8428 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8432 case dw_val_class_die_ref
:
8433 if (AT_ref_external (a
))
8435 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8436 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8437 is sized by target address length, whereas in DWARF3
8438 it's always sized as an offset. */
8439 if (use_debug_types
)
8440 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
8441 else if (dwarf_version
== 2)
8442 size
+= DWARF2_ADDR_SIZE
;
8444 size
+= DWARF_OFFSET_SIZE
;
8447 size
+= DWARF_OFFSET_SIZE
;
8449 case dw_val_class_fde_ref
:
8450 size
+= DWARF_OFFSET_SIZE
;
8452 case dw_val_class_lbl_id
:
8453 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8455 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8456 size
+= size_of_uleb128 (AT_index (a
));
8459 size
+= DWARF2_ADDR_SIZE
;
8461 case dw_val_class_lineptr
:
8462 case dw_val_class_macptr
:
8463 size
+= DWARF_OFFSET_SIZE
;
8465 case dw_val_class_str
:
8466 form
= AT_string_form (a
);
8467 if (form
== DW_FORM_strp
)
8468 size
+= DWARF_OFFSET_SIZE
;
8469 else if (form
== DW_FORM_GNU_str_index
)
8470 size
+= size_of_uleb128 (AT_index (a
));
8472 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
8474 case dw_val_class_file
:
8475 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
8477 case dw_val_class_data8
:
8480 case dw_val_class_vms_delta
:
8481 size
+= DWARF_OFFSET_SIZE
;
8483 case dw_val_class_high_pc
:
8484 size
+= DWARF2_ADDR_SIZE
;
8486 case dw_val_class_discr_value
:
8487 size
+= size_of_discr_value (&a
->dw_attr_val
.v
.val_discr_value
);
8489 case dw_val_class_discr_list
:
8491 unsigned block_size
= size_of_discr_list (AT_discr_list (a
));
8493 /* This is a block, so we have the block length and then its
8495 size
+= constant_size (block_size
) + block_size
;
8506 /* Size the debugging information associated with a given DIE. Visits the
8507 DIE's children recursively. Updates the global variable next_die_offset, on
8508 each time through. Uses the current value of next_die_offset to update the
8509 die_offset field in each DIE. */
8512 calc_die_sizes (dw_die_ref die
)
8516 gcc_assert (die
->die_offset
== 0
8517 || (unsigned long int) die
->die_offset
== next_die_offset
);
8518 die
->die_offset
= next_die_offset
;
8519 next_die_offset
+= size_of_die (die
);
8521 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
8523 if (die
->die_child
!= NULL
)
8524 /* Count the null byte used to terminate sibling lists. */
8525 next_die_offset
+= 1;
8528 /* Size just the base type children at the start of the CU.
8529 This is needed because build_abbrev needs to size locs
8530 and sizing of type based stack ops needs to know die_offset
8531 values for the base types. */
8534 calc_base_type_die_sizes (void)
8536 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8538 dw_die_ref base_type
;
8539 #if ENABLE_ASSERT_CHECKING
8540 dw_die_ref prev
= comp_unit_die ()->die_child
;
8543 die_offset
+= size_of_die (comp_unit_die ());
8544 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
8546 #if ENABLE_ASSERT_CHECKING
8547 gcc_assert (base_type
->die_offset
== 0
8548 && prev
->die_sib
== base_type
8549 && base_type
->die_child
== NULL
8550 && base_type
->die_abbrev
);
8553 base_type
->die_offset
= die_offset
;
8554 die_offset
+= size_of_die (base_type
);
8558 /* Set the marks for a die and its children. We do this so
8559 that we know whether or not a reference needs to use FORM_ref_addr; only
8560 DIEs in the same CU will be marked. We used to clear out the offset
8561 and use that as the flag, but ran into ordering problems. */
8564 mark_dies (dw_die_ref die
)
8568 gcc_assert (!die
->die_mark
);
8571 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8574 /* Clear the marks for a die and its children. */
8577 unmark_dies (dw_die_ref die
)
8581 if (! use_debug_types
)
8582 gcc_assert (die
->die_mark
);
8585 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8588 /* Clear the marks for a die, its children and referred dies. */
8591 unmark_all_dies (dw_die_ref die
)
8601 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8603 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8604 if (AT_class (a
) == dw_val_class_die_ref
)
8605 unmark_all_dies (AT_ref (a
));
8608 /* Calculate if the entry should appear in the final output file. It may be
8609 from a pruned a type. */
8612 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8614 /* By limiting gnu pubnames to definitions only, gold can generate a
8615 gdb index without entries for declarations, which don't include
8616 enough information to be useful. */
8617 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8620 if (table
== pubname_table
)
8622 /* Enumerator names are part of the pubname table, but the
8623 parent DW_TAG_enumeration_type die may have been pruned.
8624 Don't output them if that is the case. */
8625 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8626 (p
->die
->die_parent
== NULL
8627 || !p
->die
->die_parent
->die_perennial_p
))
8630 /* Everything else in the pubname table is included. */
8634 /* The pubtypes table shouldn't include types that have been
8636 return (p
->die
->die_offset
!= 0
8637 || !flag_eliminate_unused_debug_types
);
8640 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8641 generated for the compilation unit. */
8643 static unsigned long
8644 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8649 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8651 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8652 FOR_EACH_VEC_ELT (*names
, i
, p
)
8653 if (include_pubname_in_output (names
, p
))
8654 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8656 size
+= DWARF_OFFSET_SIZE
;
8660 /* Return the size of the information in the .debug_aranges section. */
8662 static unsigned long
8663 size_of_aranges (void)
8667 size
= DWARF_ARANGES_HEADER_SIZE
;
8669 /* Count the address/length pair for this compilation unit. */
8670 if (text_section_used
)
8671 size
+= 2 * DWARF2_ADDR_SIZE
;
8672 if (cold_text_section_used
)
8673 size
+= 2 * DWARF2_ADDR_SIZE
;
8674 if (have_multiple_function_sections
)
8679 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8681 if (DECL_IGNORED_P (fde
->decl
))
8683 if (!fde
->in_std_section
)
8684 size
+= 2 * DWARF2_ADDR_SIZE
;
8685 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8686 size
+= 2 * DWARF2_ADDR_SIZE
;
8690 /* Count the two zero words used to terminated the address range table. */
8691 size
+= 2 * DWARF2_ADDR_SIZE
;
8695 /* Select the encoding of an attribute value. */
8697 static enum dwarf_form
8698 value_format (dw_attr_node
*a
)
8700 switch (AT_class (a
))
8702 case dw_val_class_addr
:
8703 /* Only very few attributes allow DW_FORM_addr. */
8708 case DW_AT_entry_pc
:
8709 case DW_AT_trampoline
:
8710 return (AT_index (a
) == NOT_INDEXED
8711 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8715 switch (DWARF2_ADDR_SIZE
)
8718 return DW_FORM_data1
;
8720 return DW_FORM_data2
;
8722 return DW_FORM_data4
;
8724 return DW_FORM_data8
;
8728 case dw_val_class_range_list
:
8729 case dw_val_class_loc_list
:
8730 if (dwarf_version
>= 4)
8731 return DW_FORM_sec_offset
;
8733 case dw_val_class_vms_delta
:
8734 case dw_val_class_offset
:
8735 switch (DWARF_OFFSET_SIZE
)
8738 return DW_FORM_data4
;
8740 return DW_FORM_data8
;
8744 case dw_val_class_loc
:
8745 if (dwarf_version
>= 4)
8746 return DW_FORM_exprloc
;
8747 switch (constant_size (size_of_locs (AT_loc (a
))))
8750 return DW_FORM_block1
;
8752 return DW_FORM_block2
;
8754 return DW_FORM_block4
;
8758 case dw_val_class_const
:
8759 return DW_FORM_sdata
;
8760 case dw_val_class_unsigned_const
:
8761 switch (constant_size (AT_unsigned (a
)))
8764 return DW_FORM_data1
;
8766 return DW_FORM_data2
;
8768 /* In DWARF3 DW_AT_data_member_location with
8769 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8770 constant, so we need to use DW_FORM_udata if we need
8771 a large constant. */
8772 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8773 return DW_FORM_udata
;
8774 return DW_FORM_data4
;
8776 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8777 return DW_FORM_udata
;
8778 return DW_FORM_data8
;
8782 case dw_val_class_const_double
:
8783 switch (HOST_BITS_PER_WIDE_INT
)
8786 return DW_FORM_data2
;
8788 return DW_FORM_data4
;
8790 return DW_FORM_data8
;
8793 return DW_FORM_block1
;
8795 case dw_val_class_wide_int
:
8796 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
8799 return DW_FORM_data1
;
8801 return DW_FORM_data2
;
8803 return DW_FORM_data4
;
8805 return DW_FORM_data8
;
8807 return DW_FORM_block1
;
8809 case dw_val_class_vec
:
8810 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8811 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8814 return DW_FORM_block1
;
8816 return DW_FORM_block2
;
8818 return DW_FORM_block4
;
8822 case dw_val_class_flag
:
8823 if (dwarf_version
>= 4)
8825 /* Currently all add_AT_flag calls pass in 1 as last argument,
8826 so DW_FORM_flag_present can be used. If that ever changes,
8827 we'll need to use DW_FORM_flag and have some optimization
8828 in build_abbrev_table that will change those to
8829 DW_FORM_flag_present if it is set to 1 in all DIEs using
8830 the same abbrev entry. */
8831 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8832 return DW_FORM_flag_present
;
8834 return DW_FORM_flag
;
8835 case dw_val_class_die_ref
:
8836 if (AT_ref_external (a
))
8837 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8840 case dw_val_class_fde_ref
:
8841 return DW_FORM_data
;
8842 case dw_val_class_lbl_id
:
8843 return (AT_index (a
) == NOT_INDEXED
8844 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8845 case dw_val_class_lineptr
:
8846 case dw_val_class_macptr
:
8847 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8848 case dw_val_class_str
:
8849 return AT_string_form (a
);
8850 case dw_val_class_file
:
8851 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8854 return DW_FORM_data1
;
8856 return DW_FORM_data2
;
8858 return DW_FORM_data4
;
8863 case dw_val_class_data8
:
8864 return DW_FORM_data8
;
8866 case dw_val_class_high_pc
:
8867 switch (DWARF2_ADDR_SIZE
)
8870 return DW_FORM_data1
;
8872 return DW_FORM_data2
;
8874 return DW_FORM_data4
;
8876 return DW_FORM_data8
;
8881 case dw_val_class_discr_value
:
8882 return (a
->dw_attr_val
.v
.val_discr_value
.pos
8885 case dw_val_class_discr_list
:
8886 switch (constant_size (size_of_discr_list (AT_discr_list (a
))))
8889 return DW_FORM_block1
;
8891 return DW_FORM_block2
;
8893 return DW_FORM_block4
;
8903 /* Output the encoding of an attribute value. */
8906 output_value_format (dw_attr_node
*a
)
8908 enum dwarf_form form
= value_format (a
);
8910 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8913 /* Given a die and id, produce the appropriate abbreviations. */
8916 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8919 dw_attr_node
*a_attr
;
8921 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8922 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8923 dwarf_tag_name (abbrev
->die_tag
));
8925 if (abbrev
->die_child
!= NULL
)
8926 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8928 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8930 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8932 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8933 dwarf_attr_name (a_attr
->dw_attr
));
8934 output_value_format (a_attr
);
8937 dw2_asm_output_data (1, 0, NULL
);
8938 dw2_asm_output_data (1, 0, NULL
);
8942 /* Output the .debug_abbrev section which defines the DIE abbreviation
8946 output_abbrev_section (void)
8948 unsigned long abbrev_id
;
8950 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8951 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8953 /* Terminate the table. */
8954 dw2_asm_output_data (1, 0, NULL
);
8957 /* Output a symbol we can use to refer to this DIE from another CU. */
8960 output_die_symbol (dw_die_ref die
)
8962 const char *sym
= die
->die_id
.die_symbol
;
8964 gcc_assert (!die
->comdat_type_p
);
8969 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8970 /* We make these global, not weak; if the target doesn't support
8971 .linkonce, it doesn't support combining the sections, so debugging
8973 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8975 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8978 /* Return a new location list, given the begin and end range, and the
8981 static inline dw_loc_list_ref
8982 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8983 const char *section
)
8985 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
8987 retlist
->begin
= begin
;
8988 retlist
->begin_entry
= NULL
;
8990 retlist
->expr
= expr
;
8991 retlist
->section
= section
;
8996 /* Generate a new internal symbol for this location list node, if it
8997 hasn't got one yet. */
9000 gen_llsym (dw_loc_list_ref list
)
9002 gcc_assert (!list
->ll_symbol
);
9003 list
->ll_symbol
= gen_internal_sym ("LLST");
9006 /* Output the location list given to us. */
9009 output_loc_list (dw_loc_list_ref list_head
)
9011 dw_loc_list_ref curr
= list_head
;
9013 if (list_head
->emitted
)
9015 list_head
->emitted
= true;
9017 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
9019 /* Walk the location list, and output each range + expression. */
9020 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
9023 /* Don't output an entry that starts and ends at the same address. */
9024 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
9026 size
= size_of_locs (curr
->expr
);
9027 /* If the expression is too large, drop it on the floor. We could
9028 perhaps put it into DW_TAG_dwarf_procedure and refer to that
9029 in the expression, but >= 64KB expressions for a single value
9030 in a single range are unlikely very useful. */
9033 if (dwarf_split_debug_info
)
9035 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
9036 "Location list start/length entry (%s)",
9037 list_head
->ll_symbol
);
9038 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
9039 "Location list range start index (%s)",
9041 /* The length field is 4 bytes. If we ever need to support
9042 an 8-byte length, we can add a new DW_LLE code or fall back
9043 to DW_LLE_GNU_start_end_entry. */
9044 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
9045 "Location list range length (%s)",
9046 list_head
->ll_symbol
);
9048 else if (!have_multiple_function_sections
)
9050 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
9051 "Location list begin address (%s)",
9052 list_head
->ll_symbol
);
9053 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
9054 "Location list end address (%s)",
9055 list_head
->ll_symbol
);
9059 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
9060 "Location list begin address (%s)",
9061 list_head
->ll_symbol
);
9062 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
9063 "Location list end address (%s)",
9064 list_head
->ll_symbol
);
9067 /* Output the block length for this list of location operations. */
9068 gcc_assert (size
<= 0xffff);
9069 dw2_asm_output_data (2, size
, "%s", "Location expression size");
9071 output_loc_sequence (curr
->expr
, -1);
9074 if (dwarf_split_debug_info
)
9075 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
9076 "Location list terminator (%s)",
9077 list_head
->ll_symbol
);
9080 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9081 "Location list terminator begin (%s)",
9082 list_head
->ll_symbol
);
9083 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
9084 "Location list terminator end (%s)",
9085 list_head
->ll_symbol
);
9089 /* Output a range_list offset into the debug_range section. Emit a
9090 relocated reference if val_entry is NULL, otherwise, emit an
9091 indirect reference. */
9094 output_range_list_offset (dw_attr_node
*a
)
9096 const char *name
= dwarf_attr_name (a
->dw_attr
);
9098 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
9100 char *p
= strchr (ranges_section_label
, '\0');
9101 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
9102 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
9103 debug_ranges_section
, "%s", name
);
9107 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
9108 "%s (offset from %s)", name
, ranges_section_label
);
9111 /* Output the offset into the debug_loc section. */
9114 output_loc_list_offset (dw_attr_node
*a
)
9116 char *sym
= AT_loc_list (a
)->ll_symbol
;
9119 if (dwarf_split_debug_info
)
9120 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
9121 "%s", dwarf_attr_name (a
->dw_attr
));
9123 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
9124 "%s", dwarf_attr_name (a
->dw_attr
));
9127 /* Output an attribute's index or value appropriately. */
9130 output_attr_index_or_value (dw_attr_node
*a
)
9132 const char *name
= dwarf_attr_name (a
->dw_attr
);
9134 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
9136 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
9139 switch (AT_class (a
))
9141 case dw_val_class_addr
:
9142 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
9144 case dw_val_class_high_pc
:
9145 case dw_val_class_lbl_id
:
9146 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
9148 case dw_val_class_loc_list
:
9149 output_loc_list_offset (a
);
9156 /* Output a type signature. */
9159 output_signature (const char *sig
, const char *name
)
9163 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9164 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
9167 /* Output a discriminant value. */
9170 output_discr_value (dw_discr_value
*discr_value
, const char *name
)
9172 if (discr_value
->pos
)
9173 dw2_asm_output_data_uleb128 (discr_value
->v
.uval
, "%s", name
);
9175 dw2_asm_output_data_sleb128 (discr_value
->v
.sval
, "%s", name
);
9178 /* Output the DIE and its attributes. Called recursively to generate
9179 the definitions of each child DIE. */
9182 output_die (dw_die_ref die
)
9189 /* If someone in another CU might refer to us, set up a symbol for
9190 them to point to. */
9191 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
9192 output_die_symbol (die
);
9194 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
9195 (unsigned long)die
->die_offset
,
9196 dwarf_tag_name (die
->die_tag
));
9198 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
9200 const char *name
= dwarf_attr_name (a
->dw_attr
);
9202 switch (AT_class (a
))
9204 case dw_val_class_addr
:
9205 output_attr_index_or_value (a
);
9208 case dw_val_class_offset
:
9209 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
9213 case dw_val_class_range_list
:
9214 output_range_list_offset (a
);
9217 case dw_val_class_loc
:
9218 size
= size_of_locs (AT_loc (a
));
9220 /* Output the block length for this list of location operations. */
9221 if (dwarf_version
>= 4)
9222 dw2_asm_output_data_uleb128 (size
, "%s", name
);
9224 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
9226 output_loc_sequence (AT_loc (a
), -1);
9229 case dw_val_class_const
:
9230 /* ??? It would be slightly more efficient to use a scheme like is
9231 used for unsigned constants below, but gdb 4.x does not sign
9232 extend. Gdb 5.x does sign extend. */
9233 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
9236 case dw_val_class_unsigned_const
:
9238 int csize
= constant_size (AT_unsigned (a
));
9239 if (dwarf_version
== 3
9240 && a
->dw_attr
== DW_AT_data_member_location
9242 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
9244 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
9248 case dw_val_class_const_double
:
9250 unsigned HOST_WIDE_INT first
, second
;
9252 if (HOST_BITS_PER_WIDE_INT
>= 64)
9253 dw2_asm_output_data (1,
9254 HOST_BITS_PER_DOUBLE_INT
9255 / HOST_BITS_PER_CHAR
,
9258 if (WORDS_BIG_ENDIAN
)
9260 first
= a
->dw_attr_val
.v
.val_double
.high
;
9261 second
= a
->dw_attr_val
.v
.val_double
.low
;
9265 first
= a
->dw_attr_val
.v
.val_double
.low
;
9266 second
= a
->dw_attr_val
.v
.val_double
.high
;
9269 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
9271 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
9276 case dw_val_class_wide_int
:
9279 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
9280 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
9281 if (len
* HOST_BITS_PER_WIDE_INT
> 64)
9282 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
) * l
,
9285 if (WORDS_BIG_ENDIAN
)
9286 for (i
= len
- 1; i
>= 0; --i
)
9288 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
9293 for (i
= 0; i
< len
; ++i
)
9295 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
9302 case dw_val_class_vec
:
9304 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
9305 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
9309 dw2_asm_output_data (constant_size (len
* elt_size
),
9310 len
* elt_size
, "%s", name
);
9311 if (elt_size
> sizeof (HOST_WIDE_INT
))
9316 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
9319 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
9320 "fp or vector constant word %u", i
);
9324 case dw_val_class_flag
:
9325 if (dwarf_version
>= 4)
9327 /* Currently all add_AT_flag calls pass in 1 as last argument,
9328 so DW_FORM_flag_present can be used. If that ever changes,
9329 we'll need to use DW_FORM_flag and have some optimization
9330 in build_abbrev_table that will change those to
9331 DW_FORM_flag_present if it is set to 1 in all DIEs using
9332 the same abbrev entry. */
9333 gcc_assert (AT_flag (a
) == 1);
9335 fprintf (asm_out_file
, "\t\t\t%s %s\n",
9336 ASM_COMMENT_START
, name
);
9339 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
9342 case dw_val_class_loc_list
:
9343 output_attr_index_or_value (a
);
9346 case dw_val_class_die_ref
:
9347 if (AT_ref_external (a
))
9349 if (AT_ref (a
)->comdat_type_p
)
9351 comdat_type_node
*type_node
=
9352 AT_ref (a
)->die_id
.die_type_node
;
9354 gcc_assert (type_node
);
9355 output_signature (type_node
->signature
, name
);
9359 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
9363 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9364 length, whereas in DWARF3 it's always sized as an
9366 if (dwarf_version
== 2)
9367 size
= DWARF2_ADDR_SIZE
;
9369 size
= DWARF_OFFSET_SIZE
;
9370 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
9376 gcc_assert (AT_ref (a
)->die_offset
);
9377 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
9382 case dw_val_class_fde_ref
:
9386 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
9387 a
->dw_attr_val
.v
.val_fde_index
* 2);
9388 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
9393 case dw_val_class_vms_delta
:
9394 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
9395 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
9396 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9399 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
9400 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9405 case dw_val_class_lbl_id
:
9406 output_attr_index_or_value (a
);
9409 case dw_val_class_lineptr
:
9410 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9411 debug_line_section
, "%s", name
);
9414 case dw_val_class_macptr
:
9415 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9416 debug_macinfo_section
, "%s", name
);
9419 case dw_val_class_str
:
9420 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
9421 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9422 a
->dw_attr_val
.v
.val_str
->label
,
9424 "%s: \"%s\"", name
, AT_string (a
));
9425 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
9426 dw2_asm_output_data_uleb128 (AT_index (a
),
9427 "%s: \"%s\"", name
, AT_string (a
));
9429 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
9432 case dw_val_class_file
:
9434 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
9436 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
9437 a
->dw_attr_val
.v
.val_file
->filename
);
9441 case dw_val_class_data8
:
9445 for (i
= 0; i
< 8; i
++)
9446 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
9447 i
== 0 ? "%s" : NULL
, name
);
9451 case dw_val_class_high_pc
:
9452 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
9453 get_AT_low_pc (die
), "DW_AT_high_pc");
9456 case dw_val_class_discr_value
:
9457 output_discr_value (&a
->dw_attr_val
.v
.val_discr_value
, name
);
9460 case dw_val_class_discr_list
:
9462 dw_discr_list_ref list
= AT_discr_list (a
);
9463 const int size
= size_of_discr_list (list
);
9465 /* This is a block, so output its length first. */
9466 dw2_asm_output_data (constant_size (size
), size
,
9467 "%s: block size", name
);
9469 for (; list
!= NULL
; list
= list
->dw_discr_next
)
9471 /* One byte for the discriminant value descriptor, and then as
9472 many LEB128 numbers as required. */
9473 if (list
->dw_discr_range
)
9474 dw2_asm_output_data (1, DW_DSC_range
,
9475 "%s: DW_DSC_range", name
);
9477 dw2_asm_output_data (1, DW_DSC_label
,
9478 "%s: DW_DSC_label", name
);
9480 output_discr_value (&list
->dw_discr_lower_bound
, name
);
9481 if (list
->dw_discr_range
)
9482 output_discr_value (&list
->dw_discr_upper_bound
, name
);
9492 FOR_EACH_CHILD (die
, c
, output_die (c
));
9494 /* Add null byte to terminate sibling list. */
9495 if (die
->die_child
!= NULL
)
9496 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9497 (unsigned long) die
->die_offset
);
9500 /* Output the compilation unit that appears at the beginning of the
9501 .debug_info section, and precedes the DIE descriptions. */
9504 output_compilation_unit_header (void)
9506 /* We don't support actual DWARFv5 units yet, we just use some
9507 DWARFv5 draft DIE tags in DWARFv4 format. */
9508 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9510 if (!XCOFF_DEBUGGING_INFO
)
9512 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9513 dw2_asm_output_data (4, 0xffffffff,
9514 "Initial length escape value indicating 64-bit DWARF extension");
9515 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9516 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
9517 "Length of Compilation Unit Info");
9520 dw2_asm_output_data (2, ver
, "DWARF version number");
9521 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
9522 debug_abbrev_section
,
9523 "Offset Into Abbrev. Section");
9524 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9527 /* Output the compilation unit DIE and its children. */
9530 output_comp_unit (dw_die_ref die
, int output_if_empty
)
9532 const char *secname
, *oldsym
;
9535 /* Unless we are outputting main CU, we may throw away empty ones. */
9536 if (!output_if_empty
&& die
->die_child
== NULL
)
9539 /* Even if there are no children of this DIE, we must output the information
9540 about the compilation unit. Otherwise, on an empty translation unit, we
9541 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9542 will then complain when examining the file. First mark all the DIEs in
9543 this CU so we know which get local refs. */
9546 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
9548 build_abbrev_table (die
, extern_map
);
9552 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9553 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
9554 calc_die_sizes (die
);
9556 oldsym
= die
->die_id
.die_symbol
;
9559 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
9561 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
9563 die
->die_id
.die_symbol
= NULL
;
9564 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9568 switch_to_section (debug_info_section
);
9569 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
9570 info_section_emitted
= true;
9573 /* Output debugging information. */
9574 output_compilation_unit_header ();
9577 /* Leave the marks on the main CU, so we can check them in
9582 die
->die_id
.die_symbol
= oldsym
;
9586 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9587 and .debug_pubtypes. This is configured per-target, but can be
9588 overridden by the -gpubnames or -gno-pubnames options. */
9591 want_pubnames (void)
9593 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9595 if (debug_generate_pub_sections
!= -1)
9596 return debug_generate_pub_sections
;
9597 return targetm
.want_debug_pub_sections
;
9600 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9603 add_AT_pubnames (dw_die_ref die
)
9605 if (want_pubnames ())
9606 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
9609 /* Add a string attribute value to a skeleton DIE. */
9612 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9616 struct indirect_string_node
*node
;
9618 if (! skeleton_debug_str_hash
)
9619 skeleton_debug_str_hash
9620 = hash_table
<indirect_string_hasher
>::create_ggc (10);
9622 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
9623 find_string_form (node
);
9624 if (node
->form
== DW_FORM_GNU_str_index
)
9625 node
->form
= DW_FORM_strp
;
9627 attr
.dw_attr
= attr_kind
;
9628 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
9629 attr
.dw_attr_val
.val_entry
= NULL
;
9630 attr
.dw_attr_val
.v
.val_str
= node
;
9631 add_dwarf_attr (die
, &attr
);
9634 /* Helper function to generate top-level dies for skeleton debug_info and
9638 add_top_level_skeleton_die_attrs (dw_die_ref die
)
9640 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
9641 const char *comp_dir
= comp_dir_string ();
9643 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
9644 if (comp_dir
!= NULL
)
9645 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
9646 add_AT_pubnames (die
);
9647 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
9650 /* Output skeleton debug sections that point to the dwo file. */
9653 output_skeleton_debug_sections (dw_die_ref comp_unit
)
9655 /* We don't support actual DWARFv5 units yet, we just use some
9656 DWARFv5 draft DIE tags in DWARFv4 format. */
9657 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9659 /* These attributes will be found in the full debug_info section. */
9660 remove_AT (comp_unit
, DW_AT_producer
);
9661 remove_AT (comp_unit
, DW_AT_language
);
9663 switch_to_section (debug_skeleton_info_section
);
9664 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
9666 /* Produce the skeleton compilation-unit header. This one differs enough from
9667 a normal CU header that it's better not to call output_compilation_unit
9669 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9670 dw2_asm_output_data (4, 0xffffffff,
9671 "Initial length escape value indicating 64-bit DWARF extension");
9673 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9674 DWARF_COMPILE_UNIT_HEADER_SIZE
9675 - DWARF_INITIAL_LENGTH_SIZE
9676 + size_of_die (comp_unit
),
9677 "Length of Compilation Unit Info");
9678 dw2_asm_output_data (2, ver
, "DWARF version number");
9679 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
9680 debug_abbrev_section
,
9681 "Offset Into Abbrev. Section");
9682 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9684 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
9685 output_die (comp_unit
);
9687 /* Build the skeleton debug_abbrev section. */
9688 switch_to_section (debug_skeleton_abbrev_section
);
9689 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
9691 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
9693 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9696 /* Output a comdat type unit DIE and its children. */
9699 output_comdat_type_unit (comdat_type_node
*node
)
9701 const char *secname
;
9704 #if defined (OBJECT_FORMAT_ELF)
9708 /* First mark all the DIEs in this CU so we know which get local refs. */
9709 mark_dies (node
->root_die
);
9711 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
9713 build_abbrev_table (node
->root_die
, extern_map
);
9718 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9719 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9720 calc_die_sizes (node
->root_die
);
9722 #if defined (OBJECT_FORMAT_ELF)
9723 if (!dwarf_split_debug_info
)
9724 secname
= ".debug_types";
9726 secname
= ".debug_types.dwo";
9728 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9729 sprintf (tmp
, "wt.");
9730 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9731 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9732 comdat_key
= get_identifier (tmp
);
9733 targetm
.asm_out
.named_section (secname
,
9734 SECTION_DEBUG
| SECTION_LINKONCE
,
9737 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9738 sprintf (tmp
, ".gnu.linkonce.wt.");
9739 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9740 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9742 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9745 /* Output debugging information. */
9746 output_compilation_unit_header ();
9747 output_signature (node
->signature
, "Type Signature");
9748 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9749 "Offset to Type DIE");
9750 output_die (node
->root_die
);
9752 unmark_dies (node
->root_die
);
9755 /* Return the DWARF2/3 pubname associated with a decl. */
9758 dwarf2_name (tree decl
, int scope
)
9760 if (DECL_NAMELESS (decl
))
9762 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9765 /* Add a new entry to .debug_pubnames if appropriate. */
9768 add_pubname_string (const char *str
, dw_die_ref die
)
9773 e
.name
= xstrdup (str
);
9774 vec_safe_push (pubname_table
, e
);
9778 add_pubname (tree decl
, dw_die_ref die
)
9780 if (!want_pubnames ())
9783 /* Don't add items to the table when we expect that the consumer will have
9784 just read the enclosing die. For example, if the consumer is looking at a
9785 class_member, it will either be inside the class already, or will have just
9786 looked up the class to find the member. Either way, searching the class is
9787 faster than searching the index. */
9788 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9789 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9791 const char *name
= dwarf2_name (decl
, 1);
9794 add_pubname_string (name
, die
);
9798 /* Add an enumerator to the pubnames section. */
9801 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9805 gcc_assert (scope_name
);
9806 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9808 vec_safe_push (pubname_table
, e
);
9811 /* Add a new entry to .debug_pubtypes if appropriate. */
9814 add_pubtype (tree decl
, dw_die_ref die
)
9818 if (!want_pubnames ())
9821 if ((TREE_PUBLIC (decl
)
9822 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9823 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9826 const char *scope_name
= "";
9827 const char *sep
= is_cxx () ? "::" : ".";
9830 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9831 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9833 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9834 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9835 scope_name
= concat (scope_name
, sep
, NULL
);
9841 name
= type_tag (decl
);
9843 name
= lang_hooks
.dwarf_name (decl
, 1);
9845 /* If we don't have a name for the type, there's no point in adding
9847 if (name
!= NULL
&& name
[0] != '\0')
9850 e
.name
= concat (scope_name
, name
, NULL
);
9851 vec_safe_push (pubtype_table
, e
);
9854 /* Although it might be more consistent to add the pubinfo for the
9855 enumerators as their dies are created, they should only be added if the
9856 enum type meets the criteria above. So rather than re-check the parent
9857 enum type whenever an enumerator die is created, just output them all
9858 here. This isn't protected by the name conditional because anonymous
9859 enums don't have names. */
9860 if (die
->die_tag
== DW_TAG_enumeration_type
)
9864 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9869 /* Output a single entry in the pubnames table. */
9872 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9874 dw_die_ref die
= entry
->die
;
9875 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9877 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9879 if (debug_generate_pub_sections
== 2)
9881 /* This logic follows gdb's method for determining the value of the flag
9883 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9884 switch (die
->die_tag
)
9886 case DW_TAG_typedef
:
9887 case DW_TAG_base_type
:
9888 case DW_TAG_subrange_type
:
9889 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9890 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9892 case DW_TAG_enumerator
:
9893 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9894 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9895 if (!is_cxx () && !is_java ())
9896 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9898 case DW_TAG_subprogram
:
9899 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9900 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9902 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9904 case DW_TAG_constant
:
9905 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9906 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9907 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9909 case DW_TAG_variable
:
9910 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9911 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9912 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9914 case DW_TAG_namespace
:
9915 case DW_TAG_imported_declaration
:
9916 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9918 case DW_TAG_class_type
:
9919 case DW_TAG_interface_type
:
9920 case DW_TAG_structure_type
:
9921 case DW_TAG_union_type
:
9922 case DW_TAG_enumeration_type
:
9923 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9924 if (!is_cxx () && !is_java ())
9925 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9928 /* An unusual tag. Leave the flag-byte empty. */
9931 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9935 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9939 /* Output the public names table used to speed up access to externally
9940 visible names; or the public types table used to find type definitions. */
9943 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9946 unsigned long pubnames_length
= size_of_pubnames (names
);
9949 if (!XCOFF_DEBUGGING_INFO
)
9951 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9952 dw2_asm_output_data (4, 0xffffffff,
9953 "Initial length escape value indicating 64-bit DWARF extension");
9954 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9958 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9959 dw2_asm_output_data (2, 2, "DWARF Version");
9961 if (dwarf_split_debug_info
)
9962 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9963 debug_skeleton_info_section
,
9964 "Offset of Compilation Unit Info");
9966 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9968 "Offset of Compilation Unit Info");
9969 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9970 "Compilation Unit Length");
9972 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9974 if (include_pubname_in_output (names
, pub
))
9976 dw_offset die_offset
= pub
->die
->die_offset
;
9978 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9979 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9980 gcc_assert (pub
->die
->die_mark
);
9982 /* If we're putting types in their own .debug_types sections,
9983 the .debug_pubtypes table will still point to the compile
9984 unit (not the type unit), so we want to use the offset of
9985 the skeleton DIE (if there is one). */
9986 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9988 comdat_type_node
*type_node
= pub
->die
->die_id
.die_type_node
;
9990 if (type_node
!= NULL
)
9991 die_offset
= (type_node
->skeleton_die
!= NULL
9992 ? type_node
->skeleton_die
->die_offset
9993 : comp_unit_die ()->die_offset
);
9996 output_pubname (die_offset
, pub
);
10000 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
10003 /* Output public names and types tables if necessary. */
10006 output_pubtables (void)
10008 if (!want_pubnames () || !info_section_emitted
)
10011 switch_to_section (debug_pubnames_section
);
10012 output_pubnames (pubname_table
);
10013 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
10014 It shouldn't hurt to emit it always, since pure DWARF2 consumers
10015 simply won't look for the section. */
10016 switch_to_section (debug_pubtypes_section
);
10017 output_pubnames (pubtype_table
);
10021 /* Output the information that goes into the .debug_aranges table.
10022 Namely, define the beginning and ending address range of the
10023 text section generated for this compilation unit. */
10026 output_aranges (void)
10029 unsigned long aranges_length
= size_of_aranges ();
10031 if (!XCOFF_DEBUGGING_INFO
)
10033 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10034 dw2_asm_output_data (4, 0xffffffff,
10035 "Initial length escape value indicating 64-bit DWARF extension");
10036 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
10037 "Length of Address Ranges Info");
10040 /* Version number for aranges is still 2, even up to DWARF5. */
10041 dw2_asm_output_data (2, 2, "DWARF Version");
10042 if (dwarf_split_debug_info
)
10043 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
10044 debug_skeleton_info_section
,
10045 "Offset of Compilation Unit Info");
10047 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
10048 debug_info_section
,
10049 "Offset of Compilation Unit Info");
10050 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
10051 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
10053 /* We need to align to twice the pointer size here. */
10054 if (DWARF_ARANGES_PAD_SIZE
)
10056 /* Pad using a 2 byte words so that padding is correct for any
10058 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
10059 2 * DWARF2_ADDR_SIZE
);
10060 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
10061 dw2_asm_output_data (2, 0, NULL
);
10064 /* It is necessary not to output these entries if the sections were
10065 not used; if the sections were not used, the length will be 0 and
10066 the address may end up as 0 if the section is discarded by ld
10067 --gc-sections, leaving an invalid (0, 0) entry that can be
10068 confused with the terminator. */
10069 if (text_section_used
)
10071 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
10072 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
10073 text_section_label
, "Length");
10075 if (cold_text_section_used
)
10077 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
10079 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
10080 cold_text_section_label
, "Length");
10083 if (have_multiple_function_sections
)
10088 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
10090 if (DECL_IGNORED_P (fde
->decl
))
10092 if (!fde
->in_std_section
)
10094 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
10096 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
10097 fde
->dw_fde_begin
, "Length");
10099 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
10101 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
10103 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
10104 fde
->dw_fde_second_begin
, "Length");
10109 /* Output the terminator words. */
10110 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10111 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10114 /* Add a new entry to .debug_ranges. Return the offset at which it
10117 static unsigned int
10118 add_ranges_num (int num
)
10120 unsigned int in_use
= ranges_table_in_use
;
10122 if (in_use
== ranges_table_allocated
)
10124 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
10125 ranges_table
= GGC_RESIZEVEC (dw_ranges
, ranges_table
,
10126 ranges_table_allocated
);
10127 memset (ranges_table
+ ranges_table_in_use
, 0,
10128 RANGES_TABLE_INCREMENT
* sizeof (dw_ranges
));
10131 ranges_table
[in_use
].num
= num
;
10132 ranges_table_in_use
= in_use
+ 1;
10134 return in_use
* 2 * DWARF2_ADDR_SIZE
;
10137 /* Add a new entry to .debug_ranges corresponding to a block, or a
10138 range terminator if BLOCK is NULL. */
10140 static unsigned int
10141 add_ranges (const_tree block
)
10143 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
10146 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
10147 When using dwarf_split_debug_info, address attributes in dies destined
10148 for the final executable should be direct references--setting the
10149 parameter force_direct ensures this behavior. */
10152 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
10153 bool *added
, bool force_direct
)
10155 unsigned int in_use
= ranges_by_label_in_use
;
10156 unsigned int offset
;
10158 if (in_use
== ranges_by_label_allocated
)
10160 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
10161 ranges_by_label
= GGC_RESIZEVEC (dw_ranges_by_label
, ranges_by_label
,
10162 ranges_by_label_allocated
);
10163 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
10164 RANGES_TABLE_INCREMENT
* sizeof (dw_ranges_by_label
));
10167 ranges_by_label
[in_use
].begin
= begin
;
10168 ranges_by_label
[in_use
].end
= end
;
10169 ranges_by_label_in_use
= in_use
+ 1;
10171 offset
= add_ranges_num (-(int)in_use
- 1);
10174 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
10180 output_ranges (void)
10183 static const char *const start_fmt
= "Offset %#x";
10184 const char *fmt
= start_fmt
;
10186 for (i
= 0; i
< ranges_table_in_use
; i
++)
10188 int block_num
= ranges_table
[i
].num
;
10192 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
10193 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
10195 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
10196 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
10198 /* If all code is in the text section, then the compilation
10199 unit base address defaults to DW_AT_low_pc, which is the
10200 base of the text section. */
10201 if (!have_multiple_function_sections
)
10203 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
10204 text_section_label
,
10205 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
10206 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
10207 text_section_label
, NULL
);
10210 /* Otherwise, the compilation unit base address is zero,
10211 which allows us to use absolute addresses, and not worry
10212 about whether the target supports cross-section
10216 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
10217 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
10218 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
10224 /* Negative block_num stands for an index into ranges_by_label. */
10225 else if (block_num
< 0)
10227 int lab_idx
= - block_num
- 1;
10229 if (!have_multiple_function_sections
)
10231 gcc_unreachable ();
10233 /* If we ever use add_ranges_by_labels () for a single
10234 function section, all we have to do is to take out
10235 the #if 0 above. */
10236 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
10237 ranges_by_label
[lab_idx
].begin
,
10238 text_section_label
,
10239 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
10240 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
10241 ranges_by_label
[lab_idx
].end
,
10242 text_section_label
, NULL
);
10247 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
10248 ranges_by_label
[lab_idx
].begin
,
10249 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
10250 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
10251 ranges_by_label
[lab_idx
].end
,
10257 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10258 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
10264 /* Data structure containing information about input files. */
10267 const char *path
; /* Complete file name. */
10268 const char *fname
; /* File name part. */
10269 int length
; /* Length of entire string. */
10270 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
10271 int dir_idx
; /* Index in directory table. */
10274 /* Data structure containing information about directories with source
10278 const char *path
; /* Path including directory name. */
10279 int length
; /* Path length. */
10280 int prefix
; /* Index of directory entry which is a prefix. */
10281 int count
; /* Number of files in this directory. */
10282 int dir_idx
; /* Index of directory used as base. */
10285 /* Callback function for file_info comparison. We sort by looking at
10286 the directories in the path. */
10289 file_info_cmp (const void *p1
, const void *p2
)
10291 const struct file_info
*const s1
= (const struct file_info
*) p1
;
10292 const struct file_info
*const s2
= (const struct file_info
*) p2
;
10293 const unsigned char *cp1
;
10294 const unsigned char *cp2
;
10296 /* Take care of file names without directories. We need to make sure that
10297 we return consistent values to qsort since some will get confused if
10298 we return the same value when identical operands are passed in opposite
10299 orders. So if neither has a directory, return 0 and otherwise return
10300 1 or -1 depending on which one has the directory. */
10301 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
10302 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
10304 cp1
= (const unsigned char *) s1
->path
;
10305 cp2
= (const unsigned char *) s2
->path
;
10311 /* Reached the end of the first path? If so, handle like above. */
10312 if ((cp1
== (const unsigned char *) s1
->fname
)
10313 || (cp2
== (const unsigned char *) s2
->fname
))
10314 return ((cp2
== (const unsigned char *) s2
->fname
)
10315 - (cp1
== (const unsigned char *) s1
->fname
));
10317 /* Character of current path component the same? */
10318 else if (*cp1
!= *cp2
)
10319 return *cp1
- *cp2
;
10323 struct file_name_acquire_data
10325 struct file_info
*files
;
10330 /* Traversal function for the hash table. */
10333 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
10335 struct dwarf_file_data
*d
= *slot
;
10336 struct file_info
*fi
;
10339 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
10341 if (! d
->emitted_number
)
10344 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
10346 fi
= fnad
->files
+ fnad
->used_files
++;
10348 /* Skip all leading "./". */
10350 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
10353 /* Create a new array entry. */
10355 fi
->length
= strlen (f
);
10358 /* Search for the file name part. */
10359 f
= strrchr (f
, DIR_SEPARATOR
);
10360 #if defined (DIR_SEPARATOR_2)
10362 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
10366 if (f
== NULL
|| f
< g
)
10372 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
10376 /* Output the directory table and the file name table. We try to minimize
10377 the total amount of memory needed. A heuristic is used to avoid large
10378 slowdowns with many input files. */
10381 output_file_names (void)
10383 struct file_name_acquire_data fnad
;
10385 struct file_info
*files
;
10386 struct dir_info
*dirs
;
10394 if (!last_emitted_file
)
10396 dw2_asm_output_data (1, 0, "End directory table");
10397 dw2_asm_output_data (1, 0, "End file name table");
10401 numfiles
= last_emitted_file
->emitted_number
;
10403 /* Allocate the various arrays we need. */
10404 files
= XALLOCAVEC (struct file_info
, numfiles
);
10405 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
10407 fnad
.files
= files
;
10408 fnad
.used_files
= 0;
10409 fnad
.max_files
= numfiles
;
10410 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
10411 gcc_assert (fnad
.used_files
== fnad
.max_files
);
10413 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
10415 /* Find all the different directories used. */
10416 dirs
[0].path
= files
[0].path
;
10417 dirs
[0].length
= files
[0].fname
- files
[0].path
;
10418 dirs
[0].prefix
= -1;
10420 dirs
[0].dir_idx
= 0;
10421 files
[0].dir_idx
= 0;
10424 for (i
= 1; i
< numfiles
; i
++)
10425 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
10426 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
10427 dirs
[ndirs
- 1].length
) == 0)
10429 /* Same directory as last entry. */
10430 files
[i
].dir_idx
= ndirs
- 1;
10431 ++dirs
[ndirs
- 1].count
;
10437 /* This is a new directory. */
10438 dirs
[ndirs
].path
= files
[i
].path
;
10439 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
10440 dirs
[ndirs
].count
= 1;
10441 dirs
[ndirs
].dir_idx
= ndirs
;
10442 files
[i
].dir_idx
= ndirs
;
10444 /* Search for a prefix. */
10445 dirs
[ndirs
].prefix
= -1;
10446 for (j
= 0; j
< ndirs
; j
++)
10447 if (dirs
[j
].length
< dirs
[ndirs
].length
10448 && dirs
[j
].length
> 1
10449 && (dirs
[ndirs
].prefix
== -1
10450 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
10451 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
10452 dirs
[ndirs
].prefix
= j
;
10457 /* Now to the actual work. We have to find a subset of the directories which
10458 allow expressing the file name using references to the directory table
10459 with the least amount of characters. We do not do an exhaustive search
10460 where we would have to check out every combination of every single
10461 possible prefix. Instead we use a heuristic which provides nearly optimal
10462 results in most cases and never is much off. */
10463 saved
= XALLOCAVEC (int, ndirs
);
10464 savehere
= XALLOCAVEC (int, ndirs
);
10466 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
10467 for (i
= 0; i
< ndirs
; i
++)
10472 /* We can always save some space for the current directory. But this
10473 does not mean it will be enough to justify adding the directory. */
10474 savehere
[i
] = dirs
[i
].length
;
10475 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
10477 for (j
= i
+ 1; j
< ndirs
; j
++)
10480 if (saved
[j
] < dirs
[i
].length
)
10482 /* Determine whether the dirs[i] path is a prefix of the
10486 k
= dirs
[j
].prefix
;
10487 while (k
!= -1 && k
!= (int) i
)
10488 k
= dirs
[k
].prefix
;
10492 /* Yes it is. We can possibly save some memory by
10493 writing the filenames in dirs[j] relative to
10495 savehere
[j
] = dirs
[i
].length
;
10496 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
10501 /* Check whether we can save enough to justify adding the dirs[i]
10503 if (total
> dirs
[i
].length
+ 1)
10505 /* It's worthwhile adding. */
10506 for (j
= i
; j
< ndirs
; j
++)
10507 if (savehere
[j
] > 0)
10509 /* Remember how much we saved for this directory so far. */
10510 saved
[j
] = savehere
[j
];
10512 /* Remember the prefix directory. */
10513 dirs
[j
].dir_idx
= i
;
10518 /* Emit the directory name table. */
10519 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
10520 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
10521 dw2_asm_output_nstring (dirs
[i
].path
,
10523 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
10524 "Directory Entry: %#x", i
+ idx_offset
);
10526 dw2_asm_output_data (1, 0, "End directory table");
10528 /* We have to emit them in the order of emitted_number since that's
10529 used in the debug info generation. To do this efficiently we
10530 generate a back-mapping of the indices first. */
10531 backmap
= XALLOCAVEC (int, numfiles
);
10532 for (i
= 0; i
< numfiles
; i
++)
10533 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
10535 /* Now write all the file names. */
10536 for (i
= 0; i
< numfiles
; i
++)
10538 int file_idx
= backmap
[i
];
10539 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
10541 #ifdef VMS_DEBUGGING_INFO
10542 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
10544 /* Setting these fields can lead to debugger miscomparisons,
10545 but VMS Debug requires them to be set correctly. */
10550 int maxfilelen
= strlen (files
[file_idx
].path
)
10551 + dirs
[dir_idx
].length
10552 + MAX_VMS_VERSION_LEN
+ 1;
10553 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
10555 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
10556 snprintf (filebuf
, maxfilelen
, "%s;%d",
10557 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
10559 dw2_asm_output_nstring
10560 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
10562 /* Include directory index. */
10563 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10565 /* Modification time. */
10566 dw2_asm_output_data_uleb128
10567 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
10571 /* File length in bytes. */
10572 dw2_asm_output_data_uleb128
10573 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
10577 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
10578 "File Entry: %#x", (unsigned) i
+ 1);
10580 /* Include directory index. */
10581 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10583 /* Modification time. */
10584 dw2_asm_output_data_uleb128 (0, NULL
);
10586 /* File length in bytes. */
10587 dw2_asm_output_data_uleb128 (0, NULL
);
10588 #endif /* VMS_DEBUGGING_INFO */
10591 dw2_asm_output_data (1, 0, "End file name table");
10595 /* Output one line number table into the .debug_line section. */
10598 output_one_line_info_table (dw_line_info_table
*table
)
10600 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10601 unsigned int current_line
= 1;
10602 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
10603 dw_line_info_entry
*ent
;
10606 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
10608 switch (ent
->opcode
)
10610 case LI_set_address
:
10611 /* ??? Unfortunately, we have little choice here currently, and
10612 must always use the most general form. GCC does not know the
10613 address delta itself, so we can't use DW_LNS_advance_pc. Many
10614 ports do have length attributes which will give an upper bound
10615 on the address range. We could perhaps use length attributes
10616 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10617 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
10619 /* This can handle any delta. This takes
10620 4+DWARF2_ADDR_SIZE bytes. */
10621 dw2_asm_output_data (1, 0, "set address %s", line_label
);
10622 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10623 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10624 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
10628 if (ent
->val
== current_line
)
10630 /* We still need to start a new row, so output a copy insn. */
10631 dw2_asm_output_data (1, DW_LNS_copy
,
10632 "copy line %u", current_line
);
10636 int line_offset
= ent
->val
- current_line
;
10637 int line_delta
= line_offset
- DWARF_LINE_BASE
;
10639 current_line
= ent
->val
;
10640 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
10642 /* This can handle deltas from -10 to 234, using the current
10643 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10644 This takes 1 byte. */
10645 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
10646 "line %u", current_line
);
10650 /* This can handle any delta. This takes at least 4 bytes,
10651 depending on the value being encoded. */
10652 dw2_asm_output_data (1, DW_LNS_advance_line
,
10653 "advance to line %u", current_line
);
10654 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
10655 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
10661 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
10662 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10665 case LI_set_column
:
10666 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
10667 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10670 case LI_negate_stmt
:
10671 current_is_stmt
= !current_is_stmt
;
10672 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10673 "is_stmt %d", current_is_stmt
);
10676 case LI_set_prologue_end
:
10677 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10678 "set prologue end");
10681 case LI_set_epilogue_begin
:
10682 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10683 "set epilogue begin");
10686 case LI_set_discriminator
:
10687 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10688 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10689 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10690 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10695 /* Emit debug info for the address of the end of the table. */
10696 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10697 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10698 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10699 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10701 dw2_asm_output_data (1, 0, "end sequence");
10702 dw2_asm_output_data_uleb128 (1, NULL
);
10703 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10706 /* Output the source line number correspondence information. This
10707 information goes into the .debug_line section. */
10710 output_line_info (bool prologue_only
)
10712 char l1
[20], l2
[20], p1
[20], p2
[20];
10713 /* We don't support DWARFv5 line tables yet. */
10714 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
10715 bool saw_one
= false;
10718 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10719 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10720 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10721 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10723 if (!XCOFF_DEBUGGING_INFO
)
10725 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10726 dw2_asm_output_data (4, 0xffffffff,
10727 "Initial length escape value indicating 64-bit DWARF extension");
10728 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10729 "Length of Source Line Info");
10732 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10734 dw2_asm_output_data (2, ver
, "DWARF Version");
10735 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10736 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10738 /* Define the architecture-dependent minimum instruction length (in bytes).
10739 In this implementation of DWARF, this field is used for information
10740 purposes only. Since GCC generates assembly language, we have no
10741 a priori knowledge of how many instruction bytes are generated for each
10742 source line, and therefore can use only the DW_LNE_set_address and
10743 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10744 this as '1', which is "correct enough" for all architectures,
10745 and don't let the target override. */
10746 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10749 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10750 "Maximum Operations Per Instruction");
10751 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10752 "Default is_stmt_start flag");
10753 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10754 "Line Base Value (Special Opcodes)");
10755 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10756 "Line Range Value (Special Opcodes)");
10757 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10758 "Special Opcode Base");
10760 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10765 case DW_LNS_advance_pc
:
10766 case DW_LNS_advance_line
:
10767 case DW_LNS_set_file
:
10768 case DW_LNS_set_column
:
10769 case DW_LNS_fixed_advance_pc
:
10770 case DW_LNS_set_isa
:
10778 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10782 /* Write out the information about the files we use. */
10783 output_file_names ();
10784 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10787 /* Output the marker for the end of the line number info. */
10788 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10792 if (separate_line_info
)
10794 dw_line_info_table
*table
;
10797 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10800 output_one_line_info_table (table
);
10804 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10806 output_one_line_info_table (cold_text_section_line_info
);
10810 /* ??? Some Darwin linkers crash on a .debug_line section with no
10811 sequences. Further, merely a DW_LNE_end_sequence entry is not
10812 sufficient -- the address column must also be initialized.
10813 Make sure to output at least one set_address/end_sequence pair,
10814 choosing .text since that section is always present. */
10815 if (text_section_line_info
->in_use
|| !saw_one
)
10816 output_one_line_info_table (text_section_line_info
);
10818 /* Output the marker for the end of the line number info. */
10819 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10822 /* Return true if DW_AT_endianity should be emitted according to REVERSE. */
10825 need_endianity_attribute_p (bool reverse
)
10827 return reverse
&& (dwarf_version
>= 3 || !dwarf_strict
);
10830 /* Given a pointer to a tree node for some base type, return a pointer to
10831 a DIE that describes the given type. REVERSE is true if the type is
10832 to be interpreted in the reverse storage order wrt the target order.
10834 This routine must only be called for GCC type nodes that correspond to
10835 Dwarf base (fundamental) types. */
10838 base_type_die (tree type
, bool reverse
)
10840 dw_die_ref base_type_result
;
10841 enum dwarf_type encoding
;
10842 bool fpt_used
= false;
10843 struct fixed_point_type_info fpt_info
;
10844 tree type_bias
= NULL_TREE
;
10846 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10849 /* If this is a subtype that should not be emitted as a subrange type,
10850 use the base type. See subrange_type_for_debug_p. */
10851 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10852 type
= TREE_TYPE (type
);
10854 switch (TREE_CODE (type
))
10857 if ((dwarf_version
>= 4 || !dwarf_strict
)
10858 && TYPE_NAME (type
)
10859 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10860 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10861 && DECL_NAME (TYPE_NAME (type
)))
10863 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10864 if (strcmp (name
, "char16_t") == 0
10865 || strcmp (name
, "char32_t") == 0)
10867 encoding
= DW_ATE_UTF
;
10871 if ((dwarf_version
>= 3 || !dwarf_strict
)
10872 && lang_hooks
.types
.get_fixed_point_type_info
)
10874 memset (&fpt_info
, 0, sizeof (fpt_info
));
10875 if (lang_hooks
.types
.get_fixed_point_type_info (type
, &fpt_info
))
10878 encoding
= ((TYPE_UNSIGNED (type
))
10879 ? DW_ATE_unsigned_fixed
10880 : DW_ATE_signed_fixed
);
10884 if (TYPE_STRING_FLAG (type
))
10886 if (TYPE_UNSIGNED (type
))
10887 encoding
= DW_ATE_unsigned_char
;
10889 encoding
= DW_ATE_signed_char
;
10891 else if (TYPE_UNSIGNED (type
))
10892 encoding
= DW_ATE_unsigned
;
10894 encoding
= DW_ATE_signed
;
10897 && lang_hooks
.types
.get_type_bias
)
10898 type_bias
= lang_hooks
.types
.get_type_bias (type
);
10902 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10904 if (dwarf_version
>= 3 || !dwarf_strict
)
10905 encoding
= DW_ATE_decimal_float
;
10907 encoding
= DW_ATE_lo_user
;
10910 encoding
= DW_ATE_float
;
10913 case FIXED_POINT_TYPE
:
10914 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10915 encoding
= DW_ATE_lo_user
;
10916 else if (TYPE_UNSIGNED (type
))
10917 encoding
= DW_ATE_unsigned_fixed
;
10919 encoding
= DW_ATE_signed_fixed
;
10922 /* Dwarf2 doesn't know anything about complex ints, so use
10923 a user defined type for it. */
10925 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10926 encoding
= DW_ATE_complex_float
;
10928 encoding
= DW_ATE_lo_user
;
10932 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10933 encoding
= DW_ATE_boolean
;
10937 /* No other TREE_CODEs are Dwarf fundamental types. */
10938 gcc_unreachable ();
10941 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10943 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10944 int_size_in_bytes (type
));
10945 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10947 if (need_endianity_attribute_p (reverse
))
10948 add_AT_unsigned (base_type_result
, DW_AT_endianity
,
10949 BYTES_BIG_ENDIAN
? DW_END_little
: DW_END_big
);
10953 switch (fpt_info
.scale_factor_kind
)
10955 case fixed_point_scale_factor_binary
:
10956 add_AT_int (base_type_result
, DW_AT_binary_scale
,
10957 fpt_info
.scale_factor
.binary
);
10960 case fixed_point_scale_factor_decimal
:
10961 add_AT_int (base_type_result
, DW_AT_decimal_scale
,
10962 fpt_info
.scale_factor
.decimal
);
10965 case fixed_point_scale_factor_arbitrary
:
10966 /* Arbitrary scale factors cannot be described in standard DWARF,
10970 /* Describe the scale factor as a rational constant. */
10971 const dw_die_ref scale_factor
10972 = new_die (DW_TAG_constant
, comp_unit_die (), type
);
10974 add_AT_unsigned (scale_factor
, DW_AT_GNU_numerator
,
10975 fpt_info
.scale_factor
.arbitrary
.numerator
);
10976 add_AT_int (scale_factor
, DW_AT_GNU_denominator
,
10977 fpt_info
.scale_factor
.arbitrary
.denominator
);
10979 add_AT_die_ref (base_type_result
, DW_AT_small
, scale_factor
);
10984 gcc_unreachable ();
10989 add_scalar_info (base_type_result
, DW_AT_GNU_bias
, type_bias
,
10990 dw_scalar_form_constant
10991 | dw_scalar_form_exprloc
10992 | dw_scalar_form_reference
,
10995 add_pubtype (type
, base_type_result
);
10997 return base_type_result
;
11000 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
11001 named 'auto' in its type: return true for it, false otherwise. */
11004 is_cxx_auto (tree type
)
11008 tree name
= TYPE_IDENTIFIER (type
);
11009 if (name
== get_identifier ("auto")
11010 || name
== get_identifier ("decltype(auto)"))
11016 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
11017 given input type is a Dwarf "fundamental" type. Otherwise return null. */
11020 is_base_type (tree type
)
11022 switch (TREE_CODE (type
))
11028 case FIXED_POINT_TYPE
:
11031 case POINTER_BOUNDS_TYPE
:
11037 case QUAL_UNION_TYPE
:
11038 case ENUMERAL_TYPE
:
11039 case FUNCTION_TYPE
:
11042 case REFERENCE_TYPE
:
11050 if (is_cxx_auto (type
))
11052 gcc_unreachable ();
11058 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
11059 node, return the size in bits for the type if it is a constant, or else
11060 return the alignment for the type if the type's size is not constant, or
11061 else return BITS_PER_WORD if the type actually turns out to be an
11062 ERROR_MARK node. */
11064 static inline unsigned HOST_WIDE_INT
11065 simple_type_size_in_bits (const_tree type
)
11067 if (TREE_CODE (type
) == ERROR_MARK
)
11068 return BITS_PER_WORD
;
11069 else if (TYPE_SIZE (type
) == NULL_TREE
)
11071 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
11072 return tree_to_uhwi (TYPE_SIZE (type
));
11074 return TYPE_ALIGN (type
);
11077 /* Similarly, but return an offset_int instead of UHWI. */
11079 static inline offset_int
11080 offset_int_type_size_in_bits (const_tree type
)
11082 if (TREE_CODE (type
) == ERROR_MARK
)
11083 return BITS_PER_WORD
;
11084 else if (TYPE_SIZE (type
) == NULL_TREE
)
11086 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
11087 return wi::to_offset (TYPE_SIZE (type
));
11089 return TYPE_ALIGN (type
);
11092 /* Given a pointer to a tree node for a subrange type, return a pointer
11093 to a DIE that describes the given type. */
11096 subrange_type_die (tree type
, tree low
, tree high
, tree bias
,
11097 dw_die_ref context_die
)
11099 dw_die_ref subrange_die
;
11100 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
11102 if (context_die
== NULL
)
11103 context_die
= comp_unit_die ();
11105 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
11107 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
11109 /* The size of the subrange type and its base type do not match,
11110 so we need to generate a size attribute for the subrange type. */
11111 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
11115 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
11117 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
11118 if (bias
&& !dwarf_strict
)
11119 add_scalar_info (subrange_die
, DW_AT_GNU_bias
, bias
,
11120 dw_scalar_form_constant
11121 | dw_scalar_form_exprloc
11122 | dw_scalar_form_reference
,
11125 return subrange_die
;
11128 /* Returns the (const and/or volatile) cv_qualifiers associated with
11129 the decl node. This will normally be augmented with the
11130 cv_qualifiers of the underlying type in add_type_attribute. */
11133 decl_quals (const_tree decl
)
11135 return ((TREE_READONLY (decl
)
11136 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
11137 | (TREE_THIS_VOLATILE (decl
)
11138 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
11141 /* Determine the TYPE whose qualifiers match the largest strict subset
11142 of the given TYPE_QUALS, and return its qualifiers. Ignore all
11143 qualifiers outside QUAL_MASK. */
11146 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
11149 int best_rank
= 0, best_qual
= 0, max_rank
;
11151 type_quals
&= qual_mask
;
11152 max_rank
= popcount_hwi (type_quals
) - 1;
11154 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
11155 t
= TYPE_NEXT_VARIANT (t
))
11157 int q
= TYPE_QUALS (t
) & qual_mask
;
11159 if ((q
& type_quals
) == q
&& q
!= type_quals
11160 && check_base_type (t
, type
))
11162 int rank
= popcount_hwi (q
);
11164 if (rank
> best_rank
)
11175 struct dwarf_qual_info_t
{ int q
; enum dwarf_tag t
; };
11176 static const dwarf_qual_info_t dwarf_qual_info
[] =
11178 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
11179 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
11180 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
11181 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
}
11183 static const unsigned int dwarf_qual_info_size
11184 = sizeof (dwarf_qual_info
) / sizeof (dwarf_qual_info
[0]);
11186 /* If DIE is a qualified DIE of some base DIE with the same parent,
11187 return the base DIE, otherwise return NULL. Set MASK to the
11188 qualifiers added compared to the returned DIE. */
11191 qualified_die_p (dw_die_ref die
, int *mask
, unsigned int depth
)
11194 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
11195 if (die
->die_tag
== dwarf_qual_info
[i
].t
)
11197 if (i
== dwarf_qual_info_size
)
11199 if (vec_safe_length (die
->die_attr
) != 1)
11201 dw_die_ref type
= get_AT_ref (die
, DW_AT_type
);
11202 if (type
== NULL
|| type
->die_parent
!= die
->die_parent
)
11204 *mask
|= dwarf_qual_info
[i
].q
;
11207 dw_die_ref ret
= qualified_die_p (type
, mask
, depth
- 1);
11214 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
11215 entry that chains the modifiers specified by CV_QUALS in front of the
11216 given type. REVERSE is true if the type is to be interpreted in the
11217 reverse storage order wrt the target order. */
11220 modified_type_die (tree type
, int cv_quals
, bool reverse
,
11221 dw_die_ref context_die
)
11223 enum tree_code code
= TREE_CODE (type
);
11224 dw_die_ref mod_type_die
;
11225 dw_die_ref sub_die
= NULL
;
11226 tree item_type
= NULL
;
11227 tree qualified_type
;
11228 tree name
, low
, high
;
11229 dw_die_ref mod_scope
;
11230 /* Only these cv-qualifiers are currently handled. */
11231 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
11232 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
11234 if (code
== ERROR_MARK
)
11237 if (lang_hooks
.types
.get_debug_type
)
11239 tree debug_type
= lang_hooks
.types
.get_debug_type (type
);
11241 if (debug_type
!= NULL_TREE
&& debug_type
!= type
)
11242 return modified_type_die (debug_type
, cv_quals
, reverse
, context_die
);
11245 cv_quals
&= cv_qual_mask
;
11247 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
11248 tag modifier (and not an attribute) old consumers won't be able
11250 if (dwarf_version
< 3)
11251 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
11253 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
11254 if (dwarf_version
< 5)
11255 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
11257 /* See if we already have the appropriately qualified variant of
11259 qualified_type
= get_qualified_type (type
, cv_quals
);
11261 if (qualified_type
== sizetype
11262 && TYPE_NAME (qualified_type
)
11263 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
11265 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
11267 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
11268 && TYPE_PRECISION (t
)
11269 == TYPE_PRECISION (qualified_type
)
11270 && TYPE_UNSIGNED (t
)
11271 == TYPE_UNSIGNED (qualified_type
));
11272 qualified_type
= t
;
11275 /* If we do, then we can just use its DIE, if it exists. */
11276 if (qualified_type
)
11278 mod_type_die
= lookup_type_die (qualified_type
);
11280 /* DW_AT_endianity doesn't come from a qualifier on the type. */
11282 && (!need_endianity_attribute_p (reverse
)
11283 || !is_base_type (type
)
11284 || get_AT_unsigned (mod_type_die
, DW_AT_endianity
)))
11285 return mod_type_die
;
11288 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
11290 /* Handle C typedef types. */
11291 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
11292 && !DECL_ARTIFICIAL (name
))
11294 tree dtype
= TREE_TYPE (name
);
11296 if (qualified_type
== dtype
)
11298 /* For a named type, use the typedef. */
11299 gen_type_die (qualified_type
, context_die
);
11300 return lookup_type_die (qualified_type
);
11304 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
11305 dquals
&= cv_qual_mask
;
11306 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
11307 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
11308 /* cv-unqualified version of named type. Just use
11309 the unnamed type to which it refers. */
11310 return modified_type_die (DECL_ORIGINAL_TYPE (name
), cv_quals
,
11311 reverse
, context_die
);
11312 /* Else cv-qualified version of named type; fall through. */
11316 mod_scope
= scope_die_for (type
, context_die
);
11320 int sub_quals
= 0, first_quals
= 0;
11322 dw_die_ref first
= NULL
, last
= NULL
;
11324 /* Determine a lesser qualified type that most closely matches
11325 this one. Then generate DW_TAG_* entries for the remaining
11327 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
11329 if (sub_quals
&& use_debug_types
)
11331 bool needed
= false;
11332 /* If emitting type units, make sure the order of qualifiers
11333 is canonical. Thus, start from unqualified type if
11334 an earlier qualifier is missing in sub_quals, but some later
11335 one is present there. */
11336 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
11337 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
11339 else if (needed
&& (dwarf_qual_info
[i
].q
& cv_quals
))
11345 mod_type_die
= modified_type_die (type
, sub_quals
, reverse
, context_die
);
11346 if (mod_scope
&& mod_type_die
&& mod_type_die
->die_parent
== mod_scope
)
11348 /* As not all intermediate qualified DIEs have corresponding
11349 tree types, ensure that qualified DIEs in the same scope
11350 as their DW_AT_type are emitted after their DW_AT_type,
11351 only with other qualified DIEs for the same type possibly
11352 in between them. Determine the range of such qualified
11353 DIEs now (first being the base type, last being corresponding
11354 last qualified DIE for it). */
11355 unsigned int count
= 0;
11356 first
= qualified_die_p (mod_type_die
, &first_quals
,
11357 dwarf_qual_info_size
);
11359 first
= mod_type_die
;
11360 gcc_assert ((first_quals
& ~sub_quals
) == 0);
11361 for (count
= 0, last
= first
;
11362 count
< (1U << dwarf_qual_info_size
);
11363 count
++, last
= last
->die_sib
)
11366 if (last
== mod_scope
->die_child
)
11368 if (qualified_die_p (last
->die_sib
, &quals
, dwarf_qual_info_size
)
11374 for (i
= 0; i
< dwarf_qual_info_size
; i
++)
11375 if (dwarf_qual_info
[i
].q
& cv_quals
& ~sub_quals
)
11378 if (first
&& first
!= last
)
11380 for (d
= first
->die_sib
; ; d
= d
->die_sib
)
11383 qualified_die_p (d
, &quals
, dwarf_qual_info_size
);
11384 if (quals
== (first_quals
| dwarf_qual_info
[i
].q
))
11400 d
= ggc_cleared_alloc
<die_node
> ();
11401 d
->die_tag
= dwarf_qual_info
[i
].t
;
11402 add_child_die_after (mod_scope
, d
, last
);
11406 d
= new_die (dwarf_qual_info
[i
].t
, mod_scope
, type
);
11408 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
11410 first_quals
|= dwarf_qual_info
[i
].q
;
11413 else if (code
== POINTER_TYPE
|| code
== REFERENCE_TYPE
)
11415 dwarf_tag tag
= DW_TAG_pointer_type
;
11416 if (code
== REFERENCE_TYPE
)
11418 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
11419 tag
= DW_TAG_rvalue_reference_type
;
11421 tag
= DW_TAG_reference_type
;
11423 mod_type_die
= new_die (tag
, mod_scope
, type
);
11425 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
11426 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
11427 item_type
= TREE_TYPE (type
);
11429 addr_space_t as
= TYPE_ADDR_SPACE (item_type
);
11430 if (!ADDR_SPACE_GENERIC_P (as
))
11432 int action
= targetm
.addr_space
.debug (as
);
11435 /* Positive values indicate an address_class. */
11436 add_AT_unsigned (mod_type_die
, DW_AT_address_class
, action
);
11440 /* Negative values indicate an (inverted) segment base reg. */
11442 = one_reg_loc_descriptor (~action
, VAR_INIT_STATUS_INITIALIZED
);
11443 add_AT_loc (mod_type_die
, DW_AT_segment
, d
);
11447 else if (code
== INTEGER_TYPE
11448 && TREE_TYPE (type
) != NULL_TREE
11449 && subrange_type_for_debug_p (type
, &low
, &high
))
11451 tree bias
= NULL_TREE
;
11452 if (lang_hooks
.types
.get_type_bias
)
11453 bias
= lang_hooks
.types
.get_type_bias (type
);
11454 mod_type_die
= subrange_type_die (type
, low
, high
, bias
, context_die
);
11455 item_type
= TREE_TYPE (type
);
11457 else if (is_base_type (type
))
11458 mod_type_die
= base_type_die (type
, reverse
);
11461 gen_type_die (type
, context_die
);
11463 /* We have to get the type_main_variant here (and pass that to the
11464 `lookup_type_die' routine) because the ..._TYPE node we have
11465 might simply be a *copy* of some original type node (where the
11466 copy was created to help us keep track of typedef names) and
11467 that copy might have a different TYPE_UID from the original
11469 if (TREE_CODE (type
) != VECTOR_TYPE
11470 && TREE_CODE (type
) != ARRAY_TYPE
)
11471 return lookup_type_die (type_main_variant (type
));
11473 /* Vectors have the debugging information in the type,
11474 not the main variant. */
11475 return lookup_type_die (type
);
11478 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
11479 don't output a DW_TAG_typedef, since there isn't one in the
11480 user's program; just attach a DW_AT_name to the type.
11481 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
11482 if the base type already has the same name. */
11484 && ((TREE_CODE (name
) != TYPE_DECL
11485 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
11486 || (cv_quals
== TYPE_UNQUALIFIED
)))
11487 || (TREE_CODE (name
) == TYPE_DECL
11488 && TREE_TYPE (name
) == qualified_type
11489 && DECL_NAME (name
))))
11491 if (TREE_CODE (name
) == TYPE_DECL
)
11492 /* Could just call add_name_and_src_coords_attributes here,
11493 but since this is a builtin type it doesn't have any
11494 useful source coordinates anyway. */
11495 name
= DECL_NAME (name
);
11496 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
11498 /* This probably indicates a bug. */
11499 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
11501 name
= TYPE_IDENTIFIER (type
);
11502 add_name_attribute (mod_type_die
,
11503 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
11506 if (qualified_type
)
11507 equate_type_number_to_die (qualified_type
, mod_type_die
);
11510 /* We must do this after the equate_type_number_to_die call, in case
11511 this is a recursive type. This ensures that the modified_type_die
11512 recursion will terminate even if the type is recursive. Recursive
11513 types are possible in Ada. */
11514 sub_die
= modified_type_die (item_type
,
11515 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
11519 if (sub_die
!= NULL
)
11520 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
11522 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
11523 if (TYPE_ARTIFICIAL (type
))
11524 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
11526 return mod_type_die
;
11529 /* Generate DIEs for the generic parameters of T.
11530 T must be either a generic type or a generic function.
11531 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
11534 gen_generic_params_dies (tree t
)
11538 dw_die_ref die
= NULL
;
11541 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
11545 die
= lookup_type_die (t
);
11546 else if (DECL_P (t
))
11547 die
= lookup_decl_die (t
);
11551 parms
= lang_hooks
.get_innermost_generic_parms (t
);
11553 /* T has no generic parameter. It means T is neither a generic type
11554 or function. End of story. */
11557 parms_num
= TREE_VEC_LENGTH (parms
);
11558 args
= lang_hooks
.get_innermost_generic_args (t
);
11559 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
11560 non_default
= int_cst_value (TREE_CHAIN (args
));
11562 non_default
= TREE_VEC_LENGTH (args
);
11563 for (i
= 0; i
< parms_num
; i
++)
11565 tree parm
, arg
, arg_pack_elems
;
11566 dw_die_ref parm_die
;
11568 parm
= TREE_VEC_ELT (parms
, i
);
11569 arg
= TREE_VEC_ELT (args
, i
);
11570 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
11571 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
11573 if (parm
&& TREE_VALUE (parm
) && arg
)
11575 /* If PARM represents a template parameter pack,
11576 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
11577 by DW_TAG_template_*_parameter DIEs for the argument
11578 pack elements of ARG. Note that ARG would then be
11579 an argument pack. */
11580 if (arg_pack_elems
)
11581 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
11585 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
11586 true /* emit name */, die
);
11587 if (i
>= non_default
)
11588 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
11593 /* Create and return a DIE for PARM which should be
11594 the representation of a generic type parameter.
11595 For instance, in the C++ front end, PARM would be a template parameter.
11596 ARG is the argument to PARM.
11597 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
11599 PARENT_DIE is the parent DIE which the new created DIE should be added to,
11600 as a child node. */
11603 generic_parameter_die (tree parm
, tree arg
,
11605 dw_die_ref parent_die
)
11607 dw_die_ref tmpl_die
= NULL
;
11608 const char *name
= NULL
;
11610 if (!parm
|| !DECL_NAME (parm
) || !arg
)
11613 /* We support non-type generic parameters and arguments,
11614 type generic parameters and arguments, as well as
11615 generic generic parameters (a.k.a. template template parameters in C++)
11617 if (TREE_CODE (parm
) == PARM_DECL
)
11618 /* PARM is a nontype generic parameter */
11619 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
11620 else if (TREE_CODE (parm
) == TYPE_DECL
)
11621 /* PARM is a type generic parameter. */
11622 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
11623 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11624 /* PARM is a generic generic parameter.
11625 Its DIE is a GNU extension. It shall have a
11626 DW_AT_name attribute to represent the name of the template template
11627 parameter, and a DW_AT_GNU_template_name attribute to represent the
11628 name of the template template argument. */
11629 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
11632 gcc_unreachable ();
11638 /* If PARM is a generic parameter pack, it means we are
11639 emitting debug info for a template argument pack element.
11640 In other terms, ARG is a template argument pack element.
11641 In that case, we don't emit any DW_AT_name attribute for
11645 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
11647 add_AT_string (tmpl_die
, DW_AT_name
, name
);
11650 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11652 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
11653 TMPL_DIE should have a child DW_AT_type attribute that is set
11654 to the type of the argument to PARM, which is ARG.
11655 If PARM is a type generic parameter, TMPL_DIE should have a
11656 child DW_AT_type that is set to ARG. */
11657 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
11658 add_type_attribute (tmpl_die
, tmpl_type
,
11659 (TREE_THIS_VOLATILE (tmpl_type
)
11660 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
11661 false, parent_die
);
11665 /* So TMPL_DIE is a DIE representing a
11666 a generic generic template parameter, a.k.a template template
11667 parameter in C++ and arg is a template. */
11669 /* The DW_AT_GNU_template_name attribute of the DIE must be set
11670 to the name of the argument. */
11671 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
11673 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
11676 if (TREE_CODE (parm
) == PARM_DECL
)
11677 /* So PARM is a non-type generic parameter.
11678 DWARF3 5.6.8 says we must set a DW_AT_const_value child
11679 attribute of TMPL_DIE which value represents the value
11681 We must be careful here:
11682 The value of ARG might reference some function decls.
11683 We might currently be emitting debug info for a generic
11684 type and types are emitted before function decls, we don't
11685 know if the function decls referenced by ARG will actually be
11686 emitted after cgraph computations.
11687 So must defer the generation of the DW_AT_const_value to
11688 after cgraph is ready. */
11689 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
11695 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
11696 PARM_PACK must be a template parameter pack. The returned DIE
11697 will be child DIE of PARENT_DIE. */
11700 template_parameter_pack_die (tree parm_pack
,
11701 tree parm_pack_args
,
11702 dw_die_ref parent_die
)
11707 gcc_assert (parent_die
&& parm_pack
);
11709 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
11710 add_name_and_src_coords_attributes (die
, parm_pack
);
11711 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
11712 generic_parameter_die (parm_pack
,
11713 TREE_VEC_ELT (parm_pack_args
, j
),
11714 false /* Don't emit DW_AT_name */,
11719 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
11720 an enumerated type. */
11723 type_is_enum (const_tree type
)
11725 return TREE_CODE (type
) == ENUMERAL_TYPE
;
11728 /* Return the DBX register number described by a given RTL node. */
11730 static unsigned int
11731 dbx_reg_number (const_rtx rtl
)
11733 unsigned regno
= REGNO (rtl
);
11735 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
11737 #ifdef LEAF_REG_REMAP
11738 if (crtl
->uses_only_leaf_regs
)
11740 int leaf_reg
= LEAF_REG_REMAP (regno
);
11741 if (leaf_reg
!= -1)
11742 regno
= (unsigned) leaf_reg
;
11746 regno
= DBX_REGISTER_NUMBER (regno
);
11747 gcc_assert (regno
!= INVALID_REGNUM
);
11751 /* Optionally add a DW_OP_piece term to a location description expression.
11752 DW_OP_piece is only added if the location description expression already
11753 doesn't end with DW_OP_piece. */
11756 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
11758 dw_loc_descr_ref loc
;
11760 if (*list_head
!= NULL
)
11762 /* Find the end of the chain. */
11763 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
11766 if (loc
->dw_loc_opc
!= DW_OP_piece
)
11767 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
11771 /* Return a location descriptor that designates a machine register or
11772 zero if there is none. */
11774 static dw_loc_descr_ref
11775 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
11779 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
11782 /* We only use "frame base" when we're sure we're talking about the
11783 post-prologue local stack frame. We do this by *not* running
11784 register elimination until this point, and recognizing the special
11785 argument pointer and soft frame pointer rtx's.
11786 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
11787 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
11788 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
11790 dw_loc_descr_ref result
= NULL
;
11792 if (dwarf_version
>= 4 || !dwarf_strict
)
11794 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
11797 add_loc_descr (&result
,
11798 new_loc_descr (DW_OP_stack_value
, 0, 0));
11803 regs
= targetm
.dwarf_register_span (rtl
);
11805 if (REG_NREGS (rtl
) > 1 || regs
)
11806 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
11809 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
11810 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11812 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
11816 /* Return a location descriptor that designates a machine register for
11817 a given hard register number. */
11819 static dw_loc_descr_ref
11820 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
11822 dw_loc_descr_ref reg_loc_descr
;
11826 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
11828 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
11830 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11831 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11833 return reg_loc_descr
;
11836 /* Given an RTL of a register, return a location descriptor that
11837 designates a value that spans more than one register. */
11839 static dw_loc_descr_ref
11840 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
11841 enum var_init_status initialized
)
11844 dw_loc_descr_ref loc_result
= NULL
;
11846 /* Simple, contiguous registers. */
11847 if (regs
== NULL_RTX
)
11849 unsigned reg
= REGNO (rtl
);
11852 #ifdef LEAF_REG_REMAP
11853 if (crtl
->uses_only_leaf_regs
)
11855 int leaf_reg
= LEAF_REG_REMAP (reg
);
11856 if (leaf_reg
!= -1)
11857 reg
= (unsigned) leaf_reg
;
11861 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
11862 nregs
= REG_NREGS (rtl
);
11864 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
11869 dw_loc_descr_ref t
;
11871 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
11872 VAR_INIT_STATUS_INITIALIZED
);
11873 add_loc_descr (&loc_result
, t
);
11874 add_loc_descr_op_piece (&loc_result
, size
);
11880 /* Now onto stupid register sets in non contiguous locations. */
11882 gcc_assert (GET_CODE (regs
) == PARALLEL
);
11884 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
11887 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
11889 dw_loc_descr_ref t
;
11891 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
11892 VAR_INIT_STATUS_INITIALIZED
);
11893 add_loc_descr (&loc_result
, t
);
11894 add_loc_descr_op_piece (&loc_result
, size
);
11897 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11898 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11902 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
11904 /* Return a location descriptor that designates a constant i,
11905 as a compound operation from constant (i >> shift), constant shift
11908 static dw_loc_descr_ref
11909 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11911 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
11912 add_loc_descr (&ret
, int_loc_descriptor (shift
));
11913 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11917 /* Return a location descriptor that designates a constant. */
11919 static dw_loc_descr_ref
11920 int_loc_descriptor (HOST_WIDE_INT i
)
11922 enum dwarf_location_atom op
;
11924 /* Pick the smallest representation of a constant, rather than just
11925 defaulting to the LEB encoding. */
11928 int clz
= clz_hwi (i
);
11929 int ctz
= ctz_hwi (i
);
11931 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
11932 else if (i
<= 0xff)
11933 op
= DW_OP_const1u
;
11934 else if (i
<= 0xffff)
11935 op
= DW_OP_const2u
;
11936 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11937 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11938 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11939 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11940 while DW_OP_const4u is 5 bytes. */
11941 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
11942 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11943 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11944 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11945 while DW_OP_const4u is 5 bytes. */
11946 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11947 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11948 op
= DW_OP_const4u
;
11949 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11950 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11951 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11952 while DW_OP_constu of constant >= 0x100000000 takes at least
11954 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11955 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11956 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
11957 >= HOST_BITS_PER_WIDE_INT
)
11958 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11959 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11960 while DW_OP_constu takes in this case at least 6 bytes. */
11961 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
11962 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11963 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11964 && size_of_uleb128 (i
) > 6)
11965 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11966 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11973 op
= DW_OP_const1s
;
11974 else if (i
>= -0x8000)
11975 op
= DW_OP_const2s
;
11976 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11978 if (size_of_int_loc_descriptor (i
) < 5)
11980 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11981 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11984 op
= DW_OP_const4s
;
11988 if (size_of_int_loc_descriptor (i
)
11989 < (unsigned long) 1 + size_of_sleb128 (i
))
11991 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11992 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11999 return new_loc_descr (op
, i
, 0);
12002 /* Likewise, for unsigned constants. */
12004 static dw_loc_descr_ref
12005 uint_loc_descriptor (unsigned HOST_WIDE_INT i
)
12007 const unsigned HOST_WIDE_INT max_int
= INTTYPE_MAXIMUM (HOST_WIDE_INT
);
12008 const unsigned HOST_WIDE_INT max_uint
12009 = INTTYPE_MAXIMUM (unsigned HOST_WIDE_INT
);
12011 /* If possible, use the clever signed constants handling. */
12013 return int_loc_descriptor ((HOST_WIDE_INT
) i
);
12015 /* Here, we are left with positive numbers that cannot be represented as
12016 HOST_WIDE_INT, i.e.:
12017 max (HOST_WIDE_INT) < i <= max (unsigned HOST_WIDE_INT)
12019 Using DW_OP_const4/8/./u operation to encode them consumes a lot of bytes
12020 whereas may be better to output a negative integer: thanks to integer
12021 wrapping, we know that:
12022 x = x - 2 ** DWARF2_ADDR_SIZE
12023 = x - 2 * (max (HOST_WIDE_INT) + 1)
12024 So numbers close to max (unsigned HOST_WIDE_INT) could be represented as
12025 small negative integers. Let's try that in cases it will clearly improve
12026 the encoding: there is no gain turning DW_OP_const4u into
12028 if (DWARF2_ADDR_SIZE
* 8 == HOST_BITS_PER_WIDE_INT
12029 && ((DWARF2_ADDR_SIZE
== 4 && i
> max_uint
- 0x8000)
12030 || (DWARF2_ADDR_SIZE
== 8 && i
> max_uint
- 0x80000000)))
12032 const unsigned HOST_WIDE_INT first_shift
= i
- max_int
- 1;
12034 /* Now, -1 < first_shift <= max (HOST_WIDE_INT)
12035 i.e. 0 <= first_shift <= max (HOST_WIDE_INT). */
12036 const HOST_WIDE_INT second_shift
12037 = (HOST_WIDE_INT
) first_shift
- (HOST_WIDE_INT
) max_int
- 1;
12039 /* So we finally have:
12040 -max (HOST_WIDE_INT) - 1 <= second_shift <= -1.
12041 i.e. min (HOST_WIDE_INT) <= second_shift < 0. */
12042 return int_loc_descriptor (second_shift
);
12045 /* Last chance: fallback to a simple constant operation. */
12046 return new_loc_descr
12047 ((HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
12053 /* Generate and return a location description that computes the unsigned
12054 comparison of the two stack top entries (a OP b where b is the top-most
12055 entry and a is the second one). The KIND of comparison can be LT_EXPR,
12056 LE_EXPR, GT_EXPR or GE_EXPR. */
12058 static dw_loc_descr_ref
12059 uint_comparison_loc_list (enum tree_code kind
)
12061 enum dwarf_location_atom op
, flip_op
;
12062 dw_loc_descr_ref ret
, bra_node
, jmp_node
, tmp
;
12079 gcc_unreachable ();
12082 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12083 jmp_node
= new_loc_descr (DW_OP_skip
, 0, 0);
12085 /* Until DWARFv4, operations all work on signed integers. It is nevertheless
12086 possible to perform unsigned comparisons: we just have to distinguish
12089 1. when a and b have the same sign (as signed integers); then we should
12090 return: a OP(signed) b;
12092 2. when a is a negative signed integer while b is a positive one, then a
12093 is a greater unsigned integer than b; likewise when a and b's roles
12096 So first, compare the sign of the two operands. */
12097 ret
= new_loc_descr (DW_OP_over
, 0, 0);
12098 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12099 add_loc_descr (&ret
, new_loc_descr (DW_OP_xor
, 0, 0));
12100 /* If they have different signs (i.e. they have different sign bits), then
12101 the stack top value has now the sign bit set and thus it's smaller than
12103 add_loc_descr (&ret
, new_loc_descr (DW_OP_lit0
, 0, 0));
12104 add_loc_descr (&ret
, new_loc_descr (DW_OP_lt
, 0, 0));
12105 add_loc_descr (&ret
, bra_node
);
12107 /* We are in case 1. At this point, we know both operands have the same
12108 sign, to it's safe to use the built-in signed comparison. */
12109 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12110 add_loc_descr (&ret
, jmp_node
);
12112 /* We are in case 2. Here, we know both operands do not have the same sign,
12113 so we have to flip the signed comparison. */
12114 flip_op
= (kind
== LT_EXPR
|| kind
== LE_EXPR
) ? DW_OP_gt
: DW_OP_lt
;
12115 tmp
= new_loc_descr (flip_op
, 0, 0);
12116 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12117 bra_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
12118 add_loc_descr (&ret
, tmp
);
12120 /* This dummy operation is necessary to make the two branches join. */
12121 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
12122 jmp_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12123 jmp_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
12124 add_loc_descr (&ret
, tmp
);
12129 /* Likewise, but takes the location description lists (might be destructive on
12130 them). Return NULL if either is NULL or if concatenation fails. */
12132 static dw_loc_list_ref
12133 loc_list_from_uint_comparison (dw_loc_list_ref left
, dw_loc_list_ref right
,
12134 enum tree_code kind
)
12136 if (left
== NULL
|| right
== NULL
)
12139 add_loc_list (&left
, right
);
12143 add_loc_descr_to_each (left
, uint_comparison_loc_list (kind
));
12147 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
12148 without actually allocating it. */
12150 static unsigned long
12151 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
12153 return size_of_int_loc_descriptor (i
>> shift
)
12154 + size_of_int_loc_descriptor (shift
)
12158 /* Return size_of_locs (int_loc_descriptor (i)) without
12159 actually allocating it. */
12161 static unsigned long
12162 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
12171 else if (i
<= 0xff)
12173 else if (i
<= 0xffff)
12177 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
12178 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
12179 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12181 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
12182 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
12183 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12185 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
12187 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
12188 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
12189 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
12190 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12192 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
12193 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
12194 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12196 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
12197 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
12199 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
12208 else if (i
>= -0x8000)
12210 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
12212 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
12214 s
= size_of_int_loc_descriptor (-i
) + 1;
12222 unsigned long r
= 1 + size_of_sleb128 (i
);
12223 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
12225 s
= size_of_int_loc_descriptor (-i
) + 1;
12234 /* Return loc description representing "address" of integer value.
12235 This can appear only as toplevel expression. */
12237 static dw_loc_descr_ref
12238 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
12241 dw_loc_descr_ref loc_result
= NULL
;
12243 if (!(dwarf_version
>= 4 || !dwarf_strict
))
12246 litsize
= size_of_int_loc_descriptor (i
);
12247 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
12248 is more compact. For DW_OP_stack_value we need:
12249 litsize + 1 (DW_OP_stack_value)
12250 and for DW_OP_implicit_value:
12251 1 (DW_OP_implicit_value) + 1 (length) + size. */
12252 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
12254 loc_result
= int_loc_descriptor (i
);
12255 add_loc_descr (&loc_result
,
12256 new_loc_descr (DW_OP_stack_value
, 0, 0));
12260 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12262 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12263 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
12267 /* Return a location descriptor that designates a base+offset location. */
12269 static dw_loc_descr_ref
12270 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
12271 enum var_init_status initialized
)
12273 unsigned int regno
;
12274 dw_loc_descr_ref result
;
12275 dw_fde_ref fde
= cfun
->fde
;
12277 /* We only use "frame base" when we're sure we're talking about the
12278 post-prologue local stack frame. We do this by *not* running
12279 register elimination until this point, and recognizing the special
12280 argument pointer and soft frame pointer rtx's. */
12281 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
12283 rtx elim
= (ira_use_lra_p
12284 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
12285 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
12289 if (GET_CODE (elim
) == PLUS
)
12291 offset
+= INTVAL (XEXP (elim
, 1));
12292 elim
= XEXP (elim
, 0);
12294 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
12295 && (elim
== hard_frame_pointer_rtx
12296 || elim
== stack_pointer_rtx
))
12297 || elim
== (frame_pointer_needed
12298 ? hard_frame_pointer_rtx
12299 : stack_pointer_rtx
));
12301 /* If drap register is used to align stack, use frame
12302 pointer + offset to access stack variables. If stack
12303 is aligned without drap, use stack pointer + offset to
12304 access stack variables. */
12305 if (crtl
->stack_realign_tried
12306 && reg
== frame_pointer_rtx
)
12309 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
12310 ? HARD_FRAME_POINTER_REGNUM
12312 return new_reg_loc_descr (base_reg
, offset
);
12315 gcc_assert (frame_pointer_fb_offset_valid
);
12316 offset
+= frame_pointer_fb_offset
;
12317 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
12321 regno
= REGNO (reg
);
12322 #ifdef LEAF_REG_REMAP
12323 if (crtl
->uses_only_leaf_regs
)
12325 int leaf_reg
= LEAF_REG_REMAP (regno
);
12326 if (leaf_reg
!= -1)
12327 regno
= (unsigned) leaf_reg
;
12330 regno
= DWARF_FRAME_REGNUM (regno
);
12332 if (!optimize
&& fde
12333 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
12335 /* Use cfa+offset to represent the location of arguments passed
12336 on the stack when drap is used to align stack.
12337 Only do this when not optimizing, for optimized code var-tracking
12338 is supposed to track where the arguments live and the register
12339 used as vdrap or drap in some spot might be used for something
12340 else in other part of the routine. */
12341 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
12345 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
12348 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
12350 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12351 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12356 /* Return true if this RTL expression describes a base+offset calculation. */
12359 is_based_loc (const_rtx rtl
)
12361 return (GET_CODE (rtl
) == PLUS
12362 && ((REG_P (XEXP (rtl
, 0))
12363 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
12364 && CONST_INT_P (XEXP (rtl
, 1)))));
12367 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
12370 static dw_loc_descr_ref
12371 tls_mem_loc_descriptor (rtx mem
)
12374 dw_loc_descr_ref loc_result
;
12376 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
12379 base
= get_base_address (MEM_EXPR (mem
));
12381 || TREE_CODE (base
) != VAR_DECL
12382 || !DECL_THREAD_LOCAL_P (base
))
12385 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
12386 if (loc_result
== NULL
)
12389 if (MEM_OFFSET (mem
))
12390 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
12395 /* Output debug info about reason why we failed to expand expression as dwarf
12399 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
12401 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
12403 fprintf (dump_file
, "Failed to expand as dwarf: ");
12405 print_generic_expr (dump_file
, expr
, dump_flags
);
12408 fprintf (dump_file
, "\n");
12409 print_rtl (dump_file
, rtl
);
12411 fprintf (dump_file
, "\nReason: %s\n", reason
);
12415 /* Helper function for const_ok_for_output. */
12418 const_ok_for_output_1 (rtx rtl
)
12420 if (GET_CODE (rtl
) == UNSPEC
)
12422 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
12423 we can't express it in the debug info. */
12424 /* Don't complain about TLS UNSPECs, those are just too hard to
12425 delegitimize. Note this could be a non-decl SYMBOL_REF such as
12426 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
12427 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
12429 && (XVECLEN (rtl
, 0) == 0
12430 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
12431 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
))
12432 inform (current_function_decl
12433 ? DECL_SOURCE_LOCATION (current_function_decl
)
12434 : UNKNOWN_LOCATION
,
12435 #if NUM_UNSPEC_VALUES > 0
12436 "non-delegitimized UNSPEC %s (%d) found in variable location",
12437 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
12438 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
12441 "non-delegitimized UNSPEC %d found in variable location",
12444 expansion_failed (NULL_TREE
, rtl
,
12445 "UNSPEC hasn't been delegitimized.\n");
12449 if (targetm
.const_not_ok_for_debug_p (rtl
))
12451 expansion_failed (NULL_TREE
, rtl
,
12452 "Expression rejected for debug by the backend.\n");
12456 /* FIXME: Refer to PR60655. It is possible for simplification
12457 of rtl expressions in var tracking to produce such expressions.
12458 We should really identify / validate expressions
12459 enclosed in CONST that can be handled by assemblers on various
12460 targets and only handle legitimate cases here. */
12461 if (GET_CODE (rtl
) != SYMBOL_REF
)
12463 if (GET_CODE (rtl
) == NOT
)
12468 if (CONSTANT_POOL_ADDRESS_P (rtl
))
12471 get_pool_constant_mark (rtl
, &marked
);
12472 /* If all references to this pool constant were optimized away,
12473 it was not output and thus we can't represent it. */
12476 expansion_failed (NULL_TREE
, rtl
,
12477 "Constant was removed from constant pool.\n");
12482 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12485 /* Avoid references to external symbols in debug info, on several targets
12486 the linker might even refuse to link when linking a shared library,
12487 and in many other cases the relocations for .debug_info/.debug_loc are
12488 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
12489 to be defined within the same shared library or executable are fine. */
12490 if (SYMBOL_REF_EXTERNAL_P (rtl
))
12492 tree decl
= SYMBOL_REF_DECL (rtl
);
12494 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
12496 expansion_failed (NULL_TREE
, rtl
,
12497 "Symbol not defined in current TU.\n");
12505 /* Return true if constant RTL can be emitted in DW_OP_addr or
12506 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
12507 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
12510 const_ok_for_output (rtx rtl
)
12512 if (GET_CODE (rtl
) == SYMBOL_REF
)
12513 return const_ok_for_output_1 (rtl
);
12515 if (GET_CODE (rtl
) == CONST
)
12517 subrtx_var_iterator::array_type array
;
12518 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
12519 if (!const_ok_for_output_1 (*iter
))
12527 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
12528 if possible, NULL otherwise. */
12531 base_type_for_mode (machine_mode mode
, bool unsignedp
)
12533 dw_die_ref type_die
;
12534 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
12538 switch (TREE_CODE (type
))
12546 type_die
= lookup_type_die (type
);
12548 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, false,
12550 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
12555 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
12556 type matching MODE, or, if MODE is narrower than or as wide as
12557 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
12560 static dw_loc_descr_ref
12561 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
12563 machine_mode outer_mode
= mode
;
12564 dw_die_ref type_die
;
12565 dw_loc_descr_ref cvt
;
12567 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12569 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
12572 type_die
= base_type_for_mode (outer_mode
, 1);
12573 if (type_die
== NULL
)
12575 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12576 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12577 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12578 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12579 add_loc_descr (&op
, cvt
);
12583 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
12585 static dw_loc_descr_ref
12586 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
12587 dw_loc_descr_ref op1
)
12589 dw_loc_descr_ref ret
= op0
;
12590 add_loc_descr (&ret
, op1
);
12591 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12592 if (STORE_FLAG_VALUE
!= 1)
12594 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
12595 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
12600 /* Return location descriptor for signed comparison OP RTL. */
12602 static dw_loc_descr_ref
12603 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
12604 machine_mode mem_mode
)
12606 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
12607 dw_loc_descr_ref op0
, op1
;
12610 if (op_mode
== VOIDmode
)
12611 op_mode
= GET_MODE (XEXP (rtl
, 1));
12612 if (op_mode
== VOIDmode
)
12616 && (GET_MODE_CLASS (op_mode
) != MODE_INT
12617 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
12620 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
12621 VAR_INIT_STATUS_INITIALIZED
);
12622 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
12623 VAR_INIT_STATUS_INITIALIZED
);
12625 if (op0
== NULL
|| op1
== NULL
)
12628 if (GET_MODE_CLASS (op_mode
) != MODE_INT
12629 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
12630 return compare_loc_descriptor (op
, op0
, op1
);
12632 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
12634 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
12635 dw_loc_descr_ref cvt
;
12637 if (type_die
== NULL
)
12639 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12640 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12641 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12642 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12643 add_loc_descr (&op0
, cvt
);
12644 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12645 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12646 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12647 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12648 add_loc_descr (&op1
, cvt
);
12649 return compare_loc_descriptor (op
, op0
, op1
);
12652 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
12653 /* For eq/ne, if the operands are known to be zero-extended,
12654 there is no need to do the fancy shifting up. */
12655 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
12657 dw_loc_descr_ref last0
, last1
;
12658 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
12660 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
12662 /* deref_size zero extends, and for constants we can check
12663 whether they are zero extended or not. */
12664 if (((last0
->dw_loc_opc
== DW_OP_deref_size
12665 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
12666 || (CONST_INT_P (XEXP (rtl
, 0))
12667 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
12668 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
12669 && ((last1
->dw_loc_opc
== DW_OP_deref_size
12670 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
12671 || (CONST_INT_P (XEXP (rtl
, 1))
12672 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
12673 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
12674 return compare_loc_descriptor (op
, op0
, op1
);
12676 /* EQ/NE comparison against constant in narrower type than
12677 DWARF2_ADDR_SIZE can be performed either as
12678 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
12681 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
12682 DW_OP_{eq,ne}. Pick whatever is shorter. */
12683 if (CONST_INT_P (XEXP (rtl
, 1))
12684 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
12685 && (size_of_int_loc_descriptor (shift
) + 1
12686 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
12687 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
12688 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
12689 & GET_MODE_MASK (op_mode
))))
12691 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
12692 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12693 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
12694 & GET_MODE_MASK (op_mode
));
12695 return compare_loc_descriptor (op
, op0
, op1
);
12698 add_loc_descr (&op0
, int_loc_descriptor (shift
));
12699 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
12700 if (CONST_INT_P (XEXP (rtl
, 1)))
12701 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
12704 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12705 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12707 return compare_loc_descriptor (op
, op0
, op1
);
12710 /* Return location descriptor for unsigned comparison OP RTL. */
12712 static dw_loc_descr_ref
12713 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
12714 machine_mode mem_mode
)
12716 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
12717 dw_loc_descr_ref op0
, op1
;
12719 if (op_mode
== VOIDmode
)
12720 op_mode
= GET_MODE (XEXP (rtl
, 1));
12721 if (op_mode
== VOIDmode
)
12723 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
12726 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
12729 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
12730 VAR_INIT_STATUS_INITIALIZED
);
12731 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
12732 VAR_INIT_STATUS_INITIALIZED
);
12734 if (op0
== NULL
|| op1
== NULL
)
12737 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
12739 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
12740 dw_loc_descr_ref last0
, last1
;
12741 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
12743 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
12745 if (CONST_INT_P (XEXP (rtl
, 0)))
12746 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
12747 /* deref_size zero extends, so no need to mask it again. */
12748 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
12749 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12751 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12752 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12754 if (CONST_INT_P (XEXP (rtl
, 1)))
12755 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
12756 /* deref_size zero extends, so no need to mask it again. */
12757 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
12758 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12760 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12761 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12764 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
12766 HOST_WIDE_INT bias
= 1;
12767 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12768 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12769 if (CONST_INT_P (XEXP (rtl
, 1)))
12770 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
12771 + INTVAL (XEXP (rtl
, 1)));
12773 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
12776 return compare_loc_descriptor (op
, op0
, op1
);
12779 /* Return location descriptor for {U,S}{MIN,MAX}. */
12781 static dw_loc_descr_ref
12782 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
12783 machine_mode mem_mode
)
12785 enum dwarf_location_atom op
;
12786 dw_loc_descr_ref op0
, op1
, ret
;
12787 dw_loc_descr_ref bra_node
, drop_node
;
12790 && (GET_MODE_CLASS (mode
) != MODE_INT
12791 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
12794 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12795 VAR_INIT_STATUS_INITIALIZED
);
12796 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12797 VAR_INIT_STATUS_INITIALIZED
);
12799 if (op0
== NULL
|| op1
== NULL
)
12802 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
12803 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
12804 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
12805 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
12807 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12809 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
12810 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12811 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12812 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12813 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12815 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12817 HOST_WIDE_INT bias
= 1;
12818 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12819 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12820 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12823 else if (GET_MODE_CLASS (mode
) == MODE_INT
12824 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12826 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
12827 add_loc_descr (&op0
, int_loc_descriptor (shift
));
12828 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
12829 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12830 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12832 else if (GET_MODE_CLASS (mode
) == MODE_INT
12833 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12835 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
12836 dw_loc_descr_ref cvt
;
12837 if (type_die
== NULL
)
12839 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12840 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12841 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12842 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12843 add_loc_descr (&op0
, cvt
);
12844 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12845 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12846 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12847 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12848 add_loc_descr (&op1
, cvt
);
12851 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
12856 add_loc_descr (&ret
, op1
);
12857 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12858 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12859 add_loc_descr (&ret
, bra_node
);
12860 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12861 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12862 add_loc_descr (&ret
, drop_node
);
12863 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12864 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12865 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
12866 && GET_MODE_CLASS (mode
) == MODE_INT
12867 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12868 ret
= convert_descriptor_to_mode (mode
, ret
);
12872 /* Helper function for mem_loc_descriptor. Perform OP binary op,
12873 but after converting arguments to type_die, afterwards
12874 convert back to unsigned. */
12876 static dw_loc_descr_ref
12877 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
12878 machine_mode mode
, machine_mode mem_mode
)
12880 dw_loc_descr_ref cvt
, op0
, op1
;
12882 if (type_die
== NULL
)
12884 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12885 VAR_INIT_STATUS_INITIALIZED
);
12886 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12887 VAR_INIT_STATUS_INITIALIZED
);
12888 if (op0
== NULL
|| op1
== NULL
)
12890 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12891 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12892 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12893 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12894 add_loc_descr (&op0
, cvt
);
12895 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12896 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12897 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12898 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12899 add_loc_descr (&op1
, cvt
);
12900 add_loc_descr (&op0
, op1
);
12901 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
12902 return convert_descriptor_to_mode (mode
, op0
);
12905 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
12906 const0 is DW_OP_lit0 or corresponding typed constant,
12907 const1 is DW_OP_lit1 or corresponding typed constant
12908 and constMSB is constant with just the MSB bit set
12910 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12911 L1: const0 DW_OP_swap
12912 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
12913 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12918 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12919 L1: const0 DW_OP_swap
12920 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12921 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12926 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
12927 L1: const1 DW_OP_swap
12928 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12929 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12933 static dw_loc_descr_ref
12934 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
12935 machine_mode mem_mode
)
12937 dw_loc_descr_ref op0
, ret
, tmp
;
12938 HOST_WIDE_INT valv
;
12939 dw_loc_descr_ref l1jump
, l1label
;
12940 dw_loc_descr_ref l2jump
, l2label
;
12941 dw_loc_descr_ref l3jump
, l3label
;
12942 dw_loc_descr_ref l4jump
, l4label
;
12945 if (GET_MODE_CLASS (mode
) != MODE_INT
12946 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12949 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12950 VAR_INIT_STATUS_INITIALIZED
);
12954 if (GET_CODE (rtl
) == CLZ
)
12956 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12957 valv
= GET_MODE_BITSIZE (mode
);
12959 else if (GET_CODE (rtl
) == FFS
)
12961 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12962 valv
= GET_MODE_BITSIZE (mode
);
12963 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12964 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12965 add_loc_descr (&ret
, l1jump
);
12966 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12967 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
12968 VAR_INIT_STATUS_INITIALIZED
);
12971 add_loc_descr (&ret
, tmp
);
12972 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12973 add_loc_descr (&ret
, l4jump
);
12974 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
12975 ? const1_rtx
: const0_rtx
,
12977 VAR_INIT_STATUS_INITIALIZED
);
12978 if (l1label
== NULL
)
12980 add_loc_descr (&ret
, l1label
);
12981 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12982 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
12983 add_loc_descr (&ret
, l2label
);
12984 if (GET_CODE (rtl
) != CLZ
)
12986 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
12987 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
12988 << (GET_MODE_BITSIZE (mode
) - 1));
12990 msb
= immed_wide_int_const
12991 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
12992 GET_MODE_PRECISION (mode
)), mode
);
12993 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
12994 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12995 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
12996 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
12998 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
12999 VAR_INIT_STATUS_INITIALIZED
);
13002 add_loc_descr (&ret
, tmp
);
13003 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
13004 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
13005 add_loc_descr (&ret
, l3jump
);
13006 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
13007 VAR_INIT_STATUS_INITIALIZED
);
13010 add_loc_descr (&ret
, tmp
);
13011 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
13012 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
13013 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13014 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
13015 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13016 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
13017 add_loc_descr (&ret
, l2jump
);
13018 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
13019 add_loc_descr (&ret
, l3label
);
13020 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
13021 add_loc_descr (&ret
, l4label
);
13022 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13023 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
13024 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13025 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
13026 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13027 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
13028 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13029 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
13033 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
13034 const1 is DW_OP_lit1 or corresponding typed constant):
13036 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
13037 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
13041 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
13042 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
13045 static dw_loc_descr_ref
13046 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
13047 machine_mode mem_mode
)
13049 dw_loc_descr_ref op0
, ret
, tmp
;
13050 dw_loc_descr_ref l1jump
, l1label
;
13051 dw_loc_descr_ref l2jump
, l2label
;
13053 if (GET_MODE_CLASS (mode
) != MODE_INT
13054 || GET_MODE (XEXP (rtl
, 0)) != mode
)
13057 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13058 VAR_INIT_STATUS_INITIALIZED
);
13062 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
13063 VAR_INIT_STATUS_INITIALIZED
);
13066 add_loc_descr (&ret
, tmp
);
13067 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13068 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
13069 add_loc_descr (&ret
, l1label
);
13070 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
13071 add_loc_descr (&ret
, l2jump
);
13072 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
13073 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
13074 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
13075 VAR_INIT_STATUS_INITIALIZED
);
13078 add_loc_descr (&ret
, tmp
);
13079 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
13080 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
13081 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
13082 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13083 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
13084 VAR_INIT_STATUS_INITIALIZED
);
13085 add_loc_descr (&ret
, tmp
);
13086 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
13087 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
13088 add_loc_descr (&ret
, l1jump
);
13089 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
13090 add_loc_descr (&ret
, l2label
);
13091 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13092 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
13093 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13094 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
13098 /* BSWAP (constS is initial shift count, either 56 or 24):
13100 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
13101 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
13102 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
13103 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
13104 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
13106 static dw_loc_descr_ref
13107 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
13108 machine_mode mem_mode
)
13110 dw_loc_descr_ref op0
, ret
, tmp
;
13111 dw_loc_descr_ref l1jump
, l1label
;
13112 dw_loc_descr_ref l2jump
, l2label
;
13114 if (GET_MODE_CLASS (mode
) != MODE_INT
13115 || BITS_PER_UNIT
!= 8
13116 || (GET_MODE_BITSIZE (mode
) != 32
13117 && GET_MODE_BITSIZE (mode
) != 64))
13120 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13121 VAR_INIT_STATUS_INITIALIZED
);
13126 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
13128 VAR_INIT_STATUS_INITIALIZED
);
13131 add_loc_descr (&ret
, tmp
);
13132 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
13133 VAR_INIT_STATUS_INITIALIZED
);
13136 add_loc_descr (&ret
, tmp
);
13137 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
13138 add_loc_descr (&ret
, l1label
);
13139 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
13141 VAR_INIT_STATUS_INITIALIZED
);
13142 add_loc_descr (&ret
, tmp
);
13143 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
13144 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
13145 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
13146 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
13147 VAR_INIT_STATUS_INITIALIZED
);
13150 add_loc_descr (&ret
, tmp
);
13151 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
13152 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
13153 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13154 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
13155 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13156 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
13157 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
13158 VAR_INIT_STATUS_INITIALIZED
);
13159 add_loc_descr (&ret
, tmp
);
13160 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
13161 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
13162 add_loc_descr (&ret
, l2jump
);
13163 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
13164 VAR_INIT_STATUS_INITIALIZED
);
13165 add_loc_descr (&ret
, tmp
);
13166 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
13167 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13168 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
13169 add_loc_descr (&ret
, l1jump
);
13170 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
13171 add_loc_descr (&ret
, l2label
);
13172 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13173 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
13174 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13175 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
13176 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13177 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
13181 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
13182 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
13183 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
13184 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
13186 ROTATERT is similar:
13187 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
13188 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
13189 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
13191 static dw_loc_descr_ref
13192 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
13193 machine_mode mem_mode
)
13195 rtx rtlop1
= XEXP (rtl
, 1);
13196 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
13199 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13202 if (GET_MODE (rtlop1
) != VOIDmode
13203 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
13204 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
13205 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13206 VAR_INIT_STATUS_INITIALIZED
);
13207 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
13208 VAR_INIT_STATUS_INITIALIZED
);
13209 if (op0
== NULL
|| op1
== NULL
)
13211 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
13212 for (i
= 0; i
< 2; i
++)
13214 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
13215 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
13217 VAR_INIT_STATUS_INITIALIZED
);
13218 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
13219 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
13221 : HOST_BITS_PER_WIDE_INT
== 64
13222 ? DW_OP_const8u
: DW_OP_constu
,
13223 GET_MODE_MASK (mode
), 0);
13226 if (mask
[i
] == NULL
)
13228 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
13231 add_loc_descr (&ret
, op1
);
13232 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13233 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
13234 if (GET_CODE (rtl
) == ROTATERT
)
13236 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13237 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
13238 GET_MODE_BITSIZE (mode
), 0));
13240 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
13241 if (mask
[0] != NULL
)
13242 add_loc_descr (&ret
, mask
[0]);
13243 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
13244 if (mask
[1] != NULL
)
13246 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13247 add_loc_descr (&ret
, mask
[1]);
13248 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
13250 if (GET_CODE (rtl
) == ROTATE
)
13252 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
13253 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
13254 GET_MODE_BITSIZE (mode
), 0));
13256 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
13257 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
13261 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
13262 for DEBUG_PARAMETER_REF RTL. */
13264 static dw_loc_descr_ref
13265 parameter_ref_descriptor (rtx rtl
)
13267 dw_loc_descr_ref ret
;
13272 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
13273 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
13274 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
13277 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13278 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13279 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13283 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13284 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
13289 /* The following routine converts the RTL for a variable or parameter
13290 (resident in memory) into an equivalent Dwarf representation of a
13291 mechanism for getting the address of that same variable onto the top of a
13292 hypothetical "address evaluation" stack.
13294 When creating memory location descriptors, we are effectively transforming
13295 the RTL for a memory-resident object into its Dwarf postfix expression
13296 equivalent. This routine recursively descends an RTL tree, turning
13297 it into Dwarf postfix code as it goes.
13299 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
13301 MEM_MODE is the mode of the memory reference, needed to handle some
13302 autoincrement addressing modes.
13304 Return 0 if we can't represent the location. */
13307 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
13308 machine_mode mem_mode
,
13309 enum var_init_status initialized
)
13311 dw_loc_descr_ref mem_loc_result
= NULL
;
13312 enum dwarf_location_atom op
;
13313 dw_loc_descr_ref op0
, op1
;
13314 rtx inner
= NULL_RTX
;
13316 if (mode
== VOIDmode
)
13317 mode
= GET_MODE (rtl
);
13319 /* Note that for a dynamically sized array, the location we will generate a
13320 description of here will be the lowest numbered location which is
13321 actually within the array. That's *not* necessarily the same as the
13322 zeroth element of the array. */
13324 rtl
= targetm
.delegitimize_address (rtl
);
13326 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
13329 switch (GET_CODE (rtl
))
13334 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
13337 /* The case of a subreg may arise when we have a local (register)
13338 variable or a formal (register) parameter which doesn't quite fill
13339 up an entire register. For now, just assume that it is
13340 legitimate to make the Dwarf info refer to the whole register which
13341 contains the given subreg. */
13342 if (!subreg_lowpart_p (rtl
))
13344 inner
= SUBREG_REG (rtl
);
13346 if (inner
== NULL_RTX
)
13347 inner
= XEXP (rtl
, 0);
13348 if (GET_MODE_CLASS (mode
) == MODE_INT
13349 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
13350 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13351 #ifdef POINTERS_EXTEND_UNSIGNED
13352 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
13355 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
13357 mem_loc_result
= mem_loc_descriptor (inner
,
13359 mem_mode
, initialized
);
13364 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
13366 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
13367 && (GET_MODE_CLASS (mode
) != MODE_INT
13368 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
13372 dw_die_ref type_die
;
13373 dw_loc_descr_ref cvt
;
13375 mem_loc_result
= mem_loc_descriptor (inner
,
13377 mem_mode
, initialized
);
13378 if (mem_loc_result
== NULL
)
13380 type_die
= base_type_for_mode (mode
,
13381 GET_MODE_CLASS (mode
) == MODE_INT
);
13382 if (type_die
== NULL
)
13384 mem_loc_result
= NULL
;
13387 if (GET_MODE_SIZE (mode
)
13388 != GET_MODE_SIZE (GET_MODE (inner
)))
13389 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13391 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
13392 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13393 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13394 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13395 add_loc_descr (&mem_loc_result
, cvt
);
13396 if (GET_MODE_CLASS (mode
) == MODE_INT
13397 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13399 /* Convert it to untyped afterwards. */
13400 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13401 add_loc_descr (&mem_loc_result
, cvt
);
13407 if (GET_MODE_CLASS (mode
) != MODE_INT
13408 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
13409 && rtl
!= arg_pointer_rtx
13410 && rtl
!= frame_pointer_rtx
13411 #ifdef POINTERS_EXTEND_UNSIGNED
13412 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
13416 dw_die_ref type_die
;
13417 unsigned int dbx_regnum
;
13421 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
13423 type_die
= base_type_for_mode (mode
,
13424 GET_MODE_CLASS (mode
) == MODE_INT
);
13425 if (type_die
== NULL
)
13428 dbx_regnum
= dbx_reg_number (rtl
);
13429 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
13431 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
13433 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
13434 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
13435 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
13438 /* Whenever a register number forms a part of the description of the
13439 method for calculating the (dynamic) address of a memory resident
13440 object, DWARF rules require the register number be referred to as
13441 a "base register". This distinction is not based in any way upon
13442 what category of register the hardware believes the given register
13443 belongs to. This is strictly DWARF terminology we're dealing with
13444 here. Note that in cases where the location of a memory-resident
13445 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
13446 OP_CONST (0)) the actual DWARF location descriptor that we generate
13447 may just be OP_BASEREG (basereg). This may look deceptively like
13448 the object in question was allocated to a register (rather than in
13449 memory) so DWARF consumers need to be aware of the subtle
13450 distinction between OP_REG and OP_BASEREG. */
13451 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
13452 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
13453 else if (stack_realign_drap
13455 && crtl
->args
.internal_arg_pointer
== rtl
13456 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
13458 /* If RTL is internal_arg_pointer, which has been optimized
13459 out, use DRAP instead. */
13460 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
13461 VAR_INIT_STATUS_INITIALIZED
);
13467 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13469 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13470 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13473 else if (GET_CODE (rtl
) == ZERO_EXTEND
13474 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13475 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13476 < HOST_BITS_PER_WIDE_INT
13477 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
13478 to expand zero extend as two shifts instead of
13480 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
13482 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
13483 mem_loc_result
= op0
;
13484 add_loc_descr (&mem_loc_result
,
13485 int_loc_descriptor (GET_MODE_MASK (imode
)));
13486 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
13488 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13490 int shift
= DWARF2_ADDR_SIZE
13491 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
13492 shift
*= BITS_PER_UNIT
;
13493 if (GET_CODE (rtl
) == SIGN_EXTEND
)
13497 mem_loc_result
= op0
;
13498 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13499 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13500 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
13501 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13503 else if (!dwarf_strict
)
13505 dw_die_ref type_die1
, type_die2
;
13506 dw_loc_descr_ref cvt
;
13508 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
13509 GET_CODE (rtl
) == ZERO_EXTEND
);
13510 if (type_die1
== NULL
)
13512 type_die2
= base_type_for_mode (mode
, 1);
13513 if (type_die2
== NULL
)
13515 mem_loc_result
= op0
;
13516 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13517 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13518 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
13519 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13520 add_loc_descr (&mem_loc_result
, cvt
);
13521 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13522 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13523 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
13524 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13525 add_loc_descr (&mem_loc_result
, cvt
);
13531 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13532 if (new_rtl
!= rtl
)
13534 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
13536 if (mem_loc_result
!= NULL
)
13537 return mem_loc_result
;
13540 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
13541 get_address_mode (rtl
), mode
,
13542 VAR_INIT_STATUS_INITIALIZED
);
13543 if (mem_loc_result
== NULL
)
13544 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
13545 if (mem_loc_result
!= NULL
)
13547 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
13548 || GET_MODE_CLASS (mode
) != MODE_INT
)
13550 dw_die_ref type_die
;
13551 dw_loc_descr_ref deref
;
13556 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
13557 if (type_die
== NULL
)
13559 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
13560 GET_MODE_SIZE (mode
), 0);
13561 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
13562 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
13563 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
13564 add_loc_descr (&mem_loc_result
, deref
);
13566 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
13567 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
13569 add_loc_descr (&mem_loc_result
,
13570 new_loc_descr (DW_OP_deref_size
,
13571 GET_MODE_SIZE (mode
), 0));
13576 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
13579 /* Some ports can transform a symbol ref into a label ref, because
13580 the symbol ref is too far away and has to be dumped into a constant
13584 if ((GET_MODE_CLASS (mode
) != MODE_INT
13585 && GET_MODE_CLASS (mode
) != MODE_PARTIAL_INT
)
13586 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
13587 #ifdef POINTERS_EXTEND_UNSIGNED
13588 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
13592 if (GET_CODE (rtl
) == SYMBOL_REF
13593 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
13595 dw_loc_descr_ref temp
;
13597 /* If this is not defined, we have no way to emit the data. */
13598 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
13601 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
13603 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
13604 add_loc_descr (&mem_loc_result
, temp
);
13609 if (!const_ok_for_output (rtl
))
13611 if (GET_CODE (rtl
) == CONST
)
13612 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13618 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13619 vec_safe_push (used_rtx_array
, rtl
);
13625 case DEBUG_IMPLICIT_PTR
:
13626 expansion_failed (NULL_TREE
, rtl
,
13627 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
13633 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
13635 if (GET_MODE_CLASS (mode
) != MODE_INT
13636 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
13637 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
13638 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13641 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
13642 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
13644 op0
= one_reg_loc_descriptor (dbx_regnum
,
13645 VAR_INIT_STATUS_INITIALIZED
);
13648 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
13649 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
13651 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
13652 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13653 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
13657 gcc_unreachable ();
13660 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
13661 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13662 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
13665 case DEBUG_PARAMETER_REF
:
13666 mem_loc_result
= parameter_ref_descriptor (rtl
);
13670 /* Extract the PLUS expression nested inside and fall into
13671 PLUS code below. */
13672 rtl
= XEXP (rtl
, 1);
13677 /* Turn these into a PLUS expression and fall into the PLUS code
13679 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
13680 gen_int_mode (GET_CODE (rtl
) == PRE_INC
13681 ? GET_MODE_UNIT_SIZE (mem_mode
)
13682 : -GET_MODE_UNIT_SIZE (mem_mode
),
13685 /* ... fall through ... */
13689 if (is_based_loc (rtl
)
13690 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13691 || XEXP (rtl
, 0) == arg_pointer_rtx
13692 || XEXP (rtl
, 0) == frame_pointer_rtx
)
13693 && GET_MODE_CLASS (mode
) == MODE_INT
)
13694 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
13695 INTVAL (XEXP (rtl
, 1)),
13696 VAR_INIT_STATUS_INITIALIZED
);
13699 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13700 VAR_INIT_STATUS_INITIALIZED
);
13701 if (mem_loc_result
== 0)
13704 if (CONST_INT_P (XEXP (rtl
, 1))
13705 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
13706 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
13709 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13710 VAR_INIT_STATUS_INITIALIZED
);
13713 add_loc_descr (&mem_loc_result
, op1
);
13714 add_loc_descr (&mem_loc_result
,
13715 new_loc_descr (DW_OP_plus
, 0, 0));
13720 /* If a pseudo-reg is optimized away, it is possible for it to
13721 be replaced with a MEM containing a multiply or shift. */
13732 && GET_MODE_CLASS (mode
) == MODE_INT
13733 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
13735 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13736 base_type_for_mode (mode
, 0),
13760 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13762 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13763 VAR_INIT_STATUS_INITIALIZED
);
13765 rtx rtlop1
= XEXP (rtl
, 1);
13766 if (GET_MODE (rtlop1
) != VOIDmode
13767 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
13768 < GET_MODE_BITSIZE (mode
))
13769 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
13770 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
13771 VAR_INIT_STATUS_INITIALIZED
);
13774 if (op0
== 0 || op1
== 0)
13777 mem_loc_result
= op0
;
13778 add_loc_descr (&mem_loc_result
, op1
);
13779 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13795 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13796 VAR_INIT_STATUS_INITIALIZED
);
13797 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13798 VAR_INIT_STATUS_INITIALIZED
);
13800 if (op0
== 0 || op1
== 0)
13803 mem_loc_result
= op0
;
13804 add_loc_descr (&mem_loc_result
, op1
);
13805 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13809 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
13811 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
13812 base_type_for_mode (mode
, 0),
13817 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13818 VAR_INIT_STATUS_INITIALIZED
);
13819 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13820 VAR_INIT_STATUS_INITIALIZED
);
13822 if (op0
== 0 || op1
== 0)
13825 mem_loc_result
= op0
;
13826 add_loc_descr (&mem_loc_result
, op1
);
13827 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13828 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13829 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
13830 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13831 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
13835 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
13837 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
13842 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13843 base_type_for_mode (mode
, 1),
13861 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13862 VAR_INIT_STATUS_INITIALIZED
);
13867 mem_loc_result
= op0
;
13868 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13872 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13873 #ifdef POINTERS_EXTEND_UNSIGNED
13875 && mem_mode
!= VOIDmode
13876 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
13880 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13884 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
13885 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
13887 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
13888 machine_mode amode
;
13889 if (type_die
== NULL
)
13891 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
13893 if (INTVAL (rtl
) >= 0
13894 && amode
!= BLKmode
13895 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
13896 /* const DW_OP_GNU_convert <XXX> vs.
13897 DW_OP_GNU_const_type <XXX, 1, const>. */
13898 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
13899 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
13901 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13902 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13903 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13904 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13905 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13906 add_loc_descr (&mem_loc_result
, op0
);
13907 return mem_loc_result
;
13909 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
13911 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13912 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13913 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13914 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
13915 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13918 mem_loc_result
->dw_loc_oprnd2
.val_class
13919 = dw_val_class_const_double
;
13920 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13921 = double_int::from_shwi (INTVAL (rtl
));
13929 dw_die_ref type_die
;
13931 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
13932 CONST_DOUBLE rtx could represent either a large integer
13933 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
13934 the value is always a floating point constant.
13936 When it is an integer, a CONST_DOUBLE is used whenever
13937 the constant requires 2 HWIs to be adequately represented.
13938 We output CONST_DOUBLEs as blocks. */
13939 if (mode
== VOIDmode
13940 || (GET_MODE (rtl
) == VOIDmode
13941 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
13943 type_die
= base_type_for_mode (mode
,
13944 GET_MODE_CLASS (mode
) == MODE_INT
);
13945 if (type_die
== NULL
)
13947 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13948 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13949 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13950 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13951 #if TARGET_SUPPORTS_WIDE_INT == 0
13952 if (!SCALAR_FLOAT_MODE_P (mode
))
13954 mem_loc_result
->dw_loc_oprnd2
.val_class
13955 = dw_val_class_const_double
;
13956 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13957 = rtx_to_double_int (rtl
);
13962 unsigned int length
= GET_MODE_SIZE (mode
);
13963 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13965 insert_float (rtl
, array
);
13966 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13967 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13968 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13969 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13974 case CONST_WIDE_INT
:
13977 dw_die_ref type_die
;
13979 type_die
= base_type_for_mode (mode
,
13980 GET_MODE_CLASS (mode
) == MODE_INT
);
13981 if (type_die
== NULL
)
13983 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13984 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13985 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13986 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13987 mem_loc_result
->dw_loc_oprnd2
.val_class
13988 = dw_val_class_wide_int
;
13989 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13990 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13995 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
13999 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
14003 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
14007 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
14011 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
14015 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
14019 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
14023 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
14027 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
14031 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
14036 if (GET_MODE_CLASS (mode
) != MODE_INT
)
14041 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
14046 if (CONST_INT_P (XEXP (rtl
, 1))
14047 && CONST_INT_P (XEXP (rtl
, 2))
14048 && ((unsigned) INTVAL (XEXP (rtl
, 1))
14049 + (unsigned) INTVAL (XEXP (rtl
, 2))
14050 <= GET_MODE_BITSIZE (mode
))
14051 && GET_MODE_CLASS (mode
) == MODE_INT
14052 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
14053 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
14056 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
14057 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14060 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
14064 mem_loc_result
= op0
;
14065 size
= INTVAL (XEXP (rtl
, 1));
14066 shift
= INTVAL (XEXP (rtl
, 2));
14067 if (BITS_BIG_ENDIAN
)
14068 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
14070 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
14072 add_loc_descr (&mem_loc_result
,
14073 int_loc_descriptor (DWARF2_ADDR_SIZE
14075 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
14077 if (size
!= (int) DWARF2_ADDR_SIZE
)
14079 add_loc_descr (&mem_loc_result
,
14080 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
14081 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
14088 dw_loc_descr_ref op2
, bra_node
, drop_node
;
14089 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
14090 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
14091 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
14092 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14093 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
14094 VAR_INIT_STATUS_INITIALIZED
);
14095 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
14096 VAR_INIT_STATUS_INITIALIZED
);
14097 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
14100 mem_loc_result
= op1
;
14101 add_loc_descr (&mem_loc_result
, op2
);
14102 add_loc_descr (&mem_loc_result
, op0
);
14103 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14104 add_loc_descr (&mem_loc_result
, bra_node
);
14105 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
14106 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
14107 add_loc_descr (&mem_loc_result
, drop_node
);
14108 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14109 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
14114 case FLOAT_TRUNCATE
:
14116 case UNSIGNED_FLOAT
:
14121 dw_die_ref type_die
;
14122 dw_loc_descr_ref cvt
;
14124 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
14125 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
14128 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
14129 && (GET_CODE (rtl
) == FLOAT
14130 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
14131 <= DWARF2_ADDR_SIZE
))
14133 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
14134 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
14135 if (type_die
== NULL
)
14137 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
14138 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14139 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14140 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14141 add_loc_descr (&op0
, cvt
);
14143 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
14144 if (type_die
== NULL
)
14146 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
14147 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14148 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
14149 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14150 add_loc_descr (&op0
, cvt
);
14151 if (GET_MODE_CLASS (mode
) == MODE_INT
14152 && (GET_CODE (rtl
) == FIX
14153 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
14155 op0
= convert_descriptor_to_mode (mode
, op0
);
14159 mem_loc_result
= op0
;
14166 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
14171 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
14175 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
14180 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
14184 /* In theory, we could implement the above. */
14185 /* DWARF cannot represent the unsigned compare operations
14210 case FRACT_CONVERT
:
14211 case UNSIGNED_FRACT_CONVERT
:
14213 case UNSIGNED_SAT_FRACT
:
14219 case VEC_DUPLICATE
:
14223 case STRICT_LOW_PART
:
14228 /* If delegitimize_address couldn't do anything with the UNSPEC, we
14229 can't express it in the debug info. This can happen e.g. with some
14234 resolve_one_addr (&rtl
);
14240 print_rtl (stderr
, rtl
);
14241 gcc_unreachable ();
14246 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14247 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14249 return mem_loc_result
;
14252 /* Return a descriptor that describes the concatenation of two locations.
14253 This is typically a complex variable. */
14255 static dw_loc_descr_ref
14256 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
14258 dw_loc_descr_ref cc_loc_result
= NULL
;
14259 dw_loc_descr_ref x0_ref
14260 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14261 dw_loc_descr_ref x1_ref
14262 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14264 if (x0_ref
== 0 || x1_ref
== 0)
14267 cc_loc_result
= x0_ref
;
14268 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
14270 add_loc_descr (&cc_loc_result
, x1_ref
);
14271 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
14273 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14274 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14276 return cc_loc_result
;
14279 /* Return a descriptor that describes the concatenation of N
14282 static dw_loc_descr_ref
14283 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
14286 dw_loc_descr_ref cc_loc_result
= NULL
;
14287 unsigned int n
= XVECLEN (concatn
, 0);
14289 for (i
= 0; i
< n
; ++i
)
14291 dw_loc_descr_ref ref
;
14292 rtx x
= XVECEXP (concatn
, 0, i
);
14294 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
14298 add_loc_descr (&cc_loc_result
, ref
);
14299 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
14302 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
14303 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
14305 return cc_loc_result
;
14308 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
14309 for DEBUG_IMPLICIT_PTR RTL. */
14311 static dw_loc_descr_ref
14312 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
14314 dw_loc_descr_ref ret
;
14319 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
14320 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
14321 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
14322 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
14323 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
14324 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
14327 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
14328 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
14329 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
14333 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
14334 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
14339 /* Output a proper Dwarf location descriptor for a variable or parameter
14340 which is either allocated in a register or in a memory location. For a
14341 register, we just generate an OP_REG and the register number. For a
14342 memory location we provide a Dwarf postfix expression describing how to
14343 generate the (dynamic) address of the object onto the address stack.
14345 MODE is mode of the decl if this loc_descriptor is going to be used in
14346 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
14347 allowed, VOIDmode otherwise.
14349 If we don't know how to describe it, return 0. */
14351 static dw_loc_descr_ref
14352 loc_descriptor (rtx rtl
, machine_mode mode
,
14353 enum var_init_status initialized
)
14355 dw_loc_descr_ref loc_result
= NULL
;
14357 switch (GET_CODE (rtl
))
14360 /* The case of a subreg may arise when we have a local (register)
14361 variable or a formal (register) parameter which doesn't quite fill
14362 up an entire register. For now, just assume that it is
14363 legitimate to make the Dwarf info refer to the whole register which
14364 contains the given subreg. */
14365 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
14366 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
14367 GET_MODE (SUBREG_REG (rtl
)), initialized
);
14373 loc_result
= reg_loc_descriptor (rtl
, initialized
);
14377 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
14378 GET_MODE (rtl
), initialized
);
14379 if (loc_result
== NULL
)
14380 loc_result
= tls_mem_loc_descriptor (rtl
);
14381 if (loc_result
== NULL
)
14383 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
14384 if (new_rtl
!= rtl
)
14385 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
14390 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
14395 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
14400 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
14402 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
14403 if (GET_CODE (loc
) == EXPR_LIST
)
14404 loc
= XEXP (loc
, 0);
14405 loc_result
= loc_descriptor (loc
, mode
, initialized
);
14409 rtl
= XEXP (rtl
, 1);
14414 rtvec par_elems
= XVEC (rtl
, 0);
14415 int num_elem
= GET_NUM_ELEM (par_elems
);
14419 /* Create the first one, so we have something to add to. */
14420 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
14421 VOIDmode
, initialized
);
14422 if (loc_result
== NULL
)
14424 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
14425 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14426 for (i
= 1; i
< num_elem
; i
++)
14428 dw_loc_descr_ref temp
;
14430 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
14431 VOIDmode
, initialized
);
14434 add_loc_descr (&loc_result
, temp
);
14435 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
14436 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
14442 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
14443 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
14448 if (mode
== VOIDmode
)
14449 mode
= GET_MODE (rtl
);
14451 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14453 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14455 /* Note that a CONST_DOUBLE rtx could represent either an integer
14456 or a floating-point constant. A CONST_DOUBLE is used whenever
14457 the constant requires more than one word in order to be
14458 adequately represented. We output CONST_DOUBLEs as blocks. */
14459 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14460 GET_MODE_SIZE (mode
), 0);
14461 #if TARGET_SUPPORTS_WIDE_INT == 0
14462 if (!SCALAR_FLOAT_MODE_P (mode
))
14464 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
14465 loc_result
->dw_loc_oprnd2
.v
.val_double
14466 = rtx_to_double_int (rtl
);
14471 unsigned int length
= GET_MODE_SIZE (mode
);
14472 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
14474 insert_float (rtl
, array
);
14475 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14476 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
14477 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
14478 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14483 case CONST_WIDE_INT
:
14484 if (mode
== VOIDmode
)
14485 mode
= GET_MODE (rtl
);
14487 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14489 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14490 GET_MODE_SIZE (mode
), 0);
14491 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
14492 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
14493 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
14498 if (mode
== VOIDmode
)
14499 mode
= GET_MODE (rtl
);
14501 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
14503 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
14504 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14505 unsigned char *array
14506 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
14509 machine_mode imode
= GET_MODE_INNER (mode
);
14511 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
14512 switch (GET_MODE_CLASS (mode
))
14514 case MODE_VECTOR_INT
:
14515 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14517 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14518 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
14522 case MODE_VECTOR_FLOAT
:
14523 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14525 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14526 insert_float (elt
, p
);
14531 gcc_unreachable ();
14534 loc_result
= new_loc_descr (DW_OP_implicit_value
,
14535 length
* elt_size
, 0);
14536 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
14537 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
14538 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
14539 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
14544 if (mode
== VOIDmode
14545 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
14546 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
14547 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
14549 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
14554 if (!const_ok_for_output (rtl
))
14557 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
14558 && (dwarf_version
>= 4 || !dwarf_strict
))
14560 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14561 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14562 vec_safe_push (used_rtx_array
, rtl
);
14566 case DEBUG_IMPLICIT_PTR
:
14567 loc_result
= implicit_ptr_descriptor (rtl
, 0);
14571 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
14572 && CONST_INT_P (XEXP (rtl
, 1)))
14575 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
14581 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
14582 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
14583 && dwarf_version
>= 4)
14584 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
14586 /* Value expression. */
14587 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
14589 add_loc_descr (&loc_result
,
14590 new_loc_descr (DW_OP_stack_value
, 0, 0));
14598 /* We need to figure out what section we should use as the base for the
14599 address ranges where a given location is valid.
14600 1. If this particular DECL has a section associated with it, use that.
14601 2. If this function has a section associated with it, use that.
14602 3. Otherwise, use the text section.
14603 XXX: If you split a variable across multiple sections, we won't notice. */
14605 static const char *
14606 secname_for_decl (const_tree decl
)
14608 const char *secname
;
14610 if (VAR_OR_FUNCTION_DECL_P (decl
)
14611 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
14612 && DECL_SECTION_NAME (decl
))
14613 secname
= DECL_SECTION_NAME (decl
);
14614 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
14615 secname
= DECL_SECTION_NAME (current_function_decl
);
14616 else if (cfun
&& in_cold_section_p
)
14617 secname
= crtl
->subsections
.cold_section_label
;
14619 secname
= text_section_label
;
14624 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
14627 decl_by_reference_p (tree decl
)
14629 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
14630 || TREE_CODE (decl
) == VAR_DECL
)
14631 && DECL_BY_REFERENCE (decl
));
14634 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14637 static dw_loc_descr_ref
14638 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
14639 enum var_init_status initialized
)
14641 int have_address
= 0;
14642 dw_loc_descr_ref descr
;
14645 if (want_address
!= 2)
14647 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
14649 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14651 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14652 if (GET_CODE (varloc
) == EXPR_LIST
)
14653 varloc
= XEXP (varloc
, 0);
14654 mode
= GET_MODE (varloc
);
14655 if (MEM_P (varloc
))
14657 rtx addr
= XEXP (varloc
, 0);
14658 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
14659 mode
, initialized
);
14664 rtx x
= avoid_constant_pool_reference (varloc
);
14666 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
14671 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
14678 if (GET_CODE (varloc
) == VAR_LOCATION
)
14679 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
14681 mode
= DECL_MODE (loc
);
14682 descr
= loc_descriptor (varloc
, mode
, initialized
);
14689 if (want_address
== 2 && !have_address
14690 && (dwarf_version
>= 4 || !dwarf_strict
))
14692 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14694 expansion_failed (loc
, NULL_RTX
,
14695 "DWARF address size mismatch");
14698 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14701 /* Show if we can't fill the request for an address. */
14702 if (want_address
&& !have_address
)
14704 expansion_failed (loc
, NULL_RTX
,
14705 "Want address and only have value");
14709 /* If we've got an address and don't want one, dereference. */
14710 if (!want_address
&& have_address
)
14712 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14713 enum dwarf_location_atom op
;
14715 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14717 expansion_failed (loc
, NULL_RTX
,
14718 "DWARF address size mismatch");
14721 else if (size
== DWARF2_ADDR_SIZE
)
14724 op
= DW_OP_deref_size
;
14726 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
14732 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14733 if it is not possible. */
14735 static dw_loc_descr_ref
14736 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
14738 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
14739 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
14740 else if (dwarf_version
>= 3 || !dwarf_strict
)
14741 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
14746 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14747 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14749 static dw_loc_descr_ref
14750 dw_sra_loc_expr (tree decl
, rtx loc
)
14753 unsigned HOST_WIDE_INT padsize
= 0;
14754 dw_loc_descr_ref descr
, *descr_tail
;
14755 unsigned HOST_WIDE_INT decl_size
;
14757 enum var_init_status initialized
;
14759 if (DECL_SIZE (decl
) == NULL
14760 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
14763 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
14765 descr_tail
= &descr
;
14767 for (p
= loc
; p
; p
= XEXP (p
, 1))
14769 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
14770 rtx loc_note
= *decl_piece_varloc_ptr (p
);
14771 dw_loc_descr_ref cur_descr
;
14772 dw_loc_descr_ref
*tail
, last
= NULL
;
14773 unsigned HOST_WIDE_INT opsize
= 0;
14775 if (loc_note
== NULL_RTX
14776 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
14778 padsize
+= bitsize
;
14781 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
14782 varloc
= NOTE_VAR_LOCATION (loc_note
);
14783 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
14784 if (cur_descr
== NULL
)
14786 padsize
+= bitsize
;
14790 /* Check that cur_descr either doesn't use
14791 DW_OP_*piece operations, or their sum is equal
14792 to bitsize. Otherwise we can't embed it. */
14793 for (tail
= &cur_descr
; *tail
!= NULL
;
14794 tail
= &(*tail
)->dw_loc_next
)
14795 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
14797 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
14801 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
14803 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
14807 if (last
!= NULL
&& opsize
!= bitsize
)
14809 padsize
+= bitsize
;
14810 /* Discard the current piece of the descriptor and release any
14811 addr_table entries it uses. */
14812 remove_loc_list_addr_table_entries (cur_descr
);
14816 /* If there is a hole, add DW_OP_*piece after empty DWARF
14817 expression, which means that those bits are optimized out. */
14820 if (padsize
> decl_size
)
14822 remove_loc_list_addr_table_entries (cur_descr
);
14823 goto discard_descr
;
14825 decl_size
-= padsize
;
14826 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
14827 if (*descr_tail
== NULL
)
14829 remove_loc_list_addr_table_entries (cur_descr
);
14830 goto discard_descr
;
14832 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14835 *descr_tail
= cur_descr
;
14837 if (bitsize
> decl_size
)
14838 goto discard_descr
;
14839 decl_size
-= bitsize
;
14842 HOST_WIDE_INT offset
= 0;
14843 if (GET_CODE (varloc
) == VAR_LOCATION
14844 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14846 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14847 if (GET_CODE (varloc
) == EXPR_LIST
)
14848 varloc
= XEXP (varloc
, 0);
14852 if (GET_CODE (varloc
) == CONST
14853 || GET_CODE (varloc
) == SIGN_EXTEND
14854 || GET_CODE (varloc
) == ZERO_EXTEND
)
14855 varloc
= XEXP (varloc
, 0);
14856 else if (GET_CODE (varloc
) == SUBREG
)
14857 varloc
= SUBREG_REG (varloc
);
14862 /* DW_OP_bit_size offset should be zero for register
14863 or implicit location descriptions and empty location
14864 descriptions, but for memory addresses needs big endian
14866 if (MEM_P (varloc
))
14868 unsigned HOST_WIDE_INT memsize
14869 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
14870 if (memsize
!= bitsize
)
14872 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
14873 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
14874 goto discard_descr
;
14875 if (memsize
< bitsize
)
14876 goto discard_descr
;
14877 if (BITS_BIG_ENDIAN
)
14878 offset
= memsize
- bitsize
;
14882 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
14883 if (*descr_tail
== NULL
)
14884 goto discard_descr
;
14885 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14889 /* If there were any non-empty expressions, add padding till the end of
14891 if (descr
!= NULL
&& decl_size
!= 0)
14893 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
14894 if (*descr_tail
== NULL
)
14895 goto discard_descr
;
14900 /* Discard the descriptor and release any addr_table entries it uses. */
14901 remove_loc_list_addr_table_entries (descr
);
14905 /* Return the dwarf representation of the location list LOC_LIST of
14906 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14909 static dw_loc_list_ref
14910 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
14912 const char *endname
, *secname
;
14914 enum var_init_status initialized
;
14915 struct var_loc_node
*node
;
14916 dw_loc_descr_ref descr
;
14917 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
14918 dw_loc_list_ref list
= NULL
;
14919 dw_loc_list_ref
*listp
= &list
;
14921 /* Now that we know what section we are using for a base,
14922 actually construct the list of locations.
14923 The first location information is what is passed to the
14924 function that creates the location list, and the remaining
14925 locations just get added on to that list.
14926 Note that we only know the start address for a location
14927 (IE location changes), so to build the range, we use
14928 the range [current location start, next location start].
14929 This means we have to special case the last node, and generate
14930 a range of [last location start, end of function label]. */
14932 secname
= secname_for_decl (decl
);
14934 for (node
= loc_list
->first
; node
; node
= node
->next
)
14935 if (GET_CODE (node
->loc
) == EXPR_LIST
14936 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
14938 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14940 /* This requires DW_OP_{,bit_}piece, which is not usable
14941 inside DWARF expressions. */
14942 if (want_address
!= 2)
14944 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14950 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14951 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14952 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
14956 bool range_across_switch
= false;
14957 /* If section switch happens in between node->label
14958 and node->next->label (or end of function) and
14959 we can't emit it as a single entry list,
14960 emit two ranges, first one ending at the end
14961 of first partition and second one starting at the
14962 beginning of second partition. */
14963 if (node
== loc_list
->last_before_switch
14964 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
14965 && current_function_decl
)
14967 endname
= cfun
->fde
->dw_fde_end
;
14968 range_across_switch
= true;
14970 /* The variable has a location between NODE->LABEL and
14971 NODE->NEXT->LABEL. */
14972 else if (node
->next
)
14973 endname
= node
->next
->label
;
14974 /* If the variable has a location at the last label
14975 it keeps its location until the end of function. */
14976 else if (!current_function_decl
)
14977 endname
= text_end_label
;
14980 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
14981 current_function_funcdef_no
);
14982 endname
= ggc_strdup (label_id
);
14985 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
14986 if (TREE_CODE (decl
) == PARM_DECL
14987 && node
== loc_list
->first
14988 && NOTE_P (node
->loc
)
14989 && strcmp (node
->label
, endname
) == 0)
14990 (*listp
)->force
= true;
14991 listp
= &(*listp
)->dw_loc_next
;
14993 if (range_across_switch
)
14995 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14996 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14999 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
15000 varloc
= NOTE_VAR_LOCATION (node
->loc
);
15001 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
15004 gcc_assert (descr
);
15005 /* The variable has a location between NODE->LABEL and
15006 NODE->NEXT->LABEL. */
15008 endname
= node
->next
->label
;
15010 endname
= cfun
->fde
->dw_fde_second_end
;
15011 *listp
= new_loc_list (descr
,
15012 cfun
->fde
->dw_fde_second_begin
,
15014 listp
= &(*listp
)->dw_loc_next
;
15019 /* Try to avoid the overhead of a location list emitting a location
15020 expression instead, but only if we didn't have more than one
15021 location entry in the first place. If some entries were not
15022 representable, we don't want to pretend a single entry that was
15023 applies to the entire scope in which the variable is
15025 if (list
&& loc_list
->first
->next
)
15031 /* Return if the loc_list has only single element and thus can be represented
15032 as location description. */
15035 single_element_loc_list_p (dw_loc_list_ref list
)
15037 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
15038 return !list
->ll_symbol
;
15041 /* To each location in list LIST add loc descr REF. */
15044 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
15046 dw_loc_descr_ref copy
;
15047 add_loc_descr (&list
->expr
, ref
);
15048 list
= list
->dw_loc_next
;
15051 copy
= ggc_alloc
<dw_loc_descr_node
> ();
15052 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
15053 add_loc_descr (&list
->expr
, copy
);
15054 while (copy
->dw_loc_next
)
15056 dw_loc_descr_ref new_copy
= ggc_alloc
<dw_loc_descr_node
> ();
15057 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
15058 copy
->dw_loc_next
= new_copy
;
15061 list
= list
->dw_loc_next
;
15065 /* Given two lists RET and LIST
15066 produce location list that is result of adding expression in LIST
15067 to expression in RET on each position in program.
15068 Might be destructive on both RET and LIST.
15070 TODO: We handle only simple cases of RET or LIST having at most one
15071 element. General case would inolve sorting the lists in program order
15072 and merging them that will need some additional work.
15073 Adding that will improve quality of debug info especially for SRA-ed
15077 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
15086 if (!list
->dw_loc_next
)
15088 add_loc_descr_to_each (*ret
, list
->expr
);
15091 if (!(*ret
)->dw_loc_next
)
15093 add_loc_descr_to_each (list
, (*ret
)->expr
);
15097 expansion_failed (NULL_TREE
, NULL_RTX
,
15098 "Don't know how to merge two non-trivial"
15099 " location lists.\n");
15104 /* LOC is constant expression. Try a luck, look it up in constant
15105 pool and return its loc_descr of its address. */
15107 static dw_loc_descr_ref
15108 cst_pool_loc_descr (tree loc
)
15110 /* Get an RTL for this, if something has been emitted. */
15111 rtx rtl
= lookup_constant_def (loc
);
15113 if (!rtl
|| !MEM_P (rtl
))
15118 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
15120 /* TODO: We might get more coverage if we was actually delaying expansion
15121 of all expressions till end of compilation when constant pools are fully
15123 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
15125 expansion_failed (loc
, NULL_RTX
,
15126 "CST value in contant pool but not marked.");
15129 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
15130 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
15133 /* Return dw_loc_list representing address of addr_expr LOC
15134 by looking for inner INDIRECT_REF expression and turning
15135 it into simple arithmetics.
15137 See loc_list_from_tree for the meaning of CONTEXT. */
15139 static dw_loc_list_ref
15140 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
15141 const loc_descr_context
*context
)
15144 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
15146 int unsignedp
, reversep
, volatilep
= 0;
15147 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
15149 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
15150 &bitsize
, &bitpos
, &offset
, &mode
,
15151 &unsignedp
, &reversep
, &volatilep
, false);
15153 if (bitpos
% BITS_PER_UNIT
)
15155 expansion_failed (loc
, NULL_RTX
, "bitfield access");
15158 if (!INDIRECT_REF_P (obj
))
15160 expansion_failed (obj
,
15161 NULL_RTX
, "no indirect ref in inner refrence");
15164 if (!offset
&& !bitpos
)
15165 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
15168 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
15169 && (dwarf_version
>= 4 || !dwarf_strict
))
15171 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
15176 /* Variable offset. */
15177 list_ret1
= loc_list_from_tree (offset
, 0, context
);
15178 if (list_ret1
== 0)
15180 add_loc_list (&list_ret
, list_ret1
);
15183 add_loc_descr_to_each (list_ret
,
15184 new_loc_descr (DW_OP_plus
, 0, 0));
15186 bytepos
= bitpos
/ BITS_PER_UNIT
;
15188 add_loc_descr_to_each (list_ret
,
15189 new_loc_descr (DW_OP_plus_uconst
,
15191 else if (bytepos
< 0)
15192 loc_list_plus_const (list_ret
, bytepos
);
15193 add_loc_descr_to_each (list_ret
,
15194 new_loc_descr (DW_OP_stack_value
, 0, 0));
15199 /* Set LOC to the next operation that is not a DW_OP_nop operation. In the case
15200 all operations from LOC are nops, move to the last one. Insert in NOPS all
15201 operations that are skipped. */
15204 loc_descr_to_next_no_nop (dw_loc_descr_ref
&loc
,
15205 hash_set
<dw_loc_descr_ref
> &nops
)
15207 while (loc
->dw_loc_next
!= NULL
&& loc
->dw_loc_opc
== DW_OP_nop
)
15210 loc
= loc
->dw_loc_next
;
15214 /* Helper for loc_descr_without_nops: free the location description operation
15218 free_loc_descr (const dw_loc_descr_ref
&loc
, void *data ATTRIBUTE_UNUSED
)
15224 /* Remove all DW_OP_nop operations from LOC except, if it exists, the one that
15228 loc_descr_without_nops (dw_loc_descr_ref
&loc
)
15230 if (loc
->dw_loc_opc
== DW_OP_nop
&& loc
->dw_loc_next
== NULL
)
15233 /* Set of all DW_OP_nop operations we remove. */
15234 hash_set
<dw_loc_descr_ref
> nops
;
15236 /* First, strip all prefix NOP operations in order to keep the head of the
15237 operations list. */
15238 loc_descr_to_next_no_nop (loc
, nops
);
15240 for (dw_loc_descr_ref cur
= loc
; cur
!= NULL
;)
15242 /* For control flow operations: strip "prefix" nops in destination
15244 if (cur
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
)
15245 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd1
.v
.val_loc
, nops
);
15246 if (cur
->dw_loc_oprnd2
.val_class
== dw_val_class_loc
)
15247 loc_descr_to_next_no_nop (cur
->dw_loc_oprnd2
.v
.val_loc
, nops
);
15249 /* Do the same for the operations that follow, then move to the next
15251 if (cur
->dw_loc_next
!= NULL
)
15252 loc_descr_to_next_no_nop (cur
->dw_loc_next
, nops
);
15253 cur
= cur
->dw_loc_next
;
15256 nops
.traverse
<void *, free_loc_descr
> (NULL
);
15260 struct dwarf_procedure_info
;
15262 /* Helper structure for location descriptions generation. */
15263 struct loc_descr_context
15265 /* The type that is implicitly referenced by DW_OP_push_object_address, or
15266 NULL_TREE if DW_OP_push_object_address in invalid for this location
15267 description. This is used when processing PLACEHOLDER_EXPR nodes. */
15269 /* The ..._DECL node that should be translated as a
15270 DW_OP_push_object_address operation. */
15272 /* Information about the DWARF procedure we are currently generating. NULL if
15273 we are not generating a DWARF procedure. */
15274 struct dwarf_procedure_info
*dpi
;
15277 /* DWARF procedures generation
15279 DWARF expressions (aka. location descriptions) are used to encode variable
15280 things such as sizes or offsets. Such computations can have redundant parts
15281 that can be factorized in order to reduce the size of the output debug
15282 information. This is the whole point of DWARF procedures.
15284 Thanks to stor-layout.c, size and offset expressions in GENERIC trees are
15285 already factorized into functions ("size functions") in order to handle very
15286 big and complex types. Such functions are quite simple: they have integral
15287 arguments, they return an integral result and their body contains only a
15288 return statement with arithmetic expressions. This is the only kind of
15289 function we are interested in translating into DWARF procedures, here.
15291 DWARF expressions and DWARF procedure are executed using a stack, so we have
15292 to define some calling convention for them to interact. Let's say that:
15294 - Before calling a DWARF procedure, DWARF expressions must push on the stack
15295 all arguments in reverse order (right-to-left) so that when the DWARF
15296 procedure execution starts, the first argument is the top of the stack.
15298 - Then, when returning, the DWARF procedure must have consumed all arguments
15299 on the stack, must have pushed the result and touched nothing else.
15301 - Each integral argument and the result are integral types can be hold in a
15304 - We call "frame offset" the number of stack slots that are "under DWARF
15305 procedure control": it includes the arguments slots, the temporaries and
15306 the result slot. Thus, it is equal to the number of arguments when the
15307 procedure execution starts and must be equal to one (the result) when it
15310 /* Helper structure used when generating operations for a DWARF procedure. */
15311 struct dwarf_procedure_info
15313 /* The FUNCTION_DECL node corresponding to the DWARF procedure that is
15314 currently translated. */
15316 /* The number of arguments FNDECL takes. */
15317 unsigned args_count
;
15320 /* Return a pointer to a newly created DIE node for a DWARF procedure. Add
15321 LOCATION as its DW_AT_location attribute. If FNDECL is not NULL_TREE,
15322 equate it to this DIE. */
15325 new_dwarf_proc_die (dw_loc_descr_ref location
, tree fndecl
,
15326 dw_die_ref parent_die
)
15328 const bool dwarf_proc_supported
= dwarf_version
>= 4;
15329 dw_die_ref dwarf_proc_die
;
15331 if ((dwarf_version
< 3 && dwarf_strict
)
15332 || location
== NULL
)
15335 dwarf_proc_die
= new_die (dwarf_proc_supported
15336 ? DW_TAG_dwarf_procedure
15341 equate_decl_number_to_die (fndecl
, dwarf_proc_die
);
15342 if (!dwarf_proc_supported
)
15343 add_AT_flag (dwarf_proc_die
, DW_AT_artificial
, 1);
15344 add_AT_loc (dwarf_proc_die
, DW_AT_location
, location
);
15345 return dwarf_proc_die
;
15348 /* Return whether TYPE is a supported type as a DWARF procedure argument
15349 type or return type (we handle only scalar types and pointer types that
15350 aren't wider than the DWARF expression evaluation stack. */
15353 is_handled_procedure_type (tree type
)
15355 return ((INTEGRAL_TYPE_P (type
)
15356 || TREE_CODE (type
) == OFFSET_TYPE
15357 || TREE_CODE (type
) == POINTER_TYPE
)
15358 && int_size_in_bytes (type
) <= DWARF2_ADDR_SIZE
);
15361 /* Helper for resolve_args_picking. Stop when coming across VISITED nodes. */
15364 resolve_args_picking_1 (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
15365 struct dwarf_procedure_info
*dpi
,
15366 hash_set
<dw_loc_descr_ref
> &visited
)
15368 /* The "frame_offset" identifier is already used to name a macro... */
15369 unsigned frame_offset_
= initial_frame_offset
;
15370 dw_loc_descr_ref l
;
15372 for (l
= loc
; l
!= NULL
;)
15374 /* If we already met this node, there is nothing to compute anymore. */
15375 if (visited
.add (l
))
15378 /* Make sure that the stack size is consistent wherever the execution
15379 flow comes from. */
15380 gcc_assert ((unsigned) l
->dw_loc_frame_offset
== frame_offset_
);
15385 l
->dw_loc_frame_offset
= frame_offset_
;
15388 /* If needed, relocate the picking offset with respect to the frame
15390 if (l
->dw_loc_opc
== DW_OP_pick
&& l
->frame_offset_rel
)
15392 /* frame_offset_ is the size of the current stack frame, including
15393 incoming arguments. Besides, the arguments are pushed
15394 right-to-left. Thus, in order to access the Nth argument from
15395 this operation node, the picking has to skip temporaries *plus*
15396 one stack slot per argument (0 for the first one, 1 for the second
15399 The targetted argument number (N) is already set as the operand,
15400 and the number of temporaries can be computed with:
15401 frame_offsets_ - dpi->args_count */
15402 l
->dw_loc_oprnd1
.v
.val_unsigned
+= frame_offset_
- dpi
->args_count
;
15404 /* DW_OP_pick handles only offsets from 0 to 255 (inclusive)... */
15405 if (l
->dw_loc_oprnd1
.v
.val_unsigned
> 255)
15409 /* Update frame_offset according to the effect the current operation has
15411 switch (l
->dw_loc_opc
)
15418 case DW_OP_plus_uconst
:
15454 case DW_OP_deref_size
:
15456 case DW_OP_form_tls_address
:
15457 case DW_OP_bit_piece
:
15458 case DW_OP_implicit_value
:
15459 case DW_OP_stack_value
:
15463 case DW_OP_const1u
:
15464 case DW_OP_const1s
:
15465 case DW_OP_const2u
:
15466 case DW_OP_const2s
:
15467 case DW_OP_const4u
:
15468 case DW_OP_const4s
:
15469 case DW_OP_const8u
:
15470 case DW_OP_const8s
:
15541 case DW_OP_push_object_address
:
15542 case DW_OP_call_frame_cfa
:
15568 case DW_OP_xderef_size
:
15574 case DW_OP_call_ref
:
15576 dw_die_ref dwarf_proc
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
15577 int *stack_usage
= dwarf_proc_stack_usage_map
->get (dwarf_proc
);
15579 if (stack_usage
== NULL
)
15581 frame_offset_
+= *stack_usage
;
15585 case DW_OP_GNU_push_tls_address
:
15586 case DW_OP_GNU_uninit
:
15587 case DW_OP_GNU_encoded_addr
:
15588 case DW_OP_GNU_implicit_pointer
:
15589 case DW_OP_GNU_entry_value
:
15590 case DW_OP_GNU_const_type
:
15591 case DW_OP_GNU_regval_type
:
15592 case DW_OP_GNU_deref_type
:
15593 case DW_OP_GNU_convert
:
15594 case DW_OP_GNU_reinterpret
:
15595 case DW_OP_GNU_parameter_ref
:
15596 /* loc_list_from_tree will probably not output these operations for
15597 size functions, so assume they will not appear here. */
15598 /* Fall through... */
15601 gcc_unreachable ();
15604 /* Now, follow the control flow (except subroutine calls). */
15605 switch (l
->dw_loc_opc
)
15608 if (!resolve_args_picking_1 (l
->dw_loc_next
, frame_offset_
, dpi
,
15611 /* Fall through... */
15614 l
= l
->dw_loc_oprnd1
.v
.val_loc
;
15617 case DW_OP_stack_value
:
15621 l
= l
->dw_loc_next
;
15629 /* Make a DFS over operations reachable through LOC (i.e. follow branch
15630 operations) in order to resolve the operand of DW_OP_pick operations that
15631 target DWARF procedure arguments (DPI). Stop at already visited nodes.
15632 INITIAL_FRAME_OFFSET is the frame offset *before* LOC is executed. Return
15633 if all relocations were successful. */
15636 resolve_args_picking (dw_loc_descr_ref loc
, unsigned initial_frame_offset
,
15637 struct dwarf_procedure_info
*dpi
)
15639 hash_set
<dw_loc_descr_ref
> visited
;
15641 return resolve_args_picking_1 (loc
, initial_frame_offset
, dpi
, visited
);
15644 /* Try to generate a DWARF procedure that computes the same result as FNDECL.
15645 Return NULL if it is not possible. */
15648 function_to_dwarf_procedure (tree fndecl
)
15650 struct loc_descr_context ctx
;
15651 struct dwarf_procedure_info dpi
;
15652 dw_die_ref dwarf_proc_die
;
15653 tree tree_body
= DECL_SAVED_TREE (fndecl
);
15654 dw_loc_descr_ref loc_body
, epilogue
;
15659 /* Do not generate multiple DWARF procedures for the same function
15661 dwarf_proc_die
= lookup_decl_die (fndecl
);
15662 if (dwarf_proc_die
!= NULL
)
15663 return dwarf_proc_die
;
15665 /* DWARF procedures are available starting with the DWARFv3 standard, but
15666 it's the DWARFv4 standard that introduces the DW_TAG_dwarf_procedure
15668 if (dwarf_version
< 3 && dwarf_strict
)
15671 /* We handle only functions for which we still have a body, that return a
15672 supported type and that takes arguments with supported types. Note that
15673 there is no point translating functions that return nothing. */
15674 if (tree_body
== NULL_TREE
15675 || DECL_RESULT (fndecl
) == NULL_TREE
15676 || !is_handled_procedure_type (TREE_TYPE (DECL_RESULT (fndecl
))))
15679 for (cursor
= DECL_ARGUMENTS (fndecl
);
15680 cursor
!= NULL_TREE
;
15681 cursor
= TREE_CHAIN (cursor
))
15682 if (!is_handled_procedure_type (TREE_TYPE (cursor
)))
15685 /* Match only "expr" in: RETURN_EXPR (MODIFY_EXPR (RESULT_DECL, expr)). */
15686 if (TREE_CODE (tree_body
) != RETURN_EXPR
)
15688 tree_body
= TREE_OPERAND (tree_body
, 0);
15689 if (TREE_CODE (tree_body
) != MODIFY_EXPR
15690 || TREE_OPERAND (tree_body
, 0) != DECL_RESULT (fndecl
))
15692 tree_body
= TREE_OPERAND (tree_body
, 1);
15694 /* Try to translate the body expression itself. Note that this will probably
15695 cause an infinite recursion if its call graph has a cycle. This is very
15696 unlikely for size functions, however, so don't bother with such things at
15698 ctx
.context_type
= NULL_TREE
;
15699 ctx
.base_decl
= NULL_TREE
;
15701 dpi
.fndecl
= fndecl
;
15702 dpi
.args_count
= list_length (DECL_ARGUMENTS (fndecl
));
15703 loc_body
= loc_descriptor_from_tree (tree_body
, 0, &ctx
);
15707 /* After evaluating all operands in "loc_body", we should still have on the
15708 stack all arguments plus the desired function result (top of the stack).
15709 Generate code in order to keep only the result in our stack frame. */
15711 for (i
= 0; i
< dpi
.args_count
; ++i
)
15713 dw_loc_descr_ref op_couple
= new_loc_descr (DW_OP_swap
, 0, 0);
15714 op_couple
->dw_loc_next
= new_loc_descr (DW_OP_drop
, 0, 0);
15715 op_couple
->dw_loc_next
->dw_loc_next
= epilogue
;
15716 epilogue
= op_couple
;
15718 add_loc_descr (&loc_body
, epilogue
);
15719 if (!resolve_args_picking (loc_body
, dpi
.args_count
, &dpi
))
15722 /* Trailing nops from loc_descriptor_from_tree (if any) cannot be removed
15723 because they are considered useful. Now there is an epilogue, they are
15724 not anymore, so give it another try. */
15725 loc_descr_without_nops (loc_body
);
15727 /* fndecl may be used both as a regular DW_TAG_subprogram DIE and as
15728 a DW_TAG_dwarf_procedure, so we may have a conflict, here. It's unlikely,
15729 though, given that size functions do not come from source, so they should
15730 not have a dedicated DW_TAG_subprogram DIE. */
15732 = new_dwarf_proc_die (loc_body
, fndecl
,
15733 get_context_die (DECL_CONTEXT (fndecl
)));
15735 /* The called DWARF procedure consumes one stack slot per argument and
15736 returns one stack slot. */
15737 dwarf_proc_stack_usage_map
->put (dwarf_proc_die
, 1 - dpi
.args_count
);
15739 return dwarf_proc_die
;
15743 /* Generate Dwarf location list representing LOC.
15744 If WANT_ADDRESS is false, expression computing LOC will be computed
15745 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
15746 if WANT_ADDRESS is 2, expression computing address useable in location
15747 will be returned (i.e. DW_OP_reg can be used
15748 to refer to register values).
15750 CONTEXT provides information to customize the location descriptions
15751 generation. Its context_type field specifies what type is implicitly
15752 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
15753 will not be generated.
15755 Its DPI field determines whether we are generating a DWARF expression for a
15756 DWARF procedure, so PARM_DECL references are processed specifically.
15758 If CONTEXT is NULL, the behavior is the same as if context_type, base_decl
15759 and dpi fields were null. */
15761 static dw_loc_list_ref
15762 loc_list_from_tree_1 (tree loc
, int want_address
,
15763 const struct loc_descr_context
*context
)
15765 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
15766 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
15767 int have_address
= 0;
15768 enum dwarf_location_atom op
;
15770 /* ??? Most of the time we do not take proper care for sign/zero
15771 extending the values properly. Hopefully this won't be a real
15774 if (context
!= NULL
15775 && context
->base_decl
== loc
15776 && want_address
== 0)
15778 if (dwarf_version
>= 3 || !dwarf_strict
)
15779 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
15785 switch (TREE_CODE (loc
))
15788 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
15791 case PLACEHOLDER_EXPR
:
15792 /* This case involves extracting fields from an object to determine the
15793 position of other fields. It is supposed to appear only as the first
15794 operand of COMPONENT_REF nodes and to reference precisely the type
15795 that the context allows. */
15796 if (context
!= NULL
15797 && TREE_TYPE (loc
) == context
->context_type
15798 && want_address
>= 1)
15800 if (dwarf_version
>= 3 || !dwarf_strict
)
15802 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
15810 expansion_failed (loc
, NULL_RTX
,
15811 "PLACEHOLDER_EXPR for an unexpected type");
15816 const int nargs
= call_expr_nargs (loc
);
15817 tree callee
= get_callee_fndecl (loc
);
15819 dw_die_ref dwarf_proc
;
15821 if (callee
== NULL_TREE
)
15822 goto call_expansion_failed
;
15824 /* We handle only functions that return an integer. */
15825 if (!is_handled_procedure_type (TREE_TYPE (TREE_TYPE (callee
))))
15826 goto call_expansion_failed
;
15828 dwarf_proc
= function_to_dwarf_procedure (callee
);
15829 if (dwarf_proc
== NULL
)
15830 goto call_expansion_failed
;
15832 /* Evaluate arguments right-to-left so that the first argument will
15833 be the top-most one on the stack. */
15834 for (i
= nargs
- 1; i
>= 0; --i
)
15836 dw_loc_descr_ref loc_descr
15837 = loc_descriptor_from_tree (CALL_EXPR_ARG (loc
, i
), 0,
15840 if (loc_descr
== NULL
)
15841 goto call_expansion_failed
;
15843 add_loc_descr (&ret
, loc_descr
);
15846 ret1
= new_loc_descr (DW_OP_call4
, 0, 0);
15847 ret1
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
15848 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.die
= dwarf_proc
;
15849 ret1
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
15850 add_loc_descr (&ret
, ret1
);
15853 call_expansion_failed
:
15854 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
15855 /* There are no opcodes for these operations. */
15859 case PREINCREMENT_EXPR
:
15860 case PREDECREMENT_EXPR
:
15861 case POSTINCREMENT_EXPR
:
15862 case POSTDECREMENT_EXPR
:
15863 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
15864 /* There are no opcodes for these operations. */
15868 /* If we already want an address, see if there is INDIRECT_REF inside
15869 e.g. for &this->field. */
15872 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
15873 (loc
, want_address
== 2, context
);
15876 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
15877 && (ret
= cst_pool_loc_descr (loc
)))
15880 /* Otherwise, process the argument and look for the address. */
15881 if (!list_ret
&& !ret
)
15882 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 1, context
);
15886 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
15892 if (DECL_THREAD_LOCAL_P (loc
))
15895 enum dwarf_location_atom tls_op
;
15896 enum dtprel_bool dtprel
= dtprel_false
;
15898 if (targetm
.have_tls
)
15900 /* If this is not defined, we have no way to emit the
15902 if (!targetm
.asm_out
.output_dwarf_dtprel
)
15905 /* The way DW_OP_GNU_push_tls_address is specified, we
15906 can only look up addresses of objects in the current
15907 module. We used DW_OP_addr as first op, but that's
15908 wrong, because DW_OP_addr is relocated by the debug
15909 info consumer, while DW_OP_GNU_push_tls_address
15910 operand shouldn't be. */
15911 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
15913 dtprel
= dtprel_true
;
15914 tls_op
= DW_OP_GNU_push_tls_address
;
15918 if (!targetm
.emutls
.debug_form_tls_address
15919 || !(dwarf_version
>= 3 || !dwarf_strict
))
15921 /* We stuffed the control variable into the DECL_VALUE_EXPR
15922 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
15923 no longer appear in gimple code. We used the control
15924 variable in specific so that we could pick it up here. */
15925 loc
= DECL_VALUE_EXPR (loc
);
15926 tls_op
= DW_OP_form_tls_address
;
15929 rtl
= rtl_for_decl_location (loc
);
15930 if (rtl
== NULL_RTX
)
15935 rtl
= XEXP (rtl
, 0);
15936 if (! CONSTANT_P (rtl
))
15939 ret
= new_addr_loc_descr (rtl
, dtprel
);
15940 ret1
= new_loc_descr (tls_op
, 0, 0);
15941 add_loc_descr (&ret
, ret1
);
15949 if (context
!= NULL
&& context
->dpi
!= NULL
15950 && DECL_CONTEXT (loc
) == context
->dpi
->fndecl
)
15952 /* We are generating code for a DWARF procedure and we want to access
15953 one of its arguments: find the appropriate argument offset and let
15954 the resolve_args_picking pass compute the offset that complies
15955 with the stack frame size. */
15959 for (cursor
= DECL_ARGUMENTS (context
->dpi
->fndecl
);
15960 cursor
!= NULL_TREE
&& cursor
!= loc
;
15961 cursor
= TREE_CHAIN (cursor
), ++i
)
15963 /* If we are translating a DWARF procedure, all referenced parameters
15964 must belong to the current function. */
15965 gcc_assert (cursor
!= NULL_TREE
);
15967 ret
= new_loc_descr (DW_OP_pick
, i
, 0);
15968 ret
->frame_offset_rel
= 1;
15974 if (DECL_HAS_VALUE_EXPR_P (loc
))
15975 return loc_list_from_tree_1 (DECL_VALUE_EXPR (loc
),
15976 want_address
, context
);
15979 case FUNCTION_DECL
:
15982 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
15984 if (loc_list
&& loc_list
->first
)
15986 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
15987 have_address
= want_address
!= 0;
15990 rtl
= rtl_for_decl_location (loc
);
15991 if (rtl
== NULL_RTX
)
15993 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
15996 else if (CONST_INT_P (rtl
))
15998 HOST_WIDE_INT val
= INTVAL (rtl
);
15999 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
16000 val
&= GET_MODE_MASK (DECL_MODE (loc
));
16001 ret
= int_loc_descriptor (val
);
16003 else if (GET_CODE (rtl
) == CONST_STRING
)
16005 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
16008 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
16009 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
16012 machine_mode mode
, mem_mode
;
16014 /* Certain constructs can only be represented at top-level. */
16015 if (want_address
== 2)
16017 ret
= loc_descriptor (rtl
, VOIDmode
,
16018 VAR_INIT_STATUS_INITIALIZED
);
16023 mode
= GET_MODE (rtl
);
16024 mem_mode
= VOIDmode
;
16028 mode
= get_address_mode (rtl
);
16029 rtl
= XEXP (rtl
, 0);
16032 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
16033 VAR_INIT_STATUS_INITIALIZED
);
16036 expansion_failed (loc
, rtl
,
16037 "failed to produce loc descriptor for rtl");
16043 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
16050 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16054 case TARGET_MEM_REF
:
16056 case DEBUG_EXPR_DECL
:
16059 case COMPOUND_EXPR
:
16060 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), want_address
,
16064 case VIEW_CONVERT_EXPR
:
16067 case NON_LVALUE_EXPR
:
16068 return loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), want_address
,
16071 case COMPONENT_REF
:
16072 case BIT_FIELD_REF
:
16074 case ARRAY_RANGE_REF
:
16075 case REALPART_EXPR
:
16076 case IMAGPART_EXPR
:
16079 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
16081 int unsignedp
, reversep
, volatilep
= 0;
16083 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
16084 &unsignedp
, &reversep
, &volatilep
, false);
16086 gcc_assert (obj
!= loc
);
16088 list_ret
= loc_list_from_tree_1 (obj
,
16090 && !bitpos
&& !offset
? 2 : 1,
16092 /* TODO: We can extract value of the small expression via shifting even
16093 for nonzero bitpos. */
16096 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
16098 expansion_failed (loc
, NULL_RTX
,
16099 "bitfield access");
16103 if (offset
!= NULL_TREE
)
16105 /* Variable offset. */
16106 list_ret1
= loc_list_from_tree_1 (offset
, 0, context
);
16107 if (list_ret1
== 0)
16109 add_loc_list (&list_ret
, list_ret1
);
16112 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
16115 bytepos
= bitpos
/ BITS_PER_UNIT
;
16117 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
16118 else if (bytepos
< 0)
16119 loc_list_plus_const (list_ret
, bytepos
);
16126 if ((want_address
|| !tree_fits_shwi_p (loc
))
16127 && (ret
= cst_pool_loc_descr (loc
)))
16129 else if (want_address
== 2
16130 && tree_fits_shwi_p (loc
)
16131 && (ret
= address_of_int_loc_descriptor
16132 (int_size_in_bytes (TREE_TYPE (loc
)),
16133 tree_to_shwi (loc
))))
16135 else if (tree_fits_shwi_p (loc
))
16136 ret
= int_loc_descriptor (tree_to_shwi (loc
));
16137 else if (tree_fits_uhwi_p (loc
))
16138 ret
= uint_loc_descriptor (tree_to_uhwi (loc
));
16141 expansion_failed (loc
, NULL_RTX
,
16142 "Integer operand is not host integer");
16151 if ((ret
= cst_pool_loc_descr (loc
)))
16154 /* We can construct small constants here using int_loc_descriptor. */
16155 expansion_failed (loc
, NULL_RTX
,
16156 "constructor or constant not in constant pool");
16159 case TRUTH_AND_EXPR
:
16160 case TRUTH_ANDIF_EXPR
:
16165 case TRUTH_XOR_EXPR
:
16170 case TRUTH_OR_EXPR
:
16171 case TRUTH_ORIF_EXPR
:
16176 case FLOOR_DIV_EXPR
:
16177 case CEIL_DIV_EXPR
:
16178 case ROUND_DIV_EXPR
:
16179 case TRUNC_DIV_EXPR
:
16180 case EXACT_DIV_EXPR
:
16181 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
16190 case FLOOR_MOD_EXPR
:
16191 case CEIL_MOD_EXPR
:
16192 case ROUND_MOD_EXPR
:
16193 case TRUNC_MOD_EXPR
:
16194 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
16199 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16200 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
16201 if (list_ret
== 0 || list_ret1
== 0)
16204 add_loc_list (&list_ret
, list_ret1
);
16207 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
16208 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
16209 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
16210 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
16211 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
16223 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
16226 case POINTER_PLUS_EXPR
:
16229 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
16231 /* Big unsigned numbers can fit in HOST_WIDE_INT but it may be
16232 smarter to encode their opposite. The DW_OP_plus_uconst operation
16233 takes 1 + X bytes, X being the size of the ULEB128 addend. On the
16234 other hand, a "<push literal>; DW_OP_minus" pattern takes 1 + Y
16235 bytes, Y being the size of the operation that pushes the opposite
16236 of the addend. So let's choose the smallest representation. */
16237 const tree tree_addend
= TREE_OPERAND (loc
, 1);
16238 offset_int wi_addend
;
16239 HOST_WIDE_INT shwi_addend
;
16240 dw_loc_descr_ref loc_naddend
;
16242 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16246 /* Try to get the literal to push. It is the opposite of the addend,
16247 so as we rely on wrapping during DWARF evaluation, first decode
16248 the literal as a "DWARF-sized" signed number. */
16249 wi_addend
= wi::to_offset (tree_addend
);
16250 wi_addend
= wi::sext (wi_addend
, DWARF2_ADDR_SIZE
* 8);
16251 shwi_addend
= wi_addend
.to_shwi ();
16252 loc_naddend
= (shwi_addend
!= INTTYPE_MINIMUM (HOST_WIDE_INT
))
16253 ? int_loc_descriptor (-shwi_addend
)
16256 if (loc_naddend
!= NULL
16257 && ((unsigned) size_of_uleb128 (shwi_addend
)
16258 > size_of_loc_descr (loc_naddend
)))
16260 add_loc_descr_to_each (list_ret
, loc_naddend
);
16261 add_loc_descr_to_each (list_ret
,
16262 new_loc_descr (DW_OP_minus
, 0, 0));
16266 for (dw_loc_descr_ref loc_cur
= loc_naddend
; loc_cur
!= NULL
; )
16268 loc_naddend
= loc_cur
;
16269 loc_cur
= loc_cur
->dw_loc_next
;
16270 ggc_free (loc_naddend
);
16272 loc_list_plus_const (list_ret
, wi_addend
.to_shwi ());
16282 goto do_comp_binop
;
16286 goto do_comp_binop
;
16290 goto do_comp_binop
;
16294 goto do_comp_binop
;
16297 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
16299 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
16300 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
16301 list_ret
= loc_list_from_uint_comparison (list_ret
, list_ret1
,
16317 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16318 list_ret1
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 1), 0, context
);
16319 if (list_ret
== 0 || list_ret1
== 0)
16322 add_loc_list (&list_ret
, list_ret1
);
16325 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
16328 case TRUTH_NOT_EXPR
:
16342 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16346 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
16352 const enum tree_code code
=
16353 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
16355 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
16356 build2 (code
, integer_type_node
,
16357 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
16358 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
16361 /* ... fall through ... */
16365 dw_loc_descr_ref lhs
16366 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
16367 dw_loc_list_ref rhs
16368 = loc_list_from_tree_1 (TREE_OPERAND (loc
, 2), 0, context
);
16369 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
16371 list_ret
= loc_list_from_tree_1 (TREE_OPERAND (loc
, 0), 0, context
);
16372 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
16375 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
16376 add_loc_descr_to_each (list_ret
, bra_node
);
16378 add_loc_list (&list_ret
, rhs
);
16379 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
16380 add_loc_descr_to_each (list_ret
, jump_node
);
16382 add_loc_descr_to_each (list_ret
, lhs
);
16383 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16384 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
16386 /* ??? Need a node to point the skip at. Use a nop. */
16387 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
16388 add_loc_descr_to_each (list_ret
, tmp
);
16389 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
16390 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
16394 case FIX_TRUNC_EXPR
:
16398 /* Leave front-end specific codes as simply unknown. This comes
16399 up, for instance, with the C STMT_EXPR. */
16400 if ((unsigned int) TREE_CODE (loc
)
16401 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
16403 expansion_failed (loc
, NULL_RTX
,
16404 "language specific tree node");
16408 /* Otherwise this is a generic code; we should just lists all of
16409 these explicitly. We forgot one. */
16411 gcc_unreachable ();
16413 /* In a release build, we want to degrade gracefully: better to
16414 generate incomplete debugging information than to crash. */
16418 if (!ret
&& !list_ret
)
16421 if (want_address
== 2 && !have_address
16422 && (dwarf_version
>= 4 || !dwarf_strict
))
16424 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
16426 expansion_failed (loc
, NULL_RTX
,
16427 "DWARF address size mismatch");
16431 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
16433 add_loc_descr_to_each (list_ret
,
16434 new_loc_descr (DW_OP_stack_value
, 0, 0));
16437 /* Show if we can't fill the request for an address. */
16438 if (want_address
&& !have_address
)
16440 expansion_failed (loc
, NULL_RTX
,
16441 "Want address and only have value");
16445 gcc_assert (!ret
|| !list_ret
);
16447 /* If we've got an address and don't want one, dereference. */
16448 if (!want_address
&& have_address
)
16450 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
16452 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
16454 expansion_failed (loc
, NULL_RTX
,
16455 "DWARF address size mismatch");
16458 else if (size
== DWARF2_ADDR_SIZE
)
16461 op
= DW_OP_deref_size
;
16464 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
16466 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
16469 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
16474 /* Likewise, but strip useless DW_OP_nop operations in the resulting
16477 static dw_loc_list_ref
16478 loc_list_from_tree (tree loc
, int want_address
,
16479 const struct loc_descr_context
*context
)
16481 dw_loc_list_ref result
= loc_list_from_tree_1 (loc
, want_address
, context
);
16483 for (dw_loc_list_ref loc_cur
= result
;
16484 loc_cur
!= NULL
; loc_cur
=
16485 loc_cur
->dw_loc_next
)
16486 loc_descr_without_nops (loc_cur
->expr
);
16490 /* Same as above but return only single location expression. */
16491 static dw_loc_descr_ref
16492 loc_descriptor_from_tree (tree loc
, int want_address
,
16493 const struct loc_descr_context
*context
)
16495 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
16498 if (ret
->dw_loc_next
)
16500 expansion_failed (loc
, NULL_RTX
,
16501 "Location list where only loc descriptor needed");
16507 /* Given a value, round it up to the lowest multiple of `boundary'
16508 which is not less than the value itself. */
16510 static inline HOST_WIDE_INT
16511 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
16513 return (((value
+ boundary
- 1) / boundary
) * boundary
);
16516 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
16517 pointer to the declared type for the relevant field variable, or return
16518 `integer_type_node' if the given node turns out to be an
16519 ERROR_MARK node. */
16522 field_type (const_tree decl
)
16526 if (TREE_CODE (decl
) == ERROR_MARK
)
16527 return integer_type_node
;
16529 type
= DECL_BIT_FIELD_TYPE (decl
);
16530 if (type
== NULL_TREE
)
16531 type
= TREE_TYPE (decl
);
16536 /* Given a pointer to a tree node, return the alignment in bits for
16537 it, or else return BITS_PER_WORD if the node actually turns out to
16538 be an ERROR_MARK node. */
16540 static inline unsigned
16541 simple_type_align_in_bits (const_tree type
)
16543 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
16546 static inline unsigned
16547 simple_decl_align_in_bits (const_tree decl
)
16549 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
16552 /* Return the result of rounding T up to ALIGN. */
16554 static inline offset_int
16555 round_up_to_align (const offset_int
&t
, unsigned int align
)
16557 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
16560 /* Compute the size of TYPE in bytes. If possible, return NULL and store the
16561 size as an integer constant in CST_SIZE. Otherwise, if possible, return a
16562 DWARF expression that computes the size. Return NULL and set CST_SIZE to -1
16563 if we fail to return the size in one of these two forms. */
16565 static dw_loc_descr_ref
16566 type_byte_size (const_tree type
, HOST_WIDE_INT
*cst_size
)
16569 struct loc_descr_context ctx
;
16571 /* Return a constant integer in priority, if possible. */
16572 *cst_size
= int_size_in_bytes (type
);
16573 if (*cst_size
!= -1)
16576 ctx
.context_type
= const_cast<tree
> (type
);
16577 ctx
.base_decl
= NULL_TREE
;
16580 type
= TYPE_MAIN_VARIANT (type
);
16581 tree_size
= TYPE_SIZE_UNIT (type
);
16582 return ((tree_size
!= NULL_TREE
)
16583 ? loc_descriptor_from_tree (tree_size
, 0, &ctx
)
16587 /* Helper structure for RECORD_TYPE processing. */
16590 /* Root RECORD_TYPE. It is needed to generate data member location
16591 descriptions in variable-length records (VLR), but also to cope with
16592 variants, which are composed of nested structures multiplexed with
16593 QUAL_UNION_TYPE nodes. Each time such a structure is passed to a
16594 function processing a FIELD_DECL, it is required to be non null. */
16596 /* When generating a variant part in a RECORD_TYPE (i.e. a nested
16597 QUAL_UNION_TYPE), this holds an expression that computes the offset for
16598 this variant part as part of the root record (in storage units). For
16599 regular records, it must be NULL_TREE. */
16600 tree variant_part_offset
;
16603 /* Given a pointer to a FIELD_DECL, compute the byte offset of the lowest
16604 addressed byte of the "containing object" for the given FIELD_DECL. If
16605 possible, return a native constant through CST_OFFSET (in which case NULL is
16606 returned); otherwise return a DWARF expression that computes the offset.
16608 Set *CST_OFFSET to 0 and return NULL if we are unable to determine what
16609 that offset is, either because the argument turns out to be a pointer to an
16610 ERROR_MARK node, or because the offset expression is too complex for us.
16612 CTX is required: see the comment for VLR_CONTEXT. */
16614 static dw_loc_descr_ref
16615 field_byte_offset (const_tree decl
, struct vlr_context
*ctx
,
16616 HOST_WIDE_INT
*cst_offset
)
16618 offset_int object_offset_in_bits
;
16619 offset_int object_offset_in_bytes
;
16620 offset_int bitpos_int
;
16621 bool is_byte_offset_cst
, is_bit_offset_cst
;
16623 dw_loc_list_ref loc_result
;
16627 if (TREE_CODE (decl
) == ERROR_MARK
)
16630 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
16632 is_bit_offset_cst
= TREE_CODE (DECL_FIELD_BIT_OFFSET (decl
)) != INTEGER_CST
;
16633 is_byte_offset_cst
= TREE_CODE (DECL_FIELD_OFFSET (decl
)) != INTEGER_CST
;
16635 /* We cannot handle variable bit offsets at the moment, so abort if it's the
16637 if (is_bit_offset_cst
)
16640 #ifdef PCC_BITFIELD_TYPE_MATTERS
16641 /* We used to handle only constant offsets in all cases. Now, we handle
16642 properly dynamic byte offsets only when PCC bitfield type doesn't
16644 if (PCC_BITFIELD_TYPE_MATTERS
&& is_byte_offset_cst
&& is_bit_offset_cst
)
16647 tree field_size_tree
;
16648 offset_int deepest_bitpos
;
16649 offset_int field_size_in_bits
;
16650 unsigned int type_align_in_bits
;
16651 unsigned int decl_align_in_bits
;
16652 offset_int type_size_in_bits
;
16654 bitpos_int
= wi::to_offset (bit_position (decl
));
16655 type
= field_type (decl
);
16656 type_size_in_bits
= offset_int_type_size_in_bits (type
);
16657 type_align_in_bits
= simple_type_align_in_bits (type
);
16659 field_size_tree
= DECL_SIZE (decl
);
16661 /* The size could be unspecified if there was an error, or for
16662 a flexible array member. */
16663 if (!field_size_tree
)
16664 field_size_tree
= bitsize_zero_node
;
16666 /* If the size of the field is not constant, use the type size. */
16667 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
16668 field_size_in_bits
= wi::to_offset (field_size_tree
);
16670 field_size_in_bits
= type_size_in_bits
;
16672 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
16674 /* The GCC front-end doesn't make any attempt to keep track of the
16675 starting bit offset (relative to the start of the containing
16676 structure type) of the hypothetical "containing object" for a
16677 bit-field. Thus, when computing the byte offset value for the
16678 start of the "containing object" of a bit-field, we must deduce
16679 this information on our own. This can be rather tricky to do in
16680 some cases. For example, handling the following structure type
16681 definition when compiling for an i386/i486 target (which only
16682 aligns long long's to 32-bit boundaries) can be very tricky:
16684 struct S { int field1; long long field2:31; };
16686 Fortunately, there is a simple rule-of-thumb which can be used
16687 in such cases. When compiling for an i386/i486, GCC will
16688 allocate 8 bytes for the structure shown above. It decides to
16689 do this based upon one simple rule for bit-field allocation.
16690 GCC allocates each "containing object" for each bit-field at
16691 the first (i.e. lowest addressed) legitimate alignment boundary
16692 (based upon the required minimum alignment for the declared
16693 type of the field) which it can possibly use, subject to the
16694 condition that there is still enough available space remaining
16695 in the containing object (when allocated at the selected point)
16696 to fully accommodate all of the bits of the bit-field itself.
16698 This simple rule makes it obvious why GCC allocates 8 bytes for
16699 each object of the structure type shown above. When looking
16700 for a place to allocate the "containing object" for `field2',
16701 the compiler simply tries to allocate a 64-bit "containing
16702 object" at each successive 32-bit boundary (starting at zero)
16703 until it finds a place to allocate that 64- bit field such that
16704 at least 31 contiguous (and previously unallocated) bits remain
16705 within that selected 64 bit field. (As it turns out, for the
16706 example above, the compiler finds it is OK to allocate the
16707 "containing object" 64-bit field at bit-offset zero within the
16710 Here we attempt to work backwards from the limited set of facts
16711 we're given, and we try to deduce from those facts, where GCC
16712 must have believed that the containing object started (within
16713 the structure type). The value we deduce is then used (by the
16714 callers of this routine) to generate DW_AT_location and
16715 DW_AT_bit_offset attributes for fields (both bit-fields and, in
16716 the case of DW_AT_location, regular fields as well). */
16718 /* Figure out the bit-distance from the start of the structure to
16719 the "deepest" bit of the bit-field. */
16720 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
16722 /* This is the tricky part. Use some fancy footwork to deduce
16723 where the lowest addressed bit of the containing object must
16725 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
16727 /* Round up to type_align by default. This works best for
16729 object_offset_in_bits
16730 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
16732 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
16734 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
16736 /* Round up to decl_align instead. */
16737 object_offset_in_bits
16738 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
16741 #endif /* PCC_BITFIELD_TYPE_MATTERS */
16743 tree_result
= byte_position (decl
);
16744 if (ctx
->variant_part_offset
!= NULL_TREE
)
16745 tree_result
= fold (build2 (PLUS_EXPR
, TREE_TYPE (tree_result
),
16746 ctx
->variant_part_offset
, tree_result
));
16748 /* If the byte offset is a constant, it's simplier to handle a native
16749 constant rather than a DWARF expression. */
16750 if (TREE_CODE (tree_result
) == INTEGER_CST
)
16752 *cst_offset
= wi::to_offset (tree_result
).to_shwi ();
16755 struct loc_descr_context loc_ctx
= {
16756 ctx
->struct_type
, /* context_type */
16757 NULL_TREE
, /* base_decl */
16760 loc_result
= loc_list_from_tree (tree_result
, 0, &loc_ctx
);
16762 /* We want a DWARF expression: abort if we only have a location list with
16763 multiple elements. */
16764 if (!loc_result
|| !single_element_loc_list_p (loc_result
))
16767 return loc_result
->expr
;
16770 /* The following routines define various Dwarf attributes and any data
16771 associated with them. */
16773 /* Add a location description attribute value to a DIE.
16775 This emits location attributes suitable for whole variables and
16776 whole parameters. Note that the location attributes for struct fields are
16777 generated by the routine `data_member_location_attribute' below. */
16780 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
16781 dw_loc_list_ref descr
)
16785 if (single_element_loc_list_p (descr
))
16786 add_AT_loc (die
, attr_kind
, descr
->expr
);
16788 add_AT_loc_list (die
, attr_kind
, descr
);
16791 /* Add DW_AT_accessibility attribute to DIE if needed. */
16794 add_accessibility_attribute (dw_die_ref die
, tree decl
)
16796 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
16797 children, otherwise the default is DW_ACCESS_public. In DWARF2
16798 the default has always been DW_ACCESS_public. */
16799 if (TREE_PROTECTED (decl
))
16800 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
16801 else if (TREE_PRIVATE (decl
))
16803 if (dwarf_version
== 2
16804 || die
->die_parent
== NULL
16805 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
16806 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
16808 else if (dwarf_version
> 2
16810 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
16811 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
16814 /* Attach the specialized form of location attribute used for data members of
16815 struct and union types. In the special case of a FIELD_DECL node which
16816 represents a bit-field, the "offset" part of this special location
16817 descriptor must indicate the distance in bytes from the lowest-addressed
16818 byte of the containing struct or union type to the lowest-addressed byte of
16819 the "containing object" for the bit-field. (See the `field_byte_offset'
16822 For any given bit-field, the "containing object" is a hypothetical object
16823 (of some integral or enum type) within which the given bit-field lives. The
16824 type of this hypothetical "containing object" is always the same as the
16825 declared type of the individual bit-field itself (for GCC anyway... the
16826 DWARF spec doesn't actually mandate this). Note that it is the size (in
16827 bytes) of the hypothetical "containing object" which will be given in the
16828 DW_AT_byte_size attribute for this bit-field. (See the
16829 `byte_size_attribute' function below.) It is also used when calculating the
16830 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
16833 CTX is required: see the comment for VLR_CONTEXT. */
16836 add_data_member_location_attribute (dw_die_ref die
,
16838 struct vlr_context
*ctx
)
16840 HOST_WIDE_INT offset
;
16841 dw_loc_descr_ref loc_descr
= 0;
16843 if (TREE_CODE (decl
) == TREE_BINFO
)
16845 /* We're working on the TAG_inheritance for a base class. */
16846 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
16848 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
16849 aren't at a fixed offset from all (sub)objects of the same
16850 type. We need to extract the appropriate offset from our
16851 vtable. The following dwarf expression means
16853 BaseAddr = ObAddr + *((*ObAddr) - Offset)
16855 This is specific to the V3 ABI, of course. */
16857 dw_loc_descr_ref tmp
;
16859 /* Make a copy of the object address. */
16860 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
16861 add_loc_descr (&loc_descr
, tmp
);
16863 /* Extract the vtable address. */
16864 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
16865 add_loc_descr (&loc_descr
, tmp
);
16867 /* Calculate the address of the offset. */
16868 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
16869 gcc_assert (offset
< 0);
16871 tmp
= int_loc_descriptor (-offset
);
16872 add_loc_descr (&loc_descr
, tmp
);
16873 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
16874 add_loc_descr (&loc_descr
, tmp
);
16876 /* Extract the offset. */
16877 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
16878 add_loc_descr (&loc_descr
, tmp
);
16880 /* Add it to the object address. */
16881 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
16882 add_loc_descr (&loc_descr
, tmp
);
16885 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
16889 loc_descr
= field_byte_offset (decl
, ctx
, &offset
);
16891 /* If loc_descr is available then we know the field offset is dynamic.
16892 However, GDB does not handle dynamic field offsets very well at the
16894 if (loc_descr
!= NULL
&& gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
)
16900 /* Data member location evalutation starts with the base address on the
16901 stack. Compute the field offset and add it to this base address. */
16902 else if (loc_descr
!= NULL
)
16903 add_loc_descr (&loc_descr
, new_loc_descr (DW_OP_plus
, 0, 0));
16908 if (dwarf_version
> 2)
16910 /* Don't need to output a location expression, just the constant. */
16912 add_AT_int (die
, DW_AT_data_member_location
, offset
);
16914 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
16919 enum dwarf_location_atom op
;
16921 /* The DWARF2 standard says that we should assume that the structure
16922 address is already on the stack, so we can specify a structure
16923 field address by using DW_OP_plus_uconst. */
16924 op
= DW_OP_plus_uconst
;
16925 loc_descr
= new_loc_descr (op
, offset
, 0);
16929 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
16932 /* Writes integer values to dw_vec_const array. */
16935 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
16939 *dest
++ = val
& 0xff;
16945 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
16947 static HOST_WIDE_INT
16948 extract_int (const unsigned char *src
, unsigned int size
)
16950 HOST_WIDE_INT val
= 0;
16956 val
|= *--src
& 0xff;
16962 /* Writes wide_int values to dw_vec_const array. */
16965 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
16969 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
16971 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
16975 /* We'd have to extend this code to support odd sizes. */
16976 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
16978 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
16980 if (WORDS_BIG_ENDIAN
)
16981 for (i
= n
- 1; i
>= 0; i
--)
16983 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
16984 dest
+= sizeof (HOST_WIDE_INT
);
16987 for (i
= 0; i
< n
; i
++)
16989 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
16990 dest
+= sizeof (HOST_WIDE_INT
);
16994 /* Writes floating point values to dw_vec_const array. */
16997 insert_float (const_rtx rtl
, unsigned char *array
)
17002 real_to_target (val
, CONST_DOUBLE_REAL_VALUE (rtl
), GET_MODE (rtl
));
17004 /* real_to_target puts 32-bit pieces in each long. Pack them. */
17005 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
17007 insert_int (val
[i
], 4, array
);
17012 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
17013 does not have a "location" either in memory or in a register. These
17014 things can arise in GNU C when a constant is passed as an actual parameter
17015 to an inlined function. They can also arise in C++ where declared
17016 constants do not necessarily get memory "homes". */
17019 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
17021 switch (GET_CODE (rtl
))
17025 HOST_WIDE_INT val
= INTVAL (rtl
);
17028 add_AT_int (die
, DW_AT_const_value
, val
);
17030 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
17034 case CONST_WIDE_INT
:
17036 wide_int w1
= std::make_pair (rtl
, MAX_MODE_INT
);
17037 unsigned int prec
= MIN (wi::min_precision (w1
, UNSIGNED
),
17038 (unsigned int)CONST_WIDE_INT_NUNITS (rtl
) * HOST_BITS_PER_WIDE_INT
);
17039 wide_int w
= wi::zext (w1
, prec
);
17040 add_AT_wide (die
, DW_AT_const_value
, w
);
17045 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
17046 floating-point constant. A CONST_DOUBLE is used whenever the
17047 constant requires more than one word in order to be adequately
17050 machine_mode mode
= GET_MODE (rtl
);
17052 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
17053 add_AT_double (die
, DW_AT_const_value
,
17054 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
17057 unsigned int length
= GET_MODE_SIZE (mode
);
17058 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
17060 insert_float (rtl
, array
);
17061 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
17068 machine_mode mode
= GET_MODE (rtl
);
17069 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
17070 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
17071 unsigned char *array
17072 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
17075 machine_mode imode
= GET_MODE_INNER (mode
);
17077 switch (GET_MODE_CLASS (mode
))
17079 case MODE_VECTOR_INT
:
17080 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
17082 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
17083 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
17087 case MODE_VECTOR_FLOAT
:
17088 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
17090 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
17091 insert_float (elt
, p
);
17096 gcc_unreachable ();
17099 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
17104 if (dwarf_version
>= 4 || !dwarf_strict
)
17106 dw_loc_descr_ref loc_result
;
17107 resolve_one_addr (&rtl
);
17109 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
17110 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
17111 add_AT_loc (die
, DW_AT_location
, loc_result
);
17112 vec_safe_push (used_rtx_array
, rtl
);
17118 if (CONSTANT_P (XEXP (rtl
, 0)))
17119 return add_const_value_attribute (die
, XEXP (rtl
, 0));
17122 if (!const_ok_for_output (rtl
))
17125 if (dwarf_version
>= 4 || !dwarf_strict
)
17130 /* In cases where an inlined instance of an inline function is passed
17131 the address of an `auto' variable (which is local to the caller) we
17132 can get a situation where the DECL_RTL of the artificial local
17133 variable (for the inlining) which acts as a stand-in for the
17134 corresponding formal parameter (of the inline function) will look
17135 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
17136 exactly a compile-time constant expression, but it isn't the address
17137 of the (artificial) local variable either. Rather, it represents the
17138 *value* which the artificial local variable always has during its
17139 lifetime. We currently have no way to represent such quasi-constant
17140 values in Dwarf, so for now we just punt and generate nothing. */
17148 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
17149 && MEM_READONLY_P (rtl
)
17150 && GET_MODE (rtl
) == BLKmode
)
17152 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
17158 /* No other kinds of rtx should be possible here. */
17159 gcc_unreachable ();
17164 /* Determine whether the evaluation of EXPR references any variables
17165 or functions which aren't otherwise used (and therefore may not be
17168 reference_to_unused (tree
* tp
, int * walk_subtrees
,
17169 void * data ATTRIBUTE_UNUSED
)
17171 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
17172 *walk_subtrees
= 0;
17174 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
17175 && ! TREE_ASM_WRITTEN (*tp
))
17177 /* ??? The C++ FE emits debug information for using decls, so
17178 putting gcc_unreachable here falls over. See PR31899. For now
17179 be conservative. */
17180 else if (!symtab
->global_info_ready
17181 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
17183 else if (TREE_CODE (*tp
) == VAR_DECL
)
17185 varpool_node
*node
= varpool_node::get (*tp
);
17186 if (!node
|| !node
->definition
)
17189 else if (TREE_CODE (*tp
) == FUNCTION_DECL
17190 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
17192 /* The call graph machinery must have finished analyzing,
17193 optimizing and gimplifying the CU by now.
17194 So if *TP has no call graph node associated
17195 to it, it means *TP will not be emitted. */
17196 if (!cgraph_node::get (*tp
))
17199 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
17205 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
17206 for use in a later add_const_value_attribute call. */
17209 rtl_for_decl_init (tree init
, tree type
)
17211 rtx rtl
= NULL_RTX
;
17215 /* If a variable is initialized with a string constant without embedded
17216 zeros, build CONST_STRING. */
17217 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
17219 tree enttype
= TREE_TYPE (type
);
17220 tree domain
= TYPE_DOMAIN (type
);
17221 machine_mode mode
= TYPE_MODE (enttype
);
17223 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
17225 && integer_zerop (TYPE_MIN_VALUE (domain
))
17226 && compare_tree_int (TYPE_MAX_VALUE (domain
),
17227 TREE_STRING_LENGTH (init
) - 1) == 0
17228 && ((size_t) TREE_STRING_LENGTH (init
)
17229 == strlen (TREE_STRING_POINTER (init
)) + 1))
17231 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
17232 ggc_strdup (TREE_STRING_POINTER (init
)));
17233 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
17234 MEM_READONLY_P (rtl
) = 1;
17237 /* Other aggregates, and complex values, could be represented using
17239 else if (AGGREGATE_TYPE_P (type
)
17240 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
17241 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
17242 || TREE_CODE (type
) == COMPLEX_TYPE
)
17244 /* Vectors only work if their mode is supported by the target.
17245 FIXME: generic vectors ought to work too. */
17246 else if (TREE_CODE (type
) == VECTOR_TYPE
17247 && !VECTOR_MODE_P (TYPE_MODE (type
)))
17249 /* If the initializer is something that we know will expand into an
17250 immediate RTL constant, expand it now. We must be careful not to
17251 reference variables which won't be output. */
17252 else if (initializer_constant_valid_p (init
, type
)
17253 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
17255 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
17257 if (TREE_CODE (type
) == VECTOR_TYPE
)
17258 switch (TREE_CODE (init
))
17263 if (TREE_CONSTANT (init
))
17265 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
17266 bool constant_p
= true;
17268 unsigned HOST_WIDE_INT ix
;
17270 /* Even when ctor is constant, it might contain non-*_CST
17271 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
17272 belong into VECTOR_CST nodes. */
17273 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
17274 if (!CONSTANT_CLASS_P (value
))
17276 constant_p
= false;
17282 init
= build_vector_from_ctor (type
, elts
);
17292 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
17294 /* If expand_expr returns a MEM, it wasn't immediate. */
17295 gcc_assert (!rtl
|| !MEM_P (rtl
));
17301 /* Generate RTL for the variable DECL to represent its location. */
17304 rtl_for_decl_location (tree decl
)
17308 /* Here we have to decide where we are going to say the parameter "lives"
17309 (as far as the debugger is concerned). We only have a couple of
17310 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
17312 DECL_RTL normally indicates where the parameter lives during most of the
17313 activation of the function. If optimization is enabled however, this
17314 could be either NULL or else a pseudo-reg. Both of those cases indicate
17315 that the parameter doesn't really live anywhere (as far as the code
17316 generation parts of GCC are concerned) during most of the function's
17317 activation. That will happen (for example) if the parameter is never
17318 referenced within the function.
17320 We could just generate a location descriptor here for all non-NULL
17321 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
17322 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
17323 where DECL_RTL is NULL or is a pseudo-reg.
17325 Note however that we can only get away with using DECL_INCOMING_RTL as
17326 a backup substitute for DECL_RTL in certain limited cases. In cases
17327 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
17328 we can be sure that the parameter was passed using the same type as it is
17329 declared to have within the function, and that its DECL_INCOMING_RTL
17330 points us to a place where a value of that type is passed.
17332 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
17333 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
17334 because in these cases DECL_INCOMING_RTL points us to a value of some
17335 type which is *different* from the type of the parameter itself. Thus,
17336 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
17337 such cases, the debugger would end up (for example) trying to fetch a
17338 `float' from a place which actually contains the first part of a
17339 `double'. That would lead to really incorrect and confusing
17340 output at debug-time.
17342 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
17343 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
17344 are a couple of exceptions however. On little-endian machines we can
17345 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
17346 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
17347 an integral type that is smaller than TREE_TYPE (decl). These cases arise
17348 when (on a little-endian machine) a non-prototyped function has a
17349 parameter declared to be of type `short' or `char'. In such cases,
17350 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
17351 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
17352 passed `int' value. If the debugger then uses that address to fetch
17353 a `short' or a `char' (on a little-endian machine) the result will be
17354 the correct data, so we allow for such exceptional cases below.
17356 Note that our goal here is to describe the place where the given formal
17357 parameter lives during most of the function's activation (i.e. between the
17358 end of the prologue and the start of the epilogue). We'll do that as best
17359 as we can. Note however that if the given formal parameter is modified
17360 sometime during the execution of the function, then a stack backtrace (at
17361 debug-time) will show the function as having been called with the *new*
17362 value rather than the value which was originally passed in. This happens
17363 rarely enough that it is not a major problem, but it *is* a problem, and
17364 I'd like to fix it.
17366 A future version of dwarf2out.c may generate two additional attributes for
17367 any given DW_TAG_formal_parameter DIE which will describe the "passed
17368 type" and the "passed location" for the given formal parameter in addition
17369 to the attributes we now generate to indicate the "declared type" and the
17370 "active location" for each parameter. This additional set of attributes
17371 could be used by debuggers for stack backtraces. Separately, note that
17372 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
17373 This happens (for example) for inlined-instances of inline function formal
17374 parameters which are never referenced. This really shouldn't be
17375 happening. All PARM_DECL nodes should get valid non-NULL
17376 DECL_INCOMING_RTL values. FIXME. */
17378 /* Use DECL_RTL as the "location" unless we find something better. */
17379 rtl
= DECL_RTL_IF_SET (decl
);
17381 /* When generating abstract instances, ignore everything except
17382 constants, symbols living in memory, and symbols living in
17383 fixed registers. */
17384 if (! reload_completed
)
17387 && (CONSTANT_P (rtl
)
17389 && CONSTANT_P (XEXP (rtl
, 0)))
17391 && TREE_CODE (decl
) == VAR_DECL
17392 && TREE_STATIC (decl
))))
17394 rtl
= targetm
.delegitimize_address (rtl
);
17399 else if (TREE_CODE (decl
) == PARM_DECL
)
17401 if (rtl
== NULL_RTX
17402 || is_pseudo_reg (rtl
)
17404 && is_pseudo_reg (XEXP (rtl
, 0))
17405 && DECL_INCOMING_RTL (decl
)
17406 && MEM_P (DECL_INCOMING_RTL (decl
))
17407 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
17409 tree declared_type
= TREE_TYPE (decl
);
17410 tree passed_type
= DECL_ARG_TYPE (decl
);
17411 machine_mode dmode
= TYPE_MODE (declared_type
);
17412 machine_mode pmode
= TYPE_MODE (passed_type
);
17414 /* This decl represents a formal parameter which was optimized out.
17415 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
17416 all cases where (rtl == NULL_RTX) just below. */
17417 if (dmode
== pmode
)
17418 rtl
= DECL_INCOMING_RTL (decl
);
17419 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
17420 && SCALAR_INT_MODE_P (dmode
)
17421 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
17422 && DECL_INCOMING_RTL (decl
))
17424 rtx inc
= DECL_INCOMING_RTL (decl
);
17427 else if (MEM_P (inc
))
17429 if (BYTES_BIG_ENDIAN
)
17430 rtl
= adjust_address_nv (inc
, dmode
,
17431 GET_MODE_SIZE (pmode
)
17432 - GET_MODE_SIZE (dmode
));
17439 /* If the parm was passed in registers, but lives on the stack, then
17440 make a big endian correction if the mode of the type of the
17441 parameter is not the same as the mode of the rtl. */
17442 /* ??? This is the same series of checks that are made in dbxout.c before
17443 we reach the big endian correction code there. It isn't clear if all
17444 of these checks are necessary here, but keeping them all is the safe
17446 else if (MEM_P (rtl
)
17447 && XEXP (rtl
, 0) != const0_rtx
17448 && ! CONSTANT_P (XEXP (rtl
, 0))
17449 /* Not passed in memory. */
17450 && !MEM_P (DECL_INCOMING_RTL (decl
))
17451 /* Not passed by invisible reference. */
17452 && (!REG_P (XEXP (rtl
, 0))
17453 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
17454 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
17455 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
17456 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
17459 /* Big endian correction check. */
17460 && BYTES_BIG_ENDIAN
17461 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
17462 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
17465 machine_mode addr_mode
= get_address_mode (rtl
);
17466 int offset
= (UNITS_PER_WORD
17467 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
17469 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
17470 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
17473 else if (TREE_CODE (decl
) == VAR_DECL
17476 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
17477 && BYTES_BIG_ENDIAN
)
17479 machine_mode addr_mode
= get_address_mode (rtl
);
17480 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
17481 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
17483 /* If a variable is declared "register" yet is smaller than
17484 a register, then if we store the variable to memory, it
17485 looks like we're storing a register-sized value, when in
17486 fact we are not. We need to adjust the offset of the
17487 storage location to reflect the actual value's bytes,
17488 else gdb will not be able to display it. */
17490 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
17491 plus_constant (addr_mode
, XEXP (rtl
, 0),
17495 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
17496 and will have been substituted directly into all expressions that use it.
17497 C does not have such a concept, but C++ and other languages do. */
17498 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
17499 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
17502 rtl
= targetm
.delegitimize_address (rtl
);
17504 /* If we don't look past the constant pool, we risk emitting a
17505 reference to a constant pool entry that isn't referenced from
17506 code, and thus is not emitted. */
17508 rtl
= avoid_constant_pool_reference (rtl
);
17510 /* Try harder to get a rtl. If this symbol ends up not being emitted
17511 in the current CU, resolve_addr will remove the expression referencing
17513 if (rtl
== NULL_RTX
17514 && TREE_CODE (decl
) == VAR_DECL
17515 && !DECL_EXTERNAL (decl
)
17516 && TREE_STATIC (decl
)
17517 && DECL_NAME (decl
)
17518 && !DECL_HARD_REGISTER (decl
)
17519 && DECL_MODE (decl
) != VOIDmode
)
17521 rtl
= make_decl_rtl_for_debug (decl
);
17523 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
17524 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
17531 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
17532 returned. If so, the decl for the COMMON block is returned, and the
17533 value is the offset into the common block for the symbol. */
17536 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
17538 tree val_expr
, cvar
;
17540 HOST_WIDE_INT bitsize
, bitpos
;
17542 int unsignedp
, reversep
, volatilep
= 0;
17544 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
17545 it does not have a value (the offset into the common area), or if it
17546 is thread local (as opposed to global) then it isn't common, and shouldn't
17547 be handled as such. */
17548 if (TREE_CODE (decl
) != VAR_DECL
17549 || !TREE_STATIC (decl
)
17550 || !DECL_HAS_VALUE_EXPR_P (decl
)
17554 val_expr
= DECL_VALUE_EXPR (decl
);
17555 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
17558 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
, &mode
,
17559 &unsignedp
, &reversep
, &volatilep
, true);
17561 if (cvar
== NULL_TREE
17562 || TREE_CODE (cvar
) != VAR_DECL
17563 || DECL_ARTIFICIAL (cvar
)
17564 || !TREE_PUBLIC (cvar
))
17568 if (offset
!= NULL
)
17570 if (!tree_fits_shwi_p (offset
))
17572 *value
= tree_to_shwi (offset
);
17575 *value
+= bitpos
/ BITS_PER_UNIT
;
17580 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
17581 data attribute for a variable or a parameter. We generate the
17582 DW_AT_const_value attribute only in those cases where the given variable
17583 or parameter does not have a true "location" either in memory or in a
17584 register. This can happen (for example) when a constant is passed as an
17585 actual argument in a call to an inline function. (It's possible that
17586 these things can crop up in other ways also.) Note that one type of
17587 constant value which can be passed into an inlined function is a constant
17588 pointer. This can happen for example if an actual argument in an inlined
17589 function call evaluates to a compile-time constant address.
17591 CACHE_P is true if it is worth caching the location list for DECL,
17592 so that future calls can reuse it rather than regenerate it from scratch.
17593 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
17594 since we will need to refer to them each time the function is inlined. */
17597 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
)
17600 dw_loc_list_ref list
;
17601 var_loc_list
*loc_list
;
17602 cached_dw_loc_list
*cache
;
17607 if (TREE_CODE (decl
) == ERROR_MARK
)
17610 if (get_AT (die
, DW_AT_location
)
17611 || get_AT (die
, DW_AT_const_value
))
17614 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
17615 || TREE_CODE (decl
) == RESULT_DECL
);
17617 /* Try to get some constant RTL for this decl, and use that as the value of
17620 rtl
= rtl_for_decl_location (decl
);
17621 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
17622 && add_const_value_attribute (die
, rtl
))
17625 /* See if we have single element location list that is equivalent to
17626 a constant value. That way we are better to use add_const_value_attribute
17627 rather than expanding constant value equivalent. */
17628 loc_list
= lookup_decl_loc (decl
);
17631 && loc_list
->first
->next
== NULL
17632 && NOTE_P (loc_list
->first
->loc
)
17633 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
17634 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
17636 struct var_loc_node
*node
;
17638 node
= loc_list
->first
;
17639 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
17640 if (GET_CODE (rtl
) == EXPR_LIST
)
17641 rtl
= XEXP (rtl
, 0);
17642 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
17643 && add_const_value_attribute (die
, rtl
))
17646 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
17647 list several times. See if we've already cached the contents. */
17649 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
17653 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
17655 list
= cache
->loc_list
;
17659 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
17661 /* It is usually worth caching this result if the decl is from
17662 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
17663 if (cache_p
&& list
&& list
->dw_loc_next
)
17665 cached_dw_loc_list
**slot
17666 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
17669 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
17670 cache
->decl_id
= DECL_UID (decl
);
17671 cache
->loc_list
= list
;
17677 add_AT_location_description (die
, DW_AT_location
, list
);
17680 /* None of that worked, so it must not really have a location;
17681 try adding a constant value attribute from the DECL_INITIAL. */
17682 return tree_add_const_value_attribute_for_decl (die
, decl
);
17685 /* Helper function for tree_add_const_value_attribute. Natively encode
17686 initializer INIT into an array. Return true if successful. */
17689 native_encode_initializer (tree init
, unsigned char *array
, int size
)
17693 if (init
== NULL_TREE
)
17697 switch (TREE_CODE (init
))
17700 type
= TREE_TYPE (init
);
17701 if (TREE_CODE (type
) == ARRAY_TYPE
)
17703 tree enttype
= TREE_TYPE (type
);
17704 machine_mode mode
= TYPE_MODE (enttype
);
17706 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
17708 if (int_size_in_bytes (type
) != size
)
17710 if (size
> TREE_STRING_LENGTH (init
))
17712 memcpy (array
, TREE_STRING_POINTER (init
),
17713 TREE_STRING_LENGTH (init
));
17714 memset (array
+ TREE_STRING_LENGTH (init
),
17715 '\0', size
- TREE_STRING_LENGTH (init
));
17718 memcpy (array
, TREE_STRING_POINTER (init
), size
);
17723 type
= TREE_TYPE (init
);
17724 if (int_size_in_bytes (type
) != size
)
17726 if (TREE_CODE (type
) == ARRAY_TYPE
)
17728 HOST_WIDE_INT min_index
;
17729 unsigned HOST_WIDE_INT cnt
;
17730 int curpos
= 0, fieldsize
;
17731 constructor_elt
*ce
;
17733 if (TYPE_DOMAIN (type
) == NULL_TREE
17734 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
17737 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
17738 if (fieldsize
<= 0)
17741 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
17742 memset (array
, '\0', size
);
17743 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
17745 tree val
= ce
->value
;
17746 tree index
= ce
->index
;
17748 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
17749 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
17752 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
17757 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
17760 curpos
= pos
+ fieldsize
;
17761 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
17763 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
17764 - tree_to_shwi (TREE_OPERAND (index
, 0));
17765 while (count
-- > 0)
17768 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
17769 curpos
+= fieldsize
;
17772 gcc_assert (curpos
<= size
);
17776 else if (TREE_CODE (type
) == RECORD_TYPE
17777 || TREE_CODE (type
) == UNION_TYPE
)
17779 tree field
= NULL_TREE
;
17780 unsigned HOST_WIDE_INT cnt
;
17781 constructor_elt
*ce
;
17783 if (int_size_in_bytes (type
) != size
)
17786 if (TREE_CODE (type
) == RECORD_TYPE
)
17787 field
= TYPE_FIELDS (type
);
17789 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
17791 tree val
= ce
->value
;
17792 int pos
, fieldsize
;
17794 if (ce
->index
!= 0)
17800 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
17803 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
17804 && TYPE_DOMAIN (TREE_TYPE (field
))
17805 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
17807 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
17808 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
17810 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
17811 pos
= int_byte_position (field
);
17812 gcc_assert (pos
+ fieldsize
<= size
);
17813 if (val
&& fieldsize
!= 0
17814 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
17820 case VIEW_CONVERT_EXPR
:
17821 case NON_LVALUE_EXPR
:
17822 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
17824 return native_encode_expr (init
, array
, size
) == size
;
17828 /* Attach a DW_AT_const_value attribute to DIE. The value of the
17829 attribute is the const value T. */
17832 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
17835 tree type
= TREE_TYPE (t
);
17838 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
17842 gcc_assert (!DECL_P (init
));
17844 rtl
= rtl_for_decl_init (init
, type
);
17846 return add_const_value_attribute (die
, rtl
);
17847 /* If the host and target are sane, try harder. */
17848 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
17849 && initializer_constant_valid_p (init
, type
))
17851 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
17852 if (size
> 0 && (int) size
== size
)
17854 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
17856 if (native_encode_initializer (init
, array
, size
))
17858 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
17867 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
17868 attribute is the const value of T, where T is an integral constant
17869 variable with static storage duration
17870 (so it can't be a PARM_DECL or a RESULT_DECL). */
17873 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
17877 || (TREE_CODE (decl
) != VAR_DECL
17878 && TREE_CODE (decl
) != CONST_DECL
)
17879 || (TREE_CODE (decl
) == VAR_DECL
17880 && !TREE_STATIC (decl
)))
17883 if (TREE_READONLY (decl
)
17884 && ! TREE_THIS_VOLATILE (decl
)
17885 && DECL_INITIAL (decl
))
17890 /* Don't add DW_AT_const_value if abstract origin already has one. */
17891 if (get_AT (var_die
, DW_AT_const_value
))
17894 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
17897 /* Convert the CFI instructions for the current function into a
17898 location list. This is used for DW_AT_frame_base when we targeting
17899 a dwarf2 consumer that does not support the dwarf3
17900 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
17903 static dw_loc_list_ref
17904 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
17908 dw_loc_list_ref list
, *list_tail
;
17910 dw_cfa_location last_cfa
, next_cfa
;
17911 const char *start_label
, *last_label
, *section
;
17912 dw_cfa_location remember
;
17915 gcc_assert (fde
!= NULL
);
17917 section
= secname_for_decl (current_function_decl
);
17921 memset (&next_cfa
, 0, sizeof (next_cfa
));
17922 next_cfa
.reg
= INVALID_REGNUM
;
17923 remember
= next_cfa
;
17925 start_label
= fde
->dw_fde_begin
;
17927 /* ??? Bald assumption that the CIE opcode list does not contain
17928 advance opcodes. */
17929 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
17930 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
17932 last_cfa
= next_cfa
;
17933 last_label
= start_label
;
17935 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
17937 /* If the first partition contained no CFI adjustments, the
17938 CIE opcodes apply to the whole first partition. */
17939 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17940 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
17941 list_tail
=&(*list_tail
)->dw_loc_next
;
17942 start_label
= last_label
= fde
->dw_fde_second_begin
;
17945 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
17947 switch (cfi
->dw_cfi_opc
)
17949 case DW_CFA_set_loc
:
17950 case DW_CFA_advance_loc1
:
17951 case DW_CFA_advance_loc2
:
17952 case DW_CFA_advance_loc4
:
17953 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17955 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17956 start_label
, last_label
, section
);
17958 list_tail
= &(*list_tail
)->dw_loc_next
;
17959 last_cfa
= next_cfa
;
17960 start_label
= last_label
;
17962 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
17965 case DW_CFA_advance_loc
:
17966 /* The encoding is complex enough that we should never emit this. */
17967 gcc_unreachable ();
17970 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
17973 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
17975 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17977 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17978 start_label
, last_label
, section
);
17980 list_tail
= &(*list_tail
)->dw_loc_next
;
17981 last_cfa
= next_cfa
;
17982 start_label
= last_label
;
17984 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17985 start_label
, fde
->dw_fde_end
, section
);
17986 list_tail
= &(*list_tail
)->dw_loc_next
;
17987 start_label
= last_label
= fde
->dw_fde_second_begin
;
17991 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
17993 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
17994 start_label
, last_label
, section
);
17995 list_tail
= &(*list_tail
)->dw_loc_next
;
17996 start_label
= last_label
;
17999 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
18001 fde
->dw_fde_second_begin
18002 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
18005 if (list
&& list
->dw_loc_next
)
18011 /* Compute a displacement from the "steady-state frame pointer" to the
18012 frame base (often the same as the CFA), and store it in
18013 frame_pointer_fb_offset. OFFSET is added to the displacement
18014 before the latter is negated. */
18017 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
18021 #ifdef FRAME_POINTER_CFA_OFFSET
18022 reg
= frame_pointer_rtx
;
18023 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
18025 reg
= arg_pointer_rtx
;
18026 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
18029 elim
= (ira_use_lra_p
18030 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
18031 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
18032 if (GET_CODE (elim
) == PLUS
)
18034 offset
+= INTVAL (XEXP (elim
, 1));
18035 elim
= XEXP (elim
, 0);
18038 frame_pointer_fb_offset
= -offset
;
18040 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
18041 in which to eliminate. This is because it's stack pointer isn't
18042 directly accessible as a register within the ISA. To work around
18043 this, assume that while we cannot provide a proper value for
18044 frame_pointer_fb_offset, we won't need one either. */
18045 frame_pointer_fb_offset_valid
18046 = ((SUPPORTS_STACK_ALIGNMENT
18047 && (elim
== hard_frame_pointer_rtx
18048 || elim
== stack_pointer_rtx
))
18049 || elim
== (frame_pointer_needed
18050 ? hard_frame_pointer_rtx
18051 : stack_pointer_rtx
));
18054 /* Generate a DW_AT_name attribute given some string value to be included as
18055 the value of the attribute. */
18058 add_name_attribute (dw_die_ref die
, const char *name_string
)
18060 if (name_string
!= NULL
&& *name_string
!= 0)
18062 if (demangle_name_func
)
18063 name_string
= (*demangle_name_func
) (name_string
);
18065 add_AT_string (die
, DW_AT_name
, name_string
);
18069 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
18070 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
18071 of TYPE accordingly.
18073 ??? This is a temporary measure until after we're able to generate
18074 regular DWARF for the complex Ada type system. */
18077 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
18078 dw_die_ref context_die
)
18081 dw_die_ref dtype_die
;
18083 if (!lang_hooks
.types
.descriptive_type
)
18086 dtype
= lang_hooks
.types
.descriptive_type (type
);
18090 dtype_die
= lookup_type_die (dtype
);
18093 gen_type_die (dtype
, context_die
);
18094 dtype_die
= lookup_type_die (dtype
);
18095 gcc_assert (dtype_die
);
18098 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
18101 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
18103 static const char *
18104 comp_dir_string (void)
18108 static const char *cached_wd
= NULL
;
18110 if (cached_wd
!= NULL
)
18113 wd
= get_src_pwd ();
18117 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
18121 wdlen
= strlen (wd
);
18122 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
18124 wd1
[wdlen
] = DIR_SEPARATOR
;
18125 wd1
[wdlen
+ 1] = 0;
18129 cached_wd
= remap_debug_filename (wd
);
18133 /* Generate a DW_AT_comp_dir attribute for DIE. */
18136 add_comp_dir_attribute (dw_die_ref die
)
18138 const char * wd
= comp_dir_string ();
18140 add_AT_string (die
, DW_AT_comp_dir
, wd
);
18143 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
18144 pointer computation, ...), output a representation for that bound according
18145 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
18146 loc_list_from_tree for the meaning of CONTEXT. */
18149 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
18150 int forms
, const struct loc_descr_context
*context
)
18152 dw_die_ref context_die
, decl_die
;
18153 dw_loc_list_ref list
;
18155 bool strip_conversions
= true;
18157 while (strip_conversions
)
18158 switch (TREE_CODE (value
))
18165 case VIEW_CONVERT_EXPR
:
18166 value
= TREE_OPERAND (value
, 0);
18170 strip_conversions
= false;
18174 /* If possible and permitted, output the attribute as a constant. */
18175 if ((forms
& dw_scalar_form_constant
) != 0
18176 && TREE_CODE (value
) == INTEGER_CST
)
18178 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
18180 /* If HOST_WIDE_INT is big enough then represent the bound as
18181 a constant value. We need to choose a form based on
18182 whether the type is signed or unsigned. We cannot just
18183 call add_AT_unsigned if the value itself is positive
18184 (add_AT_unsigned might add the unsigned value encoded as
18185 DW_FORM_data[1248]). Some DWARF consumers will lookup the
18186 bounds type and then sign extend any unsigned values found
18187 for signed types. This is needed only for
18188 DW_AT_{lower,upper}_bound, since for most other attributes,
18189 consumers will treat DW_FORM_data[1248] as unsigned values,
18190 regardless of the underlying type. */
18191 if (prec
<= HOST_BITS_PER_WIDE_INT
18192 || tree_fits_uhwi_p (value
))
18194 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
18195 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
18197 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
18200 /* Otherwise represent the bound as an unsigned value with
18201 the precision of its type. The precision and signedness
18202 of the type will be necessary to re-interpret it
18204 add_AT_wide (die
, attr
, value
);
18208 /* Otherwise, if it's possible and permitted too, output a reference to
18210 if ((forms
& dw_scalar_form_reference
) != 0)
18212 tree decl
= NULL_TREE
;
18214 /* Some type attributes reference an outer type. For instance, the upper
18215 bound of an array may reference an embedding record (this happens in
18217 if (TREE_CODE (value
) == COMPONENT_REF
18218 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
18219 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
18220 decl
= TREE_OPERAND (value
, 1);
18222 else if (TREE_CODE (value
) == VAR_DECL
18223 || TREE_CODE (value
) == PARM_DECL
18224 || TREE_CODE (value
) == RESULT_DECL
)
18227 if (decl
!= NULL_TREE
)
18229 dw_die_ref decl_die
= lookup_decl_die (decl
);
18231 /* ??? Can this happen, or should the variable have been bound
18232 first? Probably it can, since I imagine that we try to create
18233 the types of parameters in the order in which they exist in
18234 the list, and won't have created a forward reference to a
18235 later parameter. */
18236 if (decl_die
!= NULL
)
18238 add_AT_die_ref (die
, attr
, decl_die
);
18244 /* Last chance: try to create a stack operation procedure to evaluate the
18245 value. Do nothing if even that is not possible or permitted. */
18246 if ((forms
& dw_scalar_form_exprloc
) == 0)
18249 list
= loc_list_from_tree (value
, 2, context
);
18250 if (list
== NULL
|| single_element_loc_list_p (list
))
18252 /* If this attribute is not a reference nor constant, it is
18253 a DWARF expression rather than location description. For that
18254 loc_list_from_tree (value, 0, &context) is needed. */
18255 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
18256 if (list2
&& single_element_loc_list_p (list2
))
18258 add_AT_loc (die
, attr
, list2
->expr
);
18263 /* If that failed to give a single element location list, fall back to
18264 outputting this as a reference... still if permitted. */
18265 if (list
== NULL
|| (forms
& dw_scalar_form_reference
) == 0)
18268 if (current_function_decl
== 0)
18269 context_die
= comp_unit_die ();
18271 context_die
= lookup_decl_die (current_function_decl
);
18273 decl_die
= new_die (DW_TAG_variable
, context_die
, value
);
18274 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18275 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, false,
18277 add_AT_location_description (decl_die
, DW_AT_location
, list
);
18278 add_AT_die_ref (die
, attr
, decl_die
);
18281 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
18285 lower_bound_default (void)
18287 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
18293 case DW_LANG_C_plus_plus
:
18294 case DW_LANG_C_plus_plus_11
:
18295 case DW_LANG_C_plus_plus_14
:
18297 case DW_LANG_ObjC_plus_plus
:
18300 case DW_LANG_Fortran77
:
18301 case DW_LANG_Fortran90
:
18302 case DW_LANG_Fortran95
:
18303 case DW_LANG_Fortran03
:
18304 case DW_LANG_Fortran08
:
18308 case DW_LANG_Python
:
18309 return dwarf_version
>= 4 ? 0 : -1;
18310 case DW_LANG_Ada95
:
18311 case DW_LANG_Ada83
:
18312 case DW_LANG_Cobol74
:
18313 case DW_LANG_Cobol85
:
18314 case DW_LANG_Pascal83
:
18315 case DW_LANG_Modula2
:
18317 return dwarf_version
>= 4 ? 1 : -1;
18323 /* Given a tree node describing an array bound (either lower or upper) output
18324 a representation for that bound. */
18327 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
18328 tree bound
, const struct loc_descr_context
*context
)
18333 switch (TREE_CODE (bound
))
18335 /* Strip all conversions. */
18337 case VIEW_CONVERT_EXPR
:
18338 bound
= TREE_OPERAND (bound
, 0);
18341 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
18342 are even omitted when they are the default. */
18344 /* If the value for this bound is the default one, we can even omit the
18346 if (bound_attr
== DW_AT_lower_bound
18347 && tree_fits_shwi_p (bound
)
18348 && (dflt
= lower_bound_default ()) != -1
18349 && tree_to_shwi (bound
) == dflt
)
18355 /* Because of the complex interaction there can be with other GNAT
18356 encodings, GDB isn't ready yet to handle proper DWARF description
18357 for self-referencial subrange bounds: let GNAT encodings do the
18358 magic in such a case. */
18359 if (gnat_encodings
!= DWARF_GNAT_ENCODINGS_MINIMAL
18360 && contains_placeholder_p (bound
))
18363 add_scalar_info (subrange_die
, bound_attr
, bound
,
18364 dw_scalar_form_constant
18365 | dw_scalar_form_exprloc
18366 | dw_scalar_form_reference
,
18372 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
18373 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
18374 Note that the block of subscript information for an array type also
18375 includes information about the element type of the given array type.
18377 This function reuses previously set type and bound information if
18381 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
18383 unsigned dimension_number
;
18385 dw_die_ref child
= type_die
->die_child
;
18387 for (dimension_number
= 0;
18388 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
18389 type
= TREE_TYPE (type
), dimension_number
++)
18391 tree domain
= TYPE_DOMAIN (type
);
18393 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
18396 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
18397 and (in GNU C only) variable bounds. Handle all three forms
18400 /* Find and reuse a previously generated DW_TAG_subrange_type if
18403 For multi-dimensional arrays, as we iterate through the
18404 various dimensions in the enclosing for loop above, we also
18405 iterate through the DIE children and pick at each
18406 DW_TAG_subrange_type previously generated (if available).
18407 Each child DW_TAG_subrange_type DIE describes the range of
18408 the current dimension. At this point we should have as many
18409 DW_TAG_subrange_type's as we have dimensions in the
18411 dw_die_ref subrange_die
= NULL
;
18415 child
= child
->die_sib
;
18416 if (child
->die_tag
== DW_TAG_subrange_type
)
18417 subrange_die
= child
;
18418 if (child
== type_die
->die_child
)
18420 /* If we wrapped around, stop looking next time. */
18424 if (child
->die_tag
== DW_TAG_subrange_type
)
18428 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
18432 /* We have an array type with specified bounds. */
18433 lower
= TYPE_MIN_VALUE (domain
);
18434 upper
= TYPE_MAX_VALUE (domain
);
18436 /* Define the index type. */
18437 if (TREE_TYPE (domain
)
18438 && !get_AT (subrange_die
, DW_AT_type
))
18440 /* ??? This is probably an Ada unnamed subrange type. Ignore the
18441 TREE_TYPE field. We can't emit debug info for this
18442 because it is an unnamed integral type. */
18443 if (TREE_CODE (domain
) == INTEGER_TYPE
18444 && TYPE_NAME (domain
) == NULL_TREE
18445 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
18446 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
18449 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
18450 TYPE_UNQUALIFIED
, false, type_die
);
18453 /* ??? If upper is NULL, the array has unspecified length,
18454 but it does have a lower bound. This happens with Fortran
18456 Since the debugger is definitely going to need to know N
18457 to produce useful results, go ahead and output the lower
18458 bound solo, and hope the debugger can cope. */
18460 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
18461 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
18462 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
18463 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
18466 /* Otherwise we have an array type with an unspecified length. The
18467 DWARF-2 spec does not say how to handle this; let's just leave out the
18472 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
18475 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
18477 dw_die_ref decl_die
;
18478 HOST_WIDE_INT size
;
18479 dw_loc_descr_ref size_expr
= NULL
;
18481 switch (TREE_CODE (tree_node
))
18486 case ENUMERAL_TYPE
:
18489 case QUAL_UNION_TYPE
:
18490 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
18491 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
18493 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
18496 size_expr
= type_byte_size (tree_node
, &size
);
18499 /* For a data member of a struct or union, the DW_AT_byte_size is
18500 generally given as the number of bytes normally allocated for an
18501 object of the *declared* type of the member itself. This is true
18502 even for bit-fields. */
18503 size
= int_size_in_bytes (field_type (tree_node
));
18506 gcc_unreachable ();
18509 /* Support for dynamically-sized objects was introduced by DWARFv3.
18510 At the moment, GDB does not handle variable byte sizes very well,
18512 if ((dwarf_version
>= 3 || !dwarf_strict
)
18513 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
18514 && size_expr
!= NULL
)
18515 add_AT_loc (die
, DW_AT_byte_size
, size_expr
);
18517 /* Note that `size' might be -1 when we get to this point. If it is, that
18518 indicates that the byte size of the entity in question is variable and
18519 that we could not generate a DWARF expression that computes it. */
18521 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
18524 /* For a FIELD_DECL node which represents a bit-field, output an attribute
18525 which specifies the distance in bits from the highest order bit of the
18526 "containing object" for the bit-field to the highest order bit of the
18529 For any given bit-field, the "containing object" is a hypothetical object
18530 (of some integral or enum type) within which the given bit-field lives. The
18531 type of this hypothetical "containing object" is always the same as the
18532 declared type of the individual bit-field itself. The determination of the
18533 exact location of the "containing object" for a bit-field is rather
18534 complicated. It's handled by the `field_byte_offset' function (above).
18536 CTX is required: see the comment for VLR_CONTEXT.
18538 Note that it is the size (in bytes) of the hypothetical "containing object"
18539 which will be given in the DW_AT_byte_size attribute for this bit-field.
18540 (See `byte_size_attribute' above). */
18543 add_bit_offset_attribute (dw_die_ref die
, tree decl
, struct vlr_context
*ctx
)
18545 HOST_WIDE_INT object_offset_in_bytes
;
18546 tree original_type
= DECL_BIT_FIELD_TYPE (decl
);
18547 HOST_WIDE_INT bitpos_int
;
18548 HOST_WIDE_INT highest_order_object_bit_offset
;
18549 HOST_WIDE_INT highest_order_field_bit_offset
;
18550 HOST_WIDE_INT bit_offset
;
18552 field_byte_offset (decl
, ctx
, &object_offset_in_bytes
);
18554 /* Must be a field and a bit field. */
18555 gcc_assert (original_type
&& TREE_CODE (decl
) == FIELD_DECL
);
18557 /* We can't yet handle bit-fields whose offsets are variable, so if we
18558 encounter such things, just return without generating any attribute
18559 whatsoever. Likewise for variable or too large size. */
18560 if (! tree_fits_shwi_p (bit_position (decl
))
18561 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
18564 bitpos_int
= int_bit_position (decl
);
18566 /* Note that the bit offset is always the distance (in bits) from the
18567 highest-order bit of the "containing object" to the highest-order bit of
18568 the bit-field itself. Since the "high-order end" of any object or field
18569 is different on big-endian and little-endian machines, the computation
18570 below must take account of these differences. */
18571 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
18572 highest_order_field_bit_offset
= bitpos_int
;
18574 if (! BYTES_BIG_ENDIAN
)
18576 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
18577 highest_order_object_bit_offset
+=
18578 simple_type_size_in_bits (original_type
);
18582 = (! BYTES_BIG_ENDIAN
18583 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
18584 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
18586 if (bit_offset
< 0)
18587 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
18589 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
18592 /* For a FIELD_DECL node which represents a bit field, output an attribute
18593 which specifies the length in bits of the given field. */
18596 add_bit_size_attribute (dw_die_ref die
, tree decl
)
18598 /* Must be a field and a bit field. */
18599 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
18600 && DECL_BIT_FIELD_TYPE (decl
));
18602 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
18603 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
18606 /* If the compiled language is ANSI C, then add a 'prototyped'
18607 attribute, if arg types are given for the parameters of a function. */
18610 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
18612 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
18619 if (prototype_p (func_type
))
18620 add_AT_flag (die
, DW_AT_prototyped
, 1);
18627 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
18628 by looking in either the type declaration or object declaration
18631 static inline dw_die_ref
18632 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
18634 dw_die_ref origin_die
= NULL
;
18636 if (TREE_CODE (origin
) != FUNCTION_DECL
)
18638 /* We may have gotten separated from the block for the inlined
18639 function, if we're in an exception handler or some such; make
18640 sure that the abstract function has been written out.
18642 Doing this for nested functions is wrong, however; functions are
18643 distinct units, and our context might not even be inline. */
18647 fn
= TYPE_STUB_DECL (fn
);
18649 fn
= decl_function_context (fn
);
18651 dwarf2out_abstract_function (fn
);
18654 if (DECL_P (origin
))
18655 origin_die
= lookup_decl_die (origin
);
18656 else if (TYPE_P (origin
))
18657 origin_die
= lookup_type_die (origin
);
18659 /* XXX: Functions that are never lowered don't always have correct block
18660 trees (in the case of java, they simply have no block tree, in some other
18661 languages). For these functions, there is nothing we can really do to
18662 output correct debug info for inlined functions in all cases. Rather
18663 than die, we'll just produce deficient debug info now, in that we will
18664 have variables without a proper abstract origin. In the future, when all
18665 functions are lowered, we should re-add a gcc_assert (origin_die)
18669 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
18673 /* We do not currently support the pure_virtual attribute. */
18676 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
18678 if (DECL_VINDEX (func_decl
))
18680 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18682 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
18683 add_AT_loc (die
, DW_AT_vtable_elem_location
,
18684 new_loc_descr (DW_OP_constu
,
18685 tree_to_shwi (DECL_VINDEX (func_decl
)),
18688 /* GNU extension: Record what type this method came from originally. */
18689 if (debug_info_level
> DINFO_LEVEL_TERSE
18690 && DECL_CONTEXT (func_decl
))
18691 add_AT_die_ref (die
, DW_AT_containing_type
,
18692 lookup_type_die (DECL_CONTEXT (func_decl
)));
18696 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
18697 given decl. This used to be a vendor extension until after DWARF 4
18698 standardized it. */
18701 add_linkage_attr (dw_die_ref die
, tree decl
)
18703 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
18705 /* Mimic what assemble_name_raw does with a leading '*'. */
18706 if (name
[0] == '*')
18709 if (dwarf_version
>= 4)
18710 add_AT_string (die
, DW_AT_linkage_name
, name
);
18712 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
18715 /* Add source coordinate attributes for the given decl. */
18718 add_src_coords_attributes (dw_die_ref die
, tree decl
)
18720 expanded_location s
;
18722 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
18724 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18725 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
18726 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
18729 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
18732 add_linkage_name_raw (dw_die_ref die
, tree decl
)
18734 /* Defer until we have an assembler name set. */
18735 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
18737 limbo_die_node
*asm_name
;
18739 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
18740 asm_name
->die
= die
;
18741 asm_name
->created_for
= decl
;
18742 asm_name
->next
= deferred_asm_name
;
18743 deferred_asm_name
= asm_name
;
18745 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
18746 add_linkage_attr (die
, decl
);
18749 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl if desired. */
18752 add_linkage_name (dw_die_ref die
, tree decl
)
18754 if (debug_info_level
> DINFO_LEVEL_NONE
18755 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
18756 && TREE_PUBLIC (decl
)
18757 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
18758 && die
->die_tag
!= DW_TAG_member
)
18759 add_linkage_name_raw (die
, decl
);
18762 /* Add a DW_AT_name attribute and source coordinate attribute for the
18763 given decl, but only if it actually has a name. */
18766 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
18770 decl_name
= DECL_NAME (decl
);
18771 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
18773 const char *name
= dwarf2_name (decl
, 0);
18775 add_name_attribute (die
, name
);
18776 if (! DECL_ARTIFICIAL (decl
))
18777 add_src_coords_attributes (die
, decl
);
18779 add_linkage_name (die
, decl
);
18782 #ifdef VMS_DEBUGGING_INFO
18783 /* Get the function's name, as described by its RTL. This may be different
18784 from the DECL_NAME name used in the source file. */
18785 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
18787 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
18788 XEXP (DECL_RTL (decl
), 0), false);
18789 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
18791 #endif /* VMS_DEBUGGING_INFO */
18794 /* Add VALUE as a DW_AT_discr_value attribute to DIE. */
18797 add_discr_value (dw_die_ref die
, dw_discr_value
*value
)
18801 attr
.dw_attr
= DW_AT_discr_value
;
18802 attr
.dw_attr_val
.val_class
= dw_val_class_discr_value
;
18803 attr
.dw_attr_val
.val_entry
= NULL
;
18804 attr
.dw_attr_val
.v
.val_discr_value
.pos
= value
->pos
;
18806 attr
.dw_attr_val
.v
.val_discr_value
.v
.uval
= value
->v
.uval
;
18808 attr
.dw_attr_val
.v
.val_discr_value
.v
.sval
= value
->v
.sval
;
18809 add_dwarf_attr (die
, &attr
);
18812 /* Add DISCR_LIST as a DW_AT_discr_list to DIE. */
18815 add_discr_list (dw_die_ref die
, dw_discr_list_ref discr_list
)
18819 attr
.dw_attr
= DW_AT_discr_list
;
18820 attr
.dw_attr_val
.val_class
= dw_val_class_discr_list
;
18821 attr
.dw_attr_val
.val_entry
= NULL
;
18822 attr
.dw_attr_val
.v
.val_discr_list
= discr_list
;
18823 add_dwarf_attr (die
, &attr
);
18826 static inline dw_discr_list_ref
18827 AT_discr_list (dw_attr_node
*attr
)
18829 return attr
->dw_attr_val
.v
.val_discr_list
;
18832 #ifdef VMS_DEBUGGING_INFO
18833 /* Output the debug main pointer die for VMS */
18836 dwarf2out_vms_debug_main_pointer (void)
18838 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18841 /* Allocate the VMS debug main subprogram die. */
18842 die
= ggc_cleared_alloc
<die_node
> ();
18843 die
->die_tag
= DW_TAG_subprogram
;
18844 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
18845 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
18846 current_function_funcdef_no
);
18847 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18849 /* Make it the first child of comp_unit_die (). */
18850 die
->die_parent
= comp_unit_die ();
18851 if (comp_unit_die ()->die_child
)
18853 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
18854 comp_unit_die ()->die_child
->die_sib
= die
;
18858 die
->die_sib
= die
;
18859 comp_unit_die ()->die_child
= die
;
18862 #endif /* VMS_DEBUGGING_INFO */
18864 /* Push a new declaration scope. */
18867 push_decl_scope (tree scope
)
18869 vec_safe_push (decl_scope_table
, scope
);
18872 /* Pop a declaration scope. */
18875 pop_decl_scope (void)
18877 decl_scope_table
->pop ();
18880 /* walk_tree helper function for uses_local_type, below. */
18883 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
18886 *walk_subtrees
= 0;
18889 tree name
= TYPE_NAME (*tp
);
18890 if (name
&& DECL_P (name
) && decl_function_context (name
))
18896 /* If TYPE involves a function-local type (including a local typedef to a
18897 non-local type), returns that type; otherwise returns NULL_TREE. */
18900 uses_local_type (tree type
)
18902 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
18906 /* Return the DIE for the scope that immediately contains this type.
18907 Non-named types that do not involve a function-local type get global
18908 scope. Named types nested in namespaces or other types get their
18909 containing scope. All other types (i.e. function-local named types) get
18910 the current active scope. */
18913 scope_die_for (tree t
, dw_die_ref context_die
)
18915 dw_die_ref scope_die
= NULL
;
18916 tree containing_scope
;
18918 /* Non-types always go in the current scope. */
18919 gcc_assert (TYPE_P (t
));
18921 /* Use the scope of the typedef, rather than the scope of the type
18923 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
18924 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
18926 containing_scope
= TYPE_CONTEXT (t
);
18928 /* Use the containing namespace if there is one. */
18929 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
18931 if (context_die
== lookup_decl_die (containing_scope
))
18933 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
18934 context_die
= get_context_die (containing_scope
);
18936 containing_scope
= NULL_TREE
;
18939 /* Ignore function type "scopes" from the C frontend. They mean that
18940 a tagged type is local to a parmlist of a function declarator, but
18941 that isn't useful to DWARF. */
18942 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
18943 containing_scope
= NULL_TREE
;
18945 if (SCOPE_FILE_SCOPE_P (containing_scope
))
18947 /* If T uses a local type keep it local as well, to avoid references
18948 to function-local DIEs from outside the function. */
18949 if (current_function_decl
&& uses_local_type (t
))
18950 scope_die
= context_die
;
18952 scope_die
= comp_unit_die ();
18954 else if (TYPE_P (containing_scope
))
18956 /* For types, we can just look up the appropriate DIE. */
18957 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18958 scope_die
= get_context_die (containing_scope
);
18961 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
18962 if (scope_die
== NULL
)
18963 scope_die
= comp_unit_die ();
18967 scope_die
= context_die
;
18972 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
18975 local_scope_p (dw_die_ref context_die
)
18977 for (; context_die
; context_die
= context_die
->die_parent
)
18978 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
18979 || context_die
->die_tag
== DW_TAG_subprogram
)
18985 /* Returns nonzero if CONTEXT_DIE is a class. */
18988 class_scope_p (dw_die_ref context_die
)
18990 return (context_die
18991 && (context_die
->die_tag
== DW_TAG_structure_type
18992 || context_die
->die_tag
== DW_TAG_class_type
18993 || context_die
->die_tag
== DW_TAG_interface_type
18994 || context_die
->die_tag
== DW_TAG_union_type
));
18997 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
18998 whether or not to treat a DIE in this context as a declaration. */
19001 class_or_namespace_scope_p (dw_die_ref context_die
)
19003 return (class_scope_p (context_die
)
19004 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
19007 /* Many forms of DIEs require a "type description" attribute. This
19008 routine locates the proper "type descriptor" die for the type given
19009 by 'type' plus any additional qualifiers given by 'cv_quals', and
19010 adds a DW_AT_type attribute below the given die. */
19013 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
19014 bool reverse
, dw_die_ref context_die
)
19016 enum tree_code code
= TREE_CODE (type
);
19017 dw_die_ref type_die
= NULL
;
19019 /* ??? If this type is an unnamed subrange type of an integral, floating-point
19020 or fixed-point type, use the inner type. This is because we have no
19021 support for unnamed types in base_type_die. This can happen if this is
19022 an Ada subrange type. Correct solution is emit a subrange type die. */
19023 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
19024 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
19025 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
19027 if (code
== ERROR_MARK
19028 /* Handle a special case. For functions whose return type is void, we
19029 generate *no* type attribute. (Note that no object may have type
19030 `void', so this only applies to function return types). */
19031 || code
== VOID_TYPE
)
19034 type_die
= modified_type_die (type
,
19035 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
19039 if (type_die
!= NULL
)
19040 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
19043 /* Given an object die, add the calling convention attribute for the
19044 function call type. */
19046 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
19048 enum dwarf_calling_convention value
= DW_CC_normal
;
19050 value
= ((enum dwarf_calling_convention
)
19051 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
19054 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
19056 /* DWARF 2 doesn't provide a way to identify a program's source-level
19057 entry point. DW_AT_calling_convention attributes are only meant
19058 to describe functions' calling conventions. However, lacking a
19059 better way to signal the Fortran main program, we used this for
19060 a long time, following existing custom. Now, DWARF 4 has
19061 DW_AT_main_subprogram, which we add below, but some tools still
19062 rely on the old way, which we thus keep. */
19063 value
= DW_CC_program
;
19065 if (dwarf_version
>= 4 || !dwarf_strict
)
19066 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
19069 /* Only add the attribute if the backend requests it, and
19070 is not DW_CC_normal. */
19071 if (value
&& (value
!= DW_CC_normal
))
19072 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
19075 /* Given a tree pointer to a struct, class, union, or enum type node, return
19076 a pointer to the (string) tag name for the given type, or zero if the type
19077 was declared without a tag. */
19079 static const char *
19080 type_tag (const_tree type
)
19082 const char *name
= 0;
19084 if (TYPE_NAME (type
) != 0)
19088 /* Find the IDENTIFIER_NODE for the type name. */
19089 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
19090 && !TYPE_NAMELESS (type
))
19091 t
= TYPE_NAME (type
);
19093 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
19094 a TYPE_DECL node, regardless of whether or not a `typedef' was
19096 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19097 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
19099 /* We want to be extra verbose. Don't call dwarf_name if
19100 DECL_NAME isn't set. The default hook for decl_printable_name
19101 doesn't like that, and in this context it's correct to return
19102 0, instead of "<anonymous>" or the like. */
19103 if (DECL_NAME (TYPE_NAME (type
))
19104 && !DECL_NAMELESS (TYPE_NAME (type
)))
19105 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
19108 /* Now get the name as a string, or invent one. */
19109 if (!name
&& t
!= 0)
19110 name
= IDENTIFIER_POINTER (t
);
19113 return (name
== 0 || *name
== '\0') ? 0 : name
;
19116 /* Return the type associated with a data member, make a special check
19117 for bit field types. */
19120 member_declared_type (const_tree member
)
19122 return (DECL_BIT_FIELD_TYPE (member
)
19123 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
19126 /* Get the decl's label, as described by its RTL. This may be different
19127 from the DECL_NAME name used in the source file. */
19130 static const char *
19131 decl_start_label (tree decl
)
19134 const char *fnname
;
19136 x
= DECL_RTL (decl
);
19137 gcc_assert (MEM_P (x
));
19140 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
19142 fnname
= XSTR (x
, 0);
19147 /* For variable-length arrays that have been previously generated, but
19148 may be incomplete due to missing subscript info, fill the subscript
19149 info. Return TRUE if this is one of those cases. */
19151 fill_variable_array_bounds (tree type
)
19153 if (TREE_ASM_WRITTEN (type
)
19154 && TREE_CODE (type
) == ARRAY_TYPE
19155 && variably_modified_type_p (type
, NULL
))
19157 dw_die_ref array_die
= lookup_type_die (type
);
19160 add_subscript_info (array_die
, type
, !is_ada ());
19166 /* These routines generate the internal representation of the DIE's for
19167 the compilation unit. Debugging information is collected by walking
19168 the declaration trees passed in from dwarf2out_decl(). */
19171 gen_array_type_die (tree type
, dw_die_ref context_die
)
19173 dw_die_ref array_die
;
19175 /* GNU compilers represent multidimensional array types as sequences of one
19176 dimensional array types whose element types are themselves array types.
19177 We sometimes squish that down to a single array_type DIE with multiple
19178 subscripts in the Dwarf debugging info. The draft Dwarf specification
19179 say that we are allowed to do this kind of compression in C, because
19180 there is no difference between an array of arrays and a multidimensional
19181 array. We don't do this for Ada to remain as close as possible to the
19182 actual representation, which is especially important against the language
19183 flexibilty wrt arrays of variable size. */
19185 bool collapse_nested_arrays
= !is_ada ();
19187 if (fill_variable_array_bounds (type
))
19190 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
19193 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
19194 DW_TAG_string_type doesn't have DW_AT_type attribute). */
19195 if (TYPE_STRING_FLAG (type
)
19196 && TREE_CODE (type
) == ARRAY_TYPE
19198 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
19200 HOST_WIDE_INT size
;
19202 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
19203 add_name_attribute (array_die
, type_tag (type
));
19204 equate_type_number_to_die (type
, array_die
);
19205 size
= int_size_in_bytes (type
);
19207 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
19208 else if (TYPE_DOMAIN (type
) != NULL_TREE
19209 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
)
19211 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
19212 tree rszdecl
= szdecl
;
19213 HOST_WIDE_INT rsize
= 0;
19215 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
19216 if (!DECL_P (szdecl
))
19218 if (TREE_CODE (szdecl
) == INDIRECT_REF
19219 && DECL_P (TREE_OPERAND (szdecl
, 0)))
19221 rszdecl
= TREE_OPERAND (szdecl
, 0);
19222 rsize
= int_size_in_bytes (TREE_TYPE (rszdecl
));
19231 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2, NULL
);
19234 && current_function_decl
19235 && DECL_CONTEXT (rszdecl
) == current_function_decl
)
19237 dw_die_ref ref
= lookup_decl_die (rszdecl
);
19238 dw_loc_descr_ref l
= NULL
;
19241 l
= new_loc_descr (DW_OP_call4
, 0, 0);
19242 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
19243 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
19244 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
19246 else if (TREE_CODE (rszdecl
) == PARM_DECL
19249 l
= new_loc_descr (DW_OP_call4
, 0, 0);
19250 l
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
19251 l
->dw_loc_oprnd1
.v
.val_decl_ref
= rszdecl
;
19252 string_types
->safe_push (array_die
);
19254 if (l
&& rszdecl
!= szdecl
)
19256 if (rsize
== DWARF2_ADDR_SIZE
)
19257 add_loc_descr (&l
, new_loc_descr (DW_OP_deref
,
19260 add_loc_descr (&l
, new_loc_descr (DW_OP_deref_size
,
19264 loc
= new_loc_list (l
, NULL
, NULL
, NULL
);
19268 add_AT_location_description (array_die
, DW_AT_string_length
,
19270 if (size
!= DWARF2_ADDR_SIZE
)
19271 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
19278 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
19279 add_name_attribute (array_die
, type_tag (type
));
19280 equate_type_number_to_die (type
, array_die
);
19282 if (TREE_CODE (type
) == VECTOR_TYPE
)
19283 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
19285 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
19287 && TREE_CODE (type
) == ARRAY_TYPE
19288 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
19289 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
19290 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
19293 /* We default the array ordering. SDB will probably do
19294 the right things even if DW_AT_ordering is not present. It's not even
19295 an issue until we start to get into multidimensional arrays anyway. If
19296 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
19297 then we'll have to put the DW_AT_ordering attribute back in. (But if
19298 and when we find out that we need to put these in, we will only do so
19299 for multidimensional arrays. */
19300 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
19303 if (TREE_CODE (type
) == VECTOR_TYPE
)
19305 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
19306 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
19307 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
19308 add_bound_info (subrange_die
, DW_AT_upper_bound
,
19309 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
19312 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
19314 /* Add representation of the type of the elements of this array type and
19315 emit the corresponding DIE if we haven't done it already. */
19316 element_type
= TREE_TYPE (type
);
19317 if (collapse_nested_arrays
)
19318 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
19320 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
19322 element_type
= TREE_TYPE (element_type
);
19325 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
,
19326 TREE_CODE (type
) == ARRAY_TYPE
19327 && TYPE_REVERSE_STORAGE_ORDER (type
),
19330 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
19331 if (TYPE_ARTIFICIAL (type
))
19332 add_AT_flag (array_die
, DW_AT_artificial
, 1);
19334 if (get_AT (array_die
, DW_AT_name
))
19335 add_pubtype (type
, array_die
);
19338 /* After all arguments are created, adjust any DW_TAG_string_type
19339 DIEs DW_AT_string_length attributes. */
19342 adjust_string_types (void)
19344 dw_die_ref array_die
;
19346 FOR_EACH_VEC_ELT (*string_types
, i
, array_die
)
19348 dw_attr_node
*a
= get_AT (array_die
, DW_AT_string_length
);
19351 dw_loc_descr_ref loc
= AT_loc (a
);
19352 gcc_assert (loc
->dw_loc_opc
== DW_OP_call4
19353 && loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
);
19354 dw_die_ref ref
= lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
19357 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
19358 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
19359 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
19363 remove_AT (array_die
, DW_AT_string_length
);
19364 remove_AT (array_die
, DW_AT_byte_size
);
19369 /* This routine generates DIE for array with hidden descriptor, details
19370 are filled into *info by a langhook. */
19373 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
19374 dw_die_ref context_die
)
19376 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
19377 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
19378 const struct loc_descr_context context
= { type
, info
->base_decl
, NULL
};
19381 add_name_attribute (array_die
, type_tag (type
));
19382 equate_type_number_to_die (type
, array_die
);
19384 if (info
->ndimensions
> 1)
19385 switch (info
->ordering
)
19387 case array_descr_ordering_row_major
:
19388 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
19390 case array_descr_ordering_column_major
:
19391 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
19397 if (dwarf_version
>= 3 || !dwarf_strict
)
19399 if (info
->data_location
)
19400 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
19401 dw_scalar_form_exprloc
, &context
);
19402 if (info
->associated
)
19403 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
19404 dw_scalar_form_constant
19405 | dw_scalar_form_exprloc
19406 | dw_scalar_form_reference
, &context
);
19407 if (info
->allocated
)
19408 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
19409 dw_scalar_form_constant
19410 | dw_scalar_form_exprloc
19411 | dw_scalar_form_reference
, &context
);
19414 const enum dwarf_attribute attr
19415 = (info
->stride_in_bits
) ? DW_AT_bit_stride
: DW_AT_byte_stride
;
19417 = (info
->stride_in_bits
)
19418 ? dw_scalar_form_constant
19419 : (dw_scalar_form_constant
19420 | dw_scalar_form_exprloc
19421 | dw_scalar_form_reference
);
19423 add_scalar_info (array_die
, attr
, info
->stride
, forms
, &context
);
19427 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
19429 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
19431 dw_die_ref subrange_die
19432 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
19434 if (info
->dimen
[dim
].bounds_type
)
19435 add_type_attribute (subrange_die
,
19436 info
->dimen
[dim
].bounds_type
, TYPE_UNQUALIFIED
,
19437 false, context_die
);
19438 if (info
->dimen
[dim
].lower_bound
)
19439 add_bound_info (subrange_die
, DW_AT_lower_bound
,
19440 info
->dimen
[dim
].lower_bound
, &context
);
19441 if (info
->dimen
[dim
].upper_bound
)
19442 add_bound_info (subrange_die
, DW_AT_upper_bound
,
19443 info
->dimen
[dim
].upper_bound
, &context
);
19444 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
19445 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
19446 info
->dimen
[dim
].stride
,
19447 dw_scalar_form_constant
19448 | dw_scalar_form_exprloc
19449 | dw_scalar_form_reference
,
19453 gen_type_die (info
->element_type
, context_die
);
19454 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
19455 TREE_CODE (type
) == ARRAY_TYPE
19456 && TYPE_REVERSE_STORAGE_ORDER (type
),
19459 if (get_AT (array_die
, DW_AT_name
))
19460 add_pubtype (type
, array_die
);
19465 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
19467 tree origin
= decl_ultimate_origin (decl
);
19468 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
19470 if (origin
!= NULL
)
19471 add_abstract_origin_attribute (decl_die
, origin
);
19474 add_name_and_src_coords_attributes (decl_die
, decl
);
19475 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
19476 TYPE_UNQUALIFIED
, false, context_die
);
19479 if (DECL_ABSTRACT_P (decl
))
19480 equate_decl_number_to_die (decl
, decl_die
);
19482 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
19486 /* Walk through the list of incomplete types again, trying once more to
19487 emit full debugging info for them. */
19490 retry_incomplete_types (void)
19495 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
19496 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
19497 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
19498 vec_safe_truncate (incomplete_types
, 0);
19501 /* Determine what tag to use for a record type. */
19503 static enum dwarf_tag
19504 record_type_tag (tree type
)
19506 if (! lang_hooks
.types
.classify_record
)
19507 return DW_TAG_structure_type
;
19509 switch (lang_hooks
.types
.classify_record (type
))
19511 case RECORD_IS_STRUCT
:
19512 return DW_TAG_structure_type
;
19514 case RECORD_IS_CLASS
:
19515 return DW_TAG_class_type
;
19517 case RECORD_IS_INTERFACE
:
19518 if (dwarf_version
>= 3 || !dwarf_strict
)
19519 return DW_TAG_interface_type
;
19520 return DW_TAG_structure_type
;
19523 gcc_unreachable ();
19527 /* Generate a DIE to represent an enumeration type. Note that these DIEs
19528 include all of the information about the enumeration values also. Each
19529 enumerated type name/value is listed as a child of the enumerated type
19533 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
19535 dw_die_ref type_die
= lookup_type_die (type
);
19537 if (type_die
== NULL
)
19539 type_die
= new_die (DW_TAG_enumeration_type
,
19540 scope_die_for (type
, context_die
), type
);
19541 equate_type_number_to_die (type
, type_die
);
19542 add_name_attribute (type_die
, type_tag (type
));
19543 if (dwarf_version
>= 4 || !dwarf_strict
)
19545 if (ENUM_IS_SCOPED (type
))
19546 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
19547 if (ENUM_IS_OPAQUE (type
))
19548 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19551 else if (! TYPE_SIZE (type
))
19554 remove_AT (type_die
, DW_AT_declaration
);
19556 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
19557 given enum type is incomplete, do not generate the DW_AT_byte_size
19558 attribute or the DW_AT_element_list attribute. */
19559 if (TYPE_SIZE (type
))
19563 TREE_ASM_WRITTEN (type
) = 1;
19564 add_byte_size_attribute (type_die
, type
);
19565 if (dwarf_version
>= 3 || !dwarf_strict
)
19567 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
19568 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
, false,
19571 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19573 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19574 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19577 /* If the first reference to this type was as the return type of an
19578 inline function, then it may not have a parent. Fix this now. */
19579 if (type_die
->die_parent
== NULL
)
19580 add_child_die (scope_die_for (type
, context_die
), type_die
);
19582 for (link
= TYPE_VALUES (type
);
19583 link
!= NULL
; link
= TREE_CHAIN (link
))
19585 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
19586 tree value
= TREE_VALUE (link
);
19588 add_name_attribute (enum_die
,
19589 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
19591 if (TREE_CODE (value
) == CONST_DECL
)
19592 value
= DECL_INITIAL (value
);
19594 if (simple_type_size_in_bits (TREE_TYPE (value
))
19595 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
19597 /* For constant forms created by add_AT_unsigned DWARF
19598 consumers (GDB, elfutils, etc.) always zero extend
19599 the value. Only when the actual value is negative
19600 do we need to use add_AT_int to generate a constant
19601 form that can represent negative values. */
19602 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
19603 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
19604 add_AT_unsigned (enum_die
, DW_AT_const_value
,
19605 (unsigned HOST_WIDE_INT
) val
);
19607 add_AT_int (enum_die
, DW_AT_const_value
, val
);
19610 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
19611 that here. TODO: This should be re-worked to use correct
19612 signed/unsigned double tags for all cases. */
19613 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
19616 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19617 if (TYPE_ARTIFICIAL (type
))
19618 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19621 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19623 add_pubtype (type
, type_die
);
19628 /* Generate a DIE to represent either a real live formal parameter decl or to
19629 represent just the type of some formal parameter position in some function
19632 Note that this routine is a bit unusual because its argument may be a
19633 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
19634 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
19635 node. If it's the former then this function is being called to output a
19636 DIE to represent a formal parameter object (or some inlining thereof). If
19637 it's the latter, then this function is only being called to output a
19638 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
19639 argument type of some subprogram type.
19640 If EMIT_NAME_P is true, name and source coordinate attributes
19644 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
19645 dw_die_ref context_die
)
19647 tree node_or_origin
= node
? node
: origin
;
19648 tree ultimate_origin
;
19649 dw_die_ref parm_die
= NULL
;
19651 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
19653 parm_die
= lookup_decl_die (node
);
19655 /* If the contexts differ, we may not be talking about the same
19657 if (parm_die
&& parm_die
->die_parent
!= context_die
)
19659 if (!DECL_ABSTRACT_P (node
))
19661 /* This can happen when creating an inlined instance, in
19662 which case we need to create a new DIE that will get
19663 annotated with DW_AT_abstract_origin. */
19668 /* FIXME: Reuse DIE even with a differing context.
19670 This can happen when calling
19671 dwarf2out_abstract_function to build debug info for
19672 the abstract instance of a function for which we have
19673 already generated a DIE in
19674 dwarf2out_early_global_decl.
19676 Once we remove dwarf2out_abstract_function, we should
19677 have a call to gcc_unreachable here. */
19681 if (parm_die
&& parm_die
->die_parent
== NULL
)
19683 /* Check that parm_die already has the right attributes that
19684 we would have added below. If any attributes are
19685 missing, fall through to add them. */
19686 if (! DECL_ABSTRACT_P (node_or_origin
)
19687 && !get_AT (parm_die
, DW_AT_location
)
19688 && !get_AT (parm_die
, DW_AT_const_value
))
19689 /* We are missing location info, and are about to add it. */
19693 add_child_die (context_die
, parm_die
);
19699 /* If we have a previously generated DIE, use it, unless this is an
19700 concrete instance (origin != NULL), in which case we need a new
19701 DIE with a corresponding DW_AT_abstract_origin. */
19703 if (parm_die
&& origin
== NULL
)
19704 reusing_die
= true;
19707 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
19708 reusing_die
= false;
19711 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
19713 case tcc_declaration
:
19714 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
19715 if (node
|| ultimate_origin
)
19716 origin
= ultimate_origin
;
19721 if (origin
!= NULL
)
19722 add_abstract_origin_attribute (parm_die
, origin
);
19723 else if (emit_name_p
)
19724 add_name_and_src_coords_attributes (parm_die
, node
);
19726 || (! DECL_ABSTRACT_P (node_or_origin
)
19727 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
19728 decl_function_context
19729 (node_or_origin
))))
19731 tree type
= TREE_TYPE (node_or_origin
);
19732 if (decl_by_reference_p (node_or_origin
))
19733 add_type_attribute (parm_die
, TREE_TYPE (type
),
19735 false, context_die
);
19737 add_type_attribute (parm_die
, type
,
19738 decl_quals (node_or_origin
),
19739 false, context_die
);
19741 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
19742 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
19744 if (node
&& node
!= origin
)
19745 equate_decl_number_to_die (node
, parm_die
);
19746 if (! DECL_ABSTRACT_P (node_or_origin
))
19747 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
19753 /* We were called with some kind of a ..._TYPE node. */
19754 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
, false,
19759 gcc_unreachable ();
19765 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
19766 children DW_TAG_formal_parameter DIEs representing the arguments of the
19769 PARM_PACK must be a function parameter pack.
19770 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
19771 must point to the subsequent arguments of the function PACK_ARG belongs to.
19772 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
19773 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
19774 following the last one for which a DIE was generated. */
19777 gen_formal_parameter_pack_die (tree parm_pack
,
19779 dw_die_ref subr_die
,
19783 dw_die_ref parm_pack_die
;
19785 gcc_assert (parm_pack
19786 && lang_hooks
.function_parameter_pack_p (parm_pack
)
19789 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
19790 add_src_coords_attributes (parm_pack_die
, parm_pack
);
19792 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
19794 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
19797 gen_formal_parameter_die (arg
, NULL
,
19798 false /* Don't emit name attribute. */,
19803 return parm_pack_die
;
19806 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
19807 at the end of an (ANSI prototyped) formal parameters list. */
19810 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
19812 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
19815 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
19816 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
19817 parameters as specified in some function type specification (except for
19818 those which appear as part of a function *definition*). */
19821 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
19824 tree formal_type
= NULL
;
19825 tree first_parm_type
;
19828 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
19830 arg
= DECL_ARGUMENTS (function_or_method_type
);
19831 function_or_method_type
= TREE_TYPE (function_or_method_type
);
19836 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
19838 /* Make our first pass over the list of formal parameter types and output a
19839 DW_TAG_formal_parameter DIE for each one. */
19840 for (link
= first_parm_type
; link
; )
19842 dw_die_ref parm_die
;
19844 formal_type
= TREE_VALUE (link
);
19845 if (formal_type
== void_type_node
)
19848 /* Output a (nameless) DIE to represent the formal parameter itself. */
19849 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
19851 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
19852 true /* Emit name attribute. */,
19854 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
19855 && link
== first_parm_type
)
19857 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
19858 if (dwarf_version
>= 3 || !dwarf_strict
)
19859 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
19861 else if (arg
&& DECL_ARTIFICIAL (arg
))
19862 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
19865 link
= TREE_CHAIN (link
);
19867 arg
= DECL_CHAIN (arg
);
19870 /* If this function type has an ellipsis, add a
19871 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
19872 if (formal_type
!= void_type_node
)
19873 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
19875 /* Make our second (and final) pass over the list of formal parameter types
19876 and output DIEs to represent those types (as necessary). */
19877 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
19878 link
&& TREE_VALUE (link
);
19879 link
= TREE_CHAIN (link
))
19880 gen_type_die (TREE_VALUE (link
), context_die
);
19883 /* We want to generate the DIE for TYPE so that we can generate the
19884 die for MEMBER, which has been defined; we will need to refer back
19885 to the member declaration nested within TYPE. If we're trying to
19886 generate minimal debug info for TYPE, processing TYPE won't do the
19887 trick; we need to attach the member declaration by hand. */
19890 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
19892 gen_type_die (type
, context_die
);
19894 /* If we're trying to avoid duplicate debug info, we may not have
19895 emitted the member decl for this function. Emit it now. */
19896 if (TYPE_STUB_DECL (type
)
19897 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
19898 && ! lookup_decl_die (member
))
19900 dw_die_ref type_die
;
19901 gcc_assert (!decl_ultimate_origin (member
));
19903 push_decl_scope (type
);
19904 type_die
= lookup_type_die_strip_naming_typedef (type
);
19905 if (TREE_CODE (member
) == FUNCTION_DECL
)
19906 gen_subprogram_die (member
, type_die
);
19907 else if (TREE_CODE (member
) == FIELD_DECL
)
19909 /* Ignore the nameless fields that are used to skip bits but handle
19910 C++ anonymous unions and structs. */
19911 if (DECL_NAME (member
) != NULL_TREE
19912 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
19913 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
19915 struct vlr_context vlr_ctx
= {
19916 DECL_CONTEXT (member
), /* struct_type */
19917 NULL_TREE
/* variant_part_offset */
19919 gen_type_die (member_declared_type (member
), type_die
);
19920 gen_field_die (member
, &vlr_ctx
, type_die
);
19924 gen_variable_die (member
, NULL_TREE
, type_die
);
19930 /* Forward declare these functions, because they are mutually recursive
19931 with their set_block_* pairing functions. */
19932 static void set_decl_origin_self (tree
);
19933 static void set_decl_abstract_flags (tree
, vec
<tree
> &);
19935 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
19936 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
19937 that it points to the node itself, thus indicating that the node is its
19938 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
19939 the given node is NULL, recursively descend the decl/block tree which
19940 it is the root of, and for each other ..._DECL or BLOCK node contained
19941 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
19942 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
19943 values to point to themselves. */
19946 set_block_origin_self (tree stmt
)
19948 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
19950 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
19955 for (local_decl
= BLOCK_VARS (stmt
);
19956 local_decl
!= NULL_TREE
;
19957 local_decl
= DECL_CHAIN (local_decl
))
19958 /* Do not recurse on nested functions since the inlining status
19959 of parent and child can be different as per the DWARF spec. */
19960 if (TREE_CODE (local_decl
) != FUNCTION_DECL
19961 && !DECL_EXTERNAL (local_decl
))
19962 set_decl_origin_self (local_decl
);
19968 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
19969 subblock
!= NULL_TREE
;
19970 subblock
= BLOCK_CHAIN (subblock
))
19971 set_block_origin_self (subblock
); /* Recurse. */
19976 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
19977 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
19978 node to so that it points to the node itself, thus indicating that the
19979 node represents its own (abstract) origin. Additionally, if the
19980 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
19981 the decl/block tree of which the given node is the root of, and for
19982 each other ..._DECL or BLOCK node contained therein whose
19983 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
19984 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
19985 point to themselves. */
19988 set_decl_origin_self (tree decl
)
19990 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
19992 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
19993 if (TREE_CODE (decl
) == FUNCTION_DECL
)
19997 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
19998 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
19999 if (DECL_INITIAL (decl
) != NULL_TREE
20000 && DECL_INITIAL (decl
) != error_mark_node
)
20001 set_block_origin_self (DECL_INITIAL (decl
));
20006 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
20007 and if it wasn't 1 before, push it to abstract_vec vector.
20008 For all local decls and all local sub-blocks (recursively) do it
20012 set_block_abstract_flags (tree stmt
, vec
<tree
> &abstract_vec
)
20018 if (!BLOCK_ABSTRACT (stmt
))
20020 abstract_vec
.safe_push (stmt
);
20021 BLOCK_ABSTRACT (stmt
) = 1;
20024 for (local_decl
= BLOCK_VARS (stmt
);
20025 local_decl
!= NULL_TREE
;
20026 local_decl
= DECL_CHAIN (local_decl
))
20027 if (! DECL_EXTERNAL (local_decl
))
20028 set_decl_abstract_flags (local_decl
, abstract_vec
);
20030 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
20032 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
20033 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
20034 || TREE_CODE (local_decl
) == PARM_DECL
)
20035 set_decl_abstract_flags (local_decl
, abstract_vec
);
20038 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
20039 subblock
!= NULL_TREE
;
20040 subblock
= BLOCK_CHAIN (subblock
))
20041 set_block_abstract_flags (subblock
, abstract_vec
);
20044 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
20045 to 1 and if it wasn't 1 before, push to abstract_vec vector.
20046 In the case where the decl is a FUNCTION_DECL also set the abstract
20047 flags for all of the parameters, local vars, local
20048 blocks and sub-blocks (recursively). */
20051 set_decl_abstract_flags (tree decl
, vec
<tree
> &abstract_vec
)
20053 if (!DECL_ABSTRACT_P (decl
))
20055 abstract_vec
.safe_push (decl
);
20056 DECL_ABSTRACT_P (decl
) = 1;
20059 if (TREE_CODE (decl
) == FUNCTION_DECL
)
20063 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
20064 if (!DECL_ABSTRACT_P (arg
))
20066 abstract_vec
.safe_push (arg
);
20067 DECL_ABSTRACT_P (arg
) = 1;
20069 if (DECL_INITIAL (decl
) != NULL_TREE
20070 && DECL_INITIAL (decl
) != error_mark_node
)
20071 set_block_abstract_flags (DECL_INITIAL (decl
), abstract_vec
);
20075 /* Generate the DWARF2 info for the "abstract" instance of a function which we
20076 may later generate inlined and/or out-of-line instances of.
20078 FIXME: In the early-dwarf world, this function, and most of the
20079 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
20080 the abstract instance. All we would need to do is annotate
20081 the early DIE with the appropriate DW_AT_inline in late
20082 dwarf (perhaps in gen_inlined_subroutine_die).
20084 However, we can't do this yet, because LTO streaming of DIEs
20085 has not been implemented yet. */
20088 dwarf2out_abstract_function (tree decl
)
20090 dw_die_ref old_die
;
20093 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
20094 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
20095 int old_call_site_count
, old_tail_call_site_count
;
20096 struct call_arg_loc_node
*old_call_arg_locations
;
20098 /* Make sure we have the actual abstract inline, not a clone. */
20099 decl
= DECL_ORIGIN (decl
);
20101 old_die
= lookup_decl_die (decl
);
20102 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
20103 /* We've already generated the abstract instance. */
20106 /* We can be called while recursively when seeing block defining inlined subroutine
20107 DIE. Be sure to not clobber the outer location table nor use it or we would
20108 get locations in abstract instantces. */
20109 old_decl_loc_table
= decl_loc_table
;
20110 decl_loc_table
= NULL
;
20111 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
20112 cached_dw_loc_list_table
= NULL
;
20113 old_call_arg_locations
= call_arg_locations
;
20114 call_arg_locations
= NULL
;
20115 old_call_site_count
= call_site_count
;
20116 call_site_count
= -1;
20117 old_tail_call_site_count
= tail_call_site_count
;
20118 tail_call_site_count
= -1;
20120 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
20121 we don't get confused by DECL_ABSTRACT_P. */
20122 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20124 context
= decl_class_context (decl
);
20126 gen_type_die_for_member
20127 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
20130 /* Pretend we've just finished compiling this function. */
20131 save_fn
= current_function_decl
;
20132 current_function_decl
= decl
;
20134 auto_vec
<tree
, 64> abstract_vec
;
20135 set_decl_abstract_flags (decl
, abstract_vec
);
20136 dwarf2out_decl (decl
);
20139 FOR_EACH_VEC_ELT (abstract_vec
, i
, t
)
20140 if (TREE_CODE (t
) == BLOCK
)
20141 BLOCK_ABSTRACT (t
) = 0;
20143 DECL_ABSTRACT_P (t
) = 0;
20145 current_function_decl
= save_fn
;
20146 decl_loc_table
= old_decl_loc_table
;
20147 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
20148 call_arg_locations
= old_call_arg_locations
;
20149 call_site_count
= old_call_site_count
;
20150 tail_call_site_count
= old_tail_call_site_count
;
20153 /* Helper function of premark_used_types() which gets called through
20156 Marks the DIE of a given type in *SLOT as perennial, so it never gets
20157 marked as unused by prune_unused_types. */
20160 premark_used_types_helper (tree
const &type
, void *)
20164 die
= lookup_type_die (type
);
20166 die
->die_perennial_p
= 1;
20170 /* Helper function of premark_types_used_by_global_vars which gets called
20171 through htab_traverse.
20173 Marks the DIE of a given type in *SLOT as perennial, so it never gets
20174 marked as unused by prune_unused_types. The DIE of the type is marked
20175 only if the global variable using the type will actually be emitted. */
20178 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
20181 struct types_used_by_vars_entry
*entry
;
20184 entry
= (struct types_used_by_vars_entry
*) *slot
;
20185 gcc_assert (entry
->type
!= NULL
20186 && entry
->var_decl
!= NULL
);
20187 die
= lookup_type_die (entry
->type
);
20190 /* Ask cgraph if the global variable really is to be emitted.
20191 If yes, then we'll keep the DIE of ENTRY->TYPE. */
20192 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
20193 if (node
&& node
->definition
)
20195 die
->die_perennial_p
= 1;
20196 /* Keep the parent DIEs as well. */
20197 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
20198 die
->die_perennial_p
= 1;
20204 /* Mark all members of used_types_hash as perennial. */
20207 premark_used_types (struct function
*fun
)
20209 if (fun
&& fun
->used_types_hash
)
20210 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
20213 /* Mark all members of types_used_by_vars_entry as perennial. */
20216 premark_types_used_by_global_vars (void)
20218 if (types_used_by_vars_hash
)
20219 types_used_by_vars_hash
20220 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
20223 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
20224 for CA_LOC call arg loc node. */
20227 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
20228 struct call_arg_loc_node
*ca_loc
)
20230 dw_die_ref stmt_die
= NULL
, die
;
20231 tree block
= ca_loc
->block
;
20234 && block
!= DECL_INITIAL (decl
)
20235 && TREE_CODE (block
) == BLOCK
)
20237 stmt_die
= BLOCK_DIE (block
);
20240 block
= BLOCK_SUPERCONTEXT (block
);
20242 if (stmt_die
== NULL
)
20243 stmt_die
= subr_die
;
20244 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
20245 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
20246 if (ca_loc
->tail_call_p
)
20247 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
20248 if (ca_loc
->symbol_ref
)
20250 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
20252 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
20254 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
20259 /* Generate a DIE to represent a declared function (either file-scope or
20263 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
20265 tree origin
= decl_ultimate_origin (decl
);
20266 dw_die_ref subr_die
;
20267 dw_die_ref old_die
= lookup_decl_die (decl
);
20269 /* This function gets called multiple times for different stages of
20270 the debug process. For example, for func() in this code:
20274 void func() { ... }
20277 ...we get called 4 times. Twice in early debug and twice in
20283 1. Once while generating func() within the namespace. This is
20284 the declaration. The declaration bit below is set, as the
20285 context is the namespace.
20287 A new DIE will be generated with DW_AT_declaration set.
20289 2. Once for func() itself. This is the specification. The
20290 declaration bit below is clear as the context is the CU.
20292 We will use the cached DIE from (1) to create a new DIE with
20293 DW_AT_specification pointing to the declaration in (1).
20295 Late debug via rest_of_handle_final()
20296 -------------------------------------
20298 3. Once generating func() within the namespace. This is also the
20299 declaration, as in (1), but this time we will early exit below
20300 as we have a cached DIE and a declaration needs no additional
20301 annotations (no locations), as the source declaration line
20304 4. Once for func() itself. As in (2), this is the specification,
20305 but this time we will re-use the cached DIE, and just annotate
20306 it with the location information that should now be available.
20308 For something without namespaces, but with abstract instances, we
20309 are also called a multiple times:
20314 Base (); // constructor declaration (1)
20317 Base::Base () { } // constructor specification (2)
20322 1. Once for the Base() constructor by virtue of it being a
20323 member of the Base class. This is done via
20324 rest_of_type_compilation.
20326 This is a declaration, so a new DIE will be created with
20329 2. Once for the Base() constructor definition, but this time
20330 while generating the abstract instance of the base
20331 constructor (__base_ctor) which is being generated via early
20332 debug of reachable functions.
20334 Even though we have a cached version of the declaration (1),
20335 we will create a DW_AT_specification of the declaration DIE
20338 3. Once for the __base_ctor itself, but this time, we generate
20339 an DW_AT_abstract_origin version of the DW_AT_specification in
20342 Late debug via rest_of_handle_final
20343 -----------------------------------
20345 4. One final time for the __base_ctor (which will have a cached
20346 DIE with DW_AT_abstract_origin created in (3). This time,
20347 we will just annotate the location information now
20350 int declaration
= (current_function_decl
!= decl
20351 || class_or_namespace_scope_p (context_die
));
20353 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
20355 /* Now that the C++ front end lazily declares artificial member fns, we
20356 might need to retrofit the declaration into its class. */
20357 if (!declaration
&& !origin
&& !old_die
20358 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
20359 && !class_or_namespace_scope_p (context_die
)
20360 && debug_info_level
> DINFO_LEVEL_TERSE
)
20361 old_die
= force_decl_die (decl
);
20363 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
20364 if (origin
!= NULL
)
20366 gcc_assert (!declaration
|| local_scope_p (context_die
));
20368 /* Fixup die_parent for the abstract instance of a nested
20369 inline function. */
20370 if (old_die
&& old_die
->die_parent
== NULL
)
20371 add_child_die (context_die
, old_die
);
20373 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
20375 /* If we have a DW_AT_abstract_origin we have a working
20377 subr_die
= old_die
;
20381 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
20382 add_abstract_origin_attribute (subr_die
, origin
);
20383 /* This is where the actual code for a cloned function is.
20384 Let's emit linkage name attribute for it. This helps
20385 debuggers to e.g, set breakpoints into
20386 constructors/destructors when the user asks "break
20388 add_linkage_name (subr_die
, decl
);
20391 /* A cached copy, possibly from early dwarf generation. Reuse as
20392 much as possible. */
20395 /* A declaration that has been previously dumped needs no
20396 additional information. */
20400 if (!get_AT_flag (old_die
, DW_AT_declaration
)
20401 /* We can have a normal definition following an inline one in the
20402 case of redefinition of GNU C extern inlines.
20403 It seems reasonable to use AT_specification in this case. */
20404 && !get_AT (old_die
, DW_AT_inline
))
20406 /* Detect and ignore this case, where we are trying to output
20407 something we have already output. */
20408 if (get_AT (old_die
, DW_AT_low_pc
)
20409 || get_AT (old_die
, DW_AT_ranges
))
20412 /* If we have no location information, this must be a
20413 partially generated DIE from early dwarf generation.
20414 Fall through and generate it. */
20417 /* If the definition comes from the same place as the declaration,
20418 maybe use the old DIE. We always want the DIE for this function
20419 that has the *_pc attributes to be under comp_unit_die so the
20420 debugger can find it. We also need to do this for abstract
20421 instances of inlines, since the spec requires the out-of-line copy
20422 to have the same parent. For local class methods, this doesn't
20423 apply; we just use the old DIE. */
20424 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
20425 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
20426 if ((is_cu_die (old_die
->die_parent
)
20427 /* This condition fixes the inconsistency/ICE with the
20428 following Fortran test (or some derivative thereof) while
20429 building libgfortran:
20433 logical function funky (FLAG)
20438 || (old_die
->die_parent
20439 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
20440 || context_die
== NULL
)
20441 && (DECL_ARTIFICIAL (decl
)
20442 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
20443 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
20444 == (unsigned) s
.line
))))
20446 subr_die
= old_die
;
20448 /* Clear out the declaration attribute, but leave the
20449 parameters so they can be augmented with location
20450 information later. Unless this was a declaration, in
20451 which case, wipe out the nameless parameters and recreate
20452 them further down. */
20453 if (remove_AT (subr_die
, DW_AT_declaration
))
20456 remove_AT (subr_die
, DW_AT_object_pointer
);
20457 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
20460 /* Make a specification pointing to the previously built
20464 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
20465 add_AT_specification (subr_die
, old_die
);
20466 add_pubname (decl
, subr_die
);
20467 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
20468 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
20469 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
20470 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
20472 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
20473 emit the real type on the definition die. */
20474 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
20476 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
20477 if (die
== auto_die
|| die
== decltype_auto_die
)
20478 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
20479 TYPE_UNQUALIFIED
, false, context_die
);
20483 /* Create a fresh DIE for anything else. */
20486 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
20488 if (TREE_PUBLIC (decl
))
20489 add_AT_flag (subr_die
, DW_AT_external
, 1);
20491 add_name_and_src_coords_attributes (subr_die
, decl
);
20492 add_pubname (decl
, subr_die
);
20493 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20495 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
20496 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
20497 TYPE_UNQUALIFIED
, false, context_die
);
20500 add_pure_or_virtual_attribute (subr_die
, decl
);
20501 if (DECL_ARTIFICIAL (decl
))
20502 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
20504 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
20505 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
20507 add_accessibility_attribute (subr_die
, decl
);
20510 /* Unless we have an existing non-declaration DIE, equate the new
20512 if (!old_die
|| is_declaration_die (old_die
))
20513 equate_decl_number_to_die (decl
, subr_die
);
20517 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
20519 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
20521 /* If this is an explicit function declaration then generate
20522 a DW_AT_explicit attribute. */
20523 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
20524 && (dwarf_version
>= 3 || !dwarf_strict
))
20525 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
20527 /* If this is a C++11 deleted special function member then generate
20528 a DW_AT_GNU_deleted attribute. */
20529 if (lang_hooks
.decls
.function_decl_deleted_p (decl
)
20530 && (! dwarf_strict
))
20531 add_AT_flag (subr_die
, DW_AT_GNU_deleted
, 1);
20534 /* Tag abstract instances with DW_AT_inline. */
20535 else if (DECL_ABSTRACT_P (decl
))
20537 if (DECL_DECLARED_INLINE_P (decl
))
20539 if (cgraph_function_possibly_inlined_p (decl
))
20540 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
20542 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
20546 if (cgraph_function_possibly_inlined_p (decl
))
20547 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
20549 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
20552 if (DECL_DECLARED_INLINE_P (decl
)
20553 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
20554 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
20556 /* For non DECL_EXTERNALs, if range information is available, fill
20557 the DIE with it. */
20558 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
20560 HOST_WIDE_INT cfa_fb_offset
;
20562 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
20564 if (!flag_reorder_blocks_and_partition
)
20566 dw_fde_ref fde
= fun
->fde
;
20567 if (fde
->dw_fde_begin
)
20569 /* We have already generated the labels. */
20570 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
20571 fde
->dw_fde_end
, false);
20575 /* Create start/end labels and add the range. */
20576 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
20577 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
20578 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
20579 current_function_funcdef_no
);
20580 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
20581 current_function_funcdef_no
);
20582 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
20586 #if VMS_DEBUGGING_INFO
20587 /* HP OpenVMS Industry Standard 64: DWARF Extensions
20588 Section 2.3 Prologue and Epilogue Attributes:
20589 When a breakpoint is set on entry to a function, it is generally
20590 desirable for execution to be suspended, not on the very first
20591 instruction of the function, but rather at a point after the
20592 function's frame has been set up, after any language defined local
20593 declaration processing has been completed, and before execution of
20594 the first statement of the function begins. Debuggers generally
20595 cannot properly determine where this point is. Similarly for a
20596 breakpoint set on exit from a function. The prologue and epilogue
20597 attributes allow a compiler to communicate the location(s) to use. */
20600 if (fde
->dw_fde_vms_end_prologue
)
20601 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
20602 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
20604 if (fde
->dw_fde_vms_begin_epilogue
)
20605 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
20606 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
20613 /* Generate pubnames entries for the split function code ranges. */
20614 dw_fde_ref fde
= fun
->fde
;
20616 if (fde
->dw_fde_second_begin
)
20618 if (dwarf_version
>= 3 || !dwarf_strict
)
20620 /* We should use ranges for non-contiguous code section
20621 addresses. Use the actual code range for the initial
20622 section, since the HOT/COLD labels might precede an
20623 alignment offset. */
20624 bool range_list_added
= false;
20625 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
20626 fde
->dw_fde_end
, &range_list_added
,
20628 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
20629 fde
->dw_fde_second_end
,
20630 &range_list_added
, false);
20631 if (range_list_added
)
20636 /* There is no real support in DW2 for this .. so we make
20637 a work-around. First, emit the pub name for the segment
20638 containing the function label. Then make and emit a
20639 simplified subprogram DIE for the second segment with the
20640 name pre-fixed by __hot/cold_sect_of_. We use the same
20641 linkage name for the second die so that gdb will find both
20642 sections when given "b foo". */
20643 const char *name
= NULL
;
20644 tree decl_name
= DECL_NAME (decl
);
20645 dw_die_ref seg_die
;
20647 /* Do the 'primary' section. */
20648 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
20649 fde
->dw_fde_end
, false);
20651 /* Build a minimal DIE for the secondary section. */
20652 seg_die
= new_die (DW_TAG_subprogram
,
20653 subr_die
->die_parent
, decl
);
20655 if (TREE_PUBLIC (decl
))
20656 add_AT_flag (seg_die
, DW_AT_external
, 1);
20658 if (decl_name
!= NULL
20659 && IDENTIFIER_POINTER (decl_name
) != NULL
)
20661 name
= dwarf2_name (decl
, 1);
20662 if (! DECL_ARTIFICIAL (decl
))
20663 add_src_coords_attributes (seg_die
, decl
);
20665 add_linkage_name (seg_die
, decl
);
20667 gcc_assert (name
!= NULL
);
20668 add_pure_or_virtual_attribute (seg_die
, decl
);
20669 if (DECL_ARTIFICIAL (decl
))
20670 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
20672 name
= concat ("__second_sect_of_", name
, NULL
);
20673 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
20674 fde
->dw_fde_second_end
, false);
20675 add_name_attribute (seg_die
, name
);
20676 if (want_pubnames ())
20677 add_pubname_string (name
, seg_die
);
20681 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
20685 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
20687 /* We define the "frame base" as the function's CFA. This is more
20688 convenient for several reasons: (1) It's stable across the prologue
20689 and epilogue, which makes it better than just a frame pointer,
20690 (2) With dwarf3, there exists a one-byte encoding that allows us
20691 to reference the .debug_frame data by proxy, but failing that,
20692 (3) We can at least reuse the code inspection and interpretation
20693 code that determines the CFA position at various points in the
20695 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
20697 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
20698 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
20702 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
20703 if (list
->dw_loc_next
)
20704 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
20706 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
20709 /* Compute a displacement from the "steady-state frame pointer" to
20710 the CFA. The former is what all stack slots and argument slots
20711 will reference in the rtl; the latter is what we've told the
20712 debugger about. We'll need to adjust all frame_base references
20713 by this displacement. */
20714 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
20716 if (fun
->static_chain_decl
)
20718 /* DWARF requires here a location expression that computes the
20719 address of the enclosing subprogram's frame base. The machinery
20720 in tree-nested.c is supposed to store this specific address in the
20721 last field of the FRAME record. */
20722 const tree frame_type
20723 = TREE_TYPE (TREE_TYPE (fun
->static_chain_decl
));
20724 const tree fb_decl
= tree_last (TYPE_FIELDS (frame_type
));
20727 = build1 (INDIRECT_REF
, frame_type
, fun
->static_chain_decl
);
20728 fb_expr
= build3 (COMPONENT_REF
, TREE_TYPE (fb_decl
),
20729 fb_expr
, fb_decl
, NULL_TREE
);
20731 add_AT_location_description (subr_die
, DW_AT_static_link
,
20732 loc_list_from_tree (fb_expr
, 0, NULL
));
20736 /* Generate child dies for template paramaters. */
20737 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
20738 gen_generic_params_dies (decl
);
20740 /* Now output descriptions of the arguments for this function. This gets
20741 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
20742 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
20743 `...' at the end of the formal parameter list. In order to find out if
20744 there was a trailing ellipsis or not, we must instead look at the type
20745 associated with the FUNCTION_DECL. This will be a node of type
20746 FUNCTION_TYPE. If the chain of type nodes hanging off of this
20747 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
20748 an ellipsis at the end. */
20750 /* In the case where we are describing a mere function declaration, all we
20751 need to do here (and all we *can* do here) is to describe the *types* of
20752 its formal parameters. */
20753 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20755 else if (declaration
)
20756 gen_formal_types_die (decl
, subr_die
);
20759 /* Generate DIEs to represent all known formal parameters. */
20760 tree parm
= DECL_ARGUMENTS (decl
);
20761 tree generic_decl
= early_dwarf
20762 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
20763 tree generic_decl_parm
= generic_decl
20764 ? DECL_ARGUMENTS (generic_decl
)
20766 auto_vec
<dw_die_ref
> string_types_vec
;
20767 if (string_types
== NULL
)
20768 string_types
= &string_types_vec
;
20770 /* Now we want to walk the list of parameters of the function and
20771 emit their relevant DIEs.
20773 We consider the case of DECL being an instance of a generic function
20774 as well as it being a normal function.
20776 If DECL is an instance of a generic function we walk the
20777 parameters of the generic function declaration _and_ the parameters of
20778 DECL itself. This is useful because we want to emit specific DIEs for
20779 function parameter packs and those are declared as part of the
20780 generic function declaration. In that particular case,
20781 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
20782 That DIE has children DIEs representing the set of arguments
20783 of the pack. Note that the set of pack arguments can be empty.
20784 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
20787 Otherwise, we just consider the parameters of DECL. */
20788 while (generic_decl_parm
|| parm
)
20790 if (generic_decl_parm
20791 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
20792 gen_formal_parameter_pack_die (generic_decl_parm
,
20795 else if (parm
&& !POINTER_BOUNDS_P (parm
))
20797 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, NULL
, subr_die
);
20799 if (parm
== DECL_ARGUMENTS (decl
)
20800 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
20802 && (dwarf_version
>= 3 || !dwarf_strict
))
20803 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
20805 parm
= DECL_CHAIN (parm
);
20808 parm
= DECL_CHAIN (parm
);
20810 if (generic_decl_parm
)
20811 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
20814 /* Decide whether we need an unspecified_parameters DIE at the end.
20815 There are 2 more cases to do this for: 1) the ansi ... declaration -
20816 this is detectable when the end of the arg list is not a
20817 void_type_node 2) an unprototyped function declaration (not a
20818 definition). This just means that we have no info about the
20819 parameters at all. */
20822 if (prototype_p (TREE_TYPE (decl
)))
20824 /* This is the prototyped case, check for.... */
20825 if (stdarg_p (TREE_TYPE (decl
)))
20826 gen_unspecified_parameters_die (decl
, subr_die
);
20828 else if (DECL_INITIAL (decl
) == NULL_TREE
)
20829 gen_unspecified_parameters_die (decl
, subr_die
);
20832 /* Adjust DW_TAG_string_type DIEs if needed, now that all arguments
20834 if (string_types
== &string_types_vec
)
20836 adjust_string_types ();
20837 string_types
= NULL
;
20841 if (subr_die
!= old_die
)
20842 /* Add the calling convention attribute if requested. */
20843 add_calling_convention_attribute (subr_die
, decl
);
20845 /* Output Dwarf info for all of the stuff within the body of the function
20846 (if it has one - it may be just a declaration).
20848 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
20849 a function. This BLOCK actually represents the outermost binding contour
20850 for the function, i.e. the contour in which the function's formal
20851 parameters and labels get declared. Curiously, it appears that the front
20852 end doesn't actually put the PARM_DECL nodes for the current function onto
20853 the BLOCK_VARS list for this outer scope, but are strung off of the
20854 DECL_ARGUMENTS list for the function instead.
20856 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
20857 the LABEL_DECL nodes for the function however, and we output DWARF info
20858 for those in decls_for_scope. Just within the `outer_scope' there will be
20859 a BLOCK node representing the function's outermost pair of curly braces,
20860 and any blocks used for the base and member initializers of a C++
20861 constructor function. */
20862 tree outer_scope
= DECL_INITIAL (decl
);
20863 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
20865 int call_site_note_count
= 0;
20866 int tail_call_site_note_count
= 0;
20868 /* Emit a DW_TAG_variable DIE for a named return value. */
20869 if (DECL_NAME (DECL_RESULT (decl
)))
20870 gen_decl_die (DECL_RESULT (decl
), NULL
, NULL
, subr_die
);
20872 /* The first time through decls_for_scope we will generate the
20873 DIEs for the locals. The second time, we fill in the
20875 decls_for_scope (outer_scope
, subr_die
);
20877 if (call_arg_locations
&& !dwarf_strict
)
20879 struct call_arg_loc_node
*ca_loc
;
20880 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
20882 dw_die_ref die
= NULL
;
20883 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
20886 for (arg
= (ca_loc
->call_arg_loc_note
!= NULL_RTX
20887 ? NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
)
20889 arg
; arg
= next_arg
)
20891 dw_loc_descr_ref reg
, val
;
20892 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
20893 dw_die_ref cdie
, tdie
= NULL
;
20895 next_arg
= XEXP (arg
, 1);
20896 if (REG_P (XEXP (XEXP (arg
, 0), 0))
20898 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
20899 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
20900 && REGNO (XEXP (XEXP (arg
, 0), 0))
20901 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
20902 next_arg
= XEXP (next_arg
, 1);
20903 if (mode
== VOIDmode
)
20905 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
20906 if (mode
== VOIDmode
)
20907 mode
= GET_MODE (XEXP (arg
, 0));
20909 if (mode
== VOIDmode
|| mode
== BLKmode
)
20911 /* Get dynamic information about call target only if we
20912 have no static information: we cannot generate both
20913 DW_AT_abstract_origin and DW_AT_GNU_call_site_target
20915 if (ca_loc
->symbol_ref
== NULL_RTX
)
20917 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
20919 tloc
= XEXP (XEXP (arg
, 0), 1);
20922 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
20923 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
20925 tlocc
= XEXP (XEXP (arg
, 0), 1);
20930 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
20931 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
20932 VAR_INIT_STATUS_INITIALIZED
);
20933 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
20935 rtx mem
= XEXP (XEXP (arg
, 0), 0);
20936 reg
= mem_loc_descriptor (XEXP (mem
, 0),
20937 get_address_mode (mem
),
20939 VAR_INIT_STATUS_INITIALIZED
);
20941 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
20942 == DEBUG_PARAMETER_REF
)
20945 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
20946 tdie
= lookup_decl_die (tdecl
);
20953 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
20954 != DEBUG_PARAMETER_REF
)
20956 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
20958 VAR_INIT_STATUS_INITIALIZED
);
20962 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
20963 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
20966 add_AT_loc (cdie
, DW_AT_location
, reg
);
20967 else if (tdie
!= NULL
)
20968 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
20969 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
20970 if (next_arg
!= XEXP (arg
, 1))
20972 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
20973 if (mode
== VOIDmode
)
20974 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
20975 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
20978 VAR_INIT_STATUS_INITIALIZED
);
20980 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
20984 && (ca_loc
->symbol_ref
|| tloc
))
20985 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
20986 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
20988 dw_loc_descr_ref tval
= NULL
;
20990 if (tloc
!= NULL_RTX
)
20991 tval
= mem_loc_descriptor (tloc
,
20992 GET_MODE (tloc
) == VOIDmode
20993 ? Pmode
: GET_MODE (tloc
),
20995 VAR_INIT_STATUS_INITIALIZED
);
20997 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
20998 else if (tlocc
!= NULL_RTX
)
21000 tval
= mem_loc_descriptor (tlocc
,
21001 GET_MODE (tlocc
) == VOIDmode
21002 ? Pmode
: GET_MODE (tlocc
),
21004 VAR_INIT_STATUS_INITIALIZED
);
21006 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
21012 call_site_note_count
++;
21013 if (ca_loc
->tail_call_p
)
21014 tail_call_site_note_count
++;
21018 call_arg_locations
= NULL
;
21019 call_arg_loc_last
= NULL
;
21020 if (tail_call_site_count
>= 0
21021 && tail_call_site_count
== tail_call_site_note_count
21024 if (call_site_count
>= 0
21025 && call_site_count
== call_site_note_count
)
21026 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
21028 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
21030 call_site_count
= -1;
21031 tail_call_site_count
= -1;
21035 /* Returns a hash value for X (which really is a die_struct). */
21038 block_die_hasher::hash (die_struct
*d
)
21040 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
21043 /* Return nonzero if decl_id and die_parent of die_struct X is the same
21044 as decl_id and die_parent of die_struct Y. */
21047 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
21049 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
21052 /* Return TRUE if DECL, which may have been previously generated as
21053 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
21054 true if decl (or its origin) is either an extern declaration or a
21055 class/namespace scoped declaration.
21057 The declare_in_namespace support causes us to get two DIEs for one
21058 variable, both of which are declarations. We want to avoid
21059 considering one to be a specification, so we must test for
21060 DECLARATION and DW_AT_declaration. */
21062 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
21064 return (old_die
&& TREE_STATIC (decl
) && !declaration
21065 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
21068 /* Return true if DECL is a local static. */
21071 local_function_static (tree decl
)
21073 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
21074 return TREE_STATIC (decl
)
21075 && DECL_CONTEXT (decl
)
21076 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
21079 /* Generate a DIE to represent a declared data object.
21080 Either DECL or ORIGIN must be non-null. */
21083 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
21085 HOST_WIDE_INT off
= 0;
21087 tree decl_or_origin
= decl
? decl
: origin
;
21088 tree ultimate_origin
;
21089 dw_die_ref var_die
;
21090 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
21091 dw_die_ref origin_die
= NULL
;
21092 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
21093 || class_or_namespace_scope_p (context_die
));
21094 bool specialization_p
= false;
21096 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
21097 if (decl
|| ultimate_origin
)
21098 origin
= ultimate_origin
;
21099 com_decl
= fortran_common (decl_or_origin
, &off
);
21101 /* Symbol in common gets emitted as a child of the common block, in the form
21102 of a data member. */
21105 dw_die_ref com_die
;
21106 dw_loc_list_ref loc
;
21107 die_node com_die_arg
;
21109 var_die
= lookup_decl_die (decl_or_origin
);
21112 if (get_AT (var_die
, DW_AT_location
) == NULL
)
21114 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
21119 /* Optimize the common case. */
21120 if (single_element_loc_list_p (loc
)
21121 && loc
->expr
->dw_loc_opc
== DW_OP_addr
21122 && loc
->expr
->dw_loc_next
== NULL
21123 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
21126 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
21127 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
21128 = plus_constant (GET_MODE (x
), x
, off
);
21131 loc_list_plus_const (loc
, off
);
21133 add_AT_location_description (var_die
, DW_AT_location
, loc
);
21134 remove_AT (var_die
, DW_AT_declaration
);
21140 if (common_block_die_table
== NULL
)
21141 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
21143 com_die_arg
.decl_id
= DECL_UID (com_decl
);
21144 com_die_arg
.die_parent
= context_die
;
21145 com_die
= common_block_die_table
->find (&com_die_arg
);
21146 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
21147 if (com_die
== NULL
)
21150 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
21153 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
21154 add_name_and_src_coords_attributes (com_die
, com_decl
);
21157 add_AT_location_description (com_die
, DW_AT_location
, loc
);
21158 /* Avoid sharing the same loc descriptor between
21159 DW_TAG_common_block and DW_TAG_variable. */
21160 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
21162 else if (DECL_EXTERNAL (decl_or_origin
))
21163 add_AT_flag (com_die
, DW_AT_declaration
, 1);
21164 if (want_pubnames ())
21165 add_pubname_string (cnam
, com_die
); /* ??? needed? */
21166 com_die
->decl_id
= DECL_UID (com_decl
);
21167 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
21170 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
21172 add_AT_location_description (com_die
, DW_AT_location
, loc
);
21173 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
21174 remove_AT (com_die
, DW_AT_declaration
);
21176 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
21177 add_name_and_src_coords_attributes (var_die
, decl_or_origin
);
21178 add_type_attribute (var_die
, TREE_TYPE (decl_or_origin
),
21179 decl_quals (decl_or_origin
), false,
21181 add_AT_flag (var_die
, DW_AT_external
, 1);
21186 /* Optimize the common case. */
21187 if (single_element_loc_list_p (loc
)
21188 && loc
->expr
->dw_loc_opc
== DW_OP_addr
21189 && loc
->expr
->dw_loc_next
== NULL
21190 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
21192 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
21193 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
21194 = plus_constant (GET_MODE (x
), x
, off
);
21197 loc_list_plus_const (loc
, off
);
21199 add_AT_location_description (var_die
, DW_AT_location
, loc
);
21201 else if (DECL_EXTERNAL (decl_or_origin
))
21202 add_AT_flag (var_die
, DW_AT_declaration
, 1);
21204 equate_decl_number_to_die (decl
, var_die
);
21212 /* A declaration that has been previously dumped, needs no
21213 further annotations, since it doesn't need location on
21214 the second pass. */
21217 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
21218 && !get_AT (old_die
, DW_AT_specification
))
21220 /* Fall-thru so we can make a new variable die along with a
21221 DW_AT_specification. */
21223 else if (origin
&& old_die
->die_parent
!= context_die
)
21225 /* If we will be creating an inlined instance, we need a
21226 new DIE that will get annotated with
21227 DW_AT_abstract_origin. Clear things so we can get a
21229 gcc_assert (!DECL_ABSTRACT_P (decl
));
21234 /* If a DIE was dumped early, it still needs location info.
21235 Skip to where we fill the location bits. */
21237 goto gen_variable_die_location
;
21241 /* For static data members, the declaration in the class is supposed
21242 to have DW_TAG_member tag; the specification should still be
21243 DW_TAG_variable referencing the DW_TAG_member DIE. */
21244 if (declaration
&& class_scope_p (context_die
))
21245 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
21247 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
21249 if (origin
!= NULL
)
21250 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
21252 /* Loop unrolling can create multiple blocks that refer to the same
21253 static variable, so we must test for the DW_AT_declaration flag.
21255 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
21256 copy decls and set the DECL_ABSTRACT_P flag on them instead of
21259 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
21260 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
21262 /* This is a definition of a C++ class level static. */
21263 add_AT_specification (var_die
, old_die
);
21264 specialization_p
= true;
21265 if (DECL_NAME (decl
))
21267 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
21268 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
21270 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
21271 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
21273 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
21274 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
21276 if (old_die
->die_tag
== DW_TAG_member
)
21277 add_linkage_name (var_die
, decl
);
21281 add_name_and_src_coords_attributes (var_die
, decl
);
21283 if ((origin
== NULL
&& !specialization_p
)
21285 && !DECL_ABSTRACT_P (decl_or_origin
)
21286 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
21287 decl_function_context
21288 (decl_or_origin
))))
21290 tree type
= TREE_TYPE (decl_or_origin
);
21292 if (decl_by_reference_p (decl_or_origin
))
21293 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
21296 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
), false,
21300 if (origin
== NULL
&& !specialization_p
)
21302 if (TREE_PUBLIC (decl
))
21303 add_AT_flag (var_die
, DW_AT_external
, 1);
21305 if (DECL_ARTIFICIAL (decl
))
21306 add_AT_flag (var_die
, DW_AT_artificial
, 1);
21308 add_accessibility_attribute (var_die
, decl
);
21312 add_AT_flag (var_die
, DW_AT_declaration
, 1);
21314 if (decl
&& (DECL_ABSTRACT_P (decl
)
21315 || !old_die
|| is_declaration_die (old_die
)))
21316 equate_decl_number_to_die (decl
, var_die
);
21318 gen_variable_die_location
:
21320 && (! DECL_ABSTRACT_P (decl_or_origin
)
21321 /* Local static vars are shared between all clones/inlines,
21322 so emit DW_AT_location on the abstract DIE if DECL_RTL is
21324 || (TREE_CODE (decl_or_origin
) == VAR_DECL
21325 && TREE_STATIC (decl_or_origin
)
21326 && DECL_RTL_SET_P (decl_or_origin
)))
21327 /* When abstract origin already has DW_AT_location attribute, no need
21328 to add it again. */
21329 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
21332 add_pubname (decl_or_origin
, var_die
);
21334 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
21338 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
21341 /* Generate a DIE to represent a named constant. */
21344 gen_const_die (tree decl
, dw_die_ref context_die
)
21346 dw_die_ref const_die
;
21347 tree type
= TREE_TYPE (decl
);
21349 const_die
= lookup_decl_die (decl
);
21353 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
21354 equate_decl_number_to_die (decl
, const_die
);
21355 add_name_and_src_coords_attributes (const_die
, decl
);
21356 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, false, context_die
);
21357 if (TREE_PUBLIC (decl
))
21358 add_AT_flag (const_die
, DW_AT_external
, 1);
21359 if (DECL_ARTIFICIAL (decl
))
21360 add_AT_flag (const_die
, DW_AT_artificial
, 1);
21361 tree_add_const_value_attribute_for_decl (const_die
, decl
);
21364 /* Generate a DIE to represent a label identifier. */
21367 gen_label_die (tree decl
, dw_die_ref context_die
)
21369 tree origin
= decl_ultimate_origin (decl
);
21370 dw_die_ref lbl_die
= lookup_decl_die (decl
);
21372 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21376 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
21377 equate_decl_number_to_die (decl
, lbl_die
);
21379 if (origin
!= NULL
)
21380 add_abstract_origin_attribute (lbl_die
, origin
);
21382 add_name_and_src_coords_attributes (lbl_die
, decl
);
21385 if (DECL_ABSTRACT_P (decl
))
21386 equate_decl_number_to_die (decl
, lbl_die
);
21389 insn
= DECL_RTL_IF_SET (decl
);
21391 /* Deleted labels are programmer specified labels which have been
21392 eliminated because of various optimizations. We still emit them
21393 here so that it is possible to put breakpoints on them. */
21397 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
21399 /* When optimization is enabled (via -O) some parts of the compiler
21400 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
21401 represent source-level labels which were explicitly declared by
21402 the user. This really shouldn't be happening though, so catch
21403 it if it ever does happen. */
21404 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
21406 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
21407 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
21411 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
21412 && CODE_LABEL_NUMBER (insn
) != -1)
21414 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
21415 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
21420 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
21421 attributes to the DIE for a block STMT, to describe where the inlined
21422 function was called from. This is similar to add_src_coords_attributes. */
21425 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
21427 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
21429 if (dwarf_version
>= 3 || !dwarf_strict
)
21431 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
21432 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
21437 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
21438 Add low_pc and high_pc attributes to the DIE for a block STMT. */
21441 add_high_low_attributes (tree stmt
, dw_die_ref die
)
21443 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21445 if (BLOCK_FRAGMENT_CHAIN (stmt
)
21446 && (dwarf_version
>= 3 || !dwarf_strict
))
21448 tree chain
, superblock
= NULL_TREE
;
21450 dw_attr_node
*attr
= NULL
;
21452 if (inlined_function_outer_scope_p (stmt
))
21454 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
21455 BLOCK_NUMBER (stmt
));
21456 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
21459 /* Optimize duplicate .debug_ranges lists or even tails of
21460 lists. If this BLOCK has same ranges as its supercontext,
21461 lookup DW_AT_ranges attribute in the supercontext (and
21462 recursively so), verify that the ranges_table contains the
21463 right values and use it instead of adding a new .debug_range. */
21464 for (chain
= stmt
, pdie
= die
;
21465 BLOCK_SAME_RANGE (chain
);
21466 chain
= BLOCK_SUPERCONTEXT (chain
))
21468 dw_attr_node
*new_attr
;
21470 pdie
= pdie
->die_parent
;
21473 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
21475 new_attr
= get_AT (pdie
, DW_AT_ranges
);
21476 if (new_attr
== NULL
21477 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
21480 superblock
= BLOCK_SUPERCONTEXT (chain
);
21483 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
21484 / 2 / DWARF2_ADDR_SIZE
].num
21485 == BLOCK_NUMBER (superblock
))
21486 && BLOCK_FRAGMENT_CHAIN (superblock
))
21488 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
21489 / 2 / DWARF2_ADDR_SIZE
;
21490 unsigned long supercnt
= 0, thiscnt
= 0;
21491 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
21492 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
21495 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
21496 == BLOCK_NUMBER (chain
));
21498 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
21499 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
21500 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
21502 gcc_assert (supercnt
>= thiscnt
);
21503 add_AT_range_list (die
, DW_AT_ranges
,
21504 ((off
+ supercnt
- thiscnt
)
21505 * 2 * DWARF2_ADDR_SIZE
),
21510 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
21512 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
21515 add_ranges (chain
);
21516 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
21523 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
21524 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
21525 BLOCK_NUMBER (stmt
));
21526 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
21527 BLOCK_NUMBER (stmt
));
21528 add_AT_low_high_pc (die
, label
, label_high
, false);
21532 /* Generate a DIE for a lexical block. */
21535 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
21537 dw_die_ref old_die
= BLOCK_DIE (stmt
);
21538 dw_die_ref stmt_die
= NULL
;
21541 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
21542 BLOCK_DIE (stmt
) = stmt_die
;
21545 if (BLOCK_ABSTRACT (stmt
))
21549 /* This must have been generated early and it won't even
21550 need location information since it's a DW_AT_inline
21553 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
21554 if (c
->die_tag
== DW_TAG_inlined_subroutine
21555 || c
->die_tag
== DW_TAG_subprogram
)
21557 gcc_assert (get_AT (c
, DW_AT_inline
));
21563 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
21565 /* If this is an inlined instance, create a new lexical die for
21566 anything below to attach DW_AT_abstract_origin to. */
21569 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
21570 BLOCK_DIE (stmt
) = stmt_die
;
21576 stmt_die
= old_die
;
21578 /* A non abstract block whose blocks have already been reordered
21579 should have the instruction range for this block. If so, set the
21580 high/low attributes. */
21581 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
21583 gcc_assert (stmt_die
);
21584 add_high_low_attributes (stmt
, stmt_die
);
21587 decls_for_scope (stmt
, stmt_die
);
21590 /* Generate a DIE for an inlined subprogram. */
21593 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
21597 /* The instance of function that is effectively being inlined shall not
21599 gcc_assert (! BLOCK_ABSTRACT (stmt
));
21601 decl
= block_ultimate_origin (stmt
);
21603 /* Make sure any inlined functions are known to be inlineable. */
21604 gcc_checking_assert (DECL_ABSTRACT_P (decl
)
21605 || cgraph_function_possibly_inlined_p (decl
));
21607 /* Emit info for the abstract instance first, if we haven't yet. We
21608 must emit this even if the block is abstract, otherwise when we
21609 emit the block below (or elsewhere), we may end up trying to emit
21610 a die whose origin die hasn't been emitted, and crashing. */
21611 dwarf2out_abstract_function (decl
);
21613 if (! BLOCK_ABSTRACT (stmt
))
21615 dw_die_ref subr_die
21616 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
21618 if (call_arg_locations
)
21619 BLOCK_DIE (stmt
) = subr_die
;
21620 add_abstract_origin_attribute (subr_die
, decl
);
21621 if (TREE_ASM_WRITTEN (stmt
))
21622 add_high_low_attributes (stmt
, subr_die
);
21623 add_call_src_coords_attributes (stmt
, subr_die
);
21625 decls_for_scope (stmt
, subr_die
);
21629 /* Generate a DIE for a field in a record, or structure. CTX is required: see
21630 the comment for VLR_CONTEXT. */
21633 gen_field_die (tree decl
, struct vlr_context
*ctx
, dw_die_ref context_die
)
21635 dw_die_ref decl_die
;
21637 if (TREE_TYPE (decl
) == error_mark_node
)
21640 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
21641 add_name_and_src_coords_attributes (decl_die
, decl
);
21642 add_type_attribute (decl_die
, member_declared_type (decl
), decl_quals (decl
),
21643 TYPE_REVERSE_STORAGE_ORDER (DECL_FIELD_CONTEXT (decl
)),
21646 if (DECL_BIT_FIELD_TYPE (decl
))
21648 add_byte_size_attribute (decl_die
, decl
);
21649 add_bit_size_attribute (decl_die
, decl
);
21650 add_bit_offset_attribute (decl_die
, decl
, ctx
);
21653 /* If we have a variant part offset, then we are supposed to process a member
21654 of a QUAL_UNION_TYPE, which is how we represent variant parts in
21656 gcc_assert (ctx
->variant_part_offset
== NULL_TREE
21657 || TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != QUAL_UNION_TYPE
);
21658 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
21659 add_data_member_location_attribute (decl_die
, decl
, ctx
);
21661 if (DECL_ARTIFICIAL (decl
))
21662 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
21664 add_accessibility_attribute (decl_die
, decl
);
21666 /* Equate decl number to die, so that we can look up this decl later on. */
21667 equate_decl_number_to_die (decl
, decl_die
);
21671 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21672 Use modified_type_die instead.
21673 We keep this code here just in case these types of DIEs may be needed to
21674 represent certain things in other languages (e.g. Pascal) someday. */
21677 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
21680 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
21682 equate_type_number_to_die (type
, ptr_die
);
21683 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
21685 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
21688 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
21689 Use modified_type_die instead.
21690 We keep this code here just in case these types of DIEs may be needed to
21691 represent certain things in other languages (e.g. Pascal) someday. */
21694 gen_reference_type_die (tree type
, dw_die_ref context_die
)
21696 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
21698 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
21699 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
21701 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
21703 equate_type_number_to_die (type
, ref_die
);
21704 add_type_attribute (ref_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
21706 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
21710 /* Generate a DIE for a pointer to a member type. */
21713 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
21716 = new_die (DW_TAG_ptr_to_member_type
,
21717 scope_die_for (type
, context_die
), type
);
21719 equate_type_number_to_die (type
, ptr_die
);
21720 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
21721 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
21722 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
, false,
21726 static char *producer_string
;
21728 /* Return a heap allocated producer string including command line options
21729 if -grecord-gcc-switches. */
21732 gen_producer_string (void)
21735 auto_vec
<const char *> switches
;
21736 const char *language_string
= lang_hooks
.name
;
21737 char *producer
, *tail
;
21739 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
21740 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
21742 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
21743 switch (save_decoded_options
[j
].opt_index
)
21750 case OPT_auxbase_strip
:
21759 case OPT_SPECIAL_unknown
:
21760 case OPT_SPECIAL_ignore
:
21761 case OPT_SPECIAL_program_name
:
21762 case OPT_SPECIAL_input_file
:
21763 case OPT_grecord_gcc_switches
:
21764 case OPT_gno_record_gcc_switches
:
21765 case OPT__output_pch_
:
21766 case OPT_fdiagnostics_show_location_
:
21767 case OPT_fdiagnostics_show_option
:
21768 case OPT_fdiagnostics_show_caret
:
21769 case OPT_fdiagnostics_color_
:
21770 case OPT_fverbose_asm
:
21772 case OPT__sysroot_
:
21774 case OPT_nostdinc__
:
21775 case OPT_fpreprocessed
:
21776 case OPT_fltrans_output_list_
:
21777 case OPT_fresolution_
:
21778 case OPT_fdebug_prefix_map_
:
21779 /* Ignore these. */
21782 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
21783 & CL_NO_DWARF_RECORD
)
21785 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
21787 switch (save_decoded_options
[j
].canonical_option
[0][1])
21794 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
21801 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
21802 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
21806 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
21808 sprintf (tail
, "%s %s", language_string
, version_string
);
21811 FOR_EACH_VEC_ELT (switches
, j
, p
)
21815 memcpy (tail
+ 1, p
, len
);
21823 /* Given a C and/or C++ language/version string return the "highest".
21824 C++ is assumed to be "higher" than C in this case. Used for merging
21825 LTO translation unit languages. */
21826 static const char *
21827 highest_c_language (const char *lang1
, const char *lang2
)
21829 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
21830 return "GNU C++14";
21831 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
21832 return "GNU C++11";
21833 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
21834 return "GNU C++98";
21836 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
21838 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
21840 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
21843 gcc_unreachable ();
21847 /* Generate the DIE for the compilation unit. */
21850 gen_compile_unit_die (const char *filename
)
21853 const char *language_string
= lang_hooks
.name
;
21856 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
21860 add_name_attribute (die
, filename
);
21861 /* Don't add cwd for <built-in>. */
21862 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
21863 add_comp_dir_attribute (die
);
21866 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
21868 /* If our producer is LTO try to figure out a common language to use
21869 from the global list of translation units. */
21870 if (strcmp (language_string
, "GNU GIMPLE") == 0)
21874 const char *common_lang
= NULL
;
21876 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
21878 if (!TRANSLATION_UNIT_LANGUAGE (t
))
21881 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
21882 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
21884 else if (strncmp (common_lang
, "GNU C", 5) == 0
21885 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
21886 /* Mixing C and C++ is ok, use C++ in that case. */
21887 common_lang
= highest_c_language (common_lang
,
21888 TRANSLATION_UNIT_LANGUAGE (t
));
21891 /* Fall back to C. */
21892 common_lang
= NULL
;
21898 language_string
= common_lang
;
21901 language
= DW_LANG_C
;
21902 if (strncmp (language_string
, "GNU C", 5) == 0
21903 && ISDIGIT (language_string
[5]))
21905 language
= DW_LANG_C89
;
21906 if (dwarf_version
>= 3 || !dwarf_strict
)
21908 if (strcmp (language_string
, "GNU C89") != 0)
21909 language
= DW_LANG_C99
;
21911 if (dwarf_version
>= 5 /* || !dwarf_strict */)
21912 if (strcmp (language_string
, "GNU C11") == 0)
21913 language
= DW_LANG_C11
;
21916 else if (strncmp (language_string
, "GNU C++", 7) == 0)
21918 language
= DW_LANG_C_plus_plus
;
21919 if (dwarf_version
>= 5 /* || !dwarf_strict */)
21921 if (strcmp (language_string
, "GNU C++11") == 0)
21922 language
= DW_LANG_C_plus_plus_11
;
21923 else if (strcmp (language_string
, "GNU C++14") == 0)
21924 language
= DW_LANG_C_plus_plus_14
;
21927 else if (strcmp (language_string
, "GNU F77") == 0)
21928 language
= DW_LANG_Fortran77
;
21929 else if (strcmp (language_string
, "GNU Pascal") == 0)
21930 language
= DW_LANG_Pascal83
;
21931 else if (dwarf_version
>= 3 || !dwarf_strict
)
21933 if (strcmp (language_string
, "GNU Ada") == 0)
21934 language
= DW_LANG_Ada95
;
21935 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
21937 language
= DW_LANG_Fortran95
;
21938 if (dwarf_version
>= 5 /* || !dwarf_strict */)
21940 if (strcmp (language_string
, "GNU Fortran2003") == 0)
21941 language
= DW_LANG_Fortran03
;
21942 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
21943 language
= DW_LANG_Fortran08
;
21946 else if (strcmp (language_string
, "GNU Java") == 0)
21947 language
= DW_LANG_Java
;
21948 else if (strcmp (language_string
, "GNU Objective-C") == 0)
21949 language
= DW_LANG_ObjC
;
21950 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
21951 language
= DW_LANG_ObjC_plus_plus
;
21952 else if (dwarf_version
>= 5 || !dwarf_strict
)
21954 if (strcmp (language_string
, "GNU Go") == 0)
21955 language
= DW_LANG_Go
;
21958 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
21959 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
21960 language
= DW_LANG_Fortran90
;
21962 add_AT_unsigned (die
, DW_AT_language
, language
);
21966 case DW_LANG_Fortran77
:
21967 case DW_LANG_Fortran90
:
21968 case DW_LANG_Fortran95
:
21969 case DW_LANG_Fortran03
:
21970 case DW_LANG_Fortran08
:
21971 /* Fortran has case insensitive identifiers and the front-end
21972 lowercases everything. */
21973 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
21976 /* The default DW_ID_case_sensitive doesn't need to be specified. */
21982 /* Generate the DIE for a base class. */
21985 gen_inheritance_die (tree binfo
, tree access
, tree type
,
21986 dw_die_ref context_die
)
21988 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
21989 struct vlr_context ctx
= { type
, NULL
};
21991 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, false,
21993 add_data_member_location_attribute (die
, binfo
, &ctx
);
21995 if (BINFO_VIRTUAL_P (binfo
))
21996 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
21998 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
21999 children, otherwise the default is DW_ACCESS_public. In DWARF2
22000 the default has always been DW_ACCESS_private. */
22001 if (access
== access_public_node
)
22003 if (dwarf_version
== 2
22004 || context_die
->die_tag
== DW_TAG_class_type
)
22005 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
22007 else if (access
== access_protected_node
)
22008 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
22009 else if (dwarf_version
> 2
22010 && context_die
->die_tag
!= DW_TAG_class_type
)
22011 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
22014 /* Return whether DECL is a FIELD_DECL that represents the variant part of a
22017 is_variant_part (tree decl
)
22019 return (TREE_CODE (decl
) == FIELD_DECL
22020 && TREE_CODE (TREE_TYPE (decl
)) == QUAL_UNION_TYPE
);
22023 /* Check that OPERAND is a reference to a field in STRUCT_TYPE. If it is,
22024 return the FIELD_DECL. Return NULL_TREE otherwise. */
22027 analyze_discr_in_predicate (tree operand
, tree struct_type
)
22029 bool continue_stripping
= true;
22030 while (continue_stripping
)
22031 switch (TREE_CODE (operand
))
22034 operand
= TREE_OPERAND (operand
, 0);
22037 continue_stripping
= false;
22041 /* Match field access to members of struct_type only. */
22042 if (TREE_CODE (operand
) == COMPONENT_REF
22043 && TREE_CODE (TREE_OPERAND (operand
, 0)) == PLACEHOLDER_EXPR
22044 && TREE_TYPE (TREE_OPERAND (operand
, 0)) == struct_type
22045 && TREE_CODE (TREE_OPERAND (operand
, 1)) == FIELD_DECL
)
22046 return TREE_OPERAND (operand
, 1);
22051 /* Check that SRC is a constant integer that can be represented as a native
22052 integer constant (either signed or unsigned). If so, store it into DEST and
22053 return true. Return false otherwise. */
22056 get_discr_value (tree src
, dw_discr_value
*dest
)
22058 bool is_unsigned
= TYPE_UNSIGNED (TREE_TYPE (src
));
22060 if (TREE_CODE (src
) != INTEGER_CST
22061 || !(is_unsigned
? tree_fits_uhwi_p (src
) : tree_fits_shwi_p (src
)))
22064 dest
->pos
= is_unsigned
;
22066 dest
->v
.uval
= tree_to_uhwi (src
);
22068 dest
->v
.sval
= tree_to_shwi (src
);
22073 /* Try to extract synthetic properties out of VARIANT_PART_DECL, which is a
22074 FIELD_DECL in STRUCT_TYPE that represents a variant part. If unsuccessful,
22075 store NULL_TREE in DISCR_DECL. Otherwise:
22077 - store the discriminant field in STRUCT_TYPE that controls the variant
22078 part to *DISCR_DECL
22080 - put in *DISCR_LISTS_P an array where for each variant, the item
22081 represents the corresponding matching list of discriminant values.
22083 - put in *DISCR_LISTS_LENGTH the number of variants, which is the size of
22086 Note that when the array is allocated (i.e. when the analysis is
22087 successful), it is up to the caller to free the array. */
22090 analyze_variants_discr (tree variant_part_decl
,
22093 dw_discr_list_ref
**discr_lists_p
,
22094 unsigned *discr_lists_length
)
22096 tree variant_part_type
= TREE_TYPE (variant_part_decl
);
22098 dw_discr_list_ref
*discr_lists
;
22101 /* Compute how many variants there are in this variant part. */
22102 *discr_lists_length
= 0;
22103 for (variant
= TYPE_FIELDS (variant_part_type
);
22104 variant
!= NULL_TREE
;
22105 variant
= DECL_CHAIN (variant
))
22106 ++*discr_lists_length
;
22108 *discr_decl
= NULL_TREE
;
22110 = (dw_discr_list_ref
*) xcalloc (*discr_lists_length
,
22111 sizeof (**discr_lists_p
));
22112 discr_lists
= *discr_lists_p
;
22114 /* And then analyze all variants to extract discriminant information for all
22115 of them. This analysis is conservative: as soon as we detect something we
22116 do not support, abort everything and pretend we found nothing. */
22117 for (variant
= TYPE_FIELDS (variant_part_type
), i
= 0;
22118 variant
!= NULL_TREE
;
22119 variant
= DECL_CHAIN (variant
), ++i
)
22121 tree match_expr
= DECL_QUALIFIER (variant
);
22123 /* Now, try to analyze the predicate and deduce a discriminant for
22125 if (match_expr
== boolean_true_node
)
22126 /* Typically happens for the default variant: it matches all cases that
22127 previous variants rejected. Don't output any matching value for
22131 /* The following loop tries to iterate over each discriminant
22132 possibility: single values or ranges. */
22133 while (match_expr
!= NULL_TREE
)
22135 tree next_round_match_expr
;
22136 tree candidate_discr
= NULL_TREE
;
22137 dw_discr_list_ref new_node
= NULL
;
22139 /* Possibilities are matched one after the other by nested
22140 TRUTH_ORIF_EXPR expressions. Process the current possibility and
22141 continue with the rest at next iteration. */
22142 if (TREE_CODE (match_expr
) == TRUTH_ORIF_EXPR
)
22144 next_round_match_expr
= TREE_OPERAND (match_expr
, 0);
22145 match_expr
= TREE_OPERAND (match_expr
, 1);
22148 next_round_match_expr
= NULL_TREE
;
22150 if (match_expr
== boolean_false_node
)
22151 /* This sub-expression matches nothing: just wait for the next
22155 else if (TREE_CODE (match_expr
) == EQ_EXPR
)
22157 /* We are matching: <discr_field> == <integer_cst>
22158 This sub-expression matches a single value. */
22159 tree integer_cst
= TREE_OPERAND (match_expr
, 1);
22162 = analyze_discr_in_predicate (TREE_OPERAND (match_expr
, 0),
22165 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
22166 if (!get_discr_value (integer_cst
,
22167 &new_node
->dw_discr_lower_bound
))
22169 new_node
->dw_discr_range
= false;
22172 else if (TREE_CODE (match_expr
) == TRUTH_ANDIF_EXPR
)
22174 /* We are matching:
22175 <discr_field> > <integer_cst>
22176 && <discr_field> < <integer_cst>.
22177 This sub-expression matches the range of values between the
22178 two matched integer constants. Note that comparisons can be
22179 inclusive or exclusive. */
22180 tree candidate_discr_1
, candidate_discr_2
;
22181 tree lower_cst
, upper_cst
;
22182 bool lower_cst_included
, upper_cst_included
;
22183 tree lower_op
= TREE_OPERAND (match_expr
, 0);
22184 tree upper_op
= TREE_OPERAND (match_expr
, 1);
22186 /* When the comparison is exclusive, the integer constant is not
22187 the discriminant range bound we are looking for: we will have
22188 to increment or decrement it. */
22189 if (TREE_CODE (lower_op
) == GE_EXPR
)
22190 lower_cst_included
= true;
22191 else if (TREE_CODE (lower_op
) == GT_EXPR
)
22192 lower_cst_included
= false;
22196 if (TREE_CODE (upper_op
) == LE_EXPR
)
22197 upper_cst_included
= true;
22198 else if (TREE_CODE (upper_op
) == LT_EXPR
)
22199 upper_cst_included
= false;
22203 /* Extract the discriminant from the first operand and check it
22204 is consistant with the same analysis in the second
22207 = analyze_discr_in_predicate (TREE_OPERAND (lower_op
, 0),
22210 = analyze_discr_in_predicate (TREE_OPERAND (upper_op
, 0),
22212 if (candidate_discr_1
== candidate_discr_2
)
22213 candidate_discr
= candidate_discr_1
;
22217 /* Extract bounds from both. */
22218 new_node
= ggc_cleared_alloc
<dw_discr_list_node
> ();
22219 lower_cst
= TREE_OPERAND (lower_op
, 1);
22220 upper_cst
= TREE_OPERAND (upper_op
, 1);
22222 if (!lower_cst_included
)
22224 = fold (build2 (PLUS_EXPR
, TREE_TYPE (lower_cst
),
22226 build_int_cst (TREE_TYPE (lower_cst
), 1)));
22227 if (!upper_cst_included
)
22229 = fold (build2 (MINUS_EXPR
, TREE_TYPE (upper_cst
),
22231 build_int_cst (TREE_TYPE (upper_cst
), 1)));
22233 if (!get_discr_value (lower_cst
,
22234 &new_node
->dw_discr_lower_bound
)
22235 || !get_discr_value (upper_cst
,
22236 &new_node
->dw_discr_upper_bound
))
22239 new_node
->dw_discr_range
= true;
22243 /* Unsupported sub-expression: we cannot determine the set of
22244 matching discriminant values. Abort everything. */
22247 /* If the discriminant info is not consistant with what we saw so
22248 far, consider the analysis failed and abort everything. */
22249 if (candidate_discr
== NULL_TREE
22250 || (*discr_decl
!= NULL_TREE
&& candidate_discr
!= *discr_decl
))
22253 *discr_decl
= candidate_discr
;
22255 if (new_node
!= NULL
)
22257 new_node
->dw_discr_next
= discr_lists
[i
];
22258 discr_lists
[i
] = new_node
;
22260 match_expr
= next_round_match_expr
;
22264 /* If we reach this point, we could match everything we were interested
22269 /* Clean all data structure and return no result. */
22270 free (*discr_lists_p
);
22271 *discr_lists_p
= NULL
;
22272 *discr_decl
= NULL_TREE
;
22275 /* Generate a DIE to represent VARIANT_PART_DECL, a variant part that is part
22276 of STRUCT_TYPE, a record type. This new DIE is emitted as the next child
22279 Variant parts are supposed to be implemented as a FIELD_DECL whose type is a
22280 QUAL_UNION_TYPE: this is the VARIANT_PART_DECL parameter. The members for
22281 this type, which are record types, represent the available variants and each
22282 has a DECL_QUALIFIER attribute. The discriminant and the discriminant
22283 values are inferred from these attributes.
22285 In trees, the offsets for the fields inside these sub-records are relative
22286 to the variant part itself, whereas the corresponding DIEs should have
22287 offset attributes that are relative to the embedding record base address.
22288 This is why the caller must provide a VARIANT_PART_OFFSET expression: it
22289 must be an expression that computes the offset of the variant part to
22290 describe in DWARF. */
22293 gen_variant_part (tree variant_part_decl
, struct vlr_context
*vlr_ctx
,
22294 dw_die_ref context_die
)
22296 const tree variant_part_type
= TREE_TYPE (variant_part_decl
);
22297 tree variant_part_offset
= vlr_ctx
->variant_part_offset
;
22298 struct loc_descr_context ctx
= {
22299 vlr_ctx
->struct_type
, /* context_type */
22300 NULL_TREE
, /* base_decl */
22304 /* The FIELD_DECL node in STRUCT_TYPE that acts as the discriminant, or
22305 NULL_TREE if there is no such field. */
22306 tree discr_decl
= NULL_TREE
;
22307 dw_discr_list_ref
*discr_lists
;
22308 unsigned discr_lists_length
= 0;
22311 dw_die_ref dwarf_proc_die
= NULL
;
22312 dw_die_ref variant_part_die
22313 = new_die (DW_TAG_variant_part
, context_die
, variant_part_type
);
22315 equate_decl_number_to_die (variant_part_decl
, variant_part_die
);
22317 analyze_variants_discr (variant_part_decl
, vlr_ctx
->struct_type
,
22318 &discr_decl
, &discr_lists
, &discr_lists_length
);
22320 if (discr_decl
!= NULL_TREE
)
22322 dw_die_ref discr_die
= lookup_decl_die (discr_decl
);
22325 add_AT_die_ref (variant_part_die
, DW_AT_discr
, discr_die
);
22327 /* We have no DIE for the discriminant, so just discard all
22328 discrimimant information in the output. */
22329 discr_decl
= NULL_TREE
;
22332 /* If the offset for this variant part is more complex than a constant,
22333 create a DWARF procedure for it so that we will not have to generate DWARF
22334 expressions for it for each member. */
22335 if (TREE_CODE (variant_part_offset
) != INTEGER_CST
22336 && (dwarf_version
>= 3 || !dwarf_strict
))
22338 const tree dwarf_proc_fndecl
22339 = build_decl (UNKNOWN_LOCATION
, FUNCTION_DECL
, NULL_TREE
,
22340 build_function_type (TREE_TYPE (variant_part_offset
),
22342 const tree dwarf_proc_call
= build_call_expr (dwarf_proc_fndecl
, 0);
22343 const dw_loc_descr_ref dwarf_proc_body
22344 = loc_descriptor_from_tree (variant_part_offset
, 0, &ctx
);
22346 dwarf_proc_die
= new_dwarf_proc_die (dwarf_proc_body
,
22347 dwarf_proc_fndecl
, context_die
);
22348 if (dwarf_proc_die
!= NULL
)
22349 variant_part_offset
= dwarf_proc_call
;
22352 /* Output DIEs for all variants. */
22354 for (tree variant
= TYPE_FIELDS (variant_part_type
);
22355 variant
!= NULL_TREE
;
22356 variant
= DECL_CHAIN (variant
), ++i
)
22358 tree variant_type
= TREE_TYPE (variant
);
22359 dw_die_ref variant_die
;
22361 /* All variants (i.e. members of a variant part) are supposed to be
22362 encoded as structures. Sub-variant parts are QUAL_UNION_TYPE fields
22363 under these records. */
22364 gcc_assert (TREE_CODE (variant_type
) == RECORD_TYPE
);
22366 variant_die
= new_die (DW_TAG_variant
, variant_part_die
, variant_type
);
22367 equate_decl_number_to_die (variant
, variant_die
);
22369 /* Output discriminant values this variant matches, if any. */
22370 if (discr_decl
== NULL
|| discr_lists
[i
] == NULL
)
22371 /* In the case we have discriminant information at all, this is
22372 probably the default variant: as the standard says, don't
22373 output any discriminant value/list attribute. */
22375 else if (discr_lists
[i
]->dw_discr_next
== NULL
22376 && !discr_lists
[i
]->dw_discr_range
)
22377 /* If there is only one accepted value, don't bother outputting a
22379 add_discr_value (variant_die
, &discr_lists
[i
]->dw_discr_lower_bound
);
22381 add_discr_list (variant_die
, discr_lists
[i
]);
22383 for (tree member
= TYPE_FIELDS (variant_type
);
22384 member
!= NULL_TREE
;
22385 member
= DECL_CHAIN (member
))
22387 struct vlr_context vlr_sub_ctx
= {
22388 vlr_ctx
->struct_type
, /* struct_type */
22389 NULL
/* variant_part_offset */
22391 if (is_variant_part (member
))
22393 /* All offsets for fields inside variant parts are relative to
22394 the top-level embedding RECORD_TYPE's base address. On the
22395 other hand, offsets in GCC's types are relative to the
22396 nested-most variant part. So we have to sum offsets each time
22399 vlr_sub_ctx
.variant_part_offset
22400 = fold (build2 (PLUS_EXPR
, TREE_TYPE (variant_part_offset
),
22401 variant_part_offset
, byte_position (member
)));
22402 gen_variant_part (member
, &vlr_sub_ctx
, variant_die
);
22406 vlr_sub_ctx
.variant_part_offset
= variant_part_offset
;
22407 gen_decl_die (member
, NULL
, &vlr_sub_ctx
, variant_die
);
22412 free (discr_lists
);
22415 /* Generate a DIE for a class member. */
22418 gen_member_die (tree type
, dw_die_ref context_die
)
22421 tree binfo
= TYPE_BINFO (type
);
22424 /* If this is not an incomplete type, output descriptions of each of its
22425 members. Note that as we output the DIEs necessary to represent the
22426 members of this record or union type, we will also be trying to output
22427 DIEs to represent the *types* of those members. However the `type'
22428 function (above) will specifically avoid generating type DIEs for member
22429 types *within* the list of member DIEs for this (containing) type except
22430 for those types (of members) which are explicitly marked as also being
22431 members of this (containing) type themselves. The g++ front- end can
22432 force any given type to be treated as a member of some other (containing)
22433 type by setting the TYPE_CONTEXT of the given (member) type to point to
22434 the TREE node representing the appropriate (containing) type. */
22436 /* First output info about the base classes. */
22439 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
22443 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
22444 gen_inheritance_die (base
,
22445 (accesses
? (*accesses
)[i
] : access_public_node
),
22450 /* Now output info about the data members and type members. */
22451 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
22453 struct vlr_context vlr_ctx
= { type
, NULL_TREE
};
22455 /* If we thought we were generating minimal debug info for TYPE
22456 and then changed our minds, some of the member declarations
22457 may have already been defined. Don't define them again, but
22458 do put them in the right order. */
22460 child
= lookup_decl_die (member
);
22462 splice_child_die (context_die
, child
);
22464 /* Do not generate standard DWARF for variant parts if we are generating
22465 the corresponding GNAT encodings: DIEs generated for both would
22466 conflict in our mappings. */
22467 else if (is_variant_part (member
)
22468 && gnat_encodings
== DWARF_GNAT_ENCODINGS_MINIMAL
)
22470 vlr_ctx
.variant_part_offset
= byte_position (member
);
22471 gen_variant_part (member
, &vlr_ctx
, context_die
);
22475 vlr_ctx
.variant_part_offset
= NULL_TREE
;
22476 gen_decl_die (member
, NULL
, &vlr_ctx
, context_die
);
22480 /* We do not keep type methods in type variants. */
22481 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
22482 /* Now output info about the function members (if any). */
22483 if (TYPE_METHODS (type
) != error_mark_node
)
22484 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
22486 /* Don't include clones in the member list. */
22487 if (DECL_ABSTRACT_ORIGIN (member
))
22489 /* Nor constructors for anonymous classes. */
22490 if (DECL_ARTIFICIAL (member
)
22491 && dwarf2_name (member
, 0) == NULL
)
22494 child
= lookup_decl_die (member
);
22496 splice_child_die (context_die
, child
);
22498 gen_decl_die (member
, NULL
, NULL
, context_die
);
22502 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
22503 is set, we pretend that the type was never defined, so we only get the
22504 member DIEs needed by later specification DIEs. */
22507 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
22508 enum debug_info_usage usage
)
22510 if (TREE_ASM_WRITTEN (type
))
22512 /* Fill in the bound of variable-length fields in late dwarf if
22513 still incomplete. */
22514 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
22515 for (tree member
= TYPE_FIELDS (type
);
22517 member
= DECL_CHAIN (member
))
22518 fill_variable_array_bounds (TREE_TYPE (member
));
22522 dw_die_ref type_die
= lookup_type_die (type
);
22523 dw_die_ref scope_die
= 0;
22525 int complete
= (TYPE_SIZE (type
)
22526 && (! TYPE_STUB_DECL (type
)
22527 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
22528 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
22529 complete
= complete
&& should_emit_struct_debug (type
, usage
);
22531 if (type_die
&& ! complete
)
22534 if (TYPE_CONTEXT (type
) != NULL_TREE
22535 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
22536 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
22539 scope_die
= scope_die_for (type
, context_die
);
22541 /* Generate child dies for template paramaters. */
22542 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
22543 schedule_generic_params_dies_gen (type
);
22545 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
22546 /* First occurrence of type or toplevel definition of nested class. */
22548 dw_die_ref old_die
= type_die
;
22550 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
22551 ? record_type_tag (type
) : DW_TAG_union_type
,
22553 equate_type_number_to_die (type
, type_die
);
22555 add_AT_specification (type_die
, old_die
);
22557 add_name_attribute (type_die
, type_tag (type
));
22560 remove_AT (type_die
, DW_AT_declaration
);
22562 /* If this type has been completed, then give it a byte_size attribute and
22563 then give a list of members. */
22564 if (complete
&& !ns_decl
)
22566 /* Prevent infinite recursion in cases where the type of some member of
22567 this type is expressed in terms of this type itself. */
22568 TREE_ASM_WRITTEN (type
) = 1;
22569 add_byte_size_attribute (type_die
, type
);
22570 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
22572 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
22573 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
22576 /* If the first reference to this type was as the return type of an
22577 inline function, then it may not have a parent. Fix this now. */
22578 if (type_die
->die_parent
== NULL
)
22579 add_child_die (scope_die
, type_die
);
22581 push_decl_scope (type
);
22582 gen_member_die (type
, type_die
);
22585 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
22586 if (TYPE_ARTIFICIAL (type
))
22587 add_AT_flag (type_die
, DW_AT_artificial
, 1);
22589 /* GNU extension: Record what type our vtable lives in. */
22590 if (TYPE_VFIELD (type
))
22592 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
22594 gen_type_die (vtype
, context_die
);
22595 add_AT_die_ref (type_die
, DW_AT_containing_type
,
22596 lookup_type_die (vtype
));
22601 add_AT_flag (type_die
, DW_AT_declaration
, 1);
22603 /* We don't need to do this for function-local types. */
22604 if (TYPE_STUB_DECL (type
)
22605 && ! decl_function_context (TYPE_STUB_DECL (type
)))
22606 vec_safe_push (incomplete_types
, type
);
22609 if (get_AT (type_die
, DW_AT_name
))
22610 add_pubtype (type
, type_die
);
22613 /* Generate a DIE for a subroutine _type_. */
22616 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
22618 tree return_type
= TREE_TYPE (type
);
22619 dw_die_ref subr_die
22620 = new_die (DW_TAG_subroutine_type
,
22621 scope_die_for (type
, context_die
), type
);
22623 equate_type_number_to_die (type
, subr_die
);
22624 add_prototyped_attribute (subr_die
, type
);
22625 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, false,
22627 gen_formal_types_die (type
, subr_die
);
22629 if (get_AT (subr_die
, DW_AT_name
))
22630 add_pubtype (type
, subr_die
);
22633 /* Generate a DIE for a type definition. */
22636 gen_typedef_die (tree decl
, dw_die_ref context_die
)
22638 dw_die_ref type_die
;
22641 if (TREE_ASM_WRITTEN (decl
))
22643 if (DECL_ORIGINAL_TYPE (decl
))
22644 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
22648 TREE_ASM_WRITTEN (decl
) = 1;
22649 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
22650 origin
= decl_ultimate_origin (decl
);
22651 if (origin
!= NULL
)
22652 add_abstract_origin_attribute (type_die
, origin
);
22657 add_name_and_src_coords_attributes (type_die
, decl
);
22658 if (DECL_ORIGINAL_TYPE (decl
))
22660 type
= DECL_ORIGINAL_TYPE (decl
);
22662 if (type
== error_mark_node
)
22665 gcc_assert (type
!= TREE_TYPE (decl
));
22666 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
22670 type
= TREE_TYPE (decl
);
22672 if (type
== error_mark_node
)
22675 if (is_naming_typedef_decl (TYPE_NAME (type
)))
22677 /* Here, we are in the case of decl being a typedef naming
22678 an anonymous type, e.g:
22679 typedef struct {...} foo;
22680 In that case TREE_TYPE (decl) is not a typedef variant
22681 type and TYPE_NAME of the anonymous type is set to the
22682 TYPE_DECL of the typedef. This construct is emitted by
22685 TYPE is the anonymous struct named by the typedef
22686 DECL. As we need the DW_AT_type attribute of the
22687 DW_TAG_typedef to point to the DIE of TYPE, let's
22688 generate that DIE right away. add_type_attribute
22689 called below will then pick (via lookup_type_die) that
22690 anonymous struct DIE. */
22691 if (!TREE_ASM_WRITTEN (type
))
22692 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
22694 /* This is a GNU Extension. We are adding a
22695 DW_AT_linkage_name attribute to the DIE of the
22696 anonymous struct TYPE. The value of that attribute
22697 is the name of the typedef decl naming the anonymous
22698 struct. This greatly eases the work of consumers of
22699 this debug info. */
22700 add_linkage_name_raw (lookup_type_die (type
), decl
);
22704 add_type_attribute (type_die
, type
, decl_quals (decl
), false,
22707 if (is_naming_typedef_decl (decl
))
22708 /* We want that all subsequent calls to lookup_type_die with
22709 TYPE in argument yield the DW_TAG_typedef we have just
22711 equate_type_number_to_die (type
, type_die
);
22713 add_accessibility_attribute (type_die
, decl
);
22716 if (DECL_ABSTRACT_P (decl
))
22717 equate_decl_number_to_die (decl
, type_die
);
22719 if (get_AT (type_die
, DW_AT_name
))
22720 add_pubtype (decl
, type_die
);
22723 /* Generate a DIE for a struct, class, enum or union type. */
22726 gen_tagged_type_die (tree type
,
22727 dw_die_ref context_die
,
22728 enum debug_info_usage usage
)
22732 if (type
== NULL_TREE
22733 || !is_tagged_type (type
))
22736 if (TREE_ASM_WRITTEN (type
))
22738 /* If this is a nested type whose containing class hasn't been written
22739 out yet, writing it out will cover this one, too. This does not apply
22740 to instantiations of member class templates; they need to be added to
22741 the containing class as they are generated. FIXME: This hurts the
22742 idea of combining type decls from multiple TUs, since we can't predict
22743 what set of template instantiations we'll get. */
22744 else if (TYPE_CONTEXT (type
)
22745 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
22746 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
22748 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
22750 if (TREE_ASM_WRITTEN (type
))
22753 /* If that failed, attach ourselves to the stub. */
22754 push_decl_scope (TYPE_CONTEXT (type
));
22755 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
22758 else if (TYPE_CONTEXT (type
) != NULL_TREE
22759 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
22761 /* If this type is local to a function that hasn't been written
22762 out yet, use a NULL context for now; it will be fixed up in
22763 decls_for_scope. */
22764 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
22765 /* A declaration DIE doesn't count; nested types need to go in the
22767 if (context_die
&& is_declaration_die (context_die
))
22768 context_die
= NULL
;
22773 context_die
= declare_in_namespace (type
, context_die
);
22777 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
22779 /* This might have been written out by the call to
22780 declare_in_namespace. */
22781 if (!TREE_ASM_WRITTEN (type
))
22782 gen_enumeration_type_die (type
, context_die
);
22785 gen_struct_or_union_type_die (type
, context_die
, usage
);
22790 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
22791 it up if it is ever completed. gen_*_type_die will set it for us
22792 when appropriate. */
22795 /* Generate a type description DIE. */
22798 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
22799 enum debug_info_usage usage
)
22801 struct array_descr_info info
;
22803 if (type
== NULL_TREE
|| type
== error_mark_node
)
22806 if (flag_checking
&& type
)
22807 verify_type (type
);
22809 if (TYPE_NAME (type
) != NULL_TREE
22810 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
22811 && is_redundant_typedef (TYPE_NAME (type
))
22812 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
22813 /* The DECL of this type is a typedef we don't want to emit debug
22814 info for but we want debug info for its underlying typedef.
22815 This can happen for e.g, the injected-class-name of a C++
22817 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
22819 /* If TYPE is a typedef type variant, let's generate debug info
22820 for the parent typedef which TYPE is a type of. */
22821 if (typedef_variant_p (type
))
22823 if (TREE_ASM_WRITTEN (type
))
22826 /* Prevent broken recursion; we can't hand off to the same type. */
22827 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
22829 /* Give typedefs the right scope. */
22830 context_die
= scope_die_for (type
, context_die
);
22832 TREE_ASM_WRITTEN (type
) = 1;
22834 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
22838 /* If type is an anonymous tagged type named by a typedef, let's
22839 generate debug info for the typedef. */
22840 if (is_naming_typedef_decl (TYPE_NAME (type
)))
22842 /* Use the DIE of the containing namespace as the parent DIE of
22843 the type description DIE we want to generate. */
22844 if (DECL_CONTEXT (TYPE_NAME (type
))
22845 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
22846 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
22848 gen_decl_die (TYPE_NAME (type
), NULL
, NULL
, context_die
);
22852 /* We are going to output a DIE to represent the unqualified version
22853 of this type (i.e. without any const or volatile qualifiers) so
22854 get the main variant (i.e. the unqualified version) of this type
22855 now. (Vectors and arrays are special because the debugging info is in the
22856 cloned type itself). */
22857 if (TREE_CODE (type
) != VECTOR_TYPE
22858 && TREE_CODE (type
) != ARRAY_TYPE
)
22859 type
= type_main_variant (type
);
22861 /* If this is an array type with hidden descriptor, handle it first. */
22862 if (!TREE_ASM_WRITTEN (type
)
22863 && lang_hooks
.types
.get_array_descr_info
)
22865 memset (&info
, 0, sizeof (info
));
22866 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
22868 /* Fortran sometimes emits array types with no dimension. */
22869 gcc_assert (info
.ndimensions
>= 0
22870 && (info
.ndimensions
22871 <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
));
22872 gen_descr_array_type_die (type
, &info
, context_die
);
22873 TREE_ASM_WRITTEN (type
) = 1;
22878 if (TREE_ASM_WRITTEN (type
))
22880 /* Variable-length types may be incomplete even if
22881 TREE_ASM_WRITTEN. For such types, fall through to
22882 gen_array_type_die() and possibly fill in
22883 DW_AT_{upper,lower}_bound attributes. */
22884 if ((TREE_CODE (type
) != ARRAY_TYPE
22885 && TREE_CODE (type
) != RECORD_TYPE
22886 && TREE_CODE (type
) != UNION_TYPE
22887 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
22888 || !variably_modified_type_p (type
, NULL
))
22892 switch (TREE_CODE (type
))
22898 case REFERENCE_TYPE
:
22899 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
22900 ensures that the gen_type_die recursion will terminate even if the
22901 type is recursive. Recursive types are possible in Ada. */
22902 /* ??? We could perhaps do this for all types before the switch
22904 TREE_ASM_WRITTEN (type
) = 1;
22906 /* For these types, all that is required is that we output a DIE (or a
22907 set of DIEs) to represent the "basis" type. */
22908 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
22909 DINFO_USAGE_IND_USE
);
22913 /* This code is used for C++ pointer-to-data-member types.
22914 Output a description of the relevant class type. */
22915 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
22916 DINFO_USAGE_IND_USE
);
22918 /* Output a description of the type of the object pointed to. */
22919 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
22920 DINFO_USAGE_IND_USE
);
22922 /* Now output a DIE to represent this pointer-to-data-member type
22924 gen_ptr_to_mbr_type_die (type
, context_die
);
22927 case FUNCTION_TYPE
:
22928 /* Force out return type (in case it wasn't forced out already). */
22929 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
22930 DINFO_USAGE_DIR_USE
);
22931 gen_subroutine_type_die (type
, context_die
);
22935 /* Force out return type (in case it wasn't forced out already). */
22936 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
22937 DINFO_USAGE_DIR_USE
);
22938 gen_subroutine_type_die (type
, context_die
);
22943 gen_array_type_die (type
, context_die
);
22946 case ENUMERAL_TYPE
:
22949 case QUAL_UNION_TYPE
:
22950 gen_tagged_type_die (type
, context_die
, usage
);
22956 case FIXED_POINT_TYPE
:
22959 case POINTER_BOUNDS_TYPE
:
22960 /* No DIEs needed for fundamental types. */
22965 /* Just use DW_TAG_unspecified_type. */
22967 dw_die_ref type_die
= lookup_type_die (type
);
22968 if (type_die
== NULL
)
22970 tree name
= TYPE_IDENTIFIER (type
);
22971 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
22973 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
22974 equate_type_number_to_die (type
, type_die
);
22980 if (is_cxx_auto (type
))
22982 tree name
= TYPE_IDENTIFIER (type
);
22983 dw_die_ref
*die
= (name
== get_identifier ("auto")
22984 ? &auto_die
: &decltype_auto_die
);
22987 *die
= new_die (DW_TAG_unspecified_type
,
22988 comp_unit_die (), NULL_TREE
);
22989 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
22991 equate_type_number_to_die (type
, *die
);
22994 gcc_unreachable ();
22997 TREE_ASM_WRITTEN (type
) = 1;
23001 gen_type_die (tree type
, dw_die_ref context_die
)
23003 if (type
!= error_mark_node
)
23005 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
23008 dw_die_ref die
= lookup_type_die (type
);
23015 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
23016 things which are local to the given block. */
23019 gen_block_die (tree stmt
, dw_die_ref context_die
)
23021 int must_output_die
= 0;
23024 /* Ignore blocks that are NULL. */
23025 if (stmt
== NULL_TREE
)
23028 inlined_func
= inlined_function_outer_scope_p (stmt
);
23030 /* If the block is one fragment of a non-contiguous block, do not
23031 process the variables, since they will have been done by the
23032 origin block. Do process subblocks. */
23033 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
23037 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
23038 gen_block_die (sub
, context_die
);
23043 /* Determine if we need to output any Dwarf DIEs at all to represent this
23046 /* The outer scopes for inlinings *must* always be represented. We
23047 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
23048 must_output_die
= 1;
23051 /* Determine if this block directly contains any "significant"
23052 local declarations which we will need to output DIEs for. */
23053 if (debug_info_level
> DINFO_LEVEL_TERSE
)
23054 /* We are not in terse mode so *any* local declaration counts
23055 as being a "significant" one. */
23056 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
23057 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
23058 && (TREE_USED (stmt
)
23059 || TREE_ASM_WRITTEN (stmt
)
23060 || BLOCK_ABSTRACT (stmt
)));
23061 else if ((TREE_USED (stmt
)
23062 || TREE_ASM_WRITTEN (stmt
)
23063 || BLOCK_ABSTRACT (stmt
))
23064 && !dwarf2out_ignore_block (stmt
))
23065 must_output_die
= 1;
23068 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
23069 DIE for any block which contains no significant local declarations at
23070 all. Rather, in such cases we just call `decls_for_scope' so that any
23071 needed Dwarf info for any sub-blocks will get properly generated. Note
23072 that in terse mode, our definition of what constitutes a "significant"
23073 local declaration gets restricted to include only inlined function
23074 instances and local (nested) function definitions. */
23075 if (must_output_die
)
23079 /* If STMT block is abstract, that means we have been called
23080 indirectly from dwarf2out_abstract_function.
23081 That function rightfully marks the descendent blocks (of
23082 the abstract function it is dealing with) as being abstract,
23083 precisely to prevent us from emitting any
23084 DW_TAG_inlined_subroutine DIE as a descendent
23085 of an abstract function instance. So in that case, we should
23086 not call gen_inlined_subroutine_die.
23088 Later though, when cgraph asks dwarf2out to emit info
23089 for the concrete instance of the function decl into which
23090 the concrete instance of STMT got inlined, the later will lead
23091 to the generation of a DW_TAG_inlined_subroutine DIE. */
23092 if (! BLOCK_ABSTRACT (stmt
))
23093 gen_inlined_subroutine_die (stmt
, context_die
);
23096 gen_lexical_block_die (stmt
, context_die
);
23099 decls_for_scope (stmt
, context_die
);
23102 /* Process variable DECL (or variable with origin ORIGIN) within
23103 block STMT and add it to CONTEXT_DIE. */
23105 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
23108 tree decl_or_origin
= decl
? decl
: origin
;
23110 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
23111 die
= lookup_decl_die (decl_or_origin
);
23112 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
23113 && TYPE_DECL_IS_STUB (decl_or_origin
))
23114 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
23118 if (die
!= NULL
&& die
->die_parent
== NULL
)
23119 add_child_die (context_die
, die
);
23120 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
23123 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
23124 stmt
, context_die
);
23127 gen_decl_die (decl
, origin
, NULL
, context_die
);
23130 /* Generate all of the decls declared within a given scope and (recursively)
23131 all of its sub-blocks. */
23134 decls_for_scope (tree stmt
, dw_die_ref context_die
)
23140 /* Ignore NULL blocks. */
23141 if (stmt
== NULL_TREE
)
23144 /* Output the DIEs to represent all of the data objects and typedefs
23145 declared directly within this block but not within any nested
23146 sub-blocks. Also, nested function and tag DIEs have been
23147 generated with a parent of NULL; fix that up now. We don't
23148 have to do this if we're at -g1. */
23149 if (debug_info_level
> DINFO_LEVEL_TERSE
)
23151 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
23152 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
23153 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
23154 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
23158 /* Even if we're at -g1, we need to process the subblocks in order to get
23159 inlined call information. */
23161 /* Output the DIEs to represent all sub-blocks (and the items declared
23162 therein) of this block. */
23163 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
23165 subblocks
= BLOCK_CHAIN (subblocks
))
23166 gen_block_die (subblocks
, context_die
);
23169 /* Is this a typedef we can avoid emitting? */
23172 is_redundant_typedef (const_tree decl
)
23174 if (TYPE_DECL_IS_STUB (decl
))
23177 if (DECL_ARTIFICIAL (decl
)
23178 && DECL_CONTEXT (decl
)
23179 && is_tagged_type (DECL_CONTEXT (decl
))
23180 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
23181 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
23182 /* Also ignore the artificial member typedef for the class name. */
23188 /* Return TRUE if TYPE is a typedef that names a type for linkage
23189 purposes. This kind of typedefs is produced by the C++ FE for
23192 typedef struct {...} foo;
23194 In that case, there is no typedef variant type produced for foo.
23195 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
23199 is_naming_typedef_decl (const_tree decl
)
23201 if (decl
== NULL_TREE
23202 || TREE_CODE (decl
) != TYPE_DECL
23203 || DECL_NAMELESS (decl
)
23204 || !is_tagged_type (TREE_TYPE (decl
))
23205 || DECL_IS_BUILTIN (decl
)
23206 || is_redundant_typedef (decl
)
23207 /* It looks like Ada produces TYPE_DECLs that are very similar
23208 to C++ naming typedefs but that have different
23209 semantics. Let's be specific to c++ for now. */
23213 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
23214 && TYPE_NAME (TREE_TYPE (decl
)) == decl
23215 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
23216 != TYPE_NAME (TREE_TYPE (decl
))));
23219 /* Looks up the DIE for a context. */
23221 static inline dw_die_ref
23222 lookup_context_die (tree context
)
23226 /* Find die that represents this context. */
23227 if (TYPE_P (context
))
23229 context
= TYPE_MAIN_VARIANT (context
);
23230 dw_die_ref ctx
= lookup_type_die (context
);
23233 return strip_naming_typedef (context
, ctx
);
23236 return lookup_decl_die (context
);
23238 return comp_unit_die ();
23241 /* Returns the DIE for a context. */
23243 static inline dw_die_ref
23244 get_context_die (tree context
)
23248 /* Find die that represents this context. */
23249 if (TYPE_P (context
))
23251 context
= TYPE_MAIN_VARIANT (context
);
23252 return strip_naming_typedef (context
, force_type_die (context
));
23255 return force_decl_die (context
);
23257 return comp_unit_die ();
23260 /* Returns the DIE for decl. A DIE will always be returned. */
23263 force_decl_die (tree decl
)
23265 dw_die_ref decl_die
;
23266 unsigned saved_external_flag
;
23267 tree save_fn
= NULL_TREE
;
23268 decl_die
= lookup_decl_die (decl
);
23271 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
23273 decl_die
= lookup_decl_die (decl
);
23277 switch (TREE_CODE (decl
))
23279 case FUNCTION_DECL
:
23280 /* Clear current_function_decl, so that gen_subprogram_die thinks
23281 that this is a declaration. At this point, we just want to force
23282 declaration die. */
23283 save_fn
= current_function_decl
;
23284 current_function_decl
= NULL_TREE
;
23285 gen_subprogram_die (decl
, context_die
);
23286 current_function_decl
= save_fn
;
23290 /* Set external flag to force declaration die. Restore it after
23291 gen_decl_die() call. */
23292 saved_external_flag
= DECL_EXTERNAL (decl
);
23293 DECL_EXTERNAL (decl
) = 1;
23294 gen_decl_die (decl
, NULL
, NULL
, context_die
);
23295 DECL_EXTERNAL (decl
) = saved_external_flag
;
23298 case NAMESPACE_DECL
:
23299 if (dwarf_version
>= 3 || !dwarf_strict
)
23300 dwarf2out_decl (decl
);
23302 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
23303 decl_die
= comp_unit_die ();
23306 case TRANSLATION_UNIT_DECL
:
23307 decl_die
= comp_unit_die ();
23311 gcc_unreachable ();
23314 /* We should be able to find the DIE now. */
23316 decl_die
= lookup_decl_die (decl
);
23317 gcc_assert (decl_die
);
23323 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
23324 always returned. */
23327 force_type_die (tree type
)
23329 dw_die_ref type_die
;
23331 type_die
= lookup_type_die (type
);
23334 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
23336 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
23337 false, context_die
);
23338 gcc_assert (type_die
);
23343 /* Force out any required namespaces to be able to output DECL,
23344 and return the new context_die for it, if it's changed. */
23347 setup_namespace_context (tree thing
, dw_die_ref context_die
)
23349 tree context
= (DECL_P (thing
)
23350 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
23351 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
23352 /* Force out the namespace. */
23353 context_die
= force_decl_die (context
);
23355 return context_die
;
23358 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
23359 type) within its namespace, if appropriate.
23361 For compatibility with older debuggers, namespace DIEs only contain
23362 declarations; all definitions are emitted at CU scope, with
23363 DW_AT_specification pointing to the declaration (like with class
23367 declare_in_namespace (tree thing
, dw_die_ref context_die
)
23369 dw_die_ref ns_context
;
23371 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23372 return context_die
;
23374 /* External declarations in the local scope only need to be emitted
23375 once, not once in the namespace and once in the scope.
23377 This avoids declaring the `extern' below in the
23378 namespace DIE as well as in the innermost scope:
23391 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
23392 return context_die
;
23394 /* If this decl is from an inlined function, then don't try to emit it in its
23395 namespace, as we will get confused. It would have already been emitted
23396 when the abstract instance of the inline function was emitted anyways. */
23397 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
23398 return context_die
;
23400 ns_context
= setup_namespace_context (thing
, context_die
);
23402 if (ns_context
!= context_die
)
23406 if (DECL_P (thing
))
23407 gen_decl_die (thing
, NULL
, NULL
, ns_context
);
23409 gen_type_die (thing
, ns_context
);
23411 return context_die
;
23414 /* Generate a DIE for a namespace or namespace alias. */
23417 gen_namespace_die (tree decl
, dw_die_ref context_die
)
23419 dw_die_ref namespace_die
;
23421 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
23422 they are an alias of. */
23423 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
23425 /* Output a real namespace or module. */
23426 context_die
= setup_namespace_context (decl
, comp_unit_die ());
23427 namespace_die
= new_die (is_fortran ()
23428 ? DW_TAG_module
: DW_TAG_namespace
,
23429 context_die
, decl
);
23430 /* For Fortran modules defined in different CU don't add src coords. */
23431 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
23433 const char *name
= dwarf2_name (decl
, 0);
23435 add_name_attribute (namespace_die
, name
);
23438 add_name_and_src_coords_attributes (namespace_die
, decl
);
23439 if (DECL_EXTERNAL (decl
))
23440 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
23441 equate_decl_number_to_die (decl
, namespace_die
);
23445 /* Output a namespace alias. */
23447 /* Force out the namespace we are an alias of, if necessary. */
23448 dw_die_ref origin_die
23449 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
23451 if (DECL_FILE_SCOPE_P (decl
)
23452 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
23453 context_die
= setup_namespace_context (decl
, comp_unit_die ());
23454 /* Now create the namespace alias DIE. */
23455 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
23456 add_name_and_src_coords_attributes (namespace_die
, decl
);
23457 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
23458 equate_decl_number_to_die (decl
, namespace_die
);
23460 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
23461 if (want_pubnames ())
23462 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
23465 /* Generate Dwarf debug information for a decl described by DECL.
23466 The return value is currently only meaningful for PARM_DECLs,
23467 for all other decls it returns NULL.
23469 If DECL is a FIELD_DECL, CTX is required: see the comment for VLR_CONTEXT.
23470 It can be NULL otherwise. */
23473 gen_decl_die (tree decl
, tree origin
, struct vlr_context
*ctx
,
23474 dw_die_ref context_die
)
23476 tree decl_or_origin
= decl
? decl
: origin
;
23477 tree class_origin
= NULL
, ultimate_origin
;
23479 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
23482 /* Ignore pointer bounds decls. */
23483 if (DECL_P (decl_or_origin
)
23484 && TREE_TYPE (decl_or_origin
)
23485 && POINTER_BOUNDS_P (decl_or_origin
))
23488 switch (TREE_CODE (decl_or_origin
))
23494 if (!is_fortran () && !is_ada ())
23496 /* The individual enumerators of an enum type get output when we output
23497 the Dwarf representation of the relevant enum type itself. */
23501 /* Emit its type. */
23502 gen_type_die (TREE_TYPE (decl
), context_die
);
23504 /* And its containing namespace. */
23505 context_die
= declare_in_namespace (decl
, context_die
);
23507 gen_const_die (decl
, context_die
);
23510 case FUNCTION_DECL
:
23511 /* Don't output any DIEs to represent mere function declarations,
23512 unless they are class members or explicit block externs. */
23513 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
23514 && DECL_FILE_SCOPE_P (decl_or_origin
)
23515 && (current_function_decl
== NULL_TREE
23516 || DECL_ARTIFICIAL (decl_or_origin
)))
23521 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
23522 on local redeclarations of global functions. That seems broken. */
23523 if (current_function_decl
!= decl
)
23524 /* This is only a declaration. */;
23527 /* If we're emitting a clone, emit info for the abstract instance. */
23528 if (origin
|| DECL_ORIGIN (decl
) != decl
)
23529 dwarf2out_abstract_function (origin
23530 ? DECL_ORIGIN (origin
)
23531 : DECL_ABSTRACT_ORIGIN (decl
));
23533 /* If we're emitting an out-of-line copy of an inline function,
23534 emit info for the abstract instance and set up to refer to it. */
23535 else if (cgraph_function_possibly_inlined_p (decl
)
23536 && ! DECL_ABSTRACT_P (decl
)
23537 && ! class_or_namespace_scope_p (context_die
)
23538 /* dwarf2out_abstract_function won't emit a die if this is just
23539 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
23540 that case, because that works only if we have a die. */
23541 && DECL_INITIAL (decl
) != NULL_TREE
)
23543 dwarf2out_abstract_function (decl
);
23544 set_decl_origin_self (decl
);
23547 /* Otherwise we're emitting the primary DIE for this decl. */
23548 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
23550 /* Before we describe the FUNCTION_DECL itself, make sure that we
23551 have its containing type. */
23553 origin
= decl_class_context (decl
);
23554 if (origin
!= NULL_TREE
)
23555 gen_type_die (origin
, context_die
);
23557 /* And its return type. */
23558 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
23560 /* And its virtual context. */
23561 if (DECL_VINDEX (decl
) != NULL_TREE
)
23562 gen_type_die (DECL_CONTEXT (decl
), context_die
);
23564 /* Make sure we have a member DIE for decl. */
23565 if (origin
!= NULL_TREE
)
23566 gen_type_die_for_member (origin
, decl
, context_die
);
23568 /* And its containing namespace. */
23569 context_die
= declare_in_namespace (decl
, context_die
);
23572 /* Now output a DIE to represent the function itself. */
23574 gen_subprogram_die (decl
, context_die
);
23578 /* If we are in terse mode, don't generate any DIEs to represent any
23579 actual typedefs. */
23580 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23583 /* In the special case of a TYPE_DECL node representing the declaration
23584 of some type tag, if the given TYPE_DECL is marked as having been
23585 instantiated from some other (original) TYPE_DECL node (e.g. one which
23586 was generated within the original definition of an inline function) we
23587 used to generate a special (abbreviated) DW_TAG_structure_type,
23588 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
23589 should be actually referencing those DIEs, as variable DIEs with that
23590 type would be emitted already in the abstract origin, so it was always
23591 removed during unused type prunning. Don't add anything in this
23593 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
23596 if (is_redundant_typedef (decl
))
23597 gen_type_die (TREE_TYPE (decl
), context_die
);
23599 /* Output a DIE to represent the typedef itself. */
23600 gen_typedef_die (decl
, context_die
);
23604 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23605 gen_label_die (decl
, context_die
);
23610 /* If we are in terse mode, don't generate any DIEs to represent any
23611 variable declarations or definitions. */
23612 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23615 /* Output any DIEs that are needed to specify the type of this data
23617 if (decl_by_reference_p (decl_or_origin
))
23618 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
23620 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
23622 /* And its containing type. */
23623 class_origin
= decl_class_context (decl_or_origin
);
23624 if (class_origin
!= NULL_TREE
)
23625 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
23627 /* And its containing namespace. */
23628 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
23630 /* Now output the DIE to represent the data object itself. This gets
23631 complicated because of the possibility that the VAR_DECL really
23632 represents an inlined instance of a formal parameter for an inline
23634 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
23635 if (ultimate_origin
!= NULL_TREE
23636 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
23637 gen_formal_parameter_die (decl
, origin
,
23638 true /* Emit name attribute. */,
23641 gen_variable_die (decl
, origin
, context_die
);
23645 gcc_assert (ctx
!= NULL
&& ctx
->struct_type
!= NULL
);
23646 /* Ignore the nameless fields that are used to skip bits but handle C++
23647 anonymous unions and structs. */
23648 if (DECL_NAME (decl
) != NULL_TREE
23649 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
23650 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
23652 gen_type_die (member_declared_type (decl
), context_die
);
23653 gen_field_die (decl
, ctx
, context_die
);
23658 if (DECL_BY_REFERENCE (decl_or_origin
))
23659 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
23661 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
23662 return gen_formal_parameter_die (decl
, origin
,
23663 true /* Emit name attribute. */,
23666 case NAMESPACE_DECL
:
23667 if (dwarf_version
>= 3 || !dwarf_strict
)
23668 gen_namespace_die (decl
, context_die
);
23671 case IMPORTED_DECL
:
23672 dwarf2out_imported_module_or_decl_1 (decl
, DECL_NAME (decl
),
23673 DECL_CONTEXT (decl
), context_die
);
23676 case NAMELIST_DECL
:
23677 gen_namelist_decl (DECL_NAME (decl
), context_die
,
23678 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
23682 /* Probably some frontend-internal decl. Assume we don't care. */
23683 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
23690 /* Output initial debug information for global DECL. Called at the
23691 end of the parsing process.
23693 This is the initial debug generation process. As such, the DIEs
23694 generated may be incomplete. A later debug generation pass
23695 (dwarf2out_late_global_decl) will augment the information generated
23696 in this pass (e.g., with complete location info). */
23699 dwarf2out_early_global_decl (tree decl
)
23703 /* gen_decl_die() will set DECL_ABSTRACT because
23704 cgraph_function_possibly_inlined_p() returns true. This is in
23705 turn will cause DW_AT_inline attributes to be set.
23707 This happens because at early dwarf generation, there is no
23708 cgraph information, causing cgraph_function_possibly_inlined_p()
23709 to return true. Trick cgraph_function_possibly_inlined_p()
23710 while we generate dwarf early. */
23711 bool save
= symtab
->global_info_ready
;
23712 symtab
->global_info_ready
= true;
23714 /* We don't handle TYPE_DECLs. If required, they'll be reached via
23715 other DECLs and they can point to template types or other things
23716 that dwarf2out can't handle when done via dwarf2out_decl. */
23717 if (TREE_CODE (decl
) != TYPE_DECL
23718 && TREE_CODE (decl
) != PARM_DECL
)
23720 tree save_fndecl
= current_function_decl
;
23721 if (TREE_CODE (decl
) == FUNCTION_DECL
)
23723 /* No cfun means the symbol has no body, so there's nothing
23725 if (!DECL_STRUCT_FUNCTION (decl
))
23726 goto early_decl_exit
;
23728 current_function_decl
= decl
;
23730 dwarf2out_decl (decl
);
23731 if (TREE_CODE (decl
) == FUNCTION_DECL
)
23732 current_function_decl
= save_fndecl
;
23735 symtab
->global_info_ready
= save
;
23738 /* Output debug information for global decl DECL. Called from
23739 toplev.c after compilation proper has finished. */
23742 dwarf2out_late_global_decl (tree decl
)
23744 /* We have to generate early debug late for LTO. */
23746 dwarf2out_early_global_decl (decl
);
23748 /* Fill-in any location information we were unable to determine
23749 on the first pass. */
23750 if (TREE_CODE (decl
) == VAR_DECL
23751 && !POINTER_BOUNDS_P (decl
))
23753 dw_die_ref die
= lookup_decl_die (decl
);
23755 add_location_or_const_value_attribute (die
, decl
, false);
23759 /* Output debug information for type decl DECL. Called from toplev.c
23760 and from language front ends (to record built-in types). */
23762 dwarf2out_type_decl (tree decl
, int local
)
23767 dwarf2out_decl (decl
);
23771 /* Output debug information for imported module or decl DECL.
23772 NAME is non-NULL name in the lexical block if the decl has been renamed.
23773 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
23774 that DECL belongs to.
23775 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
23777 dwarf2out_imported_module_or_decl_1 (tree decl
,
23779 tree lexical_block
,
23780 dw_die_ref lexical_block_die
)
23782 expanded_location xloc
;
23783 dw_die_ref imported_die
= NULL
;
23784 dw_die_ref at_import_die
;
23786 if (TREE_CODE (decl
) == IMPORTED_DECL
)
23788 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
23789 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
23793 xloc
= expand_location (input_location
);
23795 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
23797 at_import_die
= force_type_die (TREE_TYPE (decl
));
23798 /* For namespace N { typedef void T; } using N::T; base_type_die
23799 returns NULL, but DW_TAG_imported_declaration requires
23800 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
23801 if (!at_import_die
)
23803 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
23804 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
23805 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
23806 gcc_assert (at_import_die
);
23811 at_import_die
= lookup_decl_die (decl
);
23812 if (!at_import_die
)
23814 /* If we're trying to avoid duplicate debug info, we may not have
23815 emitted the member decl for this field. Emit it now. */
23816 if (TREE_CODE (decl
) == FIELD_DECL
)
23818 tree type
= DECL_CONTEXT (decl
);
23820 if (TYPE_CONTEXT (type
)
23821 && TYPE_P (TYPE_CONTEXT (type
))
23822 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
23823 DINFO_USAGE_DIR_USE
))
23825 gen_type_die_for_member (type
, decl
,
23826 get_context_die (TYPE_CONTEXT (type
)));
23828 if (TREE_CODE (decl
) == NAMELIST_DECL
)
23829 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
23830 get_context_die (DECL_CONTEXT (decl
)),
23833 at_import_die
= force_decl_die (decl
);
23837 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
23839 if (dwarf_version
>= 3 || !dwarf_strict
)
23840 imported_die
= new_die (DW_TAG_imported_module
,
23847 imported_die
= new_die (DW_TAG_imported_declaration
,
23851 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
23852 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
23854 add_AT_string (imported_die
, DW_AT_name
,
23855 IDENTIFIER_POINTER (name
));
23856 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
23859 /* Output debug information for imported module or decl DECL.
23860 NAME is non-NULL name in context if the decl has been renamed.
23861 CHILD is true if decl is one of the renamed decls as part of
23862 importing whole module. */
23865 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
23868 /* dw_die_ref at_import_die; */
23869 dw_die_ref scope_die
;
23871 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23878 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
23879 We need decl DIE for reference and scope die. First, get DIE for the decl
23882 /* Get the scope die for decl context. Use comp_unit_die for global module
23883 or decl. If die is not found for non globals, force new die. */
23885 && TYPE_P (context
)
23886 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
23889 if (!(dwarf_version
>= 3 || !dwarf_strict
))
23892 scope_die
= get_context_die (context
);
23896 gcc_assert (scope_die
->die_child
);
23897 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
23898 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
23899 scope_die
= scope_die
->die_child
;
23902 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
23903 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
23906 /* Output debug information for namelists. */
23909 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
23911 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
23915 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
23918 gcc_assert (scope_die
!= NULL
);
23919 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
23920 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
23922 /* If there are no item_decls, we have a nondefining namelist, e.g.
23923 with USE association; hence, set DW_AT_declaration. */
23924 if (item_decls
== NULL_TREE
)
23926 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
23930 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
23932 nml_item_ref_die
= lookup_decl_die (value
);
23933 if (!nml_item_ref_die
)
23934 nml_item_ref_die
= force_decl_die (value
);
23936 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
23937 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
23943 /* Write the debugging output for DECL and return the DIE. */
23946 dwarf2out_decl (tree decl
)
23948 dw_die_ref context_die
= comp_unit_die ();
23950 switch (TREE_CODE (decl
))
23955 case FUNCTION_DECL
:
23956 /* What we would really like to do here is to filter out all mere
23957 file-scope declarations of file-scope functions which are never
23958 referenced later within this translation unit (and keep all of ones
23959 that *are* referenced later on) but we aren't clairvoyant, so we have
23960 no idea which functions will be referenced in the future (i.e. later
23961 on within the current translation unit). So here we just ignore all
23962 file-scope function declarations which are not also definitions. If
23963 and when the debugger needs to know something about these functions,
23964 it will have to hunt around and find the DWARF information associated
23965 with the definition of the function.
23967 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
23968 nodes represent definitions and which ones represent mere
23969 declarations. We have to check DECL_INITIAL instead. That's because
23970 the C front-end supports some weird semantics for "extern inline"
23971 function definitions. These can get inlined within the current
23972 translation unit (and thus, we need to generate Dwarf info for their
23973 abstract instances so that the Dwarf info for the concrete inlined
23974 instances can have something to refer to) but the compiler never
23975 generates any out-of-lines instances of such things (despite the fact
23976 that they *are* definitions).
23978 The important point is that the C front-end marks these "extern
23979 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
23980 them anyway. Note that the C++ front-end also plays some similar games
23981 for inline function definitions appearing within include files which
23982 also contain `#pragma interface' pragmas.
23984 If we are called from dwarf2out_abstract_function output a DIE
23985 anyway. We can end up here this way with early inlining and LTO
23986 where the inlined function is output in a different LTRANS unit
23988 if (DECL_INITIAL (decl
) == NULL_TREE
23989 && ! DECL_ABSTRACT_P (decl
))
23992 /* If we're a nested function, initially use a parent of NULL; if we're
23993 a plain function, this will be fixed up in decls_for_scope. If
23994 we're a method, it will be ignored, since we already have a DIE. */
23995 if (decl_function_context (decl
)
23996 /* But if we're in terse mode, we don't care about scope. */
23997 && debug_info_level
> DINFO_LEVEL_TERSE
)
23998 context_die
= NULL
;
24002 /* For local statics lookup proper context die. */
24003 if (local_function_static (decl
))
24004 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
24006 /* If we are in terse mode, don't generate any DIEs to represent any
24007 variable declarations or definitions. */
24008 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24013 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24015 if (!is_fortran () && !is_ada ())
24017 if (TREE_STATIC (decl
) && decl_function_context (decl
))
24018 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
24021 case NAMESPACE_DECL
:
24022 case IMPORTED_DECL
:
24023 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24025 if (lookup_decl_die (decl
) != NULL
)
24030 /* Don't emit stubs for types unless they are needed by other DIEs. */
24031 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
24034 /* Don't bother trying to generate any DIEs to represent any of the
24035 normal built-in types for the language we are compiling. */
24036 if (DECL_IS_BUILTIN (decl
))
24039 /* If we are in terse mode, don't generate any DIEs for types. */
24040 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
24043 /* If we're a function-scope tag, initially use a parent of NULL;
24044 this will be fixed up in decls_for_scope. */
24045 if (decl_function_context (decl
))
24046 context_die
= NULL
;
24050 case NAMELIST_DECL
:
24057 gen_decl_die (decl
, NULL
, NULL
, context_die
);
24061 dw_die_ref die
= lookup_decl_die (decl
);
24067 /* Write the debugging output for DECL. */
24070 dwarf2out_function_decl (tree decl
)
24072 dwarf2out_decl (decl
);
24073 call_arg_locations
= NULL
;
24074 call_arg_loc_last
= NULL
;
24075 call_site_count
= -1;
24076 tail_call_site_count
= -1;
24077 decl_loc_table
->empty ();
24078 cached_dw_loc_list_table
->empty ();
24081 /* Output a marker (i.e. a label) for the beginning of the generated code for
24082 a lexical block. */
24085 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
24086 unsigned int blocknum
)
24088 switch_to_section (current_function_section ());
24089 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
24092 /* Output a marker (i.e. a label) for the end of the generated code for a
24096 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
24098 switch_to_section (current_function_section ());
24099 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
24102 /* Returns nonzero if it is appropriate not to emit any debugging
24103 information for BLOCK, because it doesn't contain any instructions.
24105 Don't allow this for blocks with nested functions or local classes
24106 as we would end up with orphans, and in the presence of scheduling
24107 we may end up calling them anyway. */
24110 dwarf2out_ignore_block (const_tree block
)
24115 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
24116 if (TREE_CODE (decl
) == FUNCTION_DECL
24117 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
24119 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
24121 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
24122 if (TREE_CODE (decl
) == FUNCTION_DECL
24123 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
24130 /* Hash table routines for file_hash. */
24133 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
24135 return filename_cmp (p1
->filename
, p2
) == 0;
24139 dwarf_file_hasher::hash (dwarf_file_data
*p
)
24141 return htab_hash_string (p
->filename
);
24144 /* Lookup FILE_NAME (in the list of filenames that we know about here in
24145 dwarf2out.c) and return its "index". The index of each (known) filename is
24146 just a unique number which is associated with only that one filename. We
24147 need such numbers for the sake of generating labels (in the .debug_sfnames
24148 section) and references to those files numbers (in the .debug_srcinfo
24149 and .debug_macinfo sections). If the filename given as an argument is not
24150 found in our current list, add it to the list and assign it the next
24151 available unique index number. */
24153 static struct dwarf_file_data
*
24154 lookup_filename (const char *file_name
)
24156 struct dwarf_file_data
* created
;
24161 dwarf_file_data
**slot
24162 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
24167 created
= ggc_alloc
<dwarf_file_data
> ();
24168 created
->filename
= file_name
;
24169 created
->emitted_number
= 0;
24174 /* If the assembler will construct the file table, then translate the compiler
24175 internal file table number into the assembler file table number, and emit
24176 a .file directive if we haven't already emitted one yet. The file table
24177 numbers are different because we prune debug info for unused variables and
24178 types, which may include filenames. */
24181 maybe_emit_file (struct dwarf_file_data
* fd
)
24183 if (! fd
->emitted_number
)
24185 if (last_emitted_file
)
24186 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
24188 fd
->emitted_number
= 1;
24189 last_emitted_file
= fd
;
24191 if (DWARF2_ASM_LINE_DEBUG_INFO
)
24193 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
24194 output_quoted_string (asm_out_file
,
24195 remap_debug_filename (fd
->filename
));
24196 fputc ('\n', asm_out_file
);
24200 return fd
->emitted_number
;
24203 /* Schedule generation of a DW_AT_const_value attribute to DIE.
24204 That generation should happen after function debug info has been
24205 generated. The value of the attribute is the constant value of ARG. */
24208 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
24210 die_arg_entry entry
;
24215 gcc_assert (early_dwarf
);
24217 if (!tmpl_value_parm_die_table
)
24218 vec_alloc (tmpl_value_parm_die_table
, 32);
24222 vec_safe_push (tmpl_value_parm_die_table
, entry
);
24225 /* Return TRUE if T is an instance of generic type, FALSE
24229 generic_type_p (tree t
)
24231 if (t
== NULL_TREE
|| !TYPE_P (t
))
24233 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
24236 /* Schedule the generation of the generic parameter dies for the
24237 instance of generic type T. The proper generation itself is later
24238 done by gen_scheduled_generic_parms_dies. */
24241 schedule_generic_params_dies_gen (tree t
)
24243 if (!generic_type_p (t
))
24246 gcc_assert (early_dwarf
);
24248 if (!generic_type_instances
)
24249 vec_alloc (generic_type_instances
, 256);
24251 vec_safe_push (generic_type_instances
, t
);
24254 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
24255 by append_entry_to_tmpl_value_parm_die_table. This function must
24256 be called after function DIEs have been generated. */
24259 gen_remaining_tmpl_value_param_die_attribute (void)
24261 if (tmpl_value_parm_die_table
)
24266 /* We do this in two phases - first get the cases we can
24267 handle during early-finish, preserving those we cannot
24268 (containing symbolic constants where we don't yet know
24269 whether we are going to output the referenced symbols).
24270 For those we try again at late-finish. */
24272 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
24274 if (!tree_add_const_value_attribute (e
->die
, e
->arg
))
24275 (*tmpl_value_parm_die_table
)[j
++] = *e
;
24277 tmpl_value_parm_die_table
->truncate (j
);
24281 /* Generate generic parameters DIEs for instances of generic types
24282 that have been previously scheduled by
24283 schedule_generic_params_dies_gen. This function must be called
24284 after all the types of the CU have been laid out. */
24287 gen_scheduled_generic_parms_dies (void)
24292 if (!generic_type_instances
)
24295 /* We end up "recursing" into schedule_generic_params_dies_gen, so
24296 pretend this generation is part of "early dwarf" as well. */
24299 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
24300 if (COMPLETE_TYPE_P (t
))
24301 gen_generic_params_dies (t
);
24303 generic_type_instances
= NULL
;
24307 /* Replace DW_AT_name for the decl with name. */
24310 dwarf2out_set_name (tree decl
, tree name
)
24313 dw_attr_node
*attr
;
24316 die
= TYPE_SYMTAB_DIE (decl
);
24320 dname
= dwarf2_name (name
, 0);
24324 attr
= get_AT (die
, DW_AT_name
);
24327 struct indirect_string_node
*node
;
24329 node
= find_AT_string (dname
);
24330 /* replace the string. */
24331 attr
->dw_attr_val
.v
.val_str
= node
;
24335 add_name_attribute (die
, dname
);
24338 /* True if before or during processing of the first function being emitted. */
24339 static bool in_first_function_p
= true;
24340 /* True if loc_note during dwarf2out_var_location call might still be
24341 before first real instruction at address equal to .Ltext0. */
24342 static bool maybe_at_text_label_p
= true;
24343 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
24344 static unsigned int first_loclabel_num_not_at_text_label
;
24346 /* Called by the final INSN scan whenever we see a var location. We
24347 use it to drop labels in the right places, and throw the location in
24348 our lookup table. */
24351 dwarf2out_var_location (rtx_insn
*loc_note
)
24353 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
24354 struct var_loc_node
*newloc
;
24355 rtx_insn
*next_real
, *next_note
;
24356 rtx_insn
*call_insn
= NULL
;
24357 static const char *last_label
;
24358 static const char *last_postcall_label
;
24359 static bool last_in_cold_section_p
;
24360 static rtx_insn
*expected_next_loc_note
;
24364 if (!NOTE_P (loc_note
))
24366 if (CALL_P (loc_note
))
24369 if (SIBLING_CALL_P (loc_note
))
24370 tail_call_site_count
++;
24371 if (optimize
== 0 && !flag_var_tracking
)
24373 /* When the var-tracking pass is not running, there is no note
24374 for indirect calls whose target is compile-time known. In this
24375 case, process such calls specifically so that we generate call
24376 sites for them anyway. */
24377 rtx x
= PATTERN (loc_note
);
24378 if (GET_CODE (x
) == PARALLEL
)
24379 x
= XVECEXP (x
, 0, 0);
24380 if (GET_CODE (x
) == SET
)
24382 if (GET_CODE (x
) == CALL
)
24385 || GET_CODE (XEXP (x
, 0)) != SYMBOL_REF
24386 || !SYMBOL_REF_DECL (XEXP (x
, 0))
24387 || (TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0)))
24390 call_insn
= loc_note
;
24394 next_real
= next_real_insn (call_insn
);
24396 cached_next_real_insn
= NULL
;
24404 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
24405 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
24408 /* Optimize processing a large consecutive sequence of location
24409 notes so we don't spend too much time in next_real_insn. If the
24410 next insn is another location note, remember the next_real_insn
24411 calculation for next time. */
24412 next_real
= cached_next_real_insn
;
24415 if (expected_next_loc_note
!= loc_note
)
24419 next_note
= NEXT_INSN (loc_note
);
24421 || next_note
->deleted ()
24422 || ! NOTE_P (next_note
)
24423 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
24424 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
24428 next_real
= next_real_insn (loc_note
);
24432 expected_next_loc_note
= next_note
;
24433 cached_next_real_insn
= next_real
;
24436 cached_next_real_insn
= NULL
;
24438 /* If there are no instructions which would be affected by this note,
24439 don't do anything. */
24441 && next_real
== NULL_RTX
24442 && !NOTE_DURING_CALL_P (loc_note
))
24447 if (next_real
== NULL_RTX
)
24448 next_real
= get_last_insn ();
24450 /* If there were any real insns between note we processed last time
24451 and this note (or if it is the first note), clear
24452 last_{,postcall_}label so that they are not reused this time. */
24453 if (last_var_location_insn
== NULL_RTX
24454 || last_var_location_insn
!= next_real
24455 || last_in_cold_section_p
!= in_cold_section_p
)
24458 last_postcall_label
= NULL
;
24463 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
24464 newloc
= add_var_loc_to_decl (decl
, loc_note
,
24465 NOTE_DURING_CALL_P (loc_note
)
24466 ? last_postcall_label
: last_label
);
24467 if (newloc
== NULL
)
24476 /* If there were no real insns between note we processed last time
24477 and this note, use the label we emitted last time. Otherwise
24478 create a new label and emit it. */
24479 if (last_label
== NULL
)
24481 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
24482 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
24484 last_label
= ggc_strdup (loclabel
);
24485 /* See if loclabel might be equal to .Ltext0. If yes,
24486 bump first_loclabel_num_not_at_text_label. */
24487 if (!have_multiple_function_sections
24488 && in_first_function_p
24489 && maybe_at_text_label_p
)
24491 static rtx_insn
*last_start
;
24493 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
24494 if (insn
== last_start
)
24496 else if (!NONDEBUG_INSN_P (insn
))
24500 rtx body
= PATTERN (insn
);
24501 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
24503 /* Inline asm could occupy zero bytes. */
24504 else if (GET_CODE (body
) == ASM_INPUT
24505 || asm_noperands (body
) >= 0)
24507 #ifdef HAVE_attr_length
24508 else if (get_attr_min_length (insn
) == 0)
24513 /* Assume insn has non-zero length. */
24514 maybe_at_text_label_p
= false;
24518 if (maybe_at_text_label_p
)
24520 last_start
= loc_note
;
24521 first_loclabel_num_not_at_text_label
= loclabel_num
;
24526 gcc_assert ((loc_note
== NULL_RTX
&& call_insn
!= NULL_RTX
)
24527 || (loc_note
!= NULL_RTX
&& call_insn
== NULL_RTX
));
24531 struct call_arg_loc_node
*ca_loc
24532 = ggc_cleared_alloc
<call_arg_loc_node
> ();
24534 = loc_note
!= NULL_RTX
? prev_real_insn (loc_note
) : call_insn
;
24536 ca_loc
->call_arg_loc_note
= loc_note
;
24537 ca_loc
->next
= NULL
;
24538 ca_loc
->label
= last_label
;
24541 || (NONJUMP_INSN_P (prev
)
24542 && GET_CODE (PATTERN (prev
)) == SEQUENCE
24543 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
24544 if (!CALL_P (prev
))
24545 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
24546 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
24548 /* Look for a SYMBOL_REF in the "prev" instruction. */
24549 rtx x
= get_call_rtx_from (PATTERN (prev
));
24552 /* Try to get the call symbol, if any. */
24553 if (MEM_P (XEXP (x
, 0)))
24555 /* First, look for a memory access to a symbol_ref. */
24556 if (GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
24557 && SYMBOL_REF_DECL (XEXP (x
, 0))
24558 && TREE_CODE (SYMBOL_REF_DECL (XEXP (x
, 0))) == FUNCTION_DECL
)
24559 ca_loc
->symbol_ref
= XEXP (x
, 0);
24560 /* Otherwise, look at a compile-time known user-level function
24564 && TREE_CODE (MEM_EXPR (x
)) == FUNCTION_DECL
)
24565 ca_loc
->symbol_ref
= XEXP (DECL_RTL (MEM_EXPR (x
)), 0);
24568 ca_loc
->block
= insn_scope (prev
);
24569 if (call_arg_locations
)
24570 call_arg_loc_last
->next
= ca_loc
;
24572 call_arg_locations
= ca_loc
;
24573 call_arg_loc_last
= ca_loc
;
24575 else if (loc_note
!= NULL_RTX
&& !NOTE_DURING_CALL_P (loc_note
))
24576 newloc
->label
= last_label
;
24579 if (!last_postcall_label
)
24581 sprintf (loclabel
, "%s-1", last_label
);
24582 last_postcall_label
= ggc_strdup (loclabel
);
24584 newloc
->label
= last_postcall_label
;
24587 last_var_location_insn
= next_real
;
24588 last_in_cold_section_p
= in_cold_section_p
;
24591 /* Called from finalize_size_functions for size functions so that their body
24592 can be encoded in the debug info to describe the layout of variable-length
24596 dwarf2out_size_function (tree decl
)
24598 function_to_dwarf_procedure (decl
);
24601 /* Note in one location list that text section has changed. */
24604 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
24606 var_loc_list
*list
= *slot
;
24608 list
->last_before_switch
24609 = list
->last
->next
? list
->last
->next
: list
->last
;
24613 /* Note in all location lists that text section has changed. */
24616 var_location_switch_text_section (void)
24618 if (decl_loc_table
== NULL
)
24621 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
24624 /* Create a new line number table. */
24626 static dw_line_info_table
*
24627 new_line_info_table (void)
24629 dw_line_info_table
*table
;
24631 table
= ggc_cleared_alloc
<dw_line_info_table
> ();
24632 table
->file_num
= 1;
24633 table
->line_num
= 1;
24634 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
24639 /* Lookup the "current" table into which we emit line info, so
24640 that we don't have to do it for every source line. */
24643 set_cur_line_info_table (section
*sec
)
24645 dw_line_info_table
*table
;
24647 if (sec
== text_section
)
24648 table
= text_section_line_info
;
24649 else if (sec
== cold_text_section
)
24651 table
= cold_text_section_line_info
;
24654 cold_text_section_line_info
= table
= new_line_info_table ();
24655 table
->end_label
= cold_end_label
;
24660 const char *end_label
;
24662 if (flag_reorder_blocks_and_partition
)
24664 if (in_cold_section_p
)
24665 end_label
= crtl
->subsections
.cold_section_end_label
;
24667 end_label
= crtl
->subsections
.hot_section_end_label
;
24671 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
24672 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
24673 current_function_funcdef_no
);
24674 end_label
= ggc_strdup (label
);
24677 table
= new_line_info_table ();
24678 table
->end_label
= end_label
;
24680 vec_safe_push (separate_line_info
, table
);
24683 if (DWARF2_ASM_LINE_DEBUG_INFO
)
24684 table
->is_stmt
= (cur_line_info_table
24685 ? cur_line_info_table
->is_stmt
24686 : DWARF_LINE_DEFAULT_IS_STMT_START
);
24687 cur_line_info_table
= table
;
24691 /* We need to reset the locations at the beginning of each
24692 function. We can't do this in the end_function hook, because the
24693 declarations that use the locations won't have been output when
24694 that hook is called. Also compute have_multiple_function_sections here. */
24697 dwarf2out_begin_function (tree fun
)
24699 section
*sec
= function_section (fun
);
24701 if (sec
!= text_section
)
24702 have_multiple_function_sections
= true;
24704 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
24706 gcc_assert (current_function_decl
== fun
);
24707 cold_text_section
= unlikely_text_section ();
24708 switch_to_section (cold_text_section
);
24709 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
24710 switch_to_section (sec
);
24713 dwarf2out_note_section_used ();
24714 call_site_count
= 0;
24715 tail_call_site_count
= 0;
24717 set_cur_line_info_table (sec
);
24720 /* Helper function of dwarf2out_end_function, called only after emitting
24721 the very first function into assembly. Check if some .debug_loc range
24722 might end with a .LVL* label that could be equal to .Ltext0.
24723 In that case we must force using absolute addresses in .debug_loc ranges,
24724 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
24725 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
24727 Set have_multiple_function_sections to true in that case and
24728 terminate htab traversal. */
24731 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
24733 var_loc_list
*entry
= *slot
;
24734 struct var_loc_node
*node
;
24736 node
= entry
->first
;
24737 if (node
&& node
->next
&& node
->next
->label
)
24740 const char *label
= node
->next
->label
;
24741 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
24743 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
24745 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
24746 if (strcmp (label
, loclabel
) == 0)
24748 have_multiple_function_sections
= true;
24756 /* Hook called after emitting a function into assembly.
24757 This does something only for the very first function emitted. */
24760 dwarf2out_end_function (unsigned int)
24762 if (in_first_function_p
24763 && !have_multiple_function_sections
24764 && first_loclabel_num_not_at_text_label
24766 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
24767 in_first_function_p
= false;
24768 maybe_at_text_label_p
= false;
24771 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
24772 front-ends register a translation unit even before dwarf2out_init is
24774 static tree main_translation_unit
= NULL_TREE
;
24776 /* Hook called by front-ends after they built their main translation unit.
24777 Associate comp_unit_die to UNIT. */
24780 dwarf2out_register_main_translation_unit (tree unit
)
24782 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
24783 && main_translation_unit
== NULL_TREE
);
24784 main_translation_unit
= unit
;
24785 /* If dwarf2out_init has not been called yet, it will perform the association
24786 itself looking at main_translation_unit. */
24787 if (decl_die_table
!= NULL
)
24788 equate_decl_number_to_die (unit
, comp_unit_die ());
24791 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
24794 push_dw_line_info_entry (dw_line_info_table
*table
,
24795 enum dw_line_info_opcode opcode
, unsigned int val
)
24797 dw_line_info_entry e
;
24800 vec_safe_push (table
->entries
, e
);
24803 /* Output a label to mark the beginning of a source code line entry
24804 and record information relating to this source line, in
24805 'line_info_table' for later output of the .debug_line section. */
24806 /* ??? The discriminator parameter ought to be unsigned. */
24809 dwarf2out_source_line (unsigned int line
, const char *filename
,
24810 int discriminator
, bool is_stmt
)
24812 unsigned int file_num
;
24813 dw_line_info_table
*table
;
24815 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
24818 /* The discriminator column was added in dwarf4. Simplify the below
24819 by simply removing it if we're not supposed to output it. */
24820 if (dwarf_version
< 4 && dwarf_strict
)
24823 table
= cur_line_info_table
;
24824 file_num
= maybe_emit_file (lookup_filename (filename
));
24826 /* ??? TODO: Elide duplicate line number entries. Traditionally,
24827 the debugger has used the second (possibly duplicate) line number
24828 at the beginning of the function to mark the end of the prologue.
24829 We could eliminate any other duplicates within the function. For
24830 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
24831 that second line number entry. */
24832 /* Recall that this end-of-prologue indication is *not* the same thing
24833 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
24834 to which the hook corresponds, follows the last insn that was
24835 emitted by gen_prologue. What we need is to precede the first insn
24836 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
24837 insn that corresponds to something the user wrote. These may be
24838 very different locations once scheduling is enabled. */
24840 if (0 && file_num
== table
->file_num
24841 && line
== table
->line_num
24842 && discriminator
== table
->discrim_num
24843 && is_stmt
== table
->is_stmt
)
24846 switch_to_section (current_function_section ());
24848 /* If requested, emit something human-readable. */
24849 if (flag_debug_asm
)
24850 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
24852 if (DWARF2_ASM_LINE_DEBUG_INFO
)
24854 /* Emit the .loc directive understood by GNU as. */
24855 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
24856 file_num, line, is_stmt, discriminator */
24857 fputs ("\t.loc ", asm_out_file
);
24858 fprint_ul (asm_out_file
, file_num
);
24859 putc (' ', asm_out_file
);
24860 fprint_ul (asm_out_file
, line
);
24861 putc (' ', asm_out_file
);
24862 putc ('0', asm_out_file
);
24864 if (is_stmt
!= table
->is_stmt
)
24866 fputs (" is_stmt ", asm_out_file
);
24867 putc (is_stmt
? '1' : '0', asm_out_file
);
24869 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
24871 gcc_assert (discriminator
> 0);
24872 fputs (" discriminator ", asm_out_file
);
24873 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
24875 putc ('\n', asm_out_file
);
24879 unsigned int label_num
= ++line_info_label_num
;
24881 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
24883 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
24884 if (file_num
!= table
->file_num
)
24885 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
24886 if (discriminator
!= table
->discrim_num
)
24887 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
24888 if (is_stmt
!= table
->is_stmt
)
24889 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
24890 push_dw_line_info_entry (table
, LI_set_line
, line
);
24893 table
->file_num
= file_num
;
24894 table
->line_num
= line
;
24895 table
->discrim_num
= discriminator
;
24896 table
->is_stmt
= is_stmt
;
24897 table
->in_use
= true;
24900 /* Record the beginning of a new source file. */
24903 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
24905 if (flag_eliminate_dwarf2_dups
)
24907 /* Record the beginning of the file for break_out_includes. */
24908 dw_die_ref bincl_die
;
24910 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
24911 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
24914 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
24917 e
.code
= DW_MACINFO_start_file
;
24919 e
.info
= ggc_strdup (filename
);
24920 vec_safe_push (macinfo_table
, e
);
24924 /* Record the end of a source file. */
24927 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
24929 if (flag_eliminate_dwarf2_dups
)
24930 /* Record the end of the file for break_out_includes. */
24931 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
24933 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
24936 e
.code
= DW_MACINFO_end_file
;
24939 vec_safe_push (macinfo_table
, e
);
24943 /* Called from debug_define in toplev.c. The `buffer' parameter contains
24944 the tail part of the directive line, i.e. the part which is past the
24945 initial whitespace, #, whitespace, directive-name, whitespace part. */
24948 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
24949 const char *buffer ATTRIBUTE_UNUSED
)
24951 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
24954 /* Insert a dummy first entry to be able to optimize the whole
24955 predefined macro block using DW_MACRO_GNU_transparent_include. */
24956 if (macinfo_table
->is_empty () && lineno
<= 1)
24961 vec_safe_push (macinfo_table
, e
);
24963 e
.code
= DW_MACINFO_define
;
24965 e
.info
= ggc_strdup (buffer
);
24966 vec_safe_push (macinfo_table
, e
);
24970 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
24971 the tail part of the directive line, i.e. the part which is past the
24972 initial whitespace, #, whitespace, directive-name, whitespace part. */
24975 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
24976 const char *buffer ATTRIBUTE_UNUSED
)
24978 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
24981 /* Insert a dummy first entry to be able to optimize the whole
24982 predefined macro block using DW_MACRO_GNU_transparent_include. */
24983 if (macinfo_table
->is_empty () && lineno
<= 1)
24988 vec_safe_push (macinfo_table
, e
);
24990 e
.code
= DW_MACINFO_undef
;
24992 e
.info
= ggc_strdup (buffer
);
24993 vec_safe_push (macinfo_table
, e
);
24997 /* Helpers to manipulate hash table of CUs. */
24999 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
25001 static inline hashval_t
hash (const macinfo_entry
*);
25002 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
25006 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
25008 return htab_hash_string (entry
->info
);
25012 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
25013 const macinfo_entry
*entry2
)
25015 return !strcmp (entry1
->info
, entry2
->info
);
25018 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
25020 /* Output a single .debug_macinfo entry. */
25023 output_macinfo_op (macinfo_entry
*ref
)
25027 struct indirect_string_node
*node
;
25028 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
25029 struct dwarf_file_data
*fd
;
25033 case DW_MACINFO_start_file
:
25034 fd
= lookup_filename (ref
->info
);
25035 file_num
= maybe_emit_file (fd
);
25036 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
25037 dw2_asm_output_data_uleb128 (ref
->lineno
,
25038 "Included from line number %lu",
25039 (unsigned long) ref
->lineno
);
25040 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
25042 case DW_MACINFO_end_file
:
25043 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
25045 case DW_MACINFO_define
:
25046 case DW_MACINFO_undef
:
25047 len
= strlen (ref
->info
) + 1;
25049 && len
> DWARF_OFFSET_SIZE
25050 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
25051 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
25053 ref
->code
= ref
->code
== DW_MACINFO_define
25054 ? DW_MACRO_GNU_define_indirect
25055 : DW_MACRO_GNU_undef_indirect
;
25056 output_macinfo_op (ref
);
25059 dw2_asm_output_data (1, ref
->code
,
25060 ref
->code
== DW_MACINFO_define
25061 ? "Define macro" : "Undefine macro");
25062 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
25063 (unsigned long) ref
->lineno
);
25064 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
25066 case DW_MACRO_GNU_define_indirect
:
25067 case DW_MACRO_GNU_undef_indirect
:
25068 node
= find_AT_string (ref
->info
);
25070 && ((node
->form
== DW_FORM_strp
)
25071 || (node
->form
== DW_FORM_GNU_str_index
)));
25072 dw2_asm_output_data (1, ref
->code
,
25073 ref
->code
== DW_MACRO_GNU_define_indirect
25074 ? "Define macro indirect"
25075 : "Undefine macro indirect");
25076 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
25077 (unsigned long) ref
->lineno
);
25078 if (node
->form
== DW_FORM_strp
)
25079 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
25080 debug_str_section
, "The macro: \"%s\"",
25083 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
25086 case DW_MACRO_GNU_transparent_include
:
25087 dw2_asm_output_data (1, ref
->code
, "Transparent include");
25088 ASM_GENERATE_INTERNAL_LABEL (label
,
25089 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
25090 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
25093 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
25094 ASM_COMMENT_START
, (unsigned long) ref
->code
);
25099 /* Attempt to make a sequence of define/undef macinfo ops shareable with
25100 other compilation unit .debug_macinfo sections. IDX is the first
25101 index of a define/undef, return the number of ops that should be
25102 emitted in a comdat .debug_macinfo section and emit
25103 a DW_MACRO_GNU_transparent_include entry referencing it.
25104 If the define/undef entry should be emitted normally, return 0. */
25107 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
25108 macinfo_hash_type
**macinfo_htab
)
25110 macinfo_entry
*first
, *second
, *cur
, *inc
;
25111 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
25112 unsigned char checksum
[16];
25113 struct md5_ctx ctx
;
25114 char *grp_name
, *tail
;
25116 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
25117 macinfo_entry
**slot
;
25119 first
= &(*macinfo_table
)[idx
];
25120 second
= &(*macinfo_table
)[idx
+ 1];
25122 /* Optimize only if there are at least two consecutive define/undef ops,
25123 and either all of them are before first DW_MACINFO_start_file
25124 with lineno {0,1} (i.e. predefined macro block), or all of them are
25125 in some included header file. */
25126 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
25128 if (vec_safe_is_empty (files
))
25130 if (first
->lineno
> 1 || second
->lineno
> 1)
25133 else if (first
->lineno
== 0)
25136 /* Find the last define/undef entry that can be grouped together
25137 with first and at the same time compute md5 checksum of their
25138 codes, linenumbers and strings. */
25139 md5_init_ctx (&ctx
);
25140 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
25141 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
25143 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
25147 unsigned char code
= cur
->code
;
25148 md5_process_bytes (&code
, 1, &ctx
);
25149 checksum_uleb128 (cur
->lineno
, &ctx
);
25150 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
25152 md5_finish_ctx (&ctx
, checksum
);
25155 /* From the containing include filename (if any) pick up just
25156 usable characters from its basename. */
25157 if (vec_safe_is_empty (files
))
25160 base
= lbasename (files
->last ().info
);
25161 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
25162 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
25163 encoded_filename_len
++;
25164 /* Count . at the end. */
25165 if (encoded_filename_len
)
25166 encoded_filename_len
++;
25168 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
25169 linebuf_len
= strlen (linebuf
);
25171 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
25172 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
25174 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
25175 tail
= grp_name
+ 4;
25176 if (encoded_filename_len
)
25178 for (i
= 0; base
[i
]; i
++)
25179 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
25183 memcpy (tail
, linebuf
, linebuf_len
);
25184 tail
+= linebuf_len
;
25186 for (i
= 0; i
< 16; i
++)
25187 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
25189 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
25190 in the empty vector entry before the first define/undef. */
25191 inc
= &(*macinfo_table
)[idx
- 1];
25192 inc
->code
= DW_MACRO_GNU_transparent_include
;
25194 inc
->info
= ggc_strdup (grp_name
);
25195 if (!*macinfo_htab
)
25196 *macinfo_htab
= new macinfo_hash_type (10);
25197 /* Avoid emitting duplicates. */
25198 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
25203 /* If such an entry has been used before, just emit
25204 a DW_MACRO_GNU_transparent_include op. */
25206 output_macinfo_op (inc
);
25207 /* And clear all macinfo_entry in the range to avoid emitting them
25208 in the second pass. */
25209 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
25218 inc
->lineno
= (*macinfo_htab
)->elements ();
25219 output_macinfo_op (inc
);
25224 /* Save any strings needed by the macinfo table in the debug str
25225 table. All strings must be collected into the table by the time
25226 index_string is called. */
25229 save_macinfo_strings (void)
25233 macinfo_entry
*ref
;
25235 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
25239 /* Match the logic in output_macinfo_op to decide on
25240 indirect strings. */
25241 case DW_MACINFO_define
:
25242 case DW_MACINFO_undef
:
25243 len
= strlen (ref
->info
) + 1;
25245 && len
> DWARF_OFFSET_SIZE
25246 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
25247 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
25248 set_indirect_string (find_AT_string (ref
->info
));
25250 case DW_MACRO_GNU_define_indirect
:
25251 case DW_MACRO_GNU_undef_indirect
:
25252 set_indirect_string (find_AT_string (ref
->info
));
25260 /* Output macinfo section(s). */
25263 output_macinfo (void)
25266 unsigned long length
= vec_safe_length (macinfo_table
);
25267 macinfo_entry
*ref
;
25268 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
25269 macinfo_hash_type
*macinfo_htab
= NULL
;
25274 /* output_macinfo* uses these interchangeably. */
25275 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
25276 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
25277 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
25278 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
25280 /* For .debug_macro emit the section header. */
25283 dw2_asm_output_data (2, 4, "DWARF macro version number");
25284 if (DWARF_OFFSET_SIZE
== 8)
25285 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
25287 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
25288 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
25289 (!dwarf_split_debug_info
? debug_line_section_label
25290 : debug_skeleton_line_section_label
),
25291 debug_line_section
, NULL
);
25294 /* In the first loop, it emits the primary .debug_macinfo section
25295 and after each emitted op the macinfo_entry is cleared.
25296 If a longer range of define/undef ops can be optimized using
25297 DW_MACRO_GNU_transparent_include, the
25298 DW_MACRO_GNU_transparent_include op is emitted and kept in
25299 the vector before the first define/undef in the range and the
25300 whole range of define/undef ops is not emitted and kept. */
25301 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
25305 case DW_MACINFO_start_file
:
25306 vec_safe_push (files
, *ref
);
25308 case DW_MACINFO_end_file
:
25309 if (!vec_safe_is_empty (files
))
25312 case DW_MACINFO_define
:
25313 case DW_MACINFO_undef
:
25315 && HAVE_COMDAT_GROUP
25316 && vec_safe_length (files
) != 1
25319 && (*macinfo_table
)[i
- 1].code
== 0)
25321 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
25330 /* A dummy entry may be inserted at the beginning to be able
25331 to optimize the whole block of predefined macros. */
25337 output_macinfo_op (ref
);
25345 delete macinfo_htab
;
25346 macinfo_htab
= NULL
;
25348 /* If any DW_MACRO_GNU_transparent_include were used, on those
25349 DW_MACRO_GNU_transparent_include entries terminate the
25350 current chain and switch to a new comdat .debug_macinfo
25351 section and emit the define/undef entries within it. */
25352 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
25357 case DW_MACRO_GNU_transparent_include
:
25359 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
25360 tree comdat_key
= get_identifier (ref
->info
);
25361 /* Terminate the previous .debug_macinfo section. */
25362 dw2_asm_output_data (1, 0, "End compilation unit");
25363 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
25365 | SECTION_LINKONCE
,
25367 ASM_GENERATE_INTERNAL_LABEL (label
,
25368 DEBUG_MACRO_SECTION_LABEL
,
25370 ASM_OUTPUT_LABEL (asm_out_file
, label
);
25373 dw2_asm_output_data (2, 4, "DWARF macro version number");
25374 if (DWARF_OFFSET_SIZE
== 8)
25375 dw2_asm_output_data (1, 1, "Flags: 64-bit");
25377 dw2_asm_output_data (1, 0, "Flags: 32-bit");
25380 case DW_MACINFO_define
:
25381 case DW_MACINFO_undef
:
25382 output_macinfo_op (ref
);
25387 gcc_unreachable ();
25391 /* Set up for Dwarf output at the start of compilation. */
25394 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
25396 /* This option is currently broken, see (PR53118 and PR46102). */
25397 if (flag_eliminate_dwarf2_dups
25398 && strstr (lang_hooks
.name
, "C++"))
25400 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
25401 flag_eliminate_dwarf2_dups
= 0;
25404 /* Allocate the file_table. */
25405 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
25407 #ifndef DWARF2_LINENO_DEBUGGING_INFO
25408 /* Allocate the decl_die_table. */
25409 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
25411 /* Allocate the decl_loc_table. */
25412 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
25414 /* Allocate the cached_dw_loc_list_table. */
25415 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
25417 /* Allocate the initial hunk of the decl_scope_table. */
25418 vec_alloc (decl_scope_table
, 256);
25420 /* Allocate the initial hunk of the abbrev_die_table. */
25421 abbrev_die_table
= ggc_cleared_vec_alloc
<dw_die_ref
>
25422 (ABBREV_DIE_TABLE_INCREMENT
);
25423 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
25424 /* Zero-th entry is allocated, but unused. */
25425 abbrev_die_table_in_use
= 1;
25427 /* Allocate the dwarf_proc_stack_usage_map. */
25428 dwarf_proc_stack_usage_map
= new hash_map
<dw_die_ref
, int>;
25430 /* Allocate the pubtypes and pubnames vectors. */
25431 vec_alloc (pubname_table
, 32);
25432 vec_alloc (pubtype_table
, 32);
25434 vec_alloc (incomplete_types
, 64);
25436 vec_alloc (used_rtx_array
, 32);
25438 if (!dwarf_split_debug_info
)
25440 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
25441 SECTION_DEBUG
, NULL
);
25442 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
25443 SECTION_DEBUG
, NULL
);
25444 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
25445 SECTION_DEBUG
, NULL
);
25449 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
25450 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
25451 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
25452 SECTION_DEBUG
| SECTION_EXCLUDE
,
25454 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
25455 SECTION_DEBUG
, NULL
);
25456 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
25457 SECTION_DEBUG
, NULL
);
25458 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
25459 SECTION_DEBUG
, NULL
);
25460 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
25461 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
25463 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
25464 the main .o, but the skeleton_line goes into the split off dwo. */
25465 debug_skeleton_line_section
25466 = get_section (DEBUG_DWO_LINE_SECTION
,
25467 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
25468 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
25469 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
25470 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
25471 SECTION_DEBUG
| SECTION_EXCLUDE
,
25473 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
25474 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
25475 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
25476 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
25477 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
25478 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
25480 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
25481 SECTION_DEBUG
, NULL
);
25482 debug_macinfo_section
= get_section (dwarf_strict
25483 ? DEBUG_MACINFO_SECTION
25484 : DEBUG_MACRO_SECTION
,
25485 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
25486 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
25487 SECTION_DEBUG
, NULL
);
25488 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
25489 SECTION_DEBUG
, NULL
);
25490 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
25491 SECTION_DEBUG
, NULL
);
25492 debug_str_section
= get_section (DEBUG_STR_SECTION
,
25493 DEBUG_STR_SECTION_FLAGS
, NULL
);
25494 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
25495 SECTION_DEBUG
, NULL
);
25496 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
25497 SECTION_DEBUG
, NULL
);
25499 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
25500 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
25501 DEBUG_ABBREV_SECTION_LABEL
, 0);
25502 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
25503 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
25504 COLD_TEXT_SECTION_LABEL
, 0);
25505 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
25507 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
25508 DEBUG_INFO_SECTION_LABEL
, 0);
25509 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
25510 DEBUG_LINE_SECTION_LABEL
, 0);
25511 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
25512 DEBUG_RANGES_SECTION_LABEL
, 0);
25513 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
25514 DEBUG_ADDR_SECTION_LABEL
, 0);
25515 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
25517 ? DEBUG_MACINFO_SECTION_LABEL
25518 : DEBUG_MACRO_SECTION_LABEL
, 0);
25519 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
25521 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
25522 vec_alloc (macinfo_table
, 64);
25524 switch_to_section (text_section
);
25525 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
25528 /* Make sure the line number table for .text always exists. */
25529 text_section_line_info
= new_line_info_table ();
25530 text_section_line_info
->end_label
= text_end_label
;
25532 #ifdef DWARF2_LINENO_DEBUGGING_INFO
25533 cur_line_info_table
= text_section_line_info
;
25536 /* If front-ends already registered a main translation unit but we were not
25537 ready to perform the association, do this now. */
25538 if (main_translation_unit
!= NULL_TREE
)
25539 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
25542 /* Called before compile () starts outputtting functions, variables
25543 and toplevel asms into assembly. */
25546 dwarf2out_assembly_start (void)
25548 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
25549 && dwarf2out_do_cfi_asm ()
25550 && (!(flag_unwind_tables
|| flag_exceptions
)
25551 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
25552 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
25555 /* A helper function for dwarf2out_finish called through
25556 htab_traverse. Assign a string its index. All strings must be
25557 collected into the table by the time index_string is called,
25558 because the indexing code relies on htab_traverse to traverse nodes
25559 in the same order for each run. */
25562 index_string (indirect_string_node
**h
, unsigned int *index
)
25564 indirect_string_node
*node
= *h
;
25566 find_string_form (node
);
25567 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
25569 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
25570 node
->index
= *index
;
25576 /* A helper function for output_indirect_strings called through
25577 htab_traverse. Output the offset to a string and update the
25581 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
25583 indirect_string_node
*node
= *h
;
25585 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
25587 /* Assert that this node has been assigned an index. */
25588 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
25589 && node
->index
!= NOT_INDEXED
);
25590 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
25591 "indexed string 0x%x: %s", node
->index
, node
->str
);
25592 *offset
+= strlen (node
->str
) + 1;
25597 /* A helper function for dwarf2out_finish called through
25598 htab_traverse. Output the indexed string. */
25601 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
25603 struct indirect_string_node
*node
= *h
;
25605 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
25607 /* Assert that the strings are output in the same order as their
25608 indexes were assigned. */
25609 gcc_assert (*cur_idx
== node
->index
);
25610 assemble_string (node
->str
, strlen (node
->str
) + 1);
25616 /* A helper function for dwarf2out_finish called through
25617 htab_traverse. Emit one queued .debug_str string. */
25620 output_indirect_string (indirect_string_node
**h
, void *)
25622 struct indirect_string_node
*node
= *h
;
25624 node
->form
= find_string_form (node
);
25625 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
25627 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
25628 assemble_string (node
->str
, strlen (node
->str
) + 1);
25634 /* Output the indexed string table. */
25637 output_indirect_strings (void)
25639 switch_to_section (debug_str_section
);
25640 if (!dwarf_split_debug_info
)
25641 debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
25644 unsigned int offset
= 0;
25645 unsigned int cur_idx
= 0;
25647 skeleton_debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
25649 switch_to_section (debug_str_offsets_section
);
25650 debug_str_hash
->traverse_noresize
25651 <unsigned int *, output_index_string_offset
> (&offset
);
25652 switch_to_section (debug_str_dwo_section
);
25653 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
25658 /* Callback for htab_traverse to assign an index to an entry in the
25659 table, and to write that entry to the .debug_addr section. */
25662 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
25664 addr_table_entry
*entry
= *slot
;
25666 if (entry
->refcount
== 0)
25668 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
25669 || entry
->index
== NOT_INDEXED
);
25673 gcc_assert (entry
->index
== *cur_index
);
25676 switch (entry
->kind
)
25679 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
25680 "0x%x", entry
->index
);
25682 case ate_kind_rtx_dtprel
:
25683 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
25684 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
25687 fputc ('\n', asm_out_file
);
25689 case ate_kind_label
:
25690 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
25691 "0x%x", entry
->index
);
25694 gcc_unreachable ();
25699 /* Produce the .debug_addr section. */
25702 output_addr_table (void)
25704 unsigned int index
= 0;
25705 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
25708 switch_to_section (debug_addr_section
);
25710 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
25713 #if ENABLE_ASSERT_CHECKING
25714 /* Verify that all marks are clear. */
25717 verify_marks_clear (dw_die_ref die
)
25721 gcc_assert (! die
->die_mark
);
25722 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
25724 #endif /* ENABLE_ASSERT_CHECKING */
25726 /* Clear the marks for a die and its children.
25727 Be cool if the mark isn't set. */
25730 prune_unmark_dies (dw_die_ref die
)
25736 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
25739 /* Given LOC that is referenced by a DIE we're marking as used, find all
25740 referenced DWARF procedures it references and mark them as used. */
25743 prune_unused_types_walk_loc_descr (dw_loc_descr_ref loc
)
25745 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
25746 switch (loc
->dw_loc_opc
)
25748 case DW_OP_GNU_implicit_pointer
:
25749 case DW_OP_GNU_convert
:
25750 case DW_OP_GNU_reinterpret
:
25751 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
)
25752 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
25756 case DW_OP_call_ref
:
25757 case DW_OP_GNU_const_type
:
25758 case DW_OP_GNU_parameter_ref
:
25759 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
);
25760 prune_unused_types_mark (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
, 1);
25762 case DW_OP_GNU_regval_type
:
25763 case DW_OP_GNU_deref_type
:
25764 gcc_assert (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_die_ref
);
25765 prune_unused_types_mark (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
, 1);
25767 case DW_OP_GNU_entry_value
:
25768 gcc_assert (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_loc
);
25769 prune_unused_types_walk_loc_descr (loc
->dw_loc_oprnd1
.v
.val_loc
);
25776 /* Given DIE that we're marking as used, find any other dies
25777 it references as attributes and mark them as used. */
25780 prune_unused_types_walk_attribs (dw_die_ref die
)
25785 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25787 switch (AT_class (a
))
25789 /* Make sure DWARF procedures referenced by location descriptions will
25791 case dw_val_class_loc
:
25792 prune_unused_types_walk_loc_descr (AT_loc (a
));
25794 case dw_val_class_loc_list
:
25795 for (dw_loc_list_ref list
= AT_loc_list (a
);
25797 list
= list
->dw_loc_next
)
25798 prune_unused_types_walk_loc_descr (list
->expr
);
25801 case dw_val_class_die_ref
:
25802 /* A reference to another DIE.
25803 Make sure that it will get emitted.
25804 If it was broken out into a comdat group, don't follow it. */
25805 if (! AT_ref (a
)->comdat_type_p
25806 || a
->dw_attr
== DW_AT_specification
)
25807 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
25810 case dw_val_class_str
:
25811 /* Set the string's refcount to 0 so that prune_unused_types_mark
25812 accounts properly for it. */
25813 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
25822 /* Mark the generic parameters and arguments children DIEs of DIE. */
25825 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
25829 if (die
== NULL
|| die
->die_child
== NULL
)
25831 c
= die
->die_child
;
25834 if (is_template_parameter (c
))
25835 prune_unused_types_mark (c
, 1);
25837 } while (c
&& c
!= die
->die_child
);
25840 /* Mark DIE as being used. If DOKIDS is true, then walk down
25841 to DIE's children. */
25844 prune_unused_types_mark (dw_die_ref die
, int dokids
)
25848 if (die
->die_mark
== 0)
25850 /* We haven't done this node yet. Mark it as used. */
25852 /* If this is the DIE of a generic type instantiation,
25853 mark the children DIEs that describe its generic parms and
25855 prune_unused_types_mark_generic_parms_dies (die
);
25857 /* We also have to mark its parents as used.
25858 (But we don't want to mark our parent's kids due to this,
25859 unless it is a class.) */
25860 if (die
->die_parent
)
25861 prune_unused_types_mark (die
->die_parent
,
25862 class_scope_p (die
->die_parent
));
25864 /* Mark any referenced nodes. */
25865 prune_unused_types_walk_attribs (die
);
25867 /* If this node is a specification,
25868 also mark the definition, if it exists. */
25869 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
25870 prune_unused_types_mark (die
->die_definition
, 1);
25873 if (dokids
&& die
->die_mark
!= 2)
25875 /* We need to walk the children, but haven't done so yet.
25876 Remember that we've walked the kids. */
25879 /* If this is an array type, we need to make sure our
25880 kids get marked, even if they're types. If we're
25881 breaking out types into comdat sections, do this
25882 for all type definitions. */
25883 if (die
->die_tag
== DW_TAG_array_type
25884 || (use_debug_types
25885 && is_type_die (die
) && ! is_declaration_die (die
)))
25886 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
25888 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
25892 /* For local classes, look if any static member functions were emitted
25893 and if so, mark them. */
25896 prune_unused_types_walk_local_classes (dw_die_ref die
)
25900 if (die
->die_mark
== 2)
25903 switch (die
->die_tag
)
25905 case DW_TAG_structure_type
:
25906 case DW_TAG_union_type
:
25907 case DW_TAG_class_type
:
25910 case DW_TAG_subprogram
:
25911 if (!get_AT_flag (die
, DW_AT_declaration
)
25912 || die
->die_definition
!= NULL
)
25913 prune_unused_types_mark (die
, 1);
25920 /* Mark children. */
25921 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
25924 /* Walk the tree DIE and mark types that we actually use. */
25927 prune_unused_types_walk (dw_die_ref die
)
25931 /* Don't do anything if this node is already marked and
25932 children have been marked as well. */
25933 if (die
->die_mark
== 2)
25936 switch (die
->die_tag
)
25938 case DW_TAG_structure_type
:
25939 case DW_TAG_union_type
:
25940 case DW_TAG_class_type
:
25941 if (die
->die_perennial_p
)
25944 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
25945 if (c
->die_tag
== DW_TAG_subprogram
)
25948 /* Finding used static member functions inside of classes
25949 is needed just for local classes, because for other classes
25950 static member function DIEs with DW_AT_specification
25951 are emitted outside of the DW_TAG_*_type. If we ever change
25952 it, we'd need to call this even for non-local classes. */
25954 prune_unused_types_walk_local_classes (die
);
25956 /* It's a type node --- don't mark it. */
25959 case DW_TAG_const_type
:
25960 case DW_TAG_packed_type
:
25961 case DW_TAG_pointer_type
:
25962 case DW_TAG_reference_type
:
25963 case DW_TAG_rvalue_reference_type
:
25964 case DW_TAG_volatile_type
:
25965 case DW_TAG_typedef
:
25966 case DW_TAG_array_type
:
25967 case DW_TAG_interface_type
:
25968 case DW_TAG_friend
:
25969 case DW_TAG_enumeration_type
:
25970 case DW_TAG_subroutine_type
:
25971 case DW_TAG_string_type
:
25972 case DW_TAG_set_type
:
25973 case DW_TAG_subrange_type
:
25974 case DW_TAG_ptr_to_member_type
:
25975 case DW_TAG_file_type
:
25976 /* Type nodes are useful only when other DIEs reference them --- don't
25980 case DW_TAG_dwarf_procedure
:
25981 /* Likewise for DWARF procedures. */
25983 if (die
->die_perennial_p
)
25989 /* Mark everything else. */
25993 if (die
->die_mark
== 0)
25997 /* Now, mark any dies referenced from here. */
25998 prune_unused_types_walk_attribs (die
);
26003 /* Mark children. */
26004 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
26007 /* Increment the string counts on strings referred to from DIE's
26011 prune_unused_types_update_strings (dw_die_ref die
)
26016 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
26017 if (AT_class (a
) == dw_val_class_str
)
26019 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
26021 /* Avoid unnecessarily putting strings that are used less than
26022 twice in the hash table. */
26024 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
26026 indirect_string_node
**slot
26027 = debug_str_hash
->find_slot_with_hash (s
->str
,
26028 htab_hash_string (s
->str
),
26030 gcc_assert (*slot
== NULL
);
26036 /* Remove from the tree DIE any dies that aren't marked. */
26039 prune_unused_types_prune (dw_die_ref die
)
26043 gcc_assert (die
->die_mark
);
26044 prune_unused_types_update_strings (die
);
26046 if (! die
->die_child
)
26049 c
= die
->die_child
;
26051 dw_die_ref prev
= c
;
26052 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
26053 if (c
== die
->die_child
)
26055 /* No marked children between 'prev' and the end of the list. */
26057 /* No marked children at all. */
26058 die
->die_child
= NULL
;
26061 prev
->die_sib
= c
->die_sib
;
26062 die
->die_child
= prev
;
26067 if (c
!= prev
->die_sib
)
26069 prune_unused_types_prune (c
);
26070 } while (c
!= die
->die_child
);
26073 /* Remove dies representing declarations that we never use. */
26076 prune_unused_types (void)
26079 limbo_die_node
*node
;
26080 comdat_type_node
*ctnode
;
26081 pubname_entry
*pub
;
26082 dw_die_ref base_type
;
26084 #if ENABLE_ASSERT_CHECKING
26085 /* All the marks should already be clear. */
26086 verify_marks_clear (comp_unit_die ());
26087 for (node
= limbo_die_list
; node
; node
= node
->next
)
26088 verify_marks_clear (node
->die
);
26089 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
26090 verify_marks_clear (ctnode
->root_die
);
26091 #endif /* ENABLE_ASSERT_CHECKING */
26093 /* Mark types that are used in global variables. */
26094 premark_types_used_by_global_vars ();
26096 /* Set the mark on nodes that are actually used. */
26097 prune_unused_types_walk (comp_unit_die ());
26098 for (node
= limbo_die_list
; node
; node
= node
->next
)
26099 prune_unused_types_walk (node
->die
);
26100 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
26102 prune_unused_types_walk (ctnode
->root_die
);
26103 prune_unused_types_mark (ctnode
->type_die
, 1);
26106 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
26107 are unusual in that they are pubnames that are the children of pubtypes.
26108 They should only be marked via their parent DW_TAG_enumeration_type die,
26109 not as roots in themselves. */
26110 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
26111 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
26112 prune_unused_types_mark (pub
->die
, 1);
26113 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
26114 prune_unused_types_mark (base_type
, 1);
26116 if (debug_str_hash
)
26117 debug_str_hash
->empty ();
26118 if (skeleton_debug_str_hash
)
26119 skeleton_debug_str_hash
->empty ();
26120 prune_unused_types_prune (comp_unit_die ());
26121 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
26124 if (!node
->die
->die_mark
)
26125 *pnode
= node
->next
;
26128 prune_unused_types_prune (node
->die
);
26129 pnode
= &node
->next
;
26132 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
26133 prune_unused_types_prune (ctnode
->root_die
);
26135 /* Leave the marks clear. */
26136 prune_unmark_dies (comp_unit_die ());
26137 for (node
= limbo_die_list
; node
; node
= node
->next
)
26138 prune_unmark_dies (node
->die
);
26139 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
26140 prune_unmark_dies (ctnode
->root_die
);
26143 /* Set the parameter to true if there are any relative pathnames in
26146 file_table_relative_p (dwarf_file_data
**slot
, bool *p
)
26148 struct dwarf_file_data
*d
= *slot
;
26149 if (!IS_ABSOLUTE_PATH (d
->filename
))
26157 /* Helpers to manipulate hash table of comdat type units. */
26159 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
26161 static inline hashval_t
hash (const comdat_type_node
*);
26162 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
26166 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
26169 memcpy (&h
, type_node
->signature
, sizeof (h
));
26174 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
26175 const comdat_type_node
*type_node_2
)
26177 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
26178 DWARF_TYPE_SIGNATURE_SIZE
));
26181 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
26182 to the location it would have been added, should we know its
26183 DECL_ASSEMBLER_NAME when we added other attributes. This will
26184 probably improve compactness of debug info, removing equivalent
26185 abbrevs, and hide any differences caused by deferring the
26186 computation of the assembler name, triggered by e.g. PCH. */
26189 move_linkage_attr (dw_die_ref die
)
26191 unsigned ix
= vec_safe_length (die
->die_attr
);
26192 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
26194 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
26195 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
26199 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
26201 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
26205 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
26207 die
->die_attr
->pop ();
26208 die
->die_attr
->quick_insert (ix
, linkage
);
26212 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
26213 referenced from typed stack ops and count how often they are used. */
26216 mark_base_types (dw_loc_descr_ref loc
)
26218 dw_die_ref base_type
= NULL
;
26220 for (; loc
; loc
= loc
->dw_loc_next
)
26222 switch (loc
->dw_loc_opc
)
26224 case DW_OP_GNU_regval_type
:
26225 case DW_OP_GNU_deref_type
:
26226 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
26228 case DW_OP_GNU_convert
:
26229 case DW_OP_GNU_reinterpret
:
26230 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
26233 case DW_OP_GNU_const_type
:
26234 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
26236 case DW_OP_GNU_entry_value
:
26237 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
26242 gcc_assert (base_type
->die_parent
== comp_unit_die ());
26243 if (base_type
->die_mark
)
26244 base_type
->die_mark
++;
26247 base_types
.safe_push (base_type
);
26248 base_type
->die_mark
= 1;
26253 /* Comparison function for sorting marked base types. */
26256 base_type_cmp (const void *x
, const void *y
)
26258 dw_die_ref dx
= *(const dw_die_ref
*) x
;
26259 dw_die_ref dy
= *(const dw_die_ref
*) y
;
26260 unsigned int byte_size1
, byte_size2
;
26261 unsigned int encoding1
, encoding2
;
26262 if (dx
->die_mark
> dy
->die_mark
)
26264 if (dx
->die_mark
< dy
->die_mark
)
26266 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
26267 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
26268 if (byte_size1
< byte_size2
)
26270 if (byte_size1
> byte_size2
)
26272 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
26273 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
26274 if (encoding1
< encoding2
)
26276 if (encoding1
> encoding2
)
26281 /* Move base types marked by mark_base_types as early as possible
26282 in the CU, sorted by decreasing usage count both to make the
26283 uleb128 references as small as possible and to make sure they
26284 will have die_offset already computed by calc_die_sizes when
26285 sizes of typed stack loc ops is computed. */
26288 move_marked_base_types (void)
26291 dw_die_ref base_type
, die
, c
;
26293 if (base_types
.is_empty ())
26296 /* Sort by decreasing usage count, they will be added again in that
26298 base_types
.qsort (base_type_cmp
);
26299 die
= comp_unit_die ();
26300 c
= die
->die_child
;
26303 dw_die_ref prev
= c
;
26305 while (c
->die_mark
)
26307 remove_child_with_prev (c
, prev
);
26308 /* As base types got marked, there must be at least
26309 one node other than DW_TAG_base_type. */
26310 gcc_assert (c
!= c
->die_sib
);
26314 while (c
!= die
->die_child
);
26315 gcc_assert (die
->die_child
);
26316 c
= die
->die_child
;
26317 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
26319 base_type
->die_mark
= 0;
26320 base_type
->die_sib
= c
->die_sib
;
26321 c
->die_sib
= base_type
;
26326 /* Helper function for resolve_addr, attempt to resolve
26327 one CONST_STRING, return true if successful. Similarly verify that
26328 SYMBOL_REFs refer to variables emitted in the current CU. */
26331 resolve_one_addr (rtx
*addr
)
26335 if (GET_CODE (rtl
) == CONST_STRING
)
26337 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
26338 tree t
= build_string (len
, XSTR (rtl
, 0));
26339 tree tlen
= size_int (len
- 1);
26341 = build_array_type (char_type_node
, build_index_type (tlen
));
26342 rtl
= lookup_constant_def (t
);
26343 if (!rtl
|| !MEM_P (rtl
))
26345 rtl
= XEXP (rtl
, 0);
26346 if (GET_CODE (rtl
) == SYMBOL_REF
26347 && SYMBOL_REF_DECL (rtl
)
26348 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
26350 vec_safe_push (used_rtx_array
, rtl
);
26355 if (GET_CODE (rtl
) == SYMBOL_REF
26356 && SYMBOL_REF_DECL (rtl
))
26358 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
26360 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
26363 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
26367 if (GET_CODE (rtl
) == CONST
)
26369 subrtx_ptr_iterator::array_type array
;
26370 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
26371 if (!resolve_one_addr (*iter
))
26378 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
26379 if possible, and create DW_TAG_dwarf_procedure that can be referenced
26380 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
26383 string_cst_pool_decl (tree t
)
26385 rtx rtl
= output_constant_def (t
, 1);
26386 unsigned char *array
;
26387 dw_loc_descr_ref l
;
26392 if (!rtl
|| !MEM_P (rtl
))
26394 rtl
= XEXP (rtl
, 0);
26395 if (GET_CODE (rtl
) != SYMBOL_REF
26396 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
26399 decl
= SYMBOL_REF_DECL (rtl
);
26400 if (!lookup_decl_die (decl
))
26402 len
= TREE_STRING_LENGTH (t
);
26403 vec_safe_push (used_rtx_array
, rtl
);
26404 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
26405 array
= ggc_vec_alloc
<unsigned char> (len
);
26406 memcpy (array
, TREE_STRING_POINTER (t
), len
);
26407 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
26408 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
26409 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
26410 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
26411 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
26412 add_AT_loc (ref
, DW_AT_location
, l
);
26413 equate_decl_number_to_die (decl
, ref
);
26418 /* Helper function of resolve_addr_in_expr. LOC is
26419 a DW_OP_addr followed by DW_OP_stack_value, either at the start
26420 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
26421 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
26422 with DW_OP_GNU_implicit_pointer if possible
26423 and return true, if unsuccessful, return false. */
26426 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
26428 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
26429 HOST_WIDE_INT offset
= 0;
26430 dw_die_ref ref
= NULL
;
26433 if (GET_CODE (rtl
) == CONST
26434 && GET_CODE (XEXP (rtl
, 0)) == PLUS
26435 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
26437 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
26438 rtl
= XEXP (XEXP (rtl
, 0), 0);
26440 if (GET_CODE (rtl
) == CONST_STRING
)
26442 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
26443 tree t
= build_string (len
, XSTR (rtl
, 0));
26444 tree tlen
= size_int (len
- 1);
26447 = build_array_type (char_type_node
, build_index_type (tlen
));
26448 rtl
= string_cst_pool_decl (t
);
26452 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
26454 decl
= SYMBOL_REF_DECL (rtl
);
26455 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
26457 ref
= lookup_decl_die (decl
);
26458 if (ref
&& (get_AT (ref
, DW_AT_location
)
26459 || get_AT (ref
, DW_AT_const_value
)))
26461 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
26462 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
26463 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
26464 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
26465 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
26466 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
26467 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
26475 /* Helper function for resolve_addr, handle one location
26476 expression, return false if at least one CONST_STRING or SYMBOL_REF in
26477 the location list couldn't be resolved. */
26480 resolve_addr_in_expr (dw_loc_descr_ref loc
)
26482 dw_loc_descr_ref keep
= NULL
;
26483 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
26484 switch (loc
->dw_loc_opc
)
26487 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
26490 || prev
->dw_loc_opc
== DW_OP_piece
26491 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
26492 && loc
->dw_loc_next
26493 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
26495 && optimize_one_addr_into_implicit_ptr (loc
))
26500 case DW_OP_GNU_addr_index
:
26501 case DW_OP_GNU_const_index
:
26502 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
26503 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
26505 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
26506 if (!resolve_one_addr (&rtl
))
26508 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
26509 loc
->dw_loc_oprnd1
.val_entry
=
26510 add_addr_table_entry (rtl
, ate_kind_rtx
);
26513 case DW_OP_const4u
:
26514 case DW_OP_const8u
:
26516 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
26519 case DW_OP_plus_uconst
:
26520 if (size_of_loc_descr (loc
)
26521 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
26523 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
26525 dw_loc_descr_ref repl
26526 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
26527 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
26528 add_loc_descr (&repl
, loc
->dw_loc_next
);
26532 case DW_OP_implicit_value
:
26533 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
26534 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
26537 case DW_OP_GNU_implicit_pointer
:
26538 case DW_OP_GNU_parameter_ref
:
26539 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
26542 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
26545 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
26546 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
26547 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
26550 case DW_OP_GNU_const_type
:
26551 case DW_OP_GNU_regval_type
:
26552 case DW_OP_GNU_deref_type
:
26553 case DW_OP_GNU_convert
:
26554 case DW_OP_GNU_reinterpret
:
26555 while (loc
->dw_loc_next
26556 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
26558 dw_die_ref base1
, base2
;
26559 unsigned enc1
, enc2
, size1
, size2
;
26560 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
26561 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
26562 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
26563 else if (loc
->dw_loc_oprnd1
.val_class
26564 == dw_val_class_unsigned_const
)
26567 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
26568 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
26569 == dw_val_class_unsigned_const
)
26571 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
26572 gcc_assert (base1
->die_tag
== DW_TAG_base_type
26573 && base2
->die_tag
== DW_TAG_base_type
);
26574 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
26575 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
26576 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
26577 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
26579 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
26580 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
26584 /* Optimize away next DW_OP_GNU_convert after
26585 adjusting LOC's base type die reference. */
26586 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
26587 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
26588 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
26590 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
26591 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
26594 /* Don't change integer DW_OP_GNU_convert after e.g. floating
26595 point typed stack entry. */
26596 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
26597 keep
= loc
->dw_loc_next
;
26607 /* Helper function of resolve_addr. DIE had DW_AT_location of
26608 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
26609 and DW_OP_addr couldn't be resolved. resolve_addr has already
26610 removed the DW_AT_location attribute. This function attempts to
26611 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
26612 to it or DW_AT_const_value attribute, if possible. */
26615 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
26617 if (TREE_CODE (decl
) != VAR_DECL
26618 || lookup_decl_die (decl
) != die
26619 || DECL_EXTERNAL (decl
)
26620 || !TREE_STATIC (decl
)
26621 || DECL_INITIAL (decl
) == NULL_TREE
26622 || DECL_P (DECL_INITIAL (decl
))
26623 || get_AT (die
, DW_AT_const_value
))
26626 tree init
= DECL_INITIAL (decl
);
26627 HOST_WIDE_INT offset
= 0;
26628 /* For variables that have been optimized away and thus
26629 don't have a memory location, see if we can emit
26630 DW_AT_const_value instead. */
26631 if (tree_add_const_value_attribute (die
, init
))
26635 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
26636 and ADDR_EXPR refers to a decl that has DW_AT_location or
26637 DW_AT_const_value (but isn't addressable, otherwise
26638 resolving the original DW_OP_addr wouldn't fail), see if
26639 we can add DW_OP_GNU_implicit_pointer. */
26641 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
26642 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
26644 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
26645 init
= TREE_OPERAND (init
, 0);
26648 if (TREE_CODE (init
) != ADDR_EXPR
)
26650 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
26651 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
26652 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
26653 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
26654 && TREE_OPERAND (init
, 0) != decl
))
26657 dw_loc_descr_ref l
;
26659 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
26661 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
26664 decl
= SYMBOL_REF_DECL (rtl
);
26667 decl
= TREE_OPERAND (init
, 0);
26668 ref
= lookup_decl_die (decl
);
26670 || (!get_AT (ref
, DW_AT_location
)
26671 && !get_AT (ref
, DW_AT_const_value
)))
26673 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
26674 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
26675 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
26676 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
26677 add_AT_loc (die
, DW_AT_location
, l
);
26681 /* Return NULL if l is a DWARF expression, or first op that is not
26682 valid DWARF expression. */
26684 static dw_loc_descr_ref
26685 non_dwarf_expression (dw_loc_descr_ref l
)
26689 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
26691 switch (l
->dw_loc_opc
)
26694 case DW_OP_implicit_value
:
26695 case DW_OP_stack_value
:
26696 case DW_OP_GNU_implicit_pointer
:
26697 case DW_OP_GNU_parameter_ref
:
26699 case DW_OP_bit_piece
:
26704 l
= l
->dw_loc_next
;
26709 /* Return adjusted copy of EXPR:
26710 If it is empty DWARF expression, return it.
26711 If it is valid non-empty DWARF expression,
26712 return copy of EXPR with copy of DEREF appended to it.
26713 If it is DWARF expression followed by DW_OP_reg{N,x}, return
26714 copy of the DWARF expression with DW_OP_breg{N,x} <0> appended
26716 If it is DWARF expression followed by DW_OP_stack_value, return
26717 copy of the DWARF expression without anything appended.
26718 Otherwise, return NULL. */
26720 static dw_loc_descr_ref
26721 copy_deref_exprloc (dw_loc_descr_ref expr
, dw_loc_descr_ref deref
)
26727 dw_loc_descr_ref l
= non_dwarf_expression (expr
);
26728 if (l
&& l
->dw_loc_next
)
26733 if (l
->dw_loc_opc
>= DW_OP_reg0
&& l
->dw_loc_opc
<= DW_OP_reg31
)
26734 deref
= new_loc_descr ((enum dwarf_location_atom
)
26735 (DW_OP_breg0
+ (l
->dw_loc_opc
- DW_OP_reg0
)),
26738 switch (l
->dw_loc_opc
)
26741 deref
= new_loc_descr (DW_OP_bregx
,
26742 l
->dw_loc_oprnd1
.v
.val_unsigned
, 0);
26744 case DW_OP_stack_value
:
26752 deref
= new_loc_descr (deref
->dw_loc_opc
,
26753 deref
->dw_loc_oprnd1
.v
.val_int
, 0);
26755 dw_loc_descr_ref ret
= NULL
, *p
= &ret
;
26758 *p
= new_loc_descr (expr
->dw_loc_opc
, 0, 0);
26759 (*p
)->dw_loc_oprnd1
= expr
->dw_loc_oprnd1
;
26760 (*p
)->dw_loc_oprnd2
= expr
->dw_loc_oprnd2
;
26761 p
= &(*p
)->dw_loc_next
;
26762 expr
= expr
->dw_loc_next
;
26768 /* For DW_AT_string_length attribute with DW_OP_call4 reference to a variable
26769 or argument, adjust it if needed and return:
26770 -1 if the DW_AT_string_length attribute and DW_AT_byte_size attribute
26771 if present should be removed
26772 0 keep the attribute as is if the referenced var or argument has
26773 only DWARF expression that covers all ranges
26774 1 if the attribute has been successfully adjusted. */
26777 optimize_string_length (dw_attr_node
*a
)
26779 dw_loc_descr_ref l
= AT_loc (a
), lv
;
26780 dw_die_ref die
= l
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
26781 dw_attr_node
*av
= get_AT (die
, DW_AT_location
);
26783 bool non_dwarf_expr
= false;
26787 switch (AT_class (av
))
26789 case dw_val_class_loc_list
:
26790 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
26791 if (d
->expr
&& non_dwarf_expression (d
->expr
))
26792 non_dwarf_expr
= true;
26794 case dw_val_class_loc
:
26798 if (non_dwarf_expression (lv
))
26799 non_dwarf_expr
= true;
26805 /* If it is safe to keep DW_OP_call4 in, keep it. */
26806 if (!non_dwarf_expr
26807 && (l
->dw_loc_next
== NULL
|| AT_class (av
) == dw_val_class_loc
))
26810 /* If not dereferencing the DW_OP_call4 afterwards, we can just
26811 copy over the DW_AT_location attribute from die to a. */
26812 if (l
->dw_loc_next
== NULL
)
26814 a
->dw_attr_val
= av
->dw_attr_val
;
26818 dw_loc_list_ref list
, *p
;
26819 switch (AT_class (av
))
26821 case dw_val_class_loc_list
:
26824 for (d
= AT_loc_list (av
); d
!= NULL
; d
= d
->dw_loc_next
)
26826 lv
= copy_deref_exprloc (d
->expr
, l
->dw_loc_next
);
26829 *p
= new_loc_list (lv
, d
->begin
, d
->end
, d
->section
);
26830 p
= &(*p
)->dw_loc_next
;
26835 a
->dw_attr_val
.val_class
= dw_val_class_loc_list
;
26837 *AT_loc_list_ptr (a
) = list
;
26839 case dw_val_class_loc
:
26840 lv
= copy_deref_exprloc (AT_loc (av
), l
->dw_loc_next
);
26843 a
->dw_attr_val
.v
.val_loc
= lv
;
26846 gcc_unreachable ();
26850 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
26851 an address in .rodata section if the string literal is emitted there,
26852 or remove the containing location list or replace DW_AT_const_value
26853 with DW_AT_location and empty location expression, if it isn't found
26854 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
26855 to something that has been emitted in the current CU. */
26858 resolve_addr (dw_die_ref die
)
26862 dw_loc_list_ref
*curr
, *start
, loc
;
26864 bool remove_AT_byte_size
= false;
26866 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
26867 switch (AT_class (a
))
26869 case dw_val_class_loc_list
:
26870 start
= curr
= AT_loc_list_ptr (a
);
26873 /* The same list can be referenced more than once. See if we have
26874 already recorded the result from a previous pass. */
26876 *curr
= loc
->dw_loc_next
;
26877 else if (!loc
->resolved_addr
)
26879 /* As things stand, we do not expect or allow one die to
26880 reference a suffix of another die's location list chain.
26881 References must be identical or completely separate.
26882 There is therefore no need to cache the result of this
26883 pass on any list other than the first; doing so
26884 would lead to unnecessary writes. */
26887 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
26888 if (!resolve_addr_in_expr ((*curr
)->expr
))
26890 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
26891 dw_loc_descr_ref l
= (*curr
)->expr
;
26893 if (next
&& (*curr
)->ll_symbol
)
26895 gcc_assert (!next
->ll_symbol
);
26896 next
->ll_symbol
= (*curr
)->ll_symbol
;
26898 if (dwarf_split_debug_info
)
26899 remove_loc_list_addr_table_entries (l
);
26904 mark_base_types ((*curr
)->expr
);
26905 curr
= &(*curr
)->dw_loc_next
;
26909 loc
->resolved_addr
= 1;
26913 loc
->dw_loc_next
= *start
;
26918 remove_AT (die
, a
->dw_attr
);
26922 case dw_val_class_loc
:
26924 dw_loc_descr_ref l
= AT_loc (a
);
26925 /* Using DW_OP_call4 or DW_OP_call4 DW_OP_deref in
26926 DW_AT_string_length is only a rough approximation; unfortunately
26927 DW_AT_string_length can't be a reference to a DIE. DW_OP_call4
26928 needs a DWARF expression, while DW_AT_location of the referenced
26929 variable or argument might be any location description. */
26930 if (a
->dw_attr
== DW_AT_string_length
26932 && l
->dw_loc_opc
== DW_OP_call4
26933 && l
->dw_loc_oprnd1
.val_class
== dw_val_class_die_ref
26934 && (l
->dw_loc_next
== NULL
26935 || (l
->dw_loc_next
->dw_loc_next
== NULL
26936 && (l
->dw_loc_next
->dw_loc_opc
== DW_OP_deref
26937 || l
->dw_loc_next
->dw_loc_opc
!= DW_OP_deref_size
))))
26939 switch (optimize_string_length (a
))
26942 remove_AT (die
, a
->dw_attr
);
26944 /* For DWARF4 and earlier, if we drop DW_AT_string_length,
26945 we need to drop also DW_AT_byte_size. */
26946 remove_AT_byte_size
= true;
26951 /* Even if we keep the optimized DW_AT_string_length,
26952 it might have changed AT_class, so process it again. */
26957 /* For -gdwarf-2 don't attempt to optimize
26958 DW_AT_data_member_location containing
26959 DW_OP_plus_uconst - older consumers might
26960 rely on it being that op instead of a more complex,
26961 but shorter, location description. */
26962 if ((dwarf_version
> 2
26963 || a
->dw_attr
!= DW_AT_data_member_location
26965 || l
->dw_loc_opc
!= DW_OP_plus_uconst
26966 || l
->dw_loc_next
!= NULL
)
26967 && !resolve_addr_in_expr (l
))
26969 if (dwarf_split_debug_info
)
26970 remove_loc_list_addr_table_entries (l
);
26972 && l
->dw_loc_next
== NULL
26973 && l
->dw_loc_opc
== DW_OP_addr
26974 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
26975 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
26976 && a
->dw_attr
== DW_AT_location
)
26978 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
26979 remove_AT (die
, a
->dw_attr
);
26981 optimize_location_into_implicit_ptr (die
, decl
);
26984 remove_AT (die
, a
->dw_attr
);
26988 mark_base_types (l
);
26991 case dw_val_class_addr
:
26992 if (a
->dw_attr
== DW_AT_const_value
26993 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
26995 if (AT_index (a
) != NOT_INDEXED
)
26996 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
26997 remove_AT (die
, a
->dw_attr
);
27000 if (die
->die_tag
== DW_TAG_GNU_call_site
27001 && a
->dw_attr
== DW_AT_abstract_origin
)
27003 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
27004 dw_die_ref tdie
= lookup_decl_die (tdecl
);
27007 && DECL_EXTERNAL (tdecl
)
27008 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
27009 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
27011 /* Creating a full DIE for tdecl is overly expensive and
27012 at this point even wrong when in the LTO phase
27013 as it can end up generating new type DIEs we didn't
27014 output and thus optimize_external_refs will crash. */
27015 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
27016 add_AT_flag (tdie
, DW_AT_external
, 1);
27017 add_AT_flag (tdie
, DW_AT_declaration
, 1);
27018 add_linkage_attr (tdie
, tdecl
);
27019 add_name_and_src_coords_attributes (tdie
, tdecl
);
27020 equate_decl_number_to_die (tdecl
, tdie
);
27024 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
27025 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
27026 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
27030 if (AT_index (a
) != NOT_INDEXED
)
27031 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
27032 remove_AT (die
, a
->dw_attr
);
27041 if (remove_AT_byte_size
)
27042 remove_AT (die
, DW_AT_byte_size
);
27044 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
27047 /* Helper routines for optimize_location_lists.
27048 This pass tries to share identical local lists in .debug_loc
27051 /* Iteratively hash operands of LOC opcode into HSTATE. */
27054 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
27056 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
27057 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
27059 switch (loc
->dw_loc_opc
)
27061 case DW_OP_const4u
:
27062 case DW_OP_const8u
:
27066 case DW_OP_const1u
:
27067 case DW_OP_const1s
:
27068 case DW_OP_const2u
:
27069 case DW_OP_const2s
:
27070 case DW_OP_const4s
:
27071 case DW_OP_const8s
:
27075 case DW_OP_plus_uconst
:
27111 case DW_OP_deref_size
:
27112 case DW_OP_xderef_size
:
27113 hstate
.add_object (val1
->v
.val_int
);
27120 gcc_assert (val1
->val_class
== dw_val_class_loc
);
27121 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
27122 hstate
.add_object (offset
);
27125 case DW_OP_implicit_value
:
27126 hstate
.add_object (val1
->v
.val_unsigned
);
27127 switch (val2
->val_class
)
27129 case dw_val_class_const
:
27130 hstate
.add_object (val2
->v
.val_int
);
27132 case dw_val_class_vec
:
27134 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
27135 unsigned int len
= val2
->v
.val_vec
.length
;
27137 hstate
.add_int (elt_size
);
27138 hstate
.add_int (len
);
27139 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
27142 case dw_val_class_const_double
:
27143 hstate
.add_object (val2
->v
.val_double
.low
);
27144 hstate
.add_object (val2
->v
.val_double
.high
);
27146 case dw_val_class_wide_int
:
27147 hstate
.add (val2
->v
.val_wide
->get_val (),
27148 get_full_len (*val2
->v
.val_wide
)
27149 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
27151 case dw_val_class_addr
:
27152 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
27155 gcc_unreachable ();
27159 case DW_OP_bit_piece
:
27160 hstate
.add_object (val1
->v
.val_int
);
27161 hstate
.add_object (val2
->v
.val_int
);
27167 unsigned char dtprel
= 0xd1;
27168 hstate
.add_object (dtprel
);
27170 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
27172 case DW_OP_GNU_addr_index
:
27173 case DW_OP_GNU_const_index
:
27177 unsigned char dtprel
= 0xd1;
27178 hstate
.add_object (dtprel
);
27180 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
27183 case DW_OP_GNU_implicit_pointer
:
27184 hstate
.add_int (val2
->v
.val_int
);
27186 case DW_OP_GNU_entry_value
:
27187 hstate
.add_object (val1
->v
.val_loc
);
27189 case DW_OP_GNU_regval_type
:
27190 case DW_OP_GNU_deref_type
:
27192 unsigned int byte_size
27193 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
27194 unsigned int encoding
27195 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
27196 hstate
.add_object (val1
->v
.val_int
);
27197 hstate
.add_object (byte_size
);
27198 hstate
.add_object (encoding
);
27201 case DW_OP_GNU_convert
:
27202 case DW_OP_GNU_reinterpret
:
27203 if (val1
->val_class
== dw_val_class_unsigned_const
)
27205 hstate
.add_object (val1
->v
.val_unsigned
);
27209 case DW_OP_GNU_const_type
:
27211 unsigned int byte_size
27212 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
27213 unsigned int encoding
27214 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
27215 hstate
.add_object (byte_size
);
27216 hstate
.add_object (encoding
);
27217 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
27219 hstate
.add_object (val2
->val_class
);
27220 switch (val2
->val_class
)
27222 case dw_val_class_const
:
27223 hstate
.add_object (val2
->v
.val_int
);
27225 case dw_val_class_vec
:
27227 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
27228 unsigned int len
= val2
->v
.val_vec
.length
;
27230 hstate
.add_object (elt_size
);
27231 hstate
.add_object (len
);
27232 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
27235 case dw_val_class_const_double
:
27236 hstate
.add_object (val2
->v
.val_double
.low
);
27237 hstate
.add_object (val2
->v
.val_double
.high
);
27239 case dw_val_class_wide_int
:
27240 hstate
.add (val2
->v
.val_wide
->get_val (),
27241 get_full_len (*val2
->v
.val_wide
)
27242 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
27245 gcc_unreachable ();
27251 /* Other codes have no operands. */
27256 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
27259 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
27261 dw_loc_descr_ref l
;
27262 bool sizes_computed
= false;
27263 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
27264 size_of_locs (loc
);
27266 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
27268 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
27269 hstate
.add_object (opc
);
27270 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
27272 size_of_locs (loc
);
27273 sizes_computed
= true;
27275 hash_loc_operands (l
, hstate
);
27279 /* Compute hash of the whole location list LIST_HEAD. */
27282 hash_loc_list (dw_loc_list_ref list_head
)
27284 dw_loc_list_ref curr
= list_head
;
27285 inchash::hash hstate
;
27287 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
27289 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
27290 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
27292 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
27293 hash_locs (curr
->expr
, hstate
);
27295 list_head
->hash
= hstate
.end ();
27298 /* Return true if X and Y opcodes have the same operands. */
27301 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
27303 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
27304 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
27305 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
27306 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
27308 switch (x
->dw_loc_opc
)
27310 case DW_OP_const4u
:
27311 case DW_OP_const8u
:
27315 case DW_OP_const1u
:
27316 case DW_OP_const1s
:
27317 case DW_OP_const2u
:
27318 case DW_OP_const2s
:
27319 case DW_OP_const4s
:
27320 case DW_OP_const8s
:
27324 case DW_OP_plus_uconst
:
27360 case DW_OP_deref_size
:
27361 case DW_OP_xderef_size
:
27362 return valx1
->v
.val_int
== valy1
->v
.val_int
;
27365 /* If splitting debug info, the use of DW_OP_GNU_addr_index
27366 can cause irrelevant differences in dw_loc_addr. */
27367 gcc_assert (valx1
->val_class
== dw_val_class_loc
27368 && valy1
->val_class
== dw_val_class_loc
27369 && (dwarf_split_debug_info
27370 || x
->dw_loc_addr
== y
->dw_loc_addr
));
27371 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
27372 case DW_OP_implicit_value
:
27373 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
27374 || valx2
->val_class
!= valy2
->val_class
)
27376 switch (valx2
->val_class
)
27378 case dw_val_class_const
:
27379 return valx2
->v
.val_int
== valy2
->v
.val_int
;
27380 case dw_val_class_vec
:
27381 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
27382 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
27383 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
27384 valx2
->v
.val_vec
.elt_size
27385 * valx2
->v
.val_vec
.length
) == 0;
27386 case dw_val_class_const_double
:
27387 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
27388 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
27389 case dw_val_class_wide_int
:
27390 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
27391 case dw_val_class_addr
:
27392 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
27394 gcc_unreachable ();
27397 case DW_OP_bit_piece
:
27398 return valx1
->v
.val_int
== valy1
->v
.val_int
27399 && valx2
->v
.val_int
== valy2
->v
.val_int
;
27402 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
27403 case DW_OP_GNU_addr_index
:
27404 case DW_OP_GNU_const_index
:
27406 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
27407 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
27408 return rtx_equal_p (ax1
, ay1
);
27410 case DW_OP_GNU_implicit_pointer
:
27411 return valx1
->val_class
== dw_val_class_die_ref
27412 && valx1
->val_class
== valy1
->val_class
27413 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
27414 && valx2
->v
.val_int
== valy2
->v
.val_int
;
27415 case DW_OP_GNU_entry_value
:
27416 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
27417 case DW_OP_GNU_const_type
:
27418 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
27419 || valx2
->val_class
!= valy2
->val_class
)
27421 switch (valx2
->val_class
)
27423 case dw_val_class_const
:
27424 return valx2
->v
.val_int
== valy2
->v
.val_int
;
27425 case dw_val_class_vec
:
27426 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
27427 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
27428 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
27429 valx2
->v
.val_vec
.elt_size
27430 * valx2
->v
.val_vec
.length
) == 0;
27431 case dw_val_class_const_double
:
27432 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
27433 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
27434 case dw_val_class_wide_int
:
27435 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
27437 gcc_unreachable ();
27439 case DW_OP_GNU_regval_type
:
27440 case DW_OP_GNU_deref_type
:
27441 return valx1
->v
.val_int
== valy1
->v
.val_int
27442 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
27443 case DW_OP_GNU_convert
:
27444 case DW_OP_GNU_reinterpret
:
27445 if (valx1
->val_class
!= valy1
->val_class
)
27447 if (valx1
->val_class
== dw_val_class_unsigned_const
)
27448 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
27449 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
27450 case DW_OP_GNU_parameter_ref
:
27451 return valx1
->val_class
== dw_val_class_die_ref
27452 && valx1
->val_class
== valy1
->val_class
27453 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
27455 /* Other codes have no operands. */
27460 /* Return true if DWARF location expressions X and Y are the same. */
27463 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
27465 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
27466 if (x
->dw_loc_opc
!= y
->dw_loc_opc
27467 || x
->dtprel
!= y
->dtprel
27468 || !compare_loc_operands (x
, y
))
27470 return x
== NULL
&& y
== NULL
;
27473 /* Hashtable helpers. */
27475 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
27477 static inline hashval_t
hash (const dw_loc_list_struct
*);
27478 static inline bool equal (const dw_loc_list_struct
*,
27479 const dw_loc_list_struct
*);
27482 /* Return precomputed hash of location list X. */
27485 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
27490 /* Return true if location lists A and B are the same. */
27493 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
27494 const dw_loc_list_struct
*b
)
27498 if (a
->hash
!= b
->hash
)
27500 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
27501 if (strcmp (a
->begin
, b
->begin
) != 0
27502 || strcmp (a
->end
, b
->end
) != 0
27503 || (a
->section
== NULL
) != (b
->section
== NULL
)
27504 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
27505 || !compare_locs (a
->expr
, b
->expr
))
27507 return a
== NULL
&& b
== NULL
;
27510 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
27513 /* Recursively optimize location lists referenced from DIE
27514 children and share them whenever possible. */
27517 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
27522 dw_loc_list_struct
**slot
;
27524 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27525 if (AT_class (a
) == dw_val_class_loc_list
)
27527 dw_loc_list_ref list
= AT_loc_list (a
);
27528 /* TODO: perform some optimizations here, before hashing
27529 it and storing into the hash table. */
27530 hash_loc_list (list
);
27531 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
27535 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
27538 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
27542 /* Recursively assign each location list a unique index into the debug_addr
27546 index_location_lists (dw_die_ref die
)
27552 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
27553 if (AT_class (a
) == dw_val_class_loc_list
)
27555 dw_loc_list_ref list
= AT_loc_list (a
);
27556 dw_loc_list_ref curr
;
27557 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
27559 /* Don't index an entry that has already been indexed
27560 or won't be output. */
27561 if (curr
->begin_entry
!= NULL
27562 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
27566 = add_addr_table_entry (xstrdup (curr
->begin
),
27571 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
27574 /* Optimize location lists referenced from DIE
27575 children and share them whenever possible. */
27578 optimize_location_lists (dw_die_ref die
)
27580 loc_list_hash_type
htab (500);
27581 optimize_location_lists_1 (die
, &htab
);
27584 /* Traverse the limbo die list, and add parent/child links. The only
27585 dies without parents that should be here are concrete instances of
27586 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
27587 For concrete instances, we can get the parent die from the abstract
27591 flush_limbo_die_list (void)
27593 limbo_die_node
*node
;
27595 /* get_context_die calls force_decl_die, which can put new DIEs on the
27596 limbo list in LTO mode when nested functions are put in a different
27597 partition than that of their parent function. */
27598 while ((node
= limbo_die_list
))
27600 dw_die_ref die
= node
->die
;
27601 limbo_die_list
= node
->next
;
27603 if (die
->die_parent
== NULL
)
27605 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
27607 if (origin
&& origin
->die_parent
)
27608 add_child_die (origin
->die_parent
, die
);
27609 else if (is_cu_die (die
))
27611 else if (seen_error ())
27612 /* It's OK to be confused by errors in the input. */
27613 add_child_die (comp_unit_die (), die
);
27616 /* In certain situations, the lexical block containing a
27617 nested function can be optimized away, which results
27618 in the nested function die being orphaned. Likewise
27619 with the return type of that nested function. Force
27620 this to be a child of the containing function.
27622 It may happen that even the containing function got fully
27623 inlined and optimized out. In that case we are lost and
27624 assign the empty child. This should not be big issue as
27625 the function is likely unreachable too. */
27626 gcc_assert (node
->created_for
);
27628 if (DECL_P (node
->created_for
))
27629 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
27630 else if (TYPE_P (node
->created_for
))
27631 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
27633 origin
= comp_unit_die ();
27635 add_child_die (origin
, die
);
27641 /* Output stuff that dwarf requires at the end of every file,
27642 and generate the DWARF-2 debugging info. */
27645 dwarf2out_finish (const char *filename
)
27647 comdat_type_node
*ctnode
;
27648 dw_die_ref main_comp_unit_die
;
27650 /* Flush out any latecomers to the limbo party. */
27651 flush_limbo_die_list ();
27653 /* We shouldn't have any symbols with delayed asm names for
27654 DIEs generated after early finish. */
27655 gcc_assert (deferred_asm_name
== NULL
);
27657 /* PCH might result in DW_AT_producer string being restored from the
27658 header compilation, so always fill it with empty string initially
27659 and overwrite only here. */
27660 dw_attr_node
*producer
= get_AT (comp_unit_die (), DW_AT_producer
);
27661 producer_string
= gen_producer_string ();
27662 producer
->dw_attr_val
.v
.val_str
->refcount
--;
27663 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
27665 gen_remaining_tmpl_value_param_die_attribute ();
27667 /* Add the name for the main input file now. We delayed this from
27668 dwarf2out_init to avoid complications with PCH.
27669 For LTO produced units use a fixed artificial name to avoid
27670 leaking tempfile names into the dwarf. */
27672 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
27674 add_name_attribute (comp_unit_die (), "<artificial>");
27675 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
27676 add_comp_dir_attribute (comp_unit_die ());
27677 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
27680 file_table
->traverse
<bool *, file_table_relative_p
> (&p
);
27682 add_comp_dir_attribute (comp_unit_die ());
27685 #if ENABLE_ASSERT_CHECKING
27687 dw_die_ref die
= comp_unit_die (), c
;
27688 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
27691 resolve_addr (comp_unit_die ());
27692 move_marked_base_types ();
27694 if (flag_eliminate_unused_debug_types
)
27695 prune_unused_types ();
27697 /* Generate separate COMDAT sections for type DIEs. */
27698 if (use_debug_types
)
27700 break_out_comdat_types (comp_unit_die ());
27702 /* Each new type_unit DIE was added to the limbo die list when created.
27703 Since these have all been added to comdat_type_list, clear the
27705 limbo_die_list
= NULL
;
27707 /* For each new comdat type unit, copy declarations for incomplete
27708 types to make the new unit self-contained (i.e., no direct
27709 references to the main compile unit). */
27710 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
27711 copy_decls_for_unworthy_types (ctnode
->root_die
);
27712 copy_decls_for_unworthy_types (comp_unit_die ());
27714 /* In the process of copying declarations from one unit to another,
27715 we may have left some declarations behind that are no longer
27716 referenced. Prune them. */
27717 prune_unused_types ();
27720 /* Generate separate CUs for each of the include files we've seen.
27721 They will go into limbo_die_list. */
27722 if (flag_eliminate_dwarf2_dups
)
27723 break_out_includes (comp_unit_die ());
27725 /* Traverse the DIE's and add sibling attributes to those DIE's that
27727 add_sibling_attributes (comp_unit_die ());
27728 limbo_die_node
*node
;
27729 for (node
= limbo_die_list
; node
; node
= node
->next
)
27730 add_sibling_attributes (node
->die
);
27731 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
27732 add_sibling_attributes (ctnode
->root_die
);
27734 /* When splitting DWARF info, we put some attributes in the
27735 skeleton compile_unit DIE that remains in the .o, while
27736 most attributes go in the DWO compile_unit_die. */
27737 if (dwarf_split_debug_info
)
27738 main_comp_unit_die
= gen_compile_unit_die (NULL
);
27740 main_comp_unit_die
= comp_unit_die ();
27742 /* Output a terminator label for the .text section. */
27743 switch_to_section (text_section
);
27744 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
27745 if (cold_text_section
)
27747 switch_to_section (cold_text_section
);
27748 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
27751 /* We can only use the low/high_pc attributes if all of the code was
27753 if (!have_multiple_function_sections
27754 || (dwarf_version
< 3 && dwarf_strict
))
27756 /* Don't add if the CU has no associated code. */
27757 if (text_section_used
)
27758 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
27759 text_end_label
, true);
27765 bool range_list_added
= false;
27767 if (text_section_used
)
27768 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
27769 text_end_label
, &range_list_added
, true);
27770 if (cold_text_section_used
)
27771 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
27772 cold_end_label
, &range_list_added
, true);
27774 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
27776 if (DECL_IGNORED_P (fde
->decl
))
27778 if (!fde
->in_std_section
)
27779 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
27780 fde
->dw_fde_end
, &range_list_added
,
27782 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
27783 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
27784 fde
->dw_fde_second_end
, &range_list_added
,
27788 if (range_list_added
)
27790 /* We need to give .debug_loc and .debug_ranges an appropriate
27791 "base address". Use zero so that these addresses become
27792 absolute. Historically, we've emitted the unexpected
27793 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
27794 Emit both to give time for other tools to adapt. */
27795 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
27796 if (! dwarf_strict
&& dwarf_version
< 4)
27797 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
27803 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
27804 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
27805 debug_line_section_label
);
27808 add_AT_macptr (comp_unit_die (),
27809 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
27810 macinfo_section_label
);
27812 if (dwarf_split_debug_info
)
27814 /* optimize_location_lists calculates the size of the lists,
27815 so index them first, and assign indices to the entries.
27816 Although optimize_location_lists will remove entries from
27817 the table, it only does so for duplicates, and therefore
27818 only reduces ref_counts to 1. */
27819 index_location_lists (comp_unit_die ());
27821 if (addr_index_table
!= NULL
)
27823 unsigned int index
= 0;
27825 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
27830 if (have_location_lists
)
27831 optimize_location_lists (comp_unit_die ());
27833 save_macinfo_strings ();
27835 if (dwarf_split_debug_info
)
27837 unsigned int index
= 0;
27839 /* Add attributes common to skeleton compile_units and
27840 type_units. Because these attributes include strings, it
27841 must be done before freezing the string table. Top-level
27842 skeleton die attrs are added when the skeleton type unit is
27843 created, so ensure it is created by this point. */
27844 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
27845 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
27848 /* Output all of the compilation units. We put the main one last so that
27849 the offsets are available to output_pubnames. */
27850 for (node
= limbo_die_list
; node
; node
= node
->next
)
27851 output_comp_unit (node
->die
, 0);
27853 hash_table
<comdat_type_hasher
> comdat_type_table (100);
27854 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
27856 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
27858 /* Don't output duplicate types. */
27859 if (*slot
!= HTAB_EMPTY_ENTRY
)
27862 /* Add a pointer to the line table for the main compilation unit
27863 so that the debugger can make sense of DW_AT_decl_file
27865 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
27866 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
27867 (!dwarf_split_debug_info
27868 ? debug_line_section_label
27869 : debug_skeleton_line_section_label
));
27871 output_comdat_type_unit (ctnode
);
27875 /* The AT_pubnames attribute needs to go in all skeleton dies, including
27876 both the main_cu and all skeleton TUs. Making this call unconditional
27877 would end up either adding a second copy of the AT_pubnames attribute, or
27878 requiring a special case in add_top_level_skeleton_die_attrs. */
27879 if (!dwarf_split_debug_info
)
27880 add_AT_pubnames (comp_unit_die ());
27882 if (dwarf_split_debug_info
)
27885 unsigned char checksum
[16];
27886 struct md5_ctx ctx
;
27888 /* Compute a checksum of the comp_unit to use as the dwo_id. */
27889 md5_init_ctx (&ctx
);
27891 die_checksum (comp_unit_die (), &ctx
, &mark
);
27892 unmark_all_dies (comp_unit_die ());
27893 md5_finish_ctx (&ctx
, checksum
);
27895 /* Use the first 8 bytes of the checksum as the dwo_id,
27896 and add it to both comp-unit DIEs. */
27897 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
27898 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
27900 /* Add the base offset of the ranges table to the skeleton
27902 if (ranges_table_in_use
)
27903 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
27904 ranges_section_label
);
27906 switch_to_section (debug_addr_section
);
27907 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
27908 output_addr_table ();
27911 /* Output the main compilation unit if non-empty or if .debug_macinfo
27912 or .debug_macro will be emitted. */
27913 output_comp_unit (comp_unit_die (), have_macinfo
);
27915 if (dwarf_split_debug_info
&& info_section_emitted
)
27916 output_skeleton_debug_sections (main_comp_unit_die
);
27918 /* Output the abbreviation table. */
27919 if (abbrev_die_table_in_use
!= 1)
27921 switch_to_section (debug_abbrev_section
);
27922 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
27923 output_abbrev_section ();
27926 /* Output location list section if necessary. */
27927 if (have_location_lists
)
27929 /* Output the location lists info. */
27930 switch_to_section (debug_loc_section
);
27931 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
27932 output_location_lists (comp_unit_die ());
27935 output_pubtables ();
27937 /* Output the address range information if a CU (.debug_info section)
27938 was emitted. We output an empty table even if we had no functions
27939 to put in it. This because the consumer has no way to tell the
27940 difference between an empty table that we omitted and failure to
27941 generate a table that would have contained data. */
27942 if (info_section_emitted
)
27944 switch_to_section (debug_aranges_section
);
27948 /* Output ranges section if necessary. */
27949 if (ranges_table_in_use
)
27951 switch_to_section (debug_ranges_section
);
27952 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
27956 /* Have to end the macro section. */
27959 switch_to_section (debug_macinfo_section
);
27960 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
27962 dw2_asm_output_data (1, 0, "End compilation unit");
27965 /* Output the source line correspondence table. We must do this
27966 even if there is no line information. Otherwise, on an empty
27967 translation unit, we will generate a present, but empty,
27968 .debug_info section. IRIX 6.5 `nm' will then complain when
27969 examining the file. This is done late so that any filenames
27970 used by the debug_info section are marked as 'used'. */
27971 switch_to_section (debug_line_section
);
27972 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
27973 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
27974 output_line_info (false);
27976 if (dwarf_split_debug_info
&& info_section_emitted
)
27978 switch_to_section (debug_skeleton_line_section
);
27979 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
27980 output_line_info (true);
27983 /* If we emitted any indirect strings, output the string table too. */
27984 if (debug_str_hash
|| skeleton_debug_str_hash
)
27985 output_indirect_strings ();
27988 /* Perform any cleanups needed after the early debug generation pass
27992 dwarf2out_early_finish (void)
27994 /* Walk through the list of incomplete types again, trying once more to
27995 emit full debugging info for them. */
27996 retry_incomplete_types ();
27998 /* The point here is to flush out the limbo list so that it is empty
27999 and we don't need to stream it for LTO. */
28000 flush_limbo_die_list ();
28002 gen_scheduled_generic_parms_dies ();
28003 gen_remaining_tmpl_value_param_die_attribute ();
28005 /* Add DW_AT_linkage_name for all deferred DIEs. */
28006 for (limbo_die_node
*node
= deferred_asm_name
; node
; node
= node
->next
)
28008 tree decl
= node
->created_for
;
28009 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
28010 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
28011 ended up in deferred_asm_name before we knew it was
28012 constant and never written to disk. */
28013 && DECL_ASSEMBLER_NAME (decl
))
28015 add_linkage_attr (node
->die
, decl
);
28016 move_linkage_attr (node
->die
);
28019 deferred_asm_name
= NULL
;
28022 /* Reset all state within dwarf2out.c so that we can rerun the compiler
28023 within the same process. For use by toplev::finalize. */
28026 dwarf2out_c_finalize (void)
28028 last_var_location_insn
= NULL
;
28029 cached_next_real_insn
= NULL
;
28030 used_rtx_array
= NULL
;
28031 incomplete_types
= NULL
;
28032 decl_scope_table
= NULL
;
28033 debug_info_section
= NULL
;
28034 debug_skeleton_info_section
= NULL
;
28035 debug_abbrev_section
= NULL
;
28036 debug_skeleton_abbrev_section
= NULL
;
28037 debug_aranges_section
= NULL
;
28038 debug_addr_section
= NULL
;
28039 debug_macinfo_section
= NULL
;
28040 debug_line_section
= NULL
;
28041 debug_skeleton_line_section
= NULL
;
28042 debug_loc_section
= NULL
;
28043 debug_pubnames_section
= NULL
;
28044 debug_pubtypes_section
= NULL
;
28045 debug_str_section
= NULL
;
28046 debug_str_dwo_section
= NULL
;
28047 debug_str_offsets_section
= NULL
;
28048 debug_ranges_section
= NULL
;
28049 debug_frame_section
= NULL
;
28051 debug_str_hash
= NULL
;
28052 skeleton_debug_str_hash
= NULL
;
28053 dw2_string_counter
= 0;
28054 have_multiple_function_sections
= false;
28055 text_section_used
= false;
28056 cold_text_section_used
= false;
28057 cold_text_section
= NULL
;
28058 current_unit_personality
= NULL
;
28060 next_die_offset
= 0;
28061 single_comp_unit_die
= NULL
;
28062 comdat_type_list
= NULL
;
28063 limbo_die_list
= NULL
;
28065 decl_die_table
= NULL
;
28066 common_block_die_table
= NULL
;
28067 decl_loc_table
= NULL
;
28068 call_arg_locations
= NULL
;
28069 call_arg_loc_last
= NULL
;
28070 call_site_count
= -1;
28071 tail_call_site_count
= -1;
28072 cached_dw_loc_list_table
= NULL
;
28073 abbrev_die_table
= NULL
;
28074 abbrev_die_table_allocated
= 0;
28075 abbrev_die_table_in_use
= 0;
28076 delete dwarf_proc_stack_usage_map
;
28077 dwarf_proc_stack_usage_map
= NULL
;
28078 line_info_label_num
= 0;
28079 cur_line_info_table
= NULL
;
28080 text_section_line_info
= NULL
;
28081 cold_text_section_line_info
= NULL
;
28082 separate_line_info
= NULL
;
28083 info_section_emitted
= false;
28084 pubname_table
= NULL
;
28085 pubtype_table
= NULL
;
28086 macinfo_table
= NULL
;
28087 ranges_table
= NULL
;
28088 ranges_table_allocated
= 0;
28089 ranges_table_in_use
= 0;
28090 ranges_by_label
= 0;
28091 ranges_by_label_allocated
= 0;
28092 ranges_by_label_in_use
= 0;
28093 have_location_lists
= false;
28096 last_emitted_file
= NULL
;
28098 tmpl_value_parm_die_table
= NULL
;
28099 generic_type_instances
= NULL
;
28100 frame_pointer_fb_offset
= 0;
28101 frame_pointer_fb_offset_valid
= false;
28102 base_types
.release ();
28103 XDELETEVEC (producer_string
);
28104 producer_string
= NULL
;
28107 #include "gt-dwarf2out.h"