1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2015 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 "fold-const.h"
67 #include "stringpool.h"
68 #include "stor-layout.h"
70 #include "hard-reg-set.h"
77 #include "insn-config.h"
88 #include "dwarf2out.h"
89 #include "dwarf2asm.h"
93 #include "diagnostic.h"
94 #include "tree-pretty-print.h"
97 #include "common/common-target.h"
98 #include "langhooks.h"
102 #include "dumpfile.h"
104 #include "tree-dfa.h"
105 #include "gdb/gdb-index.h"
106 #include "rtl-iter.h"
108 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
109 static rtx_insn
*last_var_location_insn
;
110 static rtx_insn
*cached_next_real_insn
;
111 static void dwarf2out_decl (tree
);
113 #ifdef VMS_DEBUGGING_INFO
114 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
116 /* Define this macro to be a nonzero value if the directory specifications
117 which are output in the debug info should end with a separator. */
118 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
119 /* Define this macro to evaluate to a nonzero value if GCC should refrain
120 from generating indirect strings in DWARF2 debug information, for instance
121 if your target is stuck with an old version of GDB that is unable to
122 process them properly or uses VMS Debug. */
123 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
125 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
126 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
129 /* ??? Poison these here until it can be done generically. They've been
130 totally replaced in this file; make sure it stays that way. */
131 #undef DWARF2_UNWIND_INFO
132 #undef DWARF2_FRAME_INFO
133 #if (GCC_VERSION >= 3000)
134 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
137 /* The size of the target's pointer type. */
139 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
142 /* Array of RTXes referenced by the debugging information, which therefore
143 must be kept around forever. */
144 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
146 /* A pointer to the base of a list of incomplete types which might be
147 completed at some later time. incomplete_types_list needs to be a
148 vec<tree, va_gc> *because we want to tell the garbage collector about
150 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
152 /* A pointer to the base of a table of references to declaration
153 scopes. This table is a display which tracks the nesting
154 of declaration scopes at the current scope and containing
155 scopes. This table is used to find the proper place to
156 define type declaration DIE's. */
157 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
159 /* Pointers to various DWARF2 sections. */
160 static GTY(()) section
*debug_info_section
;
161 static GTY(()) section
*debug_skeleton_info_section
;
162 static GTY(()) section
*debug_abbrev_section
;
163 static GTY(()) section
*debug_skeleton_abbrev_section
;
164 static GTY(()) section
*debug_aranges_section
;
165 static GTY(()) section
*debug_addr_section
;
166 static GTY(()) section
*debug_macinfo_section
;
167 static GTY(()) section
*debug_line_section
;
168 static GTY(()) section
*debug_skeleton_line_section
;
169 static GTY(()) section
*debug_loc_section
;
170 static GTY(()) section
*debug_pubnames_section
;
171 static GTY(()) section
*debug_pubtypes_section
;
172 static GTY(()) section
*debug_str_section
;
173 static GTY(()) section
*debug_str_dwo_section
;
174 static GTY(()) section
*debug_str_offsets_section
;
175 static GTY(()) section
*debug_ranges_section
;
176 static GTY(()) section
*debug_frame_section
;
178 /* Maximum size (in bytes) of an artificially generated label. */
179 #define MAX_ARTIFICIAL_LABEL_BYTES 30
181 /* According to the (draft) DWARF 3 specification, the initial length
182 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
183 bytes are 0xffffffff, followed by the length stored in the next 8
186 However, the SGI/MIPS ABI uses an initial length which is equal to
187 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
189 #ifndef DWARF_INITIAL_LENGTH_SIZE
190 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
193 /* Round SIZE up to the nearest BOUNDARY. */
194 #define DWARF_ROUND(SIZE,BOUNDARY) \
195 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
197 /* CIE identifier. */
198 #if HOST_BITS_PER_WIDE_INT >= 64
199 #define DWARF_CIE_ID \
200 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
202 #define DWARF_CIE_ID DW_CIE_ID
206 /* A vector for a table that contains frame description
207 information for each routine. */
208 #define NOT_INDEXED (-1U)
209 #define NO_INDEX_ASSIGNED (-2U)
211 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
213 struct GTY((for_user
)) indirect_string_node
{
215 unsigned int refcount
;
216 enum dwarf_form form
;
221 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
223 typedef const char *compare_type
;
225 static hashval_t
hash (indirect_string_node
*);
226 static bool equal (indirect_string_node
*, const char *);
229 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
231 /* With split_debug_info, both the comp_dir and dwo_name go in the
232 main object file, rather than the dwo, similar to the force_direct
233 parameter elsewhere but with additional complications:
235 1) The string is needed in both the main object file and the dwo.
236 That is, the comp_dir and dwo_name will appear in both places.
238 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
239 DW_FORM_GNU_str_index.
241 3) GCC chooses the form to use late, depending on the size and
244 Rather than forcing the all debug string handling functions and
245 callers to deal with these complications, simply use a separate,
246 special-cased string table for any attribute that should go in the
247 main object file. This limits the complexity to just the places
250 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
252 static GTY(()) int dw2_string_counter
;
254 /* True if the compilation unit places functions in more than one section. */
255 static GTY(()) bool have_multiple_function_sections
= false;
257 /* Whether the default text and cold text sections have been used at all. */
259 static GTY(()) bool text_section_used
= false;
260 static GTY(()) bool cold_text_section_used
= false;
262 /* The default cold text section. */
263 static GTY(()) section
*cold_text_section
;
265 /* The DIE for C++14 'auto' in a function return type. */
266 static GTY(()) dw_die_ref auto_die
;
268 /* The DIE for C++14 'decltype(auto)' in a function return type. */
269 static GTY(()) dw_die_ref decltype_auto_die
;
271 /* Forward declarations for functions defined in this file. */
273 static char *stripattributes (const char *);
274 static void output_call_frame_info (int);
275 static void dwarf2out_note_section_used (void);
277 /* Personality decl of current unit. Used only when assembler does not support
279 static GTY(()) rtx current_unit_personality
;
281 /* Data and reference forms for relocatable data. */
282 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
283 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
285 #ifndef DEBUG_FRAME_SECTION
286 #define DEBUG_FRAME_SECTION ".debug_frame"
289 #ifndef FUNC_BEGIN_LABEL
290 #define FUNC_BEGIN_LABEL "LFB"
293 #ifndef FUNC_END_LABEL
294 #define FUNC_END_LABEL "LFE"
297 #ifndef PROLOGUE_END_LABEL
298 #define PROLOGUE_END_LABEL "LPE"
301 #ifndef EPILOGUE_BEGIN_LABEL
302 #define EPILOGUE_BEGIN_LABEL "LEB"
305 #ifndef FRAME_BEGIN_LABEL
306 #define FRAME_BEGIN_LABEL "Lframe"
308 #define CIE_AFTER_SIZE_LABEL "LSCIE"
309 #define CIE_END_LABEL "LECIE"
310 #define FDE_LABEL "LSFDE"
311 #define FDE_AFTER_SIZE_LABEL "LASFDE"
312 #define FDE_END_LABEL "LEFDE"
313 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
314 #define LINE_NUMBER_END_LABEL "LELT"
315 #define LN_PROLOG_AS_LABEL "LASLTP"
316 #define LN_PROLOG_END_LABEL "LELTP"
317 #define DIE_LABEL_PREFIX "DW"
319 /* Match the base name of a file to the base name of a compilation unit. */
322 matches_main_base (const char *path
)
324 /* Cache the last query. */
325 static const char *last_path
= NULL
;
326 static int last_match
= 0;
327 if (path
!= last_path
)
330 int length
= base_of_path (path
, &base
);
332 last_match
= (length
== main_input_baselength
333 && memcmp (base
, main_input_basename
, length
) == 0);
338 #ifdef DEBUG_DEBUG_STRUCT
341 dump_struct_debug (tree type
, enum debug_info_usage usage
,
342 enum debug_struct_file criterion
, int generic
,
343 int matches
, int result
)
345 /* Find the type name. */
346 tree type_decl
= TYPE_STUB_DECL (type
);
348 const char *name
= 0;
349 if (TREE_CODE (t
) == TYPE_DECL
)
352 name
= IDENTIFIER_POINTER (t
);
354 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
356 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
357 matches
? "bas" : "hdr",
358 generic
? "gen" : "ord",
359 usage
== DINFO_USAGE_DFN
? ";" :
360 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
362 (void*) type_decl
, name
);
365 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
366 dump_struct_debug (type, usage, criterion, generic, matches, result)
370 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
375 /* Get the number of HOST_WIDE_INTs needed to represent the precision
379 get_full_len (const wide_int
&op
)
381 return ((op
.get_precision () + HOST_BITS_PER_WIDE_INT
- 1)
382 / HOST_BITS_PER_WIDE_INT
);
386 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
388 enum debug_struct_file criterion
;
390 bool generic
= lang_hooks
.types
.generic_p (type
);
393 criterion
= debug_struct_generic
[usage
];
395 criterion
= debug_struct_ordinary
[usage
];
397 if (criterion
== DINFO_STRUCT_FILE_NONE
)
398 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
399 if (criterion
== DINFO_STRUCT_FILE_ANY
)
400 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
402 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
404 if (type_decl
!= NULL
)
406 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
407 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
409 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
410 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
413 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
416 /* Return a pointer to a copy of the section string name S with all
417 attributes stripped off, and an asterisk prepended (for assemble_name). */
420 stripattributes (const char *s
)
422 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
427 while (*s
&& *s
!= ',')
434 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
435 switch to the data section instead, and write out a synthetic start label
436 for collect2 the first time around. */
439 switch_to_eh_frame_section (bool back
)
443 #ifdef EH_FRAME_SECTION_NAME
444 if (eh_frame_section
== 0)
448 if (EH_TABLES_CAN_BE_READ_ONLY
)
454 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
456 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
458 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
461 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
462 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
463 && (per_encoding
& 0x70) != DW_EH_PE_absptr
464 && (per_encoding
& 0x70) != DW_EH_PE_aligned
465 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
466 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
467 ? 0 : SECTION_WRITE
);
470 flags
= SECTION_WRITE
;
471 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
473 #endif /* EH_FRAME_SECTION_NAME */
475 if (eh_frame_section
)
476 switch_to_section (eh_frame_section
);
479 /* We have no special eh_frame section. Put the information in
480 the data section and emit special labels to guide collect2. */
481 switch_to_section (data_section
);
485 label
= get_file_function_name ("F");
486 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
487 targetm
.asm_out
.globalize_label (asm_out_file
,
488 IDENTIFIER_POINTER (label
));
489 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
494 /* Switch [BACK] to the eh or debug frame table section, depending on
498 switch_to_frame_table_section (int for_eh
, bool back
)
501 switch_to_eh_frame_section (back
);
504 if (!debug_frame_section
)
505 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
506 SECTION_DEBUG
, NULL
);
507 switch_to_section (debug_frame_section
);
511 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
513 enum dw_cfi_oprnd_type
514 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
519 case DW_CFA_GNU_window_save
:
520 case DW_CFA_remember_state
:
521 case DW_CFA_restore_state
:
522 return dw_cfi_oprnd_unused
;
525 case DW_CFA_advance_loc1
:
526 case DW_CFA_advance_loc2
:
527 case DW_CFA_advance_loc4
:
528 case DW_CFA_MIPS_advance_loc8
:
529 return dw_cfi_oprnd_addr
;
532 case DW_CFA_offset_extended
:
534 case DW_CFA_offset_extended_sf
:
535 case DW_CFA_def_cfa_sf
:
537 case DW_CFA_restore_extended
:
538 case DW_CFA_undefined
:
539 case DW_CFA_same_value
:
540 case DW_CFA_def_cfa_register
:
541 case DW_CFA_register
:
542 case DW_CFA_expression
:
543 return dw_cfi_oprnd_reg_num
;
545 case DW_CFA_def_cfa_offset
:
546 case DW_CFA_GNU_args_size
:
547 case DW_CFA_def_cfa_offset_sf
:
548 return dw_cfi_oprnd_offset
;
550 case DW_CFA_def_cfa_expression
:
551 return dw_cfi_oprnd_loc
;
558 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
560 enum dw_cfi_oprnd_type
561 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
566 case DW_CFA_def_cfa_sf
:
568 case DW_CFA_offset_extended_sf
:
569 case DW_CFA_offset_extended
:
570 return dw_cfi_oprnd_offset
;
572 case DW_CFA_register
:
573 return dw_cfi_oprnd_reg_num
;
575 case DW_CFA_expression
:
576 return dw_cfi_oprnd_loc
;
579 return dw_cfi_oprnd_unused
;
583 /* Output one FDE. */
586 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
587 char *section_start_label
, int fde_encoding
, char *augmentation
,
588 bool any_lsda_needed
, int lsda_encoding
)
590 const char *begin
, *end
;
591 static unsigned int j
;
594 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
596 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
598 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
599 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
600 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
601 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
602 " indicating 64-bit DWARF extension");
603 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
605 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
608 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
610 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
611 debug_frame_section
, "FDE CIE offset");
613 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
614 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
618 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
619 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
620 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
621 "FDE initial location");
622 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
623 end
, begin
, "FDE address range");
627 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
628 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
635 int size
= size_of_encoded_value (lsda_encoding
);
637 if (lsda_encoding
== DW_EH_PE_aligned
)
639 int offset
= ( 4 /* Length */
641 + 2 * size_of_encoded_value (fde_encoding
)
642 + 1 /* Augmentation size */ );
643 int pad
= -offset
& (PTR_SIZE
- 1);
646 gcc_assert (size_of_uleb128 (size
) == 1);
649 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
651 if (fde
->uses_eh_lsda
)
653 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
654 fde
->funcdef_number
);
655 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
656 gen_rtx_SYMBOL_REF (Pmode
, l1
),
658 "Language Specific Data Area");
662 if (lsda_encoding
== DW_EH_PE_aligned
)
663 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
664 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
665 "Language Specific Data Area (none)");
669 dw2_asm_output_data_uleb128 (0, "Augmentation size");
672 /* Loop through the Call Frame Instructions associated with this FDE. */
673 fde
->dw_fde_current_label
= begin
;
675 size_t from
, until
, i
;
678 until
= vec_safe_length (fde
->dw_fde_cfi
);
680 if (fde
->dw_fde_second_begin
== NULL
)
683 until
= fde
->dw_fde_switch_cfi_index
;
685 from
= fde
->dw_fde_switch_cfi_index
;
687 for (i
= from
; i
< until
; i
++)
688 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
691 /* If we are to emit a ref/link from function bodies to their frame tables,
692 do it now. This is typically performed to make sure that tables
693 associated with functions are dragged with them and not discarded in
694 garbage collecting links. We need to do this on a per function basis to
695 cope with -ffunction-sections. */
697 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
698 /* Switch to the function section, emit the ref to the tables, and
699 switch *back* into the table section. */
700 switch_to_section (function_section (fde
->decl
));
701 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
702 switch_to_frame_table_section (for_eh
, true);
705 /* Pad the FDE out to an address sized boundary. */
706 ASM_OUTPUT_ALIGN (asm_out_file
,
707 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
708 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
713 /* Return true if frame description entry FDE is needed for EH. */
716 fde_needed_for_eh_p (dw_fde_ref fde
)
718 if (flag_asynchronous_unwind_tables
)
721 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
724 if (fde
->uses_eh_lsda
)
727 /* If exceptions are enabled, we have collected nothrow info. */
728 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
734 /* Output the call frame information used to record information
735 that relates to calculating the frame pointer, and records the
736 location of saved registers. */
739 output_call_frame_info (int for_eh
)
744 char l1
[20], l2
[20], section_start_label
[20];
745 bool any_lsda_needed
= false;
746 char augmentation
[6];
747 int augmentation_size
;
748 int fde_encoding
= DW_EH_PE_absptr
;
749 int per_encoding
= DW_EH_PE_absptr
;
750 int lsda_encoding
= DW_EH_PE_absptr
;
752 rtx personality
= NULL
;
755 /* Don't emit a CIE if there won't be any FDEs. */
759 /* Nothing to do if the assembler's doing it all. */
760 if (dwarf2out_do_cfi_asm ())
763 /* If we don't have any functions we'll want to unwind out of, don't emit
764 any EH unwind information. If we make FDEs linkonce, we may have to
765 emit an empty label for an FDE that wouldn't otherwise be emitted. We
766 want to avoid having an FDE kept around when the function it refers to
767 is discarded. Example where this matters: a primary function template
768 in C++ requires EH information, an explicit specialization doesn't. */
771 bool any_eh_needed
= false;
773 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
775 if (fde
->uses_eh_lsda
)
776 any_eh_needed
= any_lsda_needed
= true;
777 else if (fde_needed_for_eh_p (fde
))
778 any_eh_needed
= true;
779 else if (TARGET_USES_WEAK_UNWIND_INFO
)
780 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
787 /* We're going to be generating comments, so turn on app. */
791 /* Switch to the proper frame section, first time. */
792 switch_to_frame_table_section (for_eh
, false);
794 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
795 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
797 /* Output the CIE. */
798 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
799 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
800 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
801 dw2_asm_output_data (4, 0xffffffff,
802 "Initial length escape value indicating 64-bit DWARF extension");
803 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
804 "Length of Common Information Entry");
805 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
807 /* Now that the CIE pointer is PC-relative for EH,
808 use 0 to identify the CIE. */
809 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
810 (for_eh
? 0 : DWARF_CIE_ID
),
811 "CIE Identifier Tag");
813 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
814 use CIE version 1, unless that would produce incorrect results
815 due to overflowing the return register column. */
816 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
818 if (return_reg
>= 256 || dwarf_version
> 2)
820 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
823 augmentation_size
= 0;
825 personality
= current_unit_personality
;
831 z Indicates that a uleb128 is present to size the
832 augmentation section.
833 L Indicates the encoding (and thus presence) of
834 an LSDA pointer in the FDE augmentation.
835 R Indicates a non-default pointer encoding for
837 P Indicates the presence of an encoding + language
838 personality routine in the CIE augmentation. */
840 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
841 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
842 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
844 p
= augmentation
+ 1;
848 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
849 assemble_external_libcall (personality
);
854 augmentation_size
+= 1;
856 if (fde_encoding
!= DW_EH_PE_absptr
)
859 augmentation_size
+= 1;
861 if (p
> augmentation
+ 1)
863 augmentation
[0] = 'z';
867 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
868 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
870 int offset
= ( 4 /* Length */
872 + 1 /* CIE version */
873 + strlen (augmentation
) + 1 /* Augmentation */
874 + size_of_uleb128 (1) /* Code alignment */
875 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
877 + 1 /* Augmentation size */
878 + 1 /* Personality encoding */ );
879 int pad
= -offset
& (PTR_SIZE
- 1);
881 augmentation_size
+= pad
;
883 /* Augmentations should be small, so there's scarce need to
884 iterate for a solution. Die if we exceed one uleb128 byte. */
885 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
889 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
890 if (dw_cie_version
>= 4)
892 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
893 dw2_asm_output_data (1, 0, "CIE Segment Size");
895 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
896 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
897 "CIE Data Alignment Factor");
899 if (dw_cie_version
== 1)
900 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
902 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
906 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
909 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
910 eh_data_format_name (per_encoding
));
911 dw2_asm_output_encoded_addr_rtx (per_encoding
,
917 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
918 eh_data_format_name (lsda_encoding
));
920 if (fde_encoding
!= DW_EH_PE_absptr
)
921 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
922 eh_data_format_name (fde_encoding
));
925 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
926 output_cfi (cfi
, NULL
, for_eh
);
928 /* Pad the CIE out to an address sized boundary. */
929 ASM_OUTPUT_ALIGN (asm_out_file
,
930 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
931 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
933 /* Loop through all of the FDE's. */
934 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
938 /* Don't emit EH unwind info for leaf functions that don't need it. */
939 if (for_eh
&& !fde_needed_for_eh_p (fde
))
942 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
943 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
944 augmentation
, any_lsda_needed
, lsda_encoding
);
947 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
948 dw2_asm_output_data (4, 0, "End of Table");
950 /* Turn off app to make assembly quicker. */
955 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
958 dwarf2out_do_cfi_startproc (bool second
)
962 rtx personality
= get_personality_function (current_function_decl
);
964 fprintf (asm_out_file
, "\t.cfi_startproc\n");
968 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
971 /* ??? The GAS support isn't entirely consistent. We have to
972 handle indirect support ourselves, but PC-relative is done
973 in the assembler. Further, the assembler can't handle any
974 of the weirder relocation types. */
975 if (enc
& DW_EH_PE_indirect
)
976 ref
= dw2_force_const_mem (ref
, true);
978 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
979 output_addr_const (asm_out_file
, ref
);
980 fputc ('\n', asm_out_file
);
983 if (crtl
->uses_eh_lsda
)
987 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
988 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
989 current_function_funcdef_no
);
990 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
991 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
993 if (enc
& DW_EH_PE_indirect
)
994 ref
= dw2_force_const_mem (ref
, true);
996 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
997 output_addr_const (asm_out_file
, ref
);
998 fputc ('\n', asm_out_file
);
1002 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1003 this allocation may be done before pass_final. */
1006 dwarf2out_alloc_current_fde (void)
1010 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1011 fde
->decl
= current_function_decl
;
1012 fde
->funcdef_number
= current_function_funcdef_no
;
1013 fde
->fde_index
= vec_safe_length (fde_vec
);
1014 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1015 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1016 fde
->nothrow
= crtl
->nothrow
;
1017 fde
->drap_reg
= INVALID_REGNUM
;
1018 fde
->vdrap_reg
= INVALID_REGNUM
;
1020 /* Record the FDE associated with this function. */
1022 vec_safe_push (fde_vec
, fde
);
1027 /* Output a marker (i.e. a label) for the beginning of a function, before
1031 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1032 const char *file ATTRIBUTE_UNUSED
)
1034 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1040 current_function_func_begin_label
= NULL
;
1042 do_frame
= dwarf2out_do_frame ();
1044 /* ??? current_function_func_begin_label is also used by except.c for
1045 call-site information. We must emit this label if it might be used. */
1047 && (!flag_exceptions
1048 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1051 fnsec
= function_section (current_function_decl
);
1052 switch_to_section (fnsec
);
1053 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1054 current_function_funcdef_no
);
1055 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1056 current_function_funcdef_no
);
1057 dup_label
= xstrdup (label
);
1058 current_function_func_begin_label
= dup_label
;
1060 /* We can elide the fde allocation if we're not emitting debug info. */
1064 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1065 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1066 would include pass_dwarf2_frame. If we've not created the FDE yet,
1070 fde
= dwarf2out_alloc_current_fde ();
1072 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1073 fde
->dw_fde_begin
= dup_label
;
1074 fde
->dw_fde_current_label
= dup_label
;
1075 fde
->in_std_section
= (fnsec
== text_section
1076 || (cold_text_section
&& fnsec
== cold_text_section
));
1078 /* We only want to output line number information for the genuine dwarf2
1079 prologue case, not the eh frame case. */
1080 #ifdef DWARF2_DEBUGGING_INFO
1082 dwarf2out_source_line (line
, file
, 0, true);
1085 if (dwarf2out_do_cfi_asm ())
1086 dwarf2out_do_cfi_startproc (false);
1089 rtx personality
= get_personality_function (current_function_decl
);
1090 if (!current_unit_personality
)
1091 current_unit_personality
= personality
;
1093 /* We cannot keep a current personality per function as without CFI
1094 asm, at the point where we emit the CFI data, there is no current
1095 function anymore. */
1096 if (personality
&& current_unit_personality
!= personality
)
1097 sorry ("multiple EH personalities are supported only with assemblers "
1098 "supporting .cfi_personality directive");
1102 /* Output a marker (i.e. a label) for the end of the generated code
1103 for a function prologue. This gets called *after* the prologue code has
1107 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1108 const char *file ATTRIBUTE_UNUSED
)
1110 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1112 /* Output a label to mark the endpoint of the code generated for this
1114 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1115 current_function_funcdef_no
);
1116 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1117 current_function_funcdef_no
);
1118 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1121 /* Output a marker (i.e. a label) for the beginning of the generated code
1122 for a function epilogue. This gets called *before* the prologue code has
1126 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1127 const char *file ATTRIBUTE_UNUSED
)
1129 dw_fde_ref fde
= cfun
->fde
;
1130 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1132 if (fde
->dw_fde_vms_begin_epilogue
)
1135 /* Output a label to mark the endpoint of the code generated for this
1137 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1138 current_function_funcdef_no
);
1139 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1140 current_function_funcdef_no
);
1141 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1144 /* Output a marker (i.e. a label) for the absolute end of the generated code
1145 for a function definition. This gets called *after* the epilogue code has
1149 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1150 const char *file ATTRIBUTE_UNUSED
)
1153 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1155 last_var_location_insn
= NULL
;
1156 cached_next_real_insn
= NULL
;
1158 if (dwarf2out_do_cfi_asm ())
1159 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1161 /* Output a label to mark the endpoint of the code generated for this
1163 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1164 current_function_funcdef_no
);
1165 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1167 gcc_assert (fde
!= NULL
);
1168 if (fde
->dw_fde_second_begin
== NULL
)
1169 fde
->dw_fde_end
= xstrdup (label
);
1173 dwarf2out_frame_finish (void)
1175 /* Output call frame information. */
1176 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1177 output_call_frame_info (0);
1179 /* Output another copy for the unwinder. */
1180 if ((flag_unwind_tables
|| flag_exceptions
)
1181 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1182 output_call_frame_info (1);
1185 /* Note that the current function section is being used for code. */
1188 dwarf2out_note_section_used (void)
1190 section
*sec
= current_function_section ();
1191 if (sec
== text_section
)
1192 text_section_used
= true;
1193 else if (sec
== cold_text_section
)
1194 cold_text_section_used
= true;
1197 static void var_location_switch_text_section (void);
1198 static void set_cur_line_info_table (section
*);
1201 dwarf2out_switch_text_section (void)
1204 dw_fde_ref fde
= cfun
->fde
;
1206 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1208 if (!in_cold_section_p
)
1210 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1211 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1212 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1216 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1217 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1218 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1220 have_multiple_function_sections
= true;
1222 /* There is no need to mark used sections when not debugging. */
1223 if (cold_text_section
!= NULL
)
1224 dwarf2out_note_section_used ();
1226 if (dwarf2out_do_cfi_asm ())
1227 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1229 /* Now do the real section switch. */
1230 sect
= current_function_section ();
1231 switch_to_section (sect
);
1233 fde
->second_in_std_section
1234 = (sect
== text_section
1235 || (cold_text_section
&& sect
== cold_text_section
));
1237 if (dwarf2out_do_cfi_asm ())
1238 dwarf2out_do_cfi_startproc (true);
1240 var_location_switch_text_section ();
1242 if (cold_text_section
!= NULL
)
1243 set_cur_line_info_table (sect
);
1246 /* And now, the subset of the debugging information support code necessary
1247 for emitting location expressions. */
1249 /* Data about a single source file. */
1250 struct GTY((for_user
)) dwarf_file_data
{
1251 const char * filename
;
1255 /* Describe an entry into the .debug_addr section. */
1259 ate_kind_rtx_dtprel
,
1263 typedef struct GTY((for_user
)) addr_table_entry_struct
{
1265 unsigned int refcount
;
1267 union addr_table_entry_struct_union
1269 rtx
GTY ((tag ("0"))) rtl
;
1270 char * GTY ((tag ("1"))) label
;
1272 GTY ((desc ("%1.kind"))) addr
;
1276 /* Location lists are ranges + location descriptions for that range,
1277 so you can track variables that are in different places over
1278 their entire life. */
1279 typedef struct GTY(()) dw_loc_list_struct
{
1280 dw_loc_list_ref dw_loc_next
;
1281 const char *begin
; /* Label and addr_entry for start of range */
1282 addr_table_entry
*begin_entry
;
1283 const char *end
; /* Label for end of range */
1284 char *ll_symbol
; /* Label for beginning of location list.
1285 Only on head of list */
1286 const char *section
; /* Section this loclist is relative to */
1287 dw_loc_descr_ref expr
;
1289 /* True if all addresses in this and subsequent lists are known to be
1292 /* True if this list has been replaced by dw_loc_next. */
1295 /* True if the range should be emitted even if begin and end
1300 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1302 /* Convert a DWARF stack opcode into its string name. */
1305 dwarf_stack_op_name (unsigned int op
)
1307 const char *name
= get_DW_OP_name (op
);
1312 return "OP_<unknown>";
1315 /* Return a pointer to a newly allocated location description. Location
1316 descriptions are simple expression terms that can be strung
1317 together to form more complicated location (address) descriptions. */
1319 static inline dw_loc_descr_ref
1320 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1321 unsigned HOST_WIDE_INT oprnd2
)
1323 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1325 descr
->dw_loc_opc
= op
;
1326 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1327 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1328 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1329 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1330 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1331 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1336 /* Return a pointer to a newly allocated location description for
1339 static inline dw_loc_descr_ref
1340 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1343 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1346 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1349 /* Add a location description term to a location description expression. */
1352 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1354 dw_loc_descr_ref
*d
;
1356 /* Find the end of the chain. */
1357 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1363 /* Compare two location operands for exact equality. */
1366 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1368 if (a
->val_class
!= b
->val_class
)
1370 switch (a
->val_class
)
1372 case dw_val_class_none
:
1374 case dw_val_class_addr
:
1375 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1377 case dw_val_class_offset
:
1378 case dw_val_class_unsigned_const
:
1379 case dw_val_class_const
:
1380 case dw_val_class_range_list
:
1381 case dw_val_class_lineptr
:
1382 case dw_val_class_macptr
:
1383 /* These are all HOST_WIDE_INT, signed or unsigned. */
1384 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1386 case dw_val_class_loc
:
1387 return a
->v
.val_loc
== b
->v
.val_loc
;
1388 case dw_val_class_loc_list
:
1389 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1390 case dw_val_class_die_ref
:
1391 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1392 case dw_val_class_fde_ref
:
1393 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1394 case dw_val_class_lbl_id
:
1395 case dw_val_class_high_pc
:
1396 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1397 case dw_val_class_str
:
1398 return a
->v
.val_str
== b
->v
.val_str
;
1399 case dw_val_class_flag
:
1400 return a
->v
.val_flag
== b
->v
.val_flag
;
1401 case dw_val_class_file
:
1402 return a
->v
.val_file
== b
->v
.val_file
;
1403 case dw_val_class_decl_ref
:
1404 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1406 case dw_val_class_const_double
:
1407 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1408 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1410 case dw_val_class_wide_int
:
1411 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1413 case dw_val_class_vec
:
1415 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1416 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1418 return (a_len
== b_len
1419 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1422 case dw_val_class_data8
:
1423 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1425 case dw_val_class_vms_delta
:
1426 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1427 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1432 /* Compare two location atoms for exact equality. */
1435 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1437 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1440 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1441 address size, but since we always allocate cleared storage it
1442 should be zero for other types of locations. */
1443 if (a
->dtprel
!= b
->dtprel
)
1446 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1447 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1450 /* Compare two complete location expressions for exact equality. */
1453 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1459 if (a
== NULL
|| b
== NULL
)
1461 if (!loc_descr_equal_p_1 (a
, b
))
1470 /* Add a constant OFFSET to a location expression. */
1473 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1475 dw_loc_descr_ref loc
;
1478 gcc_assert (*list_head
!= NULL
);
1483 /* Find the end of the chain. */
1484 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1488 if (loc
->dw_loc_opc
== DW_OP_fbreg
1489 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1490 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1491 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1492 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1494 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1495 offset. Don't optimize if an signed integer overflow would happen. */
1497 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1498 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1501 else if (offset
> 0)
1502 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1506 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1507 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1511 /* Add a constant OFFSET to a location list. */
1514 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1517 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1518 loc_descr_plus_const (&d
->expr
, offset
);
1521 #define DWARF_REF_SIZE \
1522 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1524 static unsigned long int get_base_type_offset (dw_die_ref
);
1526 /* Return the size of a location descriptor. */
1528 static unsigned long
1529 size_of_loc_descr (dw_loc_descr_ref loc
)
1531 unsigned long size
= 1;
1533 switch (loc
->dw_loc_opc
)
1536 size
+= DWARF2_ADDR_SIZE
;
1538 case DW_OP_GNU_addr_index
:
1539 case DW_OP_GNU_const_index
:
1540 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1541 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1560 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1563 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1568 case DW_OP_plus_uconst
:
1569 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1607 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1610 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1613 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1616 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1617 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1620 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1622 case DW_OP_bit_piece
:
1623 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1624 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1626 case DW_OP_deref_size
:
1627 case DW_OP_xderef_size
:
1636 case DW_OP_call_ref
:
1637 size
+= DWARF_REF_SIZE
;
1639 case DW_OP_implicit_value
:
1640 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1641 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1643 case DW_OP_GNU_implicit_pointer
:
1644 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1646 case DW_OP_GNU_entry_value
:
1648 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1649 size
+= size_of_uleb128 (op_size
) + op_size
;
1652 case DW_OP_GNU_const_type
:
1655 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1656 size
+= size_of_uleb128 (o
) + 1;
1657 switch (loc
->dw_loc_oprnd2
.val_class
)
1659 case dw_val_class_vec
:
1660 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1661 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1663 case dw_val_class_const
:
1664 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1666 case dw_val_class_const_double
:
1667 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1669 case dw_val_class_wide_int
:
1670 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1671 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1678 case DW_OP_GNU_regval_type
:
1681 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1682 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1683 + size_of_uleb128 (o
);
1686 case DW_OP_GNU_deref_type
:
1689 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1690 size
+= 1 + size_of_uleb128 (o
);
1693 case DW_OP_GNU_convert
:
1694 case DW_OP_GNU_reinterpret
:
1695 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1696 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1700 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1701 size
+= size_of_uleb128 (o
);
1704 case DW_OP_GNU_parameter_ref
:
1714 /* Return the size of a series of location descriptors. */
1717 size_of_locs (dw_loc_descr_ref loc
)
1722 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1723 field, to avoid writing to a PCH file. */
1724 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1726 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1728 size
+= size_of_loc_descr (l
);
1733 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1735 l
->dw_loc_addr
= size
;
1736 size
+= size_of_loc_descr (l
);
1742 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1743 static void get_ref_die_offset_label (char *, dw_die_ref
);
1744 static unsigned long int get_ref_die_offset (dw_die_ref
);
1746 /* Output location description stack opcode's operands (if any).
1747 The for_eh_or_skip parameter controls whether register numbers are
1748 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1749 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1750 info). This should be suppressed for the cases that have not been converted
1751 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1754 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1756 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1757 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1759 switch (loc
->dw_loc_opc
)
1761 #ifdef DWARF2_DEBUGGING_INFO
1764 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1769 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1770 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1772 fputc ('\n', asm_out_file
);
1777 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1782 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1783 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1785 fputc ('\n', asm_out_file
);
1790 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1791 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1798 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1799 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1801 dw2_asm_output_data (2, offset
, NULL
);
1804 case DW_OP_implicit_value
:
1805 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1806 switch (val2
->val_class
)
1808 case dw_val_class_const
:
1809 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1811 case dw_val_class_vec
:
1813 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1814 unsigned int len
= val2
->v
.val_vec
.length
;
1818 if (elt_size
> sizeof (HOST_WIDE_INT
))
1823 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1826 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1827 "fp or vector constant word %u", i
);
1830 case dw_val_class_const_double
:
1832 unsigned HOST_WIDE_INT first
, second
;
1834 if (WORDS_BIG_ENDIAN
)
1836 first
= val2
->v
.val_double
.high
;
1837 second
= val2
->v
.val_double
.low
;
1841 first
= val2
->v
.val_double
.low
;
1842 second
= val2
->v
.val_double
.high
;
1844 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1846 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1850 case dw_val_class_wide_int
:
1853 int len
= get_full_len (*val2
->v
.val_wide
);
1854 if (WORDS_BIG_ENDIAN
)
1855 for (i
= len
- 1; i
>= 0; --i
)
1856 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1857 val2
->v
.val_wide
->elt (i
), NULL
);
1859 for (i
= 0; i
< len
; ++i
)
1860 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1861 val2
->v
.val_wide
->elt (i
), NULL
);
1864 case dw_val_class_addr
:
1865 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1866 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1881 case DW_OP_implicit_value
:
1882 /* We currently don't make any attempt to make sure these are
1883 aligned properly like we do for the main unwind info, so
1884 don't support emitting things larger than a byte if we're
1885 only doing unwinding. */
1890 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1893 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1896 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1899 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1901 case DW_OP_plus_uconst
:
1902 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1936 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1940 unsigned r
= val1
->v
.val_unsigned
;
1941 if (for_eh_or_skip
>= 0)
1942 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1943 gcc_assert (size_of_uleb128 (r
)
1944 == size_of_uleb128 (val1
->v
.val_unsigned
));
1945 dw2_asm_output_data_uleb128 (r
, NULL
);
1949 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1953 unsigned r
= val1
->v
.val_unsigned
;
1954 if (for_eh_or_skip
>= 0)
1955 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1956 gcc_assert (size_of_uleb128 (r
)
1957 == size_of_uleb128 (val1
->v
.val_unsigned
));
1958 dw2_asm_output_data_uleb128 (r
, NULL
);
1959 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1963 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1965 case DW_OP_bit_piece
:
1966 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1967 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1969 case DW_OP_deref_size
:
1970 case DW_OP_xderef_size
:
1971 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1977 if (targetm
.asm_out
.output_dwarf_dtprel
)
1979 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1982 fputc ('\n', asm_out_file
);
1989 #ifdef DWARF2_DEBUGGING_INFO
1990 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1997 case DW_OP_GNU_addr_index
:
1998 case DW_OP_GNU_const_index
:
1999 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
2000 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
2001 "(index into .debug_addr)");
2004 case DW_OP_GNU_implicit_pointer
:
2006 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2007 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2008 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2009 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2010 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2011 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2015 case DW_OP_GNU_entry_value
:
2016 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2017 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2020 case DW_OP_GNU_const_type
:
2022 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2024 dw2_asm_output_data_uleb128 (o
, NULL
);
2025 switch (val2
->val_class
)
2027 case dw_val_class_const
:
2028 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2029 dw2_asm_output_data (1, l
, NULL
);
2030 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2032 case dw_val_class_vec
:
2034 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2035 unsigned int len
= val2
->v
.val_vec
.length
;
2040 dw2_asm_output_data (1, l
, NULL
);
2041 if (elt_size
> sizeof (HOST_WIDE_INT
))
2046 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2049 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2050 "fp or vector constant word %u", i
);
2053 case dw_val_class_const_double
:
2055 unsigned HOST_WIDE_INT first
, second
;
2056 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2058 dw2_asm_output_data (1, 2 * l
, NULL
);
2059 if (WORDS_BIG_ENDIAN
)
2061 first
= val2
->v
.val_double
.high
;
2062 second
= val2
->v
.val_double
.low
;
2066 first
= val2
->v
.val_double
.low
;
2067 second
= val2
->v
.val_double
.high
;
2069 dw2_asm_output_data (l
, first
, NULL
);
2070 dw2_asm_output_data (l
, second
, NULL
);
2073 case dw_val_class_wide_int
:
2076 int len
= get_full_len (*val2
->v
.val_wide
);
2077 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2079 dw2_asm_output_data (1, len
* l
, NULL
);
2080 if (WORDS_BIG_ENDIAN
)
2081 for (i
= len
- 1; i
>= 0; --i
)
2082 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2084 for (i
= 0; i
< len
; ++i
)
2085 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2093 case DW_OP_GNU_regval_type
:
2095 unsigned r
= val1
->v
.val_unsigned
;
2096 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2098 if (for_eh_or_skip
>= 0)
2100 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2101 gcc_assert (size_of_uleb128 (r
)
2102 == size_of_uleb128 (val1
->v
.val_unsigned
));
2104 dw2_asm_output_data_uleb128 (r
, NULL
);
2105 dw2_asm_output_data_uleb128 (o
, NULL
);
2108 case DW_OP_GNU_deref_type
:
2110 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2112 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2113 dw2_asm_output_data_uleb128 (o
, NULL
);
2116 case DW_OP_GNU_convert
:
2117 case DW_OP_GNU_reinterpret
:
2118 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2119 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2122 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2124 dw2_asm_output_data_uleb128 (o
, NULL
);
2128 case DW_OP_GNU_parameter_ref
:
2131 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2132 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2133 dw2_asm_output_data (4, o
, NULL
);
2138 /* Other codes have no operands. */
2143 /* Output a sequence of location operations.
2144 The for_eh_or_skip parameter controls whether register numbers are
2145 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2146 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2147 info). This should be suppressed for the cases that have not been converted
2148 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2151 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2153 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2155 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2156 /* Output the opcode. */
2157 if (for_eh_or_skip
>= 0
2158 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2160 unsigned r
= (opc
- DW_OP_breg0
);
2161 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2162 gcc_assert (r
<= 31);
2163 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2165 else if (for_eh_or_skip
>= 0
2166 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2168 unsigned r
= (opc
- DW_OP_reg0
);
2169 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2170 gcc_assert (r
<= 31);
2171 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2174 dw2_asm_output_data (1, opc
,
2175 "%s", dwarf_stack_op_name (opc
));
2177 /* Output the operand(s) (if any). */
2178 output_loc_operands (loc
, for_eh_or_skip
);
2182 /* Output location description stack opcode's operands (if any).
2183 The output is single bytes on a line, suitable for .cfi_escape. */
2186 output_loc_operands_raw (dw_loc_descr_ref loc
)
2188 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2189 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2191 switch (loc
->dw_loc_opc
)
2194 case DW_OP_GNU_addr_index
:
2195 case DW_OP_GNU_const_index
:
2196 case DW_OP_implicit_value
:
2197 /* We cannot output addresses in .cfi_escape, only bytes. */
2203 case DW_OP_deref_size
:
2204 case DW_OP_xderef_size
:
2205 fputc (',', asm_out_file
);
2206 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2211 fputc (',', asm_out_file
);
2212 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2217 fputc (',', asm_out_file
);
2218 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2223 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2224 fputc (',', asm_out_file
);
2225 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2233 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2234 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2236 fputc (',', asm_out_file
);
2237 dw2_asm_output_data_raw (2, offset
);
2243 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2244 gcc_assert (size_of_uleb128 (r
)
2245 == size_of_uleb128 (val1
->v
.val_unsigned
));
2246 fputc (',', asm_out_file
);
2247 dw2_asm_output_data_uleb128_raw (r
);
2252 case DW_OP_plus_uconst
:
2254 fputc (',', asm_out_file
);
2255 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2258 case DW_OP_bit_piece
:
2259 fputc (',', asm_out_file
);
2260 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2261 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2298 fputc (',', asm_out_file
);
2299 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
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
);
2309 fputc (',', asm_out_file
);
2310 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2314 case DW_OP_GNU_implicit_pointer
:
2315 case DW_OP_GNU_entry_value
:
2316 case DW_OP_GNU_const_type
:
2317 case DW_OP_GNU_regval_type
:
2318 case DW_OP_GNU_deref_type
:
2319 case DW_OP_GNU_convert
:
2320 case DW_OP_GNU_reinterpret
:
2321 case DW_OP_GNU_parameter_ref
:
2326 /* Other codes have no operands. */
2332 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2336 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2337 /* Output the opcode. */
2338 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2340 unsigned r
= (opc
- DW_OP_breg0
);
2341 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2342 gcc_assert (r
<= 31);
2343 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2345 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2347 unsigned r
= (opc
- DW_OP_reg0
);
2348 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2349 gcc_assert (r
<= 31);
2350 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2352 /* Output the opcode. */
2353 fprintf (asm_out_file
, "%#x", opc
);
2354 output_loc_operands_raw (loc
);
2356 if (!loc
->dw_loc_next
)
2358 loc
= loc
->dw_loc_next
;
2360 fputc (',', asm_out_file
);
2364 /* This function builds a dwarf location descriptor sequence from a
2365 dw_cfa_location, adding the given OFFSET to the result of the
2368 struct dw_loc_descr_node
*
2369 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2371 struct dw_loc_descr_node
*head
, *tmp
;
2373 offset
+= cfa
->offset
;
2377 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2378 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2379 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2380 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2381 add_loc_descr (&head
, tmp
);
2384 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2385 add_loc_descr (&head
, tmp
);
2389 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2394 /* This function builds a dwarf location descriptor sequence for
2395 the address at OFFSET from the CFA when stack is aligned to
2398 struct dw_loc_descr_node
*
2399 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2400 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2402 struct dw_loc_descr_node
*head
;
2403 unsigned int dwarf_fp
2404 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2406 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2407 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2409 head
= new_reg_loc_descr (dwarf_fp
, 0);
2410 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2411 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2412 loc_descr_plus_const (&head
, offset
);
2415 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2419 /* And now, the support for symbolic debugging information. */
2421 /* .debug_str support. */
2423 static void dwarf2out_init (const char *);
2424 static void dwarf2out_finish (const char *);
2425 static void dwarf2out_early_finish (void);
2426 static void dwarf2out_assembly_start (void);
2427 static void dwarf2out_define (unsigned int, const char *);
2428 static void dwarf2out_undef (unsigned int, const char *);
2429 static void dwarf2out_start_source_file (unsigned, const char *);
2430 static void dwarf2out_end_source_file (unsigned);
2431 static void dwarf2out_function_decl (tree
);
2432 static void dwarf2out_begin_block (unsigned, unsigned);
2433 static void dwarf2out_end_block (unsigned, unsigned);
2434 static bool dwarf2out_ignore_block (const_tree
);
2435 static void dwarf2out_early_global_decl (tree
);
2436 static void dwarf2out_late_global_decl (tree
);
2437 static void dwarf2out_type_decl (tree
, int);
2438 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2439 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2441 static void dwarf2out_abstract_function (tree
);
2442 static void dwarf2out_var_location (rtx_insn
*);
2443 static void dwarf2out_begin_function (tree
);
2444 static void dwarf2out_end_function (unsigned int);
2445 static void dwarf2out_register_main_translation_unit (tree unit
);
2446 static void dwarf2out_set_name (tree
, tree
);
2448 /* The debug hooks structure. */
2450 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2454 dwarf2out_early_finish
,
2455 dwarf2out_assembly_start
,
2458 dwarf2out_start_source_file
,
2459 dwarf2out_end_source_file
,
2460 dwarf2out_begin_block
,
2461 dwarf2out_end_block
,
2462 dwarf2out_ignore_block
,
2463 dwarf2out_source_line
,
2464 dwarf2out_begin_prologue
,
2465 #if VMS_DEBUGGING_INFO
2466 dwarf2out_vms_end_prologue
,
2467 dwarf2out_vms_begin_epilogue
,
2469 debug_nothing_int_charstar
,
2470 debug_nothing_int_charstar
,
2472 dwarf2out_end_epilogue
,
2473 dwarf2out_begin_function
,
2474 dwarf2out_end_function
, /* end_function */
2475 dwarf2out_register_main_translation_unit
,
2476 dwarf2out_function_decl
, /* function_decl */
2477 dwarf2out_early_global_decl
,
2478 dwarf2out_late_global_decl
,
2479 dwarf2out_type_decl
, /* type_decl */
2480 dwarf2out_imported_module_or_decl
,
2481 debug_nothing_tree
, /* deferred_inline_function */
2482 /* The DWARF 2 backend tries to reduce debugging bloat by not
2483 emitting the abstract description of inline functions until
2484 something tries to reference them. */
2485 dwarf2out_abstract_function
, /* outlining_inline_function */
2486 debug_nothing_rtx_code_label
, /* label */
2487 debug_nothing_int
, /* handle_pch */
2488 dwarf2out_var_location
,
2489 dwarf2out_switch_text_section
,
2491 1, /* start_end_main_source_file */
2492 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2495 /* NOTE: In the comments in this file, many references are made to
2496 "Debugging Information Entries". This term is abbreviated as `DIE'
2497 throughout the remainder of this file. */
2499 /* An internal representation of the DWARF output is built, and then
2500 walked to generate the DWARF debugging info. The walk of the internal
2501 representation is done after the entire program has been compiled.
2502 The types below are used to describe the internal representation. */
2504 /* Whether to put type DIEs into their own section .debug_types instead
2505 of making them part of the .debug_info section. Only supported for
2506 Dwarf V4 or higher and the user didn't disable them through
2507 -fno-debug-types-section. It is more efficient to put them in a
2508 separate comdat sections since the linker will then be able to
2509 remove duplicates. But not all tools support .debug_types sections
2512 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2514 /* Various DIE's use offsets relative to the beginning of the
2515 .debug_info section to refer to each other. */
2517 typedef long int dw_offset
;
2519 /* Define typedefs here to avoid circular dependencies. */
2521 typedef struct dw_attr_struct
*dw_attr_ref
;
2522 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2523 typedef struct pubname_struct
*pubname_ref
;
2524 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2525 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2526 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2528 /* The entries in the line_info table more-or-less mirror the opcodes
2529 that are used in the real dwarf line table. Arrays of these entries
2530 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2533 enum dw_line_info_opcode
{
2534 /* Emit DW_LNE_set_address; the operand is the label index. */
2537 /* Emit a row to the matrix with the given line. This may be done
2538 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2542 /* Emit a DW_LNS_set_file. */
2545 /* Emit a DW_LNS_set_column. */
2548 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2551 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2552 LI_set_prologue_end
,
2553 LI_set_epilogue_begin
,
2555 /* Emit a DW_LNE_set_discriminator. */
2556 LI_set_discriminator
2559 typedef struct GTY(()) dw_line_info_struct
{
2560 enum dw_line_info_opcode opcode
;
2562 } dw_line_info_entry
;
2565 typedef struct GTY(()) dw_line_info_table_struct
{
2566 /* The label that marks the end of this section. */
2567 const char *end_label
;
2569 /* The values for the last row of the matrix, as collected in the table.
2570 These are used to minimize the changes to the next row. */
2571 unsigned int file_num
;
2572 unsigned int line_num
;
2573 unsigned int column_num
;
2578 vec
<dw_line_info_entry
, va_gc
> *entries
;
2579 } dw_line_info_table
;
2581 typedef dw_line_info_table
*dw_line_info_table_p
;
2584 /* Each DIE attribute has a field specifying the attribute kind,
2585 a link to the next attribute in the chain, and an attribute value.
2586 Attributes are typically linked below the DIE they modify. */
2588 typedef struct GTY(()) dw_attr_struct
{
2589 enum dwarf_attribute dw_attr
;
2590 dw_val_node dw_attr_val
;
2595 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2596 The children of each node form a circular list linked by
2597 die_sib. die_child points to the node *before* the "first" child node. */
2599 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2600 union die_symbol_or_type_node
2602 const char * GTY ((tag ("0"))) die_symbol
;
2603 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2605 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2606 vec
<dw_attr_node
, va_gc
> *die_attr
;
2607 dw_die_ref die_parent
;
2608 dw_die_ref die_child
;
2610 dw_die_ref die_definition
; /* ref from a specification to its definition */
2611 dw_offset die_offset
;
2612 unsigned long die_abbrev
;
2614 unsigned int decl_id
;
2615 enum dwarf_tag die_tag
;
2616 /* Die is used and must not be pruned as unused. */
2617 BOOL_BITFIELD die_perennial_p
: 1;
2618 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2619 /* Lots of spare bits. */
2623 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2624 static bool early_dwarf
;
2625 struct set_early_dwarf
{
2627 set_early_dwarf () : saved(early_dwarf
) { early_dwarf
= true; }
2628 ~set_early_dwarf () { early_dwarf
= saved
; }
2631 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2632 #define FOR_EACH_CHILD(die, c, expr) do { \
2633 c = die->die_child; \
2637 } while (c != die->die_child); \
2640 /* The pubname structure */
2642 typedef struct GTY(()) pubname_struct
{
2649 struct GTY(()) dw_ranges_struct
{
2650 /* If this is positive, it's a block number, otherwise it's a
2651 bitwise-negated index into dw_ranges_by_label. */
2655 /* A structure to hold a macinfo entry. */
2657 typedef struct GTY(()) macinfo_struct
{
2659 unsigned HOST_WIDE_INT lineno
;
2665 struct GTY(()) dw_ranges_by_label_struct
{
2670 /* The comdat type node structure. */
2671 typedef struct GTY(()) comdat_type_struct
2673 dw_die_ref root_die
;
2674 dw_die_ref type_die
;
2675 dw_die_ref skeleton_die
;
2676 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2677 struct comdat_type_struct
*next
;
2681 /* A list of DIEs for which we can't determine ancestry (parent_die
2682 field) just yet. Later in dwarf2out_finish we will fill in the
2684 typedef struct GTY(()) limbo_die_struct
{
2686 /* The tree for which this DIE was created. We use this to
2687 determine ancestry later. */
2689 struct limbo_die_struct
*next
;
2693 typedef struct skeleton_chain_struct
2697 struct skeleton_chain_struct
*parent
;
2699 skeleton_chain_node
;
2701 /* Define a macro which returns nonzero for a TYPE_DECL which was
2702 implicitly generated for a type.
2704 Note that, unlike the C front-end (which generates a NULL named
2705 TYPE_DECL node for each complete tagged type, each array type,
2706 and each function type node created) the C++ front-end generates
2707 a _named_ TYPE_DECL node for each tagged type node created.
2708 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2709 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2710 front-end, but for each type, tagged or not. */
2712 #define TYPE_DECL_IS_STUB(decl) \
2713 (DECL_NAME (decl) == NULL_TREE \
2714 || (DECL_ARTIFICIAL (decl) \
2715 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2716 /* This is necessary for stub decls that \
2717 appear in nested inline functions. */ \
2718 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2719 && (decl_ultimate_origin (decl) \
2720 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2722 /* Information concerning the compilation unit's programming
2723 language, and compiler version. */
2725 /* Fixed size portion of the DWARF compilation unit header. */
2726 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2727 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2729 /* Fixed size portion of the DWARF comdat type unit header. */
2730 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2731 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2732 + DWARF_OFFSET_SIZE)
2734 /* Fixed size portion of public names info. */
2735 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2737 /* Fixed size portion of the address range info. */
2738 #define DWARF_ARANGES_HEADER_SIZE \
2739 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2740 DWARF2_ADDR_SIZE * 2) \
2741 - DWARF_INITIAL_LENGTH_SIZE)
2743 /* Size of padding portion in the address range info. It must be
2744 aligned to twice the pointer size. */
2745 #define DWARF_ARANGES_PAD_SIZE \
2746 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2747 DWARF2_ADDR_SIZE * 2) \
2748 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2750 /* Use assembler line directives if available. */
2751 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2752 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2753 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2755 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2759 /* Minimum line offset in a special line info. opcode.
2760 This value was chosen to give a reasonable range of values. */
2761 #define DWARF_LINE_BASE -10
2763 /* First special line opcode - leave room for the standard opcodes. */
2764 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2766 /* Range of line offsets in a special line info. opcode. */
2767 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2769 /* Flag that indicates the initial value of the is_stmt_start flag.
2770 In the present implementation, we do not mark any lines as
2771 the beginning of a source statement, because that information
2772 is not made available by the GCC front-end. */
2773 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2775 /* Maximum number of operations per instruction bundle. */
2776 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2777 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2780 /* This location is used by calc_die_sizes() to keep track
2781 the offset of each DIE within the .debug_info section. */
2782 static unsigned long next_die_offset
;
2784 /* Record the root of the DIE's built for the current compilation unit. */
2785 static GTY(()) dw_die_ref single_comp_unit_die
;
2787 /* A list of type DIEs that have been separated into comdat sections. */
2788 static GTY(()) comdat_type_node
*comdat_type_list
;
2790 /* A list of DIEs with a NULL parent waiting to be relocated. */
2791 static GTY(()) limbo_die_node
*limbo_die_list
;
2793 /* A list of DIEs for which we may have to generate
2794 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2795 static GTY(()) limbo_die_node
*deferred_asm_name
;
2797 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
2799 typedef const char *compare_type
;
2801 static hashval_t
hash (dwarf_file_data
*);
2802 static bool equal (dwarf_file_data
*, const char *);
2805 /* Filenames referenced by this compilation unit. */
2806 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
2808 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
2810 typedef tree compare_type
;
2812 static hashval_t
hash (die_node
*);
2813 static bool equal (die_node
*, tree
);
2815 /* A hash table of references to DIE's that describe declarations.
2816 The key is a DECL_UID() which is a unique number identifying each decl. */
2817 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
2819 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
2821 static hashval_t
hash (die_struct
*);
2822 static bool equal (die_struct
*, die_struct
*);
2825 /* A hash table of references to DIE's that describe COMMON blocks.
2826 The key is DECL_UID() ^ die_parent. */
2827 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
2829 typedef struct GTY(()) die_arg_entry_struct
{
2835 /* Node of the variable location list. */
2836 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2837 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2838 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2839 in mode of the EXPR_LIST node and first EXPR_LIST operand
2840 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2841 location or NULL for padding. For larger bitsizes,
2842 mode is 0 and first operand is a CONCAT with bitsize
2843 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2844 NULL as second operand. */
2846 const char * GTY (()) label
;
2847 struct var_loc_node
* GTY (()) next
;
2850 /* Variable location list. */
2851 struct GTY ((for_user
)) var_loc_list_def
{
2852 struct var_loc_node
* GTY (()) first
;
2854 /* Pointer to the last but one or last element of the
2855 chained list. If the list is empty, both first and
2856 last are NULL, if the list contains just one node
2857 or the last node certainly is not redundant, it points
2858 to the last node, otherwise points to the last but one.
2859 Do not mark it for GC because it is marked through the chain. */
2860 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2862 /* Pointer to the last element before section switch,
2863 if NULL, either sections weren't switched or first
2864 is after section switch. */
2865 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2867 /* DECL_UID of the variable decl. */
2868 unsigned int decl_id
;
2870 typedef struct var_loc_list_def var_loc_list
;
2872 /* Call argument location list. */
2873 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2874 rtx
GTY (()) call_arg_loc_note
;
2875 const char * GTY (()) label
;
2876 tree
GTY (()) block
;
2878 rtx
GTY (()) symbol_ref
;
2879 struct call_arg_loc_node
* GTY (()) next
;
2883 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
2885 typedef const_tree compare_type
;
2887 static hashval_t
hash (var_loc_list
*);
2888 static bool equal (var_loc_list
*, const_tree
);
2891 /* Table of decl location linked lists. */
2892 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
2894 /* Head and tail of call_arg_loc chain. */
2895 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2896 static struct call_arg_loc_node
*call_arg_loc_last
;
2898 /* Number of call sites in the current function. */
2899 static int call_site_count
= -1;
2900 /* Number of tail call sites in the current function. */
2901 static int tail_call_site_count
= -1;
2903 /* A cached location list. */
2904 struct GTY ((for_user
)) cached_dw_loc_list_def
{
2905 /* The DECL_UID of the decl that this entry describes. */
2906 unsigned int decl_id
;
2908 /* The cached location list. */
2909 dw_loc_list_ref loc_list
;
2911 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2913 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
2916 typedef const_tree compare_type
;
2918 static hashval_t
hash (cached_dw_loc_list
*);
2919 static bool equal (cached_dw_loc_list
*, const_tree
);
2922 /* Table of cached location lists. */
2923 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
2925 /* A pointer to the base of a list of references to DIE's that
2926 are uniquely identified by their tag, presence/absence of
2927 children DIE's, and list of attribute/value pairs. */
2928 static GTY((length ("abbrev_die_table_allocated")))
2929 dw_die_ref
*abbrev_die_table
;
2931 /* Number of elements currently allocated for abbrev_die_table. */
2932 static GTY(()) unsigned abbrev_die_table_allocated
;
2934 /* Number of elements in abbrev_die_table currently in use. */
2935 static GTY(()) unsigned abbrev_die_table_in_use
;
2937 /* Size (in elements) of increments by which we may expand the
2938 abbrev_die_table. */
2939 #define ABBREV_DIE_TABLE_INCREMENT 256
2941 /* A global counter for generating labels for line number data. */
2942 static unsigned int line_info_label_num
;
2944 /* The current table to which we should emit line number information
2945 for the current function. This will be set up at the beginning of
2946 assembly for the function. */
2947 static dw_line_info_table
*cur_line_info_table
;
2949 /* The two default tables of line number info. */
2950 static GTY(()) dw_line_info_table
*text_section_line_info
;
2951 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2953 /* The set of all non-default tables of line number info. */
2954 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2956 /* A flag to tell pubnames/types export if there is an info section to
2958 static bool info_section_emitted
;
2960 /* A pointer to the base of a table that contains a list of publicly
2961 accessible names. */
2962 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2964 /* A pointer to the base of a table that contains a list of publicly
2965 accessible types. */
2966 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2968 /* A pointer to the base of a table that contains a list of macro
2969 defines/undefines (and file start/end markers). */
2970 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2972 /* True if .debug_macinfo or .debug_macros section is going to be
2974 #define have_macinfo \
2975 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2976 && !macinfo_table->is_empty ())
2978 /* Array of dies for which we should generate .debug_ranges info. */
2979 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2981 /* Number of elements currently allocated for ranges_table. */
2982 static GTY(()) unsigned ranges_table_allocated
;
2984 /* Number of elements in ranges_table currently in use. */
2985 static GTY(()) unsigned ranges_table_in_use
;
2987 /* Array of pairs of labels referenced in ranges_table. */
2988 static GTY ((length ("ranges_by_label_allocated")))
2989 dw_ranges_by_label_ref ranges_by_label
;
2991 /* Number of elements currently allocated for ranges_by_label. */
2992 static GTY(()) unsigned ranges_by_label_allocated
;
2994 /* Number of elements in ranges_by_label currently in use. */
2995 static GTY(()) unsigned ranges_by_label_in_use
;
2997 /* Size (in elements) of increments by which we may expand the
2999 #define RANGES_TABLE_INCREMENT 64
3001 /* Whether we have location lists that need outputting */
3002 static GTY(()) bool have_location_lists
;
3004 /* Unique label counter. */
3005 static GTY(()) unsigned int loclabel_num
;
3007 /* Unique label counter for point-of-call tables. */
3008 static GTY(()) unsigned int poc_label_num
;
3010 /* The last file entry emitted by maybe_emit_file(). */
3011 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3013 /* Number of internal labels generated by gen_internal_sym(). */
3014 static GTY(()) int label_num
;
3016 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3018 /* Instances of generic types for which we need to generate debug
3019 info that describe their generic parameters and arguments. That
3020 generation needs to happen once all types are properly laid out so
3021 we do it at the end of compilation. */
3022 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3024 /* Offset from the "steady-state frame pointer" to the frame base,
3025 within the current function. */
3026 static HOST_WIDE_INT frame_pointer_fb_offset
;
3027 static bool frame_pointer_fb_offset_valid
;
3029 static vec
<dw_die_ref
> base_types
;
3031 /* Flags to represent a set of attribute classes for attributes that represent
3032 a scalar value (bounds, pointers, ...). */
3035 dw_scalar_form_constant
= 0x01,
3036 dw_scalar_form_exprloc
= 0x02,
3037 dw_scalar_form_reference
= 0x04
3040 /* Forward declarations for functions defined in this file. */
3042 static int is_pseudo_reg (const_rtx
);
3043 static tree
type_main_variant (tree
);
3044 static int is_tagged_type (const_tree
);
3045 static const char *dwarf_tag_name (unsigned);
3046 static const char *dwarf_attr_name (unsigned);
3047 static const char *dwarf_form_name (unsigned);
3048 static tree
decl_ultimate_origin (const_tree
);
3049 static tree
decl_class_context (tree
);
3050 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3051 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3052 static inline unsigned int AT_index (dw_attr_ref
);
3053 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3054 static inline unsigned AT_flag (dw_attr_ref
);
3055 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3056 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
3057 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3058 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3059 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3060 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3061 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3062 unsigned int, unsigned char *);
3063 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3064 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3065 static inline const char *AT_string (dw_attr_ref
);
3066 static enum dwarf_form
AT_string_form (dw_attr_ref
);
3067 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3068 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3069 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3070 static inline int AT_ref_external (dw_attr_ref
);
3071 static inline void set_AT_ref_external (dw_attr_ref
, int);
3072 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3073 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3074 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3075 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3077 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3078 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3079 static void remove_addr_table_entry (addr_table_entry
*);
3080 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3081 static inline rtx
AT_addr (dw_attr_ref
);
3082 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3083 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3084 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3085 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3086 unsigned HOST_WIDE_INT
);
3087 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3088 unsigned long, bool);
3089 static inline const char *AT_lbl (dw_attr_ref
);
3090 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3091 static const char *get_AT_low_pc (dw_die_ref
);
3092 static const char *get_AT_hi_pc (dw_die_ref
);
3093 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3094 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3095 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3096 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3097 static bool is_cxx (void);
3098 static bool is_fortran (void);
3099 static bool is_ada (void);
3100 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3101 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3102 static void add_child_die (dw_die_ref
, dw_die_ref
);
3103 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3104 static dw_die_ref
lookup_type_die (tree
);
3105 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3106 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3107 static void equate_type_number_to_die (tree
, dw_die_ref
);
3108 static dw_die_ref
lookup_decl_die (tree
);
3109 static var_loc_list
*lookup_decl_loc (const_tree
);
3110 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3111 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3112 static void print_spaces (FILE *);
3113 static void print_die (dw_die_ref
, FILE *);
3114 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3115 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3116 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3117 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3118 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3119 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3120 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3121 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3122 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3123 struct md5_ctx
*, int *);
3124 struct checksum_attributes
;
3125 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3126 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3127 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3128 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3129 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3130 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3131 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3132 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3133 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3134 static void compute_section_prefix (dw_die_ref
);
3135 static int is_type_die (dw_die_ref
);
3136 static int is_comdat_die (dw_die_ref
);
3137 static int is_symbol_die (dw_die_ref
);
3138 static inline bool is_template_instantiation (dw_die_ref
);
3139 static void assign_symbol_names (dw_die_ref
);
3140 static void break_out_includes (dw_die_ref
);
3141 static int is_declaration_die (dw_die_ref
);
3142 static int should_move_die_to_comdat (dw_die_ref
);
3143 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3144 static dw_die_ref
clone_die (dw_die_ref
);
3145 static dw_die_ref
clone_tree (dw_die_ref
);
3146 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3147 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3148 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3149 static dw_die_ref
generate_skeleton (dw_die_ref
);
3150 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3153 static void break_out_comdat_types (dw_die_ref
);
3154 static void copy_decls_for_unworthy_types (dw_die_ref
);
3156 static void add_sibling_attributes (dw_die_ref
);
3157 static void output_location_lists (dw_die_ref
);
3158 static int constant_size (unsigned HOST_WIDE_INT
);
3159 static unsigned long size_of_die (dw_die_ref
);
3160 static void calc_die_sizes (dw_die_ref
);
3161 static void calc_base_type_die_sizes (void);
3162 static void mark_dies (dw_die_ref
);
3163 static void unmark_dies (dw_die_ref
);
3164 static void unmark_all_dies (dw_die_ref
);
3165 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3166 static unsigned long size_of_aranges (void);
3167 static enum dwarf_form
value_format (dw_attr_ref
);
3168 static void output_value_format (dw_attr_ref
);
3169 static void output_abbrev_section (void);
3170 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3171 static void output_die_symbol (dw_die_ref
);
3172 static void output_die (dw_die_ref
);
3173 static void output_compilation_unit_header (void);
3174 static void output_comp_unit (dw_die_ref
, int);
3175 static void output_comdat_type_unit (comdat_type_node
*);
3176 static const char *dwarf2_name (tree
, int);
3177 static void add_pubname (tree
, dw_die_ref
);
3178 static void add_enumerator_pubname (const char *, dw_die_ref
);
3179 static void add_pubname_string (const char *, dw_die_ref
);
3180 static void add_pubtype (tree
, dw_die_ref
);
3181 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3182 static void output_aranges (unsigned long);
3183 static unsigned int add_ranges_num (int);
3184 static unsigned int add_ranges (const_tree
);
3185 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3187 static void output_ranges (void);
3188 static dw_line_info_table
*new_line_info_table (void);
3189 static void output_line_info (bool);
3190 static void output_file_names (void);
3191 static dw_die_ref
base_type_die (tree
);
3192 static int is_base_type (tree
);
3193 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3194 static int decl_quals (const_tree
);
3195 static dw_die_ref
modified_type_die (tree
, int, dw_die_ref
);
3196 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3197 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3198 static int type_is_enum (const_tree
);
3199 static unsigned int dbx_reg_number (const_rtx
);
3200 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3201 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3202 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3203 enum var_init_status
);
3204 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3205 enum var_init_status
);
3206 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3207 enum var_init_status
);
3208 static int is_based_loc (const_rtx
);
3209 static bool resolve_one_addr (rtx
*);
3210 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3211 enum var_init_status
);
3212 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3213 enum var_init_status
);
3214 struct loc_descr_context
;
3215 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3216 const struct loc_descr_context
*);
3217 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3218 const struct loc_descr_context
*);
3219 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3220 static tree
field_type (const_tree
);
3221 static unsigned int simple_type_align_in_bits (const_tree
);
3222 static unsigned int simple_decl_align_in_bits (const_tree
);
3223 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3224 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3225 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3227 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3228 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3229 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3230 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3231 static void insert_float (const_rtx
, unsigned char *);
3232 static rtx
rtl_for_decl_location (tree
);
3233 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3234 enum dwarf_attribute
);
3235 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3236 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3237 static void add_name_attribute (dw_die_ref
, const char *);
3238 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3239 static void add_comp_dir_attribute (dw_die_ref
);
3240 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3241 const struct loc_descr_context
*);
3242 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3243 const struct loc_descr_context
*);
3244 static void add_subscript_info (dw_die_ref
, tree
, bool);
3245 static void add_byte_size_attribute (dw_die_ref
, tree
);
3246 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3247 static void add_bit_size_attribute (dw_die_ref
, tree
);
3248 static void add_prototyped_attribute (dw_die_ref
, tree
);
3249 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3250 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3251 static void add_src_coords_attributes (dw_die_ref
, tree
);
3252 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3253 static void push_decl_scope (tree
);
3254 static void pop_decl_scope (void);
3255 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3256 static inline int local_scope_p (dw_die_ref
);
3257 static inline int class_scope_p (dw_die_ref
);
3258 static inline int class_or_namespace_scope_p (dw_die_ref
);
3259 static void add_type_attribute (dw_die_ref
, tree
, int, dw_die_ref
);
3260 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3261 static const char *type_tag (const_tree
);
3262 static tree
member_declared_type (const_tree
);
3264 static const char *decl_start_label (tree
);
3266 static void gen_array_type_die (tree
, dw_die_ref
);
3267 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3269 static void gen_entry_point_die (tree
, dw_die_ref
);
3271 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3272 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3273 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3274 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3275 static void gen_formal_types_die (tree
, dw_die_ref
);
3276 static void gen_subprogram_die (tree
, dw_die_ref
);
3277 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3278 static void gen_const_die (tree
, dw_die_ref
);
3279 static void gen_label_die (tree
, dw_die_ref
);
3280 static void gen_lexical_block_die (tree
, dw_die_ref
);
3281 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3282 static void gen_field_die (tree
, dw_die_ref
);
3283 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3284 static dw_die_ref
gen_compile_unit_die (const char *);
3285 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3286 static void gen_member_die (tree
, dw_die_ref
);
3287 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3288 enum debug_info_usage
);
3289 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3290 static void gen_typedef_die (tree
, dw_die_ref
);
3291 static void gen_type_die (tree
, dw_die_ref
);
3292 static void gen_block_die (tree
, dw_die_ref
);
3293 static void decls_for_scope (tree
, dw_die_ref
);
3294 static inline int is_redundant_typedef (const_tree
);
3295 static bool is_naming_typedef_decl (const_tree
);
3296 static inline dw_die_ref
get_context_die (tree
);
3297 static void gen_namespace_die (tree
, dw_die_ref
);
3298 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3299 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3300 static dw_die_ref
force_decl_die (tree
);
3301 static dw_die_ref
force_type_die (tree
);
3302 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3303 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3304 static struct dwarf_file_data
* lookup_filename (const char *);
3305 static void retry_incomplete_types (void);
3306 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3307 static void gen_generic_params_dies (tree
);
3308 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3309 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3310 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3311 static int file_info_cmp (const void *, const void *);
3312 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3313 const char *, const char *);
3314 static void output_loc_list (dw_loc_list_ref
);
3315 static char *gen_internal_sym (const char *);
3316 static bool want_pubnames (void);
3318 static void prune_unmark_dies (dw_die_ref
);
3319 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3320 static void prune_unused_types_mark (dw_die_ref
, int);
3321 static void prune_unused_types_walk (dw_die_ref
);
3322 static void prune_unused_types_walk_attribs (dw_die_ref
);
3323 static void prune_unused_types_prune (dw_die_ref
);
3324 static void prune_unused_types (void);
3325 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3326 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3327 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3328 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3329 const char *, const char *);
3330 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3331 static void gen_remaining_tmpl_value_param_die_attribute (void);
3332 static bool generic_type_p (tree
);
3333 static void schedule_generic_params_dies_gen (tree t
);
3334 static void gen_scheduled_generic_parms_dies (void);
3336 static const char *comp_dir_string (void);
3338 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3340 /* enum for tracking thread-local variables whose address is really an offset
3341 relative to the TLS pointer, which will need link-time relocation, but will
3342 not need relocation by the DWARF consumer. */
3350 /* Return the operator to use for an address of a variable. For dtprel_true, we
3351 use DW_OP_const*. For regular variables, which need both link-time
3352 relocation and consumer-level relocation (e.g., to account for shared objects
3353 loaded at a random address), we use DW_OP_addr*. */
3355 static inline enum dwarf_location_atom
3356 dw_addr_op (enum dtprel_bool dtprel
)
3358 if (dtprel
== dtprel_true
)
3359 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3360 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3362 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3365 /* Return a pointer to a newly allocated address location description. If
3366 dwarf_split_debug_info is true, then record the address with the appropriate
3368 static inline dw_loc_descr_ref
3369 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3371 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3373 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3374 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3375 ref
->dtprel
= dtprel
;
3376 if (dwarf_split_debug_info
)
3377 ref
->dw_loc_oprnd1
.val_entry
3378 = add_addr_table_entry (addr
,
3379 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3381 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3386 /* Section names used to hold DWARF debugging information. */
3388 #ifndef DEBUG_INFO_SECTION
3389 #define DEBUG_INFO_SECTION ".debug_info"
3391 #ifndef DEBUG_DWO_INFO_SECTION
3392 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3394 #ifndef DEBUG_ABBREV_SECTION
3395 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3397 #ifndef DEBUG_DWO_ABBREV_SECTION
3398 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3400 #ifndef DEBUG_ARANGES_SECTION
3401 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3403 #ifndef DEBUG_ADDR_SECTION
3404 #define DEBUG_ADDR_SECTION ".debug_addr"
3406 #ifndef DEBUG_NORM_MACINFO_SECTION
3407 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3409 #ifndef DEBUG_DWO_MACINFO_SECTION
3410 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3412 #ifndef DEBUG_MACINFO_SECTION
3413 #define DEBUG_MACINFO_SECTION \
3414 (!dwarf_split_debug_info \
3415 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3417 #ifndef DEBUG_NORM_MACRO_SECTION
3418 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3420 #ifndef DEBUG_DWO_MACRO_SECTION
3421 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3423 #ifndef DEBUG_MACRO_SECTION
3424 #define DEBUG_MACRO_SECTION \
3425 (!dwarf_split_debug_info \
3426 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3428 #ifndef DEBUG_LINE_SECTION
3429 #define DEBUG_LINE_SECTION ".debug_line"
3431 #ifndef DEBUG_DWO_LINE_SECTION
3432 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3434 #ifndef DEBUG_LOC_SECTION
3435 #define DEBUG_LOC_SECTION ".debug_loc"
3437 #ifndef DEBUG_DWO_LOC_SECTION
3438 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3440 #ifndef DEBUG_PUBNAMES_SECTION
3441 #define DEBUG_PUBNAMES_SECTION \
3442 ((debug_generate_pub_sections == 2) \
3443 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3445 #ifndef DEBUG_PUBTYPES_SECTION
3446 #define DEBUG_PUBTYPES_SECTION \
3447 ((debug_generate_pub_sections == 2) \
3448 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3450 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3451 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3452 #ifndef DEBUG_STR_OFFSETS_SECTION
3453 #define DEBUG_STR_OFFSETS_SECTION \
3454 (!dwarf_split_debug_info \
3455 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3457 #ifndef DEBUG_STR_DWO_SECTION
3458 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3460 #ifndef DEBUG_STR_SECTION
3461 #define DEBUG_STR_SECTION ".debug_str"
3463 #ifndef DEBUG_RANGES_SECTION
3464 #define DEBUG_RANGES_SECTION ".debug_ranges"
3467 /* Standard ELF section names for compiled code and data. */
3468 #ifndef TEXT_SECTION_NAME
3469 #define TEXT_SECTION_NAME ".text"
3472 /* Section flags for .debug_macinfo/.debug_macro section. */
3473 #define DEBUG_MACRO_SECTION_FLAGS \
3474 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3476 /* Section flags for .debug_str section. */
3477 #define DEBUG_STR_SECTION_FLAGS \
3478 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3479 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3482 /* Section flags for .debug_str.dwo section. */
3483 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3485 /* Labels we insert at beginning sections we can reference instead of
3486 the section names themselves. */
3488 #ifndef TEXT_SECTION_LABEL
3489 #define TEXT_SECTION_LABEL "Ltext"
3491 #ifndef COLD_TEXT_SECTION_LABEL
3492 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3494 #ifndef DEBUG_LINE_SECTION_LABEL
3495 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3497 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3498 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3500 #ifndef DEBUG_INFO_SECTION_LABEL
3501 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3503 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3504 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3506 #ifndef DEBUG_ABBREV_SECTION_LABEL
3507 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3509 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3510 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3512 #ifndef DEBUG_ADDR_SECTION_LABEL
3513 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3515 #ifndef DEBUG_LOC_SECTION_LABEL
3516 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3518 #ifndef DEBUG_RANGES_SECTION_LABEL
3519 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3521 #ifndef DEBUG_MACINFO_SECTION_LABEL
3522 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3524 #ifndef DEBUG_MACRO_SECTION_LABEL
3525 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3527 #define SKELETON_COMP_DIE_ABBREV 1
3528 #define SKELETON_TYPE_DIE_ABBREV 2
3530 /* Definitions of defaults for formats and names of various special
3531 (artificial) labels which may be generated within this file (when the -g
3532 options is used and DWARF2_DEBUGGING_INFO is in effect.
3533 If necessary, these may be overridden from within the tm.h file, but
3534 typically, overriding these defaults is unnecessary. */
3536 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3537 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3538 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3539 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3540 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3541 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3542 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3543 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3544 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3545 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3546 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3547 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3548 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3549 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3551 #ifndef TEXT_END_LABEL
3552 #define TEXT_END_LABEL "Letext"
3554 #ifndef COLD_END_LABEL
3555 #define COLD_END_LABEL "Letext_cold"
3557 #ifndef BLOCK_BEGIN_LABEL
3558 #define BLOCK_BEGIN_LABEL "LBB"
3560 #ifndef BLOCK_END_LABEL
3561 #define BLOCK_END_LABEL "LBE"
3563 #ifndef LINE_CODE_LABEL
3564 #define LINE_CODE_LABEL "LM"
3568 /* Return the root of the DIE's built for the current compilation unit. */
3570 comp_unit_die (void)
3572 if (!single_comp_unit_die
)
3573 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3574 return single_comp_unit_die
;
3577 /* We allow a language front-end to designate a function that is to be
3578 called to "demangle" any name before it is put into a DIE. */
3580 static const char *(*demangle_name_func
) (const char *);
3583 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3585 demangle_name_func
= func
;
3588 /* Test if rtl node points to a pseudo register. */
3591 is_pseudo_reg (const_rtx rtl
)
3593 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3594 || (GET_CODE (rtl
) == SUBREG
3595 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3598 /* Return a reference to a type, with its const and volatile qualifiers
3602 type_main_variant (tree type
)
3604 type
= TYPE_MAIN_VARIANT (type
);
3606 /* ??? There really should be only one main variant among any group of
3607 variants of a given type (and all of the MAIN_VARIANT values for all
3608 members of the group should point to that one type) but sometimes the C
3609 front-end messes this up for array types, so we work around that bug
3611 if (TREE_CODE (type
) == ARRAY_TYPE
)
3612 while (type
!= TYPE_MAIN_VARIANT (type
))
3613 type
= TYPE_MAIN_VARIANT (type
);
3618 /* Return nonzero if the given type node represents a tagged type. */
3621 is_tagged_type (const_tree type
)
3623 enum tree_code code
= TREE_CODE (type
);
3625 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3626 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3629 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3632 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3634 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3637 /* Return die_offset of a DIE reference to a base type. */
3639 static unsigned long int
3640 get_base_type_offset (dw_die_ref ref
)
3642 if (ref
->die_offset
)
3643 return ref
->die_offset
;
3644 if (comp_unit_die ()->die_abbrev
)
3646 calc_base_type_die_sizes ();
3647 gcc_assert (ref
->die_offset
);
3649 return ref
->die_offset
;
3652 /* Return die_offset of a DIE reference other than base type. */
3654 static unsigned long int
3655 get_ref_die_offset (dw_die_ref ref
)
3657 gcc_assert (ref
->die_offset
);
3658 return ref
->die_offset
;
3661 /* Convert a DIE tag into its string name. */
3664 dwarf_tag_name (unsigned int tag
)
3666 const char *name
= get_DW_TAG_name (tag
);
3671 return "DW_TAG_<unknown>";
3674 /* Convert a DWARF attribute code into its string name. */
3677 dwarf_attr_name (unsigned int attr
)
3683 #if VMS_DEBUGGING_INFO
3684 case DW_AT_HP_prologue
:
3685 return "DW_AT_HP_prologue";
3687 case DW_AT_MIPS_loop_unroll_factor
:
3688 return "DW_AT_MIPS_loop_unroll_factor";
3691 #if VMS_DEBUGGING_INFO
3692 case DW_AT_HP_epilogue
:
3693 return "DW_AT_HP_epilogue";
3695 case DW_AT_MIPS_stride
:
3696 return "DW_AT_MIPS_stride";
3700 name
= get_DW_AT_name (attr
);
3705 return "DW_AT_<unknown>";
3708 /* Convert a DWARF value form code into its string name. */
3711 dwarf_form_name (unsigned int form
)
3713 const char *name
= get_DW_FORM_name (form
);
3718 return "DW_FORM_<unknown>";
3721 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3722 instance of an inlined instance of a decl which is local to an inline
3723 function, so we have to trace all of the way back through the origin chain
3724 to find out what sort of node actually served as the original seed for the
3728 decl_ultimate_origin (const_tree decl
)
3730 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3733 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3734 we're trying to output the abstract instance of this function. */
3735 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3738 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3739 most distant ancestor, this should never happen. */
3740 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3742 return DECL_ABSTRACT_ORIGIN (decl
);
3745 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3746 of a virtual function may refer to a base class, so we check the 'this'
3750 decl_class_context (tree decl
)
3752 tree context
= NULL_TREE
;
3754 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3755 context
= DECL_CONTEXT (decl
);
3757 context
= TYPE_MAIN_VARIANT
3758 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3760 if (context
&& !TYPE_P (context
))
3761 context
= NULL_TREE
;
3766 /* Add an attribute/value pair to a DIE. */
3769 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3771 /* Maybe this should be an assert? */
3775 vec_safe_reserve (die
->die_attr
, 1);
3776 vec_safe_push (die
->die_attr
, *attr
);
3779 static inline enum dw_val_class
3780 AT_class (dw_attr_ref a
)
3782 return a
->dw_attr_val
.val_class
;
3785 /* Return the index for any attribute that will be referenced with a
3786 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3787 are stored in dw_attr_val.v.val_str for reference counting
3790 static inline unsigned int
3791 AT_index (dw_attr_ref a
)
3793 if (AT_class (a
) == dw_val_class_str
)
3794 return a
->dw_attr_val
.v
.val_str
->index
;
3795 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3796 return a
->dw_attr_val
.val_entry
->index
;
3800 /* Add a flag value attribute to a DIE. */
3803 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3807 attr
.dw_attr
= attr_kind
;
3808 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3809 attr
.dw_attr_val
.val_entry
= NULL
;
3810 attr
.dw_attr_val
.v
.val_flag
= flag
;
3811 add_dwarf_attr (die
, &attr
);
3814 static inline unsigned
3815 AT_flag (dw_attr_ref a
)
3817 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3818 return a
->dw_attr_val
.v
.val_flag
;
3821 /* Add a signed integer attribute value to a DIE. */
3824 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3828 attr
.dw_attr
= attr_kind
;
3829 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3830 attr
.dw_attr_val
.val_entry
= NULL
;
3831 attr
.dw_attr_val
.v
.val_int
= int_val
;
3832 add_dwarf_attr (die
, &attr
);
3835 static inline HOST_WIDE_INT
3836 AT_int (dw_attr_ref a
)
3838 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3839 return a
->dw_attr_val
.v
.val_int
;
3842 /* Add an unsigned integer attribute value to a DIE. */
3845 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3846 unsigned HOST_WIDE_INT unsigned_val
)
3850 attr
.dw_attr
= attr_kind
;
3851 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3852 attr
.dw_attr_val
.val_entry
= NULL
;
3853 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3854 add_dwarf_attr (die
, &attr
);
3857 static inline unsigned HOST_WIDE_INT
3858 AT_unsigned (dw_attr_ref a
)
3860 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3861 return a
->dw_attr_val
.v
.val_unsigned
;
3864 /* Add an unsigned wide integer attribute value to a DIE. */
3867 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3872 attr
.dw_attr
= attr_kind
;
3873 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
3874 attr
.dw_attr_val
.val_entry
= NULL
;
3875 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
3876 *attr
.dw_attr_val
.v
.val_wide
= w
;
3877 add_dwarf_attr (die
, &attr
);
3880 /* Add an unsigned double integer attribute value to a DIE. */
3883 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3884 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3888 attr
.dw_attr
= attr_kind
;
3889 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3890 attr
.dw_attr_val
.val_entry
= NULL
;
3891 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3892 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3893 add_dwarf_attr (die
, &attr
);
3896 /* Add a floating point attribute value to a DIE and return it. */
3899 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3900 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3904 attr
.dw_attr
= attr_kind
;
3905 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3906 attr
.dw_attr_val
.val_entry
= NULL
;
3907 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3908 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3909 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3910 add_dwarf_attr (die
, &attr
);
3913 /* Add an 8-byte data attribute value to a DIE. */
3916 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3917 unsigned char data8
[8])
3921 attr
.dw_attr
= attr_kind
;
3922 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3923 attr
.dw_attr_val
.val_entry
= NULL
;
3924 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3925 add_dwarf_attr (die
, &attr
);
3928 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3929 dwarf_split_debug_info, address attributes in dies destined for the
3930 final executable have force_direct set to avoid using indexed
3934 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3940 lbl_id
= xstrdup (lbl_low
);
3941 attr
.dw_attr
= DW_AT_low_pc
;
3942 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3943 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3944 if (dwarf_split_debug_info
&& !force_direct
)
3945 attr
.dw_attr_val
.val_entry
3946 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3948 attr
.dw_attr_val
.val_entry
= NULL
;
3949 add_dwarf_attr (die
, &attr
);
3951 attr
.dw_attr
= DW_AT_high_pc
;
3952 if (dwarf_version
< 4)
3953 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3955 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3956 lbl_id
= xstrdup (lbl_high
);
3957 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3958 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3959 && dwarf_split_debug_info
&& !force_direct
)
3960 attr
.dw_attr_val
.val_entry
3961 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3963 attr
.dw_attr_val
.val_entry
= NULL
;
3964 add_dwarf_attr (die
, &attr
);
3967 /* Hash and equality functions for debug_str_hash. */
3970 indirect_string_hasher::hash (indirect_string_node
*x
)
3972 return htab_hash_string (x
->str
);
3976 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
3978 return strcmp (x1
->str
, x2
) == 0;
3981 /* Add STR to the given string hash table. */
3983 static struct indirect_string_node
*
3984 find_AT_string_in_table (const char *str
,
3985 hash_table
<indirect_string_hasher
> *table
)
3987 struct indirect_string_node
*node
;
3989 indirect_string_node
**slot
3990 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
3993 node
= ggc_cleared_alloc
<indirect_string_node
> ();
3994 node
->str
= ggc_strdup (str
);
4004 /* Add STR to the indirect string hash table. */
4006 static struct indirect_string_node
*
4007 find_AT_string (const char *str
)
4009 if (! debug_str_hash
)
4010 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4012 return find_AT_string_in_table (str
, debug_str_hash
);
4015 /* Add a string attribute value to a DIE. */
4018 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4021 struct indirect_string_node
*node
;
4023 node
= find_AT_string (str
);
4025 attr
.dw_attr
= attr_kind
;
4026 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4027 attr
.dw_attr_val
.val_entry
= NULL
;
4028 attr
.dw_attr_val
.v
.val_str
= node
;
4029 add_dwarf_attr (die
, &attr
);
4032 static inline const char *
4033 AT_string (dw_attr_ref a
)
4035 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4036 return a
->dw_attr_val
.v
.val_str
->str
;
4039 /* Call this function directly to bypass AT_string_form's logic to put
4040 the string inline in the die. */
4043 set_indirect_string (struct indirect_string_node
*node
)
4046 /* Already indirect is a no op. */
4047 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4049 gcc_assert (node
->label
);
4052 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4053 ++dw2_string_counter
;
4054 node
->label
= xstrdup (label
);
4056 if (!dwarf_split_debug_info
)
4058 node
->form
= DW_FORM_strp
;
4059 node
->index
= NOT_INDEXED
;
4063 node
->form
= DW_FORM_GNU_str_index
;
4064 node
->index
= NO_INDEX_ASSIGNED
;
4068 /* Find out whether a string should be output inline in DIE
4069 or out-of-line in .debug_str section. */
4071 static enum dwarf_form
4072 find_string_form (struct indirect_string_node
*node
)
4079 len
= strlen (node
->str
) + 1;
4081 /* If the string is shorter or equal to the size of the reference, it is
4082 always better to put it inline. */
4083 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4084 return node
->form
= DW_FORM_string
;
4086 /* If we cannot expect the linker to merge strings in .debug_str
4087 section, only put it into .debug_str if it is worth even in this
4089 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4090 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4091 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4092 return node
->form
= DW_FORM_string
;
4094 set_indirect_string (node
);
4099 /* Find out whether the string referenced from the attribute should be
4100 output inline in DIE or out-of-line in .debug_str section. */
4102 static enum dwarf_form
4103 AT_string_form (dw_attr_ref a
)
4105 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4106 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4109 /* Add a DIE reference attribute value to a DIE. */
4112 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4116 #ifdef ENABLE_CHECKING
4117 gcc_assert (targ_die
!= NULL
);
4119 /* With LTO we can end up trying to reference something we didn't create
4120 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4121 if (targ_die
== NULL
)
4125 attr
.dw_attr
= attr_kind
;
4126 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4127 attr
.dw_attr_val
.val_entry
= NULL
;
4128 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4129 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4130 add_dwarf_attr (die
, &attr
);
4133 /* Change DIE reference REF to point to NEW_DIE instead. */
4136 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4138 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4139 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4140 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4143 /* Add an AT_specification attribute to a DIE, and also make the back
4144 pointer from the specification to the definition. */
4147 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4149 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4150 gcc_assert (!targ_die
->die_definition
);
4151 targ_die
->die_definition
= die
;
4154 static inline dw_die_ref
4155 AT_ref (dw_attr_ref a
)
4157 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4158 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4162 AT_ref_external (dw_attr_ref a
)
4164 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4165 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4171 set_AT_ref_external (dw_attr_ref a
, int i
)
4173 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4174 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4177 /* Add an FDE reference attribute value to a DIE. */
4180 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4184 attr
.dw_attr
= attr_kind
;
4185 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4186 attr
.dw_attr_val
.val_entry
= NULL
;
4187 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4188 add_dwarf_attr (die
, &attr
);
4191 /* Add a location description attribute value to a DIE. */
4194 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4198 attr
.dw_attr
= attr_kind
;
4199 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4200 attr
.dw_attr_val
.val_entry
= NULL
;
4201 attr
.dw_attr_val
.v
.val_loc
= loc
;
4202 add_dwarf_attr (die
, &attr
);
4205 static inline dw_loc_descr_ref
4206 AT_loc (dw_attr_ref a
)
4208 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4209 return a
->dw_attr_val
.v
.val_loc
;
4213 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4217 attr
.dw_attr
= attr_kind
;
4218 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4219 attr
.dw_attr_val
.val_entry
= NULL
;
4220 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4221 add_dwarf_attr (die
, &attr
);
4222 have_location_lists
= true;
4225 static inline dw_loc_list_ref
4226 AT_loc_list (dw_attr_ref a
)
4228 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4229 return a
->dw_attr_val
.v
.val_loc_list
;
4232 static inline dw_loc_list_ref
*
4233 AT_loc_list_ptr (dw_attr_ref a
)
4235 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4236 return &a
->dw_attr_val
.v
.val_loc_list
;
4239 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4241 static hashval_t
hash (addr_table_entry
*);
4242 static bool equal (addr_table_entry
*, addr_table_entry
*);
4245 /* Table of entries into the .debug_addr section. */
4247 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4249 /* Hash an address_table_entry. */
4252 addr_hasher::hash (addr_table_entry
*a
)
4254 inchash::hash hstate
;
4260 case ate_kind_rtx_dtprel
:
4263 case ate_kind_label
:
4264 return htab_hash_string (a
->addr
.label
);
4268 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4269 return hstate
.end ();
4272 /* Determine equality for two address_table_entries. */
4275 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4277 if (a1
->kind
!= a2
->kind
)
4282 case ate_kind_rtx_dtprel
:
4283 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4284 case ate_kind_label
:
4285 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4291 /* Initialize an addr_table_entry. */
4294 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4300 case ate_kind_rtx_dtprel
:
4301 e
->addr
.rtl
= (rtx
) addr
;
4303 case ate_kind_label
:
4304 e
->addr
.label
= (char *) addr
;
4308 e
->index
= NO_INDEX_ASSIGNED
;
4311 /* Add attr to the address table entry to the table. Defer setting an
4312 index until output time. */
4314 static addr_table_entry
*
4315 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4317 addr_table_entry
*node
;
4318 addr_table_entry finder
;
4320 gcc_assert (dwarf_split_debug_info
);
4321 if (! addr_index_table
)
4322 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4323 init_addr_table_entry (&finder
, kind
, addr
);
4324 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4326 if (*slot
== HTAB_EMPTY_ENTRY
)
4328 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4329 init_addr_table_entry (node
, kind
, addr
);
4339 /* Remove an entry from the addr table by decrementing its refcount.
4340 Strictly, decrementing the refcount would be enough, but the
4341 assertion that the entry is actually in the table has found
4345 remove_addr_table_entry (addr_table_entry
*entry
)
4347 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4348 /* After an index is assigned, the table is frozen. */
4349 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4353 /* Given a location list, remove all addresses it refers to from the
4357 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4359 for (; descr
; descr
= descr
->dw_loc_next
)
4360 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4362 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4363 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4367 /* A helper function for dwarf2out_finish called through
4368 htab_traverse. Assign an addr_table_entry its index. All entries
4369 must be collected into the table when this function is called,
4370 because the indexing code relies on htab_traverse to traverse nodes
4371 in the same order for each run. */
4374 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4376 addr_table_entry
*node
= *h
;
4378 /* Don't index unreferenced nodes. */
4379 if (node
->refcount
== 0)
4382 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4383 node
->index
= *index
;
4389 /* Add an address constant attribute value to a DIE. When using
4390 dwarf_split_debug_info, address attributes in dies destined for the
4391 final executable should be direct references--setting the parameter
4392 force_direct ensures this behavior. */
4395 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4400 attr
.dw_attr
= attr_kind
;
4401 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4402 attr
.dw_attr_val
.v
.val_addr
= addr
;
4403 if (dwarf_split_debug_info
&& !force_direct
)
4404 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4406 attr
.dw_attr_val
.val_entry
= NULL
;
4407 add_dwarf_attr (die
, &attr
);
4410 /* Get the RTX from to an address DIE attribute. */
4413 AT_addr (dw_attr_ref a
)
4415 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4416 return a
->dw_attr_val
.v
.val_addr
;
4419 /* Add a file attribute value to a DIE. */
4422 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4423 struct dwarf_file_data
*fd
)
4427 attr
.dw_attr
= attr_kind
;
4428 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4429 attr
.dw_attr_val
.val_entry
= NULL
;
4430 attr
.dw_attr_val
.v
.val_file
= fd
;
4431 add_dwarf_attr (die
, &attr
);
4434 /* Get the dwarf_file_data from a file DIE attribute. */
4436 static inline struct dwarf_file_data
*
4437 AT_file (dw_attr_ref a
)
4439 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4440 return a
->dw_attr_val
.v
.val_file
;
4443 /* Add a vms delta attribute value to a DIE. */
4446 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4447 const char *lbl1
, const char *lbl2
)
4451 attr
.dw_attr
= attr_kind
;
4452 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4453 attr
.dw_attr_val
.val_entry
= NULL
;
4454 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4455 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4456 add_dwarf_attr (die
, &attr
);
4459 /* Add a label identifier attribute value to a DIE. */
4462 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4467 attr
.dw_attr
= attr_kind
;
4468 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4469 attr
.dw_attr_val
.val_entry
= NULL
;
4470 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4471 if (dwarf_split_debug_info
)
4472 attr
.dw_attr_val
.val_entry
4473 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4475 add_dwarf_attr (die
, &attr
);
4478 /* Add a section offset attribute value to a DIE, an offset into the
4479 debug_line section. */
4482 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4487 attr
.dw_attr
= attr_kind
;
4488 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4489 attr
.dw_attr_val
.val_entry
= NULL
;
4490 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4491 add_dwarf_attr (die
, &attr
);
4494 /* Add a section offset attribute value to a DIE, an offset into the
4495 debug_macinfo section. */
4498 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4503 attr
.dw_attr
= attr_kind
;
4504 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4505 attr
.dw_attr_val
.val_entry
= NULL
;
4506 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4507 add_dwarf_attr (die
, &attr
);
4510 /* Add an offset attribute value to a DIE. */
4513 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4514 unsigned HOST_WIDE_INT offset
)
4518 attr
.dw_attr
= attr_kind
;
4519 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4520 attr
.dw_attr_val
.val_entry
= NULL
;
4521 attr
.dw_attr_val
.v
.val_offset
= offset
;
4522 add_dwarf_attr (die
, &attr
);
4525 /* Add a range_list attribute value to a DIE. When using
4526 dwarf_split_debug_info, address attributes in dies destined for the
4527 final executable should be direct references--setting the parameter
4528 force_direct ensures this behavior. */
4530 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4531 #define RELOCATED_OFFSET (NULL)
4534 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4535 long unsigned int offset
, bool force_direct
)
4539 attr
.dw_attr
= attr_kind
;
4540 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4541 /* For the range_list attribute, use val_entry to store whether the
4542 offset should follow split-debug-info or normal semantics. This
4543 value is read in output_range_list_offset. */
4544 if (dwarf_split_debug_info
&& !force_direct
)
4545 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4547 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4548 attr
.dw_attr_val
.v
.val_offset
= offset
;
4549 add_dwarf_attr (die
, &attr
);
4552 /* Return the start label of a delta attribute. */
4554 static inline const char *
4555 AT_vms_delta1 (dw_attr_ref a
)
4557 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4558 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4561 /* Return the end label of a delta attribute. */
4563 static inline const char *
4564 AT_vms_delta2 (dw_attr_ref a
)
4566 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4567 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4570 static inline const char *
4571 AT_lbl (dw_attr_ref a
)
4573 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4574 || AT_class (a
) == dw_val_class_lineptr
4575 || AT_class (a
) == dw_val_class_macptr
4576 || AT_class (a
) == dw_val_class_high_pc
));
4577 return a
->dw_attr_val
.v
.val_lbl_id
;
4580 /* Get the attribute of type attr_kind. */
4583 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4587 dw_die_ref spec
= NULL
;
4592 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4593 if (a
->dw_attr
== attr_kind
)
4595 else if (a
->dw_attr
== DW_AT_specification
4596 || a
->dw_attr
== DW_AT_abstract_origin
)
4600 return get_AT (spec
, attr_kind
);
4605 /* Returns the parent of the declaration of DIE. */
4608 get_die_parent (dw_die_ref die
)
4615 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4616 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4619 return die
->die_parent
;
4622 /* Return the "low pc" attribute value, typically associated with a subprogram
4623 DIE. Return null if the "low pc" attribute is either not present, or if it
4624 cannot be represented as an assembler label identifier. */
4626 static inline const char *
4627 get_AT_low_pc (dw_die_ref die
)
4629 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4631 return a
? AT_lbl (a
) : NULL
;
4634 /* Return the "high pc" attribute value, typically associated with a subprogram
4635 DIE. Return null if the "high pc" attribute is either not present, or if it
4636 cannot be represented as an assembler label identifier. */
4638 static inline const char *
4639 get_AT_hi_pc (dw_die_ref die
)
4641 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4643 return a
? AT_lbl (a
) : NULL
;
4646 /* Return the value of the string attribute designated by ATTR_KIND, or
4647 NULL if it is not present. */
4649 static inline const char *
4650 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4652 dw_attr_ref a
= get_AT (die
, attr_kind
);
4654 return a
? AT_string (a
) : NULL
;
4657 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4658 if it is not present. */
4661 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4663 dw_attr_ref a
= get_AT (die
, attr_kind
);
4665 return a
? AT_flag (a
) : 0;
4668 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4669 if it is not present. */
4671 static inline unsigned
4672 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4674 dw_attr_ref a
= get_AT (die
, attr_kind
);
4676 return a
? AT_unsigned (a
) : 0;
4679 static inline dw_die_ref
4680 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4682 dw_attr_ref a
= get_AT (die
, attr_kind
);
4684 return a
? AT_ref (a
) : NULL
;
4687 static inline struct dwarf_file_data
*
4688 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4690 dw_attr_ref a
= get_AT (die
, attr_kind
);
4692 return a
? AT_file (a
) : NULL
;
4695 /* Return TRUE if the language is C++. */
4700 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4702 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
4703 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
4706 /* Return TRUE if the language is Java. */
4711 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4713 return lang
== DW_LANG_Java
;
4716 /* Return TRUE if the language is Fortran. */
4721 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4723 return (lang
== DW_LANG_Fortran77
4724 || lang
== DW_LANG_Fortran90
4725 || lang
== DW_LANG_Fortran95
4726 || lang
== DW_LANG_Fortran03
4727 || lang
== DW_LANG_Fortran08
);
4730 /* Return TRUE if the language is Ada. */
4735 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4737 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4740 /* Remove the specified attribute if present. Return TRUE if removal
4744 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4752 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4753 if (a
->dw_attr
== attr_kind
)
4755 if (AT_class (a
) == dw_val_class_str
)
4756 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4757 a
->dw_attr_val
.v
.val_str
->refcount
--;
4759 /* vec::ordered_remove should help reduce the number of abbrevs
4761 die
->die_attr
->ordered_remove (ix
);
4767 /* Remove CHILD from its parent. PREV must have the property that
4768 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4771 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4773 gcc_assert (child
->die_parent
== prev
->die_parent
);
4774 gcc_assert (prev
->die_sib
== child
);
4777 gcc_assert (child
->die_parent
->die_child
== child
);
4781 prev
->die_sib
= child
->die_sib
;
4782 if (child
->die_parent
->die_child
== child
)
4783 child
->die_parent
->die_child
= prev
;
4786 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4787 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4790 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4792 dw_die_ref parent
= old_child
->die_parent
;
4794 gcc_assert (parent
== prev
->die_parent
);
4795 gcc_assert (prev
->die_sib
== old_child
);
4797 new_child
->die_parent
= parent
;
4798 if (prev
== old_child
)
4800 gcc_assert (parent
->die_child
== old_child
);
4801 new_child
->die_sib
= new_child
;
4805 prev
->die_sib
= new_child
;
4806 new_child
->die_sib
= old_child
->die_sib
;
4808 if (old_child
->die_parent
->die_child
== old_child
)
4809 old_child
->die_parent
->die_child
= new_child
;
4812 /* Move all children from OLD_PARENT to NEW_PARENT. */
4815 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4818 new_parent
->die_child
= old_parent
->die_child
;
4819 old_parent
->die_child
= NULL
;
4820 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4823 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4827 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4833 dw_die_ref prev
= c
;
4835 while (c
->die_tag
== tag
)
4837 remove_child_with_prev (c
, prev
);
4838 c
->die_parent
= NULL
;
4839 /* Might have removed every child. */
4840 if (c
== c
->die_sib
)
4844 } while (c
!= die
->die_child
);
4847 /* Add a CHILD_DIE as the last child of DIE. */
4850 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4852 /* FIXME this should probably be an assert. */
4853 if (! die
|| ! child_die
)
4855 gcc_assert (die
!= child_die
);
4857 child_die
->die_parent
= die
;
4860 child_die
->die_sib
= die
->die_child
->die_sib
;
4861 die
->die_child
->die_sib
= child_die
;
4864 child_die
->die_sib
= child_die
;
4865 die
->die_child
= child_die
;
4868 /* Unassociate CHILD from its parent, and make its parent be
4872 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
4874 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4875 if (p
->die_sib
== child
)
4877 remove_child_with_prev (child
, p
);
4880 add_child_die (new_parent
, child
);
4883 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4884 is the specification, to the end of PARENT's list of children.
4885 This is done by removing and re-adding it. */
4888 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4890 /* We want the declaration DIE from inside the class, not the
4891 specification DIE at toplevel. */
4892 if (child
->die_parent
!= parent
)
4894 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4900 gcc_assert (child
->die_parent
== parent
4901 || (child
->die_parent
4902 == get_AT_ref (parent
, DW_AT_specification
)));
4904 reparent_child (child
, parent
);
4907 /* Create and return a new die with a parent of PARENT_DIE. If
4908 PARENT_DIE is NULL, the new DIE is placed in limbo and an
4909 associated tree T must be supplied to determine parenthood
4912 static inline dw_die_ref
4913 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4915 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
4917 die
->die_tag
= tag_value
;
4919 if (parent_die
!= NULL
)
4920 add_child_die (parent_die
, die
);
4923 limbo_die_node
*limbo_node
;
4925 /* No DIEs created after early dwarf should end up in limbo,
4926 because the limbo list should not persist past LTO
4928 if (tag_value
!= DW_TAG_compile_unit
4929 /* These are allowed because they're generated while
4930 breaking out COMDAT units late. */
4931 && tag_value
!= DW_TAG_type_unit
4933 /* Allow nested functions to live in limbo because they will
4934 only temporarily live there, as decls_for_scope will fix
4936 && (TREE_CODE (t
) != FUNCTION_DECL
4937 || !decl_function_context (t
))
4938 /* Same as nested functions above but for types. Types that
4939 are local to a function will be fixed in
4941 && (!RECORD_OR_UNION_TYPE_P (t
)
4942 || !TYPE_CONTEXT (t
)
4943 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
4944 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
4945 especially in the ltrans stage, but once we implement LTO
4946 dwarf streaming, we should remove this exception. */
4949 fprintf (stderr
, "symbol ended up in limbo too late:");
4950 debug_generic_stmt (t
);
4954 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
4955 limbo_node
->die
= die
;
4956 limbo_node
->created_for
= t
;
4957 limbo_node
->next
= limbo_die_list
;
4958 limbo_die_list
= limbo_node
;
4964 /* Return the DIE associated with the given type specifier. */
4966 static inline dw_die_ref
4967 lookup_type_die (tree type
)
4969 return TYPE_SYMTAB_DIE (type
);
4972 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4973 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4974 anonymous type instead the one of the naming typedef. */
4976 static inline dw_die_ref
4977 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4980 && TREE_CODE (type
) == RECORD_TYPE
4982 && type_die
->die_tag
== DW_TAG_typedef
4983 && is_naming_typedef_decl (TYPE_NAME (type
)))
4984 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4988 /* Like lookup_type_die, but if type is an anonymous type named by a
4989 typedef[1], return the DIE of the anonymous type instead the one of
4990 the naming typedef. This is because in gen_typedef_die, we did
4991 equate the anonymous struct named by the typedef with the DIE of
4992 the naming typedef. So by default, lookup_type_die on an anonymous
4993 struct yields the DIE of the naming typedef.
4995 [1]: Read the comment of is_naming_typedef_decl to learn about what
4996 a naming typedef is. */
4998 static inline dw_die_ref
4999 lookup_type_die_strip_naming_typedef (tree type
)
5001 dw_die_ref die
= lookup_type_die (type
);
5002 return strip_naming_typedef (type
, die
);
5005 /* Equate a DIE to a given type specifier. */
5008 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5010 TYPE_SYMTAB_DIE (type
) = type_die
;
5013 /* Returns a hash value for X (which really is a die_struct). */
5016 decl_die_hasher::hash (die_node
*x
)
5018 return (hashval_t
) x
->decl_id
;
5021 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5024 decl_die_hasher::equal (die_node
*x
, tree y
)
5026 return (x
->decl_id
== DECL_UID (y
));
5029 /* Return the DIE associated with a given declaration. */
5031 static inline dw_die_ref
5032 lookup_decl_die (tree decl
)
5034 return decl_die_table
->find_with_hash (decl
, DECL_UID (decl
));
5037 /* Returns a hash value for X (which really is a var_loc_list). */
5040 decl_loc_hasher::hash (var_loc_list
*x
)
5042 return (hashval_t
) x
->decl_id
;
5045 /* Return nonzero if decl_id of var_loc_list X is the same as
5049 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5051 return (x
->decl_id
== DECL_UID (y
));
5054 /* Return the var_loc list associated with a given declaration. */
5056 static inline var_loc_list
*
5057 lookup_decl_loc (const_tree decl
)
5059 if (!decl_loc_table
)
5061 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5064 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5067 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5069 return (hashval_t
) x
->decl_id
;
5072 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5076 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5078 return (x
->decl_id
== DECL_UID (y
));
5081 /* Equate a DIE to a particular declaration. */
5084 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5086 unsigned int decl_id
= DECL_UID (decl
);
5088 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5089 decl_die
->decl_id
= decl_id
;
5092 /* Return how many bits covers PIECE EXPR_LIST. */
5094 static HOST_WIDE_INT
5095 decl_piece_bitsize (rtx piece
)
5097 int ret
= (int) GET_MODE (piece
);
5100 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5101 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5102 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5105 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5108 decl_piece_varloc_ptr (rtx piece
)
5110 if ((int) GET_MODE (piece
))
5111 return &XEXP (piece
, 0);
5113 return &XEXP (XEXP (piece
, 0), 1);
5116 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5117 Next is the chain of following piece nodes. */
5119 static rtx_expr_list
*
5120 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5122 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5123 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5125 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5130 /* Return rtx that should be stored into loc field for
5131 LOC_NOTE and BITPOS/BITSIZE. */
5134 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5135 HOST_WIDE_INT bitsize
)
5139 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5141 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5146 /* This function either modifies location piece list *DEST in
5147 place (if SRC and INNER is NULL), or copies location piece list
5148 *SRC to *DEST while modifying it. Location BITPOS is modified
5149 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5150 not copied and if needed some padding around it is added.
5151 When modifying in place, DEST should point to EXPR_LIST where
5152 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5153 to the start of the whole list and INNER points to the EXPR_LIST
5154 where earlier pieces cover PIECE_BITPOS bits. */
5157 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5158 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5159 HOST_WIDE_INT bitsize
, rtx loc_note
)
5162 bool copy
= inner
!= NULL
;
5166 /* First copy all nodes preceding the current bitpos. */
5167 while (src
!= inner
)
5169 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5170 decl_piece_bitsize (*src
), NULL_RTX
);
5171 dest
= &XEXP (*dest
, 1);
5172 src
= &XEXP (*src
, 1);
5175 /* Add padding if needed. */
5176 if (bitpos
!= piece_bitpos
)
5178 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5179 copy
? NULL_RTX
: *dest
);
5180 dest
= &XEXP (*dest
, 1);
5182 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5185 /* A piece with correct bitpos and bitsize already exist,
5186 just update the location for it and return. */
5187 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5190 /* Add the piece that changed. */
5191 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5192 dest
= &XEXP (*dest
, 1);
5193 /* Skip over pieces that overlap it. */
5194 diff
= bitpos
- piece_bitpos
+ bitsize
;
5197 while (diff
> 0 && *src
)
5200 diff
-= decl_piece_bitsize (piece
);
5202 src
= &XEXP (piece
, 1);
5205 *src
= XEXP (piece
, 1);
5206 free_EXPR_LIST_node (piece
);
5209 /* Add padding if needed. */
5210 if (diff
< 0 && *src
)
5214 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5215 dest
= &XEXP (*dest
, 1);
5219 /* Finally copy all nodes following it. */
5222 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5223 decl_piece_bitsize (*src
), NULL_RTX
);
5224 dest
= &XEXP (*dest
, 1);
5225 src
= &XEXP (*src
, 1);
5229 /* Add a variable location node to the linked list for DECL. */
5231 static struct var_loc_node
*
5232 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5234 unsigned int decl_id
;
5236 struct var_loc_node
*loc
= NULL
;
5237 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5239 if (TREE_CODE (decl
) == VAR_DECL
5240 && DECL_HAS_DEBUG_EXPR_P (decl
))
5242 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5243 if (handled_component_p (realdecl
)
5244 || (TREE_CODE (realdecl
) == MEM_REF
5245 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5247 HOST_WIDE_INT maxsize
;
5250 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5251 if (!DECL_P (innerdecl
)
5252 || DECL_IGNORED_P (innerdecl
)
5253 || TREE_STATIC (innerdecl
)
5255 || bitpos
+ bitsize
> 256
5256 || bitsize
!= maxsize
)
5262 decl_id
= DECL_UID (decl
);
5264 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5267 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5268 temp
->decl_id
= decl_id
;
5274 /* For PARM_DECLs try to keep around the original incoming value,
5275 even if that means we'll emit a zero-range .debug_loc entry. */
5277 && temp
->first
== temp
->last
5278 && TREE_CODE (decl
) == PARM_DECL
5279 && NOTE_P (temp
->first
->loc
)
5280 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5281 && DECL_INCOMING_RTL (decl
)
5282 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5283 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5284 == GET_CODE (DECL_INCOMING_RTL (decl
))
5285 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5287 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5288 NOTE_VAR_LOCATION_LOC (loc_note
))
5289 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5290 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5292 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5293 temp
->first
->next
= loc
;
5295 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5297 else if (temp
->last
)
5299 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5300 rtx
*piece_loc
= NULL
, last_loc_note
;
5301 HOST_WIDE_INT piece_bitpos
= 0;
5305 gcc_assert (last
->next
== NULL
);
5307 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5309 piece_loc
= &last
->loc
;
5312 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5313 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5315 piece_bitpos
+= cur_bitsize
;
5316 piece_loc
= &XEXP (*piece_loc
, 1);
5320 /* TEMP->LAST here is either pointer to the last but one or
5321 last element in the chained list, LAST is pointer to the
5323 if (label
&& strcmp (last
->label
, label
) == 0)
5325 /* For SRA optimized variables if there weren't any real
5326 insns since last note, just modify the last node. */
5327 if (piece_loc
!= NULL
)
5329 adjust_piece_list (piece_loc
, NULL
, NULL
,
5330 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5333 /* If the last note doesn't cover any instructions, remove it. */
5334 if (temp
->last
!= last
)
5336 temp
->last
->next
= NULL
;
5339 gcc_assert (strcmp (last
->label
, label
) != 0);
5343 gcc_assert (temp
->first
== temp
->last
5344 || (temp
->first
->next
== temp
->last
5345 && TREE_CODE (decl
) == PARM_DECL
));
5346 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5347 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5351 if (bitsize
== -1 && NOTE_P (last
->loc
))
5352 last_loc_note
= last
->loc
;
5353 else if (piece_loc
!= NULL
5354 && *piece_loc
!= NULL_RTX
5355 && piece_bitpos
== bitpos
5356 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5357 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5359 last_loc_note
= NULL_RTX
;
5360 /* If the current location is the same as the end of the list,
5361 and either both or neither of the locations is uninitialized,
5362 we have nothing to do. */
5363 if (last_loc_note
== NULL_RTX
5364 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5365 NOTE_VAR_LOCATION_LOC (loc_note
)))
5366 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5367 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5368 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5369 == VAR_INIT_STATUS_UNINITIALIZED
)
5370 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5371 == VAR_INIT_STATUS_UNINITIALIZED
))))
5373 /* Add LOC to the end of list and update LAST. If the last
5374 element of the list has been removed above, reuse its
5375 memory for the new node, otherwise allocate a new one. */
5379 memset (loc
, '\0', sizeof (*loc
));
5382 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5383 if (bitsize
== -1 || piece_loc
== NULL
)
5384 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5386 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5387 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5389 /* Ensure TEMP->LAST will point either to the new last but one
5390 element of the chain, or to the last element in it. */
5391 if (last
!= temp
->last
)
5399 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5402 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5407 /* Keep track of the number of spaces used to indent the
5408 output of the debugging routines that print the structure of
5409 the DIE internal representation. */
5410 static int print_indent
;
5412 /* Indent the line the number of spaces given by print_indent. */
5415 print_spaces (FILE *outfile
)
5417 fprintf (outfile
, "%*s", print_indent
, "");
5420 /* Print a type signature in hex. */
5423 print_signature (FILE *outfile
, char *sig
)
5427 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5428 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5431 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
5433 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5434 RECURSE, output location descriptor operations. */
5437 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
5439 switch (val
->val_class
)
5441 case dw_val_class_addr
:
5442 fprintf (outfile
, "address");
5444 case dw_val_class_offset
:
5445 fprintf (outfile
, "offset");
5447 case dw_val_class_loc
:
5448 fprintf (outfile
, "location descriptor");
5449 if (val
->v
.val_loc
== NULL
)
5450 fprintf (outfile
, " -> <null>\n");
5453 fprintf (outfile
, ":\n");
5455 print_loc_descr (val
->v
.val_loc
, outfile
);
5459 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
5461 case dw_val_class_loc_list
:
5462 fprintf (outfile
, "location list -> label:%s",
5463 val
->v
.val_loc_list
->ll_symbol
);
5465 case dw_val_class_range_list
:
5466 fprintf (outfile
, "range list");
5468 case dw_val_class_const
:
5469 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
5471 case dw_val_class_unsigned_const
:
5472 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
5474 case dw_val_class_const_double
:
5475 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
5476 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5477 val
->v
.val_double
.high
,
5478 val
->v
.val_double
.low
);
5480 case dw_val_class_wide_int
:
5482 int i
= val
->v
.val_wide
->get_len ();
5483 fprintf (outfile
, "constant (");
5485 if (val
->v
.val_wide
->elt (i
- 1) == 0)
5486 fprintf (outfile
, "0x");
5487 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5488 val
->v
.val_wide
->elt (--i
));
5490 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5491 val
->v
.val_wide
->elt (i
));
5492 fprintf (outfile
, ")");
5495 case dw_val_class_vec
:
5496 fprintf (outfile
, "floating-point or vector constant");
5498 case dw_val_class_flag
:
5499 fprintf (outfile
, "%u", val
->v
.val_flag
);
5501 case dw_val_class_die_ref
:
5502 if (val
->v
.val_die_ref
.die
!= NULL
)
5504 dw_die_ref die
= val
->v
.val_die_ref
.die
;
5506 if (die
->comdat_type_p
)
5508 fprintf (outfile
, "die -> signature: ");
5509 print_signature (outfile
,
5510 die
->die_id
.die_type_node
->signature
);
5512 else if (die
->die_id
.die_symbol
)
5513 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
5515 fprintf (outfile
, "die -> %ld", die
->die_offset
);
5516 fprintf (outfile
, " (%p)", (void *) die
);
5519 fprintf (outfile
, "die -> <null>");
5521 case dw_val_class_vms_delta
:
5522 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5523 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
5525 case dw_val_class_lbl_id
:
5526 case dw_val_class_lineptr
:
5527 case dw_val_class_macptr
:
5528 case dw_val_class_high_pc
:
5529 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
5531 case dw_val_class_str
:
5532 if (val
->v
.val_str
->str
!= NULL
)
5533 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
5535 fprintf (outfile
, "<null>");
5537 case dw_val_class_file
:
5538 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
5539 val
->v
.val_file
->emitted_number
);
5541 case dw_val_class_data8
:
5545 for (i
= 0; i
< 8; i
++)
5546 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
5554 /* Likewise, for a DIE attribute. */
5557 print_attribute (dw_attr_ref a
, bool recurse
, FILE *outfile
)
5559 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
5563 /* Print the list of operands in the LOC location description to OUTFILE. This
5564 routine is a debugging aid only. */
5567 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
5569 dw_loc_descr_ref l
= loc
;
5573 print_spaces (outfile
);
5574 fprintf (outfile
, "<null>\n");
5578 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5580 print_spaces (outfile
);
5581 fprintf (outfile
, "(%p) %s",
5583 dwarf_stack_op_name (l
->dw_loc_opc
));
5584 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
5586 fprintf (outfile
, " ");
5587 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
5589 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
5591 fprintf (outfile
, ", ");
5592 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
5594 fprintf (outfile
, "\n");
5598 /* Print the information associated with a given DIE, and its children.
5599 This routine is a debugging aid only. */
5602 print_die (dw_die_ref die
, FILE *outfile
)
5608 print_spaces (outfile
);
5609 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5610 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5612 print_spaces (outfile
);
5613 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5614 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5615 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5617 if (die
->comdat_type_p
)
5619 print_spaces (outfile
);
5620 fprintf (outfile
, " signature: ");
5621 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5622 fprintf (outfile
, "\n");
5625 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5627 print_spaces (outfile
);
5628 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5630 print_attribute (a
, true, outfile
);
5631 fprintf (outfile
, "\n");
5634 if (die
->die_child
!= NULL
)
5637 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5640 if (print_indent
== 0)
5641 fprintf (outfile
, "\n");
5644 /* Print the list of operations in the LOC location description. */
5647 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
5649 print_loc_descr (loc
, stderr
);
5652 /* Print the information collected for a given DIE. */
5655 debug_dwarf_die (dw_die_ref die
)
5657 print_die (die
, stderr
);
5661 debug (die_struct
&ref
)
5663 print_die (&ref
, stderr
);
5667 debug (die_struct
*ptr
)
5672 fprintf (stderr
, "<nil>\n");
5676 /* Print all DWARF information collected for the compilation unit.
5677 This routine is a debugging aid only. */
5683 print_die (comp_unit_die (), stderr
);
5686 #ifdef ENABLE_CHECKING
5687 /* Sanity checks on DIEs. */
5690 check_die (dw_die_ref die
)
5694 bool inline_found
= false;
5695 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
5696 int n_decl_line
= 0, n_decl_file
= 0;
5697 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5702 if (a
->dw_attr_val
.v
.val_unsigned
)
5703 inline_found
= true;
5705 case DW_AT_location
:
5714 case DW_AT_artificial
:
5717 case DW_AT_decl_line
:
5720 case DW_AT_decl_file
:
5727 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
5728 || n_decl_line
> 1 || n_decl_file
> 1)
5730 fprintf (stderr
, "Duplicate attributes in DIE:\n");
5731 debug_dwarf_die (die
);
5736 /* A debugging information entry that is a member of an abstract
5737 instance tree [that has DW_AT_inline] should not contain any
5738 attributes which describe aspects of the subroutine which vary
5739 between distinct inlined expansions or distinct out-of-line
5741 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5742 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
5743 && a
->dw_attr
!= DW_AT_high_pc
5744 && a
->dw_attr
!= DW_AT_location
5745 && a
->dw_attr
!= DW_AT_frame_base
5746 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
5751 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5752 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5753 DIE that marks the start of the DIEs for this include file. */
5756 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5758 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5759 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5761 new_unit
->die_sib
= old_unit
;
5765 /* Close an include-file CU and reopen the enclosing one. */
5768 pop_compile_unit (dw_die_ref old_unit
)
5770 dw_die_ref new_unit
= old_unit
->die_sib
;
5772 old_unit
->die_sib
= NULL
;
5776 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5777 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5778 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5780 /* Calculate the checksum of a location expression. */
5783 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5786 inchash::hash hstate
;
5789 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5791 hash_loc_operands (loc
, hstate
);
5792 hash
= hstate
.end();
5796 /* Calculate the checksum of an attribute. */
5799 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5801 dw_loc_descr_ref loc
;
5804 CHECKSUM (at
->dw_attr
);
5806 /* We don't care that this was compiled with a different compiler
5807 snapshot; if the output is the same, that's what matters. */
5808 if (at
->dw_attr
== DW_AT_producer
)
5811 switch (AT_class (at
))
5813 case dw_val_class_const
:
5814 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5816 case dw_val_class_unsigned_const
:
5817 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5819 case dw_val_class_const_double
:
5820 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5822 case dw_val_class_wide_int
:
5823 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
5824 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
5825 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
5827 case dw_val_class_vec
:
5828 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5829 (at
->dw_attr_val
.v
.val_vec
.length
5830 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5832 case dw_val_class_flag
:
5833 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5835 case dw_val_class_str
:
5836 CHECKSUM_STRING (AT_string (at
));
5839 case dw_val_class_addr
:
5841 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5842 CHECKSUM_STRING (XSTR (r
, 0));
5845 case dw_val_class_offset
:
5846 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5849 case dw_val_class_loc
:
5850 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5851 loc_checksum (loc
, ctx
);
5854 case dw_val_class_die_ref
:
5855 die_checksum (AT_ref (at
), ctx
, mark
);
5858 case dw_val_class_fde_ref
:
5859 case dw_val_class_vms_delta
:
5860 case dw_val_class_lbl_id
:
5861 case dw_val_class_lineptr
:
5862 case dw_val_class_macptr
:
5863 case dw_val_class_high_pc
:
5866 case dw_val_class_file
:
5867 CHECKSUM_STRING (AT_file (at
)->filename
);
5870 case dw_val_class_data8
:
5871 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5879 /* Calculate the checksum of a DIE. */
5882 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5888 /* To avoid infinite recursion. */
5891 CHECKSUM (die
->die_mark
);
5894 die
->die_mark
= ++(*mark
);
5896 CHECKSUM (die
->die_tag
);
5898 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5899 attr_checksum (a
, ctx
, mark
);
5901 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5905 #undef CHECKSUM_BLOCK
5906 #undef CHECKSUM_STRING
5908 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5909 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5910 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5911 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5912 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5913 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5914 #define CHECKSUM_ATTR(FOO) \
5915 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5917 /* Calculate the checksum of a number in signed LEB128 format. */
5920 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5927 byte
= (value
& 0x7f);
5929 more
= !((value
== 0 && (byte
& 0x40) == 0)
5930 || (value
== -1 && (byte
& 0x40) != 0));
5939 /* Calculate the checksum of a number in unsigned LEB128 format. */
5942 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5946 unsigned char byte
= (value
& 0x7f);
5949 /* More bytes to follow. */
5957 /* Checksum the context of the DIE. This adds the names of any
5958 surrounding namespaces or structures to the checksum. */
5961 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5965 int tag
= die
->die_tag
;
5967 if (tag
!= DW_TAG_namespace
5968 && tag
!= DW_TAG_structure_type
5969 && tag
!= DW_TAG_class_type
)
5972 name
= get_AT_string (die
, DW_AT_name
);
5974 spec
= get_AT_ref (die
, DW_AT_specification
);
5978 if (die
->die_parent
!= NULL
)
5979 checksum_die_context (die
->die_parent
, ctx
);
5981 CHECKSUM_ULEB128 ('C');
5982 CHECKSUM_ULEB128 (tag
);
5984 CHECKSUM_STRING (name
);
5987 /* Calculate the checksum of a location expression. */
5990 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5992 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5993 were emitted as a DW_FORM_sdata instead of a location expression. */
5994 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5996 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5997 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
6001 /* Otherwise, just checksum the raw location expression. */
6004 inchash::hash hstate
;
6007 CHECKSUM_ULEB128 (loc
->dtprel
);
6008 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6009 hash_loc_operands (loc
, hstate
);
6010 hash
= hstate
.end ();
6012 loc
= loc
->dw_loc_next
;
6016 /* Calculate the checksum of an attribute. */
6019 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
6020 struct md5_ctx
*ctx
, int *mark
)
6022 dw_loc_descr_ref loc
;
6025 if (AT_class (at
) == dw_val_class_die_ref
)
6027 dw_die_ref target_die
= AT_ref (at
);
6029 /* For pointer and reference types, we checksum only the (qualified)
6030 name of the target type (if there is a name). For friend entries,
6031 we checksum only the (qualified) name of the target type or function.
6032 This allows the checksum to remain the same whether the target type
6033 is complete or not. */
6034 if ((at
->dw_attr
== DW_AT_type
6035 && (tag
== DW_TAG_pointer_type
6036 || tag
== DW_TAG_reference_type
6037 || tag
== DW_TAG_rvalue_reference_type
6038 || tag
== DW_TAG_ptr_to_member_type
))
6039 || (at
->dw_attr
== DW_AT_friend
6040 && tag
== DW_TAG_friend
))
6042 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
6044 if (name_attr
!= NULL
)
6046 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6050 CHECKSUM_ULEB128 ('N');
6051 CHECKSUM_ULEB128 (at
->dw_attr
);
6052 if (decl
->die_parent
!= NULL
)
6053 checksum_die_context (decl
->die_parent
, ctx
);
6054 CHECKSUM_ULEB128 ('E');
6055 CHECKSUM_STRING (AT_string (name_attr
));
6060 /* For all other references to another DIE, we check to see if the
6061 target DIE has already been visited. If it has, we emit a
6062 backward reference; if not, we descend recursively. */
6063 if (target_die
->die_mark
> 0)
6065 CHECKSUM_ULEB128 ('R');
6066 CHECKSUM_ULEB128 (at
->dw_attr
);
6067 CHECKSUM_ULEB128 (target_die
->die_mark
);
6071 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6075 target_die
->die_mark
= ++(*mark
);
6076 CHECKSUM_ULEB128 ('T');
6077 CHECKSUM_ULEB128 (at
->dw_attr
);
6078 if (decl
->die_parent
!= NULL
)
6079 checksum_die_context (decl
->die_parent
, ctx
);
6080 die_checksum_ordered (target_die
, ctx
, mark
);
6085 CHECKSUM_ULEB128 ('A');
6086 CHECKSUM_ULEB128 (at
->dw_attr
);
6088 switch (AT_class (at
))
6090 case dw_val_class_const
:
6091 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6092 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6095 case dw_val_class_unsigned_const
:
6096 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6097 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6100 case dw_val_class_const_double
:
6101 CHECKSUM_ULEB128 (DW_FORM_block
);
6102 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6103 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6106 case dw_val_class_wide_int
:
6107 CHECKSUM_ULEB128 (DW_FORM_block
);
6108 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6109 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6110 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6111 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6112 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6115 case dw_val_class_vec
:
6116 CHECKSUM_ULEB128 (DW_FORM_block
);
6117 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6118 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6119 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6120 (at
->dw_attr_val
.v
.val_vec
.length
6121 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6124 case dw_val_class_flag
:
6125 CHECKSUM_ULEB128 (DW_FORM_flag
);
6126 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6129 case dw_val_class_str
:
6130 CHECKSUM_ULEB128 (DW_FORM_string
);
6131 CHECKSUM_STRING (AT_string (at
));
6134 case dw_val_class_addr
:
6136 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6137 CHECKSUM_ULEB128 (DW_FORM_string
);
6138 CHECKSUM_STRING (XSTR (r
, 0));
6141 case dw_val_class_offset
:
6142 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6143 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6146 case dw_val_class_loc
:
6147 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6148 loc_checksum_ordered (loc
, ctx
);
6151 case dw_val_class_fde_ref
:
6152 case dw_val_class_lbl_id
:
6153 case dw_val_class_lineptr
:
6154 case dw_val_class_macptr
:
6155 case dw_val_class_high_pc
:
6158 case dw_val_class_file
:
6159 CHECKSUM_ULEB128 (DW_FORM_string
);
6160 CHECKSUM_STRING (AT_file (at
)->filename
);
6163 case dw_val_class_data8
:
6164 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6172 struct checksum_attributes
6174 dw_attr_ref at_name
;
6175 dw_attr_ref at_type
;
6176 dw_attr_ref at_friend
;
6177 dw_attr_ref at_accessibility
;
6178 dw_attr_ref at_address_class
;
6179 dw_attr_ref at_allocated
;
6180 dw_attr_ref at_artificial
;
6181 dw_attr_ref at_associated
;
6182 dw_attr_ref at_binary_scale
;
6183 dw_attr_ref at_bit_offset
;
6184 dw_attr_ref at_bit_size
;
6185 dw_attr_ref at_bit_stride
;
6186 dw_attr_ref at_byte_size
;
6187 dw_attr_ref at_byte_stride
;
6188 dw_attr_ref at_const_value
;
6189 dw_attr_ref at_containing_type
;
6190 dw_attr_ref at_count
;
6191 dw_attr_ref at_data_location
;
6192 dw_attr_ref at_data_member_location
;
6193 dw_attr_ref at_decimal_scale
;
6194 dw_attr_ref at_decimal_sign
;
6195 dw_attr_ref at_default_value
;
6196 dw_attr_ref at_digit_count
;
6197 dw_attr_ref at_discr
;
6198 dw_attr_ref at_discr_list
;
6199 dw_attr_ref at_discr_value
;
6200 dw_attr_ref at_encoding
;
6201 dw_attr_ref at_endianity
;
6202 dw_attr_ref at_explicit
;
6203 dw_attr_ref at_is_optional
;
6204 dw_attr_ref at_location
;
6205 dw_attr_ref at_lower_bound
;
6206 dw_attr_ref at_mutable
;
6207 dw_attr_ref at_ordering
;
6208 dw_attr_ref at_picture_string
;
6209 dw_attr_ref at_prototyped
;
6210 dw_attr_ref at_small
;
6211 dw_attr_ref at_segment
;
6212 dw_attr_ref at_string_length
;
6213 dw_attr_ref at_threads_scaled
;
6214 dw_attr_ref at_upper_bound
;
6215 dw_attr_ref at_use_location
;
6216 dw_attr_ref at_use_UTF8
;
6217 dw_attr_ref at_variable_parameter
;
6218 dw_attr_ref at_virtuality
;
6219 dw_attr_ref at_visibility
;
6220 dw_attr_ref at_vtable_elem_location
;
6223 /* Collect the attributes that we will want to use for the checksum. */
6226 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6231 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6242 attrs
->at_friend
= a
;
6244 case DW_AT_accessibility
:
6245 attrs
->at_accessibility
= a
;
6247 case DW_AT_address_class
:
6248 attrs
->at_address_class
= a
;
6250 case DW_AT_allocated
:
6251 attrs
->at_allocated
= a
;
6253 case DW_AT_artificial
:
6254 attrs
->at_artificial
= a
;
6256 case DW_AT_associated
:
6257 attrs
->at_associated
= a
;
6259 case DW_AT_binary_scale
:
6260 attrs
->at_binary_scale
= a
;
6262 case DW_AT_bit_offset
:
6263 attrs
->at_bit_offset
= a
;
6265 case DW_AT_bit_size
:
6266 attrs
->at_bit_size
= a
;
6268 case DW_AT_bit_stride
:
6269 attrs
->at_bit_stride
= a
;
6271 case DW_AT_byte_size
:
6272 attrs
->at_byte_size
= a
;
6274 case DW_AT_byte_stride
:
6275 attrs
->at_byte_stride
= a
;
6277 case DW_AT_const_value
:
6278 attrs
->at_const_value
= a
;
6280 case DW_AT_containing_type
:
6281 attrs
->at_containing_type
= a
;
6284 attrs
->at_count
= a
;
6286 case DW_AT_data_location
:
6287 attrs
->at_data_location
= a
;
6289 case DW_AT_data_member_location
:
6290 attrs
->at_data_member_location
= a
;
6292 case DW_AT_decimal_scale
:
6293 attrs
->at_decimal_scale
= a
;
6295 case DW_AT_decimal_sign
:
6296 attrs
->at_decimal_sign
= a
;
6298 case DW_AT_default_value
:
6299 attrs
->at_default_value
= a
;
6301 case DW_AT_digit_count
:
6302 attrs
->at_digit_count
= a
;
6305 attrs
->at_discr
= a
;
6307 case DW_AT_discr_list
:
6308 attrs
->at_discr_list
= a
;
6310 case DW_AT_discr_value
:
6311 attrs
->at_discr_value
= a
;
6313 case DW_AT_encoding
:
6314 attrs
->at_encoding
= a
;
6316 case DW_AT_endianity
:
6317 attrs
->at_endianity
= a
;
6319 case DW_AT_explicit
:
6320 attrs
->at_explicit
= a
;
6322 case DW_AT_is_optional
:
6323 attrs
->at_is_optional
= a
;
6325 case DW_AT_location
:
6326 attrs
->at_location
= a
;
6328 case DW_AT_lower_bound
:
6329 attrs
->at_lower_bound
= a
;
6332 attrs
->at_mutable
= a
;
6334 case DW_AT_ordering
:
6335 attrs
->at_ordering
= a
;
6337 case DW_AT_picture_string
:
6338 attrs
->at_picture_string
= a
;
6340 case DW_AT_prototyped
:
6341 attrs
->at_prototyped
= a
;
6344 attrs
->at_small
= a
;
6347 attrs
->at_segment
= a
;
6349 case DW_AT_string_length
:
6350 attrs
->at_string_length
= a
;
6352 case DW_AT_threads_scaled
:
6353 attrs
->at_threads_scaled
= a
;
6355 case DW_AT_upper_bound
:
6356 attrs
->at_upper_bound
= a
;
6358 case DW_AT_use_location
:
6359 attrs
->at_use_location
= a
;
6361 case DW_AT_use_UTF8
:
6362 attrs
->at_use_UTF8
= a
;
6364 case DW_AT_variable_parameter
:
6365 attrs
->at_variable_parameter
= a
;
6367 case DW_AT_virtuality
:
6368 attrs
->at_virtuality
= a
;
6370 case DW_AT_visibility
:
6371 attrs
->at_visibility
= a
;
6373 case DW_AT_vtable_elem_location
:
6374 attrs
->at_vtable_elem_location
= a
;
6382 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6385 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6389 struct checksum_attributes attrs
;
6391 CHECKSUM_ULEB128 ('D');
6392 CHECKSUM_ULEB128 (die
->die_tag
);
6394 memset (&attrs
, 0, sizeof (attrs
));
6396 decl
= get_AT_ref (die
, DW_AT_specification
);
6398 collect_checksum_attributes (&attrs
, decl
);
6399 collect_checksum_attributes (&attrs
, die
);
6401 CHECKSUM_ATTR (attrs
.at_name
);
6402 CHECKSUM_ATTR (attrs
.at_accessibility
);
6403 CHECKSUM_ATTR (attrs
.at_address_class
);
6404 CHECKSUM_ATTR (attrs
.at_allocated
);
6405 CHECKSUM_ATTR (attrs
.at_artificial
);
6406 CHECKSUM_ATTR (attrs
.at_associated
);
6407 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6408 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6409 CHECKSUM_ATTR (attrs
.at_bit_size
);
6410 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6411 CHECKSUM_ATTR (attrs
.at_byte_size
);
6412 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6413 CHECKSUM_ATTR (attrs
.at_const_value
);
6414 CHECKSUM_ATTR (attrs
.at_containing_type
);
6415 CHECKSUM_ATTR (attrs
.at_count
);
6416 CHECKSUM_ATTR (attrs
.at_data_location
);
6417 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6418 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6419 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6420 CHECKSUM_ATTR (attrs
.at_default_value
);
6421 CHECKSUM_ATTR (attrs
.at_digit_count
);
6422 CHECKSUM_ATTR (attrs
.at_discr
);
6423 CHECKSUM_ATTR (attrs
.at_discr_list
);
6424 CHECKSUM_ATTR (attrs
.at_discr_value
);
6425 CHECKSUM_ATTR (attrs
.at_encoding
);
6426 CHECKSUM_ATTR (attrs
.at_endianity
);
6427 CHECKSUM_ATTR (attrs
.at_explicit
);
6428 CHECKSUM_ATTR (attrs
.at_is_optional
);
6429 CHECKSUM_ATTR (attrs
.at_location
);
6430 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6431 CHECKSUM_ATTR (attrs
.at_mutable
);
6432 CHECKSUM_ATTR (attrs
.at_ordering
);
6433 CHECKSUM_ATTR (attrs
.at_picture_string
);
6434 CHECKSUM_ATTR (attrs
.at_prototyped
);
6435 CHECKSUM_ATTR (attrs
.at_small
);
6436 CHECKSUM_ATTR (attrs
.at_segment
);
6437 CHECKSUM_ATTR (attrs
.at_string_length
);
6438 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6439 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6440 CHECKSUM_ATTR (attrs
.at_use_location
);
6441 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6442 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6443 CHECKSUM_ATTR (attrs
.at_virtuality
);
6444 CHECKSUM_ATTR (attrs
.at_visibility
);
6445 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6446 CHECKSUM_ATTR (attrs
.at_type
);
6447 CHECKSUM_ATTR (attrs
.at_friend
);
6449 /* Checksum the child DIEs. */
6452 dw_attr_ref name_attr
;
6455 name_attr
= get_AT (c
, DW_AT_name
);
6456 if (is_template_instantiation (c
))
6458 /* Ignore instantiations of member type and function templates. */
6460 else if (name_attr
!= NULL
6461 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6463 /* Use a shallow checksum for named nested types and member
6465 CHECKSUM_ULEB128 ('S');
6466 CHECKSUM_ULEB128 (c
->die_tag
);
6467 CHECKSUM_STRING (AT_string (name_attr
));
6471 /* Use a deep checksum for other children. */
6472 /* Mark this DIE so it gets processed when unmarking. */
6473 if (c
->die_mark
== 0)
6475 die_checksum_ordered (c
, ctx
, mark
);
6477 } while (c
!= die
->die_child
);
6479 CHECKSUM_ULEB128 (0);
6482 /* Add a type name and tag to a hash. */
6484 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6486 CHECKSUM_ULEB128 (tag
);
6487 CHECKSUM_STRING (name
);
6491 #undef CHECKSUM_STRING
6492 #undef CHECKSUM_ATTR
6493 #undef CHECKSUM_LEB128
6494 #undef CHECKSUM_ULEB128
6496 /* Generate the type signature for DIE. This is computed by generating an
6497 MD5 checksum over the DIE's tag, its relevant attributes, and its
6498 children. Attributes that are references to other DIEs are processed
6499 by recursion, using the MARK field to prevent infinite recursion.
6500 If the DIE is nested inside a namespace or another type, we also
6501 need to include that context in the signature. The lower 64 bits
6502 of the resulting MD5 checksum comprise the signature. */
6505 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6509 unsigned char checksum
[16];
6514 name
= get_AT_string (die
, DW_AT_name
);
6515 decl
= get_AT_ref (die
, DW_AT_specification
);
6516 parent
= get_die_parent (die
);
6518 /* First, compute a signature for just the type name (and its surrounding
6519 context, if any. This is stored in the type unit DIE for link-time
6520 ODR (one-definition rule) checking. */
6522 if (is_cxx () && name
!= NULL
)
6524 md5_init_ctx (&ctx
);
6526 /* Checksum the names of surrounding namespaces and structures. */
6528 checksum_die_context (parent
, &ctx
);
6530 /* Checksum the current DIE. */
6531 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6532 md5_finish_ctx (&ctx
, checksum
);
6534 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6537 /* Next, compute the complete type signature. */
6539 md5_init_ctx (&ctx
);
6541 die
->die_mark
= mark
;
6543 /* Checksum the names of surrounding namespaces and structures. */
6545 checksum_die_context (parent
, &ctx
);
6547 /* Checksum the DIE and its children. */
6548 die_checksum_ordered (die
, &ctx
, &mark
);
6549 unmark_all_dies (die
);
6550 md5_finish_ctx (&ctx
, checksum
);
6552 /* Store the signature in the type node and link the type DIE and the
6553 type node together. */
6554 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6555 DWARF_TYPE_SIGNATURE_SIZE
);
6556 die
->comdat_type_p
= true;
6557 die
->die_id
.die_type_node
= type_node
;
6558 type_node
->type_die
= die
;
6560 /* If the DIE is a specification, link its declaration to the type node
6564 decl
->comdat_type_p
= true;
6565 decl
->die_id
.die_type_node
= type_node
;
6569 /* Do the location expressions look same? */
6571 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6573 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6574 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6575 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6578 /* Do the values look the same? */
6580 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6582 dw_loc_descr_ref loc1
, loc2
;
6585 if (v1
->val_class
!= v2
->val_class
)
6588 switch (v1
->val_class
)
6590 case dw_val_class_const
:
6591 return v1
->v
.val_int
== v2
->v
.val_int
;
6592 case dw_val_class_unsigned_const
:
6593 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6594 case dw_val_class_const_double
:
6595 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6596 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6597 case dw_val_class_wide_int
:
6598 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
6599 case dw_val_class_vec
:
6600 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6601 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6603 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6604 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6607 case dw_val_class_flag
:
6608 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6609 case dw_val_class_str
:
6610 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6612 case dw_val_class_addr
:
6613 r1
= v1
->v
.val_addr
;
6614 r2
= v2
->v
.val_addr
;
6615 if (GET_CODE (r1
) != GET_CODE (r2
))
6617 return !rtx_equal_p (r1
, r2
);
6619 case dw_val_class_offset
:
6620 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6622 case dw_val_class_loc
:
6623 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6625 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6626 if (!same_loc_p (loc1
, loc2
, mark
))
6628 return !loc1
&& !loc2
;
6630 case dw_val_class_die_ref
:
6631 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6633 case dw_val_class_fde_ref
:
6634 case dw_val_class_vms_delta
:
6635 case dw_val_class_lbl_id
:
6636 case dw_val_class_lineptr
:
6637 case dw_val_class_macptr
:
6638 case dw_val_class_high_pc
:
6641 case dw_val_class_file
:
6642 return v1
->v
.val_file
== v2
->v
.val_file
;
6644 case dw_val_class_data8
:
6645 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6652 /* Do the attributes look the same? */
6655 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6657 if (at1
->dw_attr
!= at2
->dw_attr
)
6660 /* We don't care that this was compiled with a different compiler
6661 snapshot; if the output is the same, that's what matters. */
6662 if (at1
->dw_attr
== DW_AT_producer
)
6665 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6668 /* Do the dies look the same? */
6671 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6677 /* To avoid infinite recursion. */
6679 return die1
->die_mark
== die2
->die_mark
;
6680 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6682 if (die1
->die_tag
!= die2
->die_tag
)
6685 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6688 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6689 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6692 c1
= die1
->die_child
;
6693 c2
= die2
->die_child
;
6702 if (!same_die_p (c1
, c2
, mark
))
6706 if (c1
== die1
->die_child
)
6708 if (c2
== die2
->die_child
)
6718 /* Do the dies look the same? Wrapper around same_die_p. */
6721 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6724 int ret
= same_die_p (die1
, die2
, &mark
);
6726 unmark_all_dies (die1
);
6727 unmark_all_dies (die2
);
6732 /* The prefix to attach to symbols on DIEs in the current comdat debug
6734 static const char *comdat_symbol_id
;
6736 /* The index of the current symbol within the current comdat CU. */
6737 static unsigned int comdat_symbol_number
;
6739 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6740 children, and set comdat_symbol_id accordingly. */
6743 compute_section_prefix (dw_die_ref unit_die
)
6745 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6746 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6747 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6750 unsigned char checksum
[16];
6753 /* Compute the checksum of the DIE, then append part of it as hex digits to
6754 the name filename of the unit. */
6756 md5_init_ctx (&ctx
);
6758 die_checksum (unit_die
, &ctx
, &mark
);
6759 unmark_all_dies (unit_die
);
6760 md5_finish_ctx (&ctx
, checksum
);
6762 sprintf (name
, "%s.", base
);
6763 clean_symbol_name (name
);
6765 p
= name
+ strlen (name
);
6766 for (i
= 0; i
< 4; i
++)
6768 sprintf (p
, "%.2x", checksum
[i
]);
6772 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6773 comdat_symbol_number
= 0;
6776 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6779 is_type_die (dw_die_ref die
)
6781 switch (die
->die_tag
)
6783 case DW_TAG_array_type
:
6784 case DW_TAG_class_type
:
6785 case DW_TAG_interface_type
:
6786 case DW_TAG_enumeration_type
:
6787 case DW_TAG_pointer_type
:
6788 case DW_TAG_reference_type
:
6789 case DW_TAG_rvalue_reference_type
:
6790 case DW_TAG_string_type
:
6791 case DW_TAG_structure_type
:
6792 case DW_TAG_subroutine_type
:
6793 case DW_TAG_union_type
:
6794 case DW_TAG_ptr_to_member_type
:
6795 case DW_TAG_set_type
:
6796 case DW_TAG_subrange_type
:
6797 case DW_TAG_base_type
:
6798 case DW_TAG_const_type
:
6799 case DW_TAG_file_type
:
6800 case DW_TAG_packed_type
:
6801 case DW_TAG_volatile_type
:
6802 case DW_TAG_typedef
:
6809 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6810 Basically, we want to choose the bits that are likely to be shared between
6811 compilations (types) and leave out the bits that are specific to individual
6812 compilations (functions). */
6815 is_comdat_die (dw_die_ref c
)
6817 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6818 we do for stabs. The advantage is a greater likelihood of sharing between
6819 objects that don't include headers in the same order (and therefore would
6820 put the base types in a different comdat). jason 8/28/00 */
6822 if (c
->die_tag
== DW_TAG_base_type
)
6825 if (c
->die_tag
== DW_TAG_pointer_type
6826 || c
->die_tag
== DW_TAG_reference_type
6827 || c
->die_tag
== DW_TAG_rvalue_reference_type
6828 || c
->die_tag
== DW_TAG_const_type
6829 || c
->die_tag
== DW_TAG_volatile_type
)
6831 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6833 return t
? is_comdat_die (t
) : 0;
6836 return is_type_die (c
);
6839 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6840 compilation unit. */
6843 is_symbol_die (dw_die_ref c
)
6845 return (is_type_die (c
)
6846 || is_declaration_die (c
)
6847 || c
->die_tag
== DW_TAG_namespace
6848 || c
->die_tag
== DW_TAG_module
);
6851 /* Returns true iff C is a compile-unit DIE. */
6854 is_cu_die (dw_die_ref c
)
6856 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6859 /* Returns true iff C is a unit DIE of some sort. */
6862 is_unit_die (dw_die_ref c
)
6864 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6865 || c
->die_tag
== DW_TAG_partial_unit
6866 || c
->die_tag
== DW_TAG_type_unit
);
6869 /* Returns true iff C is a namespace DIE. */
6872 is_namespace_die (dw_die_ref c
)
6874 return c
&& c
->die_tag
== DW_TAG_namespace
;
6877 /* Returns true iff C is a class or structure DIE. */
6880 is_class_die (dw_die_ref c
)
6882 return c
&& (c
->die_tag
== DW_TAG_class_type
6883 || c
->die_tag
== DW_TAG_structure_type
);
6886 /* Return non-zero if this DIE is a template parameter. */
6889 is_template_parameter (dw_die_ref die
)
6891 switch (die
->die_tag
)
6893 case DW_TAG_template_type_param
:
6894 case DW_TAG_template_value_param
:
6895 case DW_TAG_GNU_template_template_param
:
6896 case DW_TAG_GNU_template_parameter_pack
:
6903 /* Return non-zero if this DIE represents a template instantiation. */
6906 is_template_instantiation (dw_die_ref die
)
6910 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6912 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6917 gen_internal_sym (const char *prefix
)
6921 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6922 return xstrdup (buf
);
6925 /* Assign symbols to all worthy DIEs under DIE. */
6928 assign_symbol_names (dw_die_ref die
)
6932 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6934 if (comdat_symbol_id
)
6936 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6938 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6939 comdat_symbol_id
, comdat_symbol_number
++);
6940 die
->die_id
.die_symbol
= xstrdup (p
);
6943 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6946 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6949 struct cu_hash_table_entry
6952 unsigned min_comdat_num
, max_comdat_num
;
6953 struct cu_hash_table_entry
*next
;
6956 /* Helpers to manipulate hash table of CUs. */
6958 struct cu_hash_table_entry_hasher
: pointer_hash
<cu_hash_table_entry
>
6960 typedef die_struct
*compare_type
;
6961 static inline hashval_t
hash (const cu_hash_table_entry
*);
6962 static inline bool equal (const cu_hash_table_entry
*, const die_struct
*);
6963 static inline void remove (cu_hash_table_entry
*);
6967 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry
*entry
)
6969 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6973 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry
*entry1
,
6974 const die_struct
*entry2
)
6976 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6980 cu_hash_table_entry_hasher::remove (cu_hash_table_entry
*entry
)
6982 struct cu_hash_table_entry
*next
;
6992 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6994 /* Check whether we have already seen this CU and set up SYM_NUM
6997 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
6999 struct cu_hash_table_entry dummy
;
7000 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7002 dummy
.max_comdat_num
= 0;
7004 slot
= htable
->find_slot_with_hash (cu
,
7005 htab_hash_string (cu
->die_id
.die_symbol
),
7009 for (; entry
; last
= entry
, entry
= entry
->next
)
7011 if (same_die_p_wrap (cu
, entry
->cu
))
7017 *sym_num
= entry
->min_comdat_num
;
7021 entry
= XCNEW (struct cu_hash_table_entry
);
7023 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7024 entry
->next
= *slot
;
7030 /* Record SYM_NUM to record of CU in HTABLE. */
7032 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
7033 unsigned int sym_num
)
7035 struct cu_hash_table_entry
**slot
, *entry
;
7037 slot
= htable
->find_slot_with_hash (cu
,
7038 htab_hash_string (cu
->die_id
.die_symbol
),
7042 entry
->max_comdat_num
= sym_num
;
7045 /* Traverse the DIE (which is always comp_unit_die), and set up
7046 additional compilation units for each of the include files we see
7047 bracketed by BINCL/EINCL. */
7050 break_out_includes (dw_die_ref die
)
7053 dw_die_ref unit
= NULL
;
7054 limbo_die_node
*node
, **pnode
;
7058 dw_die_ref prev
= c
;
7060 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7061 || (unit
&& is_comdat_die (c
)))
7063 dw_die_ref next
= c
->die_sib
;
7065 /* This DIE is for a secondary CU; remove it from the main one. */
7066 remove_child_with_prev (c
, prev
);
7068 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7069 unit
= push_new_compile_unit (unit
, c
);
7070 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7071 unit
= pop_compile_unit (unit
);
7073 add_child_die (unit
, c
);
7075 if (c
== die
->die_child
)
7078 } while (c
!= die
->die_child
);
7081 /* We can only use this in debugging, since the frontend doesn't check
7082 to make sure that we leave every include file we enter. */
7086 assign_symbol_names (die
);
7087 cu_hash_type
cu_hash_table (10);
7088 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7094 compute_section_prefix (node
->die
);
7095 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
7096 &comdat_symbol_number
);
7097 assign_symbol_names (node
->die
);
7099 *pnode
= node
->next
;
7102 pnode
= &node
->next
;
7103 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
7104 comdat_symbol_number
);
7109 /* Return non-zero if this DIE is a declaration. */
7112 is_declaration_die (dw_die_ref die
)
7117 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7118 if (a
->dw_attr
== DW_AT_declaration
)
7124 /* Return non-zero if this DIE is nested inside a subprogram. */
7127 is_nested_in_subprogram (dw_die_ref die
)
7129 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7133 return local_scope_p (decl
);
7136 /* Return non-zero if this DIE contains a defining declaration of a
7140 contains_subprogram_definition (dw_die_ref die
)
7144 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7146 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7150 /* Return non-zero if this is a type DIE that should be moved to a
7151 COMDAT .debug_types section. */
7154 should_move_die_to_comdat (dw_die_ref die
)
7156 switch (die
->die_tag
)
7158 case DW_TAG_class_type
:
7159 case DW_TAG_structure_type
:
7160 case DW_TAG_enumeration_type
:
7161 case DW_TAG_union_type
:
7162 /* Don't move declarations, inlined instances, types nested in a
7163 subprogram, or types that contain subprogram definitions. */
7164 if (is_declaration_die (die
)
7165 || get_AT (die
, DW_AT_abstract_origin
)
7166 || is_nested_in_subprogram (die
)
7167 || contains_subprogram_definition (die
))
7170 case DW_TAG_array_type
:
7171 case DW_TAG_interface_type
:
7172 case DW_TAG_pointer_type
:
7173 case DW_TAG_reference_type
:
7174 case DW_TAG_rvalue_reference_type
:
7175 case DW_TAG_string_type
:
7176 case DW_TAG_subroutine_type
:
7177 case DW_TAG_ptr_to_member_type
:
7178 case DW_TAG_set_type
:
7179 case DW_TAG_subrange_type
:
7180 case DW_TAG_base_type
:
7181 case DW_TAG_const_type
:
7182 case DW_TAG_file_type
:
7183 case DW_TAG_packed_type
:
7184 case DW_TAG_volatile_type
:
7185 case DW_TAG_typedef
:
7191 /* Make a clone of DIE. */
7194 clone_die (dw_die_ref die
)
7200 clone
= ggc_cleared_alloc
<die_node
> ();
7201 clone
->die_tag
= die
->die_tag
;
7203 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7204 add_dwarf_attr (clone
, a
);
7209 /* Make a clone of the tree rooted at DIE. */
7212 clone_tree (dw_die_ref die
)
7215 dw_die_ref clone
= clone_die (die
);
7217 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7222 /* Make a clone of DIE as a declaration. */
7225 clone_as_declaration (dw_die_ref die
)
7232 /* If the DIE is already a declaration, just clone it. */
7233 if (is_declaration_die (die
))
7234 return clone_die (die
);
7236 /* If the DIE is a specification, just clone its declaration DIE. */
7237 decl
= get_AT_ref (die
, DW_AT_specification
);
7240 clone
= clone_die (decl
);
7241 if (die
->comdat_type_p
)
7242 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7246 clone
= ggc_cleared_alloc
<die_node
> ();
7247 clone
->die_tag
= die
->die_tag
;
7249 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7251 /* We don't want to copy over all attributes.
7252 For example we don't want DW_AT_byte_size because otherwise we will no
7253 longer have a declaration and GDB will treat it as a definition. */
7257 case DW_AT_abstract_origin
:
7258 case DW_AT_artificial
:
7259 case DW_AT_containing_type
:
7260 case DW_AT_external
:
7263 case DW_AT_virtuality
:
7264 case DW_AT_linkage_name
:
7265 case DW_AT_MIPS_linkage_name
:
7266 add_dwarf_attr (clone
, a
);
7268 case DW_AT_byte_size
:
7274 if (die
->comdat_type_p
)
7275 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7277 add_AT_flag (clone
, DW_AT_declaration
, 1);
7282 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7284 struct decl_table_entry
7290 /* Helpers to manipulate hash table of copied declarations. */
7292 /* Hashtable helpers. */
7294 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7296 typedef die_struct
*compare_type
;
7297 static inline hashval_t
hash (const decl_table_entry
*);
7298 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7302 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7304 return htab_hash_pointer (entry
->orig
);
7308 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7309 const die_struct
*entry2
)
7311 return entry1
->orig
== entry2
;
7314 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7316 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7317 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7318 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7319 to check if the ancestor has already been copied into UNIT. */
7322 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7323 decl_hash_type
*decl_table
)
7325 dw_die_ref parent
= die
->die_parent
;
7326 dw_die_ref new_parent
= unit
;
7328 decl_table_entry
**slot
= NULL
;
7329 struct decl_table_entry
*entry
= NULL
;
7333 /* Check if the entry has already been copied to UNIT. */
7334 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7336 if (*slot
!= HTAB_EMPTY_ENTRY
)
7342 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7343 entry
= XCNEW (struct decl_table_entry
);
7351 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7354 if (!is_unit_die (parent
))
7355 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7358 copy
= clone_as_declaration (die
);
7359 add_child_die (new_parent
, copy
);
7363 /* Record the pointer to the copy. */
7369 /* Copy the declaration context to the new type unit DIE. This includes
7370 any surrounding namespace or type declarations. If the DIE has an
7371 AT_specification attribute, it also includes attributes and children
7372 attached to the specification, and returns a pointer to the original
7373 parent of the declaration DIE. Returns NULL otherwise. */
7376 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7379 dw_die_ref new_decl
;
7380 dw_die_ref orig_parent
= NULL
;
7382 decl
= get_AT_ref (die
, DW_AT_specification
);
7391 /* The original DIE will be changed to a declaration, and must
7392 be moved to be a child of the original declaration DIE. */
7393 orig_parent
= decl
->die_parent
;
7395 /* Copy the type node pointer from the new DIE to the original
7396 declaration DIE so we can forward references later. */
7397 decl
->comdat_type_p
= true;
7398 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7400 remove_AT (die
, DW_AT_specification
);
7402 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7404 if (a
->dw_attr
!= DW_AT_name
7405 && a
->dw_attr
!= DW_AT_declaration
7406 && a
->dw_attr
!= DW_AT_external
)
7407 add_dwarf_attr (die
, a
);
7410 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7413 if (decl
->die_parent
!= NULL
7414 && !is_unit_die (decl
->die_parent
))
7416 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7417 if (new_decl
!= NULL
)
7419 remove_AT (new_decl
, DW_AT_signature
);
7420 add_AT_specification (die
, new_decl
);
7427 /* Generate the skeleton ancestor tree for the given NODE, then clone
7428 the DIE and add the clone into the tree. */
7431 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7433 if (node
->new_die
!= NULL
)
7436 node
->new_die
= clone_as_declaration (node
->old_die
);
7438 if (node
->parent
!= NULL
)
7440 generate_skeleton_ancestor_tree (node
->parent
);
7441 add_child_die (node
->parent
->new_die
, node
->new_die
);
7445 /* Generate a skeleton tree of DIEs containing any declarations that are
7446 found in the original tree. We traverse the tree looking for declaration
7447 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7450 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7452 skeleton_chain_node node
;
7455 dw_die_ref prev
= NULL
;
7456 dw_die_ref next
= NULL
;
7458 node
.parent
= parent
;
7460 first
= c
= parent
->old_die
->die_child
;
7464 if (prev
== NULL
|| prev
->die_sib
== c
)
7467 next
= (c
== first
? NULL
: c
->die_sib
);
7469 node
.new_die
= NULL
;
7470 if (is_declaration_die (c
))
7472 if (is_template_instantiation (c
))
7474 /* Instantiated templates do not need to be cloned into the
7475 type unit. Just move the DIE and its children back to
7476 the skeleton tree (in the main CU). */
7477 remove_child_with_prev (c
, prev
);
7478 add_child_die (parent
->new_die
, c
);
7483 /* Clone the existing DIE, move the original to the skeleton
7484 tree (which is in the main CU), and put the clone, with
7485 all the original's children, where the original came from
7486 (which is about to be moved to the type unit). */
7487 dw_die_ref clone
= clone_die (c
);
7488 move_all_children (c
, clone
);
7490 /* If the original has a DW_AT_object_pointer attribute,
7491 it would now point to a child DIE just moved to the
7492 cloned tree, so we need to remove that attribute from
7494 remove_AT (c
, DW_AT_object_pointer
);
7496 replace_child (c
, clone
, prev
);
7497 generate_skeleton_ancestor_tree (parent
);
7498 add_child_die (parent
->new_die
, c
);
7503 generate_skeleton_bottom_up (&node
);
7504 } while (next
!= NULL
);
7507 /* Wrapper function for generate_skeleton_bottom_up. */
7510 generate_skeleton (dw_die_ref die
)
7512 skeleton_chain_node node
;
7515 node
.new_die
= NULL
;
7518 /* If this type definition is nested inside another type,
7519 and is not an instantiation of a template, always leave
7520 at least a declaration in its place. */
7521 if (die
->die_parent
!= NULL
7522 && is_type_die (die
->die_parent
)
7523 && !is_template_instantiation (die
))
7524 node
.new_die
= clone_as_declaration (die
);
7526 generate_skeleton_bottom_up (&node
);
7527 return node
.new_die
;
7530 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7531 declaration. The original DIE is moved to a new compile unit so that
7532 existing references to it follow it to the new location. If any of the
7533 original DIE's descendants is a declaration, we need to replace the
7534 original DIE with a skeleton tree and move the declarations back into the
7538 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7541 dw_die_ref skeleton
, orig_parent
;
7543 /* Copy the declaration context to the type unit DIE. If the returned
7544 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7546 orig_parent
= copy_declaration_context (unit
, child
);
7548 skeleton
= generate_skeleton (child
);
7549 if (skeleton
== NULL
)
7550 remove_child_with_prev (child
, prev
);
7553 skeleton
->comdat_type_p
= true;
7554 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7556 /* If the original DIE was a specification, we need to put
7557 the skeleton under the parent DIE of the declaration.
7558 This leaves the original declaration in the tree, but
7559 it will be pruned later since there are no longer any
7560 references to it. */
7561 if (orig_parent
!= NULL
)
7563 remove_child_with_prev (child
, prev
);
7564 add_child_die (orig_parent
, skeleton
);
7567 replace_child (child
, skeleton
, prev
);
7573 /* Traverse the DIE and set up additional .debug_types sections for each
7574 type worthy of being placed in a COMDAT section. */
7577 break_out_comdat_types (dw_die_ref die
)
7581 dw_die_ref prev
= NULL
;
7582 dw_die_ref next
= NULL
;
7583 dw_die_ref unit
= NULL
;
7585 first
= c
= die
->die_child
;
7589 if (prev
== NULL
|| prev
->die_sib
== c
)
7592 next
= (c
== first
? NULL
: c
->die_sib
);
7593 if (should_move_die_to_comdat (c
))
7595 dw_die_ref replacement
;
7596 comdat_type_node_ref type_node
;
7598 /* Break out nested types into their own type units. */
7599 break_out_comdat_types (c
);
7601 /* Create a new type unit DIE as the root for the new tree, and
7602 add it to the list of comdat types. */
7603 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7604 add_AT_unsigned (unit
, DW_AT_language
,
7605 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7606 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
7607 type_node
->root_die
= unit
;
7608 type_node
->next
= comdat_type_list
;
7609 comdat_type_list
= type_node
;
7611 /* Generate the type signature. */
7612 generate_type_signature (c
, type_node
);
7614 /* Copy the declaration context, attributes, and children of the
7615 declaration into the new type unit DIE, then remove this DIE
7616 from the main CU (or replace it with a skeleton if necessary). */
7617 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7618 type_node
->skeleton_die
= replacement
;
7620 /* Add the DIE to the new compunit. */
7621 add_child_die (unit
, c
);
7623 if (replacement
!= NULL
)
7626 else if (c
->die_tag
== DW_TAG_namespace
7627 || c
->die_tag
== DW_TAG_class_type
7628 || c
->die_tag
== DW_TAG_structure_type
7629 || c
->die_tag
== DW_TAG_union_type
)
7631 /* Look for nested types that can be broken out. */
7632 break_out_comdat_types (c
);
7634 } while (next
!= NULL
);
7637 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7638 Enter all the cloned children into the hash table decl_table. */
7641 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
7645 struct decl_table_entry
*entry
;
7646 decl_table_entry
**slot
;
7648 if (die
->die_tag
== DW_TAG_subprogram
)
7649 clone
= clone_as_declaration (die
);
7651 clone
= clone_die (die
);
7653 slot
= decl_table
->find_slot_with_hash (die
,
7654 htab_hash_pointer (die
), INSERT
);
7656 /* Assert that DIE isn't in the hash table yet. If it would be there
7657 before, the ancestors would be necessarily there as well, therefore
7658 clone_tree_partial wouldn't be called. */
7659 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7661 entry
= XCNEW (struct decl_table_entry
);
7663 entry
->copy
= clone
;
7666 if (die
->die_tag
!= DW_TAG_subprogram
)
7667 FOR_EACH_CHILD (die
, c
,
7668 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7673 /* Walk the DIE and its children, looking for references to incomplete
7674 or trivial types that are unmarked (i.e., that are not in the current
7678 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
7684 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7686 if (AT_class (a
) == dw_val_class_die_ref
)
7688 dw_die_ref targ
= AT_ref (a
);
7689 decl_table_entry
**slot
;
7690 struct decl_table_entry
*entry
;
7692 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7695 slot
= decl_table
->find_slot_with_hash (targ
,
7696 htab_hash_pointer (targ
),
7699 if (*slot
!= HTAB_EMPTY_ENTRY
)
7701 /* TARG has already been copied, so we just need to
7702 modify the reference to point to the copy. */
7704 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7708 dw_die_ref parent
= unit
;
7709 dw_die_ref copy
= clone_die (targ
);
7711 /* Record in DECL_TABLE that TARG has been copied.
7712 Need to do this now, before the recursive call,
7713 because DECL_TABLE may be expanded and SLOT
7714 would no longer be a valid pointer. */
7715 entry
= XCNEW (struct decl_table_entry
);
7720 /* If TARG is not a declaration DIE, we need to copy its
7722 if (!is_declaration_die (targ
))
7726 add_child_die (copy
,
7727 clone_tree_partial (c
, decl_table
)));
7730 /* Make sure the cloned tree is marked as part of the
7734 /* If TARG has surrounding context, copy its ancestor tree
7735 into the new type unit. */
7736 if (targ
->die_parent
!= NULL
7737 && !is_unit_die (targ
->die_parent
))
7738 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7741 add_child_die (parent
, copy
);
7742 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7744 /* Make sure the newly-copied DIE is walked. If it was
7745 installed in a previously-added context, it won't
7746 get visited otherwise. */
7749 /* Find the highest point of the newly-added tree,
7750 mark each node along the way, and walk from there. */
7751 parent
->die_mark
= 1;
7752 while (parent
->die_parent
7753 && parent
->die_parent
->die_mark
== 0)
7755 parent
= parent
->die_parent
;
7756 parent
->die_mark
= 1;
7758 copy_decls_walk (unit
, parent
, decl_table
);
7764 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7767 /* Copy declarations for "unworthy" types into the new comdat section.
7768 Incomplete types, modified types, and certain other types aren't broken
7769 out into comdat sections of their own, so they don't have a signature,
7770 and we need to copy the declaration into the same section so that we
7771 don't have an external reference. */
7774 copy_decls_for_unworthy_types (dw_die_ref unit
)
7777 decl_hash_type
decl_table (10);
7778 copy_decls_walk (unit
, unit
, &decl_table
);
7782 /* Traverse the DIE and add a sibling attribute if it may have the
7783 effect of speeding up access to siblings. To save some space,
7784 avoid generating sibling attributes for DIE's without children. */
7787 add_sibling_attributes (dw_die_ref die
)
7791 if (! die
->die_child
)
7794 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7795 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7797 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7800 /* Output all location lists for the DIE and its children. */
7803 output_location_lists (dw_die_ref die
)
7809 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7810 if (AT_class (a
) == dw_val_class_loc_list
)
7811 output_loc_list (AT_loc_list (a
));
7813 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7816 /* We want to limit the number of external references, because they are
7817 larger than local references: a relocation takes multiple words, and
7818 even a sig8 reference is always eight bytes, whereas a local reference
7819 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7820 So if we encounter multiple external references to the same type DIE, we
7821 make a local typedef stub for it and redirect all references there.
7823 This is the element of the hash table for keeping track of these
7833 /* Hashtable helpers. */
7835 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
7837 static inline hashval_t
hash (const external_ref
*);
7838 static inline bool equal (const external_ref
*, const external_ref
*);
7842 external_ref_hasher::hash (const external_ref
*r
)
7844 dw_die_ref die
= r
->type
;
7847 /* We can't use the address of the DIE for hashing, because
7848 that will make the order of the stub DIEs non-deterministic. */
7849 if (! die
->comdat_type_p
)
7850 /* We have a symbol; use it to compute a hash. */
7851 h
= htab_hash_string (die
->die_id
.die_symbol
);
7854 /* We have a type signature; use a subset of the bits as the hash.
7855 The 8-byte signature is at least as large as hashval_t. */
7856 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7857 memcpy (&h
, type_node
->signature
, sizeof (h
));
7863 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
7865 return r1
->type
== r2
->type
;
7868 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7870 /* Return a pointer to the external_ref for references to DIE. */
7872 static struct external_ref
*
7873 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
7875 struct external_ref ref
, *ref_p
;
7876 external_ref
**slot
;
7879 slot
= map
->find_slot (&ref
, INSERT
);
7880 if (*slot
!= HTAB_EMPTY_ENTRY
)
7883 ref_p
= XCNEW (struct external_ref
);
7889 /* Subroutine of optimize_external_refs, below.
7891 If we see a type skeleton, record it as our stub. If we see external
7892 references, remember how many we've seen. */
7895 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
7900 struct external_ref
*ref_p
;
7902 if (is_type_die (die
)
7903 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7905 /* This is a local skeleton; use it for local references. */
7906 ref_p
= lookup_external_ref (map
, c
);
7910 /* Scan the DIE references, and remember any that refer to DIEs from
7911 other CUs (i.e. those which are not marked). */
7912 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7913 if (AT_class (a
) == dw_val_class_die_ref
7914 && (c
= AT_ref (a
))->die_mark
== 0
7917 ref_p
= lookup_external_ref (map
, c
);
7921 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7924 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7925 points to an external_ref, DATA is the CU we're processing. If we don't
7926 already have a local stub, and we have multiple refs, build a stub. */
7929 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7931 struct external_ref
*ref_p
= *slot
;
7933 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7935 /* We have multiple references to this type, so build a small stub.
7936 Both of these forms are a bit dodgy from the perspective of the
7937 DWARF standard, since technically they should have names. */
7938 dw_die_ref cu
= data
;
7939 dw_die_ref type
= ref_p
->type
;
7940 dw_die_ref stub
= NULL
;
7942 if (type
->comdat_type_p
)
7944 /* If we refer to this type via sig8, use AT_signature. */
7945 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7946 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7950 /* Otherwise, use a typedef with no name. */
7951 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7952 add_AT_die_ref (stub
, DW_AT_type
, type
);
7961 /* DIE is a unit; look through all the DIE references to see if there are
7962 any external references to types, and if so, create local stubs for
7963 them which will be applied in build_abbrev_table. This is useful because
7964 references to local DIEs are smaller. */
7966 static external_ref_hash_type
*
7967 optimize_external_refs (dw_die_ref die
)
7969 external_ref_hash_type
*map
= new external_ref_hash_type (10);
7970 optimize_external_refs_1 (die
, map
);
7971 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7975 /* The format of each DIE (and its attribute value pairs) is encoded in an
7976 abbreviation table. This routine builds the abbreviation table and assigns
7977 a unique abbreviation id for each abbreviation entry. The children of each
7978 die are visited recursively. */
7981 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
7983 unsigned long abbrev_id
;
7984 unsigned int n_alloc
;
7989 /* Scan the DIE references, and replace any that refer to
7990 DIEs from other CUs (i.e. those which are not marked) with
7991 the local stubs we built in optimize_external_refs. */
7992 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7993 if (AT_class (a
) == dw_val_class_die_ref
7994 && (c
= AT_ref (a
))->die_mark
== 0)
7996 struct external_ref
*ref_p
;
7997 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7999 ref_p
= lookup_external_ref (extern_map
, c
);
8000 if (ref_p
->stub
&& ref_p
->stub
!= die
)
8001 change_AT_die_ref (a
, ref_p
->stub
);
8003 /* We aren't changing this reference, so mark it external. */
8004 set_AT_ref_external (a
, 1);
8007 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8009 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
8010 dw_attr_ref die_a
, abbrev_a
;
8014 if (abbrev
->die_tag
!= die
->die_tag
)
8016 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8019 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8022 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8024 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8025 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8026 || (value_format (abbrev_a
) != value_format (die_a
)))
8036 if (abbrev_id
>= abbrev_die_table_in_use
)
8038 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
8040 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
8041 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
8044 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
8045 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
8046 abbrev_die_table_allocated
= n_alloc
;
8049 ++abbrev_die_table_in_use
;
8050 abbrev_die_table
[abbrev_id
] = die
;
8053 die
->die_abbrev
= abbrev_id
;
8054 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8057 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8060 constant_size (unsigned HOST_WIDE_INT value
)
8067 log
= floor_log2 (value
);
8070 log
= 1 << (floor_log2 (log
) + 1);
8075 /* Return the size of a DIE as it is represented in the
8076 .debug_info section. */
8078 static unsigned long
8079 size_of_die (dw_die_ref die
)
8081 unsigned long size
= 0;
8084 enum dwarf_form form
;
8086 size
+= size_of_uleb128 (die
->die_abbrev
);
8087 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8089 switch (AT_class (a
))
8091 case dw_val_class_addr
:
8092 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8094 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8095 size
+= size_of_uleb128 (AT_index (a
));
8098 size
+= DWARF2_ADDR_SIZE
;
8100 case dw_val_class_offset
:
8101 size
+= DWARF_OFFSET_SIZE
;
8103 case dw_val_class_loc
:
8105 unsigned long lsize
= size_of_locs (AT_loc (a
));
8108 if (dwarf_version
>= 4)
8109 size
+= size_of_uleb128 (lsize
);
8111 size
+= constant_size (lsize
);
8115 case dw_val_class_loc_list
:
8116 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8118 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8119 size
+= size_of_uleb128 (AT_index (a
));
8122 size
+= DWARF_OFFSET_SIZE
;
8124 case dw_val_class_range_list
:
8125 size
+= DWARF_OFFSET_SIZE
;
8127 case dw_val_class_const
:
8128 size
+= size_of_sleb128 (AT_int (a
));
8130 case dw_val_class_unsigned_const
:
8132 int csize
= constant_size (AT_unsigned (a
));
8133 if (dwarf_version
== 3
8134 && a
->dw_attr
== DW_AT_data_member_location
8136 size
+= size_of_uleb128 (AT_unsigned (a
));
8141 case dw_val_class_const_double
:
8142 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
8143 if (HOST_BITS_PER_WIDE_INT
>= 64)
8146 case dw_val_class_wide_int
:
8147 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8148 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
8149 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
8153 case dw_val_class_vec
:
8154 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
8155 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
8156 + a
->dw_attr_val
.v
.val_vec
.length
8157 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
8159 case dw_val_class_flag
:
8160 if (dwarf_version
>= 4)
8161 /* Currently all add_AT_flag calls pass in 1 as last argument,
8162 so DW_FORM_flag_present can be used. If that ever changes,
8163 we'll need to use DW_FORM_flag and have some optimization
8164 in build_abbrev_table that will change those to
8165 DW_FORM_flag_present if it is set to 1 in all DIEs using
8166 the same abbrev entry. */
8167 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8171 case dw_val_class_die_ref
:
8172 if (AT_ref_external (a
))
8174 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8175 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8176 is sized by target address length, whereas in DWARF3
8177 it's always sized as an offset. */
8178 if (use_debug_types
)
8179 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
8180 else if (dwarf_version
== 2)
8181 size
+= DWARF2_ADDR_SIZE
;
8183 size
+= DWARF_OFFSET_SIZE
;
8186 size
+= DWARF_OFFSET_SIZE
;
8188 case dw_val_class_fde_ref
:
8189 size
+= DWARF_OFFSET_SIZE
;
8191 case dw_val_class_lbl_id
:
8192 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8194 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8195 size
+= size_of_uleb128 (AT_index (a
));
8198 size
+= DWARF2_ADDR_SIZE
;
8200 case dw_val_class_lineptr
:
8201 case dw_val_class_macptr
:
8202 size
+= DWARF_OFFSET_SIZE
;
8204 case dw_val_class_str
:
8205 form
= AT_string_form (a
);
8206 if (form
== DW_FORM_strp
)
8207 size
+= DWARF_OFFSET_SIZE
;
8208 else if (form
== DW_FORM_GNU_str_index
)
8209 size
+= size_of_uleb128 (AT_index (a
));
8211 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
8213 case dw_val_class_file
:
8214 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
8216 case dw_val_class_data8
:
8219 case dw_val_class_vms_delta
:
8220 size
+= DWARF_OFFSET_SIZE
;
8222 case dw_val_class_high_pc
:
8223 size
+= DWARF2_ADDR_SIZE
;
8233 /* Size the debugging information associated with a given DIE. Visits the
8234 DIE's children recursively. Updates the global variable next_die_offset, on
8235 each time through. Uses the current value of next_die_offset to update the
8236 die_offset field in each DIE. */
8239 calc_die_sizes (dw_die_ref die
)
8243 gcc_assert (die
->die_offset
== 0
8244 || (unsigned long int) die
->die_offset
== next_die_offset
);
8245 die
->die_offset
= next_die_offset
;
8246 next_die_offset
+= size_of_die (die
);
8248 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
8250 if (die
->die_child
!= NULL
)
8251 /* Count the null byte used to terminate sibling lists. */
8252 next_die_offset
+= 1;
8255 /* Size just the base type children at the start of the CU.
8256 This is needed because build_abbrev needs to size locs
8257 and sizing of type based stack ops needs to know die_offset
8258 values for the base types. */
8261 calc_base_type_die_sizes (void)
8263 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8265 dw_die_ref base_type
;
8266 #if ENABLE_ASSERT_CHECKING
8267 dw_die_ref prev
= comp_unit_die ()->die_child
;
8270 die_offset
+= size_of_die (comp_unit_die ());
8271 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
8273 #if ENABLE_ASSERT_CHECKING
8274 gcc_assert (base_type
->die_offset
== 0
8275 && prev
->die_sib
== base_type
8276 && base_type
->die_child
== NULL
8277 && base_type
->die_abbrev
);
8280 base_type
->die_offset
= die_offset
;
8281 die_offset
+= size_of_die (base_type
);
8285 /* Set the marks for a die and its children. We do this so
8286 that we know whether or not a reference needs to use FORM_ref_addr; only
8287 DIEs in the same CU will be marked. We used to clear out the offset
8288 and use that as the flag, but ran into ordering problems. */
8291 mark_dies (dw_die_ref die
)
8295 gcc_assert (!die
->die_mark
);
8298 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8301 /* Clear the marks for a die and its children. */
8304 unmark_dies (dw_die_ref die
)
8308 if (! use_debug_types
)
8309 gcc_assert (die
->die_mark
);
8312 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8315 /* Clear the marks for a die, its children and referred dies. */
8318 unmark_all_dies (dw_die_ref die
)
8328 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8330 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8331 if (AT_class (a
) == dw_val_class_die_ref
)
8332 unmark_all_dies (AT_ref (a
));
8335 /* Calculate if the entry should appear in the final output file. It may be
8336 from a pruned a type. */
8339 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8341 /* By limiting gnu pubnames to definitions only, gold can generate a
8342 gdb index without entries for declarations, which don't include
8343 enough information to be useful. */
8344 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8347 if (table
== pubname_table
)
8349 /* Enumerator names are part of the pubname table, but the
8350 parent DW_TAG_enumeration_type die may have been pruned.
8351 Don't output them if that is the case. */
8352 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8353 (p
->die
->die_parent
== NULL
8354 || !p
->die
->die_parent
->die_perennial_p
))
8357 /* Everything else in the pubname table is included. */
8361 /* The pubtypes table shouldn't include types that have been
8363 return (p
->die
->die_offset
!= 0
8364 || !flag_eliminate_unused_debug_types
);
8367 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8368 generated for the compilation unit. */
8370 static unsigned long
8371 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8376 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8378 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8379 FOR_EACH_VEC_ELT (*names
, i
, p
)
8380 if (include_pubname_in_output (names
, p
))
8381 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8383 size
+= DWARF_OFFSET_SIZE
;
8387 /* Return the size of the information in the .debug_aranges section. */
8389 static unsigned long
8390 size_of_aranges (void)
8394 size
= DWARF_ARANGES_HEADER_SIZE
;
8396 /* Count the address/length pair for this compilation unit. */
8397 if (text_section_used
)
8398 size
+= 2 * DWARF2_ADDR_SIZE
;
8399 if (cold_text_section_used
)
8400 size
+= 2 * DWARF2_ADDR_SIZE
;
8401 if (have_multiple_function_sections
)
8406 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8408 if (DECL_IGNORED_P (fde
->decl
))
8410 if (!fde
->in_std_section
)
8411 size
+= 2 * DWARF2_ADDR_SIZE
;
8412 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8413 size
+= 2 * DWARF2_ADDR_SIZE
;
8417 /* Count the two zero words used to terminated the address range table. */
8418 size
+= 2 * DWARF2_ADDR_SIZE
;
8422 /* Select the encoding of an attribute value. */
8424 static enum dwarf_form
8425 value_format (dw_attr_ref a
)
8427 switch (AT_class (a
))
8429 case dw_val_class_addr
:
8430 /* Only very few attributes allow DW_FORM_addr. */
8435 case DW_AT_entry_pc
:
8436 case DW_AT_trampoline
:
8437 return (AT_index (a
) == NOT_INDEXED
8438 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8442 switch (DWARF2_ADDR_SIZE
)
8445 return DW_FORM_data1
;
8447 return DW_FORM_data2
;
8449 return DW_FORM_data4
;
8451 return DW_FORM_data8
;
8455 case dw_val_class_range_list
:
8456 case dw_val_class_loc_list
:
8457 if (dwarf_version
>= 4)
8458 return DW_FORM_sec_offset
;
8460 case dw_val_class_vms_delta
:
8461 case dw_val_class_offset
:
8462 switch (DWARF_OFFSET_SIZE
)
8465 return DW_FORM_data4
;
8467 return DW_FORM_data8
;
8471 case dw_val_class_loc
:
8472 if (dwarf_version
>= 4)
8473 return DW_FORM_exprloc
;
8474 switch (constant_size (size_of_locs (AT_loc (a
))))
8477 return DW_FORM_block1
;
8479 return DW_FORM_block2
;
8481 return DW_FORM_block4
;
8485 case dw_val_class_const
:
8486 return DW_FORM_sdata
;
8487 case dw_val_class_unsigned_const
:
8488 switch (constant_size (AT_unsigned (a
)))
8491 return DW_FORM_data1
;
8493 return DW_FORM_data2
;
8495 /* In DWARF3 DW_AT_data_member_location with
8496 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8497 constant, so we need to use DW_FORM_udata if we need
8498 a large constant. */
8499 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8500 return DW_FORM_udata
;
8501 return DW_FORM_data4
;
8503 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8504 return DW_FORM_udata
;
8505 return DW_FORM_data8
;
8509 case dw_val_class_const_double
:
8510 switch (HOST_BITS_PER_WIDE_INT
)
8513 return DW_FORM_data2
;
8515 return DW_FORM_data4
;
8517 return DW_FORM_data8
;
8520 return DW_FORM_block1
;
8522 case dw_val_class_wide_int
:
8523 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
8526 return DW_FORM_data1
;
8528 return DW_FORM_data2
;
8530 return DW_FORM_data4
;
8532 return DW_FORM_data8
;
8534 return DW_FORM_block1
;
8536 case dw_val_class_vec
:
8537 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8538 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8541 return DW_FORM_block1
;
8543 return DW_FORM_block2
;
8545 return DW_FORM_block4
;
8549 case dw_val_class_flag
:
8550 if (dwarf_version
>= 4)
8552 /* Currently all add_AT_flag calls pass in 1 as last argument,
8553 so DW_FORM_flag_present can be used. If that ever changes,
8554 we'll need to use DW_FORM_flag and have some optimization
8555 in build_abbrev_table that will change those to
8556 DW_FORM_flag_present if it is set to 1 in all DIEs using
8557 the same abbrev entry. */
8558 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8559 return DW_FORM_flag_present
;
8561 return DW_FORM_flag
;
8562 case dw_val_class_die_ref
:
8563 if (AT_ref_external (a
))
8564 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8567 case dw_val_class_fde_ref
:
8568 return DW_FORM_data
;
8569 case dw_val_class_lbl_id
:
8570 return (AT_index (a
) == NOT_INDEXED
8571 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8572 case dw_val_class_lineptr
:
8573 case dw_val_class_macptr
:
8574 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8575 case dw_val_class_str
:
8576 return AT_string_form (a
);
8577 case dw_val_class_file
:
8578 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8581 return DW_FORM_data1
;
8583 return DW_FORM_data2
;
8585 return DW_FORM_data4
;
8590 case dw_val_class_data8
:
8591 return DW_FORM_data8
;
8593 case dw_val_class_high_pc
:
8594 switch (DWARF2_ADDR_SIZE
)
8597 return DW_FORM_data1
;
8599 return DW_FORM_data2
;
8601 return DW_FORM_data4
;
8603 return DW_FORM_data8
;
8613 /* Output the encoding of an attribute value. */
8616 output_value_format (dw_attr_ref a
)
8618 enum dwarf_form form
= value_format (a
);
8620 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8623 /* Given a die and id, produce the appropriate abbreviations. */
8626 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8631 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8632 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8633 dwarf_tag_name (abbrev
->die_tag
));
8635 if (abbrev
->die_child
!= NULL
)
8636 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8638 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8640 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8642 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8643 dwarf_attr_name (a_attr
->dw_attr
));
8644 output_value_format (a_attr
);
8647 dw2_asm_output_data (1, 0, NULL
);
8648 dw2_asm_output_data (1, 0, NULL
);
8652 /* Output the .debug_abbrev section which defines the DIE abbreviation
8656 output_abbrev_section (void)
8658 unsigned long abbrev_id
;
8660 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8661 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8663 /* Terminate the table. */
8664 dw2_asm_output_data (1, 0, NULL
);
8667 /* Output a symbol we can use to refer to this DIE from another CU. */
8670 output_die_symbol (dw_die_ref die
)
8672 const char *sym
= die
->die_id
.die_symbol
;
8674 gcc_assert (!die
->comdat_type_p
);
8679 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8680 /* We make these global, not weak; if the target doesn't support
8681 .linkonce, it doesn't support combining the sections, so debugging
8683 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8685 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8688 /* Return a new location list, given the begin and end range, and the
8691 static inline dw_loc_list_ref
8692 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8693 const char *section
)
8695 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
8697 retlist
->begin
= begin
;
8698 retlist
->begin_entry
= NULL
;
8700 retlist
->expr
= expr
;
8701 retlist
->section
= section
;
8706 /* Generate a new internal symbol for this location list node, if it
8707 hasn't got one yet. */
8710 gen_llsym (dw_loc_list_ref list
)
8712 gcc_assert (!list
->ll_symbol
);
8713 list
->ll_symbol
= gen_internal_sym ("LLST");
8716 /* Output the location list given to us. */
8719 output_loc_list (dw_loc_list_ref list_head
)
8721 dw_loc_list_ref curr
= list_head
;
8723 if (list_head
->emitted
)
8725 list_head
->emitted
= true;
8727 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8729 /* Walk the location list, and output each range + expression. */
8730 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8733 /* Don't output an entry that starts and ends at the same address. */
8734 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8736 size
= size_of_locs (curr
->expr
);
8737 /* If the expression is too large, drop it on the floor. We could
8738 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8739 in the expression, but >= 64KB expressions for a single value
8740 in a single range are unlikely very useful. */
8743 if (dwarf_split_debug_info
)
8745 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8746 "Location list start/length entry (%s)",
8747 list_head
->ll_symbol
);
8748 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8749 "Location list range start index (%s)",
8751 /* The length field is 4 bytes. If we ever need to support
8752 an 8-byte length, we can add a new DW_LLE code or fall back
8753 to DW_LLE_GNU_start_end_entry. */
8754 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8755 "Location list range length (%s)",
8756 list_head
->ll_symbol
);
8758 else if (!have_multiple_function_sections
)
8760 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8761 "Location list begin address (%s)",
8762 list_head
->ll_symbol
);
8763 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8764 "Location list end address (%s)",
8765 list_head
->ll_symbol
);
8769 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8770 "Location list begin address (%s)",
8771 list_head
->ll_symbol
);
8772 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8773 "Location list end address (%s)",
8774 list_head
->ll_symbol
);
8777 /* Output the block length for this list of location operations. */
8778 gcc_assert (size
<= 0xffff);
8779 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8781 output_loc_sequence (curr
->expr
, -1);
8784 if (dwarf_split_debug_info
)
8785 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8786 "Location list terminator (%s)",
8787 list_head
->ll_symbol
);
8790 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8791 "Location list terminator begin (%s)",
8792 list_head
->ll_symbol
);
8793 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8794 "Location list terminator end (%s)",
8795 list_head
->ll_symbol
);
8799 /* Output a range_list offset into the debug_range section. Emit a
8800 relocated reference if val_entry is NULL, otherwise, emit an
8801 indirect reference. */
8804 output_range_list_offset (dw_attr_ref a
)
8806 const char *name
= dwarf_attr_name (a
->dw_attr
);
8808 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8810 char *p
= strchr (ranges_section_label
, '\0');
8811 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8812 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8813 debug_ranges_section
, "%s", name
);
8817 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8818 "%s (offset from %s)", name
, ranges_section_label
);
8821 /* Output the offset into the debug_loc section. */
8824 output_loc_list_offset (dw_attr_ref a
)
8826 char *sym
= AT_loc_list (a
)->ll_symbol
;
8829 if (dwarf_split_debug_info
)
8830 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8831 "%s", dwarf_attr_name (a
->dw_attr
));
8833 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8834 "%s", dwarf_attr_name (a
->dw_attr
));
8837 /* Output an attribute's index or value appropriately. */
8840 output_attr_index_or_value (dw_attr_ref a
)
8842 const char *name
= dwarf_attr_name (a
->dw_attr
);
8844 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8846 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8849 switch (AT_class (a
))
8851 case dw_val_class_addr
:
8852 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8854 case dw_val_class_high_pc
:
8855 case dw_val_class_lbl_id
:
8856 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8858 case dw_val_class_loc_list
:
8859 output_loc_list_offset (a
);
8866 /* Output a type signature. */
8869 output_signature (const char *sig
, const char *name
)
8873 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8874 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8877 /* Output the DIE and its attributes. Called recursively to generate
8878 the definitions of each child DIE. */
8881 output_die (dw_die_ref die
)
8888 /* If someone in another CU might refer to us, set up a symbol for
8889 them to point to. */
8890 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8891 output_die_symbol (die
);
8893 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8894 (unsigned long)die
->die_offset
,
8895 dwarf_tag_name (die
->die_tag
));
8897 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8899 const char *name
= dwarf_attr_name (a
->dw_attr
);
8901 switch (AT_class (a
))
8903 case dw_val_class_addr
:
8904 output_attr_index_or_value (a
);
8907 case dw_val_class_offset
:
8908 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8912 case dw_val_class_range_list
:
8913 output_range_list_offset (a
);
8916 case dw_val_class_loc
:
8917 size
= size_of_locs (AT_loc (a
));
8919 /* Output the block length for this list of location operations. */
8920 if (dwarf_version
>= 4)
8921 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8923 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8925 output_loc_sequence (AT_loc (a
), -1);
8928 case dw_val_class_const
:
8929 /* ??? It would be slightly more efficient to use a scheme like is
8930 used for unsigned constants below, but gdb 4.x does not sign
8931 extend. Gdb 5.x does sign extend. */
8932 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8935 case dw_val_class_unsigned_const
:
8937 int csize
= constant_size (AT_unsigned (a
));
8938 if (dwarf_version
== 3
8939 && a
->dw_attr
== DW_AT_data_member_location
8941 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8943 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8947 case dw_val_class_const_double
:
8949 unsigned HOST_WIDE_INT first
, second
;
8951 if (HOST_BITS_PER_WIDE_INT
>= 64)
8952 dw2_asm_output_data (1,
8953 HOST_BITS_PER_DOUBLE_INT
8954 / HOST_BITS_PER_CHAR
,
8957 if (WORDS_BIG_ENDIAN
)
8959 first
= a
->dw_attr_val
.v
.val_double
.high
;
8960 second
= a
->dw_attr_val
.v
.val_double
.low
;
8964 first
= a
->dw_attr_val
.v
.val_double
.low
;
8965 second
= a
->dw_attr_val
.v
.val_double
.high
;
8968 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8970 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8975 case dw_val_class_wide_int
:
8978 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
8979 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
8980 if (len
* HOST_BITS_PER_WIDE_INT
> 64)
8981 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
) * l
,
8984 if (WORDS_BIG_ENDIAN
)
8985 for (i
= len
- 1; i
>= 0; --i
)
8987 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
8992 for (i
= 0; i
< len
; ++i
)
8994 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
9001 case dw_val_class_vec
:
9003 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
9004 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
9008 dw2_asm_output_data (constant_size (len
* elt_size
),
9009 len
* elt_size
, "%s", name
);
9010 if (elt_size
> sizeof (HOST_WIDE_INT
))
9015 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
9018 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
9019 "fp or vector constant word %u", i
);
9023 case dw_val_class_flag
:
9024 if (dwarf_version
>= 4)
9026 /* Currently all add_AT_flag calls pass in 1 as last argument,
9027 so DW_FORM_flag_present can be used. If that ever changes,
9028 we'll need to use DW_FORM_flag and have some optimization
9029 in build_abbrev_table that will change those to
9030 DW_FORM_flag_present if it is set to 1 in all DIEs using
9031 the same abbrev entry. */
9032 gcc_assert (AT_flag (a
) == 1);
9034 fprintf (asm_out_file
, "\t\t\t%s %s\n",
9035 ASM_COMMENT_START
, name
);
9038 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
9041 case dw_val_class_loc_list
:
9042 output_attr_index_or_value (a
);
9045 case dw_val_class_die_ref
:
9046 if (AT_ref_external (a
))
9048 if (AT_ref (a
)->comdat_type_p
)
9050 comdat_type_node_ref type_node
=
9051 AT_ref (a
)->die_id
.die_type_node
;
9053 gcc_assert (type_node
);
9054 output_signature (type_node
->signature
, name
);
9058 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
9062 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9063 length, whereas in DWARF3 it's always sized as an
9065 if (dwarf_version
== 2)
9066 size
= DWARF2_ADDR_SIZE
;
9068 size
= DWARF_OFFSET_SIZE
;
9069 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
9075 gcc_assert (AT_ref (a
)->die_offset
);
9076 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
9081 case dw_val_class_fde_ref
:
9085 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
9086 a
->dw_attr_val
.v
.val_fde_index
* 2);
9087 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
9092 case dw_val_class_vms_delta
:
9093 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
9094 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
9095 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9098 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
9099 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9104 case dw_val_class_lbl_id
:
9105 output_attr_index_or_value (a
);
9108 case dw_val_class_lineptr
:
9109 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9110 debug_line_section
, "%s", name
);
9113 case dw_val_class_macptr
:
9114 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9115 debug_macinfo_section
, "%s", name
);
9118 case dw_val_class_str
:
9119 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
9120 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9121 a
->dw_attr_val
.v
.val_str
->label
,
9123 "%s: \"%s\"", name
, AT_string (a
));
9124 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
9125 dw2_asm_output_data_uleb128 (AT_index (a
),
9126 "%s: \"%s\"", name
, AT_string (a
));
9128 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
9131 case dw_val_class_file
:
9133 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
9135 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
9136 a
->dw_attr_val
.v
.val_file
->filename
);
9140 case dw_val_class_data8
:
9144 for (i
= 0; i
< 8; i
++)
9145 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
9146 i
== 0 ? "%s" : NULL
, name
);
9150 case dw_val_class_high_pc
:
9151 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
9152 get_AT_low_pc (die
), "DW_AT_high_pc");
9160 FOR_EACH_CHILD (die
, c
, output_die (c
));
9162 /* Add null byte to terminate sibling list. */
9163 if (die
->die_child
!= NULL
)
9164 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9165 (unsigned long) die
->die_offset
);
9168 /* Output the compilation unit that appears at the beginning of the
9169 .debug_info section, and precedes the DIE descriptions. */
9172 output_compilation_unit_header (void)
9174 /* We don't support actual DWARFv5 units yet, we just use some
9175 DWARFv5 draft DIE tags in DWARFv4 format. */
9176 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9178 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9179 dw2_asm_output_data (4, 0xffffffff,
9180 "Initial length escape value indicating 64-bit DWARF extension");
9181 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9182 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
9183 "Length of Compilation Unit Info");
9184 dw2_asm_output_data (2, ver
, "DWARF version number");
9185 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
9186 debug_abbrev_section
,
9187 "Offset Into Abbrev. Section");
9188 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9191 /* Output the compilation unit DIE and its children. */
9194 output_comp_unit (dw_die_ref die
, int output_if_empty
)
9196 const char *secname
, *oldsym
;
9199 /* Unless we are outputting main CU, we may throw away empty ones. */
9200 if (!output_if_empty
&& die
->die_child
== NULL
)
9203 /* Even if there are no children of this DIE, we must output the information
9204 about the compilation unit. Otherwise, on an empty translation unit, we
9205 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9206 will then complain when examining the file. First mark all the DIEs in
9207 this CU so we know which get local refs. */
9210 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
9212 build_abbrev_table (die
, extern_map
);
9216 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9217 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
9218 calc_die_sizes (die
);
9220 oldsym
= die
->die_id
.die_symbol
;
9223 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
9225 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
9227 die
->die_id
.die_symbol
= NULL
;
9228 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9232 switch_to_section (debug_info_section
);
9233 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
9234 info_section_emitted
= true;
9237 /* Output debugging information. */
9238 output_compilation_unit_header ();
9241 /* Leave the marks on the main CU, so we can check them in
9246 die
->die_id
.die_symbol
= oldsym
;
9250 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9251 and .debug_pubtypes. This is configured per-target, but can be
9252 overridden by the -gpubnames or -gno-pubnames options. */
9255 want_pubnames (void)
9257 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9259 if (debug_generate_pub_sections
!= -1)
9260 return debug_generate_pub_sections
;
9261 return targetm
.want_debug_pub_sections
;
9264 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9267 add_AT_pubnames (dw_die_ref die
)
9269 if (want_pubnames ())
9270 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
9273 /* Add a string attribute value to a skeleton DIE. */
9276 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9280 struct indirect_string_node
*node
;
9282 if (! skeleton_debug_str_hash
)
9283 skeleton_debug_str_hash
9284 = hash_table
<indirect_string_hasher
>::create_ggc (10);
9286 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
9287 find_string_form (node
);
9288 if (node
->form
== DW_FORM_GNU_str_index
)
9289 node
->form
= DW_FORM_strp
;
9291 attr
.dw_attr
= attr_kind
;
9292 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
9293 attr
.dw_attr_val
.val_entry
= NULL
;
9294 attr
.dw_attr_val
.v
.val_str
= node
;
9295 add_dwarf_attr (die
, &attr
);
9298 /* Helper function to generate top-level dies for skeleton debug_info and
9302 add_top_level_skeleton_die_attrs (dw_die_ref die
)
9304 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
9305 const char *comp_dir
= comp_dir_string ();
9307 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
9308 if (comp_dir
!= NULL
)
9309 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
9310 add_AT_pubnames (die
);
9311 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
9314 /* Output skeleton debug sections that point to the dwo file. */
9317 output_skeleton_debug_sections (dw_die_ref comp_unit
)
9319 /* We don't support actual DWARFv5 units yet, we just use some
9320 DWARFv5 draft DIE tags in DWARFv4 format. */
9321 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9323 /* These attributes will be found in the full debug_info section. */
9324 remove_AT (comp_unit
, DW_AT_producer
);
9325 remove_AT (comp_unit
, DW_AT_language
);
9327 switch_to_section (debug_skeleton_info_section
);
9328 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
9330 /* Produce the skeleton compilation-unit header. This one differs enough from
9331 a normal CU header that it's better not to call output_compilation_unit
9333 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9334 dw2_asm_output_data (4, 0xffffffff,
9335 "Initial length escape value indicating 64-bit DWARF extension");
9337 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9338 DWARF_COMPILE_UNIT_HEADER_SIZE
9339 - DWARF_INITIAL_LENGTH_SIZE
9340 + size_of_die (comp_unit
),
9341 "Length of Compilation Unit Info");
9342 dw2_asm_output_data (2, ver
, "DWARF version number");
9343 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
9344 debug_abbrev_section
,
9345 "Offset Into Abbrev. Section");
9346 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9348 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
9349 output_die (comp_unit
);
9351 /* Build the skeleton debug_abbrev section. */
9352 switch_to_section (debug_skeleton_abbrev_section
);
9353 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
9355 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
9357 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9360 /* Output a comdat type unit DIE and its children. */
9363 output_comdat_type_unit (comdat_type_node
*node
)
9365 const char *secname
;
9368 #if defined (OBJECT_FORMAT_ELF)
9372 /* First mark all the DIEs in this CU so we know which get local refs. */
9373 mark_dies (node
->root_die
);
9375 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
9377 build_abbrev_table (node
->root_die
, extern_map
);
9382 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9383 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9384 calc_die_sizes (node
->root_die
);
9386 #if defined (OBJECT_FORMAT_ELF)
9387 if (!dwarf_split_debug_info
)
9388 secname
= ".debug_types";
9390 secname
= ".debug_types.dwo";
9392 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9393 sprintf (tmp
, "wt.");
9394 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9395 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9396 comdat_key
= get_identifier (tmp
);
9397 targetm
.asm_out
.named_section (secname
,
9398 SECTION_DEBUG
| SECTION_LINKONCE
,
9401 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9402 sprintf (tmp
, ".gnu.linkonce.wt.");
9403 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9404 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9406 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9409 /* Output debugging information. */
9410 output_compilation_unit_header ();
9411 output_signature (node
->signature
, "Type Signature");
9412 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9413 "Offset to Type DIE");
9414 output_die (node
->root_die
);
9416 unmark_dies (node
->root_die
);
9419 /* Return the DWARF2/3 pubname associated with a decl. */
9422 dwarf2_name (tree decl
, int scope
)
9424 if (DECL_NAMELESS (decl
))
9426 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9429 /* Add a new entry to .debug_pubnames if appropriate. */
9432 add_pubname_string (const char *str
, dw_die_ref die
)
9437 e
.name
= xstrdup (str
);
9438 vec_safe_push (pubname_table
, e
);
9442 add_pubname (tree decl
, dw_die_ref die
)
9444 if (!want_pubnames ())
9447 /* Don't add items to the table when we expect that the consumer will have
9448 just read the enclosing die. For example, if the consumer is looking at a
9449 class_member, it will either be inside the class already, or will have just
9450 looked up the class to find the member. Either way, searching the class is
9451 faster than searching the index. */
9452 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9453 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9455 const char *name
= dwarf2_name (decl
, 1);
9458 add_pubname_string (name
, die
);
9462 /* Add an enumerator to the pubnames section. */
9465 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9469 gcc_assert (scope_name
);
9470 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9472 vec_safe_push (pubname_table
, e
);
9475 /* Add a new entry to .debug_pubtypes if appropriate. */
9478 add_pubtype (tree decl
, dw_die_ref die
)
9482 if (!want_pubnames ())
9485 if ((TREE_PUBLIC (decl
)
9486 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9487 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9490 const char *scope_name
= "";
9491 const char *sep
= is_cxx () ? "::" : ".";
9494 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9495 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9497 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9498 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9499 scope_name
= concat (scope_name
, sep
, NULL
);
9505 name
= type_tag (decl
);
9507 name
= lang_hooks
.dwarf_name (decl
, 1);
9509 /* If we don't have a name for the type, there's no point in adding
9511 if (name
!= NULL
&& name
[0] != '\0')
9514 e
.name
= concat (scope_name
, name
, NULL
);
9515 vec_safe_push (pubtype_table
, e
);
9518 /* Although it might be more consistent to add the pubinfo for the
9519 enumerators as their dies are created, they should only be added if the
9520 enum type meets the criteria above. So rather than re-check the parent
9521 enum type whenever an enumerator die is created, just output them all
9522 here. This isn't protected by the name conditional because anonymous
9523 enums don't have names. */
9524 if (die
->die_tag
== DW_TAG_enumeration_type
)
9528 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9533 /* Output a single entry in the pubnames table. */
9536 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9538 dw_die_ref die
= entry
->die
;
9539 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9541 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9543 if (debug_generate_pub_sections
== 2)
9545 /* This logic follows gdb's method for determining the value of the flag
9547 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9548 switch (die
->die_tag
)
9550 case DW_TAG_typedef
:
9551 case DW_TAG_base_type
:
9552 case DW_TAG_subrange_type
:
9553 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9554 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9556 case DW_TAG_enumerator
:
9557 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9558 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9559 if (!is_cxx () && !is_java ())
9560 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9562 case DW_TAG_subprogram
:
9563 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9564 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9566 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9568 case DW_TAG_constant
:
9569 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9570 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9571 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9573 case DW_TAG_variable
:
9574 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9575 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9576 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9578 case DW_TAG_namespace
:
9579 case DW_TAG_imported_declaration
:
9580 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9582 case DW_TAG_class_type
:
9583 case DW_TAG_interface_type
:
9584 case DW_TAG_structure_type
:
9585 case DW_TAG_union_type
:
9586 case DW_TAG_enumeration_type
:
9587 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9588 if (!is_cxx () && !is_java ())
9589 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9592 /* An unusual tag. Leave the flag-byte empty. */
9595 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9599 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9603 /* Output the public names table used to speed up access to externally
9604 visible names; or the public types table used to find type definitions. */
9607 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9610 unsigned long pubnames_length
= size_of_pubnames (names
);
9613 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9614 dw2_asm_output_data (4, 0xffffffff,
9615 "Initial length escape value indicating 64-bit DWARF extension");
9616 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9618 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9619 dw2_asm_output_data (2, 2, "DWARF Version");
9621 if (dwarf_split_debug_info
)
9622 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9623 debug_skeleton_info_section
,
9624 "Offset of Compilation Unit Info");
9626 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9628 "Offset of Compilation Unit Info");
9629 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9630 "Compilation Unit Length");
9632 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9634 if (include_pubname_in_output (names
, pub
))
9636 dw_offset die_offset
= pub
->die
->die_offset
;
9638 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9639 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9640 gcc_assert (pub
->die
->die_mark
);
9642 /* If we're putting types in their own .debug_types sections,
9643 the .debug_pubtypes table will still point to the compile
9644 unit (not the type unit), so we want to use the offset of
9645 the skeleton DIE (if there is one). */
9646 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9648 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9650 if (type_node
!= NULL
)
9651 die_offset
= (type_node
->skeleton_die
!= NULL
9652 ? type_node
->skeleton_die
->die_offset
9653 : comp_unit_die ()->die_offset
);
9656 output_pubname (die_offset
, pub
);
9660 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9663 /* Output public names and types tables if necessary. */
9666 output_pubtables (void)
9668 if (!want_pubnames () || !info_section_emitted
)
9671 switch_to_section (debug_pubnames_section
);
9672 output_pubnames (pubname_table
);
9673 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9674 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9675 simply won't look for the section. */
9676 switch_to_section (debug_pubtypes_section
);
9677 output_pubnames (pubtype_table
);
9681 /* Output the information that goes into the .debug_aranges table.
9682 Namely, define the beginning and ending address range of the
9683 text section generated for this compilation unit. */
9686 output_aranges (unsigned long aranges_length
)
9690 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9691 dw2_asm_output_data (4, 0xffffffff,
9692 "Initial length escape value indicating 64-bit DWARF extension");
9693 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9694 "Length of Address Ranges Info");
9695 /* Version number for aranges is still 2, even up to DWARF5. */
9696 dw2_asm_output_data (2, 2, "DWARF Version");
9697 if (dwarf_split_debug_info
)
9698 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9699 debug_skeleton_info_section
,
9700 "Offset of Compilation Unit Info");
9702 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9704 "Offset of Compilation Unit Info");
9705 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9706 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9708 /* We need to align to twice the pointer size here. */
9709 if (DWARF_ARANGES_PAD_SIZE
)
9711 /* Pad using a 2 byte words so that padding is correct for any
9713 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9714 2 * DWARF2_ADDR_SIZE
);
9715 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9716 dw2_asm_output_data (2, 0, NULL
);
9719 /* It is necessary not to output these entries if the sections were
9720 not used; if the sections were not used, the length will be 0 and
9721 the address may end up as 0 if the section is discarded by ld
9722 --gc-sections, leaving an invalid (0, 0) entry that can be
9723 confused with the terminator. */
9724 if (text_section_used
)
9726 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9727 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9728 text_section_label
, "Length");
9730 if (cold_text_section_used
)
9732 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9734 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9735 cold_text_section_label
, "Length");
9738 if (have_multiple_function_sections
)
9743 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9745 if (DECL_IGNORED_P (fde
->decl
))
9747 if (!fde
->in_std_section
)
9749 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9751 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9752 fde
->dw_fde_begin
, "Length");
9754 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9756 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9758 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9759 fde
->dw_fde_second_begin
, "Length");
9764 /* Output the terminator words. */
9765 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9766 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9769 /* Add a new entry to .debug_ranges. Return the offset at which it
9773 add_ranges_num (int num
)
9775 unsigned int in_use
= ranges_table_in_use
;
9777 if (in_use
== ranges_table_allocated
)
9779 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9780 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9781 ranges_table_allocated
);
9782 memset (ranges_table
+ ranges_table_in_use
, 0,
9783 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9786 ranges_table
[in_use
].num
= num
;
9787 ranges_table_in_use
= in_use
+ 1;
9789 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9792 /* Add a new entry to .debug_ranges corresponding to a block, or a
9793 range terminator if BLOCK is NULL. */
9796 add_ranges (const_tree block
)
9798 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9801 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9802 When using dwarf_split_debug_info, address attributes in dies destined
9803 for the final executable should be direct references--setting the
9804 parameter force_direct ensures this behavior. */
9807 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9808 bool *added
, bool force_direct
)
9810 unsigned int in_use
= ranges_by_label_in_use
;
9811 unsigned int offset
;
9813 if (in_use
== ranges_by_label_allocated
)
9815 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9816 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9818 ranges_by_label_allocated
);
9819 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9820 RANGES_TABLE_INCREMENT
9821 * sizeof (struct dw_ranges_by_label_struct
));
9824 ranges_by_label
[in_use
].begin
= begin
;
9825 ranges_by_label
[in_use
].end
= end
;
9826 ranges_by_label_in_use
= in_use
+ 1;
9828 offset
= add_ranges_num (-(int)in_use
- 1);
9831 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9837 output_ranges (void)
9840 static const char *const start_fmt
= "Offset %#x";
9841 const char *fmt
= start_fmt
;
9843 for (i
= 0; i
< ranges_table_in_use
; i
++)
9845 int block_num
= ranges_table
[i
].num
;
9849 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9850 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9852 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9853 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9855 /* If all code is in the text section, then the compilation
9856 unit base address defaults to DW_AT_low_pc, which is the
9857 base of the text section. */
9858 if (!have_multiple_function_sections
)
9860 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9862 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9863 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9864 text_section_label
, NULL
);
9867 /* Otherwise, the compilation unit base address is zero,
9868 which allows us to use absolute addresses, and not worry
9869 about whether the target supports cross-section
9873 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9874 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9875 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9881 /* Negative block_num stands for an index into ranges_by_label. */
9882 else if (block_num
< 0)
9884 int lab_idx
= - block_num
- 1;
9886 if (!have_multiple_function_sections
)
9890 /* If we ever use add_ranges_by_labels () for a single
9891 function section, all we have to do is to take out
9893 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9894 ranges_by_label
[lab_idx
].begin
,
9896 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9897 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9898 ranges_by_label
[lab_idx
].end
,
9899 text_section_label
, NULL
);
9904 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9905 ranges_by_label
[lab_idx
].begin
,
9906 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9907 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9908 ranges_by_label
[lab_idx
].end
,
9914 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9915 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9921 /* Data structure containing information about input files. */
9924 const char *path
; /* Complete file name. */
9925 const char *fname
; /* File name part. */
9926 int length
; /* Length of entire string. */
9927 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9928 int dir_idx
; /* Index in directory table. */
9931 /* Data structure containing information about directories with source
9935 const char *path
; /* Path including directory name. */
9936 int length
; /* Path length. */
9937 int prefix
; /* Index of directory entry which is a prefix. */
9938 int count
; /* Number of files in this directory. */
9939 int dir_idx
; /* Index of directory used as base. */
9942 /* Callback function for file_info comparison. We sort by looking at
9943 the directories in the path. */
9946 file_info_cmp (const void *p1
, const void *p2
)
9948 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9949 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9950 const unsigned char *cp1
;
9951 const unsigned char *cp2
;
9953 /* Take care of file names without directories. We need to make sure that
9954 we return consistent values to qsort since some will get confused if
9955 we return the same value when identical operands are passed in opposite
9956 orders. So if neither has a directory, return 0 and otherwise return
9957 1 or -1 depending on which one has the directory. */
9958 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9959 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9961 cp1
= (const unsigned char *) s1
->path
;
9962 cp2
= (const unsigned char *) s2
->path
;
9968 /* Reached the end of the first path? If so, handle like above. */
9969 if ((cp1
== (const unsigned char *) s1
->fname
)
9970 || (cp2
== (const unsigned char *) s2
->fname
))
9971 return ((cp2
== (const unsigned char *) s2
->fname
)
9972 - (cp1
== (const unsigned char *) s1
->fname
));
9974 /* Character of current path component the same? */
9975 else if (*cp1
!= *cp2
)
9980 struct file_name_acquire_data
9982 struct file_info
*files
;
9987 /* Traversal function for the hash table. */
9990 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
9992 struct dwarf_file_data
*d
= *slot
;
9993 struct file_info
*fi
;
9996 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9998 if (! d
->emitted_number
)
10001 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
10003 fi
= fnad
->files
+ fnad
->used_files
++;
10005 /* Skip all leading "./". */
10007 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
10010 /* Create a new array entry. */
10012 fi
->length
= strlen (f
);
10015 /* Search for the file name part. */
10016 f
= strrchr (f
, DIR_SEPARATOR
);
10017 #if defined (DIR_SEPARATOR_2)
10019 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
10023 if (f
== NULL
|| f
< g
)
10029 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
10033 /* Output the directory table and the file name table. We try to minimize
10034 the total amount of memory needed. A heuristic is used to avoid large
10035 slowdowns with many input files. */
10038 output_file_names (void)
10040 struct file_name_acquire_data fnad
;
10042 struct file_info
*files
;
10043 struct dir_info
*dirs
;
10051 if (!last_emitted_file
)
10053 dw2_asm_output_data (1, 0, "End directory table");
10054 dw2_asm_output_data (1, 0, "End file name table");
10058 numfiles
= last_emitted_file
->emitted_number
;
10060 /* Allocate the various arrays we need. */
10061 files
= XALLOCAVEC (struct file_info
, numfiles
);
10062 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
10064 fnad
.files
= files
;
10065 fnad
.used_files
= 0;
10066 fnad
.max_files
= numfiles
;
10067 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
10068 gcc_assert (fnad
.used_files
== fnad
.max_files
);
10070 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
10072 /* Find all the different directories used. */
10073 dirs
[0].path
= files
[0].path
;
10074 dirs
[0].length
= files
[0].fname
- files
[0].path
;
10075 dirs
[0].prefix
= -1;
10077 dirs
[0].dir_idx
= 0;
10078 files
[0].dir_idx
= 0;
10081 for (i
= 1; i
< numfiles
; i
++)
10082 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
10083 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
10084 dirs
[ndirs
- 1].length
) == 0)
10086 /* Same directory as last entry. */
10087 files
[i
].dir_idx
= ndirs
- 1;
10088 ++dirs
[ndirs
- 1].count
;
10094 /* This is a new directory. */
10095 dirs
[ndirs
].path
= files
[i
].path
;
10096 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
10097 dirs
[ndirs
].count
= 1;
10098 dirs
[ndirs
].dir_idx
= ndirs
;
10099 files
[i
].dir_idx
= ndirs
;
10101 /* Search for a prefix. */
10102 dirs
[ndirs
].prefix
= -1;
10103 for (j
= 0; j
< ndirs
; j
++)
10104 if (dirs
[j
].length
< dirs
[ndirs
].length
10105 && dirs
[j
].length
> 1
10106 && (dirs
[ndirs
].prefix
== -1
10107 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
10108 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
10109 dirs
[ndirs
].prefix
= j
;
10114 /* Now to the actual work. We have to find a subset of the directories which
10115 allow expressing the file name using references to the directory table
10116 with the least amount of characters. We do not do an exhaustive search
10117 where we would have to check out every combination of every single
10118 possible prefix. Instead we use a heuristic which provides nearly optimal
10119 results in most cases and never is much off. */
10120 saved
= XALLOCAVEC (int, ndirs
);
10121 savehere
= XALLOCAVEC (int, ndirs
);
10123 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
10124 for (i
= 0; i
< ndirs
; i
++)
10129 /* We can always save some space for the current directory. But this
10130 does not mean it will be enough to justify adding the directory. */
10131 savehere
[i
] = dirs
[i
].length
;
10132 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
10134 for (j
= i
+ 1; j
< ndirs
; j
++)
10137 if (saved
[j
] < dirs
[i
].length
)
10139 /* Determine whether the dirs[i] path is a prefix of the
10143 k
= dirs
[j
].prefix
;
10144 while (k
!= -1 && k
!= (int) i
)
10145 k
= dirs
[k
].prefix
;
10149 /* Yes it is. We can possibly save some memory by
10150 writing the filenames in dirs[j] relative to
10152 savehere
[j
] = dirs
[i
].length
;
10153 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
10158 /* Check whether we can save enough to justify adding the dirs[i]
10160 if (total
> dirs
[i
].length
+ 1)
10162 /* It's worthwhile adding. */
10163 for (j
= i
; j
< ndirs
; j
++)
10164 if (savehere
[j
] > 0)
10166 /* Remember how much we saved for this directory so far. */
10167 saved
[j
] = savehere
[j
];
10169 /* Remember the prefix directory. */
10170 dirs
[j
].dir_idx
= i
;
10175 /* Emit the directory name table. */
10176 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
10177 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
10178 dw2_asm_output_nstring (dirs
[i
].path
,
10180 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
10181 "Directory Entry: %#x", i
+ idx_offset
);
10183 dw2_asm_output_data (1, 0, "End directory table");
10185 /* We have to emit them in the order of emitted_number since that's
10186 used in the debug info generation. To do this efficiently we
10187 generate a back-mapping of the indices first. */
10188 backmap
= XALLOCAVEC (int, numfiles
);
10189 for (i
= 0; i
< numfiles
; i
++)
10190 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
10192 /* Now write all the file names. */
10193 for (i
= 0; i
< numfiles
; i
++)
10195 int file_idx
= backmap
[i
];
10196 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
10198 #ifdef VMS_DEBUGGING_INFO
10199 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
10201 /* Setting these fields can lead to debugger miscomparisons,
10202 but VMS Debug requires them to be set correctly. */
10207 int maxfilelen
= strlen (files
[file_idx
].path
)
10208 + dirs
[dir_idx
].length
10209 + MAX_VMS_VERSION_LEN
+ 1;
10210 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
10212 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
10213 snprintf (filebuf
, maxfilelen
, "%s;%d",
10214 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
10216 dw2_asm_output_nstring
10217 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
10219 /* Include directory index. */
10220 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10222 /* Modification time. */
10223 dw2_asm_output_data_uleb128
10224 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
10228 /* File length in bytes. */
10229 dw2_asm_output_data_uleb128
10230 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
10234 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
10235 "File Entry: %#x", (unsigned) i
+ 1);
10237 /* Include directory index. */
10238 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10240 /* Modification time. */
10241 dw2_asm_output_data_uleb128 (0, NULL
);
10243 /* File length in bytes. */
10244 dw2_asm_output_data_uleb128 (0, NULL
);
10245 #endif /* VMS_DEBUGGING_INFO */
10248 dw2_asm_output_data (1, 0, "End file name table");
10252 /* Output one line number table into the .debug_line section. */
10255 output_one_line_info_table (dw_line_info_table
*table
)
10257 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10258 unsigned int current_line
= 1;
10259 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
10260 dw_line_info_entry
*ent
;
10263 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
10265 switch (ent
->opcode
)
10267 case LI_set_address
:
10268 /* ??? Unfortunately, we have little choice here currently, and
10269 must always use the most general form. GCC does not know the
10270 address delta itself, so we can't use DW_LNS_advance_pc. Many
10271 ports do have length attributes which will give an upper bound
10272 on the address range. We could perhaps use length attributes
10273 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10274 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
10276 /* This can handle any delta. This takes
10277 4+DWARF2_ADDR_SIZE bytes. */
10278 dw2_asm_output_data (1, 0, "set address %s", line_label
);
10279 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10280 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10281 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
10285 if (ent
->val
== current_line
)
10287 /* We still need to start a new row, so output a copy insn. */
10288 dw2_asm_output_data (1, DW_LNS_copy
,
10289 "copy line %u", current_line
);
10293 int line_offset
= ent
->val
- current_line
;
10294 int line_delta
= line_offset
- DWARF_LINE_BASE
;
10296 current_line
= ent
->val
;
10297 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
10299 /* This can handle deltas from -10 to 234, using the current
10300 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10301 This takes 1 byte. */
10302 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
10303 "line %u", current_line
);
10307 /* This can handle any delta. This takes at least 4 bytes,
10308 depending on the value being encoded. */
10309 dw2_asm_output_data (1, DW_LNS_advance_line
,
10310 "advance to line %u", current_line
);
10311 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
10312 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
10318 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
10319 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10322 case LI_set_column
:
10323 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
10324 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10327 case LI_negate_stmt
:
10328 current_is_stmt
= !current_is_stmt
;
10329 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10330 "is_stmt %d", current_is_stmt
);
10333 case LI_set_prologue_end
:
10334 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10335 "set prologue end");
10338 case LI_set_epilogue_begin
:
10339 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10340 "set epilogue begin");
10343 case LI_set_discriminator
:
10344 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10345 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10346 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10347 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10352 /* Emit debug info for the address of the end of the table. */
10353 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10354 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10355 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10356 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10358 dw2_asm_output_data (1, 0, "end sequence");
10359 dw2_asm_output_data_uleb128 (1, NULL
);
10360 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10363 /* Output the source line number correspondence information. This
10364 information goes into the .debug_line section. */
10367 output_line_info (bool prologue_only
)
10369 char l1
[20], l2
[20], p1
[20], p2
[20];
10370 /* We don't support DWARFv5 line tables yet. */
10371 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
10372 bool saw_one
= false;
10375 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10376 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10377 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10378 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10380 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10381 dw2_asm_output_data (4, 0xffffffff,
10382 "Initial length escape value indicating 64-bit DWARF extension");
10383 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10384 "Length of Source Line Info");
10385 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10387 dw2_asm_output_data (2, ver
, "DWARF Version");
10388 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10389 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10391 /* Define the architecture-dependent minimum instruction length (in bytes).
10392 In this implementation of DWARF, this field is used for information
10393 purposes only. Since GCC generates assembly language, we have no
10394 a priori knowledge of how many instruction bytes are generated for each
10395 source line, and therefore can use only the DW_LNE_set_address and
10396 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10397 this as '1', which is "correct enough" for all architectures,
10398 and don't let the target override. */
10399 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10402 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10403 "Maximum Operations Per Instruction");
10404 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10405 "Default is_stmt_start flag");
10406 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10407 "Line Base Value (Special Opcodes)");
10408 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10409 "Line Range Value (Special Opcodes)");
10410 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10411 "Special Opcode Base");
10413 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10418 case DW_LNS_advance_pc
:
10419 case DW_LNS_advance_line
:
10420 case DW_LNS_set_file
:
10421 case DW_LNS_set_column
:
10422 case DW_LNS_fixed_advance_pc
:
10423 case DW_LNS_set_isa
:
10431 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10435 /* Write out the information about the files we use. */
10436 output_file_names ();
10437 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10440 /* Output the marker for the end of the line number info. */
10441 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10445 if (separate_line_info
)
10447 dw_line_info_table
*table
;
10450 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10453 output_one_line_info_table (table
);
10457 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10459 output_one_line_info_table (cold_text_section_line_info
);
10463 /* ??? Some Darwin linkers crash on a .debug_line section with no
10464 sequences. Further, merely a DW_LNE_end_sequence entry is not
10465 sufficient -- the address column must also be initialized.
10466 Make sure to output at least one set_address/end_sequence pair,
10467 choosing .text since that section is always present. */
10468 if (text_section_line_info
->in_use
|| !saw_one
)
10469 output_one_line_info_table (text_section_line_info
);
10471 /* Output the marker for the end of the line number info. */
10472 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10475 /* Given a pointer to a tree node for some base type, return a pointer to
10476 a DIE that describes the given type.
10478 This routine must only be called for GCC type nodes that correspond to
10479 Dwarf base (fundamental) types. */
10482 base_type_die (tree type
)
10484 dw_die_ref base_type_result
;
10485 enum dwarf_type encoding
;
10487 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10490 /* If this is a subtype that should not be emitted as a subrange type,
10491 use the base type. See subrange_type_for_debug_p. */
10492 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10493 type
= TREE_TYPE (type
);
10495 switch (TREE_CODE (type
))
10498 if ((dwarf_version
>= 4 || !dwarf_strict
)
10499 && TYPE_NAME (type
)
10500 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10501 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10502 && DECL_NAME (TYPE_NAME (type
)))
10504 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10505 if (strcmp (name
, "char16_t") == 0
10506 || strcmp (name
, "char32_t") == 0)
10508 encoding
= DW_ATE_UTF
;
10512 if (TYPE_STRING_FLAG (type
))
10514 if (TYPE_UNSIGNED (type
))
10515 encoding
= DW_ATE_unsigned_char
;
10517 encoding
= DW_ATE_signed_char
;
10519 else if (TYPE_UNSIGNED (type
))
10520 encoding
= DW_ATE_unsigned
;
10522 encoding
= DW_ATE_signed
;
10526 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10528 if (dwarf_version
>= 3 || !dwarf_strict
)
10529 encoding
= DW_ATE_decimal_float
;
10531 encoding
= DW_ATE_lo_user
;
10534 encoding
= DW_ATE_float
;
10537 case FIXED_POINT_TYPE
:
10538 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10539 encoding
= DW_ATE_lo_user
;
10540 else if (TYPE_UNSIGNED (type
))
10541 encoding
= DW_ATE_unsigned_fixed
;
10543 encoding
= DW_ATE_signed_fixed
;
10546 /* Dwarf2 doesn't know anything about complex ints, so use
10547 a user defined type for it. */
10549 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10550 encoding
= DW_ATE_complex_float
;
10552 encoding
= DW_ATE_lo_user
;
10556 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10557 encoding
= DW_ATE_boolean
;
10561 /* No other TREE_CODEs are Dwarf fundamental types. */
10562 gcc_unreachable ();
10565 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10567 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10568 int_size_in_bytes (type
));
10569 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10570 add_pubtype (type
, base_type_result
);
10572 return base_type_result
;
10575 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
10576 named 'auto' in its type: return true for it, false otherwise. */
10579 is_cxx_auto (tree type
)
10583 tree name
= TYPE_IDENTIFIER (type
);
10584 if (name
== get_identifier ("auto")
10585 || name
== get_identifier ("decltype(auto)"))
10591 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10592 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10595 is_base_type (tree type
)
10597 switch (TREE_CODE (type
))
10603 case FIXED_POINT_TYPE
:
10606 case POINTER_BOUNDS_TYPE
:
10612 case QUAL_UNION_TYPE
:
10613 case ENUMERAL_TYPE
:
10614 case FUNCTION_TYPE
:
10617 case REFERENCE_TYPE
:
10625 if (is_cxx_auto (type
))
10627 gcc_unreachable ();
10633 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10634 node, return the size in bits for the type if it is a constant, or else
10635 return the alignment for the type if the type's size is not constant, or
10636 else return BITS_PER_WORD if the type actually turns out to be an
10637 ERROR_MARK node. */
10639 static inline unsigned HOST_WIDE_INT
10640 simple_type_size_in_bits (const_tree type
)
10642 if (TREE_CODE (type
) == ERROR_MARK
)
10643 return BITS_PER_WORD
;
10644 else if (TYPE_SIZE (type
) == NULL_TREE
)
10646 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
10647 return tree_to_uhwi (TYPE_SIZE (type
));
10649 return TYPE_ALIGN (type
);
10652 /* Similarly, but return an offset_int instead of UHWI. */
10654 static inline offset_int
10655 offset_int_type_size_in_bits (const_tree type
)
10657 if (TREE_CODE (type
) == ERROR_MARK
)
10658 return BITS_PER_WORD
;
10659 else if (TYPE_SIZE (type
) == NULL_TREE
)
10661 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10662 return wi::to_offset (TYPE_SIZE (type
));
10664 return TYPE_ALIGN (type
);
10667 /* Given a pointer to a tree node for a subrange type, return a pointer
10668 to a DIE that describes the given type. */
10671 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10673 dw_die_ref subrange_die
;
10674 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10676 if (context_die
== NULL
)
10677 context_die
= comp_unit_die ();
10679 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10681 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10683 /* The size of the subrange type and its base type do not match,
10684 so we need to generate a size attribute for the subrange type. */
10685 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10689 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
10691 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
10693 return subrange_die
;
10696 /* Returns the (const and/or volatile) cv_qualifiers associated with
10697 the decl node. This will normally be augmented with the
10698 cv_qualifiers of the underlying type in add_type_attribute. */
10701 decl_quals (const_tree decl
)
10703 return ((TREE_READONLY (decl
)
10704 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
10705 | (TREE_THIS_VOLATILE (decl
)
10706 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
10709 /* Determine the TYPE whose qualifiers match the largest strict subset
10710 of the given TYPE_QUALS, and return its qualifiers. Ignore all
10711 qualifiers outside QUAL_MASK. */
10714 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
10717 int best_rank
= 0, best_qual
= 0, max_rank
;
10719 type_quals
&= qual_mask
;
10720 max_rank
= popcount_hwi (type_quals
) - 1;
10722 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
10723 t
= TYPE_NEXT_VARIANT (t
))
10725 int q
= TYPE_QUALS (t
) & qual_mask
;
10727 if ((q
& type_quals
) == q
&& q
!= type_quals
10728 && check_base_type (t
, type
))
10730 int rank
= popcount_hwi (q
);
10732 if (rank
> best_rank
)
10743 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10744 entry that chains various modifiers in front of the given type. */
10747 modified_type_die (tree type
, int cv_quals
, dw_die_ref context_die
)
10749 enum tree_code code
= TREE_CODE (type
);
10750 dw_die_ref mod_type_die
;
10751 dw_die_ref sub_die
= NULL
;
10752 tree item_type
= NULL
;
10753 tree qualified_type
;
10754 tree name
, low
, high
;
10755 dw_die_ref mod_scope
;
10756 /* Only these cv-qualifiers are currently handled. */
10757 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
10758 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
10760 if (code
== ERROR_MARK
)
10763 cv_quals
&= cv_qual_mask
;
10765 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
10766 tag modifier (and not an attribute) old consumers won't be able
10768 if (dwarf_version
< 3)
10769 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
10771 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
10772 if (dwarf_version
< 5)
10773 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
10775 /* See if we already have the appropriately qualified variant of
10777 qualified_type
= get_qualified_type (type
, cv_quals
);
10779 if (qualified_type
== sizetype
10780 && TYPE_NAME (qualified_type
)
10781 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10783 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10785 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10786 && TYPE_PRECISION (t
)
10787 == TYPE_PRECISION (qualified_type
)
10788 && TYPE_UNSIGNED (t
)
10789 == TYPE_UNSIGNED (qualified_type
));
10790 qualified_type
= t
;
10793 /* If we do, then we can just use its DIE, if it exists. */
10794 if (qualified_type
)
10796 mod_type_die
= lookup_type_die (qualified_type
);
10798 return mod_type_die
;
10801 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10803 /* Handle C typedef types. */
10804 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10805 && !DECL_ARTIFICIAL (name
))
10807 tree dtype
= TREE_TYPE (name
);
10809 if (qualified_type
== dtype
)
10811 /* For a named type, use the typedef. */
10812 gen_type_die (qualified_type
, context_die
);
10813 return lookup_type_die (qualified_type
);
10817 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
10818 dquals
&= cv_qual_mask
;
10819 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
10820 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
10821 /* cv-unqualified version of named type. Just use
10822 the unnamed type to which it refers. */
10823 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10824 cv_quals
, context_die
);
10825 /* Else cv-qualified version of named type; fall through. */
10829 mod_scope
= scope_die_for (type
, context_die
);
10833 struct qual_info
{ int q
; enum dwarf_tag t
; };
10834 static const struct qual_info qual_info
[] =
10836 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
},
10837 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
10838 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
10839 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
10844 /* Determine a lesser qualified type that most closely matches
10845 this one. Then generate DW_TAG_* entries for the remaining
10847 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
10849 mod_type_die
= modified_type_die (type
, sub_quals
, context_die
);
10851 for (i
= 0; i
< sizeof (qual_info
) / sizeof (qual_info
[0]); i
++)
10852 if (qual_info
[i
].q
& cv_quals
& ~sub_quals
)
10854 dw_die_ref d
= new_die (qual_info
[i
].t
, mod_scope
, type
);
10856 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
10860 else if (code
== POINTER_TYPE
)
10862 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10863 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10864 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10865 item_type
= TREE_TYPE (type
);
10866 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10867 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10868 TYPE_ADDR_SPACE (item_type
));
10870 else if (code
== REFERENCE_TYPE
)
10872 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10873 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10876 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10877 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10878 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10879 item_type
= TREE_TYPE (type
);
10880 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10881 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10882 TYPE_ADDR_SPACE (item_type
));
10884 else if (code
== INTEGER_TYPE
10885 && TREE_TYPE (type
) != NULL_TREE
10886 && subrange_type_for_debug_p (type
, &low
, &high
))
10888 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10889 item_type
= TREE_TYPE (type
);
10891 else if (is_base_type (type
))
10892 mod_type_die
= base_type_die (type
);
10895 gen_type_die (type
, context_die
);
10897 /* We have to get the type_main_variant here (and pass that to the
10898 `lookup_type_die' routine) because the ..._TYPE node we have
10899 might simply be a *copy* of some original type node (where the
10900 copy was created to help us keep track of typedef names) and
10901 that copy might have a different TYPE_UID from the original
10903 if (TREE_CODE (type
) != VECTOR_TYPE
)
10904 return lookup_type_die (type_main_variant (type
));
10906 /* Vectors have the debugging information in the type,
10907 not the main variant. */
10908 return lookup_type_die (type
);
10911 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10912 don't output a DW_TAG_typedef, since there isn't one in the
10913 user's program; just attach a DW_AT_name to the type.
10914 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10915 if the base type already has the same name. */
10917 && ((TREE_CODE (name
) != TYPE_DECL
10918 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10919 || (cv_quals
== TYPE_UNQUALIFIED
)))
10920 || (TREE_CODE (name
) == TYPE_DECL
10921 && TREE_TYPE (name
) == qualified_type
10922 && DECL_NAME (name
))))
10924 if (TREE_CODE (name
) == TYPE_DECL
)
10925 /* Could just call add_name_and_src_coords_attributes here,
10926 but since this is a builtin type it doesn't have any
10927 useful source coordinates anyway. */
10928 name
= DECL_NAME (name
);
10929 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10931 /* This probably indicates a bug. */
10932 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10934 name
= TYPE_IDENTIFIER (type
);
10935 add_name_attribute (mod_type_die
,
10936 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10939 if (qualified_type
)
10940 equate_type_number_to_die (qualified_type
, mod_type_die
);
10943 /* We must do this after the equate_type_number_to_die call, in case
10944 this is a recursive type. This ensures that the modified_type_die
10945 recursion will terminate even if the type is recursive. Recursive
10946 types are possible in Ada. */
10947 sub_die
= modified_type_die (item_type
,
10948 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
10951 if (sub_die
!= NULL
)
10952 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10954 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10955 if (TYPE_ARTIFICIAL (type
))
10956 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10958 return mod_type_die
;
10961 /* Generate DIEs for the generic parameters of T.
10962 T must be either a generic type or a generic function.
10963 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10966 gen_generic_params_dies (tree t
)
10970 dw_die_ref die
= NULL
;
10973 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10977 die
= lookup_type_die (t
);
10978 else if (DECL_P (t
))
10979 die
= lookup_decl_die (t
);
10983 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10985 /* T has no generic parameter. It means T is neither a generic type
10986 or function. End of story. */
10989 parms_num
= TREE_VEC_LENGTH (parms
);
10990 args
= lang_hooks
.get_innermost_generic_args (t
);
10991 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10992 non_default
= int_cst_value (TREE_CHAIN (args
));
10994 non_default
= TREE_VEC_LENGTH (args
);
10995 for (i
= 0; i
< parms_num
; i
++)
10997 tree parm
, arg
, arg_pack_elems
;
10998 dw_die_ref parm_die
;
11000 parm
= TREE_VEC_ELT (parms
, i
);
11001 arg
= TREE_VEC_ELT (args
, i
);
11002 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
11003 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
11005 if (parm
&& TREE_VALUE (parm
) && arg
)
11007 /* If PARM represents a template parameter pack,
11008 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
11009 by DW_TAG_template_*_parameter DIEs for the argument
11010 pack elements of ARG. Note that ARG would then be
11011 an argument pack. */
11012 if (arg_pack_elems
)
11013 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
11017 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
11018 true /* emit name */, die
);
11019 if (i
>= non_default
)
11020 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
11025 /* Create and return a DIE for PARM which should be
11026 the representation of a generic type parameter.
11027 For instance, in the C++ front end, PARM would be a template parameter.
11028 ARG is the argument to PARM.
11029 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
11031 PARENT_DIE is the parent DIE which the new created DIE should be added to,
11032 as a child node. */
11035 generic_parameter_die (tree parm
, tree arg
,
11037 dw_die_ref parent_die
)
11039 dw_die_ref tmpl_die
= NULL
;
11040 const char *name
= NULL
;
11042 if (!parm
|| !DECL_NAME (parm
) || !arg
)
11045 /* We support non-type generic parameters and arguments,
11046 type generic parameters and arguments, as well as
11047 generic generic parameters (a.k.a. template template parameters in C++)
11049 if (TREE_CODE (parm
) == PARM_DECL
)
11050 /* PARM is a nontype generic parameter */
11051 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
11052 else if (TREE_CODE (parm
) == TYPE_DECL
)
11053 /* PARM is a type generic parameter. */
11054 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
11055 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11056 /* PARM is a generic generic parameter.
11057 Its DIE is a GNU extension. It shall have a
11058 DW_AT_name attribute to represent the name of the template template
11059 parameter, and a DW_AT_GNU_template_name attribute to represent the
11060 name of the template template argument. */
11061 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
11064 gcc_unreachable ();
11070 /* If PARM is a generic parameter pack, it means we are
11071 emitting debug info for a template argument pack element.
11072 In other terms, ARG is a template argument pack element.
11073 In that case, we don't emit any DW_AT_name attribute for
11077 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
11079 add_AT_string (tmpl_die
, DW_AT_name
, name
);
11082 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11084 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
11085 TMPL_DIE should have a child DW_AT_type attribute that is set
11086 to the type of the argument to PARM, which is ARG.
11087 If PARM is a type generic parameter, TMPL_DIE should have a
11088 child DW_AT_type that is set to ARG. */
11089 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
11090 add_type_attribute (tmpl_die
, tmpl_type
,
11091 (TREE_THIS_VOLATILE (tmpl_type
)
11092 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
11097 /* So TMPL_DIE is a DIE representing a
11098 a generic generic template parameter, a.k.a template template
11099 parameter in C++ and arg is a template. */
11101 /* The DW_AT_GNU_template_name attribute of the DIE must be set
11102 to the name of the argument. */
11103 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
11105 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
11108 if (TREE_CODE (parm
) == PARM_DECL
)
11109 /* So PARM is a non-type generic parameter.
11110 DWARF3 5.6.8 says we must set a DW_AT_const_value child
11111 attribute of TMPL_DIE which value represents the value
11113 We must be careful here:
11114 The value of ARG might reference some function decls.
11115 We might currently be emitting debug info for a generic
11116 type and types are emitted before function decls, we don't
11117 know if the function decls referenced by ARG will actually be
11118 emitted after cgraph computations.
11119 So must defer the generation of the DW_AT_const_value to
11120 after cgraph is ready. */
11121 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
11127 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
11128 PARM_PACK must be a template parameter pack. The returned DIE
11129 will be child DIE of PARENT_DIE. */
11132 template_parameter_pack_die (tree parm_pack
,
11133 tree parm_pack_args
,
11134 dw_die_ref parent_die
)
11139 gcc_assert (parent_die
&& parm_pack
);
11141 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
11142 add_name_and_src_coords_attributes (die
, parm_pack
);
11143 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
11144 generic_parameter_die (parm_pack
,
11145 TREE_VEC_ELT (parm_pack_args
, j
),
11146 false /* Don't emit DW_AT_name */,
11151 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
11152 an enumerated type. */
11155 type_is_enum (const_tree type
)
11157 return TREE_CODE (type
) == ENUMERAL_TYPE
;
11160 /* Return the DBX register number described by a given RTL node. */
11162 static unsigned int
11163 dbx_reg_number (const_rtx rtl
)
11165 unsigned regno
= REGNO (rtl
);
11167 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
11169 #ifdef LEAF_REG_REMAP
11170 if (crtl
->uses_only_leaf_regs
)
11172 int leaf_reg
= LEAF_REG_REMAP (regno
);
11173 if (leaf_reg
!= -1)
11174 regno
= (unsigned) leaf_reg
;
11178 regno
= DBX_REGISTER_NUMBER (regno
);
11179 gcc_assert (regno
!= INVALID_REGNUM
);
11183 /* Optionally add a DW_OP_piece term to a location description expression.
11184 DW_OP_piece is only added if the location description expression already
11185 doesn't end with DW_OP_piece. */
11188 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
11190 dw_loc_descr_ref loc
;
11192 if (*list_head
!= NULL
)
11194 /* Find the end of the chain. */
11195 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
11198 if (loc
->dw_loc_opc
!= DW_OP_piece
)
11199 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
11203 /* Return a location descriptor that designates a machine register or
11204 zero if there is none. */
11206 static dw_loc_descr_ref
11207 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
11211 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
11214 /* We only use "frame base" when we're sure we're talking about the
11215 post-prologue local stack frame. We do this by *not* running
11216 register elimination until this point, and recognizing the special
11217 argument pointer and soft frame pointer rtx's.
11218 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
11219 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
11220 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
11222 dw_loc_descr_ref result
= NULL
;
11224 if (dwarf_version
>= 4 || !dwarf_strict
)
11226 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
11229 add_loc_descr (&result
,
11230 new_loc_descr (DW_OP_stack_value
, 0, 0));
11235 regs
= targetm
.dwarf_register_span (rtl
);
11237 if (REG_NREGS (rtl
) > 1 || regs
)
11238 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
11241 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
11242 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11244 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
11248 /* Return a location descriptor that designates a machine register for
11249 a given hard register number. */
11251 static dw_loc_descr_ref
11252 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
11254 dw_loc_descr_ref reg_loc_descr
;
11258 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
11260 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
11262 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11263 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11265 return reg_loc_descr
;
11268 /* Given an RTL of a register, return a location descriptor that
11269 designates a value that spans more than one register. */
11271 static dw_loc_descr_ref
11272 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
11273 enum var_init_status initialized
)
11276 dw_loc_descr_ref loc_result
= NULL
;
11278 /* Simple, contiguous registers. */
11279 if (regs
== NULL_RTX
)
11281 unsigned reg
= REGNO (rtl
);
11284 #ifdef LEAF_REG_REMAP
11285 if (crtl
->uses_only_leaf_regs
)
11287 int leaf_reg
= LEAF_REG_REMAP (reg
);
11288 if (leaf_reg
!= -1)
11289 reg
= (unsigned) leaf_reg
;
11293 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
11294 nregs
= REG_NREGS (rtl
);
11296 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
11301 dw_loc_descr_ref t
;
11303 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
11304 VAR_INIT_STATUS_INITIALIZED
);
11305 add_loc_descr (&loc_result
, t
);
11306 add_loc_descr_op_piece (&loc_result
, size
);
11312 /* Now onto stupid register sets in non contiguous locations. */
11314 gcc_assert (GET_CODE (regs
) == PARALLEL
);
11316 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
11319 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
11321 dw_loc_descr_ref t
;
11323 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
11324 VAR_INIT_STATUS_INITIALIZED
);
11325 add_loc_descr (&loc_result
, t
);
11326 add_loc_descr_op_piece (&loc_result
, size
);
11329 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11330 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11334 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
11336 /* Return a location descriptor that designates a constant i,
11337 as a compound operation from constant (i >> shift), constant shift
11340 static dw_loc_descr_ref
11341 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11343 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
11344 add_loc_descr (&ret
, int_loc_descriptor (shift
));
11345 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11349 /* Return a location descriptor that designates a constant. */
11351 static dw_loc_descr_ref
11352 int_loc_descriptor (HOST_WIDE_INT i
)
11354 enum dwarf_location_atom op
;
11356 /* Pick the smallest representation of a constant, rather than just
11357 defaulting to the LEB encoding. */
11360 int clz
= clz_hwi (i
);
11361 int ctz
= ctz_hwi (i
);
11363 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
11364 else if (i
<= 0xff)
11365 op
= DW_OP_const1u
;
11366 else if (i
<= 0xffff)
11367 op
= DW_OP_const2u
;
11368 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11369 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11370 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11371 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11372 while DW_OP_const4u is 5 bytes. */
11373 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
11374 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11375 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11376 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11377 while DW_OP_const4u is 5 bytes. */
11378 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11379 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11380 op
= DW_OP_const4u
;
11381 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11382 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11383 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11384 while DW_OP_constu of constant >= 0x100000000 takes at least
11386 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11387 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11388 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
11389 >= HOST_BITS_PER_WIDE_INT
)
11390 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11391 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11392 while DW_OP_constu takes in this case at least 6 bytes. */
11393 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
11394 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11395 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11396 && size_of_uleb128 (i
) > 6)
11397 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11398 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11405 op
= DW_OP_const1s
;
11406 else if (i
>= -0x8000)
11407 op
= DW_OP_const2s
;
11408 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11410 if (size_of_int_loc_descriptor (i
) < 5)
11412 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11413 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11416 op
= DW_OP_const4s
;
11420 if (size_of_int_loc_descriptor (i
)
11421 < (unsigned long) 1 + size_of_sleb128 (i
))
11423 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11424 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11431 return new_loc_descr (op
, i
, 0);
11434 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
11435 without actually allocating it. */
11437 static unsigned long
11438 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11440 return size_of_int_loc_descriptor (i
>> shift
)
11441 + size_of_int_loc_descriptor (shift
)
11445 /* Return size_of_locs (int_loc_descriptor (i)) without
11446 actually allocating it. */
11448 static unsigned long
11449 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11458 else if (i
<= 0xff)
11460 else if (i
<= 0xffff)
11464 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11465 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11466 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11468 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11469 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11470 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11472 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11474 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11475 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11476 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11477 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11479 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11480 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11481 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11483 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11484 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11486 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11495 else if (i
>= -0x8000)
11497 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11499 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11501 s
= size_of_int_loc_descriptor (-i
) + 1;
11509 unsigned long r
= 1 + size_of_sleb128 (i
);
11510 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11512 s
= size_of_int_loc_descriptor (-i
) + 1;
11521 /* Return loc description representing "address" of integer value.
11522 This can appear only as toplevel expression. */
11524 static dw_loc_descr_ref
11525 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11528 dw_loc_descr_ref loc_result
= NULL
;
11530 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11533 litsize
= size_of_int_loc_descriptor (i
);
11534 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11535 is more compact. For DW_OP_stack_value we need:
11536 litsize + 1 (DW_OP_stack_value)
11537 and for DW_OP_implicit_value:
11538 1 (DW_OP_implicit_value) + 1 (length) + size. */
11539 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11541 loc_result
= int_loc_descriptor (i
);
11542 add_loc_descr (&loc_result
,
11543 new_loc_descr (DW_OP_stack_value
, 0, 0));
11547 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11549 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11550 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11554 /* Return a location descriptor that designates a base+offset location. */
11556 static dw_loc_descr_ref
11557 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11558 enum var_init_status initialized
)
11560 unsigned int regno
;
11561 dw_loc_descr_ref result
;
11562 dw_fde_ref fde
= cfun
->fde
;
11564 /* We only use "frame base" when we're sure we're talking about the
11565 post-prologue local stack frame. We do this by *not* running
11566 register elimination until this point, and recognizing the special
11567 argument pointer and soft frame pointer rtx's. */
11568 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11570 rtx elim
= (ira_use_lra_p
11571 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11572 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11576 if (GET_CODE (elim
) == PLUS
)
11578 offset
+= INTVAL (XEXP (elim
, 1));
11579 elim
= XEXP (elim
, 0);
11581 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11582 && (elim
== hard_frame_pointer_rtx
11583 || elim
== stack_pointer_rtx
))
11584 || elim
== (frame_pointer_needed
11585 ? hard_frame_pointer_rtx
11586 : stack_pointer_rtx
));
11588 /* If drap register is used to align stack, use frame
11589 pointer + offset to access stack variables. If stack
11590 is aligned without drap, use stack pointer + offset to
11591 access stack variables. */
11592 if (crtl
->stack_realign_tried
11593 && reg
== frame_pointer_rtx
)
11596 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11597 ? HARD_FRAME_POINTER_REGNUM
11599 return new_reg_loc_descr (base_reg
, offset
);
11602 gcc_assert (frame_pointer_fb_offset_valid
);
11603 offset
+= frame_pointer_fb_offset
;
11604 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11608 regno
= REGNO (reg
);
11609 #ifdef LEAF_REG_REMAP
11610 if (crtl
->uses_only_leaf_regs
)
11612 int leaf_reg
= LEAF_REG_REMAP (regno
);
11613 if (leaf_reg
!= -1)
11614 regno
= (unsigned) leaf_reg
;
11617 regno
= DWARF_FRAME_REGNUM (regno
);
11619 if (!optimize
&& fde
11620 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11622 /* Use cfa+offset to represent the location of arguments passed
11623 on the stack when drap is used to align stack.
11624 Only do this when not optimizing, for optimized code var-tracking
11625 is supposed to track where the arguments live and the register
11626 used as vdrap or drap in some spot might be used for something
11627 else in other part of the routine. */
11628 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11632 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11635 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11637 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11638 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11643 /* Return true if this RTL expression describes a base+offset calculation. */
11646 is_based_loc (const_rtx rtl
)
11648 return (GET_CODE (rtl
) == PLUS
11649 && ((REG_P (XEXP (rtl
, 0))
11650 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11651 && CONST_INT_P (XEXP (rtl
, 1)))));
11654 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11657 static dw_loc_descr_ref
11658 tls_mem_loc_descriptor (rtx mem
)
11661 dw_loc_descr_ref loc_result
;
11663 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11666 base
= get_base_address (MEM_EXPR (mem
));
11668 || TREE_CODE (base
) != VAR_DECL
11669 || !DECL_THREAD_LOCAL_P (base
))
11672 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
11673 if (loc_result
== NULL
)
11676 if (MEM_OFFSET (mem
))
11677 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11682 /* Output debug info about reason why we failed to expand expression as dwarf
11686 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11688 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11690 fprintf (dump_file
, "Failed to expand as dwarf: ");
11692 print_generic_expr (dump_file
, expr
, dump_flags
);
11695 fprintf (dump_file
, "\n");
11696 print_rtl (dump_file
, rtl
);
11698 fprintf (dump_file
, "\nReason: %s\n", reason
);
11702 /* Helper function for const_ok_for_output. */
11705 const_ok_for_output_1 (rtx rtl
)
11707 if (GET_CODE (rtl
) == UNSPEC
)
11709 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11710 we can't express it in the debug info. */
11711 #ifdef ENABLE_CHECKING
11712 /* Don't complain about TLS UNSPECs, those are just too hard to
11713 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11714 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11715 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11716 if (XVECLEN (rtl
, 0) == 0
11717 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11718 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11719 inform (current_function_decl
11720 ? DECL_SOURCE_LOCATION (current_function_decl
)
11721 : UNKNOWN_LOCATION
,
11722 #if NUM_UNSPEC_VALUES > 0
11723 "non-delegitimized UNSPEC %s (%d) found in variable location",
11724 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11725 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11728 "non-delegitimized UNSPEC %d found in variable location",
11732 expansion_failed (NULL_TREE
, rtl
,
11733 "UNSPEC hasn't been delegitimized.\n");
11737 if (targetm
.const_not_ok_for_debug_p (rtl
))
11739 expansion_failed (NULL_TREE
, rtl
,
11740 "Expression rejected for debug by the backend.\n");
11744 /* FIXME: Refer to PR60655. It is possible for simplification
11745 of rtl expressions in var tracking to produce such expressions.
11746 We should really identify / validate expressions
11747 enclosed in CONST that can be handled by assemblers on various
11748 targets and only handle legitimate cases here. */
11749 if (GET_CODE (rtl
) != SYMBOL_REF
)
11751 if (GET_CODE (rtl
) == NOT
)
11756 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11759 get_pool_constant_mark (rtl
, &marked
);
11760 /* If all references to this pool constant were optimized away,
11761 it was not output and thus we can't represent it. */
11764 expansion_failed (NULL_TREE
, rtl
,
11765 "Constant was removed from constant pool.\n");
11770 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11773 /* Avoid references to external symbols in debug info, on several targets
11774 the linker might even refuse to link when linking a shared library,
11775 and in many other cases the relocations for .debug_info/.debug_loc are
11776 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11777 to be defined within the same shared library or executable are fine. */
11778 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11780 tree decl
= SYMBOL_REF_DECL (rtl
);
11782 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11784 expansion_failed (NULL_TREE
, rtl
,
11785 "Symbol not defined in current TU.\n");
11793 /* Return true if constant RTL can be emitted in DW_OP_addr or
11794 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11795 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11798 const_ok_for_output (rtx rtl
)
11800 if (GET_CODE (rtl
) == SYMBOL_REF
)
11801 return const_ok_for_output_1 (rtl
);
11803 if (GET_CODE (rtl
) == CONST
)
11805 subrtx_var_iterator::array_type array
;
11806 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
11807 if (!const_ok_for_output_1 (*iter
))
11815 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11816 if possible, NULL otherwise. */
11819 base_type_for_mode (machine_mode mode
, bool unsignedp
)
11821 dw_die_ref type_die
;
11822 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11826 switch (TREE_CODE (type
))
11834 type_die
= lookup_type_die (type
);
11836 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, comp_unit_die ());
11837 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11842 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11843 type matching MODE, or, if MODE is narrower than or as wide as
11844 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11847 static dw_loc_descr_ref
11848 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
11850 machine_mode outer_mode
= mode
;
11851 dw_die_ref type_die
;
11852 dw_loc_descr_ref cvt
;
11854 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11856 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11859 type_die
= base_type_for_mode (outer_mode
, 1);
11860 if (type_die
== NULL
)
11862 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11863 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11864 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11865 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11866 add_loc_descr (&op
, cvt
);
11870 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11872 static dw_loc_descr_ref
11873 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11874 dw_loc_descr_ref op1
)
11876 dw_loc_descr_ref ret
= op0
;
11877 add_loc_descr (&ret
, op1
);
11878 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11879 if (STORE_FLAG_VALUE
!= 1)
11881 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11882 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11887 /* Return location descriptor for signed comparison OP RTL. */
11889 static dw_loc_descr_ref
11890 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11891 machine_mode mem_mode
)
11893 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11894 dw_loc_descr_ref op0
, op1
;
11897 if (op_mode
== VOIDmode
)
11898 op_mode
= GET_MODE (XEXP (rtl
, 1));
11899 if (op_mode
== VOIDmode
)
11903 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11904 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11907 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11908 VAR_INIT_STATUS_INITIALIZED
);
11909 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11910 VAR_INIT_STATUS_INITIALIZED
);
11912 if (op0
== NULL
|| op1
== NULL
)
11915 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11916 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11917 return compare_loc_descriptor (op
, op0
, op1
);
11919 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11921 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11922 dw_loc_descr_ref cvt
;
11924 if (type_die
== NULL
)
11926 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11927 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11928 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11929 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11930 add_loc_descr (&op0
, cvt
);
11931 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11932 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11933 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11934 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11935 add_loc_descr (&op1
, cvt
);
11936 return compare_loc_descriptor (op
, op0
, op1
);
11939 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11940 /* For eq/ne, if the operands are known to be zero-extended,
11941 there is no need to do the fancy shifting up. */
11942 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11944 dw_loc_descr_ref last0
, last1
;
11945 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11947 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11949 /* deref_size zero extends, and for constants we can check
11950 whether they are zero extended or not. */
11951 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11952 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11953 || (CONST_INT_P (XEXP (rtl
, 0))
11954 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11955 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11956 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11957 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11958 || (CONST_INT_P (XEXP (rtl
, 1))
11959 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11960 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11961 return compare_loc_descriptor (op
, op0
, op1
);
11963 /* EQ/NE comparison against constant in narrower type than
11964 DWARF2_ADDR_SIZE can be performed either as
11965 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11968 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11969 DW_OP_{eq,ne}. Pick whatever is shorter. */
11970 if (CONST_INT_P (XEXP (rtl
, 1))
11971 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11972 && (size_of_int_loc_descriptor (shift
) + 1
11973 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11974 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11975 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11976 & GET_MODE_MASK (op_mode
))))
11978 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11979 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11980 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11981 & GET_MODE_MASK (op_mode
));
11982 return compare_loc_descriptor (op
, op0
, op1
);
11985 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11986 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11987 if (CONST_INT_P (XEXP (rtl
, 1)))
11988 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11991 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11992 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11994 return compare_loc_descriptor (op
, op0
, op1
);
11997 /* Return location descriptor for unsigned comparison OP RTL. */
11999 static dw_loc_descr_ref
12000 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
12001 machine_mode mem_mode
)
12003 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
12004 dw_loc_descr_ref op0
, op1
;
12006 if (op_mode
== VOIDmode
)
12007 op_mode
= GET_MODE (XEXP (rtl
, 1));
12008 if (op_mode
== VOIDmode
)
12010 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
12013 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
12016 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
12017 VAR_INIT_STATUS_INITIALIZED
);
12018 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
12019 VAR_INIT_STATUS_INITIALIZED
);
12021 if (op0
== NULL
|| op1
== NULL
)
12024 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
12026 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
12027 dw_loc_descr_ref last0
, last1
;
12028 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
12030 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
12032 if (CONST_INT_P (XEXP (rtl
, 0)))
12033 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
12034 /* deref_size zero extends, so no need to mask it again. */
12035 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
12036 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12038 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12039 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12041 if (CONST_INT_P (XEXP (rtl
, 1)))
12042 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
12043 /* deref_size zero extends, so no need to mask it again. */
12044 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
12045 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12047 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12048 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12051 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
12053 HOST_WIDE_INT bias
= 1;
12054 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12055 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12056 if (CONST_INT_P (XEXP (rtl
, 1)))
12057 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
12058 + INTVAL (XEXP (rtl
, 1)));
12060 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
12063 return compare_loc_descriptor (op
, op0
, op1
);
12066 /* Return location descriptor for {U,S}{MIN,MAX}. */
12068 static dw_loc_descr_ref
12069 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
12070 machine_mode mem_mode
)
12072 enum dwarf_location_atom op
;
12073 dw_loc_descr_ref op0
, op1
, ret
;
12074 dw_loc_descr_ref bra_node
, drop_node
;
12077 && (GET_MODE_CLASS (mode
) != MODE_INT
12078 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
12081 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12082 VAR_INIT_STATUS_INITIALIZED
);
12083 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12084 VAR_INIT_STATUS_INITIALIZED
);
12086 if (op0
== NULL
|| op1
== NULL
)
12089 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
12090 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
12091 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
12092 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
12094 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12096 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
12097 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12098 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12099 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12100 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12102 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12104 HOST_WIDE_INT bias
= 1;
12105 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12106 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12107 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12110 else if (GET_MODE_CLASS (mode
) == MODE_INT
12111 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12113 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
12114 add_loc_descr (&op0
, int_loc_descriptor (shift
));
12115 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
12116 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12117 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12119 else if (GET_MODE_CLASS (mode
) == MODE_INT
12120 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12122 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
12123 dw_loc_descr_ref cvt
;
12124 if (type_die
== NULL
)
12126 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12127 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12128 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12129 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12130 add_loc_descr (&op0
, cvt
);
12131 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12132 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12133 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12134 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12135 add_loc_descr (&op1
, cvt
);
12138 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
12143 add_loc_descr (&ret
, op1
);
12144 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12145 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12146 add_loc_descr (&ret
, bra_node
);
12147 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12148 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12149 add_loc_descr (&ret
, drop_node
);
12150 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12151 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12152 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
12153 && GET_MODE_CLASS (mode
) == MODE_INT
12154 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12155 ret
= convert_descriptor_to_mode (mode
, ret
);
12159 /* Helper function for mem_loc_descriptor. Perform OP binary op,
12160 but after converting arguments to type_die, afterwards
12161 convert back to unsigned. */
12163 static dw_loc_descr_ref
12164 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
12165 machine_mode mode
, machine_mode mem_mode
)
12167 dw_loc_descr_ref cvt
, op0
, op1
;
12169 if (type_die
== NULL
)
12171 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12172 VAR_INIT_STATUS_INITIALIZED
);
12173 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12174 VAR_INIT_STATUS_INITIALIZED
);
12175 if (op0
== NULL
|| op1
== NULL
)
12177 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12178 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12179 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12180 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12181 add_loc_descr (&op0
, cvt
);
12182 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12183 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12184 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12185 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12186 add_loc_descr (&op1
, cvt
);
12187 add_loc_descr (&op0
, op1
);
12188 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
12189 return convert_descriptor_to_mode (mode
, op0
);
12192 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
12193 const0 is DW_OP_lit0 or corresponding typed constant,
12194 const1 is DW_OP_lit1 or corresponding typed constant
12195 and constMSB is constant with just the MSB bit set
12197 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12198 L1: const0 DW_OP_swap
12199 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
12200 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12205 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12206 L1: const0 DW_OP_swap
12207 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12208 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12213 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
12214 L1: const1 DW_OP_swap
12215 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12216 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12220 static dw_loc_descr_ref
12221 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
12222 machine_mode mem_mode
)
12224 dw_loc_descr_ref op0
, ret
, tmp
;
12225 HOST_WIDE_INT valv
;
12226 dw_loc_descr_ref l1jump
, l1label
;
12227 dw_loc_descr_ref l2jump
, l2label
;
12228 dw_loc_descr_ref l3jump
, l3label
;
12229 dw_loc_descr_ref l4jump
, l4label
;
12232 if (GET_MODE_CLASS (mode
) != MODE_INT
12233 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12236 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12237 VAR_INIT_STATUS_INITIALIZED
);
12241 if (GET_CODE (rtl
) == CLZ
)
12243 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12244 valv
= GET_MODE_BITSIZE (mode
);
12246 else if (GET_CODE (rtl
) == FFS
)
12248 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12249 valv
= GET_MODE_BITSIZE (mode
);
12250 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12251 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12252 add_loc_descr (&ret
, l1jump
);
12253 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12254 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
12255 VAR_INIT_STATUS_INITIALIZED
);
12258 add_loc_descr (&ret
, tmp
);
12259 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12260 add_loc_descr (&ret
, l4jump
);
12261 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
12262 ? const1_rtx
: const0_rtx
,
12264 VAR_INIT_STATUS_INITIALIZED
);
12265 if (l1label
== NULL
)
12267 add_loc_descr (&ret
, l1label
);
12268 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12269 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
12270 add_loc_descr (&ret
, l2label
);
12271 if (GET_CODE (rtl
) != CLZ
)
12273 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
12274 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
12275 << (GET_MODE_BITSIZE (mode
) - 1));
12277 msb
= immed_wide_int_const
12278 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
12279 GET_MODE_PRECISION (mode
)), mode
);
12280 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
12281 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12282 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
12283 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
12285 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
12286 VAR_INIT_STATUS_INITIALIZED
);
12289 add_loc_descr (&ret
, tmp
);
12290 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12291 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12292 add_loc_descr (&ret
, l3jump
);
12293 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12294 VAR_INIT_STATUS_INITIALIZED
);
12297 add_loc_descr (&ret
, tmp
);
12298 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
12299 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
12300 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12301 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
12302 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12303 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12304 add_loc_descr (&ret
, l2jump
);
12305 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
12306 add_loc_descr (&ret
, l3label
);
12307 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
12308 add_loc_descr (&ret
, l4label
);
12309 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12310 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12311 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12312 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12313 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12314 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
12315 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12316 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
12320 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
12321 const1 is DW_OP_lit1 or corresponding typed constant):
12323 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12324 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12328 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12329 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12332 static dw_loc_descr_ref
12333 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
12334 machine_mode mem_mode
)
12336 dw_loc_descr_ref op0
, ret
, tmp
;
12337 dw_loc_descr_ref l1jump
, l1label
;
12338 dw_loc_descr_ref l2jump
, l2label
;
12340 if (GET_MODE_CLASS (mode
) != MODE_INT
12341 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12344 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12345 VAR_INIT_STATUS_INITIALIZED
);
12349 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12350 VAR_INIT_STATUS_INITIALIZED
);
12353 add_loc_descr (&ret
, tmp
);
12354 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12355 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
12356 add_loc_descr (&ret
, l1label
);
12357 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12358 add_loc_descr (&ret
, l2jump
);
12359 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12360 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12361 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12362 VAR_INIT_STATUS_INITIALIZED
);
12365 add_loc_descr (&ret
, tmp
);
12366 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12367 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
12368 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
12369 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12370 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12371 VAR_INIT_STATUS_INITIALIZED
);
12372 add_loc_descr (&ret
, tmp
);
12373 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12374 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12375 add_loc_descr (&ret
, l1jump
);
12376 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12377 add_loc_descr (&ret
, l2label
);
12378 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12379 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12380 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12381 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12385 /* BSWAP (constS is initial shift count, either 56 or 24):
12387 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
12388 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
12389 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
12390 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
12391 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
12393 static dw_loc_descr_ref
12394 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
12395 machine_mode mem_mode
)
12397 dw_loc_descr_ref op0
, ret
, tmp
;
12398 dw_loc_descr_ref l1jump
, l1label
;
12399 dw_loc_descr_ref l2jump
, l2label
;
12401 if (GET_MODE_CLASS (mode
) != MODE_INT
12402 || BITS_PER_UNIT
!= 8
12403 || (GET_MODE_BITSIZE (mode
) != 32
12404 && GET_MODE_BITSIZE (mode
) != 64))
12407 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12408 VAR_INIT_STATUS_INITIALIZED
);
12413 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12415 VAR_INIT_STATUS_INITIALIZED
);
12418 add_loc_descr (&ret
, tmp
);
12419 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12420 VAR_INIT_STATUS_INITIALIZED
);
12423 add_loc_descr (&ret
, tmp
);
12424 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
12425 add_loc_descr (&ret
, l1label
);
12426 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12428 VAR_INIT_STATUS_INITIALIZED
);
12429 add_loc_descr (&ret
, tmp
);
12430 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
12431 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12432 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12433 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
12434 VAR_INIT_STATUS_INITIALIZED
);
12437 add_loc_descr (&ret
, tmp
);
12438 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12439 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
12440 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12441 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12442 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12443 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12444 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12445 VAR_INIT_STATUS_INITIALIZED
);
12446 add_loc_descr (&ret
, tmp
);
12447 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
12448 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12449 add_loc_descr (&ret
, l2jump
);
12450 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
12451 VAR_INIT_STATUS_INITIALIZED
);
12452 add_loc_descr (&ret
, tmp
);
12453 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12454 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12455 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12456 add_loc_descr (&ret
, l1jump
);
12457 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12458 add_loc_descr (&ret
, l2label
);
12459 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12460 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12461 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12462 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12463 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12464 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12468 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12469 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12470 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12471 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12473 ROTATERT is similar:
12474 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12475 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12476 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12478 static dw_loc_descr_ref
12479 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
12480 machine_mode mem_mode
)
12482 rtx rtlop1
= XEXP (rtl
, 1);
12483 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12486 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12489 if (GET_MODE (rtlop1
) != VOIDmode
12490 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12491 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12492 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12493 VAR_INIT_STATUS_INITIALIZED
);
12494 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12495 VAR_INIT_STATUS_INITIALIZED
);
12496 if (op0
== NULL
|| op1
== NULL
)
12498 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12499 for (i
= 0; i
< 2; i
++)
12501 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12502 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12504 VAR_INIT_STATUS_INITIALIZED
);
12505 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12506 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12508 : HOST_BITS_PER_WIDE_INT
== 64
12509 ? DW_OP_const8u
: DW_OP_constu
,
12510 GET_MODE_MASK (mode
), 0);
12513 if (mask
[i
] == NULL
)
12515 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12518 add_loc_descr (&ret
, op1
);
12519 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12520 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12521 if (GET_CODE (rtl
) == ROTATERT
)
12523 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12524 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12525 GET_MODE_BITSIZE (mode
), 0));
12527 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12528 if (mask
[0] != NULL
)
12529 add_loc_descr (&ret
, mask
[0]);
12530 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12531 if (mask
[1] != NULL
)
12533 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12534 add_loc_descr (&ret
, mask
[1]);
12535 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12537 if (GET_CODE (rtl
) == ROTATE
)
12539 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12540 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12541 GET_MODE_BITSIZE (mode
), 0));
12543 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12544 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12548 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12549 for DEBUG_PARAMETER_REF RTL. */
12551 static dw_loc_descr_ref
12552 parameter_ref_descriptor (rtx rtl
)
12554 dw_loc_descr_ref ret
;
12559 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12560 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12561 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12564 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12565 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12566 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12570 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12571 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12576 /* The following routine converts the RTL for a variable or parameter
12577 (resident in memory) into an equivalent Dwarf representation of a
12578 mechanism for getting the address of that same variable onto the top of a
12579 hypothetical "address evaluation" stack.
12581 When creating memory location descriptors, we are effectively transforming
12582 the RTL for a memory-resident object into its Dwarf postfix expression
12583 equivalent. This routine recursively descends an RTL tree, turning
12584 it into Dwarf postfix code as it goes.
12586 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12588 MEM_MODE is the mode of the memory reference, needed to handle some
12589 autoincrement addressing modes.
12591 Return 0 if we can't represent the location. */
12594 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
12595 machine_mode mem_mode
,
12596 enum var_init_status initialized
)
12598 dw_loc_descr_ref mem_loc_result
= NULL
;
12599 enum dwarf_location_atom op
;
12600 dw_loc_descr_ref op0
, op1
;
12601 rtx inner
= NULL_RTX
;
12603 if (mode
== VOIDmode
)
12604 mode
= GET_MODE (rtl
);
12606 /* Note that for a dynamically sized array, the location we will generate a
12607 description of here will be the lowest numbered location which is
12608 actually within the array. That's *not* necessarily the same as the
12609 zeroth element of the array. */
12611 rtl
= targetm
.delegitimize_address (rtl
);
12613 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12616 switch (GET_CODE (rtl
))
12621 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12624 /* The case of a subreg may arise when we have a local (register)
12625 variable or a formal (register) parameter which doesn't quite fill
12626 up an entire register. For now, just assume that it is
12627 legitimate to make the Dwarf info refer to the whole register which
12628 contains the given subreg. */
12629 if (!subreg_lowpart_p (rtl
))
12631 inner
= SUBREG_REG (rtl
);
12633 if (inner
== NULL_RTX
)
12634 inner
= XEXP (rtl
, 0);
12635 if (GET_MODE_CLASS (mode
) == MODE_INT
12636 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12637 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12638 #ifdef POINTERS_EXTEND_UNSIGNED
12639 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12642 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12644 mem_loc_result
= mem_loc_descriptor (inner
,
12646 mem_mode
, initialized
);
12651 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12653 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12654 && (GET_MODE_CLASS (mode
) != MODE_INT
12655 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12659 dw_die_ref type_die
;
12660 dw_loc_descr_ref cvt
;
12662 mem_loc_result
= mem_loc_descriptor (inner
,
12664 mem_mode
, initialized
);
12665 if (mem_loc_result
== NULL
)
12667 type_die
= base_type_for_mode (mode
,
12668 GET_MODE_CLASS (mode
) == MODE_INT
);
12669 if (type_die
== NULL
)
12671 mem_loc_result
= NULL
;
12674 if (GET_MODE_SIZE (mode
)
12675 != GET_MODE_SIZE (GET_MODE (inner
)))
12676 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12678 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12679 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12680 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12681 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12682 add_loc_descr (&mem_loc_result
, cvt
);
12687 if (GET_MODE_CLASS (mode
) != MODE_INT
12688 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12689 && rtl
!= arg_pointer_rtx
12690 && rtl
!= frame_pointer_rtx
12691 #ifdef POINTERS_EXTEND_UNSIGNED
12692 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12696 dw_die_ref type_die
;
12697 unsigned int dbx_regnum
;
12701 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12703 type_die
= base_type_for_mode (mode
,
12704 GET_MODE_CLASS (mode
) == MODE_INT
);
12705 if (type_die
== NULL
)
12708 dbx_regnum
= dbx_reg_number (rtl
);
12709 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12711 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12713 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12714 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12715 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12718 /* Whenever a register number forms a part of the description of the
12719 method for calculating the (dynamic) address of a memory resident
12720 object, DWARF rules require the register number be referred to as
12721 a "base register". This distinction is not based in any way upon
12722 what category of register the hardware believes the given register
12723 belongs to. This is strictly DWARF terminology we're dealing with
12724 here. Note that in cases where the location of a memory-resident
12725 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12726 OP_CONST (0)) the actual DWARF location descriptor that we generate
12727 may just be OP_BASEREG (basereg). This may look deceptively like
12728 the object in question was allocated to a register (rather than in
12729 memory) so DWARF consumers need to be aware of the subtle
12730 distinction between OP_REG and OP_BASEREG. */
12731 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12732 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12733 else if (stack_realign_drap
12735 && crtl
->args
.internal_arg_pointer
== rtl
12736 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12738 /* If RTL is internal_arg_pointer, which has been optimized
12739 out, use DRAP instead. */
12740 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12741 VAR_INIT_STATUS_INITIALIZED
);
12747 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12749 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12750 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12753 else if (GET_CODE (rtl
) == ZERO_EXTEND
12754 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12755 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12756 < HOST_BITS_PER_WIDE_INT
12757 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12758 to expand zero extend as two shifts instead of
12760 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12762 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12763 mem_loc_result
= op0
;
12764 add_loc_descr (&mem_loc_result
,
12765 int_loc_descriptor (GET_MODE_MASK (imode
)));
12766 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12768 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12770 int shift
= DWARF2_ADDR_SIZE
12771 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12772 shift
*= BITS_PER_UNIT
;
12773 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12777 mem_loc_result
= op0
;
12778 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12779 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12780 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12781 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12783 else if (!dwarf_strict
)
12785 dw_die_ref type_die1
, type_die2
;
12786 dw_loc_descr_ref cvt
;
12788 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12789 GET_CODE (rtl
) == ZERO_EXTEND
);
12790 if (type_die1
== NULL
)
12792 type_die2
= base_type_for_mode (mode
, 1);
12793 if (type_die2
== NULL
)
12795 mem_loc_result
= op0
;
12796 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12797 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12798 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12799 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12800 add_loc_descr (&mem_loc_result
, cvt
);
12801 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12802 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12803 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12804 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12805 add_loc_descr (&mem_loc_result
, cvt
);
12811 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12812 if (new_rtl
!= rtl
)
12814 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12816 if (mem_loc_result
!= NULL
)
12817 return mem_loc_result
;
12820 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12821 get_address_mode (rtl
), mode
,
12822 VAR_INIT_STATUS_INITIALIZED
);
12823 if (mem_loc_result
== NULL
)
12824 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12825 if (mem_loc_result
!= NULL
)
12827 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12828 || GET_MODE_CLASS (mode
) != MODE_INT
)
12830 dw_die_ref type_die
;
12831 dw_loc_descr_ref deref
;
12836 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12837 if (type_die
== NULL
)
12839 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12840 GET_MODE_SIZE (mode
), 0);
12841 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12842 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12843 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12844 add_loc_descr (&mem_loc_result
, deref
);
12846 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12847 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12849 add_loc_descr (&mem_loc_result
,
12850 new_loc_descr (DW_OP_deref_size
,
12851 GET_MODE_SIZE (mode
), 0));
12856 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12859 /* Some ports can transform a symbol ref into a label ref, because
12860 the symbol ref is too far away and has to be dumped into a constant
12864 if ((GET_MODE_CLASS (mode
) != MODE_INT
12865 && GET_MODE_CLASS (mode
) != MODE_PARTIAL_INT
)
12866 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12867 #ifdef POINTERS_EXTEND_UNSIGNED
12868 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12872 if (GET_CODE (rtl
) == SYMBOL_REF
12873 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12875 dw_loc_descr_ref temp
;
12877 /* If this is not defined, we have no way to emit the data. */
12878 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12881 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12883 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12884 add_loc_descr (&mem_loc_result
, temp
);
12889 if (!const_ok_for_output (rtl
))
12891 if (GET_CODE (rtl
) == CONST
)
12892 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12898 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12899 vec_safe_push (used_rtx_array
, rtl
);
12905 case DEBUG_IMPLICIT_PTR
:
12906 expansion_failed (NULL_TREE
, rtl
,
12907 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12913 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12915 if (GET_MODE_CLASS (mode
) != MODE_INT
12916 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12917 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12918 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12921 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12922 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12924 op0
= one_reg_loc_descriptor (dbx_regnum
,
12925 VAR_INIT_STATUS_INITIALIZED
);
12928 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12929 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12931 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12932 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12933 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12937 gcc_unreachable ();
12940 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12941 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12942 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12945 case DEBUG_PARAMETER_REF
:
12946 mem_loc_result
= parameter_ref_descriptor (rtl
);
12950 /* Extract the PLUS expression nested inside and fall into
12951 PLUS code below. */
12952 rtl
= XEXP (rtl
, 1);
12957 /* Turn these into a PLUS expression and fall into the PLUS code
12959 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12960 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12961 ? GET_MODE_UNIT_SIZE (mem_mode
)
12962 : -GET_MODE_UNIT_SIZE (mem_mode
),
12965 /* ... fall through ... */
12969 if (is_based_loc (rtl
)
12970 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12971 || XEXP (rtl
, 0) == arg_pointer_rtx
12972 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12973 && GET_MODE_CLASS (mode
) == MODE_INT
)
12974 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12975 INTVAL (XEXP (rtl
, 1)),
12976 VAR_INIT_STATUS_INITIALIZED
);
12979 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12980 VAR_INIT_STATUS_INITIALIZED
);
12981 if (mem_loc_result
== 0)
12984 if (CONST_INT_P (XEXP (rtl
, 1))
12985 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12986 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12989 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12990 VAR_INIT_STATUS_INITIALIZED
);
12993 add_loc_descr (&mem_loc_result
, op1
);
12994 add_loc_descr (&mem_loc_result
,
12995 new_loc_descr (DW_OP_plus
, 0, 0));
13000 /* If a pseudo-reg is optimized away, it is possible for it to
13001 be replaced with a MEM containing a multiply or shift. */
13012 && GET_MODE_CLASS (mode
) == MODE_INT
13013 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
13015 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13016 base_type_for_mode (mode
, 0),
13040 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13042 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13043 VAR_INIT_STATUS_INITIALIZED
);
13045 rtx rtlop1
= XEXP (rtl
, 1);
13046 if (GET_MODE (rtlop1
) != VOIDmode
13047 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
13048 < GET_MODE_BITSIZE (mode
))
13049 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
13050 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
13051 VAR_INIT_STATUS_INITIALIZED
);
13054 if (op0
== 0 || op1
== 0)
13057 mem_loc_result
= op0
;
13058 add_loc_descr (&mem_loc_result
, op1
);
13059 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13075 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13076 VAR_INIT_STATUS_INITIALIZED
);
13077 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13078 VAR_INIT_STATUS_INITIALIZED
);
13080 if (op0
== 0 || op1
== 0)
13083 mem_loc_result
= op0
;
13084 add_loc_descr (&mem_loc_result
, op1
);
13085 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13089 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
13091 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
13092 base_type_for_mode (mode
, 0),
13097 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13098 VAR_INIT_STATUS_INITIALIZED
);
13099 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13100 VAR_INIT_STATUS_INITIALIZED
);
13102 if (op0
== 0 || op1
== 0)
13105 mem_loc_result
= op0
;
13106 add_loc_descr (&mem_loc_result
, op1
);
13107 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13108 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13109 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
13110 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13111 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
13115 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
13117 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
13122 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13123 base_type_for_mode (mode
, 1),
13141 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13142 VAR_INIT_STATUS_INITIALIZED
);
13147 mem_loc_result
= op0
;
13148 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13152 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13153 #ifdef POINTERS_EXTEND_UNSIGNED
13155 && mem_mode
!= VOIDmode
13156 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
13160 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13164 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
13165 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
13167 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
13168 machine_mode amode
;
13169 if (type_die
== NULL
)
13171 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
13173 if (INTVAL (rtl
) >= 0
13174 && amode
!= BLKmode
13175 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
13176 /* const DW_OP_GNU_convert <XXX> vs.
13177 DW_OP_GNU_const_type <XXX, 1, const>. */
13178 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
13179 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
13181 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13182 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13183 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13184 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13185 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13186 add_loc_descr (&mem_loc_result
, op0
);
13187 return mem_loc_result
;
13189 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
13191 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13192 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13193 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13194 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
13195 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13198 mem_loc_result
->dw_loc_oprnd2
.val_class
13199 = dw_val_class_const_double
;
13200 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13201 = double_int::from_shwi (INTVAL (rtl
));
13209 dw_die_ref type_die
;
13211 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
13212 CONST_DOUBLE rtx could represent either a large integer
13213 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
13214 the value is always a floating point constant.
13216 When it is an integer, a CONST_DOUBLE is used whenever
13217 the constant requires 2 HWIs to be adequately represented.
13218 We output CONST_DOUBLEs as blocks. */
13219 if (mode
== VOIDmode
13220 || (GET_MODE (rtl
) == VOIDmode
13221 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
13223 type_die
= base_type_for_mode (mode
,
13224 GET_MODE_CLASS (mode
) == MODE_INT
);
13225 if (type_die
== NULL
)
13227 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13228 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13229 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13230 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13231 #if TARGET_SUPPORTS_WIDE_INT == 0
13232 if (!SCALAR_FLOAT_MODE_P (mode
))
13234 mem_loc_result
->dw_loc_oprnd2
.val_class
13235 = dw_val_class_const_double
;
13236 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13237 = rtx_to_double_int (rtl
);
13242 unsigned int length
= GET_MODE_SIZE (mode
);
13243 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13245 insert_float (rtl
, array
);
13246 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13247 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13248 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13249 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13254 case CONST_WIDE_INT
:
13257 dw_die_ref type_die
;
13259 type_die
= base_type_for_mode (mode
,
13260 GET_MODE_CLASS (mode
) == MODE_INT
);
13261 if (type_die
== NULL
)
13263 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13264 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13265 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13266 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13267 mem_loc_result
->dw_loc_oprnd2
.val_class
13268 = dw_val_class_wide_int
;
13269 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13270 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13275 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
13279 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13283 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13287 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13291 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13295 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
13299 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13303 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13307 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13311 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13316 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13321 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
13326 if (CONST_INT_P (XEXP (rtl
, 1))
13327 && CONST_INT_P (XEXP (rtl
, 2))
13328 && ((unsigned) INTVAL (XEXP (rtl
, 1))
13329 + (unsigned) INTVAL (XEXP (rtl
, 2))
13330 <= GET_MODE_BITSIZE (mode
))
13331 && GET_MODE_CLASS (mode
) == MODE_INT
13332 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13333 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
13336 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13337 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13340 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
13344 mem_loc_result
= op0
;
13345 size
= INTVAL (XEXP (rtl
, 1));
13346 shift
= INTVAL (XEXP (rtl
, 2));
13347 if (BITS_BIG_ENDIAN
)
13348 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13350 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
13352 add_loc_descr (&mem_loc_result
,
13353 int_loc_descriptor (DWARF2_ADDR_SIZE
13355 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13357 if (size
!= (int) DWARF2_ADDR_SIZE
)
13359 add_loc_descr (&mem_loc_result
,
13360 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
13361 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13368 dw_loc_descr_ref op2
, bra_node
, drop_node
;
13369 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
13370 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
13371 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
13372 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13373 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13374 VAR_INIT_STATUS_INITIALIZED
);
13375 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
13376 VAR_INIT_STATUS_INITIALIZED
);
13377 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
13380 mem_loc_result
= op1
;
13381 add_loc_descr (&mem_loc_result
, op2
);
13382 add_loc_descr (&mem_loc_result
, op0
);
13383 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13384 add_loc_descr (&mem_loc_result
, bra_node
);
13385 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
13386 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
13387 add_loc_descr (&mem_loc_result
, drop_node
);
13388 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13389 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
13394 case FLOAT_TRUNCATE
:
13396 case UNSIGNED_FLOAT
:
13401 dw_die_ref type_die
;
13402 dw_loc_descr_ref cvt
;
13404 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13405 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13408 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
13409 && (GET_CODE (rtl
) == FLOAT
13410 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
13411 <= DWARF2_ADDR_SIZE
))
13413 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
13414 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
13415 if (type_die
== NULL
)
13417 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13418 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13419 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13420 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13421 add_loc_descr (&op0
, cvt
);
13423 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
13424 if (type_die
== NULL
)
13426 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13427 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13428 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13429 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13430 add_loc_descr (&op0
, cvt
);
13431 if (GET_MODE_CLASS (mode
) == MODE_INT
13432 && (GET_CODE (rtl
) == FIX
13433 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
13435 op0
= convert_descriptor_to_mode (mode
, op0
);
13439 mem_loc_result
= op0
;
13446 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
13451 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
13455 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
13460 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
13464 /* In theory, we could implement the above. */
13465 /* DWARF cannot represent the unsigned compare operations
13490 case FRACT_CONVERT
:
13491 case UNSIGNED_FRACT_CONVERT
:
13493 case UNSIGNED_SAT_FRACT
:
13499 case VEC_DUPLICATE
:
13503 case STRICT_LOW_PART
:
13508 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13509 can't express it in the debug info. This can happen e.g. with some
13514 resolve_one_addr (&rtl
);
13518 #ifdef ENABLE_CHECKING
13519 print_rtl (stderr
, rtl
);
13520 gcc_unreachable ();
13526 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13527 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13529 return mem_loc_result
;
13532 /* Return a descriptor that describes the concatenation of two locations.
13533 This is typically a complex variable. */
13535 static dw_loc_descr_ref
13536 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13538 dw_loc_descr_ref cc_loc_result
= NULL
;
13539 dw_loc_descr_ref x0_ref
13540 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13541 dw_loc_descr_ref x1_ref
13542 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13544 if (x0_ref
== 0 || x1_ref
== 0)
13547 cc_loc_result
= x0_ref
;
13548 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13550 add_loc_descr (&cc_loc_result
, x1_ref
);
13551 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13553 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13554 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13556 return cc_loc_result
;
13559 /* Return a descriptor that describes the concatenation of N
13562 static dw_loc_descr_ref
13563 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13566 dw_loc_descr_ref cc_loc_result
= NULL
;
13567 unsigned int n
= XVECLEN (concatn
, 0);
13569 for (i
= 0; i
< n
; ++i
)
13571 dw_loc_descr_ref ref
;
13572 rtx x
= XVECEXP (concatn
, 0, i
);
13574 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13578 add_loc_descr (&cc_loc_result
, ref
);
13579 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13582 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13583 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13585 return cc_loc_result
;
13588 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13589 for DEBUG_IMPLICIT_PTR RTL. */
13591 static dw_loc_descr_ref
13592 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13594 dw_loc_descr_ref ret
;
13599 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13600 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13601 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13602 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13603 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13604 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13607 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13608 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13609 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13613 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13614 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13619 /* Output a proper Dwarf location descriptor for a variable or parameter
13620 which is either allocated in a register or in a memory location. For a
13621 register, we just generate an OP_REG and the register number. For a
13622 memory location we provide a Dwarf postfix expression describing how to
13623 generate the (dynamic) address of the object onto the address stack.
13625 MODE is mode of the decl if this loc_descriptor is going to be used in
13626 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13627 allowed, VOIDmode otherwise.
13629 If we don't know how to describe it, return 0. */
13631 static dw_loc_descr_ref
13632 loc_descriptor (rtx rtl
, machine_mode mode
,
13633 enum var_init_status initialized
)
13635 dw_loc_descr_ref loc_result
= NULL
;
13637 switch (GET_CODE (rtl
))
13640 /* The case of a subreg may arise when we have a local (register)
13641 variable or a formal (register) parameter which doesn't quite fill
13642 up an entire register. For now, just assume that it is
13643 legitimate to make the Dwarf info refer to the whole register which
13644 contains the given subreg. */
13645 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13646 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13647 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13653 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13657 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13658 GET_MODE (rtl
), initialized
);
13659 if (loc_result
== NULL
)
13660 loc_result
= tls_mem_loc_descriptor (rtl
);
13661 if (loc_result
== NULL
)
13663 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13664 if (new_rtl
!= rtl
)
13665 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13670 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13675 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13680 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13682 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13683 if (GET_CODE (loc
) == EXPR_LIST
)
13684 loc
= XEXP (loc
, 0);
13685 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13689 rtl
= XEXP (rtl
, 1);
13694 rtvec par_elems
= XVEC (rtl
, 0);
13695 int num_elem
= GET_NUM_ELEM (par_elems
);
13699 /* Create the first one, so we have something to add to. */
13700 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13701 VOIDmode
, initialized
);
13702 if (loc_result
== NULL
)
13704 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13705 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13706 for (i
= 1; i
< num_elem
; i
++)
13708 dw_loc_descr_ref temp
;
13710 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13711 VOIDmode
, initialized
);
13714 add_loc_descr (&loc_result
, temp
);
13715 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13716 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13722 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13723 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13728 if (mode
== VOIDmode
)
13729 mode
= GET_MODE (rtl
);
13731 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13733 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13735 /* Note that a CONST_DOUBLE rtx could represent either an integer
13736 or a floating-point constant. A CONST_DOUBLE is used whenever
13737 the constant requires more than one word in order to be
13738 adequately represented. We output CONST_DOUBLEs as blocks. */
13739 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13740 GET_MODE_SIZE (mode
), 0);
13741 #if TARGET_SUPPORTS_WIDE_INT == 0
13742 if (!SCALAR_FLOAT_MODE_P (mode
))
13744 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13745 loc_result
->dw_loc_oprnd2
.v
.val_double
13746 = rtx_to_double_int (rtl
);
13751 unsigned int length
= GET_MODE_SIZE (mode
);
13752 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13754 insert_float (rtl
, array
);
13755 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13756 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13757 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13758 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13763 case CONST_WIDE_INT
:
13764 if (mode
== VOIDmode
)
13765 mode
= GET_MODE (rtl
);
13767 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13769 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13770 GET_MODE_SIZE (mode
), 0);
13771 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
13772 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13773 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13778 if (mode
== VOIDmode
)
13779 mode
= GET_MODE (rtl
);
13781 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13783 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13784 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13785 unsigned char *array
13786 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
13789 machine_mode imode
= GET_MODE_INNER (mode
);
13791 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13792 switch (GET_MODE_CLASS (mode
))
13794 case MODE_VECTOR_INT
:
13795 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13797 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13798 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
13802 case MODE_VECTOR_FLOAT
:
13803 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13805 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13806 insert_float (elt
, p
);
13811 gcc_unreachable ();
13814 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13815 length
* elt_size
, 0);
13816 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13817 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13818 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13819 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13824 if (mode
== VOIDmode
13825 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13826 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13827 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13829 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13834 if (!const_ok_for_output (rtl
))
13837 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13838 && (dwarf_version
>= 4 || !dwarf_strict
))
13840 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13841 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13842 vec_safe_push (used_rtx_array
, rtl
);
13846 case DEBUG_IMPLICIT_PTR
:
13847 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13851 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13852 && CONST_INT_P (XEXP (rtl
, 1)))
13855 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13861 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13862 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13863 && dwarf_version
>= 4)
13864 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13866 /* Value expression. */
13867 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13869 add_loc_descr (&loc_result
,
13870 new_loc_descr (DW_OP_stack_value
, 0, 0));
13878 /* We need to figure out what section we should use as the base for the
13879 address ranges where a given location is valid.
13880 1. If this particular DECL has a section associated with it, use that.
13881 2. If this function has a section associated with it, use that.
13882 3. Otherwise, use the text section.
13883 XXX: If you split a variable across multiple sections, we won't notice. */
13885 static const char *
13886 secname_for_decl (const_tree decl
)
13888 const char *secname
;
13890 if (VAR_OR_FUNCTION_DECL_P (decl
)
13891 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
13892 && DECL_SECTION_NAME (decl
))
13893 secname
= DECL_SECTION_NAME (decl
);
13894 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13895 secname
= DECL_SECTION_NAME (current_function_decl
);
13896 else if (cfun
&& in_cold_section_p
)
13897 secname
= crtl
->subsections
.cold_section_label
;
13899 secname
= text_section_label
;
13904 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13907 decl_by_reference_p (tree decl
)
13909 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13910 || TREE_CODE (decl
) == VAR_DECL
)
13911 && DECL_BY_REFERENCE (decl
));
13914 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13917 static dw_loc_descr_ref
13918 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13919 enum var_init_status initialized
)
13921 int have_address
= 0;
13922 dw_loc_descr_ref descr
;
13925 if (want_address
!= 2)
13927 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13929 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13931 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13932 if (GET_CODE (varloc
) == EXPR_LIST
)
13933 varloc
= XEXP (varloc
, 0);
13934 mode
= GET_MODE (varloc
);
13935 if (MEM_P (varloc
))
13937 rtx addr
= XEXP (varloc
, 0);
13938 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13939 mode
, initialized
);
13944 rtx x
= avoid_constant_pool_reference (varloc
);
13946 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13951 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13958 if (GET_CODE (varloc
) == VAR_LOCATION
)
13959 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13961 mode
= DECL_MODE (loc
);
13962 descr
= loc_descriptor (varloc
, mode
, initialized
);
13969 if (want_address
== 2 && !have_address
13970 && (dwarf_version
>= 4 || !dwarf_strict
))
13972 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13974 expansion_failed (loc
, NULL_RTX
,
13975 "DWARF address size mismatch");
13978 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13981 /* Show if we can't fill the request for an address. */
13982 if (want_address
&& !have_address
)
13984 expansion_failed (loc
, NULL_RTX
,
13985 "Want address and only have value");
13989 /* If we've got an address and don't want one, dereference. */
13990 if (!want_address
&& have_address
)
13992 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13993 enum dwarf_location_atom op
;
13995 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13997 expansion_failed (loc
, NULL_RTX
,
13998 "DWARF address size mismatch");
14001 else if (size
== DWARF2_ADDR_SIZE
)
14004 op
= DW_OP_deref_size
;
14006 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
14012 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14013 if it is not possible. */
14015 static dw_loc_descr_ref
14016 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
14018 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
14019 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
14020 else if (dwarf_version
>= 3 || !dwarf_strict
)
14021 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
14026 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14027 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14029 static dw_loc_descr_ref
14030 dw_sra_loc_expr (tree decl
, rtx loc
)
14033 unsigned HOST_WIDE_INT padsize
= 0;
14034 dw_loc_descr_ref descr
, *descr_tail
;
14035 unsigned HOST_WIDE_INT decl_size
;
14037 enum var_init_status initialized
;
14039 if (DECL_SIZE (decl
) == NULL
14040 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
14043 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
14045 descr_tail
= &descr
;
14047 for (p
= loc
; p
; p
= XEXP (p
, 1))
14049 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
14050 rtx loc_note
= *decl_piece_varloc_ptr (p
);
14051 dw_loc_descr_ref cur_descr
;
14052 dw_loc_descr_ref
*tail
, last
= NULL
;
14053 unsigned HOST_WIDE_INT opsize
= 0;
14055 if (loc_note
== NULL_RTX
14056 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
14058 padsize
+= bitsize
;
14061 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
14062 varloc
= NOTE_VAR_LOCATION (loc_note
);
14063 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
14064 if (cur_descr
== NULL
)
14066 padsize
+= bitsize
;
14070 /* Check that cur_descr either doesn't use
14071 DW_OP_*piece operations, or their sum is equal
14072 to bitsize. Otherwise we can't embed it. */
14073 for (tail
= &cur_descr
; *tail
!= NULL
;
14074 tail
= &(*tail
)->dw_loc_next
)
14075 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
14077 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
14081 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
14083 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
14087 if (last
!= NULL
&& opsize
!= bitsize
)
14089 padsize
+= bitsize
;
14090 /* Discard the current piece of the descriptor and release any
14091 addr_table entries it uses. */
14092 remove_loc_list_addr_table_entries (cur_descr
);
14096 /* If there is a hole, add DW_OP_*piece after empty DWARF
14097 expression, which means that those bits are optimized out. */
14100 if (padsize
> decl_size
)
14102 remove_loc_list_addr_table_entries (cur_descr
);
14103 goto discard_descr
;
14105 decl_size
-= padsize
;
14106 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
14107 if (*descr_tail
== NULL
)
14109 remove_loc_list_addr_table_entries (cur_descr
);
14110 goto discard_descr
;
14112 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14115 *descr_tail
= cur_descr
;
14117 if (bitsize
> decl_size
)
14118 goto discard_descr
;
14119 decl_size
-= bitsize
;
14122 HOST_WIDE_INT offset
= 0;
14123 if (GET_CODE (varloc
) == VAR_LOCATION
14124 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14126 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14127 if (GET_CODE (varloc
) == EXPR_LIST
)
14128 varloc
= XEXP (varloc
, 0);
14132 if (GET_CODE (varloc
) == CONST
14133 || GET_CODE (varloc
) == SIGN_EXTEND
14134 || GET_CODE (varloc
) == ZERO_EXTEND
)
14135 varloc
= XEXP (varloc
, 0);
14136 else if (GET_CODE (varloc
) == SUBREG
)
14137 varloc
= SUBREG_REG (varloc
);
14142 /* DW_OP_bit_size offset should be zero for register
14143 or implicit location descriptions and empty location
14144 descriptions, but for memory addresses needs big endian
14146 if (MEM_P (varloc
))
14148 unsigned HOST_WIDE_INT memsize
14149 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
14150 if (memsize
!= bitsize
)
14152 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
14153 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
14154 goto discard_descr
;
14155 if (memsize
< bitsize
)
14156 goto discard_descr
;
14157 if (BITS_BIG_ENDIAN
)
14158 offset
= memsize
- bitsize
;
14162 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
14163 if (*descr_tail
== NULL
)
14164 goto discard_descr
;
14165 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14169 /* If there were any non-empty expressions, add padding till the end of
14171 if (descr
!= NULL
&& decl_size
!= 0)
14173 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
14174 if (*descr_tail
== NULL
)
14175 goto discard_descr
;
14180 /* Discard the descriptor and release any addr_table entries it uses. */
14181 remove_loc_list_addr_table_entries (descr
);
14185 /* Return the dwarf representation of the location list LOC_LIST of
14186 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14189 static dw_loc_list_ref
14190 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
14192 const char *endname
, *secname
;
14194 enum var_init_status initialized
;
14195 struct var_loc_node
*node
;
14196 dw_loc_descr_ref descr
;
14197 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
14198 dw_loc_list_ref list
= NULL
;
14199 dw_loc_list_ref
*listp
= &list
;
14201 /* Now that we know what section we are using for a base,
14202 actually construct the list of locations.
14203 The first location information is what is passed to the
14204 function that creates the location list, and the remaining
14205 locations just get added on to that list.
14206 Note that we only know the start address for a location
14207 (IE location changes), so to build the range, we use
14208 the range [current location start, next location start].
14209 This means we have to special case the last node, and generate
14210 a range of [last location start, end of function label]. */
14212 secname
= secname_for_decl (decl
);
14214 for (node
= loc_list
->first
; node
; node
= node
->next
)
14215 if (GET_CODE (node
->loc
) == EXPR_LIST
14216 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
14218 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14220 /* This requires DW_OP_{,bit_}piece, which is not usable
14221 inside DWARF expressions. */
14222 if (want_address
!= 2)
14224 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14230 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14231 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14232 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
14236 bool range_across_switch
= false;
14237 /* If section switch happens in between node->label
14238 and node->next->label (or end of function) and
14239 we can't emit it as a single entry list,
14240 emit two ranges, first one ending at the end
14241 of first partition and second one starting at the
14242 beginning of second partition. */
14243 if (node
== loc_list
->last_before_switch
14244 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
14245 && current_function_decl
)
14247 endname
= cfun
->fde
->dw_fde_end
;
14248 range_across_switch
= true;
14250 /* The variable has a location between NODE->LABEL and
14251 NODE->NEXT->LABEL. */
14252 else if (node
->next
)
14253 endname
= node
->next
->label
;
14254 /* If the variable has a location at the last label
14255 it keeps its location until the end of function. */
14256 else if (!current_function_decl
)
14257 endname
= text_end_label
;
14260 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
14261 current_function_funcdef_no
);
14262 endname
= ggc_strdup (label_id
);
14265 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
14266 if (TREE_CODE (decl
) == PARM_DECL
14267 && node
== loc_list
->first
14268 && NOTE_P (node
->loc
)
14269 && strcmp (node
->label
, endname
) == 0)
14270 (*listp
)->force
= true;
14271 listp
= &(*listp
)->dw_loc_next
;
14273 if (range_across_switch
)
14275 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14276 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14279 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14280 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14281 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
14284 gcc_assert (descr
);
14285 /* The variable has a location between NODE->LABEL and
14286 NODE->NEXT->LABEL. */
14288 endname
= node
->next
->label
;
14290 endname
= cfun
->fde
->dw_fde_second_end
;
14291 *listp
= new_loc_list (descr
,
14292 cfun
->fde
->dw_fde_second_begin
,
14294 listp
= &(*listp
)->dw_loc_next
;
14299 /* Try to avoid the overhead of a location list emitting a location
14300 expression instead, but only if we didn't have more than one
14301 location entry in the first place. If some entries were not
14302 representable, we don't want to pretend a single entry that was
14303 applies to the entire scope in which the variable is
14305 if (list
&& loc_list
->first
->next
)
14311 /* Return if the loc_list has only single element and thus can be represented
14312 as location description. */
14315 single_element_loc_list_p (dw_loc_list_ref list
)
14317 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
14318 return !list
->ll_symbol
;
14321 /* To each location in list LIST add loc descr REF. */
14324 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
14326 dw_loc_descr_ref copy
;
14327 add_loc_descr (&list
->expr
, ref
);
14328 list
= list
->dw_loc_next
;
14331 copy
= ggc_alloc
<dw_loc_descr_node
> ();
14332 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
14333 add_loc_descr (&list
->expr
, copy
);
14334 while (copy
->dw_loc_next
)
14336 dw_loc_descr_ref new_copy
= ggc_alloc
<dw_loc_descr_node
> ();
14337 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
14338 copy
->dw_loc_next
= new_copy
;
14341 list
= list
->dw_loc_next
;
14345 /* Given two lists RET and LIST
14346 produce location list that is result of adding expression in LIST
14347 to expression in RET on each position in program.
14348 Might be destructive on both RET and LIST.
14350 TODO: We handle only simple cases of RET or LIST having at most one
14351 element. General case would inolve sorting the lists in program order
14352 and merging them that will need some additional work.
14353 Adding that will improve quality of debug info especially for SRA-ed
14357 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
14366 if (!list
->dw_loc_next
)
14368 add_loc_descr_to_each (*ret
, list
->expr
);
14371 if (!(*ret
)->dw_loc_next
)
14373 add_loc_descr_to_each (list
, (*ret
)->expr
);
14377 expansion_failed (NULL_TREE
, NULL_RTX
,
14378 "Don't know how to merge two non-trivial"
14379 " location lists.\n");
14384 /* LOC is constant expression. Try a luck, look it up in constant
14385 pool and return its loc_descr of its address. */
14387 static dw_loc_descr_ref
14388 cst_pool_loc_descr (tree loc
)
14390 /* Get an RTL for this, if something has been emitted. */
14391 rtx rtl
= lookup_constant_def (loc
);
14393 if (!rtl
|| !MEM_P (rtl
))
14398 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
14400 /* TODO: We might get more coverage if we was actually delaying expansion
14401 of all expressions till end of compilation when constant pools are fully
14403 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
14405 expansion_failed (loc
, NULL_RTX
,
14406 "CST value in contant pool but not marked.");
14409 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
14410 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
14413 /* Return dw_loc_list representing address of addr_expr LOC
14414 by looking for inner INDIRECT_REF expression and turning
14415 it into simple arithmetics.
14417 See loc_list_from_tree for the meaning of CONTEXT. */
14419 static dw_loc_list_ref
14420 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
14421 const loc_descr_context
*context
)
14424 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14426 int unsignedp
, volatilep
= 0;
14427 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14429 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
14430 &bitsize
, &bitpos
, &offset
, &mode
,
14431 &unsignedp
, &volatilep
, false);
14433 if (bitpos
% BITS_PER_UNIT
)
14435 expansion_failed (loc
, NULL_RTX
, "bitfield access");
14438 if (!INDIRECT_REF_P (obj
))
14440 expansion_failed (obj
,
14441 NULL_RTX
, "no indirect ref in inner refrence");
14444 if (!offset
&& !bitpos
)
14445 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
14448 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
14449 && (dwarf_version
>= 4 || !dwarf_strict
))
14451 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
14456 /* Variable offset. */
14457 list_ret1
= loc_list_from_tree (offset
, 0, context
);
14458 if (list_ret1
== 0)
14460 add_loc_list (&list_ret
, list_ret1
);
14463 add_loc_descr_to_each (list_ret
,
14464 new_loc_descr (DW_OP_plus
, 0, 0));
14466 bytepos
= bitpos
/ BITS_PER_UNIT
;
14468 add_loc_descr_to_each (list_ret
,
14469 new_loc_descr (DW_OP_plus_uconst
,
14471 else if (bytepos
< 0)
14472 loc_list_plus_const (list_ret
, bytepos
);
14473 add_loc_descr_to_each (list_ret
,
14474 new_loc_descr (DW_OP_stack_value
, 0, 0));
14480 /* Helper structure for location descriptions generation. */
14481 struct loc_descr_context
14483 /* The type that is implicitly referenced by DW_OP_push_object_address, or
14484 NULL_TREE if DW_OP_push_object_address in invalid for this location
14485 description. This is used when processing PLACEHOLDER_EXPR nodes. */
14487 /* The ..._DECL node that should be translated as a
14488 DW_OP_push_object_address operation. */
14492 /* Generate Dwarf location list representing LOC.
14493 If WANT_ADDRESS is false, expression computing LOC will be computed
14494 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14495 if WANT_ADDRESS is 2, expression computing address useable in location
14496 will be returned (i.e. DW_OP_reg can be used
14497 to refer to register values).
14499 CONTEXT provides information to customize the location descriptions
14500 generation. Its context_type field specifies what type is implicitly
14501 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
14502 will not be generated.
14504 If CONTEXT is NULL, the behavior is the same as if both context_type and
14505 base_decl fields were NULL_TREE. */
14507 static dw_loc_list_ref
14508 loc_list_from_tree (tree loc
, int want_address
,
14509 const struct loc_descr_context
*context
)
14511 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
14512 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14513 int have_address
= 0;
14514 enum dwarf_location_atom op
;
14516 /* ??? Most of the time we do not take proper care for sign/zero
14517 extending the values properly. Hopefully this won't be a real
14520 if (context
!= NULL
14521 && context
->base_decl
== loc
14522 && want_address
== 0)
14524 if (dwarf_version
>= 3 || !dwarf_strict
)
14525 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
14531 switch (TREE_CODE (loc
))
14534 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14537 case PLACEHOLDER_EXPR
:
14538 /* This case involves extracting fields from an object to determine the
14539 position of other fields. It is supposed to appear only as the first
14540 operand of COMPONENT_REF nodes and to reference precisely the type
14541 that the context allows. */
14542 if (context
!= NULL
14543 && TREE_TYPE (loc
) == context
->context_type
14544 && want_address
>= 1)
14546 if (dwarf_version
>= 3 || !dwarf_strict
)
14548 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
14556 expansion_failed (loc
, NULL_RTX
,
14557 "PLACEHOLDER_EXPR for an unexpected type");
14561 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14562 /* There are no opcodes for these operations. */
14565 case PREINCREMENT_EXPR
:
14566 case PREDECREMENT_EXPR
:
14567 case POSTINCREMENT_EXPR
:
14568 case POSTDECREMENT_EXPR
:
14569 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14570 /* There are no opcodes for these operations. */
14574 /* If we already want an address, see if there is INDIRECT_REF inside
14575 e.g. for &this->field. */
14578 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14579 (loc
, want_address
== 2, context
);
14582 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14583 && (ret
= cst_pool_loc_descr (loc
)))
14586 /* Otherwise, process the argument and look for the address. */
14587 if (!list_ret
&& !ret
)
14588 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1, context
);
14592 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14598 if (DECL_THREAD_LOCAL_P (loc
))
14601 enum dwarf_location_atom tls_op
;
14602 enum dtprel_bool dtprel
= dtprel_false
;
14604 if (targetm
.have_tls
)
14606 /* If this is not defined, we have no way to emit the
14608 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14611 /* The way DW_OP_GNU_push_tls_address is specified, we
14612 can only look up addresses of objects in the current
14613 module. We used DW_OP_addr as first op, but that's
14614 wrong, because DW_OP_addr is relocated by the debug
14615 info consumer, while DW_OP_GNU_push_tls_address
14616 operand shouldn't be. */
14617 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14619 dtprel
= dtprel_true
;
14620 tls_op
= DW_OP_GNU_push_tls_address
;
14624 if (!targetm
.emutls
.debug_form_tls_address
14625 || !(dwarf_version
>= 3 || !dwarf_strict
))
14627 /* We stuffed the control variable into the DECL_VALUE_EXPR
14628 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14629 no longer appear in gimple code. We used the control
14630 variable in specific so that we could pick it up here. */
14631 loc
= DECL_VALUE_EXPR (loc
);
14632 tls_op
= DW_OP_form_tls_address
;
14635 rtl
= rtl_for_decl_location (loc
);
14636 if (rtl
== NULL_RTX
)
14641 rtl
= XEXP (rtl
, 0);
14642 if (! CONSTANT_P (rtl
))
14645 ret
= new_addr_loc_descr (rtl
, dtprel
);
14646 ret1
= new_loc_descr (tls_op
, 0, 0);
14647 add_loc_descr (&ret
, ret1
);
14656 if (DECL_HAS_VALUE_EXPR_P (loc
))
14657 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14658 want_address
, context
);
14661 case FUNCTION_DECL
:
14664 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14666 if (loc_list
&& loc_list
->first
)
14668 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14669 have_address
= want_address
!= 0;
14672 rtl
= rtl_for_decl_location (loc
);
14673 if (rtl
== NULL_RTX
)
14675 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14678 else if (CONST_INT_P (rtl
))
14680 HOST_WIDE_INT val
= INTVAL (rtl
);
14681 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14682 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14683 ret
= int_loc_descriptor (val
);
14685 else if (GET_CODE (rtl
) == CONST_STRING
)
14687 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14690 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14691 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14694 machine_mode mode
, mem_mode
;
14696 /* Certain constructs can only be represented at top-level. */
14697 if (want_address
== 2)
14699 ret
= loc_descriptor (rtl
, VOIDmode
,
14700 VAR_INIT_STATUS_INITIALIZED
);
14705 mode
= GET_MODE (rtl
);
14706 mem_mode
= VOIDmode
;
14710 mode
= get_address_mode (rtl
);
14711 rtl
= XEXP (rtl
, 0);
14714 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14715 VAR_INIT_STATUS_INITIALIZED
);
14718 expansion_failed (loc
, rtl
,
14719 "failed to produce loc descriptor for rtl");
14725 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14732 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14736 case TARGET_MEM_REF
:
14738 case DEBUG_EXPR_DECL
:
14741 case COMPOUND_EXPR
:
14742 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
, context
);
14745 case VIEW_CONVERT_EXPR
:
14748 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
, context
);
14750 case COMPONENT_REF
:
14751 case BIT_FIELD_REF
:
14753 case ARRAY_RANGE_REF
:
14754 case REALPART_EXPR
:
14755 case IMAGPART_EXPR
:
14758 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14760 int unsignedp
, volatilep
= 0;
14762 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14763 &unsignedp
, &volatilep
, false);
14765 gcc_assert (obj
!= loc
);
14767 list_ret
= loc_list_from_tree (obj
,
14769 && !bitpos
&& !offset
? 2 : 1,
14771 /* TODO: We can extract value of the small expression via shifting even
14772 for nonzero bitpos. */
14775 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14777 expansion_failed (loc
, NULL_RTX
,
14778 "bitfield access");
14782 if (offset
!= NULL_TREE
)
14784 /* Variable offset. */
14785 list_ret1
= loc_list_from_tree (offset
, 0, context
);
14786 if (list_ret1
== 0)
14788 add_loc_list (&list_ret
, list_ret1
);
14791 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14794 bytepos
= bitpos
/ BITS_PER_UNIT
;
14796 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14797 else if (bytepos
< 0)
14798 loc_list_plus_const (list_ret
, bytepos
);
14805 if ((want_address
|| !tree_fits_shwi_p (loc
))
14806 && (ret
= cst_pool_loc_descr (loc
)))
14808 else if (want_address
== 2
14809 && tree_fits_shwi_p (loc
)
14810 && (ret
= address_of_int_loc_descriptor
14811 (int_size_in_bytes (TREE_TYPE (loc
)),
14812 tree_to_shwi (loc
))))
14814 else if (tree_fits_shwi_p (loc
))
14815 ret
= int_loc_descriptor (tree_to_shwi (loc
));
14818 expansion_failed (loc
, NULL_RTX
,
14819 "Integer operand is not host integer");
14828 if ((ret
= cst_pool_loc_descr (loc
)))
14831 /* We can construct small constants here using int_loc_descriptor. */
14832 expansion_failed (loc
, NULL_RTX
,
14833 "constructor or constant not in constant pool");
14836 case TRUTH_AND_EXPR
:
14837 case TRUTH_ANDIF_EXPR
:
14842 case TRUTH_XOR_EXPR
:
14847 case TRUTH_OR_EXPR
:
14848 case TRUTH_ORIF_EXPR
:
14853 case FLOOR_DIV_EXPR
:
14854 case CEIL_DIV_EXPR
:
14855 case ROUND_DIV_EXPR
:
14856 case TRUNC_DIV_EXPR
:
14857 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14866 case FLOOR_MOD_EXPR
:
14867 case CEIL_MOD_EXPR
:
14868 case ROUND_MOD_EXPR
:
14869 case TRUNC_MOD_EXPR
:
14870 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14875 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14876 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
14877 if (list_ret
== 0 || list_ret1
== 0)
14880 add_loc_list (&list_ret
, list_ret1
);
14883 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14884 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14885 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14886 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14887 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14899 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14902 case POINTER_PLUS_EXPR
:
14905 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
14907 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14911 loc_list_plus_const (list_ret
, tree_to_shwi (TREE_OPERAND (loc
, 1)));
14919 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14926 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14933 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14940 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14955 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14956 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
14957 if (list_ret
== 0 || list_ret1
== 0)
14960 add_loc_list (&list_ret
, list_ret1
);
14963 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14966 case TRUTH_NOT_EXPR
:
14980 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14984 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14990 const enum tree_code code
=
14991 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14993 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14994 build2 (code
, integer_type_node
,
14995 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14996 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14999 /* ... fall through ... */
15003 dw_loc_descr_ref lhs
15004 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
15005 dw_loc_list_ref rhs
15006 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0, context
);
15007 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
15009 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
15010 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
15013 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15014 add_loc_descr_to_each (list_ret
, bra_node
);
15016 add_loc_list (&list_ret
, rhs
);
15017 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
15018 add_loc_descr_to_each (list_ret
, jump_node
);
15020 add_loc_descr_to_each (list_ret
, lhs
);
15021 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15022 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
15024 /* ??? Need a node to point the skip at. Use a nop. */
15025 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
15026 add_loc_descr_to_each (list_ret
, tmp
);
15027 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15028 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
15032 case FIX_TRUNC_EXPR
:
15036 /* Leave front-end specific codes as simply unknown. This comes
15037 up, for instance, with the C STMT_EXPR. */
15038 if ((unsigned int) TREE_CODE (loc
)
15039 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
15041 expansion_failed (loc
, NULL_RTX
,
15042 "language specific tree node");
15046 #ifdef ENABLE_CHECKING
15047 /* Otherwise this is a generic code; we should just lists all of
15048 these explicitly. We forgot one. */
15049 gcc_unreachable ();
15051 /* In a release build, we want to degrade gracefully: better to
15052 generate incomplete debugging information than to crash. */
15057 if (!ret
&& !list_ret
)
15060 if (want_address
== 2 && !have_address
15061 && (dwarf_version
>= 4 || !dwarf_strict
))
15063 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15065 expansion_failed (loc
, NULL_RTX
,
15066 "DWARF address size mismatch");
15070 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15072 add_loc_descr_to_each (list_ret
,
15073 new_loc_descr (DW_OP_stack_value
, 0, 0));
15076 /* Show if we can't fill the request for an address. */
15077 if (want_address
&& !have_address
)
15079 expansion_failed (loc
, NULL_RTX
,
15080 "Want address and only have value");
15084 gcc_assert (!ret
|| !list_ret
);
15086 /* If we've got an address and don't want one, dereference. */
15087 if (!want_address
&& have_address
)
15089 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
15091 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
15093 expansion_failed (loc
, NULL_RTX
,
15094 "DWARF address size mismatch");
15097 else if (size
== DWARF2_ADDR_SIZE
)
15100 op
= DW_OP_deref_size
;
15103 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
15105 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
15108 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
15113 /* Same as above but return only single location expression. */
15114 static dw_loc_descr_ref
15115 loc_descriptor_from_tree (tree loc
, int want_address
,
15116 const struct loc_descr_context
*context
)
15118 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
15121 if (ret
->dw_loc_next
)
15123 expansion_failed (loc
, NULL_RTX
,
15124 "Location list where only loc descriptor needed");
15130 /* Given a value, round it up to the lowest multiple of `boundary'
15131 which is not less than the value itself. */
15133 static inline HOST_WIDE_INT
15134 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
15136 return (((value
+ boundary
- 1) / boundary
) * boundary
);
15139 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15140 pointer to the declared type for the relevant field variable, or return
15141 `integer_type_node' if the given node turns out to be an
15142 ERROR_MARK node. */
15145 field_type (const_tree decl
)
15149 if (TREE_CODE (decl
) == ERROR_MARK
)
15150 return integer_type_node
;
15152 type
= DECL_BIT_FIELD_TYPE (decl
);
15153 if (type
== NULL_TREE
)
15154 type
= TREE_TYPE (decl
);
15159 /* Given a pointer to a tree node, return the alignment in bits for
15160 it, or else return BITS_PER_WORD if the node actually turns out to
15161 be an ERROR_MARK node. */
15163 static inline unsigned
15164 simple_type_align_in_bits (const_tree type
)
15166 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
15169 static inline unsigned
15170 simple_decl_align_in_bits (const_tree decl
)
15172 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
15175 /* Return the result of rounding T up to ALIGN. */
15177 static inline offset_int
15178 round_up_to_align (const offset_int
&t
, unsigned int align
)
15180 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
15183 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15184 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15185 or return 0 if we are unable to determine what that offset is, either
15186 because the argument turns out to be a pointer to an ERROR_MARK node, or
15187 because the offset is actually variable. (We can't handle the latter case
15190 static HOST_WIDE_INT
15191 field_byte_offset (const_tree decl
)
15193 offset_int object_offset_in_bits
;
15194 offset_int object_offset_in_bytes
;
15195 offset_int bitpos_int
;
15197 if (TREE_CODE (decl
) == ERROR_MARK
)
15200 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
15202 /* We cannot yet cope with fields whose positions are variable, so
15203 for now, when we see such things, we simply return 0. Someday, we may
15204 be able to handle such cases, but it will be damn difficult. */
15205 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
15208 bitpos_int
= wi::to_offset (bit_position (decl
));
15210 if (PCC_BITFIELD_TYPE_MATTERS
)
15213 tree field_size_tree
;
15214 offset_int deepest_bitpos
;
15215 offset_int field_size_in_bits
;
15216 unsigned int type_align_in_bits
;
15217 unsigned int decl_align_in_bits
;
15218 offset_int type_size_in_bits
;
15220 type
= field_type (decl
);
15221 type_size_in_bits
= offset_int_type_size_in_bits (type
);
15222 type_align_in_bits
= simple_type_align_in_bits (type
);
15224 field_size_tree
= DECL_SIZE (decl
);
15226 /* The size could be unspecified if there was an error, or for
15227 a flexible array member. */
15228 if (!field_size_tree
)
15229 field_size_tree
= bitsize_zero_node
;
15231 /* If the size of the field is not constant, use the type size. */
15232 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
15233 field_size_in_bits
= wi::to_offset (field_size_tree
);
15235 field_size_in_bits
= type_size_in_bits
;
15237 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
15239 /* The GCC front-end doesn't make any attempt to keep track of the
15240 starting bit offset (relative to the start of the containing
15241 structure type) of the hypothetical "containing object" for a
15242 bit-field. Thus, when computing the byte offset value for the
15243 start of the "containing object" of a bit-field, we must deduce
15244 this information on our own. This can be rather tricky to do in
15245 some cases. For example, handling the following structure type
15246 definition when compiling for an i386/i486 target (which only
15247 aligns long long's to 32-bit boundaries) can be very tricky:
15249 struct S { int field1; long long field2:31; };
15251 Fortunately, there is a simple rule-of-thumb which can be used
15252 in such cases. When compiling for an i386/i486, GCC will
15253 allocate 8 bytes for the structure shown above. It decides to
15254 do this based upon one simple rule for bit-field allocation.
15255 GCC allocates each "containing object" for each bit-field at
15256 the first (i.e. lowest addressed) legitimate alignment boundary
15257 (based upon the required minimum alignment for the declared
15258 type of the field) which it can possibly use, subject to the
15259 condition that there is still enough available space remaining
15260 in the containing object (when allocated at the selected point)
15261 to fully accommodate all of the bits of the bit-field itself.
15263 This simple rule makes it obvious why GCC allocates 8 bytes for
15264 each object of the structure type shown above. When looking
15265 for a place to allocate the "containing object" for `field2',
15266 the compiler simply tries to allocate a 64-bit "containing
15267 object" at each successive 32-bit boundary (starting at zero)
15268 until it finds a place to allocate that 64- bit field such that
15269 at least 31 contiguous (and previously unallocated) bits remain
15270 within that selected 64 bit field. (As it turns out, for the
15271 example above, the compiler finds it is OK to allocate the
15272 "containing object" 64-bit field at bit-offset zero within the
15275 Here we attempt to work backwards from the limited set of facts
15276 we're given, and we try to deduce from those facts, where GCC
15277 must have believed that the containing object started (within
15278 the structure type). The value we deduce is then used (by the
15279 callers of this routine) to generate DW_AT_location and
15280 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15281 the case of DW_AT_location, regular fields as well). */
15283 /* Figure out the bit-distance from the start of the structure to
15284 the "deepest" bit of the bit-field. */
15285 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
15287 /* This is the tricky part. Use some fancy footwork to deduce
15288 where the lowest addressed bit of the containing object must
15290 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
15292 /* Round up to type_align by default. This works best for
15294 object_offset_in_bits
15295 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
15297 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
15299 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
15301 /* Round up to decl_align instead. */
15302 object_offset_in_bits
15303 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
15307 object_offset_in_bits
= bitpos_int
;
15309 object_offset_in_bytes
15310 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
15311 return object_offset_in_bytes
.to_shwi ();
15314 /* The following routines define various Dwarf attributes and any data
15315 associated with them. */
15317 /* Add a location description attribute value to a DIE.
15319 This emits location attributes suitable for whole variables and
15320 whole parameters. Note that the location attributes for struct fields are
15321 generated by the routine `data_member_location_attribute' below. */
15324 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
15325 dw_loc_list_ref descr
)
15329 if (single_element_loc_list_p (descr
))
15330 add_AT_loc (die
, attr_kind
, descr
->expr
);
15332 add_AT_loc_list (die
, attr_kind
, descr
);
15335 /* Add DW_AT_accessibility attribute to DIE if needed. */
15338 add_accessibility_attribute (dw_die_ref die
, tree decl
)
15340 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
15341 children, otherwise the default is DW_ACCESS_public. In DWARF2
15342 the default has always been DW_ACCESS_public. */
15343 if (TREE_PROTECTED (decl
))
15344 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
15345 else if (TREE_PRIVATE (decl
))
15347 if (dwarf_version
== 2
15348 || die
->die_parent
== NULL
15349 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
15350 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
15352 else if (dwarf_version
> 2
15354 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
15355 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
15358 /* Attach the specialized form of location attribute used for data members of
15359 struct and union types. In the special case of a FIELD_DECL node which
15360 represents a bit-field, the "offset" part of this special location
15361 descriptor must indicate the distance in bytes from the lowest-addressed
15362 byte of the containing struct or union type to the lowest-addressed byte of
15363 the "containing object" for the bit-field. (See the `field_byte_offset'
15366 For any given bit-field, the "containing object" is a hypothetical object
15367 (of some integral or enum type) within which the given bit-field lives. The
15368 type of this hypothetical "containing object" is always the same as the
15369 declared type of the individual bit-field itself (for GCC anyway... the
15370 DWARF spec doesn't actually mandate this). Note that it is the size (in
15371 bytes) of the hypothetical "containing object" which will be given in the
15372 DW_AT_byte_size attribute for this bit-field. (See the
15373 `byte_size_attribute' function below.) It is also used when calculating the
15374 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15375 function below.) */
15378 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
15380 HOST_WIDE_INT offset
;
15381 dw_loc_descr_ref loc_descr
= 0;
15383 if (TREE_CODE (decl
) == TREE_BINFO
)
15385 /* We're working on the TAG_inheritance for a base class. */
15386 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
15388 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15389 aren't at a fixed offset from all (sub)objects of the same
15390 type. We need to extract the appropriate offset from our
15391 vtable. The following dwarf expression means
15393 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15395 This is specific to the V3 ABI, of course. */
15397 dw_loc_descr_ref tmp
;
15399 /* Make a copy of the object address. */
15400 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
15401 add_loc_descr (&loc_descr
, tmp
);
15403 /* Extract the vtable address. */
15404 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15405 add_loc_descr (&loc_descr
, tmp
);
15407 /* Calculate the address of the offset. */
15408 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
15409 gcc_assert (offset
< 0);
15411 tmp
= int_loc_descriptor (-offset
);
15412 add_loc_descr (&loc_descr
, tmp
);
15413 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
15414 add_loc_descr (&loc_descr
, tmp
);
15416 /* Extract the offset. */
15417 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15418 add_loc_descr (&loc_descr
, tmp
);
15420 /* Add it to the object address. */
15421 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
15422 add_loc_descr (&loc_descr
, tmp
);
15425 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
15428 offset
= field_byte_offset (decl
);
15432 if (dwarf_version
> 2)
15434 /* Don't need to output a location expression, just the constant. */
15436 add_AT_int (die
, DW_AT_data_member_location
, offset
);
15438 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
15443 enum dwarf_location_atom op
;
15445 /* The DWARF2 standard says that we should assume that the structure
15446 address is already on the stack, so we can specify a structure
15447 field address by using DW_OP_plus_uconst. */
15448 op
= DW_OP_plus_uconst
;
15449 loc_descr
= new_loc_descr (op
, offset
, 0);
15453 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
15456 /* Writes integer values to dw_vec_const array. */
15459 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
15463 *dest
++ = val
& 0xff;
15469 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15471 static HOST_WIDE_INT
15472 extract_int (const unsigned char *src
, unsigned int size
)
15474 HOST_WIDE_INT val
= 0;
15480 val
|= *--src
& 0xff;
15486 /* Writes wide_int values to dw_vec_const array. */
15489 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
15493 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
15495 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
15499 /* We'd have to extend this code to support odd sizes. */
15500 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
15502 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
15504 if (WORDS_BIG_ENDIAN
)
15505 for (i
= n
- 1; i
>= 0; i
--)
15507 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15508 dest
+= sizeof (HOST_WIDE_INT
);
15511 for (i
= 0; i
< n
; i
++)
15513 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15514 dest
+= sizeof (HOST_WIDE_INT
);
15518 /* Writes floating point values to dw_vec_const array. */
15521 insert_float (const_rtx rtl
, unsigned char *array
)
15523 REAL_VALUE_TYPE rv
;
15527 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
15528 real_to_target (val
, &rv
, GET_MODE (rtl
));
15530 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15531 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
15533 insert_int (val
[i
], 4, array
);
15538 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15539 does not have a "location" either in memory or in a register. These
15540 things can arise in GNU C when a constant is passed as an actual parameter
15541 to an inlined function. They can also arise in C++ where declared
15542 constants do not necessarily get memory "homes". */
15545 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
15547 switch (GET_CODE (rtl
))
15551 HOST_WIDE_INT val
= INTVAL (rtl
);
15554 add_AT_int (die
, DW_AT_const_value
, val
);
15556 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15560 case CONST_WIDE_INT
:
15561 add_AT_wide (die
, DW_AT_const_value
,
15562 std::make_pair (rtl
, GET_MODE (rtl
)));
15566 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15567 floating-point constant. A CONST_DOUBLE is used whenever the
15568 constant requires more than one word in order to be adequately
15571 machine_mode mode
= GET_MODE (rtl
);
15573 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
15574 add_AT_double (die
, DW_AT_const_value
,
15575 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15578 unsigned int length
= GET_MODE_SIZE (mode
);
15579 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15581 insert_float (rtl
, array
);
15582 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15589 machine_mode mode
= GET_MODE (rtl
);
15590 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15591 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15592 unsigned char *array
15593 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15596 machine_mode imode
= GET_MODE_INNER (mode
);
15598 switch (GET_MODE_CLASS (mode
))
15600 case MODE_VECTOR_INT
:
15601 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15603 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15604 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
15608 case MODE_VECTOR_FLOAT
:
15609 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15611 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15612 insert_float (elt
, p
);
15617 gcc_unreachable ();
15620 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15625 if (dwarf_version
>= 4 || !dwarf_strict
)
15627 dw_loc_descr_ref loc_result
;
15628 resolve_one_addr (&rtl
);
15630 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15631 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15632 add_AT_loc (die
, DW_AT_location
, loc_result
);
15633 vec_safe_push (used_rtx_array
, rtl
);
15639 if (CONSTANT_P (XEXP (rtl
, 0)))
15640 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15643 if (!const_ok_for_output (rtl
))
15646 if (dwarf_version
>= 4 || !dwarf_strict
)
15651 /* In cases where an inlined instance of an inline function is passed
15652 the address of an `auto' variable (which is local to the caller) we
15653 can get a situation where the DECL_RTL of the artificial local
15654 variable (for the inlining) which acts as a stand-in for the
15655 corresponding formal parameter (of the inline function) will look
15656 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15657 exactly a compile-time constant expression, but it isn't the address
15658 of the (artificial) local variable either. Rather, it represents the
15659 *value* which the artificial local variable always has during its
15660 lifetime. We currently have no way to represent such quasi-constant
15661 values in Dwarf, so for now we just punt and generate nothing. */
15669 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15670 && MEM_READONLY_P (rtl
)
15671 && GET_MODE (rtl
) == BLKmode
)
15673 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15679 /* No other kinds of rtx should be possible here. */
15680 gcc_unreachable ();
15685 /* Determine whether the evaluation of EXPR references any variables
15686 or functions which aren't otherwise used (and therefore may not be
15689 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15690 void * data ATTRIBUTE_UNUSED
)
15692 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15693 *walk_subtrees
= 0;
15695 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15696 && ! TREE_ASM_WRITTEN (*tp
))
15698 /* ??? The C++ FE emits debug information for using decls, so
15699 putting gcc_unreachable here falls over. See PR31899. For now
15700 be conservative. */
15701 else if (!symtab
->global_info_ready
15702 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15704 else if (TREE_CODE (*tp
) == VAR_DECL
)
15706 varpool_node
*node
= varpool_node::get (*tp
);
15707 if (!node
|| !node
->definition
)
15710 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15711 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15713 /* The call graph machinery must have finished analyzing,
15714 optimizing and gimplifying the CU by now.
15715 So if *TP has no call graph node associated
15716 to it, it means *TP will not be emitted. */
15717 if (!cgraph_node::get (*tp
))
15720 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15726 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15727 for use in a later add_const_value_attribute call. */
15730 rtl_for_decl_init (tree init
, tree type
)
15732 rtx rtl
= NULL_RTX
;
15736 /* If a variable is initialized with a string constant without embedded
15737 zeros, build CONST_STRING. */
15738 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15740 tree enttype
= TREE_TYPE (type
);
15741 tree domain
= TYPE_DOMAIN (type
);
15742 machine_mode mode
= TYPE_MODE (enttype
);
15744 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15746 && integer_zerop (TYPE_MIN_VALUE (domain
))
15747 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15748 TREE_STRING_LENGTH (init
) - 1) == 0
15749 && ((size_t) TREE_STRING_LENGTH (init
)
15750 == strlen (TREE_STRING_POINTER (init
)) + 1))
15752 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15753 ggc_strdup (TREE_STRING_POINTER (init
)));
15754 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15755 MEM_READONLY_P (rtl
) = 1;
15758 /* Other aggregates, and complex values, could be represented using
15760 else if (AGGREGATE_TYPE_P (type
)
15761 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15762 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15763 || TREE_CODE (type
) == COMPLEX_TYPE
)
15765 /* Vectors only work if their mode is supported by the target.
15766 FIXME: generic vectors ought to work too. */
15767 else if (TREE_CODE (type
) == VECTOR_TYPE
15768 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15770 /* If the initializer is something that we know will expand into an
15771 immediate RTL constant, expand it now. We must be careful not to
15772 reference variables which won't be output. */
15773 else if (initializer_constant_valid_p (init
, type
)
15774 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15776 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15778 if (TREE_CODE (type
) == VECTOR_TYPE
)
15779 switch (TREE_CODE (init
))
15784 if (TREE_CONSTANT (init
))
15786 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15787 bool constant_p
= true;
15789 unsigned HOST_WIDE_INT ix
;
15791 /* Even when ctor is constant, it might contain non-*_CST
15792 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15793 belong into VECTOR_CST nodes. */
15794 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15795 if (!CONSTANT_CLASS_P (value
))
15797 constant_p
= false;
15803 init
= build_vector_from_ctor (type
, elts
);
15813 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15815 /* If expand_expr returns a MEM, it wasn't immediate. */
15816 gcc_assert (!rtl
|| !MEM_P (rtl
));
15822 /* Generate RTL for the variable DECL to represent its location. */
15825 rtl_for_decl_location (tree decl
)
15829 /* Here we have to decide where we are going to say the parameter "lives"
15830 (as far as the debugger is concerned). We only have a couple of
15831 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15833 DECL_RTL normally indicates where the parameter lives during most of the
15834 activation of the function. If optimization is enabled however, this
15835 could be either NULL or else a pseudo-reg. Both of those cases indicate
15836 that the parameter doesn't really live anywhere (as far as the code
15837 generation parts of GCC are concerned) during most of the function's
15838 activation. That will happen (for example) if the parameter is never
15839 referenced within the function.
15841 We could just generate a location descriptor here for all non-NULL
15842 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15843 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15844 where DECL_RTL is NULL or is a pseudo-reg.
15846 Note however that we can only get away with using DECL_INCOMING_RTL as
15847 a backup substitute for DECL_RTL in certain limited cases. In cases
15848 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15849 we can be sure that the parameter was passed using the same type as it is
15850 declared to have within the function, and that its DECL_INCOMING_RTL
15851 points us to a place where a value of that type is passed.
15853 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15854 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15855 because in these cases DECL_INCOMING_RTL points us to a value of some
15856 type which is *different* from the type of the parameter itself. Thus,
15857 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15858 such cases, the debugger would end up (for example) trying to fetch a
15859 `float' from a place which actually contains the first part of a
15860 `double'. That would lead to really incorrect and confusing
15861 output at debug-time.
15863 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15864 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15865 are a couple of exceptions however. On little-endian machines we can
15866 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15867 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15868 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15869 when (on a little-endian machine) a non-prototyped function has a
15870 parameter declared to be of type `short' or `char'. In such cases,
15871 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15872 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15873 passed `int' value. If the debugger then uses that address to fetch
15874 a `short' or a `char' (on a little-endian machine) the result will be
15875 the correct data, so we allow for such exceptional cases below.
15877 Note that our goal here is to describe the place where the given formal
15878 parameter lives during most of the function's activation (i.e. between the
15879 end of the prologue and the start of the epilogue). We'll do that as best
15880 as we can. Note however that if the given formal parameter is modified
15881 sometime during the execution of the function, then a stack backtrace (at
15882 debug-time) will show the function as having been called with the *new*
15883 value rather than the value which was originally passed in. This happens
15884 rarely enough that it is not a major problem, but it *is* a problem, and
15885 I'd like to fix it.
15887 A future version of dwarf2out.c may generate two additional attributes for
15888 any given DW_TAG_formal_parameter DIE which will describe the "passed
15889 type" and the "passed location" for the given formal parameter in addition
15890 to the attributes we now generate to indicate the "declared type" and the
15891 "active location" for each parameter. This additional set of attributes
15892 could be used by debuggers for stack backtraces. Separately, note that
15893 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15894 This happens (for example) for inlined-instances of inline function formal
15895 parameters which are never referenced. This really shouldn't be
15896 happening. All PARM_DECL nodes should get valid non-NULL
15897 DECL_INCOMING_RTL values. FIXME. */
15899 /* Use DECL_RTL as the "location" unless we find something better. */
15900 rtl
= DECL_RTL_IF_SET (decl
);
15902 /* When generating abstract instances, ignore everything except
15903 constants, symbols living in memory, and symbols living in
15904 fixed registers. */
15905 if (! reload_completed
)
15908 && (CONSTANT_P (rtl
)
15910 && CONSTANT_P (XEXP (rtl
, 0)))
15912 && TREE_CODE (decl
) == VAR_DECL
15913 && TREE_STATIC (decl
))))
15915 rtl
= targetm
.delegitimize_address (rtl
);
15920 else if (TREE_CODE (decl
) == PARM_DECL
)
15922 if (rtl
== NULL_RTX
15923 || is_pseudo_reg (rtl
)
15925 && is_pseudo_reg (XEXP (rtl
, 0))
15926 && DECL_INCOMING_RTL (decl
)
15927 && MEM_P (DECL_INCOMING_RTL (decl
))
15928 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15930 tree declared_type
= TREE_TYPE (decl
);
15931 tree passed_type
= DECL_ARG_TYPE (decl
);
15932 machine_mode dmode
= TYPE_MODE (declared_type
);
15933 machine_mode pmode
= TYPE_MODE (passed_type
);
15935 /* This decl represents a formal parameter which was optimized out.
15936 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15937 all cases where (rtl == NULL_RTX) just below. */
15938 if (dmode
== pmode
)
15939 rtl
= DECL_INCOMING_RTL (decl
);
15940 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15941 && SCALAR_INT_MODE_P (dmode
)
15942 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15943 && DECL_INCOMING_RTL (decl
))
15945 rtx inc
= DECL_INCOMING_RTL (decl
);
15948 else if (MEM_P (inc
))
15950 if (BYTES_BIG_ENDIAN
)
15951 rtl
= adjust_address_nv (inc
, dmode
,
15952 GET_MODE_SIZE (pmode
)
15953 - GET_MODE_SIZE (dmode
));
15960 /* If the parm was passed in registers, but lives on the stack, then
15961 make a big endian correction if the mode of the type of the
15962 parameter is not the same as the mode of the rtl. */
15963 /* ??? This is the same series of checks that are made in dbxout.c before
15964 we reach the big endian correction code there. It isn't clear if all
15965 of these checks are necessary here, but keeping them all is the safe
15967 else if (MEM_P (rtl
)
15968 && XEXP (rtl
, 0) != const0_rtx
15969 && ! CONSTANT_P (XEXP (rtl
, 0))
15970 /* Not passed in memory. */
15971 && !MEM_P (DECL_INCOMING_RTL (decl
))
15972 /* Not passed by invisible reference. */
15973 && (!REG_P (XEXP (rtl
, 0))
15974 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15975 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15976 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15977 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15980 /* Big endian correction check. */
15981 && BYTES_BIG_ENDIAN
15982 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15983 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15986 machine_mode addr_mode
= get_address_mode (rtl
);
15987 int offset
= (UNITS_PER_WORD
15988 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15990 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15991 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15994 else if (TREE_CODE (decl
) == VAR_DECL
15997 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15998 && BYTES_BIG_ENDIAN
)
16000 machine_mode addr_mode
= get_address_mode (rtl
);
16001 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
16002 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
16004 /* If a variable is declared "register" yet is smaller than
16005 a register, then if we store the variable to memory, it
16006 looks like we're storing a register-sized value, when in
16007 fact we are not. We need to adjust the offset of the
16008 storage location to reflect the actual value's bytes,
16009 else gdb will not be able to display it. */
16011 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16012 plus_constant (addr_mode
, XEXP (rtl
, 0),
16016 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16017 and will have been substituted directly into all expressions that use it.
16018 C does not have such a concept, but C++ and other languages do. */
16019 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
16020 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
16023 rtl
= targetm
.delegitimize_address (rtl
);
16025 /* If we don't look past the constant pool, we risk emitting a
16026 reference to a constant pool entry that isn't referenced from
16027 code, and thus is not emitted. */
16029 rtl
= avoid_constant_pool_reference (rtl
);
16031 /* Try harder to get a rtl. If this symbol ends up not being emitted
16032 in the current CU, resolve_addr will remove the expression referencing
16034 if (rtl
== NULL_RTX
16035 && TREE_CODE (decl
) == VAR_DECL
16036 && !DECL_EXTERNAL (decl
)
16037 && TREE_STATIC (decl
)
16038 && DECL_NAME (decl
)
16039 && !DECL_HARD_REGISTER (decl
)
16040 && DECL_MODE (decl
) != VOIDmode
)
16042 rtl
= make_decl_rtl_for_debug (decl
);
16044 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
16045 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
16052 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16053 returned. If so, the decl for the COMMON block is returned, and the
16054 value is the offset into the common block for the symbol. */
16057 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
16059 tree val_expr
, cvar
;
16061 HOST_WIDE_INT bitsize
, bitpos
;
16063 int unsignedp
, volatilep
= 0;
16065 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16066 it does not have a value (the offset into the common area), or if it
16067 is thread local (as opposed to global) then it isn't common, and shouldn't
16068 be handled as such. */
16069 if (TREE_CODE (decl
) != VAR_DECL
16070 || !TREE_STATIC (decl
)
16071 || !DECL_HAS_VALUE_EXPR_P (decl
)
16075 val_expr
= DECL_VALUE_EXPR (decl
);
16076 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
16079 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
16080 &mode
, &unsignedp
, &volatilep
, true);
16082 if (cvar
== NULL_TREE
16083 || TREE_CODE (cvar
) != VAR_DECL
16084 || DECL_ARTIFICIAL (cvar
)
16085 || !TREE_PUBLIC (cvar
))
16089 if (offset
!= NULL
)
16091 if (!tree_fits_shwi_p (offset
))
16093 *value
= tree_to_shwi (offset
);
16096 *value
+= bitpos
/ BITS_PER_UNIT
;
16101 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16102 data attribute for a variable or a parameter. We generate the
16103 DW_AT_const_value attribute only in those cases where the given variable
16104 or parameter does not have a true "location" either in memory or in a
16105 register. This can happen (for example) when a constant is passed as an
16106 actual argument in a call to an inline function. (It's possible that
16107 these things can crop up in other ways also.) Note that one type of
16108 constant value which can be passed into an inlined function is a constant
16109 pointer. This can happen for example if an actual argument in an inlined
16110 function call evaluates to a compile-time constant address.
16112 CACHE_P is true if it is worth caching the location list for DECL,
16113 so that future calls can reuse it rather than regenerate it from scratch.
16114 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
16115 since we will need to refer to them each time the function is inlined. */
16118 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
16119 enum dwarf_attribute attr
)
16122 dw_loc_list_ref list
;
16123 var_loc_list
*loc_list
;
16124 cached_dw_loc_list
*cache
;
16126 if (TREE_CODE (decl
) == ERROR_MARK
)
16129 if (get_AT (die
, attr
))
16132 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
16133 || TREE_CODE (decl
) == RESULT_DECL
);
16135 /* Try to get some constant RTL for this decl, and use that as the value of
16138 rtl
= rtl_for_decl_location (decl
);
16139 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16140 && add_const_value_attribute (die
, rtl
))
16143 /* See if we have single element location list that is equivalent to
16144 a constant value. That way we are better to use add_const_value_attribute
16145 rather than expanding constant value equivalent. */
16146 loc_list
= lookup_decl_loc (decl
);
16149 && loc_list
->first
->next
== NULL
16150 && NOTE_P (loc_list
->first
->loc
)
16151 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
16152 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
16154 struct var_loc_node
*node
;
16156 node
= loc_list
->first
;
16157 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
16158 if (GET_CODE (rtl
) == EXPR_LIST
)
16159 rtl
= XEXP (rtl
, 0);
16160 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16161 && add_const_value_attribute (die
, rtl
))
16164 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
16165 list several times. See if we've already cached the contents. */
16167 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
16171 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
16173 list
= cache
->loc_list
;
16177 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
16179 /* It is usually worth caching this result if the decl is from
16180 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
16181 if (cache_p
&& list
&& list
->dw_loc_next
)
16183 cached_dw_loc_list
**slot
16184 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
16187 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
16188 cache
->decl_id
= DECL_UID (decl
);
16189 cache
->loc_list
= list
;
16195 add_AT_location_description (die
, attr
, list
);
16198 /* None of that worked, so it must not really have a location;
16199 try adding a constant value attribute from the DECL_INITIAL. */
16200 return tree_add_const_value_attribute_for_decl (die
, decl
);
16203 /* Helper function for tree_add_const_value_attribute. Natively encode
16204 initializer INIT into an array. Return true if successful. */
16207 native_encode_initializer (tree init
, unsigned char *array
, int size
)
16211 if (init
== NULL_TREE
)
16215 switch (TREE_CODE (init
))
16218 type
= TREE_TYPE (init
);
16219 if (TREE_CODE (type
) == ARRAY_TYPE
)
16221 tree enttype
= TREE_TYPE (type
);
16222 machine_mode mode
= TYPE_MODE (enttype
);
16224 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
16226 if (int_size_in_bytes (type
) != size
)
16228 if (size
> TREE_STRING_LENGTH (init
))
16230 memcpy (array
, TREE_STRING_POINTER (init
),
16231 TREE_STRING_LENGTH (init
));
16232 memset (array
+ TREE_STRING_LENGTH (init
),
16233 '\0', size
- TREE_STRING_LENGTH (init
));
16236 memcpy (array
, TREE_STRING_POINTER (init
), size
);
16241 type
= TREE_TYPE (init
);
16242 if (int_size_in_bytes (type
) != size
)
16244 if (TREE_CODE (type
) == ARRAY_TYPE
)
16246 HOST_WIDE_INT min_index
;
16247 unsigned HOST_WIDE_INT cnt
;
16248 int curpos
= 0, fieldsize
;
16249 constructor_elt
*ce
;
16251 if (TYPE_DOMAIN (type
) == NULL_TREE
16252 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
16255 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
16256 if (fieldsize
<= 0)
16259 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
16260 memset (array
, '\0', size
);
16261 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16263 tree val
= ce
->value
;
16264 tree index
= ce
->index
;
16266 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16267 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
16270 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
16275 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
16278 curpos
= pos
+ fieldsize
;
16279 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16281 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
16282 - tree_to_shwi (TREE_OPERAND (index
, 0));
16283 while (count
-- > 0)
16286 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
16287 curpos
+= fieldsize
;
16290 gcc_assert (curpos
<= size
);
16294 else if (TREE_CODE (type
) == RECORD_TYPE
16295 || TREE_CODE (type
) == UNION_TYPE
)
16297 tree field
= NULL_TREE
;
16298 unsigned HOST_WIDE_INT cnt
;
16299 constructor_elt
*ce
;
16301 if (int_size_in_bytes (type
) != size
)
16304 if (TREE_CODE (type
) == RECORD_TYPE
)
16305 field
= TYPE_FIELDS (type
);
16307 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16309 tree val
= ce
->value
;
16310 int pos
, fieldsize
;
16312 if (ce
->index
!= 0)
16318 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
16321 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
16322 && TYPE_DOMAIN (TREE_TYPE (field
))
16323 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
16325 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
16326 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
16328 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
16329 pos
= int_byte_position (field
);
16330 gcc_assert (pos
+ fieldsize
<= size
);
16332 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
16338 case VIEW_CONVERT_EXPR
:
16339 case NON_LVALUE_EXPR
:
16340 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
16342 return native_encode_expr (init
, array
, size
) == size
;
16346 /* Attach a DW_AT_const_value attribute to DIE. The value of the
16347 attribute is the const value T. */
16350 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
16353 tree type
= TREE_TYPE (t
);
16356 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
16360 gcc_assert (!DECL_P (init
));
16362 rtl
= rtl_for_decl_init (init
, type
);
16364 return add_const_value_attribute (die
, rtl
);
16365 /* If the host and target are sane, try harder. */
16366 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
16367 && initializer_constant_valid_p (init
, type
))
16369 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
16370 if (size
> 0 && (int) size
== size
)
16372 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
16374 if (native_encode_initializer (init
, array
, size
))
16376 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
16385 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16386 attribute is the const value of T, where T is an integral constant
16387 variable with static storage duration
16388 (so it can't be a PARM_DECL or a RESULT_DECL). */
16391 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
16395 || (TREE_CODE (decl
) != VAR_DECL
16396 && TREE_CODE (decl
) != CONST_DECL
)
16397 || (TREE_CODE (decl
) == VAR_DECL
16398 && !TREE_STATIC (decl
)))
16401 if (TREE_READONLY (decl
)
16402 && ! TREE_THIS_VOLATILE (decl
)
16403 && DECL_INITIAL (decl
))
16408 /* Don't add DW_AT_const_value if abstract origin already has one. */
16409 if (get_AT (var_die
, DW_AT_const_value
))
16412 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
16415 /* Convert the CFI instructions for the current function into a
16416 location list. This is used for DW_AT_frame_base when we targeting
16417 a dwarf2 consumer that does not support the dwarf3
16418 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16421 static dw_loc_list_ref
16422 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
16426 dw_loc_list_ref list
, *list_tail
;
16428 dw_cfa_location last_cfa
, next_cfa
;
16429 const char *start_label
, *last_label
, *section
;
16430 dw_cfa_location remember
;
16433 gcc_assert (fde
!= NULL
);
16435 section
= secname_for_decl (current_function_decl
);
16439 memset (&next_cfa
, 0, sizeof (next_cfa
));
16440 next_cfa
.reg
= INVALID_REGNUM
;
16441 remember
= next_cfa
;
16443 start_label
= fde
->dw_fde_begin
;
16445 /* ??? Bald assumption that the CIE opcode list does not contain
16446 advance opcodes. */
16447 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
16448 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16450 last_cfa
= next_cfa
;
16451 last_label
= start_label
;
16453 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
16455 /* If the first partition contained no CFI adjustments, the
16456 CIE opcodes apply to the whole first partition. */
16457 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16458 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
16459 list_tail
=&(*list_tail
)->dw_loc_next
;
16460 start_label
= last_label
= fde
->dw_fde_second_begin
;
16463 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
16465 switch (cfi
->dw_cfi_opc
)
16467 case DW_CFA_set_loc
:
16468 case DW_CFA_advance_loc1
:
16469 case DW_CFA_advance_loc2
:
16470 case DW_CFA_advance_loc4
:
16471 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16473 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16474 start_label
, last_label
, section
);
16476 list_tail
= &(*list_tail
)->dw_loc_next
;
16477 last_cfa
= next_cfa
;
16478 start_label
= last_label
;
16480 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
16483 case DW_CFA_advance_loc
:
16484 /* The encoding is complex enough that we should never emit this. */
16485 gcc_unreachable ();
16488 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16491 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
16493 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16495 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16496 start_label
, last_label
, section
);
16498 list_tail
= &(*list_tail
)->dw_loc_next
;
16499 last_cfa
= next_cfa
;
16500 start_label
= last_label
;
16502 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16503 start_label
, fde
->dw_fde_end
, section
);
16504 list_tail
= &(*list_tail
)->dw_loc_next
;
16505 start_label
= last_label
= fde
->dw_fde_second_begin
;
16509 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16511 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16512 start_label
, last_label
, section
);
16513 list_tail
= &(*list_tail
)->dw_loc_next
;
16514 start_label
= last_label
;
16517 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
16519 fde
->dw_fde_second_begin
16520 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
16523 if (list
&& list
->dw_loc_next
)
16529 /* Compute a displacement from the "steady-state frame pointer" to the
16530 frame base (often the same as the CFA), and store it in
16531 frame_pointer_fb_offset. OFFSET is added to the displacement
16532 before the latter is negated. */
16535 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
16539 #ifdef FRAME_POINTER_CFA_OFFSET
16540 reg
= frame_pointer_rtx
;
16541 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
16543 reg
= arg_pointer_rtx
;
16544 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16547 elim
= (ira_use_lra_p
16548 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16549 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16550 if (GET_CODE (elim
) == PLUS
)
16552 offset
+= INTVAL (XEXP (elim
, 1));
16553 elim
= XEXP (elim
, 0);
16556 frame_pointer_fb_offset
= -offset
;
16558 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16559 in which to eliminate. This is because it's stack pointer isn't
16560 directly accessible as a register within the ISA. To work around
16561 this, assume that while we cannot provide a proper value for
16562 frame_pointer_fb_offset, we won't need one either. */
16563 frame_pointer_fb_offset_valid
16564 = ((SUPPORTS_STACK_ALIGNMENT
16565 && (elim
== hard_frame_pointer_rtx
16566 || elim
== stack_pointer_rtx
))
16567 || elim
== (frame_pointer_needed
16568 ? hard_frame_pointer_rtx
16569 : stack_pointer_rtx
));
16572 /* Generate a DW_AT_name attribute given some string value to be included as
16573 the value of the attribute. */
16576 add_name_attribute (dw_die_ref die
, const char *name_string
)
16578 if (name_string
!= NULL
&& *name_string
!= 0)
16580 if (demangle_name_func
)
16581 name_string
= (*demangle_name_func
) (name_string
);
16583 add_AT_string (die
, DW_AT_name
, name_string
);
16587 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16588 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16589 of TYPE accordingly.
16591 ??? This is a temporary measure until after we're able to generate
16592 regular DWARF for the complex Ada type system. */
16595 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16596 dw_die_ref context_die
)
16599 dw_die_ref dtype_die
;
16601 if (!lang_hooks
.types
.descriptive_type
)
16604 dtype
= lang_hooks
.types
.descriptive_type (type
);
16608 dtype_die
= lookup_type_die (dtype
);
16611 gen_type_die (dtype
, context_die
);
16612 dtype_die
= lookup_type_die (dtype
);
16613 gcc_assert (dtype_die
);
16616 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16619 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16621 static const char *
16622 comp_dir_string (void)
16626 static const char *cached_wd
= NULL
;
16628 if (cached_wd
!= NULL
)
16631 wd
= get_src_pwd ();
16635 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16639 wdlen
= strlen (wd
);
16640 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
16642 wd1
[wdlen
] = DIR_SEPARATOR
;
16643 wd1
[wdlen
+ 1] = 0;
16647 cached_wd
= remap_debug_filename (wd
);
16651 /* Generate a DW_AT_comp_dir attribute for DIE. */
16654 add_comp_dir_attribute (dw_die_ref die
)
16656 const char * wd
= comp_dir_string ();
16658 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16661 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
16662 pointer computation, ...), output a representation for that bound according
16663 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
16664 loc_list_from_tree for the meaning of CONTEXT. */
16667 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
16668 int forms
, const struct loc_descr_context
*context
)
16670 dw_die_ref ctx
, decl_die
;
16671 dw_loc_list_ref list
;
16673 bool strip_conversions
= true;
16675 while (strip_conversions
)
16676 switch (TREE_CODE (value
))
16683 case VIEW_CONVERT_EXPR
:
16684 value
= TREE_OPERAND (value
, 0);
16688 strip_conversions
= false;
16692 /* If possible and permitted, output the attribute as a constant. */
16693 if ((forms
& dw_scalar_form_constant
) != 0
16694 && TREE_CODE (value
) == INTEGER_CST
)
16696 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
16698 /* If HOST_WIDE_INT is big enough then represent the bound as
16699 a constant value. We need to choose a form based on
16700 whether the type is signed or unsigned. We cannot just
16701 call add_AT_unsigned if the value itself is positive
16702 (add_AT_unsigned might add the unsigned value encoded as
16703 DW_FORM_data[1248]). Some DWARF consumers will lookup the
16704 bounds type and then sign extend any unsigned values found
16705 for signed types. This is needed only for
16706 DW_AT_{lower,upper}_bound, since for most other attributes,
16707 consumers will treat DW_FORM_data[1248] as unsigned values,
16708 regardless of the underlying type. */
16709 if (prec
<= HOST_BITS_PER_WIDE_INT
16710 || tree_fits_uhwi_p (value
))
16712 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
16713 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
16715 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
16718 /* Otherwise represent the bound as an unsigned value with
16719 the precision of its type. The precision and signedness
16720 of the type will be necessary to re-interpret it
16722 add_AT_wide (die
, attr
, value
);
16726 /* Otherwise, if it's possible and permitted too, output a reference to
16728 if ((forms
& dw_scalar_form_reference
) != 0)
16730 tree decl
= NULL_TREE
;
16732 /* Some type attributes reference an outer type. For instance, the upper
16733 bound of an array may reference an embedding record (this happens in
16735 if (TREE_CODE (value
) == COMPONENT_REF
16736 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
16737 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
16738 decl
= TREE_OPERAND (value
, 1);
16740 else if (TREE_CODE (value
) == VAR_DECL
16741 || TREE_CODE (value
) == PARM_DECL
16742 || TREE_CODE (value
) == RESULT_DECL
)
16745 if (decl
!= NULL_TREE
)
16747 dw_die_ref decl_die
= lookup_decl_die (decl
);
16749 /* ??? Can this happen, or should the variable have been bound
16750 first? Probably it can, since I imagine that we try to create
16751 the types of parameters in the order in which they exist in
16752 the list, and won't have created a forward reference to a
16753 later parameter. */
16754 if (decl_die
!= NULL
)
16756 add_AT_die_ref (die
, attr
, decl_die
);
16762 /* Last chance: try to create a stack operation procedure to evaluate the
16763 value. Do nothing if even that is not possible or permitted. */
16764 if ((forms
& dw_scalar_form_exprloc
) == 0)
16767 list
= loc_list_from_tree (value
, 2, context
);
16768 if (list
== NULL
|| single_element_loc_list_p (list
))
16770 /* If this attribute is not a reference nor constant, it is
16771 a DWARF expression rather than location description. For that
16772 loc_list_from_tree (value, 0, &context) is needed. */
16773 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
16774 if (list2
&& single_element_loc_list_p (list2
))
16776 add_AT_loc (die
, attr
, list2
->expr
);
16781 /* If that failed to give a single element location list, fall back to
16782 outputting this as a reference... still if permitted. */
16783 if (list
== NULL
|| (forms
& dw_scalar_form_reference
) == 0)
16786 if (current_function_decl
== 0)
16787 ctx
= comp_unit_die ();
16789 ctx
= lookup_decl_die (current_function_decl
);
16791 decl_die
= new_die (DW_TAG_variable
, ctx
, value
);
16792 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16793 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, ctx
);
16794 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16795 add_AT_die_ref (die
, attr
, decl_die
);
16798 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16802 lower_bound_default (void)
16804 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16810 case DW_LANG_C_plus_plus
:
16811 case DW_LANG_C_plus_plus_11
:
16812 case DW_LANG_C_plus_plus_14
:
16814 case DW_LANG_ObjC_plus_plus
:
16817 case DW_LANG_Fortran77
:
16818 case DW_LANG_Fortran90
:
16819 case DW_LANG_Fortran95
:
16820 case DW_LANG_Fortran03
:
16821 case DW_LANG_Fortran08
:
16825 case DW_LANG_Python
:
16826 return dwarf_version
>= 4 ? 0 : -1;
16827 case DW_LANG_Ada95
:
16828 case DW_LANG_Ada83
:
16829 case DW_LANG_Cobol74
:
16830 case DW_LANG_Cobol85
:
16831 case DW_LANG_Pascal83
:
16832 case DW_LANG_Modula2
:
16834 return dwarf_version
>= 4 ? 1 : -1;
16840 /* Given a tree node describing an array bound (either lower or upper) output
16841 a representation for that bound. */
16844 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
16845 tree bound
, const struct loc_descr_context
*context
)
16850 switch (TREE_CODE (bound
))
16852 /* Strip all conversions. */
16854 case VIEW_CONVERT_EXPR
:
16855 bound
= TREE_OPERAND (bound
, 0);
16858 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
16859 are even omitted when they are the default. */
16861 /* If the value for this bound is the default one, we can even omit the
16863 if (bound_attr
== DW_AT_lower_bound
16864 && tree_fits_shwi_p (bound
)
16865 && (dflt
= lower_bound_default ()) != -1
16866 && tree_to_shwi (bound
) == dflt
)
16872 add_scalar_info (subrange_die
, bound_attr
, bound
,
16873 dw_scalar_form_constant
16874 | dw_scalar_form_exprloc
16875 | dw_scalar_form_reference
,
16881 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16882 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16883 Note that the block of subscript information for an array type also
16884 includes information about the element type of the given array type.
16886 This function reuses previously set type and bound information if
16890 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16892 unsigned dimension_number
;
16894 dw_die_ref child
= type_die
->die_child
;
16896 for (dimension_number
= 0;
16897 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16898 type
= TREE_TYPE (type
), dimension_number
++)
16900 tree domain
= TYPE_DOMAIN (type
);
16902 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16905 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16906 and (in GNU C only) variable bounds. Handle all three forms
16909 /* Find and reuse a previously generated DW_TAG_subrange_type if
16912 For multi-dimensional arrays, as we iterate through the
16913 various dimensions in the enclosing for loop above, we also
16914 iterate through the DIE children and pick at each
16915 DW_TAG_subrange_type previously generated (if available).
16916 Each child DW_TAG_subrange_type DIE describes the range of
16917 the current dimension. At this point we should have as many
16918 DW_TAG_subrange_type's as we have dimensions in the
16920 dw_die_ref subrange_die
= NULL
;
16924 child
= child
->die_sib
;
16925 if (child
->die_tag
== DW_TAG_subrange_type
)
16926 subrange_die
= child
;
16927 if (child
== type_die
->die_child
)
16929 /* If we wrapped around, stop looking next time. */
16933 if (child
->die_tag
== DW_TAG_subrange_type
)
16937 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16941 /* We have an array type with specified bounds. */
16942 lower
= TYPE_MIN_VALUE (domain
);
16943 upper
= TYPE_MAX_VALUE (domain
);
16945 /* Define the index type. */
16946 if (TREE_TYPE (domain
)
16947 && !get_AT (subrange_die
, DW_AT_type
))
16949 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16950 TREE_TYPE field. We can't emit debug info for this
16951 because it is an unnamed integral type. */
16952 if (TREE_CODE (domain
) == INTEGER_TYPE
16953 && TYPE_NAME (domain
) == NULL_TREE
16954 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16955 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16958 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
16959 TYPE_UNQUALIFIED
, type_die
);
16962 /* ??? If upper is NULL, the array has unspecified length,
16963 but it does have a lower bound. This happens with Fortran
16965 Since the debugger is definitely going to need to know N
16966 to produce useful results, go ahead and output the lower
16967 bound solo, and hope the debugger can cope. */
16969 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
16970 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
16971 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
16972 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
16975 /* Otherwise we have an array type with an unspecified length. The
16976 DWARF-2 spec does not say how to handle this; let's just leave out the
16981 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
16984 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16986 dw_die_ref decl_die
;
16987 HOST_WIDE_INT size
;
16989 switch (TREE_CODE (tree_node
))
16994 case ENUMERAL_TYPE
:
16997 case QUAL_UNION_TYPE
:
16998 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16999 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
17001 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
17004 size
= int_size_in_bytes (tree_node
);
17007 /* For a data member of a struct or union, the DW_AT_byte_size is
17008 generally given as the number of bytes normally allocated for an
17009 object of the *declared* type of the member itself. This is true
17010 even for bit-fields. */
17011 size
= int_size_in_bytes (field_type (tree_node
));
17014 gcc_unreachable ();
17017 /* Note that `size' might be -1 when we get to this point. If it is, that
17018 indicates that the byte size of the entity in question is variable. We
17019 have no good way of expressing this fact in Dwarf at the present time,
17020 when location description was not used by the caller code instead. */
17022 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
17025 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17026 which specifies the distance in bits from the highest order bit of the
17027 "containing object" for the bit-field to the highest order bit of the
17030 For any given bit-field, the "containing object" is a hypothetical object
17031 (of some integral or enum type) within which the given bit-field lives. The
17032 type of this hypothetical "containing object" is always the same as the
17033 declared type of the individual bit-field itself. The determination of the
17034 exact location of the "containing object" for a bit-field is rather
17035 complicated. It's handled by the `field_byte_offset' function (above).
17037 Note that it is the size (in bytes) of the hypothetical "containing object"
17038 which will be given in the DW_AT_byte_size attribute for this bit-field.
17039 (See `byte_size_attribute' above). */
17042 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
17044 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
17045 tree type
= DECL_BIT_FIELD_TYPE (decl
);
17046 HOST_WIDE_INT bitpos_int
;
17047 HOST_WIDE_INT highest_order_object_bit_offset
;
17048 HOST_WIDE_INT highest_order_field_bit_offset
;
17049 HOST_WIDE_INT bit_offset
;
17051 /* Must be a field and a bit field. */
17052 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
17054 /* We can't yet handle bit-fields whose offsets are variable, so if we
17055 encounter such things, just return without generating any attribute
17056 whatsoever. Likewise for variable or too large size. */
17057 if (! tree_fits_shwi_p (bit_position (decl
))
17058 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
17061 bitpos_int
= int_bit_position (decl
);
17063 /* Note that the bit offset is always the distance (in bits) from the
17064 highest-order bit of the "containing object" to the highest-order bit of
17065 the bit-field itself. Since the "high-order end" of any object or field
17066 is different on big-endian and little-endian machines, the computation
17067 below must take account of these differences. */
17068 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
17069 highest_order_field_bit_offset
= bitpos_int
;
17071 if (! BYTES_BIG_ENDIAN
)
17073 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
17074 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
17078 = (! BYTES_BIG_ENDIAN
17079 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
17080 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
17082 if (bit_offset
< 0)
17083 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
17085 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
17088 /* For a FIELD_DECL node which represents a bit field, output an attribute
17089 which specifies the length in bits of the given field. */
17092 add_bit_size_attribute (dw_die_ref die
, tree decl
)
17094 /* Must be a field and a bit field. */
17095 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
17096 && DECL_BIT_FIELD_TYPE (decl
));
17098 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
17099 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
17102 /* If the compiled language is ANSI C, then add a 'prototyped'
17103 attribute, if arg types are given for the parameters of a function. */
17106 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
17108 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
17115 if (prototype_p (func_type
))
17116 add_AT_flag (die
, DW_AT_prototyped
, 1);
17123 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17124 by looking in either the type declaration or object declaration
17127 static inline dw_die_ref
17128 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
17130 dw_die_ref origin_die
= NULL
;
17132 if (TREE_CODE (origin
) != FUNCTION_DECL
)
17134 /* We may have gotten separated from the block for the inlined
17135 function, if we're in an exception handler or some such; make
17136 sure that the abstract function has been written out.
17138 Doing this for nested functions is wrong, however; functions are
17139 distinct units, and our context might not even be inline. */
17143 fn
= TYPE_STUB_DECL (fn
);
17145 fn
= decl_function_context (fn
);
17147 dwarf2out_abstract_function (fn
);
17150 if (DECL_P (origin
))
17151 origin_die
= lookup_decl_die (origin
);
17152 else if (TYPE_P (origin
))
17153 origin_die
= lookup_type_die (origin
);
17155 /* XXX: Functions that are never lowered don't always have correct block
17156 trees (in the case of java, they simply have no block tree, in some other
17157 languages). For these functions, there is nothing we can really do to
17158 output correct debug info for inlined functions in all cases. Rather
17159 than die, we'll just produce deficient debug info now, in that we will
17160 have variables without a proper abstract origin. In the future, when all
17161 functions are lowered, we should re-add a gcc_assert (origin_die)
17165 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
17169 /* We do not currently support the pure_virtual attribute. */
17172 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
17174 if (DECL_VINDEX (func_decl
))
17176 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
17178 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
17179 add_AT_loc (die
, DW_AT_vtable_elem_location
,
17180 new_loc_descr (DW_OP_constu
,
17181 tree_to_shwi (DECL_VINDEX (func_decl
)),
17184 /* GNU extension: Record what type this method came from originally. */
17185 if (debug_info_level
> DINFO_LEVEL_TERSE
17186 && DECL_CONTEXT (func_decl
))
17187 add_AT_die_ref (die
, DW_AT_containing_type
,
17188 lookup_type_die (DECL_CONTEXT (func_decl
)));
17192 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17193 given decl. This used to be a vendor extension until after DWARF 4
17194 standardized it. */
17197 add_linkage_attr (dw_die_ref die
, tree decl
)
17199 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
17201 /* Mimic what assemble_name_raw does with a leading '*'. */
17202 if (name
[0] == '*')
17205 if (dwarf_version
>= 4)
17206 add_AT_string (die
, DW_AT_linkage_name
, name
);
17208 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
17211 /* Add source coordinate attributes for the given decl. */
17214 add_src_coords_attributes (dw_die_ref die
, tree decl
)
17216 expanded_location s
;
17218 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
17220 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17221 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
17222 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
17225 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17228 add_linkage_name (dw_die_ref die
, tree decl
)
17230 if (debug_info_level
> DINFO_LEVEL_NONE
17231 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
17232 && TREE_PUBLIC (decl
)
17233 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
17234 && die
->die_tag
!= DW_TAG_member
)
17236 /* Defer until we have an assembler name set. */
17237 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
17239 limbo_die_node
*asm_name
;
17241 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
17242 asm_name
->die
= die
;
17243 asm_name
->created_for
= decl
;
17244 asm_name
->next
= deferred_asm_name
;
17245 deferred_asm_name
= asm_name
;
17247 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
17248 add_linkage_attr (die
, decl
);
17252 /* Add a DW_AT_name attribute and source coordinate attribute for the
17253 given decl, but only if it actually has a name. */
17256 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
17260 decl_name
= DECL_NAME (decl
);
17261 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
17263 const char *name
= dwarf2_name (decl
, 0);
17265 add_name_attribute (die
, name
);
17266 if (! DECL_ARTIFICIAL (decl
))
17267 add_src_coords_attributes (die
, decl
);
17269 add_linkage_name (die
, decl
);
17272 #ifdef VMS_DEBUGGING_INFO
17273 /* Get the function's name, as described by its RTL. This may be different
17274 from the DECL_NAME name used in the source file. */
17275 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
17277 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
17278 XEXP (DECL_RTL (decl
), 0), false);
17279 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
17281 #endif /* VMS_DEBUGGING_INFO */
17284 #ifdef VMS_DEBUGGING_INFO
17285 /* Output the debug main pointer die for VMS */
17288 dwarf2out_vms_debug_main_pointer (void)
17290 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17293 /* Allocate the VMS debug main subprogram die. */
17294 die
= ggc_cleared_alloc
<die_node
> ();
17295 die
->die_tag
= DW_TAG_subprogram
;
17296 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
17297 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
17298 current_function_funcdef_no
);
17299 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17301 /* Make it the first child of comp_unit_die (). */
17302 die
->die_parent
= comp_unit_die ();
17303 if (comp_unit_die ()->die_child
)
17305 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
17306 comp_unit_die ()->die_child
->die_sib
= die
;
17310 die
->die_sib
= die
;
17311 comp_unit_die ()->die_child
= die
;
17314 #endif /* VMS_DEBUGGING_INFO */
17316 /* Push a new declaration scope. */
17319 push_decl_scope (tree scope
)
17321 vec_safe_push (decl_scope_table
, scope
);
17324 /* Pop a declaration scope. */
17327 pop_decl_scope (void)
17329 decl_scope_table
->pop ();
17332 /* walk_tree helper function for uses_local_type, below. */
17335 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
17338 *walk_subtrees
= 0;
17341 tree name
= TYPE_NAME (*tp
);
17342 if (name
&& DECL_P (name
) && decl_function_context (name
))
17348 /* If TYPE involves a function-local type (including a local typedef to a
17349 non-local type), returns that type; otherwise returns NULL_TREE. */
17352 uses_local_type (tree type
)
17354 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
17358 /* Return the DIE for the scope that immediately contains this type.
17359 Non-named types that do not involve a function-local type get global
17360 scope. Named types nested in namespaces or other types get their
17361 containing scope. All other types (i.e. function-local named types) get
17362 the current active scope. */
17365 scope_die_for (tree t
, dw_die_ref context_die
)
17367 dw_die_ref scope_die
= NULL
;
17368 tree containing_scope
;
17370 /* Non-types always go in the current scope. */
17371 gcc_assert (TYPE_P (t
));
17373 /* Use the scope of the typedef, rather than the scope of the type
17375 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
17376 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
17378 containing_scope
= TYPE_CONTEXT (t
);
17380 /* Use the containing namespace if there is one. */
17381 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
17383 if (context_die
== lookup_decl_die (containing_scope
))
17385 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
17386 context_die
= get_context_die (containing_scope
);
17388 containing_scope
= NULL_TREE
;
17391 /* Ignore function type "scopes" from the C frontend. They mean that
17392 a tagged type is local to a parmlist of a function declarator, but
17393 that isn't useful to DWARF. */
17394 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
17395 containing_scope
= NULL_TREE
;
17397 if (SCOPE_FILE_SCOPE_P (containing_scope
))
17399 /* If T uses a local type keep it local as well, to avoid references
17400 to function-local DIEs from outside the function. */
17401 if (current_function_decl
&& uses_local_type (t
))
17402 scope_die
= context_die
;
17404 scope_die
= comp_unit_die ();
17406 else if (TYPE_P (containing_scope
))
17408 /* For types, we can just look up the appropriate DIE. */
17409 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17410 scope_die
= get_context_die (containing_scope
);
17413 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
17414 if (scope_die
== NULL
)
17415 scope_die
= comp_unit_die ();
17419 scope_die
= context_die
;
17424 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17427 local_scope_p (dw_die_ref context_die
)
17429 for (; context_die
; context_die
= context_die
->die_parent
)
17430 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
17431 || context_die
->die_tag
== DW_TAG_subprogram
)
17437 /* Returns nonzero if CONTEXT_DIE is a class. */
17440 class_scope_p (dw_die_ref context_die
)
17442 return (context_die
17443 && (context_die
->die_tag
== DW_TAG_structure_type
17444 || context_die
->die_tag
== DW_TAG_class_type
17445 || context_die
->die_tag
== DW_TAG_interface_type
17446 || context_die
->die_tag
== DW_TAG_union_type
));
17449 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17450 whether or not to treat a DIE in this context as a declaration. */
17453 class_or_namespace_scope_p (dw_die_ref context_die
)
17455 return (class_scope_p (context_die
)
17456 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
17459 /* Many forms of DIEs require a "type description" attribute. This
17460 routine locates the proper "type descriptor" die for the type given
17461 by 'type' plus any additional qualifiers given by 'cv_quals', and
17462 adds a DW_AT_type attribute below the given die. */
17465 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
17466 dw_die_ref context_die
)
17468 enum tree_code code
= TREE_CODE (type
);
17469 dw_die_ref type_die
= NULL
;
17471 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17472 or fixed-point type, use the inner type. This is because we have no
17473 support for unnamed types in base_type_die. This can happen if this is
17474 an Ada subrange type. Correct solution is emit a subrange type die. */
17475 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
17476 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
17477 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
17479 if (code
== ERROR_MARK
17480 /* Handle a special case. For functions whose return type is void, we
17481 generate *no* type attribute. (Note that no object may have type
17482 `void', so this only applies to function return types). */
17483 || code
== VOID_TYPE
)
17486 type_die
= modified_type_die (type
,
17487 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
17490 if (type_die
!= NULL
)
17491 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
17494 /* Given an object die, add the calling convention attribute for the
17495 function call type. */
17497 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
17499 enum dwarf_calling_convention value
= DW_CC_normal
;
17501 value
= ((enum dwarf_calling_convention
)
17502 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
17505 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
17507 /* DWARF 2 doesn't provide a way to identify a program's source-level
17508 entry point. DW_AT_calling_convention attributes are only meant
17509 to describe functions' calling conventions. However, lacking a
17510 better way to signal the Fortran main program, we used this for
17511 a long time, following existing custom. Now, DWARF 4 has
17512 DW_AT_main_subprogram, which we add below, but some tools still
17513 rely on the old way, which we thus keep. */
17514 value
= DW_CC_program
;
17516 if (dwarf_version
>= 4 || !dwarf_strict
)
17517 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
17520 /* Only add the attribute if the backend requests it, and
17521 is not DW_CC_normal. */
17522 if (value
&& (value
!= DW_CC_normal
))
17523 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
17526 /* Given a tree pointer to a struct, class, union, or enum type node, return
17527 a pointer to the (string) tag name for the given type, or zero if the type
17528 was declared without a tag. */
17530 static const char *
17531 type_tag (const_tree type
)
17533 const char *name
= 0;
17535 if (TYPE_NAME (type
) != 0)
17539 /* Find the IDENTIFIER_NODE for the type name. */
17540 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
17541 && !TYPE_NAMELESS (type
))
17542 t
= TYPE_NAME (type
);
17544 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17545 a TYPE_DECL node, regardless of whether or not a `typedef' was
17547 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
17548 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
17550 /* We want to be extra verbose. Don't call dwarf_name if
17551 DECL_NAME isn't set. The default hook for decl_printable_name
17552 doesn't like that, and in this context it's correct to return
17553 0, instead of "<anonymous>" or the like. */
17554 if (DECL_NAME (TYPE_NAME (type
))
17555 && !DECL_NAMELESS (TYPE_NAME (type
)))
17556 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
17559 /* Now get the name as a string, or invent one. */
17560 if (!name
&& t
!= 0)
17561 name
= IDENTIFIER_POINTER (t
);
17564 return (name
== 0 || *name
== '\0') ? 0 : name
;
17567 /* Return the type associated with a data member, make a special check
17568 for bit field types. */
17571 member_declared_type (const_tree member
)
17573 return (DECL_BIT_FIELD_TYPE (member
)
17574 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
17577 /* Get the decl's label, as described by its RTL. This may be different
17578 from the DECL_NAME name used in the source file. */
17581 static const char *
17582 decl_start_label (tree decl
)
17585 const char *fnname
;
17587 x
= DECL_RTL (decl
);
17588 gcc_assert (MEM_P (x
));
17591 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
17593 fnname
= XSTR (x
, 0);
17598 /* For variable-length arrays that have been previously generated, but
17599 may be incomplete due to missing subscript info, fill the subscript
17600 info. Return TRUE if this is one of those cases. */
17602 fill_variable_array_bounds (tree type
)
17604 if (TREE_ASM_WRITTEN (type
)
17605 && TREE_CODE (type
) == ARRAY_TYPE
17606 && variably_modified_type_p (type
, NULL
))
17608 dw_die_ref array_die
= lookup_type_die (type
);
17611 add_subscript_info (array_die
, type
, !is_ada ());
17617 /* These routines generate the internal representation of the DIE's for
17618 the compilation unit. Debugging information is collected by walking
17619 the declaration trees passed in from dwarf2out_decl(). */
17622 gen_array_type_die (tree type
, dw_die_ref context_die
)
17624 dw_die_ref array_die
;
17626 /* GNU compilers represent multidimensional array types as sequences of one
17627 dimensional array types whose element types are themselves array types.
17628 We sometimes squish that down to a single array_type DIE with multiple
17629 subscripts in the Dwarf debugging info. The draft Dwarf specification
17630 say that we are allowed to do this kind of compression in C, because
17631 there is no difference between an array of arrays and a multidimensional
17632 array. We don't do this for Ada to remain as close as possible to the
17633 actual representation, which is especially important against the language
17634 flexibilty wrt arrays of variable size. */
17636 bool collapse_nested_arrays
= !is_ada ();
17638 if (fill_variable_array_bounds (type
))
17641 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17644 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17645 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17646 if (TYPE_STRING_FLAG (type
)
17647 && TREE_CODE (type
) == ARRAY_TYPE
17649 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
17651 HOST_WIDE_INT size
;
17653 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
17654 add_name_attribute (array_die
, type_tag (type
));
17655 equate_type_number_to_die (type
, array_die
);
17656 size
= int_size_in_bytes (type
);
17658 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17659 else if (TYPE_DOMAIN (type
) != NULL_TREE
17660 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
17661 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
17663 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
17664 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2, NULL
);
17666 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
17667 if (loc
&& size
> 0)
17669 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
17670 if (size
!= DWARF2_ADDR_SIZE
)
17671 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17677 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17678 add_name_attribute (array_die
, type_tag (type
));
17679 equate_type_number_to_die (type
, array_die
);
17681 if (TREE_CODE (type
) == VECTOR_TYPE
)
17682 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
17684 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17686 && TREE_CODE (type
) == ARRAY_TYPE
17687 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17688 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17689 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17692 /* We default the array ordering. SDB will probably do
17693 the right things even if DW_AT_ordering is not present. It's not even
17694 an issue until we start to get into multidimensional arrays anyway. If
17695 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17696 then we'll have to put the DW_AT_ordering attribute back in. (But if
17697 and when we find out that we need to put these in, we will only do so
17698 for multidimensional arrays. */
17699 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17702 if (TREE_CODE (type
) == VECTOR_TYPE
)
17704 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17705 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17706 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
17707 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17708 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
17711 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17713 /* Add representation of the type of the elements of this array type and
17714 emit the corresponding DIE if we haven't done it already. */
17715 element_type
= TREE_TYPE (type
);
17716 if (collapse_nested_arrays
)
17717 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17719 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17721 element_type
= TREE_TYPE (element_type
);
17724 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
, context_die
);
17726 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17727 if (TYPE_ARTIFICIAL (type
))
17728 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17730 if (get_AT (array_die
, DW_AT_name
))
17731 add_pubtype (type
, array_die
);
17734 /* This routine generates DIE for array with hidden descriptor, details
17735 are filled into *info by a langhook. */
17738 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17739 dw_die_ref context_die
)
17741 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17742 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17743 const struct loc_descr_context context
= { type
, info
->base_decl
};
17746 add_name_attribute (array_die
, type_tag (type
));
17747 equate_type_number_to_die (type
, array_die
);
17749 if (info
->ndimensions
> 1)
17750 switch (info
->ordering
)
17752 case array_descr_ordering_row_major
:
17753 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17755 case array_descr_ordering_column_major
:
17756 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17762 if (dwarf_version
>= 3 || !dwarf_strict
)
17764 if (info
->data_location
)
17765 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
17766 dw_scalar_form_exprloc
, &context
);
17767 if (info
->associated
)
17768 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
17769 dw_scalar_form_constant
17770 | dw_scalar_form_exprloc
17771 | dw_scalar_form_reference
, &context
);
17772 if (info
->allocated
)
17773 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
17774 dw_scalar_form_constant
17775 | dw_scalar_form_exprloc
17776 | dw_scalar_form_reference
, &context
);
17779 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17781 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17783 dw_die_ref subrange_die
17784 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17786 if (info
->dimen
[dim
].bounds_type
)
17787 add_type_attribute (subrange_die
,
17788 info
->dimen
[dim
].bounds_type
, 0,
17790 if (info
->dimen
[dim
].lower_bound
)
17791 add_bound_info (subrange_die
, DW_AT_lower_bound
,
17792 info
->dimen
[dim
].lower_bound
, &context
);
17793 if (info
->dimen
[dim
].upper_bound
)
17794 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17795 info
->dimen
[dim
].upper_bound
, &context
);
17796 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
17797 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
17798 info
->dimen
[dim
].stride
,
17799 dw_scalar_form_constant
17800 | dw_scalar_form_exprloc
17801 | dw_scalar_form_reference
,
17805 gen_type_die (info
->element_type
, context_die
);
17806 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
17809 if (get_AT (array_die
, DW_AT_name
))
17810 add_pubtype (type
, array_die
);
17815 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17817 tree origin
= decl_ultimate_origin (decl
);
17818 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17820 if (origin
!= NULL
)
17821 add_abstract_origin_attribute (decl_die
, origin
);
17824 add_name_and_src_coords_attributes (decl_die
, decl
);
17825 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17826 TYPE_UNQUALIFIED
, context_die
);
17829 if (DECL_ABSTRACT_P (decl
))
17830 equate_decl_number_to_die (decl
, decl_die
);
17832 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17836 /* Walk through the list of incomplete types again, trying once more to
17837 emit full debugging info for them. */
17840 retry_incomplete_types (void)
17844 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17845 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17846 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17849 /* Determine what tag to use for a record type. */
17851 static enum dwarf_tag
17852 record_type_tag (tree type
)
17854 if (! lang_hooks
.types
.classify_record
)
17855 return DW_TAG_structure_type
;
17857 switch (lang_hooks
.types
.classify_record (type
))
17859 case RECORD_IS_STRUCT
:
17860 return DW_TAG_structure_type
;
17862 case RECORD_IS_CLASS
:
17863 return DW_TAG_class_type
;
17865 case RECORD_IS_INTERFACE
:
17866 if (dwarf_version
>= 3 || !dwarf_strict
)
17867 return DW_TAG_interface_type
;
17868 return DW_TAG_structure_type
;
17871 gcc_unreachable ();
17875 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17876 include all of the information about the enumeration values also. Each
17877 enumerated type name/value is listed as a child of the enumerated type
17881 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17883 dw_die_ref type_die
= lookup_type_die (type
);
17885 if (type_die
== NULL
)
17887 type_die
= new_die (DW_TAG_enumeration_type
,
17888 scope_die_for (type
, context_die
), type
);
17889 equate_type_number_to_die (type
, type_die
);
17890 add_name_attribute (type_die
, type_tag (type
));
17891 if (dwarf_version
>= 4 || !dwarf_strict
)
17893 if (ENUM_IS_SCOPED (type
))
17894 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17895 if (ENUM_IS_OPAQUE (type
))
17896 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17899 else if (! TYPE_SIZE (type
))
17902 remove_AT (type_die
, DW_AT_declaration
);
17904 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17905 given enum type is incomplete, do not generate the DW_AT_byte_size
17906 attribute or the DW_AT_element_list attribute. */
17907 if (TYPE_SIZE (type
))
17911 TREE_ASM_WRITTEN (type
) = 1;
17912 add_byte_size_attribute (type_die
, type
);
17913 if (dwarf_version
>= 3 || !dwarf_strict
)
17915 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
17916 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
,
17919 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17921 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17922 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17925 /* If the first reference to this type was as the return type of an
17926 inline function, then it may not have a parent. Fix this now. */
17927 if (type_die
->die_parent
== NULL
)
17928 add_child_die (scope_die_for (type
, context_die
), type_die
);
17930 for (link
= TYPE_VALUES (type
);
17931 link
!= NULL
; link
= TREE_CHAIN (link
))
17933 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17934 tree value
= TREE_VALUE (link
);
17936 add_name_attribute (enum_die
,
17937 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17939 if (TREE_CODE (value
) == CONST_DECL
)
17940 value
= DECL_INITIAL (value
);
17942 if (simple_type_size_in_bits (TREE_TYPE (value
))
17943 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
17945 /* For constant forms created by add_AT_unsigned DWARF
17946 consumers (GDB, elfutils, etc.) always zero extend
17947 the value. Only when the actual value is negative
17948 do we need to use add_AT_int to generate a constant
17949 form that can represent negative values. */
17950 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
17951 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
17952 add_AT_unsigned (enum_die
, DW_AT_const_value
,
17953 (unsigned HOST_WIDE_INT
) val
);
17955 add_AT_int (enum_die
, DW_AT_const_value
, val
);
17958 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17959 that here. TODO: This should be re-worked to use correct
17960 signed/unsigned double tags for all cases. */
17961 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
17964 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17965 if (TYPE_ARTIFICIAL (type
))
17966 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17969 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17971 add_pubtype (type
, type_die
);
17976 /* Generate a DIE to represent either a real live formal parameter decl or to
17977 represent just the type of some formal parameter position in some function
17980 Note that this routine is a bit unusual because its argument may be a
17981 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17982 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17983 node. If it's the former then this function is being called to output a
17984 DIE to represent a formal parameter object (or some inlining thereof). If
17985 it's the latter, then this function is only being called to output a
17986 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17987 argument type of some subprogram type.
17988 If EMIT_NAME_P is true, name and source coordinate attributes
17992 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17993 dw_die_ref context_die
)
17995 tree node_or_origin
= node
? node
: origin
;
17996 tree ultimate_origin
;
17997 dw_die_ref parm_die
= NULL
;
17999 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
18001 parm_die
= lookup_decl_die (node
);
18003 /* If the contexts differ, we may not be talking about the same
18005 if (parm_die
&& parm_die
->die_parent
!= context_die
)
18007 if (!DECL_ABSTRACT_P (node
))
18009 /* This can happen when creating an inlined instance, in
18010 which case we need to create a new DIE that will get
18011 annotated with DW_AT_abstract_origin. */
18016 /* FIXME: Reuse DIE even with a differing context.
18018 This can happen when calling
18019 dwarf2out_abstract_function to build debug info for
18020 the abstract instance of a function for which we have
18021 already generated a DIE in
18022 dwarf2out_early_global_decl.
18024 Once we remove dwarf2out_abstract_function, we should
18025 have a call to gcc_unreachable here. */
18029 if (parm_die
&& parm_die
->die_parent
== NULL
)
18031 /* Check that parm_die already has the right attributes that
18032 we would have added below. If any attributes are
18033 missing, fall through to add them. */
18034 if (! DECL_ABSTRACT_P (node_or_origin
)
18035 && !get_AT (parm_die
, DW_AT_location
)
18036 && !get_AT (parm_die
, DW_AT_const_value
))
18037 /* We are missing location info, and are about to add it. */
18041 add_child_die (context_die
, parm_die
);
18047 /* If we have a previously generated DIE, use it, unless this is an
18048 concrete instance (origin != NULL), in which case we need a new
18049 DIE with a corresponding DW_AT_abstract_origin. */
18051 if (parm_die
&& origin
== NULL
)
18052 reusing_die
= true;
18055 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
18056 reusing_die
= false;
18059 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
18061 case tcc_declaration
:
18062 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
18063 if (node
|| ultimate_origin
)
18064 origin
= ultimate_origin
;
18069 if (origin
!= NULL
)
18070 add_abstract_origin_attribute (parm_die
, origin
);
18071 else if (emit_name_p
)
18072 add_name_and_src_coords_attributes (parm_die
, node
);
18074 || (! DECL_ABSTRACT_P (node_or_origin
)
18075 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
18076 decl_function_context
18077 (node_or_origin
))))
18079 tree type
= TREE_TYPE (node_or_origin
);
18080 if (decl_by_reference_p (node_or_origin
))
18081 add_type_attribute (parm_die
, TREE_TYPE (type
),
18082 TYPE_UNQUALIFIED
, context_die
);
18084 add_type_attribute (parm_die
, type
,
18085 decl_quals (node_or_origin
),
18088 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
18089 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18091 if (node
&& node
!= origin
)
18092 equate_decl_number_to_die (node
, parm_die
);
18093 if (! DECL_ABSTRACT_P (node_or_origin
))
18094 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
18095 node
== NULL
, DW_AT_location
);
18100 /* We were called with some kind of a ..._TYPE node. */
18101 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
,
18106 gcc_unreachable ();
18112 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18113 children DW_TAG_formal_parameter DIEs representing the arguments of the
18116 PARM_PACK must be a function parameter pack.
18117 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18118 must point to the subsequent arguments of the function PACK_ARG belongs to.
18119 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18120 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18121 following the last one for which a DIE was generated. */
18124 gen_formal_parameter_pack_die (tree parm_pack
,
18126 dw_die_ref subr_die
,
18130 dw_die_ref parm_pack_die
;
18132 gcc_assert (parm_pack
18133 && lang_hooks
.function_parameter_pack_p (parm_pack
)
18136 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
18137 add_src_coords_attributes (parm_pack_die
, parm_pack
);
18139 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
18141 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
18144 gen_formal_parameter_die (arg
, NULL
,
18145 false /* Don't emit name attribute. */,
18150 return parm_pack_die
;
18153 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18154 at the end of an (ANSI prototyped) formal parameters list. */
18157 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
18159 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
18162 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18163 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18164 parameters as specified in some function type specification (except for
18165 those which appear as part of a function *definition*). */
18168 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
18171 tree formal_type
= NULL
;
18172 tree first_parm_type
;
18175 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
18177 arg
= DECL_ARGUMENTS (function_or_method_type
);
18178 function_or_method_type
= TREE_TYPE (function_or_method_type
);
18183 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
18185 /* Make our first pass over the list of formal parameter types and output a
18186 DW_TAG_formal_parameter DIE for each one. */
18187 for (link
= first_parm_type
; link
; )
18189 dw_die_ref parm_die
;
18191 formal_type
= TREE_VALUE (link
);
18192 if (formal_type
== void_type_node
)
18195 /* Output a (nameless) DIE to represent the formal parameter itself. */
18196 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
18198 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
18199 true /* Emit name attribute. */,
18201 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
18202 && link
== first_parm_type
)
18204 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18205 if (dwarf_version
>= 3 || !dwarf_strict
)
18206 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
18208 else if (arg
&& DECL_ARTIFICIAL (arg
))
18209 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18212 link
= TREE_CHAIN (link
);
18214 arg
= DECL_CHAIN (arg
);
18217 /* If this function type has an ellipsis, add a
18218 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18219 if (formal_type
!= void_type_node
)
18220 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
18222 /* Make our second (and final) pass over the list of formal parameter types
18223 and output DIEs to represent those types (as necessary). */
18224 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
18225 link
&& TREE_VALUE (link
);
18226 link
= TREE_CHAIN (link
))
18227 gen_type_die (TREE_VALUE (link
), context_die
);
18230 /* We want to generate the DIE for TYPE so that we can generate the
18231 die for MEMBER, which has been defined; we will need to refer back
18232 to the member declaration nested within TYPE. If we're trying to
18233 generate minimal debug info for TYPE, processing TYPE won't do the
18234 trick; we need to attach the member declaration by hand. */
18237 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
18239 gen_type_die (type
, context_die
);
18241 /* If we're trying to avoid duplicate debug info, we may not have
18242 emitted the member decl for this function. Emit it now. */
18243 if (TYPE_STUB_DECL (type
)
18244 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
18245 && ! lookup_decl_die (member
))
18247 dw_die_ref type_die
;
18248 gcc_assert (!decl_ultimate_origin (member
));
18250 push_decl_scope (type
);
18251 type_die
= lookup_type_die_strip_naming_typedef (type
);
18252 if (TREE_CODE (member
) == FUNCTION_DECL
)
18253 gen_subprogram_die (member
, type_die
);
18254 else if (TREE_CODE (member
) == FIELD_DECL
)
18256 /* Ignore the nameless fields that are used to skip bits but handle
18257 C++ anonymous unions and structs. */
18258 if (DECL_NAME (member
) != NULL_TREE
18259 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
18260 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
18262 gen_type_die (member_declared_type (member
), type_die
);
18263 gen_field_die (member
, type_die
);
18267 gen_variable_die (member
, NULL_TREE
, type_die
);
18273 /* Forward declare these functions, because they are mutually recursive
18274 with their set_block_* pairing functions. */
18275 static void set_decl_origin_self (tree
);
18276 static void set_decl_abstract_flags (tree
, vec
<tree
> &);
18278 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
18279 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
18280 that it points to the node itself, thus indicating that the node is its
18281 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
18282 the given node is NULL, recursively descend the decl/block tree which
18283 it is the root of, and for each other ..._DECL or BLOCK node contained
18284 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
18285 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
18286 values to point to themselves. */
18289 set_block_origin_self (tree stmt
)
18291 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
18293 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
18298 for (local_decl
= BLOCK_VARS (stmt
);
18299 local_decl
!= NULL_TREE
;
18300 local_decl
= DECL_CHAIN (local_decl
))
18301 /* Do not recurse on nested functions since the inlining status
18302 of parent and child can be different as per the DWARF spec. */
18303 if (TREE_CODE (local_decl
) != FUNCTION_DECL
18304 && !DECL_EXTERNAL (local_decl
))
18305 set_decl_origin_self (local_decl
);
18311 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
18312 subblock
!= NULL_TREE
;
18313 subblock
= BLOCK_CHAIN (subblock
))
18314 set_block_origin_self (subblock
); /* Recurse. */
18319 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
18320 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
18321 node to so that it points to the node itself, thus indicating that the
18322 node represents its own (abstract) origin. Additionally, if the
18323 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
18324 the decl/block tree of which the given node is the root of, and for
18325 each other ..._DECL or BLOCK node contained therein whose
18326 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
18327 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
18328 point to themselves. */
18331 set_decl_origin_self (tree decl
)
18333 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
18335 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
18336 if (TREE_CODE (decl
) == FUNCTION_DECL
)
18340 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
18341 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
18342 if (DECL_INITIAL (decl
) != NULL_TREE
18343 && DECL_INITIAL (decl
) != error_mark_node
)
18344 set_block_origin_self (DECL_INITIAL (decl
));
18349 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
18350 and if it wasn't 1 before, push it to abstract_vec vector.
18351 For all local decls and all local sub-blocks (recursively) do it
18355 set_block_abstract_flags (tree stmt
, vec
<tree
> &abstract_vec
)
18361 if (!BLOCK_ABSTRACT (stmt
))
18363 abstract_vec
.safe_push (stmt
);
18364 BLOCK_ABSTRACT (stmt
) = 1;
18367 for (local_decl
= BLOCK_VARS (stmt
);
18368 local_decl
!= NULL_TREE
;
18369 local_decl
= DECL_CHAIN (local_decl
))
18370 if (! DECL_EXTERNAL (local_decl
))
18371 set_decl_abstract_flags (local_decl
, abstract_vec
);
18373 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
18375 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
18376 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
18377 || TREE_CODE (local_decl
) == PARM_DECL
)
18378 set_decl_abstract_flags (local_decl
, abstract_vec
);
18381 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
18382 subblock
!= NULL_TREE
;
18383 subblock
= BLOCK_CHAIN (subblock
))
18384 set_block_abstract_flags (subblock
, abstract_vec
);
18387 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
18388 to 1 and if it wasn't 1 before, push to abstract_vec vector.
18389 In the case where the decl is a FUNCTION_DECL also set the abstract
18390 flags for all of the parameters, local vars, local
18391 blocks and sub-blocks (recursively). */
18394 set_decl_abstract_flags (tree decl
, vec
<tree
> &abstract_vec
)
18396 if (!DECL_ABSTRACT_P (decl
))
18398 abstract_vec
.safe_push (decl
);
18399 DECL_ABSTRACT_P (decl
) = 1;
18402 if (TREE_CODE (decl
) == FUNCTION_DECL
)
18406 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
18407 if (!DECL_ABSTRACT_P (arg
))
18409 abstract_vec
.safe_push (arg
);
18410 DECL_ABSTRACT_P (arg
) = 1;
18412 if (DECL_INITIAL (decl
) != NULL_TREE
18413 && DECL_INITIAL (decl
) != error_mark_node
)
18414 set_block_abstract_flags (DECL_INITIAL (decl
), abstract_vec
);
18418 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18419 may later generate inlined and/or out-of-line instances of.
18421 FIXME: In the early-dwarf world, this function, and most of the
18422 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
18423 the abstract instance. All we would need to do is annotate
18424 the early DIE with the appropriate DW_AT_inline in late
18425 dwarf (perhaps in gen_inlined_subroutine_die).
18427 However, we can't do this yet, because LTO streaming of DIEs
18428 has not been implemented yet. */
18431 dwarf2out_abstract_function (tree decl
)
18433 dw_die_ref old_die
;
18436 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
18437 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
18438 int old_call_site_count
, old_tail_call_site_count
;
18439 struct call_arg_loc_node
*old_call_arg_locations
;
18441 /* Make sure we have the actual abstract inline, not a clone. */
18442 decl
= DECL_ORIGIN (decl
);
18444 old_die
= lookup_decl_die (decl
);
18445 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
18446 /* We've already generated the abstract instance. */
18449 /* We can be called while recursively when seeing block defining inlined subroutine
18450 DIE. Be sure to not clobber the outer location table nor use it or we would
18451 get locations in abstract instantces. */
18452 old_decl_loc_table
= decl_loc_table
;
18453 decl_loc_table
= NULL
;
18454 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
18455 cached_dw_loc_list_table
= NULL
;
18456 old_call_arg_locations
= call_arg_locations
;
18457 call_arg_locations
= NULL
;
18458 old_call_site_count
= call_site_count
;
18459 call_site_count
= -1;
18460 old_tail_call_site_count
= tail_call_site_count
;
18461 tail_call_site_count
= -1;
18463 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18464 we don't get confused by DECL_ABSTRACT_P. */
18465 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18467 context
= decl_class_context (decl
);
18469 gen_type_die_for_member
18470 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
18473 /* Pretend we've just finished compiling this function. */
18474 save_fn
= current_function_decl
;
18475 current_function_decl
= decl
;
18477 auto_vec
<tree
, 64> abstract_vec
;
18478 set_decl_abstract_flags (decl
, abstract_vec
);
18479 dwarf2out_decl (decl
);
18482 FOR_EACH_VEC_ELT (abstract_vec
, i
, t
)
18483 if (TREE_CODE (t
) == BLOCK
)
18484 BLOCK_ABSTRACT (t
) = 0;
18486 DECL_ABSTRACT_P (t
) = 0;
18488 current_function_decl
= save_fn
;
18489 decl_loc_table
= old_decl_loc_table
;
18490 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
18491 call_arg_locations
= old_call_arg_locations
;
18492 call_site_count
= old_call_site_count
;
18493 tail_call_site_count
= old_tail_call_site_count
;
18496 /* Helper function of premark_used_types() which gets called through
18499 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18500 marked as unused by prune_unused_types. */
18503 premark_used_types_helper (tree
const &type
, void *)
18507 die
= lookup_type_die (type
);
18509 die
->die_perennial_p
= 1;
18513 /* Helper function of premark_types_used_by_global_vars which gets called
18514 through htab_traverse.
18516 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18517 marked as unused by prune_unused_types. The DIE of the type is marked
18518 only if the global variable using the type will actually be emitted. */
18521 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
18524 struct types_used_by_vars_entry
*entry
;
18527 entry
= (struct types_used_by_vars_entry
*) *slot
;
18528 gcc_assert (entry
->type
!= NULL
18529 && entry
->var_decl
!= NULL
);
18530 die
= lookup_type_die (entry
->type
);
18533 /* Ask cgraph if the global variable really is to be emitted.
18534 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18535 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
18536 if (node
&& node
->definition
)
18538 die
->die_perennial_p
= 1;
18539 /* Keep the parent DIEs as well. */
18540 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18541 die
->die_perennial_p
= 1;
18547 /* Mark all members of used_types_hash as perennial. */
18550 premark_used_types (struct function
*fun
)
18552 if (fun
&& fun
->used_types_hash
)
18553 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
18556 /* Mark all members of types_used_by_vars_entry as perennial. */
18559 premark_types_used_by_global_vars (void)
18561 if (types_used_by_vars_hash
)
18562 types_used_by_vars_hash
18563 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
18566 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18567 for CA_LOC call arg loc node. */
18570 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
18571 struct call_arg_loc_node
*ca_loc
)
18573 dw_die_ref stmt_die
= NULL
, die
;
18574 tree block
= ca_loc
->block
;
18577 && block
!= DECL_INITIAL (decl
)
18578 && TREE_CODE (block
) == BLOCK
)
18580 stmt_die
= BLOCK_DIE (block
);
18583 block
= BLOCK_SUPERCONTEXT (block
);
18585 if (stmt_die
== NULL
)
18586 stmt_die
= subr_die
;
18587 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
18588 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
18589 if (ca_loc
->tail_call_p
)
18590 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
18591 if (ca_loc
->symbol_ref
)
18593 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
18595 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
18597 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
18602 /* Generate a DIE to represent a declared function (either file-scope or
18606 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
18608 tree origin
= decl_ultimate_origin (decl
);
18609 dw_die_ref subr_die
;
18610 dw_die_ref old_die
= lookup_decl_die (decl
);
18612 /* This function gets called multiple times for different stages of
18613 the debug process. For example, for func() in this code:
18617 void func() { ... }
18620 ...we get called 4 times. Twice in early debug and twice in
18626 1. Once while generating func() within the namespace. This is
18627 the declaration. The declaration bit below is set, as the
18628 context is the namespace.
18630 A new DIE will be generated with DW_AT_declaration set.
18632 2. Once for func() itself. This is the specification. The
18633 declaration bit below is clear as the context is the CU.
18635 We will use the cached DIE from (1) to create a new DIE with
18636 DW_AT_specification pointing to the declaration in (1).
18638 Late debug via rest_of_handle_final()
18639 -------------------------------------
18641 3. Once generating func() within the namespace. This is also the
18642 declaration, as in (1), but this time we will early exit below
18643 as we have a cached DIE and a declaration needs no additional
18644 annotations (no locations), as the source declaration line
18647 4. Once for func() itself. As in (2), this is the specification,
18648 but this time we will re-use the cached DIE, and just annotate
18649 it with the location information that should now be available.
18651 For something without namespaces, but with abstract instances, we
18652 are also called a multiple times:
18657 Base (); // constructor declaration (1)
18660 Base::Base () { } // constructor specification (2)
18665 1. Once for the Base() constructor by virtue of it being a
18666 member of the Base class. This is done via
18667 rest_of_type_compilation.
18669 This is a declaration, so a new DIE will be created with
18672 2. Once for the Base() constructor definition, but this time
18673 while generating the abstract instance of the base
18674 constructor (__base_ctor) which is being generated via early
18675 debug of reachable functions.
18677 Even though we have a cached version of the declaration (1),
18678 we will create a DW_AT_specification of the declaration DIE
18681 3. Once for the __base_ctor itself, but this time, we generate
18682 an DW_AT_abstract_origin version of the DW_AT_specification in
18685 Late debug via rest_of_handle_final
18686 -----------------------------------
18688 4. One final time for the __base_ctor (which will have a cached
18689 DIE with DW_AT_abstract_origin created in (3). This time,
18690 we will just annotate the location information now
18693 int declaration
= (current_function_decl
!= decl
18694 || class_or_namespace_scope_p (context_die
));
18696 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
18698 /* Now that the C++ front end lazily declares artificial member fns, we
18699 might need to retrofit the declaration into its class. */
18700 if (!declaration
&& !origin
&& !old_die
18701 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
18702 && !class_or_namespace_scope_p (context_die
)
18703 && debug_info_level
> DINFO_LEVEL_TERSE
)
18704 old_die
= force_decl_die (decl
);
18706 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
18707 if (origin
!= NULL
)
18709 gcc_assert (!declaration
|| local_scope_p (context_die
));
18711 /* Fixup die_parent for the abstract instance of a nested
18712 inline function. */
18713 if (old_die
&& old_die
->die_parent
== NULL
)
18714 add_child_die (context_die
, old_die
);
18716 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
18718 /* If we have a DW_AT_abstract_origin we have a working
18720 subr_die
= old_die
;
18724 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18725 add_abstract_origin_attribute (subr_die
, origin
);
18726 /* This is where the actual code for a cloned function is.
18727 Let's emit linkage name attribute for it. This helps
18728 debuggers to e.g, set breakpoints into
18729 constructors/destructors when the user asks "break
18731 add_linkage_name (subr_die
, decl
);
18734 /* A cached copy, possibly from early dwarf generation. Reuse as
18735 much as possible. */
18738 /* A declaration that has been previously dumped needs no
18739 additional information. */
18743 if (!get_AT_flag (old_die
, DW_AT_declaration
)
18744 /* We can have a normal definition following an inline one in the
18745 case of redefinition of GNU C extern inlines.
18746 It seems reasonable to use AT_specification in this case. */
18747 && !get_AT (old_die
, DW_AT_inline
))
18749 /* Detect and ignore this case, where we are trying to output
18750 something we have already output. */
18751 if (get_AT (old_die
, DW_AT_low_pc
)
18752 || get_AT (old_die
, DW_AT_ranges
))
18755 /* If we have no location information, this must be a
18756 partially generated DIE from early dwarf generation.
18757 Fall through and generate it. */
18760 /* If the definition comes from the same place as the declaration,
18761 maybe use the old DIE. We always want the DIE for this function
18762 that has the *_pc attributes to be under comp_unit_die so the
18763 debugger can find it. We also need to do this for abstract
18764 instances of inlines, since the spec requires the out-of-line copy
18765 to have the same parent. For local class methods, this doesn't
18766 apply; we just use the old DIE. */
18767 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18768 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18769 if ((is_cu_die (old_die
->die_parent
)
18770 /* This condition fixes the inconsistency/ICE with the
18771 following Fortran test (or some derivative thereof) while
18772 building libgfortran:
18776 logical function funky (FLAG)
18781 || (old_die
->die_parent
18782 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
18783 || context_die
== NULL
)
18784 && (DECL_ARTIFICIAL (decl
)
18785 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
18786 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
18787 == (unsigned) s
.line
))))
18789 subr_die
= old_die
;
18791 /* Clear out the declaration attribute, but leave the
18792 parameters so they can be augmented with location
18793 information later. Unless this was a declaration, in
18794 which case, wipe out the nameless parameters and recreate
18795 them further down. */
18796 if (remove_AT (subr_die
, DW_AT_declaration
))
18799 remove_AT (subr_die
, DW_AT_object_pointer
);
18800 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
18803 /* Make a specification pointing to the previously built
18807 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18808 add_AT_specification (subr_die
, old_die
);
18809 add_pubname (decl
, subr_die
);
18810 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18811 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18812 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18813 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18815 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
18816 emit the real type on the definition die. */
18817 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
18819 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
18820 if (die
== auto_die
|| die
== decltype_auto_die
)
18821 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18822 TYPE_UNQUALIFIED
, context_die
);
18826 /* Create a fresh DIE for anything else. */
18829 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18831 if (TREE_PUBLIC (decl
))
18832 add_AT_flag (subr_die
, DW_AT_external
, 1);
18834 add_name_and_src_coords_attributes (subr_die
, decl
);
18835 add_pubname (decl
, subr_die
);
18836 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18838 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18839 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18840 TYPE_UNQUALIFIED
, context_die
);
18843 add_pure_or_virtual_attribute (subr_die
, decl
);
18844 if (DECL_ARTIFICIAL (decl
))
18845 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18847 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
18848 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
18850 add_accessibility_attribute (subr_die
, decl
);
18853 /* Unless we have an existing non-declaration DIE, equate the new
18855 if (!old_die
|| is_declaration_die (old_die
))
18856 equate_decl_number_to_die (decl
, subr_die
);
18860 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18862 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18864 /* If this is an explicit function declaration then generate
18865 a DW_AT_explicit attribute. */
18866 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18867 && (dwarf_version
>= 3 || !dwarf_strict
))
18868 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18870 /* If this is a C++11 deleted special function member then generate
18871 a DW_AT_GNU_deleted attribute. */
18872 if (lang_hooks
.decls
.function_decl_deleted_p (decl
)
18873 && (! dwarf_strict
))
18874 add_AT_flag (subr_die
, DW_AT_GNU_deleted
, 1);
18877 /* Tag abstract instances with DW_AT_inline. */
18878 else if (DECL_ABSTRACT_P (decl
))
18880 if (DECL_DECLARED_INLINE_P (decl
))
18882 if (cgraph_function_possibly_inlined_p (decl
))
18883 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18885 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18889 if (cgraph_function_possibly_inlined_p (decl
))
18890 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18892 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18895 if (DECL_DECLARED_INLINE_P (decl
)
18896 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18897 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18899 /* For non DECL_EXTERNALs, if range information is available, fill
18900 the DIE with it. */
18901 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
18903 HOST_WIDE_INT cfa_fb_offset
;
18905 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18907 if (!flag_reorder_blocks_and_partition
)
18909 dw_fde_ref fde
= fun
->fde
;
18910 if (fde
->dw_fde_begin
)
18912 /* We have already generated the labels. */
18913 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18914 fde
->dw_fde_end
, false);
18918 /* Create start/end labels and add the range. */
18919 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18920 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18921 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18922 current_function_funcdef_no
);
18923 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18924 current_function_funcdef_no
);
18925 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18929 #if VMS_DEBUGGING_INFO
18930 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18931 Section 2.3 Prologue and Epilogue Attributes:
18932 When a breakpoint is set on entry to a function, it is generally
18933 desirable for execution to be suspended, not on the very first
18934 instruction of the function, but rather at a point after the
18935 function's frame has been set up, after any language defined local
18936 declaration processing has been completed, and before execution of
18937 the first statement of the function begins. Debuggers generally
18938 cannot properly determine where this point is. Similarly for a
18939 breakpoint set on exit from a function. The prologue and epilogue
18940 attributes allow a compiler to communicate the location(s) to use. */
18943 if (fde
->dw_fde_vms_end_prologue
)
18944 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18945 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18947 if (fde
->dw_fde_vms_begin_epilogue
)
18948 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18949 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18956 /* Generate pubnames entries for the split function code ranges. */
18957 dw_fde_ref fde
= fun
->fde
;
18959 if (fde
->dw_fde_second_begin
)
18961 if (dwarf_version
>= 3 || !dwarf_strict
)
18963 /* We should use ranges for non-contiguous code section
18964 addresses. Use the actual code range for the initial
18965 section, since the HOT/COLD labels might precede an
18966 alignment offset. */
18967 bool range_list_added
= false;
18968 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18969 fde
->dw_fde_end
, &range_list_added
,
18971 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18972 fde
->dw_fde_second_end
,
18973 &range_list_added
, false);
18974 if (range_list_added
)
18979 /* There is no real support in DW2 for this .. so we make
18980 a work-around. First, emit the pub name for the segment
18981 containing the function label. Then make and emit a
18982 simplified subprogram DIE for the second segment with the
18983 name pre-fixed by __hot/cold_sect_of_. We use the same
18984 linkage name for the second die so that gdb will find both
18985 sections when given "b foo". */
18986 const char *name
= NULL
;
18987 tree decl_name
= DECL_NAME (decl
);
18988 dw_die_ref seg_die
;
18990 /* Do the 'primary' section. */
18991 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18992 fde
->dw_fde_end
, false);
18994 /* Build a minimal DIE for the secondary section. */
18995 seg_die
= new_die (DW_TAG_subprogram
,
18996 subr_die
->die_parent
, decl
);
18998 if (TREE_PUBLIC (decl
))
18999 add_AT_flag (seg_die
, DW_AT_external
, 1);
19001 if (decl_name
!= NULL
19002 && IDENTIFIER_POINTER (decl_name
) != NULL
)
19004 name
= dwarf2_name (decl
, 1);
19005 if (! DECL_ARTIFICIAL (decl
))
19006 add_src_coords_attributes (seg_die
, decl
);
19008 add_linkage_name (seg_die
, decl
);
19010 gcc_assert (name
!= NULL
);
19011 add_pure_or_virtual_attribute (seg_die
, decl
);
19012 if (DECL_ARTIFICIAL (decl
))
19013 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
19015 name
= concat ("__second_sect_of_", name
, NULL
);
19016 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
19017 fde
->dw_fde_second_end
, false);
19018 add_name_attribute (seg_die
, name
);
19019 if (want_pubnames ())
19020 add_pubname_string (name
, seg_die
);
19024 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
19028 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
19030 /* We define the "frame base" as the function's CFA. This is more
19031 convenient for several reasons: (1) It's stable across the prologue
19032 and epilogue, which makes it better than just a frame pointer,
19033 (2) With dwarf3, there exists a one-byte encoding that allows us
19034 to reference the .debug_frame data by proxy, but failing that,
19035 (3) We can at least reuse the code inspection and interpretation
19036 code that determines the CFA position at various points in the
19038 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
19040 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
19041 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
19045 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
19046 if (list
->dw_loc_next
)
19047 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
19049 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
19052 /* Compute a displacement from the "steady-state frame pointer" to
19053 the CFA. The former is what all stack slots and argument slots
19054 will reference in the rtl; the latter is what we've told the
19055 debugger about. We'll need to adjust all frame_base references
19056 by this displacement. */
19057 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
19059 if (fun
->static_chain_decl
)
19060 add_AT_location_description
19061 (subr_die
, DW_AT_static_link
,
19062 loc_list_from_tree (fun
->static_chain_decl
, 2, NULL
));
19065 /* Generate child dies for template paramaters. */
19066 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19067 gen_generic_params_dies (decl
);
19069 /* Now output descriptions of the arguments for this function. This gets
19070 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19071 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19072 `...' at the end of the formal parameter list. In order to find out if
19073 there was a trailing ellipsis or not, we must instead look at the type
19074 associated with the FUNCTION_DECL. This will be a node of type
19075 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19076 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19077 an ellipsis at the end. */
19079 /* In the case where we are describing a mere function declaration, all we
19080 need to do here (and all we *can* do here) is to describe the *types* of
19081 its formal parameters. */
19082 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19084 else if (declaration
)
19085 gen_formal_types_die (decl
, subr_die
);
19088 /* Generate DIEs to represent all known formal parameters. */
19089 tree parm
= DECL_ARGUMENTS (decl
);
19090 tree generic_decl
= early_dwarf
19091 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
19092 tree generic_decl_parm
= generic_decl
19093 ? DECL_ARGUMENTS (generic_decl
)
19096 /* Now we want to walk the list of parameters of the function and
19097 emit their relevant DIEs.
19099 We consider the case of DECL being an instance of a generic function
19100 as well as it being a normal function.
19102 If DECL is an instance of a generic function we walk the
19103 parameters of the generic function declaration _and_ the parameters of
19104 DECL itself. This is useful because we want to emit specific DIEs for
19105 function parameter packs and those are declared as part of the
19106 generic function declaration. In that particular case,
19107 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19108 That DIE has children DIEs representing the set of arguments
19109 of the pack. Note that the set of pack arguments can be empty.
19110 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19113 Otherwise, we just consider the parameters of DECL. */
19114 while (generic_decl_parm
|| parm
)
19116 if (generic_decl_parm
19117 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
19118 gen_formal_parameter_pack_die (generic_decl_parm
,
19121 else if (parm
&& !POINTER_BOUNDS_P (parm
))
19123 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
19125 if (parm
== DECL_ARGUMENTS (decl
)
19126 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
19128 && (dwarf_version
>= 3 || !dwarf_strict
))
19129 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
19131 parm
= DECL_CHAIN (parm
);
19134 parm
= DECL_CHAIN (parm
);
19136 if (generic_decl_parm
)
19137 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
19140 /* Decide whether we need an unspecified_parameters DIE at the end.
19141 There are 2 more cases to do this for: 1) the ansi ... declaration -
19142 this is detectable when the end of the arg list is not a
19143 void_type_node 2) an unprototyped function declaration (not a
19144 definition). This just means that we have no info about the
19145 parameters at all. */
19146 if (prototype_p (TREE_TYPE (decl
)))
19148 /* This is the prototyped case, check for.... */
19149 if (stdarg_p (TREE_TYPE (decl
)))
19150 gen_unspecified_parameters_die (decl
, subr_die
);
19152 else if (DECL_INITIAL (decl
) == NULL_TREE
)
19153 gen_unspecified_parameters_die (decl
, subr_die
);
19156 if (subr_die
!= old_die
)
19157 /* Add the calling convention attribute if requested. */
19158 add_calling_convention_attribute (subr_die
, decl
);
19160 /* Output Dwarf info for all of the stuff within the body of the function
19161 (if it has one - it may be just a declaration).
19163 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19164 a function. This BLOCK actually represents the outermost binding contour
19165 for the function, i.e. the contour in which the function's formal
19166 parameters and labels get declared. Curiously, it appears that the front
19167 end doesn't actually put the PARM_DECL nodes for the current function onto
19168 the BLOCK_VARS list for this outer scope, but are strung off of the
19169 DECL_ARGUMENTS list for the function instead.
19171 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19172 the LABEL_DECL nodes for the function however, and we output DWARF info
19173 for those in decls_for_scope. Just within the `outer_scope' there will be
19174 a BLOCK node representing the function's outermost pair of curly braces,
19175 and any blocks used for the base and member initializers of a C++
19176 constructor function. */
19177 tree outer_scope
= DECL_INITIAL (decl
);
19178 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
19180 int call_site_note_count
= 0;
19181 int tail_call_site_note_count
= 0;
19183 /* Emit a DW_TAG_variable DIE for a named return value. */
19184 if (DECL_NAME (DECL_RESULT (decl
)))
19185 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
19187 /* The first time through decls_for_scope we will generate the
19188 DIEs for the locals. The second time, we fill in the
19190 decls_for_scope (outer_scope
, subr_die
);
19192 if (call_arg_locations
&& !dwarf_strict
)
19194 struct call_arg_loc_node
*ca_loc
;
19195 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
19197 dw_die_ref die
= NULL
;
19198 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
19201 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
19202 arg
; arg
= next_arg
)
19204 dw_loc_descr_ref reg
, val
;
19205 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
19206 dw_die_ref cdie
, tdie
= NULL
;
19208 next_arg
= XEXP (arg
, 1);
19209 if (REG_P (XEXP (XEXP (arg
, 0), 0))
19211 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
19212 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
19213 && REGNO (XEXP (XEXP (arg
, 0), 0))
19214 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
19215 next_arg
= XEXP (next_arg
, 1);
19216 if (mode
== VOIDmode
)
19218 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
19219 if (mode
== VOIDmode
)
19220 mode
= GET_MODE (XEXP (arg
, 0));
19222 if (mode
== VOIDmode
|| mode
== BLKmode
)
19224 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
19226 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19227 tloc
= XEXP (XEXP (arg
, 0), 1);
19230 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
19231 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
19233 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19234 tlocc
= XEXP (XEXP (arg
, 0), 1);
19238 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
19239 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
19240 VAR_INIT_STATUS_INITIALIZED
);
19241 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
19243 rtx mem
= XEXP (XEXP (arg
, 0), 0);
19244 reg
= mem_loc_descriptor (XEXP (mem
, 0),
19245 get_address_mode (mem
),
19247 VAR_INIT_STATUS_INITIALIZED
);
19249 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
19250 == DEBUG_PARAMETER_REF
)
19253 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
19254 tdie
= lookup_decl_die (tdecl
);
19261 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
19262 != DEBUG_PARAMETER_REF
)
19264 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
19266 VAR_INIT_STATUS_INITIALIZED
);
19270 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19271 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
19274 add_AT_loc (cdie
, DW_AT_location
, reg
);
19275 else if (tdie
!= NULL
)
19276 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
19277 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
19278 if (next_arg
!= XEXP (arg
, 1))
19280 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
19281 if (mode
== VOIDmode
)
19282 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
19283 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
19286 VAR_INIT_STATUS_INITIALIZED
);
19288 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
19292 && (ca_loc
->symbol_ref
|| tloc
))
19293 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19294 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
19296 dw_loc_descr_ref tval
= NULL
;
19298 if (tloc
!= NULL_RTX
)
19299 tval
= mem_loc_descriptor (tloc
,
19300 GET_MODE (tloc
) == VOIDmode
19301 ? Pmode
: GET_MODE (tloc
),
19303 VAR_INIT_STATUS_INITIALIZED
);
19305 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
19306 else if (tlocc
!= NULL_RTX
)
19308 tval
= mem_loc_descriptor (tlocc
,
19309 GET_MODE (tlocc
) == VOIDmode
19310 ? Pmode
: GET_MODE (tlocc
),
19312 VAR_INIT_STATUS_INITIALIZED
);
19314 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
19320 call_site_note_count
++;
19321 if (ca_loc
->tail_call_p
)
19322 tail_call_site_note_count
++;
19326 call_arg_locations
= NULL
;
19327 call_arg_loc_last
= NULL
;
19328 if (tail_call_site_count
>= 0
19329 && tail_call_site_count
== tail_call_site_note_count
19332 if (call_site_count
>= 0
19333 && call_site_count
== call_site_note_count
)
19334 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
19336 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
19338 call_site_count
= -1;
19339 tail_call_site_count
= -1;
19343 /* Returns a hash value for X (which really is a die_struct). */
19346 block_die_hasher::hash (die_struct
*d
)
19348 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
19351 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19352 as decl_id and die_parent of die_struct Y. */
19355 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
19357 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
19360 /* Return TRUE if DECL, which may have been previously generated as
19361 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
19362 true if decl (or its origin) is either an extern declaration or a
19363 class/namespace scoped declaration.
19365 The declare_in_namespace support causes us to get two DIEs for one
19366 variable, both of which are declarations. We want to avoid
19367 considering one to be a specification, so we must test for
19368 DECLARATION and DW_AT_declaration. */
19370 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
19372 return (old_die
&& TREE_STATIC (decl
) && !declaration
19373 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
19376 /* Return true if DECL is a local static. */
19379 local_function_static (tree decl
)
19381 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
19382 return TREE_STATIC (decl
)
19383 && DECL_CONTEXT (decl
)
19384 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
19387 /* Generate a DIE to represent a declared data object.
19388 Either DECL or ORIGIN must be non-null. */
19391 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
19393 HOST_WIDE_INT off
= 0;
19395 tree decl_or_origin
= decl
? decl
: origin
;
19396 tree ultimate_origin
;
19397 dw_die_ref var_die
;
19398 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
19399 dw_die_ref origin_die
= NULL
;
19400 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
19401 || class_or_namespace_scope_p (context_die
));
19402 bool specialization_p
= false;
19404 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19405 if (decl
|| ultimate_origin
)
19406 origin
= ultimate_origin
;
19407 com_decl
= fortran_common (decl_or_origin
, &off
);
19409 /* Symbol in common gets emitted as a child of the common block, in the form
19410 of a data member. */
19413 dw_die_ref com_die
;
19414 dw_loc_list_ref loc
;
19415 die_node com_die_arg
;
19417 var_die
= lookup_decl_die (decl_or_origin
);
19420 if (get_AT (var_die
, DW_AT_location
) == NULL
)
19422 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
19427 /* Optimize the common case. */
19428 if (single_element_loc_list_p (loc
)
19429 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19430 && loc
->expr
->dw_loc_next
== NULL
19431 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
19434 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
19435 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19436 = plus_constant (GET_MODE (x
), x
, off
);
19439 loc_list_plus_const (loc
, off
);
19441 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19442 remove_AT (var_die
, DW_AT_declaration
);
19448 if (common_block_die_table
== NULL
)
19449 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
19451 com_die_arg
.decl_id
= DECL_UID (com_decl
);
19452 com_die_arg
.die_parent
= context_die
;
19453 com_die
= common_block_die_table
->find (&com_die_arg
);
19454 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19455 if (com_die
== NULL
)
19458 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
19461 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
19462 add_name_and_src_coords_attributes (com_die
, com_decl
);
19465 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19466 /* Avoid sharing the same loc descriptor between
19467 DW_TAG_common_block and DW_TAG_variable. */
19468 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19470 else if (DECL_EXTERNAL (decl
))
19471 add_AT_flag (com_die
, DW_AT_declaration
, 1);
19472 if (want_pubnames ())
19473 add_pubname_string (cnam
, com_die
); /* ??? needed? */
19474 com_die
->decl_id
= DECL_UID (com_decl
);
19475 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
19478 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
19480 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19481 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19482 remove_AT (com_die
, DW_AT_declaration
);
19484 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
19485 add_name_and_src_coords_attributes (var_die
, decl
);
19486 add_type_attribute (var_die
, TREE_TYPE (decl
), decl_quals (decl
),
19488 add_AT_flag (var_die
, DW_AT_external
, 1);
19493 /* Optimize the common case. */
19494 if (single_element_loc_list_p (loc
)
19495 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19496 && loc
->expr
->dw_loc_next
== NULL
19497 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
19499 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
19500 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19501 = plus_constant (GET_MODE (x
), x
, off
);
19504 loc_list_plus_const (loc
, off
);
19506 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19508 else if (DECL_EXTERNAL (decl
))
19509 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19510 equate_decl_number_to_die (decl
, var_die
);
19518 /* A declaration that has been previously dumped, needs no
19519 further annotations, since it doesn't need location on
19520 the second pass. */
19523 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
19524 && !get_AT (old_die
, DW_AT_specification
))
19526 /* Fall-thru so we can make a new variable die along with a
19527 DW_AT_specification. */
19529 else if (origin
&& old_die
->die_parent
!= context_die
)
19531 /* If we will be creating an inlined instance, we need a
19532 new DIE that will get annotated with
19533 DW_AT_abstract_origin. Clear things so we can get a
19535 gcc_assert (!DECL_ABSTRACT_P (decl
));
19540 /* If a DIE was dumped early, it still needs location info.
19541 Skip to where we fill the location bits. */
19543 goto gen_variable_die_location
;
19547 /* For static data members, the declaration in the class is supposed
19548 to have DW_TAG_member tag; the specification should still be
19549 DW_TAG_variable referencing the DW_TAG_member DIE. */
19550 if (declaration
&& class_scope_p (context_die
))
19551 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
19553 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
19555 if (origin
!= NULL
)
19556 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
19558 /* Loop unrolling can create multiple blocks that refer to the same
19559 static variable, so we must test for the DW_AT_declaration flag.
19561 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19562 copy decls and set the DECL_ABSTRACT_P flag on them instead of
19565 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
19566 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
19568 /* This is a definition of a C++ class level static. */
19569 add_AT_specification (var_die
, old_die
);
19570 specialization_p
= true;
19571 if (DECL_NAME (decl
))
19573 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
19574 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
19576 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
19577 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
19579 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
19580 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
19582 if (old_die
->die_tag
== DW_TAG_member
)
19583 add_linkage_name (var_die
, decl
);
19587 add_name_and_src_coords_attributes (var_die
, decl
);
19589 if ((origin
== NULL
&& !specialization_p
)
19591 && !DECL_ABSTRACT_P (decl_or_origin
)
19592 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
19593 decl_function_context
19594 (decl_or_origin
))))
19596 tree type
= TREE_TYPE (decl_or_origin
);
19598 if (decl_by_reference_p (decl_or_origin
))
19599 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19602 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
19606 if (origin
== NULL
&& !specialization_p
)
19608 if (TREE_PUBLIC (decl
))
19609 add_AT_flag (var_die
, DW_AT_external
, 1);
19611 if (DECL_ARTIFICIAL (decl
))
19612 add_AT_flag (var_die
, DW_AT_artificial
, 1);
19614 add_accessibility_attribute (var_die
, decl
);
19618 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19620 if (decl
&& (DECL_ABSTRACT_P (decl
)
19621 || !old_die
|| is_declaration_die (old_die
)))
19622 equate_decl_number_to_die (decl
, var_die
);
19624 gen_variable_die_location
:
19626 && (! DECL_ABSTRACT_P (decl_or_origin
)
19627 /* Local static vars are shared between all clones/inlines,
19628 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19630 || (TREE_CODE (decl_or_origin
) == VAR_DECL
19631 && TREE_STATIC (decl_or_origin
)
19632 && DECL_RTL_SET_P (decl_or_origin
)))
19633 /* When abstract origin already has DW_AT_location attribute, no need
19634 to add it again. */
19635 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
19638 add_pubname (decl_or_origin
, var_die
);
19640 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
19641 decl
== NULL
, DW_AT_location
);
19644 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
19647 /* Generate a DIE to represent a named constant. */
19650 gen_const_die (tree decl
, dw_die_ref context_die
)
19652 dw_die_ref const_die
;
19653 tree type
= TREE_TYPE (decl
);
19655 const_die
= lookup_decl_die (decl
);
19659 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
19660 equate_decl_number_to_die (decl
, const_die
);
19661 add_name_and_src_coords_attributes (const_die
, decl
);
19662 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, context_die
);
19663 if (TREE_PUBLIC (decl
))
19664 add_AT_flag (const_die
, DW_AT_external
, 1);
19665 if (DECL_ARTIFICIAL (decl
))
19666 add_AT_flag (const_die
, DW_AT_artificial
, 1);
19667 tree_add_const_value_attribute_for_decl (const_die
, decl
);
19670 /* Generate a DIE to represent a label identifier. */
19673 gen_label_die (tree decl
, dw_die_ref context_die
)
19675 tree origin
= decl_ultimate_origin (decl
);
19676 dw_die_ref lbl_die
= lookup_decl_die (decl
);
19678 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19682 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
19683 equate_decl_number_to_die (decl
, lbl_die
);
19685 if (origin
!= NULL
)
19686 add_abstract_origin_attribute (lbl_die
, origin
);
19688 add_name_and_src_coords_attributes (lbl_die
, decl
);
19691 if (DECL_ABSTRACT_P (decl
))
19692 equate_decl_number_to_die (decl
, lbl_die
);
19695 insn
= DECL_RTL_IF_SET (decl
);
19697 /* Deleted labels are programmer specified labels which have been
19698 eliminated because of various optimizations. We still emit them
19699 here so that it is possible to put breakpoints on them. */
19703 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
19705 /* When optimization is enabled (via -O) some parts of the compiler
19706 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19707 represent source-level labels which were explicitly declared by
19708 the user. This really shouldn't be happening though, so catch
19709 it if it ever does happen. */
19710 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
19712 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19713 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19717 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
19718 && CODE_LABEL_NUMBER (insn
) != -1)
19720 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
19721 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19726 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19727 attributes to the DIE for a block STMT, to describe where the inlined
19728 function was called from. This is similar to add_src_coords_attributes. */
19731 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19733 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19735 if (dwarf_version
>= 3 || !dwarf_strict
)
19737 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19738 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19743 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19744 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19747 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19749 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19751 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19752 && (dwarf_version
>= 3 || !dwarf_strict
))
19754 tree chain
, superblock
= NULL_TREE
;
19756 dw_attr_ref attr
= NULL
;
19758 if (inlined_function_outer_scope_p (stmt
))
19760 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19761 BLOCK_NUMBER (stmt
));
19762 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19765 /* Optimize duplicate .debug_ranges lists or even tails of
19766 lists. If this BLOCK has same ranges as its supercontext,
19767 lookup DW_AT_ranges attribute in the supercontext (and
19768 recursively so), verify that the ranges_table contains the
19769 right values and use it instead of adding a new .debug_range. */
19770 for (chain
= stmt
, pdie
= die
;
19771 BLOCK_SAME_RANGE (chain
);
19772 chain
= BLOCK_SUPERCONTEXT (chain
))
19774 dw_attr_ref new_attr
;
19776 pdie
= pdie
->die_parent
;
19779 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
19781 new_attr
= get_AT (pdie
, DW_AT_ranges
);
19782 if (new_attr
== NULL
19783 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
19786 superblock
= BLOCK_SUPERCONTEXT (chain
);
19789 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
19790 / 2 / DWARF2_ADDR_SIZE
].num
19791 == BLOCK_NUMBER (superblock
))
19792 && BLOCK_FRAGMENT_CHAIN (superblock
))
19794 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
19795 / 2 / DWARF2_ADDR_SIZE
;
19796 unsigned long supercnt
= 0, thiscnt
= 0;
19797 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
19798 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19801 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
19802 == BLOCK_NUMBER (chain
));
19804 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
19805 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19806 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19808 gcc_assert (supercnt
>= thiscnt
);
19809 add_AT_range_list (die
, DW_AT_ranges
,
19810 ((off
+ supercnt
- thiscnt
)
19811 * 2 * DWARF2_ADDR_SIZE
),
19816 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
19818 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19821 add_ranges (chain
);
19822 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19829 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
19830 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19831 BLOCK_NUMBER (stmt
));
19832 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
19833 BLOCK_NUMBER (stmt
));
19834 add_AT_low_high_pc (die
, label
, label_high
, false);
19838 /* Generate a DIE for a lexical block. */
19841 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
19843 dw_die_ref old_die
= BLOCK_DIE (stmt
);
19844 dw_die_ref stmt_die
= NULL
;
19847 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19848 BLOCK_DIE (stmt
) = stmt_die
;
19851 if (BLOCK_ABSTRACT (stmt
))
19855 #ifdef ENABLE_CHECKING
19856 /* This must have been generated early and it won't even
19857 need location information since it's a DW_AT_inline
19859 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
19860 if (c
->die_tag
== DW_TAG_inlined_subroutine
19861 || c
->die_tag
== DW_TAG_subprogram
)
19863 gcc_assert (get_AT (c
, DW_AT_inline
));
19870 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
19872 /* If this is an inlined instance, create a new lexical die for
19873 anything below to attach DW_AT_abstract_origin to. */
19876 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19877 BLOCK_DIE (stmt
) = stmt_die
;
19883 stmt_die
= old_die
;
19885 /* A non abstract block whose blocks have already been reordered
19886 should have the instruction range for this block. If so, set the
19887 high/low attributes. */
19888 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19890 gcc_assert (stmt_die
);
19891 add_high_low_attributes (stmt
, stmt_die
);
19894 decls_for_scope (stmt
, stmt_die
);
19897 /* Generate a DIE for an inlined subprogram. */
19900 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
19904 /* The instance of function that is effectively being inlined shall not
19906 gcc_assert (! BLOCK_ABSTRACT (stmt
));
19908 decl
= block_ultimate_origin (stmt
);
19910 /* Emit info for the abstract instance first, if we haven't yet. We
19911 must emit this even if the block is abstract, otherwise when we
19912 emit the block below (or elsewhere), we may end up trying to emit
19913 a die whose origin die hasn't been emitted, and crashing. */
19914 dwarf2out_abstract_function (decl
);
19916 if (! BLOCK_ABSTRACT (stmt
))
19918 dw_die_ref subr_die
19919 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
19921 if (call_arg_locations
)
19922 BLOCK_DIE (stmt
) = subr_die
;
19923 add_abstract_origin_attribute (subr_die
, decl
);
19924 if (TREE_ASM_WRITTEN (stmt
))
19925 add_high_low_attributes (stmt
, subr_die
);
19926 add_call_src_coords_attributes (stmt
, subr_die
);
19928 decls_for_scope (stmt
, subr_die
);
19932 /* Generate a DIE for a field in a record, or structure. */
19935 gen_field_die (tree decl
, dw_die_ref context_die
)
19937 dw_die_ref decl_die
;
19939 if (TREE_TYPE (decl
) == error_mark_node
)
19942 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19943 add_name_and_src_coords_attributes (decl_die
, decl
);
19944 add_type_attribute (decl_die
, member_declared_type (decl
),
19945 decl_quals (decl
), context_die
);
19947 if (DECL_BIT_FIELD_TYPE (decl
))
19949 add_byte_size_attribute (decl_die
, decl
);
19950 add_bit_size_attribute (decl_die
, decl
);
19951 add_bit_offset_attribute (decl_die
, decl
);
19954 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19955 add_data_member_location_attribute (decl_die
, decl
);
19957 if (DECL_ARTIFICIAL (decl
))
19958 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19960 add_accessibility_attribute (decl_die
, decl
);
19962 /* Equate decl number to die, so that we can look up this decl later on. */
19963 equate_decl_number_to_die (decl
, decl_die
);
19967 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19968 Use modified_type_die instead.
19969 We keep this code here just in case these types of DIEs may be needed to
19970 represent certain things in other languages (e.g. Pascal) someday. */
19973 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19976 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19978 equate_type_number_to_die (type
, ptr_die
);
19979 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19981 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19984 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19985 Use modified_type_die instead.
19986 We keep this code here just in case these types of DIEs may be needed to
19987 represent certain things in other languages (e.g. Pascal) someday. */
19990 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19992 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19994 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19995 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19997 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19999 equate_type_number_to_die (type
, ref_die
);
20000 add_type_attribute (ref_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
20002 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
20006 /* Generate a DIE for a pointer to a member type. */
20009 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
20012 = new_die (DW_TAG_ptr_to_member_type
,
20013 scope_die_for (type
, context_die
), type
);
20015 equate_type_number_to_die (type
, ptr_die
);
20016 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
20017 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
20018 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
20022 typedef const char *dchar_p
; /* For DEF_VEC_P. */
20024 static char *producer_string
;
20026 /* Return a heap allocated producer string including command line options
20027 if -grecord-gcc-switches. */
20030 gen_producer_string (void)
20033 auto_vec
<dchar_p
> switches
;
20034 const char *language_string
= lang_hooks
.name
;
20035 char *producer
, *tail
;
20037 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
20038 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
20040 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
20041 switch (save_decoded_options
[j
].opt_index
)
20048 case OPT_auxbase_strip
:
20057 case OPT_SPECIAL_unknown
:
20058 case OPT_SPECIAL_ignore
:
20059 case OPT_SPECIAL_program_name
:
20060 case OPT_SPECIAL_input_file
:
20061 case OPT_grecord_gcc_switches
:
20062 case OPT_gno_record_gcc_switches
:
20063 case OPT__output_pch_
:
20064 case OPT_fdiagnostics_show_location_
:
20065 case OPT_fdiagnostics_show_option
:
20066 case OPT_fdiagnostics_show_caret
:
20067 case OPT_fdiagnostics_color_
:
20068 case OPT_fverbose_asm
:
20070 case OPT__sysroot_
:
20072 case OPT_nostdinc__
:
20073 case OPT_fpreprocessed
:
20074 case OPT_fltrans_output_list_
:
20075 case OPT_fresolution_
:
20076 /* Ignore these. */
20079 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
20080 & CL_NO_DWARF_RECORD
)
20082 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
20084 switch (save_decoded_options
[j
].canonical_option
[0][1])
20091 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
20098 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
20099 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
20103 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
20105 sprintf (tail
, "%s %s", language_string
, version_string
);
20108 FOR_EACH_VEC_ELT (switches
, j
, p
)
20112 memcpy (tail
+ 1, p
, len
);
20120 /* Given a C and/or C++ language/version string return the "highest".
20121 C++ is assumed to be "higher" than C in this case. Used for merging
20122 LTO translation unit languages. */
20123 static const char *
20124 highest_c_language (const char *lang1
, const char *lang2
)
20126 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
20127 return "GNU C++14";
20128 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
20129 return "GNU C++11";
20130 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
20131 return "GNU C++98";
20133 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
20135 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
20137 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
20140 gcc_unreachable ();
20144 /* Generate the DIE for the compilation unit. */
20147 gen_compile_unit_die (const char *filename
)
20150 const char *language_string
= lang_hooks
.name
;
20153 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
20157 add_name_attribute (die
, filename
);
20158 /* Don't add cwd for <built-in>. */
20159 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
20160 add_comp_dir_attribute (die
);
20163 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
20165 /* If our producer is LTO try to figure out a common language to use
20166 from the global list of translation units. */
20167 if (strcmp (language_string
, "GNU GIMPLE") == 0)
20171 const char *common_lang
= NULL
;
20173 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
20175 if (!TRANSLATION_UNIT_LANGUAGE (t
))
20178 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
20179 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
20181 else if (strncmp (common_lang
, "GNU C", 5) == 0
20182 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
20183 /* Mixing C and C++ is ok, use C++ in that case. */
20184 common_lang
= highest_c_language (common_lang
,
20185 TRANSLATION_UNIT_LANGUAGE (t
));
20188 /* Fall back to C. */
20189 common_lang
= NULL
;
20195 language_string
= common_lang
;
20198 language
= DW_LANG_C
;
20199 if (strncmp (language_string
, "GNU C", 5) == 0
20200 && ISDIGIT (language_string
[5]))
20202 language
= DW_LANG_C89
;
20203 if (dwarf_version
>= 3 || !dwarf_strict
)
20205 if (strcmp (language_string
, "GNU C89") != 0)
20206 language
= DW_LANG_C99
;
20208 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20209 if (strcmp (language_string
, "GNU C11") == 0)
20210 language
= DW_LANG_C11
;
20213 else if (strncmp (language_string
, "GNU C++", 7) == 0)
20215 language
= DW_LANG_C_plus_plus
;
20216 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20218 if (strcmp (language_string
, "GNU C++11") == 0)
20219 language
= DW_LANG_C_plus_plus_11
;
20220 else if (strcmp (language_string
, "GNU C++14") == 0)
20221 language
= DW_LANG_C_plus_plus_14
;
20224 else if (strcmp (language_string
, "GNU F77") == 0)
20225 language
= DW_LANG_Fortran77
;
20226 else if (strcmp (language_string
, "GNU Pascal") == 0)
20227 language
= DW_LANG_Pascal83
;
20228 else if (dwarf_version
>= 3 || !dwarf_strict
)
20230 if (strcmp (language_string
, "GNU Ada") == 0)
20231 language
= DW_LANG_Ada95
;
20232 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
20234 language
= DW_LANG_Fortran95
;
20235 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20237 if (strcmp (language_string
, "GNU Fortran2003") == 0)
20238 language
= DW_LANG_Fortran03
;
20239 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
20240 language
= DW_LANG_Fortran08
;
20243 else if (strcmp (language_string
, "GNU Java") == 0)
20244 language
= DW_LANG_Java
;
20245 else if (strcmp (language_string
, "GNU Objective-C") == 0)
20246 language
= DW_LANG_ObjC
;
20247 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
20248 language
= DW_LANG_ObjC_plus_plus
;
20249 else if (dwarf_version
>= 5 || !dwarf_strict
)
20251 if (strcmp (language_string
, "GNU Go") == 0)
20252 language
= DW_LANG_Go
;
20255 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
20256 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
20257 language
= DW_LANG_Fortran90
;
20259 add_AT_unsigned (die
, DW_AT_language
, language
);
20263 case DW_LANG_Fortran77
:
20264 case DW_LANG_Fortran90
:
20265 case DW_LANG_Fortran95
:
20266 case DW_LANG_Fortran03
:
20267 case DW_LANG_Fortran08
:
20268 /* Fortran has case insensitive identifiers and the front-end
20269 lowercases everything. */
20270 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
20273 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20279 /* Generate the DIE for a base class. */
20282 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
20284 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
20286 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, context_die
);
20287 add_data_member_location_attribute (die
, binfo
);
20289 if (BINFO_VIRTUAL_P (binfo
))
20290 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20292 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20293 children, otherwise the default is DW_ACCESS_public. In DWARF2
20294 the default has always been DW_ACCESS_private. */
20295 if (access
== access_public_node
)
20297 if (dwarf_version
== 2
20298 || context_die
->die_tag
== DW_TAG_class_type
)
20299 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
20301 else if (access
== access_protected_node
)
20302 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
20303 else if (dwarf_version
> 2
20304 && context_die
->die_tag
!= DW_TAG_class_type
)
20305 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
20308 /* Generate a DIE for a class member. */
20311 gen_member_die (tree type
, dw_die_ref context_die
)
20314 tree binfo
= TYPE_BINFO (type
);
20317 /* If this is not an incomplete type, output descriptions of each of its
20318 members. Note that as we output the DIEs necessary to represent the
20319 members of this record or union type, we will also be trying to output
20320 DIEs to represent the *types* of those members. However the `type'
20321 function (above) will specifically avoid generating type DIEs for member
20322 types *within* the list of member DIEs for this (containing) type except
20323 for those types (of members) which are explicitly marked as also being
20324 members of this (containing) type themselves. The g++ front- end can
20325 force any given type to be treated as a member of some other (containing)
20326 type by setting the TYPE_CONTEXT of the given (member) type to point to
20327 the TREE node representing the appropriate (containing) type. */
20329 /* First output info about the base classes. */
20332 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
20336 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
20337 gen_inheritance_die (base
,
20338 (accesses
? (*accesses
)[i
] : access_public_node
),
20342 /* Now output info about the data members and type members. */
20343 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
20345 /* If we thought we were generating minimal debug info for TYPE
20346 and then changed our minds, some of the member declarations
20347 may have already been defined. Don't define them again, but
20348 do put them in the right order. */
20350 child
= lookup_decl_die (member
);
20352 splice_child_die (context_die
, child
);
20354 gen_decl_die (member
, NULL
, context_die
);
20357 /* We do not keep type methods in type variants. */
20358 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
20359 /* Now output info about the function members (if any). */
20360 if (TYPE_METHODS (type
) != error_mark_node
)
20361 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
20363 /* Don't include clones in the member list. */
20364 if (DECL_ABSTRACT_ORIGIN (member
))
20366 /* Nor constructors for anonymous classes. */
20367 if (DECL_ARTIFICIAL (member
)
20368 && dwarf2_name (member
, 0) == NULL
)
20371 child
= lookup_decl_die (member
);
20373 splice_child_die (context_die
, child
);
20375 gen_decl_die (member
, NULL
, context_die
);
20379 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20380 is set, we pretend that the type was never defined, so we only get the
20381 member DIEs needed by later specification DIEs. */
20384 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
20385 enum debug_info_usage usage
)
20387 if (TREE_ASM_WRITTEN (type
))
20389 /* Fill in the bound of variable-length fields in late dwarf if
20390 still incomplete. */
20391 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
20392 for (tree member
= TYPE_FIELDS (type
);
20394 member
= DECL_CHAIN (member
))
20395 fill_variable_array_bounds (TREE_TYPE (member
));
20399 dw_die_ref type_die
= lookup_type_die (type
);
20400 dw_die_ref scope_die
= 0;
20402 int complete
= (TYPE_SIZE (type
)
20403 && (! TYPE_STUB_DECL (type
)
20404 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
20405 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
20406 complete
= complete
&& should_emit_struct_debug (type
, usage
);
20408 if (type_die
&& ! complete
)
20411 if (TYPE_CONTEXT (type
) != NULL_TREE
20412 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20413 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
20416 scope_die
= scope_die_for (type
, context_die
);
20418 /* Generate child dies for template paramaters. */
20419 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
20420 schedule_generic_params_dies_gen (type
);
20422 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
20423 /* First occurrence of type or toplevel definition of nested class. */
20425 dw_die_ref old_die
= type_die
;
20427 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
20428 ? record_type_tag (type
) : DW_TAG_union_type
,
20430 equate_type_number_to_die (type
, type_die
);
20432 add_AT_specification (type_die
, old_die
);
20434 add_name_attribute (type_die
, type_tag (type
));
20437 remove_AT (type_die
, DW_AT_declaration
);
20439 /* If this type has been completed, then give it a byte_size attribute and
20440 then give a list of members. */
20441 if (complete
&& !ns_decl
)
20443 /* Prevent infinite recursion in cases where the type of some member of
20444 this type is expressed in terms of this type itself. */
20445 TREE_ASM_WRITTEN (type
) = 1;
20446 add_byte_size_attribute (type_die
, type
);
20447 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
20449 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
20450 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
20453 /* If the first reference to this type was as the return type of an
20454 inline function, then it may not have a parent. Fix this now. */
20455 if (type_die
->die_parent
== NULL
)
20456 add_child_die (scope_die
, type_die
);
20458 push_decl_scope (type
);
20459 gen_member_die (type
, type_die
);
20462 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
20463 if (TYPE_ARTIFICIAL (type
))
20464 add_AT_flag (type_die
, DW_AT_artificial
, 1);
20466 /* GNU extension: Record what type our vtable lives in. */
20467 if (TYPE_VFIELD (type
))
20469 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
20471 gen_type_die (vtype
, context_die
);
20472 add_AT_die_ref (type_die
, DW_AT_containing_type
,
20473 lookup_type_die (vtype
));
20478 add_AT_flag (type_die
, DW_AT_declaration
, 1);
20480 /* We don't need to do this for function-local types. */
20481 if (TYPE_STUB_DECL (type
)
20482 && ! decl_function_context (TYPE_STUB_DECL (type
)))
20483 vec_safe_push (incomplete_types
, type
);
20486 if (get_AT (type_die
, DW_AT_name
))
20487 add_pubtype (type
, type_die
);
20490 /* Generate a DIE for a subroutine _type_. */
20493 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
20495 tree return_type
= TREE_TYPE (type
);
20496 dw_die_ref subr_die
20497 = new_die (DW_TAG_subroutine_type
,
20498 scope_die_for (type
, context_die
), type
);
20500 equate_type_number_to_die (type
, subr_die
);
20501 add_prototyped_attribute (subr_die
, type
);
20502 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, context_die
);
20503 gen_formal_types_die (type
, subr_die
);
20505 if (get_AT (subr_die
, DW_AT_name
))
20506 add_pubtype (type
, subr_die
);
20509 /* Generate a DIE for a type definition. */
20512 gen_typedef_die (tree decl
, dw_die_ref context_die
)
20514 dw_die_ref type_die
;
20517 if (TREE_ASM_WRITTEN (decl
))
20519 if (DECL_ORIGINAL_TYPE (decl
))
20520 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
20524 TREE_ASM_WRITTEN (decl
) = 1;
20525 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
20526 origin
= decl_ultimate_origin (decl
);
20527 if (origin
!= NULL
)
20528 add_abstract_origin_attribute (type_die
, origin
);
20533 add_name_and_src_coords_attributes (type_die
, decl
);
20534 if (DECL_ORIGINAL_TYPE (decl
))
20536 type
= DECL_ORIGINAL_TYPE (decl
);
20538 if (type
== error_mark_node
)
20541 gcc_assert (type
!= TREE_TYPE (decl
));
20542 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
20546 type
= TREE_TYPE (decl
);
20548 if (type
== error_mark_node
)
20551 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20553 /* Here, we are in the case of decl being a typedef naming
20554 an anonymous type, e.g:
20555 typedef struct {...} foo;
20556 In that case TREE_TYPE (decl) is not a typedef variant
20557 type and TYPE_NAME of the anonymous type is set to the
20558 TYPE_DECL of the typedef. This construct is emitted by
20561 TYPE is the anonymous struct named by the typedef
20562 DECL. As we need the DW_AT_type attribute of the
20563 DW_TAG_typedef to point to the DIE of TYPE, let's
20564 generate that DIE right away. add_type_attribute
20565 called below will then pick (via lookup_type_die) that
20566 anonymous struct DIE. */
20567 if (!TREE_ASM_WRITTEN (type
))
20568 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
20570 /* This is a GNU Extension. We are adding a
20571 DW_AT_linkage_name attribute to the DIE of the
20572 anonymous struct TYPE. The value of that attribute
20573 is the name of the typedef decl naming the anonymous
20574 struct. This greatly eases the work of consumers of
20575 this debug info. */
20576 add_linkage_attr (lookup_type_die (type
), decl
);
20580 add_type_attribute (type_die
, type
, decl_quals (decl
), context_die
);
20582 if (is_naming_typedef_decl (decl
))
20583 /* We want that all subsequent calls to lookup_type_die with
20584 TYPE in argument yield the DW_TAG_typedef we have just
20586 equate_type_number_to_die (type
, type_die
);
20588 add_accessibility_attribute (type_die
, decl
);
20591 if (DECL_ABSTRACT_P (decl
))
20592 equate_decl_number_to_die (decl
, type_die
);
20594 if (get_AT (type_die
, DW_AT_name
))
20595 add_pubtype (decl
, type_die
);
20598 /* Generate a DIE for a struct, class, enum or union type. */
20601 gen_tagged_type_die (tree type
,
20602 dw_die_ref context_die
,
20603 enum debug_info_usage usage
)
20607 if (type
== NULL_TREE
20608 || !is_tagged_type (type
))
20611 if (TREE_ASM_WRITTEN (type
))
20613 /* If this is a nested type whose containing class hasn't been written
20614 out yet, writing it out will cover this one, too. This does not apply
20615 to instantiations of member class templates; they need to be added to
20616 the containing class as they are generated. FIXME: This hurts the
20617 idea of combining type decls from multiple TUs, since we can't predict
20618 what set of template instantiations we'll get. */
20619 else if (TYPE_CONTEXT (type
)
20620 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20621 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
20623 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
20625 if (TREE_ASM_WRITTEN (type
))
20628 /* If that failed, attach ourselves to the stub. */
20629 push_decl_scope (TYPE_CONTEXT (type
));
20630 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
20633 else if (TYPE_CONTEXT (type
) != NULL_TREE
20634 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
20636 /* If this type is local to a function that hasn't been written
20637 out yet, use a NULL context for now; it will be fixed up in
20638 decls_for_scope. */
20639 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
20640 /* A declaration DIE doesn't count; nested types need to go in the
20642 if (context_die
&& is_declaration_die (context_die
))
20643 context_die
= NULL
;
20648 context_die
= declare_in_namespace (type
, context_die
);
20652 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
20654 /* This might have been written out by the call to
20655 declare_in_namespace. */
20656 if (!TREE_ASM_WRITTEN (type
))
20657 gen_enumeration_type_die (type
, context_die
);
20660 gen_struct_or_union_type_die (type
, context_die
, usage
);
20665 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20666 it up if it is ever completed. gen_*_type_die will set it for us
20667 when appropriate. */
20670 /* Generate a type description DIE. */
20673 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
20674 enum debug_info_usage usage
)
20676 struct array_descr_info info
;
20678 if (type
== NULL_TREE
|| type
== error_mark_node
)
20681 #ifdef ENABLE_CHECKING
20683 verify_type (type
);
20686 if (TYPE_NAME (type
) != NULL_TREE
20687 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20688 && is_redundant_typedef (TYPE_NAME (type
))
20689 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
20690 /* The DECL of this type is a typedef we don't want to emit debug
20691 info for but we want debug info for its underlying typedef.
20692 This can happen for e.g, the injected-class-name of a C++
20694 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
20696 /* If TYPE is a typedef type variant, let's generate debug info
20697 for the parent typedef which TYPE is a type of. */
20698 if (typedef_variant_p (type
))
20700 if (TREE_ASM_WRITTEN (type
))
20703 /* Prevent broken recursion; we can't hand off to the same type. */
20704 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
20706 /* Give typedefs the right scope. */
20707 context_die
= scope_die_for (type
, context_die
);
20709 TREE_ASM_WRITTEN (type
) = 1;
20711 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20715 /* If type is an anonymous tagged type named by a typedef, let's
20716 generate debug info for the typedef. */
20717 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20719 /* Use the DIE of the containing namespace as the parent DIE of
20720 the type description DIE we want to generate. */
20721 if (DECL_CONTEXT (TYPE_NAME (type
))
20722 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
20723 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
20725 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20729 /* We are going to output a DIE to represent the unqualified version
20730 of this type (i.e. without any const or volatile qualifiers) so
20731 get the main variant (i.e. the unqualified version) of this type
20732 now. (Vectors are special because the debugging info is in the
20733 cloned type itself). */
20734 if (TREE_CODE (type
) != VECTOR_TYPE
)
20735 type
= type_main_variant (type
);
20737 /* If this is an array type with hidden descriptor, handle it first. */
20738 if (!TREE_ASM_WRITTEN (type
)
20739 && lang_hooks
.types
.get_array_descr_info
)
20741 memset (&info
, 0, sizeof (info
));
20742 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
20744 gen_descr_array_type_die (type
, &info
, context_die
);
20745 TREE_ASM_WRITTEN (type
) = 1;
20750 if (TREE_ASM_WRITTEN (type
))
20752 /* Variable-length types may be incomplete even if
20753 TREE_ASM_WRITTEN. For such types, fall through to
20754 gen_array_type_die() and possibly fill in
20755 DW_AT_{upper,lower}_bound attributes. */
20756 if ((TREE_CODE (type
) != ARRAY_TYPE
20757 && TREE_CODE (type
) != RECORD_TYPE
20758 && TREE_CODE (type
) != UNION_TYPE
20759 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
20760 || !variably_modified_type_p (type
, NULL
))
20764 switch (TREE_CODE (type
))
20770 case REFERENCE_TYPE
:
20771 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20772 ensures that the gen_type_die recursion will terminate even if the
20773 type is recursive. Recursive types are possible in Ada. */
20774 /* ??? We could perhaps do this for all types before the switch
20776 TREE_ASM_WRITTEN (type
) = 1;
20778 /* For these types, all that is required is that we output a DIE (or a
20779 set of DIEs) to represent the "basis" type. */
20780 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20781 DINFO_USAGE_IND_USE
);
20785 /* This code is used for C++ pointer-to-data-member types.
20786 Output a description of the relevant class type. */
20787 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
20788 DINFO_USAGE_IND_USE
);
20790 /* Output a description of the type of the object pointed to. */
20791 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20792 DINFO_USAGE_IND_USE
);
20794 /* Now output a DIE to represent this pointer-to-data-member type
20796 gen_ptr_to_mbr_type_die (type
, context_die
);
20799 case FUNCTION_TYPE
:
20800 /* Force out return type (in case it wasn't forced out already). */
20801 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20802 DINFO_USAGE_DIR_USE
);
20803 gen_subroutine_type_die (type
, context_die
);
20807 /* Force out return type (in case it wasn't forced out already). */
20808 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20809 DINFO_USAGE_DIR_USE
);
20810 gen_subroutine_type_die (type
, context_die
);
20815 gen_array_type_die (type
, context_die
);
20818 case ENUMERAL_TYPE
:
20821 case QUAL_UNION_TYPE
:
20822 gen_tagged_type_die (type
, context_die
, usage
);
20828 case FIXED_POINT_TYPE
:
20831 case POINTER_BOUNDS_TYPE
:
20832 /* No DIEs needed for fundamental types. */
20837 /* Just use DW_TAG_unspecified_type. */
20839 dw_die_ref type_die
= lookup_type_die (type
);
20840 if (type_die
== NULL
)
20842 tree name
= TYPE_IDENTIFIER (type
);
20843 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
20845 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
20846 equate_type_number_to_die (type
, type_die
);
20852 if (is_cxx_auto (type
))
20854 tree name
= TYPE_IDENTIFIER (type
);
20855 dw_die_ref
*die
= (name
== get_identifier ("auto")
20856 ? &auto_die
: &decltype_auto_die
);
20859 *die
= new_die (DW_TAG_unspecified_type
,
20860 comp_unit_die (), NULL_TREE
);
20861 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
20863 equate_type_number_to_die (type
, *die
);
20866 gcc_unreachable ();
20869 TREE_ASM_WRITTEN (type
) = 1;
20873 gen_type_die (tree type
, dw_die_ref context_die
)
20875 if (type
!= error_mark_node
)
20877 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
20878 #ifdef ENABLE_CHECKING
20879 dw_die_ref die
= lookup_type_die (type
);
20886 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20887 things which are local to the given block. */
20890 gen_block_die (tree stmt
, dw_die_ref context_die
)
20892 int must_output_die
= 0;
20895 /* Ignore blocks that are NULL. */
20896 if (stmt
== NULL_TREE
)
20899 inlined_func
= inlined_function_outer_scope_p (stmt
);
20901 /* If the block is one fragment of a non-contiguous block, do not
20902 process the variables, since they will have been done by the
20903 origin block. Do process subblocks. */
20904 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
20908 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
20909 gen_block_die (sub
, context_die
);
20914 /* Determine if we need to output any Dwarf DIEs at all to represent this
20917 /* The outer scopes for inlinings *must* always be represented. We
20918 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20919 must_output_die
= 1;
20922 /* Determine if this block directly contains any "significant"
20923 local declarations which we will need to output DIEs for. */
20924 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20925 /* We are not in terse mode so *any* local declaration counts
20926 as being a "significant" one. */
20927 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
20928 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
20929 && (TREE_USED (stmt
)
20930 || TREE_ASM_WRITTEN (stmt
)
20931 || BLOCK_ABSTRACT (stmt
)));
20932 else if ((TREE_USED (stmt
)
20933 || TREE_ASM_WRITTEN (stmt
)
20934 || BLOCK_ABSTRACT (stmt
))
20935 && !dwarf2out_ignore_block (stmt
))
20936 must_output_die
= 1;
20939 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20940 DIE for any block which contains no significant local declarations at
20941 all. Rather, in such cases we just call `decls_for_scope' so that any
20942 needed Dwarf info for any sub-blocks will get properly generated. Note
20943 that in terse mode, our definition of what constitutes a "significant"
20944 local declaration gets restricted to include only inlined function
20945 instances and local (nested) function definitions. */
20946 if (must_output_die
)
20950 /* If STMT block is abstract, that means we have been called
20951 indirectly from dwarf2out_abstract_function.
20952 That function rightfully marks the descendent blocks (of
20953 the abstract function it is dealing with) as being abstract,
20954 precisely to prevent us from emitting any
20955 DW_TAG_inlined_subroutine DIE as a descendent
20956 of an abstract function instance. So in that case, we should
20957 not call gen_inlined_subroutine_die.
20959 Later though, when cgraph asks dwarf2out to emit info
20960 for the concrete instance of the function decl into which
20961 the concrete instance of STMT got inlined, the later will lead
20962 to the generation of a DW_TAG_inlined_subroutine DIE. */
20963 if (! BLOCK_ABSTRACT (stmt
))
20964 gen_inlined_subroutine_die (stmt
, context_die
);
20967 gen_lexical_block_die (stmt
, context_die
);
20970 decls_for_scope (stmt
, context_die
);
20973 /* Process variable DECL (or variable with origin ORIGIN) within
20974 block STMT and add it to CONTEXT_DIE. */
20976 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20979 tree decl_or_origin
= decl
? decl
: origin
;
20981 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20982 die
= lookup_decl_die (decl_or_origin
);
20983 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20984 && TYPE_DECL_IS_STUB (decl_or_origin
))
20985 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
20989 if (die
!= NULL
&& die
->die_parent
== NULL
)
20990 add_child_die (context_die
, die
);
20991 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
20994 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
20995 stmt
, context_die
);
20998 gen_decl_die (decl
, origin
, context_die
);
21001 /* Generate all of the decls declared within a given scope and (recursively)
21002 all of its sub-blocks. */
21005 decls_for_scope (tree stmt
, dw_die_ref context_die
)
21011 /* Ignore NULL blocks. */
21012 if (stmt
== NULL_TREE
)
21015 /* Output the DIEs to represent all of the data objects and typedefs
21016 declared directly within this block but not within any nested
21017 sub-blocks. Also, nested function and tag DIEs have been
21018 generated with a parent of NULL; fix that up now. We don't
21019 have to do this if we're at -g1. */
21020 if (debug_info_level
> DINFO_LEVEL_TERSE
)
21022 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
21023 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
21024 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
21025 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
21029 /* Even if we're at -g1, we need to process the subblocks in order to get
21030 inlined call information. */
21032 /* Output the DIEs to represent all sub-blocks (and the items declared
21033 therein) of this block. */
21034 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
21036 subblocks
= BLOCK_CHAIN (subblocks
))
21037 gen_block_die (subblocks
, context_die
);
21040 /* Is this a typedef we can avoid emitting? */
21043 is_redundant_typedef (const_tree decl
)
21045 if (TYPE_DECL_IS_STUB (decl
))
21048 if (DECL_ARTIFICIAL (decl
)
21049 && DECL_CONTEXT (decl
)
21050 && is_tagged_type (DECL_CONTEXT (decl
))
21051 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
21052 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
21053 /* Also ignore the artificial member typedef for the class name. */
21059 /* Return TRUE if TYPE is a typedef that names a type for linkage
21060 purposes. This kind of typedefs is produced by the C++ FE for
21063 typedef struct {...} foo;
21065 In that case, there is no typedef variant type produced for foo.
21066 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
21070 is_naming_typedef_decl (const_tree decl
)
21072 if (decl
== NULL_TREE
21073 || TREE_CODE (decl
) != TYPE_DECL
21074 || !is_tagged_type (TREE_TYPE (decl
))
21075 || DECL_IS_BUILTIN (decl
)
21076 || is_redundant_typedef (decl
)
21077 /* It looks like Ada produces TYPE_DECLs that are very similar
21078 to C++ naming typedefs but that have different
21079 semantics. Let's be specific to c++ for now. */
21083 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
21084 && TYPE_NAME (TREE_TYPE (decl
)) == decl
21085 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
21086 != TYPE_NAME (TREE_TYPE (decl
))));
21089 /* Looks up the DIE for a context. */
21091 static inline dw_die_ref
21092 lookup_context_die (tree context
)
21096 /* Find die that represents this context. */
21097 if (TYPE_P (context
))
21099 context
= TYPE_MAIN_VARIANT (context
);
21100 dw_die_ref ctx
= lookup_type_die (context
);
21103 return strip_naming_typedef (context
, ctx
);
21106 return lookup_decl_die (context
);
21108 return comp_unit_die ();
21111 /* Returns the DIE for a context. */
21113 static inline dw_die_ref
21114 get_context_die (tree context
)
21118 /* Find die that represents this context. */
21119 if (TYPE_P (context
))
21121 context
= TYPE_MAIN_VARIANT (context
);
21122 return strip_naming_typedef (context
, force_type_die (context
));
21125 return force_decl_die (context
);
21127 return comp_unit_die ();
21130 /* Returns the DIE for decl. A DIE will always be returned. */
21133 force_decl_die (tree decl
)
21135 dw_die_ref decl_die
;
21136 unsigned saved_external_flag
;
21137 tree save_fn
= NULL_TREE
;
21138 decl_die
= lookup_decl_die (decl
);
21141 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
21143 decl_die
= lookup_decl_die (decl
);
21147 switch (TREE_CODE (decl
))
21149 case FUNCTION_DECL
:
21150 /* Clear current_function_decl, so that gen_subprogram_die thinks
21151 that this is a declaration. At this point, we just want to force
21152 declaration die. */
21153 save_fn
= current_function_decl
;
21154 current_function_decl
= NULL_TREE
;
21155 gen_subprogram_die (decl
, context_die
);
21156 current_function_decl
= save_fn
;
21160 /* Set external flag to force declaration die. Restore it after
21161 gen_decl_die() call. */
21162 saved_external_flag
= DECL_EXTERNAL (decl
);
21163 DECL_EXTERNAL (decl
) = 1;
21164 gen_decl_die (decl
, NULL
, context_die
);
21165 DECL_EXTERNAL (decl
) = saved_external_flag
;
21168 case NAMESPACE_DECL
:
21169 if (dwarf_version
>= 3 || !dwarf_strict
)
21170 dwarf2out_decl (decl
);
21172 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21173 decl_die
= comp_unit_die ();
21176 case TRANSLATION_UNIT_DECL
:
21177 decl_die
= comp_unit_die ();
21181 gcc_unreachable ();
21184 /* We should be able to find the DIE now. */
21186 decl_die
= lookup_decl_die (decl
);
21187 gcc_assert (decl_die
);
21193 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21194 always returned. */
21197 force_type_die (tree type
)
21199 dw_die_ref type_die
;
21201 type_die
= lookup_type_die (type
);
21204 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
21206 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
21208 gcc_assert (type_die
);
21213 /* Force out any required namespaces to be able to output DECL,
21214 and return the new context_die for it, if it's changed. */
21217 setup_namespace_context (tree thing
, dw_die_ref context_die
)
21219 tree context
= (DECL_P (thing
)
21220 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
21221 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
21222 /* Force out the namespace. */
21223 context_die
= force_decl_die (context
);
21225 return context_die
;
21228 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21229 type) within its namespace, if appropriate.
21231 For compatibility with older debuggers, namespace DIEs only contain
21232 declarations; all definitions are emitted at CU scope, with
21233 DW_AT_specification pointing to the declaration (like with class
21237 declare_in_namespace (tree thing
, dw_die_ref context_die
)
21239 dw_die_ref ns_context
;
21241 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21242 return context_die
;
21244 /* External declarations in the local scope only need to be emitted
21245 once, not once in the namespace and once in the scope.
21247 This avoids declaring the `extern' below in the
21248 namespace DIE as well as in the innermost scope:
21261 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
21262 return context_die
;
21264 /* If this decl is from an inlined function, then don't try to emit it in its
21265 namespace, as we will get confused. It would have already been emitted
21266 when the abstract instance of the inline function was emitted anyways. */
21267 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
21268 return context_die
;
21270 ns_context
= setup_namespace_context (thing
, context_die
);
21272 if (ns_context
!= context_die
)
21276 if (DECL_P (thing
))
21277 gen_decl_die (thing
, NULL
, ns_context
);
21279 gen_type_die (thing
, ns_context
);
21281 return context_die
;
21284 /* Generate a DIE for a namespace or namespace alias. */
21287 gen_namespace_die (tree decl
, dw_die_ref context_die
)
21289 dw_die_ref namespace_die
;
21291 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21292 they are an alias of. */
21293 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
21295 /* Output a real namespace or module. */
21296 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21297 namespace_die
= new_die (is_fortran ()
21298 ? DW_TAG_module
: DW_TAG_namespace
,
21299 context_die
, decl
);
21300 /* For Fortran modules defined in different CU don't add src coords. */
21301 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
21303 const char *name
= dwarf2_name (decl
, 0);
21305 add_name_attribute (namespace_die
, name
);
21308 add_name_and_src_coords_attributes (namespace_die
, decl
);
21309 if (DECL_EXTERNAL (decl
))
21310 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
21311 equate_decl_number_to_die (decl
, namespace_die
);
21315 /* Output a namespace alias. */
21317 /* Force out the namespace we are an alias of, if necessary. */
21318 dw_die_ref origin_die
21319 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
21321 if (DECL_FILE_SCOPE_P (decl
)
21322 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
21323 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21324 /* Now create the namespace alias DIE. */
21325 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
21326 add_name_and_src_coords_attributes (namespace_die
, decl
);
21327 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
21328 equate_decl_number_to_die (decl
, namespace_die
);
21330 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
21331 if (want_pubnames ())
21332 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
21335 /* Generate Dwarf debug information for a decl described by DECL.
21336 The return value is currently only meaningful for PARM_DECLs,
21337 for all other decls it returns NULL. */
21340 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
21342 tree decl_or_origin
= decl
? decl
: origin
;
21343 tree class_origin
= NULL
, ultimate_origin
;
21345 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
21348 /* Ignore pointer bounds decls. */
21349 if (DECL_P (decl_or_origin
)
21350 && TREE_TYPE (decl_or_origin
)
21351 && POINTER_BOUNDS_P (decl_or_origin
))
21354 switch (TREE_CODE (decl_or_origin
))
21360 if (!is_fortran () && !is_ada ())
21362 /* The individual enumerators of an enum type get output when we output
21363 the Dwarf representation of the relevant enum type itself. */
21367 /* Emit its type. */
21368 gen_type_die (TREE_TYPE (decl
), context_die
);
21370 /* And its containing namespace. */
21371 context_die
= declare_in_namespace (decl
, context_die
);
21373 gen_const_die (decl
, context_die
);
21376 case FUNCTION_DECL
:
21377 /* Don't output any DIEs to represent mere function declarations,
21378 unless they are class members or explicit block externs. */
21379 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
21380 && DECL_FILE_SCOPE_P (decl_or_origin
)
21381 && (current_function_decl
== NULL_TREE
21382 || DECL_ARTIFICIAL (decl_or_origin
)))
21387 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21388 on local redeclarations of global functions. That seems broken. */
21389 if (current_function_decl
!= decl
)
21390 /* This is only a declaration. */;
21393 /* If we're emitting a clone, emit info for the abstract instance. */
21394 if (origin
|| DECL_ORIGIN (decl
) != decl
)
21395 dwarf2out_abstract_function (origin
21396 ? DECL_ORIGIN (origin
)
21397 : DECL_ABSTRACT_ORIGIN (decl
));
21399 /* If we're emitting an out-of-line copy of an inline function,
21400 emit info for the abstract instance and set up to refer to it. */
21401 else if (cgraph_function_possibly_inlined_p (decl
)
21402 && ! DECL_ABSTRACT_P (decl
)
21403 && ! class_or_namespace_scope_p (context_die
)
21404 /* dwarf2out_abstract_function won't emit a die if this is just
21405 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21406 that case, because that works only if we have a die. */
21407 && DECL_INITIAL (decl
) != NULL_TREE
)
21409 dwarf2out_abstract_function (decl
);
21410 set_decl_origin_self (decl
);
21413 /* Otherwise we're emitting the primary DIE for this decl. */
21414 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
21416 /* Before we describe the FUNCTION_DECL itself, make sure that we
21417 have its containing type. */
21419 origin
= decl_class_context (decl
);
21420 if (origin
!= NULL_TREE
)
21421 gen_type_die (origin
, context_die
);
21423 /* And its return type. */
21424 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
21426 /* And its virtual context. */
21427 if (DECL_VINDEX (decl
) != NULL_TREE
)
21428 gen_type_die (DECL_CONTEXT (decl
), context_die
);
21430 /* Make sure we have a member DIE for decl. */
21431 if (origin
!= NULL_TREE
)
21432 gen_type_die_for_member (origin
, decl
, context_die
);
21434 /* And its containing namespace. */
21435 context_die
= declare_in_namespace (decl
, context_die
);
21438 /* Now output a DIE to represent the function itself. */
21440 gen_subprogram_die (decl
, context_die
);
21444 /* If we are in terse mode, don't generate any DIEs to represent any
21445 actual typedefs. */
21446 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21449 /* In the special case of a TYPE_DECL node representing the declaration
21450 of some type tag, if the given TYPE_DECL is marked as having been
21451 instantiated from some other (original) TYPE_DECL node (e.g. one which
21452 was generated within the original definition of an inline function) we
21453 used to generate a special (abbreviated) DW_TAG_structure_type,
21454 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21455 should be actually referencing those DIEs, as variable DIEs with that
21456 type would be emitted already in the abstract origin, so it was always
21457 removed during unused type prunning. Don't add anything in this
21459 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
21462 if (is_redundant_typedef (decl
))
21463 gen_type_die (TREE_TYPE (decl
), context_die
);
21465 /* Output a DIE to represent the typedef itself. */
21466 gen_typedef_die (decl
, context_die
);
21470 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
21471 gen_label_die (decl
, context_die
);
21476 /* If we are in terse mode, don't generate any DIEs to represent any
21477 variable declarations or definitions. */
21478 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21481 /* Output any DIEs that are needed to specify the type of this data
21483 if (decl_by_reference_p (decl_or_origin
))
21484 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21486 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21488 /* And its containing type. */
21489 class_origin
= decl_class_context (decl_or_origin
);
21490 if (class_origin
!= NULL_TREE
)
21491 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
21493 /* And its containing namespace. */
21494 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
21496 /* Now output the DIE to represent the data object itself. This gets
21497 complicated because of the possibility that the VAR_DECL really
21498 represents an inlined instance of a formal parameter for an inline
21500 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
21501 if (ultimate_origin
!= NULL_TREE
21502 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
21503 gen_formal_parameter_die (decl
, origin
,
21504 true /* Emit name attribute. */,
21507 gen_variable_die (decl
, origin
, context_die
);
21511 /* Ignore the nameless fields that are used to skip bits but handle C++
21512 anonymous unions and structs. */
21513 if (DECL_NAME (decl
) != NULL_TREE
21514 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
21515 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
21517 gen_type_die (member_declared_type (decl
), context_die
);
21518 gen_field_die (decl
, context_die
);
21523 if (DECL_BY_REFERENCE (decl_or_origin
))
21524 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21526 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21527 return gen_formal_parameter_die (decl
, origin
,
21528 true /* Emit name attribute. */,
21531 case NAMESPACE_DECL
:
21532 case IMPORTED_DECL
:
21533 if (dwarf_version
>= 3 || !dwarf_strict
)
21534 gen_namespace_die (decl
, context_die
);
21537 case NAMELIST_DECL
:
21538 gen_namelist_decl (DECL_NAME (decl
), context_die
,
21539 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
21543 /* Probably some frontend-internal decl. Assume we don't care. */
21544 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
21551 /* Output initial debug information for global DECL. Called at the
21552 end of the parsing process.
21554 This is the initial debug generation process. As such, the DIEs
21555 generated may be incomplete. A later debug generation pass
21556 (dwarf2out_late_global_decl) will augment the information generated
21557 in this pass (e.g., with complete location info). */
21560 dwarf2out_early_global_decl (tree decl
)
21564 /* gen_decl_die() will set DECL_ABSTRACT because
21565 cgraph_function_possibly_inlined_p() returns true. This is in
21566 turn will cause DW_AT_inline attributes to be set.
21568 This happens because at early dwarf generation, there is no
21569 cgraph information, causing cgraph_function_possibly_inlined_p()
21570 to return true. Trick cgraph_function_possibly_inlined_p()
21571 while we generate dwarf early. */
21572 bool save
= symtab
->global_info_ready
;
21573 symtab
->global_info_ready
= true;
21575 /* We don't handle TYPE_DECLs. If required, they'll be reached via
21576 other DECLs and they can point to template types or other things
21577 that dwarf2out can't handle when done via dwarf2out_decl. */
21578 if (TREE_CODE (decl
) != TYPE_DECL
21579 && TREE_CODE (decl
) != PARM_DECL
)
21581 tree save_fndecl
= current_function_decl
;
21582 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21584 /* No cfun means the symbol has no body, so there's nothing
21586 if (!DECL_STRUCT_FUNCTION (decl
))
21587 goto early_decl_exit
;
21589 current_function_decl
= decl
;
21591 dwarf2out_decl (decl
);
21592 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21593 current_function_decl
= save_fndecl
;
21596 symtab
->global_info_ready
= save
;
21599 /* Output debug information for global decl DECL. Called from
21600 toplev.c after compilation proper has finished. */
21603 dwarf2out_late_global_decl (tree decl
)
21605 /* Output any global decls we missed or fill-in any location
21606 information we were unable to determine on the first pass.
21608 Skip over functions because they were handled by the
21609 debug_hooks->function_decl() call in rest_of_handle_final. */
21610 if ((TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
21611 && !POINTER_BOUNDS_P (decl
))
21612 dwarf2out_decl (decl
);
21615 /* Output debug information for type decl DECL. Called from toplev.c
21616 and from language front ends (to record built-in types). */
21618 dwarf2out_type_decl (tree decl
, int local
)
21623 dwarf2out_decl (decl
);
21627 /* Output debug information for imported module or decl DECL.
21628 NAME is non-NULL name in the lexical block if the decl has been renamed.
21629 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21630 that DECL belongs to.
21631 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21633 dwarf2out_imported_module_or_decl_1 (tree decl
,
21635 tree lexical_block
,
21636 dw_die_ref lexical_block_die
)
21638 expanded_location xloc
;
21639 dw_die_ref imported_die
= NULL
;
21640 dw_die_ref at_import_die
;
21642 if (TREE_CODE (decl
) == IMPORTED_DECL
)
21644 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
21645 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
21649 xloc
= expand_location (input_location
);
21651 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
21653 at_import_die
= force_type_die (TREE_TYPE (decl
));
21654 /* For namespace N { typedef void T; } using N::T; base_type_die
21655 returns NULL, but DW_TAG_imported_declaration requires
21656 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21657 if (!at_import_die
)
21659 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
21660 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
21661 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
21662 gcc_assert (at_import_die
);
21667 at_import_die
= lookup_decl_die (decl
);
21668 if (!at_import_die
)
21670 /* If we're trying to avoid duplicate debug info, we may not have
21671 emitted the member decl for this field. Emit it now. */
21672 if (TREE_CODE (decl
) == FIELD_DECL
)
21674 tree type
= DECL_CONTEXT (decl
);
21676 if (TYPE_CONTEXT (type
)
21677 && TYPE_P (TYPE_CONTEXT (type
))
21678 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
21679 DINFO_USAGE_DIR_USE
))
21681 gen_type_die_for_member (type
, decl
,
21682 get_context_die (TYPE_CONTEXT (type
)));
21684 if (TREE_CODE (decl
) == NAMELIST_DECL
)
21685 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
21686 get_context_die (DECL_CONTEXT (decl
)),
21689 at_import_die
= force_decl_die (decl
);
21693 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
21695 if (dwarf_version
>= 3 || !dwarf_strict
)
21696 imported_die
= new_die (DW_TAG_imported_module
,
21703 imported_die
= new_die (DW_TAG_imported_declaration
,
21707 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
21708 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
21710 add_AT_string (imported_die
, DW_AT_name
,
21711 IDENTIFIER_POINTER (name
));
21712 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
21715 /* Output debug information for imported module or decl DECL.
21716 NAME is non-NULL name in context if the decl has been renamed.
21717 CHILD is true if decl is one of the renamed decls as part of
21718 importing whole module. */
21721 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
21724 /* dw_die_ref at_import_die; */
21725 dw_die_ref scope_die
;
21727 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21734 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21735 We need decl DIE for reference and scope die. First, get DIE for the decl
21738 /* Get the scope die for decl context. Use comp_unit_die for global module
21739 or decl. If die is not found for non globals, force new die. */
21741 && TYPE_P (context
)
21742 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
21745 if (!(dwarf_version
>= 3 || !dwarf_strict
))
21748 scope_die
= get_context_die (context
);
21752 gcc_assert (scope_die
->die_child
);
21753 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
21754 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
21755 scope_die
= scope_die
->die_child
;
21758 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21759 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
21762 /* Output debug information for namelists. */
21765 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
21767 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
21771 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21774 gcc_assert (scope_die
!= NULL
);
21775 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
21776 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
21778 /* If there are no item_decls, we have a nondefining namelist, e.g.
21779 with USE association; hence, set DW_AT_declaration. */
21780 if (item_decls
== NULL_TREE
)
21782 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
21786 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
21788 nml_item_ref_die
= lookup_decl_die (value
);
21789 if (!nml_item_ref_die
)
21790 nml_item_ref_die
= force_decl_die (value
);
21792 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
21793 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
21799 /* Write the debugging output for DECL and return the DIE. */
21802 dwarf2out_decl (tree decl
)
21804 dw_die_ref context_die
= comp_unit_die ();
21806 switch (TREE_CODE (decl
))
21811 case FUNCTION_DECL
:
21812 /* What we would really like to do here is to filter out all mere
21813 file-scope declarations of file-scope functions which are never
21814 referenced later within this translation unit (and keep all of ones
21815 that *are* referenced later on) but we aren't clairvoyant, so we have
21816 no idea which functions will be referenced in the future (i.e. later
21817 on within the current translation unit). So here we just ignore all
21818 file-scope function declarations which are not also definitions. If
21819 and when the debugger needs to know something about these functions,
21820 it will have to hunt around and find the DWARF information associated
21821 with the definition of the function.
21823 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21824 nodes represent definitions and which ones represent mere
21825 declarations. We have to check DECL_INITIAL instead. That's because
21826 the C front-end supports some weird semantics for "extern inline"
21827 function definitions. These can get inlined within the current
21828 translation unit (and thus, we need to generate Dwarf info for their
21829 abstract instances so that the Dwarf info for the concrete inlined
21830 instances can have something to refer to) but the compiler never
21831 generates any out-of-lines instances of such things (despite the fact
21832 that they *are* definitions).
21834 The important point is that the C front-end marks these "extern
21835 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21836 them anyway. Note that the C++ front-end also plays some similar games
21837 for inline function definitions appearing within include files which
21838 also contain `#pragma interface' pragmas.
21840 If we are called from dwarf2out_abstract_function output a DIE
21841 anyway. We can end up here this way with early inlining and LTO
21842 where the inlined function is output in a different LTRANS unit
21844 if (DECL_INITIAL (decl
) == NULL_TREE
21845 && ! DECL_ABSTRACT_P (decl
))
21848 /* If we're a nested function, initially use a parent of NULL; if we're
21849 a plain function, this will be fixed up in decls_for_scope. If
21850 we're a method, it will be ignored, since we already have a DIE. */
21851 if (decl_function_context (decl
)
21852 /* But if we're in terse mode, we don't care about scope. */
21853 && debug_info_level
> DINFO_LEVEL_TERSE
)
21854 context_die
= NULL
;
21858 /* For local statics lookup proper context die. */
21859 if (local_function_static (decl
))
21860 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21862 /* If we are in terse mode, don't generate any DIEs to represent any
21863 variable declarations or definitions. */
21864 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21869 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21871 if (!is_fortran () && !is_ada ())
21873 if (TREE_STATIC (decl
) && decl_function_context (decl
))
21874 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21877 case NAMESPACE_DECL
:
21878 case IMPORTED_DECL
:
21879 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21881 if (lookup_decl_die (decl
) != NULL
)
21886 /* Don't emit stubs for types unless they are needed by other DIEs. */
21887 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
21890 /* Don't bother trying to generate any DIEs to represent any of the
21891 normal built-in types for the language we are compiling. */
21892 if (DECL_IS_BUILTIN (decl
))
21895 /* If we are in terse mode, don't generate any DIEs for types. */
21896 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21899 /* If we're a function-scope tag, initially use a parent of NULL;
21900 this will be fixed up in decls_for_scope. */
21901 if (decl_function_context (decl
))
21902 context_die
= NULL
;
21906 case NAMELIST_DECL
:
21913 gen_decl_die (decl
, NULL
, context_die
);
21915 #ifdef ENABLE_CHECKING
21916 dw_die_ref die
= lookup_decl_die (decl
);
21922 /* Write the debugging output for DECL. */
21925 dwarf2out_function_decl (tree decl
)
21927 dwarf2out_decl (decl
);
21928 call_arg_locations
= NULL
;
21929 call_arg_loc_last
= NULL
;
21930 call_site_count
= -1;
21931 tail_call_site_count
= -1;
21932 decl_loc_table
->empty ();
21933 cached_dw_loc_list_table
->empty ();
21936 /* Output a marker (i.e. a label) for the beginning of the generated code for
21937 a lexical block. */
21940 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
21941 unsigned int blocknum
)
21943 switch_to_section (current_function_section ());
21944 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
21947 /* Output a marker (i.e. a label) for the end of the generated code for a
21951 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
21953 switch_to_section (current_function_section ());
21954 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
21957 /* Returns nonzero if it is appropriate not to emit any debugging
21958 information for BLOCK, because it doesn't contain any instructions.
21960 Don't allow this for blocks with nested functions or local classes
21961 as we would end up with orphans, and in the presence of scheduling
21962 we may end up calling them anyway. */
21965 dwarf2out_ignore_block (const_tree block
)
21970 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
21971 if (TREE_CODE (decl
) == FUNCTION_DECL
21972 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21974 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
21976 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
21977 if (TREE_CODE (decl
) == FUNCTION_DECL
21978 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21985 /* Hash table routines for file_hash. */
21988 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
21990 return filename_cmp (p1
->filename
, p2
) == 0;
21994 dwarf_file_hasher::hash (dwarf_file_data
*p
)
21996 return htab_hash_string (p
->filename
);
21999 /* Lookup FILE_NAME (in the list of filenames that we know about here in
22000 dwarf2out.c) and return its "index". The index of each (known) filename is
22001 just a unique number which is associated with only that one filename. We
22002 need such numbers for the sake of generating labels (in the .debug_sfnames
22003 section) and references to those files numbers (in the .debug_srcinfo
22004 and.debug_macinfo sections). If the filename given as an argument is not
22005 found in our current list, add it to the list and assign it the next
22006 available unique index number. */
22008 static struct dwarf_file_data
*
22009 lookup_filename (const char *file_name
)
22011 struct dwarf_file_data
* created
;
22016 dwarf_file_data
**slot
22017 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
22022 created
= ggc_alloc
<dwarf_file_data
> ();
22023 created
->filename
= file_name
;
22024 created
->emitted_number
= 0;
22029 /* If the assembler will construct the file table, then translate the compiler
22030 internal file table number into the assembler file table number, and emit
22031 a .file directive if we haven't already emitted one yet. The file table
22032 numbers are different because we prune debug info for unused variables and
22033 types, which may include filenames. */
22036 maybe_emit_file (struct dwarf_file_data
* fd
)
22038 if (! fd
->emitted_number
)
22040 if (last_emitted_file
)
22041 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
22043 fd
->emitted_number
= 1;
22044 last_emitted_file
= fd
;
22046 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22048 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
22049 output_quoted_string (asm_out_file
,
22050 remap_debug_filename (fd
->filename
));
22051 fputc ('\n', asm_out_file
);
22055 return fd
->emitted_number
;
22058 /* Schedule generation of a DW_AT_const_value attribute to DIE.
22059 That generation should happen after function debug info has been
22060 generated. The value of the attribute is the constant value of ARG. */
22063 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
22065 die_arg_entry entry
;
22070 if (!tmpl_value_parm_die_table
)
22071 vec_alloc (tmpl_value_parm_die_table
, 32);
22075 vec_safe_push (tmpl_value_parm_die_table
, entry
);
22078 /* Return TRUE if T is an instance of generic type, FALSE
22082 generic_type_p (tree t
)
22084 if (t
== NULL_TREE
|| !TYPE_P (t
))
22086 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
22089 /* Schedule the generation of the generic parameter dies for the
22090 instance of generic type T. The proper generation itself is later
22091 done by gen_scheduled_generic_parms_dies. */
22094 schedule_generic_params_dies_gen (tree t
)
22096 if (!generic_type_p (t
))
22099 if (!generic_type_instances
)
22100 vec_alloc (generic_type_instances
, 256);
22102 vec_safe_push (generic_type_instances
, t
);
22105 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
22106 by append_entry_to_tmpl_value_parm_die_table. This function must
22107 be called after function DIEs have been generated. */
22110 gen_remaining_tmpl_value_param_die_attribute (void)
22112 if (tmpl_value_parm_die_table
)
22117 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
22118 tree_add_const_value_attribute (e
->die
, e
->arg
);
22122 /* Generate generic parameters DIEs for instances of generic types
22123 that have been previously scheduled by
22124 schedule_generic_params_dies_gen. This function must be called
22125 after all the types of the CU have been laid out. */
22128 gen_scheduled_generic_parms_dies (void)
22133 if (!generic_type_instances
)
22136 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
22137 if (COMPLETE_TYPE_P (t
))
22138 gen_generic_params_dies (t
);
22142 /* Replace DW_AT_name for the decl with name. */
22145 dwarf2out_set_name (tree decl
, tree name
)
22151 die
= TYPE_SYMTAB_DIE (decl
);
22155 dname
= dwarf2_name (name
, 0);
22159 attr
= get_AT (die
, DW_AT_name
);
22162 struct indirect_string_node
*node
;
22164 node
= find_AT_string (dname
);
22165 /* replace the string. */
22166 attr
->dw_attr_val
.v
.val_str
= node
;
22170 add_name_attribute (die
, dname
);
22173 /* True if before or during processing of the first function being emitted. */
22174 static bool in_first_function_p
= true;
22175 /* True if loc_note during dwarf2out_var_location call might still be
22176 before first real instruction at address equal to .Ltext0. */
22177 static bool maybe_at_text_label_p
= true;
22178 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
22179 static unsigned int first_loclabel_num_not_at_text_label
;
22181 /* Called by the final INSN scan whenever we see a var location. We
22182 use it to drop labels in the right places, and throw the location in
22183 our lookup table. */
22186 dwarf2out_var_location (rtx_insn
*loc_note
)
22188 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
22189 struct var_loc_node
*newloc
;
22190 rtx_insn
*next_real
, *next_note
;
22191 static const char *last_label
;
22192 static const char *last_postcall_label
;
22193 static bool last_in_cold_section_p
;
22194 static rtx_insn
*expected_next_loc_note
;
22198 if (!NOTE_P (loc_note
))
22200 if (CALL_P (loc_note
))
22203 if (SIBLING_CALL_P (loc_note
))
22204 tail_call_site_count
++;
22209 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
22210 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
22213 /* Optimize processing a large consecutive sequence of location
22214 notes so we don't spend too much time in next_real_insn. If the
22215 next insn is another location note, remember the next_real_insn
22216 calculation for next time. */
22217 next_real
= cached_next_real_insn
;
22220 if (expected_next_loc_note
!= loc_note
)
22224 next_note
= NEXT_INSN (loc_note
);
22226 || next_note
->deleted ()
22227 || ! NOTE_P (next_note
)
22228 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
22229 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
22233 next_real
= next_real_insn (loc_note
);
22237 expected_next_loc_note
= next_note
;
22238 cached_next_real_insn
= next_real
;
22241 cached_next_real_insn
= NULL
;
22243 /* If there are no instructions which would be affected by this note,
22244 don't do anything. */
22246 && next_real
== NULL_RTX
22247 && !NOTE_DURING_CALL_P (loc_note
))
22250 if (next_real
== NULL_RTX
)
22251 next_real
= get_last_insn ();
22253 /* If there were any real insns between note we processed last time
22254 and this note (or if it is the first note), clear
22255 last_{,postcall_}label so that they are not reused this time. */
22256 if (last_var_location_insn
== NULL_RTX
22257 || last_var_location_insn
!= next_real
22258 || last_in_cold_section_p
!= in_cold_section_p
)
22261 last_postcall_label
= NULL
;
22266 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
22267 newloc
= add_var_loc_to_decl (decl
, loc_note
,
22268 NOTE_DURING_CALL_P (loc_note
)
22269 ? last_postcall_label
: last_label
);
22270 if (newloc
== NULL
)
22279 /* If there were no real insns between note we processed last time
22280 and this note, use the label we emitted last time. Otherwise
22281 create a new label and emit it. */
22282 if (last_label
== NULL
)
22284 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
22285 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
22287 last_label
= ggc_strdup (loclabel
);
22288 /* See if loclabel might be equal to .Ltext0. If yes,
22289 bump first_loclabel_num_not_at_text_label. */
22290 if (!have_multiple_function_sections
22291 && in_first_function_p
22292 && maybe_at_text_label_p
)
22294 static rtx_insn
*last_start
;
22296 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
22297 if (insn
== last_start
)
22299 else if (!NONDEBUG_INSN_P (insn
))
22303 rtx body
= PATTERN (insn
);
22304 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
22306 /* Inline asm could occupy zero bytes. */
22307 else if (GET_CODE (body
) == ASM_INPUT
22308 || asm_noperands (body
) >= 0)
22310 #ifdef HAVE_attr_length
22311 else if (get_attr_min_length (insn
) == 0)
22316 /* Assume insn has non-zero length. */
22317 maybe_at_text_label_p
= false;
22321 if (maybe_at_text_label_p
)
22323 last_start
= loc_note
;
22324 first_loclabel_num_not_at_text_label
= loclabel_num
;
22331 struct call_arg_loc_node
*ca_loc
22332 = ggc_cleared_alloc
<call_arg_loc_node
> ();
22333 rtx_insn
*prev
= prev_real_insn (loc_note
);
22335 ca_loc
->call_arg_loc_note
= loc_note
;
22336 ca_loc
->next
= NULL
;
22337 ca_loc
->label
= last_label
;
22340 || (NONJUMP_INSN_P (prev
)
22341 && GET_CODE (PATTERN (prev
)) == SEQUENCE
22342 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
22343 if (!CALL_P (prev
))
22344 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
22345 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
22346 x
= get_call_rtx_from (PATTERN (prev
));
22349 x
= XEXP (XEXP (x
, 0), 0);
22350 if (GET_CODE (x
) == SYMBOL_REF
22351 && SYMBOL_REF_DECL (x
)
22352 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
22353 ca_loc
->symbol_ref
= x
;
22355 ca_loc
->block
= insn_scope (prev
);
22356 if (call_arg_locations
)
22357 call_arg_loc_last
->next
= ca_loc
;
22359 call_arg_locations
= ca_loc
;
22360 call_arg_loc_last
= ca_loc
;
22362 else if (!NOTE_DURING_CALL_P (loc_note
))
22363 newloc
->label
= last_label
;
22366 if (!last_postcall_label
)
22368 sprintf (loclabel
, "%s-1", last_label
);
22369 last_postcall_label
= ggc_strdup (loclabel
);
22371 newloc
->label
= last_postcall_label
;
22374 last_var_location_insn
= next_real
;
22375 last_in_cold_section_p
= in_cold_section_p
;
22378 /* Note in one location list that text section has changed. */
22381 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
22383 var_loc_list
*list
= *slot
;
22385 list
->last_before_switch
22386 = list
->last
->next
? list
->last
->next
: list
->last
;
22390 /* Note in all location lists that text section has changed. */
22393 var_location_switch_text_section (void)
22395 if (decl_loc_table
== NULL
)
22398 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
22401 /* Create a new line number table. */
22403 static dw_line_info_table
*
22404 new_line_info_table (void)
22406 dw_line_info_table
*table
;
22408 table
= ggc_cleared_alloc
<dw_line_info_table_struct
> ();
22409 table
->file_num
= 1;
22410 table
->line_num
= 1;
22411 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
22416 /* Lookup the "current" table into which we emit line info, so
22417 that we don't have to do it for every source line. */
22420 set_cur_line_info_table (section
*sec
)
22422 dw_line_info_table
*table
;
22424 if (sec
== text_section
)
22425 table
= text_section_line_info
;
22426 else if (sec
== cold_text_section
)
22428 table
= cold_text_section_line_info
;
22431 cold_text_section_line_info
= table
= new_line_info_table ();
22432 table
->end_label
= cold_end_label
;
22437 const char *end_label
;
22439 if (flag_reorder_blocks_and_partition
)
22441 if (in_cold_section_p
)
22442 end_label
= crtl
->subsections
.cold_section_end_label
;
22444 end_label
= crtl
->subsections
.hot_section_end_label
;
22448 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22449 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
22450 current_function_funcdef_no
);
22451 end_label
= ggc_strdup (label
);
22454 table
= new_line_info_table ();
22455 table
->end_label
= end_label
;
22457 vec_safe_push (separate_line_info
, table
);
22460 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22461 table
->is_stmt
= (cur_line_info_table
22462 ? cur_line_info_table
->is_stmt
22463 : DWARF_LINE_DEFAULT_IS_STMT_START
);
22464 cur_line_info_table
= table
;
22468 /* We need to reset the locations at the beginning of each
22469 function. We can't do this in the end_function hook, because the
22470 declarations that use the locations won't have been output when
22471 that hook is called. Also compute have_multiple_function_sections here. */
22474 dwarf2out_begin_function (tree fun
)
22476 section
*sec
= function_section (fun
);
22478 if (sec
!= text_section
)
22479 have_multiple_function_sections
= true;
22481 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
22483 gcc_assert (current_function_decl
== fun
);
22484 cold_text_section
= unlikely_text_section ();
22485 switch_to_section (cold_text_section
);
22486 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
22487 switch_to_section (sec
);
22490 dwarf2out_note_section_used ();
22491 call_site_count
= 0;
22492 tail_call_site_count
= 0;
22494 set_cur_line_info_table (sec
);
22497 /* Helper function of dwarf2out_end_function, called only after emitting
22498 the very first function into assembly. Check if some .debug_loc range
22499 might end with a .LVL* label that could be equal to .Ltext0.
22500 In that case we must force using absolute addresses in .debug_loc ranges,
22501 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
22502 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
22504 Set have_multiple_function_sections to true in that case and
22505 terminate htab traversal. */
22508 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
22510 var_loc_list
*entry
= *slot
;
22511 struct var_loc_node
*node
;
22513 node
= entry
->first
;
22514 if (node
&& node
->next
&& node
->next
->label
)
22517 const char *label
= node
->next
->label
;
22518 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
22520 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
22522 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
22523 if (strcmp (label
, loclabel
) == 0)
22525 have_multiple_function_sections
= true;
22533 /* Hook called after emitting a function into assembly.
22534 This does something only for the very first function emitted. */
22537 dwarf2out_end_function (unsigned int)
22539 if (in_first_function_p
22540 && !have_multiple_function_sections
22541 && first_loclabel_num_not_at_text_label
22543 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
22544 in_first_function_p
= false;
22545 maybe_at_text_label_p
= false;
22548 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
22549 front-ends register a translation unit even before dwarf2out_init is
22551 static tree main_translation_unit
= NULL_TREE
;
22553 /* Hook called by front-ends after they built their main translation unit.
22554 Associate comp_unit_die to UNIT. */
22557 dwarf2out_register_main_translation_unit (tree unit
)
22559 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
22560 && main_translation_unit
== NULL_TREE
);
22561 main_translation_unit
= unit
;
22562 /* If dwarf2out_init has not been called yet, it will perform the association
22563 itself looking at main_translation_unit. */
22564 if (decl_die_table
!= NULL
)
22565 equate_decl_number_to_die (unit
, comp_unit_die ());
22568 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
22571 push_dw_line_info_entry (dw_line_info_table
*table
,
22572 enum dw_line_info_opcode opcode
, unsigned int val
)
22574 dw_line_info_entry e
;
22577 vec_safe_push (table
->entries
, e
);
22580 /* Output a label to mark the beginning of a source code line entry
22581 and record information relating to this source line, in
22582 'line_info_table' for later output of the .debug_line section. */
22583 /* ??? The discriminator parameter ought to be unsigned. */
22586 dwarf2out_source_line (unsigned int line
, const char *filename
,
22587 int discriminator
, bool is_stmt
)
22589 unsigned int file_num
;
22590 dw_line_info_table
*table
;
22592 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
22595 /* The discriminator column was added in dwarf4. Simplify the below
22596 by simply removing it if we're not supposed to output it. */
22597 if (dwarf_version
< 4 && dwarf_strict
)
22600 table
= cur_line_info_table
;
22601 file_num
= maybe_emit_file (lookup_filename (filename
));
22603 /* ??? TODO: Elide duplicate line number entries. Traditionally,
22604 the debugger has used the second (possibly duplicate) line number
22605 at the beginning of the function to mark the end of the prologue.
22606 We could eliminate any other duplicates within the function. For
22607 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
22608 that second line number entry. */
22609 /* Recall that this end-of-prologue indication is *not* the same thing
22610 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
22611 to which the hook corresponds, follows the last insn that was
22612 emitted by gen_prologue. What we need is to precede the first insn
22613 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
22614 insn that corresponds to something the user wrote. These may be
22615 very different locations once scheduling is enabled. */
22617 if (0 && file_num
== table
->file_num
22618 && line
== table
->line_num
22619 && discriminator
== table
->discrim_num
22620 && is_stmt
== table
->is_stmt
)
22623 switch_to_section (current_function_section ());
22625 /* If requested, emit something human-readable. */
22626 if (flag_debug_asm
)
22627 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
22629 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22631 /* Emit the .loc directive understood by GNU as. */
22632 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
22633 file_num, line, is_stmt, discriminator */
22634 fputs ("\t.loc ", asm_out_file
);
22635 fprint_ul (asm_out_file
, file_num
);
22636 putc (' ', asm_out_file
);
22637 fprint_ul (asm_out_file
, line
);
22638 putc (' ', asm_out_file
);
22639 putc ('0', asm_out_file
);
22641 if (is_stmt
!= table
->is_stmt
)
22643 fputs (" is_stmt ", asm_out_file
);
22644 putc (is_stmt
? '1' : '0', asm_out_file
);
22646 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
22648 gcc_assert (discriminator
> 0);
22649 fputs (" discriminator ", asm_out_file
);
22650 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
22652 putc ('\n', asm_out_file
);
22656 unsigned int label_num
= ++line_info_label_num
;
22658 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
22660 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
22661 if (file_num
!= table
->file_num
)
22662 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
22663 if (discriminator
!= table
->discrim_num
)
22664 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
22665 if (is_stmt
!= table
->is_stmt
)
22666 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
22667 push_dw_line_info_entry (table
, LI_set_line
, line
);
22670 table
->file_num
= file_num
;
22671 table
->line_num
= line
;
22672 table
->discrim_num
= discriminator
;
22673 table
->is_stmt
= is_stmt
;
22674 table
->in_use
= true;
22677 /* Record the beginning of a new source file. */
22680 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
22682 if (flag_eliminate_dwarf2_dups
)
22684 /* Record the beginning of the file for break_out_includes. */
22685 dw_die_ref bincl_die
;
22687 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
22688 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
22691 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22694 e
.code
= DW_MACINFO_start_file
;
22696 e
.info
= ggc_strdup (filename
);
22697 vec_safe_push (macinfo_table
, e
);
22701 /* Record the end of a source file. */
22704 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
22706 if (flag_eliminate_dwarf2_dups
)
22707 /* Record the end of the file for break_out_includes. */
22708 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
22710 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22713 e
.code
= DW_MACINFO_end_file
;
22716 vec_safe_push (macinfo_table
, e
);
22720 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22721 the tail part of the directive line, i.e. the part which is past the
22722 initial whitespace, #, whitespace, directive-name, whitespace part. */
22725 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
22726 const char *buffer ATTRIBUTE_UNUSED
)
22728 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22731 /* Insert a dummy first entry to be able to optimize the whole
22732 predefined macro block using DW_MACRO_GNU_transparent_include. */
22733 if (macinfo_table
->is_empty () && lineno
<= 1)
22738 vec_safe_push (macinfo_table
, e
);
22740 e
.code
= DW_MACINFO_define
;
22742 e
.info
= ggc_strdup (buffer
);
22743 vec_safe_push (macinfo_table
, e
);
22747 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22748 the tail part of the directive line, i.e. the part which is past the
22749 initial whitespace, #, whitespace, directive-name, whitespace part. */
22752 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
22753 const char *buffer ATTRIBUTE_UNUSED
)
22755 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22758 /* Insert a dummy first entry to be able to optimize the whole
22759 predefined macro block using DW_MACRO_GNU_transparent_include. */
22760 if (macinfo_table
->is_empty () && lineno
<= 1)
22765 vec_safe_push (macinfo_table
, e
);
22767 e
.code
= DW_MACINFO_undef
;
22769 e
.info
= ggc_strdup (buffer
);
22770 vec_safe_push (macinfo_table
, e
);
22774 /* Helpers to manipulate hash table of CUs. */
22776 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
22778 static inline hashval_t
hash (const macinfo_entry
*);
22779 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
22783 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
22785 return htab_hash_string (entry
->info
);
22789 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
22790 const macinfo_entry
*entry2
)
22792 return !strcmp (entry1
->info
, entry2
->info
);
22795 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
22797 /* Output a single .debug_macinfo entry. */
22800 output_macinfo_op (macinfo_entry
*ref
)
22804 struct indirect_string_node
*node
;
22805 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22806 struct dwarf_file_data
*fd
;
22810 case DW_MACINFO_start_file
:
22811 fd
= lookup_filename (ref
->info
);
22812 file_num
= maybe_emit_file (fd
);
22813 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
22814 dw2_asm_output_data_uleb128 (ref
->lineno
,
22815 "Included from line number %lu",
22816 (unsigned long) ref
->lineno
);
22817 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
22819 case DW_MACINFO_end_file
:
22820 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
22822 case DW_MACINFO_define
:
22823 case DW_MACINFO_undef
:
22824 len
= strlen (ref
->info
) + 1;
22826 && len
> DWARF_OFFSET_SIZE
22827 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
22828 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
22830 ref
->code
= ref
->code
== DW_MACINFO_define
22831 ? DW_MACRO_GNU_define_indirect
22832 : DW_MACRO_GNU_undef_indirect
;
22833 output_macinfo_op (ref
);
22836 dw2_asm_output_data (1, ref
->code
,
22837 ref
->code
== DW_MACINFO_define
22838 ? "Define macro" : "Undefine macro");
22839 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22840 (unsigned long) ref
->lineno
);
22841 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
22843 case DW_MACRO_GNU_define_indirect
:
22844 case DW_MACRO_GNU_undef_indirect
:
22845 node
= find_AT_string (ref
->info
);
22847 && ((node
->form
== DW_FORM_strp
)
22848 || (node
->form
== DW_FORM_GNU_str_index
)));
22849 dw2_asm_output_data (1, ref
->code
,
22850 ref
->code
== DW_MACRO_GNU_define_indirect
22851 ? "Define macro indirect"
22852 : "Undefine macro indirect");
22853 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22854 (unsigned long) ref
->lineno
);
22855 if (node
->form
== DW_FORM_strp
)
22856 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
22857 debug_str_section
, "The macro: \"%s\"",
22860 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
22863 case DW_MACRO_GNU_transparent_include
:
22864 dw2_asm_output_data (1, ref
->code
, "Transparent include");
22865 ASM_GENERATE_INTERNAL_LABEL (label
,
22866 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
22867 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
22870 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
22871 ASM_COMMENT_START
, (unsigned long) ref
->code
);
22876 /* Attempt to make a sequence of define/undef macinfo ops shareable with
22877 other compilation unit .debug_macinfo sections. IDX is the first
22878 index of a define/undef, return the number of ops that should be
22879 emitted in a comdat .debug_macinfo section and emit
22880 a DW_MACRO_GNU_transparent_include entry referencing it.
22881 If the define/undef entry should be emitted normally, return 0. */
22884 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
22885 macinfo_hash_type
**macinfo_htab
)
22887 macinfo_entry
*first
, *second
, *cur
, *inc
;
22888 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
22889 unsigned char checksum
[16];
22890 struct md5_ctx ctx
;
22891 char *grp_name
, *tail
;
22893 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
22894 macinfo_entry
**slot
;
22896 first
= &(*macinfo_table
)[idx
];
22897 second
= &(*macinfo_table
)[idx
+ 1];
22899 /* Optimize only if there are at least two consecutive define/undef ops,
22900 and either all of them are before first DW_MACINFO_start_file
22901 with lineno {0,1} (i.e. predefined macro block), or all of them are
22902 in some included header file. */
22903 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
22905 if (vec_safe_is_empty (files
))
22907 if (first
->lineno
> 1 || second
->lineno
> 1)
22910 else if (first
->lineno
== 0)
22913 /* Find the last define/undef entry that can be grouped together
22914 with first and at the same time compute md5 checksum of their
22915 codes, linenumbers and strings. */
22916 md5_init_ctx (&ctx
);
22917 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
22918 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
22920 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
22924 unsigned char code
= cur
->code
;
22925 md5_process_bytes (&code
, 1, &ctx
);
22926 checksum_uleb128 (cur
->lineno
, &ctx
);
22927 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
22929 md5_finish_ctx (&ctx
, checksum
);
22932 /* From the containing include filename (if any) pick up just
22933 usable characters from its basename. */
22934 if (vec_safe_is_empty (files
))
22937 base
= lbasename (files
->last ().info
);
22938 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
22939 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22940 encoded_filename_len
++;
22941 /* Count . at the end. */
22942 if (encoded_filename_len
)
22943 encoded_filename_len
++;
22945 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
22946 linebuf_len
= strlen (linebuf
);
22948 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
22949 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
22951 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
22952 tail
= grp_name
+ 4;
22953 if (encoded_filename_len
)
22955 for (i
= 0; base
[i
]; i
++)
22956 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22960 memcpy (tail
, linebuf
, linebuf_len
);
22961 tail
+= linebuf_len
;
22963 for (i
= 0; i
< 16; i
++)
22964 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
22966 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
22967 in the empty vector entry before the first define/undef. */
22968 inc
= &(*macinfo_table
)[idx
- 1];
22969 inc
->code
= DW_MACRO_GNU_transparent_include
;
22971 inc
->info
= ggc_strdup (grp_name
);
22972 if (!*macinfo_htab
)
22973 *macinfo_htab
= new macinfo_hash_type (10);
22974 /* Avoid emitting duplicates. */
22975 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
22980 /* If such an entry has been used before, just emit
22981 a DW_MACRO_GNU_transparent_include op. */
22983 output_macinfo_op (inc
);
22984 /* And clear all macinfo_entry in the range to avoid emitting them
22985 in the second pass. */
22986 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
22995 inc
->lineno
= (*macinfo_htab
)->elements ();
22996 output_macinfo_op (inc
);
23001 /* Save any strings needed by the macinfo table in the debug str
23002 table. All strings must be collected into the table by the time
23003 index_string is called. */
23006 save_macinfo_strings (void)
23010 macinfo_entry
*ref
;
23012 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
23016 /* Match the logic in output_macinfo_op to decide on
23017 indirect strings. */
23018 case DW_MACINFO_define
:
23019 case DW_MACINFO_undef
:
23020 len
= strlen (ref
->info
) + 1;
23022 && len
> DWARF_OFFSET_SIZE
23023 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
23024 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
23025 set_indirect_string (find_AT_string (ref
->info
));
23027 case DW_MACRO_GNU_define_indirect
:
23028 case DW_MACRO_GNU_undef_indirect
:
23029 set_indirect_string (find_AT_string (ref
->info
));
23037 /* Output macinfo section(s). */
23040 output_macinfo (void)
23043 unsigned long length
= vec_safe_length (macinfo_table
);
23044 macinfo_entry
*ref
;
23045 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
23046 macinfo_hash_type
*macinfo_htab
= NULL
;
23051 /* output_macinfo* uses these interchangeably. */
23052 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
23053 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
23054 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
23055 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
23057 /* For .debug_macro emit the section header. */
23060 dw2_asm_output_data (2, 4, "DWARF macro version number");
23061 if (DWARF_OFFSET_SIZE
== 8)
23062 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
23064 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
23065 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
23066 (!dwarf_split_debug_info
? debug_line_section_label
23067 : debug_skeleton_line_section_label
),
23068 debug_line_section
, NULL
);
23071 /* In the first loop, it emits the primary .debug_macinfo section
23072 and after each emitted op the macinfo_entry is cleared.
23073 If a longer range of define/undef ops can be optimized using
23074 DW_MACRO_GNU_transparent_include, the
23075 DW_MACRO_GNU_transparent_include op is emitted and kept in
23076 the vector before the first define/undef in the range and the
23077 whole range of define/undef ops is not emitted and kept. */
23078 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
23082 case DW_MACINFO_start_file
:
23083 vec_safe_push (files
, *ref
);
23085 case DW_MACINFO_end_file
:
23086 if (!vec_safe_is_empty (files
))
23089 case DW_MACINFO_define
:
23090 case DW_MACINFO_undef
:
23092 && HAVE_COMDAT_GROUP
23093 && vec_safe_length (files
) != 1
23096 && (*macinfo_table
)[i
- 1].code
== 0)
23098 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
23107 /* A dummy entry may be inserted at the beginning to be able
23108 to optimize the whole block of predefined macros. */
23114 output_macinfo_op (ref
);
23122 delete macinfo_htab
;
23123 macinfo_htab
= NULL
;
23125 /* If any DW_MACRO_GNU_transparent_include were used, on those
23126 DW_MACRO_GNU_transparent_include entries terminate the
23127 current chain and switch to a new comdat .debug_macinfo
23128 section and emit the define/undef entries within it. */
23129 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
23134 case DW_MACRO_GNU_transparent_include
:
23136 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23137 tree comdat_key
= get_identifier (ref
->info
);
23138 /* Terminate the previous .debug_macinfo section. */
23139 dw2_asm_output_data (1, 0, "End compilation unit");
23140 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
23142 | SECTION_LINKONCE
,
23144 ASM_GENERATE_INTERNAL_LABEL (label
,
23145 DEBUG_MACRO_SECTION_LABEL
,
23147 ASM_OUTPUT_LABEL (asm_out_file
, label
);
23150 dw2_asm_output_data (2, 4, "DWARF macro version number");
23151 if (DWARF_OFFSET_SIZE
== 8)
23152 dw2_asm_output_data (1, 1, "Flags: 64-bit");
23154 dw2_asm_output_data (1, 0, "Flags: 32-bit");
23157 case DW_MACINFO_define
:
23158 case DW_MACINFO_undef
:
23159 output_macinfo_op (ref
);
23164 gcc_unreachable ();
23168 /* Set up for Dwarf output at the start of compilation. */
23171 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
23173 /* This option is currently broken, see (PR53118 and PR46102). */
23174 if (flag_eliminate_dwarf2_dups
23175 && strstr (lang_hooks
.name
, "C++"))
23177 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
23178 flag_eliminate_dwarf2_dups
= 0;
23181 /* Allocate the file_table. */
23182 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
23184 /* Allocate the decl_die_table. */
23185 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
23187 /* Allocate the decl_loc_table. */
23188 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
23190 /* Allocate the cached_dw_loc_list_table. */
23191 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
23193 /* Allocate the initial hunk of the decl_scope_table. */
23194 vec_alloc (decl_scope_table
, 256);
23196 /* Allocate the initial hunk of the abbrev_die_table. */
23197 abbrev_die_table
= ggc_cleared_vec_alloc
<dw_die_ref
>
23198 (ABBREV_DIE_TABLE_INCREMENT
);
23199 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
23200 /* Zero-th entry is allocated, but unused. */
23201 abbrev_die_table_in_use
= 1;
23203 /* Allocate the pubtypes and pubnames vectors. */
23204 vec_alloc (pubname_table
, 32);
23205 vec_alloc (pubtype_table
, 32);
23207 vec_alloc (incomplete_types
, 64);
23209 vec_alloc (used_rtx_array
, 32);
23211 if (!dwarf_split_debug_info
)
23213 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
23214 SECTION_DEBUG
, NULL
);
23215 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
23216 SECTION_DEBUG
, NULL
);
23217 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
23218 SECTION_DEBUG
, NULL
);
23222 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
23223 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23224 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
23225 SECTION_DEBUG
| SECTION_EXCLUDE
,
23227 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
23228 SECTION_DEBUG
, NULL
);
23229 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
23230 SECTION_DEBUG
, NULL
);
23231 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
23232 SECTION_DEBUG
, NULL
);
23233 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
23234 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
23236 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
23237 the main .o, but the skeleton_line goes into the split off dwo. */
23238 debug_skeleton_line_section
23239 = get_section (DEBUG_DWO_LINE_SECTION
,
23240 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23241 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
23242 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
23243 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
23244 SECTION_DEBUG
| SECTION_EXCLUDE
,
23246 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
23247 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
23248 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
23249 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23250 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
23251 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
23253 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
23254 SECTION_DEBUG
, NULL
);
23255 debug_macinfo_section
= get_section (dwarf_strict
23256 ? DEBUG_MACINFO_SECTION
23257 : DEBUG_MACRO_SECTION
,
23258 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
23259 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
23260 SECTION_DEBUG
, NULL
);
23261 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
23262 SECTION_DEBUG
, NULL
);
23263 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
23264 SECTION_DEBUG
, NULL
);
23265 debug_str_section
= get_section (DEBUG_STR_SECTION
,
23266 DEBUG_STR_SECTION_FLAGS
, NULL
);
23267 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
23268 SECTION_DEBUG
, NULL
);
23269 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
23270 SECTION_DEBUG
, NULL
);
23272 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
23273 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
23274 DEBUG_ABBREV_SECTION_LABEL
, 0);
23275 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
23276 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
23277 COLD_TEXT_SECTION_LABEL
, 0);
23278 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
23280 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
23281 DEBUG_INFO_SECTION_LABEL
, 0);
23282 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
23283 DEBUG_LINE_SECTION_LABEL
, 0);
23284 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
23285 DEBUG_RANGES_SECTION_LABEL
, 0);
23286 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
23287 DEBUG_ADDR_SECTION_LABEL
, 0);
23288 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
23290 ? DEBUG_MACINFO_SECTION_LABEL
23291 : DEBUG_MACRO_SECTION_LABEL
, 0);
23292 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
23294 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
23295 vec_alloc (macinfo_table
, 64);
23297 switch_to_section (text_section
);
23298 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
23300 /* Make sure the line number table for .text always exists. */
23301 text_section_line_info
= new_line_info_table ();
23302 text_section_line_info
->end_label
= text_end_label
;
23304 /* If front-ends already registered a main translation unit but we were not
23305 ready to perform the association, do this now. */
23306 if (main_translation_unit
!= NULL_TREE
)
23307 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
23310 /* Called before compile () starts outputtting functions, variables
23311 and toplevel asms into assembly. */
23314 dwarf2out_assembly_start (void)
23316 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
23317 && dwarf2out_do_cfi_asm ()
23318 && (!(flag_unwind_tables
|| flag_exceptions
)
23319 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
23320 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
23323 /* A helper function for dwarf2out_finish called through
23324 htab_traverse. Assign a string its index. All strings must be
23325 collected into the table by the time index_string is called,
23326 because the indexing code relies on htab_traverse to traverse nodes
23327 in the same order for each run. */
23330 index_string (indirect_string_node
**h
, unsigned int *index
)
23332 indirect_string_node
*node
= *h
;
23334 find_string_form (node
);
23335 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23337 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
23338 node
->index
= *index
;
23344 /* A helper function for output_indirect_strings called through
23345 htab_traverse. Output the offset to a string and update the
23349 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
23351 indirect_string_node
*node
= *h
;
23353 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23355 /* Assert that this node has been assigned an index. */
23356 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
23357 && node
->index
!= NOT_INDEXED
);
23358 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
23359 "indexed string 0x%x: %s", node
->index
, node
->str
);
23360 *offset
+= strlen (node
->str
) + 1;
23365 /* A helper function for dwarf2out_finish called through
23366 htab_traverse. Output the indexed string. */
23369 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
23371 struct indirect_string_node
*node
= *h
;
23373 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23375 /* Assert that the strings are output in the same order as their
23376 indexes were assigned. */
23377 gcc_assert (*cur_idx
== node
->index
);
23378 assemble_string (node
->str
, strlen (node
->str
) + 1);
23384 /* A helper function for dwarf2out_finish called through
23385 htab_traverse. Emit one queued .debug_str string. */
23388 output_indirect_string (indirect_string_node
**h
, void *)
23390 struct indirect_string_node
*node
= *h
;
23392 node
->form
= find_string_form (node
);
23393 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
23395 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
23396 assemble_string (node
->str
, strlen (node
->str
) + 1);
23402 /* Output the indexed string table. */
23405 output_indirect_strings (void)
23407 switch_to_section (debug_str_section
);
23408 if (!dwarf_split_debug_info
)
23409 debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
23412 unsigned int offset
= 0;
23413 unsigned int cur_idx
= 0;
23415 skeleton_debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
23417 switch_to_section (debug_str_offsets_section
);
23418 debug_str_hash
->traverse_noresize
23419 <unsigned int *, output_index_string_offset
> (&offset
);
23420 switch_to_section (debug_str_dwo_section
);
23421 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
23426 /* Callback for htab_traverse to assign an index to an entry in the
23427 table, and to write that entry to the .debug_addr section. */
23430 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
23432 addr_table_entry
*entry
= *slot
;
23434 if (entry
->refcount
== 0)
23436 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
23437 || entry
->index
== NOT_INDEXED
);
23441 gcc_assert (entry
->index
== *cur_index
);
23444 switch (entry
->kind
)
23447 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
23448 "0x%x", entry
->index
);
23450 case ate_kind_rtx_dtprel
:
23451 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
23452 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
23455 fputc ('\n', asm_out_file
);
23457 case ate_kind_label
:
23458 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
23459 "0x%x", entry
->index
);
23462 gcc_unreachable ();
23467 /* Produce the .debug_addr section. */
23470 output_addr_table (void)
23472 unsigned int index
= 0;
23473 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
23476 switch_to_section (debug_addr_section
);
23478 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
23481 #if ENABLE_ASSERT_CHECKING
23482 /* Verify that all marks are clear. */
23485 verify_marks_clear (dw_die_ref die
)
23489 gcc_assert (! die
->die_mark
);
23490 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
23492 #endif /* ENABLE_ASSERT_CHECKING */
23494 /* Clear the marks for a die and its children.
23495 Be cool if the mark isn't set. */
23498 prune_unmark_dies (dw_die_ref die
)
23504 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
23507 /* Given DIE that we're marking as used, find any other dies
23508 it references as attributes and mark them as used. */
23511 prune_unused_types_walk_attribs (dw_die_ref die
)
23516 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23518 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
23520 /* A reference to another DIE.
23521 Make sure that it will get emitted.
23522 If it was broken out into a comdat group, don't follow it. */
23523 if (! AT_ref (a
)->comdat_type_p
23524 || a
->dw_attr
== DW_AT_specification
)
23525 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
23527 /* Set the string's refcount to 0 so that prune_unused_types_mark
23528 accounts properly for it. */
23529 if (AT_class (a
) == dw_val_class_str
)
23530 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
23534 /* Mark the generic parameters and arguments children DIEs of DIE. */
23537 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
23541 if (die
== NULL
|| die
->die_child
== NULL
)
23543 c
= die
->die_child
;
23546 if (is_template_parameter (c
))
23547 prune_unused_types_mark (c
, 1);
23549 } while (c
&& c
!= die
->die_child
);
23552 /* Mark DIE as being used. If DOKIDS is true, then walk down
23553 to DIE's children. */
23556 prune_unused_types_mark (dw_die_ref die
, int dokids
)
23560 if (die
->die_mark
== 0)
23562 /* We haven't done this node yet. Mark it as used. */
23564 /* If this is the DIE of a generic type instantiation,
23565 mark the children DIEs that describe its generic parms and
23567 prune_unused_types_mark_generic_parms_dies (die
);
23569 /* We also have to mark its parents as used.
23570 (But we don't want to mark our parent's kids due to this,
23571 unless it is a class.) */
23572 if (die
->die_parent
)
23573 prune_unused_types_mark (die
->die_parent
,
23574 class_scope_p (die
->die_parent
));
23576 /* Mark any referenced nodes. */
23577 prune_unused_types_walk_attribs (die
);
23579 /* If this node is a specification,
23580 also mark the definition, if it exists. */
23581 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
23582 prune_unused_types_mark (die
->die_definition
, 1);
23585 if (dokids
&& die
->die_mark
!= 2)
23587 /* We need to walk the children, but haven't done so yet.
23588 Remember that we've walked the kids. */
23591 /* If this is an array type, we need to make sure our
23592 kids get marked, even if they're types. If we're
23593 breaking out types into comdat sections, do this
23594 for all type definitions. */
23595 if (die
->die_tag
== DW_TAG_array_type
23596 || (use_debug_types
23597 && is_type_die (die
) && ! is_declaration_die (die
)))
23598 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
23600 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
23604 /* For local classes, look if any static member functions were emitted
23605 and if so, mark them. */
23608 prune_unused_types_walk_local_classes (dw_die_ref die
)
23612 if (die
->die_mark
== 2)
23615 switch (die
->die_tag
)
23617 case DW_TAG_structure_type
:
23618 case DW_TAG_union_type
:
23619 case DW_TAG_class_type
:
23622 case DW_TAG_subprogram
:
23623 if (!get_AT_flag (die
, DW_AT_declaration
)
23624 || die
->die_definition
!= NULL
)
23625 prune_unused_types_mark (die
, 1);
23632 /* Mark children. */
23633 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
23636 /* Walk the tree DIE and mark types that we actually use. */
23639 prune_unused_types_walk (dw_die_ref die
)
23643 /* Don't do anything if this node is already marked and
23644 children have been marked as well. */
23645 if (die
->die_mark
== 2)
23648 switch (die
->die_tag
)
23650 case DW_TAG_structure_type
:
23651 case DW_TAG_union_type
:
23652 case DW_TAG_class_type
:
23653 if (die
->die_perennial_p
)
23656 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
23657 if (c
->die_tag
== DW_TAG_subprogram
)
23660 /* Finding used static member functions inside of classes
23661 is needed just for local classes, because for other classes
23662 static member function DIEs with DW_AT_specification
23663 are emitted outside of the DW_TAG_*_type. If we ever change
23664 it, we'd need to call this even for non-local classes. */
23666 prune_unused_types_walk_local_classes (die
);
23668 /* It's a type node --- don't mark it. */
23671 case DW_TAG_const_type
:
23672 case DW_TAG_packed_type
:
23673 case DW_TAG_pointer_type
:
23674 case DW_TAG_reference_type
:
23675 case DW_TAG_rvalue_reference_type
:
23676 case DW_TAG_volatile_type
:
23677 case DW_TAG_typedef
:
23678 case DW_TAG_array_type
:
23679 case DW_TAG_interface_type
:
23680 case DW_TAG_friend
:
23681 case DW_TAG_variant_part
:
23682 case DW_TAG_enumeration_type
:
23683 case DW_TAG_subroutine_type
:
23684 case DW_TAG_string_type
:
23685 case DW_TAG_set_type
:
23686 case DW_TAG_subrange_type
:
23687 case DW_TAG_ptr_to_member_type
:
23688 case DW_TAG_file_type
:
23689 if (die
->die_perennial_p
)
23692 /* It's a type node --- don't mark it. */
23696 /* Mark everything else. */
23700 if (die
->die_mark
== 0)
23704 /* Now, mark any dies referenced from here. */
23705 prune_unused_types_walk_attribs (die
);
23710 /* Mark children. */
23711 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
23714 /* Increment the string counts on strings referred to from DIE's
23718 prune_unused_types_update_strings (dw_die_ref die
)
23723 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23724 if (AT_class (a
) == dw_val_class_str
)
23726 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
23728 /* Avoid unnecessarily putting strings that are used less than
23729 twice in the hash table. */
23731 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
23733 indirect_string_node
**slot
23734 = debug_str_hash
->find_slot_with_hash (s
->str
,
23735 htab_hash_string (s
->str
),
23737 gcc_assert (*slot
== NULL
);
23743 /* Remove from the tree DIE any dies that aren't marked. */
23746 prune_unused_types_prune (dw_die_ref die
)
23750 gcc_assert (die
->die_mark
);
23751 prune_unused_types_update_strings (die
);
23753 if (! die
->die_child
)
23756 c
= die
->die_child
;
23758 dw_die_ref prev
= c
;
23759 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
23760 if (c
== die
->die_child
)
23762 /* No marked children between 'prev' and the end of the list. */
23764 /* No marked children at all. */
23765 die
->die_child
= NULL
;
23768 prev
->die_sib
= c
->die_sib
;
23769 die
->die_child
= prev
;
23774 if (c
!= prev
->die_sib
)
23776 prune_unused_types_prune (c
);
23777 } while (c
!= die
->die_child
);
23780 /* Remove dies representing declarations that we never use. */
23783 prune_unused_types (void)
23786 limbo_die_node
*node
;
23787 comdat_type_node
*ctnode
;
23789 dw_die_ref base_type
;
23791 #if ENABLE_ASSERT_CHECKING
23792 /* All the marks should already be clear. */
23793 verify_marks_clear (comp_unit_die ());
23794 for (node
= limbo_die_list
; node
; node
= node
->next
)
23795 verify_marks_clear (node
->die
);
23796 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23797 verify_marks_clear (ctnode
->root_die
);
23798 #endif /* ENABLE_ASSERT_CHECKING */
23800 /* Mark types that are used in global variables. */
23801 premark_types_used_by_global_vars ();
23803 /* Set the mark on nodes that are actually used. */
23804 prune_unused_types_walk (comp_unit_die ());
23805 for (node
= limbo_die_list
; node
; node
= node
->next
)
23806 prune_unused_types_walk (node
->die
);
23807 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23809 prune_unused_types_walk (ctnode
->root_die
);
23810 prune_unused_types_mark (ctnode
->type_die
, 1);
23813 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
23814 are unusual in that they are pubnames that are the children of pubtypes.
23815 They should only be marked via their parent DW_TAG_enumeration_type die,
23816 not as roots in themselves. */
23817 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
23818 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
23819 prune_unused_types_mark (pub
->die
, 1);
23820 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
23821 prune_unused_types_mark (base_type
, 1);
23823 if (debug_str_hash
)
23824 debug_str_hash
->empty ();
23825 if (skeleton_debug_str_hash
)
23826 skeleton_debug_str_hash
->empty ();
23827 prune_unused_types_prune (comp_unit_die ());
23828 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
23831 if (!node
->die
->die_mark
)
23832 *pnode
= node
->next
;
23835 prune_unused_types_prune (node
->die
);
23836 pnode
= &node
->next
;
23839 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23840 prune_unused_types_prune (ctnode
->root_die
);
23842 /* Leave the marks clear. */
23843 prune_unmark_dies (comp_unit_die ());
23844 for (node
= limbo_die_list
; node
; node
= node
->next
)
23845 prune_unmark_dies (node
->die
);
23846 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23847 prune_unmark_dies (ctnode
->root_die
);
23850 /* Set the parameter to true if there are any relative pathnames in
23853 file_table_relative_p (dwarf_file_data
**slot
, bool *p
)
23855 struct dwarf_file_data
*d
= *slot
;
23856 if (!IS_ABSOLUTE_PATH (d
->filename
))
23864 /* Helpers to manipulate hash table of comdat type units. */
23866 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
23868 static inline hashval_t
hash (const comdat_type_node
*);
23869 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
23873 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
23876 memcpy (&h
, type_node
->signature
, sizeof (h
));
23881 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
23882 const comdat_type_node
*type_node_2
)
23884 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
23885 DWARF_TYPE_SIGNATURE_SIZE
));
23888 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
23889 to the location it would have been added, should we know its
23890 DECL_ASSEMBLER_NAME when we added other attributes. This will
23891 probably improve compactness of debug info, removing equivalent
23892 abbrevs, and hide any differences caused by deferring the
23893 computation of the assembler name, triggered by e.g. PCH. */
23896 move_linkage_attr (dw_die_ref die
)
23898 unsigned ix
= vec_safe_length (die
->die_attr
);
23899 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
23901 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
23902 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
23906 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
23908 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
23912 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
23914 die
->die_attr
->pop ();
23915 die
->die_attr
->quick_insert (ix
, linkage
);
23919 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
23920 referenced from typed stack ops and count how often they are used. */
23923 mark_base_types (dw_loc_descr_ref loc
)
23925 dw_die_ref base_type
= NULL
;
23927 for (; loc
; loc
= loc
->dw_loc_next
)
23929 switch (loc
->dw_loc_opc
)
23931 case DW_OP_GNU_regval_type
:
23932 case DW_OP_GNU_deref_type
:
23933 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23935 case DW_OP_GNU_convert
:
23936 case DW_OP_GNU_reinterpret
:
23937 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
23940 case DW_OP_GNU_const_type
:
23941 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23943 case DW_OP_GNU_entry_value
:
23944 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
23949 gcc_assert (base_type
->die_parent
== comp_unit_die ());
23950 if (base_type
->die_mark
)
23951 base_type
->die_mark
++;
23954 base_types
.safe_push (base_type
);
23955 base_type
->die_mark
= 1;
23960 /* Comparison function for sorting marked base types. */
23963 base_type_cmp (const void *x
, const void *y
)
23965 dw_die_ref dx
= *(const dw_die_ref
*) x
;
23966 dw_die_ref dy
= *(const dw_die_ref
*) y
;
23967 unsigned int byte_size1
, byte_size2
;
23968 unsigned int encoding1
, encoding2
;
23969 if (dx
->die_mark
> dy
->die_mark
)
23971 if (dx
->die_mark
< dy
->die_mark
)
23973 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
23974 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
23975 if (byte_size1
< byte_size2
)
23977 if (byte_size1
> byte_size2
)
23979 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
23980 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
23981 if (encoding1
< encoding2
)
23983 if (encoding1
> encoding2
)
23988 /* Move base types marked by mark_base_types as early as possible
23989 in the CU, sorted by decreasing usage count both to make the
23990 uleb128 references as small as possible and to make sure they
23991 will have die_offset already computed by calc_die_sizes when
23992 sizes of typed stack loc ops is computed. */
23995 move_marked_base_types (void)
23998 dw_die_ref base_type
, die
, c
;
24000 if (base_types
.is_empty ())
24003 /* Sort by decreasing usage count, they will be added again in that
24005 base_types
.qsort (base_type_cmp
);
24006 die
= comp_unit_die ();
24007 c
= die
->die_child
;
24010 dw_die_ref prev
= c
;
24012 while (c
->die_mark
)
24014 remove_child_with_prev (c
, prev
);
24015 /* As base types got marked, there must be at least
24016 one node other than DW_TAG_base_type. */
24017 gcc_assert (c
!= c
->die_sib
);
24021 while (c
!= die
->die_child
);
24022 gcc_assert (die
->die_child
);
24023 c
= die
->die_child
;
24024 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
24026 base_type
->die_mark
= 0;
24027 base_type
->die_sib
= c
->die_sib
;
24028 c
->die_sib
= base_type
;
24033 /* Helper function for resolve_addr, attempt to resolve
24034 one CONST_STRING, return true if successful. Similarly verify that
24035 SYMBOL_REFs refer to variables emitted in the current CU. */
24038 resolve_one_addr (rtx
*addr
)
24042 if (GET_CODE (rtl
) == CONST_STRING
)
24044 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
24045 tree t
= build_string (len
, XSTR (rtl
, 0));
24046 tree tlen
= size_int (len
- 1);
24048 = build_array_type (char_type_node
, build_index_type (tlen
));
24049 rtl
= lookup_constant_def (t
);
24050 if (!rtl
|| !MEM_P (rtl
))
24052 rtl
= XEXP (rtl
, 0);
24053 if (GET_CODE (rtl
) == SYMBOL_REF
24054 && SYMBOL_REF_DECL (rtl
)
24055 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
24057 vec_safe_push (used_rtx_array
, rtl
);
24062 if (GET_CODE (rtl
) == SYMBOL_REF
24063 && SYMBOL_REF_DECL (rtl
))
24065 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
24067 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
24070 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
24074 if (GET_CODE (rtl
) == CONST
)
24076 subrtx_ptr_iterator::array_type array
;
24077 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
24078 if (!resolve_one_addr (*iter
))
24085 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
24086 if possible, and create DW_TAG_dwarf_procedure that can be referenced
24087 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
24090 string_cst_pool_decl (tree t
)
24092 rtx rtl
= output_constant_def (t
, 1);
24093 unsigned char *array
;
24094 dw_loc_descr_ref l
;
24099 if (!rtl
|| !MEM_P (rtl
))
24101 rtl
= XEXP (rtl
, 0);
24102 if (GET_CODE (rtl
) != SYMBOL_REF
24103 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
24106 decl
= SYMBOL_REF_DECL (rtl
);
24107 if (!lookup_decl_die (decl
))
24109 len
= TREE_STRING_LENGTH (t
);
24110 vec_safe_push (used_rtx_array
, rtl
);
24111 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
24112 array
= ggc_vec_alloc
<unsigned char> (len
);
24113 memcpy (array
, TREE_STRING_POINTER (t
), len
);
24114 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
24115 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
24116 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
24117 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
24118 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
24119 add_AT_loc (ref
, DW_AT_location
, l
);
24120 equate_decl_number_to_die (decl
, ref
);
24125 /* Helper function of resolve_addr_in_expr. LOC is
24126 a DW_OP_addr followed by DW_OP_stack_value, either at the start
24127 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
24128 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
24129 with DW_OP_GNU_implicit_pointer if possible
24130 and return true, if unsuccessful, return false. */
24133 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
24135 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
24136 HOST_WIDE_INT offset
= 0;
24137 dw_die_ref ref
= NULL
;
24140 if (GET_CODE (rtl
) == CONST
24141 && GET_CODE (XEXP (rtl
, 0)) == PLUS
24142 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
24144 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
24145 rtl
= XEXP (XEXP (rtl
, 0), 0);
24147 if (GET_CODE (rtl
) == CONST_STRING
)
24149 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
24150 tree t
= build_string (len
, XSTR (rtl
, 0));
24151 tree tlen
= size_int (len
- 1);
24154 = build_array_type (char_type_node
, build_index_type (tlen
));
24155 rtl
= string_cst_pool_decl (t
);
24159 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
24161 decl
= SYMBOL_REF_DECL (rtl
);
24162 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
24164 ref
= lookup_decl_die (decl
);
24165 if (ref
&& (get_AT (ref
, DW_AT_location
)
24166 || get_AT (ref
, DW_AT_const_value
)))
24168 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
24169 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24170 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
24171 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24172 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24173 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
24174 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
24182 /* Helper function for resolve_addr, handle one location
24183 expression, return false if at least one CONST_STRING or SYMBOL_REF in
24184 the location list couldn't be resolved. */
24187 resolve_addr_in_expr (dw_loc_descr_ref loc
)
24189 dw_loc_descr_ref keep
= NULL
;
24190 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
24191 switch (loc
->dw_loc_opc
)
24194 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
24197 || prev
->dw_loc_opc
== DW_OP_piece
24198 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
24199 && loc
->dw_loc_next
24200 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
24202 && optimize_one_addr_into_implicit_ptr (loc
))
24207 case DW_OP_GNU_addr_index
:
24208 case DW_OP_GNU_const_index
:
24209 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
24210 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
24212 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
24213 if (!resolve_one_addr (&rtl
))
24215 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
24216 loc
->dw_loc_oprnd1
.val_entry
=
24217 add_addr_table_entry (rtl
, ate_kind_rtx
);
24220 case DW_OP_const4u
:
24221 case DW_OP_const8u
:
24223 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
24226 case DW_OP_plus_uconst
:
24227 if (size_of_loc_descr (loc
)
24228 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
24230 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
24232 dw_loc_descr_ref repl
24233 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
24234 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
24235 add_loc_descr (&repl
, loc
->dw_loc_next
);
24239 case DW_OP_implicit_value
:
24240 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
24241 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
24244 case DW_OP_GNU_implicit_pointer
:
24245 case DW_OP_GNU_parameter_ref
:
24246 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
24249 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
24252 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24253 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24254 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24257 case DW_OP_GNU_const_type
:
24258 case DW_OP_GNU_regval_type
:
24259 case DW_OP_GNU_deref_type
:
24260 case DW_OP_GNU_convert
:
24261 case DW_OP_GNU_reinterpret
:
24262 while (loc
->dw_loc_next
24263 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
24265 dw_die_ref base1
, base2
;
24266 unsigned enc1
, enc2
, size1
, size2
;
24267 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
24268 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
24269 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
24270 else if (loc
->dw_loc_oprnd1
.val_class
24271 == dw_val_class_unsigned_const
)
24274 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
24275 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
24276 == dw_val_class_unsigned_const
)
24278 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
24279 gcc_assert (base1
->die_tag
== DW_TAG_base_type
24280 && base2
->die_tag
== DW_TAG_base_type
);
24281 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
24282 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
24283 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
24284 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
24286 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
24287 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
24291 /* Optimize away next DW_OP_GNU_convert after
24292 adjusting LOC's base type die reference. */
24293 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
24294 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
24295 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
24297 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
24298 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
24301 /* Don't change integer DW_OP_GNU_convert after e.g. floating
24302 point typed stack entry. */
24303 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
24304 keep
= loc
->dw_loc_next
;
24314 /* Helper function of resolve_addr. DIE had DW_AT_location of
24315 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
24316 and DW_OP_addr couldn't be resolved. resolve_addr has already
24317 removed the DW_AT_location attribute. This function attempts to
24318 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
24319 to it or DW_AT_const_value attribute, if possible. */
24322 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
24324 if (TREE_CODE (decl
) != VAR_DECL
24325 || lookup_decl_die (decl
) != die
24326 || DECL_EXTERNAL (decl
)
24327 || !TREE_STATIC (decl
)
24328 || DECL_INITIAL (decl
) == NULL_TREE
24329 || DECL_P (DECL_INITIAL (decl
))
24330 || get_AT (die
, DW_AT_const_value
))
24333 tree init
= DECL_INITIAL (decl
);
24334 HOST_WIDE_INT offset
= 0;
24335 /* For variables that have been optimized away and thus
24336 don't have a memory location, see if we can emit
24337 DW_AT_const_value instead. */
24338 if (tree_add_const_value_attribute (die
, init
))
24342 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
24343 and ADDR_EXPR refers to a decl that has DW_AT_location or
24344 DW_AT_const_value (but isn't addressable, otherwise
24345 resolving the original DW_OP_addr wouldn't fail), see if
24346 we can add DW_OP_GNU_implicit_pointer. */
24348 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
24349 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
24351 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
24352 init
= TREE_OPERAND (init
, 0);
24355 if (TREE_CODE (init
) != ADDR_EXPR
)
24357 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
24358 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
24359 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
24360 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
24361 && TREE_OPERAND (init
, 0) != decl
))
24364 dw_loc_descr_ref l
;
24366 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
24368 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
24371 decl
= SYMBOL_REF_DECL (rtl
);
24374 decl
= TREE_OPERAND (init
, 0);
24375 ref
= lookup_decl_die (decl
);
24377 || (!get_AT (ref
, DW_AT_location
)
24378 && !get_AT (ref
, DW_AT_const_value
)))
24380 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
24381 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24382 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24383 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24384 add_AT_loc (die
, DW_AT_location
, l
);
24388 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
24389 an address in .rodata section if the string literal is emitted there,
24390 or remove the containing location list or replace DW_AT_const_value
24391 with DW_AT_location and empty location expression, if it isn't found
24392 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
24393 to something that has been emitted in the current CU. */
24396 resolve_addr (dw_die_ref die
)
24400 dw_loc_list_ref
*curr
, *start
, loc
;
24403 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
24404 switch (AT_class (a
))
24406 case dw_val_class_loc_list
:
24407 start
= curr
= AT_loc_list_ptr (a
);
24410 /* The same list can be referenced more than once. See if we have
24411 already recorded the result from a previous pass. */
24413 *curr
= loc
->dw_loc_next
;
24414 else if (!loc
->resolved_addr
)
24416 /* As things stand, we do not expect or allow one die to
24417 reference a suffix of another die's location list chain.
24418 References must be identical or completely separate.
24419 There is therefore no need to cache the result of this
24420 pass on any list other than the first; doing so
24421 would lead to unnecessary writes. */
24424 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
24425 if (!resolve_addr_in_expr ((*curr
)->expr
))
24427 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
24428 dw_loc_descr_ref l
= (*curr
)->expr
;
24430 if (next
&& (*curr
)->ll_symbol
)
24432 gcc_assert (!next
->ll_symbol
);
24433 next
->ll_symbol
= (*curr
)->ll_symbol
;
24435 if (dwarf_split_debug_info
)
24436 remove_loc_list_addr_table_entries (l
);
24441 mark_base_types ((*curr
)->expr
);
24442 curr
= &(*curr
)->dw_loc_next
;
24446 loc
->resolved_addr
= 1;
24450 loc
->dw_loc_next
= *start
;
24455 remove_AT (die
, a
->dw_attr
);
24459 case dw_val_class_loc
:
24461 dw_loc_descr_ref l
= AT_loc (a
);
24462 /* For -gdwarf-2 don't attempt to optimize
24463 DW_AT_data_member_location containing
24464 DW_OP_plus_uconst - older consumers might
24465 rely on it being that op instead of a more complex,
24466 but shorter, location description. */
24467 if ((dwarf_version
> 2
24468 || a
->dw_attr
!= DW_AT_data_member_location
24470 || l
->dw_loc_opc
!= DW_OP_plus_uconst
24471 || l
->dw_loc_next
!= NULL
)
24472 && !resolve_addr_in_expr (l
))
24474 if (dwarf_split_debug_info
)
24475 remove_loc_list_addr_table_entries (l
);
24477 && l
->dw_loc_next
== NULL
24478 && l
->dw_loc_opc
== DW_OP_addr
24479 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
24480 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
24481 && a
->dw_attr
== DW_AT_location
)
24483 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
24484 remove_AT (die
, a
->dw_attr
);
24486 optimize_location_into_implicit_ptr (die
, decl
);
24489 remove_AT (die
, a
->dw_attr
);
24493 mark_base_types (l
);
24496 case dw_val_class_addr
:
24497 if (a
->dw_attr
== DW_AT_const_value
24498 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
24500 if (AT_index (a
) != NOT_INDEXED
)
24501 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
24502 remove_AT (die
, a
->dw_attr
);
24505 if (die
->die_tag
== DW_TAG_GNU_call_site
24506 && a
->dw_attr
== DW_AT_abstract_origin
)
24508 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
24509 dw_die_ref tdie
= lookup_decl_die (tdecl
);
24512 && DECL_EXTERNAL (tdecl
)
24513 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
24514 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
24516 /* Creating a full DIE for tdecl is overly expensive and
24517 at this point even wrong when in the LTO phase
24518 as it can end up generating new type DIEs we didn't
24519 output and thus optimize_external_refs will crash. */
24520 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
24521 add_AT_flag (tdie
, DW_AT_external
, 1);
24522 add_AT_flag (tdie
, DW_AT_declaration
, 1);
24523 add_linkage_attr (tdie
, tdecl
);
24524 add_name_and_src_coords_attributes (tdie
, tdecl
);
24525 equate_decl_number_to_die (tdecl
, tdie
);
24529 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
24530 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
24531 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
24535 if (AT_index (a
) != NOT_INDEXED
)
24536 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
24537 remove_AT (die
, a
->dw_attr
);
24546 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
24549 /* Helper routines for optimize_location_lists.
24550 This pass tries to share identical local lists in .debug_loc
24553 /* Iteratively hash operands of LOC opcode into HSTATE. */
24556 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
24558 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
24559 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
24561 switch (loc
->dw_loc_opc
)
24563 case DW_OP_const4u
:
24564 case DW_OP_const8u
:
24568 case DW_OP_const1u
:
24569 case DW_OP_const1s
:
24570 case DW_OP_const2u
:
24571 case DW_OP_const2s
:
24572 case DW_OP_const4s
:
24573 case DW_OP_const8s
:
24577 case DW_OP_plus_uconst
:
24613 case DW_OP_deref_size
:
24614 case DW_OP_xderef_size
:
24615 hstate
.add_object (val1
->v
.val_int
);
24622 gcc_assert (val1
->val_class
== dw_val_class_loc
);
24623 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
24624 hstate
.add_object (offset
);
24627 case DW_OP_implicit_value
:
24628 hstate
.add_object (val1
->v
.val_unsigned
);
24629 switch (val2
->val_class
)
24631 case dw_val_class_const
:
24632 hstate
.add_object (val2
->v
.val_int
);
24634 case dw_val_class_vec
:
24636 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
24637 unsigned int len
= val2
->v
.val_vec
.length
;
24639 hstate
.add_int (elt_size
);
24640 hstate
.add_int (len
);
24641 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
24644 case dw_val_class_const_double
:
24645 hstate
.add_object (val2
->v
.val_double
.low
);
24646 hstate
.add_object (val2
->v
.val_double
.high
);
24648 case dw_val_class_wide_int
:
24649 hstate
.add (val2
->v
.val_wide
->get_val (),
24650 get_full_len (*val2
->v
.val_wide
)
24651 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
24653 case dw_val_class_addr
:
24654 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
24657 gcc_unreachable ();
24661 case DW_OP_bit_piece
:
24662 hstate
.add_object (val1
->v
.val_int
);
24663 hstate
.add_object (val2
->v
.val_int
);
24669 unsigned char dtprel
= 0xd1;
24670 hstate
.add_object (dtprel
);
24672 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
24674 case DW_OP_GNU_addr_index
:
24675 case DW_OP_GNU_const_index
:
24679 unsigned char dtprel
= 0xd1;
24680 hstate
.add_object (dtprel
);
24682 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
24685 case DW_OP_GNU_implicit_pointer
:
24686 hstate
.add_int (val2
->v
.val_int
);
24688 case DW_OP_GNU_entry_value
:
24689 hstate
.add_object (val1
->v
.val_loc
);
24691 case DW_OP_GNU_regval_type
:
24692 case DW_OP_GNU_deref_type
:
24694 unsigned int byte_size
24695 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
24696 unsigned int encoding
24697 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
24698 hstate
.add_object (val1
->v
.val_int
);
24699 hstate
.add_object (byte_size
);
24700 hstate
.add_object (encoding
);
24703 case DW_OP_GNU_convert
:
24704 case DW_OP_GNU_reinterpret
:
24705 if (val1
->val_class
== dw_val_class_unsigned_const
)
24707 hstate
.add_object (val1
->v
.val_unsigned
);
24711 case DW_OP_GNU_const_type
:
24713 unsigned int byte_size
24714 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
24715 unsigned int encoding
24716 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
24717 hstate
.add_object (byte_size
);
24718 hstate
.add_object (encoding
);
24719 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
24721 hstate
.add_object (val2
->val_class
);
24722 switch (val2
->val_class
)
24724 case dw_val_class_const
:
24725 hstate
.add_object (val2
->v
.val_int
);
24727 case dw_val_class_vec
:
24729 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
24730 unsigned int len
= val2
->v
.val_vec
.length
;
24732 hstate
.add_object (elt_size
);
24733 hstate
.add_object (len
);
24734 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
24737 case dw_val_class_const_double
:
24738 hstate
.add_object (val2
->v
.val_double
.low
);
24739 hstate
.add_object (val2
->v
.val_double
.high
);
24741 case dw_val_class_wide_int
:
24742 hstate
.add (val2
->v
.val_wide
->get_val (),
24743 get_full_len (*val2
->v
.val_wide
)
24744 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
24747 gcc_unreachable ();
24753 /* Other codes have no operands. */
24758 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
24761 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
24763 dw_loc_descr_ref l
;
24764 bool sizes_computed
= false;
24765 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
24766 size_of_locs (loc
);
24768 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
24770 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
24771 hstate
.add_object (opc
);
24772 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
24774 size_of_locs (loc
);
24775 sizes_computed
= true;
24777 hash_loc_operands (l
, hstate
);
24781 /* Compute hash of the whole location list LIST_HEAD. */
24784 hash_loc_list (dw_loc_list_ref list_head
)
24786 dw_loc_list_ref curr
= list_head
;
24787 inchash::hash hstate
;
24789 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
24791 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
24792 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
24794 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
24795 hash_locs (curr
->expr
, hstate
);
24797 list_head
->hash
= hstate
.end ();
24800 /* Return true if X and Y opcodes have the same operands. */
24803 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
24805 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
24806 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
24807 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
24808 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
24810 switch (x
->dw_loc_opc
)
24812 case DW_OP_const4u
:
24813 case DW_OP_const8u
:
24817 case DW_OP_const1u
:
24818 case DW_OP_const1s
:
24819 case DW_OP_const2u
:
24820 case DW_OP_const2s
:
24821 case DW_OP_const4s
:
24822 case DW_OP_const8s
:
24826 case DW_OP_plus_uconst
:
24862 case DW_OP_deref_size
:
24863 case DW_OP_xderef_size
:
24864 return valx1
->v
.val_int
== valy1
->v
.val_int
;
24867 /* If splitting debug info, the use of DW_OP_GNU_addr_index
24868 can cause irrelevant differences in dw_loc_addr. */
24869 gcc_assert (valx1
->val_class
== dw_val_class_loc
24870 && valy1
->val_class
== dw_val_class_loc
24871 && (dwarf_split_debug_info
24872 || x
->dw_loc_addr
== y
->dw_loc_addr
));
24873 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
24874 case DW_OP_implicit_value
:
24875 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
24876 || valx2
->val_class
!= valy2
->val_class
)
24878 switch (valx2
->val_class
)
24880 case dw_val_class_const
:
24881 return valx2
->v
.val_int
== valy2
->v
.val_int
;
24882 case dw_val_class_vec
:
24883 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
24884 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
24885 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
24886 valx2
->v
.val_vec
.elt_size
24887 * valx2
->v
.val_vec
.length
) == 0;
24888 case dw_val_class_const_double
:
24889 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
24890 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
24891 case dw_val_class_wide_int
:
24892 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
24893 case dw_val_class_addr
:
24894 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
24896 gcc_unreachable ();
24899 case DW_OP_bit_piece
:
24900 return valx1
->v
.val_int
== valy1
->v
.val_int
24901 && valx2
->v
.val_int
== valy2
->v
.val_int
;
24904 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
24905 case DW_OP_GNU_addr_index
:
24906 case DW_OP_GNU_const_index
:
24908 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
24909 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
24910 return rtx_equal_p (ax1
, ay1
);
24912 case DW_OP_GNU_implicit_pointer
:
24913 return valx1
->val_class
== dw_val_class_die_ref
24914 && valx1
->val_class
== valy1
->val_class
24915 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
24916 && valx2
->v
.val_int
== valy2
->v
.val_int
;
24917 case DW_OP_GNU_entry_value
:
24918 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
24919 case DW_OP_GNU_const_type
:
24920 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
24921 || valx2
->val_class
!= valy2
->val_class
)
24923 switch (valx2
->val_class
)
24925 case dw_val_class_const
:
24926 return valx2
->v
.val_int
== valy2
->v
.val_int
;
24927 case dw_val_class_vec
:
24928 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
24929 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
24930 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
24931 valx2
->v
.val_vec
.elt_size
24932 * valx2
->v
.val_vec
.length
) == 0;
24933 case dw_val_class_const_double
:
24934 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
24935 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
24936 case dw_val_class_wide_int
:
24937 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
24939 gcc_unreachable ();
24941 case DW_OP_GNU_regval_type
:
24942 case DW_OP_GNU_deref_type
:
24943 return valx1
->v
.val_int
== valy1
->v
.val_int
24944 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
24945 case DW_OP_GNU_convert
:
24946 case DW_OP_GNU_reinterpret
:
24947 if (valx1
->val_class
!= valy1
->val_class
)
24949 if (valx1
->val_class
== dw_val_class_unsigned_const
)
24950 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
24951 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
24952 case DW_OP_GNU_parameter_ref
:
24953 return valx1
->val_class
== dw_val_class_die_ref
24954 && valx1
->val_class
== valy1
->val_class
24955 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
24957 /* Other codes have no operands. */
24962 /* Return true if DWARF location expressions X and Y are the same. */
24965 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
24967 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
24968 if (x
->dw_loc_opc
!= y
->dw_loc_opc
24969 || x
->dtprel
!= y
->dtprel
24970 || !compare_loc_operands (x
, y
))
24972 return x
== NULL
&& y
== NULL
;
24975 /* Hashtable helpers. */
24977 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
24979 static inline hashval_t
hash (const dw_loc_list_struct
*);
24980 static inline bool equal (const dw_loc_list_struct
*,
24981 const dw_loc_list_struct
*);
24984 /* Return precomputed hash of location list X. */
24987 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
24992 /* Return true if location lists A and B are the same. */
24995 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
24996 const dw_loc_list_struct
*b
)
25000 if (a
->hash
!= b
->hash
)
25002 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
25003 if (strcmp (a
->begin
, b
->begin
) != 0
25004 || strcmp (a
->end
, b
->end
) != 0
25005 || (a
->section
== NULL
) != (b
->section
== NULL
)
25006 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
25007 || !compare_locs (a
->expr
, b
->expr
))
25009 return a
== NULL
&& b
== NULL
;
25012 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
25015 /* Recursively optimize location lists referenced from DIE
25016 children and share them whenever possible. */
25019 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
25024 dw_loc_list_struct
**slot
;
25026 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25027 if (AT_class (a
) == dw_val_class_loc_list
)
25029 dw_loc_list_ref list
= AT_loc_list (a
);
25030 /* TODO: perform some optimizations here, before hashing
25031 it and storing into the hash table. */
25032 hash_loc_list (list
);
25033 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
25037 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
25040 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
25044 /* Recursively assign each location list a unique index into the debug_addr
25048 index_location_lists (dw_die_ref die
)
25054 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25055 if (AT_class (a
) == dw_val_class_loc_list
)
25057 dw_loc_list_ref list
= AT_loc_list (a
);
25058 dw_loc_list_ref curr
;
25059 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
25061 /* Don't index an entry that has already been indexed
25062 or won't be output. */
25063 if (curr
->begin_entry
!= NULL
25064 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
25068 = add_addr_table_entry (xstrdup (curr
->begin
),
25073 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
25076 /* Optimize location lists referenced from DIE
25077 children and share them whenever possible. */
25080 optimize_location_lists (dw_die_ref die
)
25082 loc_list_hash_type
htab (500);
25083 optimize_location_lists_1 (die
, &htab
);
25086 /* Output stuff that dwarf requires at the end of every file,
25087 and generate the DWARF-2 debugging info. */
25090 dwarf2out_finish (const char *filename
)
25092 comdat_type_node
*ctnode
;
25093 dw_die_ref main_comp_unit_die
;
25095 /* Flush out any latecomers to the limbo party. */
25096 dwarf2out_early_finish ();
25098 /* PCH might result in DW_AT_producer string being restored from the
25099 header compilation, so always fill it with empty string initially
25100 and overwrite only here. */
25101 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
25102 producer_string
= gen_producer_string ();
25103 producer
->dw_attr_val
.v
.val_str
->refcount
--;
25104 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
25106 gen_scheduled_generic_parms_dies ();
25107 gen_remaining_tmpl_value_param_die_attribute ();
25109 /* Add the name for the main input file now. We delayed this from
25110 dwarf2out_init to avoid complications with PCH.
25111 For LTO produced units use a fixed artificial name to avoid
25112 leaking tempfile names into the dwarf. */
25114 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
25116 add_name_attribute (comp_unit_die (), "<artificial>");
25117 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
25118 add_comp_dir_attribute (comp_unit_die ());
25119 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
25122 file_table
->traverse
<bool *, file_table_relative_p
> (&p
);
25124 add_comp_dir_attribute (comp_unit_die ());
25127 #if ENABLE_ASSERT_CHECKING
25129 dw_die_ref die
= comp_unit_die (), c
;
25130 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
25133 resolve_addr (comp_unit_die ());
25134 move_marked_base_types ();
25136 /* Walk through the list of incomplete types again, trying once more to
25137 emit full debugging info for them. */
25138 retry_incomplete_types ();
25140 if (flag_eliminate_unused_debug_types
)
25141 prune_unused_types ();
25143 /* Generate separate COMDAT sections for type DIEs. */
25144 if (use_debug_types
)
25146 break_out_comdat_types (comp_unit_die ());
25148 /* Each new type_unit DIE was added to the limbo die list when created.
25149 Since these have all been added to comdat_type_list, clear the
25151 limbo_die_list
= NULL
;
25153 /* For each new comdat type unit, copy declarations for incomplete
25154 types to make the new unit self-contained (i.e., no direct
25155 references to the main compile unit). */
25156 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25157 copy_decls_for_unworthy_types (ctnode
->root_die
);
25158 copy_decls_for_unworthy_types (comp_unit_die ());
25160 /* In the process of copying declarations from one unit to another,
25161 we may have left some declarations behind that are no longer
25162 referenced. Prune them. */
25163 prune_unused_types ();
25166 /* Generate separate CUs for each of the include files we've seen.
25167 They will go into limbo_die_list. */
25168 if (flag_eliminate_dwarf2_dups
)
25169 break_out_includes (comp_unit_die ());
25171 /* Traverse the DIE's and add add sibling attributes to those DIE's
25172 that have children. */
25173 add_sibling_attributes (comp_unit_die ());
25174 limbo_die_node
*node
;
25175 for (node
= limbo_die_list
; node
; node
= node
->next
)
25176 add_sibling_attributes (node
->die
);
25177 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25178 add_sibling_attributes (ctnode
->root_die
);
25180 /* When splitting DWARF info, we put some attributes in the
25181 skeleton compile_unit DIE that remains in the .o, while
25182 most attributes go in the DWO compile_unit_die. */
25183 if (dwarf_split_debug_info
)
25184 main_comp_unit_die
= gen_compile_unit_die (NULL
);
25186 main_comp_unit_die
= comp_unit_die ();
25188 /* Output a terminator label for the .text section. */
25189 switch_to_section (text_section
);
25190 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
25191 if (cold_text_section
)
25193 switch_to_section (cold_text_section
);
25194 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
25197 /* We can only use the low/high_pc attributes if all of the code was
25199 if (!have_multiple_function_sections
25200 || (dwarf_version
< 3 && dwarf_strict
))
25202 /* Don't add if the CU has no associated code. */
25203 if (text_section_used
)
25204 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
25205 text_end_label
, true);
25211 bool range_list_added
= false;
25213 if (text_section_used
)
25214 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
25215 text_end_label
, &range_list_added
, true);
25216 if (cold_text_section_used
)
25217 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
25218 cold_end_label
, &range_list_added
, true);
25220 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
25222 if (DECL_IGNORED_P (fde
->decl
))
25224 if (!fde
->in_std_section
)
25225 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
25226 fde
->dw_fde_end
, &range_list_added
,
25228 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
25229 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
25230 fde
->dw_fde_second_end
, &range_list_added
,
25234 if (range_list_added
)
25236 /* We need to give .debug_loc and .debug_ranges an appropriate
25237 "base address". Use zero so that these addresses become
25238 absolute. Historically, we've emitted the unexpected
25239 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
25240 Emit both to give time for other tools to adapt. */
25241 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
25242 if (! dwarf_strict
&& dwarf_version
< 4)
25243 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
25249 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
25250 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
25251 debug_line_section_label
);
25254 add_AT_macptr (comp_unit_die (),
25255 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
25256 macinfo_section_label
);
25258 if (dwarf_split_debug_info
)
25260 /* optimize_location_lists calculates the size of the lists,
25261 so index them first, and assign indices to the entries.
25262 Although optimize_location_lists will remove entries from
25263 the table, it only does so for duplicates, and therefore
25264 only reduces ref_counts to 1. */
25265 index_location_lists (comp_unit_die ());
25267 if (addr_index_table
!= NULL
)
25269 unsigned int index
= 0;
25271 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
25276 if (have_location_lists
)
25277 optimize_location_lists (comp_unit_die ());
25279 save_macinfo_strings ();
25281 if (dwarf_split_debug_info
)
25283 unsigned int index
= 0;
25285 /* Add attributes common to skeleton compile_units and
25286 type_units. Because these attributes include strings, it
25287 must be done before freezing the string table. Top-level
25288 skeleton die attrs are added when the skeleton type unit is
25289 created, so ensure it is created by this point. */
25290 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
25291 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
25294 /* Output all of the compilation units. We put the main one last so that
25295 the offsets are available to output_pubnames. */
25296 for (node
= limbo_die_list
; node
; node
= node
->next
)
25297 output_comp_unit (node
->die
, 0);
25299 hash_table
<comdat_type_hasher
> comdat_type_table (100);
25300 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25302 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
25304 /* Don't output duplicate types. */
25305 if (*slot
!= HTAB_EMPTY_ENTRY
)
25308 /* Add a pointer to the line table for the main compilation unit
25309 so that the debugger can make sense of DW_AT_decl_file
25311 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
25312 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
25313 (!dwarf_split_debug_info
25314 ? debug_line_section_label
25315 : debug_skeleton_line_section_label
));
25317 output_comdat_type_unit (ctnode
);
25321 /* The AT_pubnames attribute needs to go in all skeleton dies, including
25322 both the main_cu and all skeleton TUs. Making this call unconditional
25323 would end up either adding a second copy of the AT_pubnames attribute, or
25324 requiring a special case in add_top_level_skeleton_die_attrs. */
25325 if (!dwarf_split_debug_info
)
25326 add_AT_pubnames (comp_unit_die ());
25328 if (dwarf_split_debug_info
)
25331 unsigned char checksum
[16];
25332 struct md5_ctx ctx
;
25334 /* Compute a checksum of the comp_unit to use as the dwo_id. */
25335 md5_init_ctx (&ctx
);
25337 die_checksum (comp_unit_die (), &ctx
, &mark
);
25338 unmark_all_dies (comp_unit_die ());
25339 md5_finish_ctx (&ctx
, checksum
);
25341 /* Use the first 8 bytes of the checksum as the dwo_id,
25342 and add it to both comp-unit DIEs. */
25343 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
25344 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
25346 /* Add the base offset of the ranges table to the skeleton
25348 if (ranges_table_in_use
)
25349 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
25350 ranges_section_label
);
25352 switch_to_section (debug_addr_section
);
25353 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
25354 output_addr_table ();
25357 /* Output the main compilation unit if non-empty or if .debug_macinfo
25358 or .debug_macro will be emitted. */
25359 output_comp_unit (comp_unit_die (), have_macinfo
);
25361 if (dwarf_split_debug_info
&& info_section_emitted
)
25362 output_skeleton_debug_sections (main_comp_unit_die
);
25364 /* Output the abbreviation table. */
25365 if (abbrev_die_table_in_use
!= 1)
25367 switch_to_section (debug_abbrev_section
);
25368 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
25369 output_abbrev_section ();
25372 /* Output location list section if necessary. */
25373 if (have_location_lists
)
25375 /* Output the location lists info. */
25376 switch_to_section (debug_loc_section
);
25377 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
25378 output_location_lists (comp_unit_die ());
25381 output_pubtables ();
25383 /* Output the address range information if a CU (.debug_info section)
25384 was emitted. We output an empty table even if we had no functions
25385 to put in it. This because the consumer has no way to tell the
25386 difference between an empty table that we omitted and failure to
25387 generate a table that would have contained data. */
25388 if (info_section_emitted
)
25390 unsigned long aranges_length
= size_of_aranges ();
25392 switch_to_section (debug_aranges_section
);
25393 output_aranges (aranges_length
);
25396 /* Output ranges section if necessary. */
25397 if (ranges_table_in_use
)
25399 switch_to_section (debug_ranges_section
);
25400 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
25404 /* Have to end the macro section. */
25407 switch_to_section (debug_macinfo_section
);
25408 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
25410 dw2_asm_output_data (1, 0, "End compilation unit");
25413 /* Output the source line correspondence table. We must do this
25414 even if there is no line information. Otherwise, on an empty
25415 translation unit, we will generate a present, but empty,
25416 .debug_info section. IRIX 6.5 `nm' will then complain when
25417 examining the file. This is done late so that any filenames
25418 used by the debug_info section are marked as 'used'. */
25419 switch_to_section (debug_line_section
);
25420 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
25421 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
25422 output_line_info (false);
25424 if (dwarf_split_debug_info
&& info_section_emitted
)
25426 switch_to_section (debug_skeleton_line_section
);
25427 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
25428 output_line_info (true);
25431 /* If we emitted any indirect strings, output the string table too. */
25432 if (debug_str_hash
|| skeleton_debug_str_hash
)
25433 output_indirect_strings ();
25436 /* Perform any cleanups needed after the early debug generation pass
25440 dwarf2out_early_finish (void)
25442 limbo_die_node
*node
, *next_node
;
25444 /* Add DW_AT_linkage_name for all deferred DIEs. */
25445 for (node
= deferred_asm_name
; node
; node
= node
->next
)
25447 tree decl
= node
->created_for
;
25448 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
25449 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
25450 ended up in in deferred_asm_name before we knew it was
25451 constant and never written to disk. */
25452 && DECL_ASSEMBLER_NAME (decl
))
25454 add_linkage_attr (node
->die
, decl
);
25455 move_linkage_attr (node
->die
);
25458 deferred_asm_name
= NULL
;
25460 /* Traverse the limbo die list, and add parent/child links. The only
25461 dies without parents that should be here are concrete instances of
25462 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
25463 For concrete instances, we can get the parent die from the abstract
25466 The point here is to flush out the limbo list so that it is empty
25467 and we don't need to stream it for LTO. */
25468 for (node
= limbo_die_list
; node
; node
= next_node
)
25470 dw_die_ref die
= node
->die
;
25471 next_node
= node
->next
;
25473 if (die
->die_parent
== NULL
)
25475 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
25477 if (origin
&& origin
->die_parent
)
25478 add_child_die (origin
->die_parent
, die
);
25479 else if (is_cu_die (die
))
25481 else if (seen_error ())
25482 /* It's OK to be confused by errors in the input. */
25483 add_child_die (comp_unit_die (), die
);
25486 /* In certain situations, the lexical block containing a
25487 nested function can be optimized away, which results
25488 in the nested function die being orphaned. Likewise
25489 with the return type of that nested function. Force
25490 this to be a child of the containing function.
25492 It may happen that even the containing function got fully
25493 inlined and optimized out. In that case we are lost and
25494 assign the empty child. This should not be big issue as
25495 the function is likely unreachable too. */
25496 gcc_assert (node
->created_for
);
25498 if (DECL_P (node
->created_for
))
25499 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
25500 else if (TYPE_P (node
->created_for
))
25501 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
25503 origin
= comp_unit_die ();
25505 add_child_die (origin
, die
);
25510 limbo_die_list
= NULL
;
25513 /* Reset all state within dwarf2out.c so that we can rerun the compiler
25514 within the same process. For use by toplev::finalize. */
25517 dwarf2out_c_finalize (void)
25519 last_var_location_insn
= NULL
;
25520 cached_next_real_insn
= NULL
;
25521 used_rtx_array
= NULL
;
25522 incomplete_types
= NULL
;
25523 decl_scope_table
= NULL
;
25524 debug_info_section
= NULL
;
25525 debug_skeleton_info_section
= NULL
;
25526 debug_abbrev_section
= NULL
;
25527 debug_skeleton_abbrev_section
= NULL
;
25528 debug_aranges_section
= NULL
;
25529 debug_addr_section
= NULL
;
25530 debug_macinfo_section
= NULL
;
25531 debug_line_section
= NULL
;
25532 debug_skeleton_line_section
= NULL
;
25533 debug_loc_section
= NULL
;
25534 debug_pubnames_section
= NULL
;
25535 debug_pubtypes_section
= NULL
;
25536 debug_str_section
= NULL
;
25537 debug_str_dwo_section
= NULL
;
25538 debug_str_offsets_section
= NULL
;
25539 debug_ranges_section
= NULL
;
25540 debug_frame_section
= NULL
;
25542 debug_str_hash
= NULL
;
25543 skeleton_debug_str_hash
= NULL
;
25544 dw2_string_counter
= 0;
25545 have_multiple_function_sections
= false;
25546 text_section_used
= false;
25547 cold_text_section_used
= false;
25548 cold_text_section
= NULL
;
25549 current_unit_personality
= NULL
;
25551 next_die_offset
= 0;
25552 single_comp_unit_die
= NULL
;
25553 comdat_type_list
= NULL
;
25554 limbo_die_list
= NULL
;
25556 decl_die_table
= NULL
;
25557 common_block_die_table
= NULL
;
25558 decl_loc_table
= NULL
;
25559 call_arg_locations
= NULL
;
25560 call_arg_loc_last
= NULL
;
25561 call_site_count
= -1;
25562 tail_call_site_count
= -1;
25563 cached_dw_loc_list_table
= NULL
;
25564 abbrev_die_table
= NULL
;
25565 abbrev_die_table_allocated
= 0;
25566 abbrev_die_table_in_use
= 0;
25567 line_info_label_num
= 0;
25568 cur_line_info_table
= NULL
;
25569 text_section_line_info
= NULL
;
25570 cold_text_section_line_info
= NULL
;
25571 separate_line_info
= NULL
;
25572 info_section_emitted
= false;
25573 pubname_table
= NULL
;
25574 pubtype_table
= NULL
;
25575 macinfo_table
= NULL
;
25576 ranges_table
= NULL
;
25577 ranges_table_allocated
= 0;
25578 ranges_table_in_use
= 0;
25579 ranges_by_label
= 0;
25580 ranges_by_label_allocated
= 0;
25581 ranges_by_label_in_use
= 0;
25582 have_location_lists
= false;
25585 last_emitted_file
= NULL
;
25587 tmpl_value_parm_die_table
= NULL
;
25588 generic_type_instances
= NULL
;
25589 frame_pointer_fb_offset
= 0;
25590 frame_pointer_fb_offset_valid
= false;
25591 base_types
.release ();
25592 XDELETEVEC (producer_string
);
25593 producer_string
= NULL
;
25596 #include "gt-dwarf2out.h"