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"
65 #include "fold-const.h"
66 #include "stringpool.h"
67 #include "stor-layout.h"
75 #include "insn-config.h"
86 #include "dwarf2out.h"
87 #include "dwarf2asm.h"
91 #include "diagnostic.h"
92 #include "tree-pretty-print.h"
95 #include "common/common-target.h"
96 #include "langhooks.h"
100 #include "dumpfile.h"
102 #include "tree-dfa.h"
103 #include "gdb/gdb-index.h"
104 #include "rtl-iter.h"
106 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
107 static rtx_insn
*last_var_location_insn
;
108 static rtx_insn
*cached_next_real_insn
;
109 static void dwarf2out_decl (tree
);
111 #ifdef VMS_DEBUGGING_INFO
112 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
114 /* Define this macro to be a nonzero value if the directory specifications
115 which are output in the debug info should end with a separator. */
116 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
117 /* Define this macro to evaluate to a nonzero value if GCC should refrain
118 from generating indirect strings in DWARF2 debug information, for instance
119 if your target is stuck with an old version of GDB that is unable to
120 process them properly or uses VMS Debug. */
121 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
123 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
124 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
127 /* ??? Poison these here until it can be done generically. They've been
128 totally replaced in this file; make sure it stays that way. */
129 #undef DWARF2_UNWIND_INFO
130 #undef DWARF2_FRAME_INFO
131 #if (GCC_VERSION >= 3000)
132 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
135 /* The size of the target's pointer type. */
137 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
140 /* Array of RTXes referenced by the debugging information, which therefore
141 must be kept around forever. */
142 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
144 /* A pointer to the base of a list of incomplete types which might be
145 completed at some later time. incomplete_types_list needs to be a
146 vec<tree, va_gc> *because we want to tell the garbage collector about
148 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
150 /* A pointer to the base of a table of references to declaration
151 scopes. This table is a display which tracks the nesting
152 of declaration scopes at the current scope and containing
153 scopes. This table is used to find the proper place to
154 define type declaration DIE's. */
155 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
157 /* Pointers to various DWARF2 sections. */
158 static GTY(()) section
*debug_info_section
;
159 static GTY(()) section
*debug_skeleton_info_section
;
160 static GTY(()) section
*debug_abbrev_section
;
161 static GTY(()) section
*debug_skeleton_abbrev_section
;
162 static GTY(()) section
*debug_aranges_section
;
163 static GTY(()) section
*debug_addr_section
;
164 static GTY(()) section
*debug_macinfo_section
;
165 static GTY(()) section
*debug_line_section
;
166 static GTY(()) section
*debug_skeleton_line_section
;
167 static GTY(()) section
*debug_loc_section
;
168 static GTY(()) section
*debug_pubnames_section
;
169 static GTY(()) section
*debug_pubtypes_section
;
170 static GTY(()) section
*debug_str_section
;
171 static GTY(()) section
*debug_str_dwo_section
;
172 static GTY(()) section
*debug_str_offsets_section
;
173 static GTY(()) section
*debug_ranges_section
;
174 static GTY(()) section
*debug_frame_section
;
176 /* Maximum size (in bytes) of an artificially generated label. */
177 #define MAX_ARTIFICIAL_LABEL_BYTES 30
179 /* According to the (draft) DWARF 3 specification, the initial length
180 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
181 bytes are 0xffffffff, followed by the length stored in the next 8
184 However, the SGI/MIPS ABI uses an initial length which is equal to
185 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
187 #ifndef DWARF_INITIAL_LENGTH_SIZE
188 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
191 /* Round SIZE up to the nearest BOUNDARY. */
192 #define DWARF_ROUND(SIZE,BOUNDARY) \
193 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
195 /* CIE identifier. */
196 #if HOST_BITS_PER_WIDE_INT >= 64
197 #define DWARF_CIE_ID \
198 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
200 #define DWARF_CIE_ID DW_CIE_ID
204 /* A vector for a table that contains frame description
205 information for each routine. */
206 #define NOT_INDEXED (-1U)
207 #define NO_INDEX_ASSIGNED (-2U)
209 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
211 struct GTY((for_user
)) indirect_string_node
{
213 unsigned int refcount
;
214 enum dwarf_form form
;
219 struct indirect_string_hasher
: ggc_ptr_hash
<indirect_string_node
>
221 typedef const char *compare_type
;
223 static hashval_t
hash (indirect_string_node
*);
224 static bool equal (indirect_string_node
*, const char *);
227 static GTY (()) hash_table
<indirect_string_hasher
> *debug_str_hash
;
229 /* With split_debug_info, both the comp_dir and dwo_name go in the
230 main object file, rather than the dwo, similar to the force_direct
231 parameter elsewhere but with additional complications:
233 1) The string is needed in both the main object file and the dwo.
234 That is, the comp_dir and dwo_name will appear in both places.
236 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
237 DW_FORM_GNU_str_index.
239 3) GCC chooses the form to use late, depending on the size and
242 Rather than forcing the all debug string handling functions and
243 callers to deal with these complications, simply use a separate,
244 special-cased string table for any attribute that should go in the
245 main object file. This limits the complexity to just the places
248 static GTY (()) hash_table
<indirect_string_hasher
> *skeleton_debug_str_hash
;
250 static GTY(()) int dw2_string_counter
;
252 /* True if the compilation unit places functions in more than one section. */
253 static GTY(()) bool have_multiple_function_sections
= false;
255 /* Whether the default text and cold text sections have been used at all. */
257 static GTY(()) bool text_section_used
= false;
258 static GTY(()) bool cold_text_section_used
= false;
260 /* The default cold text section. */
261 static GTY(()) section
*cold_text_section
;
263 /* The DIE for C++14 'auto' in a function return type. */
264 static GTY(()) dw_die_ref auto_die
;
266 /* The DIE for C++14 'decltype(auto)' in a function return type. */
267 static GTY(()) dw_die_ref decltype_auto_die
;
269 /* Forward declarations for functions defined in this file. */
271 static char *stripattributes (const char *);
272 static void output_call_frame_info (int);
273 static void dwarf2out_note_section_used (void);
275 /* Personality decl of current unit. Used only when assembler does not support
277 static GTY(()) rtx current_unit_personality
;
279 /* Data and reference forms for relocatable data. */
280 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
281 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
283 #ifndef DEBUG_FRAME_SECTION
284 #define DEBUG_FRAME_SECTION ".debug_frame"
287 #ifndef FUNC_BEGIN_LABEL
288 #define FUNC_BEGIN_LABEL "LFB"
291 #ifndef FUNC_END_LABEL
292 #define FUNC_END_LABEL "LFE"
295 #ifndef PROLOGUE_END_LABEL
296 #define PROLOGUE_END_LABEL "LPE"
299 #ifndef EPILOGUE_BEGIN_LABEL
300 #define EPILOGUE_BEGIN_LABEL "LEB"
303 #ifndef FRAME_BEGIN_LABEL
304 #define FRAME_BEGIN_LABEL "Lframe"
306 #define CIE_AFTER_SIZE_LABEL "LSCIE"
307 #define CIE_END_LABEL "LECIE"
308 #define FDE_LABEL "LSFDE"
309 #define FDE_AFTER_SIZE_LABEL "LASFDE"
310 #define FDE_END_LABEL "LEFDE"
311 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
312 #define LINE_NUMBER_END_LABEL "LELT"
313 #define LN_PROLOG_AS_LABEL "LASLTP"
314 #define LN_PROLOG_END_LABEL "LELTP"
315 #define DIE_LABEL_PREFIX "DW"
317 /* Match the base name of a file to the base name of a compilation unit. */
320 matches_main_base (const char *path
)
322 /* Cache the last query. */
323 static const char *last_path
= NULL
;
324 static int last_match
= 0;
325 if (path
!= last_path
)
328 int length
= base_of_path (path
, &base
);
330 last_match
= (length
== main_input_baselength
331 && memcmp (base
, main_input_basename
, length
) == 0);
336 #ifdef DEBUG_DEBUG_STRUCT
339 dump_struct_debug (tree type
, enum debug_info_usage usage
,
340 enum debug_struct_file criterion
, int generic
,
341 int matches
, int result
)
343 /* Find the type name. */
344 tree type_decl
= TYPE_STUB_DECL (type
);
346 const char *name
= 0;
347 if (TREE_CODE (t
) == TYPE_DECL
)
350 name
= IDENTIFIER_POINTER (t
);
352 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
354 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
355 matches
? "bas" : "hdr",
356 generic
? "gen" : "ord",
357 usage
== DINFO_USAGE_DFN
? ";" :
358 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
360 (void*) type_decl
, name
);
363 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
364 dump_struct_debug (type, usage, criterion, generic, matches, result)
368 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
373 /* Get the number of HOST_WIDE_INTs needed to represent the precision
377 get_full_len (const wide_int
&op
)
379 return ((op
.get_precision () + HOST_BITS_PER_WIDE_INT
- 1)
380 / HOST_BITS_PER_WIDE_INT
);
384 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
386 enum debug_struct_file criterion
;
388 bool generic
= lang_hooks
.types
.generic_p (type
);
391 criterion
= debug_struct_generic
[usage
];
393 criterion
= debug_struct_ordinary
[usage
];
395 if (criterion
== DINFO_STRUCT_FILE_NONE
)
396 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
397 if (criterion
== DINFO_STRUCT_FILE_ANY
)
398 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
400 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
402 if (type_decl
!= NULL
)
404 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
405 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
407 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
408 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
411 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
414 /* Return a pointer to a copy of the section string name S with all
415 attributes stripped off, and an asterisk prepended (for assemble_name). */
418 stripattributes (const char *s
)
420 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
425 while (*s
&& *s
!= ',')
432 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
433 switch to the data section instead, and write out a synthetic start label
434 for collect2 the first time around. */
437 switch_to_eh_frame_section (bool back
)
441 #ifdef EH_FRAME_SECTION_NAME
442 if (eh_frame_section
== 0)
446 if (EH_TABLES_CAN_BE_READ_ONLY
)
452 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
454 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
456 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
459 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
460 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
461 && (per_encoding
& 0x70) != DW_EH_PE_absptr
462 && (per_encoding
& 0x70) != DW_EH_PE_aligned
463 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
464 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
465 ? 0 : SECTION_WRITE
);
468 flags
= SECTION_WRITE
;
469 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
471 #endif /* EH_FRAME_SECTION_NAME */
473 if (eh_frame_section
)
474 switch_to_section (eh_frame_section
);
477 /* We have no special eh_frame section. Put the information in
478 the data section and emit special labels to guide collect2. */
479 switch_to_section (data_section
);
483 label
= get_file_function_name ("F");
484 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
485 targetm
.asm_out
.globalize_label (asm_out_file
,
486 IDENTIFIER_POINTER (label
));
487 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
492 /* Switch [BACK] to the eh or debug frame table section, depending on
496 switch_to_frame_table_section (int for_eh
, bool back
)
499 switch_to_eh_frame_section (back
);
502 if (!debug_frame_section
)
503 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
504 SECTION_DEBUG
, NULL
);
505 switch_to_section (debug_frame_section
);
509 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
511 enum dw_cfi_oprnd_type
512 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
517 case DW_CFA_GNU_window_save
:
518 case DW_CFA_remember_state
:
519 case DW_CFA_restore_state
:
520 return dw_cfi_oprnd_unused
;
523 case DW_CFA_advance_loc1
:
524 case DW_CFA_advance_loc2
:
525 case DW_CFA_advance_loc4
:
526 case DW_CFA_MIPS_advance_loc8
:
527 return dw_cfi_oprnd_addr
;
530 case DW_CFA_offset_extended
:
532 case DW_CFA_offset_extended_sf
:
533 case DW_CFA_def_cfa_sf
:
535 case DW_CFA_restore_extended
:
536 case DW_CFA_undefined
:
537 case DW_CFA_same_value
:
538 case DW_CFA_def_cfa_register
:
539 case DW_CFA_register
:
540 case DW_CFA_expression
:
541 return dw_cfi_oprnd_reg_num
;
543 case DW_CFA_def_cfa_offset
:
544 case DW_CFA_GNU_args_size
:
545 case DW_CFA_def_cfa_offset_sf
:
546 return dw_cfi_oprnd_offset
;
548 case DW_CFA_def_cfa_expression
:
549 return dw_cfi_oprnd_loc
;
556 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
558 enum dw_cfi_oprnd_type
559 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
564 case DW_CFA_def_cfa_sf
:
566 case DW_CFA_offset_extended_sf
:
567 case DW_CFA_offset_extended
:
568 return dw_cfi_oprnd_offset
;
570 case DW_CFA_register
:
571 return dw_cfi_oprnd_reg_num
;
573 case DW_CFA_expression
:
574 return dw_cfi_oprnd_loc
;
577 return dw_cfi_oprnd_unused
;
581 /* Output one FDE. */
584 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
585 char *section_start_label
, int fde_encoding
, char *augmentation
,
586 bool any_lsda_needed
, int lsda_encoding
)
588 const char *begin
, *end
;
589 static unsigned int j
;
592 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
594 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
596 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
597 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
598 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
599 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
600 " indicating 64-bit DWARF extension");
601 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
603 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
606 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
608 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
609 debug_frame_section
, "FDE CIE offset");
611 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
612 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
616 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
617 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
618 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
619 "FDE initial location");
620 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
621 end
, begin
, "FDE address range");
625 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
626 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
633 int size
= size_of_encoded_value (lsda_encoding
);
635 if (lsda_encoding
== DW_EH_PE_aligned
)
637 int offset
= ( 4 /* Length */
639 + 2 * size_of_encoded_value (fde_encoding
)
640 + 1 /* Augmentation size */ );
641 int pad
= -offset
& (PTR_SIZE
- 1);
644 gcc_assert (size_of_uleb128 (size
) == 1);
647 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
649 if (fde
->uses_eh_lsda
)
651 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
652 fde
->funcdef_number
);
653 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
654 gen_rtx_SYMBOL_REF (Pmode
, l1
),
656 "Language Specific Data Area");
660 if (lsda_encoding
== DW_EH_PE_aligned
)
661 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
662 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
663 "Language Specific Data Area (none)");
667 dw2_asm_output_data_uleb128 (0, "Augmentation size");
670 /* Loop through the Call Frame Instructions associated with this FDE. */
671 fde
->dw_fde_current_label
= begin
;
673 size_t from
, until
, i
;
676 until
= vec_safe_length (fde
->dw_fde_cfi
);
678 if (fde
->dw_fde_second_begin
== NULL
)
681 until
= fde
->dw_fde_switch_cfi_index
;
683 from
= fde
->dw_fde_switch_cfi_index
;
685 for (i
= from
; i
< until
; i
++)
686 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
689 /* If we are to emit a ref/link from function bodies to their frame tables,
690 do it now. This is typically performed to make sure that tables
691 associated with functions are dragged with them and not discarded in
692 garbage collecting links. We need to do this on a per function basis to
693 cope with -ffunction-sections. */
695 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
696 /* Switch to the function section, emit the ref to the tables, and
697 switch *back* into the table section. */
698 switch_to_section (function_section (fde
->decl
));
699 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
700 switch_to_frame_table_section (for_eh
, true);
703 /* Pad the FDE out to an address sized boundary. */
704 ASM_OUTPUT_ALIGN (asm_out_file
,
705 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
706 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
711 /* Return true if frame description entry FDE is needed for EH. */
714 fde_needed_for_eh_p (dw_fde_ref fde
)
716 if (flag_asynchronous_unwind_tables
)
719 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
722 if (fde
->uses_eh_lsda
)
725 /* If exceptions are enabled, we have collected nothrow info. */
726 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
732 /* Output the call frame information used to record information
733 that relates to calculating the frame pointer, and records the
734 location of saved registers. */
737 output_call_frame_info (int for_eh
)
742 char l1
[20], l2
[20], section_start_label
[20];
743 bool any_lsda_needed
= false;
744 char augmentation
[6];
745 int augmentation_size
;
746 int fde_encoding
= DW_EH_PE_absptr
;
747 int per_encoding
= DW_EH_PE_absptr
;
748 int lsda_encoding
= DW_EH_PE_absptr
;
750 rtx personality
= NULL
;
753 /* Don't emit a CIE if there won't be any FDEs. */
757 /* Nothing to do if the assembler's doing it all. */
758 if (dwarf2out_do_cfi_asm ())
761 /* If we don't have any functions we'll want to unwind out of, don't emit
762 any EH unwind information. If we make FDEs linkonce, we may have to
763 emit an empty label for an FDE that wouldn't otherwise be emitted. We
764 want to avoid having an FDE kept around when the function it refers to
765 is discarded. Example where this matters: a primary function template
766 in C++ requires EH information, an explicit specialization doesn't. */
769 bool any_eh_needed
= false;
771 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
773 if (fde
->uses_eh_lsda
)
774 any_eh_needed
= any_lsda_needed
= true;
775 else if (fde_needed_for_eh_p (fde
))
776 any_eh_needed
= true;
777 else if (TARGET_USES_WEAK_UNWIND_INFO
)
778 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
785 /* We're going to be generating comments, so turn on app. */
789 /* Switch to the proper frame section, first time. */
790 switch_to_frame_table_section (for_eh
, false);
792 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
793 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
795 /* Output the CIE. */
796 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
797 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
798 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
799 dw2_asm_output_data (4, 0xffffffff,
800 "Initial length escape value indicating 64-bit DWARF extension");
801 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
802 "Length of Common Information Entry");
803 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
805 /* Now that the CIE pointer is PC-relative for EH,
806 use 0 to identify the CIE. */
807 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
808 (for_eh
? 0 : DWARF_CIE_ID
),
809 "CIE Identifier Tag");
811 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
812 use CIE version 1, unless that would produce incorrect results
813 due to overflowing the return register column. */
814 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
816 if (return_reg
>= 256 || dwarf_version
> 2)
818 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
821 augmentation_size
= 0;
823 personality
= current_unit_personality
;
829 z Indicates that a uleb128 is present to size the
830 augmentation section.
831 L Indicates the encoding (and thus presence) of
832 an LSDA pointer in the FDE augmentation.
833 R Indicates a non-default pointer encoding for
835 P Indicates the presence of an encoding + language
836 personality routine in the CIE augmentation. */
838 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
839 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
840 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
842 p
= augmentation
+ 1;
846 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
847 assemble_external_libcall (personality
);
852 augmentation_size
+= 1;
854 if (fde_encoding
!= DW_EH_PE_absptr
)
857 augmentation_size
+= 1;
859 if (p
> augmentation
+ 1)
861 augmentation
[0] = 'z';
865 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
866 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
868 int offset
= ( 4 /* Length */
870 + 1 /* CIE version */
871 + strlen (augmentation
) + 1 /* Augmentation */
872 + size_of_uleb128 (1) /* Code alignment */
873 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
875 + 1 /* Augmentation size */
876 + 1 /* Personality encoding */ );
877 int pad
= -offset
& (PTR_SIZE
- 1);
879 augmentation_size
+= pad
;
881 /* Augmentations should be small, so there's scarce need to
882 iterate for a solution. Die if we exceed one uleb128 byte. */
883 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
887 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
888 if (dw_cie_version
>= 4)
890 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
891 dw2_asm_output_data (1, 0, "CIE Segment Size");
893 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
894 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
895 "CIE Data Alignment Factor");
897 if (dw_cie_version
== 1)
898 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
900 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
904 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
907 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
908 eh_data_format_name (per_encoding
));
909 dw2_asm_output_encoded_addr_rtx (per_encoding
,
915 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
916 eh_data_format_name (lsda_encoding
));
918 if (fde_encoding
!= DW_EH_PE_absptr
)
919 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
920 eh_data_format_name (fde_encoding
));
923 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
924 output_cfi (cfi
, NULL
, for_eh
);
926 /* Pad the CIE out to an address sized boundary. */
927 ASM_OUTPUT_ALIGN (asm_out_file
,
928 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
929 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
931 /* Loop through all of the FDE's. */
932 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
936 /* Don't emit EH unwind info for leaf functions that don't need it. */
937 if (for_eh
&& !fde_needed_for_eh_p (fde
))
940 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
941 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
942 augmentation
, any_lsda_needed
, lsda_encoding
);
945 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
946 dw2_asm_output_data (4, 0, "End of Table");
948 /* Turn off app to make assembly quicker. */
953 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
956 dwarf2out_do_cfi_startproc (bool second
)
960 rtx personality
= get_personality_function (current_function_decl
);
962 fprintf (asm_out_file
, "\t.cfi_startproc\n");
966 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
969 /* ??? The GAS support isn't entirely consistent. We have to
970 handle indirect support ourselves, but PC-relative is done
971 in the assembler. Further, the assembler can't handle any
972 of the weirder relocation types. */
973 if (enc
& DW_EH_PE_indirect
)
974 ref
= dw2_force_const_mem (ref
, true);
976 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
977 output_addr_const (asm_out_file
, ref
);
978 fputc ('\n', asm_out_file
);
981 if (crtl
->uses_eh_lsda
)
985 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
986 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
987 current_function_funcdef_no
);
988 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
989 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
991 if (enc
& DW_EH_PE_indirect
)
992 ref
= dw2_force_const_mem (ref
, true);
994 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
995 output_addr_const (asm_out_file
, ref
);
996 fputc ('\n', asm_out_file
);
1000 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
1001 this allocation may be done before pass_final. */
1004 dwarf2out_alloc_current_fde (void)
1008 fde
= ggc_cleared_alloc
<dw_fde_node
> ();
1009 fde
->decl
= current_function_decl
;
1010 fde
->funcdef_number
= current_function_funcdef_no
;
1011 fde
->fde_index
= vec_safe_length (fde_vec
);
1012 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1013 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1014 fde
->nothrow
= crtl
->nothrow
;
1015 fde
->drap_reg
= INVALID_REGNUM
;
1016 fde
->vdrap_reg
= INVALID_REGNUM
;
1018 /* Record the FDE associated with this function. */
1020 vec_safe_push (fde_vec
, fde
);
1025 /* Output a marker (i.e. a label) for the beginning of a function, before
1029 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1030 const char *file ATTRIBUTE_UNUSED
)
1032 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1038 current_function_func_begin_label
= NULL
;
1040 do_frame
= dwarf2out_do_frame ();
1042 /* ??? current_function_func_begin_label is also used by except.c for
1043 call-site information. We must emit this label if it might be used. */
1045 && (!flag_exceptions
1046 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1049 fnsec
= function_section (current_function_decl
);
1050 switch_to_section (fnsec
);
1051 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1052 current_function_funcdef_no
);
1053 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1054 current_function_funcdef_no
);
1055 dup_label
= xstrdup (label
);
1056 current_function_func_begin_label
= dup_label
;
1058 /* We can elide the fde allocation if we're not emitting debug info. */
1062 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1063 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1064 would include pass_dwarf2_frame. If we've not created the FDE yet,
1068 fde
= dwarf2out_alloc_current_fde ();
1070 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1071 fde
->dw_fde_begin
= dup_label
;
1072 fde
->dw_fde_current_label
= dup_label
;
1073 fde
->in_std_section
= (fnsec
== text_section
1074 || (cold_text_section
&& fnsec
== cold_text_section
));
1076 /* We only want to output line number information for the genuine dwarf2
1077 prologue case, not the eh frame case. */
1078 #ifdef DWARF2_DEBUGGING_INFO
1080 dwarf2out_source_line (line
, file
, 0, true);
1083 if (dwarf2out_do_cfi_asm ())
1084 dwarf2out_do_cfi_startproc (false);
1087 rtx personality
= get_personality_function (current_function_decl
);
1088 if (!current_unit_personality
)
1089 current_unit_personality
= personality
;
1091 /* We cannot keep a current personality per function as without CFI
1092 asm, at the point where we emit the CFI data, there is no current
1093 function anymore. */
1094 if (personality
&& current_unit_personality
!= personality
)
1095 sorry ("multiple EH personalities are supported only with assemblers "
1096 "supporting .cfi_personality directive");
1100 /* Output a marker (i.e. a label) for the end of the generated code
1101 for a function prologue. This gets called *after* the prologue code has
1105 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1106 const char *file ATTRIBUTE_UNUSED
)
1108 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1110 /* Output a label to mark the endpoint of the code generated for this
1112 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1113 current_function_funcdef_no
);
1114 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1115 current_function_funcdef_no
);
1116 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1119 /* Output a marker (i.e. a label) for the beginning of the generated code
1120 for a function epilogue. This gets called *before* the prologue code has
1124 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1125 const char *file ATTRIBUTE_UNUSED
)
1127 dw_fde_ref fde
= cfun
->fde
;
1128 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1130 if (fde
->dw_fde_vms_begin_epilogue
)
1133 /* Output a label to mark the endpoint of the code generated for this
1135 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1136 current_function_funcdef_no
);
1137 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1138 current_function_funcdef_no
);
1139 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1142 /* Output a marker (i.e. a label) for the absolute end of the generated code
1143 for a function definition. This gets called *after* the epilogue code has
1147 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1148 const char *file ATTRIBUTE_UNUSED
)
1151 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1153 last_var_location_insn
= NULL
;
1154 cached_next_real_insn
= NULL
;
1156 if (dwarf2out_do_cfi_asm ())
1157 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1159 /* Output a label to mark the endpoint of the code generated for this
1161 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1162 current_function_funcdef_no
);
1163 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1165 gcc_assert (fde
!= NULL
);
1166 if (fde
->dw_fde_second_begin
== NULL
)
1167 fde
->dw_fde_end
= xstrdup (label
);
1171 dwarf2out_frame_finish (void)
1173 /* Output call frame information. */
1174 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1175 output_call_frame_info (0);
1177 /* Output another copy for the unwinder. */
1178 if ((flag_unwind_tables
|| flag_exceptions
)
1179 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1180 output_call_frame_info (1);
1183 /* Note that the current function section is being used for code. */
1186 dwarf2out_note_section_used (void)
1188 section
*sec
= current_function_section ();
1189 if (sec
== text_section
)
1190 text_section_used
= true;
1191 else if (sec
== cold_text_section
)
1192 cold_text_section_used
= true;
1195 static void var_location_switch_text_section (void);
1196 static void set_cur_line_info_table (section
*);
1199 dwarf2out_switch_text_section (void)
1202 dw_fde_ref fde
= cfun
->fde
;
1204 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1206 if (!in_cold_section_p
)
1208 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1209 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1210 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1214 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1215 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1216 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1218 have_multiple_function_sections
= true;
1220 /* There is no need to mark used sections when not debugging. */
1221 if (cold_text_section
!= NULL
)
1222 dwarf2out_note_section_used ();
1224 if (dwarf2out_do_cfi_asm ())
1225 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1227 /* Now do the real section switch. */
1228 sect
= current_function_section ();
1229 switch_to_section (sect
);
1231 fde
->second_in_std_section
1232 = (sect
== text_section
1233 || (cold_text_section
&& sect
== cold_text_section
));
1235 if (dwarf2out_do_cfi_asm ())
1236 dwarf2out_do_cfi_startproc (true);
1238 var_location_switch_text_section ();
1240 if (cold_text_section
!= NULL
)
1241 set_cur_line_info_table (sect
);
1244 /* And now, the subset of the debugging information support code necessary
1245 for emitting location expressions. */
1247 /* Data about a single source file. */
1248 struct GTY((for_user
)) dwarf_file_data
{
1249 const char * filename
;
1253 /* Describe an entry into the .debug_addr section. */
1257 ate_kind_rtx_dtprel
,
1261 typedef struct GTY((for_user
)) addr_table_entry_struct
{
1263 unsigned int refcount
;
1265 union addr_table_entry_struct_union
1267 rtx
GTY ((tag ("0"))) rtl
;
1268 char * GTY ((tag ("1"))) label
;
1270 GTY ((desc ("%1.kind"))) addr
;
1274 /* Location lists are ranges + location descriptions for that range,
1275 so you can track variables that are in different places over
1276 their entire life. */
1277 typedef struct GTY(()) dw_loc_list_struct
{
1278 dw_loc_list_ref dw_loc_next
;
1279 const char *begin
; /* Label and addr_entry for start of range */
1280 addr_table_entry
*begin_entry
;
1281 const char *end
; /* Label for end of range */
1282 char *ll_symbol
; /* Label for beginning of location list.
1283 Only on head of list */
1284 const char *section
; /* Section this loclist is relative to */
1285 dw_loc_descr_ref expr
;
1287 /* True if all addresses in this and subsequent lists are known to be
1290 /* True if this list has been replaced by dw_loc_next. */
1293 /* True if the range should be emitted even if begin and end
1298 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1300 /* Convert a DWARF stack opcode into its string name. */
1303 dwarf_stack_op_name (unsigned int op
)
1305 const char *name
= get_DW_OP_name (op
);
1310 return "OP_<unknown>";
1313 /* Return a pointer to a newly allocated location description. Location
1314 descriptions are simple expression terms that can be strung
1315 together to form more complicated location (address) descriptions. */
1317 static inline dw_loc_descr_ref
1318 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1319 unsigned HOST_WIDE_INT oprnd2
)
1321 dw_loc_descr_ref descr
= ggc_cleared_alloc
<dw_loc_descr_node
> ();
1323 descr
->dw_loc_opc
= op
;
1324 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1325 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1326 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1327 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1328 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1329 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1334 /* Return a pointer to a newly allocated location description for
1337 static inline dw_loc_descr_ref
1338 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1341 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1344 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1347 /* Add a location description term to a location description expression. */
1350 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1352 dw_loc_descr_ref
*d
;
1354 /* Find the end of the chain. */
1355 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1361 /* Compare two location operands for exact equality. */
1364 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1366 if (a
->val_class
!= b
->val_class
)
1368 switch (a
->val_class
)
1370 case dw_val_class_none
:
1372 case dw_val_class_addr
:
1373 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1375 case dw_val_class_offset
:
1376 case dw_val_class_unsigned_const
:
1377 case dw_val_class_const
:
1378 case dw_val_class_range_list
:
1379 case dw_val_class_lineptr
:
1380 case dw_val_class_macptr
:
1381 /* These are all HOST_WIDE_INT, signed or unsigned. */
1382 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1384 case dw_val_class_loc
:
1385 return a
->v
.val_loc
== b
->v
.val_loc
;
1386 case dw_val_class_loc_list
:
1387 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1388 case dw_val_class_die_ref
:
1389 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1390 case dw_val_class_fde_ref
:
1391 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1392 case dw_val_class_lbl_id
:
1393 case dw_val_class_high_pc
:
1394 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1395 case dw_val_class_str
:
1396 return a
->v
.val_str
== b
->v
.val_str
;
1397 case dw_val_class_flag
:
1398 return a
->v
.val_flag
== b
->v
.val_flag
;
1399 case dw_val_class_file
:
1400 return a
->v
.val_file
== b
->v
.val_file
;
1401 case dw_val_class_decl_ref
:
1402 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1404 case dw_val_class_const_double
:
1405 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1406 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1408 case dw_val_class_wide_int
:
1409 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1411 case dw_val_class_vec
:
1413 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1414 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1416 return (a_len
== b_len
1417 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1420 case dw_val_class_data8
:
1421 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1423 case dw_val_class_vms_delta
:
1424 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1425 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1430 /* Compare two location atoms for exact equality. */
1433 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1435 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1438 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1439 address size, but since we always allocate cleared storage it
1440 should be zero for other types of locations. */
1441 if (a
->dtprel
!= b
->dtprel
)
1444 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1445 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1448 /* Compare two complete location expressions for exact equality. */
1451 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1457 if (a
== NULL
|| b
== NULL
)
1459 if (!loc_descr_equal_p_1 (a
, b
))
1468 /* Add a constant OFFSET to a location expression. */
1471 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1473 dw_loc_descr_ref loc
;
1476 gcc_assert (*list_head
!= NULL
);
1481 /* Find the end of the chain. */
1482 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1486 if (loc
->dw_loc_opc
== DW_OP_fbreg
1487 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1488 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1489 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1490 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1492 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1493 offset. Don't optimize if an signed integer overflow would happen. */
1495 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1496 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1499 else if (offset
> 0)
1500 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1504 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1505 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1509 /* Add a constant OFFSET to a location list. */
1512 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1515 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1516 loc_descr_plus_const (&d
->expr
, offset
);
1519 #define DWARF_REF_SIZE \
1520 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1522 static unsigned long int get_base_type_offset (dw_die_ref
);
1524 /* Return the size of a location descriptor. */
1526 static unsigned long
1527 size_of_loc_descr (dw_loc_descr_ref loc
)
1529 unsigned long size
= 1;
1531 switch (loc
->dw_loc_opc
)
1534 size
+= DWARF2_ADDR_SIZE
;
1536 case DW_OP_GNU_addr_index
:
1537 case DW_OP_GNU_const_index
:
1538 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1539 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1558 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1561 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1566 case DW_OP_plus_uconst
:
1567 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1605 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1608 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1611 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1614 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1615 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1618 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1620 case DW_OP_bit_piece
:
1621 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1622 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1624 case DW_OP_deref_size
:
1625 case DW_OP_xderef_size
:
1634 case DW_OP_call_ref
:
1635 size
+= DWARF_REF_SIZE
;
1637 case DW_OP_implicit_value
:
1638 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1639 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1641 case DW_OP_GNU_implicit_pointer
:
1642 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1644 case DW_OP_GNU_entry_value
:
1646 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1647 size
+= size_of_uleb128 (op_size
) + op_size
;
1650 case DW_OP_GNU_const_type
:
1653 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1654 size
+= size_of_uleb128 (o
) + 1;
1655 switch (loc
->dw_loc_oprnd2
.val_class
)
1657 case dw_val_class_vec
:
1658 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1659 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1661 case dw_val_class_const
:
1662 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1664 case dw_val_class_const_double
:
1665 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1667 case dw_val_class_wide_int
:
1668 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1669 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1676 case DW_OP_GNU_regval_type
:
1679 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1680 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1681 + size_of_uleb128 (o
);
1684 case DW_OP_GNU_deref_type
:
1687 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1688 size
+= 1 + size_of_uleb128 (o
);
1691 case DW_OP_GNU_convert
:
1692 case DW_OP_GNU_reinterpret
:
1693 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1694 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1698 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1699 size
+= size_of_uleb128 (o
);
1702 case DW_OP_GNU_parameter_ref
:
1712 /* Return the size of a series of location descriptors. */
1715 size_of_locs (dw_loc_descr_ref loc
)
1720 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1721 field, to avoid writing to a PCH file. */
1722 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1724 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1726 size
+= size_of_loc_descr (l
);
1731 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1733 l
->dw_loc_addr
= size
;
1734 size
+= size_of_loc_descr (l
);
1740 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1741 static void get_ref_die_offset_label (char *, dw_die_ref
);
1742 static unsigned long int get_ref_die_offset (dw_die_ref
);
1744 /* Output location description stack opcode's operands (if any).
1745 The for_eh_or_skip parameter controls whether register numbers are
1746 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1747 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1748 info). This should be suppressed for the cases that have not been converted
1749 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1752 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1754 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1755 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1757 switch (loc
->dw_loc_opc
)
1759 #ifdef DWARF2_DEBUGGING_INFO
1762 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1767 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1768 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1770 fputc ('\n', asm_out_file
);
1775 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1780 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1781 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1783 fputc ('\n', asm_out_file
);
1788 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1789 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1796 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1797 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1799 dw2_asm_output_data (2, offset
, NULL
);
1802 case DW_OP_implicit_value
:
1803 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1804 switch (val2
->val_class
)
1806 case dw_val_class_const
:
1807 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1809 case dw_val_class_vec
:
1811 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1812 unsigned int len
= val2
->v
.val_vec
.length
;
1816 if (elt_size
> sizeof (HOST_WIDE_INT
))
1821 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1824 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1825 "fp or vector constant word %u", i
);
1828 case dw_val_class_const_double
:
1830 unsigned HOST_WIDE_INT first
, second
;
1832 if (WORDS_BIG_ENDIAN
)
1834 first
= val2
->v
.val_double
.high
;
1835 second
= val2
->v
.val_double
.low
;
1839 first
= val2
->v
.val_double
.low
;
1840 second
= val2
->v
.val_double
.high
;
1842 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1844 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1848 case dw_val_class_wide_int
:
1851 int len
= get_full_len (*val2
->v
.val_wide
);
1852 if (WORDS_BIG_ENDIAN
)
1853 for (i
= len
- 1; i
>= 0; --i
)
1854 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1855 val2
->v
.val_wide
->elt (i
), NULL
);
1857 for (i
= 0; i
< len
; ++i
)
1858 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1859 val2
->v
.val_wide
->elt (i
), NULL
);
1862 case dw_val_class_addr
:
1863 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1864 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1879 case DW_OP_implicit_value
:
1880 /* We currently don't make any attempt to make sure these are
1881 aligned properly like we do for the main unwind info, so
1882 don't support emitting things larger than a byte if we're
1883 only doing unwinding. */
1888 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1891 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1894 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1897 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1899 case DW_OP_plus_uconst
:
1900 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1934 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1938 unsigned r
= val1
->v
.val_unsigned
;
1939 if (for_eh_or_skip
>= 0)
1940 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1941 gcc_assert (size_of_uleb128 (r
)
1942 == size_of_uleb128 (val1
->v
.val_unsigned
));
1943 dw2_asm_output_data_uleb128 (r
, NULL
);
1947 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1951 unsigned r
= val1
->v
.val_unsigned
;
1952 if (for_eh_or_skip
>= 0)
1953 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1954 gcc_assert (size_of_uleb128 (r
)
1955 == size_of_uleb128 (val1
->v
.val_unsigned
));
1956 dw2_asm_output_data_uleb128 (r
, NULL
);
1957 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1961 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1963 case DW_OP_bit_piece
:
1964 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1965 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1967 case DW_OP_deref_size
:
1968 case DW_OP_xderef_size
:
1969 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1975 if (targetm
.asm_out
.output_dwarf_dtprel
)
1977 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1980 fputc ('\n', asm_out_file
);
1987 #ifdef DWARF2_DEBUGGING_INFO
1988 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1995 case DW_OP_GNU_addr_index
:
1996 case DW_OP_GNU_const_index
:
1997 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1998 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1999 "(index into .debug_addr)");
2002 case DW_OP_GNU_implicit_pointer
:
2004 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2005 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2006 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2007 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2008 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2009 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2013 case DW_OP_GNU_entry_value
:
2014 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2015 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2018 case DW_OP_GNU_const_type
:
2020 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2022 dw2_asm_output_data_uleb128 (o
, NULL
);
2023 switch (val2
->val_class
)
2025 case dw_val_class_const
:
2026 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2027 dw2_asm_output_data (1, l
, NULL
);
2028 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2030 case dw_val_class_vec
:
2032 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2033 unsigned int len
= val2
->v
.val_vec
.length
;
2038 dw2_asm_output_data (1, l
, NULL
);
2039 if (elt_size
> sizeof (HOST_WIDE_INT
))
2044 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2047 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2048 "fp or vector constant word %u", i
);
2051 case dw_val_class_const_double
:
2053 unsigned HOST_WIDE_INT first
, second
;
2054 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2056 dw2_asm_output_data (1, 2 * l
, NULL
);
2057 if (WORDS_BIG_ENDIAN
)
2059 first
= val2
->v
.val_double
.high
;
2060 second
= val2
->v
.val_double
.low
;
2064 first
= val2
->v
.val_double
.low
;
2065 second
= val2
->v
.val_double
.high
;
2067 dw2_asm_output_data (l
, first
, NULL
);
2068 dw2_asm_output_data (l
, second
, NULL
);
2071 case dw_val_class_wide_int
:
2074 int len
= get_full_len (*val2
->v
.val_wide
);
2075 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2077 dw2_asm_output_data (1, len
* l
, NULL
);
2078 if (WORDS_BIG_ENDIAN
)
2079 for (i
= len
- 1; i
>= 0; --i
)
2080 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2082 for (i
= 0; i
< len
; ++i
)
2083 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2091 case DW_OP_GNU_regval_type
:
2093 unsigned r
= val1
->v
.val_unsigned
;
2094 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2096 if (for_eh_or_skip
>= 0)
2098 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2099 gcc_assert (size_of_uleb128 (r
)
2100 == size_of_uleb128 (val1
->v
.val_unsigned
));
2102 dw2_asm_output_data_uleb128 (r
, NULL
);
2103 dw2_asm_output_data_uleb128 (o
, NULL
);
2106 case DW_OP_GNU_deref_type
:
2108 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2110 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2111 dw2_asm_output_data_uleb128 (o
, NULL
);
2114 case DW_OP_GNU_convert
:
2115 case DW_OP_GNU_reinterpret
:
2116 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2117 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2120 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2122 dw2_asm_output_data_uleb128 (o
, NULL
);
2126 case DW_OP_GNU_parameter_ref
:
2129 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2130 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2131 dw2_asm_output_data (4, o
, NULL
);
2136 /* Other codes have no operands. */
2141 /* Output a sequence of location operations.
2142 The for_eh_or_skip parameter controls whether register numbers are
2143 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2144 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2145 info). This should be suppressed for the cases that have not been converted
2146 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2149 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2151 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2153 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2154 /* Output the opcode. */
2155 if (for_eh_or_skip
>= 0
2156 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2158 unsigned r
= (opc
- DW_OP_breg0
);
2159 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2160 gcc_assert (r
<= 31);
2161 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2163 else if (for_eh_or_skip
>= 0
2164 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2166 unsigned r
= (opc
- DW_OP_reg0
);
2167 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2168 gcc_assert (r
<= 31);
2169 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2172 dw2_asm_output_data (1, opc
,
2173 "%s", dwarf_stack_op_name (opc
));
2175 /* Output the operand(s) (if any). */
2176 output_loc_operands (loc
, for_eh_or_skip
);
2180 /* Output location description stack opcode's operands (if any).
2181 The output is single bytes on a line, suitable for .cfi_escape. */
2184 output_loc_operands_raw (dw_loc_descr_ref loc
)
2186 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2187 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2189 switch (loc
->dw_loc_opc
)
2192 case DW_OP_GNU_addr_index
:
2193 case DW_OP_GNU_const_index
:
2194 case DW_OP_implicit_value
:
2195 /* We cannot output addresses in .cfi_escape, only bytes. */
2201 case DW_OP_deref_size
:
2202 case DW_OP_xderef_size
:
2203 fputc (',', asm_out_file
);
2204 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2209 fputc (',', asm_out_file
);
2210 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2215 fputc (',', asm_out_file
);
2216 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2221 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2222 fputc (',', asm_out_file
);
2223 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2231 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2232 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2234 fputc (',', asm_out_file
);
2235 dw2_asm_output_data_raw (2, offset
);
2241 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2242 gcc_assert (size_of_uleb128 (r
)
2243 == size_of_uleb128 (val1
->v
.val_unsigned
));
2244 fputc (',', asm_out_file
);
2245 dw2_asm_output_data_uleb128_raw (r
);
2250 case DW_OP_plus_uconst
:
2252 fputc (',', asm_out_file
);
2253 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2256 case DW_OP_bit_piece
:
2257 fputc (',', asm_out_file
);
2258 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2259 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2296 fputc (',', asm_out_file
);
2297 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2302 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2303 gcc_assert (size_of_uleb128 (r
)
2304 == size_of_uleb128 (val1
->v
.val_unsigned
));
2305 fputc (',', asm_out_file
);
2306 dw2_asm_output_data_uleb128_raw (r
);
2307 fputc (',', asm_out_file
);
2308 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2312 case DW_OP_GNU_implicit_pointer
:
2313 case DW_OP_GNU_entry_value
:
2314 case DW_OP_GNU_const_type
:
2315 case DW_OP_GNU_regval_type
:
2316 case DW_OP_GNU_deref_type
:
2317 case DW_OP_GNU_convert
:
2318 case DW_OP_GNU_reinterpret
:
2319 case DW_OP_GNU_parameter_ref
:
2324 /* Other codes have no operands. */
2330 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2334 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2335 /* Output the opcode. */
2336 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2338 unsigned r
= (opc
- DW_OP_breg0
);
2339 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2340 gcc_assert (r
<= 31);
2341 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2343 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2345 unsigned r
= (opc
- DW_OP_reg0
);
2346 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2347 gcc_assert (r
<= 31);
2348 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2350 /* Output the opcode. */
2351 fprintf (asm_out_file
, "%#x", opc
);
2352 output_loc_operands_raw (loc
);
2354 if (!loc
->dw_loc_next
)
2356 loc
= loc
->dw_loc_next
;
2358 fputc (',', asm_out_file
);
2362 /* This function builds a dwarf location descriptor sequence from a
2363 dw_cfa_location, adding the given OFFSET to the result of the
2366 struct dw_loc_descr_node
*
2367 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2369 struct dw_loc_descr_node
*head
, *tmp
;
2371 offset
+= cfa
->offset
;
2375 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2376 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2377 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2378 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2379 add_loc_descr (&head
, tmp
);
2382 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2383 add_loc_descr (&head
, tmp
);
2387 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2392 /* This function builds a dwarf location descriptor sequence for
2393 the address at OFFSET from the CFA when stack is aligned to
2396 struct dw_loc_descr_node
*
2397 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2398 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2400 struct dw_loc_descr_node
*head
;
2401 unsigned int dwarf_fp
2402 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2404 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2405 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2407 head
= new_reg_loc_descr (dwarf_fp
, 0);
2408 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2409 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2410 loc_descr_plus_const (&head
, offset
);
2413 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2417 /* And now, the support for symbolic debugging information. */
2419 /* .debug_str support. */
2421 static void dwarf2out_init (const char *);
2422 static void dwarf2out_finish (const char *);
2423 static void dwarf2out_early_finish (void);
2424 static void dwarf2out_assembly_start (void);
2425 static void dwarf2out_define (unsigned int, const char *);
2426 static void dwarf2out_undef (unsigned int, const char *);
2427 static void dwarf2out_start_source_file (unsigned, const char *);
2428 static void dwarf2out_end_source_file (unsigned);
2429 static void dwarf2out_function_decl (tree
);
2430 static void dwarf2out_begin_block (unsigned, unsigned);
2431 static void dwarf2out_end_block (unsigned, unsigned);
2432 static bool dwarf2out_ignore_block (const_tree
);
2433 static void dwarf2out_early_global_decl (tree
);
2434 static void dwarf2out_late_global_decl (tree
);
2435 static void dwarf2out_type_decl (tree
, int);
2436 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2437 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2439 static void dwarf2out_abstract_function (tree
);
2440 static void dwarf2out_var_location (rtx_insn
*);
2441 static void dwarf2out_begin_function (tree
);
2442 static void dwarf2out_end_function (unsigned int);
2443 static void dwarf2out_register_main_translation_unit (tree unit
);
2444 static void dwarf2out_set_name (tree
, tree
);
2446 /* The debug hooks structure. */
2448 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2452 dwarf2out_early_finish
,
2453 dwarf2out_assembly_start
,
2456 dwarf2out_start_source_file
,
2457 dwarf2out_end_source_file
,
2458 dwarf2out_begin_block
,
2459 dwarf2out_end_block
,
2460 dwarf2out_ignore_block
,
2461 dwarf2out_source_line
,
2462 dwarf2out_begin_prologue
,
2463 #if VMS_DEBUGGING_INFO
2464 dwarf2out_vms_end_prologue
,
2465 dwarf2out_vms_begin_epilogue
,
2467 debug_nothing_int_charstar
,
2468 debug_nothing_int_charstar
,
2470 dwarf2out_end_epilogue
,
2471 dwarf2out_begin_function
,
2472 dwarf2out_end_function
, /* end_function */
2473 dwarf2out_register_main_translation_unit
,
2474 dwarf2out_function_decl
, /* function_decl */
2475 dwarf2out_early_global_decl
,
2476 dwarf2out_late_global_decl
,
2477 dwarf2out_type_decl
, /* type_decl */
2478 dwarf2out_imported_module_or_decl
,
2479 debug_nothing_tree
, /* deferred_inline_function */
2480 /* The DWARF 2 backend tries to reduce debugging bloat by not
2481 emitting the abstract description of inline functions until
2482 something tries to reference them. */
2483 dwarf2out_abstract_function
, /* outlining_inline_function */
2484 debug_nothing_rtx_code_label
, /* label */
2485 debug_nothing_int
, /* handle_pch */
2486 dwarf2out_var_location
,
2487 dwarf2out_switch_text_section
,
2489 1, /* start_end_main_source_file */
2490 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2493 /* NOTE: In the comments in this file, many references are made to
2494 "Debugging Information Entries". This term is abbreviated as `DIE'
2495 throughout the remainder of this file. */
2497 /* An internal representation of the DWARF output is built, and then
2498 walked to generate the DWARF debugging info. The walk of the internal
2499 representation is done after the entire program has been compiled.
2500 The types below are used to describe the internal representation. */
2502 /* Whether to put type DIEs into their own section .debug_types instead
2503 of making them part of the .debug_info section. Only supported for
2504 Dwarf V4 or higher and the user didn't disable them through
2505 -fno-debug-types-section. It is more efficient to put them in a
2506 separate comdat sections since the linker will then be able to
2507 remove duplicates. But not all tools support .debug_types sections
2510 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2512 /* Various DIE's use offsets relative to the beginning of the
2513 .debug_info section to refer to each other. */
2515 typedef long int dw_offset
;
2517 /* Define typedefs here to avoid circular dependencies. */
2519 typedef struct dw_attr_struct
*dw_attr_ref
;
2520 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2521 typedef struct pubname_struct
*pubname_ref
;
2522 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2523 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2524 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2526 /* The entries in the line_info table more-or-less mirror the opcodes
2527 that are used in the real dwarf line table. Arrays of these entries
2528 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2531 enum dw_line_info_opcode
{
2532 /* Emit DW_LNE_set_address; the operand is the label index. */
2535 /* Emit a row to the matrix with the given line. This may be done
2536 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2540 /* Emit a DW_LNS_set_file. */
2543 /* Emit a DW_LNS_set_column. */
2546 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2549 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2550 LI_set_prologue_end
,
2551 LI_set_epilogue_begin
,
2553 /* Emit a DW_LNE_set_discriminator. */
2554 LI_set_discriminator
2557 typedef struct GTY(()) dw_line_info_struct
{
2558 enum dw_line_info_opcode opcode
;
2560 } dw_line_info_entry
;
2563 typedef struct GTY(()) dw_line_info_table_struct
{
2564 /* The label that marks the end of this section. */
2565 const char *end_label
;
2567 /* The values for the last row of the matrix, as collected in the table.
2568 These are used to minimize the changes to the next row. */
2569 unsigned int file_num
;
2570 unsigned int line_num
;
2571 unsigned int column_num
;
2576 vec
<dw_line_info_entry
, va_gc
> *entries
;
2577 } dw_line_info_table
;
2579 typedef dw_line_info_table
*dw_line_info_table_p
;
2582 /* Each DIE attribute has a field specifying the attribute kind,
2583 a link to the next attribute in the chain, and an attribute value.
2584 Attributes are typically linked below the DIE they modify. */
2586 typedef struct GTY(()) dw_attr_struct
{
2587 enum dwarf_attribute dw_attr
;
2588 dw_val_node dw_attr_val
;
2593 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2594 The children of each node form a circular list linked by
2595 die_sib. die_child points to the node *before* the "first" child node. */
2597 typedef struct GTY((chain_circular ("%h.die_sib"), for_user
)) die_struct
{
2598 union die_symbol_or_type_node
2600 const char * GTY ((tag ("0"))) die_symbol
;
2601 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2603 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2604 vec
<dw_attr_node
, va_gc
> *die_attr
;
2605 dw_die_ref die_parent
;
2606 dw_die_ref die_child
;
2608 dw_die_ref die_definition
; /* ref from a specification to its definition */
2609 dw_offset die_offset
;
2610 unsigned long die_abbrev
;
2612 unsigned int decl_id
;
2613 enum dwarf_tag die_tag
;
2614 /* Die is used and must not be pruned as unused. */
2615 BOOL_BITFIELD die_perennial_p
: 1;
2616 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2617 /* Lots of spare bits. */
2621 /* Set to TRUE while dwarf2out_early_global_decl is running. */
2622 static bool early_dwarf
;
2623 struct set_early_dwarf
{
2625 set_early_dwarf () : saved(early_dwarf
) { early_dwarf
= true; }
2626 ~set_early_dwarf () { early_dwarf
= saved
; }
2629 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2630 #define FOR_EACH_CHILD(die, c, expr) do { \
2631 c = die->die_child; \
2635 } while (c != die->die_child); \
2638 /* The pubname structure */
2640 typedef struct GTY(()) pubname_struct
{
2647 struct GTY(()) dw_ranges_struct
{
2648 /* If this is positive, it's a block number, otherwise it's a
2649 bitwise-negated index into dw_ranges_by_label. */
2653 /* A structure to hold a macinfo entry. */
2655 typedef struct GTY(()) macinfo_struct
{
2657 unsigned HOST_WIDE_INT lineno
;
2663 struct GTY(()) dw_ranges_by_label_struct
{
2668 /* The comdat type node structure. */
2669 typedef struct GTY(()) comdat_type_struct
2671 dw_die_ref root_die
;
2672 dw_die_ref type_die
;
2673 dw_die_ref skeleton_die
;
2674 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2675 struct comdat_type_struct
*next
;
2679 /* A list of DIEs for which we can't determine ancestry (parent_die
2680 field) just yet. Later in dwarf2out_finish we will fill in the
2682 typedef struct GTY(()) limbo_die_struct
{
2684 /* The tree for which this DIE was created. We use this to
2685 determine ancestry later. */
2687 struct limbo_die_struct
*next
;
2691 typedef struct skeleton_chain_struct
2695 struct skeleton_chain_struct
*parent
;
2697 skeleton_chain_node
;
2699 /* Define a macro which returns nonzero for a TYPE_DECL which was
2700 implicitly generated for a type.
2702 Note that, unlike the C front-end (which generates a NULL named
2703 TYPE_DECL node for each complete tagged type, each array type,
2704 and each function type node created) the C++ front-end generates
2705 a _named_ TYPE_DECL node for each tagged type node created.
2706 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2707 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2708 front-end, but for each type, tagged or not. */
2710 #define TYPE_DECL_IS_STUB(decl) \
2711 (DECL_NAME (decl) == NULL_TREE \
2712 || (DECL_ARTIFICIAL (decl) \
2713 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2714 /* This is necessary for stub decls that \
2715 appear in nested inline functions. */ \
2716 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2717 && (decl_ultimate_origin (decl) \
2718 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2720 /* Information concerning the compilation unit's programming
2721 language, and compiler version. */
2723 /* Fixed size portion of the DWARF compilation unit header. */
2724 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2725 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2727 /* Fixed size portion of the DWARF comdat type unit header. */
2728 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2729 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2730 + DWARF_OFFSET_SIZE)
2732 /* Fixed size portion of public names info. */
2733 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2735 /* Fixed size portion of the address range info. */
2736 #define DWARF_ARANGES_HEADER_SIZE \
2737 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2738 DWARF2_ADDR_SIZE * 2) \
2739 - DWARF_INITIAL_LENGTH_SIZE)
2741 /* Size of padding portion in the address range info. It must be
2742 aligned to twice the pointer size. */
2743 #define DWARF_ARANGES_PAD_SIZE \
2744 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2745 DWARF2_ADDR_SIZE * 2) \
2746 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2748 /* Use assembler line directives if available. */
2749 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2750 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2751 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2753 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2757 /* Minimum line offset in a special line info. opcode.
2758 This value was chosen to give a reasonable range of values. */
2759 #define DWARF_LINE_BASE -10
2761 /* First special line opcode - leave room for the standard opcodes. */
2762 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2764 /* Range of line offsets in a special line info. opcode. */
2765 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2767 /* Flag that indicates the initial value of the is_stmt_start flag.
2768 In the present implementation, we do not mark any lines as
2769 the beginning of a source statement, because that information
2770 is not made available by the GCC front-end. */
2771 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2773 /* Maximum number of operations per instruction bundle. */
2774 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2775 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2778 /* This location is used by calc_die_sizes() to keep track
2779 the offset of each DIE within the .debug_info section. */
2780 static unsigned long next_die_offset
;
2782 /* Record the root of the DIE's built for the current compilation unit. */
2783 static GTY(()) dw_die_ref single_comp_unit_die
;
2785 /* A list of type DIEs that have been separated into comdat sections. */
2786 static GTY(()) comdat_type_node
*comdat_type_list
;
2788 /* A list of DIEs with a NULL parent waiting to be relocated. */
2789 static GTY(()) limbo_die_node
*limbo_die_list
;
2791 /* A list of DIEs for which we may have to generate
2792 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2793 static GTY(()) limbo_die_node
*deferred_asm_name
;
2795 struct dwarf_file_hasher
: ggc_ptr_hash
<dwarf_file_data
>
2797 typedef const char *compare_type
;
2799 static hashval_t
hash (dwarf_file_data
*);
2800 static bool equal (dwarf_file_data
*, const char *);
2803 /* Filenames referenced by this compilation unit. */
2804 static GTY(()) hash_table
<dwarf_file_hasher
> *file_table
;
2806 struct decl_die_hasher
: ggc_ptr_hash
<die_node
>
2808 typedef tree compare_type
;
2810 static hashval_t
hash (die_node
*);
2811 static bool equal (die_node
*, tree
);
2813 /* A hash table of references to DIE's that describe declarations.
2814 The key is a DECL_UID() which is a unique number identifying each decl. */
2815 static GTY (()) hash_table
<decl_die_hasher
> *decl_die_table
;
2817 struct block_die_hasher
: ggc_ptr_hash
<die_struct
>
2819 static hashval_t
hash (die_struct
*);
2820 static bool equal (die_struct
*, die_struct
*);
2823 /* A hash table of references to DIE's that describe COMMON blocks.
2824 The key is DECL_UID() ^ die_parent. */
2825 static GTY (()) hash_table
<block_die_hasher
> *common_block_die_table
;
2827 typedef struct GTY(()) die_arg_entry_struct
{
2833 /* Node of the variable location list. */
2834 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2835 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2836 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2837 in mode of the EXPR_LIST node and first EXPR_LIST operand
2838 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2839 location or NULL for padding. For larger bitsizes,
2840 mode is 0 and first operand is a CONCAT with bitsize
2841 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2842 NULL as second operand. */
2844 const char * GTY (()) label
;
2845 struct var_loc_node
* GTY (()) next
;
2848 /* Variable location list. */
2849 struct GTY ((for_user
)) var_loc_list_def
{
2850 struct var_loc_node
* GTY (()) first
;
2852 /* Pointer to the last but one or last element of the
2853 chained list. If the list is empty, both first and
2854 last are NULL, if the list contains just one node
2855 or the last node certainly is not redundant, it points
2856 to the last node, otherwise points to the last but one.
2857 Do not mark it for GC because it is marked through the chain. */
2858 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2860 /* Pointer to the last element before section switch,
2861 if NULL, either sections weren't switched or first
2862 is after section switch. */
2863 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2865 /* DECL_UID of the variable decl. */
2866 unsigned int decl_id
;
2868 typedef struct var_loc_list_def var_loc_list
;
2870 /* Call argument location list. */
2871 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2872 rtx
GTY (()) call_arg_loc_note
;
2873 const char * GTY (()) label
;
2874 tree
GTY (()) block
;
2876 rtx
GTY (()) symbol_ref
;
2877 struct call_arg_loc_node
* GTY (()) next
;
2881 struct decl_loc_hasher
: ggc_ptr_hash
<var_loc_list
>
2883 typedef const_tree compare_type
;
2885 static hashval_t
hash (var_loc_list
*);
2886 static bool equal (var_loc_list
*, const_tree
);
2889 /* Table of decl location linked lists. */
2890 static GTY (()) hash_table
<decl_loc_hasher
> *decl_loc_table
;
2892 /* Head and tail of call_arg_loc chain. */
2893 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2894 static struct call_arg_loc_node
*call_arg_loc_last
;
2896 /* Number of call sites in the current function. */
2897 static int call_site_count
= -1;
2898 /* Number of tail call sites in the current function. */
2899 static int tail_call_site_count
= -1;
2901 /* A cached location list. */
2902 struct GTY ((for_user
)) cached_dw_loc_list_def
{
2903 /* The DECL_UID of the decl that this entry describes. */
2904 unsigned int decl_id
;
2906 /* The cached location list. */
2907 dw_loc_list_ref loc_list
;
2909 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2911 struct dw_loc_list_hasher
: ggc_ptr_hash
<cached_dw_loc_list
>
2914 typedef const_tree compare_type
;
2916 static hashval_t
hash (cached_dw_loc_list
*);
2917 static bool equal (cached_dw_loc_list
*, const_tree
);
2920 /* Table of cached location lists. */
2921 static GTY (()) hash_table
<dw_loc_list_hasher
> *cached_dw_loc_list_table
;
2923 /* A pointer to the base of a list of references to DIE's that
2924 are uniquely identified by their tag, presence/absence of
2925 children DIE's, and list of attribute/value pairs. */
2926 static GTY((length ("abbrev_die_table_allocated")))
2927 dw_die_ref
*abbrev_die_table
;
2929 /* Number of elements currently allocated for abbrev_die_table. */
2930 static GTY(()) unsigned abbrev_die_table_allocated
;
2932 /* Number of elements in abbrev_die_table currently in use. */
2933 static GTY(()) unsigned abbrev_die_table_in_use
;
2935 /* Size (in elements) of increments by which we may expand the
2936 abbrev_die_table. */
2937 #define ABBREV_DIE_TABLE_INCREMENT 256
2939 /* A global counter for generating labels for line number data. */
2940 static unsigned int line_info_label_num
;
2942 /* The current table to which we should emit line number information
2943 for the current function. This will be set up at the beginning of
2944 assembly for the function. */
2945 static dw_line_info_table
*cur_line_info_table
;
2947 /* The two default tables of line number info. */
2948 static GTY(()) dw_line_info_table
*text_section_line_info
;
2949 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2951 /* The set of all non-default tables of line number info. */
2952 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2954 /* A flag to tell pubnames/types export if there is an info section to
2956 static bool info_section_emitted
;
2958 /* A pointer to the base of a table that contains a list of publicly
2959 accessible names. */
2960 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2962 /* A pointer to the base of a table that contains a list of publicly
2963 accessible types. */
2964 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2966 /* A pointer to the base of a table that contains a list of macro
2967 defines/undefines (and file start/end markers). */
2968 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2970 /* True if .debug_macinfo or .debug_macros section is going to be
2972 #define have_macinfo \
2973 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2974 && !macinfo_table->is_empty ())
2976 /* Array of dies for which we should generate .debug_ranges info. */
2977 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2979 /* Number of elements currently allocated for ranges_table. */
2980 static GTY(()) unsigned ranges_table_allocated
;
2982 /* Number of elements in ranges_table currently in use. */
2983 static GTY(()) unsigned ranges_table_in_use
;
2985 /* Array of pairs of labels referenced in ranges_table. */
2986 static GTY ((length ("ranges_by_label_allocated")))
2987 dw_ranges_by_label_ref ranges_by_label
;
2989 /* Number of elements currently allocated for ranges_by_label. */
2990 static GTY(()) unsigned ranges_by_label_allocated
;
2992 /* Number of elements in ranges_by_label currently in use. */
2993 static GTY(()) unsigned ranges_by_label_in_use
;
2995 /* Size (in elements) of increments by which we may expand the
2997 #define RANGES_TABLE_INCREMENT 64
2999 /* Whether we have location lists that need outputting */
3000 static GTY(()) bool have_location_lists
;
3002 /* Unique label counter. */
3003 static GTY(()) unsigned int loclabel_num
;
3005 /* Unique label counter for point-of-call tables. */
3006 static GTY(()) unsigned int poc_label_num
;
3008 /* The last file entry emitted by maybe_emit_file(). */
3009 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
3011 /* Number of internal labels generated by gen_internal_sym(). */
3012 static GTY(()) int label_num
;
3014 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
3016 /* Instances of generic types for which we need to generate debug
3017 info that describe their generic parameters and arguments. That
3018 generation needs to happen once all types are properly laid out so
3019 we do it at the end of compilation. */
3020 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
3022 /* Offset from the "steady-state frame pointer" to the frame base,
3023 within the current function. */
3024 static HOST_WIDE_INT frame_pointer_fb_offset
;
3025 static bool frame_pointer_fb_offset_valid
;
3027 static vec
<dw_die_ref
> base_types
;
3029 /* Flags to represent a set of attribute classes for attributes that represent
3030 a scalar value (bounds, pointers, ...). */
3033 dw_scalar_form_constant
= 0x01,
3034 dw_scalar_form_exprloc
= 0x02,
3035 dw_scalar_form_reference
= 0x04
3038 /* Forward declarations for functions defined in this file. */
3040 static int is_pseudo_reg (const_rtx
);
3041 static tree
type_main_variant (tree
);
3042 static int is_tagged_type (const_tree
);
3043 static const char *dwarf_tag_name (unsigned);
3044 static const char *dwarf_attr_name (unsigned);
3045 static const char *dwarf_form_name (unsigned);
3046 static tree
decl_ultimate_origin (const_tree
);
3047 static tree
decl_class_context (tree
);
3048 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
3049 static inline enum dw_val_class
AT_class (dw_attr_ref
);
3050 static inline unsigned int AT_index (dw_attr_ref
);
3051 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
3052 static inline unsigned AT_flag (dw_attr_ref
);
3053 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
3054 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
3055 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
3056 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3057 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3058 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3059 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3060 unsigned int, unsigned char *);
3061 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3062 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3063 static inline const char *AT_string (dw_attr_ref
);
3064 static enum dwarf_form
AT_string_form (dw_attr_ref
);
3065 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3066 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3067 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3068 static inline int AT_ref_external (dw_attr_ref
);
3069 static inline void set_AT_ref_external (dw_attr_ref
, int);
3070 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3071 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3072 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3073 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3075 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3076 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3077 static void remove_addr_table_entry (addr_table_entry
*);
3078 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3079 static inline rtx
AT_addr (dw_attr_ref
);
3080 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3081 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3082 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3083 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3084 unsigned HOST_WIDE_INT
);
3085 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3086 unsigned long, bool);
3087 static inline const char *AT_lbl (dw_attr_ref
);
3088 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3089 static const char *get_AT_low_pc (dw_die_ref
);
3090 static const char *get_AT_hi_pc (dw_die_ref
);
3091 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3092 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3093 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3094 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3095 static bool is_cxx (void);
3096 static bool is_fortran (void);
3097 static bool is_ada (void);
3098 static bool remove_AT (dw_die_ref
, enum dwarf_attribute
);
3099 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3100 static void add_child_die (dw_die_ref
, dw_die_ref
);
3101 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3102 static dw_die_ref
lookup_type_die (tree
);
3103 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3104 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3105 static void equate_type_number_to_die (tree
, dw_die_ref
);
3106 static dw_die_ref
lookup_decl_die (tree
);
3107 static var_loc_list
*lookup_decl_loc (const_tree
);
3108 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3109 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3110 static void print_spaces (FILE *);
3111 static void print_die (dw_die_ref
, FILE *);
3112 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3113 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3114 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3115 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3116 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3117 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3118 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3119 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3120 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3121 struct md5_ctx
*, int *);
3122 struct checksum_attributes
;
3123 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3124 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3125 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3126 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3127 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3128 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3129 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3130 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3131 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3132 static void compute_section_prefix (dw_die_ref
);
3133 static int is_type_die (dw_die_ref
);
3134 static int is_comdat_die (dw_die_ref
);
3135 static int is_symbol_die (dw_die_ref
);
3136 static inline bool is_template_instantiation (dw_die_ref
);
3137 static void assign_symbol_names (dw_die_ref
);
3138 static void break_out_includes (dw_die_ref
);
3139 static int is_declaration_die (dw_die_ref
);
3140 static int should_move_die_to_comdat (dw_die_ref
);
3141 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3142 static dw_die_ref
clone_die (dw_die_ref
);
3143 static dw_die_ref
clone_tree (dw_die_ref
);
3144 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3145 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3146 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3147 static dw_die_ref
generate_skeleton (dw_die_ref
);
3148 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3151 static void break_out_comdat_types (dw_die_ref
);
3152 static void copy_decls_for_unworthy_types (dw_die_ref
);
3154 static void add_sibling_attributes (dw_die_ref
);
3155 static void output_location_lists (dw_die_ref
);
3156 static int constant_size (unsigned HOST_WIDE_INT
);
3157 static unsigned long size_of_die (dw_die_ref
);
3158 static void calc_die_sizes (dw_die_ref
);
3159 static void calc_base_type_die_sizes (void);
3160 static void mark_dies (dw_die_ref
);
3161 static void unmark_dies (dw_die_ref
);
3162 static void unmark_all_dies (dw_die_ref
);
3163 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3164 static unsigned long size_of_aranges (void);
3165 static enum dwarf_form
value_format (dw_attr_ref
);
3166 static void output_value_format (dw_attr_ref
);
3167 static void output_abbrev_section (void);
3168 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3169 static void output_die_symbol (dw_die_ref
);
3170 static void output_die (dw_die_ref
);
3171 static void output_compilation_unit_header (void);
3172 static void output_comp_unit (dw_die_ref
, int);
3173 static void output_comdat_type_unit (comdat_type_node
*);
3174 static const char *dwarf2_name (tree
, int);
3175 static void add_pubname (tree
, dw_die_ref
);
3176 static void add_enumerator_pubname (const char *, dw_die_ref
);
3177 static void add_pubname_string (const char *, dw_die_ref
);
3178 static void add_pubtype (tree
, dw_die_ref
);
3179 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3180 static void output_aranges (unsigned long);
3181 static unsigned int add_ranges_num (int);
3182 static unsigned int add_ranges (const_tree
);
3183 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3185 static void output_ranges (void);
3186 static dw_line_info_table
*new_line_info_table (void);
3187 static void output_line_info (bool);
3188 static void output_file_names (void);
3189 static dw_die_ref
base_type_die (tree
);
3190 static int is_base_type (tree
);
3191 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3192 static int decl_quals (const_tree
);
3193 static dw_die_ref
modified_type_die (tree
, int, dw_die_ref
);
3194 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3195 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3196 static int type_is_enum (const_tree
);
3197 static unsigned int dbx_reg_number (const_rtx
);
3198 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3199 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3200 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3201 enum var_init_status
);
3202 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3203 enum var_init_status
);
3204 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3205 enum var_init_status
);
3206 static int is_based_loc (const_rtx
);
3207 static bool resolve_one_addr (rtx
*);
3208 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3209 enum var_init_status
);
3210 static dw_loc_descr_ref
loc_descriptor (rtx
, machine_mode mode
,
3211 enum var_init_status
);
3212 struct loc_descr_context
;
3213 static dw_loc_list_ref
loc_list_from_tree (tree
, int,
3214 const struct loc_descr_context
*);
3215 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int,
3216 const struct loc_descr_context
*);
3217 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3218 static tree
field_type (const_tree
);
3219 static unsigned int simple_type_align_in_bits (const_tree
);
3220 static unsigned int simple_decl_align_in_bits (const_tree
);
3221 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3222 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3223 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3225 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3226 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3227 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3228 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3229 static void insert_float (const_rtx
, unsigned char *);
3230 static rtx
rtl_for_decl_location (tree
);
3231 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3232 enum dwarf_attribute
);
3233 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3234 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3235 static void add_name_attribute (dw_die_ref
, const char *);
3236 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3237 static void add_comp_dir_attribute (dw_die_ref
);
3238 static void add_scalar_info (dw_die_ref
, enum dwarf_attribute
, tree
, int,
3239 const struct loc_descr_context
*);
3240 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
,
3241 const struct loc_descr_context
*);
3242 static void add_subscript_info (dw_die_ref
, tree
, bool);
3243 static void add_byte_size_attribute (dw_die_ref
, tree
);
3244 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3245 static void add_bit_size_attribute (dw_die_ref
, tree
);
3246 static void add_prototyped_attribute (dw_die_ref
, tree
);
3247 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3248 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3249 static void add_src_coords_attributes (dw_die_ref
, tree
);
3250 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3251 static void push_decl_scope (tree
);
3252 static void pop_decl_scope (void);
3253 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3254 static inline int local_scope_p (dw_die_ref
);
3255 static inline int class_scope_p (dw_die_ref
);
3256 static inline int class_or_namespace_scope_p (dw_die_ref
);
3257 static void add_type_attribute (dw_die_ref
, tree
, int, dw_die_ref
);
3258 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3259 static const char *type_tag (const_tree
);
3260 static tree
member_declared_type (const_tree
);
3262 static const char *decl_start_label (tree
);
3264 static void gen_array_type_die (tree
, dw_die_ref
);
3265 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3267 static void gen_entry_point_die (tree
, dw_die_ref
);
3269 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3270 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3271 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3272 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3273 static void gen_formal_types_die (tree
, dw_die_ref
);
3274 static void gen_subprogram_die (tree
, dw_die_ref
);
3275 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3276 static void gen_const_die (tree
, dw_die_ref
);
3277 static void gen_label_die (tree
, dw_die_ref
);
3278 static void gen_lexical_block_die (tree
, dw_die_ref
);
3279 static void gen_inlined_subroutine_die (tree
, dw_die_ref
);
3280 static void gen_field_die (tree
, dw_die_ref
);
3281 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3282 static dw_die_ref
gen_compile_unit_die (const char *);
3283 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3284 static void gen_member_die (tree
, dw_die_ref
);
3285 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3286 enum debug_info_usage
);
3287 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3288 static void gen_typedef_die (tree
, dw_die_ref
);
3289 static void gen_type_die (tree
, dw_die_ref
);
3290 static void gen_block_die (tree
, dw_die_ref
);
3291 static void decls_for_scope (tree
, dw_die_ref
);
3292 static inline int is_redundant_typedef (const_tree
);
3293 static bool is_naming_typedef_decl (const_tree
);
3294 static inline dw_die_ref
get_context_die (tree
);
3295 static void gen_namespace_die (tree
, dw_die_ref
);
3296 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3297 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3298 static dw_die_ref
force_decl_die (tree
);
3299 static dw_die_ref
force_type_die (tree
);
3300 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3301 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3302 static struct dwarf_file_data
* lookup_filename (const char *);
3303 static void retry_incomplete_types (void);
3304 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3305 static void gen_generic_params_dies (tree
);
3306 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3307 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3308 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3309 static int file_info_cmp (const void *, const void *);
3310 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3311 const char *, const char *);
3312 static void output_loc_list (dw_loc_list_ref
);
3313 static char *gen_internal_sym (const char *);
3314 static bool want_pubnames (void);
3316 static void prune_unmark_dies (dw_die_ref
);
3317 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3318 static void prune_unused_types_mark (dw_die_ref
, int);
3319 static void prune_unused_types_walk (dw_die_ref
);
3320 static void prune_unused_types_walk_attribs (dw_die_ref
);
3321 static void prune_unused_types_prune (dw_die_ref
);
3322 static void prune_unused_types (void);
3323 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3324 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3325 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3326 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3327 const char *, const char *);
3328 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3329 static void gen_remaining_tmpl_value_param_die_attribute (void);
3330 static bool generic_type_p (tree
);
3331 static void schedule_generic_params_dies_gen (tree t
);
3332 static void gen_scheduled_generic_parms_dies (void);
3334 static const char *comp_dir_string (void);
3336 static void hash_loc_operands (dw_loc_descr_ref
, inchash::hash
&);
3338 /* enum for tracking thread-local variables whose address is really an offset
3339 relative to the TLS pointer, which will need link-time relocation, but will
3340 not need relocation by the DWARF consumer. */
3348 /* Return the operator to use for an address of a variable. For dtprel_true, we
3349 use DW_OP_const*. For regular variables, which need both link-time
3350 relocation and consumer-level relocation (e.g., to account for shared objects
3351 loaded at a random address), we use DW_OP_addr*. */
3353 static inline enum dwarf_location_atom
3354 dw_addr_op (enum dtprel_bool dtprel
)
3356 if (dtprel
== dtprel_true
)
3357 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3358 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3360 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3363 /* Return a pointer to a newly allocated address location description. If
3364 dwarf_split_debug_info is true, then record the address with the appropriate
3366 static inline dw_loc_descr_ref
3367 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3369 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3371 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3372 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3373 ref
->dtprel
= dtprel
;
3374 if (dwarf_split_debug_info
)
3375 ref
->dw_loc_oprnd1
.val_entry
3376 = add_addr_table_entry (addr
,
3377 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3379 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3384 /* Section names used to hold DWARF debugging information. */
3386 #ifndef DEBUG_INFO_SECTION
3387 #define DEBUG_INFO_SECTION ".debug_info"
3389 #ifndef DEBUG_DWO_INFO_SECTION
3390 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3392 #ifndef DEBUG_ABBREV_SECTION
3393 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3395 #ifndef DEBUG_DWO_ABBREV_SECTION
3396 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3398 #ifndef DEBUG_ARANGES_SECTION
3399 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3401 #ifndef DEBUG_ADDR_SECTION
3402 #define DEBUG_ADDR_SECTION ".debug_addr"
3404 #ifndef DEBUG_NORM_MACINFO_SECTION
3405 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3407 #ifndef DEBUG_DWO_MACINFO_SECTION
3408 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3410 #ifndef DEBUG_MACINFO_SECTION
3411 #define DEBUG_MACINFO_SECTION \
3412 (!dwarf_split_debug_info \
3413 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3415 #ifndef DEBUG_NORM_MACRO_SECTION
3416 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3418 #ifndef DEBUG_DWO_MACRO_SECTION
3419 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3421 #ifndef DEBUG_MACRO_SECTION
3422 #define DEBUG_MACRO_SECTION \
3423 (!dwarf_split_debug_info \
3424 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3426 #ifndef DEBUG_LINE_SECTION
3427 #define DEBUG_LINE_SECTION ".debug_line"
3429 #ifndef DEBUG_DWO_LINE_SECTION
3430 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3432 #ifndef DEBUG_LOC_SECTION
3433 #define DEBUG_LOC_SECTION ".debug_loc"
3435 #ifndef DEBUG_DWO_LOC_SECTION
3436 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3438 #ifndef DEBUG_PUBNAMES_SECTION
3439 #define DEBUG_PUBNAMES_SECTION \
3440 ((debug_generate_pub_sections == 2) \
3441 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3443 #ifndef DEBUG_PUBTYPES_SECTION
3444 #define DEBUG_PUBTYPES_SECTION \
3445 ((debug_generate_pub_sections == 2) \
3446 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3448 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3449 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3450 #ifndef DEBUG_STR_OFFSETS_SECTION
3451 #define DEBUG_STR_OFFSETS_SECTION \
3452 (!dwarf_split_debug_info \
3453 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3455 #ifndef DEBUG_STR_DWO_SECTION
3456 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3458 #ifndef DEBUG_STR_SECTION
3459 #define DEBUG_STR_SECTION ".debug_str"
3461 #ifndef DEBUG_RANGES_SECTION
3462 #define DEBUG_RANGES_SECTION ".debug_ranges"
3465 /* Standard ELF section names for compiled code and data. */
3466 #ifndef TEXT_SECTION_NAME
3467 #define TEXT_SECTION_NAME ".text"
3470 /* Section flags for .debug_macinfo/.debug_macro section. */
3471 #define DEBUG_MACRO_SECTION_FLAGS \
3472 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3474 /* Section flags for .debug_str section. */
3475 #define DEBUG_STR_SECTION_FLAGS \
3476 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3477 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3480 /* Section flags for .debug_str.dwo section. */
3481 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3483 /* Labels we insert at beginning sections we can reference instead of
3484 the section names themselves. */
3486 #ifndef TEXT_SECTION_LABEL
3487 #define TEXT_SECTION_LABEL "Ltext"
3489 #ifndef COLD_TEXT_SECTION_LABEL
3490 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3492 #ifndef DEBUG_LINE_SECTION_LABEL
3493 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3495 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3496 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3498 #ifndef DEBUG_INFO_SECTION_LABEL
3499 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3501 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3502 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3504 #ifndef DEBUG_ABBREV_SECTION_LABEL
3505 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3507 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3508 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3510 #ifndef DEBUG_ADDR_SECTION_LABEL
3511 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3513 #ifndef DEBUG_LOC_SECTION_LABEL
3514 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3516 #ifndef DEBUG_RANGES_SECTION_LABEL
3517 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3519 #ifndef DEBUG_MACINFO_SECTION_LABEL
3520 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3522 #ifndef DEBUG_MACRO_SECTION_LABEL
3523 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3525 #define SKELETON_COMP_DIE_ABBREV 1
3526 #define SKELETON_TYPE_DIE_ABBREV 2
3528 /* Definitions of defaults for formats and names of various special
3529 (artificial) labels which may be generated within this file (when the -g
3530 options is used and DWARF2_DEBUGGING_INFO is in effect.
3531 If necessary, these may be overridden from within the tm.h file, but
3532 typically, overriding these defaults is unnecessary. */
3534 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3535 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3536 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3537 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3538 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3539 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3540 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3541 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3542 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3543 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3544 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3545 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3546 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3547 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3549 #ifndef TEXT_END_LABEL
3550 #define TEXT_END_LABEL "Letext"
3552 #ifndef COLD_END_LABEL
3553 #define COLD_END_LABEL "Letext_cold"
3555 #ifndef BLOCK_BEGIN_LABEL
3556 #define BLOCK_BEGIN_LABEL "LBB"
3558 #ifndef BLOCK_END_LABEL
3559 #define BLOCK_END_LABEL "LBE"
3561 #ifndef LINE_CODE_LABEL
3562 #define LINE_CODE_LABEL "LM"
3566 /* Return the root of the DIE's built for the current compilation unit. */
3568 comp_unit_die (void)
3570 if (!single_comp_unit_die
)
3571 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3572 return single_comp_unit_die
;
3575 /* We allow a language front-end to designate a function that is to be
3576 called to "demangle" any name before it is put into a DIE. */
3578 static const char *(*demangle_name_func
) (const char *);
3581 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3583 demangle_name_func
= func
;
3586 /* Test if rtl node points to a pseudo register. */
3589 is_pseudo_reg (const_rtx rtl
)
3591 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3592 || (GET_CODE (rtl
) == SUBREG
3593 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3596 /* Return a reference to a type, with its const and volatile qualifiers
3600 type_main_variant (tree type
)
3602 type
= TYPE_MAIN_VARIANT (type
);
3604 /* ??? There really should be only one main variant among any group of
3605 variants of a given type (and all of the MAIN_VARIANT values for all
3606 members of the group should point to that one type) but sometimes the C
3607 front-end messes this up for array types, so we work around that bug
3609 if (TREE_CODE (type
) == ARRAY_TYPE
)
3610 while (type
!= TYPE_MAIN_VARIANT (type
))
3611 type
= TYPE_MAIN_VARIANT (type
);
3616 /* Return nonzero if the given type node represents a tagged type. */
3619 is_tagged_type (const_tree type
)
3621 enum tree_code code
= TREE_CODE (type
);
3623 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3624 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3627 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3630 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3632 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3635 /* Return die_offset of a DIE reference to a base type. */
3637 static unsigned long int
3638 get_base_type_offset (dw_die_ref ref
)
3640 if (ref
->die_offset
)
3641 return ref
->die_offset
;
3642 if (comp_unit_die ()->die_abbrev
)
3644 calc_base_type_die_sizes ();
3645 gcc_assert (ref
->die_offset
);
3647 return ref
->die_offset
;
3650 /* Return die_offset of a DIE reference other than base type. */
3652 static unsigned long int
3653 get_ref_die_offset (dw_die_ref ref
)
3655 gcc_assert (ref
->die_offset
);
3656 return ref
->die_offset
;
3659 /* Convert a DIE tag into its string name. */
3662 dwarf_tag_name (unsigned int tag
)
3664 const char *name
= get_DW_TAG_name (tag
);
3669 return "DW_TAG_<unknown>";
3672 /* Convert a DWARF attribute code into its string name. */
3675 dwarf_attr_name (unsigned int attr
)
3681 #if VMS_DEBUGGING_INFO
3682 case DW_AT_HP_prologue
:
3683 return "DW_AT_HP_prologue";
3685 case DW_AT_MIPS_loop_unroll_factor
:
3686 return "DW_AT_MIPS_loop_unroll_factor";
3689 #if VMS_DEBUGGING_INFO
3690 case DW_AT_HP_epilogue
:
3691 return "DW_AT_HP_epilogue";
3693 case DW_AT_MIPS_stride
:
3694 return "DW_AT_MIPS_stride";
3698 name
= get_DW_AT_name (attr
);
3703 return "DW_AT_<unknown>";
3706 /* Convert a DWARF value form code into its string name. */
3709 dwarf_form_name (unsigned int form
)
3711 const char *name
= get_DW_FORM_name (form
);
3716 return "DW_FORM_<unknown>";
3719 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3720 instance of an inlined instance of a decl which is local to an inline
3721 function, so we have to trace all of the way back through the origin chain
3722 to find out what sort of node actually served as the original seed for the
3726 decl_ultimate_origin (const_tree decl
)
3728 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3731 /* DECL_ABSTRACT_ORIGIN can point to itself; ignore that if
3732 we're trying to output the abstract instance of this function. */
3733 if (DECL_ABSTRACT_P (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3736 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3737 most distant ancestor, this should never happen. */
3738 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3740 return DECL_ABSTRACT_ORIGIN (decl
);
3743 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3744 of a virtual function may refer to a base class, so we check the 'this'
3748 decl_class_context (tree decl
)
3750 tree context
= NULL_TREE
;
3752 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3753 context
= DECL_CONTEXT (decl
);
3755 context
= TYPE_MAIN_VARIANT
3756 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3758 if (context
&& !TYPE_P (context
))
3759 context
= NULL_TREE
;
3764 /* Add an attribute/value pair to a DIE. */
3767 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3769 /* Maybe this should be an assert? */
3773 vec_safe_reserve (die
->die_attr
, 1);
3774 vec_safe_push (die
->die_attr
, *attr
);
3777 static inline enum dw_val_class
3778 AT_class (dw_attr_ref a
)
3780 return a
->dw_attr_val
.val_class
;
3783 /* Return the index for any attribute that will be referenced with a
3784 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3785 are stored in dw_attr_val.v.val_str for reference counting
3788 static inline unsigned int
3789 AT_index (dw_attr_ref a
)
3791 if (AT_class (a
) == dw_val_class_str
)
3792 return a
->dw_attr_val
.v
.val_str
->index
;
3793 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3794 return a
->dw_attr_val
.val_entry
->index
;
3798 /* Add a flag value attribute to a DIE. */
3801 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3805 attr
.dw_attr
= attr_kind
;
3806 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3807 attr
.dw_attr_val
.val_entry
= NULL
;
3808 attr
.dw_attr_val
.v
.val_flag
= flag
;
3809 add_dwarf_attr (die
, &attr
);
3812 static inline unsigned
3813 AT_flag (dw_attr_ref a
)
3815 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3816 return a
->dw_attr_val
.v
.val_flag
;
3819 /* Add a signed integer attribute value to a DIE. */
3822 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3826 attr
.dw_attr
= attr_kind
;
3827 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3828 attr
.dw_attr_val
.val_entry
= NULL
;
3829 attr
.dw_attr_val
.v
.val_int
= int_val
;
3830 add_dwarf_attr (die
, &attr
);
3833 static inline HOST_WIDE_INT
3834 AT_int (dw_attr_ref a
)
3836 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3837 return a
->dw_attr_val
.v
.val_int
;
3840 /* Add an unsigned integer attribute value to a DIE. */
3843 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3844 unsigned HOST_WIDE_INT unsigned_val
)
3848 attr
.dw_attr
= attr_kind
;
3849 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3850 attr
.dw_attr_val
.val_entry
= NULL
;
3851 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3852 add_dwarf_attr (die
, &attr
);
3855 static inline unsigned HOST_WIDE_INT
3856 AT_unsigned (dw_attr_ref a
)
3858 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3859 return a
->dw_attr_val
.v
.val_unsigned
;
3862 /* Add an unsigned wide integer attribute value to a DIE. */
3865 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3870 attr
.dw_attr
= attr_kind
;
3871 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
3872 attr
.dw_attr_val
.val_entry
= NULL
;
3873 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc
<wide_int
> ();
3874 *attr
.dw_attr_val
.v
.val_wide
= w
;
3875 add_dwarf_attr (die
, &attr
);
3878 /* Add an unsigned double integer attribute value to a DIE. */
3881 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3882 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3886 attr
.dw_attr
= attr_kind
;
3887 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3888 attr
.dw_attr_val
.val_entry
= NULL
;
3889 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3890 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3891 add_dwarf_attr (die
, &attr
);
3894 /* Add a floating point attribute value to a DIE and return it. */
3897 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3898 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3902 attr
.dw_attr
= attr_kind
;
3903 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3904 attr
.dw_attr_val
.val_entry
= NULL
;
3905 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3906 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3907 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3908 add_dwarf_attr (die
, &attr
);
3911 /* Add an 8-byte data attribute value to a DIE. */
3914 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3915 unsigned char data8
[8])
3919 attr
.dw_attr
= attr_kind
;
3920 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3921 attr
.dw_attr_val
.val_entry
= NULL
;
3922 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3923 add_dwarf_attr (die
, &attr
);
3926 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3927 dwarf_split_debug_info, address attributes in dies destined for the
3928 final executable have force_direct set to avoid using indexed
3932 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3938 lbl_id
= xstrdup (lbl_low
);
3939 attr
.dw_attr
= DW_AT_low_pc
;
3940 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3941 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3942 if (dwarf_split_debug_info
&& !force_direct
)
3943 attr
.dw_attr_val
.val_entry
3944 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3946 attr
.dw_attr_val
.val_entry
= NULL
;
3947 add_dwarf_attr (die
, &attr
);
3949 attr
.dw_attr
= DW_AT_high_pc
;
3950 if (dwarf_version
< 4)
3951 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3953 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3954 lbl_id
= xstrdup (lbl_high
);
3955 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3956 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3957 && dwarf_split_debug_info
&& !force_direct
)
3958 attr
.dw_attr_val
.val_entry
3959 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3961 attr
.dw_attr_val
.val_entry
= NULL
;
3962 add_dwarf_attr (die
, &attr
);
3965 /* Hash and equality functions for debug_str_hash. */
3968 indirect_string_hasher::hash (indirect_string_node
*x
)
3970 return htab_hash_string (x
->str
);
3974 indirect_string_hasher::equal (indirect_string_node
*x1
, const char *x2
)
3976 return strcmp (x1
->str
, x2
) == 0;
3979 /* Add STR to the given string hash table. */
3981 static struct indirect_string_node
*
3982 find_AT_string_in_table (const char *str
,
3983 hash_table
<indirect_string_hasher
> *table
)
3985 struct indirect_string_node
*node
;
3987 indirect_string_node
**slot
3988 = table
->find_slot_with_hash (str
, htab_hash_string (str
), INSERT
);
3991 node
= ggc_cleared_alloc
<indirect_string_node
> ();
3992 node
->str
= ggc_strdup (str
);
4002 /* Add STR to the indirect string hash table. */
4004 static struct indirect_string_node
*
4005 find_AT_string (const char *str
)
4007 if (! debug_str_hash
)
4008 debug_str_hash
= hash_table
<indirect_string_hasher
>::create_ggc (10);
4010 return find_AT_string_in_table (str
, debug_str_hash
);
4013 /* Add a string attribute value to a DIE. */
4016 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
4019 struct indirect_string_node
*node
;
4021 node
= find_AT_string (str
);
4023 attr
.dw_attr
= attr_kind
;
4024 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
4025 attr
.dw_attr_val
.val_entry
= NULL
;
4026 attr
.dw_attr_val
.v
.val_str
= node
;
4027 add_dwarf_attr (die
, &attr
);
4030 static inline const char *
4031 AT_string (dw_attr_ref a
)
4033 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4034 return a
->dw_attr_val
.v
.val_str
->str
;
4037 /* Call this function directly to bypass AT_string_form's logic to put
4038 the string inline in the die. */
4041 set_indirect_string (struct indirect_string_node
*node
)
4044 /* Already indirect is a no op. */
4045 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
4047 gcc_assert (node
->label
);
4050 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
4051 ++dw2_string_counter
;
4052 node
->label
= xstrdup (label
);
4054 if (!dwarf_split_debug_info
)
4056 node
->form
= DW_FORM_strp
;
4057 node
->index
= NOT_INDEXED
;
4061 node
->form
= DW_FORM_GNU_str_index
;
4062 node
->index
= NO_INDEX_ASSIGNED
;
4066 /* Find out whether a string should be output inline in DIE
4067 or out-of-line in .debug_str section. */
4069 static enum dwarf_form
4070 find_string_form (struct indirect_string_node
*node
)
4077 len
= strlen (node
->str
) + 1;
4079 /* If the string is shorter or equal to the size of the reference, it is
4080 always better to put it inline. */
4081 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4082 return node
->form
= DW_FORM_string
;
4084 /* If we cannot expect the linker to merge strings in .debug_str
4085 section, only put it into .debug_str if it is worth even in this
4087 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4088 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4089 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4090 return node
->form
= DW_FORM_string
;
4092 set_indirect_string (node
);
4097 /* Find out whether the string referenced from the attribute should be
4098 output inline in DIE or out-of-line in .debug_str section. */
4100 static enum dwarf_form
4101 AT_string_form (dw_attr_ref a
)
4103 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4104 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4107 /* Add a DIE reference attribute value to a DIE. */
4110 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4114 #ifdef ENABLE_CHECKING
4115 gcc_assert (targ_die
!= NULL
);
4117 /* With LTO we can end up trying to reference something we didn't create
4118 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4119 if (targ_die
== NULL
)
4123 attr
.dw_attr
= attr_kind
;
4124 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4125 attr
.dw_attr_val
.val_entry
= NULL
;
4126 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4127 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4128 add_dwarf_attr (die
, &attr
);
4131 /* Change DIE reference REF to point to NEW_DIE instead. */
4134 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4136 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4137 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4138 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4141 /* Add an AT_specification attribute to a DIE, and also make the back
4142 pointer from the specification to the definition. */
4145 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4147 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4148 gcc_assert (!targ_die
->die_definition
);
4149 targ_die
->die_definition
= die
;
4152 static inline dw_die_ref
4153 AT_ref (dw_attr_ref a
)
4155 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4156 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4160 AT_ref_external (dw_attr_ref a
)
4162 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4163 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4169 set_AT_ref_external (dw_attr_ref a
, int i
)
4171 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4172 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4175 /* Add an FDE reference attribute value to a DIE. */
4178 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4182 attr
.dw_attr
= attr_kind
;
4183 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4184 attr
.dw_attr_val
.val_entry
= NULL
;
4185 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4186 add_dwarf_attr (die
, &attr
);
4189 /* Add a location description attribute value to a DIE. */
4192 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4196 attr
.dw_attr
= attr_kind
;
4197 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4198 attr
.dw_attr_val
.val_entry
= NULL
;
4199 attr
.dw_attr_val
.v
.val_loc
= loc
;
4200 add_dwarf_attr (die
, &attr
);
4203 static inline dw_loc_descr_ref
4204 AT_loc (dw_attr_ref a
)
4206 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4207 return a
->dw_attr_val
.v
.val_loc
;
4211 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4215 attr
.dw_attr
= attr_kind
;
4216 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4217 attr
.dw_attr_val
.val_entry
= NULL
;
4218 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4219 add_dwarf_attr (die
, &attr
);
4220 have_location_lists
= true;
4223 static inline dw_loc_list_ref
4224 AT_loc_list (dw_attr_ref a
)
4226 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4227 return a
->dw_attr_val
.v
.val_loc_list
;
4230 static inline dw_loc_list_ref
*
4231 AT_loc_list_ptr (dw_attr_ref a
)
4233 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4234 return &a
->dw_attr_val
.v
.val_loc_list
;
4237 struct addr_hasher
: ggc_ptr_hash
<addr_table_entry
>
4239 static hashval_t
hash (addr_table_entry
*);
4240 static bool equal (addr_table_entry
*, addr_table_entry
*);
4243 /* Table of entries into the .debug_addr section. */
4245 static GTY (()) hash_table
<addr_hasher
> *addr_index_table
;
4247 /* Hash an address_table_entry. */
4250 addr_hasher::hash (addr_table_entry
*a
)
4252 inchash::hash hstate
;
4258 case ate_kind_rtx_dtprel
:
4261 case ate_kind_label
:
4262 return htab_hash_string (a
->addr
.label
);
4266 inchash::add_rtx (a
->addr
.rtl
, hstate
);
4267 return hstate
.end ();
4270 /* Determine equality for two address_table_entries. */
4273 addr_hasher::equal (addr_table_entry
*a1
, addr_table_entry
*a2
)
4275 if (a1
->kind
!= a2
->kind
)
4280 case ate_kind_rtx_dtprel
:
4281 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4282 case ate_kind_label
:
4283 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4289 /* Initialize an addr_table_entry. */
4292 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4298 case ate_kind_rtx_dtprel
:
4299 e
->addr
.rtl
= (rtx
) addr
;
4301 case ate_kind_label
:
4302 e
->addr
.label
= (char *) addr
;
4306 e
->index
= NO_INDEX_ASSIGNED
;
4309 /* Add attr to the address table entry to the table. Defer setting an
4310 index until output time. */
4312 static addr_table_entry
*
4313 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4315 addr_table_entry
*node
;
4316 addr_table_entry finder
;
4318 gcc_assert (dwarf_split_debug_info
);
4319 if (! addr_index_table
)
4320 addr_index_table
= hash_table
<addr_hasher
>::create_ggc (10);
4321 init_addr_table_entry (&finder
, kind
, addr
);
4322 addr_table_entry
**slot
= addr_index_table
->find_slot (&finder
, INSERT
);
4324 if (*slot
== HTAB_EMPTY_ENTRY
)
4326 node
= ggc_cleared_alloc
<addr_table_entry
> ();
4327 init_addr_table_entry (node
, kind
, addr
);
4337 /* Remove an entry from the addr table by decrementing its refcount.
4338 Strictly, decrementing the refcount would be enough, but the
4339 assertion that the entry is actually in the table has found
4343 remove_addr_table_entry (addr_table_entry
*entry
)
4345 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4346 /* After an index is assigned, the table is frozen. */
4347 gcc_assert (entry
->refcount
> 0 && entry
->index
== NO_INDEX_ASSIGNED
);
4351 /* Given a location list, remove all addresses it refers to from the
4355 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4357 for (; descr
; descr
= descr
->dw_loc_next
)
4358 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4360 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4361 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4365 /* A helper function for dwarf2out_finish called through
4366 htab_traverse. Assign an addr_table_entry its index. All entries
4367 must be collected into the table when this function is called,
4368 because the indexing code relies on htab_traverse to traverse nodes
4369 in the same order for each run. */
4372 index_addr_table_entry (addr_table_entry
**h
, unsigned int *index
)
4374 addr_table_entry
*node
= *h
;
4376 /* Don't index unreferenced nodes. */
4377 if (node
->refcount
== 0)
4380 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4381 node
->index
= *index
;
4387 /* Add an address constant attribute value to a DIE. When using
4388 dwarf_split_debug_info, address attributes in dies destined for the
4389 final executable should be direct references--setting the parameter
4390 force_direct ensures this behavior. */
4393 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4398 attr
.dw_attr
= attr_kind
;
4399 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4400 attr
.dw_attr_val
.v
.val_addr
= addr
;
4401 if (dwarf_split_debug_info
&& !force_direct
)
4402 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4404 attr
.dw_attr_val
.val_entry
= NULL
;
4405 add_dwarf_attr (die
, &attr
);
4408 /* Get the RTX from to an address DIE attribute. */
4411 AT_addr (dw_attr_ref a
)
4413 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4414 return a
->dw_attr_val
.v
.val_addr
;
4417 /* Add a file attribute value to a DIE. */
4420 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4421 struct dwarf_file_data
*fd
)
4425 attr
.dw_attr
= attr_kind
;
4426 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4427 attr
.dw_attr_val
.val_entry
= NULL
;
4428 attr
.dw_attr_val
.v
.val_file
= fd
;
4429 add_dwarf_attr (die
, &attr
);
4432 /* Get the dwarf_file_data from a file DIE attribute. */
4434 static inline struct dwarf_file_data
*
4435 AT_file (dw_attr_ref a
)
4437 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4438 return a
->dw_attr_val
.v
.val_file
;
4441 /* Add a vms delta attribute value to a DIE. */
4444 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4445 const char *lbl1
, const char *lbl2
)
4449 attr
.dw_attr
= attr_kind
;
4450 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4451 attr
.dw_attr_val
.val_entry
= NULL
;
4452 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4453 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4454 add_dwarf_attr (die
, &attr
);
4457 /* Add a label identifier attribute value to a DIE. */
4460 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4465 attr
.dw_attr
= attr_kind
;
4466 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4467 attr
.dw_attr_val
.val_entry
= NULL
;
4468 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4469 if (dwarf_split_debug_info
)
4470 attr
.dw_attr_val
.val_entry
4471 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4473 add_dwarf_attr (die
, &attr
);
4476 /* Add a section offset attribute value to a DIE, an offset into the
4477 debug_line section. */
4480 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4485 attr
.dw_attr
= attr_kind
;
4486 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4487 attr
.dw_attr_val
.val_entry
= NULL
;
4488 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4489 add_dwarf_attr (die
, &attr
);
4492 /* Add a section offset attribute value to a DIE, an offset into the
4493 debug_macinfo section. */
4496 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4501 attr
.dw_attr
= attr_kind
;
4502 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4503 attr
.dw_attr_val
.val_entry
= NULL
;
4504 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4505 add_dwarf_attr (die
, &attr
);
4508 /* Add an offset attribute value to a DIE. */
4511 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4512 unsigned HOST_WIDE_INT offset
)
4516 attr
.dw_attr
= attr_kind
;
4517 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4518 attr
.dw_attr_val
.val_entry
= NULL
;
4519 attr
.dw_attr_val
.v
.val_offset
= offset
;
4520 add_dwarf_attr (die
, &attr
);
4523 /* Add a range_list attribute value to a DIE. When using
4524 dwarf_split_debug_info, address attributes in dies destined for the
4525 final executable should be direct references--setting the parameter
4526 force_direct ensures this behavior. */
4528 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4529 #define RELOCATED_OFFSET (NULL)
4532 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4533 long unsigned int offset
, bool force_direct
)
4537 attr
.dw_attr
= attr_kind
;
4538 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4539 /* For the range_list attribute, use val_entry to store whether the
4540 offset should follow split-debug-info or normal semantics. This
4541 value is read in output_range_list_offset. */
4542 if (dwarf_split_debug_info
&& !force_direct
)
4543 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4545 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4546 attr
.dw_attr_val
.v
.val_offset
= offset
;
4547 add_dwarf_attr (die
, &attr
);
4550 /* Return the start label of a delta attribute. */
4552 static inline const char *
4553 AT_vms_delta1 (dw_attr_ref a
)
4555 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4556 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4559 /* Return the end label of a delta attribute. */
4561 static inline const char *
4562 AT_vms_delta2 (dw_attr_ref a
)
4564 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4565 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4568 static inline const char *
4569 AT_lbl (dw_attr_ref a
)
4571 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4572 || AT_class (a
) == dw_val_class_lineptr
4573 || AT_class (a
) == dw_val_class_macptr
4574 || AT_class (a
) == dw_val_class_high_pc
));
4575 return a
->dw_attr_val
.v
.val_lbl_id
;
4578 /* Get the attribute of type attr_kind. */
4581 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4585 dw_die_ref spec
= NULL
;
4590 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4591 if (a
->dw_attr
== attr_kind
)
4593 else if (a
->dw_attr
== DW_AT_specification
4594 || a
->dw_attr
== DW_AT_abstract_origin
)
4598 return get_AT (spec
, attr_kind
);
4603 /* Returns the parent of the declaration of DIE. */
4606 get_die_parent (dw_die_ref die
)
4613 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4614 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4617 return die
->die_parent
;
4620 /* Return the "low pc" attribute value, typically associated with a subprogram
4621 DIE. Return null if the "low pc" attribute is either not present, or if it
4622 cannot be represented as an assembler label identifier. */
4624 static inline const char *
4625 get_AT_low_pc (dw_die_ref die
)
4627 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4629 return a
? AT_lbl (a
) : NULL
;
4632 /* Return the "high pc" attribute value, typically associated with a subprogram
4633 DIE. Return null if the "high pc" attribute is either not present, or if it
4634 cannot be represented as an assembler label identifier. */
4636 static inline const char *
4637 get_AT_hi_pc (dw_die_ref die
)
4639 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4641 return a
? AT_lbl (a
) : NULL
;
4644 /* Return the value of the string attribute designated by ATTR_KIND, or
4645 NULL if it is not present. */
4647 static inline const char *
4648 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4650 dw_attr_ref a
= get_AT (die
, attr_kind
);
4652 return a
? AT_string (a
) : NULL
;
4655 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4656 if it is not present. */
4659 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4661 dw_attr_ref a
= get_AT (die
, attr_kind
);
4663 return a
? AT_flag (a
) : 0;
4666 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4667 if it is not present. */
4669 static inline unsigned
4670 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4672 dw_attr_ref a
= get_AT (die
, attr_kind
);
4674 return a
? AT_unsigned (a
) : 0;
4677 static inline dw_die_ref
4678 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4680 dw_attr_ref a
= get_AT (die
, attr_kind
);
4682 return a
? AT_ref (a
) : NULL
;
4685 static inline struct dwarf_file_data
*
4686 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4688 dw_attr_ref a
= get_AT (die
, attr_kind
);
4690 return a
? AT_file (a
) : NULL
;
4693 /* Return TRUE if the language is C++. */
4698 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4700 return (lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
4701 || lang
== DW_LANG_C_plus_plus_11
|| lang
== DW_LANG_C_plus_plus_14
);
4704 /* Return TRUE if the language is Java. */
4709 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4711 return lang
== DW_LANG_Java
;
4714 /* Return TRUE if the language is Fortran. */
4719 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4721 return (lang
== DW_LANG_Fortran77
4722 || lang
== DW_LANG_Fortran90
4723 || lang
== DW_LANG_Fortran95
4724 || lang
== DW_LANG_Fortran03
4725 || lang
== DW_LANG_Fortran08
);
4728 /* Return TRUE if the language is Ada. */
4733 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4735 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4738 /* Remove the specified attribute if present. Return TRUE if removal
4742 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4750 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4751 if (a
->dw_attr
== attr_kind
)
4753 if (AT_class (a
) == dw_val_class_str
)
4754 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4755 a
->dw_attr_val
.v
.val_str
->refcount
--;
4757 /* vec::ordered_remove should help reduce the number of abbrevs
4759 die
->die_attr
->ordered_remove (ix
);
4765 /* Remove CHILD from its parent. PREV must have the property that
4766 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4769 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4771 gcc_assert (child
->die_parent
== prev
->die_parent
);
4772 gcc_assert (prev
->die_sib
== child
);
4775 gcc_assert (child
->die_parent
->die_child
== child
);
4779 prev
->die_sib
= child
->die_sib
;
4780 if (child
->die_parent
->die_child
== child
)
4781 child
->die_parent
->die_child
= prev
;
4784 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4785 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4788 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4790 dw_die_ref parent
= old_child
->die_parent
;
4792 gcc_assert (parent
== prev
->die_parent
);
4793 gcc_assert (prev
->die_sib
== old_child
);
4795 new_child
->die_parent
= parent
;
4796 if (prev
== old_child
)
4798 gcc_assert (parent
->die_child
== old_child
);
4799 new_child
->die_sib
= new_child
;
4803 prev
->die_sib
= new_child
;
4804 new_child
->die_sib
= old_child
->die_sib
;
4806 if (old_child
->die_parent
->die_child
== old_child
)
4807 old_child
->die_parent
->die_child
= new_child
;
4810 /* Move all children from OLD_PARENT to NEW_PARENT. */
4813 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4816 new_parent
->die_child
= old_parent
->die_child
;
4817 old_parent
->die_child
= NULL
;
4818 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4821 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4825 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4831 dw_die_ref prev
= c
;
4833 while (c
->die_tag
== tag
)
4835 remove_child_with_prev (c
, prev
);
4836 c
->die_parent
= NULL
;
4837 /* Might have removed every child. */
4838 if (c
== c
->die_sib
)
4842 } while (c
!= die
->die_child
);
4845 /* Add a CHILD_DIE as the last child of DIE. */
4848 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4850 /* FIXME this should probably be an assert. */
4851 if (! die
|| ! child_die
)
4853 gcc_assert (die
!= child_die
);
4855 child_die
->die_parent
= die
;
4858 child_die
->die_sib
= die
->die_child
->die_sib
;
4859 die
->die_child
->die_sib
= child_die
;
4862 child_die
->die_sib
= child_die
;
4863 die
->die_child
= child_die
;
4866 /* Unassociate CHILD from its parent, and make its parent be
4870 reparent_child (dw_die_ref child
, dw_die_ref new_parent
)
4872 for (dw_die_ref p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4873 if (p
->die_sib
== child
)
4875 remove_child_with_prev (child
, p
);
4878 add_child_die (new_parent
, child
);
4881 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4882 is the specification, to the end of PARENT's list of children.
4883 This is done by removing and re-adding it. */
4886 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4888 /* We want the declaration DIE from inside the class, not the
4889 specification DIE at toplevel. */
4890 if (child
->die_parent
!= parent
)
4892 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4898 gcc_assert (child
->die_parent
== parent
4899 || (child
->die_parent
4900 == get_AT_ref (parent
, DW_AT_specification
)));
4902 reparent_child (child
, parent
);
4905 /* Create and return a new die with a parent of PARENT_DIE. If
4906 PARENT_DIE is NULL, the new DIE is placed in limbo and an
4907 associated tree T must be supplied to determine parenthood
4910 static inline dw_die_ref
4911 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4913 dw_die_ref die
= ggc_cleared_alloc
<die_node
> ();
4915 die
->die_tag
= tag_value
;
4917 if (parent_die
!= NULL
)
4918 add_child_die (parent_die
, die
);
4921 limbo_die_node
*limbo_node
;
4923 /* No DIEs created after early dwarf should end up in limbo,
4924 because the limbo list should not persist past LTO
4926 if (tag_value
!= DW_TAG_compile_unit
4927 /* These are allowed because they're generated while
4928 breaking out COMDAT units late. */
4929 && tag_value
!= DW_TAG_type_unit
4931 /* Allow nested functions to live in limbo because they will
4932 only temporarily live there, as decls_for_scope will fix
4934 && (TREE_CODE (t
) != FUNCTION_DECL
4935 || !decl_function_context (t
))
4936 /* Same as nested functions above but for types. Types that
4937 are local to a function will be fixed in
4939 && (!RECORD_OR_UNION_TYPE_P (t
)
4940 || !TYPE_CONTEXT (t
)
4941 || TREE_CODE (TYPE_CONTEXT (t
)) != FUNCTION_DECL
)
4942 /* FIXME debug-early: Allow late limbo DIE creation for LTO,
4943 especially in the ltrans stage, but once we implement LTO
4944 dwarf streaming, we should remove this exception. */
4947 fprintf (stderr
, "symbol ended up in limbo too late:");
4948 debug_generic_stmt (t
);
4952 limbo_node
= ggc_cleared_alloc
<limbo_die_node
> ();
4953 limbo_node
->die
= die
;
4954 limbo_node
->created_for
= t
;
4955 limbo_node
->next
= limbo_die_list
;
4956 limbo_die_list
= limbo_node
;
4962 /* Return the DIE associated with the given type specifier. */
4964 static inline dw_die_ref
4965 lookup_type_die (tree type
)
4967 return TYPE_SYMTAB_DIE (type
);
4970 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4971 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4972 anonymous type instead the one of the naming typedef. */
4974 static inline dw_die_ref
4975 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4978 && TREE_CODE (type
) == RECORD_TYPE
4980 && type_die
->die_tag
== DW_TAG_typedef
4981 && is_naming_typedef_decl (TYPE_NAME (type
)))
4982 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4986 /* Like lookup_type_die, but if type is an anonymous type named by a
4987 typedef[1], return the DIE of the anonymous type instead the one of
4988 the naming typedef. This is because in gen_typedef_die, we did
4989 equate the anonymous struct named by the typedef with the DIE of
4990 the naming typedef. So by default, lookup_type_die on an anonymous
4991 struct yields the DIE of the naming typedef.
4993 [1]: Read the comment of is_naming_typedef_decl to learn about what
4994 a naming typedef is. */
4996 static inline dw_die_ref
4997 lookup_type_die_strip_naming_typedef (tree type
)
4999 dw_die_ref die
= lookup_type_die (type
);
5000 return strip_naming_typedef (type
, die
);
5003 /* Equate a DIE to a given type specifier. */
5006 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
5008 TYPE_SYMTAB_DIE (type
) = type_die
;
5011 /* Returns a hash value for X (which really is a die_struct). */
5014 decl_die_hasher::hash (die_node
*x
)
5016 return (hashval_t
) x
->decl_id
;
5019 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
5022 decl_die_hasher::equal (die_node
*x
, tree y
)
5024 return (x
->decl_id
== DECL_UID (y
));
5027 /* Return the DIE associated with a given declaration. */
5029 static inline dw_die_ref
5030 lookup_decl_die (tree decl
)
5032 return decl_die_table
->find_with_hash (decl
, DECL_UID (decl
));
5035 /* Returns a hash value for X (which really is a var_loc_list). */
5038 decl_loc_hasher::hash (var_loc_list
*x
)
5040 return (hashval_t
) x
->decl_id
;
5043 /* Return nonzero if decl_id of var_loc_list X is the same as
5047 decl_loc_hasher::equal (var_loc_list
*x
, const_tree y
)
5049 return (x
->decl_id
== DECL_UID (y
));
5052 /* Return the var_loc list associated with a given declaration. */
5054 static inline var_loc_list
*
5055 lookup_decl_loc (const_tree decl
)
5057 if (!decl_loc_table
)
5059 return decl_loc_table
->find_with_hash (decl
, DECL_UID (decl
));
5062 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
5065 dw_loc_list_hasher::hash (cached_dw_loc_list
*x
)
5067 return (hashval_t
) x
->decl_id
;
5070 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
5074 dw_loc_list_hasher::equal (cached_dw_loc_list
*x
, const_tree y
)
5076 return (x
->decl_id
== DECL_UID (y
));
5079 /* Equate a DIE to a particular declaration. */
5082 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
5084 unsigned int decl_id
= DECL_UID (decl
);
5086 *decl_die_table
->find_slot_with_hash (decl
, decl_id
, INSERT
) = decl_die
;
5087 decl_die
->decl_id
= decl_id
;
5090 /* Return how many bits covers PIECE EXPR_LIST. */
5092 static HOST_WIDE_INT
5093 decl_piece_bitsize (rtx piece
)
5095 int ret
= (int) GET_MODE (piece
);
5098 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5099 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5100 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5103 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5106 decl_piece_varloc_ptr (rtx piece
)
5108 if ((int) GET_MODE (piece
))
5109 return &XEXP (piece
, 0);
5111 return &XEXP (XEXP (piece
, 0), 1);
5114 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5115 Next is the chain of following piece nodes. */
5117 static rtx_expr_list
*
5118 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5120 if (bitsize
> 0 && bitsize
<= (int) MAX_MACHINE_MODE
)
5121 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5123 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5128 /* Return rtx that should be stored into loc field for
5129 LOC_NOTE and BITPOS/BITSIZE. */
5132 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5133 HOST_WIDE_INT bitsize
)
5137 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5139 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5144 /* This function either modifies location piece list *DEST in
5145 place (if SRC and INNER is NULL), or copies location piece list
5146 *SRC to *DEST while modifying it. Location BITPOS is modified
5147 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5148 not copied and if needed some padding around it is added.
5149 When modifying in place, DEST should point to EXPR_LIST where
5150 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5151 to the start of the whole list and INNER points to the EXPR_LIST
5152 where earlier pieces cover PIECE_BITPOS bits. */
5155 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5156 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5157 HOST_WIDE_INT bitsize
, rtx loc_note
)
5160 bool copy
= inner
!= NULL
;
5164 /* First copy all nodes preceding the current bitpos. */
5165 while (src
!= inner
)
5167 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5168 decl_piece_bitsize (*src
), NULL_RTX
);
5169 dest
= &XEXP (*dest
, 1);
5170 src
= &XEXP (*src
, 1);
5173 /* Add padding if needed. */
5174 if (bitpos
!= piece_bitpos
)
5176 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5177 copy
? NULL_RTX
: *dest
);
5178 dest
= &XEXP (*dest
, 1);
5180 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5183 /* A piece with correct bitpos and bitsize already exist,
5184 just update the location for it and return. */
5185 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5188 /* Add the piece that changed. */
5189 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5190 dest
= &XEXP (*dest
, 1);
5191 /* Skip over pieces that overlap it. */
5192 diff
= bitpos
- piece_bitpos
+ bitsize
;
5195 while (diff
> 0 && *src
)
5198 diff
-= decl_piece_bitsize (piece
);
5200 src
= &XEXP (piece
, 1);
5203 *src
= XEXP (piece
, 1);
5204 free_EXPR_LIST_node (piece
);
5207 /* Add padding if needed. */
5208 if (diff
< 0 && *src
)
5212 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5213 dest
= &XEXP (*dest
, 1);
5217 /* Finally copy all nodes following it. */
5220 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5221 decl_piece_bitsize (*src
), NULL_RTX
);
5222 dest
= &XEXP (*dest
, 1);
5223 src
= &XEXP (*src
, 1);
5227 /* Add a variable location node to the linked list for DECL. */
5229 static struct var_loc_node
*
5230 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5232 unsigned int decl_id
;
5234 struct var_loc_node
*loc
= NULL
;
5235 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5237 if (TREE_CODE (decl
) == VAR_DECL
5238 && DECL_HAS_DEBUG_EXPR_P (decl
))
5240 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5241 if (handled_component_p (realdecl
)
5242 || (TREE_CODE (realdecl
) == MEM_REF
5243 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5245 HOST_WIDE_INT maxsize
;
5248 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5249 if (!DECL_P (innerdecl
)
5250 || DECL_IGNORED_P (innerdecl
)
5251 || TREE_STATIC (innerdecl
)
5253 || bitpos
+ bitsize
> 256
5254 || bitsize
!= maxsize
)
5260 decl_id
= DECL_UID (decl
);
5262 = decl_loc_table
->find_slot_with_hash (decl
, decl_id
, INSERT
);
5265 temp
= ggc_cleared_alloc
<var_loc_list
> ();
5266 temp
->decl_id
= decl_id
;
5272 /* For PARM_DECLs try to keep around the original incoming value,
5273 even if that means we'll emit a zero-range .debug_loc entry. */
5275 && temp
->first
== temp
->last
5276 && TREE_CODE (decl
) == PARM_DECL
5277 && NOTE_P (temp
->first
->loc
)
5278 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5279 && DECL_INCOMING_RTL (decl
)
5280 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5281 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5282 == GET_CODE (DECL_INCOMING_RTL (decl
))
5283 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5285 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5286 NOTE_VAR_LOCATION_LOC (loc_note
))
5287 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5288 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5290 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5291 temp
->first
->next
= loc
;
5293 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5295 else if (temp
->last
)
5297 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5298 rtx
*piece_loc
= NULL
, last_loc_note
;
5299 HOST_WIDE_INT piece_bitpos
= 0;
5303 gcc_assert (last
->next
== NULL
);
5305 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5307 piece_loc
= &last
->loc
;
5310 HOST_WIDE_INT cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5311 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5313 piece_bitpos
+= cur_bitsize
;
5314 piece_loc
= &XEXP (*piece_loc
, 1);
5318 /* TEMP->LAST here is either pointer to the last but one or
5319 last element in the chained list, LAST is pointer to the
5321 if (label
&& strcmp (last
->label
, label
) == 0)
5323 /* For SRA optimized variables if there weren't any real
5324 insns since last note, just modify the last node. */
5325 if (piece_loc
!= NULL
)
5327 adjust_piece_list (piece_loc
, NULL
, NULL
,
5328 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5331 /* If the last note doesn't cover any instructions, remove it. */
5332 if (temp
->last
!= last
)
5334 temp
->last
->next
= NULL
;
5337 gcc_assert (strcmp (last
->label
, label
) != 0);
5341 gcc_assert (temp
->first
== temp
->last
5342 || (temp
->first
->next
== temp
->last
5343 && TREE_CODE (decl
) == PARM_DECL
));
5344 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5345 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5349 if (bitsize
== -1 && NOTE_P (last
->loc
))
5350 last_loc_note
= last
->loc
;
5351 else if (piece_loc
!= NULL
5352 && *piece_loc
!= NULL_RTX
5353 && piece_bitpos
== bitpos
5354 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5355 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5357 last_loc_note
= NULL_RTX
;
5358 /* If the current location is the same as the end of the list,
5359 and either both or neither of the locations is uninitialized,
5360 we have nothing to do. */
5361 if (last_loc_note
== NULL_RTX
5362 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5363 NOTE_VAR_LOCATION_LOC (loc_note
)))
5364 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5365 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5366 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5367 == VAR_INIT_STATUS_UNINITIALIZED
)
5368 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5369 == VAR_INIT_STATUS_UNINITIALIZED
))))
5371 /* Add LOC to the end of list and update LAST. If the last
5372 element of the list has been removed above, reuse its
5373 memory for the new node, otherwise allocate a new one. */
5377 memset (loc
, '\0', sizeof (*loc
));
5380 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5381 if (bitsize
== -1 || piece_loc
== NULL
)
5382 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5384 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5385 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5387 /* Ensure TEMP->LAST will point either to the new last but one
5388 element of the chain, or to the last element in it. */
5389 if (last
!= temp
->last
)
5397 loc
= ggc_cleared_alloc
<var_loc_node
> ();
5400 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5405 /* Keep track of the number of spaces used to indent the
5406 output of the debugging routines that print the structure of
5407 the DIE internal representation. */
5408 static int print_indent
;
5410 /* Indent the line the number of spaces given by print_indent. */
5413 print_spaces (FILE *outfile
)
5415 fprintf (outfile
, "%*s", print_indent
, "");
5418 /* Print a type signature in hex. */
5421 print_signature (FILE *outfile
, char *sig
)
5425 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5426 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5429 static void print_loc_descr (dw_loc_descr_ref
, FILE *);
5431 /* Print the value associated to the VAL DWARF value node to OUTFILE. If
5432 RECURSE, output location descriptor operations. */
5435 print_dw_val (dw_val_node
*val
, bool recurse
, FILE *outfile
)
5437 switch (val
->val_class
)
5439 case dw_val_class_addr
:
5440 fprintf (outfile
, "address");
5442 case dw_val_class_offset
:
5443 fprintf (outfile
, "offset");
5445 case dw_val_class_loc
:
5446 fprintf (outfile
, "location descriptor");
5447 if (val
->v
.val_loc
== NULL
)
5448 fprintf (outfile
, " -> <null>\n");
5451 fprintf (outfile
, ":\n");
5453 print_loc_descr (val
->v
.val_loc
, outfile
);
5457 fprintf (outfile
, " (%p)\n", (void *) val
->v
.val_loc
);
5459 case dw_val_class_loc_list
:
5460 fprintf (outfile
, "location list -> label:%s",
5461 val
->v
.val_loc_list
->ll_symbol
);
5463 case dw_val_class_range_list
:
5464 fprintf (outfile
, "range list");
5466 case dw_val_class_const
:
5467 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, val
->v
.val_int
);
5469 case dw_val_class_unsigned_const
:
5470 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, val
->v
.val_unsigned
);
5472 case dw_val_class_const_double
:
5473 fprintf (outfile
, "constant (" HOST_WIDE_INT_PRINT_DEC
","\
5474 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5475 val
->v
.val_double
.high
,
5476 val
->v
.val_double
.low
);
5478 case dw_val_class_wide_int
:
5480 int i
= val
->v
.val_wide
->get_len ();
5481 fprintf (outfile
, "constant (");
5483 if (val
->v
.val_wide
->elt (i
- 1) == 0)
5484 fprintf (outfile
, "0x");
5485 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5486 val
->v
.val_wide
->elt (--i
));
5488 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5489 val
->v
.val_wide
->elt (i
));
5490 fprintf (outfile
, ")");
5493 case dw_val_class_vec
:
5494 fprintf (outfile
, "floating-point or vector constant");
5496 case dw_val_class_flag
:
5497 fprintf (outfile
, "%u", val
->v
.val_flag
);
5499 case dw_val_class_die_ref
:
5500 if (val
->v
.val_die_ref
.die
!= NULL
)
5502 dw_die_ref die
= val
->v
.val_die_ref
.die
;
5504 if (die
->comdat_type_p
)
5506 fprintf (outfile
, "die -> signature: ");
5507 print_signature (outfile
,
5508 die
->die_id
.die_type_node
->signature
);
5510 else if (die
->die_id
.die_symbol
)
5511 fprintf (outfile
, "die -> label: %s", die
->die_id
.die_symbol
);
5513 fprintf (outfile
, "die -> %ld", die
->die_offset
);
5514 fprintf (outfile
, " (%p)", (void *) die
);
5517 fprintf (outfile
, "die -> <null>");
5519 case dw_val_class_vms_delta
:
5520 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5521 val
->v
.val_vms_delta
.lbl2
, val
->v
.val_vms_delta
.lbl1
);
5523 case dw_val_class_lbl_id
:
5524 case dw_val_class_lineptr
:
5525 case dw_val_class_macptr
:
5526 case dw_val_class_high_pc
:
5527 fprintf (outfile
, "label: %s", val
->v
.val_lbl_id
);
5529 case dw_val_class_str
:
5530 if (val
->v
.val_str
->str
!= NULL
)
5531 fprintf (outfile
, "\"%s\"", val
->v
.val_str
->str
);
5533 fprintf (outfile
, "<null>");
5535 case dw_val_class_file
:
5536 fprintf (outfile
, "\"%s\" (%d)", val
->v
.val_file
->filename
,
5537 val
->v
.val_file
->emitted_number
);
5539 case dw_val_class_data8
:
5543 for (i
= 0; i
< 8; i
++)
5544 fprintf (outfile
, "%02x", val
->v
.val_data8
[i
]);
5552 /* Likewise, for a DIE attribute. */
5555 print_attribute (dw_attr_ref a
, bool recurse
, FILE *outfile
)
5557 print_dw_val (&a
->dw_attr_val
, recurse
, outfile
);
5561 /* Print the list of operands in the LOC location description to OUTFILE. This
5562 routine is a debugging aid only. */
5565 print_loc_descr (dw_loc_descr_ref loc
, FILE *outfile
)
5567 dw_loc_descr_ref l
= loc
;
5571 print_spaces (outfile
);
5572 fprintf (outfile
, "<null>\n");
5576 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
5578 print_spaces (outfile
);
5579 fprintf (outfile
, "(%p) %s",
5581 dwarf_stack_op_name (l
->dw_loc_opc
));
5582 if (l
->dw_loc_oprnd1
.val_class
!= dw_val_class_none
)
5584 fprintf (outfile
, " ");
5585 print_dw_val (&l
->dw_loc_oprnd1
, false, outfile
);
5587 if (l
->dw_loc_oprnd2
.val_class
!= dw_val_class_none
)
5589 fprintf (outfile
, ", ");
5590 print_dw_val (&l
->dw_loc_oprnd2
, false, outfile
);
5592 fprintf (outfile
, "\n");
5596 /* Print the information associated with a given DIE, and its children.
5597 This routine is a debugging aid only. */
5600 print_die (dw_die_ref die
, FILE *outfile
)
5606 print_spaces (outfile
);
5607 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5608 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5610 print_spaces (outfile
);
5611 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5612 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5613 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5615 if (die
->comdat_type_p
)
5617 print_spaces (outfile
);
5618 fprintf (outfile
, " signature: ");
5619 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5620 fprintf (outfile
, "\n");
5623 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5625 print_spaces (outfile
);
5626 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5628 print_attribute (a
, true, outfile
);
5629 fprintf (outfile
, "\n");
5632 if (die
->die_child
!= NULL
)
5635 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5638 if (print_indent
== 0)
5639 fprintf (outfile
, "\n");
5642 /* Print the list of operations in the LOC location description. */
5645 debug_dwarf_loc_descr (dw_loc_descr_ref loc
)
5647 print_loc_descr (loc
, stderr
);
5650 /* Print the information collected for a given DIE. */
5653 debug_dwarf_die (dw_die_ref die
)
5655 print_die (die
, stderr
);
5659 debug (die_struct
&ref
)
5661 print_die (&ref
, stderr
);
5665 debug (die_struct
*ptr
)
5670 fprintf (stderr
, "<nil>\n");
5674 /* Print all DWARF information collected for the compilation unit.
5675 This routine is a debugging aid only. */
5681 print_die (comp_unit_die (), stderr
);
5684 #ifdef ENABLE_CHECKING
5685 /* Sanity checks on DIEs. */
5688 check_die (dw_die_ref die
)
5692 bool inline_found
= false;
5693 int n_location
= 0, n_low_pc
= 0, n_high_pc
= 0, n_artificial
= 0;
5694 int n_decl_line
= 0, n_decl_file
= 0;
5695 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5700 if (a
->dw_attr_val
.v
.val_unsigned
)
5701 inline_found
= true;
5703 case DW_AT_location
:
5712 case DW_AT_artificial
:
5715 case DW_AT_decl_line
:
5718 case DW_AT_decl_file
:
5725 if (n_location
> 1 || n_low_pc
> 1 || n_high_pc
> 1 || n_artificial
> 1
5726 || n_decl_line
> 1 || n_decl_file
> 1)
5728 fprintf (stderr
, "Duplicate attributes in DIE:\n");
5729 debug_dwarf_die (die
);
5734 /* A debugging information entry that is a member of an abstract
5735 instance tree [that has DW_AT_inline] should not contain any
5736 attributes which describe aspects of the subroutine which vary
5737 between distinct inlined expansions or distinct out-of-line
5739 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5740 gcc_assert (a
->dw_attr
!= DW_AT_low_pc
5741 && a
->dw_attr
!= DW_AT_high_pc
5742 && a
->dw_attr
!= DW_AT_location
5743 && a
->dw_attr
!= DW_AT_frame_base
5744 && a
->dw_attr
!= DW_AT_GNU_all_call_sites
);
5749 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5750 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5751 DIE that marks the start of the DIEs for this include file. */
5754 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5756 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5757 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5759 new_unit
->die_sib
= old_unit
;
5763 /* Close an include-file CU and reopen the enclosing one. */
5766 pop_compile_unit (dw_die_ref old_unit
)
5768 dw_die_ref new_unit
= old_unit
->die_sib
;
5770 old_unit
->die_sib
= NULL
;
5774 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5775 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5776 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5778 /* Calculate the checksum of a location expression. */
5781 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5784 inchash::hash hstate
;
5787 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5789 hash_loc_operands (loc
, hstate
);
5790 hash
= hstate
.end();
5794 /* Calculate the checksum of an attribute. */
5797 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5799 dw_loc_descr_ref loc
;
5802 CHECKSUM (at
->dw_attr
);
5804 /* We don't care that this was compiled with a different compiler
5805 snapshot; if the output is the same, that's what matters. */
5806 if (at
->dw_attr
== DW_AT_producer
)
5809 switch (AT_class (at
))
5811 case dw_val_class_const
:
5812 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5814 case dw_val_class_unsigned_const
:
5815 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5817 case dw_val_class_const_double
:
5818 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5820 case dw_val_class_wide_int
:
5821 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
5822 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
5823 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
5825 case dw_val_class_vec
:
5826 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5827 (at
->dw_attr_val
.v
.val_vec
.length
5828 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5830 case dw_val_class_flag
:
5831 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5833 case dw_val_class_str
:
5834 CHECKSUM_STRING (AT_string (at
));
5837 case dw_val_class_addr
:
5839 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5840 CHECKSUM_STRING (XSTR (r
, 0));
5843 case dw_val_class_offset
:
5844 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5847 case dw_val_class_loc
:
5848 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5849 loc_checksum (loc
, ctx
);
5852 case dw_val_class_die_ref
:
5853 die_checksum (AT_ref (at
), ctx
, mark
);
5856 case dw_val_class_fde_ref
:
5857 case dw_val_class_vms_delta
:
5858 case dw_val_class_lbl_id
:
5859 case dw_val_class_lineptr
:
5860 case dw_val_class_macptr
:
5861 case dw_val_class_high_pc
:
5864 case dw_val_class_file
:
5865 CHECKSUM_STRING (AT_file (at
)->filename
);
5868 case dw_val_class_data8
:
5869 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5877 /* Calculate the checksum of a DIE. */
5880 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5886 /* To avoid infinite recursion. */
5889 CHECKSUM (die
->die_mark
);
5892 die
->die_mark
= ++(*mark
);
5894 CHECKSUM (die
->die_tag
);
5896 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5897 attr_checksum (a
, ctx
, mark
);
5899 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5903 #undef CHECKSUM_BLOCK
5904 #undef CHECKSUM_STRING
5906 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5907 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5908 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5909 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5910 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5911 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5912 #define CHECKSUM_ATTR(FOO) \
5913 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5915 /* Calculate the checksum of a number in signed LEB128 format. */
5918 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5925 byte
= (value
& 0x7f);
5927 more
= !((value
== 0 && (byte
& 0x40) == 0)
5928 || (value
== -1 && (byte
& 0x40) != 0));
5937 /* Calculate the checksum of a number in unsigned LEB128 format. */
5940 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5944 unsigned char byte
= (value
& 0x7f);
5947 /* More bytes to follow. */
5955 /* Checksum the context of the DIE. This adds the names of any
5956 surrounding namespaces or structures to the checksum. */
5959 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5963 int tag
= die
->die_tag
;
5965 if (tag
!= DW_TAG_namespace
5966 && tag
!= DW_TAG_structure_type
5967 && tag
!= DW_TAG_class_type
)
5970 name
= get_AT_string (die
, DW_AT_name
);
5972 spec
= get_AT_ref (die
, DW_AT_specification
);
5976 if (die
->die_parent
!= NULL
)
5977 checksum_die_context (die
->die_parent
, ctx
);
5979 CHECKSUM_ULEB128 ('C');
5980 CHECKSUM_ULEB128 (tag
);
5982 CHECKSUM_STRING (name
);
5985 /* Calculate the checksum of a location expression. */
5988 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5990 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5991 were emitted as a DW_FORM_sdata instead of a location expression. */
5992 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5994 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5995 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5999 /* Otherwise, just checksum the raw location expression. */
6002 inchash::hash hstate
;
6005 CHECKSUM_ULEB128 (loc
->dtprel
);
6006 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
6007 hash_loc_operands (loc
, hstate
);
6008 hash
= hstate
.end ();
6010 loc
= loc
->dw_loc_next
;
6014 /* Calculate the checksum of an attribute. */
6017 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
6018 struct md5_ctx
*ctx
, int *mark
)
6020 dw_loc_descr_ref loc
;
6023 if (AT_class (at
) == dw_val_class_die_ref
)
6025 dw_die_ref target_die
= AT_ref (at
);
6027 /* For pointer and reference types, we checksum only the (qualified)
6028 name of the target type (if there is a name). For friend entries,
6029 we checksum only the (qualified) name of the target type or function.
6030 This allows the checksum to remain the same whether the target type
6031 is complete or not. */
6032 if ((at
->dw_attr
== DW_AT_type
6033 && (tag
== DW_TAG_pointer_type
6034 || tag
== DW_TAG_reference_type
6035 || tag
== DW_TAG_rvalue_reference_type
6036 || tag
== DW_TAG_ptr_to_member_type
))
6037 || (at
->dw_attr
== DW_AT_friend
6038 && tag
== DW_TAG_friend
))
6040 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
6042 if (name_attr
!= NULL
)
6044 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6048 CHECKSUM_ULEB128 ('N');
6049 CHECKSUM_ULEB128 (at
->dw_attr
);
6050 if (decl
->die_parent
!= NULL
)
6051 checksum_die_context (decl
->die_parent
, ctx
);
6052 CHECKSUM_ULEB128 ('E');
6053 CHECKSUM_STRING (AT_string (name_attr
));
6058 /* For all other references to another DIE, we check to see if the
6059 target DIE has already been visited. If it has, we emit a
6060 backward reference; if not, we descend recursively. */
6061 if (target_die
->die_mark
> 0)
6063 CHECKSUM_ULEB128 ('R');
6064 CHECKSUM_ULEB128 (at
->dw_attr
);
6065 CHECKSUM_ULEB128 (target_die
->die_mark
);
6069 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
6073 target_die
->die_mark
= ++(*mark
);
6074 CHECKSUM_ULEB128 ('T');
6075 CHECKSUM_ULEB128 (at
->dw_attr
);
6076 if (decl
->die_parent
!= NULL
)
6077 checksum_die_context (decl
->die_parent
, ctx
);
6078 die_checksum_ordered (target_die
, ctx
, mark
);
6083 CHECKSUM_ULEB128 ('A');
6084 CHECKSUM_ULEB128 (at
->dw_attr
);
6086 switch (AT_class (at
))
6088 case dw_val_class_const
:
6089 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6090 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
6093 case dw_val_class_unsigned_const
:
6094 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6095 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
6098 case dw_val_class_const_double
:
6099 CHECKSUM_ULEB128 (DW_FORM_block
);
6100 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
6101 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
6104 case dw_val_class_wide_int
:
6105 CHECKSUM_ULEB128 (DW_FORM_block
);
6106 CHECKSUM_ULEB128 (get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6107 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
6108 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_wide
->get_val (),
6109 get_full_len (*at
->dw_attr_val
.v
.val_wide
)
6110 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
6113 case dw_val_class_vec
:
6114 CHECKSUM_ULEB128 (DW_FORM_block
);
6115 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
6116 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
6117 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
6118 (at
->dw_attr_val
.v
.val_vec
.length
6119 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
6122 case dw_val_class_flag
:
6123 CHECKSUM_ULEB128 (DW_FORM_flag
);
6124 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
6127 case dw_val_class_str
:
6128 CHECKSUM_ULEB128 (DW_FORM_string
);
6129 CHECKSUM_STRING (AT_string (at
));
6132 case dw_val_class_addr
:
6134 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
6135 CHECKSUM_ULEB128 (DW_FORM_string
);
6136 CHECKSUM_STRING (XSTR (r
, 0));
6139 case dw_val_class_offset
:
6140 CHECKSUM_ULEB128 (DW_FORM_sdata
);
6141 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
6144 case dw_val_class_loc
:
6145 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
6146 loc_checksum_ordered (loc
, ctx
);
6149 case dw_val_class_fde_ref
:
6150 case dw_val_class_lbl_id
:
6151 case dw_val_class_lineptr
:
6152 case dw_val_class_macptr
:
6153 case dw_val_class_high_pc
:
6156 case dw_val_class_file
:
6157 CHECKSUM_ULEB128 (DW_FORM_string
);
6158 CHECKSUM_STRING (AT_file (at
)->filename
);
6161 case dw_val_class_data8
:
6162 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
6170 struct checksum_attributes
6172 dw_attr_ref at_name
;
6173 dw_attr_ref at_type
;
6174 dw_attr_ref at_friend
;
6175 dw_attr_ref at_accessibility
;
6176 dw_attr_ref at_address_class
;
6177 dw_attr_ref at_allocated
;
6178 dw_attr_ref at_artificial
;
6179 dw_attr_ref at_associated
;
6180 dw_attr_ref at_binary_scale
;
6181 dw_attr_ref at_bit_offset
;
6182 dw_attr_ref at_bit_size
;
6183 dw_attr_ref at_bit_stride
;
6184 dw_attr_ref at_byte_size
;
6185 dw_attr_ref at_byte_stride
;
6186 dw_attr_ref at_const_value
;
6187 dw_attr_ref at_containing_type
;
6188 dw_attr_ref at_count
;
6189 dw_attr_ref at_data_location
;
6190 dw_attr_ref at_data_member_location
;
6191 dw_attr_ref at_decimal_scale
;
6192 dw_attr_ref at_decimal_sign
;
6193 dw_attr_ref at_default_value
;
6194 dw_attr_ref at_digit_count
;
6195 dw_attr_ref at_discr
;
6196 dw_attr_ref at_discr_list
;
6197 dw_attr_ref at_discr_value
;
6198 dw_attr_ref at_encoding
;
6199 dw_attr_ref at_endianity
;
6200 dw_attr_ref at_explicit
;
6201 dw_attr_ref at_is_optional
;
6202 dw_attr_ref at_location
;
6203 dw_attr_ref at_lower_bound
;
6204 dw_attr_ref at_mutable
;
6205 dw_attr_ref at_ordering
;
6206 dw_attr_ref at_picture_string
;
6207 dw_attr_ref at_prototyped
;
6208 dw_attr_ref at_small
;
6209 dw_attr_ref at_segment
;
6210 dw_attr_ref at_string_length
;
6211 dw_attr_ref at_threads_scaled
;
6212 dw_attr_ref at_upper_bound
;
6213 dw_attr_ref at_use_location
;
6214 dw_attr_ref at_use_UTF8
;
6215 dw_attr_ref at_variable_parameter
;
6216 dw_attr_ref at_virtuality
;
6217 dw_attr_ref at_visibility
;
6218 dw_attr_ref at_vtable_elem_location
;
6221 /* Collect the attributes that we will want to use for the checksum. */
6224 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
6229 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6240 attrs
->at_friend
= a
;
6242 case DW_AT_accessibility
:
6243 attrs
->at_accessibility
= a
;
6245 case DW_AT_address_class
:
6246 attrs
->at_address_class
= a
;
6248 case DW_AT_allocated
:
6249 attrs
->at_allocated
= a
;
6251 case DW_AT_artificial
:
6252 attrs
->at_artificial
= a
;
6254 case DW_AT_associated
:
6255 attrs
->at_associated
= a
;
6257 case DW_AT_binary_scale
:
6258 attrs
->at_binary_scale
= a
;
6260 case DW_AT_bit_offset
:
6261 attrs
->at_bit_offset
= a
;
6263 case DW_AT_bit_size
:
6264 attrs
->at_bit_size
= a
;
6266 case DW_AT_bit_stride
:
6267 attrs
->at_bit_stride
= a
;
6269 case DW_AT_byte_size
:
6270 attrs
->at_byte_size
= a
;
6272 case DW_AT_byte_stride
:
6273 attrs
->at_byte_stride
= a
;
6275 case DW_AT_const_value
:
6276 attrs
->at_const_value
= a
;
6278 case DW_AT_containing_type
:
6279 attrs
->at_containing_type
= a
;
6282 attrs
->at_count
= a
;
6284 case DW_AT_data_location
:
6285 attrs
->at_data_location
= a
;
6287 case DW_AT_data_member_location
:
6288 attrs
->at_data_member_location
= a
;
6290 case DW_AT_decimal_scale
:
6291 attrs
->at_decimal_scale
= a
;
6293 case DW_AT_decimal_sign
:
6294 attrs
->at_decimal_sign
= a
;
6296 case DW_AT_default_value
:
6297 attrs
->at_default_value
= a
;
6299 case DW_AT_digit_count
:
6300 attrs
->at_digit_count
= a
;
6303 attrs
->at_discr
= a
;
6305 case DW_AT_discr_list
:
6306 attrs
->at_discr_list
= a
;
6308 case DW_AT_discr_value
:
6309 attrs
->at_discr_value
= a
;
6311 case DW_AT_encoding
:
6312 attrs
->at_encoding
= a
;
6314 case DW_AT_endianity
:
6315 attrs
->at_endianity
= a
;
6317 case DW_AT_explicit
:
6318 attrs
->at_explicit
= a
;
6320 case DW_AT_is_optional
:
6321 attrs
->at_is_optional
= a
;
6323 case DW_AT_location
:
6324 attrs
->at_location
= a
;
6326 case DW_AT_lower_bound
:
6327 attrs
->at_lower_bound
= a
;
6330 attrs
->at_mutable
= a
;
6332 case DW_AT_ordering
:
6333 attrs
->at_ordering
= a
;
6335 case DW_AT_picture_string
:
6336 attrs
->at_picture_string
= a
;
6338 case DW_AT_prototyped
:
6339 attrs
->at_prototyped
= a
;
6342 attrs
->at_small
= a
;
6345 attrs
->at_segment
= a
;
6347 case DW_AT_string_length
:
6348 attrs
->at_string_length
= a
;
6350 case DW_AT_threads_scaled
:
6351 attrs
->at_threads_scaled
= a
;
6353 case DW_AT_upper_bound
:
6354 attrs
->at_upper_bound
= a
;
6356 case DW_AT_use_location
:
6357 attrs
->at_use_location
= a
;
6359 case DW_AT_use_UTF8
:
6360 attrs
->at_use_UTF8
= a
;
6362 case DW_AT_variable_parameter
:
6363 attrs
->at_variable_parameter
= a
;
6365 case DW_AT_virtuality
:
6366 attrs
->at_virtuality
= a
;
6368 case DW_AT_visibility
:
6369 attrs
->at_visibility
= a
;
6371 case DW_AT_vtable_elem_location
:
6372 attrs
->at_vtable_elem_location
= a
;
6380 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6383 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6387 struct checksum_attributes attrs
;
6389 CHECKSUM_ULEB128 ('D');
6390 CHECKSUM_ULEB128 (die
->die_tag
);
6392 memset (&attrs
, 0, sizeof (attrs
));
6394 decl
= get_AT_ref (die
, DW_AT_specification
);
6396 collect_checksum_attributes (&attrs
, decl
);
6397 collect_checksum_attributes (&attrs
, die
);
6399 CHECKSUM_ATTR (attrs
.at_name
);
6400 CHECKSUM_ATTR (attrs
.at_accessibility
);
6401 CHECKSUM_ATTR (attrs
.at_address_class
);
6402 CHECKSUM_ATTR (attrs
.at_allocated
);
6403 CHECKSUM_ATTR (attrs
.at_artificial
);
6404 CHECKSUM_ATTR (attrs
.at_associated
);
6405 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6406 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6407 CHECKSUM_ATTR (attrs
.at_bit_size
);
6408 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6409 CHECKSUM_ATTR (attrs
.at_byte_size
);
6410 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6411 CHECKSUM_ATTR (attrs
.at_const_value
);
6412 CHECKSUM_ATTR (attrs
.at_containing_type
);
6413 CHECKSUM_ATTR (attrs
.at_count
);
6414 CHECKSUM_ATTR (attrs
.at_data_location
);
6415 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6416 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6417 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6418 CHECKSUM_ATTR (attrs
.at_default_value
);
6419 CHECKSUM_ATTR (attrs
.at_digit_count
);
6420 CHECKSUM_ATTR (attrs
.at_discr
);
6421 CHECKSUM_ATTR (attrs
.at_discr_list
);
6422 CHECKSUM_ATTR (attrs
.at_discr_value
);
6423 CHECKSUM_ATTR (attrs
.at_encoding
);
6424 CHECKSUM_ATTR (attrs
.at_endianity
);
6425 CHECKSUM_ATTR (attrs
.at_explicit
);
6426 CHECKSUM_ATTR (attrs
.at_is_optional
);
6427 CHECKSUM_ATTR (attrs
.at_location
);
6428 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6429 CHECKSUM_ATTR (attrs
.at_mutable
);
6430 CHECKSUM_ATTR (attrs
.at_ordering
);
6431 CHECKSUM_ATTR (attrs
.at_picture_string
);
6432 CHECKSUM_ATTR (attrs
.at_prototyped
);
6433 CHECKSUM_ATTR (attrs
.at_small
);
6434 CHECKSUM_ATTR (attrs
.at_segment
);
6435 CHECKSUM_ATTR (attrs
.at_string_length
);
6436 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6437 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6438 CHECKSUM_ATTR (attrs
.at_use_location
);
6439 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6440 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6441 CHECKSUM_ATTR (attrs
.at_virtuality
);
6442 CHECKSUM_ATTR (attrs
.at_visibility
);
6443 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6444 CHECKSUM_ATTR (attrs
.at_type
);
6445 CHECKSUM_ATTR (attrs
.at_friend
);
6447 /* Checksum the child DIEs. */
6450 dw_attr_ref name_attr
;
6453 name_attr
= get_AT (c
, DW_AT_name
);
6454 if (is_template_instantiation (c
))
6456 /* Ignore instantiations of member type and function templates. */
6458 else if (name_attr
!= NULL
6459 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6461 /* Use a shallow checksum for named nested types and member
6463 CHECKSUM_ULEB128 ('S');
6464 CHECKSUM_ULEB128 (c
->die_tag
);
6465 CHECKSUM_STRING (AT_string (name_attr
));
6469 /* Use a deep checksum for other children. */
6470 /* Mark this DIE so it gets processed when unmarking. */
6471 if (c
->die_mark
== 0)
6473 die_checksum_ordered (c
, ctx
, mark
);
6475 } while (c
!= die
->die_child
);
6477 CHECKSUM_ULEB128 (0);
6480 /* Add a type name and tag to a hash. */
6482 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6484 CHECKSUM_ULEB128 (tag
);
6485 CHECKSUM_STRING (name
);
6489 #undef CHECKSUM_STRING
6490 #undef CHECKSUM_ATTR
6491 #undef CHECKSUM_LEB128
6492 #undef CHECKSUM_ULEB128
6494 /* Generate the type signature for DIE. This is computed by generating an
6495 MD5 checksum over the DIE's tag, its relevant attributes, and its
6496 children. Attributes that are references to other DIEs are processed
6497 by recursion, using the MARK field to prevent infinite recursion.
6498 If the DIE is nested inside a namespace or another type, we also
6499 need to include that context in the signature. The lower 64 bits
6500 of the resulting MD5 checksum comprise the signature. */
6503 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6507 unsigned char checksum
[16];
6512 name
= get_AT_string (die
, DW_AT_name
);
6513 decl
= get_AT_ref (die
, DW_AT_specification
);
6514 parent
= get_die_parent (die
);
6516 /* First, compute a signature for just the type name (and its surrounding
6517 context, if any. This is stored in the type unit DIE for link-time
6518 ODR (one-definition rule) checking. */
6520 if (is_cxx () && name
!= NULL
)
6522 md5_init_ctx (&ctx
);
6524 /* Checksum the names of surrounding namespaces and structures. */
6526 checksum_die_context (parent
, &ctx
);
6528 /* Checksum the current DIE. */
6529 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6530 md5_finish_ctx (&ctx
, checksum
);
6532 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6535 /* Next, compute the complete type signature. */
6537 md5_init_ctx (&ctx
);
6539 die
->die_mark
= mark
;
6541 /* Checksum the names of surrounding namespaces and structures. */
6543 checksum_die_context (parent
, &ctx
);
6545 /* Checksum the DIE and its children. */
6546 die_checksum_ordered (die
, &ctx
, &mark
);
6547 unmark_all_dies (die
);
6548 md5_finish_ctx (&ctx
, checksum
);
6550 /* Store the signature in the type node and link the type DIE and the
6551 type node together. */
6552 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6553 DWARF_TYPE_SIGNATURE_SIZE
);
6554 die
->comdat_type_p
= true;
6555 die
->die_id
.die_type_node
= type_node
;
6556 type_node
->type_die
= die
;
6558 /* If the DIE is a specification, link its declaration to the type node
6562 decl
->comdat_type_p
= true;
6563 decl
->die_id
.die_type_node
= type_node
;
6567 /* Do the location expressions look same? */
6569 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6571 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6572 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6573 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6576 /* Do the values look the same? */
6578 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6580 dw_loc_descr_ref loc1
, loc2
;
6583 if (v1
->val_class
!= v2
->val_class
)
6586 switch (v1
->val_class
)
6588 case dw_val_class_const
:
6589 return v1
->v
.val_int
== v2
->v
.val_int
;
6590 case dw_val_class_unsigned_const
:
6591 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6592 case dw_val_class_const_double
:
6593 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6594 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6595 case dw_val_class_wide_int
:
6596 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
6597 case dw_val_class_vec
:
6598 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6599 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6601 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6602 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6605 case dw_val_class_flag
:
6606 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6607 case dw_val_class_str
:
6608 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6610 case dw_val_class_addr
:
6611 r1
= v1
->v
.val_addr
;
6612 r2
= v2
->v
.val_addr
;
6613 if (GET_CODE (r1
) != GET_CODE (r2
))
6615 return !rtx_equal_p (r1
, r2
);
6617 case dw_val_class_offset
:
6618 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6620 case dw_val_class_loc
:
6621 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6623 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6624 if (!same_loc_p (loc1
, loc2
, mark
))
6626 return !loc1
&& !loc2
;
6628 case dw_val_class_die_ref
:
6629 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6631 case dw_val_class_fde_ref
:
6632 case dw_val_class_vms_delta
:
6633 case dw_val_class_lbl_id
:
6634 case dw_val_class_lineptr
:
6635 case dw_val_class_macptr
:
6636 case dw_val_class_high_pc
:
6639 case dw_val_class_file
:
6640 return v1
->v
.val_file
== v2
->v
.val_file
;
6642 case dw_val_class_data8
:
6643 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6650 /* Do the attributes look the same? */
6653 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6655 if (at1
->dw_attr
!= at2
->dw_attr
)
6658 /* We don't care that this was compiled with a different compiler
6659 snapshot; if the output is the same, that's what matters. */
6660 if (at1
->dw_attr
== DW_AT_producer
)
6663 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6666 /* Do the dies look the same? */
6669 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6675 /* To avoid infinite recursion. */
6677 return die1
->die_mark
== die2
->die_mark
;
6678 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6680 if (die1
->die_tag
!= die2
->die_tag
)
6683 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6686 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6687 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6690 c1
= die1
->die_child
;
6691 c2
= die2
->die_child
;
6700 if (!same_die_p (c1
, c2
, mark
))
6704 if (c1
== die1
->die_child
)
6706 if (c2
== die2
->die_child
)
6716 /* Do the dies look the same? Wrapper around same_die_p. */
6719 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6722 int ret
= same_die_p (die1
, die2
, &mark
);
6724 unmark_all_dies (die1
);
6725 unmark_all_dies (die2
);
6730 /* The prefix to attach to symbols on DIEs in the current comdat debug
6732 static const char *comdat_symbol_id
;
6734 /* The index of the current symbol within the current comdat CU. */
6735 static unsigned int comdat_symbol_number
;
6737 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6738 children, and set comdat_symbol_id accordingly. */
6741 compute_section_prefix (dw_die_ref unit_die
)
6743 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6744 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6745 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6748 unsigned char checksum
[16];
6751 /* Compute the checksum of the DIE, then append part of it as hex digits to
6752 the name filename of the unit. */
6754 md5_init_ctx (&ctx
);
6756 die_checksum (unit_die
, &ctx
, &mark
);
6757 unmark_all_dies (unit_die
);
6758 md5_finish_ctx (&ctx
, checksum
);
6760 sprintf (name
, "%s.", base
);
6761 clean_symbol_name (name
);
6763 p
= name
+ strlen (name
);
6764 for (i
= 0; i
< 4; i
++)
6766 sprintf (p
, "%.2x", checksum
[i
]);
6770 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6771 comdat_symbol_number
= 0;
6774 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6777 is_type_die (dw_die_ref die
)
6779 switch (die
->die_tag
)
6781 case DW_TAG_array_type
:
6782 case DW_TAG_class_type
:
6783 case DW_TAG_interface_type
:
6784 case DW_TAG_enumeration_type
:
6785 case DW_TAG_pointer_type
:
6786 case DW_TAG_reference_type
:
6787 case DW_TAG_rvalue_reference_type
:
6788 case DW_TAG_string_type
:
6789 case DW_TAG_structure_type
:
6790 case DW_TAG_subroutine_type
:
6791 case DW_TAG_union_type
:
6792 case DW_TAG_ptr_to_member_type
:
6793 case DW_TAG_set_type
:
6794 case DW_TAG_subrange_type
:
6795 case DW_TAG_base_type
:
6796 case DW_TAG_const_type
:
6797 case DW_TAG_file_type
:
6798 case DW_TAG_packed_type
:
6799 case DW_TAG_volatile_type
:
6800 case DW_TAG_typedef
:
6807 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6808 Basically, we want to choose the bits that are likely to be shared between
6809 compilations (types) and leave out the bits that are specific to individual
6810 compilations (functions). */
6813 is_comdat_die (dw_die_ref c
)
6815 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6816 we do for stabs. The advantage is a greater likelihood of sharing between
6817 objects that don't include headers in the same order (and therefore would
6818 put the base types in a different comdat). jason 8/28/00 */
6820 if (c
->die_tag
== DW_TAG_base_type
)
6823 if (c
->die_tag
== DW_TAG_pointer_type
6824 || c
->die_tag
== DW_TAG_reference_type
6825 || c
->die_tag
== DW_TAG_rvalue_reference_type
6826 || c
->die_tag
== DW_TAG_const_type
6827 || c
->die_tag
== DW_TAG_volatile_type
)
6829 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6831 return t
? is_comdat_die (t
) : 0;
6834 return is_type_die (c
);
6837 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6838 compilation unit. */
6841 is_symbol_die (dw_die_ref c
)
6843 return (is_type_die (c
)
6844 || is_declaration_die (c
)
6845 || c
->die_tag
== DW_TAG_namespace
6846 || c
->die_tag
== DW_TAG_module
);
6849 /* Returns true iff C is a compile-unit DIE. */
6852 is_cu_die (dw_die_ref c
)
6854 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6857 /* Returns true iff C is a unit DIE of some sort. */
6860 is_unit_die (dw_die_ref c
)
6862 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6863 || c
->die_tag
== DW_TAG_partial_unit
6864 || c
->die_tag
== DW_TAG_type_unit
);
6867 /* Returns true iff C is a namespace DIE. */
6870 is_namespace_die (dw_die_ref c
)
6872 return c
&& c
->die_tag
== DW_TAG_namespace
;
6875 /* Returns true iff C is a class or structure DIE. */
6878 is_class_die (dw_die_ref c
)
6880 return c
&& (c
->die_tag
== DW_TAG_class_type
6881 || c
->die_tag
== DW_TAG_structure_type
);
6884 /* Return non-zero if this DIE is a template parameter. */
6887 is_template_parameter (dw_die_ref die
)
6889 switch (die
->die_tag
)
6891 case DW_TAG_template_type_param
:
6892 case DW_TAG_template_value_param
:
6893 case DW_TAG_GNU_template_template_param
:
6894 case DW_TAG_GNU_template_parameter_pack
:
6901 /* Return non-zero if this DIE represents a template instantiation. */
6904 is_template_instantiation (dw_die_ref die
)
6908 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6910 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6915 gen_internal_sym (const char *prefix
)
6919 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6920 return xstrdup (buf
);
6923 /* Assign symbols to all worthy DIEs under DIE. */
6926 assign_symbol_names (dw_die_ref die
)
6930 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6932 if (comdat_symbol_id
)
6934 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6936 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6937 comdat_symbol_id
, comdat_symbol_number
++);
6938 die
->die_id
.die_symbol
= xstrdup (p
);
6941 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6944 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6947 struct cu_hash_table_entry
6950 unsigned min_comdat_num
, max_comdat_num
;
6951 struct cu_hash_table_entry
*next
;
6954 /* Helpers to manipulate hash table of CUs. */
6956 struct cu_hash_table_entry_hasher
: pointer_hash
<cu_hash_table_entry
>
6958 typedef die_struct
*compare_type
;
6959 static inline hashval_t
hash (const cu_hash_table_entry
*);
6960 static inline bool equal (const cu_hash_table_entry
*, const die_struct
*);
6961 static inline void remove (cu_hash_table_entry
*);
6965 cu_hash_table_entry_hasher::hash (const cu_hash_table_entry
*entry
)
6967 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6971 cu_hash_table_entry_hasher::equal (const cu_hash_table_entry
*entry1
,
6972 const die_struct
*entry2
)
6974 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6978 cu_hash_table_entry_hasher::remove (cu_hash_table_entry
*entry
)
6980 struct cu_hash_table_entry
*next
;
6990 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6992 /* Check whether we have already seen this CU and set up SYM_NUM
6995 check_duplicate_cu (dw_die_ref cu
, cu_hash_type
*htable
, unsigned int *sym_num
)
6997 struct cu_hash_table_entry dummy
;
6998 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
7000 dummy
.max_comdat_num
= 0;
7002 slot
= htable
->find_slot_with_hash (cu
,
7003 htab_hash_string (cu
->die_id
.die_symbol
),
7007 for (; entry
; last
= entry
, entry
= entry
->next
)
7009 if (same_die_p_wrap (cu
, entry
->cu
))
7015 *sym_num
= entry
->min_comdat_num
;
7019 entry
= XCNEW (struct cu_hash_table_entry
);
7021 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
7022 entry
->next
= *slot
;
7028 /* Record SYM_NUM to record of CU in HTABLE. */
7030 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type
*htable
,
7031 unsigned int sym_num
)
7033 struct cu_hash_table_entry
**slot
, *entry
;
7035 slot
= htable
->find_slot_with_hash (cu
,
7036 htab_hash_string (cu
->die_id
.die_symbol
),
7040 entry
->max_comdat_num
= sym_num
;
7043 /* Traverse the DIE (which is always comp_unit_die), and set up
7044 additional compilation units for each of the include files we see
7045 bracketed by BINCL/EINCL. */
7048 break_out_includes (dw_die_ref die
)
7051 dw_die_ref unit
= NULL
;
7052 limbo_die_node
*node
, **pnode
;
7056 dw_die_ref prev
= c
;
7058 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
7059 || (unit
&& is_comdat_die (c
)))
7061 dw_die_ref next
= c
->die_sib
;
7063 /* This DIE is for a secondary CU; remove it from the main one. */
7064 remove_child_with_prev (c
, prev
);
7066 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
7067 unit
= push_new_compile_unit (unit
, c
);
7068 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
7069 unit
= pop_compile_unit (unit
);
7071 add_child_die (unit
, c
);
7073 if (c
== die
->die_child
)
7076 } while (c
!= die
->die_child
);
7079 /* We can only use this in debugging, since the frontend doesn't check
7080 to make sure that we leave every include file we enter. */
7084 assign_symbol_names (die
);
7085 cu_hash_type
cu_hash_table (10);
7086 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
7092 compute_section_prefix (node
->die
);
7093 is_dupl
= check_duplicate_cu (node
->die
, &cu_hash_table
,
7094 &comdat_symbol_number
);
7095 assign_symbol_names (node
->die
);
7097 *pnode
= node
->next
;
7100 pnode
= &node
->next
;
7101 record_comdat_symbol_number (node
->die
, &cu_hash_table
,
7102 comdat_symbol_number
);
7107 /* Return non-zero if this DIE is a declaration. */
7110 is_declaration_die (dw_die_ref die
)
7115 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7116 if (a
->dw_attr
== DW_AT_declaration
)
7122 /* Return non-zero if this DIE is nested inside a subprogram. */
7125 is_nested_in_subprogram (dw_die_ref die
)
7127 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
7131 return local_scope_p (decl
);
7134 /* Return non-zero if this DIE contains a defining declaration of a
7138 contains_subprogram_definition (dw_die_ref die
)
7142 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
7144 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
7148 /* Return non-zero if this is a type DIE that should be moved to a
7149 COMDAT .debug_types section. */
7152 should_move_die_to_comdat (dw_die_ref die
)
7154 switch (die
->die_tag
)
7156 case DW_TAG_class_type
:
7157 case DW_TAG_structure_type
:
7158 case DW_TAG_enumeration_type
:
7159 case DW_TAG_union_type
:
7160 /* Don't move declarations, inlined instances, types nested in a
7161 subprogram, or types that contain subprogram definitions. */
7162 if (is_declaration_die (die
)
7163 || get_AT (die
, DW_AT_abstract_origin
)
7164 || is_nested_in_subprogram (die
)
7165 || contains_subprogram_definition (die
))
7168 case DW_TAG_array_type
:
7169 case DW_TAG_interface_type
:
7170 case DW_TAG_pointer_type
:
7171 case DW_TAG_reference_type
:
7172 case DW_TAG_rvalue_reference_type
:
7173 case DW_TAG_string_type
:
7174 case DW_TAG_subroutine_type
:
7175 case DW_TAG_ptr_to_member_type
:
7176 case DW_TAG_set_type
:
7177 case DW_TAG_subrange_type
:
7178 case DW_TAG_base_type
:
7179 case DW_TAG_const_type
:
7180 case DW_TAG_file_type
:
7181 case DW_TAG_packed_type
:
7182 case DW_TAG_volatile_type
:
7183 case DW_TAG_typedef
:
7189 /* Make a clone of DIE. */
7192 clone_die (dw_die_ref die
)
7198 clone
= ggc_cleared_alloc
<die_node
> ();
7199 clone
->die_tag
= die
->die_tag
;
7201 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7202 add_dwarf_attr (clone
, a
);
7207 /* Make a clone of the tree rooted at DIE. */
7210 clone_tree (dw_die_ref die
)
7213 dw_die_ref clone
= clone_die (die
);
7215 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
7220 /* Make a clone of DIE as a declaration. */
7223 clone_as_declaration (dw_die_ref die
)
7230 /* If the DIE is already a declaration, just clone it. */
7231 if (is_declaration_die (die
))
7232 return clone_die (die
);
7234 /* If the DIE is a specification, just clone its declaration DIE. */
7235 decl
= get_AT_ref (die
, DW_AT_specification
);
7238 clone
= clone_die (decl
);
7239 if (die
->comdat_type_p
)
7240 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7244 clone
= ggc_cleared_alloc
<die_node
> ();
7245 clone
->die_tag
= die
->die_tag
;
7247 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7249 /* We don't want to copy over all attributes.
7250 For example we don't want DW_AT_byte_size because otherwise we will no
7251 longer have a declaration and GDB will treat it as a definition. */
7255 case DW_AT_abstract_origin
:
7256 case DW_AT_artificial
:
7257 case DW_AT_containing_type
:
7258 case DW_AT_external
:
7261 case DW_AT_virtuality
:
7262 case DW_AT_linkage_name
:
7263 case DW_AT_MIPS_linkage_name
:
7264 add_dwarf_attr (clone
, a
);
7266 case DW_AT_byte_size
:
7272 if (die
->comdat_type_p
)
7273 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7275 add_AT_flag (clone
, DW_AT_declaration
, 1);
7280 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7282 struct decl_table_entry
7288 /* Helpers to manipulate hash table of copied declarations. */
7290 /* Hashtable helpers. */
7292 struct decl_table_entry_hasher
: free_ptr_hash
<decl_table_entry
>
7294 typedef die_struct
*compare_type
;
7295 static inline hashval_t
hash (const decl_table_entry
*);
7296 static inline bool equal (const decl_table_entry
*, const die_struct
*);
7300 decl_table_entry_hasher::hash (const decl_table_entry
*entry
)
7302 return htab_hash_pointer (entry
->orig
);
7306 decl_table_entry_hasher::equal (const decl_table_entry
*entry1
,
7307 const die_struct
*entry2
)
7309 return entry1
->orig
== entry2
;
7312 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7314 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7315 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7316 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7317 to check if the ancestor has already been copied into UNIT. */
7320 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
,
7321 decl_hash_type
*decl_table
)
7323 dw_die_ref parent
= die
->die_parent
;
7324 dw_die_ref new_parent
= unit
;
7326 decl_table_entry
**slot
= NULL
;
7327 struct decl_table_entry
*entry
= NULL
;
7331 /* Check if the entry has already been copied to UNIT. */
7332 slot
= decl_table
->find_slot_with_hash (die
, htab_hash_pointer (die
),
7334 if (*slot
!= HTAB_EMPTY_ENTRY
)
7340 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7341 entry
= XCNEW (struct decl_table_entry
);
7349 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7352 if (!is_unit_die (parent
))
7353 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7356 copy
= clone_as_declaration (die
);
7357 add_child_die (new_parent
, copy
);
7361 /* Record the pointer to the copy. */
7367 /* Copy the declaration context to the new type unit DIE. This includes
7368 any surrounding namespace or type declarations. If the DIE has an
7369 AT_specification attribute, it also includes attributes and children
7370 attached to the specification, and returns a pointer to the original
7371 parent of the declaration DIE. Returns NULL otherwise. */
7374 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7377 dw_die_ref new_decl
;
7378 dw_die_ref orig_parent
= NULL
;
7380 decl
= get_AT_ref (die
, DW_AT_specification
);
7389 /* The original DIE will be changed to a declaration, and must
7390 be moved to be a child of the original declaration DIE. */
7391 orig_parent
= decl
->die_parent
;
7393 /* Copy the type node pointer from the new DIE to the original
7394 declaration DIE so we can forward references later. */
7395 decl
->comdat_type_p
= true;
7396 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7398 remove_AT (die
, DW_AT_specification
);
7400 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7402 if (a
->dw_attr
!= DW_AT_name
7403 && a
->dw_attr
!= DW_AT_declaration
7404 && a
->dw_attr
!= DW_AT_external
)
7405 add_dwarf_attr (die
, a
);
7408 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7411 if (decl
->die_parent
!= NULL
7412 && !is_unit_die (decl
->die_parent
))
7414 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
7415 if (new_decl
!= NULL
)
7417 remove_AT (new_decl
, DW_AT_signature
);
7418 add_AT_specification (die
, new_decl
);
7425 /* Generate the skeleton ancestor tree for the given NODE, then clone
7426 the DIE and add the clone into the tree. */
7429 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7431 if (node
->new_die
!= NULL
)
7434 node
->new_die
= clone_as_declaration (node
->old_die
);
7436 if (node
->parent
!= NULL
)
7438 generate_skeleton_ancestor_tree (node
->parent
);
7439 add_child_die (node
->parent
->new_die
, node
->new_die
);
7443 /* Generate a skeleton tree of DIEs containing any declarations that are
7444 found in the original tree. We traverse the tree looking for declaration
7445 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7448 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7450 skeleton_chain_node node
;
7453 dw_die_ref prev
= NULL
;
7454 dw_die_ref next
= NULL
;
7456 node
.parent
= parent
;
7458 first
= c
= parent
->old_die
->die_child
;
7462 if (prev
== NULL
|| prev
->die_sib
== c
)
7465 next
= (c
== first
? NULL
: c
->die_sib
);
7467 node
.new_die
= NULL
;
7468 if (is_declaration_die (c
))
7470 if (is_template_instantiation (c
))
7472 /* Instantiated templates do not need to be cloned into the
7473 type unit. Just move the DIE and its children back to
7474 the skeleton tree (in the main CU). */
7475 remove_child_with_prev (c
, prev
);
7476 add_child_die (parent
->new_die
, c
);
7481 /* Clone the existing DIE, move the original to the skeleton
7482 tree (which is in the main CU), and put the clone, with
7483 all the original's children, where the original came from
7484 (which is about to be moved to the type unit). */
7485 dw_die_ref clone
= clone_die (c
);
7486 move_all_children (c
, clone
);
7488 /* If the original has a DW_AT_object_pointer attribute,
7489 it would now point to a child DIE just moved to the
7490 cloned tree, so we need to remove that attribute from
7492 remove_AT (c
, DW_AT_object_pointer
);
7494 replace_child (c
, clone
, prev
);
7495 generate_skeleton_ancestor_tree (parent
);
7496 add_child_die (parent
->new_die
, c
);
7501 generate_skeleton_bottom_up (&node
);
7502 } while (next
!= NULL
);
7505 /* Wrapper function for generate_skeleton_bottom_up. */
7508 generate_skeleton (dw_die_ref die
)
7510 skeleton_chain_node node
;
7513 node
.new_die
= NULL
;
7516 /* If this type definition is nested inside another type,
7517 and is not an instantiation of a template, always leave
7518 at least a declaration in its place. */
7519 if (die
->die_parent
!= NULL
7520 && is_type_die (die
->die_parent
)
7521 && !is_template_instantiation (die
))
7522 node
.new_die
= clone_as_declaration (die
);
7524 generate_skeleton_bottom_up (&node
);
7525 return node
.new_die
;
7528 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7529 declaration. The original DIE is moved to a new compile unit so that
7530 existing references to it follow it to the new location. If any of the
7531 original DIE's descendants is a declaration, we need to replace the
7532 original DIE with a skeleton tree and move the declarations back into the
7536 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7539 dw_die_ref skeleton
, orig_parent
;
7541 /* Copy the declaration context to the type unit DIE. If the returned
7542 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7544 orig_parent
= copy_declaration_context (unit
, child
);
7546 skeleton
= generate_skeleton (child
);
7547 if (skeleton
== NULL
)
7548 remove_child_with_prev (child
, prev
);
7551 skeleton
->comdat_type_p
= true;
7552 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7554 /* If the original DIE was a specification, we need to put
7555 the skeleton under the parent DIE of the declaration.
7556 This leaves the original declaration in the tree, but
7557 it will be pruned later since there are no longer any
7558 references to it. */
7559 if (orig_parent
!= NULL
)
7561 remove_child_with_prev (child
, prev
);
7562 add_child_die (orig_parent
, skeleton
);
7565 replace_child (child
, skeleton
, prev
);
7571 /* Traverse the DIE and set up additional .debug_types sections for each
7572 type worthy of being placed in a COMDAT section. */
7575 break_out_comdat_types (dw_die_ref die
)
7579 dw_die_ref prev
= NULL
;
7580 dw_die_ref next
= NULL
;
7581 dw_die_ref unit
= NULL
;
7583 first
= c
= die
->die_child
;
7587 if (prev
== NULL
|| prev
->die_sib
== c
)
7590 next
= (c
== first
? NULL
: c
->die_sib
);
7591 if (should_move_die_to_comdat (c
))
7593 dw_die_ref replacement
;
7594 comdat_type_node_ref type_node
;
7596 /* Break out nested types into their own type units. */
7597 break_out_comdat_types (c
);
7599 /* Create a new type unit DIE as the root for the new tree, and
7600 add it to the list of comdat types. */
7601 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7602 add_AT_unsigned (unit
, DW_AT_language
,
7603 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7604 type_node
= ggc_cleared_alloc
<comdat_type_node
> ();
7605 type_node
->root_die
= unit
;
7606 type_node
->next
= comdat_type_list
;
7607 comdat_type_list
= type_node
;
7609 /* Generate the type signature. */
7610 generate_type_signature (c
, type_node
);
7612 /* Copy the declaration context, attributes, and children of the
7613 declaration into the new type unit DIE, then remove this DIE
7614 from the main CU (or replace it with a skeleton if necessary). */
7615 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7616 type_node
->skeleton_die
= replacement
;
7618 /* Add the DIE to the new compunit. */
7619 add_child_die (unit
, c
);
7621 if (replacement
!= NULL
)
7624 else if (c
->die_tag
== DW_TAG_namespace
7625 || c
->die_tag
== DW_TAG_class_type
7626 || c
->die_tag
== DW_TAG_structure_type
7627 || c
->die_tag
== DW_TAG_union_type
)
7629 /* Look for nested types that can be broken out. */
7630 break_out_comdat_types (c
);
7632 } while (next
!= NULL
);
7635 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7636 Enter all the cloned children into the hash table decl_table. */
7639 clone_tree_partial (dw_die_ref die
, decl_hash_type
*decl_table
)
7643 struct decl_table_entry
*entry
;
7644 decl_table_entry
**slot
;
7646 if (die
->die_tag
== DW_TAG_subprogram
)
7647 clone
= clone_as_declaration (die
);
7649 clone
= clone_die (die
);
7651 slot
= decl_table
->find_slot_with_hash (die
,
7652 htab_hash_pointer (die
), INSERT
);
7654 /* Assert that DIE isn't in the hash table yet. If it would be there
7655 before, the ancestors would be necessarily there as well, therefore
7656 clone_tree_partial wouldn't be called. */
7657 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7659 entry
= XCNEW (struct decl_table_entry
);
7661 entry
->copy
= clone
;
7664 if (die
->die_tag
!= DW_TAG_subprogram
)
7665 FOR_EACH_CHILD (die
, c
,
7666 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7671 /* Walk the DIE and its children, looking for references to incomplete
7672 or trivial types that are unmarked (i.e., that are not in the current
7676 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type
*decl_table
)
7682 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7684 if (AT_class (a
) == dw_val_class_die_ref
)
7686 dw_die_ref targ
= AT_ref (a
);
7687 decl_table_entry
**slot
;
7688 struct decl_table_entry
*entry
;
7690 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7693 slot
= decl_table
->find_slot_with_hash (targ
,
7694 htab_hash_pointer (targ
),
7697 if (*slot
!= HTAB_EMPTY_ENTRY
)
7699 /* TARG has already been copied, so we just need to
7700 modify the reference to point to the copy. */
7702 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7706 dw_die_ref parent
= unit
;
7707 dw_die_ref copy
= clone_die (targ
);
7709 /* Record in DECL_TABLE that TARG has been copied.
7710 Need to do this now, before the recursive call,
7711 because DECL_TABLE may be expanded and SLOT
7712 would no longer be a valid pointer. */
7713 entry
= XCNEW (struct decl_table_entry
);
7718 /* If TARG is not a declaration DIE, we need to copy its
7720 if (!is_declaration_die (targ
))
7724 add_child_die (copy
,
7725 clone_tree_partial (c
, decl_table
)));
7728 /* Make sure the cloned tree is marked as part of the
7732 /* If TARG has surrounding context, copy its ancestor tree
7733 into the new type unit. */
7734 if (targ
->die_parent
!= NULL
7735 && !is_unit_die (targ
->die_parent
))
7736 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7739 add_child_die (parent
, copy
);
7740 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7742 /* Make sure the newly-copied DIE is walked. If it was
7743 installed in a previously-added context, it won't
7744 get visited otherwise. */
7747 /* Find the highest point of the newly-added tree,
7748 mark each node along the way, and walk from there. */
7749 parent
->die_mark
= 1;
7750 while (parent
->die_parent
7751 && parent
->die_parent
->die_mark
== 0)
7753 parent
= parent
->die_parent
;
7754 parent
->die_mark
= 1;
7756 copy_decls_walk (unit
, parent
, decl_table
);
7762 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7765 /* Copy declarations for "unworthy" types into the new comdat section.
7766 Incomplete types, modified types, and certain other types aren't broken
7767 out into comdat sections of their own, so they don't have a signature,
7768 and we need to copy the declaration into the same section so that we
7769 don't have an external reference. */
7772 copy_decls_for_unworthy_types (dw_die_ref unit
)
7775 decl_hash_type
decl_table (10);
7776 copy_decls_walk (unit
, unit
, &decl_table
);
7780 /* Traverse the DIE and add a sibling attribute if it may have the
7781 effect of speeding up access to siblings. To save some space,
7782 avoid generating sibling attributes for DIE's without children. */
7785 add_sibling_attributes (dw_die_ref die
)
7789 if (! die
->die_child
)
7792 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7793 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7795 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7798 /* Output all location lists for the DIE and its children. */
7801 output_location_lists (dw_die_ref die
)
7807 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7808 if (AT_class (a
) == dw_val_class_loc_list
)
7809 output_loc_list (AT_loc_list (a
));
7811 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7814 /* We want to limit the number of external references, because they are
7815 larger than local references: a relocation takes multiple words, and
7816 even a sig8 reference is always eight bytes, whereas a local reference
7817 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7818 So if we encounter multiple external references to the same type DIE, we
7819 make a local typedef stub for it and redirect all references there.
7821 This is the element of the hash table for keeping track of these
7831 /* Hashtable helpers. */
7833 struct external_ref_hasher
: free_ptr_hash
<external_ref
>
7835 static inline hashval_t
hash (const external_ref
*);
7836 static inline bool equal (const external_ref
*, const external_ref
*);
7840 external_ref_hasher::hash (const external_ref
*r
)
7842 dw_die_ref die
= r
->type
;
7845 /* We can't use the address of the DIE for hashing, because
7846 that will make the order of the stub DIEs non-deterministic. */
7847 if (! die
->comdat_type_p
)
7848 /* We have a symbol; use it to compute a hash. */
7849 h
= htab_hash_string (die
->die_id
.die_symbol
);
7852 /* We have a type signature; use a subset of the bits as the hash.
7853 The 8-byte signature is at least as large as hashval_t. */
7854 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7855 memcpy (&h
, type_node
->signature
, sizeof (h
));
7861 external_ref_hasher::equal (const external_ref
*r1
, const external_ref
*r2
)
7863 return r1
->type
== r2
->type
;
7866 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7868 /* Return a pointer to the external_ref for references to DIE. */
7870 static struct external_ref
*
7871 lookup_external_ref (external_ref_hash_type
*map
, dw_die_ref die
)
7873 struct external_ref ref
, *ref_p
;
7874 external_ref
**slot
;
7877 slot
= map
->find_slot (&ref
, INSERT
);
7878 if (*slot
!= HTAB_EMPTY_ENTRY
)
7881 ref_p
= XCNEW (struct external_ref
);
7887 /* Subroutine of optimize_external_refs, below.
7889 If we see a type skeleton, record it as our stub. If we see external
7890 references, remember how many we've seen. */
7893 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type
*map
)
7898 struct external_ref
*ref_p
;
7900 if (is_type_die (die
)
7901 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7903 /* This is a local skeleton; use it for local references. */
7904 ref_p
= lookup_external_ref (map
, c
);
7908 /* Scan the DIE references, and remember any that refer to DIEs from
7909 other CUs (i.e. those which are not marked). */
7910 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7911 if (AT_class (a
) == dw_val_class_die_ref
7912 && (c
= AT_ref (a
))->die_mark
== 0
7915 ref_p
= lookup_external_ref (map
, c
);
7919 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7922 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7923 points to an external_ref, DATA is the CU we're processing. If we don't
7924 already have a local stub, and we have multiple refs, build a stub. */
7927 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7929 struct external_ref
*ref_p
= *slot
;
7931 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7933 /* We have multiple references to this type, so build a small stub.
7934 Both of these forms are a bit dodgy from the perspective of the
7935 DWARF standard, since technically they should have names. */
7936 dw_die_ref cu
= data
;
7937 dw_die_ref type
= ref_p
->type
;
7938 dw_die_ref stub
= NULL
;
7940 if (type
->comdat_type_p
)
7942 /* If we refer to this type via sig8, use AT_signature. */
7943 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7944 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7948 /* Otherwise, use a typedef with no name. */
7949 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7950 add_AT_die_ref (stub
, DW_AT_type
, type
);
7959 /* DIE is a unit; look through all the DIE references to see if there are
7960 any external references to types, and if so, create local stubs for
7961 them which will be applied in build_abbrev_table. This is useful because
7962 references to local DIEs are smaller. */
7964 static external_ref_hash_type
*
7965 optimize_external_refs (dw_die_ref die
)
7967 external_ref_hash_type
*map
= new external_ref_hash_type (10);
7968 optimize_external_refs_1 (die
, map
);
7969 map
->traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7973 /* The format of each DIE (and its attribute value pairs) is encoded in an
7974 abbreviation table. This routine builds the abbreviation table and assigns
7975 a unique abbreviation id for each abbreviation entry. The children of each
7976 die are visited recursively. */
7979 build_abbrev_table (dw_die_ref die
, external_ref_hash_type
*extern_map
)
7981 unsigned long abbrev_id
;
7982 unsigned int n_alloc
;
7987 /* Scan the DIE references, and replace any that refer to
7988 DIEs from other CUs (i.e. those which are not marked) with
7989 the local stubs we built in optimize_external_refs. */
7990 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7991 if (AT_class (a
) == dw_val_class_die_ref
7992 && (c
= AT_ref (a
))->die_mark
== 0)
7994 struct external_ref
*ref_p
;
7995 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7997 ref_p
= lookup_external_ref (extern_map
, c
);
7998 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7999 change_AT_die_ref (a
, ref_p
->stub
);
8001 /* We aren't changing this reference, so mark it external. */
8002 set_AT_ref_external (a
, 1);
8005 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8007 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
8008 dw_attr_ref die_a
, abbrev_a
;
8012 if (abbrev
->die_tag
!= die
->die_tag
)
8014 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
8017 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
8020 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
8022 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
8023 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
8024 || (value_format (abbrev_a
) != value_format (die_a
)))
8034 if (abbrev_id
>= abbrev_die_table_in_use
)
8036 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
8038 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
8039 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
8042 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
8043 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
8044 abbrev_die_table_allocated
= n_alloc
;
8047 ++abbrev_die_table_in_use
;
8048 abbrev_die_table
[abbrev_id
] = die
;
8051 die
->die_abbrev
= abbrev_id
;
8052 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
8055 /* Return the power-of-two number of bytes necessary to represent VALUE. */
8058 constant_size (unsigned HOST_WIDE_INT value
)
8065 log
= floor_log2 (value
);
8068 log
= 1 << (floor_log2 (log
) + 1);
8073 /* Return the size of a DIE as it is represented in the
8074 .debug_info section. */
8076 static unsigned long
8077 size_of_die (dw_die_ref die
)
8079 unsigned long size
= 0;
8082 enum dwarf_form form
;
8084 size
+= size_of_uleb128 (die
->die_abbrev
);
8085 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8087 switch (AT_class (a
))
8089 case dw_val_class_addr
:
8090 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8092 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8093 size
+= size_of_uleb128 (AT_index (a
));
8096 size
+= DWARF2_ADDR_SIZE
;
8098 case dw_val_class_offset
:
8099 size
+= DWARF_OFFSET_SIZE
;
8101 case dw_val_class_loc
:
8103 unsigned long lsize
= size_of_locs (AT_loc (a
));
8106 if (dwarf_version
>= 4)
8107 size
+= size_of_uleb128 (lsize
);
8109 size
+= constant_size (lsize
);
8113 case dw_val_class_loc_list
:
8114 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8116 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8117 size
+= size_of_uleb128 (AT_index (a
));
8120 size
+= DWARF_OFFSET_SIZE
;
8122 case dw_val_class_range_list
:
8123 size
+= DWARF_OFFSET_SIZE
;
8125 case dw_val_class_const
:
8126 size
+= size_of_sleb128 (AT_int (a
));
8128 case dw_val_class_unsigned_const
:
8130 int csize
= constant_size (AT_unsigned (a
));
8131 if (dwarf_version
== 3
8132 && a
->dw_attr
== DW_AT_data_member_location
8134 size
+= size_of_uleb128 (AT_unsigned (a
));
8139 case dw_val_class_const_double
:
8140 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
8141 if (HOST_BITS_PER_WIDE_INT
>= 64)
8144 case dw_val_class_wide_int
:
8145 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
8146 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
8147 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
8151 case dw_val_class_vec
:
8152 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
8153 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
8154 + a
->dw_attr_val
.v
.val_vec
.length
8155 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
8157 case dw_val_class_flag
:
8158 if (dwarf_version
>= 4)
8159 /* Currently all add_AT_flag calls pass in 1 as last argument,
8160 so DW_FORM_flag_present can be used. If that ever changes,
8161 we'll need to use DW_FORM_flag and have some optimization
8162 in build_abbrev_table that will change those to
8163 DW_FORM_flag_present if it is set to 1 in all DIEs using
8164 the same abbrev entry. */
8165 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8169 case dw_val_class_die_ref
:
8170 if (AT_ref_external (a
))
8172 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
8173 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
8174 is sized by target address length, whereas in DWARF3
8175 it's always sized as an offset. */
8176 if (use_debug_types
)
8177 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
8178 else if (dwarf_version
== 2)
8179 size
+= DWARF2_ADDR_SIZE
;
8181 size
+= DWARF_OFFSET_SIZE
;
8184 size
+= DWARF_OFFSET_SIZE
;
8186 case dw_val_class_fde_ref
:
8187 size
+= DWARF_OFFSET_SIZE
;
8189 case dw_val_class_lbl_id
:
8190 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8192 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
8193 size
+= size_of_uleb128 (AT_index (a
));
8196 size
+= DWARF2_ADDR_SIZE
;
8198 case dw_val_class_lineptr
:
8199 case dw_val_class_macptr
:
8200 size
+= DWARF_OFFSET_SIZE
;
8202 case dw_val_class_str
:
8203 form
= AT_string_form (a
);
8204 if (form
== DW_FORM_strp
)
8205 size
+= DWARF_OFFSET_SIZE
;
8206 else if (form
== DW_FORM_GNU_str_index
)
8207 size
+= size_of_uleb128 (AT_index (a
));
8209 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
8211 case dw_val_class_file
:
8212 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
8214 case dw_val_class_data8
:
8217 case dw_val_class_vms_delta
:
8218 size
+= DWARF_OFFSET_SIZE
;
8220 case dw_val_class_high_pc
:
8221 size
+= DWARF2_ADDR_SIZE
;
8231 /* Size the debugging information associated with a given DIE. Visits the
8232 DIE's children recursively. Updates the global variable next_die_offset, on
8233 each time through. Uses the current value of next_die_offset to update the
8234 die_offset field in each DIE. */
8237 calc_die_sizes (dw_die_ref die
)
8241 gcc_assert (die
->die_offset
== 0
8242 || (unsigned long int) die
->die_offset
== next_die_offset
);
8243 die
->die_offset
= next_die_offset
;
8244 next_die_offset
+= size_of_die (die
);
8246 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
8248 if (die
->die_child
!= NULL
)
8249 /* Count the null byte used to terminate sibling lists. */
8250 next_die_offset
+= 1;
8253 /* Size just the base type children at the start of the CU.
8254 This is needed because build_abbrev needs to size locs
8255 and sizing of type based stack ops needs to know die_offset
8256 values for the base types. */
8259 calc_base_type_die_sizes (void)
8261 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8263 dw_die_ref base_type
;
8264 #if ENABLE_ASSERT_CHECKING
8265 dw_die_ref prev
= comp_unit_die ()->die_child
;
8268 die_offset
+= size_of_die (comp_unit_die ());
8269 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
8271 #if ENABLE_ASSERT_CHECKING
8272 gcc_assert (base_type
->die_offset
== 0
8273 && prev
->die_sib
== base_type
8274 && base_type
->die_child
== NULL
8275 && base_type
->die_abbrev
);
8278 base_type
->die_offset
= die_offset
;
8279 die_offset
+= size_of_die (base_type
);
8283 /* Set the marks for a die and its children. We do this so
8284 that we know whether or not a reference needs to use FORM_ref_addr; only
8285 DIEs in the same CU will be marked. We used to clear out the offset
8286 and use that as the flag, but ran into ordering problems. */
8289 mark_dies (dw_die_ref die
)
8293 gcc_assert (!die
->die_mark
);
8296 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8299 /* Clear the marks for a die and its children. */
8302 unmark_dies (dw_die_ref die
)
8306 if (! use_debug_types
)
8307 gcc_assert (die
->die_mark
);
8310 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8313 /* Clear the marks for a die, its children and referred dies. */
8316 unmark_all_dies (dw_die_ref die
)
8326 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8328 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8329 if (AT_class (a
) == dw_val_class_die_ref
)
8330 unmark_all_dies (AT_ref (a
));
8333 /* Calculate if the entry should appear in the final output file. It may be
8334 from a pruned a type. */
8337 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8339 /* By limiting gnu pubnames to definitions only, gold can generate a
8340 gdb index without entries for declarations, which don't include
8341 enough information to be useful. */
8342 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8345 if (table
== pubname_table
)
8347 /* Enumerator names are part of the pubname table, but the
8348 parent DW_TAG_enumeration_type die may have been pruned.
8349 Don't output them if that is the case. */
8350 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8351 (p
->die
->die_parent
== NULL
8352 || !p
->die
->die_parent
->die_perennial_p
))
8355 /* Everything else in the pubname table is included. */
8359 /* The pubtypes table shouldn't include types that have been
8361 return (p
->die
->die_offset
!= 0
8362 || !flag_eliminate_unused_debug_types
);
8365 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8366 generated for the compilation unit. */
8368 static unsigned long
8369 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8374 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8376 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8377 FOR_EACH_VEC_ELT (*names
, i
, p
)
8378 if (include_pubname_in_output (names
, p
))
8379 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8381 size
+= DWARF_OFFSET_SIZE
;
8385 /* Return the size of the information in the .debug_aranges section. */
8387 static unsigned long
8388 size_of_aranges (void)
8392 size
= DWARF_ARANGES_HEADER_SIZE
;
8394 /* Count the address/length pair for this compilation unit. */
8395 if (text_section_used
)
8396 size
+= 2 * DWARF2_ADDR_SIZE
;
8397 if (cold_text_section_used
)
8398 size
+= 2 * DWARF2_ADDR_SIZE
;
8399 if (have_multiple_function_sections
)
8404 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8406 if (DECL_IGNORED_P (fde
->decl
))
8408 if (!fde
->in_std_section
)
8409 size
+= 2 * DWARF2_ADDR_SIZE
;
8410 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8411 size
+= 2 * DWARF2_ADDR_SIZE
;
8415 /* Count the two zero words used to terminated the address range table. */
8416 size
+= 2 * DWARF2_ADDR_SIZE
;
8420 /* Select the encoding of an attribute value. */
8422 static enum dwarf_form
8423 value_format (dw_attr_ref a
)
8425 switch (AT_class (a
))
8427 case dw_val_class_addr
:
8428 /* Only very few attributes allow DW_FORM_addr. */
8433 case DW_AT_entry_pc
:
8434 case DW_AT_trampoline
:
8435 return (AT_index (a
) == NOT_INDEXED
8436 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8440 switch (DWARF2_ADDR_SIZE
)
8443 return DW_FORM_data1
;
8445 return DW_FORM_data2
;
8447 return DW_FORM_data4
;
8449 return DW_FORM_data8
;
8453 case dw_val_class_range_list
:
8454 case dw_val_class_loc_list
:
8455 if (dwarf_version
>= 4)
8456 return DW_FORM_sec_offset
;
8458 case dw_val_class_vms_delta
:
8459 case dw_val_class_offset
:
8460 switch (DWARF_OFFSET_SIZE
)
8463 return DW_FORM_data4
;
8465 return DW_FORM_data8
;
8469 case dw_val_class_loc
:
8470 if (dwarf_version
>= 4)
8471 return DW_FORM_exprloc
;
8472 switch (constant_size (size_of_locs (AT_loc (a
))))
8475 return DW_FORM_block1
;
8477 return DW_FORM_block2
;
8479 return DW_FORM_block4
;
8483 case dw_val_class_const
:
8484 return DW_FORM_sdata
;
8485 case dw_val_class_unsigned_const
:
8486 switch (constant_size (AT_unsigned (a
)))
8489 return DW_FORM_data1
;
8491 return DW_FORM_data2
;
8493 /* In DWARF3 DW_AT_data_member_location with
8494 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8495 constant, so we need to use DW_FORM_udata if we need
8496 a large constant. */
8497 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8498 return DW_FORM_udata
;
8499 return DW_FORM_data4
;
8501 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8502 return DW_FORM_udata
;
8503 return DW_FORM_data8
;
8507 case dw_val_class_const_double
:
8508 switch (HOST_BITS_PER_WIDE_INT
)
8511 return DW_FORM_data2
;
8513 return DW_FORM_data4
;
8515 return DW_FORM_data8
;
8518 return DW_FORM_block1
;
8520 case dw_val_class_wide_int
:
8521 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
8524 return DW_FORM_data1
;
8526 return DW_FORM_data2
;
8528 return DW_FORM_data4
;
8530 return DW_FORM_data8
;
8532 return DW_FORM_block1
;
8534 case dw_val_class_vec
:
8535 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8536 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8539 return DW_FORM_block1
;
8541 return DW_FORM_block2
;
8543 return DW_FORM_block4
;
8547 case dw_val_class_flag
:
8548 if (dwarf_version
>= 4)
8550 /* Currently all add_AT_flag calls pass in 1 as last argument,
8551 so DW_FORM_flag_present can be used. If that ever changes,
8552 we'll need to use DW_FORM_flag and have some optimization
8553 in build_abbrev_table that will change those to
8554 DW_FORM_flag_present if it is set to 1 in all DIEs using
8555 the same abbrev entry. */
8556 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8557 return DW_FORM_flag_present
;
8559 return DW_FORM_flag
;
8560 case dw_val_class_die_ref
:
8561 if (AT_ref_external (a
))
8562 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8565 case dw_val_class_fde_ref
:
8566 return DW_FORM_data
;
8567 case dw_val_class_lbl_id
:
8568 return (AT_index (a
) == NOT_INDEXED
8569 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8570 case dw_val_class_lineptr
:
8571 case dw_val_class_macptr
:
8572 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8573 case dw_val_class_str
:
8574 return AT_string_form (a
);
8575 case dw_val_class_file
:
8576 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8579 return DW_FORM_data1
;
8581 return DW_FORM_data2
;
8583 return DW_FORM_data4
;
8588 case dw_val_class_data8
:
8589 return DW_FORM_data8
;
8591 case dw_val_class_high_pc
:
8592 switch (DWARF2_ADDR_SIZE
)
8595 return DW_FORM_data1
;
8597 return DW_FORM_data2
;
8599 return DW_FORM_data4
;
8601 return DW_FORM_data8
;
8611 /* Output the encoding of an attribute value. */
8614 output_value_format (dw_attr_ref a
)
8616 enum dwarf_form form
= value_format (a
);
8618 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8621 /* Given a die and id, produce the appropriate abbreviations. */
8624 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8629 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8630 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8631 dwarf_tag_name (abbrev
->die_tag
));
8633 if (abbrev
->die_child
!= NULL
)
8634 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8636 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8638 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8640 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8641 dwarf_attr_name (a_attr
->dw_attr
));
8642 output_value_format (a_attr
);
8645 dw2_asm_output_data (1, 0, NULL
);
8646 dw2_asm_output_data (1, 0, NULL
);
8650 /* Output the .debug_abbrev section which defines the DIE abbreviation
8654 output_abbrev_section (void)
8656 unsigned long abbrev_id
;
8658 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8659 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8661 /* Terminate the table. */
8662 dw2_asm_output_data (1, 0, NULL
);
8665 /* Output a symbol we can use to refer to this DIE from another CU. */
8668 output_die_symbol (dw_die_ref die
)
8670 const char *sym
= die
->die_id
.die_symbol
;
8672 gcc_assert (!die
->comdat_type_p
);
8677 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8678 /* We make these global, not weak; if the target doesn't support
8679 .linkonce, it doesn't support combining the sections, so debugging
8681 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8683 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8686 /* Return a new location list, given the begin and end range, and the
8689 static inline dw_loc_list_ref
8690 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8691 const char *section
)
8693 dw_loc_list_ref retlist
= ggc_cleared_alloc
<dw_loc_list_node
> ();
8695 retlist
->begin
= begin
;
8696 retlist
->begin_entry
= NULL
;
8698 retlist
->expr
= expr
;
8699 retlist
->section
= section
;
8704 /* Generate a new internal symbol for this location list node, if it
8705 hasn't got one yet. */
8708 gen_llsym (dw_loc_list_ref list
)
8710 gcc_assert (!list
->ll_symbol
);
8711 list
->ll_symbol
= gen_internal_sym ("LLST");
8714 /* Output the location list given to us. */
8717 output_loc_list (dw_loc_list_ref list_head
)
8719 dw_loc_list_ref curr
= list_head
;
8721 if (list_head
->emitted
)
8723 list_head
->emitted
= true;
8725 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8727 /* Walk the location list, and output each range + expression. */
8728 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8731 /* Don't output an entry that starts and ends at the same address. */
8732 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8734 size
= size_of_locs (curr
->expr
);
8735 /* If the expression is too large, drop it on the floor. We could
8736 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8737 in the expression, but >= 64KB expressions for a single value
8738 in a single range are unlikely very useful. */
8741 if (dwarf_split_debug_info
)
8743 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8744 "Location list start/length entry (%s)",
8745 list_head
->ll_symbol
);
8746 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8747 "Location list range start index (%s)",
8749 /* The length field is 4 bytes. If we ever need to support
8750 an 8-byte length, we can add a new DW_LLE code or fall back
8751 to DW_LLE_GNU_start_end_entry. */
8752 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8753 "Location list range length (%s)",
8754 list_head
->ll_symbol
);
8756 else if (!have_multiple_function_sections
)
8758 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8759 "Location list begin address (%s)",
8760 list_head
->ll_symbol
);
8761 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8762 "Location list end address (%s)",
8763 list_head
->ll_symbol
);
8767 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8768 "Location list begin address (%s)",
8769 list_head
->ll_symbol
);
8770 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8771 "Location list end address (%s)",
8772 list_head
->ll_symbol
);
8775 /* Output the block length for this list of location operations. */
8776 gcc_assert (size
<= 0xffff);
8777 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8779 output_loc_sequence (curr
->expr
, -1);
8782 if (dwarf_split_debug_info
)
8783 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8784 "Location list terminator (%s)",
8785 list_head
->ll_symbol
);
8788 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8789 "Location list terminator begin (%s)",
8790 list_head
->ll_symbol
);
8791 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8792 "Location list terminator end (%s)",
8793 list_head
->ll_symbol
);
8797 /* Output a range_list offset into the debug_range section. Emit a
8798 relocated reference if val_entry is NULL, otherwise, emit an
8799 indirect reference. */
8802 output_range_list_offset (dw_attr_ref a
)
8804 const char *name
= dwarf_attr_name (a
->dw_attr
);
8806 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8808 char *p
= strchr (ranges_section_label
, '\0');
8809 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8810 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8811 debug_ranges_section
, "%s", name
);
8815 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8816 "%s (offset from %s)", name
, ranges_section_label
);
8819 /* Output the offset into the debug_loc section. */
8822 output_loc_list_offset (dw_attr_ref a
)
8824 char *sym
= AT_loc_list (a
)->ll_symbol
;
8827 if (dwarf_split_debug_info
)
8828 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8829 "%s", dwarf_attr_name (a
->dw_attr
));
8831 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8832 "%s", dwarf_attr_name (a
->dw_attr
));
8835 /* Output an attribute's index or value appropriately. */
8838 output_attr_index_or_value (dw_attr_ref a
)
8840 const char *name
= dwarf_attr_name (a
->dw_attr
);
8842 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8844 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8847 switch (AT_class (a
))
8849 case dw_val_class_addr
:
8850 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8852 case dw_val_class_high_pc
:
8853 case dw_val_class_lbl_id
:
8854 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8856 case dw_val_class_loc_list
:
8857 output_loc_list_offset (a
);
8864 /* Output a type signature. */
8867 output_signature (const char *sig
, const char *name
)
8871 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8872 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8875 /* Output the DIE and its attributes. Called recursively to generate
8876 the definitions of each child DIE. */
8879 output_die (dw_die_ref die
)
8886 /* If someone in another CU might refer to us, set up a symbol for
8887 them to point to. */
8888 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8889 output_die_symbol (die
);
8891 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8892 (unsigned long)die
->die_offset
,
8893 dwarf_tag_name (die
->die_tag
));
8895 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8897 const char *name
= dwarf_attr_name (a
->dw_attr
);
8899 switch (AT_class (a
))
8901 case dw_val_class_addr
:
8902 output_attr_index_or_value (a
);
8905 case dw_val_class_offset
:
8906 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8910 case dw_val_class_range_list
:
8911 output_range_list_offset (a
);
8914 case dw_val_class_loc
:
8915 size
= size_of_locs (AT_loc (a
));
8917 /* Output the block length for this list of location operations. */
8918 if (dwarf_version
>= 4)
8919 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8921 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8923 output_loc_sequence (AT_loc (a
), -1);
8926 case dw_val_class_const
:
8927 /* ??? It would be slightly more efficient to use a scheme like is
8928 used for unsigned constants below, but gdb 4.x does not sign
8929 extend. Gdb 5.x does sign extend. */
8930 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8933 case dw_val_class_unsigned_const
:
8935 int csize
= constant_size (AT_unsigned (a
));
8936 if (dwarf_version
== 3
8937 && a
->dw_attr
== DW_AT_data_member_location
8939 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8941 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8945 case dw_val_class_const_double
:
8947 unsigned HOST_WIDE_INT first
, second
;
8949 if (HOST_BITS_PER_WIDE_INT
>= 64)
8950 dw2_asm_output_data (1,
8951 HOST_BITS_PER_DOUBLE_INT
8952 / HOST_BITS_PER_CHAR
,
8955 if (WORDS_BIG_ENDIAN
)
8957 first
= a
->dw_attr_val
.v
.val_double
.high
;
8958 second
= a
->dw_attr_val
.v
.val_double
.low
;
8962 first
= a
->dw_attr_val
.v
.val_double
.low
;
8963 second
= a
->dw_attr_val
.v
.val_double
.high
;
8966 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8968 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8973 case dw_val_class_wide_int
:
8976 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
8977 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
8978 if (len
* HOST_BITS_PER_WIDE_INT
> 64)
8979 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
) * l
,
8982 if (WORDS_BIG_ENDIAN
)
8983 for (i
= len
- 1; i
>= 0; --i
)
8985 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
8990 for (i
= 0; i
< len
; ++i
)
8992 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
8999 case dw_val_class_vec
:
9001 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
9002 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
9006 dw2_asm_output_data (constant_size (len
* elt_size
),
9007 len
* elt_size
, "%s", name
);
9008 if (elt_size
> sizeof (HOST_WIDE_INT
))
9013 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
9016 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
9017 "fp or vector constant word %u", i
);
9021 case dw_val_class_flag
:
9022 if (dwarf_version
>= 4)
9024 /* Currently all add_AT_flag calls pass in 1 as last argument,
9025 so DW_FORM_flag_present can be used. If that ever changes,
9026 we'll need to use DW_FORM_flag and have some optimization
9027 in build_abbrev_table that will change those to
9028 DW_FORM_flag_present if it is set to 1 in all DIEs using
9029 the same abbrev entry. */
9030 gcc_assert (AT_flag (a
) == 1);
9032 fprintf (asm_out_file
, "\t\t\t%s %s\n",
9033 ASM_COMMENT_START
, name
);
9036 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
9039 case dw_val_class_loc_list
:
9040 output_attr_index_or_value (a
);
9043 case dw_val_class_die_ref
:
9044 if (AT_ref_external (a
))
9046 if (AT_ref (a
)->comdat_type_p
)
9048 comdat_type_node_ref type_node
=
9049 AT_ref (a
)->die_id
.die_type_node
;
9051 gcc_assert (type_node
);
9052 output_signature (type_node
->signature
, name
);
9056 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
9060 /* In DWARF2, DW_FORM_ref_addr is sized by target address
9061 length, whereas in DWARF3 it's always sized as an
9063 if (dwarf_version
== 2)
9064 size
= DWARF2_ADDR_SIZE
;
9066 size
= DWARF_OFFSET_SIZE
;
9067 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
9073 gcc_assert (AT_ref (a
)->die_offset
);
9074 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
9079 case dw_val_class_fde_ref
:
9083 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
9084 a
->dw_attr_val
.v
.val_fde_index
* 2);
9085 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
9090 case dw_val_class_vms_delta
:
9091 #ifdef ASM_OUTPUT_DWARF_VMS_DELTA
9092 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
9093 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9096 dw2_asm_output_delta (DWARF_OFFSET_SIZE
,
9097 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
9102 case dw_val_class_lbl_id
:
9103 output_attr_index_or_value (a
);
9106 case dw_val_class_lineptr
:
9107 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9108 debug_line_section
, "%s", name
);
9111 case dw_val_class_macptr
:
9112 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
9113 debug_macinfo_section
, "%s", name
);
9116 case dw_val_class_str
:
9117 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
9118 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9119 a
->dw_attr_val
.v
.val_str
->label
,
9121 "%s: \"%s\"", name
, AT_string (a
));
9122 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
9123 dw2_asm_output_data_uleb128 (AT_index (a
),
9124 "%s: \"%s\"", name
, AT_string (a
));
9126 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
9129 case dw_val_class_file
:
9131 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
9133 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
9134 a
->dw_attr_val
.v
.val_file
->filename
);
9138 case dw_val_class_data8
:
9142 for (i
= 0; i
< 8; i
++)
9143 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
9144 i
== 0 ? "%s" : NULL
, name
);
9148 case dw_val_class_high_pc
:
9149 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
9150 get_AT_low_pc (die
), "DW_AT_high_pc");
9158 FOR_EACH_CHILD (die
, c
, output_die (c
));
9160 /* Add null byte to terminate sibling list. */
9161 if (die
->die_child
!= NULL
)
9162 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
9163 (unsigned long) die
->die_offset
);
9166 /* Output the compilation unit that appears at the beginning of the
9167 .debug_info section, and precedes the DIE descriptions. */
9170 output_compilation_unit_header (void)
9172 /* We don't support actual DWARFv5 units yet, we just use some
9173 DWARFv5 draft DIE tags in DWARFv4 format. */
9174 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9176 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9177 dw2_asm_output_data (4, 0xffffffff,
9178 "Initial length escape value indicating 64-bit DWARF extension");
9179 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9180 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
9181 "Length of Compilation Unit Info");
9182 dw2_asm_output_data (2, ver
, "DWARF version number");
9183 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
9184 debug_abbrev_section
,
9185 "Offset Into Abbrev. Section");
9186 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9189 /* Output the compilation unit DIE and its children. */
9192 output_comp_unit (dw_die_ref die
, int output_if_empty
)
9194 const char *secname
, *oldsym
;
9197 /* Unless we are outputting main CU, we may throw away empty ones. */
9198 if (!output_if_empty
&& die
->die_child
== NULL
)
9201 /* Even if there are no children of this DIE, we must output the information
9202 about the compilation unit. Otherwise, on an empty translation unit, we
9203 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
9204 will then complain when examining the file. First mark all the DIEs in
9205 this CU so we know which get local refs. */
9208 external_ref_hash_type
*extern_map
= optimize_external_refs (die
);
9210 build_abbrev_table (die
, extern_map
);
9214 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9215 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
9216 calc_die_sizes (die
);
9218 oldsym
= die
->die_id
.die_symbol
;
9221 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
9223 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
9225 die
->die_id
.die_symbol
= NULL
;
9226 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9230 switch_to_section (debug_info_section
);
9231 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
9232 info_section_emitted
= true;
9235 /* Output debugging information. */
9236 output_compilation_unit_header ();
9239 /* Leave the marks on the main CU, so we can check them in
9244 die
->die_id
.die_symbol
= oldsym
;
9248 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
9249 and .debug_pubtypes. This is configured per-target, but can be
9250 overridden by the -gpubnames or -gno-pubnames options. */
9253 want_pubnames (void)
9255 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
9257 if (debug_generate_pub_sections
!= -1)
9258 return debug_generate_pub_sections
;
9259 return targetm
.want_debug_pub_sections
;
9262 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9265 add_AT_pubnames (dw_die_ref die
)
9267 if (want_pubnames ())
9268 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
9271 /* Add a string attribute value to a skeleton DIE. */
9274 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9278 struct indirect_string_node
*node
;
9280 if (! skeleton_debug_str_hash
)
9281 skeleton_debug_str_hash
9282 = hash_table
<indirect_string_hasher
>::create_ggc (10);
9284 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
9285 find_string_form (node
);
9286 if (node
->form
== DW_FORM_GNU_str_index
)
9287 node
->form
= DW_FORM_strp
;
9289 attr
.dw_attr
= attr_kind
;
9290 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
9291 attr
.dw_attr_val
.val_entry
= NULL
;
9292 attr
.dw_attr_val
.v
.val_str
= node
;
9293 add_dwarf_attr (die
, &attr
);
9296 /* Helper function to generate top-level dies for skeleton debug_info and
9300 add_top_level_skeleton_die_attrs (dw_die_ref die
)
9302 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
9303 const char *comp_dir
= comp_dir_string ();
9305 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
9306 if (comp_dir
!= NULL
)
9307 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
9308 add_AT_pubnames (die
);
9309 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
9312 /* Output skeleton debug sections that point to the dwo file. */
9315 output_skeleton_debug_sections (dw_die_ref comp_unit
)
9317 /* We don't support actual DWARFv5 units yet, we just use some
9318 DWARFv5 draft DIE tags in DWARFv4 format. */
9319 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
9321 /* These attributes will be found in the full debug_info section. */
9322 remove_AT (comp_unit
, DW_AT_producer
);
9323 remove_AT (comp_unit
, DW_AT_language
);
9325 switch_to_section (debug_skeleton_info_section
);
9326 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
9328 /* Produce the skeleton compilation-unit header. This one differs enough from
9329 a normal CU header that it's better not to call output_compilation_unit
9331 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9332 dw2_asm_output_data (4, 0xffffffff,
9333 "Initial length escape value indicating 64-bit DWARF extension");
9335 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9336 DWARF_COMPILE_UNIT_HEADER_SIZE
9337 - DWARF_INITIAL_LENGTH_SIZE
9338 + size_of_die (comp_unit
),
9339 "Length of Compilation Unit Info");
9340 dw2_asm_output_data (2, ver
, "DWARF version number");
9341 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
9342 debug_abbrev_section
,
9343 "Offset Into Abbrev. Section");
9344 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9346 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
9347 output_die (comp_unit
);
9349 /* Build the skeleton debug_abbrev section. */
9350 switch_to_section (debug_skeleton_abbrev_section
);
9351 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
9353 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
9355 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9358 /* Output a comdat type unit DIE and its children. */
9361 output_comdat_type_unit (comdat_type_node
*node
)
9363 const char *secname
;
9366 #if defined (OBJECT_FORMAT_ELF)
9370 /* First mark all the DIEs in this CU so we know which get local refs. */
9371 mark_dies (node
->root_die
);
9373 external_ref_hash_type
*extern_map
= optimize_external_refs (node
->root_die
);
9375 build_abbrev_table (node
->root_die
, extern_map
);
9380 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9381 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9382 calc_die_sizes (node
->root_die
);
9384 #if defined (OBJECT_FORMAT_ELF)
9385 if (!dwarf_split_debug_info
)
9386 secname
= ".debug_types";
9388 secname
= ".debug_types.dwo";
9390 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9391 sprintf (tmp
, "wt.");
9392 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9393 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9394 comdat_key
= get_identifier (tmp
);
9395 targetm
.asm_out
.named_section (secname
,
9396 SECTION_DEBUG
| SECTION_LINKONCE
,
9399 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9400 sprintf (tmp
, ".gnu.linkonce.wt.");
9401 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9402 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9404 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9407 /* Output debugging information. */
9408 output_compilation_unit_header ();
9409 output_signature (node
->signature
, "Type Signature");
9410 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9411 "Offset to Type DIE");
9412 output_die (node
->root_die
);
9414 unmark_dies (node
->root_die
);
9417 /* Return the DWARF2/3 pubname associated with a decl. */
9420 dwarf2_name (tree decl
, int scope
)
9422 if (DECL_NAMELESS (decl
))
9424 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9427 /* Add a new entry to .debug_pubnames if appropriate. */
9430 add_pubname_string (const char *str
, dw_die_ref die
)
9435 e
.name
= xstrdup (str
);
9436 vec_safe_push (pubname_table
, e
);
9440 add_pubname (tree decl
, dw_die_ref die
)
9442 if (!want_pubnames ())
9445 /* Don't add items to the table when we expect that the consumer will have
9446 just read the enclosing die. For example, if the consumer is looking at a
9447 class_member, it will either be inside the class already, or will have just
9448 looked up the class to find the member. Either way, searching the class is
9449 faster than searching the index. */
9450 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9451 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9453 const char *name
= dwarf2_name (decl
, 1);
9456 add_pubname_string (name
, die
);
9460 /* Add an enumerator to the pubnames section. */
9463 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9467 gcc_assert (scope_name
);
9468 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9470 vec_safe_push (pubname_table
, e
);
9473 /* Add a new entry to .debug_pubtypes if appropriate. */
9476 add_pubtype (tree decl
, dw_die_ref die
)
9480 if (!want_pubnames ())
9483 if ((TREE_PUBLIC (decl
)
9484 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9485 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9488 const char *scope_name
= "";
9489 const char *sep
= is_cxx () ? "::" : ".";
9492 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9493 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9495 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9496 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9497 scope_name
= concat (scope_name
, sep
, NULL
);
9503 name
= type_tag (decl
);
9505 name
= lang_hooks
.dwarf_name (decl
, 1);
9507 /* If we don't have a name for the type, there's no point in adding
9509 if (name
!= NULL
&& name
[0] != '\0')
9512 e
.name
= concat (scope_name
, name
, NULL
);
9513 vec_safe_push (pubtype_table
, e
);
9516 /* Although it might be more consistent to add the pubinfo for the
9517 enumerators as their dies are created, they should only be added if the
9518 enum type meets the criteria above. So rather than re-check the parent
9519 enum type whenever an enumerator die is created, just output them all
9520 here. This isn't protected by the name conditional because anonymous
9521 enums don't have names. */
9522 if (die
->die_tag
== DW_TAG_enumeration_type
)
9526 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9531 /* Output a single entry in the pubnames table. */
9534 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9536 dw_die_ref die
= entry
->die
;
9537 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9539 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9541 if (debug_generate_pub_sections
== 2)
9543 /* This logic follows gdb's method for determining the value of the flag
9545 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9546 switch (die
->die_tag
)
9548 case DW_TAG_typedef
:
9549 case DW_TAG_base_type
:
9550 case DW_TAG_subrange_type
:
9551 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9552 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9554 case DW_TAG_enumerator
:
9555 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9556 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9557 if (!is_cxx () && !is_java ())
9558 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9560 case DW_TAG_subprogram
:
9561 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9562 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9564 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9566 case DW_TAG_constant
:
9567 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9568 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9569 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9571 case DW_TAG_variable
:
9572 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9573 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9574 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9576 case DW_TAG_namespace
:
9577 case DW_TAG_imported_declaration
:
9578 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9580 case DW_TAG_class_type
:
9581 case DW_TAG_interface_type
:
9582 case DW_TAG_structure_type
:
9583 case DW_TAG_union_type
:
9584 case DW_TAG_enumeration_type
:
9585 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9586 if (!is_cxx () && !is_java ())
9587 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9590 /* An unusual tag. Leave the flag-byte empty. */
9593 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9597 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9601 /* Output the public names table used to speed up access to externally
9602 visible names; or the public types table used to find type definitions. */
9605 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9608 unsigned long pubnames_length
= size_of_pubnames (names
);
9611 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9612 dw2_asm_output_data (4, 0xffffffff,
9613 "Initial length escape value indicating 64-bit DWARF extension");
9614 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9616 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9617 dw2_asm_output_data (2, 2, "DWARF Version");
9619 if (dwarf_split_debug_info
)
9620 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9621 debug_skeleton_info_section
,
9622 "Offset of Compilation Unit Info");
9624 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9626 "Offset of Compilation Unit Info");
9627 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9628 "Compilation Unit Length");
9630 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9632 if (include_pubname_in_output (names
, pub
))
9634 dw_offset die_offset
= pub
->die
->die_offset
;
9636 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9637 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9638 gcc_assert (pub
->die
->die_mark
);
9640 /* If we're putting types in their own .debug_types sections,
9641 the .debug_pubtypes table will still point to the compile
9642 unit (not the type unit), so we want to use the offset of
9643 the skeleton DIE (if there is one). */
9644 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9646 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9648 if (type_node
!= NULL
)
9649 die_offset
= (type_node
->skeleton_die
!= NULL
9650 ? type_node
->skeleton_die
->die_offset
9651 : comp_unit_die ()->die_offset
);
9654 output_pubname (die_offset
, pub
);
9658 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9661 /* Output public names and types tables if necessary. */
9664 output_pubtables (void)
9666 if (!want_pubnames () || !info_section_emitted
)
9669 switch_to_section (debug_pubnames_section
);
9670 output_pubnames (pubname_table
);
9671 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9672 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9673 simply won't look for the section. */
9674 switch_to_section (debug_pubtypes_section
);
9675 output_pubnames (pubtype_table
);
9679 /* Output the information that goes into the .debug_aranges table.
9680 Namely, define the beginning and ending address range of the
9681 text section generated for this compilation unit. */
9684 output_aranges (unsigned long aranges_length
)
9688 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9689 dw2_asm_output_data (4, 0xffffffff,
9690 "Initial length escape value indicating 64-bit DWARF extension");
9691 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9692 "Length of Address Ranges Info");
9693 /* Version number for aranges is still 2, even up to DWARF5. */
9694 dw2_asm_output_data (2, 2, "DWARF Version");
9695 if (dwarf_split_debug_info
)
9696 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9697 debug_skeleton_info_section
,
9698 "Offset of Compilation Unit Info");
9700 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9702 "Offset of Compilation Unit Info");
9703 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9704 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9706 /* We need to align to twice the pointer size here. */
9707 if (DWARF_ARANGES_PAD_SIZE
)
9709 /* Pad using a 2 byte words so that padding is correct for any
9711 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9712 2 * DWARF2_ADDR_SIZE
);
9713 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9714 dw2_asm_output_data (2, 0, NULL
);
9717 /* It is necessary not to output these entries if the sections were
9718 not used; if the sections were not used, the length will be 0 and
9719 the address may end up as 0 if the section is discarded by ld
9720 --gc-sections, leaving an invalid (0, 0) entry that can be
9721 confused with the terminator. */
9722 if (text_section_used
)
9724 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9725 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9726 text_section_label
, "Length");
9728 if (cold_text_section_used
)
9730 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9732 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9733 cold_text_section_label
, "Length");
9736 if (have_multiple_function_sections
)
9741 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9743 if (DECL_IGNORED_P (fde
->decl
))
9745 if (!fde
->in_std_section
)
9747 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9749 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9750 fde
->dw_fde_begin
, "Length");
9752 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9754 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9756 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9757 fde
->dw_fde_second_begin
, "Length");
9762 /* Output the terminator words. */
9763 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9764 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9767 /* Add a new entry to .debug_ranges. Return the offset at which it
9771 add_ranges_num (int num
)
9773 unsigned int in_use
= ranges_table_in_use
;
9775 if (in_use
== ranges_table_allocated
)
9777 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9778 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9779 ranges_table_allocated
);
9780 memset (ranges_table
+ ranges_table_in_use
, 0,
9781 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9784 ranges_table
[in_use
].num
= num
;
9785 ranges_table_in_use
= in_use
+ 1;
9787 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9790 /* Add a new entry to .debug_ranges corresponding to a block, or a
9791 range terminator if BLOCK is NULL. */
9794 add_ranges (const_tree block
)
9796 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9799 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9800 When using dwarf_split_debug_info, address attributes in dies destined
9801 for the final executable should be direct references--setting the
9802 parameter force_direct ensures this behavior. */
9805 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9806 bool *added
, bool force_direct
)
9808 unsigned int in_use
= ranges_by_label_in_use
;
9809 unsigned int offset
;
9811 if (in_use
== ranges_by_label_allocated
)
9813 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9814 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9816 ranges_by_label_allocated
);
9817 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9818 RANGES_TABLE_INCREMENT
9819 * sizeof (struct dw_ranges_by_label_struct
));
9822 ranges_by_label
[in_use
].begin
= begin
;
9823 ranges_by_label
[in_use
].end
= end
;
9824 ranges_by_label_in_use
= in_use
+ 1;
9826 offset
= add_ranges_num (-(int)in_use
- 1);
9829 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9835 output_ranges (void)
9838 static const char *const start_fmt
= "Offset %#x";
9839 const char *fmt
= start_fmt
;
9841 for (i
= 0; i
< ranges_table_in_use
; i
++)
9843 int block_num
= ranges_table
[i
].num
;
9847 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9848 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9850 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9851 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9853 /* If all code is in the text section, then the compilation
9854 unit base address defaults to DW_AT_low_pc, which is the
9855 base of the text section. */
9856 if (!have_multiple_function_sections
)
9858 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9860 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9861 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9862 text_section_label
, NULL
);
9865 /* Otherwise, the compilation unit base address is zero,
9866 which allows us to use absolute addresses, and not worry
9867 about whether the target supports cross-section
9871 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9872 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9873 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9879 /* Negative block_num stands for an index into ranges_by_label. */
9880 else if (block_num
< 0)
9882 int lab_idx
= - block_num
- 1;
9884 if (!have_multiple_function_sections
)
9888 /* If we ever use add_ranges_by_labels () for a single
9889 function section, all we have to do is to take out
9891 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9892 ranges_by_label
[lab_idx
].begin
,
9894 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9895 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9896 ranges_by_label
[lab_idx
].end
,
9897 text_section_label
, NULL
);
9902 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9903 ranges_by_label
[lab_idx
].begin
,
9904 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9905 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9906 ranges_by_label
[lab_idx
].end
,
9912 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9913 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9919 /* Data structure containing information about input files. */
9922 const char *path
; /* Complete file name. */
9923 const char *fname
; /* File name part. */
9924 int length
; /* Length of entire string. */
9925 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9926 int dir_idx
; /* Index in directory table. */
9929 /* Data structure containing information about directories with source
9933 const char *path
; /* Path including directory name. */
9934 int length
; /* Path length. */
9935 int prefix
; /* Index of directory entry which is a prefix. */
9936 int count
; /* Number of files in this directory. */
9937 int dir_idx
; /* Index of directory used as base. */
9940 /* Callback function for file_info comparison. We sort by looking at
9941 the directories in the path. */
9944 file_info_cmp (const void *p1
, const void *p2
)
9946 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9947 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9948 const unsigned char *cp1
;
9949 const unsigned char *cp2
;
9951 /* Take care of file names without directories. We need to make sure that
9952 we return consistent values to qsort since some will get confused if
9953 we return the same value when identical operands are passed in opposite
9954 orders. So if neither has a directory, return 0 and otherwise return
9955 1 or -1 depending on which one has the directory. */
9956 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9957 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9959 cp1
= (const unsigned char *) s1
->path
;
9960 cp2
= (const unsigned char *) s2
->path
;
9966 /* Reached the end of the first path? If so, handle like above. */
9967 if ((cp1
== (const unsigned char *) s1
->fname
)
9968 || (cp2
== (const unsigned char *) s2
->fname
))
9969 return ((cp2
== (const unsigned char *) s2
->fname
)
9970 - (cp1
== (const unsigned char *) s1
->fname
));
9972 /* Character of current path component the same? */
9973 else if (*cp1
!= *cp2
)
9978 struct file_name_acquire_data
9980 struct file_info
*files
;
9985 /* Traversal function for the hash table. */
9988 file_name_acquire (dwarf_file_data
**slot
, file_name_acquire_data
*fnad
)
9990 struct dwarf_file_data
*d
= *slot
;
9991 struct file_info
*fi
;
9994 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9996 if (! d
->emitted_number
)
9999 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
10001 fi
= fnad
->files
+ fnad
->used_files
++;
10003 /* Skip all leading "./". */
10005 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
10008 /* Create a new array entry. */
10010 fi
->length
= strlen (f
);
10013 /* Search for the file name part. */
10014 f
= strrchr (f
, DIR_SEPARATOR
);
10015 #if defined (DIR_SEPARATOR_2)
10017 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
10021 if (f
== NULL
|| f
< g
)
10027 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
10031 /* Output the directory table and the file name table. We try to minimize
10032 the total amount of memory needed. A heuristic is used to avoid large
10033 slowdowns with many input files. */
10036 output_file_names (void)
10038 struct file_name_acquire_data fnad
;
10040 struct file_info
*files
;
10041 struct dir_info
*dirs
;
10049 if (!last_emitted_file
)
10051 dw2_asm_output_data (1, 0, "End directory table");
10052 dw2_asm_output_data (1, 0, "End file name table");
10056 numfiles
= last_emitted_file
->emitted_number
;
10058 /* Allocate the various arrays we need. */
10059 files
= XALLOCAVEC (struct file_info
, numfiles
);
10060 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
10062 fnad
.files
= files
;
10063 fnad
.used_files
= 0;
10064 fnad
.max_files
= numfiles
;
10065 file_table
->traverse
<file_name_acquire_data
*, file_name_acquire
> (&fnad
);
10066 gcc_assert (fnad
.used_files
== fnad
.max_files
);
10068 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
10070 /* Find all the different directories used. */
10071 dirs
[0].path
= files
[0].path
;
10072 dirs
[0].length
= files
[0].fname
- files
[0].path
;
10073 dirs
[0].prefix
= -1;
10075 dirs
[0].dir_idx
= 0;
10076 files
[0].dir_idx
= 0;
10079 for (i
= 1; i
< numfiles
; i
++)
10080 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
10081 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
10082 dirs
[ndirs
- 1].length
) == 0)
10084 /* Same directory as last entry. */
10085 files
[i
].dir_idx
= ndirs
- 1;
10086 ++dirs
[ndirs
- 1].count
;
10092 /* This is a new directory. */
10093 dirs
[ndirs
].path
= files
[i
].path
;
10094 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
10095 dirs
[ndirs
].count
= 1;
10096 dirs
[ndirs
].dir_idx
= ndirs
;
10097 files
[i
].dir_idx
= ndirs
;
10099 /* Search for a prefix. */
10100 dirs
[ndirs
].prefix
= -1;
10101 for (j
= 0; j
< ndirs
; j
++)
10102 if (dirs
[j
].length
< dirs
[ndirs
].length
10103 && dirs
[j
].length
> 1
10104 && (dirs
[ndirs
].prefix
== -1
10105 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
10106 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
10107 dirs
[ndirs
].prefix
= j
;
10112 /* Now to the actual work. We have to find a subset of the directories which
10113 allow expressing the file name using references to the directory table
10114 with the least amount of characters. We do not do an exhaustive search
10115 where we would have to check out every combination of every single
10116 possible prefix. Instead we use a heuristic which provides nearly optimal
10117 results in most cases and never is much off. */
10118 saved
= XALLOCAVEC (int, ndirs
);
10119 savehere
= XALLOCAVEC (int, ndirs
);
10121 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
10122 for (i
= 0; i
< ndirs
; i
++)
10127 /* We can always save some space for the current directory. But this
10128 does not mean it will be enough to justify adding the directory. */
10129 savehere
[i
] = dirs
[i
].length
;
10130 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
10132 for (j
= i
+ 1; j
< ndirs
; j
++)
10135 if (saved
[j
] < dirs
[i
].length
)
10137 /* Determine whether the dirs[i] path is a prefix of the
10141 k
= dirs
[j
].prefix
;
10142 while (k
!= -1 && k
!= (int) i
)
10143 k
= dirs
[k
].prefix
;
10147 /* Yes it is. We can possibly save some memory by
10148 writing the filenames in dirs[j] relative to
10150 savehere
[j
] = dirs
[i
].length
;
10151 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
10156 /* Check whether we can save enough to justify adding the dirs[i]
10158 if (total
> dirs
[i
].length
+ 1)
10160 /* It's worthwhile adding. */
10161 for (j
= i
; j
< ndirs
; j
++)
10162 if (savehere
[j
] > 0)
10164 /* Remember how much we saved for this directory so far. */
10165 saved
[j
] = savehere
[j
];
10167 /* Remember the prefix directory. */
10168 dirs
[j
].dir_idx
= i
;
10173 /* Emit the directory name table. */
10174 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
10175 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
10176 dw2_asm_output_nstring (dirs
[i
].path
,
10178 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
10179 "Directory Entry: %#x", i
+ idx_offset
);
10181 dw2_asm_output_data (1, 0, "End directory table");
10183 /* We have to emit them in the order of emitted_number since that's
10184 used in the debug info generation. To do this efficiently we
10185 generate a back-mapping of the indices first. */
10186 backmap
= XALLOCAVEC (int, numfiles
);
10187 for (i
= 0; i
< numfiles
; i
++)
10188 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
10190 /* Now write all the file names. */
10191 for (i
= 0; i
< numfiles
; i
++)
10193 int file_idx
= backmap
[i
];
10194 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
10196 #ifdef VMS_DEBUGGING_INFO
10197 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
10199 /* Setting these fields can lead to debugger miscomparisons,
10200 but VMS Debug requires them to be set correctly. */
10205 int maxfilelen
= strlen (files
[file_idx
].path
)
10206 + dirs
[dir_idx
].length
10207 + MAX_VMS_VERSION_LEN
+ 1;
10208 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
10210 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
10211 snprintf (filebuf
, maxfilelen
, "%s;%d",
10212 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
10214 dw2_asm_output_nstring
10215 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
10217 /* Include directory index. */
10218 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10220 /* Modification time. */
10221 dw2_asm_output_data_uleb128
10222 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
10226 /* File length in bytes. */
10227 dw2_asm_output_data_uleb128
10228 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
10232 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
10233 "File Entry: %#x", (unsigned) i
+ 1);
10235 /* Include directory index. */
10236 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10238 /* Modification time. */
10239 dw2_asm_output_data_uleb128 (0, NULL
);
10241 /* File length in bytes. */
10242 dw2_asm_output_data_uleb128 (0, NULL
);
10243 #endif /* VMS_DEBUGGING_INFO */
10246 dw2_asm_output_data (1, 0, "End file name table");
10250 /* Output one line number table into the .debug_line section. */
10253 output_one_line_info_table (dw_line_info_table
*table
)
10255 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10256 unsigned int current_line
= 1;
10257 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
10258 dw_line_info_entry
*ent
;
10261 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
10263 switch (ent
->opcode
)
10265 case LI_set_address
:
10266 /* ??? Unfortunately, we have little choice here currently, and
10267 must always use the most general form. GCC does not know the
10268 address delta itself, so we can't use DW_LNS_advance_pc. Many
10269 ports do have length attributes which will give an upper bound
10270 on the address range. We could perhaps use length attributes
10271 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10272 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
10274 /* This can handle any delta. This takes
10275 4+DWARF2_ADDR_SIZE bytes. */
10276 dw2_asm_output_data (1, 0, "set address %s", line_label
);
10277 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10278 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10279 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
10283 if (ent
->val
== current_line
)
10285 /* We still need to start a new row, so output a copy insn. */
10286 dw2_asm_output_data (1, DW_LNS_copy
,
10287 "copy line %u", current_line
);
10291 int line_offset
= ent
->val
- current_line
;
10292 int line_delta
= line_offset
- DWARF_LINE_BASE
;
10294 current_line
= ent
->val
;
10295 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
10297 /* This can handle deltas from -10 to 234, using the current
10298 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10299 This takes 1 byte. */
10300 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
10301 "line %u", current_line
);
10305 /* This can handle any delta. This takes at least 4 bytes,
10306 depending on the value being encoded. */
10307 dw2_asm_output_data (1, DW_LNS_advance_line
,
10308 "advance to line %u", current_line
);
10309 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
10310 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
10316 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
10317 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10320 case LI_set_column
:
10321 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
10322 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10325 case LI_negate_stmt
:
10326 current_is_stmt
= !current_is_stmt
;
10327 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10328 "is_stmt %d", current_is_stmt
);
10331 case LI_set_prologue_end
:
10332 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10333 "set prologue end");
10336 case LI_set_epilogue_begin
:
10337 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10338 "set epilogue begin");
10341 case LI_set_discriminator
:
10342 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10343 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10344 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10345 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10350 /* Emit debug info for the address of the end of the table. */
10351 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10352 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10353 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10354 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10356 dw2_asm_output_data (1, 0, "end sequence");
10357 dw2_asm_output_data_uleb128 (1, NULL
);
10358 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10361 /* Output the source line number correspondence information. This
10362 information goes into the .debug_line section. */
10365 output_line_info (bool prologue_only
)
10367 char l1
[20], l2
[20], p1
[20], p2
[20];
10368 /* We don't support DWARFv5 line tables yet. */
10369 int ver
= dwarf_version
< 5 ? dwarf_version
: 4;
10370 bool saw_one
= false;
10373 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10374 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10375 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10376 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10378 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10379 dw2_asm_output_data (4, 0xffffffff,
10380 "Initial length escape value indicating 64-bit DWARF extension");
10381 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10382 "Length of Source Line Info");
10383 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10385 dw2_asm_output_data (2, ver
, "DWARF Version");
10386 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10387 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10389 /* Define the architecture-dependent minimum instruction length (in bytes).
10390 In this implementation of DWARF, this field is used for information
10391 purposes only. Since GCC generates assembly language, we have no
10392 a priori knowledge of how many instruction bytes are generated for each
10393 source line, and therefore can use only the DW_LNE_set_address and
10394 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10395 this as '1', which is "correct enough" for all architectures,
10396 and don't let the target override. */
10397 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10400 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10401 "Maximum Operations Per Instruction");
10402 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10403 "Default is_stmt_start flag");
10404 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10405 "Line Base Value (Special Opcodes)");
10406 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10407 "Line Range Value (Special Opcodes)");
10408 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10409 "Special Opcode Base");
10411 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10416 case DW_LNS_advance_pc
:
10417 case DW_LNS_advance_line
:
10418 case DW_LNS_set_file
:
10419 case DW_LNS_set_column
:
10420 case DW_LNS_fixed_advance_pc
:
10421 case DW_LNS_set_isa
:
10429 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10433 /* Write out the information about the files we use. */
10434 output_file_names ();
10435 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10438 /* Output the marker for the end of the line number info. */
10439 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10443 if (separate_line_info
)
10445 dw_line_info_table
*table
;
10448 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10451 output_one_line_info_table (table
);
10455 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10457 output_one_line_info_table (cold_text_section_line_info
);
10461 /* ??? Some Darwin linkers crash on a .debug_line section with no
10462 sequences. Further, merely a DW_LNE_end_sequence entry is not
10463 sufficient -- the address column must also be initialized.
10464 Make sure to output at least one set_address/end_sequence pair,
10465 choosing .text since that section is always present. */
10466 if (text_section_line_info
->in_use
|| !saw_one
)
10467 output_one_line_info_table (text_section_line_info
);
10469 /* Output the marker for the end of the line number info. */
10470 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10473 /* Given a pointer to a tree node for some base type, return a pointer to
10474 a DIE that describes the given type.
10476 This routine must only be called for GCC type nodes that correspond to
10477 Dwarf base (fundamental) types. */
10480 base_type_die (tree type
)
10482 dw_die_ref base_type_result
;
10483 enum dwarf_type encoding
;
10485 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10488 /* If this is a subtype that should not be emitted as a subrange type,
10489 use the base type. See subrange_type_for_debug_p. */
10490 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10491 type
= TREE_TYPE (type
);
10493 switch (TREE_CODE (type
))
10496 if ((dwarf_version
>= 4 || !dwarf_strict
)
10497 && TYPE_NAME (type
)
10498 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10499 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10500 && DECL_NAME (TYPE_NAME (type
)))
10502 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10503 if (strcmp (name
, "char16_t") == 0
10504 || strcmp (name
, "char32_t") == 0)
10506 encoding
= DW_ATE_UTF
;
10510 if (TYPE_STRING_FLAG (type
))
10512 if (TYPE_UNSIGNED (type
))
10513 encoding
= DW_ATE_unsigned_char
;
10515 encoding
= DW_ATE_signed_char
;
10517 else if (TYPE_UNSIGNED (type
))
10518 encoding
= DW_ATE_unsigned
;
10520 encoding
= DW_ATE_signed
;
10524 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10526 if (dwarf_version
>= 3 || !dwarf_strict
)
10527 encoding
= DW_ATE_decimal_float
;
10529 encoding
= DW_ATE_lo_user
;
10532 encoding
= DW_ATE_float
;
10535 case FIXED_POINT_TYPE
:
10536 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10537 encoding
= DW_ATE_lo_user
;
10538 else if (TYPE_UNSIGNED (type
))
10539 encoding
= DW_ATE_unsigned_fixed
;
10541 encoding
= DW_ATE_signed_fixed
;
10544 /* Dwarf2 doesn't know anything about complex ints, so use
10545 a user defined type for it. */
10547 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10548 encoding
= DW_ATE_complex_float
;
10550 encoding
= DW_ATE_lo_user
;
10554 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10555 encoding
= DW_ATE_boolean
;
10559 /* No other TREE_CODEs are Dwarf fundamental types. */
10560 gcc_unreachable ();
10563 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10565 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10566 int_size_in_bytes (type
));
10567 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10568 add_pubtype (type
, base_type_result
);
10570 return base_type_result
;
10573 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
10574 named 'auto' in its type: return true for it, false otherwise. */
10577 is_cxx_auto (tree type
)
10581 tree name
= TYPE_IDENTIFIER (type
);
10582 if (name
== get_identifier ("auto")
10583 || name
== get_identifier ("decltype(auto)"))
10589 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10590 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10593 is_base_type (tree type
)
10595 switch (TREE_CODE (type
))
10601 case FIXED_POINT_TYPE
:
10604 case POINTER_BOUNDS_TYPE
:
10610 case QUAL_UNION_TYPE
:
10611 case ENUMERAL_TYPE
:
10612 case FUNCTION_TYPE
:
10615 case REFERENCE_TYPE
:
10623 if (is_cxx_auto (type
))
10625 gcc_unreachable ();
10631 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10632 node, return the size in bits for the type if it is a constant, or else
10633 return the alignment for the type if the type's size is not constant, or
10634 else return BITS_PER_WORD if the type actually turns out to be an
10635 ERROR_MARK node. */
10637 static inline unsigned HOST_WIDE_INT
10638 simple_type_size_in_bits (const_tree type
)
10640 if (TREE_CODE (type
) == ERROR_MARK
)
10641 return BITS_PER_WORD
;
10642 else if (TYPE_SIZE (type
) == NULL_TREE
)
10644 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
10645 return tree_to_uhwi (TYPE_SIZE (type
));
10647 return TYPE_ALIGN (type
);
10650 /* Similarly, but return an offset_int instead of UHWI. */
10652 static inline offset_int
10653 offset_int_type_size_in_bits (const_tree type
)
10655 if (TREE_CODE (type
) == ERROR_MARK
)
10656 return BITS_PER_WORD
;
10657 else if (TYPE_SIZE (type
) == NULL_TREE
)
10659 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10660 return wi::to_offset (TYPE_SIZE (type
));
10662 return TYPE_ALIGN (type
);
10665 /* Given a pointer to a tree node for a subrange type, return a pointer
10666 to a DIE that describes the given type. */
10669 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10671 dw_die_ref subrange_die
;
10672 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10674 if (context_die
== NULL
)
10675 context_die
= comp_unit_die ();
10677 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10679 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10681 /* The size of the subrange type and its base type do not match,
10682 so we need to generate a size attribute for the subrange type. */
10683 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10687 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
, NULL
);
10689 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
, NULL
);
10691 return subrange_die
;
10694 /* Returns the (const and/or volatile) cv_qualifiers associated with
10695 the decl node. This will normally be augmented with the
10696 cv_qualifiers of the underlying type in add_type_attribute. */
10699 decl_quals (const_tree decl
)
10701 return ((TREE_READONLY (decl
)
10702 ? TYPE_QUAL_CONST
: TYPE_UNQUALIFIED
)
10703 | (TREE_THIS_VOLATILE (decl
)
10704 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
));
10707 /* Determine the TYPE whose qualifiers match the largest strict subset
10708 of the given TYPE_QUALS, and return its qualifiers. Ignore all
10709 qualifiers outside QUAL_MASK. */
10712 get_nearest_type_subqualifiers (tree type
, int type_quals
, int qual_mask
)
10715 int best_rank
= 0, best_qual
= 0, max_rank
;
10717 type_quals
&= qual_mask
;
10718 max_rank
= popcount_hwi (type_quals
) - 1;
10720 for (t
= TYPE_MAIN_VARIANT (type
); t
&& best_rank
< max_rank
;
10721 t
= TYPE_NEXT_VARIANT (t
))
10723 int q
= TYPE_QUALS (t
) & qual_mask
;
10725 if ((q
& type_quals
) == q
&& q
!= type_quals
10726 && check_base_type (t
, type
))
10728 int rank
= popcount_hwi (q
);
10730 if (rank
> best_rank
)
10741 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10742 entry that chains various modifiers in front of the given type. */
10745 modified_type_die (tree type
, int cv_quals
, dw_die_ref context_die
)
10747 enum tree_code code
= TREE_CODE (type
);
10748 dw_die_ref mod_type_die
;
10749 dw_die_ref sub_die
= NULL
;
10750 tree item_type
= NULL
;
10751 tree qualified_type
;
10752 tree name
, low
, high
;
10753 dw_die_ref mod_scope
;
10754 /* Only these cv-qualifiers are currently handled. */
10755 const int cv_qual_mask
= (TYPE_QUAL_CONST
| TYPE_QUAL_VOLATILE
10756 | TYPE_QUAL_RESTRICT
| TYPE_QUAL_ATOMIC
);
10758 if (code
== ERROR_MARK
)
10761 cv_quals
&= cv_qual_mask
;
10763 /* Don't emit DW_TAG_restrict_type for DWARFv2, since it is a type
10764 tag modifier (and not an attribute) old consumers won't be able
10766 if (dwarf_version
< 3)
10767 cv_quals
&= ~TYPE_QUAL_RESTRICT
;
10769 /* Likewise for DW_TAG_atomic_type for DWARFv5. */
10770 if (dwarf_version
< 5)
10771 cv_quals
&= ~TYPE_QUAL_ATOMIC
;
10773 /* See if we already have the appropriately qualified variant of
10775 qualified_type
= get_qualified_type (type
, cv_quals
);
10777 if (qualified_type
== sizetype
10778 && TYPE_NAME (qualified_type
)
10779 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10781 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10783 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10784 && TYPE_PRECISION (t
)
10785 == TYPE_PRECISION (qualified_type
)
10786 && TYPE_UNSIGNED (t
)
10787 == TYPE_UNSIGNED (qualified_type
));
10788 qualified_type
= t
;
10791 /* If we do, then we can just use its DIE, if it exists. */
10792 if (qualified_type
)
10794 mod_type_die
= lookup_type_die (qualified_type
);
10796 return mod_type_die
;
10799 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10801 /* Handle C typedef types. */
10802 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10803 && !DECL_ARTIFICIAL (name
))
10805 tree dtype
= TREE_TYPE (name
);
10807 if (qualified_type
== dtype
)
10809 /* For a named type, use the typedef. */
10810 gen_type_die (qualified_type
, context_die
);
10811 return lookup_type_die (qualified_type
);
10815 int dquals
= TYPE_QUALS_NO_ADDR_SPACE (dtype
);
10816 dquals
&= cv_qual_mask
;
10817 if ((dquals
& ~cv_quals
) != TYPE_UNQUALIFIED
10818 || (cv_quals
== dquals
&& DECL_ORIGINAL_TYPE (name
) != type
))
10819 /* cv-unqualified version of named type. Just use
10820 the unnamed type to which it refers. */
10821 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10822 cv_quals
, context_die
);
10823 /* Else cv-qualified version of named type; fall through. */
10827 mod_scope
= scope_die_for (type
, context_die
);
10831 struct qual_info
{ int q
; enum dwarf_tag t
; };
10832 static const struct qual_info qual_info
[] =
10834 { TYPE_QUAL_ATOMIC
, DW_TAG_atomic_type
},
10835 { TYPE_QUAL_RESTRICT
, DW_TAG_restrict_type
},
10836 { TYPE_QUAL_VOLATILE
, DW_TAG_volatile_type
},
10837 { TYPE_QUAL_CONST
, DW_TAG_const_type
},
10842 /* Determine a lesser qualified type that most closely matches
10843 this one. Then generate DW_TAG_* entries for the remaining
10845 sub_quals
= get_nearest_type_subqualifiers (type
, cv_quals
,
10847 mod_type_die
= modified_type_die (type
, sub_quals
, context_die
);
10849 for (i
= 0; i
< sizeof (qual_info
) / sizeof (qual_info
[0]); i
++)
10850 if (qual_info
[i
].q
& cv_quals
& ~sub_quals
)
10852 dw_die_ref d
= new_die (qual_info
[i
].t
, mod_scope
, type
);
10854 add_AT_die_ref (d
, DW_AT_type
, mod_type_die
);
10858 else if (code
== POINTER_TYPE
)
10860 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10861 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10862 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10863 item_type
= TREE_TYPE (type
);
10864 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10865 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10866 TYPE_ADDR_SPACE (item_type
));
10868 else if (code
== REFERENCE_TYPE
)
10870 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10871 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10874 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10875 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10876 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10877 item_type
= TREE_TYPE (type
);
10878 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10879 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10880 TYPE_ADDR_SPACE (item_type
));
10882 else if (code
== INTEGER_TYPE
10883 && TREE_TYPE (type
) != NULL_TREE
10884 && subrange_type_for_debug_p (type
, &low
, &high
))
10886 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10887 item_type
= TREE_TYPE (type
);
10889 else if (is_base_type (type
))
10890 mod_type_die
= base_type_die (type
);
10893 gen_type_die (type
, context_die
);
10895 /* We have to get the type_main_variant here (and pass that to the
10896 `lookup_type_die' routine) because the ..._TYPE node we have
10897 might simply be a *copy* of some original type node (where the
10898 copy was created to help us keep track of typedef names) and
10899 that copy might have a different TYPE_UID from the original
10901 if (TREE_CODE (type
) != VECTOR_TYPE
)
10902 return lookup_type_die (type_main_variant (type
));
10904 /* Vectors have the debugging information in the type,
10905 not the main variant. */
10906 return lookup_type_die (type
);
10909 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10910 don't output a DW_TAG_typedef, since there isn't one in the
10911 user's program; just attach a DW_AT_name to the type.
10912 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10913 if the base type already has the same name. */
10915 && ((TREE_CODE (name
) != TYPE_DECL
10916 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10917 || (cv_quals
== TYPE_UNQUALIFIED
)))
10918 || (TREE_CODE (name
) == TYPE_DECL
10919 && TREE_TYPE (name
) == qualified_type
10920 && DECL_NAME (name
))))
10922 if (TREE_CODE (name
) == TYPE_DECL
)
10923 /* Could just call add_name_and_src_coords_attributes here,
10924 but since this is a builtin type it doesn't have any
10925 useful source coordinates anyway. */
10926 name
= DECL_NAME (name
);
10927 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10929 /* This probably indicates a bug. */
10930 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10932 name
= TYPE_IDENTIFIER (type
);
10933 add_name_attribute (mod_type_die
,
10934 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10937 if (qualified_type
)
10938 equate_type_number_to_die (qualified_type
, mod_type_die
);
10941 /* We must do this after the equate_type_number_to_die call, in case
10942 this is a recursive type. This ensures that the modified_type_die
10943 recursion will terminate even if the type is recursive. Recursive
10944 types are possible in Ada. */
10945 sub_die
= modified_type_die (item_type
,
10946 TYPE_QUALS_NO_ADDR_SPACE (item_type
),
10949 if (sub_die
!= NULL
)
10950 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10952 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10953 if (TYPE_ARTIFICIAL (type
))
10954 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10956 return mod_type_die
;
10959 /* Generate DIEs for the generic parameters of T.
10960 T must be either a generic type or a generic function.
10961 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10964 gen_generic_params_dies (tree t
)
10968 dw_die_ref die
= NULL
;
10971 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10975 die
= lookup_type_die (t
);
10976 else if (DECL_P (t
))
10977 die
= lookup_decl_die (t
);
10981 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10983 /* T has no generic parameter. It means T is neither a generic type
10984 or function. End of story. */
10987 parms_num
= TREE_VEC_LENGTH (parms
);
10988 args
= lang_hooks
.get_innermost_generic_args (t
);
10989 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10990 non_default
= int_cst_value (TREE_CHAIN (args
));
10992 non_default
= TREE_VEC_LENGTH (args
);
10993 for (i
= 0; i
< parms_num
; i
++)
10995 tree parm
, arg
, arg_pack_elems
;
10996 dw_die_ref parm_die
;
10998 parm
= TREE_VEC_ELT (parms
, i
);
10999 arg
= TREE_VEC_ELT (args
, i
);
11000 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
11001 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
11003 if (parm
&& TREE_VALUE (parm
) && arg
)
11005 /* If PARM represents a template parameter pack,
11006 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
11007 by DW_TAG_template_*_parameter DIEs for the argument
11008 pack elements of ARG. Note that ARG would then be
11009 an argument pack. */
11010 if (arg_pack_elems
)
11011 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
11015 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
11016 true /* emit name */, die
);
11017 if (i
>= non_default
)
11018 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
11023 /* Create and return a DIE for PARM which should be
11024 the representation of a generic type parameter.
11025 For instance, in the C++ front end, PARM would be a template parameter.
11026 ARG is the argument to PARM.
11027 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
11029 PARENT_DIE is the parent DIE which the new created DIE should be added to,
11030 as a child node. */
11033 generic_parameter_die (tree parm
, tree arg
,
11035 dw_die_ref parent_die
)
11037 dw_die_ref tmpl_die
= NULL
;
11038 const char *name
= NULL
;
11040 if (!parm
|| !DECL_NAME (parm
) || !arg
)
11043 /* We support non-type generic parameters and arguments,
11044 type generic parameters and arguments, as well as
11045 generic generic parameters (a.k.a. template template parameters in C++)
11047 if (TREE_CODE (parm
) == PARM_DECL
)
11048 /* PARM is a nontype generic parameter */
11049 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
11050 else if (TREE_CODE (parm
) == TYPE_DECL
)
11051 /* PARM is a type generic parameter. */
11052 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
11053 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11054 /* PARM is a generic generic parameter.
11055 Its DIE is a GNU extension. It shall have a
11056 DW_AT_name attribute to represent the name of the template template
11057 parameter, and a DW_AT_GNU_template_name attribute to represent the
11058 name of the template template argument. */
11059 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
11062 gcc_unreachable ();
11068 /* If PARM is a generic parameter pack, it means we are
11069 emitting debug info for a template argument pack element.
11070 In other terms, ARG is a template argument pack element.
11071 In that case, we don't emit any DW_AT_name attribute for
11075 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
11077 add_AT_string (tmpl_die
, DW_AT_name
, name
);
11080 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
11082 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
11083 TMPL_DIE should have a child DW_AT_type attribute that is set
11084 to the type of the argument to PARM, which is ARG.
11085 If PARM is a type generic parameter, TMPL_DIE should have a
11086 child DW_AT_type that is set to ARG. */
11087 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
11088 add_type_attribute (tmpl_die
, tmpl_type
,
11089 (TREE_THIS_VOLATILE (tmpl_type
)
11090 ? TYPE_QUAL_VOLATILE
: TYPE_UNQUALIFIED
),
11095 /* So TMPL_DIE is a DIE representing a
11096 a generic generic template parameter, a.k.a template template
11097 parameter in C++ and arg is a template. */
11099 /* The DW_AT_GNU_template_name attribute of the DIE must be set
11100 to the name of the argument. */
11101 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
11103 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
11106 if (TREE_CODE (parm
) == PARM_DECL
)
11107 /* So PARM is a non-type generic parameter.
11108 DWARF3 5.6.8 says we must set a DW_AT_const_value child
11109 attribute of TMPL_DIE which value represents the value
11111 We must be careful here:
11112 The value of ARG might reference some function decls.
11113 We might currently be emitting debug info for a generic
11114 type and types are emitted before function decls, we don't
11115 know if the function decls referenced by ARG will actually be
11116 emitted after cgraph computations.
11117 So must defer the generation of the DW_AT_const_value to
11118 after cgraph is ready. */
11119 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
11125 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
11126 PARM_PACK must be a template parameter pack. The returned DIE
11127 will be child DIE of PARENT_DIE. */
11130 template_parameter_pack_die (tree parm_pack
,
11131 tree parm_pack_args
,
11132 dw_die_ref parent_die
)
11137 gcc_assert (parent_die
&& parm_pack
);
11139 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
11140 add_name_and_src_coords_attributes (die
, parm_pack
);
11141 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
11142 generic_parameter_die (parm_pack
,
11143 TREE_VEC_ELT (parm_pack_args
, j
),
11144 false /* Don't emit DW_AT_name */,
11149 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
11150 an enumerated type. */
11153 type_is_enum (const_tree type
)
11155 return TREE_CODE (type
) == ENUMERAL_TYPE
;
11158 /* Return the DBX register number described by a given RTL node. */
11160 static unsigned int
11161 dbx_reg_number (const_rtx rtl
)
11163 unsigned regno
= REGNO (rtl
);
11165 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
11167 #ifdef LEAF_REG_REMAP
11168 if (crtl
->uses_only_leaf_regs
)
11170 int leaf_reg
= LEAF_REG_REMAP (regno
);
11171 if (leaf_reg
!= -1)
11172 regno
= (unsigned) leaf_reg
;
11176 regno
= DBX_REGISTER_NUMBER (regno
);
11177 gcc_assert (regno
!= INVALID_REGNUM
);
11181 /* Optionally add a DW_OP_piece term to a location description expression.
11182 DW_OP_piece is only added if the location description expression already
11183 doesn't end with DW_OP_piece. */
11186 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
11188 dw_loc_descr_ref loc
;
11190 if (*list_head
!= NULL
)
11192 /* Find the end of the chain. */
11193 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
11196 if (loc
->dw_loc_opc
!= DW_OP_piece
)
11197 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
11201 /* Return a location descriptor that designates a machine register or
11202 zero if there is none. */
11204 static dw_loc_descr_ref
11205 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
11209 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
11212 /* We only use "frame base" when we're sure we're talking about the
11213 post-prologue local stack frame. We do this by *not* running
11214 register elimination until this point, and recognizing the special
11215 argument pointer and soft frame pointer rtx's.
11216 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
11217 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
11218 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
11220 dw_loc_descr_ref result
= NULL
;
11222 if (dwarf_version
>= 4 || !dwarf_strict
)
11224 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
11227 add_loc_descr (&result
,
11228 new_loc_descr (DW_OP_stack_value
, 0, 0));
11233 regs
= targetm
.dwarf_register_span (rtl
);
11235 if (REG_NREGS (rtl
) > 1 || regs
)
11236 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
11239 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
11240 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11242 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
11246 /* Return a location descriptor that designates a machine register for
11247 a given hard register number. */
11249 static dw_loc_descr_ref
11250 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
11252 dw_loc_descr_ref reg_loc_descr
;
11256 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
11258 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
11260 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11261 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11263 return reg_loc_descr
;
11266 /* Given an RTL of a register, return a location descriptor that
11267 designates a value that spans more than one register. */
11269 static dw_loc_descr_ref
11270 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
11271 enum var_init_status initialized
)
11274 dw_loc_descr_ref loc_result
= NULL
;
11276 /* Simple, contiguous registers. */
11277 if (regs
== NULL_RTX
)
11279 unsigned reg
= REGNO (rtl
);
11282 #ifdef LEAF_REG_REMAP
11283 if (crtl
->uses_only_leaf_regs
)
11285 int leaf_reg
= LEAF_REG_REMAP (reg
);
11286 if (leaf_reg
!= -1)
11287 reg
= (unsigned) leaf_reg
;
11291 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
11292 nregs
= REG_NREGS (rtl
);
11294 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
11299 dw_loc_descr_ref t
;
11301 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
11302 VAR_INIT_STATUS_INITIALIZED
);
11303 add_loc_descr (&loc_result
, t
);
11304 add_loc_descr_op_piece (&loc_result
, size
);
11310 /* Now onto stupid register sets in non contiguous locations. */
11312 gcc_assert (GET_CODE (regs
) == PARALLEL
);
11314 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
11317 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
11319 dw_loc_descr_ref t
;
11321 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
11322 VAR_INIT_STATUS_INITIALIZED
);
11323 add_loc_descr (&loc_result
, t
);
11324 add_loc_descr_op_piece (&loc_result
, size
);
11327 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11328 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11332 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
11334 /* Return a location descriptor that designates a constant i,
11335 as a compound operation from constant (i >> shift), constant shift
11338 static dw_loc_descr_ref
11339 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11341 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
11342 add_loc_descr (&ret
, int_loc_descriptor (shift
));
11343 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11347 /* Return a location descriptor that designates a constant. */
11349 static dw_loc_descr_ref
11350 int_loc_descriptor (HOST_WIDE_INT i
)
11352 enum dwarf_location_atom op
;
11354 /* Pick the smallest representation of a constant, rather than just
11355 defaulting to the LEB encoding. */
11358 int clz
= clz_hwi (i
);
11359 int ctz
= ctz_hwi (i
);
11361 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
11362 else if (i
<= 0xff)
11363 op
= DW_OP_const1u
;
11364 else if (i
<= 0xffff)
11365 op
= DW_OP_const2u
;
11366 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11367 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11368 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11369 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11370 while DW_OP_const4u is 5 bytes. */
11371 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
11372 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11373 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11374 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11375 while DW_OP_const4u is 5 bytes. */
11376 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11377 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11378 op
= DW_OP_const4u
;
11379 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11380 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11381 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11382 while DW_OP_constu of constant >= 0x100000000 takes at least
11384 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11385 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11386 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
11387 >= HOST_BITS_PER_WIDE_INT
)
11388 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11389 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11390 while DW_OP_constu takes in this case at least 6 bytes. */
11391 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
11392 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11393 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11394 && size_of_uleb128 (i
) > 6)
11395 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11396 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11403 op
= DW_OP_const1s
;
11404 else if (i
>= -0x8000)
11405 op
= DW_OP_const2s
;
11406 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11408 if (size_of_int_loc_descriptor (i
) < 5)
11410 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11411 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11414 op
= DW_OP_const4s
;
11418 if (size_of_int_loc_descriptor (i
)
11419 < (unsigned long) 1 + size_of_sleb128 (i
))
11421 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11422 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11429 return new_loc_descr (op
, i
, 0);
11432 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
11433 without actually allocating it. */
11435 static unsigned long
11436 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11438 return size_of_int_loc_descriptor (i
>> shift
)
11439 + size_of_int_loc_descriptor (shift
)
11443 /* Return size_of_locs (int_loc_descriptor (i)) without
11444 actually allocating it. */
11446 static unsigned long
11447 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11456 else if (i
<= 0xff)
11458 else if (i
<= 0xffff)
11462 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11463 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11464 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11466 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11467 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11468 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11470 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11472 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11473 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11474 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11475 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11477 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11478 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11479 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11481 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11482 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11484 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11493 else if (i
>= -0x8000)
11495 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11497 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11499 s
= size_of_int_loc_descriptor (-i
) + 1;
11507 unsigned long r
= 1 + size_of_sleb128 (i
);
11508 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11510 s
= size_of_int_loc_descriptor (-i
) + 1;
11519 /* Return loc description representing "address" of integer value.
11520 This can appear only as toplevel expression. */
11522 static dw_loc_descr_ref
11523 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11526 dw_loc_descr_ref loc_result
= NULL
;
11528 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11531 litsize
= size_of_int_loc_descriptor (i
);
11532 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11533 is more compact. For DW_OP_stack_value we need:
11534 litsize + 1 (DW_OP_stack_value)
11535 and for DW_OP_implicit_value:
11536 1 (DW_OP_implicit_value) + 1 (length) + size. */
11537 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11539 loc_result
= int_loc_descriptor (i
);
11540 add_loc_descr (&loc_result
,
11541 new_loc_descr (DW_OP_stack_value
, 0, 0));
11545 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11547 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11548 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11552 /* Return a location descriptor that designates a base+offset location. */
11554 static dw_loc_descr_ref
11555 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11556 enum var_init_status initialized
)
11558 unsigned int regno
;
11559 dw_loc_descr_ref result
;
11560 dw_fde_ref fde
= cfun
->fde
;
11562 /* We only use "frame base" when we're sure we're talking about the
11563 post-prologue local stack frame. We do this by *not* running
11564 register elimination until this point, and recognizing the special
11565 argument pointer and soft frame pointer rtx's. */
11566 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11568 rtx elim
= (ira_use_lra_p
11569 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11570 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11574 if (GET_CODE (elim
) == PLUS
)
11576 offset
+= INTVAL (XEXP (elim
, 1));
11577 elim
= XEXP (elim
, 0);
11579 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11580 && (elim
== hard_frame_pointer_rtx
11581 || elim
== stack_pointer_rtx
))
11582 || elim
== (frame_pointer_needed
11583 ? hard_frame_pointer_rtx
11584 : stack_pointer_rtx
));
11586 /* If drap register is used to align stack, use frame
11587 pointer + offset to access stack variables. If stack
11588 is aligned without drap, use stack pointer + offset to
11589 access stack variables. */
11590 if (crtl
->stack_realign_tried
11591 && reg
== frame_pointer_rtx
)
11594 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11595 ? HARD_FRAME_POINTER_REGNUM
11597 return new_reg_loc_descr (base_reg
, offset
);
11600 gcc_assert (frame_pointer_fb_offset_valid
);
11601 offset
+= frame_pointer_fb_offset
;
11602 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11606 regno
= REGNO (reg
);
11607 #ifdef LEAF_REG_REMAP
11608 if (crtl
->uses_only_leaf_regs
)
11610 int leaf_reg
= LEAF_REG_REMAP (regno
);
11611 if (leaf_reg
!= -1)
11612 regno
= (unsigned) leaf_reg
;
11615 regno
= DWARF_FRAME_REGNUM (regno
);
11617 if (!optimize
&& fde
11618 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11620 /* Use cfa+offset to represent the location of arguments passed
11621 on the stack when drap is used to align stack.
11622 Only do this when not optimizing, for optimized code var-tracking
11623 is supposed to track where the arguments live and the register
11624 used as vdrap or drap in some spot might be used for something
11625 else in other part of the routine. */
11626 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11630 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11633 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11635 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11636 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11641 /* Return true if this RTL expression describes a base+offset calculation. */
11644 is_based_loc (const_rtx rtl
)
11646 return (GET_CODE (rtl
) == PLUS
11647 && ((REG_P (XEXP (rtl
, 0))
11648 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11649 && CONST_INT_P (XEXP (rtl
, 1)))));
11652 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11655 static dw_loc_descr_ref
11656 tls_mem_loc_descriptor (rtx mem
)
11659 dw_loc_descr_ref loc_result
;
11661 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11664 base
= get_base_address (MEM_EXPR (mem
));
11666 || TREE_CODE (base
) != VAR_DECL
11667 || !DECL_THREAD_LOCAL_P (base
))
11670 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1, NULL
);
11671 if (loc_result
== NULL
)
11674 if (MEM_OFFSET (mem
))
11675 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11680 /* Output debug info about reason why we failed to expand expression as dwarf
11684 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11686 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11688 fprintf (dump_file
, "Failed to expand as dwarf: ");
11690 print_generic_expr (dump_file
, expr
, dump_flags
);
11693 fprintf (dump_file
, "\n");
11694 print_rtl (dump_file
, rtl
);
11696 fprintf (dump_file
, "\nReason: %s\n", reason
);
11700 /* Helper function for const_ok_for_output. */
11703 const_ok_for_output_1 (rtx rtl
)
11705 if (GET_CODE (rtl
) == UNSPEC
)
11707 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11708 we can't express it in the debug info. */
11709 #ifdef ENABLE_CHECKING
11710 /* Don't complain about TLS UNSPECs, those are just too hard to
11711 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11712 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11713 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11714 if (XVECLEN (rtl
, 0) == 0
11715 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11716 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11717 inform (current_function_decl
11718 ? DECL_SOURCE_LOCATION (current_function_decl
)
11719 : UNKNOWN_LOCATION
,
11720 #if NUM_UNSPEC_VALUES > 0
11721 "non-delegitimized UNSPEC %s (%d) found in variable location",
11722 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11723 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11726 "non-delegitimized UNSPEC %d found in variable location",
11730 expansion_failed (NULL_TREE
, rtl
,
11731 "UNSPEC hasn't been delegitimized.\n");
11735 if (targetm
.const_not_ok_for_debug_p (rtl
))
11737 expansion_failed (NULL_TREE
, rtl
,
11738 "Expression rejected for debug by the backend.\n");
11742 /* FIXME: Refer to PR60655. It is possible for simplification
11743 of rtl expressions in var tracking to produce such expressions.
11744 We should really identify / validate expressions
11745 enclosed in CONST that can be handled by assemblers on various
11746 targets and only handle legitimate cases here. */
11747 if (GET_CODE (rtl
) != SYMBOL_REF
)
11749 if (GET_CODE (rtl
) == NOT
)
11754 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11757 get_pool_constant_mark (rtl
, &marked
);
11758 /* If all references to this pool constant were optimized away,
11759 it was not output and thus we can't represent it. */
11762 expansion_failed (NULL_TREE
, rtl
,
11763 "Constant was removed from constant pool.\n");
11768 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11771 /* Avoid references to external symbols in debug info, on several targets
11772 the linker might even refuse to link when linking a shared library,
11773 and in many other cases the relocations for .debug_info/.debug_loc are
11774 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11775 to be defined within the same shared library or executable are fine. */
11776 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11778 tree decl
= SYMBOL_REF_DECL (rtl
);
11780 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11782 expansion_failed (NULL_TREE
, rtl
,
11783 "Symbol not defined in current TU.\n");
11791 /* Return true if constant RTL can be emitted in DW_OP_addr or
11792 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11793 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11796 const_ok_for_output (rtx rtl
)
11798 if (GET_CODE (rtl
) == SYMBOL_REF
)
11799 return const_ok_for_output_1 (rtl
);
11801 if (GET_CODE (rtl
) == CONST
)
11803 subrtx_var_iterator::array_type array
;
11804 FOR_EACH_SUBRTX_VAR (iter
, array
, XEXP (rtl
, 0), ALL
)
11805 if (!const_ok_for_output_1 (*iter
))
11813 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11814 if possible, NULL otherwise. */
11817 base_type_for_mode (machine_mode mode
, bool unsignedp
)
11819 dw_die_ref type_die
;
11820 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11824 switch (TREE_CODE (type
))
11832 type_die
= lookup_type_die (type
);
11834 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, comp_unit_die ());
11835 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11840 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11841 type matching MODE, or, if MODE is narrower than or as wide as
11842 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11845 static dw_loc_descr_ref
11846 convert_descriptor_to_mode (machine_mode mode
, dw_loc_descr_ref op
)
11848 machine_mode outer_mode
= mode
;
11849 dw_die_ref type_die
;
11850 dw_loc_descr_ref cvt
;
11852 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11854 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11857 type_die
= base_type_for_mode (outer_mode
, 1);
11858 if (type_die
== NULL
)
11860 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11861 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11862 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11863 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11864 add_loc_descr (&op
, cvt
);
11868 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11870 static dw_loc_descr_ref
11871 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11872 dw_loc_descr_ref op1
)
11874 dw_loc_descr_ref ret
= op0
;
11875 add_loc_descr (&ret
, op1
);
11876 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11877 if (STORE_FLAG_VALUE
!= 1)
11879 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11880 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11885 /* Return location descriptor for signed comparison OP RTL. */
11887 static dw_loc_descr_ref
11888 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11889 machine_mode mem_mode
)
11891 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11892 dw_loc_descr_ref op0
, op1
;
11895 if (op_mode
== VOIDmode
)
11896 op_mode
= GET_MODE (XEXP (rtl
, 1));
11897 if (op_mode
== VOIDmode
)
11901 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11902 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11905 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11906 VAR_INIT_STATUS_INITIALIZED
);
11907 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11908 VAR_INIT_STATUS_INITIALIZED
);
11910 if (op0
== NULL
|| op1
== NULL
)
11913 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11914 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11915 return compare_loc_descriptor (op
, op0
, op1
);
11917 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11919 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11920 dw_loc_descr_ref cvt
;
11922 if (type_die
== NULL
)
11924 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11925 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11926 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11927 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11928 add_loc_descr (&op0
, cvt
);
11929 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11930 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11931 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11932 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11933 add_loc_descr (&op1
, cvt
);
11934 return compare_loc_descriptor (op
, op0
, op1
);
11937 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11938 /* For eq/ne, if the operands are known to be zero-extended,
11939 there is no need to do the fancy shifting up. */
11940 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11942 dw_loc_descr_ref last0
, last1
;
11943 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11945 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11947 /* deref_size zero extends, and for constants we can check
11948 whether they are zero extended or not. */
11949 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11950 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11951 || (CONST_INT_P (XEXP (rtl
, 0))
11952 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11953 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11954 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11955 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11956 || (CONST_INT_P (XEXP (rtl
, 1))
11957 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11958 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11959 return compare_loc_descriptor (op
, op0
, op1
);
11961 /* EQ/NE comparison against constant in narrower type than
11962 DWARF2_ADDR_SIZE can be performed either as
11963 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11966 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11967 DW_OP_{eq,ne}. Pick whatever is shorter. */
11968 if (CONST_INT_P (XEXP (rtl
, 1))
11969 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11970 && (size_of_int_loc_descriptor (shift
) + 1
11971 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11972 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11973 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11974 & GET_MODE_MASK (op_mode
))))
11976 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11977 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11978 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11979 & GET_MODE_MASK (op_mode
));
11980 return compare_loc_descriptor (op
, op0
, op1
);
11983 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11984 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11985 if (CONST_INT_P (XEXP (rtl
, 1)))
11986 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11989 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11990 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11992 return compare_loc_descriptor (op
, op0
, op1
);
11995 /* Return location descriptor for unsigned comparison OP RTL. */
11997 static dw_loc_descr_ref
11998 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11999 machine_mode mem_mode
)
12001 machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
12002 dw_loc_descr_ref op0
, op1
;
12004 if (op_mode
== VOIDmode
)
12005 op_mode
= GET_MODE (XEXP (rtl
, 1));
12006 if (op_mode
== VOIDmode
)
12008 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
12011 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
12014 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
12015 VAR_INIT_STATUS_INITIALIZED
);
12016 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
12017 VAR_INIT_STATUS_INITIALIZED
);
12019 if (op0
== NULL
|| op1
== NULL
)
12022 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
12024 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
12025 dw_loc_descr_ref last0
, last1
;
12026 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
12028 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
12030 if (CONST_INT_P (XEXP (rtl
, 0)))
12031 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
12032 /* deref_size zero extends, so no need to mask it again. */
12033 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
12034 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12036 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12037 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12039 if (CONST_INT_P (XEXP (rtl
, 1)))
12040 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
12041 /* deref_size zero extends, so no need to mask it again. */
12042 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
12043 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
12045 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12046 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12049 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
12051 HOST_WIDE_INT bias
= 1;
12052 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12053 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12054 if (CONST_INT_P (XEXP (rtl
, 1)))
12055 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
12056 + INTVAL (XEXP (rtl
, 1)));
12058 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
12061 return compare_loc_descriptor (op
, op0
, op1
);
12064 /* Return location descriptor for {U,S}{MIN,MAX}. */
12066 static dw_loc_descr_ref
12067 minmax_loc_descriptor (rtx rtl
, machine_mode mode
,
12068 machine_mode mem_mode
)
12070 enum dwarf_location_atom op
;
12071 dw_loc_descr_ref op0
, op1
, ret
;
12072 dw_loc_descr_ref bra_node
, drop_node
;
12075 && (GET_MODE_CLASS (mode
) != MODE_INT
12076 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
12079 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12080 VAR_INIT_STATUS_INITIALIZED
);
12081 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12082 VAR_INIT_STATUS_INITIALIZED
);
12084 if (op0
== NULL
|| op1
== NULL
)
12087 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
12088 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
12089 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
12090 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
12092 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12094 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
12095 add_loc_descr (&op0
, int_loc_descriptor (mask
));
12096 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
12097 add_loc_descr (&op1
, int_loc_descriptor (mask
));
12098 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
12100 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12102 HOST_WIDE_INT bias
= 1;
12103 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
12104 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12105 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
12108 else if (GET_MODE_CLASS (mode
) == MODE_INT
12109 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12111 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
12112 add_loc_descr (&op0
, int_loc_descriptor (shift
));
12113 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
12114 add_loc_descr (&op1
, int_loc_descriptor (shift
));
12115 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
12117 else if (GET_MODE_CLASS (mode
) == MODE_INT
12118 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12120 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
12121 dw_loc_descr_ref cvt
;
12122 if (type_die
== NULL
)
12124 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12125 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12126 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12127 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12128 add_loc_descr (&op0
, cvt
);
12129 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12130 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12131 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12132 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12133 add_loc_descr (&op1
, cvt
);
12136 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
12141 add_loc_descr (&ret
, op1
);
12142 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
12143 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12144 add_loc_descr (&ret
, bra_node
);
12145 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12146 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12147 add_loc_descr (&ret
, drop_node
);
12148 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12149 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12150 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
12151 && GET_MODE_CLASS (mode
) == MODE_INT
12152 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12153 ret
= convert_descriptor_to_mode (mode
, ret
);
12157 /* Helper function for mem_loc_descriptor. Perform OP binary op,
12158 but after converting arguments to type_die, afterwards
12159 convert back to unsigned. */
12161 static dw_loc_descr_ref
12162 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
12163 machine_mode mode
, machine_mode mem_mode
)
12165 dw_loc_descr_ref cvt
, op0
, op1
;
12167 if (type_die
== NULL
)
12169 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12170 VAR_INIT_STATUS_INITIALIZED
);
12171 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12172 VAR_INIT_STATUS_INITIALIZED
);
12173 if (op0
== NULL
|| op1
== NULL
)
12175 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12176 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12177 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12178 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12179 add_loc_descr (&op0
, cvt
);
12180 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12181 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12182 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12183 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12184 add_loc_descr (&op1
, cvt
);
12185 add_loc_descr (&op0
, op1
);
12186 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
12187 return convert_descriptor_to_mode (mode
, op0
);
12190 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
12191 const0 is DW_OP_lit0 or corresponding typed constant,
12192 const1 is DW_OP_lit1 or corresponding typed constant
12193 and constMSB is constant with just the MSB bit set
12195 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12196 L1: const0 DW_OP_swap
12197 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
12198 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12203 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
12204 L1: const0 DW_OP_swap
12205 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12206 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12211 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
12212 L1: const1 DW_OP_swap
12213 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
12214 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
12218 static dw_loc_descr_ref
12219 clz_loc_descriptor (rtx rtl
, machine_mode mode
,
12220 machine_mode mem_mode
)
12222 dw_loc_descr_ref op0
, ret
, tmp
;
12223 HOST_WIDE_INT valv
;
12224 dw_loc_descr_ref l1jump
, l1label
;
12225 dw_loc_descr_ref l2jump
, l2label
;
12226 dw_loc_descr_ref l3jump
, l3label
;
12227 dw_loc_descr_ref l4jump
, l4label
;
12230 if (GET_MODE_CLASS (mode
) != MODE_INT
12231 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12234 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12235 VAR_INIT_STATUS_INITIALIZED
);
12239 if (GET_CODE (rtl
) == CLZ
)
12241 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12242 valv
= GET_MODE_BITSIZE (mode
);
12244 else if (GET_CODE (rtl
) == FFS
)
12246 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
12247 valv
= GET_MODE_BITSIZE (mode
);
12248 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12249 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12250 add_loc_descr (&ret
, l1jump
);
12251 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12252 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
12253 VAR_INIT_STATUS_INITIALIZED
);
12256 add_loc_descr (&ret
, tmp
);
12257 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12258 add_loc_descr (&ret
, l4jump
);
12259 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
12260 ? const1_rtx
: const0_rtx
,
12262 VAR_INIT_STATUS_INITIALIZED
);
12263 if (l1label
== NULL
)
12265 add_loc_descr (&ret
, l1label
);
12266 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12267 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
12268 add_loc_descr (&ret
, l2label
);
12269 if (GET_CODE (rtl
) != CLZ
)
12271 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
12272 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
12273 << (GET_MODE_BITSIZE (mode
) - 1));
12275 msb
= immed_wide_int_const
12276 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
12277 GET_MODE_PRECISION (mode
)), mode
);
12278 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
12279 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12280 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
12281 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
12283 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
12284 VAR_INIT_STATUS_INITIALIZED
);
12287 add_loc_descr (&ret
, tmp
);
12288 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12289 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12290 add_loc_descr (&ret
, l3jump
);
12291 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12292 VAR_INIT_STATUS_INITIALIZED
);
12295 add_loc_descr (&ret
, tmp
);
12296 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
12297 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
12298 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12299 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
12300 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12301 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12302 add_loc_descr (&ret
, l2jump
);
12303 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
12304 add_loc_descr (&ret
, l3label
);
12305 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
12306 add_loc_descr (&ret
, l4label
);
12307 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12308 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12309 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12310 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12311 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12312 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
12313 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12314 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
12318 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
12319 const1 is DW_OP_lit1 or corresponding typed constant):
12321 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12322 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12326 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12327 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12330 static dw_loc_descr_ref
12331 popcount_loc_descriptor (rtx rtl
, machine_mode mode
,
12332 machine_mode mem_mode
)
12334 dw_loc_descr_ref op0
, ret
, tmp
;
12335 dw_loc_descr_ref l1jump
, l1label
;
12336 dw_loc_descr_ref l2jump
, l2label
;
12338 if (GET_MODE_CLASS (mode
) != MODE_INT
12339 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12342 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12343 VAR_INIT_STATUS_INITIALIZED
);
12347 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12348 VAR_INIT_STATUS_INITIALIZED
);
12351 add_loc_descr (&ret
, tmp
);
12352 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12353 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
12354 add_loc_descr (&ret
, l1label
);
12355 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12356 add_loc_descr (&ret
, l2jump
);
12357 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12358 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12359 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12360 VAR_INIT_STATUS_INITIALIZED
);
12363 add_loc_descr (&ret
, tmp
);
12364 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12365 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
12366 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
12367 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12368 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12369 VAR_INIT_STATUS_INITIALIZED
);
12370 add_loc_descr (&ret
, tmp
);
12371 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12372 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12373 add_loc_descr (&ret
, l1jump
);
12374 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12375 add_loc_descr (&ret
, l2label
);
12376 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12377 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12378 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12379 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12383 /* BSWAP (constS is initial shift count, either 56 or 24):
12385 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
12386 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
12387 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
12388 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
12389 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
12391 static dw_loc_descr_ref
12392 bswap_loc_descriptor (rtx rtl
, machine_mode mode
,
12393 machine_mode mem_mode
)
12395 dw_loc_descr_ref op0
, ret
, tmp
;
12396 dw_loc_descr_ref l1jump
, l1label
;
12397 dw_loc_descr_ref l2jump
, l2label
;
12399 if (GET_MODE_CLASS (mode
) != MODE_INT
12400 || BITS_PER_UNIT
!= 8
12401 || (GET_MODE_BITSIZE (mode
) != 32
12402 && GET_MODE_BITSIZE (mode
) != 64))
12405 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12406 VAR_INIT_STATUS_INITIALIZED
);
12411 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12413 VAR_INIT_STATUS_INITIALIZED
);
12416 add_loc_descr (&ret
, tmp
);
12417 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12418 VAR_INIT_STATUS_INITIALIZED
);
12421 add_loc_descr (&ret
, tmp
);
12422 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
12423 add_loc_descr (&ret
, l1label
);
12424 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12426 VAR_INIT_STATUS_INITIALIZED
);
12427 add_loc_descr (&ret
, tmp
);
12428 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
12429 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12430 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12431 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
12432 VAR_INIT_STATUS_INITIALIZED
);
12435 add_loc_descr (&ret
, tmp
);
12436 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12437 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
12438 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12439 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12440 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12441 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12442 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12443 VAR_INIT_STATUS_INITIALIZED
);
12444 add_loc_descr (&ret
, tmp
);
12445 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
12446 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12447 add_loc_descr (&ret
, l2jump
);
12448 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
12449 VAR_INIT_STATUS_INITIALIZED
);
12450 add_loc_descr (&ret
, tmp
);
12451 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12452 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12453 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12454 add_loc_descr (&ret
, l1jump
);
12455 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12456 add_loc_descr (&ret
, l2label
);
12457 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12458 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12459 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12460 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12461 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12462 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12466 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12467 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12468 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12469 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12471 ROTATERT is similar:
12472 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12473 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12474 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12476 static dw_loc_descr_ref
12477 rotate_loc_descriptor (rtx rtl
, machine_mode mode
,
12478 machine_mode mem_mode
)
12480 rtx rtlop1
= XEXP (rtl
, 1);
12481 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12484 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12487 if (GET_MODE (rtlop1
) != VOIDmode
12488 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12489 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12490 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12491 VAR_INIT_STATUS_INITIALIZED
);
12492 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12493 VAR_INIT_STATUS_INITIALIZED
);
12494 if (op0
== NULL
|| op1
== NULL
)
12496 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12497 for (i
= 0; i
< 2; i
++)
12499 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12500 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12502 VAR_INIT_STATUS_INITIALIZED
);
12503 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12504 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12506 : HOST_BITS_PER_WIDE_INT
== 64
12507 ? DW_OP_const8u
: DW_OP_constu
,
12508 GET_MODE_MASK (mode
), 0);
12511 if (mask
[i
] == NULL
)
12513 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12516 add_loc_descr (&ret
, op1
);
12517 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12518 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12519 if (GET_CODE (rtl
) == ROTATERT
)
12521 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12522 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12523 GET_MODE_BITSIZE (mode
), 0));
12525 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12526 if (mask
[0] != NULL
)
12527 add_loc_descr (&ret
, mask
[0]);
12528 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12529 if (mask
[1] != NULL
)
12531 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12532 add_loc_descr (&ret
, mask
[1]);
12533 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12535 if (GET_CODE (rtl
) == ROTATE
)
12537 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12538 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12539 GET_MODE_BITSIZE (mode
), 0));
12541 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12542 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12546 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12547 for DEBUG_PARAMETER_REF RTL. */
12549 static dw_loc_descr_ref
12550 parameter_ref_descriptor (rtx rtl
)
12552 dw_loc_descr_ref ret
;
12557 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12558 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12559 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12562 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12563 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12564 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12568 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12569 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12574 /* The following routine converts the RTL for a variable or parameter
12575 (resident in memory) into an equivalent Dwarf representation of a
12576 mechanism for getting the address of that same variable onto the top of a
12577 hypothetical "address evaluation" stack.
12579 When creating memory location descriptors, we are effectively transforming
12580 the RTL for a memory-resident object into its Dwarf postfix expression
12581 equivalent. This routine recursively descends an RTL tree, turning
12582 it into Dwarf postfix code as it goes.
12584 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12586 MEM_MODE is the mode of the memory reference, needed to handle some
12587 autoincrement addressing modes.
12589 Return 0 if we can't represent the location. */
12592 mem_loc_descriptor (rtx rtl
, machine_mode mode
,
12593 machine_mode mem_mode
,
12594 enum var_init_status initialized
)
12596 dw_loc_descr_ref mem_loc_result
= NULL
;
12597 enum dwarf_location_atom op
;
12598 dw_loc_descr_ref op0
, op1
;
12599 rtx inner
= NULL_RTX
;
12601 if (mode
== VOIDmode
)
12602 mode
= GET_MODE (rtl
);
12604 /* Note that for a dynamically sized array, the location we will generate a
12605 description of here will be the lowest numbered location which is
12606 actually within the array. That's *not* necessarily the same as the
12607 zeroth element of the array. */
12609 rtl
= targetm
.delegitimize_address (rtl
);
12611 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12614 switch (GET_CODE (rtl
))
12619 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12622 /* The case of a subreg may arise when we have a local (register)
12623 variable or a formal (register) parameter which doesn't quite fill
12624 up an entire register. For now, just assume that it is
12625 legitimate to make the Dwarf info refer to the whole register which
12626 contains the given subreg. */
12627 if (!subreg_lowpart_p (rtl
))
12629 inner
= SUBREG_REG (rtl
);
12631 if (inner
== NULL_RTX
)
12632 inner
= XEXP (rtl
, 0);
12633 if (GET_MODE_CLASS (mode
) == MODE_INT
12634 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12635 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12636 #ifdef POINTERS_EXTEND_UNSIGNED
12637 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12640 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12642 mem_loc_result
= mem_loc_descriptor (inner
,
12644 mem_mode
, initialized
);
12649 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12651 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12652 && (GET_MODE_CLASS (mode
) != MODE_INT
12653 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12657 dw_die_ref type_die
;
12658 dw_loc_descr_ref cvt
;
12660 mem_loc_result
= mem_loc_descriptor (inner
,
12662 mem_mode
, initialized
);
12663 if (mem_loc_result
== NULL
)
12665 type_die
= base_type_for_mode (mode
,
12666 GET_MODE_CLASS (mode
) == MODE_INT
);
12667 if (type_die
== NULL
)
12669 mem_loc_result
= NULL
;
12672 if (GET_MODE_SIZE (mode
)
12673 != GET_MODE_SIZE (GET_MODE (inner
)))
12674 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12676 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12677 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12678 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12679 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12680 add_loc_descr (&mem_loc_result
, cvt
);
12685 if (GET_MODE_CLASS (mode
) != MODE_INT
12686 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12687 && rtl
!= arg_pointer_rtx
12688 && rtl
!= frame_pointer_rtx
12689 #ifdef POINTERS_EXTEND_UNSIGNED
12690 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12694 dw_die_ref type_die
;
12695 unsigned int dbx_regnum
;
12699 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12701 type_die
= base_type_for_mode (mode
,
12702 GET_MODE_CLASS (mode
) == MODE_INT
);
12703 if (type_die
== NULL
)
12706 dbx_regnum
= dbx_reg_number (rtl
);
12707 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12709 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12711 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12712 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12713 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12716 /* Whenever a register number forms a part of the description of the
12717 method for calculating the (dynamic) address of a memory resident
12718 object, DWARF rules require the register number be referred to as
12719 a "base register". This distinction is not based in any way upon
12720 what category of register the hardware believes the given register
12721 belongs to. This is strictly DWARF terminology we're dealing with
12722 here. Note that in cases where the location of a memory-resident
12723 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12724 OP_CONST (0)) the actual DWARF location descriptor that we generate
12725 may just be OP_BASEREG (basereg). This may look deceptively like
12726 the object in question was allocated to a register (rather than in
12727 memory) so DWARF consumers need to be aware of the subtle
12728 distinction between OP_REG and OP_BASEREG. */
12729 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12730 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12731 else if (stack_realign_drap
12733 && crtl
->args
.internal_arg_pointer
== rtl
12734 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12736 /* If RTL is internal_arg_pointer, which has been optimized
12737 out, use DRAP instead. */
12738 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12739 VAR_INIT_STATUS_INITIALIZED
);
12745 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12747 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12748 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12751 else if (GET_CODE (rtl
) == ZERO_EXTEND
12752 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12753 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12754 < HOST_BITS_PER_WIDE_INT
12755 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12756 to expand zero extend as two shifts instead of
12758 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12760 machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12761 mem_loc_result
= op0
;
12762 add_loc_descr (&mem_loc_result
,
12763 int_loc_descriptor (GET_MODE_MASK (imode
)));
12764 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12766 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12768 int shift
= DWARF2_ADDR_SIZE
12769 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12770 shift
*= BITS_PER_UNIT
;
12771 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12775 mem_loc_result
= op0
;
12776 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12777 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12778 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12779 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12781 else if (!dwarf_strict
)
12783 dw_die_ref type_die1
, type_die2
;
12784 dw_loc_descr_ref cvt
;
12786 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12787 GET_CODE (rtl
) == ZERO_EXTEND
);
12788 if (type_die1
== NULL
)
12790 type_die2
= base_type_for_mode (mode
, 1);
12791 if (type_die2
== NULL
)
12793 mem_loc_result
= op0
;
12794 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12795 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12796 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12797 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12798 add_loc_descr (&mem_loc_result
, cvt
);
12799 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12800 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12801 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12802 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12803 add_loc_descr (&mem_loc_result
, cvt
);
12809 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12810 if (new_rtl
!= rtl
)
12812 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12814 if (mem_loc_result
!= NULL
)
12815 return mem_loc_result
;
12818 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12819 get_address_mode (rtl
), mode
,
12820 VAR_INIT_STATUS_INITIALIZED
);
12821 if (mem_loc_result
== NULL
)
12822 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12823 if (mem_loc_result
!= NULL
)
12825 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12826 || GET_MODE_CLASS (mode
) != MODE_INT
)
12828 dw_die_ref type_die
;
12829 dw_loc_descr_ref deref
;
12834 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12835 if (type_die
== NULL
)
12837 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12838 GET_MODE_SIZE (mode
), 0);
12839 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12840 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12841 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12842 add_loc_descr (&mem_loc_result
, deref
);
12844 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12845 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12847 add_loc_descr (&mem_loc_result
,
12848 new_loc_descr (DW_OP_deref_size
,
12849 GET_MODE_SIZE (mode
), 0));
12854 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12857 /* Some ports can transform a symbol ref into a label ref, because
12858 the symbol ref is too far away and has to be dumped into a constant
12862 if ((GET_MODE_CLASS (mode
) != MODE_INT
12863 && GET_MODE_CLASS (mode
) != MODE_PARTIAL_INT
)
12864 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12865 #ifdef POINTERS_EXTEND_UNSIGNED
12866 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12870 if (GET_CODE (rtl
) == SYMBOL_REF
12871 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12873 dw_loc_descr_ref temp
;
12875 /* If this is not defined, we have no way to emit the data. */
12876 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12879 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12881 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12882 add_loc_descr (&mem_loc_result
, temp
);
12887 if (!const_ok_for_output (rtl
))
12889 if (GET_CODE (rtl
) == CONST
)
12890 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12896 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12897 vec_safe_push (used_rtx_array
, rtl
);
12903 case DEBUG_IMPLICIT_PTR
:
12904 expansion_failed (NULL_TREE
, rtl
,
12905 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12911 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12913 if (GET_MODE_CLASS (mode
) != MODE_INT
12914 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12915 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12916 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12919 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12920 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12922 op0
= one_reg_loc_descriptor (dbx_regnum
,
12923 VAR_INIT_STATUS_INITIALIZED
);
12926 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12927 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12929 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12930 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12931 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12935 gcc_unreachable ();
12938 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12939 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12940 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12943 case DEBUG_PARAMETER_REF
:
12944 mem_loc_result
= parameter_ref_descriptor (rtl
);
12948 /* Extract the PLUS expression nested inside and fall into
12949 PLUS code below. */
12950 rtl
= XEXP (rtl
, 1);
12955 /* Turn these into a PLUS expression and fall into the PLUS code
12957 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12958 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12959 ? GET_MODE_UNIT_SIZE (mem_mode
)
12960 : -GET_MODE_UNIT_SIZE (mem_mode
),
12963 /* ... fall through ... */
12967 if (is_based_loc (rtl
)
12968 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12969 || XEXP (rtl
, 0) == arg_pointer_rtx
12970 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12971 && GET_MODE_CLASS (mode
) == MODE_INT
)
12972 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12973 INTVAL (XEXP (rtl
, 1)),
12974 VAR_INIT_STATUS_INITIALIZED
);
12977 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12978 VAR_INIT_STATUS_INITIALIZED
);
12979 if (mem_loc_result
== 0)
12982 if (CONST_INT_P (XEXP (rtl
, 1))
12983 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12984 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12987 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12988 VAR_INIT_STATUS_INITIALIZED
);
12991 add_loc_descr (&mem_loc_result
, op1
);
12992 add_loc_descr (&mem_loc_result
,
12993 new_loc_descr (DW_OP_plus
, 0, 0));
12998 /* If a pseudo-reg is optimized away, it is possible for it to
12999 be replaced with a MEM containing a multiply or shift. */
13010 && GET_MODE_CLASS (mode
) == MODE_INT
13011 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
13013 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13014 base_type_for_mode (mode
, 0),
13038 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13040 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13041 VAR_INIT_STATUS_INITIALIZED
);
13043 rtx rtlop1
= XEXP (rtl
, 1);
13044 if (GET_MODE (rtlop1
) != VOIDmode
13045 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
13046 < GET_MODE_BITSIZE (mode
))
13047 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
13048 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
13049 VAR_INIT_STATUS_INITIALIZED
);
13052 if (op0
== 0 || op1
== 0)
13055 mem_loc_result
= op0
;
13056 add_loc_descr (&mem_loc_result
, op1
);
13057 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13073 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13074 VAR_INIT_STATUS_INITIALIZED
);
13075 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13076 VAR_INIT_STATUS_INITIALIZED
);
13078 if (op0
== 0 || op1
== 0)
13081 mem_loc_result
= op0
;
13082 add_loc_descr (&mem_loc_result
, op1
);
13083 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13087 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
13089 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
13090 base_type_for_mode (mode
, 0),
13095 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13096 VAR_INIT_STATUS_INITIALIZED
);
13097 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13098 VAR_INIT_STATUS_INITIALIZED
);
13100 if (op0
== 0 || op1
== 0)
13103 mem_loc_result
= op0
;
13104 add_loc_descr (&mem_loc_result
, op1
);
13105 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13106 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
13107 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
13108 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
13109 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
13113 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
13115 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
13120 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
13121 base_type_for_mode (mode
, 1),
13139 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
13140 VAR_INIT_STATUS_INITIALIZED
);
13145 mem_loc_result
= op0
;
13146 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13150 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13151 #ifdef POINTERS_EXTEND_UNSIGNED
13153 && mem_mode
!= VOIDmode
13154 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
13158 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13162 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
13163 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
13165 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
13166 machine_mode amode
;
13167 if (type_die
== NULL
)
13169 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
13171 if (INTVAL (rtl
) >= 0
13172 && amode
!= BLKmode
13173 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
13174 /* const DW_OP_GNU_convert <XXX> vs.
13175 DW_OP_GNU_const_type <XXX, 1, const>. */
13176 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
13177 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
13179 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
13180 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13181 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13182 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13183 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13184 add_loc_descr (&mem_loc_result
, op0
);
13185 return mem_loc_result
;
13187 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
13189 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13190 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13191 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13192 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
13193 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13196 mem_loc_result
->dw_loc_oprnd2
.val_class
13197 = dw_val_class_const_double
;
13198 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13199 = double_int::from_shwi (INTVAL (rtl
));
13207 dw_die_ref type_die
;
13209 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
13210 CONST_DOUBLE rtx could represent either a large integer
13211 or a floating-point constant. If TARGET_SUPPORTS_WIDE_INT != 0,
13212 the value is always a floating point constant.
13214 When it is an integer, a CONST_DOUBLE is used whenever
13215 the constant requires 2 HWIs to be adequately represented.
13216 We output CONST_DOUBLEs as blocks. */
13217 if (mode
== VOIDmode
13218 || (GET_MODE (rtl
) == VOIDmode
13219 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
13221 type_die
= base_type_for_mode (mode
,
13222 GET_MODE_CLASS (mode
) == MODE_INT
);
13223 if (type_die
== NULL
)
13225 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13226 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13227 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13228 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13229 #if TARGET_SUPPORTS_WIDE_INT == 0
13230 if (!SCALAR_FLOAT_MODE_P (mode
))
13232 mem_loc_result
->dw_loc_oprnd2
.val_class
13233 = dw_val_class_const_double
;
13234 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
13235 = rtx_to_double_int (rtl
);
13240 unsigned int length
= GET_MODE_SIZE (mode
);
13241 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13243 insert_float (rtl
, array
);
13244 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13245 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13246 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13247 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13252 case CONST_WIDE_INT
:
13255 dw_die_ref type_die
;
13257 type_die
= base_type_for_mode (mode
,
13258 GET_MODE_CLASS (mode
) == MODE_INT
);
13259 if (type_die
== NULL
)
13261 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
13262 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13263 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13264 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13265 mem_loc_result
->dw_loc_oprnd2
.val_class
13266 = dw_val_class_wide_int
;
13267 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13268 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13273 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
13277 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13281 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13285 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13289 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13293 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
13297 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13301 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13305 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13309 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13314 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13319 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
13324 if (CONST_INT_P (XEXP (rtl
, 1))
13325 && CONST_INT_P (XEXP (rtl
, 2))
13326 && ((unsigned) INTVAL (XEXP (rtl
, 1))
13327 + (unsigned) INTVAL (XEXP (rtl
, 2))
13328 <= GET_MODE_BITSIZE (mode
))
13329 && GET_MODE_CLASS (mode
) == MODE_INT
13330 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13331 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
13334 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13335 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13338 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
13342 mem_loc_result
= op0
;
13343 size
= INTVAL (XEXP (rtl
, 1));
13344 shift
= INTVAL (XEXP (rtl
, 2));
13345 if (BITS_BIG_ENDIAN
)
13346 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13348 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
13350 add_loc_descr (&mem_loc_result
,
13351 int_loc_descriptor (DWARF2_ADDR_SIZE
13353 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13355 if (size
!= (int) DWARF2_ADDR_SIZE
)
13357 add_loc_descr (&mem_loc_result
,
13358 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
13359 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13366 dw_loc_descr_ref op2
, bra_node
, drop_node
;
13367 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
13368 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
13369 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
13370 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13371 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13372 VAR_INIT_STATUS_INITIALIZED
);
13373 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
13374 VAR_INIT_STATUS_INITIALIZED
);
13375 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
13378 mem_loc_result
= op1
;
13379 add_loc_descr (&mem_loc_result
, op2
);
13380 add_loc_descr (&mem_loc_result
, op0
);
13381 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13382 add_loc_descr (&mem_loc_result
, bra_node
);
13383 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
13384 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
13385 add_loc_descr (&mem_loc_result
, drop_node
);
13386 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13387 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
13392 case FLOAT_TRUNCATE
:
13394 case UNSIGNED_FLOAT
:
13399 dw_die_ref type_die
;
13400 dw_loc_descr_ref cvt
;
13402 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13403 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13406 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
13407 && (GET_CODE (rtl
) == FLOAT
13408 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
13409 <= DWARF2_ADDR_SIZE
))
13411 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
13412 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
13413 if (type_die
== NULL
)
13415 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13416 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13417 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13418 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13419 add_loc_descr (&op0
, cvt
);
13421 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
13422 if (type_die
== NULL
)
13424 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13425 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13426 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13427 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13428 add_loc_descr (&op0
, cvt
);
13429 if (GET_MODE_CLASS (mode
) == MODE_INT
13430 && (GET_CODE (rtl
) == FIX
13431 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
13433 op0
= convert_descriptor_to_mode (mode
, op0
);
13437 mem_loc_result
= op0
;
13444 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
13449 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
13453 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
13458 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
13462 /* In theory, we could implement the above. */
13463 /* DWARF cannot represent the unsigned compare operations
13488 case FRACT_CONVERT
:
13489 case UNSIGNED_FRACT_CONVERT
:
13491 case UNSIGNED_SAT_FRACT
:
13497 case VEC_DUPLICATE
:
13501 case STRICT_LOW_PART
:
13506 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13507 can't express it in the debug info. This can happen e.g. with some
13512 resolve_one_addr (&rtl
);
13516 #ifdef ENABLE_CHECKING
13517 print_rtl (stderr
, rtl
);
13518 gcc_unreachable ();
13524 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13525 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13527 return mem_loc_result
;
13530 /* Return a descriptor that describes the concatenation of two locations.
13531 This is typically a complex variable. */
13533 static dw_loc_descr_ref
13534 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13536 dw_loc_descr_ref cc_loc_result
= NULL
;
13537 dw_loc_descr_ref x0_ref
13538 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13539 dw_loc_descr_ref x1_ref
13540 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13542 if (x0_ref
== 0 || x1_ref
== 0)
13545 cc_loc_result
= x0_ref
;
13546 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13548 add_loc_descr (&cc_loc_result
, x1_ref
);
13549 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13551 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13552 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13554 return cc_loc_result
;
13557 /* Return a descriptor that describes the concatenation of N
13560 static dw_loc_descr_ref
13561 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13564 dw_loc_descr_ref cc_loc_result
= NULL
;
13565 unsigned int n
= XVECLEN (concatn
, 0);
13567 for (i
= 0; i
< n
; ++i
)
13569 dw_loc_descr_ref ref
;
13570 rtx x
= XVECEXP (concatn
, 0, i
);
13572 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13576 add_loc_descr (&cc_loc_result
, ref
);
13577 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13580 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13581 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13583 return cc_loc_result
;
13586 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13587 for DEBUG_IMPLICIT_PTR RTL. */
13589 static dw_loc_descr_ref
13590 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13592 dw_loc_descr_ref ret
;
13597 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13598 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13599 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13600 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13601 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13602 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13605 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13606 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13607 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13611 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13612 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13617 /* Output a proper Dwarf location descriptor for a variable or parameter
13618 which is either allocated in a register or in a memory location. For a
13619 register, we just generate an OP_REG and the register number. For a
13620 memory location we provide a Dwarf postfix expression describing how to
13621 generate the (dynamic) address of the object onto the address stack.
13623 MODE is mode of the decl if this loc_descriptor is going to be used in
13624 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13625 allowed, VOIDmode otherwise.
13627 If we don't know how to describe it, return 0. */
13629 static dw_loc_descr_ref
13630 loc_descriptor (rtx rtl
, machine_mode mode
,
13631 enum var_init_status initialized
)
13633 dw_loc_descr_ref loc_result
= NULL
;
13635 switch (GET_CODE (rtl
))
13638 /* The case of a subreg may arise when we have a local (register)
13639 variable or a formal (register) parameter which doesn't quite fill
13640 up an entire register. For now, just assume that it is
13641 legitimate to make the Dwarf info refer to the whole register which
13642 contains the given subreg. */
13643 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13644 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13645 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13651 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13655 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13656 GET_MODE (rtl
), initialized
);
13657 if (loc_result
== NULL
)
13658 loc_result
= tls_mem_loc_descriptor (rtl
);
13659 if (loc_result
== NULL
)
13661 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13662 if (new_rtl
!= rtl
)
13663 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13668 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13673 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13678 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13680 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13681 if (GET_CODE (loc
) == EXPR_LIST
)
13682 loc
= XEXP (loc
, 0);
13683 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13687 rtl
= XEXP (rtl
, 1);
13692 rtvec par_elems
= XVEC (rtl
, 0);
13693 int num_elem
= GET_NUM_ELEM (par_elems
);
13697 /* Create the first one, so we have something to add to. */
13698 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13699 VOIDmode
, initialized
);
13700 if (loc_result
== NULL
)
13702 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13703 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13704 for (i
= 1; i
< num_elem
; i
++)
13706 dw_loc_descr_ref temp
;
13708 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13709 VOIDmode
, initialized
);
13712 add_loc_descr (&loc_result
, temp
);
13713 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13714 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13720 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13721 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13726 if (mode
== VOIDmode
)
13727 mode
= GET_MODE (rtl
);
13729 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13731 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13733 /* Note that a CONST_DOUBLE rtx could represent either an integer
13734 or a floating-point constant. A CONST_DOUBLE is used whenever
13735 the constant requires more than one word in order to be
13736 adequately represented. We output CONST_DOUBLEs as blocks. */
13737 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13738 GET_MODE_SIZE (mode
), 0);
13739 #if TARGET_SUPPORTS_WIDE_INT == 0
13740 if (!SCALAR_FLOAT_MODE_P (mode
))
13742 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13743 loc_result
->dw_loc_oprnd2
.v
.val_double
13744 = rtx_to_double_int (rtl
);
13749 unsigned int length
= GET_MODE_SIZE (mode
);
13750 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
13752 insert_float (rtl
, array
);
13753 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13754 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13755 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13756 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13761 case CONST_WIDE_INT
:
13762 if (mode
== VOIDmode
)
13763 mode
= GET_MODE (rtl
);
13765 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13767 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13768 GET_MODE_SIZE (mode
), 0);
13769 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
13770 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc
<wide_int
> ();
13771 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13776 if (mode
== VOIDmode
)
13777 mode
= GET_MODE (rtl
);
13779 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13781 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13782 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13783 unsigned char *array
13784 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
13787 machine_mode imode
= GET_MODE_INNER (mode
);
13789 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13790 switch (GET_MODE_CLASS (mode
))
13792 case MODE_VECTOR_INT
:
13793 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13795 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13796 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
13800 case MODE_VECTOR_FLOAT
:
13801 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13803 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13804 insert_float (elt
, p
);
13809 gcc_unreachable ();
13812 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13813 length
* elt_size
, 0);
13814 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13815 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13816 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13817 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13822 if (mode
== VOIDmode
13823 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13824 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13825 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13827 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13832 if (!const_ok_for_output (rtl
))
13835 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13836 && (dwarf_version
>= 4 || !dwarf_strict
))
13838 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13839 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13840 vec_safe_push (used_rtx_array
, rtl
);
13844 case DEBUG_IMPLICIT_PTR
:
13845 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13849 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13850 && CONST_INT_P (XEXP (rtl
, 1)))
13853 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13859 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13860 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13861 && dwarf_version
>= 4)
13862 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13864 /* Value expression. */
13865 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13867 add_loc_descr (&loc_result
,
13868 new_loc_descr (DW_OP_stack_value
, 0, 0));
13876 /* We need to figure out what section we should use as the base for the
13877 address ranges where a given location is valid.
13878 1. If this particular DECL has a section associated with it, use that.
13879 2. If this function has a section associated with it, use that.
13880 3. Otherwise, use the text section.
13881 XXX: If you split a variable across multiple sections, we won't notice. */
13883 static const char *
13884 secname_for_decl (const_tree decl
)
13886 const char *secname
;
13888 if (VAR_OR_FUNCTION_DECL_P (decl
)
13889 && (DECL_EXTERNAL (decl
) || TREE_PUBLIC (decl
) || TREE_STATIC (decl
))
13890 && DECL_SECTION_NAME (decl
))
13891 secname
= DECL_SECTION_NAME (decl
);
13892 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13893 secname
= DECL_SECTION_NAME (current_function_decl
);
13894 else if (cfun
&& in_cold_section_p
)
13895 secname
= crtl
->subsections
.cold_section_label
;
13897 secname
= text_section_label
;
13902 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13905 decl_by_reference_p (tree decl
)
13907 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13908 || TREE_CODE (decl
) == VAR_DECL
)
13909 && DECL_BY_REFERENCE (decl
));
13912 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13915 static dw_loc_descr_ref
13916 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13917 enum var_init_status initialized
)
13919 int have_address
= 0;
13920 dw_loc_descr_ref descr
;
13923 if (want_address
!= 2)
13925 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13927 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13929 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13930 if (GET_CODE (varloc
) == EXPR_LIST
)
13931 varloc
= XEXP (varloc
, 0);
13932 mode
= GET_MODE (varloc
);
13933 if (MEM_P (varloc
))
13935 rtx addr
= XEXP (varloc
, 0);
13936 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13937 mode
, initialized
);
13942 rtx x
= avoid_constant_pool_reference (varloc
);
13944 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13949 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13956 if (GET_CODE (varloc
) == VAR_LOCATION
)
13957 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13959 mode
= DECL_MODE (loc
);
13960 descr
= loc_descriptor (varloc
, mode
, initialized
);
13967 if (want_address
== 2 && !have_address
13968 && (dwarf_version
>= 4 || !dwarf_strict
))
13970 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13972 expansion_failed (loc
, NULL_RTX
,
13973 "DWARF address size mismatch");
13976 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13979 /* Show if we can't fill the request for an address. */
13980 if (want_address
&& !have_address
)
13982 expansion_failed (loc
, NULL_RTX
,
13983 "Want address and only have value");
13987 /* If we've got an address and don't want one, dereference. */
13988 if (!want_address
&& have_address
)
13990 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13991 enum dwarf_location_atom op
;
13993 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13995 expansion_failed (loc
, NULL_RTX
,
13996 "DWARF address size mismatch");
13999 else if (size
== DWARF2_ADDR_SIZE
)
14002 op
= DW_OP_deref_size
;
14004 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
14010 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
14011 if it is not possible. */
14013 static dw_loc_descr_ref
14014 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
14016 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
14017 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
14018 else if (dwarf_version
>= 3 || !dwarf_strict
)
14019 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
14024 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
14025 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
14027 static dw_loc_descr_ref
14028 dw_sra_loc_expr (tree decl
, rtx loc
)
14031 unsigned HOST_WIDE_INT padsize
= 0;
14032 dw_loc_descr_ref descr
, *descr_tail
;
14033 unsigned HOST_WIDE_INT decl_size
;
14035 enum var_init_status initialized
;
14037 if (DECL_SIZE (decl
) == NULL
14038 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
14041 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
14043 descr_tail
= &descr
;
14045 for (p
= loc
; p
; p
= XEXP (p
, 1))
14047 unsigned HOST_WIDE_INT bitsize
= decl_piece_bitsize (p
);
14048 rtx loc_note
= *decl_piece_varloc_ptr (p
);
14049 dw_loc_descr_ref cur_descr
;
14050 dw_loc_descr_ref
*tail
, last
= NULL
;
14051 unsigned HOST_WIDE_INT opsize
= 0;
14053 if (loc_note
== NULL_RTX
14054 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
14056 padsize
+= bitsize
;
14059 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
14060 varloc
= NOTE_VAR_LOCATION (loc_note
);
14061 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
14062 if (cur_descr
== NULL
)
14064 padsize
+= bitsize
;
14068 /* Check that cur_descr either doesn't use
14069 DW_OP_*piece operations, or their sum is equal
14070 to bitsize. Otherwise we can't embed it. */
14071 for (tail
= &cur_descr
; *tail
!= NULL
;
14072 tail
= &(*tail
)->dw_loc_next
)
14073 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
14075 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
14079 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
14081 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
14085 if (last
!= NULL
&& opsize
!= bitsize
)
14087 padsize
+= bitsize
;
14088 /* Discard the current piece of the descriptor and release any
14089 addr_table entries it uses. */
14090 remove_loc_list_addr_table_entries (cur_descr
);
14094 /* If there is a hole, add DW_OP_*piece after empty DWARF
14095 expression, which means that those bits are optimized out. */
14098 if (padsize
> decl_size
)
14100 remove_loc_list_addr_table_entries (cur_descr
);
14101 goto discard_descr
;
14103 decl_size
-= padsize
;
14104 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
14105 if (*descr_tail
== NULL
)
14107 remove_loc_list_addr_table_entries (cur_descr
);
14108 goto discard_descr
;
14110 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14113 *descr_tail
= cur_descr
;
14115 if (bitsize
> decl_size
)
14116 goto discard_descr
;
14117 decl_size
-= bitsize
;
14120 HOST_WIDE_INT offset
= 0;
14121 if (GET_CODE (varloc
) == VAR_LOCATION
14122 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
14124 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
14125 if (GET_CODE (varloc
) == EXPR_LIST
)
14126 varloc
= XEXP (varloc
, 0);
14130 if (GET_CODE (varloc
) == CONST
14131 || GET_CODE (varloc
) == SIGN_EXTEND
14132 || GET_CODE (varloc
) == ZERO_EXTEND
)
14133 varloc
= XEXP (varloc
, 0);
14134 else if (GET_CODE (varloc
) == SUBREG
)
14135 varloc
= SUBREG_REG (varloc
);
14140 /* DW_OP_bit_size offset should be zero for register
14141 or implicit location descriptions and empty location
14142 descriptions, but for memory addresses needs big endian
14144 if (MEM_P (varloc
))
14146 unsigned HOST_WIDE_INT memsize
14147 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
14148 if (memsize
!= bitsize
)
14150 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
14151 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
14152 goto discard_descr
;
14153 if (memsize
< bitsize
)
14154 goto discard_descr
;
14155 if (BITS_BIG_ENDIAN
)
14156 offset
= memsize
- bitsize
;
14160 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
14161 if (*descr_tail
== NULL
)
14162 goto discard_descr
;
14163 descr_tail
= &(*descr_tail
)->dw_loc_next
;
14167 /* If there were any non-empty expressions, add padding till the end of
14169 if (descr
!= NULL
&& decl_size
!= 0)
14171 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
14172 if (*descr_tail
== NULL
)
14173 goto discard_descr
;
14178 /* Discard the descriptor and release any addr_table entries it uses. */
14179 remove_loc_list_addr_table_entries (descr
);
14183 /* Return the dwarf representation of the location list LOC_LIST of
14184 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
14187 static dw_loc_list_ref
14188 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
14190 const char *endname
, *secname
;
14192 enum var_init_status initialized
;
14193 struct var_loc_node
*node
;
14194 dw_loc_descr_ref descr
;
14195 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
14196 dw_loc_list_ref list
= NULL
;
14197 dw_loc_list_ref
*listp
= &list
;
14199 /* Now that we know what section we are using for a base,
14200 actually construct the list of locations.
14201 The first location information is what is passed to the
14202 function that creates the location list, and the remaining
14203 locations just get added on to that list.
14204 Note that we only know the start address for a location
14205 (IE location changes), so to build the range, we use
14206 the range [current location start, next location start].
14207 This means we have to special case the last node, and generate
14208 a range of [last location start, end of function label]. */
14210 secname
= secname_for_decl (decl
);
14212 for (node
= loc_list
->first
; node
; node
= node
->next
)
14213 if (GET_CODE (node
->loc
) == EXPR_LIST
14214 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
14216 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14218 /* This requires DW_OP_{,bit_}piece, which is not usable
14219 inside DWARF expressions. */
14220 if (want_address
!= 2)
14222 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14228 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14229 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14230 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
14234 bool range_across_switch
= false;
14235 /* If section switch happens in between node->label
14236 and node->next->label (or end of function) and
14237 we can't emit it as a single entry list,
14238 emit two ranges, first one ending at the end
14239 of first partition and second one starting at the
14240 beginning of second partition. */
14241 if (node
== loc_list
->last_before_switch
14242 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
14243 && current_function_decl
)
14245 endname
= cfun
->fde
->dw_fde_end
;
14246 range_across_switch
= true;
14248 /* The variable has a location between NODE->LABEL and
14249 NODE->NEXT->LABEL. */
14250 else if (node
->next
)
14251 endname
= node
->next
->label
;
14252 /* If the variable has a location at the last label
14253 it keeps its location until the end of function. */
14254 else if (!current_function_decl
)
14255 endname
= text_end_label
;
14258 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
14259 current_function_funcdef_no
);
14260 endname
= ggc_strdup (label_id
);
14263 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
14264 if (TREE_CODE (decl
) == PARM_DECL
14265 && node
== loc_list
->first
14266 && NOTE_P (node
->loc
)
14267 && strcmp (node
->label
, endname
) == 0)
14268 (*listp
)->force
= true;
14269 listp
= &(*listp
)->dw_loc_next
;
14271 if (range_across_switch
)
14273 if (GET_CODE (node
->loc
) == EXPR_LIST
)
14274 descr
= dw_sra_loc_expr (decl
, node
->loc
);
14277 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
14278 varloc
= NOTE_VAR_LOCATION (node
->loc
);
14279 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
14282 gcc_assert (descr
);
14283 /* The variable has a location between NODE->LABEL and
14284 NODE->NEXT->LABEL. */
14286 endname
= node
->next
->label
;
14288 endname
= cfun
->fde
->dw_fde_second_end
;
14289 *listp
= new_loc_list (descr
,
14290 cfun
->fde
->dw_fde_second_begin
,
14292 listp
= &(*listp
)->dw_loc_next
;
14297 /* Try to avoid the overhead of a location list emitting a location
14298 expression instead, but only if we didn't have more than one
14299 location entry in the first place. If some entries were not
14300 representable, we don't want to pretend a single entry that was
14301 applies to the entire scope in which the variable is
14303 if (list
&& loc_list
->first
->next
)
14309 /* Return if the loc_list has only single element and thus can be represented
14310 as location description. */
14313 single_element_loc_list_p (dw_loc_list_ref list
)
14315 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
14316 return !list
->ll_symbol
;
14319 /* To each location in list LIST add loc descr REF. */
14322 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
14324 dw_loc_descr_ref copy
;
14325 add_loc_descr (&list
->expr
, ref
);
14326 list
= list
->dw_loc_next
;
14329 copy
= ggc_alloc
<dw_loc_descr_node
> ();
14330 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
14331 add_loc_descr (&list
->expr
, copy
);
14332 while (copy
->dw_loc_next
)
14334 dw_loc_descr_ref new_copy
= ggc_alloc
<dw_loc_descr_node
> ();
14335 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
14336 copy
->dw_loc_next
= new_copy
;
14339 list
= list
->dw_loc_next
;
14343 /* Given two lists RET and LIST
14344 produce location list that is result of adding expression in LIST
14345 to expression in RET on each position in program.
14346 Might be destructive on both RET and LIST.
14348 TODO: We handle only simple cases of RET or LIST having at most one
14349 element. General case would inolve sorting the lists in program order
14350 and merging them that will need some additional work.
14351 Adding that will improve quality of debug info especially for SRA-ed
14355 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
14364 if (!list
->dw_loc_next
)
14366 add_loc_descr_to_each (*ret
, list
->expr
);
14369 if (!(*ret
)->dw_loc_next
)
14371 add_loc_descr_to_each (list
, (*ret
)->expr
);
14375 expansion_failed (NULL_TREE
, NULL_RTX
,
14376 "Don't know how to merge two non-trivial"
14377 " location lists.\n");
14382 /* LOC is constant expression. Try a luck, look it up in constant
14383 pool and return its loc_descr of its address. */
14385 static dw_loc_descr_ref
14386 cst_pool_loc_descr (tree loc
)
14388 /* Get an RTL for this, if something has been emitted. */
14389 rtx rtl
= lookup_constant_def (loc
);
14391 if (!rtl
|| !MEM_P (rtl
))
14396 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
14398 /* TODO: We might get more coverage if we was actually delaying expansion
14399 of all expressions till end of compilation when constant pools are fully
14401 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
14403 expansion_failed (loc
, NULL_RTX
,
14404 "CST value in contant pool but not marked.");
14407 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
14408 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
14411 /* Return dw_loc_list representing address of addr_expr LOC
14412 by looking for inner INDIRECT_REF expression and turning
14413 it into simple arithmetics.
14415 See loc_list_from_tree for the meaning of CONTEXT. */
14417 static dw_loc_list_ref
14418 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
,
14419 const loc_descr_context
*context
)
14422 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14424 int unsignedp
, volatilep
= 0;
14425 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14427 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
14428 &bitsize
, &bitpos
, &offset
, &mode
,
14429 &unsignedp
, &volatilep
, false);
14431 if (bitpos
% BITS_PER_UNIT
)
14433 expansion_failed (loc
, NULL_RTX
, "bitfield access");
14436 if (!INDIRECT_REF_P (obj
))
14438 expansion_failed (obj
,
14439 NULL_RTX
, "no indirect ref in inner refrence");
14442 if (!offset
&& !bitpos
)
14443 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1,
14446 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
14447 && (dwarf_version
>= 4 || !dwarf_strict
))
14449 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0, context
);
14454 /* Variable offset. */
14455 list_ret1
= loc_list_from_tree (offset
, 0, context
);
14456 if (list_ret1
== 0)
14458 add_loc_list (&list_ret
, list_ret1
);
14461 add_loc_descr_to_each (list_ret
,
14462 new_loc_descr (DW_OP_plus
, 0, 0));
14464 bytepos
= bitpos
/ BITS_PER_UNIT
;
14466 add_loc_descr_to_each (list_ret
,
14467 new_loc_descr (DW_OP_plus_uconst
,
14469 else if (bytepos
< 0)
14470 loc_list_plus_const (list_ret
, bytepos
);
14471 add_loc_descr_to_each (list_ret
,
14472 new_loc_descr (DW_OP_stack_value
, 0, 0));
14478 /* Helper structure for location descriptions generation. */
14479 struct loc_descr_context
14481 /* The type that is implicitly referenced by DW_OP_push_object_address, or
14482 NULL_TREE if DW_OP_push_object_address in invalid for this location
14483 description. This is used when processing PLACEHOLDER_EXPR nodes. */
14485 /* The ..._DECL node that should be translated as a
14486 DW_OP_push_object_address operation. */
14490 /* Generate Dwarf location list representing LOC.
14491 If WANT_ADDRESS is false, expression computing LOC will be computed
14492 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14493 if WANT_ADDRESS is 2, expression computing address useable in location
14494 will be returned (i.e. DW_OP_reg can be used
14495 to refer to register values).
14497 CONTEXT provides information to customize the location descriptions
14498 generation. Its context_type field specifies what type is implicitly
14499 referenced by DW_OP_push_object_address. If it is NULL_TREE, this operation
14500 will not be generated.
14502 If CONTEXT is NULL, the behavior is the same as if both context_type and
14503 base_decl fields were NULL_TREE. */
14505 static dw_loc_list_ref
14506 loc_list_from_tree (tree loc
, int want_address
,
14507 const struct loc_descr_context
*context
)
14509 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
14510 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14511 int have_address
= 0;
14512 enum dwarf_location_atom op
;
14514 /* ??? Most of the time we do not take proper care for sign/zero
14515 extending the values properly. Hopefully this won't be a real
14518 if (context
!= NULL
14519 && context
->base_decl
== loc
14520 && want_address
== 0)
14522 if (dwarf_version
>= 3 || !dwarf_strict
)
14523 return new_loc_list (new_loc_descr (DW_OP_push_object_address
, 0, 0),
14529 switch (TREE_CODE (loc
))
14532 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14535 case PLACEHOLDER_EXPR
:
14536 /* This case involves extracting fields from an object to determine the
14537 position of other fields. It is supposed to appear only as the first
14538 operand of COMPONENT_REF nodes and to reference precisely the type
14539 that the context allows. */
14540 if (context
!= NULL
14541 && TREE_TYPE (loc
) == context
->context_type
14542 && want_address
>= 1)
14544 if (dwarf_version
>= 3 || !dwarf_strict
)
14546 ret
= new_loc_descr (DW_OP_push_object_address
, 0, 0);
14554 expansion_failed (loc
, NULL_RTX
,
14555 "PLACEHOLDER_EXPR for an unexpected type");
14559 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14560 /* There are no opcodes for these operations. */
14563 case PREINCREMENT_EXPR
:
14564 case PREDECREMENT_EXPR
:
14565 case POSTINCREMENT_EXPR
:
14566 case POSTDECREMENT_EXPR
:
14567 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14568 /* There are no opcodes for these operations. */
14572 /* If we already want an address, see if there is INDIRECT_REF inside
14573 e.g. for &this->field. */
14576 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14577 (loc
, want_address
== 2, context
);
14580 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14581 && (ret
= cst_pool_loc_descr (loc
)))
14584 /* Otherwise, process the argument and look for the address. */
14585 if (!list_ret
&& !ret
)
14586 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1, context
);
14590 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14596 if (DECL_THREAD_LOCAL_P (loc
))
14599 enum dwarf_location_atom tls_op
;
14600 enum dtprel_bool dtprel
= dtprel_false
;
14602 if (targetm
.have_tls
)
14604 /* If this is not defined, we have no way to emit the
14606 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14609 /* The way DW_OP_GNU_push_tls_address is specified, we
14610 can only look up addresses of objects in the current
14611 module. We used DW_OP_addr as first op, but that's
14612 wrong, because DW_OP_addr is relocated by the debug
14613 info consumer, while DW_OP_GNU_push_tls_address
14614 operand shouldn't be. */
14615 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14617 dtprel
= dtprel_true
;
14618 tls_op
= DW_OP_GNU_push_tls_address
;
14622 if (!targetm
.emutls
.debug_form_tls_address
14623 || !(dwarf_version
>= 3 || !dwarf_strict
))
14625 /* We stuffed the control variable into the DECL_VALUE_EXPR
14626 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14627 no longer appear in gimple code. We used the control
14628 variable in specific so that we could pick it up here. */
14629 loc
= DECL_VALUE_EXPR (loc
);
14630 tls_op
= DW_OP_form_tls_address
;
14633 rtl
= rtl_for_decl_location (loc
);
14634 if (rtl
== NULL_RTX
)
14639 rtl
= XEXP (rtl
, 0);
14640 if (! CONSTANT_P (rtl
))
14643 ret
= new_addr_loc_descr (rtl
, dtprel
);
14644 ret1
= new_loc_descr (tls_op
, 0, 0);
14645 add_loc_descr (&ret
, ret1
);
14654 if (DECL_HAS_VALUE_EXPR_P (loc
))
14655 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14656 want_address
, context
);
14659 case FUNCTION_DECL
:
14662 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14664 if (loc_list
&& loc_list
->first
)
14666 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14667 have_address
= want_address
!= 0;
14670 rtl
= rtl_for_decl_location (loc
);
14671 if (rtl
== NULL_RTX
)
14673 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14676 else if (CONST_INT_P (rtl
))
14678 HOST_WIDE_INT val
= INTVAL (rtl
);
14679 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14680 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14681 ret
= int_loc_descriptor (val
);
14683 else if (GET_CODE (rtl
) == CONST_STRING
)
14685 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14688 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14689 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14692 machine_mode mode
, mem_mode
;
14694 /* Certain constructs can only be represented at top-level. */
14695 if (want_address
== 2)
14697 ret
= loc_descriptor (rtl
, VOIDmode
,
14698 VAR_INIT_STATUS_INITIALIZED
);
14703 mode
= GET_MODE (rtl
);
14704 mem_mode
= VOIDmode
;
14708 mode
= get_address_mode (rtl
);
14709 rtl
= XEXP (rtl
, 0);
14712 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14713 VAR_INIT_STATUS_INITIALIZED
);
14716 expansion_failed (loc
, rtl
,
14717 "failed to produce loc descriptor for rtl");
14723 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14730 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14734 case TARGET_MEM_REF
:
14736 case DEBUG_EXPR_DECL
:
14739 case COMPOUND_EXPR
:
14740 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
, context
);
14743 case VIEW_CONVERT_EXPR
:
14746 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
, context
);
14748 case COMPONENT_REF
:
14749 case BIT_FIELD_REF
:
14751 case ARRAY_RANGE_REF
:
14752 case REALPART_EXPR
:
14753 case IMAGPART_EXPR
:
14756 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14758 int unsignedp
, volatilep
= 0;
14760 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14761 &unsignedp
, &volatilep
, false);
14763 gcc_assert (obj
!= loc
);
14765 list_ret
= loc_list_from_tree (obj
,
14767 && !bitpos
&& !offset
? 2 : 1,
14769 /* TODO: We can extract value of the small expression via shifting even
14770 for nonzero bitpos. */
14773 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14775 expansion_failed (loc
, NULL_RTX
,
14776 "bitfield access");
14780 if (offset
!= NULL_TREE
)
14782 /* Variable offset. */
14783 list_ret1
= loc_list_from_tree (offset
, 0, context
);
14784 if (list_ret1
== 0)
14786 add_loc_list (&list_ret
, list_ret1
);
14789 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14792 bytepos
= bitpos
/ BITS_PER_UNIT
;
14794 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14795 else if (bytepos
< 0)
14796 loc_list_plus_const (list_ret
, bytepos
);
14803 if ((want_address
|| !tree_fits_shwi_p (loc
))
14804 && (ret
= cst_pool_loc_descr (loc
)))
14806 else if (want_address
== 2
14807 && tree_fits_shwi_p (loc
)
14808 && (ret
= address_of_int_loc_descriptor
14809 (int_size_in_bytes (TREE_TYPE (loc
)),
14810 tree_to_shwi (loc
))))
14812 else if (tree_fits_shwi_p (loc
))
14813 ret
= int_loc_descriptor (tree_to_shwi (loc
));
14816 expansion_failed (loc
, NULL_RTX
,
14817 "Integer operand is not host integer");
14826 if ((ret
= cst_pool_loc_descr (loc
)))
14829 /* We can construct small constants here using int_loc_descriptor. */
14830 expansion_failed (loc
, NULL_RTX
,
14831 "constructor or constant not in constant pool");
14834 case TRUTH_AND_EXPR
:
14835 case TRUTH_ANDIF_EXPR
:
14840 case TRUTH_XOR_EXPR
:
14845 case TRUTH_OR_EXPR
:
14846 case TRUTH_ORIF_EXPR
:
14851 case FLOOR_DIV_EXPR
:
14852 case CEIL_DIV_EXPR
:
14853 case ROUND_DIV_EXPR
:
14854 case TRUNC_DIV_EXPR
:
14855 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14864 case FLOOR_MOD_EXPR
:
14865 case CEIL_MOD_EXPR
:
14866 case ROUND_MOD_EXPR
:
14867 case TRUNC_MOD_EXPR
:
14868 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14873 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14874 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
14875 if (list_ret
== 0 || list_ret1
== 0)
14878 add_loc_list (&list_ret
, list_ret1
);
14881 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14882 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14883 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14884 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14885 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14897 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14900 case POINTER_PLUS_EXPR
:
14903 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
14905 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14909 loc_list_plus_const (list_ret
, tree_to_shwi (TREE_OPERAND (loc
, 1)));
14917 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14924 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14931 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14938 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14953 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14954 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
14955 if (list_ret
== 0 || list_ret1
== 0)
14958 add_loc_list (&list_ret
, list_ret1
);
14961 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14964 case TRUTH_NOT_EXPR
:
14978 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
14982 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14988 const enum tree_code code
=
14989 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14991 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14992 build2 (code
, integer_type_node
,
14993 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14994 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14997 /* ... fall through ... */
15001 dw_loc_descr_ref lhs
15002 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0, context
);
15003 dw_loc_list_ref rhs
15004 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0, context
);
15005 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
15007 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0, context
);
15008 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
15011 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
15012 add_loc_descr_to_each (list_ret
, bra_node
);
15014 add_loc_list (&list_ret
, rhs
);
15015 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
15016 add_loc_descr_to_each (list_ret
, jump_node
);
15018 add_loc_descr_to_each (list_ret
, lhs
);
15019 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15020 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
15022 /* ??? Need a node to point the skip at. Use a nop. */
15023 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
15024 add_loc_descr_to_each (list_ret
, tmp
);
15025 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
15026 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
15030 case FIX_TRUNC_EXPR
:
15034 /* Leave front-end specific codes as simply unknown. This comes
15035 up, for instance, with the C STMT_EXPR. */
15036 if ((unsigned int) TREE_CODE (loc
)
15037 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
15039 expansion_failed (loc
, NULL_RTX
,
15040 "language specific tree node");
15044 #ifdef ENABLE_CHECKING
15045 /* Otherwise this is a generic code; we should just lists all of
15046 these explicitly. We forgot one. */
15047 gcc_unreachable ();
15049 /* In a release build, we want to degrade gracefully: better to
15050 generate incomplete debugging information than to crash. */
15055 if (!ret
&& !list_ret
)
15058 if (want_address
== 2 && !have_address
15059 && (dwarf_version
>= 4 || !dwarf_strict
))
15061 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
15063 expansion_failed (loc
, NULL_RTX
,
15064 "DWARF address size mismatch");
15068 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15070 add_loc_descr_to_each (list_ret
,
15071 new_loc_descr (DW_OP_stack_value
, 0, 0));
15074 /* Show if we can't fill the request for an address. */
15075 if (want_address
&& !have_address
)
15077 expansion_failed (loc
, NULL_RTX
,
15078 "Want address and only have value");
15082 gcc_assert (!ret
|| !list_ret
);
15084 /* If we've got an address and don't want one, dereference. */
15085 if (!want_address
&& have_address
)
15087 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
15089 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
15091 expansion_failed (loc
, NULL_RTX
,
15092 "DWARF address size mismatch");
15095 else if (size
== DWARF2_ADDR_SIZE
)
15098 op
= DW_OP_deref_size
;
15101 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
15103 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
15106 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
15111 /* Same as above but return only single location expression. */
15112 static dw_loc_descr_ref
15113 loc_descriptor_from_tree (tree loc
, int want_address
,
15114 const struct loc_descr_context
*context
)
15116 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
, context
);
15119 if (ret
->dw_loc_next
)
15121 expansion_failed (loc
, NULL_RTX
,
15122 "Location list where only loc descriptor needed");
15128 /* Given a value, round it up to the lowest multiple of `boundary'
15129 which is not less than the value itself. */
15131 static inline HOST_WIDE_INT
15132 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
15134 return (((value
+ boundary
- 1) / boundary
) * boundary
);
15137 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
15138 pointer to the declared type for the relevant field variable, or return
15139 `integer_type_node' if the given node turns out to be an
15140 ERROR_MARK node. */
15143 field_type (const_tree decl
)
15147 if (TREE_CODE (decl
) == ERROR_MARK
)
15148 return integer_type_node
;
15150 type
= DECL_BIT_FIELD_TYPE (decl
);
15151 if (type
== NULL_TREE
)
15152 type
= TREE_TYPE (decl
);
15157 /* Given a pointer to a tree node, return the alignment in bits for
15158 it, or else return BITS_PER_WORD if the node actually turns out to
15159 be an ERROR_MARK node. */
15161 static inline unsigned
15162 simple_type_align_in_bits (const_tree type
)
15164 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
15167 static inline unsigned
15168 simple_decl_align_in_bits (const_tree decl
)
15170 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
15173 /* Return the result of rounding T up to ALIGN. */
15175 static inline offset_int
15176 round_up_to_align (const offset_int
&t
, unsigned int align
)
15178 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
15181 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
15182 lowest addressed byte of the "containing object" for the given FIELD_DECL,
15183 or return 0 if we are unable to determine what that offset is, either
15184 because the argument turns out to be a pointer to an ERROR_MARK node, or
15185 because the offset is actually variable. (We can't handle the latter case
15188 static HOST_WIDE_INT
15189 field_byte_offset (const_tree decl
)
15191 offset_int object_offset_in_bits
;
15192 offset_int object_offset_in_bytes
;
15193 offset_int bitpos_int
;
15195 if (TREE_CODE (decl
) == ERROR_MARK
)
15198 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
15200 /* We cannot yet cope with fields whose positions are variable, so
15201 for now, when we see such things, we simply return 0. Someday, we may
15202 be able to handle such cases, but it will be damn difficult. */
15203 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
15206 bitpos_int
= wi::to_offset (bit_position (decl
));
15208 if (PCC_BITFIELD_TYPE_MATTERS
)
15211 tree field_size_tree
;
15212 offset_int deepest_bitpos
;
15213 offset_int field_size_in_bits
;
15214 unsigned int type_align_in_bits
;
15215 unsigned int decl_align_in_bits
;
15216 offset_int type_size_in_bits
;
15218 type
= field_type (decl
);
15219 type_size_in_bits
= offset_int_type_size_in_bits (type
);
15220 type_align_in_bits
= simple_type_align_in_bits (type
);
15222 field_size_tree
= DECL_SIZE (decl
);
15224 /* The size could be unspecified if there was an error, or for
15225 a flexible array member. */
15226 if (!field_size_tree
)
15227 field_size_tree
= bitsize_zero_node
;
15229 /* If the size of the field is not constant, use the type size. */
15230 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
15231 field_size_in_bits
= wi::to_offset (field_size_tree
);
15233 field_size_in_bits
= type_size_in_bits
;
15235 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
15237 /* The GCC front-end doesn't make any attempt to keep track of the
15238 starting bit offset (relative to the start of the containing
15239 structure type) of the hypothetical "containing object" for a
15240 bit-field. Thus, when computing the byte offset value for the
15241 start of the "containing object" of a bit-field, we must deduce
15242 this information on our own. This can be rather tricky to do in
15243 some cases. For example, handling the following structure type
15244 definition when compiling for an i386/i486 target (which only
15245 aligns long long's to 32-bit boundaries) can be very tricky:
15247 struct S { int field1; long long field2:31; };
15249 Fortunately, there is a simple rule-of-thumb which can be used
15250 in such cases. When compiling for an i386/i486, GCC will
15251 allocate 8 bytes for the structure shown above. It decides to
15252 do this based upon one simple rule for bit-field allocation.
15253 GCC allocates each "containing object" for each bit-field at
15254 the first (i.e. lowest addressed) legitimate alignment boundary
15255 (based upon the required minimum alignment for the declared
15256 type of the field) which it can possibly use, subject to the
15257 condition that there is still enough available space remaining
15258 in the containing object (when allocated at the selected point)
15259 to fully accommodate all of the bits of the bit-field itself.
15261 This simple rule makes it obvious why GCC allocates 8 bytes for
15262 each object of the structure type shown above. When looking
15263 for a place to allocate the "containing object" for `field2',
15264 the compiler simply tries to allocate a 64-bit "containing
15265 object" at each successive 32-bit boundary (starting at zero)
15266 until it finds a place to allocate that 64- bit field such that
15267 at least 31 contiguous (and previously unallocated) bits remain
15268 within that selected 64 bit field. (As it turns out, for the
15269 example above, the compiler finds it is OK to allocate the
15270 "containing object" 64-bit field at bit-offset zero within the
15273 Here we attempt to work backwards from the limited set of facts
15274 we're given, and we try to deduce from those facts, where GCC
15275 must have believed that the containing object started (within
15276 the structure type). The value we deduce is then used (by the
15277 callers of this routine) to generate DW_AT_location and
15278 DW_AT_bit_offset attributes for fields (both bit-fields and, in
15279 the case of DW_AT_location, regular fields as well). */
15281 /* Figure out the bit-distance from the start of the structure to
15282 the "deepest" bit of the bit-field. */
15283 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
15285 /* This is the tricky part. Use some fancy footwork to deduce
15286 where the lowest addressed bit of the containing object must
15288 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
15290 /* Round up to type_align by default. This works best for
15292 object_offset_in_bits
15293 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
15295 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
15297 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
15299 /* Round up to decl_align instead. */
15300 object_offset_in_bits
15301 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
15305 object_offset_in_bits
= bitpos_int
;
15307 object_offset_in_bytes
15308 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
15309 return object_offset_in_bytes
.to_shwi ();
15312 /* The following routines define various Dwarf attributes and any data
15313 associated with them. */
15315 /* Add a location description attribute value to a DIE.
15317 This emits location attributes suitable for whole variables and
15318 whole parameters. Note that the location attributes for struct fields are
15319 generated by the routine `data_member_location_attribute' below. */
15322 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
15323 dw_loc_list_ref descr
)
15327 if (single_element_loc_list_p (descr
))
15328 add_AT_loc (die
, attr_kind
, descr
->expr
);
15330 add_AT_loc_list (die
, attr_kind
, descr
);
15333 /* Add DW_AT_accessibility attribute to DIE if needed. */
15336 add_accessibility_attribute (dw_die_ref die
, tree decl
)
15338 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
15339 children, otherwise the default is DW_ACCESS_public. In DWARF2
15340 the default has always been DW_ACCESS_public. */
15341 if (TREE_PROTECTED (decl
))
15342 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
15343 else if (TREE_PRIVATE (decl
))
15345 if (dwarf_version
== 2
15346 || die
->die_parent
== NULL
15347 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
15348 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
15350 else if (dwarf_version
> 2
15352 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
15353 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
15356 /* Attach the specialized form of location attribute used for data members of
15357 struct and union types. In the special case of a FIELD_DECL node which
15358 represents a bit-field, the "offset" part of this special location
15359 descriptor must indicate the distance in bytes from the lowest-addressed
15360 byte of the containing struct or union type to the lowest-addressed byte of
15361 the "containing object" for the bit-field. (See the `field_byte_offset'
15364 For any given bit-field, the "containing object" is a hypothetical object
15365 (of some integral or enum type) within which the given bit-field lives. The
15366 type of this hypothetical "containing object" is always the same as the
15367 declared type of the individual bit-field itself (for GCC anyway... the
15368 DWARF spec doesn't actually mandate this). Note that it is the size (in
15369 bytes) of the hypothetical "containing object" which will be given in the
15370 DW_AT_byte_size attribute for this bit-field. (See the
15371 `byte_size_attribute' function below.) It is also used when calculating the
15372 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15373 function below.) */
15376 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
15378 HOST_WIDE_INT offset
;
15379 dw_loc_descr_ref loc_descr
= 0;
15381 if (TREE_CODE (decl
) == TREE_BINFO
)
15383 /* We're working on the TAG_inheritance for a base class. */
15384 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
15386 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15387 aren't at a fixed offset from all (sub)objects of the same
15388 type. We need to extract the appropriate offset from our
15389 vtable. The following dwarf expression means
15391 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15393 This is specific to the V3 ABI, of course. */
15395 dw_loc_descr_ref tmp
;
15397 /* Make a copy of the object address. */
15398 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
15399 add_loc_descr (&loc_descr
, tmp
);
15401 /* Extract the vtable address. */
15402 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15403 add_loc_descr (&loc_descr
, tmp
);
15405 /* Calculate the address of the offset. */
15406 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
15407 gcc_assert (offset
< 0);
15409 tmp
= int_loc_descriptor (-offset
);
15410 add_loc_descr (&loc_descr
, tmp
);
15411 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
15412 add_loc_descr (&loc_descr
, tmp
);
15414 /* Extract the offset. */
15415 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15416 add_loc_descr (&loc_descr
, tmp
);
15418 /* Add it to the object address. */
15419 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
15420 add_loc_descr (&loc_descr
, tmp
);
15423 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
15426 offset
= field_byte_offset (decl
);
15430 if (dwarf_version
> 2)
15432 /* Don't need to output a location expression, just the constant. */
15434 add_AT_int (die
, DW_AT_data_member_location
, offset
);
15436 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
15441 enum dwarf_location_atom op
;
15443 /* The DWARF2 standard says that we should assume that the structure
15444 address is already on the stack, so we can specify a structure
15445 field address by using DW_OP_plus_uconst. */
15446 op
= DW_OP_plus_uconst
;
15447 loc_descr
= new_loc_descr (op
, offset
, 0);
15451 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
15454 /* Writes integer values to dw_vec_const array. */
15457 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
15461 *dest
++ = val
& 0xff;
15467 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15469 static HOST_WIDE_INT
15470 extract_int (const unsigned char *src
, unsigned int size
)
15472 HOST_WIDE_INT val
= 0;
15478 val
|= *--src
& 0xff;
15484 /* Writes wide_int values to dw_vec_const array. */
15487 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
15491 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
15493 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
15497 /* We'd have to extend this code to support odd sizes. */
15498 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
) == 0);
15500 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
15502 if (WORDS_BIG_ENDIAN
)
15503 for (i
= n
- 1; i
>= 0; i
--)
15505 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15506 dest
+= sizeof (HOST_WIDE_INT
);
15509 for (i
= 0; i
< n
; i
++)
15511 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15512 dest
+= sizeof (HOST_WIDE_INT
);
15516 /* Writes floating point values to dw_vec_const array. */
15519 insert_float (const_rtx rtl
, unsigned char *array
)
15521 REAL_VALUE_TYPE rv
;
15525 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
15526 real_to_target (val
, &rv
, GET_MODE (rtl
));
15528 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15529 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
15531 insert_int (val
[i
], 4, array
);
15536 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15537 does not have a "location" either in memory or in a register. These
15538 things can arise in GNU C when a constant is passed as an actual parameter
15539 to an inlined function. They can also arise in C++ where declared
15540 constants do not necessarily get memory "homes". */
15543 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
15545 switch (GET_CODE (rtl
))
15549 HOST_WIDE_INT val
= INTVAL (rtl
);
15552 add_AT_int (die
, DW_AT_const_value
, val
);
15554 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15558 case CONST_WIDE_INT
:
15559 add_AT_wide (die
, DW_AT_const_value
,
15560 std::make_pair (rtl
, GET_MODE (rtl
)));
15564 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15565 floating-point constant. A CONST_DOUBLE is used whenever the
15566 constant requires more than one word in order to be adequately
15569 machine_mode mode
= GET_MODE (rtl
);
15571 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
15572 add_AT_double (die
, DW_AT_const_value
,
15573 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15576 unsigned int length
= GET_MODE_SIZE (mode
);
15577 unsigned char *array
= ggc_vec_alloc
<unsigned char> (length
);
15579 insert_float (rtl
, array
);
15580 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15587 machine_mode mode
= GET_MODE (rtl
);
15588 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15589 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15590 unsigned char *array
15591 = ggc_vec_alloc
<unsigned char> (length
* elt_size
);
15594 machine_mode imode
= GET_MODE_INNER (mode
);
15596 switch (GET_MODE_CLASS (mode
))
15598 case MODE_VECTOR_INT
:
15599 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15601 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15602 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
15606 case MODE_VECTOR_FLOAT
:
15607 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15609 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15610 insert_float (elt
, p
);
15615 gcc_unreachable ();
15618 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15623 if (dwarf_version
>= 4 || !dwarf_strict
)
15625 dw_loc_descr_ref loc_result
;
15626 resolve_one_addr (&rtl
);
15628 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15629 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15630 add_AT_loc (die
, DW_AT_location
, loc_result
);
15631 vec_safe_push (used_rtx_array
, rtl
);
15637 if (CONSTANT_P (XEXP (rtl
, 0)))
15638 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15641 if (!const_ok_for_output (rtl
))
15644 if (dwarf_version
>= 4 || !dwarf_strict
)
15649 /* In cases where an inlined instance of an inline function is passed
15650 the address of an `auto' variable (which is local to the caller) we
15651 can get a situation where the DECL_RTL of the artificial local
15652 variable (for the inlining) which acts as a stand-in for the
15653 corresponding formal parameter (of the inline function) will look
15654 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15655 exactly a compile-time constant expression, but it isn't the address
15656 of the (artificial) local variable either. Rather, it represents the
15657 *value* which the artificial local variable always has during its
15658 lifetime. We currently have no way to represent such quasi-constant
15659 values in Dwarf, so for now we just punt and generate nothing. */
15667 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15668 && MEM_READONLY_P (rtl
)
15669 && GET_MODE (rtl
) == BLKmode
)
15671 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15677 /* No other kinds of rtx should be possible here. */
15678 gcc_unreachable ();
15683 /* Determine whether the evaluation of EXPR references any variables
15684 or functions which aren't otherwise used (and therefore may not be
15687 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15688 void * data ATTRIBUTE_UNUSED
)
15690 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15691 *walk_subtrees
= 0;
15693 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15694 && ! TREE_ASM_WRITTEN (*tp
))
15696 /* ??? The C++ FE emits debug information for using decls, so
15697 putting gcc_unreachable here falls over. See PR31899. For now
15698 be conservative. */
15699 else if (!symtab
->global_info_ready
15700 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15702 else if (TREE_CODE (*tp
) == VAR_DECL
)
15704 varpool_node
*node
= varpool_node::get (*tp
);
15705 if (!node
|| !node
->definition
)
15708 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15709 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15711 /* The call graph machinery must have finished analyzing,
15712 optimizing and gimplifying the CU by now.
15713 So if *TP has no call graph node associated
15714 to it, it means *TP will not be emitted. */
15715 if (!cgraph_node::get (*tp
))
15718 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15724 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15725 for use in a later add_const_value_attribute call. */
15728 rtl_for_decl_init (tree init
, tree type
)
15730 rtx rtl
= NULL_RTX
;
15734 /* If a variable is initialized with a string constant without embedded
15735 zeros, build CONST_STRING. */
15736 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15738 tree enttype
= TREE_TYPE (type
);
15739 tree domain
= TYPE_DOMAIN (type
);
15740 machine_mode mode
= TYPE_MODE (enttype
);
15742 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15744 && integer_zerop (TYPE_MIN_VALUE (domain
))
15745 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15746 TREE_STRING_LENGTH (init
) - 1) == 0
15747 && ((size_t) TREE_STRING_LENGTH (init
)
15748 == strlen (TREE_STRING_POINTER (init
)) + 1))
15750 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15751 ggc_strdup (TREE_STRING_POINTER (init
)));
15752 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15753 MEM_READONLY_P (rtl
) = 1;
15756 /* Other aggregates, and complex values, could be represented using
15758 else if (AGGREGATE_TYPE_P (type
)
15759 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15760 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15761 || TREE_CODE (type
) == COMPLEX_TYPE
)
15763 /* Vectors only work if their mode is supported by the target.
15764 FIXME: generic vectors ought to work too. */
15765 else if (TREE_CODE (type
) == VECTOR_TYPE
15766 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15768 /* If the initializer is something that we know will expand into an
15769 immediate RTL constant, expand it now. We must be careful not to
15770 reference variables which won't be output. */
15771 else if (initializer_constant_valid_p (init
, type
)
15772 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15774 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15776 if (TREE_CODE (type
) == VECTOR_TYPE
)
15777 switch (TREE_CODE (init
))
15782 if (TREE_CONSTANT (init
))
15784 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15785 bool constant_p
= true;
15787 unsigned HOST_WIDE_INT ix
;
15789 /* Even when ctor is constant, it might contain non-*_CST
15790 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15791 belong into VECTOR_CST nodes. */
15792 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15793 if (!CONSTANT_CLASS_P (value
))
15795 constant_p
= false;
15801 init
= build_vector_from_ctor (type
, elts
);
15811 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15813 /* If expand_expr returns a MEM, it wasn't immediate. */
15814 gcc_assert (!rtl
|| !MEM_P (rtl
));
15820 /* Generate RTL for the variable DECL to represent its location. */
15823 rtl_for_decl_location (tree decl
)
15827 /* Here we have to decide where we are going to say the parameter "lives"
15828 (as far as the debugger is concerned). We only have a couple of
15829 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15831 DECL_RTL normally indicates where the parameter lives during most of the
15832 activation of the function. If optimization is enabled however, this
15833 could be either NULL or else a pseudo-reg. Both of those cases indicate
15834 that the parameter doesn't really live anywhere (as far as the code
15835 generation parts of GCC are concerned) during most of the function's
15836 activation. That will happen (for example) if the parameter is never
15837 referenced within the function.
15839 We could just generate a location descriptor here for all non-NULL
15840 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15841 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15842 where DECL_RTL is NULL or is a pseudo-reg.
15844 Note however that we can only get away with using DECL_INCOMING_RTL as
15845 a backup substitute for DECL_RTL in certain limited cases. In cases
15846 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15847 we can be sure that the parameter was passed using the same type as it is
15848 declared to have within the function, and that its DECL_INCOMING_RTL
15849 points us to a place where a value of that type is passed.
15851 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15852 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15853 because in these cases DECL_INCOMING_RTL points us to a value of some
15854 type which is *different* from the type of the parameter itself. Thus,
15855 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15856 such cases, the debugger would end up (for example) trying to fetch a
15857 `float' from a place which actually contains the first part of a
15858 `double'. That would lead to really incorrect and confusing
15859 output at debug-time.
15861 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15862 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15863 are a couple of exceptions however. On little-endian machines we can
15864 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15865 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15866 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15867 when (on a little-endian machine) a non-prototyped function has a
15868 parameter declared to be of type `short' or `char'. In such cases,
15869 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15870 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15871 passed `int' value. If the debugger then uses that address to fetch
15872 a `short' or a `char' (on a little-endian machine) the result will be
15873 the correct data, so we allow for such exceptional cases below.
15875 Note that our goal here is to describe the place where the given formal
15876 parameter lives during most of the function's activation (i.e. between the
15877 end of the prologue and the start of the epilogue). We'll do that as best
15878 as we can. Note however that if the given formal parameter is modified
15879 sometime during the execution of the function, then a stack backtrace (at
15880 debug-time) will show the function as having been called with the *new*
15881 value rather than the value which was originally passed in. This happens
15882 rarely enough that it is not a major problem, but it *is* a problem, and
15883 I'd like to fix it.
15885 A future version of dwarf2out.c may generate two additional attributes for
15886 any given DW_TAG_formal_parameter DIE which will describe the "passed
15887 type" and the "passed location" for the given formal parameter in addition
15888 to the attributes we now generate to indicate the "declared type" and the
15889 "active location" for each parameter. This additional set of attributes
15890 could be used by debuggers for stack backtraces. Separately, note that
15891 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15892 This happens (for example) for inlined-instances of inline function formal
15893 parameters which are never referenced. This really shouldn't be
15894 happening. All PARM_DECL nodes should get valid non-NULL
15895 DECL_INCOMING_RTL values. FIXME. */
15897 /* Use DECL_RTL as the "location" unless we find something better. */
15898 rtl
= DECL_RTL_IF_SET (decl
);
15900 /* When generating abstract instances, ignore everything except
15901 constants, symbols living in memory, and symbols living in
15902 fixed registers. */
15903 if (! reload_completed
)
15906 && (CONSTANT_P (rtl
)
15908 && CONSTANT_P (XEXP (rtl
, 0)))
15910 && TREE_CODE (decl
) == VAR_DECL
15911 && TREE_STATIC (decl
))))
15913 rtl
= targetm
.delegitimize_address (rtl
);
15918 else if (TREE_CODE (decl
) == PARM_DECL
)
15920 if (rtl
== NULL_RTX
15921 || is_pseudo_reg (rtl
)
15923 && is_pseudo_reg (XEXP (rtl
, 0))
15924 && DECL_INCOMING_RTL (decl
)
15925 && MEM_P (DECL_INCOMING_RTL (decl
))
15926 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15928 tree declared_type
= TREE_TYPE (decl
);
15929 tree passed_type
= DECL_ARG_TYPE (decl
);
15930 machine_mode dmode
= TYPE_MODE (declared_type
);
15931 machine_mode pmode
= TYPE_MODE (passed_type
);
15933 /* This decl represents a formal parameter which was optimized out.
15934 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15935 all cases where (rtl == NULL_RTX) just below. */
15936 if (dmode
== pmode
)
15937 rtl
= DECL_INCOMING_RTL (decl
);
15938 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15939 && SCALAR_INT_MODE_P (dmode
)
15940 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15941 && DECL_INCOMING_RTL (decl
))
15943 rtx inc
= DECL_INCOMING_RTL (decl
);
15946 else if (MEM_P (inc
))
15948 if (BYTES_BIG_ENDIAN
)
15949 rtl
= adjust_address_nv (inc
, dmode
,
15950 GET_MODE_SIZE (pmode
)
15951 - GET_MODE_SIZE (dmode
));
15958 /* If the parm was passed in registers, but lives on the stack, then
15959 make a big endian correction if the mode of the type of the
15960 parameter is not the same as the mode of the rtl. */
15961 /* ??? This is the same series of checks that are made in dbxout.c before
15962 we reach the big endian correction code there. It isn't clear if all
15963 of these checks are necessary here, but keeping them all is the safe
15965 else if (MEM_P (rtl
)
15966 && XEXP (rtl
, 0) != const0_rtx
15967 && ! CONSTANT_P (XEXP (rtl
, 0))
15968 /* Not passed in memory. */
15969 && !MEM_P (DECL_INCOMING_RTL (decl
))
15970 /* Not passed by invisible reference. */
15971 && (!REG_P (XEXP (rtl
, 0))
15972 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15973 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15974 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15975 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15978 /* Big endian correction check. */
15979 && BYTES_BIG_ENDIAN
15980 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15981 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15984 machine_mode addr_mode
= get_address_mode (rtl
);
15985 int offset
= (UNITS_PER_WORD
15986 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15988 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15989 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15992 else if (TREE_CODE (decl
) == VAR_DECL
15995 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15996 && BYTES_BIG_ENDIAN
)
15998 machine_mode addr_mode
= get_address_mode (rtl
);
15999 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
16000 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
16002 /* If a variable is declared "register" yet is smaller than
16003 a register, then if we store the variable to memory, it
16004 looks like we're storing a register-sized value, when in
16005 fact we are not. We need to adjust the offset of the
16006 storage location to reflect the actual value's bytes,
16007 else gdb will not be able to display it. */
16009 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
16010 plus_constant (addr_mode
, XEXP (rtl
, 0),
16014 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
16015 and will have been substituted directly into all expressions that use it.
16016 C does not have such a concept, but C++ and other languages do. */
16017 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
16018 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
16021 rtl
= targetm
.delegitimize_address (rtl
);
16023 /* If we don't look past the constant pool, we risk emitting a
16024 reference to a constant pool entry that isn't referenced from
16025 code, and thus is not emitted. */
16027 rtl
= avoid_constant_pool_reference (rtl
);
16029 /* Try harder to get a rtl. If this symbol ends up not being emitted
16030 in the current CU, resolve_addr will remove the expression referencing
16032 if (rtl
== NULL_RTX
16033 && TREE_CODE (decl
) == VAR_DECL
16034 && !DECL_EXTERNAL (decl
)
16035 && TREE_STATIC (decl
)
16036 && DECL_NAME (decl
)
16037 && !DECL_HARD_REGISTER (decl
)
16038 && DECL_MODE (decl
) != VOIDmode
)
16040 rtl
= make_decl_rtl_for_debug (decl
);
16042 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
16043 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
16050 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
16051 returned. If so, the decl for the COMMON block is returned, and the
16052 value is the offset into the common block for the symbol. */
16055 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
16057 tree val_expr
, cvar
;
16059 HOST_WIDE_INT bitsize
, bitpos
;
16061 int unsignedp
, volatilep
= 0;
16063 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
16064 it does not have a value (the offset into the common area), or if it
16065 is thread local (as opposed to global) then it isn't common, and shouldn't
16066 be handled as such. */
16067 if (TREE_CODE (decl
) != VAR_DECL
16068 || !TREE_STATIC (decl
)
16069 || !DECL_HAS_VALUE_EXPR_P (decl
)
16073 val_expr
= DECL_VALUE_EXPR (decl
);
16074 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
16077 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
16078 &mode
, &unsignedp
, &volatilep
, true);
16080 if (cvar
== NULL_TREE
16081 || TREE_CODE (cvar
) != VAR_DECL
16082 || DECL_ARTIFICIAL (cvar
)
16083 || !TREE_PUBLIC (cvar
))
16087 if (offset
!= NULL
)
16089 if (!tree_fits_shwi_p (offset
))
16091 *value
= tree_to_shwi (offset
);
16094 *value
+= bitpos
/ BITS_PER_UNIT
;
16099 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
16100 data attribute for a variable or a parameter. We generate the
16101 DW_AT_const_value attribute only in those cases where the given variable
16102 or parameter does not have a true "location" either in memory or in a
16103 register. This can happen (for example) when a constant is passed as an
16104 actual argument in a call to an inline function. (It's possible that
16105 these things can crop up in other ways also.) Note that one type of
16106 constant value which can be passed into an inlined function is a constant
16107 pointer. This can happen for example if an actual argument in an inlined
16108 function call evaluates to a compile-time constant address.
16110 CACHE_P is true if it is worth caching the location list for DECL,
16111 so that future calls can reuse it rather than regenerate it from scratch.
16112 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
16113 since we will need to refer to them each time the function is inlined. */
16116 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
16117 enum dwarf_attribute attr
)
16120 dw_loc_list_ref list
;
16121 var_loc_list
*loc_list
;
16122 cached_dw_loc_list
*cache
;
16124 if (TREE_CODE (decl
) == ERROR_MARK
)
16127 if (get_AT (die
, attr
))
16130 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
16131 || TREE_CODE (decl
) == RESULT_DECL
);
16133 /* Try to get some constant RTL for this decl, and use that as the value of
16136 rtl
= rtl_for_decl_location (decl
);
16137 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16138 && add_const_value_attribute (die
, rtl
))
16141 /* See if we have single element location list that is equivalent to
16142 a constant value. That way we are better to use add_const_value_attribute
16143 rather than expanding constant value equivalent. */
16144 loc_list
= lookup_decl_loc (decl
);
16147 && loc_list
->first
->next
== NULL
16148 && NOTE_P (loc_list
->first
->loc
)
16149 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
16150 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
16152 struct var_loc_node
*node
;
16154 node
= loc_list
->first
;
16155 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
16156 if (GET_CODE (rtl
) == EXPR_LIST
)
16157 rtl
= XEXP (rtl
, 0);
16158 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
16159 && add_const_value_attribute (die
, rtl
))
16162 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
16163 list several times. See if we've already cached the contents. */
16165 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
16169 cache
= cached_dw_loc_list_table
->find_with_hash (decl
, DECL_UID (decl
));
16171 list
= cache
->loc_list
;
16175 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2,
16177 /* It is usually worth caching this result if the decl is from
16178 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
16179 if (cache_p
&& list
&& list
->dw_loc_next
)
16181 cached_dw_loc_list
**slot
16182 = cached_dw_loc_list_table
->find_slot_with_hash (decl
,
16185 cache
= ggc_cleared_alloc
<cached_dw_loc_list
> ();
16186 cache
->decl_id
= DECL_UID (decl
);
16187 cache
->loc_list
= list
;
16193 add_AT_location_description (die
, attr
, list
);
16196 /* None of that worked, so it must not really have a location;
16197 try adding a constant value attribute from the DECL_INITIAL. */
16198 return tree_add_const_value_attribute_for_decl (die
, decl
);
16201 /* Helper function for tree_add_const_value_attribute. Natively encode
16202 initializer INIT into an array. Return true if successful. */
16205 native_encode_initializer (tree init
, unsigned char *array
, int size
)
16209 if (init
== NULL_TREE
)
16213 switch (TREE_CODE (init
))
16216 type
= TREE_TYPE (init
);
16217 if (TREE_CODE (type
) == ARRAY_TYPE
)
16219 tree enttype
= TREE_TYPE (type
);
16220 machine_mode mode
= TYPE_MODE (enttype
);
16222 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
16224 if (int_size_in_bytes (type
) != size
)
16226 if (size
> TREE_STRING_LENGTH (init
))
16228 memcpy (array
, TREE_STRING_POINTER (init
),
16229 TREE_STRING_LENGTH (init
));
16230 memset (array
+ TREE_STRING_LENGTH (init
),
16231 '\0', size
- TREE_STRING_LENGTH (init
));
16234 memcpy (array
, TREE_STRING_POINTER (init
), size
);
16239 type
= TREE_TYPE (init
);
16240 if (int_size_in_bytes (type
) != size
)
16242 if (TREE_CODE (type
) == ARRAY_TYPE
)
16244 HOST_WIDE_INT min_index
;
16245 unsigned HOST_WIDE_INT cnt
;
16246 int curpos
= 0, fieldsize
;
16247 constructor_elt
*ce
;
16249 if (TYPE_DOMAIN (type
) == NULL_TREE
16250 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
16253 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
16254 if (fieldsize
<= 0)
16257 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
16258 memset (array
, '\0', size
);
16259 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16261 tree val
= ce
->value
;
16262 tree index
= ce
->index
;
16264 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16265 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
16268 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
16273 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
16276 curpos
= pos
+ fieldsize
;
16277 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
16279 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
16280 - tree_to_shwi (TREE_OPERAND (index
, 0));
16281 while (count
-- > 0)
16284 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
16285 curpos
+= fieldsize
;
16288 gcc_assert (curpos
<= size
);
16292 else if (TREE_CODE (type
) == RECORD_TYPE
16293 || TREE_CODE (type
) == UNION_TYPE
)
16295 tree field
= NULL_TREE
;
16296 unsigned HOST_WIDE_INT cnt
;
16297 constructor_elt
*ce
;
16299 if (int_size_in_bytes (type
) != size
)
16302 if (TREE_CODE (type
) == RECORD_TYPE
)
16303 field
= TYPE_FIELDS (type
);
16305 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
16307 tree val
= ce
->value
;
16308 int pos
, fieldsize
;
16310 if (ce
->index
!= 0)
16316 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
16319 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
16320 && TYPE_DOMAIN (TREE_TYPE (field
))
16321 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
16323 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
16324 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
16326 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
16327 pos
= int_byte_position (field
);
16328 gcc_assert (pos
+ fieldsize
<= size
);
16330 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
16336 case VIEW_CONVERT_EXPR
:
16337 case NON_LVALUE_EXPR
:
16338 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
16340 return native_encode_expr (init
, array
, size
) == size
;
16344 /* Attach a DW_AT_const_value attribute to DIE. The value of the
16345 attribute is the const value T. */
16348 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
16351 tree type
= TREE_TYPE (t
);
16354 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
16358 gcc_assert (!DECL_P (init
));
16360 rtl
= rtl_for_decl_init (init
, type
);
16362 return add_const_value_attribute (die
, rtl
);
16363 /* If the host and target are sane, try harder. */
16364 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
16365 && initializer_constant_valid_p (init
, type
))
16367 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
16368 if (size
> 0 && (int) size
== size
)
16370 unsigned char *array
= ggc_cleared_vec_alloc
<unsigned char> (size
);
16372 if (native_encode_initializer (init
, array
, size
))
16374 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
16383 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16384 attribute is the const value of T, where T is an integral constant
16385 variable with static storage duration
16386 (so it can't be a PARM_DECL or a RESULT_DECL). */
16389 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
16393 || (TREE_CODE (decl
) != VAR_DECL
16394 && TREE_CODE (decl
) != CONST_DECL
)
16395 || (TREE_CODE (decl
) == VAR_DECL
16396 && !TREE_STATIC (decl
)))
16399 if (TREE_READONLY (decl
)
16400 && ! TREE_THIS_VOLATILE (decl
)
16401 && DECL_INITIAL (decl
))
16406 /* Don't add DW_AT_const_value if abstract origin already has one. */
16407 if (get_AT (var_die
, DW_AT_const_value
))
16410 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
16413 /* Convert the CFI instructions for the current function into a
16414 location list. This is used for DW_AT_frame_base when we targeting
16415 a dwarf2 consumer that does not support the dwarf3
16416 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16419 static dw_loc_list_ref
16420 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
16424 dw_loc_list_ref list
, *list_tail
;
16426 dw_cfa_location last_cfa
, next_cfa
;
16427 const char *start_label
, *last_label
, *section
;
16428 dw_cfa_location remember
;
16431 gcc_assert (fde
!= NULL
);
16433 section
= secname_for_decl (current_function_decl
);
16437 memset (&next_cfa
, 0, sizeof (next_cfa
));
16438 next_cfa
.reg
= INVALID_REGNUM
;
16439 remember
= next_cfa
;
16441 start_label
= fde
->dw_fde_begin
;
16443 /* ??? Bald assumption that the CIE opcode list does not contain
16444 advance opcodes. */
16445 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
16446 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16448 last_cfa
= next_cfa
;
16449 last_label
= start_label
;
16451 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
16453 /* If the first partition contained no CFI adjustments, the
16454 CIE opcodes apply to the whole first partition. */
16455 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16456 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
16457 list_tail
=&(*list_tail
)->dw_loc_next
;
16458 start_label
= last_label
= fde
->dw_fde_second_begin
;
16461 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
16463 switch (cfi
->dw_cfi_opc
)
16465 case DW_CFA_set_loc
:
16466 case DW_CFA_advance_loc1
:
16467 case DW_CFA_advance_loc2
:
16468 case DW_CFA_advance_loc4
:
16469 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16471 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16472 start_label
, last_label
, section
);
16474 list_tail
= &(*list_tail
)->dw_loc_next
;
16475 last_cfa
= next_cfa
;
16476 start_label
= last_label
;
16478 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
16481 case DW_CFA_advance_loc
:
16482 /* The encoding is complex enough that we should never emit this. */
16483 gcc_unreachable ();
16486 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16489 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
16491 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16493 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16494 start_label
, last_label
, section
);
16496 list_tail
= &(*list_tail
)->dw_loc_next
;
16497 last_cfa
= next_cfa
;
16498 start_label
= last_label
;
16500 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16501 start_label
, fde
->dw_fde_end
, section
);
16502 list_tail
= &(*list_tail
)->dw_loc_next
;
16503 start_label
= last_label
= fde
->dw_fde_second_begin
;
16507 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16509 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16510 start_label
, last_label
, section
);
16511 list_tail
= &(*list_tail
)->dw_loc_next
;
16512 start_label
= last_label
;
16515 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
16517 fde
->dw_fde_second_begin
16518 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
16521 if (list
&& list
->dw_loc_next
)
16527 /* Compute a displacement from the "steady-state frame pointer" to the
16528 frame base (often the same as the CFA), and store it in
16529 frame_pointer_fb_offset. OFFSET is added to the displacement
16530 before the latter is negated. */
16533 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
16537 #ifdef FRAME_POINTER_CFA_OFFSET
16538 reg
= frame_pointer_rtx
;
16539 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
16541 reg
= arg_pointer_rtx
;
16542 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16545 elim
= (ira_use_lra_p
16546 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16547 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16548 if (GET_CODE (elim
) == PLUS
)
16550 offset
+= INTVAL (XEXP (elim
, 1));
16551 elim
= XEXP (elim
, 0);
16554 frame_pointer_fb_offset
= -offset
;
16556 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16557 in which to eliminate. This is because it's stack pointer isn't
16558 directly accessible as a register within the ISA. To work around
16559 this, assume that while we cannot provide a proper value for
16560 frame_pointer_fb_offset, we won't need one either. */
16561 frame_pointer_fb_offset_valid
16562 = ((SUPPORTS_STACK_ALIGNMENT
16563 && (elim
== hard_frame_pointer_rtx
16564 || elim
== stack_pointer_rtx
))
16565 || elim
== (frame_pointer_needed
16566 ? hard_frame_pointer_rtx
16567 : stack_pointer_rtx
));
16570 /* Generate a DW_AT_name attribute given some string value to be included as
16571 the value of the attribute. */
16574 add_name_attribute (dw_die_ref die
, const char *name_string
)
16576 if (name_string
!= NULL
&& *name_string
!= 0)
16578 if (demangle_name_func
)
16579 name_string
= (*demangle_name_func
) (name_string
);
16581 add_AT_string (die
, DW_AT_name
, name_string
);
16585 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16586 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16587 of TYPE accordingly.
16589 ??? This is a temporary measure until after we're able to generate
16590 regular DWARF for the complex Ada type system. */
16593 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16594 dw_die_ref context_die
)
16597 dw_die_ref dtype_die
;
16599 if (!lang_hooks
.types
.descriptive_type
)
16602 dtype
= lang_hooks
.types
.descriptive_type (type
);
16606 dtype_die
= lookup_type_die (dtype
);
16609 gen_type_die (dtype
, context_die
);
16610 dtype_die
= lookup_type_die (dtype
);
16611 gcc_assert (dtype_die
);
16614 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16617 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16619 static const char *
16620 comp_dir_string (void)
16624 static const char *cached_wd
= NULL
;
16626 if (cached_wd
!= NULL
)
16629 wd
= get_src_pwd ();
16633 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16637 wdlen
= strlen (wd
);
16638 wd1
= ggc_vec_alloc
<char> (wdlen
+ 2);
16640 wd1
[wdlen
] = DIR_SEPARATOR
;
16641 wd1
[wdlen
+ 1] = 0;
16645 cached_wd
= remap_debug_filename (wd
);
16649 /* Generate a DW_AT_comp_dir attribute for DIE. */
16652 add_comp_dir_attribute (dw_die_ref die
)
16654 const char * wd
= comp_dir_string ();
16656 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16659 /* Given a tree node VALUE describing a scalar attribute ATTR (i.e. a bound, a
16660 pointer computation, ...), output a representation for that bound according
16661 to the accepted FORMS (see enum dw_scalar_form) and add it to DIE. See
16662 loc_list_from_tree for the meaning of CONTEXT. */
16665 add_scalar_info (dw_die_ref die
, enum dwarf_attribute attr
, tree value
,
16666 int forms
, const struct loc_descr_context
*context
)
16668 dw_die_ref ctx
, decl_die
;
16669 dw_loc_list_ref list
;
16671 bool strip_conversions
= true;
16673 while (strip_conversions
)
16674 switch (TREE_CODE (value
))
16681 case VIEW_CONVERT_EXPR
:
16682 value
= TREE_OPERAND (value
, 0);
16686 strip_conversions
= false;
16690 /* If possible and permitted, output the attribute as a constant. */
16691 if ((forms
& dw_scalar_form_constant
) != 0
16692 && TREE_CODE (value
) == INTEGER_CST
)
16694 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (value
));
16696 /* If HOST_WIDE_INT is big enough then represent the bound as
16697 a constant value. We need to choose a form based on
16698 whether the type is signed or unsigned. We cannot just
16699 call add_AT_unsigned if the value itself is positive
16700 (add_AT_unsigned might add the unsigned value encoded as
16701 DW_FORM_data[1248]). Some DWARF consumers will lookup the
16702 bounds type and then sign extend any unsigned values found
16703 for signed types. This is needed only for
16704 DW_AT_{lower,upper}_bound, since for most other attributes,
16705 consumers will treat DW_FORM_data[1248] as unsigned values,
16706 regardless of the underlying type. */
16707 if (prec
<= HOST_BITS_PER_WIDE_INT
16708 || tree_fits_uhwi_p (value
))
16710 if (TYPE_UNSIGNED (TREE_TYPE (value
)))
16711 add_AT_unsigned (die
, attr
, TREE_INT_CST_LOW (value
));
16713 add_AT_int (die
, attr
, TREE_INT_CST_LOW (value
));
16716 /* Otherwise represent the bound as an unsigned value with
16717 the precision of its type. The precision and signedness
16718 of the type will be necessary to re-interpret it
16720 add_AT_wide (die
, attr
, value
);
16724 /* Otherwise, if it's possible and permitted too, output a reference to
16726 if ((forms
& dw_scalar_form_reference
) != 0)
16728 tree decl
= NULL_TREE
;
16730 /* Some type attributes reference an outer type. For instance, the upper
16731 bound of an array may reference an embedding record (this happens in
16733 if (TREE_CODE (value
) == COMPONENT_REF
16734 && TREE_CODE (TREE_OPERAND (value
, 0)) == PLACEHOLDER_EXPR
16735 && TREE_CODE (TREE_OPERAND (value
, 1)) == FIELD_DECL
)
16736 decl
= TREE_OPERAND (value
, 1);
16738 else if (TREE_CODE (value
) == VAR_DECL
16739 || TREE_CODE (value
) == PARM_DECL
16740 || TREE_CODE (value
) == RESULT_DECL
)
16743 if (decl
!= NULL_TREE
)
16745 dw_die_ref decl_die
= lookup_decl_die (decl
);
16747 /* ??? Can this happen, or should the variable have been bound
16748 first? Probably it can, since I imagine that we try to create
16749 the types of parameters in the order in which they exist in
16750 the list, and won't have created a forward reference to a
16751 later parameter. */
16752 if (decl_die
!= NULL
)
16754 add_AT_die_ref (die
, attr
, decl_die
);
16760 /* Last chance: try to create a stack operation procedure to evaluate the
16761 value. Do nothing if even that is not possible or permitted. */
16762 if ((forms
& dw_scalar_form_exprloc
) == 0)
16765 list
= loc_list_from_tree (value
, 2, context
);
16766 if (list
== NULL
|| single_element_loc_list_p (list
))
16768 /* If this attribute is not a reference nor constant, it is
16769 a DWARF expression rather than location description. For that
16770 loc_list_from_tree (value, 0, &context) is needed. */
16771 dw_loc_list_ref list2
= loc_list_from_tree (value
, 0, context
);
16772 if (list2
&& single_element_loc_list_p (list2
))
16774 add_AT_loc (die
, attr
, list2
->expr
);
16779 /* If that failed to give a single element location list, fall back to
16780 outputting this as a reference... still if permitted. */
16781 if (list
== NULL
|| (forms
& dw_scalar_form_reference
) == 0)
16784 if (current_function_decl
== 0)
16785 ctx
= comp_unit_die ();
16787 ctx
= lookup_decl_die (current_function_decl
);
16789 decl_die
= new_die (DW_TAG_variable
, ctx
, value
);
16790 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16791 add_type_attribute (decl_die
, TREE_TYPE (value
), TYPE_QUAL_CONST
, ctx
);
16792 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16793 add_AT_die_ref (die
, attr
, decl_die
);
16796 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16800 lower_bound_default (void)
16802 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16808 case DW_LANG_C_plus_plus
:
16809 case DW_LANG_C_plus_plus_11
:
16810 case DW_LANG_C_plus_plus_14
:
16812 case DW_LANG_ObjC_plus_plus
:
16815 case DW_LANG_Fortran77
:
16816 case DW_LANG_Fortran90
:
16817 case DW_LANG_Fortran95
:
16818 case DW_LANG_Fortran03
:
16819 case DW_LANG_Fortran08
:
16823 case DW_LANG_Python
:
16824 return dwarf_version
>= 4 ? 0 : -1;
16825 case DW_LANG_Ada95
:
16826 case DW_LANG_Ada83
:
16827 case DW_LANG_Cobol74
:
16828 case DW_LANG_Cobol85
:
16829 case DW_LANG_Pascal83
:
16830 case DW_LANG_Modula2
:
16832 return dwarf_version
>= 4 ? 1 : -1;
16838 /* Given a tree node describing an array bound (either lower or upper) output
16839 a representation for that bound. */
16842 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
,
16843 tree bound
, const struct loc_descr_context
*context
)
16848 switch (TREE_CODE (bound
))
16850 /* Strip all conversions. */
16852 case VIEW_CONVERT_EXPR
:
16853 bound
= TREE_OPERAND (bound
, 0);
16856 /* All fixed-bounds are represented by INTEGER_CST nodes. Lower bounds
16857 are even omitted when they are the default. */
16859 /* If the value for this bound is the default one, we can even omit the
16861 if (bound_attr
== DW_AT_lower_bound
16862 && tree_fits_shwi_p (bound
)
16863 && (dflt
= lower_bound_default ()) != -1
16864 && tree_to_shwi (bound
) == dflt
)
16870 add_scalar_info (subrange_die
, bound_attr
, bound
,
16871 dw_scalar_form_constant
16872 | dw_scalar_form_exprloc
16873 | dw_scalar_form_reference
,
16879 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16880 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16881 Note that the block of subscript information for an array type also
16882 includes information about the element type of the given array type.
16884 This function reuses previously set type and bound information if
16888 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16890 unsigned dimension_number
;
16892 dw_die_ref child
= type_die
->die_child
;
16894 for (dimension_number
= 0;
16895 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16896 type
= TREE_TYPE (type
), dimension_number
++)
16898 tree domain
= TYPE_DOMAIN (type
);
16900 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16903 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16904 and (in GNU C only) variable bounds. Handle all three forms
16907 /* Find and reuse a previously generated DW_TAG_subrange_type if
16910 For multi-dimensional arrays, as we iterate through the
16911 various dimensions in the enclosing for loop above, we also
16912 iterate through the DIE children and pick at each
16913 DW_TAG_subrange_type previously generated (if available).
16914 Each child DW_TAG_subrange_type DIE describes the range of
16915 the current dimension. At this point we should have as many
16916 DW_TAG_subrange_type's as we have dimensions in the
16918 dw_die_ref subrange_die
= NULL
;
16922 child
= child
->die_sib
;
16923 if (child
->die_tag
== DW_TAG_subrange_type
)
16924 subrange_die
= child
;
16925 if (child
== type_die
->die_child
)
16927 /* If we wrapped around, stop looking next time. */
16931 if (child
->die_tag
== DW_TAG_subrange_type
)
16935 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16939 /* We have an array type with specified bounds. */
16940 lower
= TYPE_MIN_VALUE (domain
);
16941 upper
= TYPE_MAX_VALUE (domain
);
16943 /* Define the index type. */
16944 if (TREE_TYPE (domain
)
16945 && !get_AT (subrange_die
, DW_AT_type
))
16947 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16948 TREE_TYPE field. We can't emit debug info for this
16949 because it is an unnamed integral type. */
16950 if (TREE_CODE (domain
) == INTEGER_TYPE
16951 && TYPE_NAME (domain
) == NULL_TREE
16952 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16953 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16956 add_type_attribute (subrange_die
, TREE_TYPE (domain
),
16957 TYPE_UNQUALIFIED
, type_die
);
16960 /* ??? If upper is NULL, the array has unspecified length,
16961 but it does have a lower bound. This happens with Fortran
16963 Since the debugger is definitely going to need to know N
16964 to produce useful results, go ahead and output the lower
16965 bound solo, and hope the debugger can cope. */
16967 if (!get_AT (subrange_die
, DW_AT_lower_bound
))
16968 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
, NULL
);
16969 if (upper
&& !get_AT (subrange_die
, DW_AT_upper_bound
))
16970 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
, NULL
);
16973 /* Otherwise we have an array type with an unspecified length. The
16974 DWARF-2 spec does not say how to handle this; let's just leave out the
16979 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
16982 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16984 dw_die_ref decl_die
;
16985 HOST_WIDE_INT size
;
16987 switch (TREE_CODE (tree_node
))
16992 case ENUMERAL_TYPE
:
16995 case QUAL_UNION_TYPE
:
16996 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16997 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16999 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
17002 size
= int_size_in_bytes (tree_node
);
17005 /* For a data member of a struct or union, the DW_AT_byte_size is
17006 generally given as the number of bytes normally allocated for an
17007 object of the *declared* type of the member itself. This is true
17008 even for bit-fields. */
17009 size
= int_size_in_bytes (field_type (tree_node
));
17012 gcc_unreachable ();
17015 /* Note that `size' might be -1 when we get to this point. If it is, that
17016 indicates that the byte size of the entity in question is variable. We
17017 have no good way of expressing this fact in Dwarf at the present time,
17018 when location description was not used by the caller code instead. */
17020 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
17023 /* For a FIELD_DECL node which represents a bit-field, output an attribute
17024 which specifies the distance in bits from the highest order bit of the
17025 "containing object" for the bit-field to the highest order bit of the
17028 For any given bit-field, the "containing object" is a hypothetical object
17029 (of some integral or enum type) within which the given bit-field lives. The
17030 type of this hypothetical "containing object" is always the same as the
17031 declared type of the individual bit-field itself. The determination of the
17032 exact location of the "containing object" for a bit-field is rather
17033 complicated. It's handled by the `field_byte_offset' function (above).
17035 Note that it is the size (in bytes) of the hypothetical "containing object"
17036 which will be given in the DW_AT_byte_size attribute for this bit-field.
17037 (See `byte_size_attribute' above). */
17040 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
17042 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
17043 tree type
= DECL_BIT_FIELD_TYPE (decl
);
17044 HOST_WIDE_INT bitpos_int
;
17045 HOST_WIDE_INT highest_order_object_bit_offset
;
17046 HOST_WIDE_INT highest_order_field_bit_offset
;
17047 HOST_WIDE_INT bit_offset
;
17049 /* Must be a field and a bit field. */
17050 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
17052 /* We can't yet handle bit-fields whose offsets are variable, so if we
17053 encounter such things, just return without generating any attribute
17054 whatsoever. Likewise for variable or too large size. */
17055 if (! tree_fits_shwi_p (bit_position (decl
))
17056 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
17059 bitpos_int
= int_bit_position (decl
);
17061 /* Note that the bit offset is always the distance (in bits) from the
17062 highest-order bit of the "containing object" to the highest-order bit of
17063 the bit-field itself. Since the "high-order end" of any object or field
17064 is different on big-endian and little-endian machines, the computation
17065 below must take account of these differences. */
17066 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
17067 highest_order_field_bit_offset
= bitpos_int
;
17069 if (! BYTES_BIG_ENDIAN
)
17071 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
17072 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
17076 = (! BYTES_BIG_ENDIAN
17077 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
17078 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
17080 if (bit_offset
< 0)
17081 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
17083 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
17086 /* For a FIELD_DECL node which represents a bit field, output an attribute
17087 which specifies the length in bits of the given field. */
17090 add_bit_size_attribute (dw_die_ref die
, tree decl
)
17092 /* Must be a field and a bit field. */
17093 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
17094 && DECL_BIT_FIELD_TYPE (decl
));
17096 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
17097 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
17100 /* If the compiled language is ANSI C, then add a 'prototyped'
17101 attribute, if arg types are given for the parameters of a function. */
17104 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
17106 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
17113 if (prototype_p (func_type
))
17114 add_AT_flag (die
, DW_AT_prototyped
, 1);
17121 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
17122 by looking in either the type declaration or object declaration
17125 static inline dw_die_ref
17126 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
17128 dw_die_ref origin_die
= NULL
;
17130 if (TREE_CODE (origin
) != FUNCTION_DECL
)
17132 /* We may have gotten separated from the block for the inlined
17133 function, if we're in an exception handler or some such; make
17134 sure that the abstract function has been written out.
17136 Doing this for nested functions is wrong, however; functions are
17137 distinct units, and our context might not even be inline. */
17141 fn
= TYPE_STUB_DECL (fn
);
17143 fn
= decl_function_context (fn
);
17145 dwarf2out_abstract_function (fn
);
17148 if (DECL_P (origin
))
17149 origin_die
= lookup_decl_die (origin
);
17150 else if (TYPE_P (origin
))
17151 origin_die
= lookup_type_die (origin
);
17153 /* XXX: Functions that are never lowered don't always have correct block
17154 trees (in the case of java, they simply have no block tree, in some other
17155 languages). For these functions, there is nothing we can really do to
17156 output correct debug info for inlined functions in all cases. Rather
17157 than die, we'll just produce deficient debug info now, in that we will
17158 have variables without a proper abstract origin. In the future, when all
17159 functions are lowered, we should re-add a gcc_assert (origin_die)
17163 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
17167 /* We do not currently support the pure_virtual attribute. */
17170 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
17172 if (DECL_VINDEX (func_decl
))
17174 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
17176 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
17177 add_AT_loc (die
, DW_AT_vtable_elem_location
,
17178 new_loc_descr (DW_OP_constu
,
17179 tree_to_shwi (DECL_VINDEX (func_decl
)),
17182 /* GNU extension: Record what type this method came from originally. */
17183 if (debug_info_level
> DINFO_LEVEL_TERSE
17184 && DECL_CONTEXT (func_decl
))
17185 add_AT_die_ref (die
, DW_AT_containing_type
,
17186 lookup_type_die (DECL_CONTEXT (func_decl
)));
17190 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
17191 given decl. This used to be a vendor extension until after DWARF 4
17192 standardized it. */
17195 add_linkage_attr (dw_die_ref die
, tree decl
)
17197 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
17199 /* Mimic what assemble_name_raw does with a leading '*'. */
17200 if (name
[0] == '*')
17203 if (dwarf_version
>= 4)
17204 add_AT_string (die
, DW_AT_linkage_name
, name
);
17206 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
17209 /* Add source coordinate attributes for the given decl. */
17212 add_src_coords_attributes (dw_die_ref die
, tree decl
)
17214 expanded_location s
;
17216 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
17218 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17219 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
17220 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
17223 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
17226 add_linkage_name (dw_die_ref die
, tree decl
)
17228 if (debug_info_level
> DINFO_LEVEL_NONE
17229 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
17230 && TREE_PUBLIC (decl
)
17231 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
17232 && die
->die_tag
!= DW_TAG_member
)
17234 /* Defer until we have an assembler name set. */
17235 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
17237 limbo_die_node
*asm_name
;
17239 asm_name
= ggc_cleared_alloc
<limbo_die_node
> ();
17240 asm_name
->die
= die
;
17241 asm_name
->created_for
= decl
;
17242 asm_name
->next
= deferred_asm_name
;
17243 deferred_asm_name
= asm_name
;
17245 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
17246 add_linkage_attr (die
, decl
);
17250 /* Add a DW_AT_name attribute and source coordinate attribute for the
17251 given decl, but only if it actually has a name. */
17254 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
17258 decl_name
= DECL_NAME (decl
);
17259 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
17261 const char *name
= dwarf2_name (decl
, 0);
17263 add_name_attribute (die
, name
);
17264 if (! DECL_ARTIFICIAL (decl
))
17265 add_src_coords_attributes (die
, decl
);
17267 add_linkage_name (die
, decl
);
17270 #ifdef VMS_DEBUGGING_INFO
17271 /* Get the function's name, as described by its RTL. This may be different
17272 from the DECL_NAME name used in the source file. */
17273 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
17275 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
17276 XEXP (DECL_RTL (decl
), 0), false);
17277 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
17279 #endif /* VMS_DEBUGGING_INFO */
17282 #ifdef VMS_DEBUGGING_INFO
17283 /* Output the debug main pointer die for VMS */
17286 dwarf2out_vms_debug_main_pointer (void)
17288 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
17291 /* Allocate the VMS debug main subprogram die. */
17292 die
= ggc_cleared_alloc
<die_node
> ();
17293 die
->die_tag
= DW_TAG_subprogram
;
17294 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
17295 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
17296 current_function_funcdef_no
);
17297 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
17299 /* Make it the first child of comp_unit_die (). */
17300 die
->die_parent
= comp_unit_die ();
17301 if (comp_unit_die ()->die_child
)
17303 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
17304 comp_unit_die ()->die_child
->die_sib
= die
;
17308 die
->die_sib
= die
;
17309 comp_unit_die ()->die_child
= die
;
17312 #endif /* VMS_DEBUGGING_INFO */
17314 /* Push a new declaration scope. */
17317 push_decl_scope (tree scope
)
17319 vec_safe_push (decl_scope_table
, scope
);
17322 /* Pop a declaration scope. */
17325 pop_decl_scope (void)
17327 decl_scope_table
->pop ();
17330 /* walk_tree helper function for uses_local_type, below. */
17333 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
17336 *walk_subtrees
= 0;
17339 tree name
= TYPE_NAME (*tp
);
17340 if (name
&& DECL_P (name
) && decl_function_context (name
))
17346 /* If TYPE involves a function-local type (including a local typedef to a
17347 non-local type), returns that type; otherwise returns NULL_TREE. */
17350 uses_local_type (tree type
)
17352 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
17356 /* Return the DIE for the scope that immediately contains this type.
17357 Non-named types that do not involve a function-local type get global
17358 scope. Named types nested in namespaces or other types get their
17359 containing scope. All other types (i.e. function-local named types) get
17360 the current active scope. */
17363 scope_die_for (tree t
, dw_die_ref context_die
)
17365 dw_die_ref scope_die
= NULL
;
17366 tree containing_scope
;
17368 /* Non-types always go in the current scope. */
17369 gcc_assert (TYPE_P (t
));
17371 /* Use the scope of the typedef, rather than the scope of the type
17373 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
17374 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
17376 containing_scope
= TYPE_CONTEXT (t
);
17378 /* Use the containing namespace if there is one. */
17379 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
17381 if (context_die
== lookup_decl_die (containing_scope
))
17383 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
17384 context_die
= get_context_die (containing_scope
);
17386 containing_scope
= NULL_TREE
;
17389 /* Ignore function type "scopes" from the C frontend. They mean that
17390 a tagged type is local to a parmlist of a function declarator, but
17391 that isn't useful to DWARF. */
17392 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
17393 containing_scope
= NULL_TREE
;
17395 if (SCOPE_FILE_SCOPE_P (containing_scope
))
17397 /* If T uses a local type keep it local as well, to avoid references
17398 to function-local DIEs from outside the function. */
17399 if (current_function_decl
&& uses_local_type (t
))
17400 scope_die
= context_die
;
17402 scope_die
= comp_unit_die ();
17404 else if (TYPE_P (containing_scope
))
17406 /* For types, we can just look up the appropriate DIE. */
17407 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17408 scope_die
= get_context_die (containing_scope
);
17411 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
17412 if (scope_die
== NULL
)
17413 scope_die
= comp_unit_die ();
17417 scope_die
= context_die
;
17422 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
17425 local_scope_p (dw_die_ref context_die
)
17427 for (; context_die
; context_die
= context_die
->die_parent
)
17428 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
17429 || context_die
->die_tag
== DW_TAG_subprogram
)
17435 /* Returns nonzero if CONTEXT_DIE is a class. */
17438 class_scope_p (dw_die_ref context_die
)
17440 return (context_die
17441 && (context_die
->die_tag
== DW_TAG_structure_type
17442 || context_die
->die_tag
== DW_TAG_class_type
17443 || context_die
->die_tag
== DW_TAG_interface_type
17444 || context_die
->die_tag
== DW_TAG_union_type
));
17447 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
17448 whether or not to treat a DIE in this context as a declaration. */
17451 class_or_namespace_scope_p (dw_die_ref context_die
)
17453 return (class_scope_p (context_die
)
17454 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
17457 /* Many forms of DIEs require a "type description" attribute. This
17458 routine locates the proper "type descriptor" die for the type given
17459 by 'type' plus any additional qualifiers given by 'cv_quals', and
17460 adds a DW_AT_type attribute below the given die. */
17463 add_type_attribute (dw_die_ref object_die
, tree type
, int cv_quals
,
17464 dw_die_ref context_die
)
17466 enum tree_code code
= TREE_CODE (type
);
17467 dw_die_ref type_die
= NULL
;
17469 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17470 or fixed-point type, use the inner type. This is because we have no
17471 support for unnamed types in base_type_die. This can happen if this is
17472 an Ada subrange type. Correct solution is emit a subrange type die. */
17473 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
17474 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
17475 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
17477 if (code
== ERROR_MARK
17478 /* Handle a special case. For functions whose return type is void, we
17479 generate *no* type attribute. (Note that no object may have type
17480 `void', so this only applies to function return types). */
17481 || code
== VOID_TYPE
)
17484 type_die
= modified_type_die (type
,
17485 cv_quals
| TYPE_QUALS_NO_ADDR_SPACE (type
),
17488 if (type_die
!= NULL
)
17489 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
17492 /* Given an object die, add the calling convention attribute for the
17493 function call type. */
17495 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
17497 enum dwarf_calling_convention value
= DW_CC_normal
;
17499 value
= ((enum dwarf_calling_convention
)
17500 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
17503 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
17505 /* DWARF 2 doesn't provide a way to identify a program's source-level
17506 entry point. DW_AT_calling_convention attributes are only meant
17507 to describe functions' calling conventions. However, lacking a
17508 better way to signal the Fortran main program, we used this for
17509 a long time, following existing custom. Now, DWARF 4 has
17510 DW_AT_main_subprogram, which we add below, but some tools still
17511 rely on the old way, which we thus keep. */
17512 value
= DW_CC_program
;
17514 if (dwarf_version
>= 4 || !dwarf_strict
)
17515 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
17518 /* Only add the attribute if the backend requests it, and
17519 is not DW_CC_normal. */
17520 if (value
&& (value
!= DW_CC_normal
))
17521 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
17524 /* Given a tree pointer to a struct, class, union, or enum type node, return
17525 a pointer to the (string) tag name for the given type, or zero if the type
17526 was declared without a tag. */
17528 static const char *
17529 type_tag (const_tree type
)
17531 const char *name
= 0;
17533 if (TYPE_NAME (type
) != 0)
17537 /* Find the IDENTIFIER_NODE for the type name. */
17538 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
17539 && !TYPE_NAMELESS (type
))
17540 t
= TYPE_NAME (type
);
17542 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17543 a TYPE_DECL node, regardless of whether or not a `typedef' was
17545 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
17546 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
17548 /* We want to be extra verbose. Don't call dwarf_name if
17549 DECL_NAME isn't set. The default hook for decl_printable_name
17550 doesn't like that, and in this context it's correct to return
17551 0, instead of "<anonymous>" or the like. */
17552 if (DECL_NAME (TYPE_NAME (type
))
17553 && !DECL_NAMELESS (TYPE_NAME (type
)))
17554 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
17557 /* Now get the name as a string, or invent one. */
17558 if (!name
&& t
!= 0)
17559 name
= IDENTIFIER_POINTER (t
);
17562 return (name
== 0 || *name
== '\0') ? 0 : name
;
17565 /* Return the type associated with a data member, make a special check
17566 for bit field types. */
17569 member_declared_type (const_tree member
)
17571 return (DECL_BIT_FIELD_TYPE (member
)
17572 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
17575 /* Get the decl's label, as described by its RTL. This may be different
17576 from the DECL_NAME name used in the source file. */
17579 static const char *
17580 decl_start_label (tree decl
)
17583 const char *fnname
;
17585 x
= DECL_RTL (decl
);
17586 gcc_assert (MEM_P (x
));
17589 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
17591 fnname
= XSTR (x
, 0);
17596 /* For variable-length arrays that have been previously generated, but
17597 may be incomplete due to missing subscript info, fill the subscript
17598 info. Return TRUE if this is one of those cases. */
17600 fill_variable_array_bounds (tree type
)
17602 if (TREE_ASM_WRITTEN (type
)
17603 && TREE_CODE (type
) == ARRAY_TYPE
17604 && variably_modified_type_p (type
, NULL
))
17606 dw_die_ref array_die
= lookup_type_die (type
);
17609 add_subscript_info (array_die
, type
, !is_ada ());
17615 /* These routines generate the internal representation of the DIE's for
17616 the compilation unit. Debugging information is collected by walking
17617 the declaration trees passed in from dwarf2out_decl(). */
17620 gen_array_type_die (tree type
, dw_die_ref context_die
)
17622 dw_die_ref array_die
;
17624 /* GNU compilers represent multidimensional array types as sequences of one
17625 dimensional array types whose element types are themselves array types.
17626 We sometimes squish that down to a single array_type DIE with multiple
17627 subscripts in the Dwarf debugging info. The draft Dwarf specification
17628 say that we are allowed to do this kind of compression in C, because
17629 there is no difference between an array of arrays and a multidimensional
17630 array. We don't do this for Ada to remain as close as possible to the
17631 actual representation, which is especially important against the language
17632 flexibilty wrt arrays of variable size. */
17634 bool collapse_nested_arrays
= !is_ada ();
17636 if (fill_variable_array_bounds (type
))
17639 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17642 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17643 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17644 if (TYPE_STRING_FLAG (type
)
17645 && TREE_CODE (type
) == ARRAY_TYPE
17647 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
17649 HOST_WIDE_INT size
;
17651 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
17652 add_name_attribute (array_die
, type_tag (type
));
17653 equate_type_number_to_die (type
, array_die
);
17654 size
= int_size_in_bytes (type
);
17656 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17657 else if (TYPE_DOMAIN (type
) != NULL_TREE
17658 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
17659 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
17661 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
17662 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2, NULL
);
17664 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
17665 if (loc
&& size
> 0)
17667 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
17668 if (size
!= DWARF2_ADDR_SIZE
)
17669 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17675 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17676 add_name_attribute (array_die
, type_tag (type
));
17677 equate_type_number_to_die (type
, array_die
);
17679 if (TREE_CODE (type
) == VECTOR_TYPE
)
17680 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
17682 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17684 && TREE_CODE (type
) == ARRAY_TYPE
17685 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17686 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17687 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17690 /* We default the array ordering. SDB will probably do
17691 the right things even if DW_AT_ordering is not present. It's not even
17692 an issue until we start to get into multidimensional arrays anyway. If
17693 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17694 then we'll have to put the DW_AT_ordering attribute back in. (But if
17695 and when we find out that we need to put these in, we will only do so
17696 for multidimensional arrays. */
17697 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17700 if (TREE_CODE (type
) == VECTOR_TYPE
)
17702 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17703 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17704 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
, NULL
);
17705 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17706 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1), NULL
);
17709 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17711 /* Add representation of the type of the elements of this array type and
17712 emit the corresponding DIE if we haven't done it already. */
17713 element_type
= TREE_TYPE (type
);
17714 if (collapse_nested_arrays
)
17715 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17717 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17719 element_type
= TREE_TYPE (element_type
);
17722 add_type_attribute (array_die
, element_type
, TYPE_UNQUALIFIED
, context_die
);
17724 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17725 if (TYPE_ARTIFICIAL (type
))
17726 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17728 if (get_AT (array_die
, DW_AT_name
))
17729 add_pubtype (type
, array_die
);
17732 /* This routine generates DIE for array with hidden descriptor, details
17733 are filled into *info by a langhook. */
17736 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17737 dw_die_ref context_die
)
17739 const dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17740 const dw_die_ref array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17741 const struct loc_descr_context context
= { type
, info
->base_decl
};
17744 add_name_attribute (array_die
, type_tag (type
));
17745 equate_type_number_to_die (type
, array_die
);
17747 if (info
->ndimensions
> 1)
17748 switch (info
->ordering
)
17750 case array_descr_ordering_row_major
:
17751 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17753 case array_descr_ordering_column_major
:
17754 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17760 if (dwarf_version
>= 3 || !dwarf_strict
)
17762 if (info
->data_location
)
17763 add_scalar_info (array_die
, DW_AT_data_location
, info
->data_location
,
17764 dw_scalar_form_exprloc
, &context
);
17765 if (info
->associated
)
17766 add_scalar_info (array_die
, DW_AT_associated
, info
->associated
,
17767 dw_scalar_form_constant
17768 | dw_scalar_form_exprloc
17769 | dw_scalar_form_reference
, &context
);
17770 if (info
->allocated
)
17771 add_scalar_info (array_die
, DW_AT_allocated
, info
->allocated
,
17772 dw_scalar_form_constant
17773 | dw_scalar_form_exprloc
17774 | dw_scalar_form_reference
, &context
);
17777 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17779 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17781 dw_die_ref subrange_die
17782 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17784 if (info
->dimen
[dim
].bounds_type
)
17785 add_type_attribute (subrange_die
,
17786 info
->dimen
[dim
].bounds_type
, 0,
17788 if (info
->dimen
[dim
].lower_bound
)
17789 add_bound_info (subrange_die
, DW_AT_lower_bound
,
17790 info
->dimen
[dim
].lower_bound
, &context
);
17791 if (info
->dimen
[dim
].upper_bound
)
17792 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17793 info
->dimen
[dim
].upper_bound
, &context
);
17794 if ((dwarf_version
>= 3 || !dwarf_strict
) && info
->dimen
[dim
].stride
)
17795 add_scalar_info (subrange_die
, DW_AT_byte_stride
,
17796 info
->dimen
[dim
].stride
,
17797 dw_scalar_form_constant
17798 | dw_scalar_form_exprloc
17799 | dw_scalar_form_reference
,
17803 gen_type_die (info
->element_type
, context_die
);
17804 add_type_attribute (array_die
, info
->element_type
, TYPE_UNQUALIFIED
,
17807 if (get_AT (array_die
, DW_AT_name
))
17808 add_pubtype (type
, array_die
);
17813 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17815 tree origin
= decl_ultimate_origin (decl
);
17816 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17818 if (origin
!= NULL
)
17819 add_abstract_origin_attribute (decl_die
, origin
);
17822 add_name_and_src_coords_attributes (decl_die
, decl
);
17823 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17824 TYPE_UNQUALIFIED
, context_die
);
17827 if (DECL_ABSTRACT_P (decl
))
17828 equate_decl_number_to_die (decl
, decl_die
);
17830 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17834 /* Walk through the list of incomplete types again, trying once more to
17835 emit full debugging info for them. */
17838 retry_incomplete_types (void)
17842 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17843 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17844 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17847 /* Determine what tag to use for a record type. */
17849 static enum dwarf_tag
17850 record_type_tag (tree type
)
17852 if (! lang_hooks
.types
.classify_record
)
17853 return DW_TAG_structure_type
;
17855 switch (lang_hooks
.types
.classify_record (type
))
17857 case RECORD_IS_STRUCT
:
17858 return DW_TAG_structure_type
;
17860 case RECORD_IS_CLASS
:
17861 return DW_TAG_class_type
;
17863 case RECORD_IS_INTERFACE
:
17864 if (dwarf_version
>= 3 || !dwarf_strict
)
17865 return DW_TAG_interface_type
;
17866 return DW_TAG_structure_type
;
17869 gcc_unreachable ();
17873 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17874 include all of the information about the enumeration values also. Each
17875 enumerated type name/value is listed as a child of the enumerated type
17879 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17881 dw_die_ref type_die
= lookup_type_die (type
);
17883 if (type_die
== NULL
)
17885 type_die
= new_die (DW_TAG_enumeration_type
,
17886 scope_die_for (type
, context_die
), type
);
17887 equate_type_number_to_die (type
, type_die
);
17888 add_name_attribute (type_die
, type_tag (type
));
17889 if (dwarf_version
>= 4 || !dwarf_strict
)
17891 if (ENUM_IS_SCOPED (type
))
17892 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17893 if (ENUM_IS_OPAQUE (type
))
17894 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17897 else if (! TYPE_SIZE (type
))
17900 remove_AT (type_die
, DW_AT_declaration
);
17902 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17903 given enum type is incomplete, do not generate the DW_AT_byte_size
17904 attribute or the DW_AT_element_list attribute. */
17905 if (TYPE_SIZE (type
))
17909 TREE_ASM_WRITTEN (type
) = 1;
17910 add_byte_size_attribute (type_die
, type
);
17911 if (dwarf_version
>= 3 || !dwarf_strict
)
17913 tree underlying
= lang_hooks
.types
.enum_underlying_base_type (type
);
17914 add_type_attribute (type_die
, underlying
, TYPE_UNQUALIFIED
,
17917 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17919 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17920 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17923 /* If the first reference to this type was as the return type of an
17924 inline function, then it may not have a parent. Fix this now. */
17925 if (type_die
->die_parent
== NULL
)
17926 add_child_die (scope_die_for (type
, context_die
), type_die
);
17928 for (link
= TYPE_VALUES (type
);
17929 link
!= NULL
; link
= TREE_CHAIN (link
))
17931 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17932 tree value
= TREE_VALUE (link
);
17934 add_name_attribute (enum_die
,
17935 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17937 if (TREE_CODE (value
) == CONST_DECL
)
17938 value
= DECL_INITIAL (value
);
17940 if (simple_type_size_in_bits (TREE_TYPE (value
))
17941 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
17943 /* For constant forms created by add_AT_unsigned DWARF
17944 consumers (GDB, elfutils, etc.) always zero extend
17945 the value. Only when the actual value is negative
17946 do we need to use add_AT_int to generate a constant
17947 form that can represent negative values. */
17948 HOST_WIDE_INT val
= TREE_INT_CST_LOW (value
);
17949 if (TYPE_UNSIGNED (TREE_TYPE (value
)) || val
>= 0)
17950 add_AT_unsigned (enum_die
, DW_AT_const_value
,
17951 (unsigned HOST_WIDE_INT
) val
);
17953 add_AT_int (enum_die
, DW_AT_const_value
, val
);
17956 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17957 that here. TODO: This should be re-worked to use correct
17958 signed/unsigned double tags for all cases. */
17959 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
17962 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17963 if (TYPE_ARTIFICIAL (type
))
17964 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17967 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17969 add_pubtype (type
, type_die
);
17974 /* Generate a DIE to represent either a real live formal parameter decl or to
17975 represent just the type of some formal parameter position in some function
17978 Note that this routine is a bit unusual because its argument may be a
17979 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17980 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17981 node. If it's the former then this function is being called to output a
17982 DIE to represent a formal parameter object (or some inlining thereof). If
17983 it's the latter, then this function is only being called to output a
17984 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17985 argument type of some subprogram type.
17986 If EMIT_NAME_P is true, name and source coordinate attributes
17990 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17991 dw_die_ref context_die
)
17993 tree node_or_origin
= node
? node
: origin
;
17994 tree ultimate_origin
;
17995 dw_die_ref parm_die
= NULL
;
17997 if (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)) == tcc_declaration
)
17999 parm_die
= lookup_decl_die (node
);
18001 /* If the contexts differ, we may not be talking about the same
18003 if (parm_die
&& parm_die
->die_parent
!= context_die
)
18005 if (!DECL_ABSTRACT_P (node
))
18007 /* This can happen when creating an inlined instance, in
18008 which case we need to create a new DIE that will get
18009 annotated with DW_AT_abstract_origin. */
18014 /* FIXME: Reuse DIE even with a differing context.
18016 This can happen when calling
18017 dwarf2out_abstract_function to build debug info for
18018 the abstract instance of a function for which we have
18019 already generated a DIE in
18020 dwarf2out_early_global_decl.
18022 Once we remove dwarf2out_abstract_function, we should
18023 have a call to gcc_unreachable here. */
18027 if (parm_die
&& parm_die
->die_parent
== NULL
)
18029 /* Check that parm_die already has the right attributes that
18030 we would have added below. If any attributes are
18031 missing, fall through to add them. */
18032 if (! DECL_ABSTRACT_P (node_or_origin
)
18033 && !get_AT (parm_die
, DW_AT_location
)
18034 && !get_AT (parm_die
, DW_AT_const_value
))
18035 /* We are missing location info, and are about to add it. */
18039 add_child_die (context_die
, parm_die
);
18045 /* If we have a previously generated DIE, use it, unless this is an
18046 concrete instance (origin != NULL), in which case we need a new
18047 DIE with a corresponding DW_AT_abstract_origin. */
18049 if (parm_die
&& origin
== NULL
)
18050 reusing_die
= true;
18053 parm_die
= new_die (DW_TAG_formal_parameter
, context_die
, node
);
18054 reusing_die
= false;
18057 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
18059 case tcc_declaration
:
18060 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
18061 if (node
|| ultimate_origin
)
18062 origin
= ultimate_origin
;
18067 if (origin
!= NULL
)
18068 add_abstract_origin_attribute (parm_die
, origin
);
18069 else if (emit_name_p
)
18070 add_name_and_src_coords_attributes (parm_die
, node
);
18072 || (! DECL_ABSTRACT_P (node_or_origin
)
18073 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
18074 decl_function_context
18075 (node_or_origin
))))
18077 tree type
= TREE_TYPE (node_or_origin
);
18078 if (decl_by_reference_p (node_or_origin
))
18079 add_type_attribute (parm_die
, TREE_TYPE (type
),
18080 TYPE_UNQUALIFIED
, context_die
);
18082 add_type_attribute (parm_die
, type
,
18083 decl_quals (node_or_origin
),
18086 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
18087 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18089 if (node
&& node
!= origin
)
18090 equate_decl_number_to_die (node
, parm_die
);
18091 if (! DECL_ABSTRACT_P (node_or_origin
))
18092 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
18093 node
== NULL
, DW_AT_location
);
18098 /* We were called with some kind of a ..._TYPE node. */
18099 add_type_attribute (parm_die
, node_or_origin
, TYPE_UNQUALIFIED
,
18104 gcc_unreachable ();
18110 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
18111 children DW_TAG_formal_parameter DIEs representing the arguments of the
18114 PARM_PACK must be a function parameter pack.
18115 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
18116 must point to the subsequent arguments of the function PACK_ARG belongs to.
18117 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
18118 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
18119 following the last one for which a DIE was generated. */
18122 gen_formal_parameter_pack_die (tree parm_pack
,
18124 dw_die_ref subr_die
,
18128 dw_die_ref parm_pack_die
;
18130 gcc_assert (parm_pack
18131 && lang_hooks
.function_parameter_pack_p (parm_pack
)
18134 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
18135 add_src_coords_attributes (parm_pack_die
, parm_pack
);
18137 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
18139 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
18142 gen_formal_parameter_die (arg
, NULL
,
18143 false /* Don't emit name attribute. */,
18148 return parm_pack_die
;
18151 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
18152 at the end of an (ANSI prototyped) formal parameters list. */
18155 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
18157 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
18160 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
18161 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
18162 parameters as specified in some function type specification (except for
18163 those which appear as part of a function *definition*). */
18166 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
18169 tree formal_type
= NULL
;
18170 tree first_parm_type
;
18173 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
18175 arg
= DECL_ARGUMENTS (function_or_method_type
);
18176 function_or_method_type
= TREE_TYPE (function_or_method_type
);
18181 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
18183 /* Make our first pass over the list of formal parameter types and output a
18184 DW_TAG_formal_parameter DIE for each one. */
18185 for (link
= first_parm_type
; link
; )
18187 dw_die_ref parm_die
;
18189 formal_type
= TREE_VALUE (link
);
18190 if (formal_type
== void_type_node
)
18193 /* Output a (nameless) DIE to represent the formal parameter itself. */
18194 if (!POINTER_BOUNDS_TYPE_P (formal_type
))
18196 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
18197 true /* Emit name attribute. */,
18199 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
18200 && link
== first_parm_type
)
18202 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18203 if (dwarf_version
>= 3 || !dwarf_strict
)
18204 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
18206 else if (arg
&& DECL_ARTIFICIAL (arg
))
18207 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
18210 link
= TREE_CHAIN (link
);
18212 arg
= DECL_CHAIN (arg
);
18215 /* If this function type has an ellipsis, add a
18216 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
18217 if (formal_type
!= void_type_node
)
18218 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
18220 /* Make our second (and final) pass over the list of formal parameter types
18221 and output DIEs to represent those types (as necessary). */
18222 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
18223 link
&& TREE_VALUE (link
);
18224 link
= TREE_CHAIN (link
))
18225 gen_type_die (TREE_VALUE (link
), context_die
);
18228 /* We want to generate the DIE for TYPE so that we can generate the
18229 die for MEMBER, which has been defined; we will need to refer back
18230 to the member declaration nested within TYPE. If we're trying to
18231 generate minimal debug info for TYPE, processing TYPE won't do the
18232 trick; we need to attach the member declaration by hand. */
18235 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
18237 gen_type_die (type
, context_die
);
18239 /* If we're trying to avoid duplicate debug info, we may not have
18240 emitted the member decl for this function. Emit it now. */
18241 if (TYPE_STUB_DECL (type
)
18242 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
18243 && ! lookup_decl_die (member
))
18245 dw_die_ref type_die
;
18246 gcc_assert (!decl_ultimate_origin (member
));
18248 push_decl_scope (type
);
18249 type_die
= lookup_type_die_strip_naming_typedef (type
);
18250 if (TREE_CODE (member
) == FUNCTION_DECL
)
18251 gen_subprogram_die (member
, type_die
);
18252 else if (TREE_CODE (member
) == FIELD_DECL
)
18254 /* Ignore the nameless fields that are used to skip bits but handle
18255 C++ anonymous unions and structs. */
18256 if (DECL_NAME (member
) != NULL_TREE
18257 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
18258 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
18260 gen_type_die (member_declared_type (member
), type_die
);
18261 gen_field_die (member
, type_die
);
18265 gen_variable_die (member
, NULL_TREE
, type_die
);
18271 /* Forward declare these functions, because they are mutually recursive
18272 with their set_block_* pairing functions. */
18273 static void set_decl_origin_self (tree
);
18274 static void set_decl_abstract_flags (tree
, vec
<tree
> &);
18276 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
18277 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
18278 that it points to the node itself, thus indicating that the node is its
18279 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
18280 the given node is NULL, recursively descend the decl/block tree which
18281 it is the root of, and for each other ..._DECL or BLOCK node contained
18282 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
18283 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
18284 values to point to themselves. */
18287 set_block_origin_self (tree stmt
)
18289 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
18291 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
18296 for (local_decl
= BLOCK_VARS (stmt
);
18297 local_decl
!= NULL_TREE
;
18298 local_decl
= DECL_CHAIN (local_decl
))
18299 /* Do not recurse on nested functions since the inlining status
18300 of parent and child can be different as per the DWARF spec. */
18301 if (TREE_CODE (local_decl
) != FUNCTION_DECL
18302 && !DECL_EXTERNAL (local_decl
))
18303 set_decl_origin_self (local_decl
);
18309 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
18310 subblock
!= NULL_TREE
;
18311 subblock
= BLOCK_CHAIN (subblock
))
18312 set_block_origin_self (subblock
); /* Recurse. */
18317 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
18318 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
18319 node to so that it points to the node itself, thus indicating that the
18320 node represents its own (abstract) origin. Additionally, if the
18321 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
18322 the decl/block tree of which the given node is the root of, and for
18323 each other ..._DECL or BLOCK node contained therein whose
18324 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
18325 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
18326 point to themselves. */
18329 set_decl_origin_self (tree decl
)
18331 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
18333 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
18334 if (TREE_CODE (decl
) == FUNCTION_DECL
)
18338 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
18339 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
18340 if (DECL_INITIAL (decl
) != NULL_TREE
18341 && DECL_INITIAL (decl
) != error_mark_node
)
18342 set_block_origin_self (DECL_INITIAL (decl
));
18347 /* Given a pointer to some BLOCK node, set the BLOCK_ABSTRACT flag to 1
18348 and if it wasn't 1 before, push it to abstract_vec vector.
18349 For all local decls and all local sub-blocks (recursively) do it
18353 set_block_abstract_flags (tree stmt
, vec
<tree
> &abstract_vec
)
18359 if (!BLOCK_ABSTRACT (stmt
))
18361 abstract_vec
.safe_push (stmt
);
18362 BLOCK_ABSTRACT (stmt
) = 1;
18365 for (local_decl
= BLOCK_VARS (stmt
);
18366 local_decl
!= NULL_TREE
;
18367 local_decl
= DECL_CHAIN (local_decl
))
18368 if (! DECL_EXTERNAL (local_decl
))
18369 set_decl_abstract_flags (local_decl
, abstract_vec
);
18371 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
18373 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
18374 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
18375 || TREE_CODE (local_decl
) == PARM_DECL
)
18376 set_decl_abstract_flags (local_decl
, abstract_vec
);
18379 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
18380 subblock
!= NULL_TREE
;
18381 subblock
= BLOCK_CHAIN (subblock
))
18382 set_block_abstract_flags (subblock
, abstract_vec
);
18385 /* Given a pointer to some ..._DECL node, set DECL_ABSTRACT_P flag on it
18386 to 1 and if it wasn't 1 before, push to abstract_vec vector.
18387 In the case where the decl is a FUNCTION_DECL also set the abstract
18388 flags for all of the parameters, local vars, local
18389 blocks and sub-blocks (recursively). */
18392 set_decl_abstract_flags (tree decl
, vec
<tree
> &abstract_vec
)
18394 if (!DECL_ABSTRACT_P (decl
))
18396 abstract_vec
.safe_push (decl
);
18397 DECL_ABSTRACT_P (decl
) = 1;
18400 if (TREE_CODE (decl
) == FUNCTION_DECL
)
18404 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
18405 if (!DECL_ABSTRACT_P (arg
))
18407 abstract_vec
.safe_push (arg
);
18408 DECL_ABSTRACT_P (arg
) = 1;
18410 if (DECL_INITIAL (decl
) != NULL_TREE
18411 && DECL_INITIAL (decl
) != error_mark_node
)
18412 set_block_abstract_flags (DECL_INITIAL (decl
), abstract_vec
);
18416 /* Generate the DWARF2 info for the "abstract" instance of a function which we
18417 may later generate inlined and/or out-of-line instances of.
18419 FIXME: In the early-dwarf world, this function, and most of the
18420 DECL_ABSTRACT code should be obsoleted. The early DIE _is_
18421 the abstract instance. All we would need to do is annotate
18422 the early DIE with the appropriate DW_AT_inline in late
18423 dwarf (perhaps in gen_inlined_subroutine_die).
18425 However, we can't do this yet, because LTO streaming of DIEs
18426 has not been implemented yet. */
18429 dwarf2out_abstract_function (tree decl
)
18431 dw_die_ref old_die
;
18434 hash_table
<decl_loc_hasher
> *old_decl_loc_table
;
18435 hash_table
<dw_loc_list_hasher
> *old_cached_dw_loc_list_table
;
18436 int old_call_site_count
, old_tail_call_site_count
;
18437 struct call_arg_loc_node
*old_call_arg_locations
;
18439 /* Make sure we have the actual abstract inline, not a clone. */
18440 decl
= DECL_ORIGIN (decl
);
18442 old_die
= lookup_decl_die (decl
);
18443 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
18444 /* We've already generated the abstract instance. */
18447 /* We can be called while recursively when seeing block defining inlined subroutine
18448 DIE. Be sure to not clobber the outer location table nor use it or we would
18449 get locations in abstract instantces. */
18450 old_decl_loc_table
= decl_loc_table
;
18451 decl_loc_table
= NULL
;
18452 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
18453 cached_dw_loc_list_table
= NULL
;
18454 old_call_arg_locations
= call_arg_locations
;
18455 call_arg_locations
= NULL
;
18456 old_call_site_count
= call_site_count
;
18457 call_site_count
= -1;
18458 old_tail_call_site_count
= tail_call_site_count
;
18459 tail_call_site_count
= -1;
18461 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
18462 we don't get confused by DECL_ABSTRACT_P. */
18463 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18465 context
= decl_class_context (decl
);
18467 gen_type_die_for_member
18468 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
18471 /* Pretend we've just finished compiling this function. */
18472 save_fn
= current_function_decl
;
18473 current_function_decl
= decl
;
18475 auto_vec
<tree
, 64> abstract_vec
;
18476 set_decl_abstract_flags (decl
, abstract_vec
);
18477 dwarf2out_decl (decl
);
18480 FOR_EACH_VEC_ELT (abstract_vec
, i
, t
)
18481 if (TREE_CODE (t
) == BLOCK
)
18482 BLOCK_ABSTRACT (t
) = 0;
18484 DECL_ABSTRACT_P (t
) = 0;
18486 current_function_decl
= save_fn
;
18487 decl_loc_table
= old_decl_loc_table
;
18488 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
18489 call_arg_locations
= old_call_arg_locations
;
18490 call_site_count
= old_call_site_count
;
18491 tail_call_site_count
= old_tail_call_site_count
;
18494 /* Helper function of premark_used_types() which gets called through
18497 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18498 marked as unused by prune_unused_types. */
18501 premark_used_types_helper (tree
const &type
, void *)
18505 die
= lookup_type_die (type
);
18507 die
->die_perennial_p
= 1;
18511 /* Helper function of premark_types_used_by_global_vars which gets called
18512 through htab_traverse.
18514 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18515 marked as unused by prune_unused_types. The DIE of the type is marked
18516 only if the global variable using the type will actually be emitted. */
18519 premark_types_used_by_global_vars_helper (types_used_by_vars_entry
**slot
,
18522 struct types_used_by_vars_entry
*entry
;
18525 entry
= (struct types_used_by_vars_entry
*) *slot
;
18526 gcc_assert (entry
->type
!= NULL
18527 && entry
->var_decl
!= NULL
);
18528 die
= lookup_type_die (entry
->type
);
18531 /* Ask cgraph if the global variable really is to be emitted.
18532 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18533 varpool_node
*node
= varpool_node::get (entry
->var_decl
);
18534 if (node
&& node
->definition
)
18536 die
->die_perennial_p
= 1;
18537 /* Keep the parent DIEs as well. */
18538 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18539 die
->die_perennial_p
= 1;
18545 /* Mark all members of used_types_hash as perennial. */
18548 premark_used_types (struct function
*fun
)
18550 if (fun
&& fun
->used_types_hash
)
18551 fun
->used_types_hash
->traverse
<void *, premark_used_types_helper
> (NULL
);
18554 /* Mark all members of types_used_by_vars_entry as perennial. */
18557 premark_types_used_by_global_vars (void)
18559 if (types_used_by_vars_hash
)
18560 types_used_by_vars_hash
18561 ->traverse
<void *, premark_types_used_by_global_vars_helper
> (NULL
);
18564 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18565 for CA_LOC call arg loc node. */
18568 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
18569 struct call_arg_loc_node
*ca_loc
)
18571 dw_die_ref stmt_die
= NULL
, die
;
18572 tree block
= ca_loc
->block
;
18575 && block
!= DECL_INITIAL (decl
)
18576 && TREE_CODE (block
) == BLOCK
)
18578 stmt_die
= BLOCK_DIE (block
);
18581 block
= BLOCK_SUPERCONTEXT (block
);
18583 if (stmt_die
== NULL
)
18584 stmt_die
= subr_die
;
18585 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
18586 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
18587 if (ca_loc
->tail_call_p
)
18588 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
18589 if (ca_loc
->symbol_ref
)
18591 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
18593 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
18595 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
18600 /* Generate a DIE to represent a declared function (either file-scope or
18604 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
18606 tree origin
= decl_ultimate_origin (decl
);
18607 dw_die_ref subr_die
;
18608 dw_die_ref old_die
= lookup_decl_die (decl
);
18610 /* This function gets called multiple times for different stages of
18611 the debug process. For example, for func() in this code:
18615 void func() { ... }
18618 ...we get called 4 times. Twice in early debug and twice in
18624 1. Once while generating func() within the namespace. This is
18625 the declaration. The declaration bit below is set, as the
18626 context is the namespace.
18628 A new DIE will be generated with DW_AT_declaration set.
18630 2. Once for func() itself. This is the specification. The
18631 declaration bit below is clear as the context is the CU.
18633 We will use the cached DIE from (1) to create a new DIE with
18634 DW_AT_specification pointing to the declaration in (1).
18636 Late debug via rest_of_handle_final()
18637 -------------------------------------
18639 3. Once generating func() within the namespace. This is also the
18640 declaration, as in (1), but this time we will early exit below
18641 as we have a cached DIE and a declaration needs no additional
18642 annotations (no locations), as the source declaration line
18645 4. Once for func() itself. As in (2), this is the specification,
18646 but this time we will re-use the cached DIE, and just annotate
18647 it with the location information that should now be available.
18649 For something without namespaces, but with abstract instances, we
18650 are also called a multiple times:
18655 Base (); // constructor declaration (1)
18658 Base::Base () { } // constructor specification (2)
18663 1. Once for the Base() constructor by virtue of it being a
18664 member of the Base class. This is done via
18665 rest_of_type_compilation.
18667 This is a declaration, so a new DIE will be created with
18670 2. Once for the Base() constructor definition, but this time
18671 while generating the abstract instance of the base
18672 constructor (__base_ctor) which is being generated via early
18673 debug of reachable functions.
18675 Even though we have a cached version of the declaration (1),
18676 we will create a DW_AT_specification of the declaration DIE
18679 3. Once for the __base_ctor itself, but this time, we generate
18680 an DW_AT_abstract_origin version of the DW_AT_specification in
18683 Late debug via rest_of_handle_final
18684 -----------------------------------
18686 4. One final time for the __base_ctor (which will have a cached
18687 DIE with DW_AT_abstract_origin created in (3). This time,
18688 we will just annotate the location information now
18691 int declaration
= (current_function_decl
!= decl
18692 || class_or_namespace_scope_p (context_die
));
18694 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
18696 /* Now that the C++ front end lazily declares artificial member fns, we
18697 might need to retrofit the declaration into its class. */
18698 if (!declaration
&& !origin
&& !old_die
18699 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
18700 && !class_or_namespace_scope_p (context_die
)
18701 && debug_info_level
> DINFO_LEVEL_TERSE
)
18702 old_die
= force_decl_die (decl
);
18704 /* An inlined instance, tag a new DIE with DW_AT_abstract_origin. */
18705 if (origin
!= NULL
)
18707 gcc_assert (!declaration
|| local_scope_p (context_die
));
18709 /* Fixup die_parent for the abstract instance of a nested
18710 inline function. */
18711 if (old_die
&& old_die
->die_parent
== NULL
)
18712 add_child_die (context_die
, old_die
);
18714 if (old_die
&& get_AT_ref (old_die
, DW_AT_abstract_origin
))
18716 /* If we have a DW_AT_abstract_origin we have a working
18718 subr_die
= old_die
;
18722 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18723 add_abstract_origin_attribute (subr_die
, origin
);
18724 /* This is where the actual code for a cloned function is.
18725 Let's emit linkage name attribute for it. This helps
18726 debuggers to e.g, set breakpoints into
18727 constructors/destructors when the user asks "break
18729 add_linkage_name (subr_die
, decl
);
18732 /* A cached copy, possibly from early dwarf generation. Reuse as
18733 much as possible. */
18736 /* A declaration that has been previously dumped needs no
18737 additional information. */
18741 if (!get_AT_flag (old_die
, DW_AT_declaration
)
18742 /* We can have a normal definition following an inline one in the
18743 case of redefinition of GNU C extern inlines.
18744 It seems reasonable to use AT_specification in this case. */
18745 && !get_AT (old_die
, DW_AT_inline
))
18747 /* Detect and ignore this case, where we are trying to output
18748 something we have already output. */
18749 if (get_AT (old_die
, DW_AT_low_pc
)
18750 || get_AT (old_die
, DW_AT_ranges
))
18753 /* If we have no location information, this must be a
18754 partially generated DIE from early dwarf generation.
18755 Fall through and generate it. */
18758 /* If the definition comes from the same place as the declaration,
18759 maybe use the old DIE. We always want the DIE for this function
18760 that has the *_pc attributes to be under comp_unit_die so the
18761 debugger can find it. We also need to do this for abstract
18762 instances of inlines, since the spec requires the out-of-line copy
18763 to have the same parent. For local class methods, this doesn't
18764 apply; we just use the old DIE. */
18765 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18766 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18767 if ((is_cu_die (old_die
->die_parent
)
18768 /* This condition fixes the inconsistency/ICE with the
18769 following Fortran test (or some derivative thereof) while
18770 building libgfortran:
18774 logical function funky (FLAG)
18779 || (old_die
->die_parent
18780 && old_die
->die_parent
->die_tag
== DW_TAG_module
)
18781 || context_die
== NULL
)
18782 && (DECL_ARTIFICIAL (decl
)
18783 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
18784 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
18785 == (unsigned) s
.line
))))
18787 subr_die
= old_die
;
18789 /* Clear out the declaration attribute, but leave the
18790 parameters so they can be augmented with location
18791 information later. Unless this was a declaration, in
18792 which case, wipe out the nameless parameters and recreate
18793 them further down. */
18794 if (remove_AT (subr_die
, DW_AT_declaration
))
18797 remove_AT (subr_die
, DW_AT_object_pointer
);
18798 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
18801 /* Make a specification pointing to the previously built
18805 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18806 add_AT_specification (subr_die
, old_die
);
18807 add_pubname (decl
, subr_die
);
18808 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18809 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18810 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18811 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18813 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
18814 emit the real type on the definition die. */
18815 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
18817 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
18818 if (die
== auto_die
|| die
== decltype_auto_die
)
18819 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18820 TYPE_UNQUALIFIED
, context_die
);
18824 /* Create a fresh DIE for anything else. */
18827 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18829 if (TREE_PUBLIC (decl
))
18830 add_AT_flag (subr_die
, DW_AT_external
, 1);
18832 add_name_and_src_coords_attributes (subr_die
, decl
);
18833 add_pubname (decl
, subr_die
);
18834 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18836 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18837 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18838 TYPE_UNQUALIFIED
, context_die
);
18841 add_pure_or_virtual_attribute (subr_die
, decl
);
18842 if (DECL_ARTIFICIAL (decl
))
18843 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18845 if (TREE_THIS_VOLATILE (decl
) && (dwarf_version
>= 5 || !dwarf_strict
))
18846 add_AT_flag (subr_die
, DW_AT_noreturn
, 1);
18848 add_accessibility_attribute (subr_die
, decl
);
18851 /* Unless we have an existing non-declaration DIE, equate the new
18853 if (!old_die
|| is_declaration_die (old_die
))
18854 equate_decl_number_to_die (decl
, subr_die
);
18858 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18860 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18862 /* If this is an explicit function declaration then generate
18863 a DW_AT_explicit attribute. */
18864 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18865 && (dwarf_version
>= 3 || !dwarf_strict
))
18866 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18868 /* If this is a C++11 deleted special function member then generate
18869 a DW_AT_GNU_deleted attribute. */
18870 if (lang_hooks
.decls
.function_decl_deleted_p (decl
)
18871 && (! dwarf_strict
))
18872 add_AT_flag (subr_die
, DW_AT_GNU_deleted
, 1);
18875 /* Tag abstract instances with DW_AT_inline. */
18876 else if (DECL_ABSTRACT_P (decl
))
18878 if (DECL_DECLARED_INLINE_P (decl
))
18880 if (cgraph_function_possibly_inlined_p (decl
))
18881 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18883 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18887 if (cgraph_function_possibly_inlined_p (decl
))
18888 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18890 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18893 if (DECL_DECLARED_INLINE_P (decl
)
18894 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18895 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18897 /* For non DECL_EXTERNALs, if range information is available, fill
18898 the DIE with it. */
18899 else if (!DECL_EXTERNAL (decl
) && !early_dwarf
)
18901 HOST_WIDE_INT cfa_fb_offset
;
18903 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18905 if (!flag_reorder_blocks_and_partition
)
18907 dw_fde_ref fde
= fun
->fde
;
18908 if (fde
->dw_fde_begin
)
18910 /* We have already generated the labels. */
18911 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18912 fde
->dw_fde_end
, false);
18916 /* Create start/end labels and add the range. */
18917 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18918 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18919 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18920 current_function_funcdef_no
);
18921 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18922 current_function_funcdef_no
);
18923 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18927 #if VMS_DEBUGGING_INFO
18928 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18929 Section 2.3 Prologue and Epilogue Attributes:
18930 When a breakpoint is set on entry to a function, it is generally
18931 desirable for execution to be suspended, not on the very first
18932 instruction of the function, but rather at a point after the
18933 function's frame has been set up, after any language defined local
18934 declaration processing has been completed, and before execution of
18935 the first statement of the function begins. Debuggers generally
18936 cannot properly determine where this point is. Similarly for a
18937 breakpoint set on exit from a function. The prologue and epilogue
18938 attributes allow a compiler to communicate the location(s) to use. */
18941 if (fde
->dw_fde_vms_end_prologue
)
18942 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18943 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18945 if (fde
->dw_fde_vms_begin_epilogue
)
18946 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18947 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18954 /* Generate pubnames entries for the split function code ranges. */
18955 dw_fde_ref fde
= fun
->fde
;
18957 if (fde
->dw_fde_second_begin
)
18959 if (dwarf_version
>= 3 || !dwarf_strict
)
18961 /* We should use ranges for non-contiguous code section
18962 addresses. Use the actual code range for the initial
18963 section, since the HOT/COLD labels might precede an
18964 alignment offset. */
18965 bool range_list_added
= false;
18966 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18967 fde
->dw_fde_end
, &range_list_added
,
18969 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18970 fde
->dw_fde_second_end
,
18971 &range_list_added
, false);
18972 if (range_list_added
)
18977 /* There is no real support in DW2 for this .. so we make
18978 a work-around. First, emit the pub name for the segment
18979 containing the function label. Then make and emit a
18980 simplified subprogram DIE for the second segment with the
18981 name pre-fixed by __hot/cold_sect_of_. We use the same
18982 linkage name for the second die so that gdb will find both
18983 sections when given "b foo". */
18984 const char *name
= NULL
;
18985 tree decl_name
= DECL_NAME (decl
);
18986 dw_die_ref seg_die
;
18988 /* Do the 'primary' section. */
18989 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18990 fde
->dw_fde_end
, false);
18992 /* Build a minimal DIE for the secondary section. */
18993 seg_die
= new_die (DW_TAG_subprogram
,
18994 subr_die
->die_parent
, decl
);
18996 if (TREE_PUBLIC (decl
))
18997 add_AT_flag (seg_die
, DW_AT_external
, 1);
18999 if (decl_name
!= NULL
19000 && IDENTIFIER_POINTER (decl_name
) != NULL
)
19002 name
= dwarf2_name (decl
, 1);
19003 if (! DECL_ARTIFICIAL (decl
))
19004 add_src_coords_attributes (seg_die
, decl
);
19006 add_linkage_name (seg_die
, decl
);
19008 gcc_assert (name
!= NULL
);
19009 add_pure_or_virtual_attribute (seg_die
, decl
);
19010 if (DECL_ARTIFICIAL (decl
))
19011 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
19013 name
= concat ("__second_sect_of_", name
, NULL
);
19014 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
19015 fde
->dw_fde_second_end
, false);
19016 add_name_attribute (seg_die
, name
);
19017 if (want_pubnames ())
19018 add_pubname_string (name
, seg_die
);
19022 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
19026 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
19028 /* We define the "frame base" as the function's CFA. This is more
19029 convenient for several reasons: (1) It's stable across the prologue
19030 and epilogue, which makes it better than just a frame pointer,
19031 (2) With dwarf3, there exists a one-byte encoding that allows us
19032 to reference the .debug_frame data by proxy, but failing that,
19033 (3) We can at least reuse the code inspection and interpretation
19034 code that determines the CFA position at various points in the
19036 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
19038 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
19039 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
19043 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
19044 if (list
->dw_loc_next
)
19045 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
19047 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
19050 /* Compute a displacement from the "steady-state frame pointer" to
19051 the CFA. The former is what all stack slots and argument slots
19052 will reference in the rtl; the latter is what we've told the
19053 debugger about. We'll need to adjust all frame_base references
19054 by this displacement. */
19055 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
19057 if (fun
->static_chain_decl
)
19058 add_AT_location_description
19059 (subr_die
, DW_AT_static_link
,
19060 loc_list_from_tree (fun
->static_chain_decl
, 2, NULL
));
19063 /* Generate child dies for template paramaters. */
19064 if (early_dwarf
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19065 gen_generic_params_dies (decl
);
19067 /* Now output descriptions of the arguments for this function. This gets
19068 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
19069 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
19070 `...' at the end of the formal parameter list. In order to find out if
19071 there was a trailing ellipsis or not, we must instead look at the type
19072 associated with the FUNCTION_DECL. This will be a node of type
19073 FUNCTION_TYPE. If the chain of type nodes hanging off of this
19074 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
19075 an ellipsis at the end. */
19077 /* In the case where we are describing a mere function declaration, all we
19078 need to do here (and all we *can* do here) is to describe the *types* of
19079 its formal parameters. */
19080 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19082 else if (declaration
)
19083 gen_formal_types_die (decl
, subr_die
);
19086 /* Generate DIEs to represent all known formal parameters. */
19087 tree parm
= DECL_ARGUMENTS (decl
);
19088 tree generic_decl
= early_dwarf
19089 ? lang_hooks
.decls
.get_generic_function_decl (decl
) : NULL
;
19090 tree generic_decl_parm
= generic_decl
19091 ? DECL_ARGUMENTS (generic_decl
)
19094 /* Now we want to walk the list of parameters of the function and
19095 emit their relevant DIEs.
19097 We consider the case of DECL being an instance of a generic function
19098 as well as it being a normal function.
19100 If DECL is an instance of a generic function we walk the
19101 parameters of the generic function declaration _and_ the parameters of
19102 DECL itself. This is useful because we want to emit specific DIEs for
19103 function parameter packs and those are declared as part of the
19104 generic function declaration. In that particular case,
19105 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
19106 That DIE has children DIEs representing the set of arguments
19107 of the pack. Note that the set of pack arguments can be empty.
19108 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
19111 Otherwise, we just consider the parameters of DECL. */
19112 while (generic_decl_parm
|| parm
)
19114 if (generic_decl_parm
19115 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
19116 gen_formal_parameter_pack_die (generic_decl_parm
,
19119 else if (parm
&& !POINTER_BOUNDS_P (parm
))
19121 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
19123 if (parm
== DECL_ARGUMENTS (decl
)
19124 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
19126 && (dwarf_version
>= 3 || !dwarf_strict
))
19127 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
19129 parm
= DECL_CHAIN (parm
);
19132 parm
= DECL_CHAIN (parm
);
19134 if (generic_decl_parm
)
19135 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
19138 /* Decide whether we need an unspecified_parameters DIE at the end.
19139 There are 2 more cases to do this for: 1) the ansi ... declaration -
19140 this is detectable when the end of the arg list is not a
19141 void_type_node 2) an unprototyped function declaration (not a
19142 definition). This just means that we have no info about the
19143 parameters at all. */
19144 if (prototype_p (TREE_TYPE (decl
)))
19146 /* This is the prototyped case, check for.... */
19147 if (stdarg_p (TREE_TYPE (decl
)))
19148 gen_unspecified_parameters_die (decl
, subr_die
);
19150 else if (DECL_INITIAL (decl
) == NULL_TREE
)
19151 gen_unspecified_parameters_die (decl
, subr_die
);
19154 if (subr_die
!= old_die
)
19155 /* Add the calling convention attribute if requested. */
19156 add_calling_convention_attribute (subr_die
, decl
);
19158 /* Output Dwarf info for all of the stuff within the body of the function
19159 (if it has one - it may be just a declaration).
19161 OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
19162 a function. This BLOCK actually represents the outermost binding contour
19163 for the function, i.e. the contour in which the function's formal
19164 parameters and labels get declared. Curiously, it appears that the front
19165 end doesn't actually put the PARM_DECL nodes for the current function onto
19166 the BLOCK_VARS list for this outer scope, but are strung off of the
19167 DECL_ARGUMENTS list for the function instead.
19169 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
19170 the LABEL_DECL nodes for the function however, and we output DWARF info
19171 for those in decls_for_scope. Just within the `outer_scope' there will be
19172 a BLOCK node representing the function's outermost pair of curly braces,
19173 and any blocks used for the base and member initializers of a C++
19174 constructor function. */
19175 tree outer_scope
= DECL_INITIAL (decl
);
19176 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
19178 int call_site_note_count
= 0;
19179 int tail_call_site_note_count
= 0;
19181 /* Emit a DW_TAG_variable DIE for a named return value. */
19182 if (DECL_NAME (DECL_RESULT (decl
)))
19183 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
19185 /* The first time through decls_for_scope we will generate the
19186 DIEs for the locals. The second time, we fill in the
19188 decls_for_scope (outer_scope
, subr_die
);
19190 if (call_arg_locations
&& !dwarf_strict
)
19192 struct call_arg_loc_node
*ca_loc
;
19193 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
19195 dw_die_ref die
= NULL
;
19196 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
19199 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
19200 arg
; arg
= next_arg
)
19202 dw_loc_descr_ref reg
, val
;
19203 machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
19204 dw_die_ref cdie
, tdie
= NULL
;
19206 next_arg
= XEXP (arg
, 1);
19207 if (REG_P (XEXP (XEXP (arg
, 0), 0))
19209 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
19210 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
19211 && REGNO (XEXP (XEXP (arg
, 0), 0))
19212 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
19213 next_arg
= XEXP (next_arg
, 1);
19214 if (mode
== VOIDmode
)
19216 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
19217 if (mode
== VOIDmode
)
19218 mode
= GET_MODE (XEXP (arg
, 0));
19220 if (mode
== VOIDmode
|| mode
== BLKmode
)
19222 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
19224 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19225 tloc
= XEXP (XEXP (arg
, 0), 1);
19228 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
19229 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
19231 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
19232 tlocc
= XEXP (XEXP (arg
, 0), 1);
19236 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
19237 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
19238 VAR_INIT_STATUS_INITIALIZED
);
19239 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
19241 rtx mem
= XEXP (XEXP (arg
, 0), 0);
19242 reg
= mem_loc_descriptor (XEXP (mem
, 0),
19243 get_address_mode (mem
),
19245 VAR_INIT_STATUS_INITIALIZED
);
19247 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
19248 == DEBUG_PARAMETER_REF
)
19251 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
19252 tdie
= lookup_decl_die (tdecl
);
19259 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
19260 != DEBUG_PARAMETER_REF
)
19262 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
19264 VAR_INIT_STATUS_INITIALIZED
);
19268 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19269 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
19272 add_AT_loc (cdie
, DW_AT_location
, reg
);
19273 else if (tdie
!= NULL
)
19274 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
19275 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
19276 if (next_arg
!= XEXP (arg
, 1))
19278 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
19279 if (mode
== VOIDmode
)
19280 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
19281 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
19284 VAR_INIT_STATUS_INITIALIZED
);
19286 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
19290 && (ca_loc
->symbol_ref
|| tloc
))
19291 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
19292 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
19294 dw_loc_descr_ref tval
= NULL
;
19296 if (tloc
!= NULL_RTX
)
19297 tval
= mem_loc_descriptor (tloc
,
19298 GET_MODE (tloc
) == VOIDmode
19299 ? Pmode
: GET_MODE (tloc
),
19301 VAR_INIT_STATUS_INITIALIZED
);
19303 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
19304 else if (tlocc
!= NULL_RTX
)
19306 tval
= mem_loc_descriptor (tlocc
,
19307 GET_MODE (tlocc
) == VOIDmode
19308 ? Pmode
: GET_MODE (tlocc
),
19310 VAR_INIT_STATUS_INITIALIZED
);
19312 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
19318 call_site_note_count
++;
19319 if (ca_loc
->tail_call_p
)
19320 tail_call_site_note_count
++;
19324 call_arg_locations
= NULL
;
19325 call_arg_loc_last
= NULL
;
19326 if (tail_call_site_count
>= 0
19327 && tail_call_site_count
== tail_call_site_note_count
19330 if (call_site_count
>= 0
19331 && call_site_count
== call_site_note_count
)
19332 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
19334 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
19336 call_site_count
= -1;
19337 tail_call_site_count
= -1;
19341 /* Returns a hash value for X (which really is a die_struct). */
19344 block_die_hasher::hash (die_struct
*d
)
19346 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
19349 /* Return nonzero if decl_id and die_parent of die_struct X is the same
19350 as decl_id and die_parent of die_struct Y. */
19353 block_die_hasher::equal (die_struct
*x
, die_struct
*y
)
19355 return x
->decl_id
== y
->decl_id
&& x
->die_parent
== y
->die_parent
;
19358 /* Return TRUE if DECL, which may have been previously generated as
19359 OLD_DIE, is a candidate for a DW_AT_specification. DECLARATION is
19360 true if decl (or its origin) is either an extern declaration or a
19361 class/namespace scoped declaration.
19363 The declare_in_namespace support causes us to get two DIEs for one
19364 variable, both of which are declarations. We want to avoid
19365 considering one to be a specification, so we must test for
19366 DECLARATION and DW_AT_declaration. */
19368 decl_will_get_specification_p (dw_die_ref old_die
, tree decl
, bool declaration
)
19370 return (old_die
&& TREE_STATIC (decl
) && !declaration
19371 && get_AT_flag (old_die
, DW_AT_declaration
) == 1);
19374 /* Return true if DECL is a local static. */
19377 local_function_static (tree decl
)
19379 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
19380 return TREE_STATIC (decl
)
19381 && DECL_CONTEXT (decl
)
19382 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
;
19385 /* Generate a DIE to represent a declared data object.
19386 Either DECL or ORIGIN must be non-null. */
19389 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
19391 HOST_WIDE_INT off
= 0;
19393 tree decl_or_origin
= decl
? decl
: origin
;
19394 tree ultimate_origin
;
19395 dw_die_ref var_die
;
19396 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
19397 dw_die_ref origin_die
= NULL
;
19398 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
19399 || class_or_namespace_scope_p (context_die
));
19400 bool specialization_p
= false;
19402 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
19403 if (decl
|| ultimate_origin
)
19404 origin
= ultimate_origin
;
19405 com_decl
= fortran_common (decl_or_origin
, &off
);
19407 /* Symbol in common gets emitted as a child of the common block, in the form
19408 of a data member. */
19411 dw_die_ref com_die
;
19412 dw_loc_list_ref loc
;
19413 die_node com_die_arg
;
19415 var_die
= lookup_decl_die (decl_or_origin
);
19418 if (get_AT (var_die
, DW_AT_location
) == NULL
)
19420 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2, NULL
);
19425 /* Optimize the common case. */
19426 if (single_element_loc_list_p (loc
)
19427 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19428 && loc
->expr
->dw_loc_next
== NULL
19429 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
19432 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
19433 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19434 = plus_constant (GET_MODE (x
), x
, off
);
19437 loc_list_plus_const (loc
, off
);
19439 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19440 remove_AT (var_die
, DW_AT_declaration
);
19446 if (common_block_die_table
== NULL
)
19447 common_block_die_table
= hash_table
<block_die_hasher
>::create_ggc (10);
19449 com_die_arg
.decl_id
= DECL_UID (com_decl
);
19450 com_die_arg
.die_parent
= context_die
;
19451 com_die
= common_block_die_table
->find (&com_die_arg
);
19452 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19453 if (com_die
== NULL
)
19456 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
19459 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
19460 add_name_and_src_coords_attributes (com_die
, com_decl
);
19463 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19464 /* Avoid sharing the same loc descriptor between
19465 DW_TAG_common_block and DW_TAG_variable. */
19466 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19468 else if (DECL_EXTERNAL (decl
))
19469 add_AT_flag (com_die
, DW_AT_declaration
, 1);
19470 if (want_pubnames ())
19471 add_pubname_string (cnam
, com_die
); /* ??? needed? */
19472 com_die
->decl_id
= DECL_UID (com_decl
);
19473 slot
= common_block_die_table
->find_slot (com_die
, INSERT
);
19476 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
19478 add_AT_location_description (com_die
, DW_AT_location
, loc
);
19479 loc
= loc_list_from_tree (com_decl
, 2, NULL
);
19480 remove_AT (com_die
, DW_AT_declaration
);
19482 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
19483 add_name_and_src_coords_attributes (var_die
, decl
);
19484 add_type_attribute (var_die
, TREE_TYPE (decl
), decl_quals (decl
),
19486 add_AT_flag (var_die
, DW_AT_external
, 1);
19491 /* Optimize the common case. */
19492 if (single_element_loc_list_p (loc
)
19493 && loc
->expr
->dw_loc_opc
== DW_OP_addr
19494 && loc
->expr
->dw_loc_next
== NULL
19495 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
19497 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
19498 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
19499 = plus_constant (GET_MODE (x
), x
, off
);
19502 loc_list_plus_const (loc
, off
);
19504 add_AT_location_description (var_die
, DW_AT_location
, loc
);
19506 else if (DECL_EXTERNAL (decl
))
19507 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19508 equate_decl_number_to_die (decl
, var_die
);
19516 /* A declaration that has been previously dumped, needs no
19517 further annotations, since it doesn't need location on
19518 the second pass. */
19521 else if (decl_will_get_specification_p (old_die
, decl
, declaration
)
19522 && !get_AT (old_die
, DW_AT_specification
))
19524 /* Fall-thru so we can make a new variable die along with a
19525 DW_AT_specification. */
19527 else if (origin
&& old_die
->die_parent
!= context_die
)
19529 /* If we will be creating an inlined instance, we need a
19530 new DIE that will get annotated with
19531 DW_AT_abstract_origin. Clear things so we can get a
19533 gcc_assert (!DECL_ABSTRACT_P (decl
));
19538 /* If a DIE was dumped early, it still needs location info.
19539 Skip to where we fill the location bits. */
19541 goto gen_variable_die_location
;
19545 /* For static data members, the declaration in the class is supposed
19546 to have DW_TAG_member tag; the specification should still be
19547 DW_TAG_variable referencing the DW_TAG_member DIE. */
19548 if (declaration
&& class_scope_p (context_die
))
19549 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
19551 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
19553 if (origin
!= NULL
)
19554 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
19556 /* Loop unrolling can create multiple blocks that refer to the same
19557 static variable, so we must test for the DW_AT_declaration flag.
19559 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
19560 copy decls and set the DECL_ABSTRACT_P flag on them instead of
19563 ??? Duplicated blocks have been rewritten to use .debug_ranges. */
19564 else if (decl_will_get_specification_p (old_die
, decl
, declaration
))
19566 /* This is a definition of a C++ class level static. */
19567 add_AT_specification (var_die
, old_die
);
19568 specialization_p
= true;
19569 if (DECL_NAME (decl
))
19571 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
19572 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
19574 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
19575 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
19577 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
19578 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
19580 if (old_die
->die_tag
== DW_TAG_member
)
19581 add_linkage_name (var_die
, decl
);
19585 add_name_and_src_coords_attributes (var_die
, decl
);
19587 if ((origin
== NULL
&& !specialization_p
)
19589 && !DECL_ABSTRACT_P (decl_or_origin
)
19590 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
19591 decl_function_context
19592 (decl_or_origin
))))
19594 tree type
= TREE_TYPE (decl_or_origin
);
19596 if (decl_by_reference_p (decl_or_origin
))
19597 add_type_attribute (var_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19600 add_type_attribute (var_die
, type
, decl_quals (decl_or_origin
),
19604 if (origin
== NULL
&& !specialization_p
)
19606 if (TREE_PUBLIC (decl
))
19607 add_AT_flag (var_die
, DW_AT_external
, 1);
19609 if (DECL_ARTIFICIAL (decl
))
19610 add_AT_flag (var_die
, DW_AT_artificial
, 1);
19612 add_accessibility_attribute (var_die
, decl
);
19616 add_AT_flag (var_die
, DW_AT_declaration
, 1);
19618 if (decl
&& (DECL_ABSTRACT_P (decl
)
19619 || !old_die
|| is_declaration_die (old_die
)))
19620 equate_decl_number_to_die (decl
, var_die
);
19622 gen_variable_die_location
:
19624 && (! DECL_ABSTRACT_P (decl_or_origin
)
19625 /* Local static vars are shared between all clones/inlines,
19626 so emit DW_AT_location on the abstract DIE if DECL_RTL is
19628 || (TREE_CODE (decl_or_origin
) == VAR_DECL
19629 && TREE_STATIC (decl_or_origin
)
19630 && DECL_RTL_SET_P (decl_or_origin
)))
19631 /* When abstract origin already has DW_AT_location attribute, no need
19632 to add it again. */
19633 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
19636 add_pubname (decl_or_origin
, var_die
);
19638 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
19639 decl
== NULL
, DW_AT_location
);
19642 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
19645 /* Generate a DIE to represent a named constant. */
19648 gen_const_die (tree decl
, dw_die_ref context_die
)
19650 dw_die_ref const_die
;
19651 tree type
= TREE_TYPE (decl
);
19653 const_die
= lookup_decl_die (decl
);
19657 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
19658 equate_decl_number_to_die (decl
, const_die
);
19659 add_name_and_src_coords_attributes (const_die
, decl
);
19660 add_type_attribute (const_die
, type
, TYPE_QUAL_CONST
, context_die
);
19661 if (TREE_PUBLIC (decl
))
19662 add_AT_flag (const_die
, DW_AT_external
, 1);
19663 if (DECL_ARTIFICIAL (decl
))
19664 add_AT_flag (const_die
, DW_AT_artificial
, 1);
19665 tree_add_const_value_attribute_for_decl (const_die
, decl
);
19668 /* Generate a DIE to represent a label identifier. */
19671 gen_label_die (tree decl
, dw_die_ref context_die
)
19673 tree origin
= decl_ultimate_origin (decl
);
19674 dw_die_ref lbl_die
= lookup_decl_die (decl
);
19676 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19680 lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
19681 equate_decl_number_to_die (decl
, lbl_die
);
19683 if (origin
!= NULL
)
19684 add_abstract_origin_attribute (lbl_die
, origin
);
19686 add_name_and_src_coords_attributes (lbl_die
, decl
);
19689 if (DECL_ABSTRACT_P (decl
))
19690 equate_decl_number_to_die (decl
, lbl_die
);
19693 insn
= DECL_RTL_IF_SET (decl
);
19695 /* Deleted labels are programmer specified labels which have been
19696 eliminated because of various optimizations. We still emit them
19697 here so that it is possible to put breakpoints on them. */
19701 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
19703 /* When optimization is enabled (via -O) some parts of the compiler
19704 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19705 represent source-level labels which were explicitly declared by
19706 the user. This really shouldn't be happening though, so catch
19707 it if it ever does happen. */
19708 gcc_assert (!as_a
<rtx_insn
*> (insn
)->deleted ());
19710 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19711 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19715 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
19716 && CODE_LABEL_NUMBER (insn
) != -1)
19718 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
19719 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19724 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19725 attributes to the DIE for a block STMT, to describe where the inlined
19726 function was called from. This is similar to add_src_coords_attributes. */
19729 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19731 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19733 if (dwarf_version
>= 3 || !dwarf_strict
)
19735 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19736 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19741 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19742 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19745 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19747 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19749 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19750 && (dwarf_version
>= 3 || !dwarf_strict
))
19752 tree chain
, superblock
= NULL_TREE
;
19754 dw_attr_ref attr
= NULL
;
19756 if (inlined_function_outer_scope_p (stmt
))
19758 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19759 BLOCK_NUMBER (stmt
));
19760 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19763 /* Optimize duplicate .debug_ranges lists or even tails of
19764 lists. If this BLOCK has same ranges as its supercontext,
19765 lookup DW_AT_ranges attribute in the supercontext (and
19766 recursively so), verify that the ranges_table contains the
19767 right values and use it instead of adding a new .debug_range. */
19768 for (chain
= stmt
, pdie
= die
;
19769 BLOCK_SAME_RANGE (chain
);
19770 chain
= BLOCK_SUPERCONTEXT (chain
))
19772 dw_attr_ref new_attr
;
19774 pdie
= pdie
->die_parent
;
19777 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
19779 new_attr
= get_AT (pdie
, DW_AT_ranges
);
19780 if (new_attr
== NULL
19781 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
19784 superblock
= BLOCK_SUPERCONTEXT (chain
);
19787 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
19788 / 2 / DWARF2_ADDR_SIZE
].num
19789 == BLOCK_NUMBER (superblock
))
19790 && BLOCK_FRAGMENT_CHAIN (superblock
))
19792 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
19793 / 2 / DWARF2_ADDR_SIZE
;
19794 unsigned long supercnt
= 0, thiscnt
= 0;
19795 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
19796 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19799 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
19800 == BLOCK_NUMBER (chain
));
19802 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
19803 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19804 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19806 gcc_assert (supercnt
>= thiscnt
);
19807 add_AT_range_list (die
, DW_AT_ranges
,
19808 ((off
+ supercnt
- thiscnt
)
19809 * 2 * DWARF2_ADDR_SIZE
),
19814 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
19816 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19819 add_ranges (chain
);
19820 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19827 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
19828 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19829 BLOCK_NUMBER (stmt
));
19830 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
19831 BLOCK_NUMBER (stmt
));
19832 add_AT_low_high_pc (die
, label
, label_high
, false);
19836 /* Generate a DIE for a lexical block. */
19839 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
)
19841 dw_die_ref old_die
= BLOCK_DIE (stmt
);
19842 dw_die_ref stmt_die
= NULL
;
19845 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19846 BLOCK_DIE (stmt
) = stmt_die
;
19849 if (BLOCK_ABSTRACT (stmt
))
19853 #ifdef ENABLE_CHECKING
19854 /* This must have been generated early and it won't even
19855 need location information since it's a DW_AT_inline
19857 for (dw_die_ref c
= context_die
; c
; c
= c
->die_parent
)
19858 if (c
->die_tag
== DW_TAG_inlined_subroutine
19859 || c
->die_tag
== DW_TAG_subprogram
)
19861 gcc_assert (get_AT (c
, DW_AT_inline
));
19868 else if (BLOCK_ABSTRACT_ORIGIN (stmt
))
19870 /* If this is an inlined instance, create a new lexical die for
19871 anything below to attach DW_AT_abstract_origin to. */
19874 stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19875 BLOCK_DIE (stmt
) = stmt_die
;
19881 stmt_die
= old_die
;
19883 /* A non abstract block whose blocks have already been reordered
19884 should have the instruction range for this block. If so, set the
19885 high/low attributes. */
19886 if (!early_dwarf
&& !BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19888 gcc_assert (stmt_die
);
19889 add_high_low_attributes (stmt
, stmt_die
);
19892 decls_for_scope (stmt
, stmt_die
);
19895 /* Generate a DIE for an inlined subprogram. */
19898 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
)
19902 /* The instance of function that is effectively being inlined shall not
19904 gcc_assert (! BLOCK_ABSTRACT (stmt
));
19906 decl
= block_ultimate_origin (stmt
);
19908 /* Emit info for the abstract instance first, if we haven't yet. We
19909 must emit this even if the block is abstract, otherwise when we
19910 emit the block below (or elsewhere), we may end up trying to emit
19911 a die whose origin die hasn't been emitted, and crashing. */
19912 dwarf2out_abstract_function (decl
);
19914 if (! BLOCK_ABSTRACT (stmt
))
19916 dw_die_ref subr_die
19917 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
19919 if (call_arg_locations
)
19920 BLOCK_DIE (stmt
) = subr_die
;
19921 add_abstract_origin_attribute (subr_die
, decl
);
19922 if (TREE_ASM_WRITTEN (stmt
))
19923 add_high_low_attributes (stmt
, subr_die
);
19924 add_call_src_coords_attributes (stmt
, subr_die
);
19926 decls_for_scope (stmt
, subr_die
);
19930 /* Generate a DIE for a field in a record, or structure. */
19933 gen_field_die (tree decl
, dw_die_ref context_die
)
19935 dw_die_ref decl_die
;
19937 if (TREE_TYPE (decl
) == error_mark_node
)
19940 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19941 add_name_and_src_coords_attributes (decl_die
, decl
);
19942 add_type_attribute (decl_die
, member_declared_type (decl
),
19943 decl_quals (decl
), context_die
);
19945 if (DECL_BIT_FIELD_TYPE (decl
))
19947 add_byte_size_attribute (decl_die
, decl
);
19948 add_bit_size_attribute (decl_die
, decl
);
19949 add_bit_offset_attribute (decl_die
, decl
);
19952 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19953 add_data_member_location_attribute (decl_die
, decl
);
19955 if (DECL_ARTIFICIAL (decl
))
19956 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19958 add_accessibility_attribute (decl_die
, decl
);
19960 /* Equate decl number to die, so that we can look up this decl later on. */
19961 equate_decl_number_to_die (decl
, decl_die
);
19965 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19966 Use modified_type_die instead.
19967 We keep this code here just in case these types of DIEs may be needed to
19968 represent certain things in other languages (e.g. Pascal) someday. */
19971 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19974 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19976 equate_type_number_to_die (type
, ptr_die
);
19977 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
19979 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19982 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19983 Use modified_type_die instead.
19984 We keep this code here just in case these types of DIEs may be needed to
19985 represent certain things in other languages (e.g. Pascal) someday. */
19988 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19990 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19992 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19993 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19995 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19997 equate_type_number_to_die (type
, ref_die
);
19998 add_type_attribute (ref_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
20000 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
20004 /* Generate a DIE for a pointer to a member type. */
20007 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
20010 = new_die (DW_TAG_ptr_to_member_type
,
20011 scope_die_for (type
, context_die
), type
);
20013 equate_type_number_to_die (type
, ptr_die
);
20014 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
20015 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
20016 add_type_attribute (ptr_die
, TREE_TYPE (type
), TYPE_UNQUALIFIED
,
20020 typedef const char *dchar_p
; /* For DEF_VEC_P. */
20022 static char *producer_string
;
20024 /* Return a heap allocated producer string including command line options
20025 if -grecord-gcc-switches. */
20028 gen_producer_string (void)
20031 auto_vec
<dchar_p
> switches
;
20032 const char *language_string
= lang_hooks
.name
;
20033 char *producer
, *tail
;
20035 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
20036 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
20038 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
20039 switch (save_decoded_options
[j
].opt_index
)
20046 case OPT_auxbase_strip
:
20055 case OPT_SPECIAL_unknown
:
20056 case OPT_SPECIAL_ignore
:
20057 case OPT_SPECIAL_program_name
:
20058 case OPT_SPECIAL_input_file
:
20059 case OPT_grecord_gcc_switches
:
20060 case OPT_gno_record_gcc_switches
:
20061 case OPT__output_pch_
:
20062 case OPT_fdiagnostics_show_location_
:
20063 case OPT_fdiagnostics_show_option
:
20064 case OPT_fdiagnostics_show_caret
:
20065 case OPT_fdiagnostics_color_
:
20066 case OPT_fverbose_asm
:
20068 case OPT__sysroot_
:
20070 case OPT_nostdinc__
:
20071 case OPT_fpreprocessed
:
20072 case OPT_fltrans_output_list_
:
20073 case OPT_fresolution_
:
20074 /* Ignore these. */
20077 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
20078 & CL_NO_DWARF_RECORD
)
20080 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
20082 switch (save_decoded_options
[j
].canonical_option
[0][1])
20089 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
20096 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
20097 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
20101 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
20103 sprintf (tail
, "%s %s", language_string
, version_string
);
20106 FOR_EACH_VEC_ELT (switches
, j
, p
)
20110 memcpy (tail
+ 1, p
, len
);
20118 /* Given a C and/or C++ language/version string return the "highest".
20119 C++ is assumed to be "higher" than C in this case. Used for merging
20120 LTO translation unit languages. */
20121 static const char *
20122 highest_c_language (const char *lang1
, const char *lang2
)
20124 if (strcmp ("GNU C++14", lang1
) == 0 || strcmp ("GNU C++14", lang2
) == 0)
20125 return "GNU C++14";
20126 if (strcmp ("GNU C++11", lang1
) == 0 || strcmp ("GNU C++11", lang2
) == 0)
20127 return "GNU C++11";
20128 if (strcmp ("GNU C++98", lang1
) == 0 || strcmp ("GNU C++98", lang2
) == 0)
20129 return "GNU C++98";
20131 if (strcmp ("GNU C11", lang1
) == 0 || strcmp ("GNU C11", lang2
) == 0)
20133 if (strcmp ("GNU C99", lang1
) == 0 || strcmp ("GNU C99", lang2
) == 0)
20135 if (strcmp ("GNU C89", lang1
) == 0 || strcmp ("GNU C89", lang2
) == 0)
20138 gcc_unreachable ();
20142 /* Generate the DIE for the compilation unit. */
20145 gen_compile_unit_die (const char *filename
)
20148 const char *language_string
= lang_hooks
.name
;
20151 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
20155 add_name_attribute (die
, filename
);
20156 /* Don't add cwd for <built-in>. */
20157 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
20158 add_comp_dir_attribute (die
);
20161 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
20163 /* If our producer is LTO try to figure out a common language to use
20164 from the global list of translation units. */
20165 if (strcmp (language_string
, "GNU GIMPLE") == 0)
20169 const char *common_lang
= NULL
;
20171 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
20173 if (!TRANSLATION_UNIT_LANGUAGE (t
))
20176 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
20177 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
20179 else if (strncmp (common_lang
, "GNU C", 5) == 0
20180 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
20181 /* Mixing C and C++ is ok, use C++ in that case. */
20182 common_lang
= highest_c_language (common_lang
,
20183 TRANSLATION_UNIT_LANGUAGE (t
));
20186 /* Fall back to C. */
20187 common_lang
= NULL
;
20193 language_string
= common_lang
;
20196 language
= DW_LANG_C
;
20197 if (strncmp (language_string
, "GNU C", 5) == 0
20198 && ISDIGIT (language_string
[5]))
20200 language
= DW_LANG_C89
;
20201 if (dwarf_version
>= 3 || !dwarf_strict
)
20203 if (strcmp (language_string
, "GNU C89") != 0)
20204 language
= DW_LANG_C99
;
20206 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20207 if (strcmp (language_string
, "GNU C11") == 0)
20208 language
= DW_LANG_C11
;
20211 else if (strncmp (language_string
, "GNU C++", 7) == 0)
20213 language
= DW_LANG_C_plus_plus
;
20214 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20216 if (strcmp (language_string
, "GNU C++11") == 0)
20217 language
= DW_LANG_C_plus_plus_11
;
20218 else if (strcmp (language_string
, "GNU C++14") == 0)
20219 language
= DW_LANG_C_plus_plus_14
;
20222 else if (strcmp (language_string
, "GNU F77") == 0)
20223 language
= DW_LANG_Fortran77
;
20224 else if (strcmp (language_string
, "GNU Pascal") == 0)
20225 language
= DW_LANG_Pascal83
;
20226 else if (dwarf_version
>= 3 || !dwarf_strict
)
20228 if (strcmp (language_string
, "GNU Ada") == 0)
20229 language
= DW_LANG_Ada95
;
20230 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
20232 language
= DW_LANG_Fortran95
;
20233 if (dwarf_version
>= 5 /* || !dwarf_strict */)
20235 if (strcmp (language_string
, "GNU Fortran2003") == 0)
20236 language
= DW_LANG_Fortran03
;
20237 else if (strcmp (language_string
, "GNU Fortran2008") == 0)
20238 language
= DW_LANG_Fortran08
;
20241 else if (strcmp (language_string
, "GNU Java") == 0)
20242 language
= DW_LANG_Java
;
20243 else if (strcmp (language_string
, "GNU Objective-C") == 0)
20244 language
= DW_LANG_ObjC
;
20245 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
20246 language
= DW_LANG_ObjC_plus_plus
;
20247 else if (dwarf_version
>= 5 || !dwarf_strict
)
20249 if (strcmp (language_string
, "GNU Go") == 0)
20250 language
= DW_LANG_Go
;
20253 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
20254 else if (strncmp (language_string
, "GNU Fortran", 11) == 0)
20255 language
= DW_LANG_Fortran90
;
20257 add_AT_unsigned (die
, DW_AT_language
, language
);
20261 case DW_LANG_Fortran77
:
20262 case DW_LANG_Fortran90
:
20263 case DW_LANG_Fortran95
:
20264 case DW_LANG_Fortran03
:
20265 case DW_LANG_Fortran08
:
20266 /* Fortran has case insensitive identifiers and the front-end
20267 lowercases everything. */
20268 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
20271 /* The default DW_ID_case_sensitive doesn't need to be specified. */
20277 /* Generate the DIE for a base class. */
20280 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
20282 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
20284 add_type_attribute (die
, BINFO_TYPE (binfo
), TYPE_UNQUALIFIED
, context_die
);
20285 add_data_member_location_attribute (die
, binfo
);
20287 if (BINFO_VIRTUAL_P (binfo
))
20288 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
20290 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
20291 children, otherwise the default is DW_ACCESS_public. In DWARF2
20292 the default has always been DW_ACCESS_private. */
20293 if (access
== access_public_node
)
20295 if (dwarf_version
== 2
20296 || context_die
->die_tag
== DW_TAG_class_type
)
20297 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
20299 else if (access
== access_protected_node
)
20300 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
20301 else if (dwarf_version
> 2
20302 && context_die
->die_tag
!= DW_TAG_class_type
)
20303 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
20306 /* Generate a DIE for a class member. */
20309 gen_member_die (tree type
, dw_die_ref context_die
)
20312 tree binfo
= TYPE_BINFO (type
);
20315 /* If this is not an incomplete type, output descriptions of each of its
20316 members. Note that as we output the DIEs necessary to represent the
20317 members of this record or union type, we will also be trying to output
20318 DIEs to represent the *types* of those members. However the `type'
20319 function (above) will specifically avoid generating type DIEs for member
20320 types *within* the list of member DIEs for this (containing) type except
20321 for those types (of members) which are explicitly marked as also being
20322 members of this (containing) type themselves. The g++ front- end can
20323 force any given type to be treated as a member of some other (containing)
20324 type by setting the TYPE_CONTEXT of the given (member) type to point to
20325 the TREE node representing the appropriate (containing) type. */
20327 /* First output info about the base classes. */
20330 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
20334 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
20335 gen_inheritance_die (base
,
20336 (accesses
? (*accesses
)[i
] : access_public_node
),
20340 /* Now output info about the data members and type members. */
20341 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
20343 /* If we thought we were generating minimal debug info for TYPE
20344 and then changed our minds, some of the member declarations
20345 may have already been defined. Don't define them again, but
20346 do put them in the right order. */
20348 child
= lookup_decl_die (member
);
20350 splice_child_die (context_die
, child
);
20352 gen_decl_die (member
, NULL
, context_die
);
20355 /* We do not keep type methods in type variants. */
20356 gcc_assert (TYPE_MAIN_VARIANT (type
) == type
);
20357 /* Now output info about the function members (if any). */
20358 if (TYPE_METHODS (type
) != error_mark_node
)
20359 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
20361 /* Don't include clones in the member list. */
20362 if (DECL_ABSTRACT_ORIGIN (member
))
20364 /* Nor constructors for anonymous classes. */
20365 if (DECL_ARTIFICIAL (member
)
20366 && dwarf2_name (member
, 0) == NULL
)
20369 child
= lookup_decl_die (member
);
20371 splice_child_die (context_die
, child
);
20373 gen_decl_die (member
, NULL
, context_die
);
20377 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
20378 is set, we pretend that the type was never defined, so we only get the
20379 member DIEs needed by later specification DIEs. */
20382 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
20383 enum debug_info_usage usage
)
20385 if (TREE_ASM_WRITTEN (type
))
20387 /* Fill in the bound of variable-length fields in late dwarf if
20388 still incomplete. */
20389 if (!early_dwarf
&& variably_modified_type_p (type
, NULL
))
20390 for (tree member
= TYPE_FIELDS (type
);
20392 member
= DECL_CHAIN (member
))
20393 fill_variable_array_bounds (TREE_TYPE (member
));
20397 dw_die_ref type_die
= lookup_type_die (type
);
20398 dw_die_ref scope_die
= 0;
20400 int complete
= (TYPE_SIZE (type
)
20401 && (! TYPE_STUB_DECL (type
)
20402 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
20403 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
20404 complete
= complete
&& should_emit_struct_debug (type
, usage
);
20406 if (type_die
&& ! complete
)
20409 if (TYPE_CONTEXT (type
) != NULL_TREE
20410 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20411 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
20414 scope_die
= scope_die_for (type
, context_die
);
20416 /* Generate child dies for template paramaters. */
20417 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
20418 schedule_generic_params_dies_gen (type
);
20420 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
20421 /* First occurrence of type or toplevel definition of nested class. */
20423 dw_die_ref old_die
= type_die
;
20425 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
20426 ? record_type_tag (type
) : DW_TAG_union_type
,
20428 equate_type_number_to_die (type
, type_die
);
20430 add_AT_specification (type_die
, old_die
);
20432 add_name_attribute (type_die
, type_tag (type
));
20435 remove_AT (type_die
, DW_AT_declaration
);
20437 /* If this type has been completed, then give it a byte_size attribute and
20438 then give a list of members. */
20439 if (complete
&& !ns_decl
)
20441 /* Prevent infinite recursion in cases where the type of some member of
20442 this type is expressed in terms of this type itself. */
20443 TREE_ASM_WRITTEN (type
) = 1;
20444 add_byte_size_attribute (type_die
, type
);
20445 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
20447 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
20448 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
20451 /* If the first reference to this type was as the return type of an
20452 inline function, then it may not have a parent. Fix this now. */
20453 if (type_die
->die_parent
== NULL
)
20454 add_child_die (scope_die
, type_die
);
20456 push_decl_scope (type
);
20457 gen_member_die (type
, type_die
);
20460 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
20461 if (TYPE_ARTIFICIAL (type
))
20462 add_AT_flag (type_die
, DW_AT_artificial
, 1);
20464 /* GNU extension: Record what type our vtable lives in. */
20465 if (TYPE_VFIELD (type
))
20467 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
20469 gen_type_die (vtype
, context_die
);
20470 add_AT_die_ref (type_die
, DW_AT_containing_type
,
20471 lookup_type_die (vtype
));
20476 add_AT_flag (type_die
, DW_AT_declaration
, 1);
20478 /* We don't need to do this for function-local types. */
20479 if (TYPE_STUB_DECL (type
)
20480 && ! decl_function_context (TYPE_STUB_DECL (type
)))
20481 vec_safe_push (incomplete_types
, type
);
20484 if (get_AT (type_die
, DW_AT_name
))
20485 add_pubtype (type
, type_die
);
20488 /* Generate a DIE for a subroutine _type_. */
20491 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
20493 tree return_type
= TREE_TYPE (type
);
20494 dw_die_ref subr_die
20495 = new_die (DW_TAG_subroutine_type
,
20496 scope_die_for (type
, context_die
), type
);
20498 equate_type_number_to_die (type
, subr_die
);
20499 add_prototyped_attribute (subr_die
, type
);
20500 add_type_attribute (subr_die
, return_type
, TYPE_UNQUALIFIED
, context_die
);
20501 gen_formal_types_die (type
, subr_die
);
20503 if (get_AT (subr_die
, DW_AT_name
))
20504 add_pubtype (type
, subr_die
);
20507 /* Generate a DIE for a type definition. */
20510 gen_typedef_die (tree decl
, dw_die_ref context_die
)
20512 dw_die_ref type_die
;
20515 if (TREE_ASM_WRITTEN (decl
))
20517 if (DECL_ORIGINAL_TYPE (decl
))
20518 fill_variable_array_bounds (DECL_ORIGINAL_TYPE (decl
));
20522 TREE_ASM_WRITTEN (decl
) = 1;
20523 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
20524 origin
= decl_ultimate_origin (decl
);
20525 if (origin
!= NULL
)
20526 add_abstract_origin_attribute (type_die
, origin
);
20531 add_name_and_src_coords_attributes (type_die
, decl
);
20532 if (DECL_ORIGINAL_TYPE (decl
))
20534 type
= DECL_ORIGINAL_TYPE (decl
);
20536 if (type
== error_mark_node
)
20539 gcc_assert (type
!= TREE_TYPE (decl
));
20540 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
20544 type
= TREE_TYPE (decl
);
20546 if (type
== error_mark_node
)
20549 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20551 /* Here, we are in the case of decl being a typedef naming
20552 an anonymous type, e.g:
20553 typedef struct {...} foo;
20554 In that case TREE_TYPE (decl) is not a typedef variant
20555 type and TYPE_NAME of the anonymous type is set to the
20556 TYPE_DECL of the typedef. This construct is emitted by
20559 TYPE is the anonymous struct named by the typedef
20560 DECL. As we need the DW_AT_type attribute of the
20561 DW_TAG_typedef to point to the DIE of TYPE, let's
20562 generate that DIE right away. add_type_attribute
20563 called below will then pick (via lookup_type_die) that
20564 anonymous struct DIE. */
20565 if (!TREE_ASM_WRITTEN (type
))
20566 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
20568 /* This is a GNU Extension. We are adding a
20569 DW_AT_linkage_name attribute to the DIE of the
20570 anonymous struct TYPE. The value of that attribute
20571 is the name of the typedef decl naming the anonymous
20572 struct. This greatly eases the work of consumers of
20573 this debug info. */
20574 add_linkage_attr (lookup_type_die (type
), decl
);
20578 add_type_attribute (type_die
, type
, decl_quals (decl
), context_die
);
20580 if (is_naming_typedef_decl (decl
))
20581 /* We want that all subsequent calls to lookup_type_die with
20582 TYPE in argument yield the DW_TAG_typedef we have just
20584 equate_type_number_to_die (type
, type_die
);
20586 add_accessibility_attribute (type_die
, decl
);
20589 if (DECL_ABSTRACT_P (decl
))
20590 equate_decl_number_to_die (decl
, type_die
);
20592 if (get_AT (type_die
, DW_AT_name
))
20593 add_pubtype (decl
, type_die
);
20596 /* Generate a DIE for a struct, class, enum or union type. */
20599 gen_tagged_type_die (tree type
,
20600 dw_die_ref context_die
,
20601 enum debug_info_usage usage
)
20605 if (type
== NULL_TREE
20606 || !is_tagged_type (type
))
20609 if (TREE_ASM_WRITTEN (type
))
20611 /* If this is a nested type whose containing class hasn't been written
20612 out yet, writing it out will cover this one, too. This does not apply
20613 to instantiations of member class templates; they need to be added to
20614 the containing class as they are generated. FIXME: This hurts the
20615 idea of combining type decls from multiple TUs, since we can't predict
20616 what set of template instantiations we'll get. */
20617 else if (TYPE_CONTEXT (type
)
20618 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
20619 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
20621 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
20623 if (TREE_ASM_WRITTEN (type
))
20626 /* If that failed, attach ourselves to the stub. */
20627 push_decl_scope (TYPE_CONTEXT (type
));
20628 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
20631 else if (TYPE_CONTEXT (type
) != NULL_TREE
20632 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
20634 /* If this type is local to a function that hasn't been written
20635 out yet, use a NULL context for now; it will be fixed up in
20636 decls_for_scope. */
20637 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
20638 /* A declaration DIE doesn't count; nested types need to go in the
20640 if (context_die
&& is_declaration_die (context_die
))
20641 context_die
= NULL
;
20646 context_die
= declare_in_namespace (type
, context_die
);
20650 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
20652 /* This might have been written out by the call to
20653 declare_in_namespace. */
20654 if (!TREE_ASM_WRITTEN (type
))
20655 gen_enumeration_type_die (type
, context_die
);
20658 gen_struct_or_union_type_die (type
, context_die
, usage
);
20663 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
20664 it up if it is ever completed. gen_*_type_die will set it for us
20665 when appropriate. */
20668 /* Generate a type description DIE. */
20671 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
20672 enum debug_info_usage usage
)
20674 struct array_descr_info info
;
20676 if (type
== NULL_TREE
|| type
== error_mark_node
)
20679 #ifdef ENABLE_CHECKING
20681 verify_type (type
);
20684 if (TYPE_NAME (type
) != NULL_TREE
20685 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
20686 && is_redundant_typedef (TYPE_NAME (type
))
20687 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
20688 /* The DECL of this type is a typedef we don't want to emit debug
20689 info for but we want debug info for its underlying typedef.
20690 This can happen for e.g, the injected-class-name of a C++
20692 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
20694 /* If TYPE is a typedef type variant, let's generate debug info
20695 for the parent typedef which TYPE is a type of. */
20696 if (typedef_variant_p (type
))
20698 if (TREE_ASM_WRITTEN (type
))
20701 /* Prevent broken recursion; we can't hand off to the same type. */
20702 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
20704 /* Give typedefs the right scope. */
20705 context_die
= scope_die_for (type
, context_die
);
20707 TREE_ASM_WRITTEN (type
) = 1;
20709 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20713 /* If type is an anonymous tagged type named by a typedef, let's
20714 generate debug info for the typedef. */
20715 if (is_naming_typedef_decl (TYPE_NAME (type
)))
20717 /* Use the DIE of the containing namespace as the parent DIE of
20718 the type description DIE we want to generate. */
20719 if (DECL_CONTEXT (TYPE_NAME (type
))
20720 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
20721 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
20723 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
20727 /* We are going to output a DIE to represent the unqualified version
20728 of this type (i.e. without any const or volatile qualifiers) so
20729 get the main variant (i.e. the unqualified version) of this type
20730 now. (Vectors are special because the debugging info is in the
20731 cloned type itself). */
20732 if (TREE_CODE (type
) != VECTOR_TYPE
)
20733 type
= type_main_variant (type
);
20735 /* If this is an array type with hidden descriptor, handle it first. */
20736 if (!TREE_ASM_WRITTEN (type
)
20737 && lang_hooks
.types
.get_array_descr_info
)
20739 memset (&info
, 0, sizeof (info
));
20740 if (lang_hooks
.types
.get_array_descr_info (type
, &info
))
20742 gen_descr_array_type_die (type
, &info
, context_die
);
20743 TREE_ASM_WRITTEN (type
) = 1;
20748 if (TREE_ASM_WRITTEN (type
))
20750 /* Variable-length types may be incomplete even if
20751 TREE_ASM_WRITTEN. For such types, fall through to
20752 gen_array_type_die() and possibly fill in
20753 DW_AT_{upper,lower}_bound attributes. */
20754 if ((TREE_CODE (type
) != ARRAY_TYPE
20755 && TREE_CODE (type
) != RECORD_TYPE
20756 && TREE_CODE (type
) != UNION_TYPE
20757 && TREE_CODE (type
) != QUAL_UNION_TYPE
)
20758 || !variably_modified_type_p (type
, NULL
))
20762 switch (TREE_CODE (type
))
20768 case REFERENCE_TYPE
:
20769 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
20770 ensures that the gen_type_die recursion will terminate even if the
20771 type is recursive. Recursive types are possible in Ada. */
20772 /* ??? We could perhaps do this for all types before the switch
20774 TREE_ASM_WRITTEN (type
) = 1;
20776 /* For these types, all that is required is that we output a DIE (or a
20777 set of DIEs) to represent the "basis" type. */
20778 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20779 DINFO_USAGE_IND_USE
);
20783 /* This code is used for C++ pointer-to-data-member types.
20784 Output a description of the relevant class type. */
20785 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
20786 DINFO_USAGE_IND_USE
);
20788 /* Output a description of the type of the object pointed to. */
20789 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20790 DINFO_USAGE_IND_USE
);
20792 /* Now output a DIE to represent this pointer-to-data-member type
20794 gen_ptr_to_mbr_type_die (type
, context_die
);
20797 case FUNCTION_TYPE
:
20798 /* Force out return type (in case it wasn't forced out already). */
20799 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20800 DINFO_USAGE_DIR_USE
);
20801 gen_subroutine_type_die (type
, context_die
);
20805 /* Force out return type (in case it wasn't forced out already). */
20806 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
20807 DINFO_USAGE_DIR_USE
);
20808 gen_subroutine_type_die (type
, context_die
);
20813 gen_array_type_die (type
, context_die
);
20816 case ENUMERAL_TYPE
:
20819 case QUAL_UNION_TYPE
:
20820 gen_tagged_type_die (type
, context_die
, usage
);
20826 case FIXED_POINT_TYPE
:
20829 case POINTER_BOUNDS_TYPE
:
20830 /* No DIEs needed for fundamental types. */
20835 /* Just use DW_TAG_unspecified_type. */
20837 dw_die_ref type_die
= lookup_type_die (type
);
20838 if (type_die
== NULL
)
20840 tree name
= TYPE_IDENTIFIER (type
);
20841 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (),
20843 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
20844 equate_type_number_to_die (type
, type_die
);
20850 if (is_cxx_auto (type
))
20852 tree name
= TYPE_IDENTIFIER (type
);
20853 dw_die_ref
*die
= (name
== get_identifier ("auto")
20854 ? &auto_die
: &decltype_auto_die
);
20857 *die
= new_die (DW_TAG_unspecified_type
,
20858 comp_unit_die (), NULL_TREE
);
20859 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
20861 equate_type_number_to_die (type
, *die
);
20864 gcc_unreachable ();
20867 TREE_ASM_WRITTEN (type
) = 1;
20871 gen_type_die (tree type
, dw_die_ref context_die
)
20873 if (type
!= error_mark_node
)
20875 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
20876 #ifdef ENABLE_CHECKING
20877 dw_die_ref die
= lookup_type_die (type
);
20884 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20885 things which are local to the given block. */
20888 gen_block_die (tree stmt
, dw_die_ref context_die
)
20890 int must_output_die
= 0;
20893 /* Ignore blocks that are NULL. */
20894 if (stmt
== NULL_TREE
)
20897 inlined_func
= inlined_function_outer_scope_p (stmt
);
20899 /* If the block is one fragment of a non-contiguous block, do not
20900 process the variables, since they will have been done by the
20901 origin block. Do process subblocks. */
20902 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
20906 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
20907 gen_block_die (sub
, context_die
);
20912 /* Determine if we need to output any Dwarf DIEs at all to represent this
20915 /* The outer scopes for inlinings *must* always be represented. We
20916 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20917 must_output_die
= 1;
20920 /* Determine if this block directly contains any "significant"
20921 local declarations which we will need to output DIEs for. */
20922 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20923 /* We are not in terse mode so *any* local declaration counts
20924 as being a "significant" one. */
20925 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
20926 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
20927 && (TREE_USED (stmt
)
20928 || TREE_ASM_WRITTEN (stmt
)
20929 || BLOCK_ABSTRACT (stmt
)));
20930 else if ((TREE_USED (stmt
)
20931 || TREE_ASM_WRITTEN (stmt
)
20932 || BLOCK_ABSTRACT (stmt
))
20933 && !dwarf2out_ignore_block (stmt
))
20934 must_output_die
= 1;
20937 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20938 DIE for any block which contains no significant local declarations at
20939 all. Rather, in such cases we just call `decls_for_scope' so that any
20940 needed Dwarf info for any sub-blocks will get properly generated. Note
20941 that in terse mode, our definition of what constitutes a "significant"
20942 local declaration gets restricted to include only inlined function
20943 instances and local (nested) function definitions. */
20944 if (must_output_die
)
20948 /* If STMT block is abstract, that means we have been called
20949 indirectly from dwarf2out_abstract_function.
20950 That function rightfully marks the descendent blocks (of
20951 the abstract function it is dealing with) as being abstract,
20952 precisely to prevent us from emitting any
20953 DW_TAG_inlined_subroutine DIE as a descendent
20954 of an abstract function instance. So in that case, we should
20955 not call gen_inlined_subroutine_die.
20957 Later though, when cgraph asks dwarf2out to emit info
20958 for the concrete instance of the function decl into which
20959 the concrete instance of STMT got inlined, the later will lead
20960 to the generation of a DW_TAG_inlined_subroutine DIE. */
20961 if (! BLOCK_ABSTRACT (stmt
))
20962 gen_inlined_subroutine_die (stmt
, context_die
);
20965 gen_lexical_block_die (stmt
, context_die
);
20968 decls_for_scope (stmt
, context_die
);
20971 /* Process variable DECL (or variable with origin ORIGIN) within
20972 block STMT and add it to CONTEXT_DIE. */
20974 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20977 tree decl_or_origin
= decl
? decl
: origin
;
20979 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20980 die
= lookup_decl_die (decl_or_origin
);
20981 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20982 && TYPE_DECL_IS_STUB (decl_or_origin
))
20983 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
20987 if (die
!= NULL
&& die
->die_parent
== NULL
)
20988 add_child_die (context_die
, die
);
20989 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
20992 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
20993 stmt
, context_die
);
20996 gen_decl_die (decl
, origin
, context_die
);
20999 /* Generate all of the decls declared within a given scope and (recursively)
21000 all of its sub-blocks. */
21003 decls_for_scope (tree stmt
, dw_die_ref context_die
)
21009 /* Ignore NULL blocks. */
21010 if (stmt
== NULL_TREE
)
21013 /* Output the DIEs to represent all of the data objects and typedefs
21014 declared directly within this block but not within any nested
21015 sub-blocks. Also, nested function and tag DIEs have been
21016 generated with a parent of NULL; fix that up now. We don't
21017 have to do this if we're at -g1. */
21018 if (debug_info_level
> DINFO_LEVEL_TERSE
)
21020 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
21021 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
21022 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
21023 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
21027 /* Even if we're at -g1, we need to process the subblocks in order to get
21028 inlined call information. */
21030 /* Output the DIEs to represent all sub-blocks (and the items declared
21031 therein) of this block. */
21032 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
21034 subblocks
= BLOCK_CHAIN (subblocks
))
21035 gen_block_die (subblocks
, context_die
);
21038 /* Is this a typedef we can avoid emitting? */
21041 is_redundant_typedef (const_tree decl
)
21043 if (TYPE_DECL_IS_STUB (decl
))
21046 if (DECL_ARTIFICIAL (decl
)
21047 && DECL_CONTEXT (decl
)
21048 && is_tagged_type (DECL_CONTEXT (decl
))
21049 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
21050 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
21051 /* Also ignore the artificial member typedef for the class name. */
21057 /* Return TRUE if TYPE is a typedef that names a type for linkage
21058 purposes. This kind of typedefs is produced by the C++ FE for
21061 typedef struct {...} foo;
21063 In that case, there is no typedef variant type produced for foo.
21064 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
21068 is_naming_typedef_decl (const_tree decl
)
21070 if (decl
== NULL_TREE
21071 || TREE_CODE (decl
) != TYPE_DECL
21072 || !is_tagged_type (TREE_TYPE (decl
))
21073 || DECL_IS_BUILTIN (decl
)
21074 || is_redundant_typedef (decl
)
21075 /* It looks like Ada produces TYPE_DECLs that are very similar
21076 to C++ naming typedefs but that have different
21077 semantics. Let's be specific to c++ for now. */
21081 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
21082 && TYPE_NAME (TREE_TYPE (decl
)) == decl
21083 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
21084 != TYPE_NAME (TREE_TYPE (decl
))));
21087 /* Looks up the DIE for a context. */
21089 static inline dw_die_ref
21090 lookup_context_die (tree context
)
21094 /* Find die that represents this context. */
21095 if (TYPE_P (context
))
21097 context
= TYPE_MAIN_VARIANT (context
);
21098 dw_die_ref ctx
= lookup_type_die (context
);
21101 return strip_naming_typedef (context
, ctx
);
21104 return lookup_decl_die (context
);
21106 return comp_unit_die ();
21109 /* Returns the DIE for a context. */
21111 static inline dw_die_ref
21112 get_context_die (tree context
)
21116 /* Find die that represents this context. */
21117 if (TYPE_P (context
))
21119 context
= TYPE_MAIN_VARIANT (context
);
21120 return strip_naming_typedef (context
, force_type_die (context
));
21123 return force_decl_die (context
);
21125 return comp_unit_die ();
21128 /* Returns the DIE for decl. A DIE will always be returned. */
21131 force_decl_die (tree decl
)
21133 dw_die_ref decl_die
;
21134 unsigned saved_external_flag
;
21135 tree save_fn
= NULL_TREE
;
21136 decl_die
= lookup_decl_die (decl
);
21139 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
21141 decl_die
= lookup_decl_die (decl
);
21145 switch (TREE_CODE (decl
))
21147 case FUNCTION_DECL
:
21148 /* Clear current_function_decl, so that gen_subprogram_die thinks
21149 that this is a declaration. At this point, we just want to force
21150 declaration die. */
21151 save_fn
= current_function_decl
;
21152 current_function_decl
= NULL_TREE
;
21153 gen_subprogram_die (decl
, context_die
);
21154 current_function_decl
= save_fn
;
21158 /* Set external flag to force declaration die. Restore it after
21159 gen_decl_die() call. */
21160 saved_external_flag
= DECL_EXTERNAL (decl
);
21161 DECL_EXTERNAL (decl
) = 1;
21162 gen_decl_die (decl
, NULL
, context_die
);
21163 DECL_EXTERNAL (decl
) = saved_external_flag
;
21166 case NAMESPACE_DECL
:
21167 if (dwarf_version
>= 3 || !dwarf_strict
)
21168 dwarf2out_decl (decl
);
21170 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
21171 decl_die
= comp_unit_die ();
21174 case TRANSLATION_UNIT_DECL
:
21175 decl_die
= comp_unit_die ();
21179 gcc_unreachable ();
21182 /* We should be able to find the DIE now. */
21184 decl_die
= lookup_decl_die (decl
);
21185 gcc_assert (decl_die
);
21191 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
21192 always returned. */
21195 force_type_die (tree type
)
21197 dw_die_ref type_die
;
21199 type_die
= lookup_type_die (type
);
21202 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
21204 type_die
= modified_type_die (type
, TYPE_QUALS_NO_ADDR_SPACE (type
),
21206 gcc_assert (type_die
);
21211 /* Force out any required namespaces to be able to output DECL,
21212 and return the new context_die for it, if it's changed. */
21215 setup_namespace_context (tree thing
, dw_die_ref context_die
)
21217 tree context
= (DECL_P (thing
)
21218 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
21219 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
21220 /* Force out the namespace. */
21221 context_die
= force_decl_die (context
);
21223 return context_die
;
21226 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
21227 type) within its namespace, if appropriate.
21229 For compatibility with older debuggers, namespace DIEs only contain
21230 declarations; all definitions are emitted at CU scope, with
21231 DW_AT_specification pointing to the declaration (like with class
21235 declare_in_namespace (tree thing
, dw_die_ref context_die
)
21237 dw_die_ref ns_context
;
21239 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21240 return context_die
;
21242 /* External declarations in the local scope only need to be emitted
21243 once, not once in the namespace and once in the scope.
21245 This avoids declaring the `extern' below in the
21246 namespace DIE as well as in the innermost scope:
21259 if (DECL_P (thing
) && DECL_EXTERNAL (thing
) && local_scope_p (context_die
))
21260 return context_die
;
21262 /* If this decl is from an inlined function, then don't try to emit it in its
21263 namespace, as we will get confused. It would have already been emitted
21264 when the abstract instance of the inline function was emitted anyways. */
21265 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
21266 return context_die
;
21268 ns_context
= setup_namespace_context (thing
, context_die
);
21270 if (ns_context
!= context_die
)
21274 if (DECL_P (thing
))
21275 gen_decl_die (thing
, NULL
, ns_context
);
21277 gen_type_die (thing
, ns_context
);
21279 return context_die
;
21282 /* Generate a DIE for a namespace or namespace alias. */
21285 gen_namespace_die (tree decl
, dw_die_ref context_die
)
21287 dw_die_ref namespace_die
;
21289 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
21290 they are an alias of. */
21291 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
21293 /* Output a real namespace or module. */
21294 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21295 namespace_die
= new_die (is_fortran ()
21296 ? DW_TAG_module
: DW_TAG_namespace
,
21297 context_die
, decl
);
21298 /* For Fortran modules defined in different CU don't add src coords. */
21299 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
21301 const char *name
= dwarf2_name (decl
, 0);
21303 add_name_attribute (namespace_die
, name
);
21306 add_name_and_src_coords_attributes (namespace_die
, decl
);
21307 if (DECL_EXTERNAL (decl
))
21308 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
21309 equate_decl_number_to_die (decl
, namespace_die
);
21313 /* Output a namespace alias. */
21315 /* Force out the namespace we are an alias of, if necessary. */
21316 dw_die_ref origin_die
21317 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
21319 if (DECL_FILE_SCOPE_P (decl
)
21320 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
21321 context_die
= setup_namespace_context (decl
, comp_unit_die ());
21322 /* Now create the namespace alias DIE. */
21323 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
21324 add_name_and_src_coords_attributes (namespace_die
, decl
);
21325 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
21326 equate_decl_number_to_die (decl
, namespace_die
);
21328 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
21329 if (want_pubnames ())
21330 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
21333 /* Generate Dwarf debug information for a decl described by DECL.
21334 The return value is currently only meaningful for PARM_DECLs,
21335 for all other decls it returns NULL. */
21338 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
21340 tree decl_or_origin
= decl
? decl
: origin
;
21341 tree class_origin
= NULL
, ultimate_origin
;
21343 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
21346 /* Ignore pointer bounds decls. */
21347 if (DECL_P (decl_or_origin
)
21348 && TREE_TYPE (decl_or_origin
)
21349 && POINTER_BOUNDS_P (decl_or_origin
))
21352 switch (TREE_CODE (decl_or_origin
))
21358 if (!is_fortran () && !is_ada ())
21360 /* The individual enumerators of an enum type get output when we output
21361 the Dwarf representation of the relevant enum type itself. */
21365 /* Emit its type. */
21366 gen_type_die (TREE_TYPE (decl
), context_die
);
21368 /* And its containing namespace. */
21369 context_die
= declare_in_namespace (decl
, context_die
);
21371 gen_const_die (decl
, context_die
);
21374 case FUNCTION_DECL
:
21375 /* Don't output any DIEs to represent mere function declarations,
21376 unless they are class members or explicit block externs. */
21377 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
21378 && DECL_FILE_SCOPE_P (decl_or_origin
)
21379 && (current_function_decl
== NULL_TREE
21380 || DECL_ARTIFICIAL (decl_or_origin
)))
21385 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
21386 on local redeclarations of global functions. That seems broken. */
21387 if (current_function_decl
!= decl
)
21388 /* This is only a declaration. */;
21391 /* If we're emitting a clone, emit info for the abstract instance. */
21392 if (origin
|| DECL_ORIGIN (decl
) != decl
)
21393 dwarf2out_abstract_function (origin
21394 ? DECL_ORIGIN (origin
)
21395 : DECL_ABSTRACT_ORIGIN (decl
));
21397 /* If we're emitting an out-of-line copy of an inline function,
21398 emit info for the abstract instance and set up to refer to it. */
21399 else if (cgraph_function_possibly_inlined_p (decl
)
21400 && ! DECL_ABSTRACT_P (decl
)
21401 && ! class_or_namespace_scope_p (context_die
)
21402 /* dwarf2out_abstract_function won't emit a die if this is just
21403 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
21404 that case, because that works only if we have a die. */
21405 && DECL_INITIAL (decl
) != NULL_TREE
)
21407 dwarf2out_abstract_function (decl
);
21408 set_decl_origin_self (decl
);
21411 /* Otherwise we're emitting the primary DIE for this decl. */
21412 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
21414 /* Before we describe the FUNCTION_DECL itself, make sure that we
21415 have its containing type. */
21417 origin
= decl_class_context (decl
);
21418 if (origin
!= NULL_TREE
)
21419 gen_type_die (origin
, context_die
);
21421 /* And its return type. */
21422 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
21424 /* And its virtual context. */
21425 if (DECL_VINDEX (decl
) != NULL_TREE
)
21426 gen_type_die (DECL_CONTEXT (decl
), context_die
);
21428 /* Make sure we have a member DIE for decl. */
21429 if (origin
!= NULL_TREE
)
21430 gen_type_die_for_member (origin
, decl
, context_die
);
21432 /* And its containing namespace. */
21433 context_die
= declare_in_namespace (decl
, context_die
);
21436 /* Now output a DIE to represent the function itself. */
21438 gen_subprogram_die (decl
, context_die
);
21442 /* If we are in terse mode, don't generate any DIEs to represent any
21443 actual typedefs. */
21444 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21447 /* In the special case of a TYPE_DECL node representing the declaration
21448 of some type tag, if the given TYPE_DECL is marked as having been
21449 instantiated from some other (original) TYPE_DECL node (e.g. one which
21450 was generated within the original definition of an inline function) we
21451 used to generate a special (abbreviated) DW_TAG_structure_type,
21452 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
21453 should be actually referencing those DIEs, as variable DIEs with that
21454 type would be emitted already in the abstract origin, so it was always
21455 removed during unused type prunning. Don't add anything in this
21457 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
21460 if (is_redundant_typedef (decl
))
21461 gen_type_die (TREE_TYPE (decl
), context_die
);
21463 /* Output a DIE to represent the typedef itself. */
21464 gen_typedef_die (decl
, context_die
);
21468 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
21469 gen_label_die (decl
, context_die
);
21474 /* If we are in terse mode, don't generate any DIEs to represent any
21475 variable declarations or definitions. */
21476 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21479 /* Output any DIEs that are needed to specify the type of this data
21481 if (decl_by_reference_p (decl_or_origin
))
21482 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21484 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21486 /* And its containing type. */
21487 class_origin
= decl_class_context (decl_or_origin
);
21488 if (class_origin
!= NULL_TREE
)
21489 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
21491 /* And its containing namespace. */
21492 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
21494 /* Now output the DIE to represent the data object itself. This gets
21495 complicated because of the possibility that the VAR_DECL really
21496 represents an inlined instance of a formal parameter for an inline
21498 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
21499 if (ultimate_origin
!= NULL_TREE
21500 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
21501 gen_formal_parameter_die (decl
, origin
,
21502 true /* Emit name attribute. */,
21505 gen_variable_die (decl
, origin
, context_die
);
21509 /* Ignore the nameless fields that are used to skip bits but handle C++
21510 anonymous unions and structs. */
21511 if (DECL_NAME (decl
) != NULL_TREE
21512 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
21513 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
21515 gen_type_die (member_declared_type (decl
), context_die
);
21516 gen_field_die (decl
, context_die
);
21521 if (DECL_BY_REFERENCE (decl_or_origin
))
21522 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
21524 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
21525 return gen_formal_parameter_die (decl
, origin
,
21526 true /* Emit name attribute. */,
21529 case NAMESPACE_DECL
:
21530 case IMPORTED_DECL
:
21531 if (dwarf_version
>= 3 || !dwarf_strict
)
21532 gen_namespace_die (decl
, context_die
);
21535 case NAMELIST_DECL
:
21536 gen_namelist_decl (DECL_NAME (decl
), context_die
,
21537 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
21541 /* Probably some frontend-internal decl. Assume we don't care. */
21542 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
21549 /* Output initial debug information for global DECL. Called at the
21550 end of the parsing process.
21552 This is the initial debug generation process. As such, the DIEs
21553 generated may be incomplete. A later debug generation pass
21554 (dwarf2out_late_global_decl) will augment the information generated
21555 in this pass (e.g., with complete location info). */
21558 dwarf2out_early_global_decl (tree decl
)
21562 /* gen_decl_die() will set DECL_ABSTRACT because
21563 cgraph_function_possibly_inlined_p() returns true. This is in
21564 turn will cause DW_AT_inline attributes to be set.
21566 This happens because at early dwarf generation, there is no
21567 cgraph information, causing cgraph_function_possibly_inlined_p()
21568 to return true. Trick cgraph_function_possibly_inlined_p()
21569 while we generate dwarf early. */
21570 bool save
= symtab
->global_info_ready
;
21571 symtab
->global_info_ready
= true;
21573 /* We don't handle TYPE_DECLs. If required, they'll be reached via
21574 other DECLs and they can point to template types or other things
21575 that dwarf2out can't handle when done via dwarf2out_decl. */
21576 if (TREE_CODE (decl
) != TYPE_DECL
21577 && TREE_CODE (decl
) != PARM_DECL
)
21579 tree save_fndecl
= current_function_decl
;
21580 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21582 /* No cfun means the symbol has no body, so there's nothing
21584 if (!DECL_STRUCT_FUNCTION (decl
))
21585 goto early_decl_exit
;
21587 current_function_decl
= decl
;
21589 dwarf2out_decl (decl
);
21590 if (TREE_CODE (decl
) == FUNCTION_DECL
)
21591 current_function_decl
= save_fndecl
;
21594 symtab
->global_info_ready
= save
;
21597 /* Output debug information for global decl DECL. Called from
21598 toplev.c after compilation proper has finished. */
21601 dwarf2out_late_global_decl (tree decl
)
21603 /* Output any global decls we missed or fill-in any location
21604 information we were unable to determine on the first pass.
21606 Skip over functions because they were handled by the
21607 debug_hooks->function_decl() call in rest_of_handle_final. */
21608 if ((TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
21609 && !POINTER_BOUNDS_P (decl
))
21610 dwarf2out_decl (decl
);
21613 /* Output debug information for type decl DECL. Called from toplev.c
21614 and from language front ends (to record built-in types). */
21616 dwarf2out_type_decl (tree decl
, int local
)
21621 dwarf2out_decl (decl
);
21625 /* Output debug information for imported module or decl DECL.
21626 NAME is non-NULL name in the lexical block if the decl has been renamed.
21627 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
21628 that DECL belongs to.
21629 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
21631 dwarf2out_imported_module_or_decl_1 (tree decl
,
21633 tree lexical_block
,
21634 dw_die_ref lexical_block_die
)
21636 expanded_location xloc
;
21637 dw_die_ref imported_die
= NULL
;
21638 dw_die_ref at_import_die
;
21640 if (TREE_CODE (decl
) == IMPORTED_DECL
)
21642 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
21643 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
21647 xloc
= expand_location (input_location
);
21649 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
21651 at_import_die
= force_type_die (TREE_TYPE (decl
));
21652 /* For namespace N { typedef void T; } using N::T; base_type_die
21653 returns NULL, but DW_TAG_imported_declaration requires
21654 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
21655 if (!at_import_die
)
21657 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
21658 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
21659 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
21660 gcc_assert (at_import_die
);
21665 at_import_die
= lookup_decl_die (decl
);
21666 if (!at_import_die
)
21668 /* If we're trying to avoid duplicate debug info, we may not have
21669 emitted the member decl for this field. Emit it now. */
21670 if (TREE_CODE (decl
) == FIELD_DECL
)
21672 tree type
= DECL_CONTEXT (decl
);
21674 if (TYPE_CONTEXT (type
)
21675 && TYPE_P (TYPE_CONTEXT (type
))
21676 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
21677 DINFO_USAGE_DIR_USE
))
21679 gen_type_die_for_member (type
, decl
,
21680 get_context_die (TYPE_CONTEXT (type
)));
21682 if (TREE_CODE (decl
) == NAMELIST_DECL
)
21683 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
21684 get_context_die (DECL_CONTEXT (decl
)),
21687 at_import_die
= force_decl_die (decl
);
21691 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
21693 if (dwarf_version
>= 3 || !dwarf_strict
)
21694 imported_die
= new_die (DW_TAG_imported_module
,
21701 imported_die
= new_die (DW_TAG_imported_declaration
,
21705 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
21706 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
21708 add_AT_string (imported_die
, DW_AT_name
,
21709 IDENTIFIER_POINTER (name
));
21710 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
21713 /* Output debug information for imported module or decl DECL.
21714 NAME is non-NULL name in context if the decl has been renamed.
21715 CHILD is true if decl is one of the renamed decls as part of
21716 importing whole module. */
21719 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
21722 /* dw_die_ref at_import_die; */
21723 dw_die_ref scope_die
;
21725 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21732 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
21733 We need decl DIE for reference and scope die. First, get DIE for the decl
21736 /* Get the scope die for decl context. Use comp_unit_die for global module
21737 or decl. If die is not found for non globals, force new die. */
21739 && TYPE_P (context
)
21740 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
21743 if (!(dwarf_version
>= 3 || !dwarf_strict
))
21746 scope_die
= get_context_die (context
);
21750 gcc_assert (scope_die
->die_child
);
21751 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
21752 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
21753 scope_die
= scope_die
->die_child
;
21756 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
21757 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
21760 /* Output debug information for namelists. */
21763 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
21765 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
21769 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21772 gcc_assert (scope_die
!= NULL
);
21773 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
21774 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
21776 /* If there are no item_decls, we have a nondefining namelist, e.g.
21777 with USE association; hence, set DW_AT_declaration. */
21778 if (item_decls
== NULL_TREE
)
21780 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
21784 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
21786 nml_item_ref_die
= lookup_decl_die (value
);
21787 if (!nml_item_ref_die
)
21788 nml_item_ref_die
= force_decl_die (value
);
21790 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
21791 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
21797 /* Write the debugging output for DECL and return the DIE. */
21800 dwarf2out_decl (tree decl
)
21802 dw_die_ref context_die
= comp_unit_die ();
21804 switch (TREE_CODE (decl
))
21809 case FUNCTION_DECL
:
21810 /* What we would really like to do here is to filter out all mere
21811 file-scope declarations of file-scope functions which are never
21812 referenced later within this translation unit (and keep all of ones
21813 that *are* referenced later on) but we aren't clairvoyant, so we have
21814 no idea which functions will be referenced in the future (i.e. later
21815 on within the current translation unit). So here we just ignore all
21816 file-scope function declarations which are not also definitions. If
21817 and when the debugger needs to know something about these functions,
21818 it will have to hunt around and find the DWARF information associated
21819 with the definition of the function.
21821 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
21822 nodes represent definitions and which ones represent mere
21823 declarations. We have to check DECL_INITIAL instead. That's because
21824 the C front-end supports some weird semantics for "extern inline"
21825 function definitions. These can get inlined within the current
21826 translation unit (and thus, we need to generate Dwarf info for their
21827 abstract instances so that the Dwarf info for the concrete inlined
21828 instances can have something to refer to) but the compiler never
21829 generates any out-of-lines instances of such things (despite the fact
21830 that they *are* definitions).
21832 The important point is that the C front-end marks these "extern
21833 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
21834 them anyway. Note that the C++ front-end also plays some similar games
21835 for inline function definitions appearing within include files which
21836 also contain `#pragma interface' pragmas.
21838 If we are called from dwarf2out_abstract_function output a DIE
21839 anyway. We can end up here this way with early inlining and LTO
21840 where the inlined function is output in a different LTRANS unit
21842 if (DECL_INITIAL (decl
) == NULL_TREE
21843 && ! DECL_ABSTRACT_P (decl
))
21846 /* If we're a nested function, initially use a parent of NULL; if we're
21847 a plain function, this will be fixed up in decls_for_scope. If
21848 we're a method, it will be ignored, since we already have a DIE. */
21849 if (decl_function_context (decl
)
21850 /* But if we're in terse mode, we don't care about scope. */
21851 && debug_info_level
> DINFO_LEVEL_TERSE
)
21852 context_die
= NULL
;
21856 /* For local statics lookup proper context die. */
21857 if (local_function_static (decl
))
21858 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21860 /* If we are in terse mode, don't generate any DIEs to represent any
21861 variable declarations or definitions. */
21862 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21867 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21869 if (!is_fortran () && !is_ada ())
21871 if (TREE_STATIC (decl
) && decl_function_context (decl
))
21872 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
21875 case NAMESPACE_DECL
:
21876 case IMPORTED_DECL
:
21877 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21879 if (lookup_decl_die (decl
) != NULL
)
21884 /* Don't emit stubs for types unless they are needed by other DIEs. */
21885 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
21888 /* Don't bother trying to generate any DIEs to represent any of the
21889 normal built-in types for the language we are compiling. */
21890 if (DECL_IS_BUILTIN (decl
))
21893 /* If we are in terse mode, don't generate any DIEs for types. */
21894 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
21897 /* If we're a function-scope tag, initially use a parent of NULL;
21898 this will be fixed up in decls_for_scope. */
21899 if (decl_function_context (decl
))
21900 context_die
= NULL
;
21904 case NAMELIST_DECL
:
21911 gen_decl_die (decl
, NULL
, context_die
);
21913 #ifdef ENABLE_CHECKING
21914 dw_die_ref die
= lookup_decl_die (decl
);
21920 /* Write the debugging output for DECL. */
21923 dwarf2out_function_decl (tree decl
)
21925 dwarf2out_decl (decl
);
21926 call_arg_locations
= NULL
;
21927 call_arg_loc_last
= NULL
;
21928 call_site_count
= -1;
21929 tail_call_site_count
= -1;
21930 decl_loc_table
->empty ();
21931 cached_dw_loc_list_table
->empty ();
21934 /* Output a marker (i.e. a label) for the beginning of the generated code for
21935 a lexical block. */
21938 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
21939 unsigned int blocknum
)
21941 switch_to_section (current_function_section ());
21942 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
21945 /* Output a marker (i.e. a label) for the end of the generated code for a
21949 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
21951 switch_to_section (current_function_section ());
21952 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
21955 /* Returns nonzero if it is appropriate not to emit any debugging
21956 information for BLOCK, because it doesn't contain any instructions.
21958 Don't allow this for blocks with nested functions or local classes
21959 as we would end up with orphans, and in the presence of scheduling
21960 we may end up calling them anyway. */
21963 dwarf2out_ignore_block (const_tree block
)
21968 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
21969 if (TREE_CODE (decl
) == FUNCTION_DECL
21970 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21972 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
21974 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
21975 if (TREE_CODE (decl
) == FUNCTION_DECL
21976 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21983 /* Hash table routines for file_hash. */
21986 dwarf_file_hasher::equal (dwarf_file_data
*p1
, const char *p2
)
21988 return filename_cmp (p1
->filename
, p2
) == 0;
21992 dwarf_file_hasher::hash (dwarf_file_data
*p
)
21994 return htab_hash_string (p
->filename
);
21997 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21998 dwarf2out.c) and return its "index". The index of each (known) filename is
21999 just a unique number which is associated with only that one filename. We
22000 need such numbers for the sake of generating labels (in the .debug_sfnames
22001 section) and references to those files numbers (in the .debug_srcinfo
22002 and.debug_macinfo sections). If the filename given as an argument is not
22003 found in our current list, add it to the list and assign it the next
22004 available unique index number. */
22006 static struct dwarf_file_data
*
22007 lookup_filename (const char *file_name
)
22009 struct dwarf_file_data
* created
;
22014 dwarf_file_data
**slot
22015 = file_table
->find_slot_with_hash (file_name
, htab_hash_string (file_name
),
22020 created
= ggc_alloc
<dwarf_file_data
> ();
22021 created
->filename
= file_name
;
22022 created
->emitted_number
= 0;
22027 /* If the assembler will construct the file table, then translate the compiler
22028 internal file table number into the assembler file table number, and emit
22029 a .file directive if we haven't already emitted one yet. The file table
22030 numbers are different because we prune debug info for unused variables and
22031 types, which may include filenames. */
22034 maybe_emit_file (struct dwarf_file_data
* fd
)
22036 if (! fd
->emitted_number
)
22038 if (last_emitted_file
)
22039 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
22041 fd
->emitted_number
= 1;
22042 last_emitted_file
= fd
;
22044 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22046 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
22047 output_quoted_string (asm_out_file
,
22048 remap_debug_filename (fd
->filename
));
22049 fputc ('\n', asm_out_file
);
22053 return fd
->emitted_number
;
22056 /* Schedule generation of a DW_AT_const_value attribute to DIE.
22057 That generation should happen after function debug info has been
22058 generated. The value of the attribute is the constant value of ARG. */
22061 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
22063 die_arg_entry entry
;
22068 if (!tmpl_value_parm_die_table
)
22069 vec_alloc (tmpl_value_parm_die_table
, 32);
22073 vec_safe_push (tmpl_value_parm_die_table
, entry
);
22076 /* Return TRUE if T is an instance of generic type, FALSE
22080 generic_type_p (tree t
)
22082 if (t
== NULL_TREE
|| !TYPE_P (t
))
22084 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
22087 /* Schedule the generation of the generic parameter dies for the
22088 instance of generic type T. The proper generation itself is later
22089 done by gen_scheduled_generic_parms_dies. */
22092 schedule_generic_params_dies_gen (tree t
)
22094 if (!generic_type_p (t
))
22097 if (!generic_type_instances
)
22098 vec_alloc (generic_type_instances
, 256);
22100 vec_safe_push (generic_type_instances
, t
);
22103 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
22104 by append_entry_to_tmpl_value_parm_die_table. This function must
22105 be called after function DIEs have been generated. */
22108 gen_remaining_tmpl_value_param_die_attribute (void)
22110 if (tmpl_value_parm_die_table
)
22115 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
22116 tree_add_const_value_attribute (e
->die
, e
->arg
);
22120 /* Generate generic parameters DIEs for instances of generic types
22121 that have been previously scheduled by
22122 schedule_generic_params_dies_gen. This function must be called
22123 after all the types of the CU have been laid out. */
22126 gen_scheduled_generic_parms_dies (void)
22131 if (!generic_type_instances
)
22134 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
22135 if (COMPLETE_TYPE_P (t
))
22136 gen_generic_params_dies (t
);
22140 /* Replace DW_AT_name for the decl with name. */
22143 dwarf2out_set_name (tree decl
, tree name
)
22149 die
= TYPE_SYMTAB_DIE (decl
);
22153 dname
= dwarf2_name (name
, 0);
22157 attr
= get_AT (die
, DW_AT_name
);
22160 struct indirect_string_node
*node
;
22162 node
= find_AT_string (dname
);
22163 /* replace the string. */
22164 attr
->dw_attr_val
.v
.val_str
= node
;
22168 add_name_attribute (die
, dname
);
22171 /* True if before or during processing of the first function being emitted. */
22172 static bool in_first_function_p
= true;
22173 /* True if loc_note during dwarf2out_var_location call might still be
22174 before first real instruction at address equal to .Ltext0. */
22175 static bool maybe_at_text_label_p
= true;
22176 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
22177 static unsigned int first_loclabel_num_not_at_text_label
;
22179 /* Called by the final INSN scan whenever we see a var location. We
22180 use it to drop labels in the right places, and throw the location in
22181 our lookup table. */
22184 dwarf2out_var_location (rtx_insn
*loc_note
)
22186 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
22187 struct var_loc_node
*newloc
;
22188 rtx_insn
*next_real
, *next_note
;
22189 static const char *last_label
;
22190 static const char *last_postcall_label
;
22191 static bool last_in_cold_section_p
;
22192 static rtx_insn
*expected_next_loc_note
;
22196 if (!NOTE_P (loc_note
))
22198 if (CALL_P (loc_note
))
22201 if (SIBLING_CALL_P (loc_note
))
22202 tail_call_site_count
++;
22207 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
22208 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
22211 /* Optimize processing a large consecutive sequence of location
22212 notes so we don't spend too much time in next_real_insn. If the
22213 next insn is another location note, remember the next_real_insn
22214 calculation for next time. */
22215 next_real
= cached_next_real_insn
;
22218 if (expected_next_loc_note
!= loc_note
)
22222 next_note
= NEXT_INSN (loc_note
);
22224 || next_note
->deleted ()
22225 || ! NOTE_P (next_note
)
22226 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
22227 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
22231 next_real
= next_real_insn (loc_note
);
22235 expected_next_loc_note
= next_note
;
22236 cached_next_real_insn
= next_real
;
22239 cached_next_real_insn
= NULL
;
22241 /* If there are no instructions which would be affected by this note,
22242 don't do anything. */
22244 && next_real
== NULL_RTX
22245 && !NOTE_DURING_CALL_P (loc_note
))
22248 if (next_real
== NULL_RTX
)
22249 next_real
= get_last_insn ();
22251 /* If there were any real insns between note we processed last time
22252 and this note (or if it is the first note), clear
22253 last_{,postcall_}label so that they are not reused this time. */
22254 if (last_var_location_insn
== NULL_RTX
22255 || last_var_location_insn
!= next_real
22256 || last_in_cold_section_p
!= in_cold_section_p
)
22259 last_postcall_label
= NULL
;
22264 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
22265 newloc
= add_var_loc_to_decl (decl
, loc_note
,
22266 NOTE_DURING_CALL_P (loc_note
)
22267 ? last_postcall_label
: last_label
);
22268 if (newloc
== NULL
)
22277 /* If there were no real insns between note we processed last time
22278 and this note, use the label we emitted last time. Otherwise
22279 create a new label and emit it. */
22280 if (last_label
== NULL
)
22282 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
22283 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
22285 last_label
= ggc_strdup (loclabel
);
22286 /* See if loclabel might be equal to .Ltext0. If yes,
22287 bump first_loclabel_num_not_at_text_label. */
22288 if (!have_multiple_function_sections
22289 && in_first_function_p
22290 && maybe_at_text_label_p
)
22292 static rtx_insn
*last_start
;
22294 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
22295 if (insn
== last_start
)
22297 else if (!NONDEBUG_INSN_P (insn
))
22301 rtx body
= PATTERN (insn
);
22302 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
22304 /* Inline asm could occupy zero bytes. */
22305 else if (GET_CODE (body
) == ASM_INPUT
22306 || asm_noperands (body
) >= 0)
22308 #ifdef HAVE_attr_length
22309 else if (get_attr_min_length (insn
) == 0)
22314 /* Assume insn has non-zero length. */
22315 maybe_at_text_label_p
= false;
22319 if (maybe_at_text_label_p
)
22321 last_start
= loc_note
;
22322 first_loclabel_num_not_at_text_label
= loclabel_num
;
22329 struct call_arg_loc_node
*ca_loc
22330 = ggc_cleared_alloc
<call_arg_loc_node
> ();
22331 rtx_insn
*prev
= prev_real_insn (loc_note
);
22333 ca_loc
->call_arg_loc_note
= loc_note
;
22334 ca_loc
->next
= NULL
;
22335 ca_loc
->label
= last_label
;
22338 || (NONJUMP_INSN_P (prev
)
22339 && GET_CODE (PATTERN (prev
)) == SEQUENCE
22340 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
22341 if (!CALL_P (prev
))
22342 prev
= as_a
<rtx_sequence
*> (PATTERN (prev
))->insn (0);
22343 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
22344 x
= get_call_rtx_from (PATTERN (prev
));
22347 x
= XEXP (XEXP (x
, 0), 0);
22348 if (GET_CODE (x
) == SYMBOL_REF
22349 && SYMBOL_REF_DECL (x
)
22350 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
22351 ca_loc
->symbol_ref
= x
;
22353 ca_loc
->block
= insn_scope (prev
);
22354 if (call_arg_locations
)
22355 call_arg_loc_last
->next
= ca_loc
;
22357 call_arg_locations
= ca_loc
;
22358 call_arg_loc_last
= ca_loc
;
22360 else if (!NOTE_DURING_CALL_P (loc_note
))
22361 newloc
->label
= last_label
;
22364 if (!last_postcall_label
)
22366 sprintf (loclabel
, "%s-1", last_label
);
22367 last_postcall_label
= ggc_strdup (loclabel
);
22369 newloc
->label
= last_postcall_label
;
22372 last_var_location_insn
= next_real
;
22373 last_in_cold_section_p
= in_cold_section_p
;
22376 /* Note in one location list that text section has changed. */
22379 var_location_switch_text_section_1 (var_loc_list
**slot
, void *)
22381 var_loc_list
*list
= *slot
;
22383 list
->last_before_switch
22384 = list
->last
->next
? list
->last
->next
: list
->last
;
22388 /* Note in all location lists that text section has changed. */
22391 var_location_switch_text_section (void)
22393 if (decl_loc_table
== NULL
)
22396 decl_loc_table
->traverse
<void *, var_location_switch_text_section_1
> (NULL
);
22399 /* Create a new line number table. */
22401 static dw_line_info_table
*
22402 new_line_info_table (void)
22404 dw_line_info_table
*table
;
22406 table
= ggc_cleared_alloc
<dw_line_info_table_struct
> ();
22407 table
->file_num
= 1;
22408 table
->line_num
= 1;
22409 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
22414 /* Lookup the "current" table into which we emit line info, so
22415 that we don't have to do it for every source line. */
22418 set_cur_line_info_table (section
*sec
)
22420 dw_line_info_table
*table
;
22422 if (sec
== text_section
)
22423 table
= text_section_line_info
;
22424 else if (sec
== cold_text_section
)
22426 table
= cold_text_section_line_info
;
22429 cold_text_section_line_info
= table
= new_line_info_table ();
22430 table
->end_label
= cold_end_label
;
22435 const char *end_label
;
22437 if (flag_reorder_blocks_and_partition
)
22439 if (in_cold_section_p
)
22440 end_label
= crtl
->subsections
.cold_section_end_label
;
22442 end_label
= crtl
->subsections
.hot_section_end_label
;
22446 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22447 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
22448 current_function_funcdef_no
);
22449 end_label
= ggc_strdup (label
);
22452 table
= new_line_info_table ();
22453 table
->end_label
= end_label
;
22455 vec_safe_push (separate_line_info
, table
);
22458 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22459 table
->is_stmt
= (cur_line_info_table
22460 ? cur_line_info_table
->is_stmt
22461 : DWARF_LINE_DEFAULT_IS_STMT_START
);
22462 cur_line_info_table
= table
;
22466 /* We need to reset the locations at the beginning of each
22467 function. We can't do this in the end_function hook, because the
22468 declarations that use the locations won't have been output when
22469 that hook is called. Also compute have_multiple_function_sections here. */
22472 dwarf2out_begin_function (tree fun
)
22474 section
*sec
= function_section (fun
);
22476 if (sec
!= text_section
)
22477 have_multiple_function_sections
= true;
22479 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
22481 gcc_assert (current_function_decl
== fun
);
22482 cold_text_section
= unlikely_text_section ();
22483 switch_to_section (cold_text_section
);
22484 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
22485 switch_to_section (sec
);
22488 dwarf2out_note_section_used ();
22489 call_site_count
= 0;
22490 tail_call_site_count
= 0;
22492 set_cur_line_info_table (sec
);
22495 /* Helper function of dwarf2out_end_function, called only after emitting
22496 the very first function into assembly. Check if some .debug_loc range
22497 might end with a .LVL* label that could be equal to .Ltext0.
22498 In that case we must force using absolute addresses in .debug_loc ranges,
22499 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
22500 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
22502 Set have_multiple_function_sections to true in that case and
22503 terminate htab traversal. */
22506 find_empty_loc_ranges_at_text_label (var_loc_list
**slot
, int)
22508 var_loc_list
*entry
= *slot
;
22509 struct var_loc_node
*node
;
22511 node
= entry
->first
;
22512 if (node
&& node
->next
&& node
->next
->label
)
22515 const char *label
= node
->next
->label
;
22516 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
22518 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
22520 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
22521 if (strcmp (label
, loclabel
) == 0)
22523 have_multiple_function_sections
= true;
22531 /* Hook called after emitting a function into assembly.
22532 This does something only for the very first function emitted. */
22535 dwarf2out_end_function (unsigned int)
22537 if (in_first_function_p
22538 && !have_multiple_function_sections
22539 && first_loclabel_num_not_at_text_label
22541 decl_loc_table
->traverse
<int, find_empty_loc_ranges_at_text_label
> (0);
22542 in_first_function_p
= false;
22543 maybe_at_text_label_p
= false;
22546 /* Temporary holder for dwarf2out_register_main_translation_unit. Used to let
22547 front-ends register a translation unit even before dwarf2out_init is
22549 static tree main_translation_unit
= NULL_TREE
;
22551 /* Hook called by front-ends after they built their main translation unit.
22552 Associate comp_unit_die to UNIT. */
22555 dwarf2out_register_main_translation_unit (tree unit
)
22557 gcc_assert (TREE_CODE (unit
) == TRANSLATION_UNIT_DECL
22558 && main_translation_unit
== NULL_TREE
);
22559 main_translation_unit
= unit
;
22560 /* If dwarf2out_init has not been called yet, it will perform the association
22561 itself looking at main_translation_unit. */
22562 if (decl_die_table
!= NULL
)
22563 equate_decl_number_to_die (unit
, comp_unit_die ());
22566 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
22569 push_dw_line_info_entry (dw_line_info_table
*table
,
22570 enum dw_line_info_opcode opcode
, unsigned int val
)
22572 dw_line_info_entry e
;
22575 vec_safe_push (table
->entries
, e
);
22578 /* Output a label to mark the beginning of a source code line entry
22579 and record information relating to this source line, in
22580 'line_info_table' for later output of the .debug_line section. */
22581 /* ??? The discriminator parameter ought to be unsigned. */
22584 dwarf2out_source_line (unsigned int line
, const char *filename
,
22585 int discriminator
, bool is_stmt
)
22587 unsigned int file_num
;
22588 dw_line_info_table
*table
;
22590 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
22593 /* The discriminator column was added in dwarf4. Simplify the below
22594 by simply removing it if we're not supposed to output it. */
22595 if (dwarf_version
< 4 && dwarf_strict
)
22598 table
= cur_line_info_table
;
22599 file_num
= maybe_emit_file (lookup_filename (filename
));
22601 /* ??? TODO: Elide duplicate line number entries. Traditionally,
22602 the debugger has used the second (possibly duplicate) line number
22603 at the beginning of the function to mark the end of the prologue.
22604 We could eliminate any other duplicates within the function. For
22605 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
22606 that second line number entry. */
22607 /* Recall that this end-of-prologue indication is *not* the same thing
22608 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
22609 to which the hook corresponds, follows the last insn that was
22610 emitted by gen_prologue. What we need is to precede the first insn
22611 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
22612 insn that corresponds to something the user wrote. These may be
22613 very different locations once scheduling is enabled. */
22615 if (0 && file_num
== table
->file_num
22616 && line
== table
->line_num
22617 && discriminator
== table
->discrim_num
22618 && is_stmt
== table
->is_stmt
)
22621 switch_to_section (current_function_section ());
22623 /* If requested, emit something human-readable. */
22624 if (flag_debug_asm
)
22625 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
22627 if (DWARF2_ASM_LINE_DEBUG_INFO
)
22629 /* Emit the .loc directive understood by GNU as. */
22630 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
22631 file_num, line, is_stmt, discriminator */
22632 fputs ("\t.loc ", asm_out_file
);
22633 fprint_ul (asm_out_file
, file_num
);
22634 putc (' ', asm_out_file
);
22635 fprint_ul (asm_out_file
, line
);
22636 putc (' ', asm_out_file
);
22637 putc ('0', asm_out_file
);
22639 if (is_stmt
!= table
->is_stmt
)
22641 fputs (" is_stmt ", asm_out_file
);
22642 putc (is_stmt
? '1' : '0', asm_out_file
);
22644 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
22646 gcc_assert (discriminator
> 0);
22647 fputs (" discriminator ", asm_out_file
);
22648 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
22650 putc ('\n', asm_out_file
);
22654 unsigned int label_num
= ++line_info_label_num
;
22656 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
22658 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
22659 if (file_num
!= table
->file_num
)
22660 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
22661 if (discriminator
!= table
->discrim_num
)
22662 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
22663 if (is_stmt
!= table
->is_stmt
)
22664 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
22665 push_dw_line_info_entry (table
, LI_set_line
, line
);
22668 table
->file_num
= file_num
;
22669 table
->line_num
= line
;
22670 table
->discrim_num
= discriminator
;
22671 table
->is_stmt
= is_stmt
;
22672 table
->in_use
= true;
22675 /* Record the beginning of a new source file. */
22678 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
22680 if (flag_eliminate_dwarf2_dups
)
22682 /* Record the beginning of the file for break_out_includes. */
22683 dw_die_ref bincl_die
;
22685 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
22686 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
22689 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22692 e
.code
= DW_MACINFO_start_file
;
22694 e
.info
= ggc_strdup (filename
);
22695 vec_safe_push (macinfo_table
, e
);
22699 /* Record the end of a source file. */
22702 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
22704 if (flag_eliminate_dwarf2_dups
)
22705 /* Record the end of the file for break_out_includes. */
22706 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
22708 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22711 e
.code
= DW_MACINFO_end_file
;
22714 vec_safe_push (macinfo_table
, e
);
22718 /* Called from debug_define in toplev.c. The `buffer' parameter contains
22719 the tail part of the directive line, i.e. the part which is past the
22720 initial whitespace, #, whitespace, directive-name, whitespace part. */
22723 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
22724 const char *buffer ATTRIBUTE_UNUSED
)
22726 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22729 /* Insert a dummy first entry to be able to optimize the whole
22730 predefined macro block using DW_MACRO_GNU_transparent_include. */
22731 if (macinfo_table
->is_empty () && lineno
<= 1)
22736 vec_safe_push (macinfo_table
, e
);
22738 e
.code
= DW_MACINFO_define
;
22740 e
.info
= ggc_strdup (buffer
);
22741 vec_safe_push (macinfo_table
, e
);
22745 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
22746 the tail part of the directive line, i.e. the part which is past the
22747 initial whitespace, #, whitespace, directive-name, whitespace part. */
22750 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
22751 const char *buffer ATTRIBUTE_UNUSED
)
22753 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22756 /* Insert a dummy first entry to be able to optimize the whole
22757 predefined macro block using DW_MACRO_GNU_transparent_include. */
22758 if (macinfo_table
->is_empty () && lineno
<= 1)
22763 vec_safe_push (macinfo_table
, e
);
22765 e
.code
= DW_MACINFO_undef
;
22767 e
.info
= ggc_strdup (buffer
);
22768 vec_safe_push (macinfo_table
, e
);
22772 /* Helpers to manipulate hash table of CUs. */
22774 struct macinfo_entry_hasher
: nofree_ptr_hash
<macinfo_entry
>
22776 static inline hashval_t
hash (const macinfo_entry
*);
22777 static inline bool equal (const macinfo_entry
*, const macinfo_entry
*);
22781 macinfo_entry_hasher::hash (const macinfo_entry
*entry
)
22783 return htab_hash_string (entry
->info
);
22787 macinfo_entry_hasher::equal (const macinfo_entry
*entry1
,
22788 const macinfo_entry
*entry2
)
22790 return !strcmp (entry1
->info
, entry2
->info
);
22793 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
22795 /* Output a single .debug_macinfo entry. */
22798 output_macinfo_op (macinfo_entry
*ref
)
22802 struct indirect_string_node
*node
;
22803 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22804 struct dwarf_file_data
*fd
;
22808 case DW_MACINFO_start_file
:
22809 fd
= lookup_filename (ref
->info
);
22810 file_num
= maybe_emit_file (fd
);
22811 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
22812 dw2_asm_output_data_uleb128 (ref
->lineno
,
22813 "Included from line number %lu",
22814 (unsigned long) ref
->lineno
);
22815 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
22817 case DW_MACINFO_end_file
:
22818 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
22820 case DW_MACINFO_define
:
22821 case DW_MACINFO_undef
:
22822 len
= strlen (ref
->info
) + 1;
22824 && len
> DWARF_OFFSET_SIZE
22825 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
22826 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
22828 ref
->code
= ref
->code
== DW_MACINFO_define
22829 ? DW_MACRO_GNU_define_indirect
22830 : DW_MACRO_GNU_undef_indirect
;
22831 output_macinfo_op (ref
);
22834 dw2_asm_output_data (1, ref
->code
,
22835 ref
->code
== DW_MACINFO_define
22836 ? "Define macro" : "Undefine macro");
22837 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22838 (unsigned long) ref
->lineno
);
22839 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
22841 case DW_MACRO_GNU_define_indirect
:
22842 case DW_MACRO_GNU_undef_indirect
:
22843 node
= find_AT_string (ref
->info
);
22845 && ((node
->form
== DW_FORM_strp
)
22846 || (node
->form
== DW_FORM_GNU_str_index
)));
22847 dw2_asm_output_data (1, ref
->code
,
22848 ref
->code
== DW_MACRO_GNU_define_indirect
22849 ? "Define macro indirect"
22850 : "Undefine macro indirect");
22851 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
22852 (unsigned long) ref
->lineno
);
22853 if (node
->form
== DW_FORM_strp
)
22854 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
22855 debug_str_section
, "The macro: \"%s\"",
22858 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
22861 case DW_MACRO_GNU_transparent_include
:
22862 dw2_asm_output_data (1, ref
->code
, "Transparent include");
22863 ASM_GENERATE_INTERNAL_LABEL (label
,
22864 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
22865 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
22868 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
22869 ASM_COMMENT_START
, (unsigned long) ref
->code
);
22874 /* Attempt to make a sequence of define/undef macinfo ops shareable with
22875 other compilation unit .debug_macinfo sections. IDX is the first
22876 index of a define/undef, return the number of ops that should be
22877 emitted in a comdat .debug_macinfo section and emit
22878 a DW_MACRO_GNU_transparent_include entry referencing it.
22879 If the define/undef entry should be emitted normally, return 0. */
22882 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
22883 macinfo_hash_type
**macinfo_htab
)
22885 macinfo_entry
*first
, *second
, *cur
, *inc
;
22886 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
22887 unsigned char checksum
[16];
22888 struct md5_ctx ctx
;
22889 char *grp_name
, *tail
;
22891 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
22892 macinfo_entry
**slot
;
22894 first
= &(*macinfo_table
)[idx
];
22895 second
= &(*macinfo_table
)[idx
+ 1];
22897 /* Optimize only if there are at least two consecutive define/undef ops,
22898 and either all of them are before first DW_MACINFO_start_file
22899 with lineno {0,1} (i.e. predefined macro block), or all of them are
22900 in some included header file. */
22901 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
22903 if (vec_safe_is_empty (files
))
22905 if (first
->lineno
> 1 || second
->lineno
> 1)
22908 else if (first
->lineno
== 0)
22911 /* Find the last define/undef entry that can be grouped together
22912 with first and at the same time compute md5 checksum of their
22913 codes, linenumbers and strings. */
22914 md5_init_ctx (&ctx
);
22915 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
22916 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
22918 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
22922 unsigned char code
= cur
->code
;
22923 md5_process_bytes (&code
, 1, &ctx
);
22924 checksum_uleb128 (cur
->lineno
, &ctx
);
22925 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
22927 md5_finish_ctx (&ctx
, checksum
);
22930 /* From the containing include filename (if any) pick up just
22931 usable characters from its basename. */
22932 if (vec_safe_is_empty (files
))
22935 base
= lbasename (files
->last ().info
);
22936 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
22937 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22938 encoded_filename_len
++;
22939 /* Count . at the end. */
22940 if (encoded_filename_len
)
22941 encoded_filename_len
++;
22943 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
22944 linebuf_len
= strlen (linebuf
);
22946 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
22947 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
22949 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
22950 tail
= grp_name
+ 4;
22951 if (encoded_filename_len
)
22953 for (i
= 0; base
[i
]; i
++)
22954 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22958 memcpy (tail
, linebuf
, linebuf_len
);
22959 tail
+= linebuf_len
;
22961 for (i
= 0; i
< 16; i
++)
22962 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
22964 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
22965 in the empty vector entry before the first define/undef. */
22966 inc
= &(*macinfo_table
)[idx
- 1];
22967 inc
->code
= DW_MACRO_GNU_transparent_include
;
22969 inc
->info
= ggc_strdup (grp_name
);
22970 if (!*macinfo_htab
)
22971 *macinfo_htab
= new macinfo_hash_type (10);
22972 /* Avoid emitting duplicates. */
22973 slot
= (*macinfo_htab
)->find_slot (inc
, INSERT
);
22978 /* If such an entry has been used before, just emit
22979 a DW_MACRO_GNU_transparent_include op. */
22981 output_macinfo_op (inc
);
22982 /* And clear all macinfo_entry in the range to avoid emitting them
22983 in the second pass. */
22984 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
22993 inc
->lineno
= (*macinfo_htab
)->elements ();
22994 output_macinfo_op (inc
);
22999 /* Save any strings needed by the macinfo table in the debug str
23000 table. All strings must be collected into the table by the time
23001 index_string is called. */
23004 save_macinfo_strings (void)
23008 macinfo_entry
*ref
;
23010 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
23014 /* Match the logic in output_macinfo_op to decide on
23015 indirect strings. */
23016 case DW_MACINFO_define
:
23017 case DW_MACINFO_undef
:
23018 len
= strlen (ref
->info
) + 1;
23020 && len
> DWARF_OFFSET_SIZE
23021 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
23022 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
23023 set_indirect_string (find_AT_string (ref
->info
));
23025 case DW_MACRO_GNU_define_indirect
:
23026 case DW_MACRO_GNU_undef_indirect
:
23027 set_indirect_string (find_AT_string (ref
->info
));
23035 /* Output macinfo section(s). */
23038 output_macinfo (void)
23041 unsigned long length
= vec_safe_length (macinfo_table
);
23042 macinfo_entry
*ref
;
23043 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
23044 macinfo_hash_type
*macinfo_htab
= NULL
;
23049 /* output_macinfo* uses these interchangeably. */
23050 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
23051 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
23052 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
23053 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
23055 /* For .debug_macro emit the section header. */
23058 dw2_asm_output_data (2, 4, "DWARF macro version number");
23059 if (DWARF_OFFSET_SIZE
== 8)
23060 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
23062 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
23063 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
23064 (!dwarf_split_debug_info
? debug_line_section_label
23065 : debug_skeleton_line_section_label
),
23066 debug_line_section
, NULL
);
23069 /* In the first loop, it emits the primary .debug_macinfo section
23070 and after each emitted op the macinfo_entry is cleared.
23071 If a longer range of define/undef ops can be optimized using
23072 DW_MACRO_GNU_transparent_include, the
23073 DW_MACRO_GNU_transparent_include op is emitted and kept in
23074 the vector before the first define/undef in the range and the
23075 whole range of define/undef ops is not emitted and kept. */
23076 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
23080 case DW_MACINFO_start_file
:
23081 vec_safe_push (files
, *ref
);
23083 case DW_MACINFO_end_file
:
23084 if (!vec_safe_is_empty (files
))
23087 case DW_MACINFO_define
:
23088 case DW_MACINFO_undef
:
23090 && HAVE_COMDAT_GROUP
23091 && vec_safe_length (files
) != 1
23094 && (*macinfo_table
)[i
- 1].code
== 0)
23096 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
23105 /* A dummy entry may be inserted at the beginning to be able
23106 to optimize the whole block of predefined macros. */
23112 output_macinfo_op (ref
);
23120 delete macinfo_htab
;
23121 macinfo_htab
= NULL
;
23123 /* If any DW_MACRO_GNU_transparent_include were used, on those
23124 DW_MACRO_GNU_transparent_include entries terminate the
23125 current chain and switch to a new comdat .debug_macinfo
23126 section and emit the define/undef entries within it. */
23127 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
23132 case DW_MACRO_GNU_transparent_include
:
23134 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
23135 tree comdat_key
= get_identifier (ref
->info
);
23136 /* Terminate the previous .debug_macinfo section. */
23137 dw2_asm_output_data (1, 0, "End compilation unit");
23138 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
23140 | SECTION_LINKONCE
,
23142 ASM_GENERATE_INTERNAL_LABEL (label
,
23143 DEBUG_MACRO_SECTION_LABEL
,
23145 ASM_OUTPUT_LABEL (asm_out_file
, label
);
23148 dw2_asm_output_data (2, 4, "DWARF macro version number");
23149 if (DWARF_OFFSET_SIZE
== 8)
23150 dw2_asm_output_data (1, 1, "Flags: 64-bit");
23152 dw2_asm_output_data (1, 0, "Flags: 32-bit");
23155 case DW_MACINFO_define
:
23156 case DW_MACINFO_undef
:
23157 output_macinfo_op (ref
);
23162 gcc_unreachable ();
23166 /* Set up for Dwarf output at the start of compilation. */
23169 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
23171 /* This option is currently broken, see (PR53118 and PR46102). */
23172 if (flag_eliminate_dwarf2_dups
23173 && strstr (lang_hooks
.name
, "C++"))
23175 warning (0, "-feliminate-dwarf2-dups is broken for C++, ignoring");
23176 flag_eliminate_dwarf2_dups
= 0;
23179 /* Allocate the file_table. */
23180 file_table
= hash_table
<dwarf_file_hasher
>::create_ggc (50);
23182 /* Allocate the decl_die_table. */
23183 decl_die_table
= hash_table
<decl_die_hasher
>::create_ggc (10);
23185 /* Allocate the decl_loc_table. */
23186 decl_loc_table
= hash_table
<decl_loc_hasher
>::create_ggc (10);
23188 /* Allocate the cached_dw_loc_list_table. */
23189 cached_dw_loc_list_table
= hash_table
<dw_loc_list_hasher
>::create_ggc (10);
23191 /* Allocate the initial hunk of the decl_scope_table. */
23192 vec_alloc (decl_scope_table
, 256);
23194 /* Allocate the initial hunk of the abbrev_die_table. */
23195 abbrev_die_table
= ggc_cleared_vec_alloc
<dw_die_ref
>
23196 (ABBREV_DIE_TABLE_INCREMENT
);
23197 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
23198 /* Zero-th entry is allocated, but unused. */
23199 abbrev_die_table_in_use
= 1;
23201 /* Allocate the pubtypes and pubnames vectors. */
23202 vec_alloc (pubname_table
, 32);
23203 vec_alloc (pubtype_table
, 32);
23205 vec_alloc (incomplete_types
, 64);
23207 vec_alloc (used_rtx_array
, 32);
23209 if (!dwarf_split_debug_info
)
23211 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
23212 SECTION_DEBUG
, NULL
);
23213 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
23214 SECTION_DEBUG
, NULL
);
23215 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
23216 SECTION_DEBUG
, NULL
);
23220 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
23221 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23222 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
23223 SECTION_DEBUG
| SECTION_EXCLUDE
,
23225 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
23226 SECTION_DEBUG
, NULL
);
23227 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
23228 SECTION_DEBUG
, NULL
);
23229 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
23230 SECTION_DEBUG
, NULL
);
23231 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
23232 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
23234 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
23235 the main .o, but the skeleton_line goes into the split off dwo. */
23236 debug_skeleton_line_section
23237 = get_section (DEBUG_DWO_LINE_SECTION
,
23238 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23239 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
23240 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
23241 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
23242 SECTION_DEBUG
| SECTION_EXCLUDE
,
23244 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
23245 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
23246 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
23247 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
23248 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
23249 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
23251 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
23252 SECTION_DEBUG
, NULL
);
23253 debug_macinfo_section
= get_section (dwarf_strict
23254 ? DEBUG_MACINFO_SECTION
23255 : DEBUG_MACRO_SECTION
,
23256 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
23257 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
23258 SECTION_DEBUG
, NULL
);
23259 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
23260 SECTION_DEBUG
, NULL
);
23261 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
23262 SECTION_DEBUG
, NULL
);
23263 debug_str_section
= get_section (DEBUG_STR_SECTION
,
23264 DEBUG_STR_SECTION_FLAGS
, NULL
);
23265 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
23266 SECTION_DEBUG
, NULL
);
23267 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
23268 SECTION_DEBUG
, NULL
);
23270 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
23271 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
23272 DEBUG_ABBREV_SECTION_LABEL
, 0);
23273 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
23274 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
23275 COLD_TEXT_SECTION_LABEL
, 0);
23276 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
23278 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
23279 DEBUG_INFO_SECTION_LABEL
, 0);
23280 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
23281 DEBUG_LINE_SECTION_LABEL
, 0);
23282 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
23283 DEBUG_RANGES_SECTION_LABEL
, 0);
23284 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
23285 DEBUG_ADDR_SECTION_LABEL
, 0);
23286 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
23288 ? DEBUG_MACINFO_SECTION_LABEL
23289 : DEBUG_MACRO_SECTION_LABEL
, 0);
23290 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
23292 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
23293 vec_alloc (macinfo_table
, 64);
23295 switch_to_section (text_section
);
23296 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
23298 /* Make sure the line number table for .text always exists. */
23299 text_section_line_info
= new_line_info_table ();
23300 text_section_line_info
->end_label
= text_end_label
;
23302 /* If front-ends already registered a main translation unit but we were not
23303 ready to perform the association, do this now. */
23304 if (main_translation_unit
!= NULL_TREE
)
23305 equate_decl_number_to_die (main_translation_unit
, comp_unit_die ());
23308 /* Called before compile () starts outputtting functions, variables
23309 and toplevel asms into assembly. */
23312 dwarf2out_assembly_start (void)
23314 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
23315 && dwarf2out_do_cfi_asm ()
23316 && (!(flag_unwind_tables
|| flag_exceptions
)
23317 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
23318 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
23321 /* A helper function for dwarf2out_finish called through
23322 htab_traverse. Assign a string its index. All strings must be
23323 collected into the table by the time index_string is called,
23324 because the indexing code relies on htab_traverse to traverse nodes
23325 in the same order for each run. */
23328 index_string (indirect_string_node
**h
, unsigned int *index
)
23330 indirect_string_node
*node
= *h
;
23332 find_string_form (node
);
23333 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23335 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
23336 node
->index
= *index
;
23342 /* A helper function for output_indirect_strings called through
23343 htab_traverse. Output the offset to a string and update the
23347 output_index_string_offset (indirect_string_node
**h
, unsigned int *offset
)
23349 indirect_string_node
*node
= *h
;
23351 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23353 /* Assert that this node has been assigned an index. */
23354 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
23355 && node
->index
!= NOT_INDEXED
);
23356 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
23357 "indexed string 0x%x: %s", node
->index
, node
->str
);
23358 *offset
+= strlen (node
->str
) + 1;
23363 /* A helper function for dwarf2out_finish called through
23364 htab_traverse. Output the indexed string. */
23367 output_index_string (indirect_string_node
**h
, unsigned int *cur_idx
)
23369 struct indirect_string_node
*node
= *h
;
23371 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
23373 /* Assert that the strings are output in the same order as their
23374 indexes were assigned. */
23375 gcc_assert (*cur_idx
== node
->index
);
23376 assemble_string (node
->str
, strlen (node
->str
) + 1);
23382 /* A helper function for dwarf2out_finish called through
23383 htab_traverse. Emit one queued .debug_str string. */
23386 output_indirect_string (indirect_string_node
**h
, void *)
23388 struct indirect_string_node
*node
= *h
;
23390 node
->form
= find_string_form (node
);
23391 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
23393 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
23394 assemble_string (node
->str
, strlen (node
->str
) + 1);
23400 /* Output the indexed string table. */
23403 output_indirect_strings (void)
23405 switch_to_section (debug_str_section
);
23406 if (!dwarf_split_debug_info
)
23407 debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
23410 unsigned int offset
= 0;
23411 unsigned int cur_idx
= 0;
23413 skeleton_debug_str_hash
->traverse
<void *, output_indirect_string
> (NULL
);
23415 switch_to_section (debug_str_offsets_section
);
23416 debug_str_hash
->traverse_noresize
23417 <unsigned int *, output_index_string_offset
> (&offset
);
23418 switch_to_section (debug_str_dwo_section
);
23419 debug_str_hash
->traverse_noresize
<unsigned int *, output_index_string
>
23424 /* Callback for htab_traverse to assign an index to an entry in the
23425 table, and to write that entry to the .debug_addr section. */
23428 output_addr_table_entry (addr_table_entry
**slot
, unsigned int *cur_index
)
23430 addr_table_entry
*entry
= *slot
;
23432 if (entry
->refcount
== 0)
23434 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
23435 || entry
->index
== NOT_INDEXED
);
23439 gcc_assert (entry
->index
== *cur_index
);
23442 switch (entry
->kind
)
23445 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
23446 "0x%x", entry
->index
);
23448 case ate_kind_rtx_dtprel
:
23449 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
23450 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
23453 fputc ('\n', asm_out_file
);
23455 case ate_kind_label
:
23456 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
23457 "0x%x", entry
->index
);
23460 gcc_unreachable ();
23465 /* Produce the .debug_addr section. */
23468 output_addr_table (void)
23470 unsigned int index
= 0;
23471 if (addr_index_table
== NULL
|| addr_index_table
->size () == 0)
23474 switch_to_section (debug_addr_section
);
23476 ->traverse_noresize
<unsigned int *, output_addr_table_entry
> (&index
);
23479 #if ENABLE_ASSERT_CHECKING
23480 /* Verify that all marks are clear. */
23483 verify_marks_clear (dw_die_ref die
)
23487 gcc_assert (! die
->die_mark
);
23488 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
23490 #endif /* ENABLE_ASSERT_CHECKING */
23492 /* Clear the marks for a die and its children.
23493 Be cool if the mark isn't set. */
23496 prune_unmark_dies (dw_die_ref die
)
23502 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
23505 /* Given DIE that we're marking as used, find any other dies
23506 it references as attributes and mark them as used. */
23509 prune_unused_types_walk_attribs (dw_die_ref die
)
23514 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23516 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
23518 /* A reference to another DIE.
23519 Make sure that it will get emitted.
23520 If it was broken out into a comdat group, don't follow it. */
23521 if (! AT_ref (a
)->comdat_type_p
23522 || a
->dw_attr
== DW_AT_specification
)
23523 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
23525 /* Set the string's refcount to 0 so that prune_unused_types_mark
23526 accounts properly for it. */
23527 if (AT_class (a
) == dw_val_class_str
)
23528 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
23532 /* Mark the generic parameters and arguments children DIEs of DIE. */
23535 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
23539 if (die
== NULL
|| die
->die_child
== NULL
)
23541 c
= die
->die_child
;
23544 if (is_template_parameter (c
))
23545 prune_unused_types_mark (c
, 1);
23547 } while (c
&& c
!= die
->die_child
);
23550 /* Mark DIE as being used. If DOKIDS is true, then walk down
23551 to DIE's children. */
23554 prune_unused_types_mark (dw_die_ref die
, int dokids
)
23558 if (die
->die_mark
== 0)
23560 /* We haven't done this node yet. Mark it as used. */
23562 /* If this is the DIE of a generic type instantiation,
23563 mark the children DIEs that describe its generic parms and
23565 prune_unused_types_mark_generic_parms_dies (die
);
23567 /* We also have to mark its parents as used.
23568 (But we don't want to mark our parent's kids due to this,
23569 unless it is a class.) */
23570 if (die
->die_parent
)
23571 prune_unused_types_mark (die
->die_parent
,
23572 class_scope_p (die
->die_parent
));
23574 /* Mark any referenced nodes. */
23575 prune_unused_types_walk_attribs (die
);
23577 /* If this node is a specification,
23578 also mark the definition, if it exists. */
23579 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
23580 prune_unused_types_mark (die
->die_definition
, 1);
23583 if (dokids
&& die
->die_mark
!= 2)
23585 /* We need to walk the children, but haven't done so yet.
23586 Remember that we've walked the kids. */
23589 /* If this is an array type, we need to make sure our
23590 kids get marked, even if they're types. If we're
23591 breaking out types into comdat sections, do this
23592 for all type definitions. */
23593 if (die
->die_tag
== DW_TAG_array_type
23594 || (use_debug_types
23595 && is_type_die (die
) && ! is_declaration_die (die
)))
23596 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
23598 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
23602 /* For local classes, look if any static member functions were emitted
23603 and if so, mark them. */
23606 prune_unused_types_walk_local_classes (dw_die_ref die
)
23610 if (die
->die_mark
== 2)
23613 switch (die
->die_tag
)
23615 case DW_TAG_structure_type
:
23616 case DW_TAG_union_type
:
23617 case DW_TAG_class_type
:
23620 case DW_TAG_subprogram
:
23621 if (!get_AT_flag (die
, DW_AT_declaration
)
23622 || die
->die_definition
!= NULL
)
23623 prune_unused_types_mark (die
, 1);
23630 /* Mark children. */
23631 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
23634 /* Walk the tree DIE and mark types that we actually use. */
23637 prune_unused_types_walk (dw_die_ref die
)
23641 /* Don't do anything if this node is already marked and
23642 children have been marked as well. */
23643 if (die
->die_mark
== 2)
23646 switch (die
->die_tag
)
23648 case DW_TAG_structure_type
:
23649 case DW_TAG_union_type
:
23650 case DW_TAG_class_type
:
23651 if (die
->die_perennial_p
)
23654 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
23655 if (c
->die_tag
== DW_TAG_subprogram
)
23658 /* Finding used static member functions inside of classes
23659 is needed just for local classes, because for other classes
23660 static member function DIEs with DW_AT_specification
23661 are emitted outside of the DW_TAG_*_type. If we ever change
23662 it, we'd need to call this even for non-local classes. */
23664 prune_unused_types_walk_local_classes (die
);
23666 /* It's a type node --- don't mark it. */
23669 case DW_TAG_const_type
:
23670 case DW_TAG_packed_type
:
23671 case DW_TAG_pointer_type
:
23672 case DW_TAG_reference_type
:
23673 case DW_TAG_rvalue_reference_type
:
23674 case DW_TAG_volatile_type
:
23675 case DW_TAG_typedef
:
23676 case DW_TAG_array_type
:
23677 case DW_TAG_interface_type
:
23678 case DW_TAG_friend
:
23679 case DW_TAG_variant_part
:
23680 case DW_TAG_enumeration_type
:
23681 case DW_TAG_subroutine_type
:
23682 case DW_TAG_string_type
:
23683 case DW_TAG_set_type
:
23684 case DW_TAG_subrange_type
:
23685 case DW_TAG_ptr_to_member_type
:
23686 case DW_TAG_file_type
:
23687 if (die
->die_perennial_p
)
23690 /* It's a type node --- don't mark it. */
23694 /* Mark everything else. */
23698 if (die
->die_mark
== 0)
23702 /* Now, mark any dies referenced from here. */
23703 prune_unused_types_walk_attribs (die
);
23708 /* Mark children. */
23709 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
23712 /* Increment the string counts on strings referred to from DIE's
23716 prune_unused_types_update_strings (dw_die_ref die
)
23721 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23722 if (AT_class (a
) == dw_val_class_str
)
23724 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
23726 /* Avoid unnecessarily putting strings that are used less than
23727 twice in the hash table. */
23729 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
23731 indirect_string_node
**slot
23732 = debug_str_hash
->find_slot_with_hash (s
->str
,
23733 htab_hash_string (s
->str
),
23735 gcc_assert (*slot
== NULL
);
23741 /* Remove from the tree DIE any dies that aren't marked. */
23744 prune_unused_types_prune (dw_die_ref die
)
23748 gcc_assert (die
->die_mark
);
23749 prune_unused_types_update_strings (die
);
23751 if (! die
->die_child
)
23754 c
= die
->die_child
;
23756 dw_die_ref prev
= c
;
23757 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
23758 if (c
== die
->die_child
)
23760 /* No marked children between 'prev' and the end of the list. */
23762 /* No marked children at all. */
23763 die
->die_child
= NULL
;
23766 prev
->die_sib
= c
->die_sib
;
23767 die
->die_child
= prev
;
23772 if (c
!= prev
->die_sib
)
23774 prune_unused_types_prune (c
);
23775 } while (c
!= die
->die_child
);
23778 /* Remove dies representing declarations that we never use. */
23781 prune_unused_types (void)
23784 limbo_die_node
*node
;
23785 comdat_type_node
*ctnode
;
23787 dw_die_ref base_type
;
23789 #if ENABLE_ASSERT_CHECKING
23790 /* All the marks should already be clear. */
23791 verify_marks_clear (comp_unit_die ());
23792 for (node
= limbo_die_list
; node
; node
= node
->next
)
23793 verify_marks_clear (node
->die
);
23794 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23795 verify_marks_clear (ctnode
->root_die
);
23796 #endif /* ENABLE_ASSERT_CHECKING */
23798 /* Mark types that are used in global variables. */
23799 premark_types_used_by_global_vars ();
23801 /* Set the mark on nodes that are actually used. */
23802 prune_unused_types_walk (comp_unit_die ());
23803 for (node
= limbo_die_list
; node
; node
= node
->next
)
23804 prune_unused_types_walk (node
->die
);
23805 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23807 prune_unused_types_walk (ctnode
->root_die
);
23808 prune_unused_types_mark (ctnode
->type_die
, 1);
23811 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
23812 are unusual in that they are pubnames that are the children of pubtypes.
23813 They should only be marked via their parent DW_TAG_enumeration_type die,
23814 not as roots in themselves. */
23815 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
23816 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
23817 prune_unused_types_mark (pub
->die
, 1);
23818 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
23819 prune_unused_types_mark (base_type
, 1);
23821 if (debug_str_hash
)
23822 debug_str_hash
->empty ();
23823 if (skeleton_debug_str_hash
)
23824 skeleton_debug_str_hash
->empty ();
23825 prune_unused_types_prune (comp_unit_die ());
23826 for (limbo_die_node
**pnode
= &limbo_die_list
; *pnode
; )
23829 if (!node
->die
->die_mark
)
23830 *pnode
= node
->next
;
23833 prune_unused_types_prune (node
->die
);
23834 pnode
= &node
->next
;
23837 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23838 prune_unused_types_prune (ctnode
->root_die
);
23840 /* Leave the marks clear. */
23841 prune_unmark_dies (comp_unit_die ());
23842 for (node
= limbo_die_list
; node
; node
= node
->next
)
23843 prune_unmark_dies (node
->die
);
23844 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
23845 prune_unmark_dies (ctnode
->root_die
);
23848 /* Set the parameter to true if there are any relative pathnames in
23851 file_table_relative_p (dwarf_file_data
**slot
, bool *p
)
23853 struct dwarf_file_data
*d
= *slot
;
23854 if (!IS_ABSOLUTE_PATH (d
->filename
))
23862 /* Helpers to manipulate hash table of comdat type units. */
23864 struct comdat_type_hasher
: nofree_ptr_hash
<comdat_type_node
>
23866 static inline hashval_t
hash (const comdat_type_node
*);
23867 static inline bool equal (const comdat_type_node
*, const comdat_type_node
*);
23871 comdat_type_hasher::hash (const comdat_type_node
*type_node
)
23874 memcpy (&h
, type_node
->signature
, sizeof (h
));
23879 comdat_type_hasher::equal (const comdat_type_node
*type_node_1
,
23880 const comdat_type_node
*type_node_2
)
23882 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
23883 DWARF_TYPE_SIGNATURE_SIZE
));
23886 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
23887 to the location it would have been added, should we know its
23888 DECL_ASSEMBLER_NAME when we added other attributes. This will
23889 probably improve compactness of debug info, removing equivalent
23890 abbrevs, and hide any differences caused by deferring the
23891 computation of the assembler name, triggered by e.g. PCH. */
23894 move_linkage_attr (dw_die_ref die
)
23896 unsigned ix
= vec_safe_length (die
->die_attr
);
23897 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
23899 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
23900 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
23904 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
23906 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
23910 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
23912 die
->die_attr
->pop ();
23913 die
->die_attr
->quick_insert (ix
, linkage
);
23917 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
23918 referenced from typed stack ops and count how often they are used. */
23921 mark_base_types (dw_loc_descr_ref loc
)
23923 dw_die_ref base_type
= NULL
;
23925 for (; loc
; loc
= loc
->dw_loc_next
)
23927 switch (loc
->dw_loc_opc
)
23929 case DW_OP_GNU_regval_type
:
23930 case DW_OP_GNU_deref_type
:
23931 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23933 case DW_OP_GNU_convert
:
23934 case DW_OP_GNU_reinterpret
:
23935 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
23938 case DW_OP_GNU_const_type
:
23939 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23941 case DW_OP_GNU_entry_value
:
23942 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
23947 gcc_assert (base_type
->die_parent
== comp_unit_die ());
23948 if (base_type
->die_mark
)
23949 base_type
->die_mark
++;
23952 base_types
.safe_push (base_type
);
23953 base_type
->die_mark
= 1;
23958 /* Comparison function for sorting marked base types. */
23961 base_type_cmp (const void *x
, const void *y
)
23963 dw_die_ref dx
= *(const dw_die_ref
*) x
;
23964 dw_die_ref dy
= *(const dw_die_ref
*) y
;
23965 unsigned int byte_size1
, byte_size2
;
23966 unsigned int encoding1
, encoding2
;
23967 if (dx
->die_mark
> dy
->die_mark
)
23969 if (dx
->die_mark
< dy
->die_mark
)
23971 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
23972 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
23973 if (byte_size1
< byte_size2
)
23975 if (byte_size1
> byte_size2
)
23977 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
23978 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
23979 if (encoding1
< encoding2
)
23981 if (encoding1
> encoding2
)
23986 /* Move base types marked by mark_base_types as early as possible
23987 in the CU, sorted by decreasing usage count both to make the
23988 uleb128 references as small as possible and to make sure they
23989 will have die_offset already computed by calc_die_sizes when
23990 sizes of typed stack loc ops is computed. */
23993 move_marked_base_types (void)
23996 dw_die_ref base_type
, die
, c
;
23998 if (base_types
.is_empty ())
24001 /* Sort by decreasing usage count, they will be added again in that
24003 base_types
.qsort (base_type_cmp
);
24004 die
= comp_unit_die ();
24005 c
= die
->die_child
;
24008 dw_die_ref prev
= c
;
24010 while (c
->die_mark
)
24012 remove_child_with_prev (c
, prev
);
24013 /* As base types got marked, there must be at least
24014 one node other than DW_TAG_base_type. */
24015 gcc_assert (c
!= c
->die_sib
);
24019 while (c
!= die
->die_child
);
24020 gcc_assert (die
->die_child
);
24021 c
= die
->die_child
;
24022 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
24024 base_type
->die_mark
= 0;
24025 base_type
->die_sib
= c
->die_sib
;
24026 c
->die_sib
= base_type
;
24031 /* Helper function for resolve_addr, attempt to resolve
24032 one CONST_STRING, return true if successful. Similarly verify that
24033 SYMBOL_REFs refer to variables emitted in the current CU. */
24036 resolve_one_addr (rtx
*addr
)
24040 if (GET_CODE (rtl
) == CONST_STRING
)
24042 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
24043 tree t
= build_string (len
, XSTR (rtl
, 0));
24044 tree tlen
= size_int (len
- 1);
24046 = build_array_type (char_type_node
, build_index_type (tlen
));
24047 rtl
= lookup_constant_def (t
);
24048 if (!rtl
|| !MEM_P (rtl
))
24050 rtl
= XEXP (rtl
, 0);
24051 if (GET_CODE (rtl
) == SYMBOL_REF
24052 && SYMBOL_REF_DECL (rtl
)
24053 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
24055 vec_safe_push (used_rtx_array
, rtl
);
24060 if (GET_CODE (rtl
) == SYMBOL_REF
24061 && SYMBOL_REF_DECL (rtl
))
24063 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
24065 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
24068 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
24072 if (GET_CODE (rtl
) == CONST
)
24074 subrtx_ptr_iterator::array_type array
;
24075 FOR_EACH_SUBRTX_PTR (iter
, array
, &XEXP (rtl
, 0), ALL
)
24076 if (!resolve_one_addr (*iter
))
24083 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
24084 if possible, and create DW_TAG_dwarf_procedure that can be referenced
24085 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
24088 string_cst_pool_decl (tree t
)
24090 rtx rtl
= output_constant_def (t
, 1);
24091 unsigned char *array
;
24092 dw_loc_descr_ref l
;
24097 if (!rtl
|| !MEM_P (rtl
))
24099 rtl
= XEXP (rtl
, 0);
24100 if (GET_CODE (rtl
) != SYMBOL_REF
24101 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
24104 decl
= SYMBOL_REF_DECL (rtl
);
24105 if (!lookup_decl_die (decl
))
24107 len
= TREE_STRING_LENGTH (t
);
24108 vec_safe_push (used_rtx_array
, rtl
);
24109 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
24110 array
= ggc_vec_alloc
<unsigned char> (len
);
24111 memcpy (array
, TREE_STRING_POINTER (t
), len
);
24112 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
24113 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
24114 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
24115 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
24116 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
24117 add_AT_loc (ref
, DW_AT_location
, l
);
24118 equate_decl_number_to_die (decl
, ref
);
24123 /* Helper function of resolve_addr_in_expr. LOC is
24124 a DW_OP_addr followed by DW_OP_stack_value, either at the start
24125 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
24126 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
24127 with DW_OP_GNU_implicit_pointer if possible
24128 and return true, if unsuccessful, return false. */
24131 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
24133 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
24134 HOST_WIDE_INT offset
= 0;
24135 dw_die_ref ref
= NULL
;
24138 if (GET_CODE (rtl
) == CONST
24139 && GET_CODE (XEXP (rtl
, 0)) == PLUS
24140 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
24142 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
24143 rtl
= XEXP (XEXP (rtl
, 0), 0);
24145 if (GET_CODE (rtl
) == CONST_STRING
)
24147 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
24148 tree t
= build_string (len
, XSTR (rtl
, 0));
24149 tree tlen
= size_int (len
- 1);
24152 = build_array_type (char_type_node
, build_index_type (tlen
));
24153 rtl
= string_cst_pool_decl (t
);
24157 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
24159 decl
= SYMBOL_REF_DECL (rtl
);
24160 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
24162 ref
= lookup_decl_die (decl
);
24163 if (ref
&& (get_AT (ref
, DW_AT_location
)
24164 || get_AT (ref
, DW_AT_const_value
)))
24166 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
24167 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24168 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
24169 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24170 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24171 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
24172 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
24180 /* Helper function for resolve_addr, handle one location
24181 expression, return false if at least one CONST_STRING or SYMBOL_REF in
24182 the location list couldn't be resolved. */
24185 resolve_addr_in_expr (dw_loc_descr_ref loc
)
24187 dw_loc_descr_ref keep
= NULL
;
24188 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
24189 switch (loc
->dw_loc_opc
)
24192 if (!resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
24195 || prev
->dw_loc_opc
== DW_OP_piece
24196 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
24197 && loc
->dw_loc_next
24198 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
24200 && optimize_one_addr_into_implicit_ptr (loc
))
24205 case DW_OP_GNU_addr_index
:
24206 case DW_OP_GNU_const_index
:
24207 if (loc
->dw_loc_opc
== DW_OP_GNU_addr_index
24208 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
24210 rtx rtl
= loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
;
24211 if (!resolve_one_addr (&rtl
))
24213 remove_addr_table_entry (loc
->dw_loc_oprnd1
.val_entry
);
24214 loc
->dw_loc_oprnd1
.val_entry
=
24215 add_addr_table_entry (rtl
, ate_kind_rtx
);
24218 case DW_OP_const4u
:
24219 case DW_OP_const8u
:
24221 && !resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
))
24224 case DW_OP_plus_uconst
:
24225 if (size_of_loc_descr (loc
)
24226 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
24228 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
24230 dw_loc_descr_ref repl
24231 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
24232 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
24233 add_loc_descr (&repl
, loc
->dw_loc_next
);
24237 case DW_OP_implicit_value
:
24238 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
24239 && !resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
))
24242 case DW_OP_GNU_implicit_pointer
:
24243 case DW_OP_GNU_parameter_ref
:
24244 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
24247 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
24250 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24251 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24252 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24255 case DW_OP_GNU_const_type
:
24256 case DW_OP_GNU_regval_type
:
24257 case DW_OP_GNU_deref_type
:
24258 case DW_OP_GNU_convert
:
24259 case DW_OP_GNU_reinterpret
:
24260 while (loc
->dw_loc_next
24261 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
24263 dw_die_ref base1
, base2
;
24264 unsigned enc1
, enc2
, size1
, size2
;
24265 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
24266 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
24267 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
24268 else if (loc
->dw_loc_oprnd1
.val_class
24269 == dw_val_class_unsigned_const
)
24272 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
24273 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
24274 == dw_val_class_unsigned_const
)
24276 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
24277 gcc_assert (base1
->die_tag
== DW_TAG_base_type
24278 && base2
->die_tag
== DW_TAG_base_type
);
24279 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
24280 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
24281 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
24282 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
24284 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
24285 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
24289 /* Optimize away next DW_OP_GNU_convert after
24290 adjusting LOC's base type die reference. */
24291 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
24292 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
24293 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
24295 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
24296 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
24299 /* Don't change integer DW_OP_GNU_convert after e.g. floating
24300 point typed stack entry. */
24301 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
24302 keep
= loc
->dw_loc_next
;
24312 /* Helper function of resolve_addr. DIE had DW_AT_location of
24313 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
24314 and DW_OP_addr couldn't be resolved. resolve_addr has already
24315 removed the DW_AT_location attribute. This function attempts to
24316 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
24317 to it or DW_AT_const_value attribute, if possible. */
24320 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
24322 if (TREE_CODE (decl
) != VAR_DECL
24323 || lookup_decl_die (decl
) != die
24324 || DECL_EXTERNAL (decl
)
24325 || !TREE_STATIC (decl
)
24326 || DECL_INITIAL (decl
) == NULL_TREE
24327 || DECL_P (DECL_INITIAL (decl
))
24328 || get_AT (die
, DW_AT_const_value
))
24331 tree init
= DECL_INITIAL (decl
);
24332 HOST_WIDE_INT offset
= 0;
24333 /* For variables that have been optimized away and thus
24334 don't have a memory location, see if we can emit
24335 DW_AT_const_value instead. */
24336 if (tree_add_const_value_attribute (die
, init
))
24340 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
24341 and ADDR_EXPR refers to a decl that has DW_AT_location or
24342 DW_AT_const_value (but isn't addressable, otherwise
24343 resolving the original DW_OP_addr wouldn't fail), see if
24344 we can add DW_OP_GNU_implicit_pointer. */
24346 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
24347 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
24349 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
24350 init
= TREE_OPERAND (init
, 0);
24353 if (TREE_CODE (init
) != ADDR_EXPR
)
24355 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
24356 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
24357 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
24358 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
24359 && TREE_OPERAND (init
, 0) != decl
))
24362 dw_loc_descr_ref l
;
24364 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
24366 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
24369 decl
= SYMBOL_REF_DECL (rtl
);
24372 decl
= TREE_OPERAND (init
, 0);
24373 ref
= lookup_decl_die (decl
);
24375 || (!get_AT (ref
, DW_AT_location
)
24376 && !get_AT (ref
, DW_AT_const_value
)))
24378 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
24379 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
24380 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
24381 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
24382 add_AT_loc (die
, DW_AT_location
, l
);
24386 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
24387 an address in .rodata section if the string literal is emitted there,
24388 or remove the containing location list or replace DW_AT_const_value
24389 with DW_AT_location and empty location expression, if it isn't found
24390 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
24391 to something that has been emitted in the current CU. */
24394 resolve_addr (dw_die_ref die
)
24398 dw_loc_list_ref
*curr
, *start
, loc
;
24401 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
24402 switch (AT_class (a
))
24404 case dw_val_class_loc_list
:
24405 start
= curr
= AT_loc_list_ptr (a
);
24408 /* The same list can be referenced more than once. See if we have
24409 already recorded the result from a previous pass. */
24411 *curr
= loc
->dw_loc_next
;
24412 else if (!loc
->resolved_addr
)
24414 /* As things stand, we do not expect or allow one die to
24415 reference a suffix of another die's location list chain.
24416 References must be identical or completely separate.
24417 There is therefore no need to cache the result of this
24418 pass on any list other than the first; doing so
24419 would lead to unnecessary writes. */
24422 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
24423 if (!resolve_addr_in_expr ((*curr
)->expr
))
24425 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
24426 dw_loc_descr_ref l
= (*curr
)->expr
;
24428 if (next
&& (*curr
)->ll_symbol
)
24430 gcc_assert (!next
->ll_symbol
);
24431 next
->ll_symbol
= (*curr
)->ll_symbol
;
24433 if (dwarf_split_debug_info
)
24434 remove_loc_list_addr_table_entries (l
);
24439 mark_base_types ((*curr
)->expr
);
24440 curr
= &(*curr
)->dw_loc_next
;
24444 loc
->resolved_addr
= 1;
24448 loc
->dw_loc_next
= *start
;
24453 remove_AT (die
, a
->dw_attr
);
24457 case dw_val_class_loc
:
24459 dw_loc_descr_ref l
= AT_loc (a
);
24460 /* For -gdwarf-2 don't attempt to optimize
24461 DW_AT_data_member_location containing
24462 DW_OP_plus_uconst - older consumers might
24463 rely on it being that op instead of a more complex,
24464 but shorter, location description. */
24465 if ((dwarf_version
> 2
24466 || a
->dw_attr
!= DW_AT_data_member_location
24468 || l
->dw_loc_opc
!= DW_OP_plus_uconst
24469 || l
->dw_loc_next
!= NULL
)
24470 && !resolve_addr_in_expr (l
))
24472 if (dwarf_split_debug_info
)
24473 remove_loc_list_addr_table_entries (l
);
24475 && l
->dw_loc_next
== NULL
24476 && l
->dw_loc_opc
== DW_OP_addr
24477 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
24478 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
24479 && a
->dw_attr
== DW_AT_location
)
24481 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
24482 remove_AT (die
, a
->dw_attr
);
24484 optimize_location_into_implicit_ptr (die
, decl
);
24487 remove_AT (die
, a
->dw_attr
);
24491 mark_base_types (l
);
24494 case dw_val_class_addr
:
24495 if (a
->dw_attr
== DW_AT_const_value
24496 && !resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
))
24498 if (AT_index (a
) != NOT_INDEXED
)
24499 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
24500 remove_AT (die
, a
->dw_attr
);
24503 if (die
->die_tag
== DW_TAG_GNU_call_site
24504 && a
->dw_attr
== DW_AT_abstract_origin
)
24506 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
24507 dw_die_ref tdie
= lookup_decl_die (tdecl
);
24510 && DECL_EXTERNAL (tdecl
)
24511 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
24512 && (cdie
= lookup_context_die (DECL_CONTEXT (tdecl
))))
24514 /* Creating a full DIE for tdecl is overly expensive and
24515 at this point even wrong when in the LTO phase
24516 as it can end up generating new type DIEs we didn't
24517 output and thus optimize_external_refs will crash. */
24518 tdie
= new_die (DW_TAG_subprogram
, cdie
, NULL_TREE
);
24519 add_AT_flag (tdie
, DW_AT_external
, 1);
24520 add_AT_flag (tdie
, DW_AT_declaration
, 1);
24521 add_linkage_attr (tdie
, tdecl
);
24522 add_name_and_src_coords_attributes (tdie
, tdecl
);
24523 equate_decl_number_to_die (tdecl
, tdie
);
24527 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
24528 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
24529 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
24533 if (AT_index (a
) != NOT_INDEXED
)
24534 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
24535 remove_AT (die
, a
->dw_attr
);
24544 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
24547 /* Helper routines for optimize_location_lists.
24548 This pass tries to share identical local lists in .debug_loc
24551 /* Iteratively hash operands of LOC opcode into HSTATE. */
24554 hash_loc_operands (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
24556 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
24557 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
24559 switch (loc
->dw_loc_opc
)
24561 case DW_OP_const4u
:
24562 case DW_OP_const8u
:
24566 case DW_OP_const1u
:
24567 case DW_OP_const1s
:
24568 case DW_OP_const2u
:
24569 case DW_OP_const2s
:
24570 case DW_OP_const4s
:
24571 case DW_OP_const8s
:
24575 case DW_OP_plus_uconst
:
24611 case DW_OP_deref_size
:
24612 case DW_OP_xderef_size
:
24613 hstate
.add_object (val1
->v
.val_int
);
24620 gcc_assert (val1
->val_class
== dw_val_class_loc
);
24621 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
24622 hstate
.add_object (offset
);
24625 case DW_OP_implicit_value
:
24626 hstate
.add_object (val1
->v
.val_unsigned
);
24627 switch (val2
->val_class
)
24629 case dw_val_class_const
:
24630 hstate
.add_object (val2
->v
.val_int
);
24632 case dw_val_class_vec
:
24634 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
24635 unsigned int len
= val2
->v
.val_vec
.length
;
24637 hstate
.add_int (elt_size
);
24638 hstate
.add_int (len
);
24639 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
24642 case dw_val_class_const_double
:
24643 hstate
.add_object (val2
->v
.val_double
.low
);
24644 hstate
.add_object (val2
->v
.val_double
.high
);
24646 case dw_val_class_wide_int
:
24647 hstate
.add (val2
->v
.val_wide
->get_val (),
24648 get_full_len (*val2
->v
.val_wide
)
24649 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
24651 case dw_val_class_addr
:
24652 inchash::add_rtx (val2
->v
.val_addr
, hstate
);
24655 gcc_unreachable ();
24659 case DW_OP_bit_piece
:
24660 hstate
.add_object (val1
->v
.val_int
);
24661 hstate
.add_object (val2
->v
.val_int
);
24667 unsigned char dtprel
= 0xd1;
24668 hstate
.add_object (dtprel
);
24670 inchash::add_rtx (val1
->v
.val_addr
, hstate
);
24672 case DW_OP_GNU_addr_index
:
24673 case DW_OP_GNU_const_index
:
24677 unsigned char dtprel
= 0xd1;
24678 hstate
.add_object (dtprel
);
24680 inchash::add_rtx (val1
->val_entry
->addr
.rtl
, hstate
);
24683 case DW_OP_GNU_implicit_pointer
:
24684 hstate
.add_int (val2
->v
.val_int
);
24686 case DW_OP_GNU_entry_value
:
24687 hstate
.add_object (val1
->v
.val_loc
);
24689 case DW_OP_GNU_regval_type
:
24690 case DW_OP_GNU_deref_type
:
24692 unsigned int byte_size
24693 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
24694 unsigned int encoding
24695 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
24696 hstate
.add_object (val1
->v
.val_int
);
24697 hstate
.add_object (byte_size
);
24698 hstate
.add_object (encoding
);
24701 case DW_OP_GNU_convert
:
24702 case DW_OP_GNU_reinterpret
:
24703 if (val1
->val_class
== dw_val_class_unsigned_const
)
24705 hstate
.add_object (val1
->v
.val_unsigned
);
24709 case DW_OP_GNU_const_type
:
24711 unsigned int byte_size
24712 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
24713 unsigned int encoding
24714 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
24715 hstate
.add_object (byte_size
);
24716 hstate
.add_object (encoding
);
24717 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
24719 hstate
.add_object (val2
->val_class
);
24720 switch (val2
->val_class
)
24722 case dw_val_class_const
:
24723 hstate
.add_object (val2
->v
.val_int
);
24725 case dw_val_class_vec
:
24727 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
24728 unsigned int len
= val2
->v
.val_vec
.length
;
24730 hstate
.add_object (elt_size
);
24731 hstate
.add_object (len
);
24732 hstate
.add (val2
->v
.val_vec
.array
, len
* elt_size
);
24735 case dw_val_class_const_double
:
24736 hstate
.add_object (val2
->v
.val_double
.low
);
24737 hstate
.add_object (val2
->v
.val_double
.high
);
24739 case dw_val_class_wide_int
:
24740 hstate
.add (val2
->v
.val_wide
->get_val (),
24741 get_full_len (*val2
->v
.val_wide
)
24742 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
24745 gcc_unreachable ();
24751 /* Other codes have no operands. */
24756 /* Iteratively hash the whole DWARF location expression LOC into HSTATE. */
24759 hash_locs (dw_loc_descr_ref loc
, inchash::hash
&hstate
)
24761 dw_loc_descr_ref l
;
24762 bool sizes_computed
= false;
24763 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
24764 size_of_locs (loc
);
24766 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
24768 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
24769 hstate
.add_object (opc
);
24770 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
24772 size_of_locs (loc
);
24773 sizes_computed
= true;
24775 hash_loc_operands (l
, hstate
);
24779 /* Compute hash of the whole location list LIST_HEAD. */
24782 hash_loc_list (dw_loc_list_ref list_head
)
24784 dw_loc_list_ref curr
= list_head
;
24785 inchash::hash hstate
;
24787 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
24789 hstate
.add (curr
->begin
, strlen (curr
->begin
) + 1);
24790 hstate
.add (curr
->end
, strlen (curr
->end
) + 1);
24792 hstate
.add (curr
->section
, strlen (curr
->section
) + 1);
24793 hash_locs (curr
->expr
, hstate
);
24795 list_head
->hash
= hstate
.end ();
24798 /* Return true if X and Y opcodes have the same operands. */
24801 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
24803 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
24804 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
24805 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
24806 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
24808 switch (x
->dw_loc_opc
)
24810 case DW_OP_const4u
:
24811 case DW_OP_const8u
:
24815 case DW_OP_const1u
:
24816 case DW_OP_const1s
:
24817 case DW_OP_const2u
:
24818 case DW_OP_const2s
:
24819 case DW_OP_const4s
:
24820 case DW_OP_const8s
:
24824 case DW_OP_plus_uconst
:
24860 case DW_OP_deref_size
:
24861 case DW_OP_xderef_size
:
24862 return valx1
->v
.val_int
== valy1
->v
.val_int
;
24865 /* If splitting debug info, the use of DW_OP_GNU_addr_index
24866 can cause irrelevant differences in dw_loc_addr. */
24867 gcc_assert (valx1
->val_class
== dw_val_class_loc
24868 && valy1
->val_class
== dw_val_class_loc
24869 && (dwarf_split_debug_info
24870 || x
->dw_loc_addr
== y
->dw_loc_addr
));
24871 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
24872 case DW_OP_implicit_value
:
24873 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
24874 || valx2
->val_class
!= valy2
->val_class
)
24876 switch (valx2
->val_class
)
24878 case dw_val_class_const
:
24879 return valx2
->v
.val_int
== valy2
->v
.val_int
;
24880 case dw_val_class_vec
:
24881 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
24882 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
24883 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
24884 valx2
->v
.val_vec
.elt_size
24885 * valx2
->v
.val_vec
.length
) == 0;
24886 case dw_val_class_const_double
:
24887 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
24888 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
24889 case dw_val_class_wide_int
:
24890 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
24891 case dw_val_class_addr
:
24892 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
24894 gcc_unreachable ();
24897 case DW_OP_bit_piece
:
24898 return valx1
->v
.val_int
== valy1
->v
.val_int
24899 && valx2
->v
.val_int
== valy2
->v
.val_int
;
24902 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
24903 case DW_OP_GNU_addr_index
:
24904 case DW_OP_GNU_const_index
:
24906 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
24907 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
24908 return rtx_equal_p (ax1
, ay1
);
24910 case DW_OP_GNU_implicit_pointer
:
24911 return valx1
->val_class
== dw_val_class_die_ref
24912 && valx1
->val_class
== valy1
->val_class
24913 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
24914 && valx2
->v
.val_int
== valy2
->v
.val_int
;
24915 case DW_OP_GNU_entry_value
:
24916 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
24917 case DW_OP_GNU_const_type
:
24918 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
24919 || valx2
->val_class
!= valy2
->val_class
)
24921 switch (valx2
->val_class
)
24923 case dw_val_class_const
:
24924 return valx2
->v
.val_int
== valy2
->v
.val_int
;
24925 case dw_val_class_vec
:
24926 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
24927 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
24928 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
24929 valx2
->v
.val_vec
.elt_size
24930 * valx2
->v
.val_vec
.length
) == 0;
24931 case dw_val_class_const_double
:
24932 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
24933 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
24934 case dw_val_class_wide_int
:
24935 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
24937 gcc_unreachable ();
24939 case DW_OP_GNU_regval_type
:
24940 case DW_OP_GNU_deref_type
:
24941 return valx1
->v
.val_int
== valy1
->v
.val_int
24942 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
24943 case DW_OP_GNU_convert
:
24944 case DW_OP_GNU_reinterpret
:
24945 if (valx1
->val_class
!= valy1
->val_class
)
24947 if (valx1
->val_class
== dw_val_class_unsigned_const
)
24948 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
24949 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
24950 case DW_OP_GNU_parameter_ref
:
24951 return valx1
->val_class
== dw_val_class_die_ref
24952 && valx1
->val_class
== valy1
->val_class
24953 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
24955 /* Other codes have no operands. */
24960 /* Return true if DWARF location expressions X and Y are the same. */
24963 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
24965 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
24966 if (x
->dw_loc_opc
!= y
->dw_loc_opc
24967 || x
->dtprel
!= y
->dtprel
24968 || !compare_loc_operands (x
, y
))
24970 return x
== NULL
&& y
== NULL
;
24973 /* Hashtable helpers. */
24975 struct loc_list_hasher
: nofree_ptr_hash
<dw_loc_list_struct
>
24977 static inline hashval_t
hash (const dw_loc_list_struct
*);
24978 static inline bool equal (const dw_loc_list_struct
*,
24979 const dw_loc_list_struct
*);
24982 /* Return precomputed hash of location list X. */
24985 loc_list_hasher::hash (const dw_loc_list_struct
*x
)
24990 /* Return true if location lists A and B are the same. */
24993 loc_list_hasher::equal (const dw_loc_list_struct
*a
,
24994 const dw_loc_list_struct
*b
)
24998 if (a
->hash
!= b
->hash
)
25000 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
25001 if (strcmp (a
->begin
, b
->begin
) != 0
25002 || strcmp (a
->end
, b
->end
) != 0
25003 || (a
->section
== NULL
) != (b
->section
== NULL
)
25004 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
25005 || !compare_locs (a
->expr
, b
->expr
))
25007 return a
== NULL
&& b
== NULL
;
25010 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
25013 /* Recursively optimize location lists referenced from DIE
25014 children and share them whenever possible. */
25017 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type
*htab
)
25022 dw_loc_list_struct
**slot
;
25024 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25025 if (AT_class (a
) == dw_val_class_loc_list
)
25027 dw_loc_list_ref list
= AT_loc_list (a
);
25028 /* TODO: perform some optimizations here, before hashing
25029 it and storing into the hash table. */
25030 hash_loc_list (list
);
25031 slot
= htab
->find_slot_with_hash (list
, list
->hash
, INSERT
);
25035 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
25038 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
25042 /* Recursively assign each location list a unique index into the debug_addr
25046 index_location_lists (dw_die_ref die
)
25052 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
25053 if (AT_class (a
) == dw_val_class_loc_list
)
25055 dw_loc_list_ref list
= AT_loc_list (a
);
25056 dw_loc_list_ref curr
;
25057 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
25059 /* Don't index an entry that has already been indexed
25060 or won't be output. */
25061 if (curr
->begin_entry
!= NULL
25062 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
25066 = add_addr_table_entry (xstrdup (curr
->begin
),
25071 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
25074 /* Optimize location lists referenced from DIE
25075 children and share them whenever possible. */
25078 optimize_location_lists (dw_die_ref die
)
25080 loc_list_hash_type
htab (500);
25081 optimize_location_lists_1 (die
, &htab
);
25084 /* Output stuff that dwarf requires at the end of every file,
25085 and generate the DWARF-2 debugging info. */
25088 dwarf2out_finish (const char *filename
)
25090 comdat_type_node
*ctnode
;
25091 dw_die_ref main_comp_unit_die
;
25093 /* Flush out any latecomers to the limbo party. */
25094 dwarf2out_early_finish ();
25096 /* PCH might result in DW_AT_producer string being restored from the
25097 header compilation, so always fill it with empty string initially
25098 and overwrite only here. */
25099 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
25100 producer_string
= gen_producer_string ();
25101 producer
->dw_attr_val
.v
.val_str
->refcount
--;
25102 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
25104 gen_scheduled_generic_parms_dies ();
25105 gen_remaining_tmpl_value_param_die_attribute ();
25107 /* Add the name for the main input file now. We delayed this from
25108 dwarf2out_init to avoid complications with PCH.
25109 For LTO produced units use a fixed artificial name to avoid
25110 leaking tempfile names into the dwarf. */
25112 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
25114 add_name_attribute (comp_unit_die (), "<artificial>");
25115 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
25116 add_comp_dir_attribute (comp_unit_die ());
25117 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
25120 file_table
->traverse
<bool *, file_table_relative_p
> (&p
);
25122 add_comp_dir_attribute (comp_unit_die ());
25125 #if ENABLE_ASSERT_CHECKING
25127 dw_die_ref die
= comp_unit_die (), c
;
25128 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
25131 resolve_addr (comp_unit_die ());
25132 move_marked_base_types ();
25134 /* Walk through the list of incomplete types again, trying once more to
25135 emit full debugging info for them. */
25136 retry_incomplete_types ();
25138 if (flag_eliminate_unused_debug_types
)
25139 prune_unused_types ();
25141 /* Generate separate COMDAT sections for type DIEs. */
25142 if (use_debug_types
)
25144 break_out_comdat_types (comp_unit_die ());
25146 /* Each new type_unit DIE was added to the limbo die list when created.
25147 Since these have all been added to comdat_type_list, clear the
25149 limbo_die_list
= NULL
;
25151 /* For each new comdat type unit, copy declarations for incomplete
25152 types to make the new unit self-contained (i.e., no direct
25153 references to the main compile unit). */
25154 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25155 copy_decls_for_unworthy_types (ctnode
->root_die
);
25156 copy_decls_for_unworthy_types (comp_unit_die ());
25158 /* In the process of copying declarations from one unit to another,
25159 we may have left some declarations behind that are no longer
25160 referenced. Prune them. */
25161 prune_unused_types ();
25164 /* Generate separate CUs for each of the include files we've seen.
25165 They will go into limbo_die_list. */
25166 if (flag_eliminate_dwarf2_dups
)
25167 break_out_includes (comp_unit_die ());
25169 /* Traverse the DIE's and add sibling attributes to those DIE's that
25171 add_sibling_attributes (comp_unit_die ());
25172 limbo_die_node
*node
;
25173 for (node
= limbo_die_list
; node
; node
= node
->next
)
25174 add_sibling_attributes (node
->die
);
25175 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25176 add_sibling_attributes (ctnode
->root_die
);
25178 /* When splitting DWARF info, we put some attributes in the
25179 skeleton compile_unit DIE that remains in the .o, while
25180 most attributes go in the DWO compile_unit_die. */
25181 if (dwarf_split_debug_info
)
25182 main_comp_unit_die
= gen_compile_unit_die (NULL
);
25184 main_comp_unit_die
= comp_unit_die ();
25186 /* Output a terminator label for the .text section. */
25187 switch_to_section (text_section
);
25188 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
25189 if (cold_text_section
)
25191 switch_to_section (cold_text_section
);
25192 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
25195 /* We can only use the low/high_pc attributes if all of the code was
25197 if (!have_multiple_function_sections
25198 || (dwarf_version
< 3 && dwarf_strict
))
25200 /* Don't add if the CU has no associated code. */
25201 if (text_section_used
)
25202 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
25203 text_end_label
, true);
25209 bool range_list_added
= false;
25211 if (text_section_used
)
25212 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
25213 text_end_label
, &range_list_added
, true);
25214 if (cold_text_section_used
)
25215 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
25216 cold_end_label
, &range_list_added
, true);
25218 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
25220 if (DECL_IGNORED_P (fde
->decl
))
25222 if (!fde
->in_std_section
)
25223 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
25224 fde
->dw_fde_end
, &range_list_added
,
25226 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
25227 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
25228 fde
->dw_fde_second_end
, &range_list_added
,
25232 if (range_list_added
)
25234 /* We need to give .debug_loc and .debug_ranges an appropriate
25235 "base address". Use zero so that these addresses become
25236 absolute. Historically, we've emitted the unexpected
25237 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
25238 Emit both to give time for other tools to adapt. */
25239 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
25240 if (! dwarf_strict
&& dwarf_version
< 4)
25241 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
25247 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
25248 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
25249 debug_line_section_label
);
25252 add_AT_macptr (comp_unit_die (),
25253 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
25254 macinfo_section_label
);
25256 if (dwarf_split_debug_info
)
25258 /* optimize_location_lists calculates the size of the lists,
25259 so index them first, and assign indices to the entries.
25260 Although optimize_location_lists will remove entries from
25261 the table, it only does so for duplicates, and therefore
25262 only reduces ref_counts to 1. */
25263 index_location_lists (comp_unit_die ());
25265 if (addr_index_table
!= NULL
)
25267 unsigned int index
= 0;
25269 ->traverse_noresize
<unsigned int *, index_addr_table_entry
>
25274 if (have_location_lists
)
25275 optimize_location_lists (comp_unit_die ());
25277 save_macinfo_strings ();
25279 if (dwarf_split_debug_info
)
25281 unsigned int index
= 0;
25283 /* Add attributes common to skeleton compile_units and
25284 type_units. Because these attributes include strings, it
25285 must be done before freezing the string table. Top-level
25286 skeleton die attrs are added when the skeleton type unit is
25287 created, so ensure it is created by this point. */
25288 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
25289 debug_str_hash
->traverse_noresize
<unsigned int *, index_string
> (&index
);
25292 /* Output all of the compilation units. We put the main one last so that
25293 the offsets are available to output_pubnames. */
25294 for (node
= limbo_die_list
; node
; node
= node
->next
)
25295 output_comp_unit (node
->die
, 0);
25297 hash_table
<comdat_type_hasher
> comdat_type_table (100);
25298 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
25300 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
25302 /* Don't output duplicate types. */
25303 if (*slot
!= HTAB_EMPTY_ENTRY
)
25306 /* Add a pointer to the line table for the main compilation unit
25307 so that the debugger can make sense of DW_AT_decl_file
25309 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
25310 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
25311 (!dwarf_split_debug_info
25312 ? debug_line_section_label
25313 : debug_skeleton_line_section_label
));
25315 output_comdat_type_unit (ctnode
);
25319 /* The AT_pubnames attribute needs to go in all skeleton dies, including
25320 both the main_cu and all skeleton TUs. Making this call unconditional
25321 would end up either adding a second copy of the AT_pubnames attribute, or
25322 requiring a special case in add_top_level_skeleton_die_attrs. */
25323 if (!dwarf_split_debug_info
)
25324 add_AT_pubnames (comp_unit_die ());
25326 if (dwarf_split_debug_info
)
25329 unsigned char checksum
[16];
25330 struct md5_ctx ctx
;
25332 /* Compute a checksum of the comp_unit to use as the dwo_id. */
25333 md5_init_ctx (&ctx
);
25335 die_checksum (comp_unit_die (), &ctx
, &mark
);
25336 unmark_all_dies (comp_unit_die ());
25337 md5_finish_ctx (&ctx
, checksum
);
25339 /* Use the first 8 bytes of the checksum as the dwo_id,
25340 and add it to both comp-unit DIEs. */
25341 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
25342 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
25344 /* Add the base offset of the ranges table to the skeleton
25346 if (ranges_table_in_use
)
25347 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
25348 ranges_section_label
);
25350 switch_to_section (debug_addr_section
);
25351 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
25352 output_addr_table ();
25355 /* Output the main compilation unit if non-empty or if .debug_macinfo
25356 or .debug_macro will be emitted. */
25357 output_comp_unit (comp_unit_die (), have_macinfo
);
25359 if (dwarf_split_debug_info
&& info_section_emitted
)
25360 output_skeleton_debug_sections (main_comp_unit_die
);
25362 /* Output the abbreviation table. */
25363 if (abbrev_die_table_in_use
!= 1)
25365 switch_to_section (debug_abbrev_section
);
25366 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
25367 output_abbrev_section ();
25370 /* Output location list section if necessary. */
25371 if (have_location_lists
)
25373 /* Output the location lists info. */
25374 switch_to_section (debug_loc_section
);
25375 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
25376 output_location_lists (comp_unit_die ());
25379 output_pubtables ();
25381 /* Output the address range information if a CU (.debug_info section)
25382 was emitted. We output an empty table even if we had no functions
25383 to put in it. This because the consumer has no way to tell the
25384 difference between an empty table that we omitted and failure to
25385 generate a table that would have contained data. */
25386 if (info_section_emitted
)
25388 unsigned long aranges_length
= size_of_aranges ();
25390 switch_to_section (debug_aranges_section
);
25391 output_aranges (aranges_length
);
25394 /* Output ranges section if necessary. */
25395 if (ranges_table_in_use
)
25397 switch_to_section (debug_ranges_section
);
25398 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
25402 /* Have to end the macro section. */
25405 switch_to_section (debug_macinfo_section
);
25406 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
25408 dw2_asm_output_data (1, 0, "End compilation unit");
25411 /* Output the source line correspondence table. We must do this
25412 even if there is no line information. Otherwise, on an empty
25413 translation unit, we will generate a present, but empty,
25414 .debug_info section. IRIX 6.5 `nm' will then complain when
25415 examining the file. This is done late so that any filenames
25416 used by the debug_info section are marked as 'used'. */
25417 switch_to_section (debug_line_section
);
25418 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
25419 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
25420 output_line_info (false);
25422 if (dwarf_split_debug_info
&& info_section_emitted
)
25424 switch_to_section (debug_skeleton_line_section
);
25425 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
25426 output_line_info (true);
25429 /* If we emitted any indirect strings, output the string table too. */
25430 if (debug_str_hash
|| skeleton_debug_str_hash
)
25431 output_indirect_strings ();
25434 /* Perform any cleanups needed after the early debug generation pass
25438 dwarf2out_early_finish (void)
25440 limbo_die_node
*node
, *next_node
;
25442 /* Add DW_AT_linkage_name for all deferred DIEs. */
25443 for (node
= deferred_asm_name
; node
; node
= node
->next
)
25445 tree decl
= node
->created_for
;
25446 if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
)
25447 /* A missing DECL_ASSEMBLER_NAME can be a constant DIE that
25448 ended up in deferred_asm_name before we knew it was
25449 constant and never written to disk. */
25450 && DECL_ASSEMBLER_NAME (decl
))
25452 add_linkage_attr (node
->die
, decl
);
25453 move_linkage_attr (node
->die
);
25456 deferred_asm_name
= NULL
;
25458 /* Traverse the limbo die list, and add parent/child links. The only
25459 dies without parents that should be here are concrete instances of
25460 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
25461 For concrete instances, we can get the parent die from the abstract
25464 The point here is to flush out the limbo list so that it is empty
25465 and we don't need to stream it for LTO. */
25466 for (node
= limbo_die_list
; node
; node
= next_node
)
25468 dw_die_ref die
= node
->die
;
25469 next_node
= node
->next
;
25471 if (die
->die_parent
== NULL
)
25473 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
25475 if (origin
&& origin
->die_parent
)
25476 add_child_die (origin
->die_parent
, die
);
25477 else if (is_cu_die (die
))
25479 else if (seen_error ())
25480 /* It's OK to be confused by errors in the input. */
25481 add_child_die (comp_unit_die (), die
);
25484 /* In certain situations, the lexical block containing a
25485 nested function can be optimized away, which results
25486 in the nested function die being orphaned. Likewise
25487 with the return type of that nested function. Force
25488 this to be a child of the containing function.
25490 It may happen that even the containing function got fully
25491 inlined and optimized out. In that case we are lost and
25492 assign the empty child. This should not be big issue as
25493 the function is likely unreachable too. */
25494 gcc_assert (node
->created_for
);
25496 if (DECL_P (node
->created_for
))
25497 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
25498 else if (TYPE_P (node
->created_for
))
25499 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
25501 origin
= comp_unit_die ();
25503 add_child_die (origin
, die
);
25508 limbo_die_list
= NULL
;
25511 /* Reset all state within dwarf2out.c so that we can rerun the compiler
25512 within the same process. For use by toplev::finalize. */
25515 dwarf2out_c_finalize (void)
25517 last_var_location_insn
= NULL
;
25518 cached_next_real_insn
= NULL
;
25519 used_rtx_array
= NULL
;
25520 incomplete_types
= NULL
;
25521 decl_scope_table
= NULL
;
25522 debug_info_section
= NULL
;
25523 debug_skeleton_info_section
= NULL
;
25524 debug_abbrev_section
= NULL
;
25525 debug_skeleton_abbrev_section
= NULL
;
25526 debug_aranges_section
= NULL
;
25527 debug_addr_section
= NULL
;
25528 debug_macinfo_section
= NULL
;
25529 debug_line_section
= NULL
;
25530 debug_skeleton_line_section
= NULL
;
25531 debug_loc_section
= NULL
;
25532 debug_pubnames_section
= NULL
;
25533 debug_pubtypes_section
= NULL
;
25534 debug_str_section
= NULL
;
25535 debug_str_dwo_section
= NULL
;
25536 debug_str_offsets_section
= NULL
;
25537 debug_ranges_section
= NULL
;
25538 debug_frame_section
= NULL
;
25540 debug_str_hash
= NULL
;
25541 skeleton_debug_str_hash
= NULL
;
25542 dw2_string_counter
= 0;
25543 have_multiple_function_sections
= false;
25544 text_section_used
= false;
25545 cold_text_section_used
= false;
25546 cold_text_section
= NULL
;
25547 current_unit_personality
= NULL
;
25549 next_die_offset
= 0;
25550 single_comp_unit_die
= NULL
;
25551 comdat_type_list
= NULL
;
25552 limbo_die_list
= NULL
;
25554 decl_die_table
= NULL
;
25555 common_block_die_table
= NULL
;
25556 decl_loc_table
= NULL
;
25557 call_arg_locations
= NULL
;
25558 call_arg_loc_last
= NULL
;
25559 call_site_count
= -1;
25560 tail_call_site_count
= -1;
25561 cached_dw_loc_list_table
= NULL
;
25562 abbrev_die_table
= NULL
;
25563 abbrev_die_table_allocated
= 0;
25564 abbrev_die_table_in_use
= 0;
25565 line_info_label_num
= 0;
25566 cur_line_info_table
= NULL
;
25567 text_section_line_info
= NULL
;
25568 cold_text_section_line_info
= NULL
;
25569 separate_line_info
= NULL
;
25570 info_section_emitted
= false;
25571 pubname_table
= NULL
;
25572 pubtype_table
= NULL
;
25573 macinfo_table
= NULL
;
25574 ranges_table
= NULL
;
25575 ranges_table_allocated
= 0;
25576 ranges_table_in_use
= 0;
25577 ranges_by_label
= 0;
25578 ranges_by_label_allocated
= 0;
25579 ranges_by_label_in_use
= 0;
25580 have_location_lists
= false;
25583 last_emitted_file
= NULL
;
25585 tmpl_value_parm_die_table
= NULL
;
25586 generic_type_instances
= NULL
;
25587 frame_pointer_fb_offset
= 0;
25588 frame_pointer_fb_offset_valid
= false;
25589 base_types
.release ();
25590 XDELETEVEC (producer_string
);
25591 producer_string
= NULL
;
25594 #include "gt-dwarf2out.h"