1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2013 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"
64 #include "stringpool.h"
65 #include "stor-layout.h"
72 #include "hard-reg-set.h"
74 #include "insn-config.h"
81 #include "dwarf2out.h"
82 #include "dwarf2asm.h"
87 #include "diagnostic.h"
88 #include "tree-pretty-print.h"
91 #include "common/common-target.h"
92 #include "langhooks.h"
93 #include "hash-table.h"
100 #include "tree-dfa.h"
101 #include "gdb/gdb-index.h"
103 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
104 static rtx last_var_location_insn
;
105 static rtx cached_next_real_insn
;
107 #ifdef VMS_DEBUGGING_INFO
108 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
110 /* Define this macro to be a nonzero value if the directory specifications
111 which are output in the debug info should end with a separator. */
112 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
113 /* Define this macro to evaluate to a nonzero value if GCC should refrain
114 from generating indirect strings in DWARF2 debug information, for instance
115 if your target is stuck with an old version of GDB that is unable to
116 process them properly or uses VMS Debug. */
117 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
119 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
120 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
123 /* ??? Poison these here until it can be done generically. They've been
124 totally replaced in this file; make sure it stays that way. */
125 #undef DWARF2_UNWIND_INFO
126 #undef DWARF2_FRAME_INFO
127 #if (GCC_VERSION >= 3000)
128 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
131 /* The size of the target's pointer type. */
133 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
136 /* Array of RTXes referenced by the debugging information, which therefore
137 must be kept around forever. */
138 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
140 /* A pointer to the base of a list of incomplete types which might be
141 completed at some later time. incomplete_types_list needs to be a
142 vec<tree, va_gc> *because we want to tell the garbage collector about
144 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
146 /* A pointer to the base of a table of references to declaration
147 scopes. This table is a display which tracks the nesting
148 of declaration scopes at the current scope and containing
149 scopes. This table is used to find the proper place to
150 define type declaration DIE's. */
151 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
153 /* Pointers to various DWARF2 sections. */
154 static GTY(()) section
*debug_info_section
;
155 static GTY(()) section
*debug_skeleton_info_section
;
156 static GTY(()) section
*debug_abbrev_section
;
157 static GTY(()) section
*debug_skeleton_abbrev_section
;
158 static GTY(()) section
*debug_aranges_section
;
159 static GTY(()) section
*debug_addr_section
;
160 static GTY(()) section
*debug_macinfo_section
;
161 static GTY(()) section
*debug_line_section
;
162 static GTY(()) section
*debug_skeleton_line_section
;
163 static GTY(()) section
*debug_loc_section
;
164 static GTY(()) section
*debug_pubnames_section
;
165 static GTY(()) section
*debug_pubtypes_section
;
166 static GTY(()) section
*debug_str_section
;
167 static GTY(()) section
*debug_str_dwo_section
;
168 static GTY(()) section
*debug_str_offsets_section
;
169 static GTY(()) section
*debug_ranges_section
;
170 static GTY(()) section
*debug_frame_section
;
172 /* Maximum size (in bytes) of an artificially generated label. */
173 #define MAX_ARTIFICIAL_LABEL_BYTES 30
175 /* According to the (draft) DWARF 3 specification, the initial length
176 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
177 bytes are 0xffffffff, followed by the length stored in the next 8
180 However, the SGI/MIPS ABI uses an initial length which is equal to
181 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
183 #ifndef DWARF_INITIAL_LENGTH_SIZE
184 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
187 /* Round SIZE up to the nearest BOUNDARY. */
188 #define DWARF_ROUND(SIZE,BOUNDARY) \
189 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
191 /* CIE identifier. */
192 #if HOST_BITS_PER_WIDE_INT >= 64
193 #define DWARF_CIE_ID \
194 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
196 #define DWARF_CIE_ID DW_CIE_ID
200 /* A vector for a table that contains frame description
201 information for each routine. */
202 #define NOT_INDEXED (-1U)
203 #define NO_INDEX_ASSIGNED (-2U)
205 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
207 struct GTY(()) indirect_string_node
{
209 unsigned int refcount
;
210 enum dwarf_form form
;
215 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
217 /* With split_debug_info, both the comp_dir and dwo_name go in the
218 main object file, rather than the dwo, similar to the force_direct
219 parameter elsewhere but with additional complications:
221 1) The string is needed in both the main object file and the dwo.
222 That is, the comp_dir and dwo_name will appear in both places.
224 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
225 DW_FORM_GNU_str_index.
227 3) GCC chooses the form to use late, depending on the size and
230 Rather than forcing the all debug string handling functions and
231 callers to deal with these complications, simply use a separate,
232 special-cased string table for any attribute that should go in the
233 main object file. This limits the complexity to just the places
236 static GTY ((param_is (struct indirect_string_node
)))
237 htab_t skeleton_debug_str_hash
;
239 static GTY(()) int dw2_string_counter
;
241 /* True if the compilation unit places functions in more than one section. */
242 static GTY(()) bool have_multiple_function_sections
= false;
244 /* Whether the default text and cold text sections have been used at all. */
246 static GTY(()) bool text_section_used
= false;
247 static GTY(()) bool cold_text_section_used
= false;
249 /* The default cold text section. */
250 static GTY(()) section
*cold_text_section
;
252 /* Forward declarations for functions defined in this file. */
254 static char *stripattributes (const char *);
255 static void output_call_frame_info (int);
256 static void dwarf2out_note_section_used (void);
258 /* Personality decl of current unit. Used only when assembler does not support
260 static GTY(()) rtx current_unit_personality
;
262 /* Data and reference forms for relocatable data. */
263 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
264 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
266 #ifndef DEBUG_FRAME_SECTION
267 #define DEBUG_FRAME_SECTION ".debug_frame"
270 #ifndef FUNC_BEGIN_LABEL
271 #define FUNC_BEGIN_LABEL "LFB"
274 #ifndef FUNC_END_LABEL
275 #define FUNC_END_LABEL "LFE"
278 #ifndef PROLOGUE_END_LABEL
279 #define PROLOGUE_END_LABEL "LPE"
282 #ifndef EPILOGUE_BEGIN_LABEL
283 #define EPILOGUE_BEGIN_LABEL "LEB"
286 #ifndef FRAME_BEGIN_LABEL
287 #define FRAME_BEGIN_LABEL "Lframe"
289 #define CIE_AFTER_SIZE_LABEL "LSCIE"
290 #define CIE_END_LABEL "LECIE"
291 #define FDE_LABEL "LSFDE"
292 #define FDE_AFTER_SIZE_LABEL "LASFDE"
293 #define FDE_END_LABEL "LEFDE"
294 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
295 #define LINE_NUMBER_END_LABEL "LELT"
296 #define LN_PROLOG_AS_LABEL "LASLTP"
297 #define LN_PROLOG_END_LABEL "LELTP"
298 #define DIE_LABEL_PREFIX "DW"
300 /* Match the base name of a file to the base name of a compilation unit. */
303 matches_main_base (const char *path
)
305 /* Cache the last query. */
306 static const char *last_path
= NULL
;
307 static int last_match
= 0;
308 if (path
!= last_path
)
311 int length
= base_of_path (path
, &base
);
313 last_match
= (length
== main_input_baselength
314 && memcmp (base
, main_input_basename
, length
) == 0);
319 #ifdef DEBUG_DEBUG_STRUCT
322 dump_struct_debug (tree type
, enum debug_info_usage usage
,
323 enum debug_struct_file criterion
, int generic
,
324 int matches
, int result
)
326 /* Find the type name. */
327 tree type_decl
= TYPE_STUB_DECL (type
);
329 const char *name
= 0;
330 if (TREE_CODE (t
) == TYPE_DECL
)
333 name
= IDENTIFIER_POINTER (t
);
335 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
337 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
338 matches
? "bas" : "hdr",
339 generic
? "gen" : "ord",
340 usage
== DINFO_USAGE_DFN
? ";" :
341 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
343 (void*) type_decl
, name
);
346 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
347 dump_struct_debug (type, usage, criterion, generic, matches, result)
351 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
357 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
359 enum debug_struct_file criterion
;
361 bool generic
= lang_hooks
.types
.generic_p (type
);
364 criterion
= debug_struct_generic
[usage
];
366 criterion
= debug_struct_ordinary
[usage
];
368 if (criterion
== DINFO_STRUCT_FILE_NONE
)
369 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
370 if (criterion
== DINFO_STRUCT_FILE_ANY
)
371 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
373 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
375 if (type_decl
!= NULL
)
377 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
378 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
380 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
381 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
384 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
387 /* Return a pointer to a copy of the section string name S with all
388 attributes stripped off, and an asterisk prepended (for assemble_name). */
391 stripattributes (const char *s
)
393 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
398 while (*s
&& *s
!= ',')
405 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
406 switch to the data section instead, and write out a synthetic start label
407 for collect2 the first time around. */
410 switch_to_eh_frame_section (bool back
)
414 #ifdef EH_FRAME_SECTION_NAME
415 if (eh_frame_section
== 0)
419 if (EH_TABLES_CAN_BE_READ_ONLY
)
425 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
427 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
429 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
432 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
433 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
434 && (per_encoding
& 0x70) != DW_EH_PE_absptr
435 && (per_encoding
& 0x70) != DW_EH_PE_aligned
436 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
437 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
438 ? 0 : SECTION_WRITE
);
441 flags
= SECTION_WRITE
;
442 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
444 #endif /* EH_FRAME_SECTION_NAME */
446 if (eh_frame_section
)
447 switch_to_section (eh_frame_section
);
450 /* We have no special eh_frame section. Put the information in
451 the data section and emit special labels to guide collect2. */
452 switch_to_section (data_section
);
456 label
= get_file_function_name ("F");
457 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
458 targetm
.asm_out
.globalize_label (asm_out_file
,
459 IDENTIFIER_POINTER (label
));
460 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
465 /* Switch [BACK] to the eh or debug frame table section, depending on
469 switch_to_frame_table_section (int for_eh
, bool back
)
472 switch_to_eh_frame_section (back
);
475 if (!debug_frame_section
)
476 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
477 SECTION_DEBUG
, NULL
);
478 switch_to_section (debug_frame_section
);
482 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
484 enum dw_cfi_oprnd_type
485 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
490 case DW_CFA_GNU_window_save
:
491 case DW_CFA_remember_state
:
492 case DW_CFA_restore_state
:
493 return dw_cfi_oprnd_unused
;
496 case DW_CFA_advance_loc1
:
497 case DW_CFA_advance_loc2
:
498 case DW_CFA_advance_loc4
:
499 case DW_CFA_MIPS_advance_loc8
:
500 return dw_cfi_oprnd_addr
;
503 case DW_CFA_offset_extended
:
505 case DW_CFA_offset_extended_sf
:
506 case DW_CFA_def_cfa_sf
:
508 case DW_CFA_restore_extended
:
509 case DW_CFA_undefined
:
510 case DW_CFA_same_value
:
511 case DW_CFA_def_cfa_register
:
512 case DW_CFA_register
:
513 case DW_CFA_expression
:
514 return dw_cfi_oprnd_reg_num
;
516 case DW_CFA_def_cfa_offset
:
517 case DW_CFA_GNU_args_size
:
518 case DW_CFA_def_cfa_offset_sf
:
519 return dw_cfi_oprnd_offset
;
521 case DW_CFA_def_cfa_expression
:
522 return dw_cfi_oprnd_loc
;
529 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
531 enum dw_cfi_oprnd_type
532 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
537 case DW_CFA_def_cfa_sf
:
539 case DW_CFA_offset_extended_sf
:
540 case DW_CFA_offset_extended
:
541 return dw_cfi_oprnd_offset
;
543 case DW_CFA_register
:
544 return dw_cfi_oprnd_reg_num
;
546 case DW_CFA_expression
:
547 return dw_cfi_oprnd_loc
;
550 return dw_cfi_oprnd_unused
;
554 /* Output one FDE. */
557 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
558 char *section_start_label
, int fde_encoding
, char *augmentation
,
559 bool any_lsda_needed
, int lsda_encoding
)
561 const char *begin
, *end
;
562 static unsigned int j
;
565 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
567 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
569 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
570 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
571 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
572 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
573 " indicating 64-bit DWARF extension");
574 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
576 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
579 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
581 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
582 debug_frame_section
, "FDE CIE offset");
584 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
585 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
589 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
590 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
591 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
592 "FDE initial location");
593 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
594 end
, begin
, "FDE address range");
598 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
599 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
606 int size
= size_of_encoded_value (lsda_encoding
);
608 if (lsda_encoding
== DW_EH_PE_aligned
)
610 int offset
= ( 4 /* Length */
612 + 2 * size_of_encoded_value (fde_encoding
)
613 + 1 /* Augmentation size */ );
614 int pad
= -offset
& (PTR_SIZE
- 1);
617 gcc_assert (size_of_uleb128 (size
) == 1);
620 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
622 if (fde
->uses_eh_lsda
)
624 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
625 fde
->funcdef_number
);
626 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
627 gen_rtx_SYMBOL_REF (Pmode
, l1
),
629 "Language Specific Data Area");
633 if (lsda_encoding
== DW_EH_PE_aligned
)
634 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
635 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
636 "Language Specific Data Area (none)");
640 dw2_asm_output_data_uleb128 (0, "Augmentation size");
643 /* Loop through the Call Frame Instructions associated with this FDE. */
644 fde
->dw_fde_current_label
= begin
;
646 size_t from
, until
, i
;
649 until
= vec_safe_length (fde
->dw_fde_cfi
);
651 if (fde
->dw_fde_second_begin
== NULL
)
654 until
= fde
->dw_fde_switch_cfi_index
;
656 from
= fde
->dw_fde_switch_cfi_index
;
658 for (i
= from
; i
< until
; i
++)
659 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
662 /* If we are to emit a ref/link from function bodies to their frame tables,
663 do it now. This is typically performed to make sure that tables
664 associated with functions are dragged with them and not discarded in
665 garbage collecting links. We need to do this on a per function basis to
666 cope with -ffunction-sections. */
668 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
669 /* Switch to the function section, emit the ref to the tables, and
670 switch *back* into the table section. */
671 switch_to_section (function_section (fde
->decl
));
672 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
673 switch_to_frame_table_section (for_eh
, true);
676 /* Pad the FDE out to an address sized boundary. */
677 ASM_OUTPUT_ALIGN (asm_out_file
,
678 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
679 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
684 /* Return true if frame description entry FDE is needed for EH. */
687 fde_needed_for_eh_p (dw_fde_ref fde
)
689 if (flag_asynchronous_unwind_tables
)
692 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
695 if (fde
->uses_eh_lsda
)
698 /* If exceptions are enabled, we have collected nothrow info. */
699 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
705 /* Output the call frame information used to record information
706 that relates to calculating the frame pointer, and records the
707 location of saved registers. */
710 output_call_frame_info (int for_eh
)
715 char l1
[20], l2
[20], section_start_label
[20];
716 bool any_lsda_needed
= false;
717 char augmentation
[6];
718 int augmentation_size
;
719 int fde_encoding
= DW_EH_PE_absptr
;
720 int per_encoding
= DW_EH_PE_absptr
;
721 int lsda_encoding
= DW_EH_PE_absptr
;
723 rtx personality
= NULL
;
726 /* Don't emit a CIE if there won't be any FDEs. */
730 /* Nothing to do if the assembler's doing it all. */
731 if (dwarf2out_do_cfi_asm ())
734 /* If we don't have any functions we'll want to unwind out of, don't emit
735 any EH unwind information. If we make FDEs linkonce, we may have to
736 emit an empty label for an FDE that wouldn't otherwise be emitted. We
737 want to avoid having an FDE kept around when the function it refers to
738 is discarded. Example where this matters: a primary function template
739 in C++ requires EH information, an explicit specialization doesn't. */
742 bool any_eh_needed
= false;
744 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
746 if (fde
->uses_eh_lsda
)
747 any_eh_needed
= any_lsda_needed
= true;
748 else if (fde_needed_for_eh_p (fde
))
749 any_eh_needed
= true;
750 else if (TARGET_USES_WEAK_UNWIND_INFO
)
751 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
758 /* We're going to be generating comments, so turn on app. */
762 /* Switch to the proper frame section, first time. */
763 switch_to_frame_table_section (for_eh
, false);
765 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
766 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
768 /* Output the CIE. */
769 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
770 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
771 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
772 dw2_asm_output_data (4, 0xffffffff,
773 "Initial length escape value indicating 64-bit DWARF extension");
774 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
775 "Length of Common Information Entry");
776 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
778 /* Now that the CIE pointer is PC-relative for EH,
779 use 0 to identify the CIE. */
780 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
781 (for_eh
? 0 : DWARF_CIE_ID
),
782 "CIE Identifier Tag");
784 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
785 use CIE version 1, unless that would produce incorrect results
786 due to overflowing the return register column. */
787 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
789 if (return_reg
>= 256 || dwarf_version
> 2)
791 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
794 augmentation_size
= 0;
796 personality
= current_unit_personality
;
802 z Indicates that a uleb128 is present to size the
803 augmentation section.
804 L Indicates the encoding (and thus presence) of
805 an LSDA pointer in the FDE augmentation.
806 R Indicates a non-default pointer encoding for
808 P Indicates the presence of an encoding + language
809 personality routine in the CIE augmentation. */
811 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
812 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
813 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
815 p
= augmentation
+ 1;
819 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
820 assemble_external_libcall (personality
);
825 augmentation_size
+= 1;
827 if (fde_encoding
!= DW_EH_PE_absptr
)
830 augmentation_size
+= 1;
832 if (p
> augmentation
+ 1)
834 augmentation
[0] = 'z';
838 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
839 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
841 int offset
= ( 4 /* Length */
843 + 1 /* CIE version */
844 + strlen (augmentation
) + 1 /* Augmentation */
845 + size_of_uleb128 (1) /* Code alignment */
846 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
848 + 1 /* Augmentation size */
849 + 1 /* Personality encoding */ );
850 int pad
= -offset
& (PTR_SIZE
- 1);
852 augmentation_size
+= pad
;
854 /* Augmentations should be small, so there's scarce need to
855 iterate for a solution. Die if we exceed one uleb128 byte. */
856 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
860 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
861 if (dw_cie_version
>= 4)
863 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
864 dw2_asm_output_data (1, 0, "CIE Segment Size");
866 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
867 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
868 "CIE Data Alignment Factor");
870 if (dw_cie_version
== 1)
871 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
873 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
877 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
880 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
881 eh_data_format_name (per_encoding
));
882 dw2_asm_output_encoded_addr_rtx (per_encoding
,
888 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
889 eh_data_format_name (lsda_encoding
));
891 if (fde_encoding
!= DW_EH_PE_absptr
)
892 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
893 eh_data_format_name (fde_encoding
));
896 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
897 output_cfi (cfi
, NULL
, for_eh
);
899 /* Pad the CIE out to an address sized boundary. */
900 ASM_OUTPUT_ALIGN (asm_out_file
,
901 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
902 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
904 /* Loop through all of the FDE's. */
905 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
909 /* Don't emit EH unwind info for leaf functions that don't need it. */
910 if (for_eh
&& !fde_needed_for_eh_p (fde
))
913 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
914 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
915 augmentation
, any_lsda_needed
, lsda_encoding
);
918 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
919 dw2_asm_output_data (4, 0, "End of Table");
921 /* Turn off app to make assembly quicker. */
926 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
929 dwarf2out_do_cfi_startproc (bool second
)
933 rtx personality
= get_personality_function (current_function_decl
);
935 fprintf (asm_out_file
, "\t.cfi_startproc\n");
939 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
942 /* ??? The GAS support isn't entirely consistent. We have to
943 handle indirect support ourselves, but PC-relative is done
944 in the assembler. Further, the assembler can't handle any
945 of the weirder relocation types. */
946 if (enc
& DW_EH_PE_indirect
)
947 ref
= dw2_force_const_mem (ref
, true);
949 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
950 output_addr_const (asm_out_file
, ref
);
951 fputc ('\n', asm_out_file
);
954 if (crtl
->uses_eh_lsda
)
958 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
959 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
960 current_function_funcdef_no
);
961 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
962 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
964 if (enc
& DW_EH_PE_indirect
)
965 ref
= dw2_force_const_mem (ref
, true);
967 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
968 output_addr_const (asm_out_file
, ref
);
969 fputc ('\n', asm_out_file
);
973 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
974 this allocation may be done before pass_final. */
977 dwarf2out_alloc_current_fde (void)
981 fde
= ggc_alloc_cleared_dw_fde_node ();
982 fde
->decl
= current_function_decl
;
983 fde
->funcdef_number
= current_function_funcdef_no
;
984 fde
->fde_index
= vec_safe_length (fde_vec
);
985 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
986 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
987 fde
->nothrow
= crtl
->nothrow
;
988 fde
->drap_reg
= INVALID_REGNUM
;
989 fde
->vdrap_reg
= INVALID_REGNUM
;
991 /* Record the FDE associated with this function. */
993 vec_safe_push (fde_vec
, fde
);
998 /* Output a marker (i.e. a label) for the beginning of a function, before
1002 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1003 const char *file ATTRIBUTE_UNUSED
)
1005 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1011 current_function_func_begin_label
= NULL
;
1013 do_frame
= dwarf2out_do_frame ();
1015 /* ??? current_function_func_begin_label is also used by except.c for
1016 call-site information. We must emit this label if it might be used. */
1018 && (!flag_exceptions
1019 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1022 fnsec
= function_section (current_function_decl
);
1023 switch_to_section (fnsec
);
1024 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1025 current_function_funcdef_no
);
1026 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1027 current_function_funcdef_no
);
1028 dup_label
= xstrdup (label
);
1029 current_function_func_begin_label
= dup_label
;
1031 /* We can elide the fde allocation if we're not emitting debug info. */
1035 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1036 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1037 would include pass_dwarf2_frame. If we've not created the FDE yet,
1041 fde
= dwarf2out_alloc_current_fde ();
1043 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1044 fde
->dw_fde_begin
= dup_label
;
1045 fde
->dw_fde_current_label
= dup_label
;
1046 fde
->in_std_section
= (fnsec
== text_section
1047 || (cold_text_section
&& fnsec
== cold_text_section
));
1049 /* We only want to output line number information for the genuine dwarf2
1050 prologue case, not the eh frame case. */
1051 #ifdef DWARF2_DEBUGGING_INFO
1053 dwarf2out_source_line (line
, file
, 0, true);
1056 if (dwarf2out_do_cfi_asm ())
1057 dwarf2out_do_cfi_startproc (false);
1060 rtx personality
= get_personality_function (current_function_decl
);
1061 if (!current_unit_personality
)
1062 current_unit_personality
= personality
;
1064 /* We cannot keep a current personality per function as without CFI
1065 asm, at the point where we emit the CFI data, there is no current
1066 function anymore. */
1067 if (personality
&& current_unit_personality
!= personality
)
1068 sorry ("multiple EH personalities are supported only with assemblers "
1069 "supporting .cfi_personality directive");
1073 /* Output a marker (i.e. a label) for the end of the generated code
1074 for a function prologue. This gets called *after* the prologue code has
1078 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1079 const char *file ATTRIBUTE_UNUSED
)
1081 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1083 /* Output a label to mark the endpoint of the code generated for this
1085 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1086 current_function_funcdef_no
);
1087 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1088 current_function_funcdef_no
);
1089 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1092 /* Output a marker (i.e. a label) for the beginning of the generated code
1093 for a function epilogue. This gets called *before* the prologue code has
1097 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1098 const char *file ATTRIBUTE_UNUSED
)
1100 dw_fde_ref fde
= cfun
->fde
;
1101 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1103 if (fde
->dw_fde_vms_begin_epilogue
)
1106 /* Output a label to mark the endpoint of the code generated for this
1108 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1109 current_function_funcdef_no
);
1110 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1111 current_function_funcdef_no
);
1112 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1115 /* Output a marker (i.e. a label) for the absolute end of the generated code
1116 for a function definition. This gets called *after* the epilogue code has
1120 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1121 const char *file ATTRIBUTE_UNUSED
)
1124 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1126 last_var_location_insn
= NULL_RTX
;
1127 cached_next_real_insn
= NULL_RTX
;
1129 if (dwarf2out_do_cfi_asm ())
1130 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1132 /* Output a label to mark the endpoint of the code generated for this
1134 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1135 current_function_funcdef_no
);
1136 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1138 gcc_assert (fde
!= NULL
);
1139 if (fde
->dw_fde_second_begin
== NULL
)
1140 fde
->dw_fde_end
= xstrdup (label
);
1144 dwarf2out_frame_finish (void)
1146 /* Output call frame information. */
1147 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1148 output_call_frame_info (0);
1150 /* Output another copy for the unwinder. */
1151 if ((flag_unwind_tables
|| flag_exceptions
)
1152 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1153 output_call_frame_info (1);
1156 /* Note that the current function section is being used for code. */
1159 dwarf2out_note_section_used (void)
1161 section
*sec
= current_function_section ();
1162 if (sec
== text_section
)
1163 text_section_used
= true;
1164 else if (sec
== cold_text_section
)
1165 cold_text_section_used
= true;
1168 static void var_location_switch_text_section (void);
1169 static void set_cur_line_info_table (section
*);
1172 dwarf2out_switch_text_section (void)
1175 dw_fde_ref fde
= cfun
->fde
;
1177 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1179 if (!in_cold_section_p
)
1181 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1182 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1183 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1187 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1188 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1189 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1191 have_multiple_function_sections
= true;
1193 /* There is no need to mark used sections when not debugging. */
1194 if (cold_text_section
!= NULL
)
1195 dwarf2out_note_section_used ();
1197 if (dwarf2out_do_cfi_asm ())
1198 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1200 /* Now do the real section switch. */
1201 sect
= current_function_section ();
1202 switch_to_section (sect
);
1204 fde
->second_in_std_section
1205 = (sect
== text_section
1206 || (cold_text_section
&& sect
== cold_text_section
));
1208 if (dwarf2out_do_cfi_asm ())
1209 dwarf2out_do_cfi_startproc (true);
1211 var_location_switch_text_section ();
1213 if (cold_text_section
!= NULL
)
1214 set_cur_line_info_table (sect
);
1217 /* And now, the subset of the debugging information support code necessary
1218 for emitting location expressions. */
1220 /* Data about a single source file. */
1221 struct GTY(()) dwarf_file_data
{
1222 const char * filename
;
1226 typedef struct GTY(()) deferred_locations_struct
1230 } deferred_locations
;
1233 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1236 /* Describe an entry into the .debug_addr section. */
1240 ate_kind_rtx_dtprel
,
1244 typedef struct GTY(()) addr_table_entry_struct
{
1246 unsigned int refcount
;
1248 union addr_table_entry_struct_union
1250 rtx
GTY ((tag ("0"))) rtl
;
1251 char * GTY ((tag ("1"))) label
;
1253 GTY ((desc ("%1.kind"))) addr
;
1257 /* Location lists are ranges + location descriptions for that range,
1258 so you can track variables that are in different places over
1259 their entire life. */
1260 typedef struct GTY(()) dw_loc_list_struct
{
1261 dw_loc_list_ref dw_loc_next
;
1262 const char *begin
; /* Label and addr_entry for start of range */
1263 addr_table_entry
*begin_entry
;
1264 const char *end
; /* Label for end of range */
1265 char *ll_symbol
; /* Label for beginning of location list.
1266 Only on head of list */
1267 const char *section
; /* Section this loclist is relative to */
1268 dw_loc_descr_ref expr
;
1270 /* True if all addresses in this and subsequent lists are known to be
1273 /* True if this list has been replaced by dw_loc_next. */
1276 /* True if the range should be emitted even if begin and end
1281 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1283 /* Convert a DWARF stack opcode into its string name. */
1286 dwarf_stack_op_name (unsigned int op
)
1288 const char *name
= get_DW_OP_name (op
);
1293 return "OP_<unknown>";
1296 /* Return a pointer to a newly allocated location description. Location
1297 descriptions are simple expression terms that can be strung
1298 together to form more complicated location (address) descriptions. */
1300 static inline dw_loc_descr_ref
1301 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1302 unsigned HOST_WIDE_INT oprnd2
)
1304 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1306 descr
->dw_loc_opc
= op
;
1307 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1308 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1309 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1310 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1311 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1312 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1317 /* Return a pointer to a newly allocated location description for
1320 static inline dw_loc_descr_ref
1321 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1324 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1327 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1330 /* Add a location description term to a location description expression. */
1333 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1335 dw_loc_descr_ref
*d
;
1337 /* Find the end of the chain. */
1338 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1344 /* Compare two location operands for exact equality. */
1347 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1349 if (a
->val_class
!= b
->val_class
)
1351 switch (a
->val_class
)
1353 case dw_val_class_none
:
1355 case dw_val_class_addr
:
1356 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1358 case dw_val_class_offset
:
1359 case dw_val_class_unsigned_const
:
1360 case dw_val_class_const
:
1361 case dw_val_class_range_list
:
1362 case dw_val_class_lineptr
:
1363 case dw_val_class_macptr
:
1364 /* These are all HOST_WIDE_INT, signed or unsigned. */
1365 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1367 case dw_val_class_loc
:
1368 return a
->v
.val_loc
== b
->v
.val_loc
;
1369 case dw_val_class_loc_list
:
1370 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1371 case dw_val_class_die_ref
:
1372 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1373 case dw_val_class_fde_ref
:
1374 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1375 case dw_val_class_lbl_id
:
1376 case dw_val_class_high_pc
:
1377 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1378 case dw_val_class_str
:
1379 return a
->v
.val_str
== b
->v
.val_str
;
1380 case dw_val_class_flag
:
1381 return a
->v
.val_flag
== b
->v
.val_flag
;
1382 case dw_val_class_file
:
1383 return a
->v
.val_file
== b
->v
.val_file
;
1384 case dw_val_class_decl_ref
:
1385 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1387 case dw_val_class_const_double
:
1388 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1389 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1391 case dw_val_class_vec
:
1393 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1394 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1396 return (a_len
== b_len
1397 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1400 case dw_val_class_data8
:
1401 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1403 case dw_val_class_vms_delta
:
1404 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1405 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1410 /* Compare two location atoms for exact equality. */
1413 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1415 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1418 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1419 address size, but since we always allocate cleared storage it
1420 should be zero for other types of locations. */
1421 if (a
->dtprel
!= b
->dtprel
)
1424 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1425 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1428 /* Compare two complete location expressions for exact equality. */
1431 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1437 if (a
== NULL
|| b
== NULL
)
1439 if (!loc_descr_equal_p_1 (a
, b
))
1448 /* Add a constant OFFSET to a location expression. */
1451 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1453 dw_loc_descr_ref loc
;
1456 gcc_assert (*list_head
!= NULL
);
1461 /* Find the end of the chain. */
1462 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1466 if (loc
->dw_loc_opc
== DW_OP_fbreg
1467 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1468 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1469 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1470 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1472 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1473 offset. Don't optimize if an signed integer overflow would happen. */
1475 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1476 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1479 else if (offset
> 0)
1480 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1484 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1485 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1489 /* Add a constant OFFSET to a location list. */
1492 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1495 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1496 loc_descr_plus_const (&d
->expr
, offset
);
1499 #define DWARF_REF_SIZE \
1500 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1502 static unsigned long int get_base_type_offset (dw_die_ref
);
1504 /* Return the size of a location descriptor. */
1506 static unsigned long
1507 size_of_loc_descr (dw_loc_descr_ref loc
)
1509 unsigned long size
= 1;
1511 switch (loc
->dw_loc_opc
)
1514 size
+= DWARF2_ADDR_SIZE
;
1516 case DW_OP_GNU_addr_index
:
1517 case DW_OP_GNU_const_index
:
1518 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1519 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1538 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1541 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1546 case DW_OP_plus_uconst
:
1547 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1585 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1588 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1591 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1594 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1595 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1598 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1600 case DW_OP_bit_piece
:
1601 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1602 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1604 case DW_OP_deref_size
:
1605 case DW_OP_xderef_size
:
1614 case DW_OP_call_ref
:
1615 size
+= DWARF_REF_SIZE
;
1617 case DW_OP_implicit_value
:
1618 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1619 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1621 case DW_OP_GNU_implicit_pointer
:
1622 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1624 case DW_OP_GNU_entry_value
:
1626 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1627 size
+= size_of_uleb128 (op_size
) + op_size
;
1630 case DW_OP_GNU_const_type
:
1633 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1634 size
+= size_of_uleb128 (o
) + 1;
1635 switch (loc
->dw_loc_oprnd2
.val_class
)
1637 case dw_val_class_vec
:
1638 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1639 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1641 case dw_val_class_const
:
1642 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1644 case dw_val_class_const_double
:
1645 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1652 case DW_OP_GNU_regval_type
:
1655 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1656 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1657 + size_of_uleb128 (o
);
1660 case DW_OP_GNU_deref_type
:
1663 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1664 size
+= 1 + size_of_uleb128 (o
);
1667 case DW_OP_GNU_convert
:
1668 case DW_OP_GNU_reinterpret
:
1669 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1670 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1674 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1675 size
+= size_of_uleb128 (o
);
1678 case DW_OP_GNU_parameter_ref
:
1688 /* Return the size of a series of location descriptors. */
1691 size_of_locs (dw_loc_descr_ref loc
)
1696 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1697 field, to avoid writing to a PCH file. */
1698 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1700 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1702 size
+= size_of_loc_descr (l
);
1707 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1709 l
->dw_loc_addr
= size
;
1710 size
+= size_of_loc_descr (l
);
1716 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1717 static void get_ref_die_offset_label (char *, dw_die_ref
);
1718 static unsigned long int get_ref_die_offset (dw_die_ref
);
1720 /* Output location description stack opcode's operands (if any).
1721 The for_eh_or_skip parameter controls whether register numbers are
1722 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1723 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1724 info). This should be suppressed for the cases that have not been converted
1725 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1728 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1730 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1731 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1733 switch (loc
->dw_loc_opc
)
1735 #ifdef DWARF2_DEBUGGING_INFO
1738 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1743 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1744 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1746 fputc ('\n', asm_out_file
);
1751 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1756 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1757 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1759 fputc ('\n', asm_out_file
);
1764 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1765 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1772 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1773 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1775 dw2_asm_output_data (2, offset
, NULL
);
1778 case DW_OP_implicit_value
:
1779 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1780 switch (val2
->val_class
)
1782 case dw_val_class_const
:
1783 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1785 case dw_val_class_vec
:
1787 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1788 unsigned int len
= val2
->v
.val_vec
.length
;
1792 if (elt_size
> sizeof (HOST_WIDE_INT
))
1797 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1800 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1801 "fp or vector constant word %u", i
);
1804 case dw_val_class_const_double
:
1806 unsigned HOST_WIDE_INT first
, second
;
1808 if (WORDS_BIG_ENDIAN
)
1810 first
= val2
->v
.val_double
.high
;
1811 second
= val2
->v
.val_double
.low
;
1815 first
= val2
->v
.val_double
.low
;
1816 second
= val2
->v
.val_double
.high
;
1818 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1820 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1824 case dw_val_class_addr
:
1825 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1826 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1841 case DW_OP_implicit_value
:
1842 /* We currently don't make any attempt to make sure these are
1843 aligned properly like we do for the main unwind info, so
1844 don't support emitting things larger than a byte if we're
1845 only doing unwinding. */
1850 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1853 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1856 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1859 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1861 case DW_OP_plus_uconst
:
1862 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1896 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1900 unsigned r
= val1
->v
.val_unsigned
;
1901 if (for_eh_or_skip
>= 0)
1902 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1903 gcc_assert (size_of_uleb128 (r
)
1904 == size_of_uleb128 (val1
->v
.val_unsigned
));
1905 dw2_asm_output_data_uleb128 (r
, NULL
);
1909 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1913 unsigned r
= val1
->v
.val_unsigned
;
1914 if (for_eh_or_skip
>= 0)
1915 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1916 gcc_assert (size_of_uleb128 (r
)
1917 == size_of_uleb128 (val1
->v
.val_unsigned
));
1918 dw2_asm_output_data_uleb128 (r
, NULL
);
1919 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1923 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1925 case DW_OP_bit_piece
:
1926 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1927 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1929 case DW_OP_deref_size
:
1930 case DW_OP_xderef_size
:
1931 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1937 if (targetm
.asm_out
.output_dwarf_dtprel
)
1939 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1942 fputc ('\n', asm_out_file
);
1949 #ifdef DWARF2_DEBUGGING_INFO
1950 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1957 case DW_OP_GNU_addr_index
:
1958 case DW_OP_GNU_const_index
:
1959 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1960 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1961 "(index into .debug_addr)");
1964 case DW_OP_GNU_implicit_pointer
:
1966 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1967 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1968 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1969 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1970 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1971 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1975 case DW_OP_GNU_entry_value
:
1976 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1977 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1980 case DW_OP_GNU_const_type
:
1982 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1984 dw2_asm_output_data_uleb128 (o
, NULL
);
1985 switch (val2
->val_class
)
1987 case dw_val_class_const
:
1988 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1989 dw2_asm_output_data (1, l
, NULL
);
1990 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1992 case dw_val_class_vec
:
1994 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1995 unsigned int len
= val2
->v
.val_vec
.length
;
2000 dw2_asm_output_data (1, l
, NULL
);
2001 if (elt_size
> sizeof (HOST_WIDE_INT
))
2006 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2009 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2010 "fp or vector constant word %u", i
);
2013 case dw_val_class_const_double
:
2015 unsigned HOST_WIDE_INT first
, second
;
2016 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2018 dw2_asm_output_data (1, 2 * l
, NULL
);
2019 if (WORDS_BIG_ENDIAN
)
2021 first
= val2
->v
.val_double
.high
;
2022 second
= val2
->v
.val_double
.low
;
2026 first
= val2
->v
.val_double
.low
;
2027 second
= val2
->v
.val_double
.high
;
2029 dw2_asm_output_data (l
, first
, NULL
);
2030 dw2_asm_output_data (l
, second
, NULL
);
2038 case DW_OP_GNU_regval_type
:
2040 unsigned r
= val1
->v
.val_unsigned
;
2041 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2043 if (for_eh_or_skip
>= 0)
2045 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2046 gcc_assert (size_of_uleb128 (r
)
2047 == size_of_uleb128 (val1
->v
.val_unsigned
));
2049 dw2_asm_output_data_uleb128 (r
, NULL
);
2050 dw2_asm_output_data_uleb128 (o
, NULL
);
2053 case DW_OP_GNU_deref_type
:
2055 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2057 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2058 dw2_asm_output_data_uleb128 (o
, NULL
);
2061 case DW_OP_GNU_convert
:
2062 case DW_OP_GNU_reinterpret
:
2063 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2064 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2067 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2069 dw2_asm_output_data_uleb128 (o
, NULL
);
2073 case DW_OP_GNU_parameter_ref
:
2076 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2077 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2078 dw2_asm_output_data (4, o
, NULL
);
2083 /* Other codes have no operands. */
2088 /* Output a sequence of location operations.
2089 The for_eh_or_skip parameter controls whether register numbers are
2090 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2091 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2092 info). This should be suppressed for the cases that have not been converted
2093 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2096 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2098 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2100 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2101 /* Output the opcode. */
2102 if (for_eh_or_skip
>= 0
2103 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2105 unsigned r
= (opc
- DW_OP_breg0
);
2106 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2107 gcc_assert (r
<= 31);
2108 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2110 else if (for_eh_or_skip
>= 0
2111 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2113 unsigned r
= (opc
- DW_OP_reg0
);
2114 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2115 gcc_assert (r
<= 31);
2116 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2119 dw2_asm_output_data (1, opc
,
2120 "%s", dwarf_stack_op_name (opc
));
2122 /* Output the operand(s) (if any). */
2123 output_loc_operands (loc
, for_eh_or_skip
);
2127 /* Output location description stack opcode's operands (if any).
2128 The output is single bytes on a line, suitable for .cfi_escape. */
2131 output_loc_operands_raw (dw_loc_descr_ref loc
)
2133 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2134 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2136 switch (loc
->dw_loc_opc
)
2139 case DW_OP_GNU_addr_index
:
2140 case DW_OP_GNU_const_index
:
2141 case DW_OP_implicit_value
:
2142 /* We cannot output addresses in .cfi_escape, only bytes. */
2148 case DW_OP_deref_size
:
2149 case DW_OP_xderef_size
:
2150 fputc (',', asm_out_file
);
2151 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2156 fputc (',', asm_out_file
);
2157 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2162 fputc (',', asm_out_file
);
2163 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2168 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2169 fputc (',', asm_out_file
);
2170 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2178 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2179 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2181 fputc (',', asm_out_file
);
2182 dw2_asm_output_data_raw (2, offset
);
2188 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2189 gcc_assert (size_of_uleb128 (r
)
2190 == size_of_uleb128 (val1
->v
.val_unsigned
));
2191 fputc (',', asm_out_file
);
2192 dw2_asm_output_data_uleb128_raw (r
);
2197 case DW_OP_plus_uconst
:
2199 fputc (',', asm_out_file
);
2200 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2203 case DW_OP_bit_piece
:
2204 fputc (',', asm_out_file
);
2205 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2206 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2243 fputc (',', asm_out_file
);
2244 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2249 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2250 gcc_assert (size_of_uleb128 (r
)
2251 == size_of_uleb128 (val1
->v
.val_unsigned
));
2252 fputc (',', asm_out_file
);
2253 dw2_asm_output_data_uleb128_raw (r
);
2254 fputc (',', asm_out_file
);
2255 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2259 case DW_OP_GNU_implicit_pointer
:
2260 case DW_OP_GNU_entry_value
:
2261 case DW_OP_GNU_const_type
:
2262 case DW_OP_GNU_regval_type
:
2263 case DW_OP_GNU_deref_type
:
2264 case DW_OP_GNU_convert
:
2265 case DW_OP_GNU_reinterpret
:
2266 case DW_OP_GNU_parameter_ref
:
2271 /* Other codes have no operands. */
2277 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2281 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2282 /* Output the opcode. */
2283 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2285 unsigned r
= (opc
- DW_OP_breg0
);
2286 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2287 gcc_assert (r
<= 31);
2288 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2290 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2292 unsigned r
= (opc
- DW_OP_reg0
);
2293 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2294 gcc_assert (r
<= 31);
2295 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2297 /* Output the opcode. */
2298 fprintf (asm_out_file
, "%#x", opc
);
2299 output_loc_operands_raw (loc
);
2301 if (!loc
->dw_loc_next
)
2303 loc
= loc
->dw_loc_next
;
2305 fputc (',', asm_out_file
);
2309 /* This function builds a dwarf location descriptor sequence from a
2310 dw_cfa_location, adding the given OFFSET to the result of the
2313 struct dw_loc_descr_struct
*
2314 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2316 struct dw_loc_descr_struct
*head
, *tmp
;
2318 offset
+= cfa
->offset
;
2322 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2323 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2324 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2325 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2326 add_loc_descr (&head
, tmp
);
2329 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2330 add_loc_descr (&head
, tmp
);
2334 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2339 /* This function builds a dwarf location descriptor sequence for
2340 the address at OFFSET from the CFA when stack is aligned to
2343 struct dw_loc_descr_struct
*
2344 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2345 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2347 struct dw_loc_descr_struct
*head
;
2348 unsigned int dwarf_fp
2349 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2351 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2352 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2354 head
= new_reg_loc_descr (dwarf_fp
, 0);
2355 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2356 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2357 loc_descr_plus_const (&head
, offset
);
2360 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2364 /* And now, the support for symbolic debugging information. */
2366 /* .debug_str support. */
2367 static int output_indirect_string (void **, void *);
2369 static void dwarf2out_init (const char *);
2370 static void dwarf2out_finish (const char *);
2371 static void dwarf2out_assembly_start (void);
2372 static void dwarf2out_define (unsigned int, const char *);
2373 static void dwarf2out_undef (unsigned int, const char *);
2374 static void dwarf2out_start_source_file (unsigned, const char *);
2375 static void dwarf2out_end_source_file (unsigned);
2376 static void dwarf2out_function_decl (tree
);
2377 static void dwarf2out_begin_block (unsigned, unsigned);
2378 static void dwarf2out_end_block (unsigned, unsigned);
2379 static bool dwarf2out_ignore_block (const_tree
);
2380 static void dwarf2out_global_decl (tree
);
2381 static void dwarf2out_type_decl (tree
, int);
2382 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2383 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2385 static void dwarf2out_abstract_function (tree
);
2386 static void dwarf2out_var_location (rtx
);
2387 static void dwarf2out_begin_function (tree
);
2388 static void dwarf2out_end_function (unsigned int);
2389 static void dwarf2out_set_name (tree
, tree
);
2391 /* The debug hooks structure. */
2393 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2397 dwarf2out_assembly_start
,
2400 dwarf2out_start_source_file
,
2401 dwarf2out_end_source_file
,
2402 dwarf2out_begin_block
,
2403 dwarf2out_end_block
,
2404 dwarf2out_ignore_block
,
2405 dwarf2out_source_line
,
2406 dwarf2out_begin_prologue
,
2407 #if VMS_DEBUGGING_INFO
2408 dwarf2out_vms_end_prologue
,
2409 dwarf2out_vms_begin_epilogue
,
2411 debug_nothing_int_charstar
,
2412 debug_nothing_int_charstar
,
2414 dwarf2out_end_epilogue
,
2415 dwarf2out_begin_function
,
2416 dwarf2out_end_function
, /* end_function */
2417 dwarf2out_function_decl
, /* function_decl */
2418 dwarf2out_global_decl
,
2419 dwarf2out_type_decl
, /* type_decl */
2420 dwarf2out_imported_module_or_decl
,
2421 debug_nothing_tree
, /* deferred_inline_function */
2422 /* The DWARF 2 backend tries to reduce debugging bloat by not
2423 emitting the abstract description of inline functions until
2424 something tries to reference them. */
2425 dwarf2out_abstract_function
, /* outlining_inline_function */
2426 debug_nothing_rtx
, /* label */
2427 debug_nothing_int
, /* handle_pch */
2428 dwarf2out_var_location
,
2429 dwarf2out_switch_text_section
,
2431 1, /* start_end_main_source_file */
2432 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2435 /* NOTE: In the comments in this file, many references are made to
2436 "Debugging Information Entries". This term is abbreviated as `DIE'
2437 throughout the remainder of this file. */
2439 /* An internal representation of the DWARF output is built, and then
2440 walked to generate the DWARF debugging info. The walk of the internal
2441 representation is done after the entire program has been compiled.
2442 The types below are used to describe the internal representation. */
2444 /* Whether to put type DIEs into their own section .debug_types instead
2445 of making them part of the .debug_info section. Only supported for
2446 Dwarf V4 or higher and the user didn't disable them through
2447 -fno-debug-types-section. It is more efficient to put them in a
2448 separate comdat sections since the linker will then be able to
2449 remove duplicates. But not all tools support .debug_types sections
2452 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2454 /* Various DIE's use offsets relative to the beginning of the
2455 .debug_info section to refer to each other. */
2457 typedef long int dw_offset
;
2459 /* Define typedefs here to avoid circular dependencies. */
2461 typedef struct dw_attr_struct
*dw_attr_ref
;
2462 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2463 typedef struct pubname_struct
*pubname_ref
;
2464 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2465 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2466 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2468 /* The entries in the line_info table more-or-less mirror the opcodes
2469 that are used in the real dwarf line table. Arrays of these entries
2470 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2473 enum dw_line_info_opcode
{
2474 /* Emit DW_LNE_set_address; the operand is the label index. */
2477 /* Emit a row to the matrix with the given line. This may be done
2478 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2482 /* Emit a DW_LNS_set_file. */
2485 /* Emit a DW_LNS_set_column. */
2488 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2491 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2492 LI_set_prologue_end
,
2493 LI_set_epilogue_begin
,
2495 /* Emit a DW_LNE_set_discriminator. */
2496 LI_set_discriminator
2499 typedef struct GTY(()) dw_line_info_struct
{
2500 enum dw_line_info_opcode opcode
;
2502 } dw_line_info_entry
;
2505 typedef struct GTY(()) dw_line_info_table_struct
{
2506 /* The label that marks the end of this section. */
2507 const char *end_label
;
2509 /* The values for the last row of the matrix, as collected in the table.
2510 These are used to minimize the changes to the next row. */
2511 unsigned int file_num
;
2512 unsigned int line_num
;
2513 unsigned int column_num
;
2518 vec
<dw_line_info_entry
, va_gc
> *entries
;
2519 } dw_line_info_table
;
2521 typedef dw_line_info_table
*dw_line_info_table_p
;
2524 /* Each DIE attribute has a field specifying the attribute kind,
2525 a link to the next attribute in the chain, and an attribute value.
2526 Attributes are typically linked below the DIE they modify. */
2528 typedef struct GTY(()) dw_attr_struct
{
2529 enum dwarf_attribute dw_attr
;
2530 dw_val_node dw_attr_val
;
2535 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2536 The children of each node form a circular list linked by
2537 die_sib. die_child points to the node *before* the "first" child node. */
2539 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2540 union die_symbol_or_type_node
2542 const char * GTY ((tag ("0"))) die_symbol
;
2543 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2545 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2546 vec
<dw_attr_node
, va_gc
> *die_attr
;
2547 dw_die_ref die_parent
;
2548 dw_die_ref die_child
;
2550 dw_die_ref die_definition
; /* ref from a specification to its definition */
2551 dw_offset die_offset
;
2552 unsigned long die_abbrev
;
2554 unsigned int decl_id
;
2555 enum dwarf_tag die_tag
;
2556 /* Die is used and must not be pruned as unused. */
2557 BOOL_BITFIELD die_perennial_p
: 1;
2558 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2559 /* Lots of spare bits. */
2563 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2564 #define FOR_EACH_CHILD(die, c, expr) do { \
2565 c = die->die_child; \
2569 } while (c != die->die_child); \
2572 /* The pubname structure */
2574 typedef struct GTY(()) pubname_struct
{
2581 struct GTY(()) dw_ranges_struct
{
2582 /* If this is positive, it's a block number, otherwise it's a
2583 bitwise-negated index into dw_ranges_by_label. */
2587 /* A structure to hold a macinfo entry. */
2589 typedef struct GTY(()) macinfo_struct
{
2591 unsigned HOST_WIDE_INT lineno
;
2597 struct GTY(()) dw_ranges_by_label_struct
{
2602 /* The comdat type node structure. */
2603 typedef struct GTY(()) comdat_type_struct
2605 dw_die_ref root_die
;
2606 dw_die_ref type_die
;
2607 dw_die_ref skeleton_die
;
2608 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2609 struct comdat_type_struct
*next
;
2613 /* The limbo die list structure. */
2614 typedef struct GTY(()) limbo_die_struct
{
2617 struct limbo_die_struct
*next
;
2621 typedef struct skeleton_chain_struct
2625 struct skeleton_chain_struct
*parent
;
2627 skeleton_chain_node
;
2629 /* Define a macro which returns nonzero for a TYPE_DECL which was
2630 implicitly generated for a type.
2632 Note that, unlike the C front-end (which generates a NULL named
2633 TYPE_DECL node for each complete tagged type, each array type,
2634 and each function type node created) the C++ front-end generates
2635 a _named_ TYPE_DECL node for each tagged type node created.
2636 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2637 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2638 front-end, but for each type, tagged or not. */
2640 #define TYPE_DECL_IS_STUB(decl) \
2641 (DECL_NAME (decl) == NULL_TREE \
2642 || (DECL_ARTIFICIAL (decl) \
2643 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2644 /* This is necessary for stub decls that \
2645 appear in nested inline functions. */ \
2646 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2647 && (decl_ultimate_origin (decl) \
2648 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2650 /* Information concerning the compilation unit's programming
2651 language, and compiler version. */
2653 /* Fixed size portion of the DWARF compilation unit header. */
2654 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2655 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2657 /* Fixed size portion of the DWARF comdat type unit header. */
2658 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2659 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2660 + DWARF_OFFSET_SIZE)
2662 /* Fixed size portion of public names info. */
2663 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2665 /* Fixed size portion of the address range info. */
2666 #define DWARF_ARANGES_HEADER_SIZE \
2667 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2668 DWARF2_ADDR_SIZE * 2) \
2669 - DWARF_INITIAL_LENGTH_SIZE)
2671 /* Size of padding portion in the address range info. It must be
2672 aligned to twice the pointer size. */
2673 #define DWARF_ARANGES_PAD_SIZE \
2674 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2675 DWARF2_ADDR_SIZE * 2) \
2676 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2678 /* Use assembler line directives if available. */
2679 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2680 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2681 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2683 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2687 /* Minimum line offset in a special line info. opcode.
2688 This value was chosen to give a reasonable range of values. */
2689 #define DWARF_LINE_BASE -10
2691 /* First special line opcode - leave room for the standard opcodes. */
2692 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2694 /* Range of line offsets in a special line info. opcode. */
2695 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2697 /* Flag that indicates the initial value of the is_stmt_start flag.
2698 In the present implementation, we do not mark any lines as
2699 the beginning of a source statement, because that information
2700 is not made available by the GCC front-end. */
2701 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2703 /* Maximum number of operations per instruction bundle. */
2704 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2705 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2708 /* This location is used by calc_die_sizes() to keep track
2709 the offset of each DIE within the .debug_info section. */
2710 static unsigned long next_die_offset
;
2712 /* Record the root of the DIE's built for the current compilation unit. */
2713 static GTY(()) dw_die_ref single_comp_unit_die
;
2715 /* A list of type DIEs that have been separated into comdat sections. */
2716 static GTY(()) comdat_type_node
*comdat_type_list
;
2718 /* A list of DIEs with a NULL parent waiting to be relocated. */
2719 static GTY(()) limbo_die_node
*limbo_die_list
;
2721 /* A list of DIEs for which we may have to generate
2722 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2723 static GTY(()) limbo_die_node
*deferred_asm_name
;
2725 /* Filenames referenced by this compilation unit. */
2726 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2728 /* A hash table of references to DIE's that describe declarations.
2729 The key is a DECL_UID() which is a unique number identifying each decl. */
2730 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2732 /* A hash table of references to DIE's that describe COMMON blocks.
2733 The key is DECL_UID() ^ die_parent. */
2734 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2736 typedef struct GTY(()) die_arg_entry_struct
{
2742 /* Node of the variable location list. */
2743 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2744 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2745 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2746 in mode of the EXPR_LIST node and first EXPR_LIST operand
2747 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2748 location or NULL for padding. For larger bitsizes,
2749 mode is 0 and first operand is a CONCAT with bitsize
2750 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2751 NULL as second operand. */
2753 const char * GTY (()) label
;
2754 struct var_loc_node
* GTY (()) next
;
2757 /* Variable location list. */
2758 struct GTY (()) var_loc_list_def
{
2759 struct var_loc_node
* GTY (()) first
;
2761 /* Pointer to the last but one or last element of the
2762 chained list. If the list is empty, both first and
2763 last are NULL, if the list contains just one node
2764 or the last node certainly is not redundant, it points
2765 to the last node, otherwise points to the last but one.
2766 Do not mark it for GC because it is marked through the chain. */
2767 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2769 /* Pointer to the last element before section switch,
2770 if NULL, either sections weren't switched or first
2771 is after section switch. */
2772 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2774 /* DECL_UID of the variable decl. */
2775 unsigned int decl_id
;
2777 typedef struct var_loc_list_def var_loc_list
;
2779 /* Call argument location list. */
2780 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2781 rtx
GTY (()) call_arg_loc_note
;
2782 const char * GTY (()) label
;
2783 tree
GTY (()) block
;
2785 rtx
GTY (()) symbol_ref
;
2786 struct call_arg_loc_node
* GTY (()) next
;
2790 /* Table of decl location linked lists. */
2791 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2793 /* Head and tail of call_arg_loc chain. */
2794 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2795 static struct call_arg_loc_node
*call_arg_loc_last
;
2797 /* Number of call sites in the current function. */
2798 static int call_site_count
= -1;
2799 /* Number of tail call sites in the current function. */
2800 static int tail_call_site_count
= -1;
2802 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2804 static vec
<dw_die_ref
> block_map
;
2806 /* A cached location list. */
2807 struct GTY (()) cached_dw_loc_list_def
{
2808 /* The DECL_UID of the decl that this entry describes. */
2809 unsigned int decl_id
;
2811 /* The cached location list. */
2812 dw_loc_list_ref loc_list
;
2814 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2816 /* Table of cached location lists. */
2817 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2819 /* A pointer to the base of a list of references to DIE's that
2820 are uniquely identified by their tag, presence/absence of
2821 children DIE's, and list of attribute/value pairs. */
2822 static GTY((length ("abbrev_die_table_allocated")))
2823 dw_die_ref
*abbrev_die_table
;
2825 /* Number of elements currently allocated for abbrev_die_table. */
2826 static GTY(()) unsigned abbrev_die_table_allocated
;
2828 /* Number of elements in type_die_table currently in use. */
2829 static GTY(()) unsigned abbrev_die_table_in_use
;
2831 /* Size (in elements) of increments by which we may expand the
2832 abbrev_die_table. */
2833 #define ABBREV_DIE_TABLE_INCREMENT 256
2835 /* A global counter for generating labels for line number data. */
2836 static unsigned int line_info_label_num
;
2838 /* The current table to which we should emit line number information
2839 for the current function. This will be set up at the beginning of
2840 assembly for the function. */
2841 static dw_line_info_table
*cur_line_info_table
;
2843 /* The two default tables of line number info. */
2844 static GTY(()) dw_line_info_table
*text_section_line_info
;
2845 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2847 /* The set of all non-default tables of line number info. */
2848 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2850 /* A flag to tell pubnames/types export if there is an info section to
2852 static bool info_section_emitted
;
2854 /* A pointer to the base of a table that contains a list of publicly
2855 accessible names. */
2856 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2858 /* A pointer to the base of a table that contains a list of publicly
2859 accessible types. */
2860 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2862 /* A pointer to the base of a table that contains a list of macro
2863 defines/undefines (and file start/end markers). */
2864 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2866 /* True if .debug_macinfo or .debug_macros section is going to be
2868 #define have_macinfo \
2869 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2870 && !macinfo_table->is_empty ())
2872 /* Array of dies for which we should generate .debug_ranges info. */
2873 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2875 /* Number of elements currently allocated for ranges_table. */
2876 static GTY(()) unsigned ranges_table_allocated
;
2878 /* Number of elements in ranges_table currently in use. */
2879 static GTY(()) unsigned ranges_table_in_use
;
2881 /* Array of pairs of labels referenced in ranges_table. */
2882 static GTY ((length ("ranges_by_label_allocated")))
2883 dw_ranges_by_label_ref ranges_by_label
;
2885 /* Number of elements currently allocated for ranges_by_label. */
2886 static GTY(()) unsigned ranges_by_label_allocated
;
2888 /* Number of elements in ranges_by_label currently in use. */
2889 static GTY(()) unsigned ranges_by_label_in_use
;
2891 /* Size (in elements) of increments by which we may expand the
2893 #define RANGES_TABLE_INCREMENT 64
2895 /* Whether we have location lists that need outputting */
2896 static GTY(()) bool have_location_lists
;
2898 /* Unique label counter. */
2899 static GTY(()) unsigned int loclabel_num
;
2901 /* Unique label counter for point-of-call tables. */
2902 static GTY(()) unsigned int poc_label_num
;
2904 /* Record whether the function being analyzed contains inlined functions. */
2905 static int current_function_has_inlines
;
2907 /* The last file entry emitted by maybe_emit_file(). */
2908 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2910 /* Number of internal labels generated by gen_internal_sym(). */
2911 static GTY(()) int label_num
;
2913 /* Cached result of previous call to lookup_filename. */
2914 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2916 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2918 /* Instances of generic types for which we need to generate debug
2919 info that describe their generic parameters and arguments. That
2920 generation needs to happen once all types are properly laid out so
2921 we do it at the end of compilation. */
2922 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2924 /* Offset from the "steady-state frame pointer" to the frame base,
2925 within the current function. */
2926 static HOST_WIDE_INT frame_pointer_fb_offset
;
2927 static bool frame_pointer_fb_offset_valid
;
2929 static vec
<dw_die_ref
> base_types
;
2931 /* Forward declarations for functions defined in this file. */
2933 static int is_pseudo_reg (const_rtx
);
2934 static tree
type_main_variant (tree
);
2935 static int is_tagged_type (const_tree
);
2936 static const char *dwarf_tag_name (unsigned);
2937 static const char *dwarf_attr_name (unsigned);
2938 static const char *dwarf_form_name (unsigned);
2939 static tree
decl_ultimate_origin (const_tree
);
2940 static tree
decl_class_context (tree
);
2941 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2942 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2943 static inline unsigned int AT_index (dw_attr_ref
);
2944 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2945 static inline unsigned AT_flag (dw_attr_ref
);
2946 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2947 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2948 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2949 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2950 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2951 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2952 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2953 unsigned int, unsigned char *);
2954 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2955 static hashval_t
debug_str_do_hash (const void *);
2956 static int debug_str_eq (const void *, const void *);
2957 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2958 static inline const char *AT_string (dw_attr_ref
);
2959 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2960 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2961 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2962 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2963 static inline int AT_ref_external (dw_attr_ref
);
2964 static inline void set_AT_ref_external (dw_attr_ref
, int);
2965 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2966 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2967 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2968 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2970 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2971 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2972 static void remove_addr_table_entry (addr_table_entry
*);
2973 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
2974 static inline rtx
AT_addr (dw_attr_ref
);
2975 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2976 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2977 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2978 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2979 unsigned HOST_WIDE_INT
);
2980 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2981 unsigned long, bool);
2982 static inline const char *AT_lbl (dw_attr_ref
);
2983 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2984 static const char *get_AT_low_pc (dw_die_ref
);
2985 static const char *get_AT_hi_pc (dw_die_ref
);
2986 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2987 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2988 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2989 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2990 static bool is_cxx (void);
2991 static bool is_fortran (void);
2992 static bool is_ada (void);
2993 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2994 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2995 static void add_child_die (dw_die_ref
, dw_die_ref
);
2996 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2997 static dw_die_ref
lookup_type_die (tree
);
2998 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2999 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3000 static void equate_type_number_to_die (tree
, dw_die_ref
);
3001 static hashval_t
decl_die_table_hash (const void *);
3002 static int decl_die_table_eq (const void *, const void *);
3003 static dw_die_ref
lookup_decl_die (tree
);
3004 static hashval_t
common_block_die_table_hash (const void *);
3005 static int common_block_die_table_eq (const void *, const void *);
3006 static hashval_t
decl_loc_table_hash (const void *);
3007 static int decl_loc_table_eq (const void *, const void *);
3008 static var_loc_list
*lookup_decl_loc (const_tree
);
3009 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3010 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3011 static void print_spaces (FILE *);
3012 static void print_die (dw_die_ref
, FILE *);
3013 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3014 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3015 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3016 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3017 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3018 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3019 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3020 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3021 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3022 struct md5_ctx
*, int *);
3023 struct checksum_attributes
;
3024 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3025 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3026 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3027 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3028 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3029 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3030 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3031 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3032 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3033 static void compute_section_prefix (dw_die_ref
);
3034 static int is_type_die (dw_die_ref
);
3035 static int is_comdat_die (dw_die_ref
);
3036 static int is_symbol_die (dw_die_ref
);
3037 static inline bool is_template_instantiation (dw_die_ref
);
3038 static void assign_symbol_names (dw_die_ref
);
3039 static void break_out_includes (dw_die_ref
);
3040 static int is_declaration_die (dw_die_ref
);
3041 static int should_move_die_to_comdat (dw_die_ref
);
3042 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3043 static dw_die_ref
clone_die (dw_die_ref
);
3044 static dw_die_ref
clone_tree (dw_die_ref
);
3045 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3046 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3047 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3048 static dw_die_ref
generate_skeleton (dw_die_ref
);
3049 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3052 static void break_out_comdat_types (dw_die_ref
);
3053 static void copy_decls_for_unworthy_types (dw_die_ref
);
3055 static void add_sibling_attributes (dw_die_ref
);
3056 static void output_location_lists (dw_die_ref
);
3057 static int constant_size (unsigned HOST_WIDE_INT
);
3058 static unsigned long size_of_die (dw_die_ref
);
3059 static void calc_die_sizes (dw_die_ref
);
3060 static void calc_base_type_die_sizes (void);
3061 static void mark_dies (dw_die_ref
);
3062 static void unmark_dies (dw_die_ref
);
3063 static void unmark_all_dies (dw_die_ref
);
3064 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3065 static unsigned long size_of_aranges (void);
3066 static enum dwarf_form
value_format (dw_attr_ref
);
3067 static void output_value_format (dw_attr_ref
);
3068 static void output_abbrev_section (void);
3069 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3070 static void output_die_symbol (dw_die_ref
);
3071 static void output_die (dw_die_ref
);
3072 static void output_compilation_unit_header (void);
3073 static void output_comp_unit (dw_die_ref
, int);
3074 static void output_comdat_type_unit (comdat_type_node
*);
3075 static const char *dwarf2_name (tree
, int);
3076 static void add_pubname (tree
, dw_die_ref
);
3077 static void add_enumerator_pubname (const char *, dw_die_ref
);
3078 static void add_pubname_string (const char *, dw_die_ref
);
3079 static void add_pubtype (tree
, dw_die_ref
);
3080 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3081 static void output_aranges (unsigned long);
3082 static unsigned int add_ranges_num (int);
3083 static unsigned int add_ranges (const_tree
);
3084 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3086 static void output_ranges (void);
3087 static dw_line_info_table
*new_line_info_table (void);
3088 static void output_line_info (bool);
3089 static void output_file_names (void);
3090 static dw_die_ref
base_type_die (tree
);
3091 static int is_base_type (tree
);
3092 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3093 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3094 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3095 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3096 static int type_is_enum (const_tree
);
3097 static unsigned int dbx_reg_number (const_rtx
);
3098 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3099 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3100 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3101 enum var_init_status
);
3102 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3103 enum var_init_status
);
3104 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3105 enum var_init_status
);
3106 static int is_based_loc (const_rtx
);
3107 static int resolve_one_addr (rtx
*, void *);
3108 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3109 enum var_init_status
);
3110 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3111 enum var_init_status
);
3112 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3113 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3114 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3115 static tree
field_type (const_tree
);
3116 static unsigned int simple_type_align_in_bits (const_tree
);
3117 static unsigned int simple_decl_align_in_bits (const_tree
);
3118 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3119 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3120 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3122 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3123 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3124 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3125 static void insert_double (double_int
, unsigned char *);
3126 static void insert_float (const_rtx
, unsigned char *);
3127 static rtx
rtl_for_decl_location (tree
);
3128 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3129 enum dwarf_attribute
);
3130 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3131 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3132 static void add_name_attribute (dw_die_ref
, const char *);
3133 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3134 static void add_comp_dir_attribute (dw_die_ref
);
3135 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3136 static void add_subscript_info (dw_die_ref
, tree
, bool);
3137 static void add_byte_size_attribute (dw_die_ref
, tree
);
3138 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3139 static void add_bit_size_attribute (dw_die_ref
, tree
);
3140 static void add_prototyped_attribute (dw_die_ref
, tree
);
3141 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3142 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3143 static void add_src_coords_attributes (dw_die_ref
, tree
);
3144 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3145 static void push_decl_scope (tree
);
3146 static void pop_decl_scope (void);
3147 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3148 static inline int local_scope_p (dw_die_ref
);
3149 static inline int class_scope_p (dw_die_ref
);
3150 static inline int class_or_namespace_scope_p (dw_die_ref
);
3151 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3152 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3153 static const char *type_tag (const_tree
);
3154 static tree
member_declared_type (const_tree
);
3156 static const char *decl_start_label (tree
);
3158 static void gen_array_type_die (tree
, dw_die_ref
);
3159 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3161 static void gen_entry_point_die (tree
, dw_die_ref
);
3163 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3164 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3165 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3166 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3167 static void gen_formal_types_die (tree
, dw_die_ref
);
3168 static void gen_subprogram_die (tree
, dw_die_ref
);
3169 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3170 static void gen_const_die (tree
, dw_die_ref
);
3171 static void gen_label_die (tree
, dw_die_ref
);
3172 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3173 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3174 static void gen_field_die (tree
, dw_die_ref
);
3175 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3176 static dw_die_ref
gen_compile_unit_die (const char *);
3177 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3178 static void gen_member_die (tree
, dw_die_ref
);
3179 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3180 enum debug_info_usage
);
3181 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3182 static void gen_typedef_die (tree
, dw_die_ref
);
3183 static void gen_type_die (tree
, dw_die_ref
);
3184 static void gen_block_die (tree
, dw_die_ref
, int);
3185 static void decls_for_scope (tree
, dw_die_ref
, int);
3186 static inline int is_redundant_typedef (const_tree
);
3187 static bool is_naming_typedef_decl (const_tree
);
3188 static inline dw_die_ref
get_context_die (tree
);
3189 static void gen_namespace_die (tree
, dw_die_ref
);
3190 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3191 static dw_die_ref
force_decl_die (tree
);
3192 static dw_die_ref
force_type_die (tree
);
3193 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3194 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3195 static struct dwarf_file_data
* lookup_filename (const char *);
3196 static void retry_incomplete_types (void);
3197 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3198 static void gen_generic_params_dies (tree
);
3199 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3200 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3201 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3202 static int file_info_cmp (const void *, const void *);
3203 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3204 const char *, const char *);
3205 static void output_loc_list (dw_loc_list_ref
);
3206 static char *gen_internal_sym (const char *);
3207 static bool want_pubnames (void);
3209 static void prune_unmark_dies (dw_die_ref
);
3210 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3211 static void prune_unused_types_mark (dw_die_ref
, int);
3212 static void prune_unused_types_walk (dw_die_ref
);
3213 static void prune_unused_types_walk_attribs (dw_die_ref
);
3214 static void prune_unused_types_prune (dw_die_ref
);
3215 static void prune_unused_types (void);
3216 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3217 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3218 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3219 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3220 const char *, const char *);
3221 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3222 static void gen_remaining_tmpl_value_param_die_attribute (void);
3223 static bool generic_type_p (tree
);
3224 static void schedule_generic_params_dies_gen (tree t
);
3225 static void gen_scheduled_generic_parms_dies (void);
3227 static const char *comp_dir_string (void);
3229 static hashval_t
hash_loc_operands (dw_loc_descr_ref
, hashval_t
);
3231 /* enum for tracking thread-local variables whose address is really an offset
3232 relative to the TLS pointer, which will need link-time relocation, but will
3233 not need relocation by the DWARF consumer. */
3241 /* Return the operator to use for an address of a variable. For dtprel_true, we
3242 use DW_OP_const*. For regular variables, which need both link-time
3243 relocation and consumer-level relocation (e.g., to account for shared objects
3244 loaded at a random address), we use DW_OP_addr*. */
3246 static inline enum dwarf_location_atom
3247 dw_addr_op (enum dtprel_bool dtprel
)
3249 if (dtprel
== dtprel_true
)
3250 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3251 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3253 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3256 /* Return a pointer to a newly allocated address location description. If
3257 dwarf_split_debug_info is true, then record the address with the appropriate
3259 static inline dw_loc_descr_ref
3260 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3262 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3264 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3265 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3266 ref
->dtprel
= dtprel
;
3267 if (dwarf_split_debug_info
)
3268 ref
->dw_loc_oprnd1
.val_entry
3269 = add_addr_table_entry (addr
,
3270 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3272 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3277 /* Section names used to hold DWARF debugging information. */
3279 #ifndef DEBUG_INFO_SECTION
3280 #define DEBUG_INFO_SECTION ".debug_info"
3282 #ifndef DEBUG_DWO_INFO_SECTION
3283 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3285 #ifndef DEBUG_ABBREV_SECTION
3286 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3288 #ifndef DEBUG_DWO_ABBREV_SECTION
3289 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3291 #ifndef DEBUG_ARANGES_SECTION
3292 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3294 #ifndef DEBUG_ADDR_SECTION
3295 #define DEBUG_ADDR_SECTION ".debug_addr"
3297 #ifndef DEBUG_NORM_MACINFO_SECTION
3298 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3300 #ifndef DEBUG_DWO_MACINFO_SECTION
3301 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3303 #ifndef DEBUG_MACINFO_SECTION
3304 #define DEBUG_MACINFO_SECTION \
3305 (!dwarf_split_debug_info \
3306 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3308 #ifndef DEBUG_NORM_MACRO_SECTION
3309 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3311 #ifndef DEBUG_DWO_MACRO_SECTION
3312 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3314 #ifndef DEBUG_MACRO_SECTION
3315 #define DEBUG_MACRO_SECTION \
3316 (!dwarf_split_debug_info \
3317 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3319 #ifndef DEBUG_LINE_SECTION
3320 #define DEBUG_LINE_SECTION ".debug_line"
3322 #ifndef DEBUG_DWO_LINE_SECTION
3323 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3325 #ifndef DEBUG_LOC_SECTION
3326 #define DEBUG_LOC_SECTION ".debug_loc"
3328 #ifndef DEBUG_DWO_LOC_SECTION
3329 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3331 #ifndef DEBUG_PUBNAMES_SECTION
3332 #define DEBUG_PUBNAMES_SECTION \
3333 ((debug_generate_pub_sections == 2) \
3334 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3336 #ifndef DEBUG_PUBTYPES_SECTION
3337 #define DEBUG_PUBTYPES_SECTION \
3338 ((debug_generate_pub_sections == 2) \
3339 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3341 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3342 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3343 #ifndef DEBUG_STR_OFFSETS_SECTION
3344 #define DEBUG_STR_OFFSETS_SECTION \
3345 (!dwarf_split_debug_info \
3346 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3348 #ifndef DEBUG_STR_DWO_SECTION
3349 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3351 #ifndef DEBUG_STR_SECTION
3352 #define DEBUG_STR_SECTION ".debug_str"
3354 #ifndef DEBUG_RANGES_SECTION
3355 #define DEBUG_RANGES_SECTION ".debug_ranges"
3358 /* Standard ELF section names for compiled code and data. */
3359 #ifndef TEXT_SECTION_NAME
3360 #define TEXT_SECTION_NAME ".text"
3363 /* Section flags for .debug_macinfo/.debug_macro section. */
3364 #define DEBUG_MACRO_SECTION_FLAGS \
3365 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3367 /* Section flags for .debug_str section. */
3368 #define DEBUG_STR_SECTION_FLAGS \
3369 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3370 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3373 /* Section flags for .debug_str.dwo section. */
3374 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3376 /* Labels we insert at beginning sections we can reference instead of
3377 the section names themselves. */
3379 #ifndef TEXT_SECTION_LABEL
3380 #define TEXT_SECTION_LABEL "Ltext"
3382 #ifndef COLD_TEXT_SECTION_LABEL
3383 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3385 #ifndef DEBUG_LINE_SECTION_LABEL
3386 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3388 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3389 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3391 #ifndef DEBUG_INFO_SECTION_LABEL
3392 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3394 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3395 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3397 #ifndef DEBUG_ABBREV_SECTION_LABEL
3398 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3400 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3401 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3403 #ifndef DEBUG_ADDR_SECTION_LABEL
3404 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3406 #ifndef DEBUG_LOC_SECTION_LABEL
3407 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3409 #ifndef DEBUG_RANGES_SECTION_LABEL
3410 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3412 #ifndef DEBUG_MACINFO_SECTION_LABEL
3413 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3415 #ifndef DEBUG_MACRO_SECTION_LABEL
3416 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3418 #define SKELETON_COMP_DIE_ABBREV 1
3419 #define SKELETON_TYPE_DIE_ABBREV 2
3421 /* Definitions of defaults for formats and names of various special
3422 (artificial) labels which may be generated within this file (when the -g
3423 options is used and DWARF2_DEBUGGING_INFO is in effect.
3424 If necessary, these may be overridden from within the tm.h file, but
3425 typically, overriding these defaults is unnecessary. */
3427 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3428 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3429 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3430 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3431 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3432 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3433 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3434 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3435 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3436 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3437 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3438 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3439 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3440 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3442 #ifndef TEXT_END_LABEL
3443 #define TEXT_END_LABEL "Letext"
3445 #ifndef COLD_END_LABEL
3446 #define COLD_END_LABEL "Letext_cold"
3448 #ifndef BLOCK_BEGIN_LABEL
3449 #define BLOCK_BEGIN_LABEL "LBB"
3451 #ifndef BLOCK_END_LABEL
3452 #define BLOCK_END_LABEL "LBE"
3454 #ifndef LINE_CODE_LABEL
3455 #define LINE_CODE_LABEL "LM"
3459 /* Return the root of the DIE's built for the current compilation unit. */
3461 comp_unit_die (void)
3463 if (!single_comp_unit_die
)
3464 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3465 return single_comp_unit_die
;
3468 /* We allow a language front-end to designate a function that is to be
3469 called to "demangle" any name before it is put into a DIE. */
3471 static const char *(*demangle_name_func
) (const char *);
3474 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3476 demangle_name_func
= func
;
3479 /* Test if rtl node points to a pseudo register. */
3482 is_pseudo_reg (const_rtx rtl
)
3484 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3485 || (GET_CODE (rtl
) == SUBREG
3486 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3489 /* Return a reference to a type, with its const and volatile qualifiers
3493 type_main_variant (tree type
)
3495 type
= TYPE_MAIN_VARIANT (type
);
3497 /* ??? There really should be only one main variant among any group of
3498 variants of a given type (and all of the MAIN_VARIANT values for all
3499 members of the group should point to that one type) but sometimes the C
3500 front-end messes this up for array types, so we work around that bug
3502 if (TREE_CODE (type
) == ARRAY_TYPE
)
3503 while (type
!= TYPE_MAIN_VARIANT (type
))
3504 type
= TYPE_MAIN_VARIANT (type
);
3509 /* Return nonzero if the given type node represents a tagged type. */
3512 is_tagged_type (const_tree type
)
3514 enum tree_code code
= TREE_CODE (type
);
3516 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3517 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3520 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3523 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3525 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3528 /* Return die_offset of a DIE reference to a base type. */
3530 static unsigned long int
3531 get_base_type_offset (dw_die_ref ref
)
3533 if (ref
->die_offset
)
3534 return ref
->die_offset
;
3535 if (comp_unit_die ()->die_abbrev
)
3537 calc_base_type_die_sizes ();
3538 gcc_assert (ref
->die_offset
);
3540 return ref
->die_offset
;
3543 /* Return die_offset of a DIE reference other than base type. */
3545 static unsigned long int
3546 get_ref_die_offset (dw_die_ref ref
)
3548 gcc_assert (ref
->die_offset
);
3549 return ref
->die_offset
;
3552 /* Convert a DIE tag into its string name. */
3555 dwarf_tag_name (unsigned int tag
)
3557 const char *name
= get_DW_TAG_name (tag
);
3562 return "DW_TAG_<unknown>";
3565 /* Convert a DWARF attribute code into its string name. */
3568 dwarf_attr_name (unsigned int attr
)
3574 #if VMS_DEBUGGING_INFO
3575 case DW_AT_HP_prologue
:
3576 return "DW_AT_HP_prologue";
3578 case DW_AT_MIPS_loop_unroll_factor
:
3579 return "DW_AT_MIPS_loop_unroll_factor";
3582 #if VMS_DEBUGGING_INFO
3583 case DW_AT_HP_epilogue
:
3584 return "DW_AT_HP_epilogue";
3586 case DW_AT_MIPS_stride
:
3587 return "DW_AT_MIPS_stride";
3591 name
= get_DW_AT_name (attr
);
3596 return "DW_AT_<unknown>";
3599 /* Convert a DWARF value form code into its string name. */
3602 dwarf_form_name (unsigned int form
)
3604 const char *name
= get_DW_FORM_name (form
);
3609 return "DW_FORM_<unknown>";
3612 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3613 instance of an inlined instance of a decl which is local to an inline
3614 function, so we have to trace all of the way back through the origin chain
3615 to find out what sort of node actually served as the original seed for the
3619 decl_ultimate_origin (const_tree decl
)
3621 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3624 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3625 nodes in the function to point to themselves; ignore that if
3626 we're trying to output the abstract instance of this function. */
3627 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3630 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3631 most distant ancestor, this should never happen. */
3632 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3634 return DECL_ABSTRACT_ORIGIN (decl
);
3637 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3638 of a virtual function may refer to a base class, so we check the 'this'
3642 decl_class_context (tree decl
)
3644 tree context
= NULL_TREE
;
3646 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3647 context
= DECL_CONTEXT (decl
);
3649 context
= TYPE_MAIN_VARIANT
3650 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3652 if (context
&& !TYPE_P (context
))
3653 context
= NULL_TREE
;
3658 /* Add an attribute/value pair to a DIE. */
3661 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3663 /* Maybe this should be an assert? */
3667 vec_safe_reserve (die
->die_attr
, 1);
3668 vec_safe_push (die
->die_attr
, *attr
);
3671 static inline enum dw_val_class
3672 AT_class (dw_attr_ref a
)
3674 return a
->dw_attr_val
.val_class
;
3677 /* Return the index for any attribute that will be referenced with a
3678 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3679 are stored in dw_attr_val.v.val_str for reference counting
3682 static inline unsigned int
3683 AT_index (dw_attr_ref a
)
3685 if (AT_class (a
) == dw_val_class_str
)
3686 return a
->dw_attr_val
.v
.val_str
->index
;
3687 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3688 return a
->dw_attr_val
.val_entry
->index
;
3692 /* Add a flag value attribute to a DIE. */
3695 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3699 attr
.dw_attr
= attr_kind
;
3700 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3701 attr
.dw_attr_val
.val_entry
= NULL
;
3702 attr
.dw_attr_val
.v
.val_flag
= flag
;
3703 add_dwarf_attr (die
, &attr
);
3706 static inline unsigned
3707 AT_flag (dw_attr_ref a
)
3709 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3710 return a
->dw_attr_val
.v
.val_flag
;
3713 /* Add a signed integer attribute value to a DIE. */
3716 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3720 attr
.dw_attr
= attr_kind
;
3721 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3722 attr
.dw_attr_val
.val_entry
= NULL
;
3723 attr
.dw_attr_val
.v
.val_int
= int_val
;
3724 add_dwarf_attr (die
, &attr
);
3727 static inline HOST_WIDE_INT
3728 AT_int (dw_attr_ref a
)
3730 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3731 return a
->dw_attr_val
.v
.val_int
;
3734 /* Add an unsigned integer attribute value to a DIE. */
3737 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3738 unsigned HOST_WIDE_INT unsigned_val
)
3742 attr
.dw_attr
= attr_kind
;
3743 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3744 attr
.dw_attr_val
.val_entry
= NULL
;
3745 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3746 add_dwarf_attr (die
, &attr
);
3749 static inline unsigned HOST_WIDE_INT
3750 AT_unsigned (dw_attr_ref a
)
3752 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3753 return a
->dw_attr_val
.v
.val_unsigned
;
3756 /* Add an unsigned double integer attribute value to a DIE. */
3759 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3760 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3764 attr
.dw_attr
= attr_kind
;
3765 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3766 attr
.dw_attr_val
.val_entry
= NULL
;
3767 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3768 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3769 add_dwarf_attr (die
, &attr
);
3772 /* Add a floating point attribute value to a DIE and return it. */
3775 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3776 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3780 attr
.dw_attr
= attr_kind
;
3781 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3782 attr
.dw_attr_val
.val_entry
= NULL
;
3783 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3784 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3785 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3786 add_dwarf_attr (die
, &attr
);
3789 /* Add an 8-byte data attribute value to a DIE. */
3792 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3793 unsigned char data8
[8])
3797 attr
.dw_attr
= attr_kind
;
3798 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3799 attr
.dw_attr_val
.val_entry
= NULL
;
3800 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3801 add_dwarf_attr (die
, &attr
);
3804 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3805 dwarf_split_debug_info, address attributes in dies destined for the
3806 final executable have force_direct set to avoid using indexed
3810 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3816 lbl_id
= xstrdup (lbl_low
);
3817 attr
.dw_attr
= DW_AT_low_pc
;
3818 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3819 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3820 if (dwarf_split_debug_info
&& !force_direct
)
3821 attr
.dw_attr_val
.val_entry
3822 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3824 attr
.dw_attr_val
.val_entry
= NULL
;
3825 add_dwarf_attr (die
, &attr
);
3827 attr
.dw_attr
= DW_AT_high_pc
;
3828 if (dwarf_version
< 4)
3829 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3831 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3832 lbl_id
= xstrdup (lbl_high
);
3833 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3834 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3835 && dwarf_split_debug_info
&& !force_direct
)
3836 attr
.dw_attr_val
.val_entry
3837 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3839 attr
.dw_attr_val
.val_entry
= NULL
;
3840 add_dwarf_attr (die
, &attr
);
3843 /* Hash and equality functions for debug_str_hash. */
3846 debug_str_do_hash (const void *x
)
3848 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3852 debug_str_eq (const void *x1
, const void *x2
)
3854 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3855 (const char *)x2
) == 0;
3858 /* Add STR to the given string hash table. */
3860 static struct indirect_string_node
*
3861 find_AT_string_in_table (const char *str
, htab_t table
)
3863 struct indirect_string_node
*node
;
3866 slot
= htab_find_slot_with_hash (table
, str
,
3867 htab_hash_string (str
), INSERT
);
3870 node
= ggc_alloc_cleared_indirect_string_node ();
3871 node
->str
= ggc_strdup (str
);
3875 node
= (struct indirect_string_node
*) *slot
;
3881 /* Add STR to the indirect string hash table. */
3883 static struct indirect_string_node
*
3884 find_AT_string (const char *str
)
3886 if (! debug_str_hash
)
3887 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3888 debug_str_eq
, NULL
);
3890 return find_AT_string_in_table (str
, debug_str_hash
);
3893 /* Add a string attribute value to a DIE. */
3896 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3899 struct indirect_string_node
*node
;
3901 node
= find_AT_string (str
);
3903 attr
.dw_attr
= attr_kind
;
3904 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3905 attr
.dw_attr_val
.val_entry
= NULL
;
3906 attr
.dw_attr_val
.v
.val_str
= node
;
3907 add_dwarf_attr (die
, &attr
);
3910 static inline const char *
3911 AT_string (dw_attr_ref a
)
3913 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3914 return a
->dw_attr_val
.v
.val_str
->str
;
3917 /* Call this function directly to bypass AT_string_form's logic to put
3918 the string inline in the die. */
3921 set_indirect_string (struct indirect_string_node
*node
)
3924 /* Already indirect is a no op. */
3925 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3927 gcc_assert (node
->label
);
3930 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3931 ++dw2_string_counter
;
3932 node
->label
= xstrdup (label
);
3934 if (!dwarf_split_debug_info
)
3936 node
->form
= DW_FORM_strp
;
3937 node
->index
= NOT_INDEXED
;
3941 node
->form
= DW_FORM_GNU_str_index
;
3942 node
->index
= NO_INDEX_ASSIGNED
;
3946 /* Find out whether a string should be output inline in DIE
3947 or out-of-line in .debug_str section. */
3949 static enum dwarf_form
3950 find_string_form (struct indirect_string_node
*node
)
3957 len
= strlen (node
->str
) + 1;
3959 /* If the string is shorter or equal to the size of the reference, it is
3960 always better to put it inline. */
3961 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3962 return node
->form
= DW_FORM_string
;
3964 /* If we cannot expect the linker to merge strings in .debug_str
3965 section, only put it into .debug_str if it is worth even in this
3967 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3968 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3969 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3970 return node
->form
= DW_FORM_string
;
3972 set_indirect_string (node
);
3977 /* Find out whether the string referenced from the attribute should be
3978 output inline in DIE or out-of-line in .debug_str section. */
3980 static enum dwarf_form
3981 AT_string_form (dw_attr_ref a
)
3983 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3984 return find_string_form (a
->dw_attr_val
.v
.val_str
);
3987 /* Add a DIE reference attribute value to a DIE. */
3990 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3994 #ifdef ENABLE_CHECKING
3995 gcc_assert (targ_die
!= NULL
);
3997 /* With LTO we can end up trying to reference something we didn't create
3998 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3999 if (targ_die
== NULL
)
4003 attr
.dw_attr
= attr_kind
;
4004 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4005 attr
.dw_attr_val
.val_entry
= NULL
;
4006 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4007 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4008 add_dwarf_attr (die
, &attr
);
4011 /* Change DIE reference REF to point to NEW_DIE instead. */
4014 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4016 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4017 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4018 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4021 /* Add an AT_specification attribute to a DIE, and also make the back
4022 pointer from the specification to the definition. */
4025 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4027 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4028 gcc_assert (!targ_die
->die_definition
);
4029 targ_die
->die_definition
= die
;
4032 static inline dw_die_ref
4033 AT_ref (dw_attr_ref a
)
4035 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4036 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4040 AT_ref_external (dw_attr_ref a
)
4042 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4043 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4049 set_AT_ref_external (dw_attr_ref a
, int i
)
4051 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4052 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4055 /* Add an FDE reference attribute value to a DIE. */
4058 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4062 attr
.dw_attr
= attr_kind
;
4063 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4064 attr
.dw_attr_val
.val_entry
= NULL
;
4065 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4066 add_dwarf_attr (die
, &attr
);
4069 /* Add a location description attribute value to a DIE. */
4072 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4076 attr
.dw_attr
= attr_kind
;
4077 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4078 attr
.dw_attr_val
.val_entry
= NULL
;
4079 attr
.dw_attr_val
.v
.val_loc
= loc
;
4080 add_dwarf_attr (die
, &attr
);
4083 static inline dw_loc_descr_ref
4084 AT_loc (dw_attr_ref a
)
4086 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4087 return a
->dw_attr_val
.v
.val_loc
;
4091 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4095 attr
.dw_attr
= attr_kind
;
4096 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4097 attr
.dw_attr_val
.val_entry
= NULL
;
4098 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4099 add_dwarf_attr (die
, &attr
);
4100 have_location_lists
= true;
4103 static inline dw_loc_list_ref
4104 AT_loc_list (dw_attr_ref a
)
4106 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4107 return a
->dw_attr_val
.v
.val_loc_list
;
4110 static inline dw_loc_list_ref
*
4111 AT_loc_list_ptr (dw_attr_ref a
)
4113 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4114 return &a
->dw_attr_val
.v
.val_loc_list
;
4117 /* Table of entries into the .debug_addr section. */
4119 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4121 /* Hash an address_table_entry. */
4124 addr_table_entry_do_hash (const void *x
)
4126 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4130 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4131 case ate_kind_rtx_dtprel
:
4132 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4133 case ate_kind_label
:
4134 return htab_hash_string (a
->addr
.label
);
4140 /* Determine equality for two address_table_entries. */
4143 addr_table_entry_eq (const void *x1
, const void *x2
)
4145 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4146 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4148 if (a1
->kind
!= a2
->kind
)
4153 case ate_kind_rtx_dtprel
:
4154 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4155 case ate_kind_label
:
4156 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4162 /* Initialize an addr_table_entry. */
4165 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4171 case ate_kind_rtx_dtprel
:
4172 e
->addr
.rtl
= (rtx
) addr
;
4174 case ate_kind_label
:
4175 e
->addr
.label
= (char *) addr
;
4179 e
->index
= NO_INDEX_ASSIGNED
;
4182 /* Add attr to the address table entry to the table. Defer setting an
4183 index until output time. */
4185 static addr_table_entry
*
4186 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4188 addr_table_entry
*node
;
4189 addr_table_entry finder
;
4192 gcc_assert (dwarf_split_debug_info
);
4193 if (! addr_index_table
)
4194 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4195 addr_table_entry_eq
, NULL
);
4196 init_addr_table_entry (&finder
, kind
, addr
);
4197 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4199 if (*slot
== HTAB_EMPTY_ENTRY
)
4201 node
= ggc_alloc_cleared_addr_table_entry ();
4202 init_addr_table_entry (node
, kind
, addr
);
4206 node
= (addr_table_entry
*) *slot
;
4212 /* Remove an entry from the addr table by decrementing its refcount.
4213 Strictly, decrementing the refcount would be enough, but the
4214 assertion that the entry is actually in the table has found
4218 remove_addr_table_entry (addr_table_entry
*entry
)
4220 addr_table_entry
*node
;
4222 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4223 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4224 /* After an index is assigned, the table is frozen. */
4225 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4229 /* Given a location list, remove all addresses it refers to from the
4233 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4235 for (; descr
; descr
= descr
->dw_loc_next
)
4236 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4238 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4239 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4243 /* A helper function for dwarf2out_finish called through
4244 htab_traverse. Assign an addr_table_entry its index. All entries
4245 must be collected into the table when this function is called,
4246 because the indexing code relies on htab_traverse to traverse nodes
4247 in the same order for each run. */
4250 index_addr_table_entry (void **h
, void *v
)
4252 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4253 unsigned int *index
= (unsigned int *) v
;
4255 /* Don't index unreferenced nodes. */
4256 if (node
->refcount
== 0)
4259 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4260 node
->index
= *index
;
4266 /* Add an address constant attribute value to a DIE. When using
4267 dwarf_split_debug_info, address attributes in dies destined for the
4268 final executable should be direct references--setting the parameter
4269 force_direct ensures this behavior. */
4272 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4277 attr
.dw_attr
= attr_kind
;
4278 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4279 attr
.dw_attr_val
.v
.val_addr
= addr
;
4280 if (dwarf_split_debug_info
&& !force_direct
)
4281 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4283 attr
.dw_attr_val
.val_entry
= NULL
;
4284 add_dwarf_attr (die
, &attr
);
4287 /* Get the RTX from to an address DIE attribute. */
4290 AT_addr (dw_attr_ref a
)
4292 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4293 return a
->dw_attr_val
.v
.val_addr
;
4296 /* Add a file attribute value to a DIE. */
4299 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4300 struct dwarf_file_data
*fd
)
4304 attr
.dw_attr
= attr_kind
;
4305 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4306 attr
.dw_attr_val
.val_entry
= NULL
;
4307 attr
.dw_attr_val
.v
.val_file
= fd
;
4308 add_dwarf_attr (die
, &attr
);
4311 /* Get the dwarf_file_data from a file DIE attribute. */
4313 static inline struct dwarf_file_data
*
4314 AT_file (dw_attr_ref a
)
4316 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4317 return a
->dw_attr_val
.v
.val_file
;
4320 /* Add a vms delta attribute value to a DIE. */
4323 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4324 const char *lbl1
, const char *lbl2
)
4328 attr
.dw_attr
= attr_kind
;
4329 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4330 attr
.dw_attr_val
.val_entry
= NULL
;
4331 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4332 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4333 add_dwarf_attr (die
, &attr
);
4336 /* Add a label identifier attribute value to a DIE. */
4339 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4344 attr
.dw_attr
= attr_kind
;
4345 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4346 attr
.dw_attr_val
.val_entry
= NULL
;
4347 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4348 if (dwarf_split_debug_info
)
4349 attr
.dw_attr_val
.val_entry
4350 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4352 add_dwarf_attr (die
, &attr
);
4355 /* Add a section offset attribute value to a DIE, an offset into the
4356 debug_line section. */
4359 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4364 attr
.dw_attr
= attr_kind
;
4365 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4366 attr
.dw_attr_val
.val_entry
= NULL
;
4367 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4368 add_dwarf_attr (die
, &attr
);
4371 /* Add a section offset attribute value to a DIE, an offset into the
4372 debug_macinfo section. */
4375 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4380 attr
.dw_attr
= attr_kind
;
4381 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4382 attr
.dw_attr_val
.val_entry
= NULL
;
4383 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4384 add_dwarf_attr (die
, &attr
);
4387 /* Add an offset attribute value to a DIE. */
4390 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4391 unsigned HOST_WIDE_INT offset
)
4395 attr
.dw_attr
= attr_kind
;
4396 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4397 attr
.dw_attr_val
.val_entry
= NULL
;
4398 attr
.dw_attr_val
.v
.val_offset
= offset
;
4399 add_dwarf_attr (die
, &attr
);
4402 /* Add a range_list attribute value to a DIE. When using
4403 dwarf_split_debug_info, address attributes in dies destined for the
4404 final executable should be direct references--setting the parameter
4405 force_direct ensures this behavior. */
4407 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4408 #define RELOCATED_OFFSET (NULL)
4411 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4412 long unsigned int offset
, bool force_direct
)
4416 attr
.dw_attr
= attr_kind
;
4417 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4418 /* For the range_list attribute, use val_entry to store whether the
4419 offset should follow split-debug-info or normal semantics. This
4420 value is read in output_range_list_offset. */
4421 if (dwarf_split_debug_info
&& !force_direct
)
4422 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4424 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4425 attr
.dw_attr_val
.v
.val_offset
= offset
;
4426 add_dwarf_attr (die
, &attr
);
4429 /* Return the start label of a delta attribute. */
4431 static inline const char *
4432 AT_vms_delta1 (dw_attr_ref a
)
4434 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4435 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4438 /* Return the end label of a delta attribute. */
4440 static inline const char *
4441 AT_vms_delta2 (dw_attr_ref a
)
4443 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4444 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4447 static inline const char *
4448 AT_lbl (dw_attr_ref a
)
4450 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4451 || AT_class (a
) == dw_val_class_lineptr
4452 || AT_class (a
) == dw_val_class_macptr
4453 || AT_class (a
) == dw_val_class_high_pc
));
4454 return a
->dw_attr_val
.v
.val_lbl_id
;
4457 /* Get the attribute of type attr_kind. */
4460 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4464 dw_die_ref spec
= NULL
;
4469 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4470 if (a
->dw_attr
== attr_kind
)
4472 else if (a
->dw_attr
== DW_AT_specification
4473 || a
->dw_attr
== DW_AT_abstract_origin
)
4477 return get_AT (spec
, attr_kind
);
4482 /* Returns the parent of the declaration of DIE. */
4485 get_die_parent (dw_die_ref die
)
4492 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4493 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4496 return die
->die_parent
;
4499 /* Return the "low pc" attribute value, typically associated with a subprogram
4500 DIE. Return null if the "low pc" attribute is either not present, or if it
4501 cannot be represented as an assembler label identifier. */
4503 static inline const char *
4504 get_AT_low_pc (dw_die_ref die
)
4506 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4508 return a
? AT_lbl (a
) : NULL
;
4511 /* Return the "high pc" attribute value, typically associated with a subprogram
4512 DIE. Return null if the "high pc" attribute is either not present, or if it
4513 cannot be represented as an assembler label identifier. */
4515 static inline const char *
4516 get_AT_hi_pc (dw_die_ref die
)
4518 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4520 return a
? AT_lbl (a
) : NULL
;
4523 /* Return the value of the string attribute designated by ATTR_KIND, or
4524 NULL if it is not present. */
4526 static inline const char *
4527 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4529 dw_attr_ref a
= get_AT (die
, attr_kind
);
4531 return a
? AT_string (a
) : NULL
;
4534 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4535 if it is not present. */
4538 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4540 dw_attr_ref a
= get_AT (die
, attr_kind
);
4542 return a
? AT_flag (a
) : 0;
4545 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4546 if it is not present. */
4548 static inline unsigned
4549 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4551 dw_attr_ref a
= get_AT (die
, attr_kind
);
4553 return a
? AT_unsigned (a
) : 0;
4556 static inline dw_die_ref
4557 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4559 dw_attr_ref a
= get_AT (die
, attr_kind
);
4561 return a
? AT_ref (a
) : NULL
;
4564 static inline struct dwarf_file_data
*
4565 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4567 dw_attr_ref a
= get_AT (die
, attr_kind
);
4569 return a
? AT_file (a
) : NULL
;
4572 /* Return TRUE if the language is C++. */
4577 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4579 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4582 /* Return TRUE if the language is Java. */
4587 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4589 return lang
== DW_LANG_Java
;
4592 /* Return TRUE if the language is Fortran. */
4597 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4599 return (lang
== DW_LANG_Fortran77
4600 || lang
== DW_LANG_Fortran90
4601 || lang
== DW_LANG_Fortran95
);
4604 /* Return TRUE if the language is Ada. */
4609 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4611 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4614 /* Remove the specified attribute if present. */
4617 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4625 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4626 if (a
->dw_attr
== attr_kind
)
4628 if (AT_class (a
) == dw_val_class_str
)
4629 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4630 a
->dw_attr_val
.v
.val_str
->refcount
--;
4632 /* vec::ordered_remove should help reduce the number of abbrevs
4634 die
->die_attr
->ordered_remove (ix
);
4639 /* Remove CHILD from its parent. PREV must have the property that
4640 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4643 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4645 gcc_assert (child
->die_parent
== prev
->die_parent
);
4646 gcc_assert (prev
->die_sib
== child
);
4649 gcc_assert (child
->die_parent
->die_child
== child
);
4653 prev
->die_sib
= child
->die_sib
;
4654 if (child
->die_parent
->die_child
== child
)
4655 child
->die_parent
->die_child
= prev
;
4658 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4659 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4662 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4664 dw_die_ref parent
= old_child
->die_parent
;
4666 gcc_assert (parent
== prev
->die_parent
);
4667 gcc_assert (prev
->die_sib
== old_child
);
4669 new_child
->die_parent
= parent
;
4670 if (prev
== old_child
)
4672 gcc_assert (parent
->die_child
== old_child
);
4673 new_child
->die_sib
= new_child
;
4677 prev
->die_sib
= new_child
;
4678 new_child
->die_sib
= old_child
->die_sib
;
4680 if (old_child
->die_parent
->die_child
== old_child
)
4681 old_child
->die_parent
->die_child
= new_child
;
4684 /* Move all children from OLD_PARENT to NEW_PARENT. */
4687 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4690 new_parent
->die_child
= old_parent
->die_child
;
4691 old_parent
->die_child
= NULL
;
4692 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4695 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4699 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4705 dw_die_ref prev
= c
;
4707 while (c
->die_tag
== tag
)
4709 remove_child_with_prev (c
, prev
);
4710 /* Might have removed every child. */
4711 if (c
== c
->die_sib
)
4715 } while (c
!= die
->die_child
);
4718 /* Add a CHILD_DIE as the last child of DIE. */
4721 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4723 /* FIXME this should probably be an assert. */
4724 if (! die
|| ! child_die
)
4726 gcc_assert (die
!= child_die
);
4728 child_die
->die_parent
= die
;
4731 child_die
->die_sib
= die
->die_child
->die_sib
;
4732 die
->die_child
->die_sib
= child_die
;
4735 child_die
->die_sib
= child_die
;
4736 die
->die_child
= child_die
;
4739 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4740 is the specification, to the end of PARENT's list of children.
4741 This is done by removing and re-adding it. */
4744 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4748 /* We want the declaration DIE from inside the class, not the
4749 specification DIE at toplevel. */
4750 if (child
->die_parent
!= parent
)
4752 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4758 gcc_assert (child
->die_parent
== parent
4759 || (child
->die_parent
4760 == get_AT_ref (parent
, DW_AT_specification
)));
4762 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4763 if (p
->die_sib
== child
)
4765 remove_child_with_prev (child
, p
);
4769 add_child_die (parent
, child
);
4772 /* Return a pointer to a newly created DIE node. */
4774 static inline dw_die_ref
4775 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4777 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4779 die
->die_tag
= tag_value
;
4781 if (parent_die
!= NULL
)
4782 add_child_die (parent_die
, die
);
4785 limbo_die_node
*limbo_node
;
4787 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4788 limbo_node
->die
= die
;
4789 limbo_node
->created_for
= t
;
4790 limbo_node
->next
= limbo_die_list
;
4791 limbo_die_list
= limbo_node
;
4797 /* Return the DIE associated with the given type specifier. */
4799 static inline dw_die_ref
4800 lookup_type_die (tree type
)
4802 return TYPE_SYMTAB_DIE (type
);
4805 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4806 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4807 anonymous type instead the one of the naming typedef. */
4809 static inline dw_die_ref
4810 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4813 && TREE_CODE (type
) == RECORD_TYPE
4815 && type_die
->die_tag
== DW_TAG_typedef
4816 && is_naming_typedef_decl (TYPE_NAME (type
)))
4817 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4821 /* Like lookup_type_die, but if type is an anonymous type named by a
4822 typedef[1], return the DIE of the anonymous type instead the one of
4823 the naming typedef. This is because in gen_typedef_die, we did
4824 equate the anonymous struct named by the typedef with the DIE of
4825 the naming typedef. So by default, lookup_type_die on an anonymous
4826 struct yields the DIE of the naming typedef.
4828 [1]: Read the comment of is_naming_typedef_decl to learn about what
4829 a naming typedef is. */
4831 static inline dw_die_ref
4832 lookup_type_die_strip_naming_typedef (tree type
)
4834 dw_die_ref die
= lookup_type_die (type
);
4835 return strip_naming_typedef (type
, die
);
4838 /* Equate a DIE to a given type specifier. */
4841 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4843 TYPE_SYMTAB_DIE (type
) = type_die
;
4846 /* Returns a hash value for X (which really is a die_struct). */
4849 decl_die_table_hash (const void *x
)
4851 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4854 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4857 decl_die_table_eq (const void *x
, const void *y
)
4859 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4862 /* Return the DIE associated with a given declaration. */
4864 static inline dw_die_ref
4865 lookup_decl_die (tree decl
)
4867 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4870 /* Returns a hash value for X (which really is a var_loc_list). */
4873 decl_loc_table_hash (const void *x
)
4875 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4878 /* Return nonzero if decl_id of var_loc_list X is the same as
4882 decl_loc_table_eq (const void *x
, const void *y
)
4884 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4887 /* Return the var_loc list associated with a given declaration. */
4889 static inline var_loc_list
*
4890 lookup_decl_loc (const_tree decl
)
4892 if (!decl_loc_table
)
4894 return (var_loc_list
*)
4895 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4898 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4901 cached_dw_loc_list_table_hash (const void *x
)
4903 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4906 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4910 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4912 return (((const cached_dw_loc_list
*) x
)->decl_id
4913 == DECL_UID ((const_tree
) y
));
4916 /* Equate a DIE to a particular declaration. */
4919 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4921 unsigned int decl_id
= DECL_UID (decl
);
4924 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4926 decl_die
->decl_id
= decl_id
;
4929 /* Return how many bits covers PIECE EXPR_LIST. */
4932 decl_piece_bitsize (rtx piece
)
4934 int ret
= (int) GET_MODE (piece
);
4937 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4938 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4939 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4942 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4945 decl_piece_varloc_ptr (rtx piece
)
4947 if ((int) GET_MODE (piece
))
4948 return &XEXP (piece
, 0);
4950 return &XEXP (XEXP (piece
, 0), 1);
4953 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4954 Next is the chain of following piece nodes. */
4957 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4959 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4960 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4962 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4967 /* Return rtx that should be stored into loc field for
4968 LOC_NOTE and BITPOS/BITSIZE. */
4971 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4972 HOST_WIDE_INT bitsize
)
4976 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4978 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4983 /* This function either modifies location piece list *DEST in
4984 place (if SRC and INNER is NULL), or copies location piece list
4985 *SRC to *DEST while modifying it. Location BITPOS is modified
4986 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4987 not copied and if needed some padding around it is added.
4988 When modifying in place, DEST should point to EXPR_LIST where
4989 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4990 to the start of the whole list and INNER points to the EXPR_LIST
4991 where earlier pieces cover PIECE_BITPOS bits. */
4994 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4995 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4996 HOST_WIDE_INT bitsize
, rtx loc_note
)
4999 bool copy
= inner
!= NULL
;
5003 /* First copy all nodes preceding the current bitpos. */
5004 while (src
!= inner
)
5006 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5007 decl_piece_bitsize (*src
), NULL_RTX
);
5008 dest
= &XEXP (*dest
, 1);
5009 src
= &XEXP (*src
, 1);
5012 /* Add padding if needed. */
5013 if (bitpos
!= piece_bitpos
)
5015 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5016 copy
? NULL_RTX
: *dest
);
5017 dest
= &XEXP (*dest
, 1);
5019 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5022 /* A piece with correct bitpos and bitsize already exist,
5023 just update the location for it and return. */
5024 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5027 /* Add the piece that changed. */
5028 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5029 dest
= &XEXP (*dest
, 1);
5030 /* Skip over pieces that overlap it. */
5031 diff
= bitpos
- piece_bitpos
+ bitsize
;
5034 while (diff
> 0 && *src
)
5037 diff
-= decl_piece_bitsize (piece
);
5039 src
= &XEXP (piece
, 1);
5042 *src
= XEXP (piece
, 1);
5043 free_EXPR_LIST_node (piece
);
5046 /* Add padding if needed. */
5047 if (diff
< 0 && *src
)
5051 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5052 dest
= &XEXP (*dest
, 1);
5056 /* Finally copy all nodes following it. */
5059 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5060 decl_piece_bitsize (*src
), NULL_RTX
);
5061 dest
= &XEXP (*dest
, 1);
5062 src
= &XEXP (*src
, 1);
5066 /* Add a variable location node to the linked list for DECL. */
5068 static struct var_loc_node
*
5069 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5071 unsigned int decl_id
;
5074 struct var_loc_node
*loc
= NULL
;
5075 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5077 if (TREE_CODE (decl
) == VAR_DECL
5078 && DECL_HAS_DEBUG_EXPR_P (decl
))
5080 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5081 if (handled_component_p (realdecl
)
5082 || (TREE_CODE (realdecl
) == MEM_REF
5083 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5085 HOST_WIDE_INT maxsize
;
5088 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5089 if (!DECL_P (innerdecl
)
5090 || DECL_IGNORED_P (innerdecl
)
5091 || TREE_STATIC (innerdecl
)
5093 || bitpos
+ bitsize
> 256
5094 || bitsize
!= maxsize
)
5100 decl_id
= DECL_UID (decl
);
5101 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5104 temp
= ggc_alloc_cleared_var_loc_list ();
5105 temp
->decl_id
= decl_id
;
5109 temp
= (var_loc_list
*) *slot
;
5111 /* For PARM_DECLs try to keep around the original incoming value,
5112 even if that means we'll emit a zero-range .debug_loc entry. */
5114 && temp
->first
== temp
->last
5115 && TREE_CODE (decl
) == PARM_DECL
5116 && NOTE_P (temp
->first
->loc
)
5117 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5118 && DECL_INCOMING_RTL (decl
)
5119 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5120 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5121 == GET_CODE (DECL_INCOMING_RTL (decl
))
5122 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5124 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5125 NOTE_VAR_LOCATION_LOC (loc_note
))
5126 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5127 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5129 loc
= ggc_alloc_cleared_var_loc_node ();
5130 temp
->first
->next
= loc
;
5132 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5134 else if (temp
->last
)
5136 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5137 rtx
*piece_loc
= NULL
, last_loc_note
;
5138 int piece_bitpos
= 0;
5142 gcc_assert (last
->next
== NULL
);
5144 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5146 piece_loc
= &last
->loc
;
5149 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5150 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5152 piece_bitpos
+= cur_bitsize
;
5153 piece_loc
= &XEXP (*piece_loc
, 1);
5157 /* TEMP->LAST here is either pointer to the last but one or
5158 last element in the chained list, LAST is pointer to the
5160 if (label
&& strcmp (last
->label
, label
) == 0)
5162 /* For SRA optimized variables if there weren't any real
5163 insns since last note, just modify the last node. */
5164 if (piece_loc
!= NULL
)
5166 adjust_piece_list (piece_loc
, NULL
, NULL
,
5167 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5170 /* If the last note doesn't cover any instructions, remove it. */
5171 if (temp
->last
!= last
)
5173 temp
->last
->next
= NULL
;
5176 gcc_assert (strcmp (last
->label
, label
) != 0);
5180 gcc_assert (temp
->first
== temp
->last
5181 || (temp
->first
->next
== temp
->last
5182 && TREE_CODE (decl
) == PARM_DECL
));
5183 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5184 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5188 if (bitsize
== -1 && NOTE_P (last
->loc
))
5189 last_loc_note
= last
->loc
;
5190 else if (piece_loc
!= NULL
5191 && *piece_loc
!= NULL_RTX
5192 && piece_bitpos
== bitpos
5193 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5194 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5196 last_loc_note
= NULL_RTX
;
5197 /* If the current location is the same as the end of the list,
5198 and either both or neither of the locations is uninitialized,
5199 we have nothing to do. */
5200 if (last_loc_note
== NULL_RTX
5201 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5202 NOTE_VAR_LOCATION_LOC (loc_note
)))
5203 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5204 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5205 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5206 == VAR_INIT_STATUS_UNINITIALIZED
)
5207 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5208 == VAR_INIT_STATUS_UNINITIALIZED
))))
5210 /* Add LOC to the end of list and update LAST. If the last
5211 element of the list has been removed above, reuse its
5212 memory for the new node, otherwise allocate a new one. */
5216 memset (loc
, '\0', sizeof (*loc
));
5219 loc
= ggc_alloc_cleared_var_loc_node ();
5220 if (bitsize
== -1 || piece_loc
== NULL
)
5221 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5223 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5224 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5226 /* Ensure TEMP->LAST will point either to the new last but one
5227 element of the chain, or to the last element in it. */
5228 if (last
!= temp
->last
)
5236 loc
= ggc_alloc_cleared_var_loc_node ();
5239 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5244 /* Keep track of the number of spaces used to indent the
5245 output of the debugging routines that print the structure of
5246 the DIE internal representation. */
5247 static int print_indent
;
5249 /* Indent the line the number of spaces given by print_indent. */
5252 print_spaces (FILE *outfile
)
5254 fprintf (outfile
, "%*s", print_indent
, "");
5257 /* Print a type signature in hex. */
5260 print_signature (FILE *outfile
, char *sig
)
5264 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5265 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5268 /* Print the information associated with a given DIE, and its children.
5269 This routine is a debugging aid only. */
5272 print_die (dw_die_ref die
, FILE *outfile
)
5278 print_spaces (outfile
);
5279 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5280 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5282 print_spaces (outfile
);
5283 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5284 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5285 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5287 if (die
->comdat_type_p
)
5289 print_spaces (outfile
);
5290 fprintf (outfile
, " signature: ");
5291 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5292 fprintf (outfile
, "\n");
5295 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5297 print_spaces (outfile
);
5298 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5300 switch (AT_class (a
))
5302 case dw_val_class_addr
:
5303 fprintf (outfile
, "address");
5305 case dw_val_class_offset
:
5306 fprintf (outfile
, "offset");
5308 case dw_val_class_loc
:
5309 fprintf (outfile
, "location descriptor");
5311 case dw_val_class_loc_list
:
5312 fprintf (outfile
, "location list -> label:%s",
5313 AT_loc_list (a
)->ll_symbol
);
5315 case dw_val_class_range_list
:
5316 fprintf (outfile
, "range list");
5318 case dw_val_class_const
:
5319 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5321 case dw_val_class_unsigned_const
:
5322 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5324 case dw_val_class_const_double
:
5325 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5326 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5327 a
->dw_attr_val
.v
.val_double
.high
,
5328 a
->dw_attr_val
.v
.val_double
.low
);
5330 case dw_val_class_vec
:
5331 fprintf (outfile
, "floating-point or vector constant");
5333 case dw_val_class_flag
:
5334 fprintf (outfile
, "%u", AT_flag (a
));
5336 case dw_val_class_die_ref
:
5337 if (AT_ref (a
) != NULL
)
5339 if (AT_ref (a
)->comdat_type_p
)
5341 fprintf (outfile
, "die -> signature: ");
5342 print_signature (outfile
,
5343 AT_ref (a
)->die_id
.die_type_node
->signature
);
5345 else if (AT_ref (a
)->die_id
.die_symbol
)
5346 fprintf (outfile
, "die -> label: %s",
5347 AT_ref (a
)->die_id
.die_symbol
);
5349 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5350 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5353 fprintf (outfile
, "die -> <null>");
5355 case dw_val_class_vms_delta
:
5356 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5357 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5359 case dw_val_class_lbl_id
:
5360 case dw_val_class_lineptr
:
5361 case dw_val_class_macptr
:
5362 case dw_val_class_high_pc
:
5363 fprintf (outfile
, "label: %s", AT_lbl (a
));
5365 case dw_val_class_str
:
5366 if (AT_string (a
) != NULL
)
5367 fprintf (outfile
, "\"%s\"", AT_string (a
));
5369 fprintf (outfile
, "<null>");
5371 case dw_val_class_file
:
5372 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5373 AT_file (a
)->emitted_number
);
5375 case dw_val_class_data8
:
5379 for (i
= 0; i
< 8; i
++)
5380 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5387 fprintf (outfile
, "\n");
5390 if (die
->die_child
!= NULL
)
5393 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5396 if (print_indent
== 0)
5397 fprintf (outfile
, "\n");
5400 /* Print the information collected for a given DIE. */
5403 debug_dwarf_die (dw_die_ref die
)
5405 print_die (die
, stderr
);
5409 debug (die_struct
&ref
)
5411 print_die (&ref
, stderr
);
5415 debug (die_struct
*ptr
)
5420 fprintf (stderr
, "<nil>\n");
5424 /* Print all DWARF information collected for the compilation unit.
5425 This routine is a debugging aid only. */
5431 print_die (comp_unit_die (), stderr
);
5434 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5435 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5436 DIE that marks the start of the DIEs for this include file. */
5439 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5441 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5442 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5444 new_unit
->die_sib
= old_unit
;
5448 /* Close an include-file CU and reopen the enclosing one. */
5451 pop_compile_unit (dw_die_ref old_unit
)
5453 dw_die_ref new_unit
= old_unit
->die_sib
;
5455 old_unit
->die_sib
= NULL
;
5459 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5460 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5461 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5463 /* Calculate the checksum of a location expression. */
5466 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5471 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5473 hash
= hash_loc_operands (loc
, hash
);
5477 /* Calculate the checksum of an attribute. */
5480 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5482 dw_loc_descr_ref loc
;
5485 CHECKSUM (at
->dw_attr
);
5487 /* We don't care that this was compiled with a different compiler
5488 snapshot; if the output is the same, that's what matters. */
5489 if (at
->dw_attr
== DW_AT_producer
)
5492 switch (AT_class (at
))
5494 case dw_val_class_const
:
5495 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5497 case dw_val_class_unsigned_const
:
5498 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5500 case dw_val_class_const_double
:
5501 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5503 case dw_val_class_vec
:
5504 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5505 (at
->dw_attr_val
.v
.val_vec
.length
5506 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5508 case dw_val_class_flag
:
5509 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5511 case dw_val_class_str
:
5512 CHECKSUM_STRING (AT_string (at
));
5515 case dw_val_class_addr
:
5517 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5518 CHECKSUM_STRING (XSTR (r
, 0));
5521 case dw_val_class_offset
:
5522 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5525 case dw_val_class_loc
:
5526 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5527 loc_checksum (loc
, ctx
);
5530 case dw_val_class_die_ref
:
5531 die_checksum (AT_ref (at
), ctx
, mark
);
5534 case dw_val_class_fde_ref
:
5535 case dw_val_class_vms_delta
:
5536 case dw_val_class_lbl_id
:
5537 case dw_val_class_lineptr
:
5538 case dw_val_class_macptr
:
5539 case dw_val_class_high_pc
:
5542 case dw_val_class_file
:
5543 CHECKSUM_STRING (AT_file (at
)->filename
);
5546 case dw_val_class_data8
:
5547 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5555 /* Calculate the checksum of a DIE. */
5558 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5564 /* To avoid infinite recursion. */
5567 CHECKSUM (die
->die_mark
);
5570 die
->die_mark
= ++(*mark
);
5572 CHECKSUM (die
->die_tag
);
5574 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5575 attr_checksum (a
, ctx
, mark
);
5577 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5581 #undef CHECKSUM_BLOCK
5582 #undef CHECKSUM_STRING
5584 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5585 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5586 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5587 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5588 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5589 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5590 #define CHECKSUM_ATTR(FOO) \
5591 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5593 /* Calculate the checksum of a number in signed LEB128 format. */
5596 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5603 byte
= (value
& 0x7f);
5605 more
= !((value
== 0 && (byte
& 0x40) == 0)
5606 || (value
== -1 && (byte
& 0x40) != 0));
5615 /* Calculate the checksum of a number in unsigned LEB128 format. */
5618 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5622 unsigned char byte
= (value
& 0x7f);
5625 /* More bytes to follow. */
5633 /* Checksum the context of the DIE. This adds the names of any
5634 surrounding namespaces or structures to the checksum. */
5637 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5641 int tag
= die
->die_tag
;
5643 if (tag
!= DW_TAG_namespace
5644 && tag
!= DW_TAG_structure_type
5645 && tag
!= DW_TAG_class_type
)
5648 name
= get_AT_string (die
, DW_AT_name
);
5650 spec
= get_AT_ref (die
, DW_AT_specification
);
5654 if (die
->die_parent
!= NULL
)
5655 checksum_die_context (die
->die_parent
, ctx
);
5657 CHECKSUM_ULEB128 ('C');
5658 CHECKSUM_ULEB128 (tag
);
5660 CHECKSUM_STRING (name
);
5663 /* Calculate the checksum of a location expression. */
5666 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5668 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5669 were emitted as a DW_FORM_sdata instead of a location expression. */
5670 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5672 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5673 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5677 /* Otherwise, just checksum the raw location expression. */
5682 CHECKSUM_ULEB128 (loc
->dtprel
);
5683 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5684 hash
= hash_loc_operands (loc
, hash
);
5686 loc
= loc
->dw_loc_next
;
5690 /* Calculate the checksum of an attribute. */
5693 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5694 struct md5_ctx
*ctx
, int *mark
)
5696 dw_loc_descr_ref loc
;
5699 if (AT_class (at
) == dw_val_class_die_ref
)
5701 dw_die_ref target_die
= AT_ref (at
);
5703 /* For pointer and reference types, we checksum only the (qualified)
5704 name of the target type (if there is a name). For friend entries,
5705 we checksum only the (qualified) name of the target type or function.
5706 This allows the checksum to remain the same whether the target type
5707 is complete or not. */
5708 if ((at
->dw_attr
== DW_AT_type
5709 && (tag
== DW_TAG_pointer_type
5710 || tag
== DW_TAG_reference_type
5711 || tag
== DW_TAG_rvalue_reference_type
5712 || tag
== DW_TAG_ptr_to_member_type
))
5713 || (at
->dw_attr
== DW_AT_friend
5714 && tag
== DW_TAG_friend
))
5716 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5718 if (name_attr
!= NULL
)
5720 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5724 CHECKSUM_ULEB128 ('N');
5725 CHECKSUM_ULEB128 (at
->dw_attr
);
5726 if (decl
->die_parent
!= NULL
)
5727 checksum_die_context (decl
->die_parent
, ctx
);
5728 CHECKSUM_ULEB128 ('E');
5729 CHECKSUM_STRING (AT_string (name_attr
));
5734 /* For all other references to another DIE, we check to see if the
5735 target DIE has already been visited. If it has, we emit a
5736 backward reference; if not, we descend recursively. */
5737 if (target_die
->die_mark
> 0)
5739 CHECKSUM_ULEB128 ('R');
5740 CHECKSUM_ULEB128 (at
->dw_attr
);
5741 CHECKSUM_ULEB128 (target_die
->die_mark
);
5745 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5749 target_die
->die_mark
= ++(*mark
);
5750 CHECKSUM_ULEB128 ('T');
5751 CHECKSUM_ULEB128 (at
->dw_attr
);
5752 if (decl
->die_parent
!= NULL
)
5753 checksum_die_context (decl
->die_parent
, ctx
);
5754 die_checksum_ordered (target_die
, ctx
, mark
);
5759 CHECKSUM_ULEB128 ('A');
5760 CHECKSUM_ULEB128 (at
->dw_attr
);
5762 switch (AT_class (at
))
5764 case dw_val_class_const
:
5765 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5766 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5769 case dw_val_class_unsigned_const
:
5770 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5771 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5774 case dw_val_class_const_double
:
5775 CHECKSUM_ULEB128 (DW_FORM_block
);
5776 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5777 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5780 case dw_val_class_vec
:
5781 CHECKSUM_ULEB128 (DW_FORM_block
);
5782 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
5783 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
5784 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5785 (at
->dw_attr_val
.v
.val_vec
.length
5786 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5789 case dw_val_class_flag
:
5790 CHECKSUM_ULEB128 (DW_FORM_flag
);
5791 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5794 case dw_val_class_str
:
5795 CHECKSUM_ULEB128 (DW_FORM_string
);
5796 CHECKSUM_STRING (AT_string (at
));
5799 case dw_val_class_addr
:
5801 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5802 CHECKSUM_ULEB128 (DW_FORM_string
);
5803 CHECKSUM_STRING (XSTR (r
, 0));
5806 case dw_val_class_offset
:
5807 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5808 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5811 case dw_val_class_loc
:
5812 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5813 loc_checksum_ordered (loc
, ctx
);
5816 case dw_val_class_fde_ref
:
5817 case dw_val_class_lbl_id
:
5818 case dw_val_class_lineptr
:
5819 case dw_val_class_macptr
:
5820 case dw_val_class_high_pc
:
5823 case dw_val_class_file
:
5824 CHECKSUM_ULEB128 (DW_FORM_string
);
5825 CHECKSUM_STRING (AT_file (at
)->filename
);
5828 case dw_val_class_data8
:
5829 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5837 struct checksum_attributes
5839 dw_attr_ref at_name
;
5840 dw_attr_ref at_type
;
5841 dw_attr_ref at_friend
;
5842 dw_attr_ref at_accessibility
;
5843 dw_attr_ref at_address_class
;
5844 dw_attr_ref at_allocated
;
5845 dw_attr_ref at_artificial
;
5846 dw_attr_ref at_associated
;
5847 dw_attr_ref at_binary_scale
;
5848 dw_attr_ref at_bit_offset
;
5849 dw_attr_ref at_bit_size
;
5850 dw_attr_ref at_bit_stride
;
5851 dw_attr_ref at_byte_size
;
5852 dw_attr_ref at_byte_stride
;
5853 dw_attr_ref at_const_value
;
5854 dw_attr_ref at_containing_type
;
5855 dw_attr_ref at_count
;
5856 dw_attr_ref at_data_location
;
5857 dw_attr_ref at_data_member_location
;
5858 dw_attr_ref at_decimal_scale
;
5859 dw_attr_ref at_decimal_sign
;
5860 dw_attr_ref at_default_value
;
5861 dw_attr_ref at_digit_count
;
5862 dw_attr_ref at_discr
;
5863 dw_attr_ref at_discr_list
;
5864 dw_attr_ref at_discr_value
;
5865 dw_attr_ref at_encoding
;
5866 dw_attr_ref at_endianity
;
5867 dw_attr_ref at_explicit
;
5868 dw_attr_ref at_is_optional
;
5869 dw_attr_ref at_location
;
5870 dw_attr_ref at_lower_bound
;
5871 dw_attr_ref at_mutable
;
5872 dw_attr_ref at_ordering
;
5873 dw_attr_ref at_picture_string
;
5874 dw_attr_ref at_prototyped
;
5875 dw_attr_ref at_small
;
5876 dw_attr_ref at_segment
;
5877 dw_attr_ref at_string_length
;
5878 dw_attr_ref at_threads_scaled
;
5879 dw_attr_ref at_upper_bound
;
5880 dw_attr_ref at_use_location
;
5881 dw_attr_ref at_use_UTF8
;
5882 dw_attr_ref at_variable_parameter
;
5883 dw_attr_ref at_virtuality
;
5884 dw_attr_ref at_visibility
;
5885 dw_attr_ref at_vtable_elem_location
;
5888 /* Collect the attributes that we will want to use for the checksum. */
5891 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5896 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5907 attrs
->at_friend
= a
;
5909 case DW_AT_accessibility
:
5910 attrs
->at_accessibility
= a
;
5912 case DW_AT_address_class
:
5913 attrs
->at_address_class
= a
;
5915 case DW_AT_allocated
:
5916 attrs
->at_allocated
= a
;
5918 case DW_AT_artificial
:
5919 attrs
->at_artificial
= a
;
5921 case DW_AT_associated
:
5922 attrs
->at_associated
= a
;
5924 case DW_AT_binary_scale
:
5925 attrs
->at_binary_scale
= a
;
5927 case DW_AT_bit_offset
:
5928 attrs
->at_bit_offset
= a
;
5930 case DW_AT_bit_size
:
5931 attrs
->at_bit_size
= a
;
5933 case DW_AT_bit_stride
:
5934 attrs
->at_bit_stride
= a
;
5936 case DW_AT_byte_size
:
5937 attrs
->at_byte_size
= a
;
5939 case DW_AT_byte_stride
:
5940 attrs
->at_byte_stride
= a
;
5942 case DW_AT_const_value
:
5943 attrs
->at_const_value
= a
;
5945 case DW_AT_containing_type
:
5946 attrs
->at_containing_type
= a
;
5949 attrs
->at_count
= a
;
5951 case DW_AT_data_location
:
5952 attrs
->at_data_location
= a
;
5954 case DW_AT_data_member_location
:
5955 attrs
->at_data_member_location
= a
;
5957 case DW_AT_decimal_scale
:
5958 attrs
->at_decimal_scale
= a
;
5960 case DW_AT_decimal_sign
:
5961 attrs
->at_decimal_sign
= a
;
5963 case DW_AT_default_value
:
5964 attrs
->at_default_value
= a
;
5966 case DW_AT_digit_count
:
5967 attrs
->at_digit_count
= a
;
5970 attrs
->at_discr
= a
;
5972 case DW_AT_discr_list
:
5973 attrs
->at_discr_list
= a
;
5975 case DW_AT_discr_value
:
5976 attrs
->at_discr_value
= a
;
5978 case DW_AT_encoding
:
5979 attrs
->at_encoding
= a
;
5981 case DW_AT_endianity
:
5982 attrs
->at_endianity
= a
;
5984 case DW_AT_explicit
:
5985 attrs
->at_explicit
= a
;
5987 case DW_AT_is_optional
:
5988 attrs
->at_is_optional
= a
;
5990 case DW_AT_location
:
5991 attrs
->at_location
= a
;
5993 case DW_AT_lower_bound
:
5994 attrs
->at_lower_bound
= a
;
5997 attrs
->at_mutable
= a
;
5999 case DW_AT_ordering
:
6000 attrs
->at_ordering
= a
;
6002 case DW_AT_picture_string
:
6003 attrs
->at_picture_string
= a
;
6005 case DW_AT_prototyped
:
6006 attrs
->at_prototyped
= a
;
6009 attrs
->at_small
= a
;
6012 attrs
->at_segment
= a
;
6014 case DW_AT_string_length
:
6015 attrs
->at_string_length
= a
;
6017 case DW_AT_threads_scaled
:
6018 attrs
->at_threads_scaled
= a
;
6020 case DW_AT_upper_bound
:
6021 attrs
->at_upper_bound
= a
;
6023 case DW_AT_use_location
:
6024 attrs
->at_use_location
= a
;
6026 case DW_AT_use_UTF8
:
6027 attrs
->at_use_UTF8
= a
;
6029 case DW_AT_variable_parameter
:
6030 attrs
->at_variable_parameter
= a
;
6032 case DW_AT_virtuality
:
6033 attrs
->at_virtuality
= a
;
6035 case DW_AT_visibility
:
6036 attrs
->at_visibility
= a
;
6038 case DW_AT_vtable_elem_location
:
6039 attrs
->at_vtable_elem_location
= a
;
6047 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6050 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6054 struct checksum_attributes attrs
;
6056 CHECKSUM_ULEB128 ('D');
6057 CHECKSUM_ULEB128 (die
->die_tag
);
6059 memset (&attrs
, 0, sizeof (attrs
));
6061 decl
= get_AT_ref (die
, DW_AT_specification
);
6063 collect_checksum_attributes (&attrs
, decl
);
6064 collect_checksum_attributes (&attrs
, die
);
6066 CHECKSUM_ATTR (attrs
.at_name
);
6067 CHECKSUM_ATTR (attrs
.at_accessibility
);
6068 CHECKSUM_ATTR (attrs
.at_address_class
);
6069 CHECKSUM_ATTR (attrs
.at_allocated
);
6070 CHECKSUM_ATTR (attrs
.at_artificial
);
6071 CHECKSUM_ATTR (attrs
.at_associated
);
6072 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6073 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6074 CHECKSUM_ATTR (attrs
.at_bit_size
);
6075 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6076 CHECKSUM_ATTR (attrs
.at_byte_size
);
6077 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6078 CHECKSUM_ATTR (attrs
.at_const_value
);
6079 CHECKSUM_ATTR (attrs
.at_containing_type
);
6080 CHECKSUM_ATTR (attrs
.at_count
);
6081 CHECKSUM_ATTR (attrs
.at_data_location
);
6082 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6083 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6084 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6085 CHECKSUM_ATTR (attrs
.at_default_value
);
6086 CHECKSUM_ATTR (attrs
.at_digit_count
);
6087 CHECKSUM_ATTR (attrs
.at_discr
);
6088 CHECKSUM_ATTR (attrs
.at_discr_list
);
6089 CHECKSUM_ATTR (attrs
.at_discr_value
);
6090 CHECKSUM_ATTR (attrs
.at_encoding
);
6091 CHECKSUM_ATTR (attrs
.at_endianity
);
6092 CHECKSUM_ATTR (attrs
.at_explicit
);
6093 CHECKSUM_ATTR (attrs
.at_is_optional
);
6094 CHECKSUM_ATTR (attrs
.at_location
);
6095 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6096 CHECKSUM_ATTR (attrs
.at_mutable
);
6097 CHECKSUM_ATTR (attrs
.at_ordering
);
6098 CHECKSUM_ATTR (attrs
.at_picture_string
);
6099 CHECKSUM_ATTR (attrs
.at_prototyped
);
6100 CHECKSUM_ATTR (attrs
.at_small
);
6101 CHECKSUM_ATTR (attrs
.at_segment
);
6102 CHECKSUM_ATTR (attrs
.at_string_length
);
6103 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6104 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6105 CHECKSUM_ATTR (attrs
.at_use_location
);
6106 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6107 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6108 CHECKSUM_ATTR (attrs
.at_virtuality
);
6109 CHECKSUM_ATTR (attrs
.at_visibility
);
6110 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6111 CHECKSUM_ATTR (attrs
.at_type
);
6112 CHECKSUM_ATTR (attrs
.at_friend
);
6114 /* Checksum the child DIEs. */
6117 dw_attr_ref name_attr
;
6120 name_attr
= get_AT (c
, DW_AT_name
);
6121 if (is_template_instantiation (c
))
6123 /* Ignore instantiations of member type and function templates. */
6125 else if (name_attr
!= NULL
6126 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6128 /* Use a shallow checksum for named nested types and member
6130 CHECKSUM_ULEB128 ('S');
6131 CHECKSUM_ULEB128 (c
->die_tag
);
6132 CHECKSUM_STRING (AT_string (name_attr
));
6136 /* Use a deep checksum for other children. */
6137 /* Mark this DIE so it gets processed when unmarking. */
6138 if (c
->die_mark
== 0)
6140 die_checksum_ordered (c
, ctx
, mark
);
6142 } while (c
!= die
->die_child
);
6144 CHECKSUM_ULEB128 (0);
6147 /* Add a type name and tag to a hash. */
6149 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6151 CHECKSUM_ULEB128 (tag
);
6152 CHECKSUM_STRING (name
);
6156 #undef CHECKSUM_STRING
6157 #undef CHECKSUM_ATTR
6158 #undef CHECKSUM_LEB128
6159 #undef CHECKSUM_ULEB128
6161 /* Generate the type signature for DIE. This is computed by generating an
6162 MD5 checksum over the DIE's tag, its relevant attributes, and its
6163 children. Attributes that are references to other DIEs are processed
6164 by recursion, using the MARK field to prevent infinite recursion.
6165 If the DIE is nested inside a namespace or another type, we also
6166 need to include that context in the signature. The lower 64 bits
6167 of the resulting MD5 checksum comprise the signature. */
6170 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6174 unsigned char checksum
[16];
6179 name
= get_AT_string (die
, DW_AT_name
);
6180 decl
= get_AT_ref (die
, DW_AT_specification
);
6181 parent
= get_die_parent (die
);
6183 /* First, compute a signature for just the type name (and its surrounding
6184 context, if any. This is stored in the type unit DIE for link-time
6185 ODR (one-definition rule) checking. */
6187 if (is_cxx () && name
!= NULL
)
6189 md5_init_ctx (&ctx
);
6191 /* Checksum the names of surrounding namespaces and structures. */
6193 checksum_die_context (parent
, &ctx
);
6195 /* Checksum the current DIE. */
6196 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6197 md5_finish_ctx (&ctx
, checksum
);
6199 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6202 /* Next, compute the complete type signature. */
6204 md5_init_ctx (&ctx
);
6206 die
->die_mark
= mark
;
6208 /* Checksum the names of surrounding namespaces and structures. */
6210 checksum_die_context (parent
, &ctx
);
6212 /* Checksum the DIE and its children. */
6213 die_checksum_ordered (die
, &ctx
, &mark
);
6214 unmark_all_dies (die
);
6215 md5_finish_ctx (&ctx
, checksum
);
6217 /* Store the signature in the type node and link the type DIE and the
6218 type node together. */
6219 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6220 DWARF_TYPE_SIGNATURE_SIZE
);
6221 die
->comdat_type_p
= true;
6222 die
->die_id
.die_type_node
= type_node
;
6223 type_node
->type_die
= die
;
6225 /* If the DIE is a specification, link its declaration to the type node
6229 decl
->comdat_type_p
= true;
6230 decl
->die_id
.die_type_node
= type_node
;
6234 /* Do the location expressions look same? */
6236 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6238 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6239 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6240 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6243 /* Do the values look the same? */
6245 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6247 dw_loc_descr_ref loc1
, loc2
;
6250 if (v1
->val_class
!= v2
->val_class
)
6253 switch (v1
->val_class
)
6255 case dw_val_class_const
:
6256 return v1
->v
.val_int
== v2
->v
.val_int
;
6257 case dw_val_class_unsigned_const
:
6258 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6259 case dw_val_class_const_double
:
6260 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6261 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6262 case dw_val_class_vec
:
6263 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6264 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6266 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6267 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6270 case dw_val_class_flag
:
6271 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6272 case dw_val_class_str
:
6273 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6275 case dw_val_class_addr
:
6276 r1
= v1
->v
.val_addr
;
6277 r2
= v2
->v
.val_addr
;
6278 if (GET_CODE (r1
) != GET_CODE (r2
))
6280 return !rtx_equal_p (r1
, r2
);
6282 case dw_val_class_offset
:
6283 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6285 case dw_val_class_loc
:
6286 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6288 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6289 if (!same_loc_p (loc1
, loc2
, mark
))
6291 return !loc1
&& !loc2
;
6293 case dw_val_class_die_ref
:
6294 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6296 case dw_val_class_fde_ref
:
6297 case dw_val_class_vms_delta
:
6298 case dw_val_class_lbl_id
:
6299 case dw_val_class_lineptr
:
6300 case dw_val_class_macptr
:
6301 case dw_val_class_high_pc
:
6304 case dw_val_class_file
:
6305 return v1
->v
.val_file
== v2
->v
.val_file
;
6307 case dw_val_class_data8
:
6308 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6315 /* Do the attributes look the same? */
6318 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6320 if (at1
->dw_attr
!= at2
->dw_attr
)
6323 /* We don't care that this was compiled with a different compiler
6324 snapshot; if the output is the same, that's what matters. */
6325 if (at1
->dw_attr
== DW_AT_producer
)
6328 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6331 /* Do the dies look the same? */
6334 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6340 /* To avoid infinite recursion. */
6342 return die1
->die_mark
== die2
->die_mark
;
6343 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6345 if (die1
->die_tag
!= die2
->die_tag
)
6348 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6351 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6352 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6355 c1
= die1
->die_child
;
6356 c2
= die2
->die_child
;
6365 if (!same_die_p (c1
, c2
, mark
))
6369 if (c1
== die1
->die_child
)
6371 if (c2
== die2
->die_child
)
6381 /* Do the dies look the same? Wrapper around same_die_p. */
6384 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6387 int ret
= same_die_p (die1
, die2
, &mark
);
6389 unmark_all_dies (die1
);
6390 unmark_all_dies (die2
);
6395 /* The prefix to attach to symbols on DIEs in the current comdat debug
6397 static const char *comdat_symbol_id
;
6399 /* The index of the current symbol within the current comdat CU. */
6400 static unsigned int comdat_symbol_number
;
6402 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6403 children, and set comdat_symbol_id accordingly. */
6406 compute_section_prefix (dw_die_ref unit_die
)
6408 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6409 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6410 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6413 unsigned char checksum
[16];
6416 /* Compute the checksum of the DIE, then append part of it as hex digits to
6417 the name filename of the unit. */
6419 md5_init_ctx (&ctx
);
6421 die_checksum (unit_die
, &ctx
, &mark
);
6422 unmark_all_dies (unit_die
);
6423 md5_finish_ctx (&ctx
, checksum
);
6425 sprintf (name
, "%s.", base
);
6426 clean_symbol_name (name
);
6428 p
= name
+ strlen (name
);
6429 for (i
= 0; i
< 4; i
++)
6431 sprintf (p
, "%.2x", checksum
[i
]);
6435 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6436 comdat_symbol_number
= 0;
6439 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6442 is_type_die (dw_die_ref die
)
6444 switch (die
->die_tag
)
6446 case DW_TAG_array_type
:
6447 case DW_TAG_class_type
:
6448 case DW_TAG_interface_type
:
6449 case DW_TAG_enumeration_type
:
6450 case DW_TAG_pointer_type
:
6451 case DW_TAG_reference_type
:
6452 case DW_TAG_rvalue_reference_type
:
6453 case DW_TAG_string_type
:
6454 case DW_TAG_structure_type
:
6455 case DW_TAG_subroutine_type
:
6456 case DW_TAG_union_type
:
6457 case DW_TAG_ptr_to_member_type
:
6458 case DW_TAG_set_type
:
6459 case DW_TAG_subrange_type
:
6460 case DW_TAG_base_type
:
6461 case DW_TAG_const_type
:
6462 case DW_TAG_file_type
:
6463 case DW_TAG_packed_type
:
6464 case DW_TAG_volatile_type
:
6465 case DW_TAG_typedef
:
6472 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6473 Basically, we want to choose the bits that are likely to be shared between
6474 compilations (types) and leave out the bits that are specific to individual
6475 compilations (functions). */
6478 is_comdat_die (dw_die_ref c
)
6480 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6481 we do for stabs. The advantage is a greater likelihood of sharing between
6482 objects that don't include headers in the same order (and therefore would
6483 put the base types in a different comdat). jason 8/28/00 */
6485 if (c
->die_tag
== DW_TAG_base_type
)
6488 if (c
->die_tag
== DW_TAG_pointer_type
6489 || c
->die_tag
== DW_TAG_reference_type
6490 || c
->die_tag
== DW_TAG_rvalue_reference_type
6491 || c
->die_tag
== DW_TAG_const_type
6492 || c
->die_tag
== DW_TAG_volatile_type
)
6494 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6496 return t
? is_comdat_die (t
) : 0;
6499 return is_type_die (c
);
6502 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6503 compilation unit. */
6506 is_symbol_die (dw_die_ref c
)
6508 return (is_type_die (c
)
6509 || is_declaration_die (c
)
6510 || c
->die_tag
== DW_TAG_namespace
6511 || c
->die_tag
== DW_TAG_module
);
6514 /* Returns true iff C is a compile-unit DIE. */
6517 is_cu_die (dw_die_ref c
)
6519 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6522 /* Returns true iff C is a unit DIE of some sort. */
6525 is_unit_die (dw_die_ref c
)
6527 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6528 || c
->die_tag
== DW_TAG_partial_unit
6529 || c
->die_tag
== DW_TAG_type_unit
);
6532 /* Returns true iff C is a namespace DIE. */
6535 is_namespace_die (dw_die_ref c
)
6537 return c
&& c
->die_tag
== DW_TAG_namespace
;
6540 /* Returns true iff C is a class or structure DIE. */
6543 is_class_die (dw_die_ref c
)
6545 return c
&& (c
->die_tag
== DW_TAG_class_type
6546 || c
->die_tag
== DW_TAG_structure_type
);
6549 /* Return non-zero if this DIE is a template parameter. */
6552 is_template_parameter (dw_die_ref die
)
6554 switch (die
->die_tag
)
6556 case DW_TAG_template_type_param
:
6557 case DW_TAG_template_value_param
:
6558 case DW_TAG_GNU_template_template_param
:
6559 case DW_TAG_GNU_template_parameter_pack
:
6566 /* Return non-zero if this DIE represents a template instantiation. */
6569 is_template_instantiation (dw_die_ref die
)
6573 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6575 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6580 gen_internal_sym (const char *prefix
)
6584 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6585 return xstrdup (buf
);
6588 /* Assign symbols to all worthy DIEs under DIE. */
6591 assign_symbol_names (dw_die_ref die
)
6595 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6597 if (comdat_symbol_id
)
6599 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6601 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6602 comdat_symbol_id
, comdat_symbol_number
++);
6603 die
->die_id
.die_symbol
= xstrdup (p
);
6606 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6609 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6612 struct cu_hash_table_entry
6615 unsigned min_comdat_num
, max_comdat_num
;
6616 struct cu_hash_table_entry
*next
;
6619 /* Helpers to manipulate hash table of CUs. */
6621 struct cu_hash_table_entry_hasher
6623 typedef cu_hash_table_entry value_type
;
6624 typedef die_struct compare_type
;
6625 static inline hashval_t
hash (const value_type
*);
6626 static inline bool equal (const value_type
*, const compare_type
*);
6627 static inline void remove (value_type
*);
6631 cu_hash_table_entry_hasher::hash (const value_type
*entry
)
6633 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6637 cu_hash_table_entry_hasher::equal (const value_type
*entry1
,
6638 const compare_type
*entry2
)
6640 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6644 cu_hash_table_entry_hasher::remove (value_type
*entry
)
6646 struct cu_hash_table_entry
*next
;
6656 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6658 /* Check whether we have already seen this CU and set up SYM_NUM
6661 check_duplicate_cu (dw_die_ref cu
, cu_hash_type htable
, unsigned int *sym_num
)
6663 struct cu_hash_table_entry dummy
;
6664 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6666 dummy
.max_comdat_num
= 0;
6668 slot
= htable
.find_slot_with_hash (cu
,
6669 htab_hash_string (cu
->die_id
.die_symbol
),
6673 for (; entry
; last
= entry
, entry
= entry
->next
)
6675 if (same_die_p_wrap (cu
, entry
->cu
))
6681 *sym_num
= entry
->min_comdat_num
;
6685 entry
= XCNEW (struct cu_hash_table_entry
);
6687 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6688 entry
->next
= *slot
;
6694 /* Record SYM_NUM to record of CU in HTABLE. */
6696 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type htable
,
6697 unsigned int sym_num
)
6699 struct cu_hash_table_entry
**slot
, *entry
;
6701 slot
= htable
.find_slot_with_hash (cu
,
6702 htab_hash_string (cu
->die_id
.die_symbol
),
6706 entry
->max_comdat_num
= sym_num
;
6709 /* Traverse the DIE (which is always comp_unit_die), and set up
6710 additional compilation units for each of the include files we see
6711 bracketed by BINCL/EINCL. */
6714 break_out_includes (dw_die_ref die
)
6717 dw_die_ref unit
= NULL
;
6718 limbo_die_node
*node
, **pnode
;
6719 cu_hash_type cu_hash_table
;
6723 dw_die_ref prev
= c
;
6725 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6726 || (unit
&& is_comdat_die (c
)))
6728 dw_die_ref next
= c
->die_sib
;
6730 /* This DIE is for a secondary CU; remove it from the main one. */
6731 remove_child_with_prev (c
, prev
);
6733 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6734 unit
= push_new_compile_unit (unit
, c
);
6735 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6736 unit
= pop_compile_unit (unit
);
6738 add_child_die (unit
, c
);
6740 if (c
== die
->die_child
)
6743 } while (c
!= die
->die_child
);
6746 /* We can only use this in debugging, since the frontend doesn't check
6747 to make sure that we leave every include file we enter. */
6751 assign_symbol_names (die
);
6752 cu_hash_table
.create (10);
6753 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6759 compute_section_prefix (node
->die
);
6760 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6761 &comdat_symbol_number
);
6762 assign_symbol_names (node
->die
);
6764 *pnode
= node
->next
;
6767 pnode
= &node
->next
;
6768 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6769 comdat_symbol_number
);
6772 cu_hash_table
.dispose ();
6775 /* Return non-zero if this DIE is a declaration. */
6778 is_declaration_die (dw_die_ref die
)
6783 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6784 if (a
->dw_attr
== DW_AT_declaration
)
6790 /* Return non-zero if this DIE is nested inside a subprogram. */
6793 is_nested_in_subprogram (dw_die_ref die
)
6795 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6799 return local_scope_p (decl
);
6802 /* Return non-zero if this DIE contains a defining declaration of a
6806 contains_subprogram_definition (dw_die_ref die
)
6810 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6812 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
6816 /* Return non-zero if this is a type DIE that should be moved to a
6817 COMDAT .debug_types section. */
6820 should_move_die_to_comdat (dw_die_ref die
)
6822 switch (die
->die_tag
)
6824 case DW_TAG_class_type
:
6825 case DW_TAG_structure_type
:
6826 case DW_TAG_enumeration_type
:
6827 case DW_TAG_union_type
:
6828 /* Don't move declarations, inlined instances, or types nested in a
6830 if (is_declaration_die (die
)
6831 || get_AT (die
, DW_AT_abstract_origin
)
6832 || is_nested_in_subprogram (die
))
6834 /* A type definition should never contain a subprogram definition. */
6835 gcc_assert (!contains_subprogram_definition (die
));
6837 case DW_TAG_array_type
:
6838 case DW_TAG_interface_type
:
6839 case DW_TAG_pointer_type
:
6840 case DW_TAG_reference_type
:
6841 case DW_TAG_rvalue_reference_type
:
6842 case DW_TAG_string_type
:
6843 case DW_TAG_subroutine_type
:
6844 case DW_TAG_ptr_to_member_type
:
6845 case DW_TAG_set_type
:
6846 case DW_TAG_subrange_type
:
6847 case DW_TAG_base_type
:
6848 case DW_TAG_const_type
:
6849 case DW_TAG_file_type
:
6850 case DW_TAG_packed_type
:
6851 case DW_TAG_volatile_type
:
6852 case DW_TAG_typedef
:
6858 /* Make a clone of DIE. */
6861 clone_die (dw_die_ref die
)
6867 clone
= ggc_alloc_cleared_die_node ();
6868 clone
->die_tag
= die
->die_tag
;
6870 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6871 add_dwarf_attr (clone
, a
);
6876 /* Make a clone of the tree rooted at DIE. */
6879 clone_tree (dw_die_ref die
)
6882 dw_die_ref clone
= clone_die (die
);
6884 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
6889 /* Make a clone of DIE as a declaration. */
6892 clone_as_declaration (dw_die_ref die
)
6899 /* If the DIE is already a declaration, just clone it. */
6900 if (is_declaration_die (die
))
6901 return clone_die (die
);
6903 /* If the DIE is a specification, just clone its declaration DIE. */
6904 decl
= get_AT_ref (die
, DW_AT_specification
);
6907 clone
= clone_die (decl
);
6908 if (die
->comdat_type_p
)
6909 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6913 clone
= ggc_alloc_cleared_die_node ();
6914 clone
->die_tag
= die
->die_tag
;
6916 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6918 /* We don't want to copy over all attributes.
6919 For example we don't want DW_AT_byte_size because otherwise we will no
6920 longer have a declaration and GDB will treat it as a definition. */
6924 case DW_AT_artificial
:
6925 case DW_AT_containing_type
:
6926 case DW_AT_external
:
6929 case DW_AT_virtuality
:
6930 case DW_AT_linkage_name
:
6931 case DW_AT_MIPS_linkage_name
:
6932 add_dwarf_attr (clone
, a
);
6934 case DW_AT_byte_size
:
6940 if (die
->comdat_type_p
)
6941 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6943 add_AT_flag (clone
, DW_AT_declaration
, 1);
6948 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
6950 struct decl_table_entry
6956 /* Helpers to manipulate hash table of copied declarations. */
6958 /* Hashtable helpers. */
6960 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
6962 typedef decl_table_entry value_type
;
6963 typedef die_struct compare_type
;
6964 static inline hashval_t
hash (const value_type
*);
6965 static inline bool equal (const value_type
*, const compare_type
*);
6969 decl_table_entry_hasher::hash (const value_type
*entry
)
6971 return htab_hash_pointer (entry
->orig
);
6975 decl_table_entry_hasher::equal (const value_type
*entry1
,
6976 const compare_type
*entry2
)
6978 return entry1
->orig
== entry2
;
6981 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
6983 /* Copy DIE and its ancestors, up to, but not including, the compile unit
6984 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
6985 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
6986 to check if the ancestor has already been copied into UNIT. */
6989 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
6991 dw_die_ref parent
= die
->die_parent
;
6992 dw_die_ref new_parent
= unit
;
6994 decl_table_entry
**slot
= NULL
;
6995 struct decl_table_entry
*entry
= NULL
;
6997 if (decl_table
.is_created ())
6999 /* Check if the entry has already been copied to UNIT. */
7000 slot
= decl_table
.find_slot_with_hash (die
, htab_hash_pointer (die
),
7002 if (*slot
!= HTAB_EMPTY_ENTRY
)
7008 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7009 entry
= XCNEW (struct decl_table_entry
);
7017 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7020 if (!is_unit_die (parent
))
7021 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7024 copy
= clone_as_declaration (die
);
7025 add_child_die (new_parent
, copy
);
7027 if (decl_table
.is_created ())
7029 /* Record the pointer to the copy. */
7035 /* Copy the declaration context to the new type unit DIE. This includes
7036 any surrounding namespace or type declarations. If the DIE has an
7037 AT_specification attribute, it also includes attributes and children
7038 attached to the specification, and returns a pointer to the original
7039 parent of the declaration DIE. Returns NULL otherwise. */
7042 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7045 dw_die_ref new_decl
;
7046 dw_die_ref orig_parent
= NULL
;
7048 decl
= get_AT_ref (die
, DW_AT_specification
);
7057 /* The original DIE will be changed to a declaration, and must
7058 be moved to be a child of the original declaration DIE. */
7059 orig_parent
= decl
->die_parent
;
7061 /* Copy the type node pointer from the new DIE to the original
7062 declaration DIE so we can forward references later. */
7063 decl
->comdat_type_p
= true;
7064 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7066 remove_AT (die
, DW_AT_specification
);
7068 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7070 if (a
->dw_attr
!= DW_AT_name
7071 && a
->dw_attr
!= DW_AT_declaration
7072 && a
->dw_attr
!= DW_AT_external
)
7073 add_dwarf_attr (die
, a
);
7076 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7079 if (decl
->die_parent
!= NULL
7080 && !is_unit_die (decl
->die_parent
))
7082 new_decl
= copy_ancestor_tree (unit
, decl
, decl_hash_type ());
7083 if (new_decl
!= NULL
)
7085 remove_AT (new_decl
, DW_AT_signature
);
7086 add_AT_specification (die
, new_decl
);
7093 /* Generate the skeleton ancestor tree for the given NODE, then clone
7094 the DIE and add the clone into the tree. */
7097 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7099 if (node
->new_die
!= NULL
)
7102 node
->new_die
= clone_as_declaration (node
->old_die
);
7104 if (node
->parent
!= NULL
)
7106 generate_skeleton_ancestor_tree (node
->parent
);
7107 add_child_die (node
->parent
->new_die
, node
->new_die
);
7111 /* Generate a skeleton tree of DIEs containing any declarations that are
7112 found in the original tree. We traverse the tree looking for declaration
7113 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7116 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7118 skeleton_chain_node node
;
7121 dw_die_ref prev
= NULL
;
7122 dw_die_ref next
= NULL
;
7124 node
.parent
= parent
;
7126 first
= c
= parent
->old_die
->die_child
;
7130 if (prev
== NULL
|| prev
->die_sib
== c
)
7133 next
= (c
== first
? NULL
: c
->die_sib
);
7135 node
.new_die
= NULL
;
7136 if (is_declaration_die (c
))
7138 if (is_template_instantiation (c
))
7140 /* Instantiated templates do not need to be cloned into the
7141 type unit. Just move the DIE and its children back to
7142 the skeleton tree (in the main CU). */
7143 remove_child_with_prev (c
, prev
);
7144 add_child_die (parent
->new_die
, c
);
7149 /* Clone the existing DIE, move the original to the skeleton
7150 tree (which is in the main CU), and put the clone, with
7151 all the original's children, where the original came from
7152 (which is about to be moved to the type unit). */
7153 dw_die_ref clone
= clone_die (c
);
7154 move_all_children (c
, clone
);
7156 replace_child (c
, clone
, prev
);
7157 generate_skeleton_ancestor_tree (parent
);
7158 add_child_die (parent
->new_die
, c
);
7163 generate_skeleton_bottom_up (&node
);
7164 } while (next
!= NULL
);
7167 /* Wrapper function for generate_skeleton_bottom_up. */
7170 generate_skeleton (dw_die_ref die
)
7172 skeleton_chain_node node
;
7175 node
.new_die
= NULL
;
7178 /* If this type definition is nested inside another type,
7179 and is not an instantiation of a template, always leave
7180 at least a declaration in its place. */
7181 if (die
->die_parent
!= NULL
7182 && is_type_die (die
->die_parent
)
7183 && !is_template_instantiation (die
))
7184 node
.new_die
= clone_as_declaration (die
);
7186 generate_skeleton_bottom_up (&node
);
7187 return node
.new_die
;
7190 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7191 declaration. The original DIE is moved to a new compile unit so that
7192 existing references to it follow it to the new location. If any of the
7193 original DIE's descendants is a declaration, we need to replace the
7194 original DIE with a skeleton tree and move the declarations back into the
7198 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7201 dw_die_ref skeleton
, orig_parent
;
7203 /* Copy the declaration context to the type unit DIE. If the returned
7204 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7206 orig_parent
= copy_declaration_context (unit
, child
);
7208 skeleton
= generate_skeleton (child
);
7209 if (skeleton
== NULL
)
7210 remove_child_with_prev (child
, prev
);
7213 skeleton
->comdat_type_p
= true;
7214 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7216 /* If the original DIE was a specification, we need to put
7217 the skeleton under the parent DIE of the declaration.
7218 This leaves the original declaration in the tree, but
7219 it will be pruned later since there are no longer any
7220 references to it. */
7221 if (orig_parent
!= NULL
)
7223 remove_child_with_prev (child
, prev
);
7224 add_child_die (orig_parent
, skeleton
);
7227 replace_child (child
, skeleton
, prev
);
7233 /* Traverse the DIE and set up additional .debug_types sections for each
7234 type worthy of being placed in a COMDAT section. */
7237 break_out_comdat_types (dw_die_ref die
)
7241 dw_die_ref prev
= NULL
;
7242 dw_die_ref next
= NULL
;
7243 dw_die_ref unit
= NULL
;
7245 first
= c
= die
->die_child
;
7249 if (prev
== NULL
|| prev
->die_sib
== c
)
7252 next
= (c
== first
? NULL
: c
->die_sib
);
7253 if (should_move_die_to_comdat (c
))
7255 dw_die_ref replacement
;
7256 comdat_type_node_ref type_node
;
7258 /* Break out nested types into their own type units. */
7259 break_out_comdat_types (c
);
7261 /* Create a new type unit DIE as the root for the new tree, and
7262 add it to the list of comdat types. */
7263 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7264 add_AT_unsigned (unit
, DW_AT_language
,
7265 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7266 type_node
= ggc_alloc_cleared_comdat_type_node ();
7267 type_node
->root_die
= unit
;
7268 type_node
->next
= comdat_type_list
;
7269 comdat_type_list
= type_node
;
7271 /* Generate the type signature. */
7272 generate_type_signature (c
, type_node
);
7274 /* Copy the declaration context, attributes, and children of the
7275 declaration into the new type unit DIE, then remove this DIE
7276 from the main CU (or replace it with a skeleton if necessary). */
7277 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7278 type_node
->skeleton_die
= replacement
;
7280 /* Add the DIE to the new compunit. */
7281 add_child_die (unit
, c
);
7283 if (replacement
!= NULL
)
7286 else if (c
->die_tag
== DW_TAG_namespace
7287 || c
->die_tag
== DW_TAG_class_type
7288 || c
->die_tag
== DW_TAG_structure_type
7289 || c
->die_tag
== DW_TAG_union_type
)
7291 /* Look for nested types that can be broken out. */
7292 break_out_comdat_types (c
);
7294 } while (next
!= NULL
);
7297 /* Like clone_tree, but additionally enter all the children into
7298 the hash table decl_table. */
7301 clone_tree_hash (dw_die_ref die
, decl_hash_type decl_table
)
7304 dw_die_ref clone
= clone_die (die
);
7305 struct decl_table_entry
*entry
;
7306 decl_table_entry
**slot
= decl_table
.find_slot_with_hash (die
,
7307 htab_hash_pointer (die
), INSERT
);
7308 /* Assert that DIE isn't in the hash table yet. If it would be there
7309 before, the ancestors would be necessarily there as well, therefore
7310 clone_tree_hash wouldn't be called. */
7311 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7312 entry
= XCNEW (struct decl_table_entry
);
7314 entry
->copy
= clone
;
7317 FOR_EACH_CHILD (die
, c
,
7318 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7323 /* Walk the DIE and its children, looking for references to incomplete
7324 or trivial types that are unmarked (i.e., that are not in the current
7328 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
7334 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7336 if (AT_class (a
) == dw_val_class_die_ref
)
7338 dw_die_ref targ
= AT_ref (a
);
7339 decl_table_entry
**slot
;
7340 struct decl_table_entry
*entry
;
7342 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7345 slot
= decl_table
.find_slot_with_hash (targ
, htab_hash_pointer (targ
),
7348 if (*slot
!= HTAB_EMPTY_ENTRY
)
7350 /* TARG has already been copied, so we just need to
7351 modify the reference to point to the copy. */
7353 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7357 dw_die_ref parent
= unit
;
7358 dw_die_ref copy
= clone_die (targ
);
7360 /* Record in DECL_TABLE that TARG has been copied.
7361 Need to do this now, before the recursive call,
7362 because DECL_TABLE may be expanded and SLOT
7363 would no longer be a valid pointer. */
7364 entry
= XCNEW (struct decl_table_entry
);
7369 FOR_EACH_CHILD (targ
, c
,
7370 add_child_die (copy
,
7371 clone_tree_hash (c
, decl_table
)));
7373 /* Make sure the cloned tree is marked as part of the
7377 /* If TARG has surrounding context, copy its ancestor tree
7378 into the new type unit. */
7379 if (targ
->die_parent
!= NULL
7380 && !is_unit_die (targ
->die_parent
))
7381 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7384 add_child_die (parent
, copy
);
7385 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7387 /* Make sure the newly-copied DIE is walked. If it was
7388 installed in a previously-added context, it won't
7389 get visited otherwise. */
7392 /* Find the highest point of the newly-added tree,
7393 mark each node along the way, and walk from there. */
7394 parent
->die_mark
= 1;
7395 while (parent
->die_parent
7396 && parent
->die_parent
->die_mark
== 0)
7398 parent
= parent
->die_parent
;
7399 parent
->die_mark
= 1;
7401 copy_decls_walk (unit
, parent
, decl_table
);
7407 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7410 /* Copy declarations for "unworthy" types into the new comdat section.
7411 Incomplete types, modified types, and certain other types aren't broken
7412 out into comdat sections of their own, so they don't have a signature,
7413 and we need to copy the declaration into the same section so that we
7414 don't have an external reference. */
7417 copy_decls_for_unworthy_types (dw_die_ref unit
)
7419 decl_hash_type decl_table
;
7422 decl_table
.create (10);
7423 copy_decls_walk (unit
, unit
, decl_table
);
7424 decl_table
.dispose ();
7428 /* Traverse the DIE and add a sibling attribute if it may have the
7429 effect of speeding up access to siblings. To save some space,
7430 avoid generating sibling attributes for DIE's without children. */
7433 add_sibling_attributes (dw_die_ref die
)
7437 if (! die
->die_child
)
7440 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7441 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7443 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7446 /* Output all location lists for the DIE and its children. */
7449 output_location_lists (dw_die_ref die
)
7455 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7456 if (AT_class (a
) == dw_val_class_loc_list
)
7457 output_loc_list (AT_loc_list (a
));
7459 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7462 /* We want to limit the number of external references, because they are
7463 larger than local references: a relocation takes multiple words, and
7464 even a sig8 reference is always eight bytes, whereas a local reference
7465 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7466 So if we encounter multiple external references to the same type DIE, we
7467 make a local typedef stub for it and redirect all references there.
7469 This is the element of the hash table for keeping track of these
7479 /* Hashtable helpers. */
7481 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7483 typedef external_ref value_type
;
7484 typedef external_ref compare_type
;
7485 static inline hashval_t
hash (const value_type
*);
7486 static inline bool equal (const value_type
*, const compare_type
*);
7490 external_ref_hasher::hash (const value_type
*r
)
7492 dw_die_ref die
= r
->type
;
7495 /* We can't use the address of the DIE for hashing, because
7496 that will make the order of the stub DIEs non-deterministic. */
7497 if (! die
->comdat_type_p
)
7498 /* We have a symbol; use it to compute a hash. */
7499 h
= htab_hash_string (die
->die_id
.die_symbol
);
7502 /* We have a type signature; use a subset of the bits as the hash.
7503 The 8-byte signature is at least as large as hashval_t. */
7504 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7505 memcpy (&h
, type_node
->signature
, sizeof (h
));
7511 external_ref_hasher::equal (const value_type
*r1
, const compare_type
*r2
)
7513 return r1
->type
== r2
->type
;
7516 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7518 /* Return a pointer to the external_ref for references to DIE. */
7520 static struct external_ref
*
7521 lookup_external_ref (external_ref_hash_type map
, dw_die_ref die
)
7523 struct external_ref ref
, *ref_p
;
7524 external_ref
**slot
;
7527 slot
= map
.find_slot (&ref
, INSERT
);
7528 if (*slot
!= HTAB_EMPTY_ENTRY
)
7531 ref_p
= XCNEW (struct external_ref
);
7537 /* Subroutine of optimize_external_refs, below.
7539 If we see a type skeleton, record it as our stub. If we see external
7540 references, remember how many we've seen. */
7543 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type map
)
7548 struct external_ref
*ref_p
;
7550 if (is_type_die (die
)
7551 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7553 /* This is a local skeleton; use it for local references. */
7554 ref_p
= lookup_external_ref (map
, c
);
7558 /* Scan the DIE references, and remember any that refer to DIEs from
7559 other CUs (i.e. those which are not marked). */
7560 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7561 if (AT_class (a
) == dw_val_class_die_ref
7562 && (c
= AT_ref (a
))->die_mark
== 0
7565 ref_p
= lookup_external_ref (map
, c
);
7569 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7572 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7573 points to an external_ref, DATA is the CU we're processing. If we don't
7574 already have a local stub, and we have multiple refs, build a stub. */
7577 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7579 struct external_ref
*ref_p
= *slot
;
7581 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7583 /* We have multiple references to this type, so build a small stub.
7584 Both of these forms are a bit dodgy from the perspective of the
7585 DWARF standard, since technically they should have names. */
7586 dw_die_ref cu
= data
;
7587 dw_die_ref type
= ref_p
->type
;
7588 dw_die_ref stub
= NULL
;
7590 if (type
->comdat_type_p
)
7592 /* If we refer to this type via sig8, use AT_signature. */
7593 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7594 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7598 /* Otherwise, use a typedef with no name. */
7599 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7600 add_AT_die_ref (stub
, DW_AT_type
, type
);
7609 /* DIE is a unit; look through all the DIE references to see if there are
7610 any external references to types, and if so, create local stubs for
7611 them which will be applied in build_abbrev_table. This is useful because
7612 references to local DIEs are smaller. */
7614 static external_ref_hash_type
7615 optimize_external_refs (dw_die_ref die
)
7617 external_ref_hash_type map
;
7619 optimize_external_refs_1 (die
, map
);
7620 map
.traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7624 /* The format of each DIE (and its attribute value pairs) is encoded in an
7625 abbreviation table. This routine builds the abbreviation table and assigns
7626 a unique abbreviation id for each abbreviation entry. The children of each
7627 die are visited recursively. */
7630 build_abbrev_table (dw_die_ref die
, external_ref_hash_type extern_map
)
7632 unsigned long abbrev_id
;
7633 unsigned int n_alloc
;
7638 /* Scan the DIE references, and replace any that refer to
7639 DIEs from other CUs (i.e. those which are not marked) with
7640 the local stubs we built in optimize_external_refs. */
7641 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7642 if (AT_class (a
) == dw_val_class_die_ref
7643 && (c
= AT_ref (a
))->die_mark
== 0)
7645 struct external_ref
*ref_p
;
7646 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7648 ref_p
= lookup_external_ref (extern_map
, c
);
7649 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7650 change_AT_die_ref (a
, ref_p
->stub
);
7652 /* We aren't changing this reference, so mark it external. */
7653 set_AT_ref_external (a
, 1);
7656 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7658 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7659 dw_attr_ref die_a
, abbrev_a
;
7663 if (abbrev
->die_tag
!= die
->die_tag
)
7665 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7668 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7671 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7673 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7674 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7675 || (value_format (abbrev_a
) != value_format (die_a
)))
7685 if (abbrev_id
>= abbrev_die_table_in_use
)
7687 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7689 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7690 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7693 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7694 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7695 abbrev_die_table_allocated
= n_alloc
;
7698 ++abbrev_die_table_in_use
;
7699 abbrev_die_table
[abbrev_id
] = die
;
7702 die
->die_abbrev
= abbrev_id
;
7703 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7706 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7709 constant_size (unsigned HOST_WIDE_INT value
)
7716 log
= floor_log2 (value
);
7719 log
= 1 << (floor_log2 (log
) + 1);
7724 /* Return the size of a DIE as it is represented in the
7725 .debug_info section. */
7727 static unsigned long
7728 size_of_die (dw_die_ref die
)
7730 unsigned long size
= 0;
7733 enum dwarf_form form
;
7735 size
+= size_of_uleb128 (die
->die_abbrev
);
7736 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7738 switch (AT_class (a
))
7740 case dw_val_class_addr
:
7741 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7743 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7744 size
+= size_of_uleb128 (AT_index (a
));
7747 size
+= DWARF2_ADDR_SIZE
;
7749 case dw_val_class_offset
:
7750 size
+= DWARF_OFFSET_SIZE
;
7752 case dw_val_class_loc
:
7754 unsigned long lsize
= size_of_locs (AT_loc (a
));
7757 if (dwarf_version
>= 4)
7758 size
+= size_of_uleb128 (lsize
);
7760 size
+= constant_size (lsize
);
7764 case dw_val_class_loc_list
:
7765 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7767 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7768 size
+= size_of_uleb128 (AT_index (a
));
7771 size
+= DWARF_OFFSET_SIZE
;
7773 case dw_val_class_range_list
:
7774 size
+= DWARF_OFFSET_SIZE
;
7776 case dw_val_class_const
:
7777 size
+= size_of_sleb128 (AT_int (a
));
7779 case dw_val_class_unsigned_const
:
7781 int csize
= constant_size (AT_unsigned (a
));
7782 if (dwarf_version
== 3
7783 && a
->dw_attr
== DW_AT_data_member_location
7785 size
+= size_of_uleb128 (AT_unsigned (a
));
7790 case dw_val_class_const_double
:
7791 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7792 if (HOST_BITS_PER_WIDE_INT
>= 64)
7795 case dw_val_class_vec
:
7796 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7797 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7798 + a
->dw_attr_val
.v
.val_vec
.length
7799 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7801 case dw_val_class_flag
:
7802 if (dwarf_version
>= 4)
7803 /* Currently all add_AT_flag calls pass in 1 as last argument,
7804 so DW_FORM_flag_present can be used. If that ever changes,
7805 we'll need to use DW_FORM_flag and have some optimization
7806 in build_abbrev_table that will change those to
7807 DW_FORM_flag_present if it is set to 1 in all DIEs using
7808 the same abbrev entry. */
7809 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7813 case dw_val_class_die_ref
:
7814 if (AT_ref_external (a
))
7816 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7817 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7818 is sized by target address length, whereas in DWARF3
7819 it's always sized as an offset. */
7820 if (use_debug_types
)
7821 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7822 else if (dwarf_version
== 2)
7823 size
+= DWARF2_ADDR_SIZE
;
7825 size
+= DWARF_OFFSET_SIZE
;
7828 size
+= DWARF_OFFSET_SIZE
;
7830 case dw_val_class_fde_ref
:
7831 size
+= DWARF_OFFSET_SIZE
;
7833 case dw_val_class_lbl_id
:
7834 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7836 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7837 size
+= size_of_uleb128 (AT_index (a
));
7840 size
+= DWARF2_ADDR_SIZE
;
7842 case dw_val_class_lineptr
:
7843 case dw_val_class_macptr
:
7844 size
+= DWARF_OFFSET_SIZE
;
7846 case dw_val_class_str
:
7847 form
= AT_string_form (a
);
7848 if (form
== DW_FORM_strp
)
7849 size
+= DWARF_OFFSET_SIZE
;
7850 else if (form
== DW_FORM_GNU_str_index
)
7851 size
+= size_of_uleb128 (AT_index (a
));
7853 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7855 case dw_val_class_file
:
7856 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7858 case dw_val_class_data8
:
7861 case dw_val_class_vms_delta
:
7862 size
+= DWARF_OFFSET_SIZE
;
7864 case dw_val_class_high_pc
:
7865 size
+= DWARF2_ADDR_SIZE
;
7875 /* Size the debugging information associated with a given DIE. Visits the
7876 DIE's children recursively. Updates the global variable next_die_offset, on
7877 each time through. Uses the current value of next_die_offset to update the
7878 die_offset field in each DIE. */
7881 calc_die_sizes (dw_die_ref die
)
7885 gcc_assert (die
->die_offset
== 0
7886 || (unsigned long int) die
->die_offset
== next_die_offset
);
7887 die
->die_offset
= next_die_offset
;
7888 next_die_offset
+= size_of_die (die
);
7890 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7892 if (die
->die_child
!= NULL
)
7893 /* Count the null byte used to terminate sibling lists. */
7894 next_die_offset
+= 1;
7897 /* Size just the base type children at the start of the CU.
7898 This is needed because build_abbrev needs to size locs
7899 and sizing of type based stack ops needs to know die_offset
7900 values for the base types. */
7903 calc_base_type_die_sizes (void)
7905 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7907 dw_die_ref base_type
;
7908 #if ENABLE_ASSERT_CHECKING
7909 dw_die_ref prev
= comp_unit_die ()->die_child
;
7912 die_offset
+= size_of_die (comp_unit_die ());
7913 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7915 #if ENABLE_ASSERT_CHECKING
7916 gcc_assert (base_type
->die_offset
== 0
7917 && prev
->die_sib
== base_type
7918 && base_type
->die_child
== NULL
7919 && base_type
->die_abbrev
);
7922 base_type
->die_offset
= die_offset
;
7923 die_offset
+= size_of_die (base_type
);
7927 /* Set the marks for a die and its children. We do this so
7928 that we know whether or not a reference needs to use FORM_ref_addr; only
7929 DIEs in the same CU will be marked. We used to clear out the offset
7930 and use that as the flag, but ran into ordering problems. */
7933 mark_dies (dw_die_ref die
)
7937 gcc_assert (!die
->die_mark
);
7940 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7943 /* Clear the marks for a die and its children. */
7946 unmark_dies (dw_die_ref die
)
7950 if (! use_debug_types
)
7951 gcc_assert (die
->die_mark
);
7954 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7957 /* Clear the marks for a die, its children and referred dies. */
7960 unmark_all_dies (dw_die_ref die
)
7970 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7972 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7973 if (AT_class (a
) == dw_val_class_die_ref
)
7974 unmark_all_dies (AT_ref (a
));
7977 /* Calculate if the entry should appear in the final output file. It may be
7978 from a pruned a type. */
7981 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
7983 /* By limiting gnu pubnames to definitions only, gold can generate a
7984 gdb index without entries for declarations, which don't include
7985 enough information to be useful. */
7986 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
7989 if (table
== pubname_table
)
7991 /* Enumerator names are part of the pubname table, but the
7992 parent DW_TAG_enumeration_type die may have been pruned.
7993 Don't output them if that is the case. */
7994 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
7995 (p
->die
->die_parent
== NULL
7996 || !p
->die
->die_parent
->die_perennial_p
))
7999 /* Everything else in the pubname table is included. */
8003 /* The pubtypes table shouldn't include types that have been
8005 return (p
->die
->die_offset
!= 0
8006 || !flag_eliminate_unused_debug_types
);
8009 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8010 generated for the compilation unit. */
8012 static unsigned long
8013 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8018 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8020 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8021 FOR_EACH_VEC_ELT (*names
, i
, p
)
8022 if (include_pubname_in_output (names
, p
))
8023 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8025 size
+= DWARF_OFFSET_SIZE
;
8029 /* Return the size of the information in the .debug_aranges section. */
8031 static unsigned long
8032 size_of_aranges (void)
8036 size
= DWARF_ARANGES_HEADER_SIZE
;
8038 /* Count the address/length pair for this compilation unit. */
8039 if (text_section_used
)
8040 size
+= 2 * DWARF2_ADDR_SIZE
;
8041 if (cold_text_section_used
)
8042 size
+= 2 * DWARF2_ADDR_SIZE
;
8043 if (have_multiple_function_sections
)
8048 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8050 if (DECL_IGNORED_P (fde
->decl
))
8052 if (!fde
->in_std_section
)
8053 size
+= 2 * DWARF2_ADDR_SIZE
;
8054 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8055 size
+= 2 * DWARF2_ADDR_SIZE
;
8059 /* Count the two zero words used to terminated the address range table. */
8060 size
+= 2 * DWARF2_ADDR_SIZE
;
8064 /* Select the encoding of an attribute value. */
8066 static enum dwarf_form
8067 value_format (dw_attr_ref a
)
8069 switch (AT_class (a
))
8071 case dw_val_class_addr
:
8072 /* Only very few attributes allow DW_FORM_addr. */
8077 case DW_AT_entry_pc
:
8078 case DW_AT_trampoline
:
8079 return (AT_index (a
) == NOT_INDEXED
8080 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8084 switch (DWARF2_ADDR_SIZE
)
8087 return DW_FORM_data1
;
8089 return DW_FORM_data2
;
8091 return DW_FORM_data4
;
8093 return DW_FORM_data8
;
8097 case dw_val_class_range_list
:
8098 case dw_val_class_loc_list
:
8099 if (dwarf_version
>= 4)
8100 return DW_FORM_sec_offset
;
8102 case dw_val_class_vms_delta
:
8103 case dw_val_class_offset
:
8104 switch (DWARF_OFFSET_SIZE
)
8107 return DW_FORM_data4
;
8109 return DW_FORM_data8
;
8113 case dw_val_class_loc
:
8114 if (dwarf_version
>= 4)
8115 return DW_FORM_exprloc
;
8116 switch (constant_size (size_of_locs (AT_loc (a
))))
8119 return DW_FORM_block1
;
8121 return DW_FORM_block2
;
8123 return DW_FORM_block4
;
8127 case dw_val_class_const
:
8128 return DW_FORM_sdata
;
8129 case dw_val_class_unsigned_const
:
8130 switch (constant_size (AT_unsigned (a
)))
8133 return DW_FORM_data1
;
8135 return DW_FORM_data2
;
8137 /* In DWARF3 DW_AT_data_member_location with
8138 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8139 constant, so we need to use DW_FORM_udata if we need
8140 a large constant. */
8141 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8142 return DW_FORM_udata
;
8143 return DW_FORM_data4
;
8145 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8146 return DW_FORM_udata
;
8147 return DW_FORM_data8
;
8151 case dw_val_class_const_double
:
8152 switch (HOST_BITS_PER_WIDE_INT
)
8155 return DW_FORM_data2
;
8157 return DW_FORM_data4
;
8159 return DW_FORM_data8
;
8162 return DW_FORM_block1
;
8164 case dw_val_class_vec
:
8165 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8166 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8169 return DW_FORM_block1
;
8171 return DW_FORM_block2
;
8173 return DW_FORM_block4
;
8177 case dw_val_class_flag
:
8178 if (dwarf_version
>= 4)
8180 /* Currently all add_AT_flag calls pass in 1 as last argument,
8181 so DW_FORM_flag_present can be used. If that ever changes,
8182 we'll need to use DW_FORM_flag and have some optimization
8183 in build_abbrev_table that will change those to
8184 DW_FORM_flag_present if it is set to 1 in all DIEs using
8185 the same abbrev entry. */
8186 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8187 return DW_FORM_flag_present
;
8189 return DW_FORM_flag
;
8190 case dw_val_class_die_ref
:
8191 if (AT_ref_external (a
))
8192 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8195 case dw_val_class_fde_ref
:
8196 return DW_FORM_data
;
8197 case dw_val_class_lbl_id
:
8198 return (AT_index (a
) == NOT_INDEXED
8199 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8200 case dw_val_class_lineptr
:
8201 case dw_val_class_macptr
:
8202 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8203 case dw_val_class_str
:
8204 return AT_string_form (a
);
8205 case dw_val_class_file
:
8206 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8209 return DW_FORM_data1
;
8211 return DW_FORM_data2
;
8213 return DW_FORM_data4
;
8218 case dw_val_class_data8
:
8219 return DW_FORM_data8
;
8221 case dw_val_class_high_pc
:
8222 switch (DWARF2_ADDR_SIZE
)
8225 return DW_FORM_data1
;
8227 return DW_FORM_data2
;
8229 return DW_FORM_data4
;
8231 return DW_FORM_data8
;
8241 /* Output the encoding of an attribute value. */
8244 output_value_format (dw_attr_ref a
)
8246 enum dwarf_form form
= value_format (a
);
8248 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8251 /* Given a die and id, produce the appropriate abbreviations. */
8254 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8259 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8260 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8261 dwarf_tag_name (abbrev
->die_tag
));
8263 if (abbrev
->die_child
!= NULL
)
8264 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8266 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8268 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8270 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8271 dwarf_attr_name (a_attr
->dw_attr
));
8272 output_value_format (a_attr
);
8275 dw2_asm_output_data (1, 0, NULL
);
8276 dw2_asm_output_data (1, 0, NULL
);
8280 /* Output the .debug_abbrev section which defines the DIE abbreviation
8284 output_abbrev_section (void)
8286 unsigned long abbrev_id
;
8288 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8289 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8291 /* Terminate the table. */
8292 dw2_asm_output_data (1, 0, NULL
);
8295 /* Output a symbol we can use to refer to this DIE from another CU. */
8298 output_die_symbol (dw_die_ref die
)
8300 const char *sym
= die
->die_id
.die_symbol
;
8302 gcc_assert (!die
->comdat_type_p
);
8307 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8308 /* We make these global, not weak; if the target doesn't support
8309 .linkonce, it doesn't support combining the sections, so debugging
8311 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8313 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8316 /* Return a new location list, given the begin and end range, and the
8319 static inline dw_loc_list_ref
8320 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8321 const char *section
)
8323 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8325 retlist
->begin
= begin
;
8326 retlist
->begin_entry
= NULL
;
8328 retlist
->expr
= expr
;
8329 retlist
->section
= section
;
8334 /* Generate a new internal symbol for this location list node, if it
8335 hasn't got one yet. */
8338 gen_llsym (dw_loc_list_ref list
)
8340 gcc_assert (!list
->ll_symbol
);
8341 list
->ll_symbol
= gen_internal_sym ("LLST");
8344 /* Output the location list given to us. */
8347 output_loc_list (dw_loc_list_ref list_head
)
8349 dw_loc_list_ref curr
= list_head
;
8351 if (list_head
->emitted
)
8353 list_head
->emitted
= true;
8355 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8357 /* Walk the location list, and output each range + expression. */
8358 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8361 /* Don't output an entry that starts and ends at the same address. */
8362 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8364 size
= size_of_locs (curr
->expr
);
8365 /* If the expression is too large, drop it on the floor. We could
8366 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8367 in the expression, but >= 64KB expressions for a single value
8368 in a single range are unlikely very useful. */
8371 if (dwarf_split_debug_info
)
8373 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8374 "Location list start/length entry (%s)",
8375 list_head
->ll_symbol
);
8376 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8377 "Location list range start index (%s)",
8379 /* The length field is 4 bytes. If we ever need to support
8380 an 8-byte length, we can add a new DW_LLE code or fall back
8381 to DW_LLE_GNU_start_end_entry. */
8382 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8383 "Location list range length (%s)",
8384 list_head
->ll_symbol
);
8386 else if (!have_multiple_function_sections
)
8388 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8389 "Location list begin address (%s)",
8390 list_head
->ll_symbol
);
8391 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8392 "Location list end address (%s)",
8393 list_head
->ll_symbol
);
8397 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8398 "Location list begin address (%s)",
8399 list_head
->ll_symbol
);
8400 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8401 "Location list end address (%s)",
8402 list_head
->ll_symbol
);
8405 /* Output the block length for this list of location operations. */
8406 gcc_assert (size
<= 0xffff);
8407 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8409 output_loc_sequence (curr
->expr
, -1);
8412 if (dwarf_split_debug_info
)
8413 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8414 "Location list terminator (%s)",
8415 list_head
->ll_symbol
);
8418 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8419 "Location list terminator begin (%s)",
8420 list_head
->ll_symbol
);
8421 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8422 "Location list terminator end (%s)",
8423 list_head
->ll_symbol
);
8427 /* Output a range_list offset into the debug_range section. Emit a
8428 relocated reference if val_entry is NULL, otherwise, emit an
8429 indirect reference. */
8432 output_range_list_offset (dw_attr_ref a
)
8434 const char *name
= dwarf_attr_name (a
->dw_attr
);
8436 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8438 char *p
= strchr (ranges_section_label
, '\0');
8439 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8440 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8441 debug_ranges_section
, "%s", name
);
8445 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8446 "%s (offset from %s)", name
, ranges_section_label
);
8449 /* Output the offset into the debug_loc section. */
8452 output_loc_list_offset (dw_attr_ref a
)
8454 char *sym
= AT_loc_list (a
)->ll_symbol
;
8457 if (dwarf_split_debug_info
)
8458 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8459 "%s", dwarf_attr_name (a
->dw_attr
));
8461 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8462 "%s", dwarf_attr_name (a
->dw_attr
));
8465 /* Output an attribute's index or value appropriately. */
8468 output_attr_index_or_value (dw_attr_ref a
)
8470 const char *name
= dwarf_attr_name (a
->dw_attr
);
8472 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8474 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8477 switch (AT_class (a
))
8479 case dw_val_class_addr
:
8480 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8482 case dw_val_class_high_pc
:
8483 case dw_val_class_lbl_id
:
8484 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8486 case dw_val_class_loc_list
:
8487 output_loc_list_offset (a
);
8494 /* Output a type signature. */
8497 output_signature (const char *sig
, const char *name
)
8501 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8502 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8505 /* Output the DIE and its attributes. Called recursively to generate
8506 the definitions of each child DIE. */
8509 output_die (dw_die_ref die
)
8516 /* If someone in another CU might refer to us, set up a symbol for
8517 them to point to. */
8518 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8519 output_die_symbol (die
);
8521 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8522 (unsigned long)die
->die_offset
,
8523 dwarf_tag_name (die
->die_tag
));
8525 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8527 const char *name
= dwarf_attr_name (a
->dw_attr
);
8529 switch (AT_class (a
))
8531 case dw_val_class_addr
:
8532 output_attr_index_or_value (a
);
8535 case dw_val_class_offset
:
8536 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8540 case dw_val_class_range_list
:
8541 output_range_list_offset (a
);
8544 case dw_val_class_loc
:
8545 size
= size_of_locs (AT_loc (a
));
8547 /* Output the block length for this list of location operations. */
8548 if (dwarf_version
>= 4)
8549 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8551 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8553 output_loc_sequence (AT_loc (a
), -1);
8556 case dw_val_class_const
:
8557 /* ??? It would be slightly more efficient to use a scheme like is
8558 used for unsigned constants below, but gdb 4.x does not sign
8559 extend. Gdb 5.x does sign extend. */
8560 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8563 case dw_val_class_unsigned_const
:
8565 int csize
= constant_size (AT_unsigned (a
));
8566 if (dwarf_version
== 3
8567 && a
->dw_attr
== DW_AT_data_member_location
8569 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8571 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8575 case dw_val_class_const_double
:
8577 unsigned HOST_WIDE_INT first
, second
;
8579 if (HOST_BITS_PER_WIDE_INT
>= 64)
8580 dw2_asm_output_data (1,
8581 HOST_BITS_PER_DOUBLE_INT
8582 / HOST_BITS_PER_CHAR
,
8585 if (WORDS_BIG_ENDIAN
)
8587 first
= a
->dw_attr_val
.v
.val_double
.high
;
8588 second
= a
->dw_attr_val
.v
.val_double
.low
;
8592 first
= a
->dw_attr_val
.v
.val_double
.low
;
8593 second
= a
->dw_attr_val
.v
.val_double
.high
;
8596 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8598 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8603 case dw_val_class_vec
:
8605 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8606 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8610 dw2_asm_output_data (constant_size (len
* elt_size
),
8611 len
* elt_size
, "%s", name
);
8612 if (elt_size
> sizeof (HOST_WIDE_INT
))
8617 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8620 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8621 "fp or vector constant word %u", i
);
8625 case dw_val_class_flag
:
8626 if (dwarf_version
>= 4)
8628 /* Currently all add_AT_flag calls pass in 1 as last argument,
8629 so DW_FORM_flag_present can be used. If that ever changes,
8630 we'll need to use DW_FORM_flag and have some optimization
8631 in build_abbrev_table that will change those to
8632 DW_FORM_flag_present if it is set to 1 in all DIEs using
8633 the same abbrev entry. */
8634 gcc_assert (AT_flag (a
) == 1);
8636 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8637 ASM_COMMENT_START
, name
);
8640 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8643 case dw_val_class_loc_list
:
8644 output_attr_index_or_value (a
);
8647 case dw_val_class_die_ref
:
8648 if (AT_ref_external (a
))
8650 if (AT_ref (a
)->comdat_type_p
)
8652 comdat_type_node_ref type_node
=
8653 AT_ref (a
)->die_id
.die_type_node
;
8655 gcc_assert (type_node
);
8656 output_signature (type_node
->signature
, name
);
8660 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8664 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8665 length, whereas in DWARF3 it's always sized as an
8667 if (dwarf_version
== 2)
8668 size
= DWARF2_ADDR_SIZE
;
8670 size
= DWARF_OFFSET_SIZE
;
8671 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8677 gcc_assert (AT_ref (a
)->die_offset
);
8678 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8683 case dw_val_class_fde_ref
:
8687 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8688 a
->dw_attr_val
.v
.val_fde_index
* 2);
8689 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8694 case dw_val_class_vms_delta
:
8695 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8696 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8700 case dw_val_class_lbl_id
:
8701 output_attr_index_or_value (a
);
8704 case dw_val_class_lineptr
:
8705 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8706 debug_line_section
, "%s", name
);
8709 case dw_val_class_macptr
:
8710 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8711 debug_macinfo_section
, "%s", name
);
8714 case dw_val_class_str
:
8715 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8716 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8717 a
->dw_attr_val
.v
.val_str
->label
,
8719 "%s: \"%s\"", name
, AT_string (a
));
8720 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8721 dw2_asm_output_data_uleb128 (AT_index (a
),
8722 "%s: \"%s\"", name
, AT_string (a
));
8724 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8727 case dw_val_class_file
:
8729 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8731 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8732 a
->dw_attr_val
.v
.val_file
->filename
);
8736 case dw_val_class_data8
:
8740 for (i
= 0; i
< 8; i
++)
8741 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8742 i
== 0 ? "%s" : NULL
, name
);
8746 case dw_val_class_high_pc
:
8747 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8748 get_AT_low_pc (die
), "DW_AT_high_pc");
8756 FOR_EACH_CHILD (die
, c
, output_die (c
));
8758 /* Add null byte to terminate sibling list. */
8759 if (die
->die_child
!= NULL
)
8760 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8761 (unsigned long) die
->die_offset
);
8764 /* Output the compilation unit that appears at the beginning of the
8765 .debug_info section, and precedes the DIE descriptions. */
8768 output_compilation_unit_header (void)
8770 int ver
= dwarf_version
;
8772 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8773 dw2_asm_output_data (4, 0xffffffff,
8774 "Initial length escape value indicating 64-bit DWARF extension");
8775 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8776 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8777 "Length of Compilation Unit Info");
8778 dw2_asm_output_data (2, ver
, "DWARF version number");
8779 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8780 debug_abbrev_section
,
8781 "Offset Into Abbrev. Section");
8782 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8785 /* Output the compilation unit DIE and its children. */
8788 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8790 const char *secname
, *oldsym
;
8792 external_ref_hash_type extern_map
;
8794 /* Unless we are outputting main CU, we may throw away empty ones. */
8795 if (!output_if_empty
&& die
->die_child
== NULL
)
8798 /* Even if there are no children of this DIE, we must output the information
8799 about the compilation unit. Otherwise, on an empty translation unit, we
8800 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8801 will then complain when examining the file. First mark all the DIEs in
8802 this CU so we know which get local refs. */
8805 extern_map
= optimize_external_refs (die
);
8807 build_abbrev_table (die
, extern_map
);
8809 extern_map
.dispose ();
8811 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8812 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8813 calc_die_sizes (die
);
8815 oldsym
= die
->die_id
.die_symbol
;
8818 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8820 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8822 die
->die_id
.die_symbol
= NULL
;
8823 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8827 switch_to_section (debug_info_section
);
8828 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8829 info_section_emitted
= true;
8832 /* Output debugging information. */
8833 output_compilation_unit_header ();
8836 /* Leave the marks on the main CU, so we can check them in
8841 die
->die_id
.die_symbol
= oldsym
;
8845 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8846 and .debug_pubtypes. This is configured per-target, but can be
8847 overridden by the -gpubnames or -gno-pubnames options. */
8850 want_pubnames (void)
8852 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8854 if (debug_generate_pub_sections
!= -1)
8855 return debug_generate_pub_sections
;
8856 return targetm
.want_debug_pub_sections
;
8859 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8862 add_AT_pubnames (dw_die_ref die
)
8864 if (want_pubnames ())
8865 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8868 /* Add a string attribute value to a skeleton DIE. */
8871 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8875 struct indirect_string_node
*node
;
8877 if (! skeleton_debug_str_hash
)
8878 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
8879 debug_str_eq
, NULL
);
8881 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
8882 find_string_form (node
);
8883 if (node
->form
== DW_FORM_GNU_str_index
)
8884 node
->form
= DW_FORM_strp
;
8886 attr
.dw_attr
= attr_kind
;
8887 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
8888 attr
.dw_attr_val
.val_entry
= NULL
;
8889 attr
.dw_attr_val
.v
.val_str
= node
;
8890 add_dwarf_attr (die
, &attr
);
8893 /* Helper function to generate top-level dies for skeleton debug_info and
8897 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8899 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8900 const char *comp_dir
= comp_dir_string ();
8902 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8903 if (comp_dir
!= NULL
)
8904 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
8905 add_AT_pubnames (die
);
8906 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8909 /* Return the single type-unit die for skeleton type units. */
8912 get_skeleton_type_unit (void)
8914 /* For dwarf_split_debug_sections with use_type info, all type units in the
8915 skeleton sections have identical dies (but different headers). This
8916 single die will be output many times. */
8918 static dw_die_ref skeleton_type_unit
= NULL
;
8920 if (skeleton_type_unit
== NULL
)
8922 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8923 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8924 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8926 return skeleton_type_unit
;
8929 /* Output skeleton debug sections that point to the dwo file. */
8932 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8934 /* These attributes will be found in the full debug_info section. */
8935 remove_AT (comp_unit
, DW_AT_producer
);
8936 remove_AT (comp_unit
, DW_AT_language
);
8938 switch_to_section (debug_skeleton_info_section
);
8939 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8941 /* Produce the skeleton compilation-unit header. This one differs enough from
8942 a normal CU header that it's better not to call output_compilation_unit
8944 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8945 dw2_asm_output_data (4, 0xffffffff,
8946 "Initial length escape value indicating 64-bit DWARF extension");
8948 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8949 DWARF_COMPILE_UNIT_HEADER_SIZE
8950 - DWARF_INITIAL_LENGTH_SIZE
8951 + size_of_die (comp_unit
),
8952 "Length of Compilation Unit Info");
8953 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8954 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8955 debug_abbrev_section
,
8956 "Offset Into Abbrev. Section");
8957 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8959 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8960 output_die (comp_unit
);
8962 /* Build the skeleton debug_abbrev section. */
8963 switch_to_section (debug_skeleton_abbrev_section
);
8964 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8966 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8967 if (use_debug_types
)
8968 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8970 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8973 /* Output a comdat type unit DIE and its children. */
8976 output_comdat_type_unit (comdat_type_node
*node
)
8978 const char *secname
;
8981 #if defined (OBJECT_FORMAT_ELF)
8984 external_ref_hash_type extern_map
;
8986 /* First mark all the DIEs in this CU so we know which get local refs. */
8987 mark_dies (node
->root_die
);
8989 extern_map
= optimize_external_refs (node
->root_die
);
8991 build_abbrev_table (node
->root_die
, extern_map
);
8993 extern_map
.dispose ();
8995 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8996 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8997 calc_die_sizes (node
->root_die
);
8999 #if defined (OBJECT_FORMAT_ELF)
9000 if (!dwarf_split_debug_info
)
9001 secname
= ".debug_types";
9003 secname
= ".debug_types.dwo";
9005 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9006 sprintf (tmp
, "wt.");
9007 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9008 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9009 comdat_key
= get_identifier (tmp
);
9010 targetm
.asm_out
.named_section (secname
,
9011 SECTION_DEBUG
| SECTION_LINKONCE
,
9014 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9015 sprintf (tmp
, ".gnu.linkonce.wt.");
9016 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9017 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9019 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9022 /* Output debugging information. */
9023 output_compilation_unit_header ();
9024 output_signature (node
->signature
, "Type Signature");
9025 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9026 "Offset to Type DIE");
9027 output_die (node
->root_die
);
9029 unmark_dies (node
->root_die
);
9031 #if defined (OBJECT_FORMAT_ELF)
9032 if (dwarf_split_debug_info
)
9034 /* Produce the skeleton type-unit header. */
9035 const char *secname
= ".debug_types";
9037 targetm
.asm_out
.named_section (secname
,
9038 SECTION_DEBUG
| SECTION_LINKONCE
,
9040 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9041 dw2_asm_output_data (4, 0xffffffff,
9042 "Initial length escape value indicating 64-bit DWARF extension");
9044 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9045 DWARF_COMPILE_UNIT_HEADER_SIZE
9046 - DWARF_INITIAL_LENGTH_SIZE
9047 + size_of_die (get_skeleton_type_unit ())
9048 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
9049 "Length of Type Unit Info");
9050 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9051 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9052 debug_skeleton_abbrev_section_label
,
9053 debug_abbrev_section
,
9054 "Offset Into Abbrev. Section");
9055 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9056 output_signature (node
->signature
, "Type Signature");
9057 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
9059 output_die (get_skeleton_type_unit ());
9064 /* Return the DWARF2/3 pubname associated with a decl. */
9067 dwarf2_name (tree decl
, int scope
)
9069 if (DECL_NAMELESS (decl
))
9071 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9074 /* Add a new entry to .debug_pubnames if appropriate. */
9077 add_pubname_string (const char *str
, dw_die_ref die
)
9082 e
.name
= xstrdup (str
);
9083 vec_safe_push (pubname_table
, e
);
9087 add_pubname (tree decl
, dw_die_ref die
)
9089 if (!want_pubnames ())
9092 /* Don't add items to the table when we expect that the consumer will have
9093 just read the enclosing die. For example, if the consumer is looking at a
9094 class_member, it will either be inside the class already, or will have just
9095 looked up the class to find the member. Either way, searching the class is
9096 faster than searching the index. */
9097 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9098 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9100 const char *name
= dwarf2_name (decl
, 1);
9103 add_pubname_string (name
, die
);
9107 /* Add an enumerator to the pubnames section. */
9110 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9114 gcc_assert (scope_name
);
9115 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9117 vec_safe_push (pubname_table
, e
);
9120 /* Add a new entry to .debug_pubtypes if appropriate. */
9123 add_pubtype (tree decl
, dw_die_ref die
)
9127 if (!want_pubnames ())
9130 if ((TREE_PUBLIC (decl
)
9131 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9132 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9135 const char *scope_name
= "";
9136 const char *sep
= is_cxx () ? "::" : ".";
9139 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9140 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9142 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9143 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9144 scope_name
= concat (scope_name
, sep
, NULL
);
9150 name
= type_tag (decl
);
9152 name
= lang_hooks
.dwarf_name (decl
, 1);
9154 /* If we don't have a name for the type, there's no point in adding
9156 if (name
!= NULL
&& name
[0] != '\0')
9159 e
.name
= concat (scope_name
, name
, NULL
);
9160 vec_safe_push (pubtype_table
, e
);
9163 /* Although it might be more consistent to add the pubinfo for the
9164 enumerators as their dies are created, they should only be added if the
9165 enum type meets the criteria above. So rather than re-check the parent
9166 enum type whenever an enumerator die is created, just output them all
9167 here. This isn't protected by the name conditional because anonymous
9168 enums don't have names. */
9169 if (die
->die_tag
== DW_TAG_enumeration_type
)
9173 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9178 /* Output a single entry in the pubnames table. */
9181 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9183 dw_die_ref die
= entry
->die
;
9184 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9186 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9188 if (debug_generate_pub_sections
== 2)
9190 /* This logic follows gdb's method for determining the value of the flag
9192 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9193 switch (die
->die_tag
)
9195 case DW_TAG_typedef
:
9196 case DW_TAG_base_type
:
9197 case DW_TAG_subrange_type
:
9198 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9199 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9201 case DW_TAG_enumerator
:
9202 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9203 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9204 if (!is_cxx () && !is_java ())
9205 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9207 case DW_TAG_subprogram
:
9208 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9209 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9211 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9213 case DW_TAG_constant
:
9214 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9215 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9216 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9218 case DW_TAG_variable
:
9219 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9220 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9221 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9223 case DW_TAG_namespace
:
9224 case DW_TAG_imported_declaration
:
9225 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9227 case DW_TAG_class_type
:
9228 case DW_TAG_interface_type
:
9229 case DW_TAG_structure_type
:
9230 case DW_TAG_union_type
:
9231 case DW_TAG_enumeration_type
:
9232 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9233 if (!is_cxx () && !is_java ())
9234 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9237 /* An unusual tag. Leave the flag-byte empty. */
9240 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9244 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9248 /* Output the public names table used to speed up access to externally
9249 visible names; or the public types table used to find type definitions. */
9252 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9255 unsigned long pubnames_length
= size_of_pubnames (names
);
9258 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9259 dw2_asm_output_data (4, 0xffffffff,
9260 "Initial length escape value indicating 64-bit DWARF extension");
9261 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9263 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9264 dw2_asm_output_data (2, 2, "DWARF Version");
9266 if (dwarf_split_debug_info
)
9267 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9268 debug_skeleton_info_section
,
9269 "Offset of Compilation Unit Info");
9271 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9273 "Offset of Compilation Unit Info");
9274 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9275 "Compilation Unit Length");
9277 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9279 if (include_pubname_in_output (names
, pub
))
9281 dw_offset die_offset
= pub
->die
->die_offset
;
9283 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9284 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9285 gcc_assert (pub
->die
->die_mark
);
9287 /* If we're putting types in their own .debug_types sections,
9288 the .debug_pubtypes table will still point to the compile
9289 unit (not the type unit), so we want to use the offset of
9290 the skeleton DIE (if there is one). */
9291 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9293 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9295 if (type_node
!= NULL
)
9296 die_offset
= (type_node
->skeleton_die
!= NULL
9297 ? type_node
->skeleton_die
->die_offset
9301 output_pubname (die_offset
, pub
);
9305 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9308 /* Output public names and types tables if necessary. */
9311 output_pubtables (void)
9313 if (!want_pubnames () || !info_section_emitted
)
9316 switch_to_section (debug_pubnames_section
);
9317 output_pubnames (pubname_table
);
9318 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9319 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9320 simply won't look for the section. */
9321 switch_to_section (debug_pubtypes_section
);
9322 output_pubnames (pubtype_table
);
9326 /* Output the information that goes into the .debug_aranges table.
9327 Namely, define the beginning and ending address range of the
9328 text section generated for this compilation unit. */
9331 output_aranges (unsigned long aranges_length
)
9335 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9336 dw2_asm_output_data (4, 0xffffffff,
9337 "Initial length escape value indicating 64-bit DWARF extension");
9338 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9339 "Length of Address Ranges Info");
9340 /* Version number for aranges is still 2, even in DWARF3. */
9341 dw2_asm_output_data (2, 2, "DWARF Version");
9342 if (dwarf_split_debug_info
)
9343 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9344 debug_skeleton_info_section
,
9345 "Offset of Compilation Unit Info");
9347 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9349 "Offset of Compilation Unit Info");
9350 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9351 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9353 /* We need to align to twice the pointer size here. */
9354 if (DWARF_ARANGES_PAD_SIZE
)
9356 /* Pad using a 2 byte words so that padding is correct for any
9358 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9359 2 * DWARF2_ADDR_SIZE
);
9360 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9361 dw2_asm_output_data (2, 0, NULL
);
9364 /* It is necessary not to output these entries if the sections were
9365 not used; if the sections were not used, the length will be 0 and
9366 the address may end up as 0 if the section is discarded by ld
9367 --gc-sections, leaving an invalid (0, 0) entry that can be
9368 confused with the terminator. */
9369 if (text_section_used
)
9371 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9372 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9373 text_section_label
, "Length");
9375 if (cold_text_section_used
)
9377 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9379 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9380 cold_text_section_label
, "Length");
9383 if (have_multiple_function_sections
)
9388 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9390 if (DECL_IGNORED_P (fde
->decl
))
9392 if (!fde
->in_std_section
)
9394 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9396 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9397 fde
->dw_fde_begin
, "Length");
9399 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9401 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9403 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9404 fde
->dw_fde_second_begin
, "Length");
9409 /* Output the terminator words. */
9410 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9411 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9414 /* Add a new entry to .debug_ranges. Return the offset at which it
9418 add_ranges_num (int num
)
9420 unsigned int in_use
= ranges_table_in_use
;
9422 if (in_use
== ranges_table_allocated
)
9424 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9425 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9426 ranges_table_allocated
);
9427 memset (ranges_table
+ ranges_table_in_use
, 0,
9428 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9431 ranges_table
[in_use
].num
= num
;
9432 ranges_table_in_use
= in_use
+ 1;
9434 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9437 /* Add a new entry to .debug_ranges corresponding to a block, or a
9438 range terminator if BLOCK is NULL. */
9441 add_ranges (const_tree block
)
9443 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9446 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9447 When using dwarf_split_debug_info, address attributes in dies destined
9448 for the final executable should be direct references--setting the
9449 parameter force_direct ensures this behavior. */
9452 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9453 bool *added
, bool force_direct
)
9455 unsigned int in_use
= ranges_by_label_in_use
;
9456 unsigned int offset
;
9458 if (in_use
== ranges_by_label_allocated
)
9460 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9461 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9463 ranges_by_label_allocated
);
9464 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9465 RANGES_TABLE_INCREMENT
9466 * sizeof (struct dw_ranges_by_label_struct
));
9469 ranges_by_label
[in_use
].begin
= begin
;
9470 ranges_by_label
[in_use
].end
= end
;
9471 ranges_by_label_in_use
= in_use
+ 1;
9473 offset
= add_ranges_num (-(int)in_use
- 1);
9476 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9482 output_ranges (void)
9485 static const char *const start_fmt
= "Offset %#x";
9486 const char *fmt
= start_fmt
;
9488 for (i
= 0; i
< ranges_table_in_use
; i
++)
9490 int block_num
= ranges_table
[i
].num
;
9494 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9495 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9497 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9498 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9500 /* If all code is in the text section, then the compilation
9501 unit base address defaults to DW_AT_low_pc, which is the
9502 base of the text section. */
9503 if (!have_multiple_function_sections
)
9505 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9507 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9508 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9509 text_section_label
, NULL
);
9512 /* Otherwise, the compilation unit base address is zero,
9513 which allows us to use absolute addresses, and not worry
9514 about whether the target supports cross-section
9518 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9519 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9520 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9526 /* Negative block_num stands for an index into ranges_by_label. */
9527 else if (block_num
< 0)
9529 int lab_idx
= - block_num
- 1;
9531 if (!have_multiple_function_sections
)
9535 /* If we ever use add_ranges_by_labels () for a single
9536 function section, all we have to do is to take out
9538 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9539 ranges_by_label
[lab_idx
].begin
,
9541 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9542 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9543 ranges_by_label
[lab_idx
].end
,
9544 text_section_label
, NULL
);
9549 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9550 ranges_by_label
[lab_idx
].begin
,
9551 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9552 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9553 ranges_by_label
[lab_idx
].end
,
9559 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9560 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9566 /* Data structure containing information about input files. */
9569 const char *path
; /* Complete file name. */
9570 const char *fname
; /* File name part. */
9571 int length
; /* Length of entire string. */
9572 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9573 int dir_idx
; /* Index in directory table. */
9576 /* Data structure containing information about directories with source
9580 const char *path
; /* Path including directory name. */
9581 int length
; /* Path length. */
9582 int prefix
; /* Index of directory entry which is a prefix. */
9583 int count
; /* Number of files in this directory. */
9584 int dir_idx
; /* Index of directory used as base. */
9587 /* Callback function for file_info comparison. We sort by looking at
9588 the directories in the path. */
9591 file_info_cmp (const void *p1
, const void *p2
)
9593 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9594 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9595 const unsigned char *cp1
;
9596 const unsigned char *cp2
;
9598 /* Take care of file names without directories. We need to make sure that
9599 we return consistent values to qsort since some will get confused if
9600 we return the same value when identical operands are passed in opposite
9601 orders. So if neither has a directory, return 0 and otherwise return
9602 1 or -1 depending on which one has the directory. */
9603 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9604 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9606 cp1
= (const unsigned char *) s1
->path
;
9607 cp2
= (const unsigned char *) s2
->path
;
9613 /* Reached the end of the first path? If so, handle like above. */
9614 if ((cp1
== (const unsigned char *) s1
->fname
)
9615 || (cp2
== (const unsigned char *) s2
->fname
))
9616 return ((cp2
== (const unsigned char *) s2
->fname
)
9617 - (cp1
== (const unsigned char *) s1
->fname
));
9619 /* Character of current path component the same? */
9620 else if (*cp1
!= *cp2
)
9625 struct file_name_acquire_data
9627 struct file_info
*files
;
9632 /* Traversal function for the hash table. */
9635 file_name_acquire (void ** slot
, void *data
)
9637 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9638 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9639 struct file_info
*fi
;
9642 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9644 if (! d
->emitted_number
)
9647 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9649 fi
= fnad
->files
+ fnad
->used_files
++;
9651 /* Skip all leading "./". */
9653 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9656 /* Create a new array entry. */
9658 fi
->length
= strlen (f
);
9661 /* Search for the file name part. */
9662 f
= strrchr (f
, DIR_SEPARATOR
);
9663 #if defined (DIR_SEPARATOR_2)
9665 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9669 if (f
== NULL
|| f
< g
)
9675 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9679 /* Output the directory table and the file name table. We try to minimize
9680 the total amount of memory needed. A heuristic is used to avoid large
9681 slowdowns with many input files. */
9684 output_file_names (void)
9686 struct file_name_acquire_data fnad
;
9688 struct file_info
*files
;
9689 struct dir_info
*dirs
;
9697 if (!last_emitted_file
)
9699 dw2_asm_output_data (1, 0, "End directory table");
9700 dw2_asm_output_data (1, 0, "End file name table");
9704 numfiles
= last_emitted_file
->emitted_number
;
9706 /* Allocate the various arrays we need. */
9707 files
= XALLOCAVEC (struct file_info
, numfiles
);
9708 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9711 fnad
.used_files
= 0;
9712 fnad
.max_files
= numfiles
;
9713 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9714 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9716 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9718 /* Find all the different directories used. */
9719 dirs
[0].path
= files
[0].path
;
9720 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9721 dirs
[0].prefix
= -1;
9723 dirs
[0].dir_idx
= 0;
9724 files
[0].dir_idx
= 0;
9727 for (i
= 1; i
< numfiles
; i
++)
9728 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9729 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9730 dirs
[ndirs
- 1].length
) == 0)
9732 /* Same directory as last entry. */
9733 files
[i
].dir_idx
= ndirs
- 1;
9734 ++dirs
[ndirs
- 1].count
;
9740 /* This is a new directory. */
9741 dirs
[ndirs
].path
= files
[i
].path
;
9742 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9743 dirs
[ndirs
].count
= 1;
9744 dirs
[ndirs
].dir_idx
= ndirs
;
9745 files
[i
].dir_idx
= ndirs
;
9747 /* Search for a prefix. */
9748 dirs
[ndirs
].prefix
= -1;
9749 for (j
= 0; j
< ndirs
; j
++)
9750 if (dirs
[j
].length
< dirs
[ndirs
].length
9751 && dirs
[j
].length
> 1
9752 && (dirs
[ndirs
].prefix
== -1
9753 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9754 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9755 dirs
[ndirs
].prefix
= j
;
9760 /* Now to the actual work. We have to find a subset of the directories which
9761 allow expressing the file name using references to the directory table
9762 with the least amount of characters. We do not do an exhaustive search
9763 where we would have to check out every combination of every single
9764 possible prefix. Instead we use a heuristic which provides nearly optimal
9765 results in most cases and never is much off. */
9766 saved
= XALLOCAVEC (int, ndirs
);
9767 savehere
= XALLOCAVEC (int, ndirs
);
9769 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9770 for (i
= 0; i
< ndirs
; i
++)
9775 /* We can always save some space for the current directory. But this
9776 does not mean it will be enough to justify adding the directory. */
9777 savehere
[i
] = dirs
[i
].length
;
9778 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9780 for (j
= i
+ 1; j
< ndirs
; j
++)
9783 if (saved
[j
] < dirs
[i
].length
)
9785 /* Determine whether the dirs[i] path is a prefix of the
9790 while (k
!= -1 && k
!= (int) i
)
9795 /* Yes it is. We can possibly save some memory by
9796 writing the filenames in dirs[j] relative to
9798 savehere
[j
] = dirs
[i
].length
;
9799 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9804 /* Check whether we can save enough to justify adding the dirs[i]
9806 if (total
> dirs
[i
].length
+ 1)
9808 /* It's worthwhile adding. */
9809 for (j
= i
; j
< ndirs
; j
++)
9810 if (savehere
[j
] > 0)
9812 /* Remember how much we saved for this directory so far. */
9813 saved
[j
] = savehere
[j
];
9815 /* Remember the prefix directory. */
9816 dirs
[j
].dir_idx
= i
;
9821 /* Emit the directory name table. */
9822 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9823 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9824 dw2_asm_output_nstring (dirs
[i
].path
,
9826 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9827 "Directory Entry: %#x", i
+ idx_offset
);
9829 dw2_asm_output_data (1, 0, "End directory table");
9831 /* We have to emit them in the order of emitted_number since that's
9832 used in the debug info generation. To do this efficiently we
9833 generate a back-mapping of the indices first. */
9834 backmap
= XALLOCAVEC (int, numfiles
);
9835 for (i
= 0; i
< numfiles
; i
++)
9836 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9838 /* Now write all the file names. */
9839 for (i
= 0; i
< numfiles
; i
++)
9841 int file_idx
= backmap
[i
];
9842 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9844 #ifdef VMS_DEBUGGING_INFO
9845 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9847 /* Setting these fields can lead to debugger miscomparisons,
9848 but VMS Debug requires them to be set correctly. */
9853 int maxfilelen
= strlen (files
[file_idx
].path
)
9854 + dirs
[dir_idx
].length
9855 + MAX_VMS_VERSION_LEN
+ 1;
9856 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9858 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9859 snprintf (filebuf
, maxfilelen
, "%s;%d",
9860 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9862 dw2_asm_output_nstring
9863 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9865 /* Include directory index. */
9866 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9868 /* Modification time. */
9869 dw2_asm_output_data_uleb128
9870 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9874 /* File length in bytes. */
9875 dw2_asm_output_data_uleb128
9876 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9880 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9881 "File Entry: %#x", (unsigned) i
+ 1);
9883 /* Include directory index. */
9884 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9886 /* Modification time. */
9887 dw2_asm_output_data_uleb128 (0, NULL
);
9889 /* File length in bytes. */
9890 dw2_asm_output_data_uleb128 (0, NULL
);
9891 #endif /* VMS_DEBUGGING_INFO */
9894 dw2_asm_output_data (1, 0, "End file name table");
9898 /* Output one line number table into the .debug_line section. */
9901 output_one_line_info_table (dw_line_info_table
*table
)
9903 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9904 unsigned int current_line
= 1;
9905 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9906 dw_line_info_entry
*ent
;
9909 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9911 switch (ent
->opcode
)
9913 case LI_set_address
:
9914 /* ??? Unfortunately, we have little choice here currently, and
9915 must always use the most general form. GCC does not know the
9916 address delta itself, so we can't use DW_LNS_advance_pc. Many
9917 ports do have length attributes which will give an upper bound
9918 on the address range. We could perhaps use length attributes
9919 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9920 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9922 /* This can handle any delta. This takes
9923 4+DWARF2_ADDR_SIZE bytes. */
9924 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9925 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9926 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9927 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9931 if (ent
->val
== current_line
)
9933 /* We still need to start a new row, so output a copy insn. */
9934 dw2_asm_output_data (1, DW_LNS_copy
,
9935 "copy line %u", current_line
);
9939 int line_offset
= ent
->val
- current_line
;
9940 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9942 current_line
= ent
->val
;
9943 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9945 /* This can handle deltas from -10 to 234, using the current
9946 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9947 This takes 1 byte. */
9948 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9949 "line %u", current_line
);
9953 /* This can handle any delta. This takes at least 4 bytes,
9954 depending on the value being encoded. */
9955 dw2_asm_output_data (1, DW_LNS_advance_line
,
9956 "advance to line %u", current_line
);
9957 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9958 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9964 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9965 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9969 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9970 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9973 case LI_negate_stmt
:
9974 current_is_stmt
= !current_is_stmt
;
9975 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9976 "is_stmt %d", current_is_stmt
);
9979 case LI_set_prologue_end
:
9980 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9981 "set prologue end");
9984 case LI_set_epilogue_begin
:
9985 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9986 "set epilogue begin");
9989 case LI_set_discriminator
:
9990 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9991 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9992 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9993 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9998 /* Emit debug info for the address of the end of the table. */
9999 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10000 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10001 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10002 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10004 dw2_asm_output_data (1, 0, "end sequence");
10005 dw2_asm_output_data_uleb128 (1, NULL
);
10006 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10009 /* Output the source line number correspondence information. This
10010 information goes into the .debug_line section. */
10013 output_line_info (bool prologue_only
)
10015 char l1
[20], l2
[20], p1
[20], p2
[20];
10016 int ver
= dwarf_version
;
10017 bool saw_one
= false;
10020 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10021 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10022 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10023 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10025 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10026 dw2_asm_output_data (4, 0xffffffff,
10027 "Initial length escape value indicating 64-bit DWARF extension");
10028 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10029 "Length of Source Line Info");
10030 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10032 dw2_asm_output_data (2, ver
, "DWARF Version");
10033 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10034 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10036 /* Define the architecture-dependent minimum instruction length (in bytes).
10037 In this implementation of DWARF, this field is used for information
10038 purposes only. Since GCC generates assembly language, we have no
10039 a priori knowledge of how many instruction bytes are generated for each
10040 source line, and therefore can use only the DW_LNE_set_address and
10041 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10042 this as '1', which is "correct enough" for all architectures,
10043 and don't let the target override. */
10044 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10047 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10048 "Maximum Operations Per Instruction");
10049 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10050 "Default is_stmt_start flag");
10051 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10052 "Line Base Value (Special Opcodes)");
10053 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10054 "Line Range Value (Special Opcodes)");
10055 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10056 "Special Opcode Base");
10058 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10063 case DW_LNS_advance_pc
:
10064 case DW_LNS_advance_line
:
10065 case DW_LNS_set_file
:
10066 case DW_LNS_set_column
:
10067 case DW_LNS_fixed_advance_pc
:
10068 case DW_LNS_set_isa
:
10076 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10080 /* Write out the information about the files we use. */
10081 output_file_names ();
10082 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10085 /* Output the marker for the end of the line number info. */
10086 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10090 if (separate_line_info
)
10092 dw_line_info_table
*table
;
10095 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10098 output_one_line_info_table (table
);
10102 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10104 output_one_line_info_table (cold_text_section_line_info
);
10108 /* ??? Some Darwin linkers crash on a .debug_line section with no
10109 sequences. Further, merely a DW_LNE_end_sequence entry is not
10110 sufficient -- the address column must also be initialized.
10111 Make sure to output at least one set_address/end_sequence pair,
10112 choosing .text since that section is always present. */
10113 if (text_section_line_info
->in_use
|| !saw_one
)
10114 output_one_line_info_table (text_section_line_info
);
10116 /* Output the marker for the end of the line number info. */
10117 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10120 /* Given a pointer to a tree node for some base type, return a pointer to
10121 a DIE that describes the given type.
10123 This routine must only be called for GCC type nodes that correspond to
10124 Dwarf base (fundamental) types. */
10127 base_type_die (tree type
)
10129 dw_die_ref base_type_result
;
10130 enum dwarf_type encoding
;
10132 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10135 /* If this is a subtype that should not be emitted as a subrange type,
10136 use the base type. See subrange_type_for_debug_p. */
10137 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10138 type
= TREE_TYPE (type
);
10140 switch (TREE_CODE (type
))
10143 if ((dwarf_version
>= 4 || !dwarf_strict
)
10144 && TYPE_NAME (type
)
10145 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10146 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10147 && DECL_NAME (TYPE_NAME (type
)))
10149 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10150 if (strcmp (name
, "char16_t") == 0
10151 || strcmp (name
, "char32_t") == 0)
10153 encoding
= DW_ATE_UTF
;
10157 if (TYPE_STRING_FLAG (type
))
10159 if (TYPE_UNSIGNED (type
))
10160 encoding
= DW_ATE_unsigned_char
;
10162 encoding
= DW_ATE_signed_char
;
10164 else if (TYPE_UNSIGNED (type
))
10165 encoding
= DW_ATE_unsigned
;
10167 encoding
= DW_ATE_signed
;
10171 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10173 if (dwarf_version
>= 3 || !dwarf_strict
)
10174 encoding
= DW_ATE_decimal_float
;
10176 encoding
= DW_ATE_lo_user
;
10179 encoding
= DW_ATE_float
;
10182 case FIXED_POINT_TYPE
:
10183 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10184 encoding
= DW_ATE_lo_user
;
10185 else if (TYPE_UNSIGNED (type
))
10186 encoding
= DW_ATE_unsigned_fixed
;
10188 encoding
= DW_ATE_signed_fixed
;
10191 /* Dwarf2 doesn't know anything about complex ints, so use
10192 a user defined type for it. */
10194 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10195 encoding
= DW_ATE_complex_float
;
10197 encoding
= DW_ATE_lo_user
;
10201 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10202 encoding
= DW_ATE_boolean
;
10206 /* No other TREE_CODEs are Dwarf fundamental types. */
10207 gcc_unreachable ();
10210 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10212 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10213 int_size_in_bytes (type
));
10214 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10215 add_pubtype (type
, base_type_result
);
10217 return base_type_result
;
10220 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10221 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10224 is_base_type (tree type
)
10226 switch (TREE_CODE (type
))
10232 case FIXED_POINT_TYPE
:
10240 case QUAL_UNION_TYPE
:
10241 case ENUMERAL_TYPE
:
10242 case FUNCTION_TYPE
:
10245 case REFERENCE_TYPE
:
10253 gcc_unreachable ();
10259 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10260 node, return the size in bits for the type if it is a constant, or else
10261 return the alignment for the type if the type's size is not constant, or
10262 else return BITS_PER_WORD if the type actually turns out to be an
10263 ERROR_MARK node. */
10265 static inline unsigned HOST_WIDE_INT
10266 simple_type_size_in_bits (const_tree type
)
10268 if (TREE_CODE (type
) == ERROR_MARK
)
10269 return BITS_PER_WORD
;
10270 else if (TYPE_SIZE (type
) == NULL_TREE
)
10272 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
10273 return tree_to_uhwi (TYPE_SIZE (type
));
10275 return TYPE_ALIGN (type
);
10278 /* Similarly, but return a double_int instead of UHWI. */
10280 static inline double_int
10281 double_int_type_size_in_bits (const_tree type
)
10283 if (TREE_CODE (type
) == ERROR_MARK
)
10284 return double_int::from_uhwi (BITS_PER_WORD
);
10285 else if (TYPE_SIZE (type
) == NULL_TREE
)
10286 return double_int_zero
;
10287 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10288 return tree_to_double_int (TYPE_SIZE (type
));
10290 return double_int::from_uhwi (TYPE_ALIGN (type
));
10293 /* Given a pointer to a tree node for a subrange type, return a pointer
10294 to a DIE that describes the given type. */
10297 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10299 dw_die_ref subrange_die
;
10300 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10302 if (context_die
== NULL
)
10303 context_die
= comp_unit_die ();
10305 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10307 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10309 /* The size of the subrange type and its base type do not match,
10310 so we need to generate a size attribute for the subrange type. */
10311 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10315 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10317 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10319 return subrange_die
;
10322 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10323 entry that chains various modifiers in front of the given type. */
10326 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10327 dw_die_ref context_die
)
10329 enum tree_code code
= TREE_CODE (type
);
10330 dw_die_ref mod_type_die
;
10331 dw_die_ref sub_die
= NULL
;
10332 tree item_type
= NULL
;
10333 tree qualified_type
;
10334 tree name
, low
, high
;
10335 dw_die_ref mod_scope
;
10337 if (code
== ERROR_MARK
)
10340 /* See if we already have the appropriately qualified variant of
10343 = get_qualified_type (type
,
10344 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10345 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10347 if (qualified_type
== sizetype
10348 && TYPE_NAME (qualified_type
)
10349 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10351 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10353 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10354 && TYPE_PRECISION (t
)
10355 == TYPE_PRECISION (qualified_type
)
10356 && TYPE_UNSIGNED (t
)
10357 == TYPE_UNSIGNED (qualified_type
));
10358 qualified_type
= t
;
10361 /* If we do, then we can just use its DIE, if it exists. */
10362 if (qualified_type
)
10364 mod_type_die
= lookup_type_die (qualified_type
);
10366 return mod_type_die
;
10369 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10371 /* Handle C typedef types. */
10372 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10373 && !DECL_ARTIFICIAL (name
))
10375 tree dtype
= TREE_TYPE (name
);
10377 if (qualified_type
== dtype
)
10379 /* For a named type, use the typedef. */
10380 gen_type_die (qualified_type
, context_die
);
10381 return lookup_type_die (qualified_type
);
10383 else if (is_const_type
< TYPE_READONLY (dtype
)
10384 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10385 || (is_const_type
<= TYPE_READONLY (dtype
)
10386 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10387 && DECL_ORIGINAL_TYPE (name
) != type
))
10388 /* cv-unqualified version of named type. Just use the unnamed
10389 type to which it refers. */
10390 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10391 is_const_type
, is_volatile_type
,
10393 /* Else cv-qualified version of named type; fall through. */
10396 mod_scope
= scope_die_for (type
, context_die
);
10399 /* If both is_const_type and is_volatile_type, prefer the path
10400 which leads to a qualified type. */
10401 && (!is_volatile_type
10402 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10403 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10405 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10406 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10408 else if (is_volatile_type
)
10410 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10411 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10413 else if (code
== POINTER_TYPE
)
10415 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10416 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10417 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10418 item_type
= TREE_TYPE (type
);
10419 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10420 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10421 TYPE_ADDR_SPACE (item_type
));
10423 else if (code
== REFERENCE_TYPE
)
10425 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10426 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10429 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10430 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10431 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10432 item_type
= TREE_TYPE (type
);
10433 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10434 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10435 TYPE_ADDR_SPACE (item_type
));
10437 else if (code
== INTEGER_TYPE
10438 && TREE_TYPE (type
) != NULL_TREE
10439 && subrange_type_for_debug_p (type
, &low
, &high
))
10441 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10442 item_type
= TREE_TYPE (type
);
10444 else if (is_base_type (type
))
10445 mod_type_die
= base_type_die (type
);
10448 gen_type_die (type
, context_die
);
10450 /* We have to get the type_main_variant here (and pass that to the
10451 `lookup_type_die' routine) because the ..._TYPE node we have
10452 might simply be a *copy* of some original type node (where the
10453 copy was created to help us keep track of typedef names) and
10454 that copy might have a different TYPE_UID from the original
10456 if (TREE_CODE (type
) != VECTOR_TYPE
)
10457 return lookup_type_die (type_main_variant (type
));
10459 /* Vectors have the debugging information in the type,
10460 not the main variant. */
10461 return lookup_type_die (type
);
10464 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10465 don't output a DW_TAG_typedef, since there isn't one in the
10466 user's program; just attach a DW_AT_name to the type.
10467 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10468 if the base type already has the same name. */
10470 && ((TREE_CODE (name
) != TYPE_DECL
10471 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10472 || (!is_const_type
&& !is_volatile_type
)))
10473 || (TREE_CODE (name
) == TYPE_DECL
10474 && TREE_TYPE (name
) == qualified_type
10475 && DECL_NAME (name
))))
10477 if (TREE_CODE (name
) == TYPE_DECL
)
10478 /* Could just call add_name_and_src_coords_attributes here,
10479 but since this is a builtin type it doesn't have any
10480 useful source coordinates anyway. */
10481 name
= DECL_NAME (name
);
10482 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10484 /* This probably indicates a bug. */
10485 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10487 name
= TYPE_NAME (type
);
10489 && TREE_CODE (name
) == TYPE_DECL
)
10490 name
= DECL_NAME (name
);
10491 add_name_attribute (mod_type_die
,
10492 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10495 if (qualified_type
)
10496 equate_type_number_to_die (qualified_type
, mod_type_die
);
10499 /* We must do this after the equate_type_number_to_die call, in case
10500 this is a recursive type. This ensures that the modified_type_die
10501 recursion will terminate even if the type is recursive. Recursive
10502 types are possible in Ada. */
10503 sub_die
= modified_type_die (item_type
,
10504 TYPE_READONLY (item_type
),
10505 TYPE_VOLATILE (item_type
),
10508 if (sub_die
!= NULL
)
10509 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10511 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10512 if (TYPE_ARTIFICIAL (type
))
10513 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10515 return mod_type_die
;
10518 /* Generate DIEs for the generic parameters of T.
10519 T must be either a generic type or a generic function.
10520 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10523 gen_generic_params_dies (tree t
)
10527 dw_die_ref die
= NULL
;
10530 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10534 die
= lookup_type_die (t
);
10535 else if (DECL_P (t
))
10536 die
= lookup_decl_die (t
);
10540 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10542 /* T has no generic parameter. It means T is neither a generic type
10543 or function. End of story. */
10546 parms_num
= TREE_VEC_LENGTH (parms
);
10547 args
= lang_hooks
.get_innermost_generic_args (t
);
10548 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10549 non_default
= int_cst_value (TREE_CHAIN (args
));
10551 non_default
= TREE_VEC_LENGTH (args
);
10552 for (i
= 0; i
< parms_num
; i
++)
10554 tree parm
, arg
, arg_pack_elems
;
10555 dw_die_ref parm_die
;
10557 parm
= TREE_VEC_ELT (parms
, i
);
10558 arg
= TREE_VEC_ELT (args
, i
);
10559 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10560 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10562 if (parm
&& TREE_VALUE (parm
) && arg
)
10564 /* If PARM represents a template parameter pack,
10565 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10566 by DW_TAG_template_*_parameter DIEs for the argument
10567 pack elements of ARG. Note that ARG would then be
10568 an argument pack. */
10569 if (arg_pack_elems
)
10570 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10574 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10575 true /* emit name */, die
);
10576 if (i
>= non_default
)
10577 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10582 /* Create and return a DIE for PARM which should be
10583 the representation of a generic type parameter.
10584 For instance, in the C++ front end, PARM would be a template parameter.
10585 ARG is the argument to PARM.
10586 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10588 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10589 as a child node. */
10592 generic_parameter_die (tree parm
, tree arg
,
10594 dw_die_ref parent_die
)
10596 dw_die_ref tmpl_die
= NULL
;
10597 const char *name
= NULL
;
10599 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10602 /* We support non-type generic parameters and arguments,
10603 type generic parameters and arguments, as well as
10604 generic generic parameters (a.k.a. template template parameters in C++)
10606 if (TREE_CODE (parm
) == PARM_DECL
)
10607 /* PARM is a nontype generic parameter */
10608 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10609 else if (TREE_CODE (parm
) == TYPE_DECL
)
10610 /* PARM is a type generic parameter. */
10611 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10612 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10613 /* PARM is a generic generic parameter.
10614 Its DIE is a GNU extension. It shall have a
10615 DW_AT_name attribute to represent the name of the template template
10616 parameter, and a DW_AT_GNU_template_name attribute to represent the
10617 name of the template template argument. */
10618 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10621 gcc_unreachable ();
10627 /* If PARM is a generic parameter pack, it means we are
10628 emitting debug info for a template argument pack element.
10629 In other terms, ARG is a template argument pack element.
10630 In that case, we don't emit any DW_AT_name attribute for
10634 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10636 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10639 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10641 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10642 TMPL_DIE should have a child DW_AT_type attribute that is set
10643 to the type of the argument to PARM, which is ARG.
10644 If PARM is a type generic parameter, TMPL_DIE should have a
10645 child DW_AT_type that is set to ARG. */
10646 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10647 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10648 TREE_THIS_VOLATILE (tmpl_type
),
10653 /* So TMPL_DIE is a DIE representing a
10654 a generic generic template parameter, a.k.a template template
10655 parameter in C++ and arg is a template. */
10657 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10658 to the name of the argument. */
10659 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10661 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10664 if (TREE_CODE (parm
) == PARM_DECL
)
10665 /* So PARM is a non-type generic parameter.
10666 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10667 attribute of TMPL_DIE which value represents the value
10669 We must be careful here:
10670 The value of ARG might reference some function decls.
10671 We might currently be emitting debug info for a generic
10672 type and types are emitted before function decls, we don't
10673 know if the function decls referenced by ARG will actually be
10674 emitted after cgraph computations.
10675 So must defer the generation of the DW_AT_const_value to
10676 after cgraph is ready. */
10677 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10683 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10684 PARM_PACK must be a template parameter pack. The returned DIE
10685 will be child DIE of PARENT_DIE. */
10688 template_parameter_pack_die (tree parm_pack
,
10689 tree parm_pack_args
,
10690 dw_die_ref parent_die
)
10695 gcc_assert (parent_die
&& parm_pack
);
10697 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10698 add_name_and_src_coords_attributes (die
, parm_pack
);
10699 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10700 generic_parameter_die (parm_pack
,
10701 TREE_VEC_ELT (parm_pack_args
, j
),
10702 false /* Don't emit DW_AT_name */,
10707 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10708 an enumerated type. */
10711 type_is_enum (const_tree type
)
10713 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10716 /* Return the DBX register number described by a given RTL node. */
10718 static unsigned int
10719 dbx_reg_number (const_rtx rtl
)
10721 unsigned regno
= REGNO (rtl
);
10723 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10725 #ifdef LEAF_REG_REMAP
10726 if (crtl
->uses_only_leaf_regs
)
10728 int leaf_reg
= LEAF_REG_REMAP (regno
);
10729 if (leaf_reg
!= -1)
10730 regno
= (unsigned) leaf_reg
;
10734 regno
= DBX_REGISTER_NUMBER (regno
);
10735 gcc_assert (regno
!= INVALID_REGNUM
);
10739 /* Optionally add a DW_OP_piece term to a location description expression.
10740 DW_OP_piece is only added if the location description expression already
10741 doesn't end with DW_OP_piece. */
10744 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10746 dw_loc_descr_ref loc
;
10748 if (*list_head
!= NULL
)
10750 /* Find the end of the chain. */
10751 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10754 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10755 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10759 /* Return a location descriptor that designates a machine register or
10760 zero if there is none. */
10762 static dw_loc_descr_ref
10763 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10767 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10770 /* We only use "frame base" when we're sure we're talking about the
10771 post-prologue local stack frame. We do this by *not* running
10772 register elimination until this point, and recognizing the special
10773 argument pointer and soft frame pointer rtx's.
10774 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10775 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10776 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10778 dw_loc_descr_ref result
= NULL
;
10780 if (dwarf_version
>= 4 || !dwarf_strict
)
10782 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10785 add_loc_descr (&result
,
10786 new_loc_descr (DW_OP_stack_value
, 0, 0));
10791 regs
= targetm
.dwarf_register_span (rtl
);
10793 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10794 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10797 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10798 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10800 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10804 /* Return a location descriptor that designates a machine register for
10805 a given hard register number. */
10807 static dw_loc_descr_ref
10808 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10810 dw_loc_descr_ref reg_loc_descr
;
10814 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10816 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10818 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10819 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10821 return reg_loc_descr
;
10824 /* Given an RTL of a register, return a location descriptor that
10825 designates a value that spans more than one register. */
10827 static dw_loc_descr_ref
10828 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10829 enum var_init_status initialized
)
10832 dw_loc_descr_ref loc_result
= NULL
;
10834 /* Simple, contiguous registers. */
10835 if (regs
== NULL_RTX
)
10837 unsigned reg
= REGNO (rtl
);
10840 #ifdef LEAF_REG_REMAP
10841 if (crtl
->uses_only_leaf_regs
)
10843 int leaf_reg
= LEAF_REG_REMAP (reg
);
10844 if (leaf_reg
!= -1)
10845 reg
= (unsigned) leaf_reg
;
10849 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10850 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10852 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10857 dw_loc_descr_ref t
;
10859 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10860 VAR_INIT_STATUS_INITIALIZED
);
10861 add_loc_descr (&loc_result
, t
);
10862 add_loc_descr_op_piece (&loc_result
, size
);
10868 /* Now onto stupid register sets in non contiguous locations. */
10870 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10872 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10875 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10877 dw_loc_descr_ref t
;
10879 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
10880 VAR_INIT_STATUS_INITIALIZED
);
10881 add_loc_descr (&loc_result
, t
);
10882 add_loc_descr_op_piece (&loc_result
, size
);
10885 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10886 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10890 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10892 /* Return a location descriptor that designates a constant i,
10893 as a compound operation from constant (i >> shift), constant shift
10896 static dw_loc_descr_ref
10897 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10899 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10900 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10901 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10905 /* Return a location descriptor that designates a constant. */
10907 static dw_loc_descr_ref
10908 int_loc_descriptor (HOST_WIDE_INT i
)
10910 enum dwarf_location_atom op
;
10912 /* Pick the smallest representation of a constant, rather than just
10913 defaulting to the LEB encoding. */
10916 int clz
= clz_hwi (i
);
10917 int ctz
= ctz_hwi (i
);
10919 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10920 else if (i
<= 0xff)
10921 op
= DW_OP_const1u
;
10922 else if (i
<= 0xffff)
10923 op
= DW_OP_const2u
;
10924 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10925 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10926 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10927 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10928 while DW_OP_const4u is 5 bytes. */
10929 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10930 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10931 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10932 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10933 while DW_OP_const4u is 5 bytes. */
10934 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10935 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10936 op
= DW_OP_const4u
;
10937 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10938 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10939 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10940 while DW_OP_constu of constant >= 0x100000000 takes at least
10942 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10943 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10944 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10945 >= HOST_BITS_PER_WIDE_INT
)
10946 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10947 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10948 while DW_OP_constu takes in this case at least 6 bytes. */
10949 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10950 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10951 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10952 && size_of_uleb128 (i
) > 6)
10953 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10954 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10961 op
= DW_OP_const1s
;
10962 else if (i
>= -0x8000)
10963 op
= DW_OP_const2s
;
10964 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10966 if (size_of_int_loc_descriptor (i
) < 5)
10968 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10969 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10972 op
= DW_OP_const4s
;
10976 if (size_of_int_loc_descriptor (i
)
10977 < (unsigned long) 1 + size_of_sleb128 (i
))
10979 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10980 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10987 return new_loc_descr (op
, i
, 0);
10990 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10991 without actually allocating it. */
10993 static unsigned long
10994 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10996 return size_of_int_loc_descriptor (i
>> shift
)
10997 + size_of_int_loc_descriptor (shift
)
11001 /* Return size_of_locs (int_loc_descriptor (i)) without
11002 actually allocating it. */
11004 static unsigned long
11005 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11014 else if (i
<= 0xff)
11016 else if (i
<= 0xffff)
11020 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11021 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11022 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11024 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11025 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11026 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11028 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11030 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11031 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11032 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11033 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11035 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11036 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11037 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11039 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11040 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11042 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11051 else if (i
>= -0x8000)
11053 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11055 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11057 s
= size_of_int_loc_descriptor (-i
) + 1;
11065 unsigned long r
= 1 + size_of_sleb128 (i
);
11066 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11068 s
= size_of_int_loc_descriptor (-i
) + 1;
11077 /* Return loc description representing "address" of integer value.
11078 This can appear only as toplevel expression. */
11080 static dw_loc_descr_ref
11081 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11084 dw_loc_descr_ref loc_result
= NULL
;
11086 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11089 litsize
= size_of_int_loc_descriptor (i
);
11090 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11091 is more compact. For DW_OP_stack_value we need:
11092 litsize + 1 (DW_OP_stack_value)
11093 and for DW_OP_implicit_value:
11094 1 (DW_OP_implicit_value) + 1 (length) + size. */
11095 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11097 loc_result
= int_loc_descriptor (i
);
11098 add_loc_descr (&loc_result
,
11099 new_loc_descr (DW_OP_stack_value
, 0, 0));
11103 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11105 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11106 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11110 /* Return a location descriptor that designates a base+offset location. */
11112 static dw_loc_descr_ref
11113 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11114 enum var_init_status initialized
)
11116 unsigned int regno
;
11117 dw_loc_descr_ref result
;
11118 dw_fde_ref fde
= cfun
->fde
;
11120 /* We only use "frame base" when we're sure we're talking about the
11121 post-prologue local stack frame. We do this by *not* running
11122 register elimination until this point, and recognizing the special
11123 argument pointer and soft frame pointer rtx's. */
11124 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11126 rtx elim
= (ira_use_lra_p
11127 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11128 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11132 if (GET_CODE (elim
) == PLUS
)
11134 offset
+= INTVAL (XEXP (elim
, 1));
11135 elim
= XEXP (elim
, 0);
11137 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11138 && (elim
== hard_frame_pointer_rtx
11139 || elim
== stack_pointer_rtx
))
11140 || elim
== (frame_pointer_needed
11141 ? hard_frame_pointer_rtx
11142 : stack_pointer_rtx
));
11144 /* If drap register is used to align stack, use frame
11145 pointer + offset to access stack variables. If stack
11146 is aligned without drap, use stack pointer + offset to
11147 access stack variables. */
11148 if (crtl
->stack_realign_tried
11149 && reg
== frame_pointer_rtx
)
11152 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11153 ? HARD_FRAME_POINTER_REGNUM
11155 return new_reg_loc_descr (base_reg
, offset
);
11158 gcc_assert (frame_pointer_fb_offset_valid
);
11159 offset
+= frame_pointer_fb_offset
;
11160 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11164 regno
= REGNO (reg
);
11165 #ifdef LEAF_REG_REMAP
11166 if (crtl
->uses_only_leaf_regs
)
11168 int leaf_reg
= LEAF_REG_REMAP (regno
);
11169 if (leaf_reg
!= -1)
11170 regno
= (unsigned) leaf_reg
;
11173 regno
= DWARF_FRAME_REGNUM (regno
);
11175 if (!optimize
&& fde
11176 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11178 /* Use cfa+offset to represent the location of arguments passed
11179 on the stack when drap is used to align stack.
11180 Only do this when not optimizing, for optimized code var-tracking
11181 is supposed to track where the arguments live and the register
11182 used as vdrap or drap in some spot might be used for something
11183 else in other part of the routine. */
11184 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11188 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11191 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11193 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11194 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11199 /* Return true if this RTL expression describes a base+offset calculation. */
11202 is_based_loc (const_rtx rtl
)
11204 return (GET_CODE (rtl
) == PLUS
11205 && ((REG_P (XEXP (rtl
, 0))
11206 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11207 && CONST_INT_P (XEXP (rtl
, 1)))));
11210 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11213 static dw_loc_descr_ref
11214 tls_mem_loc_descriptor (rtx mem
)
11217 dw_loc_descr_ref loc_result
;
11219 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11222 base
= get_base_address (MEM_EXPR (mem
));
11224 || TREE_CODE (base
) != VAR_DECL
11225 || !DECL_THREAD_LOCAL_P (base
))
11228 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11229 if (loc_result
== NULL
)
11232 if (MEM_OFFSET (mem
))
11233 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11238 /* Output debug info about reason why we failed to expand expression as dwarf
11242 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11244 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11246 fprintf (dump_file
, "Failed to expand as dwarf: ");
11248 print_generic_expr (dump_file
, expr
, dump_flags
);
11251 fprintf (dump_file
, "\n");
11252 print_rtl (dump_file
, rtl
);
11254 fprintf (dump_file
, "\nReason: %s\n", reason
);
11258 /* Helper function for const_ok_for_output, called either directly
11259 or via for_each_rtx. */
11262 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11266 if (GET_CODE (rtl
) == UNSPEC
)
11268 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11269 we can't express it in the debug info. */
11270 #ifdef ENABLE_CHECKING
11271 /* Don't complain about TLS UNSPECs, those are just too hard to
11272 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11273 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11274 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11275 if (XVECLEN (rtl
, 0) == 0
11276 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11277 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11278 inform (current_function_decl
11279 ? DECL_SOURCE_LOCATION (current_function_decl
)
11280 : UNKNOWN_LOCATION
,
11281 #if NUM_UNSPEC_VALUES > 0
11282 "non-delegitimized UNSPEC %s (%d) found in variable location",
11283 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11284 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11287 "non-delegitimized UNSPEC %d found in variable location",
11291 expansion_failed (NULL_TREE
, rtl
,
11292 "UNSPEC hasn't been delegitimized.\n");
11296 if (targetm
.const_not_ok_for_debug_p (rtl
))
11298 expansion_failed (NULL_TREE
, rtl
,
11299 "Expression rejected for debug by the backend.\n");
11303 if (GET_CODE (rtl
) != SYMBOL_REF
)
11306 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11309 get_pool_constant_mark (rtl
, &marked
);
11310 /* If all references to this pool constant were optimized away,
11311 it was not output and thus we can't represent it. */
11314 expansion_failed (NULL_TREE
, rtl
,
11315 "Constant was removed from constant pool.\n");
11320 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11323 /* Avoid references to external symbols in debug info, on several targets
11324 the linker might even refuse to link when linking a shared library,
11325 and in many other cases the relocations for .debug_info/.debug_loc are
11326 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11327 to be defined within the same shared library or executable are fine. */
11328 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11330 tree decl
= SYMBOL_REF_DECL (rtl
);
11332 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11334 expansion_failed (NULL_TREE
, rtl
,
11335 "Symbol not defined in current TU.\n");
11343 /* Return true if constant RTL can be emitted in DW_OP_addr or
11344 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11345 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11348 const_ok_for_output (rtx rtl
)
11350 if (GET_CODE (rtl
) == SYMBOL_REF
)
11351 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11353 if (GET_CODE (rtl
) == CONST
)
11354 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11359 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11360 if possible, NULL otherwise. */
11363 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11365 dw_die_ref type_die
;
11366 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11370 switch (TREE_CODE (type
))
11378 type_die
= lookup_type_die (type
);
11380 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11381 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11386 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11387 type matching MODE, or, if MODE is narrower than or as wide as
11388 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11391 static dw_loc_descr_ref
11392 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11394 enum machine_mode outer_mode
= mode
;
11395 dw_die_ref type_die
;
11396 dw_loc_descr_ref cvt
;
11398 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11400 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11403 type_die
= base_type_for_mode (outer_mode
, 1);
11404 if (type_die
== NULL
)
11406 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11407 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11408 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11409 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11410 add_loc_descr (&op
, cvt
);
11414 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11416 static dw_loc_descr_ref
11417 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11418 dw_loc_descr_ref op1
)
11420 dw_loc_descr_ref ret
= op0
;
11421 add_loc_descr (&ret
, op1
);
11422 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11423 if (STORE_FLAG_VALUE
!= 1)
11425 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11426 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11431 /* Return location descriptor for signed comparison OP RTL. */
11433 static dw_loc_descr_ref
11434 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11435 enum machine_mode mem_mode
)
11437 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11438 dw_loc_descr_ref op0
, op1
;
11441 if (op_mode
== VOIDmode
)
11442 op_mode
= GET_MODE (XEXP (rtl
, 1));
11443 if (op_mode
== VOIDmode
)
11447 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11448 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11451 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11452 VAR_INIT_STATUS_INITIALIZED
);
11453 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11454 VAR_INIT_STATUS_INITIALIZED
);
11456 if (op0
== NULL
|| op1
== NULL
)
11459 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11460 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11461 return compare_loc_descriptor (op
, op0
, op1
);
11463 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11465 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11466 dw_loc_descr_ref cvt
;
11468 if (type_die
== NULL
)
11470 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11471 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11472 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11473 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11474 add_loc_descr (&op0
, cvt
);
11475 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11476 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11477 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11478 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11479 add_loc_descr (&op1
, cvt
);
11480 return compare_loc_descriptor (op
, op0
, op1
);
11483 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11484 /* For eq/ne, if the operands are known to be zero-extended,
11485 there is no need to do the fancy shifting up. */
11486 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11488 dw_loc_descr_ref last0
, last1
;
11489 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11491 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11493 /* deref_size zero extends, and for constants we can check
11494 whether they are zero extended or not. */
11495 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11496 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11497 || (CONST_INT_P (XEXP (rtl
, 0))
11498 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11499 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11500 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11501 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11502 || (CONST_INT_P (XEXP (rtl
, 1))
11503 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11504 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11505 return compare_loc_descriptor (op
, op0
, op1
);
11507 /* EQ/NE comparison against constant in narrower type than
11508 DWARF2_ADDR_SIZE can be performed either as
11509 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11512 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11513 DW_OP_{eq,ne}. Pick whatever is shorter. */
11514 if (CONST_INT_P (XEXP (rtl
, 1))
11515 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11516 && (size_of_int_loc_descriptor (shift
) + 1
11517 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11518 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11519 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11520 & GET_MODE_MASK (op_mode
))))
11522 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11523 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11524 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11525 & GET_MODE_MASK (op_mode
));
11526 return compare_loc_descriptor (op
, op0
, op1
);
11529 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11530 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11531 if (CONST_INT_P (XEXP (rtl
, 1)))
11532 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11535 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11536 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11538 return compare_loc_descriptor (op
, op0
, op1
);
11541 /* Return location descriptor for unsigned comparison OP RTL. */
11543 static dw_loc_descr_ref
11544 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11545 enum machine_mode mem_mode
)
11547 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11548 dw_loc_descr_ref op0
, op1
;
11550 if (op_mode
== VOIDmode
)
11551 op_mode
= GET_MODE (XEXP (rtl
, 1));
11552 if (op_mode
== VOIDmode
)
11554 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11557 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11560 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11561 VAR_INIT_STATUS_INITIALIZED
);
11562 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11563 VAR_INIT_STATUS_INITIALIZED
);
11565 if (op0
== NULL
|| op1
== NULL
)
11568 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11570 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11571 dw_loc_descr_ref last0
, last1
;
11572 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11574 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11576 if (CONST_INT_P (XEXP (rtl
, 0)))
11577 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11578 /* deref_size zero extends, so no need to mask it again. */
11579 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11580 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11582 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11583 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11585 if (CONST_INT_P (XEXP (rtl
, 1)))
11586 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11587 /* deref_size zero extends, so no need to mask it again. */
11588 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11589 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11591 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11592 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11595 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11597 HOST_WIDE_INT bias
= 1;
11598 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11599 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11600 if (CONST_INT_P (XEXP (rtl
, 1)))
11601 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11602 + INTVAL (XEXP (rtl
, 1)));
11604 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11607 return compare_loc_descriptor (op
, op0
, op1
);
11610 /* Return location descriptor for {U,S}{MIN,MAX}. */
11612 static dw_loc_descr_ref
11613 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11614 enum machine_mode mem_mode
)
11616 enum dwarf_location_atom op
;
11617 dw_loc_descr_ref op0
, op1
, ret
;
11618 dw_loc_descr_ref bra_node
, drop_node
;
11621 && (GET_MODE_CLASS (mode
) != MODE_INT
11622 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11625 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11626 VAR_INIT_STATUS_INITIALIZED
);
11627 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11628 VAR_INIT_STATUS_INITIALIZED
);
11630 if (op0
== NULL
|| op1
== NULL
)
11633 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11634 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11635 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11636 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11638 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11640 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11641 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11642 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11643 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11644 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11646 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11648 HOST_WIDE_INT bias
= 1;
11649 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11650 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11651 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11654 else if (GET_MODE_CLASS (mode
) == MODE_INT
11655 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11657 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11658 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11659 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11660 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11661 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11663 else if (GET_MODE_CLASS (mode
) == MODE_INT
11664 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11666 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11667 dw_loc_descr_ref cvt
;
11668 if (type_die
== NULL
)
11670 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11671 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11672 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11673 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11674 add_loc_descr (&op0
, cvt
);
11675 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11676 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11677 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11678 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11679 add_loc_descr (&op1
, cvt
);
11682 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11687 add_loc_descr (&ret
, op1
);
11688 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11689 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11690 add_loc_descr (&ret
, bra_node
);
11691 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11692 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11693 add_loc_descr (&ret
, drop_node
);
11694 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11695 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11696 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11697 && GET_MODE_CLASS (mode
) == MODE_INT
11698 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11699 ret
= convert_descriptor_to_mode (mode
, ret
);
11703 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11704 but after converting arguments to type_die, afterwards
11705 convert back to unsigned. */
11707 static dw_loc_descr_ref
11708 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11709 enum machine_mode mode
, enum machine_mode mem_mode
)
11711 dw_loc_descr_ref cvt
, op0
, op1
;
11713 if (type_die
== NULL
)
11715 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11716 VAR_INIT_STATUS_INITIALIZED
);
11717 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11718 VAR_INIT_STATUS_INITIALIZED
);
11719 if (op0
== NULL
|| op1
== NULL
)
11721 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11722 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11723 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11724 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11725 add_loc_descr (&op0
, cvt
);
11726 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11727 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11728 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11729 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11730 add_loc_descr (&op1
, cvt
);
11731 add_loc_descr (&op0
, op1
);
11732 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11733 return convert_descriptor_to_mode (mode
, op0
);
11736 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11737 const0 is DW_OP_lit0 or corresponding typed constant,
11738 const1 is DW_OP_lit1 or corresponding typed constant
11739 and constMSB is constant with just the MSB bit set
11741 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11742 L1: const0 DW_OP_swap
11743 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11744 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11749 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11750 L1: const0 DW_OP_swap
11751 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11752 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11757 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11758 L1: const1 DW_OP_swap
11759 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11760 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11764 static dw_loc_descr_ref
11765 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11766 enum machine_mode mem_mode
)
11768 dw_loc_descr_ref op0
, ret
, tmp
;
11769 HOST_WIDE_INT valv
;
11770 dw_loc_descr_ref l1jump
, l1label
;
11771 dw_loc_descr_ref l2jump
, l2label
;
11772 dw_loc_descr_ref l3jump
, l3label
;
11773 dw_loc_descr_ref l4jump
, l4label
;
11776 if (GET_MODE_CLASS (mode
) != MODE_INT
11777 || GET_MODE (XEXP (rtl
, 0)) != mode
11778 || (GET_CODE (rtl
) == CLZ
11779 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11782 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11783 VAR_INIT_STATUS_INITIALIZED
);
11787 if (GET_CODE (rtl
) == CLZ
)
11789 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11790 valv
= GET_MODE_BITSIZE (mode
);
11792 else if (GET_CODE (rtl
) == FFS
)
11794 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11795 valv
= GET_MODE_BITSIZE (mode
);
11796 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11797 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11798 add_loc_descr (&ret
, l1jump
);
11799 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11800 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11801 VAR_INIT_STATUS_INITIALIZED
);
11804 add_loc_descr (&ret
, tmp
);
11805 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11806 add_loc_descr (&ret
, l4jump
);
11807 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11808 ? const1_rtx
: const0_rtx
,
11810 VAR_INIT_STATUS_INITIALIZED
);
11811 if (l1label
== NULL
)
11813 add_loc_descr (&ret
, l1label
);
11814 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11815 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11816 add_loc_descr (&ret
, l2label
);
11817 if (GET_CODE (rtl
) != CLZ
)
11819 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11820 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11821 << (GET_MODE_BITSIZE (mode
) - 1));
11823 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11824 << (GET_MODE_BITSIZE (mode
)
11825 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11826 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11827 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11828 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11829 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11831 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11832 VAR_INIT_STATUS_INITIALIZED
);
11835 add_loc_descr (&ret
, tmp
);
11836 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11837 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11838 add_loc_descr (&ret
, l3jump
);
11839 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11840 VAR_INIT_STATUS_INITIALIZED
);
11843 add_loc_descr (&ret
, tmp
);
11844 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11845 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11846 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11847 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11848 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11849 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11850 add_loc_descr (&ret
, l2jump
);
11851 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11852 add_loc_descr (&ret
, l3label
);
11853 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11854 add_loc_descr (&ret
, l4label
);
11855 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11856 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11857 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11858 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11859 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11860 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11861 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11862 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11866 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11867 const1 is DW_OP_lit1 or corresponding typed constant):
11869 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11870 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11874 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11875 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11878 static dw_loc_descr_ref
11879 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11880 enum machine_mode mem_mode
)
11882 dw_loc_descr_ref op0
, ret
, tmp
;
11883 dw_loc_descr_ref l1jump
, l1label
;
11884 dw_loc_descr_ref l2jump
, l2label
;
11886 if (GET_MODE_CLASS (mode
) != MODE_INT
11887 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11890 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11891 VAR_INIT_STATUS_INITIALIZED
);
11895 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11896 VAR_INIT_STATUS_INITIALIZED
);
11899 add_loc_descr (&ret
, tmp
);
11900 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11901 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11902 add_loc_descr (&ret
, l1label
);
11903 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11904 add_loc_descr (&ret
, l2jump
);
11905 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11906 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11907 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11908 VAR_INIT_STATUS_INITIALIZED
);
11911 add_loc_descr (&ret
, tmp
);
11912 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11913 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11914 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11915 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11916 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11917 VAR_INIT_STATUS_INITIALIZED
);
11918 add_loc_descr (&ret
, tmp
);
11919 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11920 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11921 add_loc_descr (&ret
, l1jump
);
11922 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11923 add_loc_descr (&ret
, l2label
);
11924 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11925 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11926 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11927 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11931 /* BSWAP (constS is initial shift count, either 56 or 24):
11933 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11934 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11935 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11936 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11937 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11939 static dw_loc_descr_ref
11940 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11941 enum machine_mode mem_mode
)
11943 dw_loc_descr_ref op0
, ret
, tmp
;
11944 dw_loc_descr_ref l1jump
, l1label
;
11945 dw_loc_descr_ref l2jump
, l2label
;
11947 if (GET_MODE_CLASS (mode
) != MODE_INT
11948 || BITS_PER_UNIT
!= 8
11949 || (GET_MODE_BITSIZE (mode
) != 32
11950 && GET_MODE_BITSIZE (mode
) != 64))
11953 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11954 VAR_INIT_STATUS_INITIALIZED
);
11959 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11961 VAR_INIT_STATUS_INITIALIZED
);
11964 add_loc_descr (&ret
, tmp
);
11965 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11966 VAR_INIT_STATUS_INITIALIZED
);
11969 add_loc_descr (&ret
, tmp
);
11970 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11971 add_loc_descr (&ret
, l1label
);
11972 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11974 VAR_INIT_STATUS_INITIALIZED
);
11975 add_loc_descr (&ret
, tmp
);
11976 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11977 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11978 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11979 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11980 VAR_INIT_STATUS_INITIALIZED
);
11983 add_loc_descr (&ret
, tmp
);
11984 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11985 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11986 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11987 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11988 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11989 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11990 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11991 VAR_INIT_STATUS_INITIALIZED
);
11992 add_loc_descr (&ret
, tmp
);
11993 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11994 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11995 add_loc_descr (&ret
, l2jump
);
11996 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11997 VAR_INIT_STATUS_INITIALIZED
);
11998 add_loc_descr (&ret
, tmp
);
11999 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12000 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12001 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12002 add_loc_descr (&ret
, l1jump
);
12003 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12004 add_loc_descr (&ret
, l2label
);
12005 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12006 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12007 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12008 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12009 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12010 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12014 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12015 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12016 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12017 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12019 ROTATERT is similar:
12020 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12021 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12022 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12024 static dw_loc_descr_ref
12025 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12026 enum machine_mode mem_mode
)
12028 rtx rtlop1
= XEXP (rtl
, 1);
12029 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12032 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12035 if (GET_MODE (rtlop1
) != VOIDmode
12036 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12037 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12038 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12039 VAR_INIT_STATUS_INITIALIZED
);
12040 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12041 VAR_INIT_STATUS_INITIALIZED
);
12042 if (op0
== NULL
|| op1
== NULL
)
12044 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12045 for (i
= 0; i
< 2; i
++)
12047 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12048 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12050 VAR_INIT_STATUS_INITIALIZED
);
12051 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12052 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12054 : HOST_BITS_PER_WIDE_INT
== 64
12055 ? DW_OP_const8u
: DW_OP_constu
,
12056 GET_MODE_MASK (mode
), 0);
12059 if (mask
[i
] == NULL
)
12061 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12064 add_loc_descr (&ret
, op1
);
12065 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12066 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12067 if (GET_CODE (rtl
) == ROTATERT
)
12069 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12070 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12071 GET_MODE_BITSIZE (mode
), 0));
12073 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12074 if (mask
[0] != NULL
)
12075 add_loc_descr (&ret
, mask
[0]);
12076 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12077 if (mask
[1] != NULL
)
12079 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12080 add_loc_descr (&ret
, mask
[1]);
12081 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12083 if (GET_CODE (rtl
) == ROTATE
)
12085 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12086 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12087 GET_MODE_BITSIZE (mode
), 0));
12089 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12090 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12094 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12095 for DEBUG_PARAMETER_REF RTL. */
12097 static dw_loc_descr_ref
12098 parameter_ref_descriptor (rtx rtl
)
12100 dw_loc_descr_ref ret
;
12105 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12106 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12107 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12110 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12111 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12112 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12116 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12117 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12122 /* The following routine converts the RTL for a variable or parameter
12123 (resident in memory) into an equivalent Dwarf representation of a
12124 mechanism for getting the address of that same variable onto the top of a
12125 hypothetical "address evaluation" stack.
12127 When creating memory location descriptors, we are effectively transforming
12128 the RTL for a memory-resident object into its Dwarf postfix expression
12129 equivalent. This routine recursively descends an RTL tree, turning
12130 it into Dwarf postfix code as it goes.
12132 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12134 MEM_MODE is the mode of the memory reference, needed to handle some
12135 autoincrement addressing modes.
12137 Return 0 if we can't represent the location. */
12140 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12141 enum machine_mode mem_mode
,
12142 enum var_init_status initialized
)
12144 dw_loc_descr_ref mem_loc_result
= NULL
;
12145 enum dwarf_location_atom op
;
12146 dw_loc_descr_ref op0
, op1
;
12147 rtx inner
= NULL_RTX
;
12149 if (mode
== VOIDmode
)
12150 mode
= GET_MODE (rtl
);
12152 /* Note that for a dynamically sized array, the location we will generate a
12153 description of here will be the lowest numbered location which is
12154 actually within the array. That's *not* necessarily the same as the
12155 zeroth element of the array. */
12157 rtl
= targetm
.delegitimize_address (rtl
);
12159 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12162 switch (GET_CODE (rtl
))
12167 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12170 /* The case of a subreg may arise when we have a local (register)
12171 variable or a formal (register) parameter which doesn't quite fill
12172 up an entire register. For now, just assume that it is
12173 legitimate to make the Dwarf info refer to the whole register which
12174 contains the given subreg. */
12175 if (!subreg_lowpart_p (rtl
))
12177 inner
= SUBREG_REG (rtl
);
12179 if (inner
== NULL_RTX
)
12180 inner
= XEXP (rtl
, 0);
12181 if (GET_MODE_CLASS (mode
) == MODE_INT
12182 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12183 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12184 #ifdef POINTERS_EXTEND_UNSIGNED
12185 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12188 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12190 mem_loc_result
= mem_loc_descriptor (inner
,
12192 mem_mode
, initialized
);
12197 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12199 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12200 && (GET_MODE_CLASS (mode
) != MODE_INT
12201 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12205 dw_die_ref type_die
;
12206 dw_loc_descr_ref cvt
;
12208 mem_loc_result
= mem_loc_descriptor (inner
,
12210 mem_mode
, initialized
);
12211 if (mem_loc_result
== NULL
)
12213 type_die
= base_type_for_mode (mode
,
12214 GET_MODE_CLASS (mode
) == MODE_INT
);
12215 if (type_die
== NULL
)
12217 mem_loc_result
= NULL
;
12220 if (GET_MODE_SIZE (mode
)
12221 != GET_MODE_SIZE (GET_MODE (inner
)))
12222 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12224 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12225 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12226 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12227 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12228 add_loc_descr (&mem_loc_result
, cvt
);
12233 if (GET_MODE_CLASS (mode
) != MODE_INT
12234 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12235 && rtl
!= arg_pointer_rtx
12236 && rtl
!= frame_pointer_rtx
12237 #ifdef POINTERS_EXTEND_UNSIGNED
12238 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12242 dw_die_ref type_die
;
12243 unsigned int dbx_regnum
;
12247 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12249 type_die
= base_type_for_mode (mode
,
12250 GET_MODE_CLASS (mode
) == MODE_INT
);
12251 if (type_die
== NULL
)
12254 dbx_regnum
= dbx_reg_number (rtl
);
12255 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12257 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12259 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12260 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12261 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12264 /* Whenever a register number forms a part of the description of the
12265 method for calculating the (dynamic) address of a memory resident
12266 object, DWARF rules require the register number be referred to as
12267 a "base register". This distinction is not based in any way upon
12268 what category of register the hardware believes the given register
12269 belongs to. This is strictly DWARF terminology we're dealing with
12270 here. Note that in cases where the location of a memory-resident
12271 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12272 OP_CONST (0)) the actual DWARF location descriptor that we generate
12273 may just be OP_BASEREG (basereg). This may look deceptively like
12274 the object in question was allocated to a register (rather than in
12275 memory) so DWARF consumers need to be aware of the subtle
12276 distinction between OP_REG and OP_BASEREG. */
12277 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12278 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12279 else if (stack_realign_drap
12281 && crtl
->args
.internal_arg_pointer
== rtl
12282 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12284 /* If RTL is internal_arg_pointer, which has been optimized
12285 out, use DRAP instead. */
12286 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12287 VAR_INIT_STATUS_INITIALIZED
);
12293 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12295 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12296 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12299 else if (GET_CODE (rtl
) == ZERO_EXTEND
12300 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12301 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12302 < HOST_BITS_PER_WIDE_INT
12303 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12304 to expand zero extend as two shifts instead of
12306 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12308 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12309 mem_loc_result
= op0
;
12310 add_loc_descr (&mem_loc_result
,
12311 int_loc_descriptor (GET_MODE_MASK (imode
)));
12312 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12314 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12316 int shift
= DWARF2_ADDR_SIZE
12317 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12318 shift
*= BITS_PER_UNIT
;
12319 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12323 mem_loc_result
= op0
;
12324 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12325 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12326 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12327 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12329 else if (!dwarf_strict
)
12331 dw_die_ref type_die1
, type_die2
;
12332 dw_loc_descr_ref cvt
;
12334 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12335 GET_CODE (rtl
) == ZERO_EXTEND
);
12336 if (type_die1
== NULL
)
12338 type_die2
= base_type_for_mode (mode
, 1);
12339 if (type_die2
== NULL
)
12341 mem_loc_result
= op0
;
12342 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12343 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12344 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12345 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12346 add_loc_descr (&mem_loc_result
, cvt
);
12347 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12348 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12349 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12350 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12351 add_loc_descr (&mem_loc_result
, cvt
);
12357 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12358 if (new_rtl
!= rtl
)
12360 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12362 if (mem_loc_result
!= NULL
)
12363 return mem_loc_result
;
12366 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12367 get_address_mode (rtl
), mode
,
12368 VAR_INIT_STATUS_INITIALIZED
);
12369 if (mem_loc_result
== NULL
)
12370 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12371 if (mem_loc_result
!= NULL
)
12373 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12374 || GET_MODE_CLASS (mode
) != MODE_INT
)
12376 dw_die_ref type_die
;
12377 dw_loc_descr_ref deref
;
12382 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12383 if (type_die
== NULL
)
12385 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12386 GET_MODE_SIZE (mode
), 0);
12387 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12388 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12389 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12390 add_loc_descr (&mem_loc_result
, deref
);
12392 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12393 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12395 add_loc_descr (&mem_loc_result
,
12396 new_loc_descr (DW_OP_deref_size
,
12397 GET_MODE_SIZE (mode
), 0));
12402 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12405 /* Some ports can transform a symbol ref into a label ref, because
12406 the symbol ref is too far away and has to be dumped into a constant
12410 if (GET_MODE_CLASS (mode
) != MODE_INT
12411 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12412 #ifdef POINTERS_EXTEND_UNSIGNED
12413 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12417 if (GET_CODE (rtl
) == SYMBOL_REF
12418 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12420 dw_loc_descr_ref temp
;
12422 /* If this is not defined, we have no way to emit the data. */
12423 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12426 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12428 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12429 add_loc_descr (&mem_loc_result
, temp
);
12434 if (!const_ok_for_output (rtl
))
12438 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12439 vec_safe_push (used_rtx_array
, rtl
);
12445 case DEBUG_IMPLICIT_PTR
:
12446 expansion_failed (NULL_TREE
, rtl
,
12447 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12453 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12455 if (GET_MODE_CLASS (mode
) != MODE_INT
12456 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12457 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12458 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12461 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12462 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12464 op0
= one_reg_loc_descriptor (dbx_regnum
,
12465 VAR_INIT_STATUS_INITIALIZED
);
12468 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12469 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12471 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12472 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12473 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12477 gcc_unreachable ();
12480 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12481 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12482 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12485 case DEBUG_PARAMETER_REF
:
12486 mem_loc_result
= parameter_ref_descriptor (rtl
);
12490 /* Extract the PLUS expression nested inside and fall into
12491 PLUS code below. */
12492 rtl
= XEXP (rtl
, 1);
12497 /* Turn these into a PLUS expression and fall into the PLUS code
12499 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12500 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12501 ? GET_MODE_UNIT_SIZE (mem_mode
)
12502 : -GET_MODE_UNIT_SIZE (mem_mode
),
12505 /* ... fall through ... */
12509 if (is_based_loc (rtl
)
12510 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12511 || XEXP (rtl
, 0) == arg_pointer_rtx
12512 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12513 && GET_MODE_CLASS (mode
) == MODE_INT
)
12514 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12515 INTVAL (XEXP (rtl
, 1)),
12516 VAR_INIT_STATUS_INITIALIZED
);
12519 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12520 VAR_INIT_STATUS_INITIALIZED
);
12521 if (mem_loc_result
== 0)
12524 if (CONST_INT_P (XEXP (rtl
, 1))
12525 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12526 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12529 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12530 VAR_INIT_STATUS_INITIALIZED
);
12533 add_loc_descr (&mem_loc_result
, op1
);
12534 add_loc_descr (&mem_loc_result
,
12535 new_loc_descr (DW_OP_plus
, 0, 0));
12540 /* If a pseudo-reg is optimized away, it is possible for it to
12541 be replaced with a MEM containing a multiply or shift. */
12552 && GET_MODE_CLASS (mode
) == MODE_INT
12553 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12555 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12556 base_type_for_mode (mode
, 0),
12580 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12582 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12583 VAR_INIT_STATUS_INITIALIZED
);
12585 rtx rtlop1
= XEXP (rtl
, 1);
12586 if (GET_MODE (rtlop1
) != VOIDmode
12587 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12588 < GET_MODE_BITSIZE (mode
))
12589 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12590 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12591 VAR_INIT_STATUS_INITIALIZED
);
12594 if (op0
== 0 || op1
== 0)
12597 mem_loc_result
= op0
;
12598 add_loc_descr (&mem_loc_result
, op1
);
12599 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12615 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12616 VAR_INIT_STATUS_INITIALIZED
);
12617 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12618 VAR_INIT_STATUS_INITIALIZED
);
12620 if (op0
== 0 || op1
== 0)
12623 mem_loc_result
= op0
;
12624 add_loc_descr (&mem_loc_result
, op1
);
12625 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12629 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12631 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12632 base_type_for_mode (mode
, 0),
12637 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12638 VAR_INIT_STATUS_INITIALIZED
);
12639 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12640 VAR_INIT_STATUS_INITIALIZED
);
12642 if (op0
== 0 || op1
== 0)
12645 mem_loc_result
= op0
;
12646 add_loc_descr (&mem_loc_result
, op1
);
12647 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12648 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12649 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12650 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12651 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12655 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12657 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12662 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12663 base_type_for_mode (mode
, 1),
12681 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12682 VAR_INIT_STATUS_INITIALIZED
);
12687 mem_loc_result
= op0
;
12688 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12692 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12693 #ifdef POINTERS_EXTEND_UNSIGNED
12695 && mem_mode
!= VOIDmode
12696 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12700 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12704 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12705 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12707 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12708 enum machine_mode amode
;
12709 if (type_die
== NULL
)
12711 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12713 if (INTVAL (rtl
) >= 0
12714 && amode
!= BLKmode
12715 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12716 /* const DW_OP_GNU_convert <XXX> vs.
12717 DW_OP_GNU_const_type <XXX, 1, const>. */
12718 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12719 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12721 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12722 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12723 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12724 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12725 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12726 add_loc_descr (&mem_loc_result
, op0
);
12727 return mem_loc_result
;
12729 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12731 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12732 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12733 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12734 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12735 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12738 mem_loc_result
->dw_loc_oprnd2
.val_class
12739 = dw_val_class_const_double
;
12740 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12741 = double_int::from_shwi (INTVAL (rtl
));
12749 dw_die_ref type_die
;
12751 /* Note that a CONST_DOUBLE rtx could represent either an integer
12752 or a floating-point constant. A CONST_DOUBLE is used whenever
12753 the constant requires more than one word in order to be
12754 adequately represented. We output CONST_DOUBLEs as blocks. */
12755 if (mode
== VOIDmode
12756 || (GET_MODE (rtl
) == VOIDmode
12757 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12759 type_die
= base_type_for_mode (mode
,
12760 GET_MODE_CLASS (mode
) == MODE_INT
);
12761 if (type_die
== NULL
)
12763 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12764 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12765 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12766 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12767 if (SCALAR_FLOAT_MODE_P (mode
))
12769 unsigned int length
= GET_MODE_SIZE (mode
);
12770 unsigned char *array
12771 = (unsigned char*) ggc_alloc_atomic (length
);
12773 insert_float (rtl
, array
);
12774 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12775 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12776 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12777 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12781 mem_loc_result
->dw_loc_oprnd2
.val_class
12782 = dw_val_class_const_double
;
12783 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12784 = rtx_to_double_int (rtl
);
12790 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12794 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12798 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12802 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12806 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12810 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12814 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12818 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12822 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12826 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12831 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12836 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12841 if (CONST_INT_P (XEXP (rtl
, 1))
12842 && CONST_INT_P (XEXP (rtl
, 2))
12843 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12844 + (unsigned) INTVAL (XEXP (rtl
, 2))
12845 <= GET_MODE_BITSIZE (mode
))
12846 && GET_MODE_CLASS (mode
) == MODE_INT
12847 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12848 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12851 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12852 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12855 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12859 mem_loc_result
= op0
;
12860 size
= INTVAL (XEXP (rtl
, 1));
12861 shift
= INTVAL (XEXP (rtl
, 2));
12862 if (BITS_BIG_ENDIAN
)
12863 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12865 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12867 add_loc_descr (&mem_loc_result
,
12868 int_loc_descriptor (DWARF2_ADDR_SIZE
12870 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12872 if (size
!= (int) DWARF2_ADDR_SIZE
)
12874 add_loc_descr (&mem_loc_result
,
12875 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12876 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12883 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12884 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12885 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12886 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12887 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12888 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12889 VAR_INIT_STATUS_INITIALIZED
);
12890 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12891 VAR_INIT_STATUS_INITIALIZED
);
12892 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12895 mem_loc_result
= op1
;
12896 add_loc_descr (&mem_loc_result
, op2
);
12897 add_loc_descr (&mem_loc_result
, op0
);
12898 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12899 add_loc_descr (&mem_loc_result
, bra_node
);
12900 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12901 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12902 add_loc_descr (&mem_loc_result
, drop_node
);
12903 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12904 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12909 case FLOAT_TRUNCATE
:
12911 case UNSIGNED_FLOAT
:
12916 dw_die_ref type_die
;
12917 dw_loc_descr_ref cvt
;
12919 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12920 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12923 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12924 && (GET_CODE (rtl
) == FLOAT
12925 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12926 <= DWARF2_ADDR_SIZE
))
12928 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12929 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12930 if (type_die
== NULL
)
12932 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12933 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12934 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12935 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12936 add_loc_descr (&op0
, cvt
);
12938 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12939 if (type_die
== NULL
)
12941 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12942 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12943 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12944 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12945 add_loc_descr (&op0
, cvt
);
12946 if (GET_MODE_CLASS (mode
) == MODE_INT
12947 && (GET_CODE (rtl
) == FIX
12948 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12950 op0
= convert_descriptor_to_mode (mode
, op0
);
12954 mem_loc_result
= op0
;
12961 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12966 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12970 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12975 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12979 /* In theory, we could implement the above. */
12980 /* DWARF cannot represent the unsigned compare operations
13005 case FRACT_CONVERT
:
13006 case UNSIGNED_FRACT_CONVERT
:
13008 case UNSIGNED_SAT_FRACT
:
13014 case VEC_DUPLICATE
:
13018 case STRICT_LOW_PART
:
13023 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13024 can't express it in the debug info. This can happen e.g. with some
13029 resolve_one_addr (&rtl
, NULL
);
13033 #ifdef ENABLE_CHECKING
13034 print_rtl (stderr
, rtl
);
13035 gcc_unreachable ();
13041 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13042 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13044 return mem_loc_result
;
13047 /* Return a descriptor that describes the concatenation of two locations.
13048 This is typically a complex variable. */
13050 static dw_loc_descr_ref
13051 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13053 dw_loc_descr_ref cc_loc_result
= NULL
;
13054 dw_loc_descr_ref x0_ref
13055 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13056 dw_loc_descr_ref x1_ref
13057 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13059 if (x0_ref
== 0 || x1_ref
== 0)
13062 cc_loc_result
= x0_ref
;
13063 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13065 add_loc_descr (&cc_loc_result
, x1_ref
);
13066 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13068 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13069 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13071 return cc_loc_result
;
13074 /* Return a descriptor that describes the concatenation of N
13077 static dw_loc_descr_ref
13078 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13081 dw_loc_descr_ref cc_loc_result
= NULL
;
13082 unsigned int n
= XVECLEN (concatn
, 0);
13084 for (i
= 0; i
< n
; ++i
)
13086 dw_loc_descr_ref ref
;
13087 rtx x
= XVECEXP (concatn
, 0, i
);
13089 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13093 add_loc_descr (&cc_loc_result
, ref
);
13094 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13097 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13098 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13100 return cc_loc_result
;
13103 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13104 for DEBUG_IMPLICIT_PTR RTL. */
13106 static dw_loc_descr_ref
13107 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13109 dw_loc_descr_ref ret
;
13114 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13115 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13116 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13117 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13118 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13119 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13122 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13123 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13124 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13128 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13129 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13134 /* Output a proper Dwarf location descriptor for a variable or parameter
13135 which is either allocated in a register or in a memory location. For a
13136 register, we just generate an OP_REG and the register number. For a
13137 memory location we provide a Dwarf postfix expression describing how to
13138 generate the (dynamic) address of the object onto the address stack.
13140 MODE is mode of the decl if this loc_descriptor is going to be used in
13141 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13142 allowed, VOIDmode otherwise.
13144 If we don't know how to describe it, return 0. */
13146 static dw_loc_descr_ref
13147 loc_descriptor (rtx rtl
, enum machine_mode mode
,
13148 enum var_init_status initialized
)
13150 dw_loc_descr_ref loc_result
= NULL
;
13152 switch (GET_CODE (rtl
))
13155 /* The case of a subreg may arise when we have a local (register)
13156 variable or a formal (register) parameter which doesn't quite fill
13157 up an entire register. For now, just assume that it is
13158 legitimate to make the Dwarf info refer to the whole register which
13159 contains the given subreg. */
13160 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13161 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13162 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13168 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13172 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13173 GET_MODE (rtl
), initialized
);
13174 if (loc_result
== NULL
)
13175 loc_result
= tls_mem_loc_descriptor (rtl
);
13176 if (loc_result
== NULL
)
13178 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13179 if (new_rtl
!= rtl
)
13180 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13185 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13190 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13195 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13197 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13198 if (GET_CODE (loc
) == EXPR_LIST
)
13199 loc
= XEXP (loc
, 0);
13200 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13204 rtl
= XEXP (rtl
, 1);
13209 rtvec par_elems
= XVEC (rtl
, 0);
13210 int num_elem
= GET_NUM_ELEM (par_elems
);
13211 enum machine_mode mode
;
13214 /* Create the first one, so we have something to add to. */
13215 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13216 VOIDmode
, initialized
);
13217 if (loc_result
== NULL
)
13219 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13220 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13221 for (i
= 1; i
< num_elem
; i
++)
13223 dw_loc_descr_ref temp
;
13225 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13226 VOIDmode
, initialized
);
13229 add_loc_descr (&loc_result
, temp
);
13230 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13231 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13237 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13238 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13243 if (mode
== VOIDmode
)
13244 mode
= GET_MODE (rtl
);
13246 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13248 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13250 /* Note that a CONST_DOUBLE rtx could represent either an integer
13251 or a floating-point constant. A CONST_DOUBLE is used whenever
13252 the constant requires more than one word in order to be
13253 adequately represented. We output CONST_DOUBLEs as blocks. */
13254 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13255 GET_MODE_SIZE (mode
), 0);
13256 if (SCALAR_FLOAT_MODE_P (mode
))
13258 unsigned int length
= GET_MODE_SIZE (mode
);
13259 unsigned char *array
13260 = (unsigned char*) ggc_alloc_atomic (length
);
13262 insert_float (rtl
, array
);
13263 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13264 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13265 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13266 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13270 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13271 loc_result
->dw_loc_oprnd2
.v
.val_double
13272 = rtx_to_double_int (rtl
);
13278 if (mode
== VOIDmode
)
13279 mode
= GET_MODE (rtl
);
13281 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13283 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13284 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13285 unsigned char *array
= (unsigned char *)
13286 ggc_alloc_atomic (length
* elt_size
);
13290 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13291 switch (GET_MODE_CLASS (mode
))
13293 case MODE_VECTOR_INT
:
13294 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13296 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13297 double_int val
= rtx_to_double_int (elt
);
13299 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13300 insert_int (val
.to_shwi (), elt_size
, p
);
13303 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13304 insert_double (val
, p
);
13309 case MODE_VECTOR_FLOAT
:
13310 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13312 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13313 insert_float (elt
, p
);
13318 gcc_unreachable ();
13321 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13322 length
* elt_size
, 0);
13323 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13324 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13325 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13326 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13331 if (mode
== VOIDmode
13332 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13333 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13334 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13336 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13341 if (!const_ok_for_output (rtl
))
13344 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13345 && (dwarf_version
>= 4 || !dwarf_strict
))
13347 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13348 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13349 vec_safe_push (used_rtx_array
, rtl
);
13353 case DEBUG_IMPLICIT_PTR
:
13354 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13358 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13359 && CONST_INT_P (XEXP (rtl
, 1)))
13362 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13368 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13369 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13370 && dwarf_version
>= 4)
13371 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13373 /* Value expression. */
13374 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13376 add_loc_descr (&loc_result
,
13377 new_loc_descr (DW_OP_stack_value
, 0, 0));
13385 /* We need to figure out what section we should use as the base for the
13386 address ranges where a given location is valid.
13387 1. If this particular DECL has a section associated with it, use that.
13388 2. If this function has a section associated with it, use that.
13389 3. Otherwise, use the text section.
13390 XXX: If you split a variable across multiple sections, we won't notice. */
13392 static const char *
13393 secname_for_decl (const_tree decl
)
13395 const char *secname
;
13397 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13399 tree sectree
= DECL_SECTION_NAME (decl
);
13400 secname
= TREE_STRING_POINTER (sectree
);
13402 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13404 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13405 secname
= TREE_STRING_POINTER (sectree
);
13407 else if (cfun
&& in_cold_section_p
)
13408 secname
= crtl
->subsections
.cold_section_label
;
13410 secname
= text_section_label
;
13415 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13418 decl_by_reference_p (tree decl
)
13420 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13421 || TREE_CODE (decl
) == VAR_DECL
)
13422 && DECL_BY_REFERENCE (decl
));
13425 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13428 static dw_loc_descr_ref
13429 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13430 enum var_init_status initialized
)
13432 int have_address
= 0;
13433 dw_loc_descr_ref descr
;
13434 enum machine_mode mode
;
13436 if (want_address
!= 2)
13438 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13440 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13442 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13443 if (GET_CODE (varloc
) == EXPR_LIST
)
13444 varloc
= XEXP (varloc
, 0);
13445 mode
= GET_MODE (varloc
);
13446 if (MEM_P (varloc
))
13448 rtx addr
= XEXP (varloc
, 0);
13449 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13450 mode
, initialized
);
13455 rtx x
= avoid_constant_pool_reference (varloc
);
13457 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13462 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13469 if (GET_CODE (varloc
) == VAR_LOCATION
)
13470 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13472 mode
= DECL_MODE (loc
);
13473 descr
= loc_descriptor (varloc
, mode
, initialized
);
13480 if (want_address
== 2 && !have_address
13481 && (dwarf_version
>= 4 || !dwarf_strict
))
13483 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13485 expansion_failed (loc
, NULL_RTX
,
13486 "DWARF address size mismatch");
13489 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13492 /* Show if we can't fill the request for an address. */
13493 if (want_address
&& !have_address
)
13495 expansion_failed (loc
, NULL_RTX
,
13496 "Want address and only have value");
13500 /* If we've got an address and don't want one, dereference. */
13501 if (!want_address
&& have_address
)
13503 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13504 enum dwarf_location_atom op
;
13506 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13508 expansion_failed (loc
, NULL_RTX
,
13509 "DWARF address size mismatch");
13512 else if (size
== DWARF2_ADDR_SIZE
)
13515 op
= DW_OP_deref_size
;
13517 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13523 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13524 if it is not possible. */
13526 static dw_loc_descr_ref
13527 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13529 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13530 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13531 else if (dwarf_version
>= 3 || !dwarf_strict
)
13532 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13537 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13538 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13540 static dw_loc_descr_ref
13541 dw_sra_loc_expr (tree decl
, rtx loc
)
13544 unsigned int padsize
= 0;
13545 dw_loc_descr_ref descr
, *descr_tail
;
13546 unsigned HOST_WIDE_INT decl_size
;
13548 enum var_init_status initialized
;
13550 if (DECL_SIZE (decl
) == NULL
13551 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
13554 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
13556 descr_tail
= &descr
;
13558 for (p
= loc
; p
; p
= XEXP (p
, 1))
13560 unsigned int bitsize
= decl_piece_bitsize (p
);
13561 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13562 dw_loc_descr_ref cur_descr
;
13563 dw_loc_descr_ref
*tail
, last
= NULL
;
13564 unsigned int opsize
= 0;
13566 if (loc_note
== NULL_RTX
13567 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13569 padsize
+= bitsize
;
13572 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13573 varloc
= NOTE_VAR_LOCATION (loc_note
);
13574 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13575 if (cur_descr
== NULL
)
13577 padsize
+= bitsize
;
13581 /* Check that cur_descr either doesn't use
13582 DW_OP_*piece operations, or their sum is equal
13583 to bitsize. Otherwise we can't embed it. */
13584 for (tail
= &cur_descr
; *tail
!= NULL
;
13585 tail
= &(*tail
)->dw_loc_next
)
13586 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13588 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13592 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13594 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13598 if (last
!= NULL
&& opsize
!= bitsize
)
13600 padsize
+= bitsize
;
13601 /* Discard the current piece of the descriptor and release any
13602 addr_table entries it uses. */
13603 remove_loc_list_addr_table_entries (cur_descr
);
13607 /* If there is a hole, add DW_OP_*piece after empty DWARF
13608 expression, which means that those bits are optimized out. */
13611 if (padsize
> decl_size
)
13613 remove_loc_list_addr_table_entries (cur_descr
);
13614 goto discard_descr
;
13616 decl_size
-= padsize
;
13617 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13618 if (*descr_tail
== NULL
)
13620 remove_loc_list_addr_table_entries (cur_descr
);
13621 goto discard_descr
;
13623 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13626 *descr_tail
= cur_descr
;
13628 if (bitsize
> decl_size
)
13629 goto discard_descr
;
13630 decl_size
-= bitsize
;
13633 HOST_WIDE_INT offset
= 0;
13634 if (GET_CODE (varloc
) == VAR_LOCATION
13635 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13637 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13638 if (GET_CODE (varloc
) == EXPR_LIST
)
13639 varloc
= XEXP (varloc
, 0);
13643 if (GET_CODE (varloc
) == CONST
13644 || GET_CODE (varloc
) == SIGN_EXTEND
13645 || GET_CODE (varloc
) == ZERO_EXTEND
)
13646 varloc
= XEXP (varloc
, 0);
13647 else if (GET_CODE (varloc
) == SUBREG
)
13648 varloc
= SUBREG_REG (varloc
);
13653 /* DW_OP_bit_size offset should be zero for register
13654 or implicit location descriptions and empty location
13655 descriptions, but for memory addresses needs big endian
13657 if (MEM_P (varloc
))
13659 unsigned HOST_WIDE_INT memsize
13660 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13661 if (memsize
!= bitsize
)
13663 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13664 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13665 goto discard_descr
;
13666 if (memsize
< bitsize
)
13667 goto discard_descr
;
13668 if (BITS_BIG_ENDIAN
)
13669 offset
= memsize
- bitsize
;
13673 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13674 if (*descr_tail
== NULL
)
13675 goto discard_descr
;
13676 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13680 /* If there were any non-empty expressions, add padding till the end of
13682 if (descr
!= NULL
&& decl_size
!= 0)
13684 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13685 if (*descr_tail
== NULL
)
13686 goto discard_descr
;
13691 /* Discard the descriptor and release any addr_table entries it uses. */
13692 remove_loc_list_addr_table_entries (descr
);
13696 /* Return the dwarf representation of the location list LOC_LIST of
13697 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13700 static dw_loc_list_ref
13701 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13703 const char *endname
, *secname
;
13705 enum var_init_status initialized
;
13706 struct var_loc_node
*node
;
13707 dw_loc_descr_ref descr
;
13708 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13709 dw_loc_list_ref list
= NULL
;
13710 dw_loc_list_ref
*listp
= &list
;
13712 /* Now that we know what section we are using for a base,
13713 actually construct the list of locations.
13714 The first location information is what is passed to the
13715 function that creates the location list, and the remaining
13716 locations just get added on to that list.
13717 Note that we only know the start address for a location
13718 (IE location changes), so to build the range, we use
13719 the range [current location start, next location start].
13720 This means we have to special case the last node, and generate
13721 a range of [last location start, end of function label]. */
13723 secname
= secname_for_decl (decl
);
13725 for (node
= loc_list
->first
; node
; node
= node
->next
)
13726 if (GET_CODE (node
->loc
) == EXPR_LIST
13727 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13729 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13731 /* This requires DW_OP_{,bit_}piece, which is not usable
13732 inside DWARF expressions. */
13733 if (want_address
!= 2)
13735 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13741 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13742 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13743 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13747 bool range_across_switch
= false;
13748 /* If section switch happens in between node->label
13749 and node->next->label (or end of function) and
13750 we can't emit it as a single entry list,
13751 emit two ranges, first one ending at the end
13752 of first partition and second one starting at the
13753 beginning of second partition. */
13754 if (node
== loc_list
->last_before_switch
13755 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13756 && current_function_decl
)
13758 endname
= cfun
->fde
->dw_fde_end
;
13759 range_across_switch
= true;
13761 /* The variable has a location between NODE->LABEL and
13762 NODE->NEXT->LABEL. */
13763 else if (node
->next
)
13764 endname
= node
->next
->label
;
13765 /* If the variable has a location at the last label
13766 it keeps its location until the end of function. */
13767 else if (!current_function_decl
)
13768 endname
= text_end_label
;
13771 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13772 current_function_funcdef_no
);
13773 endname
= ggc_strdup (label_id
);
13776 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13777 if (TREE_CODE (decl
) == PARM_DECL
13778 && node
== loc_list
->first
13779 && NOTE_P (node
->loc
)
13780 && strcmp (node
->label
, endname
) == 0)
13781 (*listp
)->force
= true;
13782 listp
= &(*listp
)->dw_loc_next
;
13784 if (range_across_switch
)
13786 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13787 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13790 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13791 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13792 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13795 gcc_assert (descr
);
13796 /* The variable has a location between NODE->LABEL and
13797 NODE->NEXT->LABEL. */
13799 endname
= node
->next
->label
;
13801 endname
= cfun
->fde
->dw_fde_second_end
;
13802 *listp
= new_loc_list (descr
,
13803 cfun
->fde
->dw_fde_second_begin
,
13805 listp
= &(*listp
)->dw_loc_next
;
13810 /* Try to avoid the overhead of a location list emitting a location
13811 expression instead, but only if we didn't have more than one
13812 location entry in the first place. If some entries were not
13813 representable, we don't want to pretend a single entry that was
13814 applies to the entire scope in which the variable is
13816 if (list
&& loc_list
->first
->next
)
13822 /* Return if the loc_list has only single element and thus can be represented
13823 as location description. */
13826 single_element_loc_list_p (dw_loc_list_ref list
)
13828 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13829 return !list
->ll_symbol
;
13832 /* To each location in list LIST add loc descr REF. */
13835 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13837 dw_loc_descr_ref copy
;
13838 add_loc_descr (&list
->expr
, ref
);
13839 list
= list
->dw_loc_next
;
13842 copy
= ggc_alloc_dw_loc_descr_node ();
13843 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13844 add_loc_descr (&list
->expr
, copy
);
13845 while (copy
->dw_loc_next
)
13847 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13848 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13849 copy
->dw_loc_next
= new_copy
;
13852 list
= list
->dw_loc_next
;
13856 /* Given two lists RET and LIST
13857 produce location list that is result of adding expression in LIST
13858 to expression in RET on each position in program.
13859 Might be destructive on both RET and LIST.
13861 TODO: We handle only simple cases of RET or LIST having at most one
13862 element. General case would inolve sorting the lists in program order
13863 and merging them that will need some additional work.
13864 Adding that will improve quality of debug info especially for SRA-ed
13868 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13877 if (!list
->dw_loc_next
)
13879 add_loc_descr_to_each (*ret
, list
->expr
);
13882 if (!(*ret
)->dw_loc_next
)
13884 add_loc_descr_to_each (list
, (*ret
)->expr
);
13888 expansion_failed (NULL_TREE
, NULL_RTX
,
13889 "Don't know how to merge two non-trivial"
13890 " location lists.\n");
13895 /* LOC is constant expression. Try a luck, look it up in constant
13896 pool and return its loc_descr of its address. */
13898 static dw_loc_descr_ref
13899 cst_pool_loc_descr (tree loc
)
13901 /* Get an RTL for this, if something has been emitted. */
13902 rtx rtl
= lookup_constant_def (loc
);
13904 if (!rtl
|| !MEM_P (rtl
))
13909 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13911 /* TODO: We might get more coverage if we was actually delaying expansion
13912 of all expressions till end of compilation when constant pools are fully
13914 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13916 expansion_failed (loc
, NULL_RTX
,
13917 "CST value in contant pool but not marked.");
13920 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13921 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13924 /* Return dw_loc_list representing address of addr_expr LOC
13925 by looking for inner INDIRECT_REF expression and turning
13926 it into simple arithmetics. */
13928 static dw_loc_list_ref
13929 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13932 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13933 enum machine_mode mode
;
13934 int unsignedp
, volatilep
= 0;
13935 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13937 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13938 &bitsize
, &bitpos
, &offset
, &mode
,
13939 &unsignedp
, &volatilep
, false);
13941 if (bitpos
% BITS_PER_UNIT
)
13943 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13946 if (!INDIRECT_REF_P (obj
))
13948 expansion_failed (obj
,
13949 NULL_RTX
, "no indirect ref in inner refrence");
13952 if (!offset
&& !bitpos
)
13953 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13955 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13956 && (dwarf_version
>= 4 || !dwarf_strict
))
13958 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13963 /* Variable offset. */
13964 list_ret1
= loc_list_from_tree (offset
, 0);
13965 if (list_ret1
== 0)
13967 add_loc_list (&list_ret
, list_ret1
);
13970 add_loc_descr_to_each (list_ret
,
13971 new_loc_descr (DW_OP_plus
, 0, 0));
13973 bytepos
= bitpos
/ BITS_PER_UNIT
;
13975 add_loc_descr_to_each (list_ret
,
13976 new_loc_descr (DW_OP_plus_uconst
,
13978 else if (bytepos
< 0)
13979 loc_list_plus_const (list_ret
, bytepos
);
13980 add_loc_descr_to_each (list_ret
,
13981 new_loc_descr (DW_OP_stack_value
, 0, 0));
13987 /* Generate Dwarf location list representing LOC.
13988 If WANT_ADDRESS is false, expression computing LOC will be computed
13989 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13990 if WANT_ADDRESS is 2, expression computing address useable in location
13991 will be returned (i.e. DW_OP_reg can be used
13992 to refer to register values). */
13994 static dw_loc_list_ref
13995 loc_list_from_tree (tree loc
, int want_address
)
13997 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13998 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13999 int have_address
= 0;
14000 enum dwarf_location_atom op
;
14002 /* ??? Most of the time we do not take proper care for sign/zero
14003 extending the values properly. Hopefully this won't be a real
14006 switch (TREE_CODE (loc
))
14009 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14012 case PLACEHOLDER_EXPR
:
14013 /* This case involves extracting fields from an object to determine the
14014 position of other fields. We don't try to encode this here. The
14015 only user of this is Ada, which encodes the needed information using
14016 the names of types. */
14017 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
14021 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14022 /* There are no opcodes for these operations. */
14025 case PREINCREMENT_EXPR
:
14026 case PREDECREMENT_EXPR
:
14027 case POSTINCREMENT_EXPR
:
14028 case POSTDECREMENT_EXPR
:
14029 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14030 /* There are no opcodes for these operations. */
14034 /* If we already want an address, see if there is INDIRECT_REF inside
14035 e.g. for &this->field. */
14038 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14039 (loc
, want_address
== 2);
14042 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14043 && (ret
= cst_pool_loc_descr (loc
)))
14046 /* Otherwise, process the argument and look for the address. */
14047 if (!list_ret
&& !ret
)
14048 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
14052 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14058 if (DECL_THREAD_LOCAL_P (loc
))
14061 enum dwarf_location_atom tls_op
;
14062 enum dtprel_bool dtprel
= dtprel_false
;
14064 if (targetm
.have_tls
)
14066 /* If this is not defined, we have no way to emit the
14068 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14071 /* The way DW_OP_GNU_push_tls_address is specified, we
14072 can only look up addresses of objects in the current
14073 module. We used DW_OP_addr as first op, but that's
14074 wrong, because DW_OP_addr is relocated by the debug
14075 info consumer, while DW_OP_GNU_push_tls_address
14076 operand shouldn't be. */
14077 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14079 dtprel
= dtprel_true
;
14080 tls_op
= DW_OP_GNU_push_tls_address
;
14084 if (!targetm
.emutls
.debug_form_tls_address
14085 || !(dwarf_version
>= 3 || !dwarf_strict
))
14087 /* We stuffed the control variable into the DECL_VALUE_EXPR
14088 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14089 no longer appear in gimple code. We used the control
14090 variable in specific so that we could pick it up here. */
14091 loc
= DECL_VALUE_EXPR (loc
);
14092 tls_op
= DW_OP_form_tls_address
;
14095 rtl
= rtl_for_decl_location (loc
);
14096 if (rtl
== NULL_RTX
)
14101 rtl
= XEXP (rtl
, 0);
14102 if (! CONSTANT_P (rtl
))
14105 ret
= new_addr_loc_descr (rtl
, dtprel
);
14106 ret1
= new_loc_descr (tls_op
, 0, 0);
14107 add_loc_descr (&ret
, ret1
);
14116 if (DECL_HAS_VALUE_EXPR_P (loc
))
14117 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14121 case FUNCTION_DECL
:
14124 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14126 if (loc_list
&& loc_list
->first
)
14128 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14129 have_address
= want_address
!= 0;
14132 rtl
= rtl_for_decl_location (loc
);
14133 if (rtl
== NULL_RTX
)
14135 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14138 else if (CONST_INT_P (rtl
))
14140 HOST_WIDE_INT val
= INTVAL (rtl
);
14141 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14142 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14143 ret
= int_loc_descriptor (val
);
14145 else if (GET_CODE (rtl
) == CONST_STRING
)
14147 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14150 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14151 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14154 enum machine_mode mode
, mem_mode
;
14156 /* Certain constructs can only be represented at top-level. */
14157 if (want_address
== 2)
14159 ret
= loc_descriptor (rtl
, VOIDmode
,
14160 VAR_INIT_STATUS_INITIALIZED
);
14165 mode
= GET_MODE (rtl
);
14166 mem_mode
= VOIDmode
;
14170 mode
= get_address_mode (rtl
);
14171 rtl
= XEXP (rtl
, 0);
14174 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14175 VAR_INIT_STATUS_INITIALIZED
);
14178 expansion_failed (loc
, rtl
,
14179 "failed to produce loc descriptor for rtl");
14186 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14190 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14194 case COMPOUND_EXPR
:
14195 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14198 case VIEW_CONVERT_EXPR
:
14201 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14203 case COMPONENT_REF
:
14204 case BIT_FIELD_REF
:
14206 case ARRAY_RANGE_REF
:
14207 case REALPART_EXPR
:
14208 case IMAGPART_EXPR
:
14211 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14212 enum machine_mode mode
;
14213 int unsignedp
, volatilep
= 0;
14215 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14216 &unsignedp
, &volatilep
, false);
14218 gcc_assert (obj
!= loc
);
14220 list_ret
= loc_list_from_tree (obj
,
14222 && !bitpos
&& !offset
? 2 : 1);
14223 /* TODO: We can extract value of the small expression via shifting even
14224 for nonzero bitpos. */
14227 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14229 expansion_failed (loc
, NULL_RTX
,
14230 "bitfield access");
14234 if (offset
!= NULL_TREE
)
14236 /* Variable offset. */
14237 list_ret1
= loc_list_from_tree (offset
, 0);
14238 if (list_ret1
== 0)
14240 add_loc_list (&list_ret
, list_ret1
);
14243 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14246 bytepos
= bitpos
/ BITS_PER_UNIT
;
14248 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14249 else if (bytepos
< 0)
14250 loc_list_plus_const (list_ret
, bytepos
);
14257 if ((want_address
|| !tree_fits_shwi_p (loc
))
14258 && (ret
= cst_pool_loc_descr (loc
)))
14260 else if (want_address
== 2
14261 && tree_fits_shwi_p (loc
)
14262 && (ret
= address_of_int_loc_descriptor
14263 (int_size_in_bytes (TREE_TYPE (loc
)),
14264 tree_to_shwi (loc
))))
14266 else if (tree_fits_shwi_p (loc
))
14267 ret
= int_loc_descriptor (tree_to_shwi (loc
));
14270 expansion_failed (loc
, NULL_RTX
,
14271 "Integer operand is not host integer");
14280 if ((ret
= cst_pool_loc_descr (loc
)))
14283 /* We can construct small constants here using int_loc_descriptor. */
14284 expansion_failed (loc
, NULL_RTX
,
14285 "constructor or constant not in constant pool");
14288 case TRUTH_AND_EXPR
:
14289 case TRUTH_ANDIF_EXPR
:
14294 case TRUTH_XOR_EXPR
:
14299 case TRUTH_OR_EXPR
:
14300 case TRUTH_ORIF_EXPR
:
14305 case FLOOR_DIV_EXPR
:
14306 case CEIL_DIV_EXPR
:
14307 case ROUND_DIV_EXPR
:
14308 case TRUNC_DIV_EXPR
:
14309 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14318 case FLOOR_MOD_EXPR
:
14319 case CEIL_MOD_EXPR
:
14320 case ROUND_MOD_EXPR
:
14321 case TRUNC_MOD_EXPR
:
14322 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14327 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14328 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14329 if (list_ret
== 0 || list_ret1
== 0)
14332 add_loc_list (&list_ret
, list_ret1
);
14335 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14336 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14337 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14338 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14339 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14351 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14354 case POINTER_PLUS_EXPR
:
14356 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
14358 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14362 loc_list_plus_const (list_ret
, tree_to_shwi (TREE_OPERAND (loc
, 1)));
14370 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14377 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14384 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14391 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14406 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14407 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14408 if (list_ret
== 0 || list_ret1
== 0)
14411 add_loc_list (&list_ret
, list_ret1
);
14414 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14417 case TRUTH_NOT_EXPR
:
14431 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14435 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14441 const enum tree_code code
=
14442 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14444 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14445 build2 (code
, integer_type_node
,
14446 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14447 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14450 /* ... fall through ... */
14454 dw_loc_descr_ref lhs
14455 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14456 dw_loc_list_ref rhs
14457 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14458 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14460 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14461 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14464 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14465 add_loc_descr_to_each (list_ret
, bra_node
);
14467 add_loc_list (&list_ret
, rhs
);
14468 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14469 add_loc_descr_to_each (list_ret
, jump_node
);
14471 add_loc_descr_to_each (list_ret
, lhs
);
14472 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14473 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14475 /* ??? Need a node to point the skip at. Use a nop. */
14476 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14477 add_loc_descr_to_each (list_ret
, tmp
);
14478 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14479 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14483 case FIX_TRUNC_EXPR
:
14487 /* Leave front-end specific codes as simply unknown. This comes
14488 up, for instance, with the C STMT_EXPR. */
14489 if ((unsigned int) TREE_CODE (loc
)
14490 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14492 expansion_failed (loc
, NULL_RTX
,
14493 "language specific tree node");
14497 #ifdef ENABLE_CHECKING
14498 /* Otherwise this is a generic code; we should just lists all of
14499 these explicitly. We forgot one. */
14500 gcc_unreachable ();
14502 /* In a release build, we want to degrade gracefully: better to
14503 generate incomplete debugging information than to crash. */
14508 if (!ret
&& !list_ret
)
14511 if (want_address
== 2 && !have_address
14512 && (dwarf_version
>= 4 || !dwarf_strict
))
14514 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14516 expansion_failed (loc
, NULL_RTX
,
14517 "DWARF address size mismatch");
14521 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14523 add_loc_descr_to_each (list_ret
,
14524 new_loc_descr (DW_OP_stack_value
, 0, 0));
14527 /* Show if we can't fill the request for an address. */
14528 if (want_address
&& !have_address
)
14530 expansion_failed (loc
, NULL_RTX
,
14531 "Want address and only have value");
14535 gcc_assert (!ret
|| !list_ret
);
14537 /* If we've got an address and don't want one, dereference. */
14538 if (!want_address
&& have_address
)
14540 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14542 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14544 expansion_failed (loc
, NULL_RTX
,
14545 "DWARF address size mismatch");
14548 else if (size
== DWARF2_ADDR_SIZE
)
14551 op
= DW_OP_deref_size
;
14554 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14556 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14559 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14564 /* Same as above but return only single location expression. */
14565 static dw_loc_descr_ref
14566 loc_descriptor_from_tree (tree loc
, int want_address
)
14568 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14571 if (ret
->dw_loc_next
)
14573 expansion_failed (loc
, NULL_RTX
,
14574 "Location list where only loc descriptor needed");
14580 /* Given a value, round it up to the lowest multiple of `boundary'
14581 which is not less than the value itself. */
14583 static inline HOST_WIDE_INT
14584 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14586 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14589 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14590 pointer to the declared type for the relevant field variable, or return
14591 `integer_type_node' if the given node turns out to be an
14592 ERROR_MARK node. */
14595 field_type (const_tree decl
)
14599 if (TREE_CODE (decl
) == ERROR_MARK
)
14600 return integer_type_node
;
14602 type
= DECL_BIT_FIELD_TYPE (decl
);
14603 if (type
== NULL_TREE
)
14604 type
= TREE_TYPE (decl
);
14609 /* Given a pointer to a tree node, return the alignment in bits for
14610 it, or else return BITS_PER_WORD if the node actually turns out to
14611 be an ERROR_MARK node. */
14613 static inline unsigned
14614 simple_type_align_in_bits (const_tree type
)
14616 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14619 static inline unsigned
14620 simple_decl_align_in_bits (const_tree decl
)
14622 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14625 /* Return the result of rounding T up to ALIGN. */
14627 static inline double_int
14628 round_up_to_align (double_int t
, unsigned int align
)
14630 double_int alignd
= double_int::from_uhwi (align
);
14632 t
+= double_int_minus_one
;
14633 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14638 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14639 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14640 or return 0 if we are unable to determine what that offset is, either
14641 because the argument turns out to be a pointer to an ERROR_MARK node, or
14642 because the offset is actually variable. (We can't handle the latter case
14645 static HOST_WIDE_INT
14646 field_byte_offset (const_tree decl
)
14648 double_int object_offset_in_bits
;
14649 double_int object_offset_in_bytes
;
14650 double_int bitpos_int
;
14652 if (TREE_CODE (decl
) == ERROR_MARK
)
14655 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14657 /* We cannot yet cope with fields whose positions are variable, so
14658 for now, when we see such things, we simply return 0. Someday, we may
14659 be able to handle such cases, but it will be damn difficult. */
14660 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14663 bitpos_int
= tree_to_double_int (bit_position (decl
));
14665 #ifdef PCC_BITFIELD_TYPE_MATTERS
14666 if (PCC_BITFIELD_TYPE_MATTERS
)
14669 tree field_size_tree
;
14670 double_int deepest_bitpos
;
14671 double_int field_size_in_bits
;
14672 unsigned int type_align_in_bits
;
14673 unsigned int decl_align_in_bits
;
14674 double_int type_size_in_bits
;
14676 type
= field_type (decl
);
14677 type_size_in_bits
= double_int_type_size_in_bits (type
);
14678 type_align_in_bits
= simple_type_align_in_bits (type
);
14680 field_size_tree
= DECL_SIZE (decl
);
14682 /* The size could be unspecified if there was an error, or for
14683 a flexible array member. */
14684 if (!field_size_tree
)
14685 field_size_tree
= bitsize_zero_node
;
14687 /* If the size of the field is not constant, use the type size. */
14688 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14689 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14691 field_size_in_bits
= type_size_in_bits
;
14693 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14695 /* The GCC front-end doesn't make any attempt to keep track of the
14696 starting bit offset (relative to the start of the containing
14697 structure type) of the hypothetical "containing object" for a
14698 bit-field. Thus, when computing the byte offset value for the
14699 start of the "containing object" of a bit-field, we must deduce
14700 this information on our own. This can be rather tricky to do in
14701 some cases. For example, handling the following structure type
14702 definition when compiling for an i386/i486 target (which only
14703 aligns long long's to 32-bit boundaries) can be very tricky:
14705 struct S { int field1; long long field2:31; };
14707 Fortunately, there is a simple rule-of-thumb which can be used
14708 in such cases. When compiling for an i386/i486, GCC will
14709 allocate 8 bytes for the structure shown above. It decides to
14710 do this based upon one simple rule for bit-field allocation.
14711 GCC allocates each "containing object" for each bit-field at
14712 the first (i.e. lowest addressed) legitimate alignment boundary
14713 (based upon the required minimum alignment for the declared
14714 type of the field) which it can possibly use, subject to the
14715 condition that there is still enough available space remaining
14716 in the containing object (when allocated at the selected point)
14717 to fully accommodate all of the bits of the bit-field itself.
14719 This simple rule makes it obvious why GCC allocates 8 bytes for
14720 each object of the structure type shown above. When looking
14721 for a place to allocate the "containing object" for `field2',
14722 the compiler simply tries to allocate a 64-bit "containing
14723 object" at each successive 32-bit boundary (starting at zero)
14724 until it finds a place to allocate that 64- bit field such that
14725 at least 31 contiguous (and previously unallocated) bits remain
14726 within that selected 64 bit field. (As it turns out, for the
14727 example above, the compiler finds it is OK to allocate the
14728 "containing object" 64-bit field at bit-offset zero within the
14731 Here we attempt to work backwards from the limited set of facts
14732 we're given, and we try to deduce from those facts, where GCC
14733 must have believed that the containing object started (within
14734 the structure type). The value we deduce is then used (by the
14735 callers of this routine) to generate DW_AT_location and
14736 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14737 the case of DW_AT_location, regular fields as well). */
14739 /* Figure out the bit-distance from the start of the structure to
14740 the "deepest" bit of the bit-field. */
14741 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14743 /* This is the tricky part. Use some fancy footwork to deduce
14744 where the lowest addressed bit of the containing object must
14746 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14748 /* Round up to type_align by default. This works best for
14750 object_offset_in_bits
14751 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14753 if (object_offset_in_bits
.ugt (bitpos_int
))
14755 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14757 /* Round up to decl_align instead. */
14758 object_offset_in_bits
14759 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14763 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14764 object_offset_in_bits
= bitpos_int
;
14766 object_offset_in_bytes
14767 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14768 true, TRUNC_DIV_EXPR
);
14769 return object_offset_in_bytes
.to_shwi ();
14772 /* The following routines define various Dwarf attributes and any data
14773 associated with them. */
14775 /* Add a location description attribute value to a DIE.
14777 This emits location attributes suitable for whole variables and
14778 whole parameters. Note that the location attributes for struct fields are
14779 generated by the routine `data_member_location_attribute' below. */
14782 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14783 dw_loc_list_ref descr
)
14787 if (single_element_loc_list_p (descr
))
14788 add_AT_loc (die
, attr_kind
, descr
->expr
);
14790 add_AT_loc_list (die
, attr_kind
, descr
);
14793 /* Add DW_AT_accessibility attribute to DIE if needed. */
14796 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14798 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14799 children, otherwise the default is DW_ACCESS_public. In DWARF2
14800 the default has always been DW_ACCESS_public. */
14801 if (TREE_PROTECTED (decl
))
14802 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14803 else if (TREE_PRIVATE (decl
))
14805 if (dwarf_version
== 2
14806 || die
->die_parent
== NULL
14807 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14808 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14810 else if (dwarf_version
> 2
14812 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14813 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14816 /* Attach the specialized form of location attribute used for data members of
14817 struct and union types. In the special case of a FIELD_DECL node which
14818 represents a bit-field, the "offset" part of this special location
14819 descriptor must indicate the distance in bytes from the lowest-addressed
14820 byte of the containing struct or union type to the lowest-addressed byte of
14821 the "containing object" for the bit-field. (See the `field_byte_offset'
14824 For any given bit-field, the "containing object" is a hypothetical object
14825 (of some integral or enum type) within which the given bit-field lives. The
14826 type of this hypothetical "containing object" is always the same as the
14827 declared type of the individual bit-field itself (for GCC anyway... the
14828 DWARF spec doesn't actually mandate this). Note that it is the size (in
14829 bytes) of the hypothetical "containing object" which will be given in the
14830 DW_AT_byte_size attribute for this bit-field. (See the
14831 `byte_size_attribute' function below.) It is also used when calculating the
14832 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14833 function below.) */
14836 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14838 HOST_WIDE_INT offset
;
14839 dw_loc_descr_ref loc_descr
= 0;
14841 if (TREE_CODE (decl
) == TREE_BINFO
)
14843 /* We're working on the TAG_inheritance for a base class. */
14844 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14846 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14847 aren't at a fixed offset from all (sub)objects of the same
14848 type. We need to extract the appropriate offset from our
14849 vtable. The following dwarf expression means
14851 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14853 This is specific to the V3 ABI, of course. */
14855 dw_loc_descr_ref tmp
;
14857 /* Make a copy of the object address. */
14858 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14859 add_loc_descr (&loc_descr
, tmp
);
14861 /* Extract the vtable address. */
14862 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14863 add_loc_descr (&loc_descr
, tmp
);
14865 /* Calculate the address of the offset. */
14866 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
14867 gcc_assert (offset
< 0);
14869 tmp
= int_loc_descriptor (-offset
);
14870 add_loc_descr (&loc_descr
, tmp
);
14871 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14872 add_loc_descr (&loc_descr
, tmp
);
14874 /* Extract the offset. */
14875 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14876 add_loc_descr (&loc_descr
, tmp
);
14878 /* Add it to the object address. */
14879 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14880 add_loc_descr (&loc_descr
, tmp
);
14883 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
14886 offset
= field_byte_offset (decl
);
14890 if (dwarf_version
> 2)
14892 /* Don't need to output a location expression, just the constant. */
14894 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14896 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14901 enum dwarf_location_atom op
;
14903 /* The DWARF2 standard says that we should assume that the structure
14904 address is already on the stack, so we can specify a structure
14905 field address by using DW_OP_plus_uconst. */
14906 op
= DW_OP_plus_uconst
;
14907 loc_descr
= new_loc_descr (op
, offset
, 0);
14911 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14914 /* Writes integer values to dw_vec_const array. */
14917 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14921 *dest
++ = val
& 0xff;
14927 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14929 static HOST_WIDE_INT
14930 extract_int (const unsigned char *src
, unsigned int size
)
14932 HOST_WIDE_INT val
= 0;
14938 val
|= *--src
& 0xff;
14944 /* Writes double_int values to dw_vec_const array. */
14947 insert_double (double_int val
, unsigned char *dest
)
14949 unsigned char *p0
= dest
;
14950 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14952 if (WORDS_BIG_ENDIAN
)
14958 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14959 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14962 /* Writes floating point values to dw_vec_const array. */
14965 insert_float (const_rtx rtl
, unsigned char *array
)
14967 REAL_VALUE_TYPE rv
;
14971 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14972 real_to_target (val
, &rv
, GET_MODE (rtl
));
14974 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14975 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14977 insert_int (val
[i
], 4, array
);
14982 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14983 does not have a "location" either in memory or in a register. These
14984 things can arise in GNU C when a constant is passed as an actual parameter
14985 to an inlined function. They can also arise in C++ where declared
14986 constants do not necessarily get memory "homes". */
14989 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14991 switch (GET_CODE (rtl
))
14995 HOST_WIDE_INT val
= INTVAL (rtl
);
14998 add_AT_int (die
, DW_AT_const_value
, val
);
15000 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15005 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15006 floating-point constant. A CONST_DOUBLE is used whenever the
15007 constant requires more than one word in order to be adequately
15010 enum machine_mode mode
= GET_MODE (rtl
);
15012 if (SCALAR_FLOAT_MODE_P (mode
))
15014 unsigned int length
= GET_MODE_SIZE (mode
);
15015 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
15017 insert_float (rtl
, array
);
15018 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15021 add_AT_double (die
, DW_AT_const_value
,
15022 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15028 enum machine_mode mode
= GET_MODE (rtl
);
15029 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15030 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15031 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
15032 (length
* elt_size
);
15036 switch (GET_MODE_CLASS (mode
))
15038 case MODE_VECTOR_INT
:
15039 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15041 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15042 double_int val
= rtx_to_double_int (elt
);
15044 if (elt_size
<= sizeof (HOST_WIDE_INT
))
15045 insert_int (val
.to_shwi (), elt_size
, p
);
15048 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
15049 insert_double (val
, p
);
15054 case MODE_VECTOR_FLOAT
:
15055 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15057 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15058 insert_float (elt
, p
);
15063 gcc_unreachable ();
15066 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15071 if (dwarf_version
>= 4 || !dwarf_strict
)
15073 dw_loc_descr_ref loc_result
;
15074 resolve_one_addr (&rtl
, NULL
);
15076 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15077 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15078 add_AT_loc (die
, DW_AT_location
, loc_result
);
15079 vec_safe_push (used_rtx_array
, rtl
);
15085 if (CONSTANT_P (XEXP (rtl
, 0)))
15086 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15089 if (!const_ok_for_output (rtl
))
15092 if (dwarf_version
>= 4 || !dwarf_strict
)
15097 /* In cases where an inlined instance of an inline function is passed
15098 the address of an `auto' variable (which is local to the caller) we
15099 can get a situation where the DECL_RTL of the artificial local
15100 variable (for the inlining) which acts as a stand-in for the
15101 corresponding formal parameter (of the inline function) will look
15102 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15103 exactly a compile-time constant expression, but it isn't the address
15104 of the (artificial) local variable either. Rather, it represents the
15105 *value* which the artificial local variable always has during its
15106 lifetime. We currently have no way to represent such quasi-constant
15107 values in Dwarf, so for now we just punt and generate nothing. */
15115 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15116 && MEM_READONLY_P (rtl
)
15117 && GET_MODE (rtl
) == BLKmode
)
15119 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15125 /* No other kinds of rtx should be possible here. */
15126 gcc_unreachable ();
15131 /* Determine whether the evaluation of EXPR references any variables
15132 or functions which aren't otherwise used (and therefore may not be
15135 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15136 void * data ATTRIBUTE_UNUSED
)
15138 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15139 *walk_subtrees
= 0;
15141 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15142 && ! TREE_ASM_WRITTEN (*tp
))
15144 /* ??? The C++ FE emits debug information for using decls, so
15145 putting gcc_unreachable here falls over. See PR31899. For now
15146 be conservative. */
15147 else if (!cgraph_global_info_ready
15148 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15150 else if (TREE_CODE (*tp
) == VAR_DECL
)
15152 struct varpool_node
*node
= varpool_get_node (*tp
);
15153 if (!node
|| !node
->definition
)
15156 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15157 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15159 /* The call graph machinery must have finished analyzing,
15160 optimizing and gimplifying the CU by now.
15161 So if *TP has no call graph node associated
15162 to it, it means *TP will not be emitted. */
15163 if (!cgraph_get_node (*tp
))
15166 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15172 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15173 for use in a later add_const_value_attribute call. */
15176 rtl_for_decl_init (tree init
, tree type
)
15178 rtx rtl
= NULL_RTX
;
15182 /* If a variable is initialized with a string constant without embedded
15183 zeros, build CONST_STRING. */
15184 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15186 tree enttype
= TREE_TYPE (type
);
15187 tree domain
= TYPE_DOMAIN (type
);
15188 enum machine_mode mode
= TYPE_MODE (enttype
);
15190 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15192 && integer_zerop (TYPE_MIN_VALUE (domain
))
15193 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15194 TREE_STRING_LENGTH (init
) - 1) == 0
15195 && ((size_t) TREE_STRING_LENGTH (init
)
15196 == strlen (TREE_STRING_POINTER (init
)) + 1))
15198 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15199 ggc_strdup (TREE_STRING_POINTER (init
)));
15200 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15201 MEM_READONLY_P (rtl
) = 1;
15204 /* Other aggregates, and complex values, could be represented using
15206 else if (AGGREGATE_TYPE_P (type
)
15207 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15208 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15209 || TREE_CODE (type
) == COMPLEX_TYPE
)
15211 /* Vectors only work if their mode is supported by the target.
15212 FIXME: generic vectors ought to work too. */
15213 else if (TREE_CODE (type
) == VECTOR_TYPE
15214 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15216 /* If the initializer is something that we know will expand into an
15217 immediate RTL constant, expand it now. We must be careful not to
15218 reference variables which won't be output. */
15219 else if (initializer_constant_valid_p (init
, type
)
15220 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15222 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15224 if (TREE_CODE (type
) == VECTOR_TYPE
)
15225 switch (TREE_CODE (init
))
15230 if (TREE_CONSTANT (init
))
15232 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15233 bool constant_p
= true;
15235 unsigned HOST_WIDE_INT ix
;
15237 /* Even when ctor is constant, it might contain non-*_CST
15238 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15239 belong into VECTOR_CST nodes. */
15240 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15241 if (!CONSTANT_CLASS_P (value
))
15243 constant_p
= false;
15249 init
= build_vector_from_ctor (type
, elts
);
15259 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15261 /* If expand_expr returns a MEM, it wasn't immediate. */
15262 gcc_assert (!rtl
|| !MEM_P (rtl
));
15268 /* Generate RTL for the variable DECL to represent its location. */
15271 rtl_for_decl_location (tree decl
)
15275 /* Here we have to decide where we are going to say the parameter "lives"
15276 (as far as the debugger is concerned). We only have a couple of
15277 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15279 DECL_RTL normally indicates where the parameter lives during most of the
15280 activation of the function. If optimization is enabled however, this
15281 could be either NULL or else a pseudo-reg. Both of those cases indicate
15282 that the parameter doesn't really live anywhere (as far as the code
15283 generation parts of GCC are concerned) during most of the function's
15284 activation. That will happen (for example) if the parameter is never
15285 referenced within the function.
15287 We could just generate a location descriptor here for all non-NULL
15288 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15289 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15290 where DECL_RTL is NULL or is a pseudo-reg.
15292 Note however that we can only get away with using DECL_INCOMING_RTL as
15293 a backup substitute for DECL_RTL in certain limited cases. In cases
15294 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15295 we can be sure that the parameter was passed using the same type as it is
15296 declared to have within the function, and that its DECL_INCOMING_RTL
15297 points us to a place where a value of that type is passed.
15299 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15300 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15301 because in these cases DECL_INCOMING_RTL points us to a value of some
15302 type which is *different* from the type of the parameter itself. Thus,
15303 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15304 such cases, the debugger would end up (for example) trying to fetch a
15305 `float' from a place which actually contains the first part of a
15306 `double'. That would lead to really incorrect and confusing
15307 output at debug-time.
15309 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15310 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15311 are a couple of exceptions however. On little-endian machines we can
15312 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15313 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15314 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15315 when (on a little-endian machine) a non-prototyped function has a
15316 parameter declared to be of type `short' or `char'. In such cases,
15317 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15318 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15319 passed `int' value. If the debugger then uses that address to fetch
15320 a `short' or a `char' (on a little-endian machine) the result will be
15321 the correct data, so we allow for such exceptional cases below.
15323 Note that our goal here is to describe the place where the given formal
15324 parameter lives during most of the function's activation (i.e. between the
15325 end of the prologue and the start of the epilogue). We'll do that as best
15326 as we can. Note however that if the given formal parameter is modified
15327 sometime during the execution of the function, then a stack backtrace (at
15328 debug-time) will show the function as having been called with the *new*
15329 value rather than the value which was originally passed in. This happens
15330 rarely enough that it is not a major problem, but it *is* a problem, and
15331 I'd like to fix it.
15333 A future version of dwarf2out.c may generate two additional attributes for
15334 any given DW_TAG_formal_parameter DIE which will describe the "passed
15335 type" and the "passed location" for the given formal parameter in addition
15336 to the attributes we now generate to indicate the "declared type" and the
15337 "active location" for each parameter. This additional set of attributes
15338 could be used by debuggers for stack backtraces. Separately, note that
15339 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15340 This happens (for example) for inlined-instances of inline function formal
15341 parameters which are never referenced. This really shouldn't be
15342 happening. All PARM_DECL nodes should get valid non-NULL
15343 DECL_INCOMING_RTL values. FIXME. */
15345 /* Use DECL_RTL as the "location" unless we find something better. */
15346 rtl
= DECL_RTL_IF_SET (decl
);
15348 /* When generating abstract instances, ignore everything except
15349 constants, symbols living in memory, and symbols living in
15350 fixed registers. */
15351 if (! reload_completed
)
15354 && (CONSTANT_P (rtl
)
15356 && CONSTANT_P (XEXP (rtl
, 0)))
15358 && TREE_CODE (decl
) == VAR_DECL
15359 && TREE_STATIC (decl
))))
15361 rtl
= targetm
.delegitimize_address (rtl
);
15366 else if (TREE_CODE (decl
) == PARM_DECL
)
15368 if (rtl
== NULL_RTX
15369 || is_pseudo_reg (rtl
)
15371 && is_pseudo_reg (XEXP (rtl
, 0))
15372 && DECL_INCOMING_RTL (decl
)
15373 && MEM_P (DECL_INCOMING_RTL (decl
))
15374 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15376 tree declared_type
= TREE_TYPE (decl
);
15377 tree passed_type
= DECL_ARG_TYPE (decl
);
15378 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15379 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15381 /* This decl represents a formal parameter which was optimized out.
15382 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15383 all cases where (rtl == NULL_RTX) just below. */
15384 if (dmode
== pmode
)
15385 rtl
= DECL_INCOMING_RTL (decl
);
15386 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15387 && SCALAR_INT_MODE_P (dmode
)
15388 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15389 && DECL_INCOMING_RTL (decl
))
15391 rtx inc
= DECL_INCOMING_RTL (decl
);
15394 else if (MEM_P (inc
))
15396 if (BYTES_BIG_ENDIAN
)
15397 rtl
= adjust_address_nv (inc
, dmode
,
15398 GET_MODE_SIZE (pmode
)
15399 - GET_MODE_SIZE (dmode
));
15406 /* If the parm was passed in registers, but lives on the stack, then
15407 make a big endian correction if the mode of the type of the
15408 parameter is not the same as the mode of the rtl. */
15409 /* ??? This is the same series of checks that are made in dbxout.c before
15410 we reach the big endian correction code there. It isn't clear if all
15411 of these checks are necessary here, but keeping them all is the safe
15413 else if (MEM_P (rtl
)
15414 && XEXP (rtl
, 0) != const0_rtx
15415 && ! CONSTANT_P (XEXP (rtl
, 0))
15416 /* Not passed in memory. */
15417 && !MEM_P (DECL_INCOMING_RTL (decl
))
15418 /* Not passed by invisible reference. */
15419 && (!REG_P (XEXP (rtl
, 0))
15420 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15421 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15422 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15423 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15426 /* Big endian correction check. */
15427 && BYTES_BIG_ENDIAN
15428 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15429 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15432 enum machine_mode addr_mode
= get_address_mode (rtl
);
15433 int offset
= (UNITS_PER_WORD
15434 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15436 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15437 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15440 else if (TREE_CODE (decl
) == VAR_DECL
15443 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15444 && BYTES_BIG_ENDIAN
)
15446 enum machine_mode addr_mode
= get_address_mode (rtl
);
15447 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15448 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15450 /* If a variable is declared "register" yet is smaller than
15451 a register, then if we store the variable to memory, it
15452 looks like we're storing a register-sized value, when in
15453 fact we are not. We need to adjust the offset of the
15454 storage location to reflect the actual value's bytes,
15455 else gdb will not be able to display it. */
15457 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15458 plus_constant (addr_mode
, XEXP (rtl
, 0),
15462 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15463 and will have been substituted directly into all expressions that use it.
15464 C does not have such a concept, but C++ and other languages do. */
15465 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15466 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15469 rtl
= targetm
.delegitimize_address (rtl
);
15471 /* If we don't look past the constant pool, we risk emitting a
15472 reference to a constant pool entry that isn't referenced from
15473 code, and thus is not emitted. */
15475 rtl
= avoid_constant_pool_reference (rtl
);
15477 /* Try harder to get a rtl. If this symbol ends up not being emitted
15478 in the current CU, resolve_addr will remove the expression referencing
15480 if (rtl
== NULL_RTX
15481 && TREE_CODE (decl
) == VAR_DECL
15482 && !DECL_EXTERNAL (decl
)
15483 && TREE_STATIC (decl
)
15484 && DECL_NAME (decl
)
15485 && !DECL_HARD_REGISTER (decl
)
15486 && DECL_MODE (decl
) != VOIDmode
)
15488 rtl
= make_decl_rtl_for_debug (decl
);
15490 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15491 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15498 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15499 returned. If so, the decl for the COMMON block is returned, and the
15500 value is the offset into the common block for the symbol. */
15503 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15505 tree val_expr
, cvar
;
15506 enum machine_mode mode
;
15507 HOST_WIDE_INT bitsize
, bitpos
;
15509 int unsignedp
, volatilep
= 0;
15511 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15512 it does not have a value (the offset into the common area), or if it
15513 is thread local (as opposed to global) then it isn't common, and shouldn't
15514 be handled as such. */
15515 if (TREE_CODE (decl
) != VAR_DECL
15516 || !TREE_STATIC (decl
)
15517 || !DECL_HAS_VALUE_EXPR_P (decl
)
15521 val_expr
= DECL_VALUE_EXPR (decl
);
15522 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15525 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15526 &mode
, &unsignedp
, &volatilep
, true);
15528 if (cvar
== NULL_TREE
15529 || TREE_CODE (cvar
) != VAR_DECL
15530 || DECL_ARTIFICIAL (cvar
)
15531 || !TREE_PUBLIC (cvar
))
15535 if (offset
!= NULL
)
15537 if (!tree_fits_shwi_p (offset
))
15539 *value
= tree_to_shwi (offset
);
15542 *value
+= bitpos
/ BITS_PER_UNIT
;
15547 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15548 data attribute for a variable or a parameter. We generate the
15549 DW_AT_const_value attribute only in those cases where the given variable
15550 or parameter does not have a true "location" either in memory or in a
15551 register. This can happen (for example) when a constant is passed as an
15552 actual argument in a call to an inline function. (It's possible that
15553 these things can crop up in other ways also.) Note that one type of
15554 constant value which can be passed into an inlined function is a constant
15555 pointer. This can happen for example if an actual argument in an inlined
15556 function call evaluates to a compile-time constant address.
15558 CACHE_P is true if it is worth caching the location list for DECL,
15559 so that future calls can reuse it rather than regenerate it from scratch.
15560 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15561 since we will need to refer to them each time the function is inlined. */
15564 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15565 enum dwarf_attribute attr
)
15568 dw_loc_list_ref list
;
15569 var_loc_list
*loc_list
;
15570 cached_dw_loc_list
*cache
;
15573 if (TREE_CODE (decl
) == ERROR_MARK
)
15576 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15577 || TREE_CODE (decl
) == RESULT_DECL
);
15579 /* Try to get some constant RTL for this decl, and use that as the value of
15582 rtl
= rtl_for_decl_location (decl
);
15583 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15584 && add_const_value_attribute (die
, rtl
))
15587 /* See if we have single element location list that is equivalent to
15588 a constant value. That way we are better to use add_const_value_attribute
15589 rather than expanding constant value equivalent. */
15590 loc_list
= lookup_decl_loc (decl
);
15593 && loc_list
->first
->next
== NULL
15594 && NOTE_P (loc_list
->first
->loc
)
15595 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15596 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15598 struct var_loc_node
*node
;
15600 node
= loc_list
->first
;
15601 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15602 if (GET_CODE (rtl
) == EXPR_LIST
)
15603 rtl
= XEXP (rtl
, 0);
15604 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15605 && add_const_value_attribute (die
, rtl
))
15608 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15609 list several times. See if we've already cached the contents. */
15611 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15615 cache
= (cached_dw_loc_list
*)
15616 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15618 list
= cache
->loc_list
;
15622 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15623 /* It is usually worth caching this result if the decl is from
15624 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15625 if (cache_p
&& list
&& list
->dw_loc_next
)
15627 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15628 DECL_UID (decl
), INSERT
);
15629 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15630 cache
->decl_id
= DECL_UID (decl
);
15631 cache
->loc_list
= list
;
15637 add_AT_location_description (die
, attr
, list
);
15640 /* None of that worked, so it must not really have a location;
15641 try adding a constant value attribute from the DECL_INITIAL. */
15642 return tree_add_const_value_attribute_for_decl (die
, decl
);
15645 /* Add VARIABLE and DIE into deferred locations list. */
15648 defer_location (tree variable
, dw_die_ref die
)
15650 deferred_locations entry
;
15651 entry
.variable
= variable
;
15653 vec_safe_push (deferred_locations_list
, entry
);
15656 /* Helper function for tree_add_const_value_attribute. Natively encode
15657 initializer INIT into an array. Return true if successful. */
15660 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15664 if (init
== NULL_TREE
)
15668 switch (TREE_CODE (init
))
15671 type
= TREE_TYPE (init
);
15672 if (TREE_CODE (type
) == ARRAY_TYPE
)
15674 tree enttype
= TREE_TYPE (type
);
15675 enum machine_mode mode
= TYPE_MODE (enttype
);
15677 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15679 if (int_size_in_bytes (type
) != size
)
15681 if (size
> TREE_STRING_LENGTH (init
))
15683 memcpy (array
, TREE_STRING_POINTER (init
),
15684 TREE_STRING_LENGTH (init
));
15685 memset (array
+ TREE_STRING_LENGTH (init
),
15686 '\0', size
- TREE_STRING_LENGTH (init
));
15689 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15694 type
= TREE_TYPE (init
);
15695 if (int_size_in_bytes (type
) != size
)
15697 if (TREE_CODE (type
) == ARRAY_TYPE
)
15699 HOST_WIDE_INT min_index
;
15700 unsigned HOST_WIDE_INT cnt
;
15701 int curpos
= 0, fieldsize
;
15702 constructor_elt
*ce
;
15704 if (TYPE_DOMAIN (type
) == NULL_TREE
15705 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
15708 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15709 if (fieldsize
<= 0)
15712 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
15713 memset (array
, '\0', size
);
15714 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15716 tree val
= ce
->value
;
15717 tree index
= ce
->index
;
15719 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15720 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
15723 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
15728 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15731 curpos
= pos
+ fieldsize
;
15732 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15734 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
15735 - tree_to_shwi (TREE_OPERAND (index
, 0));
15736 while (count
-- > 0)
15739 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15740 curpos
+= fieldsize
;
15743 gcc_assert (curpos
<= size
);
15747 else if (TREE_CODE (type
) == RECORD_TYPE
15748 || TREE_CODE (type
) == UNION_TYPE
)
15750 tree field
= NULL_TREE
;
15751 unsigned HOST_WIDE_INT cnt
;
15752 constructor_elt
*ce
;
15754 if (int_size_in_bytes (type
) != size
)
15757 if (TREE_CODE (type
) == RECORD_TYPE
)
15758 field
= TYPE_FIELDS (type
);
15760 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15762 tree val
= ce
->value
;
15763 int pos
, fieldsize
;
15765 if (ce
->index
!= 0)
15771 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15774 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15775 && TYPE_DOMAIN (TREE_TYPE (field
))
15776 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15778 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15779 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
15781 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
15782 pos
= int_byte_position (field
);
15783 gcc_assert (pos
+ fieldsize
<= size
);
15785 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15791 case VIEW_CONVERT_EXPR
:
15792 case NON_LVALUE_EXPR
:
15793 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15795 return native_encode_expr (init
, array
, size
) == size
;
15799 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15800 attribute is the const value T. */
15803 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15806 tree type
= TREE_TYPE (t
);
15809 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15813 gcc_assert (!DECL_P (init
));
15815 rtl
= rtl_for_decl_init (init
, type
);
15817 return add_const_value_attribute (die
, rtl
);
15818 /* If the host and target are sane, try harder. */
15819 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15820 && initializer_constant_valid_p (init
, type
))
15822 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15823 if (size
> 0 && (int) size
== size
)
15825 unsigned char *array
= (unsigned char *)
15826 ggc_alloc_cleared_atomic (size
);
15828 if (native_encode_initializer (init
, array
, size
))
15830 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15839 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15840 attribute is the const value of T, where T is an integral constant
15841 variable with static storage duration
15842 (so it can't be a PARM_DECL or a RESULT_DECL). */
15845 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15849 || (TREE_CODE (decl
) != VAR_DECL
15850 && TREE_CODE (decl
) != CONST_DECL
)
15851 || (TREE_CODE (decl
) == VAR_DECL
15852 && !TREE_STATIC (decl
)))
15855 if (TREE_READONLY (decl
)
15856 && ! TREE_THIS_VOLATILE (decl
)
15857 && DECL_INITIAL (decl
))
15862 /* Don't add DW_AT_const_value if abstract origin already has one. */
15863 if (get_AT (var_die
, DW_AT_const_value
))
15866 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15869 /* Convert the CFI instructions for the current function into a
15870 location list. This is used for DW_AT_frame_base when we targeting
15871 a dwarf2 consumer that does not support the dwarf3
15872 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15875 static dw_loc_list_ref
15876 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15880 dw_loc_list_ref list
, *list_tail
;
15882 dw_cfa_location last_cfa
, next_cfa
;
15883 const char *start_label
, *last_label
, *section
;
15884 dw_cfa_location remember
;
15887 gcc_assert (fde
!= NULL
);
15889 section
= secname_for_decl (current_function_decl
);
15893 memset (&next_cfa
, 0, sizeof (next_cfa
));
15894 next_cfa
.reg
= INVALID_REGNUM
;
15895 remember
= next_cfa
;
15897 start_label
= fde
->dw_fde_begin
;
15899 /* ??? Bald assumption that the CIE opcode list does not contain
15900 advance opcodes. */
15901 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15902 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15904 last_cfa
= next_cfa
;
15905 last_label
= start_label
;
15907 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15909 /* If the first partition contained no CFI adjustments, the
15910 CIE opcodes apply to the whole first partition. */
15911 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15912 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15913 list_tail
=&(*list_tail
)->dw_loc_next
;
15914 start_label
= last_label
= fde
->dw_fde_second_begin
;
15917 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15919 switch (cfi
->dw_cfi_opc
)
15921 case DW_CFA_set_loc
:
15922 case DW_CFA_advance_loc1
:
15923 case DW_CFA_advance_loc2
:
15924 case DW_CFA_advance_loc4
:
15925 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15927 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15928 start_label
, last_label
, section
);
15930 list_tail
= &(*list_tail
)->dw_loc_next
;
15931 last_cfa
= next_cfa
;
15932 start_label
= last_label
;
15934 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15937 case DW_CFA_advance_loc
:
15938 /* The encoding is complex enough that we should never emit this. */
15939 gcc_unreachable ();
15942 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15945 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15947 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15949 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15950 start_label
, last_label
, section
);
15952 list_tail
= &(*list_tail
)->dw_loc_next
;
15953 last_cfa
= next_cfa
;
15954 start_label
= last_label
;
15956 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15957 start_label
, fde
->dw_fde_end
, section
);
15958 list_tail
= &(*list_tail
)->dw_loc_next
;
15959 start_label
= last_label
= fde
->dw_fde_second_begin
;
15963 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15965 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15966 start_label
, last_label
, section
);
15967 list_tail
= &(*list_tail
)->dw_loc_next
;
15968 start_label
= last_label
;
15971 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15973 fde
->dw_fde_second_begin
15974 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15977 if (list
&& list
->dw_loc_next
)
15983 /* Compute a displacement from the "steady-state frame pointer" to the
15984 frame base (often the same as the CFA), and store it in
15985 frame_pointer_fb_offset. OFFSET is added to the displacement
15986 before the latter is negated. */
15989 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15993 #ifdef FRAME_POINTER_CFA_OFFSET
15994 reg
= frame_pointer_rtx
;
15995 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15997 reg
= arg_pointer_rtx
;
15998 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16001 elim
= (ira_use_lra_p
16002 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16003 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16004 if (GET_CODE (elim
) == PLUS
)
16006 offset
+= INTVAL (XEXP (elim
, 1));
16007 elim
= XEXP (elim
, 0);
16010 frame_pointer_fb_offset
= -offset
;
16012 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16013 in which to eliminate. This is because it's stack pointer isn't
16014 directly accessible as a register within the ISA. To work around
16015 this, assume that while we cannot provide a proper value for
16016 frame_pointer_fb_offset, we won't need one either. */
16017 frame_pointer_fb_offset_valid
16018 = ((SUPPORTS_STACK_ALIGNMENT
16019 && (elim
== hard_frame_pointer_rtx
16020 || elim
== stack_pointer_rtx
))
16021 || elim
== (frame_pointer_needed
16022 ? hard_frame_pointer_rtx
16023 : stack_pointer_rtx
));
16026 /* Generate a DW_AT_name attribute given some string value to be included as
16027 the value of the attribute. */
16030 add_name_attribute (dw_die_ref die
, const char *name_string
)
16032 if (name_string
!= NULL
&& *name_string
!= 0)
16034 if (demangle_name_func
)
16035 name_string
= (*demangle_name_func
) (name_string
);
16037 add_AT_string (die
, DW_AT_name
, name_string
);
16041 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16042 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16043 of TYPE accordingly.
16045 ??? This is a temporary measure until after we're able to generate
16046 regular DWARF for the complex Ada type system. */
16049 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16050 dw_die_ref context_die
)
16053 dw_die_ref dtype_die
;
16055 if (!lang_hooks
.types
.descriptive_type
)
16058 dtype
= lang_hooks
.types
.descriptive_type (type
);
16062 dtype_die
= lookup_type_die (dtype
);
16065 gen_type_die (dtype
, context_die
);
16066 dtype_die
= lookup_type_die (dtype
);
16067 gcc_assert (dtype_die
);
16070 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16073 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16075 static const char *
16076 comp_dir_string (void)
16080 static const char *cached_wd
= NULL
;
16082 if (cached_wd
!= NULL
)
16085 wd
= get_src_pwd ();
16089 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16093 wdlen
= strlen (wd
);
16094 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
16096 wd1
[wdlen
] = DIR_SEPARATOR
;
16097 wd1
[wdlen
+ 1] = 0;
16101 cached_wd
= remap_debug_filename (wd
);
16105 /* Generate a DW_AT_comp_dir attribute for DIE. */
16108 add_comp_dir_attribute (dw_die_ref die
)
16110 const char * wd
= comp_dir_string ();
16112 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16115 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16119 lower_bound_default (void)
16121 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16126 case DW_LANG_C_plus_plus
:
16128 case DW_LANG_ObjC_plus_plus
:
16131 case DW_LANG_Fortran77
:
16132 case DW_LANG_Fortran90
:
16133 case DW_LANG_Fortran95
:
16137 case DW_LANG_Python
:
16138 return dwarf_version
>= 4 ? 0 : -1;
16139 case DW_LANG_Ada95
:
16140 case DW_LANG_Ada83
:
16141 case DW_LANG_Cobol74
:
16142 case DW_LANG_Cobol85
:
16143 case DW_LANG_Pascal83
:
16144 case DW_LANG_Modula2
:
16146 return dwarf_version
>= 4 ? 1 : -1;
16152 /* Given a tree node describing an array bound (either lower or upper) output
16153 a representation for that bound. */
16156 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16158 switch (TREE_CODE (bound
))
16163 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16166 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16169 /* Use the default if possible. */
16170 if (bound_attr
== DW_AT_lower_bound
16171 && tree_fits_shwi_p (bound
)
16172 && (dflt
= lower_bound_default ()) != -1
16173 && tree_to_shwi (bound
) == dflt
)
16176 /* Otherwise represent the bound as an unsigned value with the
16177 precision of its type. The precision and signedness of the
16178 type will be necessary to re-interpret it unambiguously. */
16179 else if (prec
< HOST_BITS_PER_WIDE_INT
)
16181 unsigned HOST_WIDE_INT mask
16182 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
16183 add_AT_unsigned (subrange_die
, bound_attr
,
16184 TREE_INT_CST_LOW (bound
) & mask
);
16186 else if (prec
== HOST_BITS_PER_WIDE_INT
16187 || TREE_INT_CST_HIGH (bound
) == 0)
16188 add_AT_unsigned (subrange_die
, bound_attr
,
16189 TREE_INT_CST_LOW (bound
));
16191 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
16192 TREE_INT_CST_LOW (bound
));
16197 case VIEW_CONVERT_EXPR
:
16198 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16208 dw_die_ref decl_die
= lookup_decl_die (bound
);
16210 /* ??? Can this happen, or should the variable have been bound
16211 first? Probably it can, since I imagine that we try to create
16212 the types of parameters in the order in which they exist in
16213 the list, and won't have created a forward reference to a
16214 later parameter. */
16215 if (decl_die
!= NULL
)
16217 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16225 /* Otherwise try to create a stack operation procedure to
16226 evaluate the value of the array bound. */
16228 dw_die_ref ctx
, decl_die
;
16229 dw_loc_list_ref list
;
16231 list
= loc_list_from_tree (bound
, 2);
16232 if (list
== NULL
|| single_element_loc_list_p (list
))
16234 /* If DW_AT_*bound is not a reference nor constant, it is
16235 a DWARF expression rather than location description.
16236 For that loc_list_from_tree (bound, 0) is needed.
16237 If that fails to give a single element list,
16238 fall back to outputting this as a reference anyway. */
16239 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16240 if (list2
&& single_element_loc_list_p (list2
))
16242 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16249 if (current_function_decl
== 0)
16250 ctx
= comp_unit_die ();
16252 ctx
= lookup_decl_die (current_function_decl
);
16254 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16255 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16256 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16257 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16258 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16264 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16265 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16266 Note that the block of subscript information for an array type also
16267 includes information about the element type of the given array type. */
16270 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16272 unsigned dimension_number
;
16274 dw_die_ref subrange_die
;
16276 for (dimension_number
= 0;
16277 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16278 type
= TREE_TYPE (type
), dimension_number
++)
16280 tree domain
= TYPE_DOMAIN (type
);
16282 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16285 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16286 and (in GNU C only) variable bounds. Handle all three forms
16288 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16291 /* We have an array type with specified bounds. */
16292 lower
= TYPE_MIN_VALUE (domain
);
16293 upper
= TYPE_MAX_VALUE (domain
);
16295 /* Define the index type. */
16296 if (TREE_TYPE (domain
))
16298 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16299 TREE_TYPE field. We can't emit debug info for this
16300 because it is an unnamed integral type. */
16301 if (TREE_CODE (domain
) == INTEGER_TYPE
16302 && TYPE_NAME (domain
) == NULL_TREE
16303 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16304 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16307 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16311 /* ??? If upper is NULL, the array has unspecified length,
16312 but it does have a lower bound. This happens with Fortran
16314 Since the debugger is definitely going to need to know N
16315 to produce useful results, go ahead and output the lower
16316 bound solo, and hope the debugger can cope. */
16318 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16320 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16323 /* Otherwise we have an array type with an unspecified length. The
16324 DWARF-2 spec does not say how to handle this; let's just leave out the
16329 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
16332 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16334 dw_die_ref decl_die
;
16335 HOST_WIDE_INT size
;
16337 switch (TREE_CODE (tree_node
))
16342 case ENUMERAL_TYPE
:
16345 case QUAL_UNION_TYPE
:
16346 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16347 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16349 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16352 size
= int_size_in_bytes (tree_node
);
16355 /* For a data member of a struct or union, the DW_AT_byte_size is
16356 generally given as the number of bytes normally allocated for an
16357 object of the *declared* type of the member itself. This is true
16358 even for bit-fields. */
16359 size
= int_size_in_bytes (field_type (tree_node
));
16362 gcc_unreachable ();
16365 /* Note that `size' might be -1 when we get to this point. If it is, that
16366 indicates that the byte size of the entity in question is variable. We
16367 have no good way of expressing this fact in Dwarf at the present time,
16368 when location description was not used by the caller code instead. */
16370 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16373 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16374 which specifies the distance in bits from the highest order bit of the
16375 "containing object" for the bit-field to the highest order bit of the
16378 For any given bit-field, the "containing object" is a hypothetical object
16379 (of some integral or enum type) within which the given bit-field lives. The
16380 type of this hypothetical "containing object" is always the same as the
16381 declared type of the individual bit-field itself. The determination of the
16382 exact location of the "containing object" for a bit-field is rather
16383 complicated. It's handled by the `field_byte_offset' function (above).
16385 Note that it is the size (in bytes) of the hypothetical "containing object"
16386 which will be given in the DW_AT_byte_size attribute for this bit-field.
16387 (See `byte_size_attribute' above). */
16390 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16392 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16393 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16394 HOST_WIDE_INT bitpos_int
;
16395 HOST_WIDE_INT highest_order_object_bit_offset
;
16396 HOST_WIDE_INT highest_order_field_bit_offset
;
16397 HOST_WIDE_INT bit_offset
;
16399 /* Must be a field and a bit field. */
16400 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16402 /* We can't yet handle bit-fields whose offsets are variable, so if we
16403 encounter such things, just return without generating any attribute
16404 whatsoever. Likewise for variable or too large size. */
16405 if (! tree_fits_shwi_p (bit_position (decl
))
16406 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
16409 bitpos_int
= int_bit_position (decl
);
16411 /* Note that the bit offset is always the distance (in bits) from the
16412 highest-order bit of the "containing object" to the highest-order bit of
16413 the bit-field itself. Since the "high-order end" of any object or field
16414 is different on big-endian and little-endian machines, the computation
16415 below must take account of these differences. */
16416 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16417 highest_order_field_bit_offset
= bitpos_int
;
16419 if (! BYTES_BIG_ENDIAN
)
16421 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
16422 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16426 = (! BYTES_BIG_ENDIAN
16427 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16428 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16430 if (bit_offset
< 0)
16431 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16433 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16436 /* For a FIELD_DECL node which represents a bit field, output an attribute
16437 which specifies the length in bits of the given field. */
16440 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16442 /* Must be a field and a bit field. */
16443 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16444 && DECL_BIT_FIELD_TYPE (decl
));
16446 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
16447 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
16450 /* If the compiled language is ANSI C, then add a 'prototyped'
16451 attribute, if arg types are given for the parameters of a function. */
16454 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16456 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16457 && prototype_p (func_type
))
16458 add_AT_flag (die
, DW_AT_prototyped
, 1);
16461 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16462 by looking in either the type declaration or object declaration
16465 static inline dw_die_ref
16466 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16468 dw_die_ref origin_die
= NULL
;
16470 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16472 /* We may have gotten separated from the block for the inlined
16473 function, if we're in an exception handler or some such; make
16474 sure that the abstract function has been written out.
16476 Doing this for nested functions is wrong, however; functions are
16477 distinct units, and our context might not even be inline. */
16481 fn
= TYPE_STUB_DECL (fn
);
16483 fn
= decl_function_context (fn
);
16485 dwarf2out_abstract_function (fn
);
16488 if (DECL_P (origin
))
16489 origin_die
= lookup_decl_die (origin
);
16490 else if (TYPE_P (origin
))
16491 origin_die
= lookup_type_die (origin
);
16493 /* XXX: Functions that are never lowered don't always have correct block
16494 trees (in the case of java, they simply have no block tree, in some other
16495 languages). For these functions, there is nothing we can really do to
16496 output correct debug info for inlined functions in all cases. Rather
16497 than die, we'll just produce deficient debug info now, in that we will
16498 have variables without a proper abstract origin. In the future, when all
16499 functions are lowered, we should re-add a gcc_assert (origin_die)
16503 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16507 /* We do not currently support the pure_virtual attribute. */
16510 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16512 if (DECL_VINDEX (func_decl
))
16514 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16516 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
16517 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16518 new_loc_descr (DW_OP_constu
,
16519 tree_to_shwi (DECL_VINDEX (func_decl
)),
16522 /* GNU extension: Record what type this method came from originally. */
16523 if (debug_info_level
> DINFO_LEVEL_TERSE
16524 && DECL_CONTEXT (func_decl
))
16525 add_AT_die_ref (die
, DW_AT_containing_type
,
16526 lookup_type_die (DECL_CONTEXT (func_decl
)));
16530 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16531 given decl. This used to be a vendor extension until after DWARF 4
16532 standardized it. */
16535 add_linkage_attr (dw_die_ref die
, tree decl
)
16537 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16539 /* Mimic what assemble_name_raw does with a leading '*'. */
16540 if (name
[0] == '*')
16543 if (dwarf_version
>= 4)
16544 add_AT_string (die
, DW_AT_linkage_name
, name
);
16546 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16549 /* Add source coordinate attributes for the given decl. */
16552 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16554 expanded_location s
;
16556 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16558 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16559 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16560 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16563 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16566 add_linkage_name (dw_die_ref die
, tree decl
)
16568 if (debug_info_level
> DINFO_LEVEL_TERSE
16569 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16570 && TREE_PUBLIC (decl
)
16571 && !DECL_ABSTRACT (decl
)
16572 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16573 && die
->die_tag
!= DW_TAG_member
)
16575 /* Defer until we have an assembler name set. */
16576 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16578 limbo_die_node
*asm_name
;
16580 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16581 asm_name
->die
= die
;
16582 asm_name
->created_for
= decl
;
16583 asm_name
->next
= deferred_asm_name
;
16584 deferred_asm_name
= asm_name
;
16586 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16587 add_linkage_attr (die
, decl
);
16591 /* Add a DW_AT_name attribute and source coordinate attribute for the
16592 given decl, but only if it actually has a name. */
16595 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16599 decl_name
= DECL_NAME (decl
);
16600 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16602 const char *name
= dwarf2_name (decl
, 0);
16604 add_name_attribute (die
, name
);
16605 if (! DECL_ARTIFICIAL (decl
))
16606 add_src_coords_attributes (die
, decl
);
16608 add_linkage_name (die
, decl
);
16611 #ifdef VMS_DEBUGGING_INFO
16612 /* Get the function's name, as described by its RTL. This may be different
16613 from the DECL_NAME name used in the source file. */
16614 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16616 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16617 XEXP (DECL_RTL (decl
), 0), false);
16618 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16620 #endif /* VMS_DEBUGGING_INFO */
16623 #ifdef VMS_DEBUGGING_INFO
16624 /* Output the debug main pointer die for VMS */
16627 dwarf2out_vms_debug_main_pointer (void)
16629 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16632 /* Allocate the VMS debug main subprogram die. */
16633 die
= ggc_alloc_cleared_die_node ();
16634 die
->die_tag
= DW_TAG_subprogram
;
16635 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16636 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16637 current_function_funcdef_no
);
16638 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16640 /* Make it the first child of comp_unit_die (). */
16641 die
->die_parent
= comp_unit_die ();
16642 if (comp_unit_die ()->die_child
)
16644 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16645 comp_unit_die ()->die_child
->die_sib
= die
;
16649 die
->die_sib
= die
;
16650 comp_unit_die ()->die_child
= die
;
16653 #endif /* VMS_DEBUGGING_INFO */
16655 /* Push a new declaration scope. */
16658 push_decl_scope (tree scope
)
16660 vec_safe_push (decl_scope_table
, scope
);
16663 /* Pop a declaration scope. */
16666 pop_decl_scope (void)
16668 decl_scope_table
->pop ();
16671 /* walk_tree helper function for uses_local_type, below. */
16674 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16677 *walk_subtrees
= 0;
16680 tree name
= TYPE_NAME (*tp
);
16681 if (name
&& DECL_P (name
) && decl_function_context (name
))
16687 /* If TYPE involves a function-local type (including a local typedef to a
16688 non-local type), returns that type; otherwise returns NULL_TREE. */
16691 uses_local_type (tree type
)
16693 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16697 /* Return the DIE for the scope that immediately contains this type.
16698 Non-named types that do not involve a function-local type get global
16699 scope. Named types nested in namespaces or other types get their
16700 containing scope. All other types (i.e. function-local named types) get
16701 the current active scope. */
16704 scope_die_for (tree t
, dw_die_ref context_die
)
16706 dw_die_ref scope_die
= NULL
;
16707 tree containing_scope
;
16709 /* Non-types always go in the current scope. */
16710 gcc_assert (TYPE_P (t
));
16712 /* Use the scope of the typedef, rather than the scope of the type
16714 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16715 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16717 containing_scope
= TYPE_CONTEXT (t
);
16719 /* Use the containing namespace if there is one. */
16720 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16722 if (context_die
== lookup_decl_die (containing_scope
))
16724 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16725 context_die
= get_context_die (containing_scope
);
16727 containing_scope
= NULL_TREE
;
16730 /* Ignore function type "scopes" from the C frontend. They mean that
16731 a tagged type is local to a parmlist of a function declarator, but
16732 that isn't useful to DWARF. */
16733 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16734 containing_scope
= NULL_TREE
;
16736 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16738 /* If T uses a local type keep it local as well, to avoid references
16739 to function-local DIEs from outside the function. */
16740 if (current_function_decl
&& uses_local_type (t
))
16741 scope_die
= context_die
;
16743 scope_die
= comp_unit_die ();
16745 else if (TYPE_P (containing_scope
))
16747 /* For types, we can just look up the appropriate DIE. */
16748 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16749 scope_die
= get_context_die (containing_scope
);
16752 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16753 if (scope_die
== NULL
)
16754 scope_die
= comp_unit_die ();
16758 scope_die
= context_die
;
16763 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16766 local_scope_p (dw_die_ref context_die
)
16768 for (; context_die
; context_die
= context_die
->die_parent
)
16769 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16770 || context_die
->die_tag
== DW_TAG_subprogram
)
16776 /* Returns nonzero if CONTEXT_DIE is a class. */
16779 class_scope_p (dw_die_ref context_die
)
16781 return (context_die
16782 && (context_die
->die_tag
== DW_TAG_structure_type
16783 || context_die
->die_tag
== DW_TAG_class_type
16784 || context_die
->die_tag
== DW_TAG_interface_type
16785 || context_die
->die_tag
== DW_TAG_union_type
));
16788 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16789 whether or not to treat a DIE in this context as a declaration. */
16792 class_or_namespace_scope_p (dw_die_ref context_die
)
16794 return (class_scope_p (context_die
)
16795 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16798 /* Many forms of DIEs require a "type description" attribute. This
16799 routine locates the proper "type descriptor" die for the type given
16800 by 'type', and adds a DW_AT_type attribute below the given die. */
16803 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16804 int decl_volatile
, dw_die_ref context_die
)
16806 enum tree_code code
= TREE_CODE (type
);
16807 dw_die_ref type_die
= NULL
;
16809 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16810 or fixed-point type, use the inner type. This is because we have no
16811 support for unnamed types in base_type_die. This can happen if this is
16812 an Ada subrange type. Correct solution is emit a subrange type die. */
16813 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16814 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16815 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16817 if (code
== ERROR_MARK
16818 /* Handle a special case. For functions whose return type is void, we
16819 generate *no* type attribute. (Note that no object may have type
16820 `void', so this only applies to function return types). */
16821 || code
== VOID_TYPE
)
16824 type_die
= modified_type_die (type
,
16825 decl_const
|| TYPE_READONLY (type
),
16826 decl_volatile
|| TYPE_VOLATILE (type
),
16829 if (type_die
!= NULL
)
16830 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16833 /* Given an object die, add the calling convention attribute for the
16834 function call type. */
16836 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16838 enum dwarf_calling_convention value
= DW_CC_normal
;
16840 value
= ((enum dwarf_calling_convention
)
16841 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16844 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16846 /* DWARF 2 doesn't provide a way to identify a program's source-level
16847 entry point. DW_AT_calling_convention attributes are only meant
16848 to describe functions' calling conventions. However, lacking a
16849 better way to signal the Fortran main program, we used this for
16850 a long time, following existing custom. Now, DWARF 4 has
16851 DW_AT_main_subprogram, which we add below, but some tools still
16852 rely on the old way, which we thus keep. */
16853 value
= DW_CC_program
;
16855 if (dwarf_version
>= 4 || !dwarf_strict
)
16856 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16859 /* Only add the attribute if the backend requests it, and
16860 is not DW_CC_normal. */
16861 if (value
&& (value
!= DW_CC_normal
))
16862 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16865 /* Given a tree pointer to a struct, class, union, or enum type node, return
16866 a pointer to the (string) tag name for the given type, or zero if the type
16867 was declared without a tag. */
16869 static const char *
16870 type_tag (const_tree type
)
16872 const char *name
= 0;
16874 if (TYPE_NAME (type
) != 0)
16878 /* Find the IDENTIFIER_NODE for the type name. */
16879 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16880 && !TYPE_NAMELESS (type
))
16881 t
= TYPE_NAME (type
);
16883 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16884 a TYPE_DECL node, regardless of whether or not a `typedef' was
16886 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16887 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16889 /* We want to be extra verbose. Don't call dwarf_name if
16890 DECL_NAME isn't set. The default hook for decl_printable_name
16891 doesn't like that, and in this context it's correct to return
16892 0, instead of "<anonymous>" or the like. */
16893 if (DECL_NAME (TYPE_NAME (type
))
16894 && !DECL_NAMELESS (TYPE_NAME (type
)))
16895 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16898 /* Now get the name as a string, or invent one. */
16899 if (!name
&& t
!= 0)
16900 name
= IDENTIFIER_POINTER (t
);
16903 return (name
== 0 || *name
== '\0') ? 0 : name
;
16906 /* Return the type associated with a data member, make a special check
16907 for bit field types. */
16910 member_declared_type (const_tree member
)
16912 return (DECL_BIT_FIELD_TYPE (member
)
16913 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16916 /* Get the decl's label, as described by its RTL. This may be different
16917 from the DECL_NAME name used in the source file. */
16920 static const char *
16921 decl_start_label (tree decl
)
16924 const char *fnname
;
16926 x
= DECL_RTL (decl
);
16927 gcc_assert (MEM_P (x
));
16930 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16932 fnname
= XSTR (x
, 0);
16937 /* These routines generate the internal representation of the DIE's for
16938 the compilation unit. Debugging information is collected by walking
16939 the declaration trees passed in from dwarf2out_decl(). */
16942 gen_array_type_die (tree type
, dw_die_ref context_die
)
16944 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16945 dw_die_ref array_die
;
16947 /* GNU compilers represent multidimensional array types as sequences of one
16948 dimensional array types whose element types are themselves array types.
16949 We sometimes squish that down to a single array_type DIE with multiple
16950 subscripts in the Dwarf debugging info. The draft Dwarf specification
16951 say that we are allowed to do this kind of compression in C, because
16952 there is no difference between an array of arrays and a multidimensional
16953 array. We don't do this for Ada to remain as close as possible to the
16954 actual representation, which is especially important against the language
16955 flexibilty wrt arrays of variable size. */
16957 bool collapse_nested_arrays
= !is_ada ();
16960 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16961 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16962 if (TYPE_STRING_FLAG (type
)
16963 && TREE_CODE (type
) == ARRAY_TYPE
16965 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16967 HOST_WIDE_INT size
;
16969 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16970 add_name_attribute (array_die
, type_tag (type
));
16971 equate_type_number_to_die (type
, array_die
);
16972 size
= int_size_in_bytes (type
);
16974 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16975 else if (TYPE_DOMAIN (type
) != NULL_TREE
16976 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16977 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16979 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16980 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16982 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16983 if (loc
&& size
> 0)
16985 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16986 if (size
!= DWARF2_ADDR_SIZE
)
16987 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16993 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16994 add_name_attribute (array_die
, type_tag (type
));
16995 equate_type_number_to_die (type
, array_die
);
16997 if (TREE_CODE (type
) == VECTOR_TYPE
)
16998 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
17000 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17002 && TREE_CODE (type
) == ARRAY_TYPE
17003 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17004 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17005 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17008 /* We default the array ordering. SDB will probably do
17009 the right things even if DW_AT_ordering is not present. It's not even
17010 an issue until we start to get into multidimensional arrays anyway. If
17011 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17012 then we'll have to put the DW_AT_ordering attribute back in. (But if
17013 and when we find out that we need to put these in, we will only do so
17014 for multidimensional arrays. */
17015 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17018 if (TREE_CODE (type
) == VECTOR_TYPE
)
17020 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17021 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17022 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
17023 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17024 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
17027 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17029 /* Add representation of the type of the elements of this array type and
17030 emit the corresponding DIE if we haven't done it already. */
17031 element_type
= TREE_TYPE (type
);
17032 if (collapse_nested_arrays
)
17033 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17035 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17037 element_type
= TREE_TYPE (element_type
);
17040 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
17042 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17043 if (TYPE_ARTIFICIAL (type
))
17044 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17046 if (get_AT (array_die
, DW_AT_name
))
17047 add_pubtype (type
, array_die
);
17050 static dw_loc_descr_ref
17051 descr_info_loc (tree val
, tree base_decl
)
17053 HOST_WIDE_INT size
;
17054 dw_loc_descr_ref loc
, loc2
;
17055 enum dwarf_location_atom op
;
17057 if (val
== base_decl
)
17058 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
17060 switch (TREE_CODE (val
))
17063 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17065 return loc_descriptor_from_tree (val
, 0);
17067 if (tree_fits_shwi_p (val
))
17068 return int_loc_descriptor (tree_to_shwi (val
));
17071 size
= int_size_in_bytes (TREE_TYPE (val
));
17074 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17077 if (size
== DWARF2_ADDR_SIZE
)
17078 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
17080 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
17082 case POINTER_PLUS_EXPR
:
17084 if (tree_fits_uhwi_p (TREE_OPERAND (val
, 1))
17085 && tree_to_uhwi (TREE_OPERAND (val
, 1)) < 16384)
17087 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17090 loc_descr_plus_const (&loc
, tree_to_shwi (TREE_OPERAND (val
, 1)));
17096 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17099 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
17102 add_loc_descr (&loc
, loc2
);
17103 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17125 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17126 tree val
, tree base_decl
)
17128 dw_loc_descr_ref loc
;
17130 if (tree_fits_shwi_p (val
))
17132 add_AT_unsigned (die
, attr
, tree_to_shwi (val
));
17136 loc
= descr_info_loc (val
, base_decl
);
17140 add_AT_loc (die
, attr
, loc
);
17143 /* This routine generates DIE for array with hidden descriptor, details
17144 are filled into *info by a langhook. */
17147 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17148 dw_die_ref context_die
)
17150 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17151 dw_die_ref array_die
;
17154 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17155 add_name_attribute (array_die
, type_tag (type
));
17156 equate_type_number_to_die (type
, array_die
);
17158 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17160 && info
->ndimensions
>= 2)
17161 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17163 if (info
->data_location
)
17164 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17166 if (info
->associated
)
17167 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17169 if (info
->allocated
)
17170 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17173 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17175 dw_die_ref subrange_die
17176 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17178 if (info
->dimen
[dim
].lower_bound
)
17180 /* If it is the default value, omit it. */
17183 if (tree_fits_shwi_p (info
->dimen
[dim
].lower_bound
)
17184 && (dflt
= lower_bound_default ()) != -1
17185 && tree_to_shwi (info
->dimen
[dim
].lower_bound
) == dflt
)
17188 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17189 info
->dimen
[dim
].lower_bound
,
17192 if (info
->dimen
[dim
].upper_bound
)
17193 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17194 info
->dimen
[dim
].upper_bound
,
17196 if (info
->dimen
[dim
].stride
)
17197 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17198 info
->dimen
[dim
].stride
,
17202 gen_type_die (info
->element_type
, context_die
);
17203 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17205 if (get_AT (array_die
, DW_AT_name
))
17206 add_pubtype (type
, array_die
);
17211 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17213 tree origin
= decl_ultimate_origin (decl
);
17214 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17216 if (origin
!= NULL
)
17217 add_abstract_origin_attribute (decl_die
, origin
);
17220 add_name_and_src_coords_attributes (decl_die
, decl
);
17221 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17222 0, 0, context_die
);
17225 if (DECL_ABSTRACT (decl
))
17226 equate_decl_number_to_die (decl
, decl_die
);
17228 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17232 /* Walk through the list of incomplete types again, trying once more to
17233 emit full debugging info for them. */
17236 retry_incomplete_types (void)
17240 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17241 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17242 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17245 /* Determine what tag to use for a record type. */
17247 static enum dwarf_tag
17248 record_type_tag (tree type
)
17250 if (! lang_hooks
.types
.classify_record
)
17251 return DW_TAG_structure_type
;
17253 switch (lang_hooks
.types
.classify_record (type
))
17255 case RECORD_IS_STRUCT
:
17256 return DW_TAG_structure_type
;
17258 case RECORD_IS_CLASS
:
17259 return DW_TAG_class_type
;
17261 case RECORD_IS_INTERFACE
:
17262 if (dwarf_version
>= 3 || !dwarf_strict
)
17263 return DW_TAG_interface_type
;
17264 return DW_TAG_structure_type
;
17267 gcc_unreachable ();
17271 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17272 include all of the information about the enumeration values also. Each
17273 enumerated type name/value is listed as a child of the enumerated type
17277 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17279 dw_die_ref type_die
= lookup_type_die (type
);
17281 if (type_die
== NULL
)
17283 type_die
= new_die (DW_TAG_enumeration_type
,
17284 scope_die_for (type
, context_die
), type
);
17285 equate_type_number_to_die (type
, type_die
);
17286 add_name_attribute (type_die
, type_tag (type
));
17287 if (dwarf_version
>= 4 || !dwarf_strict
)
17289 if (ENUM_IS_SCOPED (type
))
17290 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17291 if (ENUM_IS_OPAQUE (type
))
17292 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17295 else if (! TYPE_SIZE (type
))
17298 remove_AT (type_die
, DW_AT_declaration
);
17300 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17301 given enum type is incomplete, do not generate the DW_AT_byte_size
17302 attribute or the DW_AT_element_list attribute. */
17303 if (TYPE_SIZE (type
))
17307 TREE_ASM_WRITTEN (type
) = 1;
17308 add_byte_size_attribute (type_die
, type
);
17309 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17311 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17312 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17315 /* If the first reference to this type was as the return type of an
17316 inline function, then it may not have a parent. Fix this now. */
17317 if (type_die
->die_parent
== NULL
)
17318 add_child_die (scope_die_for (type
, context_die
), type_die
);
17320 for (link
= TYPE_VALUES (type
);
17321 link
!= NULL
; link
= TREE_CHAIN (link
))
17323 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17324 tree value
= TREE_VALUE (link
);
17326 add_name_attribute (enum_die
,
17327 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17329 if (TREE_CODE (value
) == CONST_DECL
)
17330 value
= DECL_INITIAL (value
);
17332 if (simple_type_size_in_bits (TREE_TYPE (value
))
17333 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
17334 /* DWARF2 does not provide a way of indicating whether or
17335 not enumeration constants are signed or unsigned. GDB
17336 always assumes the values are signed, so we output all
17337 values as if they were signed. That means that
17338 enumeration constants with very large unsigned values
17339 will appear to have negative values in the debugger.
17341 TODO: the above comment is wrong, DWARF2 does provide
17342 DW_FORM_sdata/DW_FORM_udata to represent signed/unsigned data.
17343 This should be re-worked to use correct signed/unsigned
17344 int/double tags for all cases, instead of always treating as
17346 add_AT_int (enum_die
, DW_AT_const_value
, TREE_INT_CST_LOW (value
));
17348 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17350 add_AT_double (enum_die
, DW_AT_const_value
,
17351 TREE_INT_CST_HIGH (value
), TREE_INT_CST_LOW (value
));
17354 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17355 if (TYPE_ARTIFICIAL (type
))
17356 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17359 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17361 add_pubtype (type
, type_die
);
17366 /* Generate a DIE to represent either a real live formal parameter decl or to
17367 represent just the type of some formal parameter position in some function
17370 Note that this routine is a bit unusual because its argument may be a
17371 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17372 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17373 node. If it's the former then this function is being called to output a
17374 DIE to represent a formal parameter object (or some inlining thereof). If
17375 it's the latter, then this function is only being called to output a
17376 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17377 argument type of some subprogram type.
17378 If EMIT_NAME_P is true, name and source coordinate attributes
17382 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17383 dw_die_ref context_die
)
17385 tree node_or_origin
= node
? node
: origin
;
17386 tree ultimate_origin
;
17387 dw_die_ref parm_die
17388 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17390 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17392 case tcc_declaration
:
17393 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17394 if (node
|| ultimate_origin
)
17395 origin
= ultimate_origin
;
17396 if (origin
!= NULL
)
17397 add_abstract_origin_attribute (parm_die
, origin
);
17398 else if (emit_name_p
)
17399 add_name_and_src_coords_attributes (parm_die
, node
);
17401 || (! DECL_ABSTRACT (node_or_origin
)
17402 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17403 decl_function_context
17404 (node_or_origin
))))
17406 tree type
= TREE_TYPE (node_or_origin
);
17407 if (decl_by_reference_p (node_or_origin
))
17408 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17411 add_type_attribute (parm_die
, type
,
17412 TREE_READONLY (node_or_origin
),
17413 TREE_THIS_VOLATILE (node_or_origin
),
17416 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17417 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17419 if (node
&& node
!= origin
)
17420 equate_decl_number_to_die (node
, parm_die
);
17421 if (! DECL_ABSTRACT (node_or_origin
))
17422 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17423 node
== NULL
, DW_AT_location
);
17428 /* We were called with some kind of a ..._TYPE node. */
17429 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17433 gcc_unreachable ();
17439 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17440 children DW_TAG_formal_parameter DIEs representing the arguments of the
17443 PARM_PACK must be a function parameter pack.
17444 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17445 must point to the subsequent arguments of the function PACK_ARG belongs to.
17446 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17447 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17448 following the last one for which a DIE was generated. */
17451 gen_formal_parameter_pack_die (tree parm_pack
,
17453 dw_die_ref subr_die
,
17457 dw_die_ref parm_pack_die
;
17459 gcc_assert (parm_pack
17460 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17463 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17464 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17466 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17468 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17471 gen_formal_parameter_die (arg
, NULL
,
17472 false /* Don't emit name attribute. */,
17477 return parm_pack_die
;
17480 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17481 at the end of an (ANSI prototyped) formal parameters list. */
17484 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17486 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17489 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17490 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17491 parameters as specified in some function type specification (except for
17492 those which appear as part of a function *definition*). */
17495 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17498 tree formal_type
= NULL
;
17499 tree first_parm_type
;
17502 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17504 arg
= DECL_ARGUMENTS (function_or_method_type
);
17505 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17510 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17512 /* Make our first pass over the list of formal parameter types and output a
17513 DW_TAG_formal_parameter DIE for each one. */
17514 for (link
= first_parm_type
; link
; )
17516 dw_die_ref parm_die
;
17518 formal_type
= TREE_VALUE (link
);
17519 if (formal_type
== void_type_node
)
17522 /* Output a (nameless) DIE to represent the formal parameter itself. */
17523 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17524 true /* Emit name attribute. */,
17526 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17527 && link
== first_parm_type
)
17529 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17530 if (dwarf_version
>= 3 || !dwarf_strict
)
17531 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17533 else if (arg
&& DECL_ARTIFICIAL (arg
))
17534 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17536 link
= TREE_CHAIN (link
);
17538 arg
= DECL_CHAIN (arg
);
17541 /* If this function type has an ellipsis, add a
17542 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17543 if (formal_type
!= void_type_node
)
17544 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17546 /* Make our second (and final) pass over the list of formal parameter types
17547 and output DIEs to represent those types (as necessary). */
17548 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17549 link
&& TREE_VALUE (link
);
17550 link
= TREE_CHAIN (link
))
17551 gen_type_die (TREE_VALUE (link
), context_die
);
17554 /* We want to generate the DIE for TYPE so that we can generate the
17555 die for MEMBER, which has been defined; we will need to refer back
17556 to the member declaration nested within TYPE. If we're trying to
17557 generate minimal debug info for TYPE, processing TYPE won't do the
17558 trick; we need to attach the member declaration by hand. */
17561 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17563 gen_type_die (type
, context_die
);
17565 /* If we're trying to avoid duplicate debug info, we may not have
17566 emitted the member decl for this function. Emit it now. */
17567 if (TYPE_STUB_DECL (type
)
17568 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17569 && ! lookup_decl_die (member
))
17571 dw_die_ref type_die
;
17572 gcc_assert (!decl_ultimate_origin (member
));
17574 push_decl_scope (type
);
17575 type_die
= lookup_type_die_strip_naming_typedef (type
);
17576 if (TREE_CODE (member
) == FUNCTION_DECL
)
17577 gen_subprogram_die (member
, type_die
);
17578 else if (TREE_CODE (member
) == FIELD_DECL
)
17580 /* Ignore the nameless fields that are used to skip bits but handle
17581 C++ anonymous unions and structs. */
17582 if (DECL_NAME (member
) != NULL_TREE
17583 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17584 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17586 gen_type_die (member_declared_type (member
), type_die
);
17587 gen_field_die (member
, type_die
);
17591 gen_variable_die (member
, NULL_TREE
, type_die
);
17597 /* Forward declare these functions, because they are mutually recursive
17598 with their set_block_* pairing functions. */
17599 static void set_decl_origin_self (tree
);
17600 static void set_decl_abstract_flags (tree
, int);
17602 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17603 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17604 that it points to the node itself, thus indicating that the node is its
17605 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17606 the given node is NULL, recursively descend the decl/block tree which
17607 it is the root of, and for each other ..._DECL or BLOCK node contained
17608 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17609 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17610 values to point to themselves. */
17613 set_block_origin_self (tree stmt
)
17615 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17617 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17622 for (local_decl
= BLOCK_VARS (stmt
);
17623 local_decl
!= NULL_TREE
;
17624 local_decl
= DECL_CHAIN (local_decl
))
17625 if (! DECL_EXTERNAL (local_decl
))
17626 set_decl_origin_self (local_decl
); /* Potential recursion. */
17632 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17633 subblock
!= NULL_TREE
;
17634 subblock
= BLOCK_CHAIN (subblock
))
17635 set_block_origin_self (subblock
); /* Recurse. */
17640 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17641 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17642 node to so that it points to the node itself, thus indicating that the
17643 node represents its own (abstract) origin. Additionally, if the
17644 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17645 the decl/block tree of which the given node is the root of, and for
17646 each other ..._DECL or BLOCK node contained therein whose
17647 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17648 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17649 point to themselves. */
17652 set_decl_origin_self (tree decl
)
17654 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17656 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17657 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17661 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17662 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17663 if (DECL_INITIAL (decl
) != NULL_TREE
17664 && DECL_INITIAL (decl
) != error_mark_node
)
17665 set_block_origin_self (DECL_INITIAL (decl
));
17670 /* Given a pointer to some BLOCK node, and a boolean value to set the
17671 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17672 the given block, and for all local decls and all local sub-blocks
17673 (recursively) which are contained therein. */
17676 set_block_abstract_flags (tree stmt
, int setting
)
17682 BLOCK_ABSTRACT (stmt
) = setting
;
17684 for (local_decl
= BLOCK_VARS (stmt
);
17685 local_decl
!= NULL_TREE
;
17686 local_decl
= DECL_CHAIN (local_decl
))
17687 if (! DECL_EXTERNAL (local_decl
))
17688 set_decl_abstract_flags (local_decl
, setting
);
17690 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17692 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17693 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17694 || TREE_CODE (local_decl
) == PARM_DECL
)
17695 set_decl_abstract_flags (local_decl
, setting
);
17698 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17699 subblock
!= NULL_TREE
;
17700 subblock
= BLOCK_CHAIN (subblock
))
17701 set_block_abstract_flags (subblock
, setting
);
17704 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17705 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17706 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17707 set the abstract flags for all of the parameters, local vars, local
17708 blocks and sub-blocks (recursively) to the same setting. */
17711 set_decl_abstract_flags (tree decl
, int setting
)
17713 DECL_ABSTRACT (decl
) = setting
;
17714 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17718 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17719 DECL_ABSTRACT (arg
) = setting
;
17720 if (DECL_INITIAL (decl
) != NULL_TREE
17721 && DECL_INITIAL (decl
) != error_mark_node
)
17722 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17726 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17727 may later generate inlined and/or out-of-line instances of. */
17730 dwarf2out_abstract_function (tree decl
)
17732 dw_die_ref old_die
;
17736 htab_t old_decl_loc_table
;
17737 htab_t old_cached_dw_loc_list_table
;
17738 int old_call_site_count
, old_tail_call_site_count
;
17739 struct call_arg_loc_node
*old_call_arg_locations
;
17741 /* Make sure we have the actual abstract inline, not a clone. */
17742 decl
= DECL_ORIGIN (decl
);
17744 old_die
= lookup_decl_die (decl
);
17745 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17746 /* We've already generated the abstract instance. */
17749 /* We can be called while recursively when seeing block defining inlined subroutine
17750 DIE. Be sure to not clobber the outer location table nor use it or we would
17751 get locations in abstract instantces. */
17752 old_decl_loc_table
= decl_loc_table
;
17753 decl_loc_table
= NULL
;
17754 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17755 cached_dw_loc_list_table
= NULL
;
17756 old_call_arg_locations
= call_arg_locations
;
17757 call_arg_locations
= NULL
;
17758 old_call_site_count
= call_site_count
;
17759 call_site_count
= -1;
17760 old_tail_call_site_count
= tail_call_site_count
;
17761 tail_call_site_count
= -1;
17763 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17764 we don't get confused by DECL_ABSTRACT. */
17765 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17767 context
= decl_class_context (decl
);
17769 gen_type_die_for_member
17770 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17773 /* Pretend we've just finished compiling this function. */
17774 save_fn
= current_function_decl
;
17775 current_function_decl
= decl
;
17777 was_abstract
= DECL_ABSTRACT (decl
);
17778 set_decl_abstract_flags (decl
, 1);
17779 dwarf2out_decl (decl
);
17780 if (! was_abstract
)
17781 set_decl_abstract_flags (decl
, 0);
17783 current_function_decl
= save_fn
;
17784 decl_loc_table
= old_decl_loc_table
;
17785 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17786 call_arg_locations
= old_call_arg_locations
;
17787 call_site_count
= old_call_site_count
;
17788 tail_call_site_count
= old_tail_call_site_count
;
17791 /* Helper function of premark_used_types() which gets called through
17794 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17795 marked as unused by prune_unused_types. */
17798 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17803 type
= (tree
) *slot
;
17804 die
= lookup_type_die (type
);
17806 die
->die_perennial_p
= 1;
17810 /* Helper function of premark_types_used_by_global_vars which gets called
17811 through htab_traverse.
17813 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17814 marked as unused by prune_unused_types. The DIE of the type is marked
17815 only if the global variable using the type will actually be emitted. */
17818 premark_types_used_by_global_vars_helper (void **slot
,
17819 void *data ATTRIBUTE_UNUSED
)
17821 struct types_used_by_vars_entry
*entry
;
17824 entry
= (struct types_used_by_vars_entry
*) *slot
;
17825 gcc_assert (entry
->type
!= NULL
17826 && entry
->var_decl
!= NULL
);
17827 die
= lookup_type_die (entry
->type
);
17830 /* Ask cgraph if the global variable really is to be emitted.
17831 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17832 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17833 if (node
&& node
->definition
)
17835 die
->die_perennial_p
= 1;
17836 /* Keep the parent DIEs as well. */
17837 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17838 die
->die_perennial_p
= 1;
17844 /* Mark all members of used_types_hash as perennial. */
17847 premark_used_types (struct function
*fun
)
17849 if (fun
&& fun
->used_types_hash
)
17850 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17853 /* Mark all members of types_used_by_vars_entry as perennial. */
17856 premark_types_used_by_global_vars (void)
17858 if (types_used_by_vars_hash
)
17859 htab_traverse (types_used_by_vars_hash
,
17860 premark_types_used_by_global_vars_helper
, NULL
);
17863 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17864 for CA_LOC call arg loc node. */
17867 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17868 struct call_arg_loc_node
*ca_loc
)
17870 dw_die_ref stmt_die
= NULL
, die
;
17871 tree block
= ca_loc
->block
;
17874 && block
!= DECL_INITIAL (decl
)
17875 && TREE_CODE (block
) == BLOCK
)
17877 if (block_map
.length () > BLOCK_NUMBER (block
))
17878 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17881 block
= BLOCK_SUPERCONTEXT (block
);
17883 if (stmt_die
== NULL
)
17884 stmt_die
= subr_die
;
17885 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17886 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17887 if (ca_loc
->tail_call_p
)
17888 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17889 if (ca_loc
->symbol_ref
)
17891 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17893 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17895 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17900 /* Generate a DIE to represent a declared function (either file-scope or
17904 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17906 tree origin
= decl_ultimate_origin (decl
);
17907 dw_die_ref subr_die
;
17909 dw_die_ref old_die
= lookup_decl_die (decl
);
17910 int declaration
= (current_function_decl
!= decl
17911 || class_or_namespace_scope_p (context_die
));
17913 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17915 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17916 started to generate the abstract instance of an inline, decided to output
17917 its containing class, and proceeded to emit the declaration of the inline
17918 from the member list for the class. If so, DECLARATION takes priority;
17919 we'll get back to the abstract instance when done with the class. */
17921 /* The class-scope declaration DIE must be the primary DIE. */
17922 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17925 gcc_assert (!old_die
);
17928 /* Now that the C++ front end lazily declares artificial member fns, we
17929 might need to retrofit the declaration into its class. */
17930 if (!declaration
&& !origin
&& !old_die
17931 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17932 && !class_or_namespace_scope_p (context_die
)
17933 && debug_info_level
> DINFO_LEVEL_TERSE
)
17934 old_die
= force_decl_die (decl
);
17936 if (origin
!= NULL
)
17938 gcc_assert (!declaration
|| local_scope_p (context_die
));
17940 /* Fixup die_parent for the abstract instance of a nested
17941 inline function. */
17942 if (old_die
&& old_die
->die_parent
== NULL
)
17943 add_child_die (context_die
, old_die
);
17945 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17946 add_abstract_origin_attribute (subr_die
, origin
);
17947 /* This is where the actual code for a cloned function is.
17948 Let's emit linkage name attribute for it. This helps
17949 debuggers to e.g, set breakpoints into
17950 constructors/destructors when the user asks "break
17952 add_linkage_name (subr_die
, decl
);
17956 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17957 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17959 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17960 /* We can have a normal definition following an inline one in the
17961 case of redefinition of GNU C extern inlines.
17962 It seems reasonable to use AT_specification in this case. */
17963 && !get_AT (old_die
, DW_AT_inline
))
17965 /* Detect and ignore this case, where we are trying to output
17966 something we have already output. */
17970 /* If the definition comes from the same place as the declaration,
17971 maybe use the old DIE. We always want the DIE for this function
17972 that has the *_pc attributes to be under comp_unit_die so the
17973 debugger can find it. We also need to do this for abstract
17974 instances of inlines, since the spec requires the out-of-line copy
17975 to have the same parent. For local class methods, this doesn't
17976 apply; we just use the old DIE. */
17977 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17978 && (DECL_ARTIFICIAL (decl
)
17979 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17980 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17981 == (unsigned) s
.line
))))
17983 subr_die
= old_die
;
17985 /* Clear out the declaration attribute and the formal parameters.
17986 Do not remove all children, because it is possible that this
17987 declaration die was forced using force_decl_die(). In such
17988 cases die that forced declaration die (e.g. TAG_imported_module)
17989 is one of the children that we do not want to remove. */
17990 remove_AT (subr_die
, DW_AT_declaration
);
17991 remove_AT (subr_die
, DW_AT_object_pointer
);
17992 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17996 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17997 add_AT_specification (subr_die
, old_die
);
17998 add_pubname (decl
, subr_die
);
17999 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18000 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18001 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18002 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18007 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18009 if (TREE_PUBLIC (decl
))
18010 add_AT_flag (subr_die
, DW_AT_external
, 1);
18012 add_name_and_src_coords_attributes (subr_die
, decl
);
18013 add_pubname (decl
, subr_die
);
18014 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18016 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18017 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18018 0, 0, context_die
);
18021 add_pure_or_virtual_attribute (subr_die
, decl
);
18022 if (DECL_ARTIFICIAL (decl
))
18023 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18025 add_accessibility_attribute (subr_die
, decl
);
18030 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18032 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18034 /* If this is an explicit function declaration then generate
18035 a DW_AT_explicit attribute. */
18036 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18037 && (dwarf_version
>= 3 || !dwarf_strict
))
18038 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18040 /* The first time we see a member function, it is in the context of
18041 the class to which it belongs. We make sure of this by emitting
18042 the class first. The next time is the definition, which is
18043 handled above. The two may come from the same source text.
18045 Note that force_decl_die() forces function declaration die. It is
18046 later reused to represent definition. */
18047 equate_decl_number_to_die (decl
, subr_die
);
18050 else if (DECL_ABSTRACT (decl
))
18052 if (DECL_DECLARED_INLINE_P (decl
))
18054 if (cgraph_function_possibly_inlined_p (decl
))
18055 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18057 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18061 if (cgraph_function_possibly_inlined_p (decl
))
18062 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18064 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18067 if (DECL_DECLARED_INLINE_P (decl
)
18068 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18069 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18071 equate_decl_number_to_die (decl
, subr_die
);
18073 else if (!DECL_EXTERNAL (decl
))
18075 HOST_WIDE_INT cfa_fb_offset
;
18076 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18078 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18079 equate_decl_number_to_die (decl
, subr_die
);
18081 gcc_checking_assert (fun
);
18082 if (!flag_reorder_blocks_and_partition
)
18084 dw_fde_ref fde
= fun
->fde
;
18085 if (fde
->dw_fde_begin
)
18087 /* We have already generated the labels. */
18088 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18089 fde
->dw_fde_end
, false);
18093 /* Create start/end labels and add the range. */
18094 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18095 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18096 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18097 current_function_funcdef_no
);
18098 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18099 current_function_funcdef_no
);
18100 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18104 #if VMS_DEBUGGING_INFO
18105 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18106 Section 2.3 Prologue and Epilogue Attributes:
18107 When a breakpoint is set on entry to a function, it is generally
18108 desirable for execution to be suspended, not on the very first
18109 instruction of the function, but rather at a point after the
18110 function's frame has been set up, after any language defined local
18111 declaration processing has been completed, and before execution of
18112 the first statement of the function begins. Debuggers generally
18113 cannot properly determine where this point is. Similarly for a
18114 breakpoint set on exit from a function. The prologue and epilogue
18115 attributes allow a compiler to communicate the location(s) to use. */
18118 if (fde
->dw_fde_vms_end_prologue
)
18119 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18120 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18122 if (fde
->dw_fde_vms_begin_epilogue
)
18123 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18124 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18131 /* Generate pubnames entries for the split function code ranges. */
18132 dw_fde_ref fde
= fun
->fde
;
18134 if (fde
->dw_fde_second_begin
)
18136 if (dwarf_version
>= 3 || !dwarf_strict
)
18138 /* We should use ranges for non-contiguous code section
18139 addresses. Use the actual code range for the initial
18140 section, since the HOT/COLD labels might precede an
18141 alignment offset. */
18142 bool range_list_added
= false;
18143 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18144 fde
->dw_fde_end
, &range_list_added
,
18146 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18147 fde
->dw_fde_second_end
,
18148 &range_list_added
, false);
18149 if (range_list_added
)
18154 /* There is no real support in DW2 for this .. so we make
18155 a work-around. First, emit the pub name for the segment
18156 containing the function label. Then make and emit a
18157 simplified subprogram DIE for the second segment with the
18158 name pre-fixed by __hot/cold_sect_of_. We use the same
18159 linkage name for the second die so that gdb will find both
18160 sections when given "b foo". */
18161 const char *name
= NULL
;
18162 tree decl_name
= DECL_NAME (decl
);
18163 dw_die_ref seg_die
;
18165 /* Do the 'primary' section. */
18166 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18167 fde
->dw_fde_end
, false);
18169 /* Build a minimal DIE for the secondary section. */
18170 seg_die
= new_die (DW_TAG_subprogram
,
18171 subr_die
->die_parent
, decl
);
18173 if (TREE_PUBLIC (decl
))
18174 add_AT_flag (seg_die
, DW_AT_external
, 1);
18176 if (decl_name
!= NULL
18177 && IDENTIFIER_POINTER (decl_name
) != NULL
)
18179 name
= dwarf2_name (decl
, 1);
18180 if (! DECL_ARTIFICIAL (decl
))
18181 add_src_coords_attributes (seg_die
, decl
);
18183 add_linkage_name (seg_die
, decl
);
18185 gcc_assert (name
!= NULL
);
18186 add_pure_or_virtual_attribute (seg_die
, decl
);
18187 if (DECL_ARTIFICIAL (decl
))
18188 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
18190 name
= concat ("__second_sect_of_", name
, NULL
);
18191 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
18192 fde
->dw_fde_second_end
, false);
18193 add_name_attribute (seg_die
, name
);
18194 if (want_pubnames ())
18195 add_pubname_string (name
, seg_die
);
18199 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
18203 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18205 /* We define the "frame base" as the function's CFA. This is more
18206 convenient for several reasons: (1) It's stable across the prologue
18207 and epilogue, which makes it better than just a frame pointer,
18208 (2) With dwarf3, there exists a one-byte encoding that allows us
18209 to reference the .debug_frame data by proxy, but failing that,
18210 (3) We can at least reuse the code inspection and interpretation
18211 code that determines the CFA position at various points in the
18213 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18215 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18216 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18220 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18221 if (list
->dw_loc_next
)
18222 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18224 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18227 /* Compute a displacement from the "steady-state frame pointer" to
18228 the CFA. The former is what all stack slots and argument slots
18229 will reference in the rtl; the latter is what we've told the
18230 debugger about. We'll need to adjust all frame_base references
18231 by this displacement. */
18232 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18234 if (fun
->static_chain_decl
)
18235 add_AT_location_description (subr_die
, DW_AT_static_link
,
18236 loc_list_from_tree (fun
->static_chain_decl
, 2));
18239 /* Generate child dies for template paramaters. */
18240 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18241 gen_generic_params_dies (decl
);
18243 /* Now output descriptions of the arguments for this function. This gets
18244 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18245 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18246 `...' at the end of the formal parameter list. In order to find out if
18247 there was a trailing ellipsis or not, we must instead look at the type
18248 associated with the FUNCTION_DECL. This will be a node of type
18249 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18250 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18251 an ellipsis at the end. */
18253 /* In the case where we are describing a mere function declaration, all we
18254 need to do here (and all we *can* do here) is to describe the *types* of
18255 its formal parameters. */
18256 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18258 else if (declaration
)
18259 gen_formal_types_die (decl
, subr_die
);
18262 /* Generate DIEs to represent all known formal parameters. */
18263 tree parm
= DECL_ARGUMENTS (decl
);
18264 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18265 tree generic_decl_parm
= generic_decl
18266 ? DECL_ARGUMENTS (generic_decl
)
18269 /* Now we want to walk the list of parameters of the function and
18270 emit their relevant DIEs.
18272 We consider the case of DECL being an instance of a generic function
18273 as well as it being a normal function.
18275 If DECL is an instance of a generic function we walk the
18276 parameters of the generic function declaration _and_ the parameters of
18277 DECL itself. This is useful because we want to emit specific DIEs for
18278 function parameter packs and those are declared as part of the
18279 generic function declaration. In that particular case,
18280 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18281 That DIE has children DIEs representing the set of arguments
18282 of the pack. Note that the set of pack arguments can be empty.
18283 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18286 Otherwise, we just consider the parameters of DECL. */
18287 while (generic_decl_parm
|| parm
)
18289 if (generic_decl_parm
18290 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18291 gen_formal_parameter_pack_die (generic_decl_parm
,
18294 else if (parm
&& !POINTER_BOUNDS_P (parm
))
18296 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18298 if (parm
== DECL_ARGUMENTS (decl
)
18299 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18301 && (dwarf_version
>= 3 || !dwarf_strict
))
18302 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18304 parm
= DECL_CHAIN (parm
);
18307 parm
= DECL_CHAIN (parm
);
18309 if (generic_decl_parm
)
18310 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18313 /* Decide whether we need an unspecified_parameters DIE at the end.
18314 There are 2 more cases to do this for: 1) the ansi ... declaration -
18315 this is detectable when the end of the arg list is not a
18316 void_type_node 2) an unprototyped function declaration (not a
18317 definition). This just means that we have no info about the
18318 parameters at all. */
18319 if (prototype_p (TREE_TYPE (decl
)))
18321 /* This is the prototyped case, check for.... */
18322 if (stdarg_p (TREE_TYPE (decl
)))
18323 gen_unspecified_parameters_die (decl
, subr_die
);
18325 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18326 gen_unspecified_parameters_die (decl
, subr_die
);
18329 /* Output Dwarf info for all of the stuff within the body of the function
18330 (if it has one - it may be just a declaration). */
18331 outer_scope
= DECL_INITIAL (decl
);
18333 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18334 a function. This BLOCK actually represents the outermost binding contour
18335 for the function, i.e. the contour in which the function's formal
18336 parameters and labels get declared. Curiously, it appears that the front
18337 end doesn't actually put the PARM_DECL nodes for the current function onto
18338 the BLOCK_VARS list for this outer scope, but are strung off of the
18339 DECL_ARGUMENTS list for the function instead.
18341 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18342 the LABEL_DECL nodes for the function however, and we output DWARF info
18343 for those in decls_for_scope. Just within the `outer_scope' there will be
18344 a BLOCK node representing the function's outermost pair of curly braces,
18345 and any blocks used for the base and member initializers of a C++
18346 constructor function. */
18347 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18349 int call_site_note_count
= 0;
18350 int tail_call_site_note_count
= 0;
18352 /* Emit a DW_TAG_variable DIE for a named return value. */
18353 if (DECL_NAME (DECL_RESULT (decl
)))
18354 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18356 current_function_has_inlines
= 0;
18357 decls_for_scope (outer_scope
, subr_die
, 0);
18359 if (call_arg_locations
&& !dwarf_strict
)
18361 struct call_arg_loc_node
*ca_loc
;
18362 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18364 dw_die_ref die
= NULL
;
18365 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18368 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18369 arg
; arg
= next_arg
)
18371 dw_loc_descr_ref reg
, val
;
18372 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18373 dw_die_ref cdie
, tdie
= NULL
;
18375 next_arg
= XEXP (arg
, 1);
18376 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18378 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18379 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18380 && REGNO (XEXP (XEXP (arg
, 0), 0))
18381 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18382 next_arg
= XEXP (next_arg
, 1);
18383 if (mode
== VOIDmode
)
18385 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18386 if (mode
== VOIDmode
)
18387 mode
= GET_MODE (XEXP (arg
, 0));
18389 if (mode
== VOIDmode
|| mode
== BLKmode
)
18391 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18393 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18394 tloc
= XEXP (XEXP (arg
, 0), 1);
18397 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18398 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18400 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18401 tlocc
= XEXP (XEXP (arg
, 0), 1);
18405 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18406 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18407 VAR_INIT_STATUS_INITIALIZED
);
18408 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18410 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18411 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18412 get_address_mode (mem
),
18414 VAR_INIT_STATUS_INITIALIZED
);
18416 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18417 == DEBUG_PARAMETER_REF
)
18420 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18421 tdie
= lookup_decl_die (tdecl
);
18428 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18429 != DEBUG_PARAMETER_REF
)
18431 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18433 VAR_INIT_STATUS_INITIALIZED
);
18437 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18438 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18441 add_AT_loc (cdie
, DW_AT_location
, reg
);
18442 else if (tdie
!= NULL
)
18443 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18444 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18445 if (next_arg
!= XEXP (arg
, 1))
18447 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18448 if (mode
== VOIDmode
)
18449 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18450 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18453 VAR_INIT_STATUS_INITIALIZED
);
18455 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18459 && (ca_loc
->symbol_ref
|| tloc
))
18460 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18461 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18463 dw_loc_descr_ref tval
= NULL
;
18465 if (tloc
!= NULL_RTX
)
18466 tval
= mem_loc_descriptor (tloc
,
18467 GET_MODE (tloc
) == VOIDmode
18468 ? Pmode
: GET_MODE (tloc
),
18470 VAR_INIT_STATUS_INITIALIZED
);
18472 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18473 else if (tlocc
!= NULL_RTX
)
18475 tval
= mem_loc_descriptor (tlocc
,
18476 GET_MODE (tlocc
) == VOIDmode
18477 ? Pmode
: GET_MODE (tlocc
),
18479 VAR_INIT_STATUS_INITIALIZED
);
18481 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18487 call_site_note_count
++;
18488 if (ca_loc
->tail_call_p
)
18489 tail_call_site_note_count
++;
18493 call_arg_locations
= NULL
;
18494 call_arg_loc_last
= NULL
;
18495 if (tail_call_site_count
>= 0
18496 && tail_call_site_count
== tail_call_site_note_count
18499 if (call_site_count
>= 0
18500 && call_site_count
== call_site_note_count
)
18501 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18503 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18505 call_site_count
= -1;
18506 tail_call_site_count
= -1;
18508 /* Add the calling convention attribute if requested. */
18509 add_calling_convention_attribute (subr_die
, decl
);
18513 /* Returns a hash value for X (which really is a die_struct). */
18516 common_block_die_table_hash (const void *x
)
18518 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18519 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18522 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18523 as decl_id and die_parent of die_struct Y. */
18526 common_block_die_table_eq (const void *x
, const void *y
)
18528 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18529 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18530 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18533 /* Generate a DIE to represent a declared data object.
18534 Either DECL or ORIGIN must be non-null. */
18537 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18539 HOST_WIDE_INT off
= 0;
18541 tree decl_or_origin
= decl
? decl
: origin
;
18542 tree ultimate_origin
;
18543 dw_die_ref var_die
;
18544 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18545 dw_die_ref origin_die
;
18546 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18547 || class_or_namespace_scope_p (context_die
));
18548 bool specialization_p
= false;
18550 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18551 if (decl
|| ultimate_origin
)
18552 origin
= ultimate_origin
;
18553 com_decl
= fortran_common (decl_or_origin
, &off
);
18555 /* Symbol in common gets emitted as a child of the common block, in the form
18556 of a data member. */
18559 dw_die_ref com_die
;
18560 dw_loc_list_ref loc
;
18561 die_node com_die_arg
;
18563 var_die
= lookup_decl_die (decl_or_origin
);
18566 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18568 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18573 /* Optimize the common case. */
18574 if (single_element_loc_list_p (loc
)
18575 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18576 && loc
->expr
->dw_loc_next
== NULL
18577 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18580 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18581 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18582 = plus_constant (GET_MODE (x
), x
, off
);
18585 loc_list_plus_const (loc
, off
);
18587 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18588 remove_AT (var_die
, DW_AT_declaration
);
18594 if (common_block_die_table
== NULL
)
18595 common_block_die_table
18596 = htab_create_ggc (10, common_block_die_table_hash
,
18597 common_block_die_table_eq
, NULL
);
18599 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18600 com_die_arg
.die_parent
= context_die
;
18601 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18602 loc
= loc_list_from_tree (com_decl
, 2);
18603 if (com_die
== NULL
)
18606 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18609 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18610 add_name_and_src_coords_attributes (com_die
, com_decl
);
18613 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18614 /* Avoid sharing the same loc descriptor between
18615 DW_TAG_common_block and DW_TAG_variable. */
18616 loc
= loc_list_from_tree (com_decl
, 2);
18618 else if (DECL_EXTERNAL (decl
))
18619 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18620 if (want_pubnames ())
18621 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18622 com_die
->decl_id
= DECL_UID (com_decl
);
18623 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18624 *slot
= (void *) com_die
;
18626 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18628 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18629 loc
= loc_list_from_tree (com_decl
, 2);
18630 remove_AT (com_die
, DW_AT_declaration
);
18632 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18633 add_name_and_src_coords_attributes (var_die
, decl
);
18634 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18635 TREE_THIS_VOLATILE (decl
), context_die
);
18636 add_AT_flag (var_die
, DW_AT_external
, 1);
18641 /* Optimize the common case. */
18642 if (single_element_loc_list_p (loc
)
18643 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18644 && loc
->expr
->dw_loc_next
== NULL
18645 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18647 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18648 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18649 = plus_constant (GET_MODE (x
), x
, off
);
18652 loc_list_plus_const (loc
, off
);
18654 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18656 else if (DECL_EXTERNAL (decl
))
18657 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18658 equate_decl_number_to_die (decl
, var_die
);
18662 /* If the compiler emitted a definition for the DECL declaration
18663 and if we already emitted a DIE for it, don't emit a second
18664 DIE for it again. Allow re-declarations of DECLs that are
18665 inside functions, though. */
18666 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18669 /* For static data members, the declaration in the class is supposed
18670 to have DW_TAG_member tag; the specification should still be
18671 DW_TAG_variable referencing the DW_TAG_member DIE. */
18672 if (declaration
&& class_scope_p (context_die
))
18673 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18675 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18678 if (origin
!= NULL
)
18679 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18681 /* Loop unrolling can create multiple blocks that refer to the same
18682 static variable, so we must test for the DW_AT_declaration flag.
18684 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18685 copy decls and set the DECL_ABSTRACT flag on them instead of
18688 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18690 ??? The declare_in_namespace support causes us to get two DIEs for one
18691 variable, both of which are declarations. We want to avoid considering
18692 one to be a specification, so we must test that this DIE is not a
18694 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18695 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18697 /* This is a definition of a C++ class level static. */
18698 add_AT_specification (var_die
, old_die
);
18699 specialization_p
= true;
18700 if (DECL_NAME (decl
))
18702 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18703 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18705 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18706 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18708 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18709 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18711 if (old_die
->die_tag
== DW_TAG_member
)
18712 add_linkage_name (var_die
, decl
);
18716 add_name_and_src_coords_attributes (var_die
, decl
);
18718 if ((origin
== NULL
&& !specialization_p
)
18720 && !DECL_ABSTRACT (decl_or_origin
)
18721 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18722 decl_function_context
18723 (decl_or_origin
))))
18725 tree type
= TREE_TYPE (decl_or_origin
);
18727 if (decl_by_reference_p (decl_or_origin
))
18728 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18730 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18731 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18734 if (origin
== NULL
&& !specialization_p
)
18736 if (TREE_PUBLIC (decl
))
18737 add_AT_flag (var_die
, DW_AT_external
, 1);
18739 if (DECL_ARTIFICIAL (decl
))
18740 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18742 add_accessibility_attribute (var_die
, decl
);
18746 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18748 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18749 equate_decl_number_to_die (decl
, var_die
);
18752 && (! DECL_ABSTRACT (decl_or_origin
)
18753 /* Local static vars are shared between all clones/inlines,
18754 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18756 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18757 && TREE_STATIC (decl_or_origin
)
18758 && DECL_RTL_SET_P (decl_or_origin
)))
18759 /* When abstract origin already has DW_AT_location attribute, no need
18760 to add it again. */
18761 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18763 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18764 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18765 defer_location (decl_or_origin
, var_die
);
18767 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18768 decl
== NULL
, DW_AT_location
);
18769 add_pubname (decl_or_origin
, var_die
);
18772 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18775 /* Generate a DIE to represent a named constant. */
18778 gen_const_die (tree decl
, dw_die_ref context_die
)
18780 dw_die_ref const_die
;
18781 tree type
= TREE_TYPE (decl
);
18783 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18784 add_name_and_src_coords_attributes (const_die
, decl
);
18785 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18786 if (TREE_PUBLIC (decl
))
18787 add_AT_flag (const_die
, DW_AT_external
, 1);
18788 if (DECL_ARTIFICIAL (decl
))
18789 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18790 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18793 /* Generate a DIE to represent a label identifier. */
18796 gen_label_die (tree decl
, dw_die_ref context_die
)
18798 tree origin
= decl_ultimate_origin (decl
);
18799 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18801 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18803 if (origin
!= NULL
)
18804 add_abstract_origin_attribute (lbl_die
, origin
);
18806 add_name_and_src_coords_attributes (lbl_die
, decl
);
18808 if (DECL_ABSTRACT (decl
))
18809 equate_decl_number_to_die (decl
, lbl_die
);
18812 insn
= DECL_RTL_IF_SET (decl
);
18814 /* Deleted labels are programmer specified labels which have been
18815 eliminated because of various optimizations. We still emit them
18816 here so that it is possible to put breakpoints on them. */
18820 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18822 /* When optimization is enabled (via -O) some parts of the compiler
18823 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18824 represent source-level labels which were explicitly declared by
18825 the user. This really shouldn't be happening though, so catch
18826 it if it ever does happen. */
18827 gcc_assert (!INSN_DELETED_P (insn
));
18829 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18830 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18834 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18835 && CODE_LABEL_NUMBER (insn
) != -1)
18837 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18838 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18843 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18844 attributes to the DIE for a block STMT, to describe where the inlined
18845 function was called from. This is similar to add_src_coords_attributes. */
18848 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18850 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18852 if (dwarf_version
>= 3 || !dwarf_strict
)
18854 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18855 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18860 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18861 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18864 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18866 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18868 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18869 && (dwarf_version
>= 3 || !dwarf_strict
))
18871 tree chain
, superblock
= NULL_TREE
;
18873 dw_attr_ref attr
= NULL
;
18875 if (inlined_function_outer_scope_p (stmt
))
18877 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18878 BLOCK_NUMBER (stmt
));
18879 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18882 /* Optimize duplicate .debug_ranges lists or even tails of
18883 lists. If this BLOCK has same ranges as its supercontext,
18884 lookup DW_AT_ranges attribute in the supercontext (and
18885 recursively so), verify that the ranges_table contains the
18886 right values and use it instead of adding a new .debug_range. */
18887 for (chain
= stmt
, pdie
= die
;
18888 BLOCK_SAME_RANGE (chain
);
18889 chain
= BLOCK_SUPERCONTEXT (chain
))
18891 dw_attr_ref new_attr
;
18893 pdie
= pdie
->die_parent
;
18896 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18898 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18899 if (new_attr
== NULL
18900 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18903 superblock
= BLOCK_SUPERCONTEXT (chain
);
18906 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18907 / 2 / DWARF2_ADDR_SIZE
].num
18908 == BLOCK_NUMBER (superblock
))
18909 && BLOCK_FRAGMENT_CHAIN (superblock
))
18911 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18912 / 2 / DWARF2_ADDR_SIZE
;
18913 unsigned long supercnt
= 0, thiscnt
= 0;
18914 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18915 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18918 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18919 == BLOCK_NUMBER (chain
));
18921 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18922 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18923 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18925 gcc_assert (supercnt
>= thiscnt
);
18926 add_AT_range_list (die
, DW_AT_ranges
,
18927 ((off
+ supercnt
- thiscnt
)
18928 * 2 * DWARF2_ADDR_SIZE
),
18933 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18935 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18938 add_ranges (chain
);
18939 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18946 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18947 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18948 BLOCK_NUMBER (stmt
));
18949 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18950 BLOCK_NUMBER (stmt
));
18951 add_AT_low_high_pc (die
, label
, label_high
, false);
18955 /* Generate a DIE for a lexical block. */
18958 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18960 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18962 if (call_arg_locations
)
18964 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18965 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18966 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18969 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18970 add_high_low_attributes (stmt
, stmt_die
);
18972 decls_for_scope (stmt
, stmt_die
, depth
);
18975 /* Generate a DIE for an inlined subprogram. */
18978 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18982 /* The instance of function that is effectively being inlined shall not
18984 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18986 decl
= block_ultimate_origin (stmt
);
18988 /* Emit info for the abstract instance first, if we haven't yet. We
18989 must emit this even if the block is abstract, otherwise when we
18990 emit the block below (or elsewhere), we may end up trying to emit
18991 a die whose origin die hasn't been emitted, and crashing. */
18992 dwarf2out_abstract_function (decl
);
18994 if (! BLOCK_ABSTRACT (stmt
))
18996 dw_die_ref subr_die
18997 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18999 if (call_arg_locations
)
19001 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
19002 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
19003 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
19005 add_abstract_origin_attribute (subr_die
, decl
);
19006 if (TREE_ASM_WRITTEN (stmt
))
19007 add_high_low_attributes (stmt
, subr_die
);
19008 add_call_src_coords_attributes (stmt
, subr_die
);
19010 decls_for_scope (stmt
, subr_die
, depth
);
19011 current_function_has_inlines
= 1;
19015 /* Generate a DIE for a field in a record, or structure. */
19018 gen_field_die (tree decl
, dw_die_ref context_die
)
19020 dw_die_ref decl_die
;
19022 if (TREE_TYPE (decl
) == error_mark_node
)
19025 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19026 add_name_and_src_coords_attributes (decl_die
, decl
);
19027 add_type_attribute (decl_die
, member_declared_type (decl
),
19028 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
19031 if (DECL_BIT_FIELD_TYPE (decl
))
19033 add_byte_size_attribute (decl_die
, decl
);
19034 add_bit_size_attribute (decl_die
, decl
);
19035 add_bit_offset_attribute (decl_die
, decl
);
19038 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19039 add_data_member_location_attribute (decl_die
, decl
);
19041 if (DECL_ARTIFICIAL (decl
))
19042 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19044 add_accessibility_attribute (decl_die
, decl
);
19046 /* Equate decl number to die, so that we can look up this decl later on. */
19047 equate_decl_number_to_die (decl
, decl_die
);
19051 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19052 Use modified_type_die instead.
19053 We keep this code here just in case these types of DIEs may be needed to
19054 represent certain things in other languages (e.g. Pascal) someday. */
19057 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19060 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19062 equate_type_number_to_die (type
, ptr_die
);
19063 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19064 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19067 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19068 Use modified_type_die instead.
19069 We keep this code here just in case these types of DIEs may be needed to
19070 represent certain things in other languages (e.g. Pascal) someday. */
19073 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19075 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19077 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19078 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19080 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19082 equate_type_number_to_die (type
, ref_die
);
19083 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
19084 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19088 /* Generate a DIE for a pointer to a member type. */
19091 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
19094 = new_die (DW_TAG_ptr_to_member_type
,
19095 scope_die_for (type
, context_die
), type
);
19097 equate_type_number_to_die (type
, ptr_die
);
19098 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
19099 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
19100 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19103 typedef const char *dchar_p
; /* For DEF_VEC_P. */
19105 static char *producer_string
;
19107 /* Return a heap allocated producer string including command line options
19108 if -grecord-gcc-switches. */
19111 gen_producer_string (void)
19114 auto_vec
<dchar_p
> switches
;
19115 const char *language_string
= lang_hooks
.name
;
19116 char *producer
, *tail
;
19118 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
19119 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
19121 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
19122 switch (save_decoded_options
[j
].opt_index
)
19129 case OPT_auxbase_strip
:
19138 case OPT_SPECIAL_unknown
:
19139 case OPT_SPECIAL_ignore
:
19140 case OPT_SPECIAL_program_name
:
19141 case OPT_SPECIAL_input_file
:
19142 case OPT_grecord_gcc_switches
:
19143 case OPT_gno_record_gcc_switches
:
19144 case OPT__output_pch_
:
19145 case OPT_fdiagnostics_show_location_
:
19146 case OPT_fdiagnostics_show_option
:
19147 case OPT_fdiagnostics_show_caret
:
19148 case OPT_fdiagnostics_color_
:
19149 case OPT_fverbose_asm
:
19151 case OPT__sysroot_
:
19153 case OPT_nostdinc__
:
19154 /* Ignore these. */
19157 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
19158 & CL_NO_DWARF_RECORD
)
19160 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
19162 switch (save_decoded_options
[j
].canonical_option
[0][1])
19169 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
19176 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
19177 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
19181 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
19183 sprintf (tail
, "%s %s", language_string
, version_string
);
19186 FOR_EACH_VEC_ELT (switches
, j
, p
)
19190 memcpy (tail
+ 1, p
, len
);
19198 /* Generate the DIE for the compilation unit. */
19201 gen_compile_unit_die (const char *filename
)
19204 const char *language_string
= lang_hooks
.name
;
19207 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19211 add_name_attribute (die
, filename
);
19212 /* Don't add cwd for <built-in>. */
19213 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19214 add_comp_dir_attribute (die
);
19217 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19219 /* If our producer is LTO try to figure out a common language to use
19220 from the global list of translation units. */
19221 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19225 const char *common_lang
= NULL
;
19227 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19229 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19232 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19233 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19235 else if (strncmp (common_lang
, "GNU C", 5) == 0
19236 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19237 /* Mixing C and C++ is ok, use C++ in that case. */
19238 common_lang
= "GNU C++";
19241 /* Fall back to C. */
19242 common_lang
= NULL
;
19248 language_string
= common_lang
;
19251 language
= DW_LANG_C89
;
19252 if (strcmp (language_string
, "GNU C++") == 0)
19253 language
= DW_LANG_C_plus_plus
;
19254 else if (strcmp (language_string
, "GNU F77") == 0)
19255 language
= DW_LANG_Fortran77
;
19256 else if (strcmp (language_string
, "GNU Pascal") == 0)
19257 language
= DW_LANG_Pascal83
;
19258 else if (dwarf_version
>= 3 || !dwarf_strict
)
19260 if (strcmp (language_string
, "GNU Ada") == 0)
19261 language
= DW_LANG_Ada95
;
19262 else if (strcmp (language_string
, "GNU Fortran") == 0)
19263 language
= DW_LANG_Fortran95
;
19264 else if (strcmp (language_string
, "GNU Java") == 0)
19265 language
= DW_LANG_Java
;
19266 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19267 language
= DW_LANG_ObjC
;
19268 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19269 language
= DW_LANG_ObjC_plus_plus
;
19270 else if (dwarf_version
>= 5 || !dwarf_strict
)
19272 if (strcmp (language_string
, "GNU Go") == 0)
19273 language
= DW_LANG_Go
;
19276 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19277 else if (strcmp (language_string
, "GNU Fortran") == 0)
19278 language
= DW_LANG_Fortran90
;
19280 add_AT_unsigned (die
, DW_AT_language
, language
);
19284 case DW_LANG_Fortran77
:
19285 case DW_LANG_Fortran90
:
19286 case DW_LANG_Fortran95
:
19287 /* Fortran has case insensitive identifiers and the front-end
19288 lowercases everything. */
19289 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19292 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19298 /* Generate the DIE for a base class. */
19301 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19303 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19305 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19306 add_data_member_location_attribute (die
, binfo
);
19308 if (BINFO_VIRTUAL_P (binfo
))
19309 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19311 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19312 children, otherwise the default is DW_ACCESS_public. In DWARF2
19313 the default has always been DW_ACCESS_private. */
19314 if (access
== access_public_node
)
19316 if (dwarf_version
== 2
19317 || context_die
->die_tag
== DW_TAG_class_type
)
19318 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19320 else if (access
== access_protected_node
)
19321 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19322 else if (dwarf_version
> 2
19323 && context_die
->die_tag
!= DW_TAG_class_type
)
19324 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19327 /* Generate a DIE for a class member. */
19330 gen_member_die (tree type
, dw_die_ref context_die
)
19333 tree binfo
= TYPE_BINFO (type
);
19336 /* If this is not an incomplete type, output descriptions of each of its
19337 members. Note that as we output the DIEs necessary to represent the
19338 members of this record or union type, we will also be trying to output
19339 DIEs to represent the *types* of those members. However the `type'
19340 function (above) will specifically avoid generating type DIEs for member
19341 types *within* the list of member DIEs for this (containing) type except
19342 for those types (of members) which are explicitly marked as also being
19343 members of this (containing) type themselves. The g++ front- end can
19344 force any given type to be treated as a member of some other (containing)
19345 type by setting the TYPE_CONTEXT of the given (member) type to point to
19346 the TREE node representing the appropriate (containing) type. */
19348 /* First output info about the base classes. */
19351 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19355 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19356 gen_inheritance_die (base
,
19357 (accesses
? (*accesses
)[i
] : access_public_node
),
19361 /* Now output info about the data members and type members. */
19362 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19364 /* If we thought we were generating minimal debug info for TYPE
19365 and then changed our minds, some of the member declarations
19366 may have already been defined. Don't define them again, but
19367 do put them in the right order. */
19369 child
= lookup_decl_die (member
);
19371 splice_child_die (context_die
, child
);
19373 gen_decl_die (member
, NULL
, context_die
);
19376 /* Now output info about the function members (if any). */
19377 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19379 /* Don't include clones in the member list. */
19380 if (DECL_ABSTRACT_ORIGIN (member
))
19383 child
= lookup_decl_die (member
);
19385 splice_child_die (context_die
, child
);
19387 gen_decl_die (member
, NULL
, context_die
);
19391 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19392 is set, we pretend that the type was never defined, so we only get the
19393 member DIEs needed by later specification DIEs. */
19396 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19397 enum debug_info_usage usage
)
19399 dw_die_ref type_die
= lookup_type_die (type
);
19400 dw_die_ref scope_die
= 0;
19402 int complete
= (TYPE_SIZE (type
)
19403 && (! TYPE_STUB_DECL (type
)
19404 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19405 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19406 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19408 if (type_die
&& ! complete
)
19411 if (TYPE_CONTEXT (type
) != NULL_TREE
19412 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19413 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19416 scope_die
= scope_die_for (type
, context_die
);
19418 /* Generate child dies for template paramaters. */
19419 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19420 schedule_generic_params_dies_gen (type
);
19422 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19423 /* First occurrence of type or toplevel definition of nested class. */
19425 dw_die_ref old_die
= type_die
;
19427 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19428 ? record_type_tag (type
) : DW_TAG_union_type
,
19430 equate_type_number_to_die (type
, type_die
);
19432 add_AT_specification (type_die
, old_die
);
19434 add_name_attribute (type_die
, type_tag (type
));
19437 remove_AT (type_die
, DW_AT_declaration
);
19439 /* If this type has been completed, then give it a byte_size attribute and
19440 then give a list of members. */
19441 if (complete
&& !ns_decl
)
19443 /* Prevent infinite recursion in cases where the type of some member of
19444 this type is expressed in terms of this type itself. */
19445 TREE_ASM_WRITTEN (type
) = 1;
19446 add_byte_size_attribute (type_die
, type
);
19447 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19449 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19450 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19453 /* If the first reference to this type was as the return type of an
19454 inline function, then it may not have a parent. Fix this now. */
19455 if (type_die
->die_parent
== NULL
)
19456 add_child_die (scope_die
, type_die
);
19458 push_decl_scope (type
);
19459 gen_member_die (type
, type_die
);
19462 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19463 if (TYPE_ARTIFICIAL (type
))
19464 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19466 /* GNU extension: Record what type our vtable lives in. */
19467 if (TYPE_VFIELD (type
))
19469 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19471 gen_type_die (vtype
, context_die
);
19472 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19473 lookup_type_die (vtype
));
19478 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19480 /* We don't need to do this for function-local types. */
19481 if (TYPE_STUB_DECL (type
)
19482 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19483 vec_safe_push (incomplete_types
, type
);
19486 if (get_AT (type_die
, DW_AT_name
))
19487 add_pubtype (type
, type_die
);
19490 /* Generate a DIE for a subroutine _type_. */
19493 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19495 tree return_type
= TREE_TYPE (type
);
19496 dw_die_ref subr_die
19497 = new_die (DW_TAG_subroutine_type
,
19498 scope_die_for (type
, context_die
), type
);
19500 equate_type_number_to_die (type
, subr_die
);
19501 add_prototyped_attribute (subr_die
, type
);
19502 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19503 gen_formal_types_die (type
, subr_die
);
19505 if (get_AT (subr_die
, DW_AT_name
))
19506 add_pubtype (type
, subr_die
);
19509 /* Generate a DIE for a type definition. */
19512 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19514 dw_die_ref type_die
;
19517 if (TREE_ASM_WRITTEN (decl
))
19520 TREE_ASM_WRITTEN (decl
) = 1;
19521 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19522 origin
= decl_ultimate_origin (decl
);
19523 if (origin
!= NULL
)
19524 add_abstract_origin_attribute (type_die
, origin
);
19529 add_name_and_src_coords_attributes (type_die
, decl
);
19530 if (DECL_ORIGINAL_TYPE (decl
))
19532 type
= DECL_ORIGINAL_TYPE (decl
);
19534 gcc_assert (type
!= TREE_TYPE (decl
));
19535 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19539 type
= TREE_TYPE (decl
);
19541 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19543 /* Here, we are in the case of decl being a typedef naming
19544 an anonymous type, e.g:
19545 typedef struct {...} foo;
19546 In that case TREE_TYPE (decl) is not a typedef variant
19547 type and TYPE_NAME of the anonymous type is set to the
19548 TYPE_DECL of the typedef. This construct is emitted by
19551 TYPE is the anonymous struct named by the typedef
19552 DECL. As we need the DW_AT_type attribute of the
19553 DW_TAG_typedef to point to the DIE of TYPE, let's
19554 generate that DIE right away. add_type_attribute
19555 called below will then pick (via lookup_type_die) that
19556 anonymous struct DIE. */
19557 if (!TREE_ASM_WRITTEN (type
))
19558 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19560 /* This is a GNU Extension. We are adding a
19561 DW_AT_linkage_name attribute to the DIE of the
19562 anonymous struct TYPE. The value of that attribute
19563 is the name of the typedef decl naming the anonymous
19564 struct. This greatly eases the work of consumers of
19565 this debug info. */
19566 add_linkage_attr (lookup_type_die (type
), decl
);
19570 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19571 TREE_THIS_VOLATILE (decl
), context_die
);
19573 if (is_naming_typedef_decl (decl
))
19574 /* We want that all subsequent calls to lookup_type_die with
19575 TYPE in argument yield the DW_TAG_typedef we have just
19577 equate_type_number_to_die (type
, type_die
);
19579 add_accessibility_attribute (type_die
, decl
);
19582 if (DECL_ABSTRACT (decl
))
19583 equate_decl_number_to_die (decl
, type_die
);
19585 if (get_AT (type_die
, DW_AT_name
))
19586 add_pubtype (decl
, type_die
);
19589 /* Generate a DIE for a struct, class, enum or union type. */
19592 gen_tagged_type_die (tree type
,
19593 dw_die_ref context_die
,
19594 enum debug_info_usage usage
)
19598 if (type
== NULL_TREE
19599 || !is_tagged_type (type
))
19602 /* If this is a nested type whose containing class hasn't been written
19603 out yet, writing it out will cover this one, too. This does not apply
19604 to instantiations of member class templates; they need to be added to
19605 the containing class as they are generated. FIXME: This hurts the
19606 idea of combining type decls from multiple TUs, since we can't predict
19607 what set of template instantiations we'll get. */
19608 if (TYPE_CONTEXT (type
)
19609 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19610 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19612 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19614 if (TREE_ASM_WRITTEN (type
))
19617 /* If that failed, attach ourselves to the stub. */
19618 push_decl_scope (TYPE_CONTEXT (type
));
19619 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19622 else if (TYPE_CONTEXT (type
) != NULL_TREE
19623 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19625 /* If this type is local to a function that hasn't been written
19626 out yet, use a NULL context for now; it will be fixed up in
19627 decls_for_scope. */
19628 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19629 /* A declaration DIE doesn't count; nested types need to go in the
19631 if (context_die
&& is_declaration_die (context_die
))
19632 context_die
= NULL
;
19637 context_die
= declare_in_namespace (type
, context_die
);
19641 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19643 /* This might have been written out by the call to
19644 declare_in_namespace. */
19645 if (!TREE_ASM_WRITTEN (type
))
19646 gen_enumeration_type_die (type
, context_die
);
19649 gen_struct_or_union_type_die (type
, context_die
, usage
);
19654 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19655 it up if it is ever completed. gen_*_type_die will set it for us
19656 when appropriate. */
19659 /* Generate a type description DIE. */
19662 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19663 enum debug_info_usage usage
)
19665 struct array_descr_info info
;
19667 if (type
== NULL_TREE
|| type
== error_mark_node
)
19670 if (TYPE_NAME (type
) != NULL_TREE
19671 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19672 && is_redundant_typedef (TYPE_NAME (type
))
19673 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19674 /* The DECL of this type is a typedef we don't want to emit debug
19675 info for but we want debug info for its underlying typedef.
19676 This can happen for e.g, the injected-class-name of a C++
19678 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19680 /* If TYPE is a typedef type variant, let's generate debug info
19681 for the parent typedef which TYPE is a type of. */
19682 if (typedef_variant_p (type
))
19684 if (TREE_ASM_WRITTEN (type
))
19687 /* Prevent broken recursion; we can't hand off to the same type. */
19688 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19690 /* Give typedefs the right scope. */
19691 context_die
= scope_die_for (type
, context_die
);
19693 TREE_ASM_WRITTEN (type
) = 1;
19695 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19699 /* If type is an anonymous tagged type named by a typedef, let's
19700 generate debug info for the typedef. */
19701 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19703 /* Use the DIE of the containing namespace as the parent DIE of
19704 the type description DIE we want to generate. */
19705 if (DECL_CONTEXT (TYPE_NAME (type
))
19706 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19707 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19709 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19713 /* If this is an array type with hidden descriptor, handle it first. */
19714 if (!TREE_ASM_WRITTEN (type
)
19715 && lang_hooks
.types
.get_array_descr_info
19716 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19717 && (dwarf_version
>= 3 || !dwarf_strict
))
19719 gen_descr_array_type_die (type
, &info
, context_die
);
19720 TREE_ASM_WRITTEN (type
) = 1;
19724 /* We are going to output a DIE to represent the unqualified version
19725 of this type (i.e. without any const or volatile qualifiers) so
19726 get the main variant (i.e. the unqualified version) of this type
19727 now. (Vectors are special because the debugging info is in the
19728 cloned type itself). */
19729 if (TREE_CODE (type
) != VECTOR_TYPE
)
19730 type
= type_main_variant (type
);
19732 if (TREE_ASM_WRITTEN (type
))
19735 switch (TREE_CODE (type
))
19741 case REFERENCE_TYPE
:
19742 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19743 ensures that the gen_type_die recursion will terminate even if the
19744 type is recursive. Recursive types are possible in Ada. */
19745 /* ??? We could perhaps do this for all types before the switch
19747 TREE_ASM_WRITTEN (type
) = 1;
19749 /* For these types, all that is required is that we output a DIE (or a
19750 set of DIEs) to represent the "basis" type. */
19751 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19752 DINFO_USAGE_IND_USE
);
19756 /* This code is used for C++ pointer-to-data-member types.
19757 Output a description of the relevant class type. */
19758 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19759 DINFO_USAGE_IND_USE
);
19761 /* Output a description of the type of the object pointed to. */
19762 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19763 DINFO_USAGE_IND_USE
);
19765 /* Now output a DIE to represent this pointer-to-data-member type
19767 gen_ptr_to_mbr_type_die (type
, context_die
);
19770 case FUNCTION_TYPE
:
19771 /* Force out return type (in case it wasn't forced out already). */
19772 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19773 DINFO_USAGE_DIR_USE
);
19774 gen_subroutine_type_die (type
, context_die
);
19778 /* Force out return type (in case it wasn't forced out already). */
19779 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19780 DINFO_USAGE_DIR_USE
);
19781 gen_subroutine_type_die (type
, context_die
);
19785 gen_array_type_die (type
, context_die
);
19789 gen_array_type_die (type
, context_die
);
19792 case ENUMERAL_TYPE
:
19795 case QUAL_UNION_TYPE
:
19796 gen_tagged_type_die (type
, context_die
, usage
);
19802 case FIXED_POINT_TYPE
:
19805 case POINTER_BOUNDS_TYPE
:
19806 /* No DIEs needed for fundamental types. */
19811 /* Just use DW_TAG_unspecified_type. */
19813 dw_die_ref type_die
= lookup_type_die (type
);
19814 if (type_die
== NULL
)
19816 tree name
= TYPE_NAME (type
);
19817 if (TREE_CODE (name
) == TYPE_DECL
)
19818 name
= DECL_NAME (name
);
19819 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19820 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19821 equate_type_number_to_die (type
, type_die
);
19827 gcc_unreachable ();
19830 TREE_ASM_WRITTEN (type
) = 1;
19834 gen_type_die (tree type
, dw_die_ref context_die
)
19836 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19839 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19840 things which are local to the given block. */
19843 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19845 int must_output_die
= 0;
19848 /* Ignore blocks that are NULL. */
19849 if (stmt
== NULL_TREE
)
19852 inlined_func
= inlined_function_outer_scope_p (stmt
);
19854 /* If the block is one fragment of a non-contiguous block, do not
19855 process the variables, since they will have been done by the
19856 origin block. Do process subblocks. */
19857 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19861 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19862 gen_block_die (sub
, context_die
, depth
+ 1);
19867 /* Determine if we need to output any Dwarf DIEs at all to represent this
19870 /* The outer scopes for inlinings *must* always be represented. We
19871 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19872 must_output_die
= 1;
19875 /* Determine if this block directly contains any "significant"
19876 local declarations which we will need to output DIEs for. */
19877 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19878 /* We are not in terse mode so *any* local declaration counts
19879 as being a "significant" one. */
19880 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19881 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19882 && (TREE_USED (stmt
)
19883 || TREE_ASM_WRITTEN (stmt
)
19884 || BLOCK_ABSTRACT (stmt
)));
19885 else if ((TREE_USED (stmt
)
19886 || TREE_ASM_WRITTEN (stmt
)
19887 || BLOCK_ABSTRACT (stmt
))
19888 && !dwarf2out_ignore_block (stmt
))
19889 must_output_die
= 1;
19892 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19893 DIE for any block which contains no significant local declarations at
19894 all. Rather, in such cases we just call `decls_for_scope' so that any
19895 needed Dwarf info for any sub-blocks will get properly generated. Note
19896 that in terse mode, our definition of what constitutes a "significant"
19897 local declaration gets restricted to include only inlined function
19898 instances and local (nested) function definitions. */
19899 if (must_output_die
)
19903 /* If STMT block is abstract, that means we have been called
19904 indirectly from dwarf2out_abstract_function.
19905 That function rightfully marks the descendent blocks (of
19906 the abstract function it is dealing with) as being abstract,
19907 precisely to prevent us from emitting any
19908 DW_TAG_inlined_subroutine DIE as a descendent
19909 of an abstract function instance. So in that case, we should
19910 not call gen_inlined_subroutine_die.
19912 Later though, when cgraph asks dwarf2out to emit info
19913 for the concrete instance of the function decl into which
19914 the concrete instance of STMT got inlined, the later will lead
19915 to the generation of a DW_TAG_inlined_subroutine DIE. */
19916 if (! BLOCK_ABSTRACT (stmt
))
19917 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19920 gen_lexical_block_die (stmt
, context_die
, depth
);
19923 decls_for_scope (stmt
, context_die
, depth
);
19926 /* Process variable DECL (or variable with origin ORIGIN) within
19927 block STMT and add it to CONTEXT_DIE. */
19929 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19932 tree decl_or_origin
= decl
? decl
: origin
;
19934 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19935 die
= lookup_decl_die (decl_or_origin
);
19936 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19937 && TYPE_DECL_IS_STUB (decl_or_origin
))
19938 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19942 if (die
!= NULL
&& die
->die_parent
== NULL
)
19943 add_child_die (context_die
, die
);
19944 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19945 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19946 stmt
, context_die
);
19948 gen_decl_die (decl
, origin
, context_die
);
19951 /* Generate all of the decls declared within a given scope and (recursively)
19952 all of its sub-blocks. */
19955 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19961 /* Ignore NULL blocks. */
19962 if (stmt
== NULL_TREE
)
19965 /* Output the DIEs to represent all of the data objects and typedefs
19966 declared directly within this block but not within any nested
19967 sub-blocks. Also, nested function and tag DIEs have been
19968 generated with a parent of NULL; fix that up now. We don't
19969 have to do this if we're at -g1. */
19970 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19972 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19973 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19974 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19975 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19979 /* Even if we're at -g1, we need to process the subblocks in order to get
19980 inlined call information. */
19982 /* Output the DIEs to represent all sub-blocks (and the items declared
19983 therein) of this block. */
19984 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19986 subblocks
= BLOCK_CHAIN (subblocks
))
19987 gen_block_die (subblocks
, context_die
, depth
+ 1);
19990 /* Is this a typedef we can avoid emitting? */
19993 is_redundant_typedef (const_tree decl
)
19995 if (TYPE_DECL_IS_STUB (decl
))
19998 if (DECL_ARTIFICIAL (decl
)
19999 && DECL_CONTEXT (decl
)
20000 && is_tagged_type (DECL_CONTEXT (decl
))
20001 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
20002 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
20003 /* Also ignore the artificial member typedef for the class name. */
20009 /* Return TRUE if TYPE is a typedef that names a type for linkage
20010 purposes. This kind of typedefs is produced by the C++ FE for
20013 typedef struct {...} foo;
20015 In that case, there is no typedef variant type produced for foo.
20016 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20020 is_naming_typedef_decl (const_tree decl
)
20022 if (decl
== NULL_TREE
20023 || TREE_CODE (decl
) != TYPE_DECL
20024 || !is_tagged_type (TREE_TYPE (decl
))
20025 || DECL_IS_BUILTIN (decl
)
20026 || is_redundant_typedef (decl
)
20027 /* It looks like Ada produces TYPE_DECLs that are very similar
20028 to C++ naming typedefs but that have different
20029 semantics. Let's be specific to c++ for now. */
20033 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20034 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20035 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20036 != TYPE_NAME (TREE_TYPE (decl
))));
20039 /* Returns the DIE for a context. */
20041 static inline dw_die_ref
20042 get_context_die (tree context
)
20046 /* Find die that represents this context. */
20047 if (TYPE_P (context
))
20049 context
= TYPE_MAIN_VARIANT (context
);
20050 return strip_naming_typedef (context
, force_type_die (context
));
20053 return force_decl_die (context
);
20055 return comp_unit_die ();
20058 /* Returns the DIE for decl. A DIE will always be returned. */
20061 force_decl_die (tree decl
)
20063 dw_die_ref decl_die
;
20064 unsigned saved_external_flag
;
20065 tree save_fn
= NULL_TREE
;
20066 decl_die
= lookup_decl_die (decl
);
20069 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20071 decl_die
= lookup_decl_die (decl
);
20075 switch (TREE_CODE (decl
))
20077 case FUNCTION_DECL
:
20078 /* Clear current_function_decl, so that gen_subprogram_die thinks
20079 that this is a declaration. At this point, we just want to force
20080 declaration die. */
20081 save_fn
= current_function_decl
;
20082 current_function_decl
= NULL_TREE
;
20083 gen_subprogram_die (decl
, context_die
);
20084 current_function_decl
= save_fn
;
20088 /* Set external flag to force declaration die. Restore it after
20089 gen_decl_die() call. */
20090 saved_external_flag
= DECL_EXTERNAL (decl
);
20091 DECL_EXTERNAL (decl
) = 1;
20092 gen_decl_die (decl
, NULL
, context_die
);
20093 DECL_EXTERNAL (decl
) = saved_external_flag
;
20096 case NAMESPACE_DECL
:
20097 if (dwarf_version
>= 3 || !dwarf_strict
)
20098 dwarf2out_decl (decl
);
20100 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20101 decl_die
= comp_unit_die ();
20104 case TRANSLATION_UNIT_DECL
:
20105 decl_die
= comp_unit_die ();
20109 gcc_unreachable ();
20112 /* We should be able to find the DIE now. */
20114 decl_die
= lookup_decl_die (decl
);
20115 gcc_assert (decl_die
);
20121 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20122 always returned. */
20125 force_type_die (tree type
)
20127 dw_die_ref type_die
;
20129 type_die
= lookup_type_die (type
);
20132 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20134 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20135 TYPE_VOLATILE (type
), context_die
);
20136 gcc_assert (type_die
);
20141 /* Force out any required namespaces to be able to output DECL,
20142 and return the new context_die for it, if it's changed. */
20145 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20147 tree context
= (DECL_P (thing
)
20148 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20149 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20150 /* Force out the namespace. */
20151 context_die
= force_decl_die (context
);
20153 return context_die
;
20156 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20157 type) within its namespace, if appropriate.
20159 For compatibility with older debuggers, namespace DIEs only contain
20160 declarations; all definitions are emitted at CU scope. */
20163 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20165 dw_die_ref ns_context
;
20167 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20168 return context_die
;
20170 /* If this decl is from an inlined function, then don't try to emit it in its
20171 namespace, as we will get confused. It would have already been emitted
20172 when the abstract instance of the inline function was emitted anyways. */
20173 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20174 return context_die
;
20176 ns_context
= setup_namespace_context (thing
, context_die
);
20178 if (ns_context
!= context_die
)
20182 if (DECL_P (thing
))
20183 gen_decl_die (thing
, NULL
, ns_context
);
20185 gen_type_die (thing
, ns_context
);
20187 return context_die
;
20190 /* Generate a DIE for a namespace or namespace alias. */
20193 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20195 dw_die_ref namespace_die
;
20197 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20198 they are an alias of. */
20199 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20201 /* Output a real namespace or module. */
20202 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20203 namespace_die
= new_die (is_fortran ()
20204 ? DW_TAG_module
: DW_TAG_namespace
,
20205 context_die
, decl
);
20206 /* For Fortran modules defined in different CU don't add src coords. */
20207 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20209 const char *name
= dwarf2_name (decl
, 0);
20211 add_name_attribute (namespace_die
, name
);
20214 add_name_and_src_coords_attributes (namespace_die
, decl
);
20215 if (DECL_EXTERNAL (decl
))
20216 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20217 equate_decl_number_to_die (decl
, namespace_die
);
20221 /* Output a namespace alias. */
20223 /* Force out the namespace we are an alias of, if necessary. */
20224 dw_die_ref origin_die
20225 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20227 if (DECL_FILE_SCOPE_P (decl
)
20228 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20229 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20230 /* Now create the namespace alias DIE. */
20231 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20232 add_name_and_src_coords_attributes (namespace_die
, decl
);
20233 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20234 equate_decl_number_to_die (decl
, namespace_die
);
20236 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20237 if (want_pubnames ())
20238 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20241 /* Generate Dwarf debug information for a decl described by DECL.
20242 The return value is currently only meaningful for PARM_DECLs,
20243 for all other decls it returns NULL. */
20246 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20248 tree decl_or_origin
= decl
? decl
: origin
;
20249 tree class_origin
= NULL
, ultimate_origin
;
20251 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20254 switch (TREE_CODE (decl_or_origin
))
20260 if (!is_fortran () && !is_ada ())
20262 /* The individual enumerators of an enum type get output when we output
20263 the Dwarf representation of the relevant enum type itself. */
20267 /* Emit its type. */
20268 gen_type_die (TREE_TYPE (decl
), context_die
);
20270 /* And its containing namespace. */
20271 context_die
= declare_in_namespace (decl
, context_die
);
20273 gen_const_die (decl
, context_die
);
20276 case FUNCTION_DECL
:
20277 /* Don't output any DIEs to represent mere function declarations,
20278 unless they are class members or explicit block externs. */
20279 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20280 && DECL_FILE_SCOPE_P (decl_or_origin
)
20281 && (current_function_decl
== NULL_TREE
20282 || DECL_ARTIFICIAL (decl_or_origin
)))
20287 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20288 on local redeclarations of global functions. That seems broken. */
20289 if (current_function_decl
!= decl
)
20290 /* This is only a declaration. */;
20293 /* If we're emitting a clone, emit info for the abstract instance. */
20294 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20295 dwarf2out_abstract_function (origin
20296 ? DECL_ORIGIN (origin
)
20297 : DECL_ABSTRACT_ORIGIN (decl
));
20299 /* If we're emitting an out-of-line copy of an inline function,
20300 emit info for the abstract instance and set up to refer to it. */
20301 else if (cgraph_function_possibly_inlined_p (decl
)
20302 && ! DECL_ABSTRACT (decl
)
20303 && ! class_or_namespace_scope_p (context_die
)
20304 /* dwarf2out_abstract_function won't emit a die if this is just
20305 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20306 that case, because that works only if we have a die. */
20307 && DECL_INITIAL (decl
) != NULL_TREE
)
20309 dwarf2out_abstract_function (decl
);
20310 set_decl_origin_self (decl
);
20313 /* Otherwise we're emitting the primary DIE for this decl. */
20314 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20316 /* Before we describe the FUNCTION_DECL itself, make sure that we
20317 have its containing type. */
20319 origin
= decl_class_context (decl
);
20320 if (origin
!= NULL_TREE
)
20321 gen_type_die (origin
, context_die
);
20323 /* And its return type. */
20324 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20326 /* And its virtual context. */
20327 if (DECL_VINDEX (decl
) != NULL_TREE
)
20328 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20330 /* Make sure we have a member DIE for decl. */
20331 if (origin
!= NULL_TREE
)
20332 gen_type_die_for_member (origin
, decl
, context_die
);
20334 /* And its containing namespace. */
20335 context_die
= declare_in_namespace (decl
, context_die
);
20338 /* Now output a DIE to represent the function itself. */
20340 gen_subprogram_die (decl
, context_die
);
20344 /* If we are in terse mode, don't generate any DIEs to represent any
20345 actual typedefs. */
20346 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20349 /* In the special case of a TYPE_DECL node representing the declaration
20350 of some type tag, if the given TYPE_DECL is marked as having been
20351 instantiated from some other (original) TYPE_DECL node (e.g. one which
20352 was generated within the original definition of an inline function) we
20353 used to generate a special (abbreviated) DW_TAG_structure_type,
20354 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20355 should be actually referencing those DIEs, as variable DIEs with that
20356 type would be emitted already in the abstract origin, so it was always
20357 removed during unused type prunning. Don't add anything in this
20359 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20362 if (is_redundant_typedef (decl
))
20363 gen_type_die (TREE_TYPE (decl
), context_die
);
20365 /* Output a DIE to represent the typedef itself. */
20366 gen_typedef_die (decl
, context_die
);
20370 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20371 gen_label_die (decl
, context_die
);
20376 /* If we are in terse mode, don't generate any DIEs to represent any
20377 variable declarations or definitions. */
20378 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20381 /* Output any DIEs that are needed to specify the type of this data
20383 if (decl_by_reference_p (decl_or_origin
))
20384 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20386 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20388 /* And its containing type. */
20389 class_origin
= decl_class_context (decl_or_origin
);
20390 if (class_origin
!= NULL_TREE
)
20391 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20393 /* And its containing namespace. */
20394 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20396 /* Now output the DIE to represent the data object itself. This gets
20397 complicated because of the possibility that the VAR_DECL really
20398 represents an inlined instance of a formal parameter for an inline
20400 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20401 if (ultimate_origin
!= NULL_TREE
20402 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20403 gen_formal_parameter_die (decl
, origin
,
20404 true /* Emit name attribute. */,
20407 gen_variable_die (decl
, origin
, context_die
);
20411 /* Ignore the nameless fields that are used to skip bits but handle C++
20412 anonymous unions and structs. */
20413 if (DECL_NAME (decl
) != NULL_TREE
20414 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20415 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20417 gen_type_die (member_declared_type (decl
), context_die
);
20418 gen_field_die (decl
, context_die
);
20423 if (DECL_BY_REFERENCE (decl_or_origin
))
20424 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20426 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20427 return gen_formal_parameter_die (decl
, origin
,
20428 true /* Emit name attribute. */,
20431 case NAMESPACE_DECL
:
20432 case IMPORTED_DECL
:
20433 if (dwarf_version
>= 3 || !dwarf_strict
)
20434 gen_namespace_die (decl
, context_die
);
20438 /* Probably some frontend-internal decl. Assume we don't care. */
20439 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20446 /* Output debug information for global decl DECL. Called from toplev.c after
20447 compilation proper has finished. */
20450 dwarf2out_global_decl (tree decl
)
20452 /* Output DWARF2 information for file-scope tentative data object
20453 declarations, file-scope (extern) function declarations (which
20454 had no corresponding body) and file-scope tagged type declarations
20455 and definitions which have not yet been forced out. */
20456 if ((TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20457 && !POINTER_BOUNDS_P (decl
))
20458 dwarf2out_decl (decl
);
20461 /* Output debug information for type decl DECL. Called from toplev.c
20462 and from language front ends (to record built-in types). */
20464 dwarf2out_type_decl (tree decl
, int local
)
20467 dwarf2out_decl (decl
);
20470 /* Output debug information for imported module or decl DECL.
20471 NAME is non-NULL name in the lexical block if the decl has been renamed.
20472 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20473 that DECL belongs to.
20474 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20476 dwarf2out_imported_module_or_decl_1 (tree decl
,
20478 tree lexical_block
,
20479 dw_die_ref lexical_block_die
)
20481 expanded_location xloc
;
20482 dw_die_ref imported_die
= NULL
;
20483 dw_die_ref at_import_die
;
20485 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20487 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20488 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20492 xloc
= expand_location (input_location
);
20494 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20496 at_import_die
= force_type_die (TREE_TYPE (decl
));
20497 /* For namespace N { typedef void T; } using N::T; base_type_die
20498 returns NULL, but DW_TAG_imported_declaration requires
20499 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20500 if (!at_import_die
)
20502 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20503 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20504 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20505 gcc_assert (at_import_die
);
20510 at_import_die
= lookup_decl_die (decl
);
20511 if (!at_import_die
)
20513 /* If we're trying to avoid duplicate debug info, we may not have
20514 emitted the member decl for this field. Emit it now. */
20515 if (TREE_CODE (decl
) == FIELD_DECL
)
20517 tree type
= DECL_CONTEXT (decl
);
20519 if (TYPE_CONTEXT (type
)
20520 && TYPE_P (TYPE_CONTEXT (type
))
20521 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20522 DINFO_USAGE_DIR_USE
))
20524 gen_type_die_for_member (type
, decl
,
20525 get_context_die (TYPE_CONTEXT (type
)));
20527 at_import_die
= force_decl_die (decl
);
20531 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20533 if (dwarf_version
>= 3 || !dwarf_strict
)
20534 imported_die
= new_die (DW_TAG_imported_module
,
20541 imported_die
= new_die (DW_TAG_imported_declaration
,
20545 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20546 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20548 add_AT_string (imported_die
, DW_AT_name
,
20549 IDENTIFIER_POINTER (name
));
20550 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20553 /* Output debug information for imported module or decl DECL.
20554 NAME is non-NULL name in context if the decl has been renamed.
20555 CHILD is true if decl is one of the renamed decls as part of
20556 importing whole module. */
20559 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20562 /* dw_die_ref at_import_die; */
20563 dw_die_ref scope_die
;
20565 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20570 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20571 We need decl DIE for reference and scope die. First, get DIE for the decl
20574 /* Get the scope die for decl context. Use comp_unit_die for global module
20575 or decl. If die is not found for non globals, force new die. */
20577 && TYPE_P (context
)
20578 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20581 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20584 scope_die
= get_context_die (context
);
20588 gcc_assert (scope_die
->die_child
);
20589 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20590 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20591 scope_die
= scope_die
->die_child
;
20594 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20595 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20599 /* Write the debugging output for DECL. */
20602 dwarf2out_decl (tree decl
)
20604 dw_die_ref context_die
= comp_unit_die ();
20606 switch (TREE_CODE (decl
))
20611 case FUNCTION_DECL
:
20612 /* What we would really like to do here is to filter out all mere
20613 file-scope declarations of file-scope functions which are never
20614 referenced later within this translation unit (and keep all of ones
20615 that *are* referenced later on) but we aren't clairvoyant, so we have
20616 no idea which functions will be referenced in the future (i.e. later
20617 on within the current translation unit). So here we just ignore all
20618 file-scope function declarations which are not also definitions. If
20619 and when the debugger needs to know something about these functions,
20620 it will have to hunt around and find the DWARF information associated
20621 with the definition of the function.
20623 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20624 nodes represent definitions and which ones represent mere
20625 declarations. We have to check DECL_INITIAL instead. That's because
20626 the C front-end supports some weird semantics for "extern inline"
20627 function definitions. These can get inlined within the current
20628 translation unit (and thus, we need to generate Dwarf info for their
20629 abstract instances so that the Dwarf info for the concrete inlined
20630 instances can have something to refer to) but the compiler never
20631 generates any out-of-lines instances of such things (despite the fact
20632 that they *are* definitions).
20634 The important point is that the C front-end marks these "extern
20635 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20636 them anyway. Note that the C++ front-end also plays some similar games
20637 for inline function definitions appearing within include files which
20638 also contain `#pragma interface' pragmas.
20640 If we are called from dwarf2out_abstract_function output a DIE
20641 anyway. We can end up here this way with early inlining and LTO
20642 where the inlined function is output in a different LTRANS unit
20644 if (DECL_INITIAL (decl
) == NULL_TREE
20645 && ! DECL_ABSTRACT (decl
))
20648 /* If we're a nested function, initially use a parent of NULL; if we're
20649 a plain function, this will be fixed up in decls_for_scope. If
20650 we're a method, it will be ignored, since we already have a DIE. */
20651 if (decl_function_context (decl
)
20652 /* But if we're in terse mode, we don't care about scope. */
20653 && debug_info_level
> DINFO_LEVEL_TERSE
)
20654 context_die
= NULL
;
20658 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20659 declaration and if the declaration was never even referenced from
20660 within this entire compilation unit. We suppress these DIEs in
20661 order to save space in the .debug section (by eliminating entries
20662 which are probably useless). Note that we must not suppress
20663 block-local extern declarations (whether used or not) because that
20664 would screw-up the debugger's name lookup mechanism and cause it to
20665 miss things which really ought to be in scope at a given point. */
20666 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20669 /* For local statics lookup proper context die. */
20670 if (TREE_STATIC (decl
)
20671 && DECL_CONTEXT (decl
)
20672 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20673 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20675 /* If we are in terse mode, don't generate any DIEs to represent any
20676 variable declarations or definitions. */
20677 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20682 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20684 if (!is_fortran () && !is_ada ())
20686 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20687 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20690 case NAMESPACE_DECL
:
20691 case IMPORTED_DECL
:
20692 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20694 if (lookup_decl_die (decl
) != NULL
)
20699 /* Don't emit stubs for types unless they are needed by other DIEs. */
20700 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20703 /* Don't bother trying to generate any DIEs to represent any of the
20704 normal built-in types for the language we are compiling. */
20705 if (DECL_IS_BUILTIN (decl
))
20708 /* If we are in terse mode, don't generate any DIEs for types. */
20709 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20712 /* If we're a function-scope tag, initially use a parent of NULL;
20713 this will be fixed up in decls_for_scope. */
20714 if (decl_function_context (decl
))
20715 context_die
= NULL
;
20723 gen_decl_die (decl
, NULL
, context_die
);
20726 /* Write the debugging output for DECL. */
20729 dwarf2out_function_decl (tree decl
)
20731 dwarf2out_decl (decl
);
20732 call_arg_locations
= NULL
;
20733 call_arg_loc_last
= NULL
;
20734 call_site_count
= -1;
20735 tail_call_site_count
= -1;
20736 block_map
.release ();
20737 htab_empty (decl_loc_table
);
20738 htab_empty (cached_dw_loc_list_table
);
20741 /* Output a marker (i.e. a label) for the beginning of the generated code for
20742 a lexical block. */
20745 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20746 unsigned int blocknum
)
20748 switch_to_section (current_function_section ());
20749 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20752 /* Output a marker (i.e. a label) for the end of the generated code for a
20756 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20758 switch_to_section (current_function_section ());
20759 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20762 /* Returns nonzero if it is appropriate not to emit any debugging
20763 information for BLOCK, because it doesn't contain any instructions.
20765 Don't allow this for blocks with nested functions or local classes
20766 as we would end up with orphans, and in the presence of scheduling
20767 we may end up calling them anyway. */
20770 dwarf2out_ignore_block (const_tree block
)
20775 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20776 if (TREE_CODE (decl
) == FUNCTION_DECL
20777 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20779 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20781 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20782 if (TREE_CODE (decl
) == FUNCTION_DECL
20783 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20790 /* Hash table routines for file_hash. */
20793 file_table_eq (const void *p1_p
, const void *p2_p
)
20795 const struct dwarf_file_data
*const p1
=
20796 (const struct dwarf_file_data
*) p1_p
;
20797 const char *const p2
= (const char *) p2_p
;
20798 return filename_cmp (p1
->filename
, p2
) == 0;
20802 file_table_hash (const void *p_p
)
20804 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20805 return htab_hash_string (p
->filename
);
20808 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20809 dwarf2out.c) and return its "index". The index of each (known) filename is
20810 just a unique number which is associated with only that one filename. We
20811 need such numbers for the sake of generating labels (in the .debug_sfnames
20812 section) and references to those files numbers (in the .debug_srcinfo
20813 and.debug_macinfo sections). If the filename given as an argument is not
20814 found in our current list, add it to the list and assign it the next
20815 available unique index number. In order to speed up searches, we remember
20816 the index of the filename was looked up last. This handles the majority of
20819 static struct dwarf_file_data
*
20820 lookup_filename (const char *file_name
)
20823 struct dwarf_file_data
* created
;
20825 /* Check to see if the file name that was searched on the previous
20826 call matches this file name. If so, return the index. */
20827 if (file_table_last_lookup
20828 && (file_name
== file_table_last_lookup
->filename
20829 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20830 return file_table_last_lookup
;
20832 /* Didn't match the previous lookup, search the table. */
20833 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20834 htab_hash_string (file_name
), INSERT
);
20836 return (struct dwarf_file_data
*) *slot
;
20838 created
= ggc_alloc_dwarf_file_data ();
20839 created
->filename
= file_name
;
20840 created
->emitted_number
= 0;
20845 /* If the assembler will construct the file table, then translate the compiler
20846 internal file table number into the assembler file table number, and emit
20847 a .file directive if we haven't already emitted one yet. The file table
20848 numbers are different because we prune debug info for unused variables and
20849 types, which may include filenames. */
20852 maybe_emit_file (struct dwarf_file_data
* fd
)
20854 if (! fd
->emitted_number
)
20856 if (last_emitted_file
)
20857 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20859 fd
->emitted_number
= 1;
20860 last_emitted_file
= fd
;
20862 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20864 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20865 output_quoted_string (asm_out_file
,
20866 remap_debug_filename (fd
->filename
));
20867 fputc ('\n', asm_out_file
);
20871 return fd
->emitted_number
;
20874 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20875 That generation should happen after function debug info has been
20876 generated. The value of the attribute is the constant value of ARG. */
20879 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20881 die_arg_entry entry
;
20886 if (!tmpl_value_parm_die_table
)
20887 vec_alloc (tmpl_value_parm_die_table
, 32);
20891 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20894 /* Return TRUE if T is an instance of generic type, FALSE
20898 generic_type_p (tree t
)
20900 if (t
== NULL_TREE
|| !TYPE_P (t
))
20902 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20905 /* Schedule the generation of the generic parameter dies for the
20906 instance of generic type T. The proper generation itself is later
20907 done by gen_scheduled_generic_parms_dies. */
20910 schedule_generic_params_dies_gen (tree t
)
20912 if (!generic_type_p (t
))
20915 if (!generic_type_instances
)
20916 vec_alloc (generic_type_instances
, 256);
20918 vec_safe_push (generic_type_instances
, t
);
20921 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20922 by append_entry_to_tmpl_value_parm_die_table. This function must
20923 be called after function DIEs have been generated. */
20926 gen_remaining_tmpl_value_param_die_attribute (void)
20928 if (tmpl_value_parm_die_table
)
20933 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20934 tree_add_const_value_attribute (e
->die
, e
->arg
);
20938 /* Generate generic parameters DIEs for instances of generic types
20939 that have been previously scheduled by
20940 schedule_generic_params_dies_gen. This function must be called
20941 after all the types of the CU have been laid out. */
20944 gen_scheduled_generic_parms_dies (void)
20949 if (!generic_type_instances
)
20952 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20953 if (COMPLETE_TYPE_P (t
))
20954 gen_generic_params_dies (t
);
20958 /* Replace DW_AT_name for the decl with name. */
20961 dwarf2out_set_name (tree decl
, tree name
)
20967 die
= TYPE_SYMTAB_DIE (decl
);
20971 dname
= dwarf2_name (name
, 0);
20975 attr
= get_AT (die
, DW_AT_name
);
20978 struct indirect_string_node
*node
;
20980 node
= find_AT_string (dname
);
20981 /* replace the string. */
20982 attr
->dw_attr_val
.v
.val_str
= node
;
20986 add_name_attribute (die
, dname
);
20989 /* True if before or during processing of the first function being emitted. */
20990 static bool in_first_function_p
= true;
20991 /* True if loc_note during dwarf2out_var_location call might still be
20992 before first real instruction at address equal to .Ltext0. */
20993 static bool maybe_at_text_label_p
= true;
20994 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
20995 static unsigned int first_loclabel_num_not_at_text_label
;
20997 /* Called by the final INSN scan whenever we see a var location. We
20998 use it to drop labels in the right places, and throw the location in
20999 our lookup table. */
21002 dwarf2out_var_location (rtx loc_note
)
21004 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
21005 struct var_loc_node
*newloc
;
21006 rtx next_real
, next_note
;
21007 static const char *last_label
;
21008 static const char *last_postcall_label
;
21009 static bool last_in_cold_section_p
;
21010 static rtx expected_next_loc_note
;
21014 if (!NOTE_P (loc_note
))
21016 if (CALL_P (loc_note
))
21019 if (SIBLING_CALL_P (loc_note
))
21020 tail_call_site_count
++;
21025 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
21026 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21029 /* Optimize processing a large consecutive sequence of location
21030 notes so we don't spend too much time in next_real_insn. If the
21031 next insn is another location note, remember the next_real_insn
21032 calculation for next time. */
21033 next_real
= cached_next_real_insn
;
21036 if (expected_next_loc_note
!= loc_note
)
21037 next_real
= NULL_RTX
;
21040 next_note
= NEXT_INSN (loc_note
);
21042 || INSN_DELETED_P (next_note
)
21043 || ! NOTE_P (next_note
)
21044 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
21045 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
21046 next_note
= NULL_RTX
;
21049 next_real
= next_real_insn (loc_note
);
21053 expected_next_loc_note
= next_note
;
21054 cached_next_real_insn
= next_real
;
21057 cached_next_real_insn
= NULL_RTX
;
21059 /* If there are no instructions which would be affected by this note,
21060 don't do anything. */
21062 && next_real
== NULL_RTX
21063 && !NOTE_DURING_CALL_P (loc_note
))
21066 if (next_real
== NULL_RTX
)
21067 next_real
= get_last_insn ();
21069 /* If there were any real insns between note we processed last time
21070 and this note (or if it is the first note), clear
21071 last_{,postcall_}label so that they are not reused this time. */
21072 if (last_var_location_insn
== NULL_RTX
21073 || last_var_location_insn
!= next_real
21074 || last_in_cold_section_p
!= in_cold_section_p
)
21077 last_postcall_label
= NULL
;
21082 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21083 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21084 NOTE_DURING_CALL_P (loc_note
)
21085 ? last_postcall_label
: last_label
);
21086 if (newloc
== NULL
)
21095 /* If there were no real insns between note we processed last time
21096 and this note, use the label we emitted last time. Otherwise
21097 create a new label and emit it. */
21098 if (last_label
== NULL
)
21100 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21101 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21103 last_label
= ggc_strdup (loclabel
);
21104 /* See if loclabel might be equal to .Ltext0. If yes,
21105 bump first_loclabel_num_not_at_text_label. */
21106 if (!have_multiple_function_sections
21107 && in_first_function_p
21108 && maybe_at_text_label_p
)
21110 static rtx last_start
;
21112 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
21113 if (insn
== last_start
)
21115 else if (!NONDEBUG_INSN_P (insn
))
21119 rtx body
= PATTERN (insn
);
21120 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
21122 /* Inline asm could occupy zero bytes. */
21123 else if (GET_CODE (body
) == ASM_INPUT
21124 || asm_noperands (body
) >= 0)
21126 #ifdef HAVE_attr_length
21127 else if (get_attr_min_length (insn
) == 0)
21132 /* Assume insn has non-zero length. */
21133 maybe_at_text_label_p
= false;
21137 if (maybe_at_text_label_p
)
21139 last_start
= loc_note
;
21140 first_loclabel_num_not_at_text_label
= loclabel_num
;
21147 struct call_arg_loc_node
*ca_loc
21148 = ggc_alloc_cleared_call_arg_loc_node ();
21149 rtx prev
= prev_real_insn (loc_note
), x
;
21150 ca_loc
->call_arg_loc_note
= loc_note
;
21151 ca_loc
->next
= NULL
;
21152 ca_loc
->label
= last_label
;
21155 || (NONJUMP_INSN_P (prev
)
21156 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21157 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21158 if (!CALL_P (prev
))
21159 prev
= XVECEXP (PATTERN (prev
), 0, 0);
21160 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
21161 x
= get_call_rtx_from (PATTERN (prev
));
21164 x
= XEXP (XEXP (x
, 0), 0);
21165 if (GET_CODE (x
) == SYMBOL_REF
21166 && SYMBOL_REF_DECL (x
)
21167 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21168 ca_loc
->symbol_ref
= x
;
21170 ca_loc
->block
= insn_scope (prev
);
21171 if (call_arg_locations
)
21172 call_arg_loc_last
->next
= ca_loc
;
21174 call_arg_locations
= ca_loc
;
21175 call_arg_loc_last
= ca_loc
;
21177 else if (!NOTE_DURING_CALL_P (loc_note
))
21178 newloc
->label
= last_label
;
21181 if (!last_postcall_label
)
21183 sprintf (loclabel
, "%s-1", last_label
);
21184 last_postcall_label
= ggc_strdup (loclabel
);
21186 newloc
->label
= last_postcall_label
;
21189 last_var_location_insn
= next_real
;
21190 last_in_cold_section_p
= in_cold_section_p
;
21193 /* Note in one location list that text section has changed. */
21196 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
21198 var_loc_list
*list
= (var_loc_list
*) *slot
;
21200 list
->last_before_switch
21201 = list
->last
->next
? list
->last
->next
: list
->last
;
21205 /* Note in all location lists that text section has changed. */
21208 var_location_switch_text_section (void)
21210 if (decl_loc_table
== NULL
)
21213 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
21216 /* Create a new line number table. */
21218 static dw_line_info_table
*
21219 new_line_info_table (void)
21221 dw_line_info_table
*table
;
21223 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
21224 table
->file_num
= 1;
21225 table
->line_num
= 1;
21226 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21231 /* Lookup the "current" table into which we emit line info, so
21232 that we don't have to do it for every source line. */
21235 set_cur_line_info_table (section
*sec
)
21237 dw_line_info_table
*table
;
21239 if (sec
== text_section
)
21240 table
= text_section_line_info
;
21241 else if (sec
== cold_text_section
)
21243 table
= cold_text_section_line_info
;
21246 cold_text_section_line_info
= table
= new_line_info_table ();
21247 table
->end_label
= cold_end_label
;
21252 const char *end_label
;
21254 if (flag_reorder_blocks_and_partition
)
21256 if (in_cold_section_p
)
21257 end_label
= crtl
->subsections
.cold_section_end_label
;
21259 end_label
= crtl
->subsections
.hot_section_end_label
;
21263 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21264 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21265 current_function_funcdef_no
);
21266 end_label
= ggc_strdup (label
);
21269 table
= new_line_info_table ();
21270 table
->end_label
= end_label
;
21272 vec_safe_push (separate_line_info
, table
);
21275 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21276 table
->is_stmt
= (cur_line_info_table
21277 ? cur_line_info_table
->is_stmt
21278 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21279 cur_line_info_table
= table
;
21283 /* We need to reset the locations at the beginning of each
21284 function. We can't do this in the end_function hook, because the
21285 declarations that use the locations won't have been output when
21286 that hook is called. Also compute have_multiple_function_sections here. */
21289 dwarf2out_begin_function (tree fun
)
21291 section
*sec
= function_section (fun
);
21293 if (sec
!= text_section
)
21294 have_multiple_function_sections
= true;
21296 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21298 gcc_assert (current_function_decl
== fun
);
21299 cold_text_section
= unlikely_text_section ();
21300 switch_to_section (cold_text_section
);
21301 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21302 switch_to_section (sec
);
21305 dwarf2out_note_section_used ();
21306 call_site_count
= 0;
21307 tail_call_site_count
= 0;
21309 set_cur_line_info_table (sec
);
21312 /* Helper function of dwarf2out_end_function, called only after emitting
21313 the very first function into assembly. Check if some .debug_loc range
21314 might end with a .LVL* label that could be equal to .Ltext0.
21315 In that case we must force using absolute addresses in .debug_loc ranges,
21316 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21317 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21319 Set have_multiple_function_sections to true in that case and
21320 terminate htab traversal. */
21323 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21325 var_loc_list
*entry
;
21326 struct var_loc_node
*node
;
21328 entry
= (var_loc_list
*) *slot
;
21329 node
= entry
->first
;
21330 if (node
&& node
->next
&& node
->next
->label
)
21333 const char *label
= node
->next
->label
;
21334 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21336 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21338 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21339 if (strcmp (label
, loclabel
) == 0)
21341 have_multiple_function_sections
= true;
21349 /* Hook called after emitting a function into assembly.
21350 This does something only for the very first function emitted. */
21353 dwarf2out_end_function (unsigned int)
21355 if (in_first_function_p
21356 && !have_multiple_function_sections
21357 && first_loclabel_num_not_at_text_label
21359 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21361 in_first_function_p
= false;
21362 maybe_at_text_label_p
= false;
21365 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21368 push_dw_line_info_entry (dw_line_info_table
*table
,
21369 enum dw_line_info_opcode opcode
, unsigned int val
)
21371 dw_line_info_entry e
;
21374 vec_safe_push (table
->entries
, e
);
21377 /* Output a label to mark the beginning of a source code line entry
21378 and record information relating to this source line, in
21379 'line_info_table' for later output of the .debug_line section. */
21380 /* ??? The discriminator parameter ought to be unsigned. */
21383 dwarf2out_source_line (unsigned int line
, const char *filename
,
21384 int discriminator
, bool is_stmt
)
21386 unsigned int file_num
;
21387 dw_line_info_table
*table
;
21389 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
21392 /* The discriminator column was added in dwarf4. Simplify the below
21393 by simply removing it if we're not supposed to output it. */
21394 if (dwarf_version
< 4 && dwarf_strict
)
21397 table
= cur_line_info_table
;
21398 file_num
= maybe_emit_file (lookup_filename (filename
));
21400 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21401 the debugger has used the second (possibly duplicate) line number
21402 at the beginning of the function to mark the end of the prologue.
21403 We could eliminate any other duplicates within the function. For
21404 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21405 that second line number entry. */
21406 /* Recall that this end-of-prologue indication is *not* the same thing
21407 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21408 to which the hook corresponds, follows the last insn that was
21409 emitted by gen_prologue. What we need is to precede the first insn
21410 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21411 insn that corresponds to something the user wrote. These may be
21412 very different locations once scheduling is enabled. */
21414 if (0 && file_num
== table
->file_num
21415 && line
== table
->line_num
21416 && discriminator
== table
->discrim_num
21417 && is_stmt
== table
->is_stmt
)
21420 switch_to_section (current_function_section ());
21422 /* If requested, emit something human-readable. */
21423 if (flag_debug_asm
)
21424 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21426 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21428 /* Emit the .loc directive understood by GNU as. */
21429 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21430 file_num, line, is_stmt, discriminator */
21431 fputs ("\t.loc ", asm_out_file
);
21432 fprint_ul (asm_out_file
, file_num
);
21433 putc (' ', asm_out_file
);
21434 fprint_ul (asm_out_file
, line
);
21435 putc (' ', asm_out_file
);
21436 putc ('0', asm_out_file
);
21438 if (is_stmt
!= table
->is_stmt
)
21440 fputs (" is_stmt ", asm_out_file
);
21441 putc (is_stmt
? '1' : '0', asm_out_file
);
21443 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21445 gcc_assert (discriminator
> 0);
21446 fputs (" discriminator ", asm_out_file
);
21447 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21449 putc ('\n', asm_out_file
);
21453 unsigned int label_num
= ++line_info_label_num
;
21455 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21457 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21458 if (file_num
!= table
->file_num
)
21459 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21460 if (discriminator
!= table
->discrim_num
)
21461 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21462 if (is_stmt
!= table
->is_stmt
)
21463 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21464 push_dw_line_info_entry (table
, LI_set_line
, line
);
21467 table
->file_num
= file_num
;
21468 table
->line_num
= line
;
21469 table
->discrim_num
= discriminator
;
21470 table
->is_stmt
= is_stmt
;
21471 table
->in_use
= true;
21474 /* Record the beginning of a new source file. */
21477 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21479 if (flag_eliminate_dwarf2_dups
)
21481 /* Record the beginning of the file for break_out_includes. */
21482 dw_die_ref bincl_die
;
21484 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21485 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21488 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21491 e
.code
= DW_MACINFO_start_file
;
21493 e
.info
= ggc_strdup (filename
);
21494 vec_safe_push (macinfo_table
, e
);
21498 /* Record the end of a source file. */
21501 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21503 if (flag_eliminate_dwarf2_dups
)
21504 /* Record the end of the file for break_out_includes. */
21505 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21507 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21510 e
.code
= DW_MACINFO_end_file
;
21513 vec_safe_push (macinfo_table
, e
);
21517 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21518 the tail part of the directive line, i.e. the part which is past the
21519 initial whitespace, #, whitespace, directive-name, whitespace part. */
21522 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21523 const char *buffer ATTRIBUTE_UNUSED
)
21525 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21528 /* Insert a dummy first entry to be able to optimize the whole
21529 predefined macro block using DW_MACRO_GNU_transparent_include. */
21530 if (macinfo_table
->is_empty () && lineno
<= 1)
21535 vec_safe_push (macinfo_table
, e
);
21537 e
.code
= DW_MACINFO_define
;
21539 e
.info
= ggc_strdup (buffer
);
21540 vec_safe_push (macinfo_table
, e
);
21544 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21545 the tail part of the directive line, i.e. the part which is past the
21546 initial whitespace, #, whitespace, directive-name, whitespace part. */
21549 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21550 const char *buffer ATTRIBUTE_UNUSED
)
21552 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21555 /* Insert a dummy first entry to be able to optimize the whole
21556 predefined macro block using DW_MACRO_GNU_transparent_include. */
21557 if (macinfo_table
->is_empty () && lineno
<= 1)
21562 vec_safe_push (macinfo_table
, e
);
21564 e
.code
= DW_MACINFO_undef
;
21566 e
.info
= ggc_strdup (buffer
);
21567 vec_safe_push (macinfo_table
, e
);
21571 /* Helpers to manipulate hash table of CUs. */
21573 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
21575 typedef macinfo_entry value_type
;
21576 typedef macinfo_entry compare_type
;
21577 static inline hashval_t
hash (const value_type
*);
21578 static inline bool equal (const value_type
*, const compare_type
*);
21582 macinfo_entry_hasher::hash (const value_type
*entry
)
21584 return htab_hash_string (entry
->info
);
21588 macinfo_entry_hasher::equal (const value_type
*entry1
,
21589 const compare_type
*entry2
)
21591 return !strcmp (entry1
->info
, entry2
->info
);
21594 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
21596 /* Output a single .debug_macinfo entry. */
21599 output_macinfo_op (macinfo_entry
*ref
)
21603 struct indirect_string_node
*node
;
21604 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21605 struct dwarf_file_data
*fd
;
21609 case DW_MACINFO_start_file
:
21610 fd
= lookup_filename (ref
->info
);
21611 file_num
= maybe_emit_file (fd
);
21612 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21613 dw2_asm_output_data_uleb128 (ref
->lineno
,
21614 "Included from line number %lu",
21615 (unsigned long) ref
->lineno
);
21616 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21618 case DW_MACINFO_end_file
:
21619 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21621 case DW_MACINFO_define
:
21622 case DW_MACINFO_undef
:
21623 len
= strlen (ref
->info
) + 1;
21625 && len
> DWARF_OFFSET_SIZE
21626 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21627 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21629 ref
->code
= ref
->code
== DW_MACINFO_define
21630 ? DW_MACRO_GNU_define_indirect
21631 : DW_MACRO_GNU_undef_indirect
;
21632 output_macinfo_op (ref
);
21635 dw2_asm_output_data (1, ref
->code
,
21636 ref
->code
== DW_MACINFO_define
21637 ? "Define macro" : "Undefine macro");
21638 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21639 (unsigned long) ref
->lineno
);
21640 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21642 case DW_MACRO_GNU_define_indirect
:
21643 case DW_MACRO_GNU_undef_indirect
:
21644 node
= find_AT_string (ref
->info
);
21646 && ((node
->form
== DW_FORM_strp
)
21647 || (node
->form
== DW_FORM_GNU_str_index
)));
21648 dw2_asm_output_data (1, ref
->code
,
21649 ref
->code
== DW_MACRO_GNU_define_indirect
21650 ? "Define macro indirect"
21651 : "Undefine macro indirect");
21652 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21653 (unsigned long) ref
->lineno
);
21654 if (node
->form
== DW_FORM_strp
)
21655 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21656 debug_str_section
, "The macro: \"%s\"",
21659 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21662 case DW_MACRO_GNU_transparent_include
:
21663 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21664 ASM_GENERATE_INTERNAL_LABEL (label
,
21665 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21666 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21669 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21670 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21675 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21676 other compilation unit .debug_macinfo sections. IDX is the first
21677 index of a define/undef, return the number of ops that should be
21678 emitted in a comdat .debug_macinfo section and emit
21679 a DW_MACRO_GNU_transparent_include entry referencing it.
21680 If the define/undef entry should be emitted normally, return 0. */
21683 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21684 macinfo_hash_type
*macinfo_htab
)
21686 macinfo_entry
*first
, *second
, *cur
, *inc
;
21687 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21688 unsigned char checksum
[16];
21689 struct md5_ctx ctx
;
21690 char *grp_name
, *tail
;
21692 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21693 macinfo_entry
**slot
;
21695 first
= &(*macinfo_table
)[idx
];
21696 second
= &(*macinfo_table
)[idx
+ 1];
21698 /* Optimize only if there are at least two consecutive define/undef ops,
21699 and either all of them are before first DW_MACINFO_start_file
21700 with lineno {0,1} (i.e. predefined macro block), or all of them are
21701 in some included header file. */
21702 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21704 if (vec_safe_is_empty (files
))
21706 if (first
->lineno
> 1 || second
->lineno
> 1)
21709 else if (first
->lineno
== 0)
21712 /* Find the last define/undef entry that can be grouped together
21713 with first and at the same time compute md5 checksum of their
21714 codes, linenumbers and strings. */
21715 md5_init_ctx (&ctx
);
21716 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21717 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21719 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21723 unsigned char code
= cur
->code
;
21724 md5_process_bytes (&code
, 1, &ctx
);
21725 checksum_uleb128 (cur
->lineno
, &ctx
);
21726 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21728 md5_finish_ctx (&ctx
, checksum
);
21731 /* From the containing include filename (if any) pick up just
21732 usable characters from its basename. */
21733 if (vec_safe_is_empty (files
))
21736 base
= lbasename (files
->last ().info
);
21737 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21738 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21739 encoded_filename_len
++;
21740 /* Count . at the end. */
21741 if (encoded_filename_len
)
21742 encoded_filename_len
++;
21744 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21745 linebuf_len
= strlen (linebuf
);
21747 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21748 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21750 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21751 tail
= grp_name
+ 4;
21752 if (encoded_filename_len
)
21754 for (i
= 0; base
[i
]; i
++)
21755 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21759 memcpy (tail
, linebuf
, linebuf_len
);
21760 tail
+= linebuf_len
;
21762 for (i
= 0; i
< 16; i
++)
21763 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21765 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21766 in the empty vector entry before the first define/undef. */
21767 inc
= &(*macinfo_table
)[idx
- 1];
21768 inc
->code
= DW_MACRO_GNU_transparent_include
;
21770 inc
->info
= ggc_strdup (grp_name
);
21771 if (!macinfo_htab
->is_created ())
21772 macinfo_htab
->create (10);
21773 /* Avoid emitting duplicates. */
21774 slot
= macinfo_htab
->find_slot (inc
, INSERT
);
21779 /* If such an entry has been used before, just emit
21780 a DW_MACRO_GNU_transparent_include op. */
21782 output_macinfo_op (inc
);
21783 /* And clear all macinfo_entry in the range to avoid emitting them
21784 in the second pass. */
21785 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21794 inc
->lineno
= macinfo_htab
->elements ();
21795 output_macinfo_op (inc
);
21800 /* Save any strings needed by the macinfo table in the debug str
21801 table. All strings must be collected into the table by the time
21802 index_string is called. */
21805 save_macinfo_strings (void)
21809 macinfo_entry
*ref
;
21811 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21815 /* Match the logic in output_macinfo_op to decide on
21816 indirect strings. */
21817 case DW_MACINFO_define
:
21818 case DW_MACINFO_undef
:
21819 len
= strlen (ref
->info
) + 1;
21821 && len
> DWARF_OFFSET_SIZE
21822 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21823 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21824 set_indirect_string (find_AT_string (ref
->info
));
21826 case DW_MACRO_GNU_define_indirect
:
21827 case DW_MACRO_GNU_undef_indirect
:
21828 set_indirect_string (find_AT_string (ref
->info
));
21836 /* Output macinfo section(s). */
21839 output_macinfo (void)
21842 unsigned long length
= vec_safe_length (macinfo_table
);
21843 macinfo_entry
*ref
;
21844 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21845 macinfo_hash_type macinfo_htab
;
21850 /* output_macinfo* uses these interchangeably. */
21851 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21852 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21853 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21854 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21856 /* For .debug_macro emit the section header. */
21859 dw2_asm_output_data (2, 4, "DWARF macro version number");
21860 if (DWARF_OFFSET_SIZE
== 8)
21861 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21863 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21864 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21865 (!dwarf_split_debug_info
? debug_line_section_label
21866 : debug_skeleton_line_section_label
),
21867 debug_line_section
, NULL
);
21870 /* In the first loop, it emits the primary .debug_macinfo section
21871 and after each emitted op the macinfo_entry is cleared.
21872 If a longer range of define/undef ops can be optimized using
21873 DW_MACRO_GNU_transparent_include, the
21874 DW_MACRO_GNU_transparent_include op is emitted and kept in
21875 the vector before the first define/undef in the range and the
21876 whole range of define/undef ops is not emitted and kept. */
21877 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21881 case DW_MACINFO_start_file
:
21882 vec_safe_push (files
, *ref
);
21884 case DW_MACINFO_end_file
:
21885 if (!vec_safe_is_empty (files
))
21888 case DW_MACINFO_define
:
21889 case DW_MACINFO_undef
:
21891 && HAVE_COMDAT_GROUP
21892 && vec_safe_length (files
) != 1
21895 && (*macinfo_table
)[i
- 1].code
== 0)
21897 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21906 /* A dummy entry may be inserted at the beginning to be able
21907 to optimize the whole block of predefined macros. */
21913 output_macinfo_op (ref
);
21918 if (!macinfo_htab
.is_created ())
21921 macinfo_htab
.dispose ();
21923 /* If any DW_MACRO_GNU_transparent_include were used, on those
21924 DW_MACRO_GNU_transparent_include entries terminate the
21925 current chain and switch to a new comdat .debug_macinfo
21926 section and emit the define/undef entries within it. */
21927 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21932 case DW_MACRO_GNU_transparent_include
:
21934 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21935 tree comdat_key
= get_identifier (ref
->info
);
21936 /* Terminate the previous .debug_macinfo section. */
21937 dw2_asm_output_data (1, 0, "End compilation unit");
21938 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21940 | SECTION_LINKONCE
,
21942 ASM_GENERATE_INTERNAL_LABEL (label
,
21943 DEBUG_MACRO_SECTION_LABEL
,
21945 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21948 dw2_asm_output_data (2, 4, "DWARF macro version number");
21949 if (DWARF_OFFSET_SIZE
== 8)
21950 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21952 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21955 case DW_MACINFO_define
:
21956 case DW_MACINFO_undef
:
21957 output_macinfo_op (ref
);
21962 gcc_unreachable ();
21966 /* Set up for Dwarf output at the start of compilation. */
21969 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21971 /* Allocate the file_table. */
21972 file_table
= htab_create_ggc (50, file_table_hash
,
21973 file_table_eq
, NULL
);
21975 /* Allocate the decl_die_table. */
21976 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21977 decl_die_table_eq
, NULL
);
21979 /* Allocate the decl_loc_table. */
21980 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21981 decl_loc_table_eq
, NULL
);
21983 /* Allocate the cached_dw_loc_list_table. */
21984 cached_dw_loc_list_table
21985 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21986 cached_dw_loc_list_table_eq
, NULL
);
21988 /* Allocate the initial hunk of the decl_scope_table. */
21989 vec_alloc (decl_scope_table
, 256);
21991 /* Allocate the initial hunk of the abbrev_die_table. */
21992 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21993 (ABBREV_DIE_TABLE_INCREMENT
);
21994 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21995 /* Zero-th entry is allocated, but unused. */
21996 abbrev_die_table_in_use
= 1;
21998 /* Allocate the pubtypes and pubnames vectors. */
21999 vec_alloc (pubname_table
, 32);
22000 vec_alloc (pubtype_table
, 32);
22002 vec_alloc (incomplete_types
, 64);
22004 vec_alloc (used_rtx_array
, 32);
22006 if (!dwarf_split_debug_info
)
22008 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
22009 SECTION_DEBUG
, NULL
);
22010 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22011 SECTION_DEBUG
, NULL
);
22012 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
22013 SECTION_DEBUG
, NULL
);
22017 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
22018 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22019 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
22020 SECTION_DEBUG
| SECTION_EXCLUDE
,
22022 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
22023 SECTION_DEBUG
, NULL
);
22024 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
22025 SECTION_DEBUG
, NULL
);
22026 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22027 SECTION_DEBUG
, NULL
);
22028 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
22029 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
22031 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
22032 the main .o, but the skeleton_line goes into the split off dwo. */
22033 debug_skeleton_line_section
22034 = get_section (DEBUG_DWO_LINE_SECTION
,
22035 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22036 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
22037 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
22038 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
22039 SECTION_DEBUG
| SECTION_EXCLUDE
,
22041 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
22042 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
22043 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
22044 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22045 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
22046 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
22048 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
22049 SECTION_DEBUG
, NULL
);
22050 debug_macinfo_section
= get_section (dwarf_strict
22051 ? DEBUG_MACINFO_SECTION
22052 : DEBUG_MACRO_SECTION
,
22053 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
22054 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
22055 SECTION_DEBUG
, NULL
);
22056 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
22057 SECTION_DEBUG
, NULL
);
22058 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
22059 SECTION_DEBUG
, NULL
);
22060 debug_str_section
= get_section (DEBUG_STR_SECTION
,
22061 DEBUG_STR_SECTION_FLAGS
, NULL
);
22062 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
22063 SECTION_DEBUG
, NULL
);
22064 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
22065 SECTION_DEBUG
, NULL
);
22067 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
22068 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
22069 DEBUG_ABBREV_SECTION_LABEL
, 0);
22070 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
22071 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
22072 COLD_TEXT_SECTION_LABEL
, 0);
22073 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
22075 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
22076 DEBUG_INFO_SECTION_LABEL
, 0);
22077 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
22078 DEBUG_LINE_SECTION_LABEL
, 0);
22079 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
22080 DEBUG_RANGES_SECTION_LABEL
, 0);
22081 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
22082 DEBUG_ADDR_SECTION_LABEL
, 0);
22083 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
22085 ? DEBUG_MACINFO_SECTION_LABEL
22086 : DEBUG_MACRO_SECTION_LABEL
, 0);
22087 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
22089 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22090 vec_alloc (macinfo_table
, 64);
22092 switch_to_section (text_section
);
22093 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
22095 /* Make sure the line number table for .text always exists. */
22096 text_section_line_info
= new_line_info_table ();
22097 text_section_line_info
->end_label
= text_end_label
;
22100 /* Called before compile () starts outputtting functions, variables
22101 and toplevel asms into assembly. */
22104 dwarf2out_assembly_start (void)
22106 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22107 && dwarf2out_do_cfi_asm ()
22108 && (!(flag_unwind_tables
|| flag_exceptions
)
22109 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
22110 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
22113 /* A helper function for dwarf2out_finish called through
22114 htab_traverse. Assign a string its index. All strings must be
22115 collected into the table by the time index_string is called,
22116 because the indexing code relies on htab_traverse to traverse nodes
22117 in the same order for each run. */
22120 index_string (void **h
, void *v
)
22122 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22123 unsigned int *index
= (unsigned int *) v
;
22125 find_string_form (node
);
22126 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22128 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
22129 node
->index
= *index
;
22135 /* A helper function for output_indirect_strings called through
22136 htab_traverse. Output the offset to a string and update the
22140 output_index_string_offset (void **h
, void *v
)
22142 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22143 unsigned int *offset
= (unsigned int *) v
;
22145 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22147 /* Assert that this node has been assigned an index. */
22148 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
22149 && node
->index
!= NOT_INDEXED
);
22150 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
22151 "indexed string 0x%x: %s", node
->index
, node
->str
);
22152 *offset
+= strlen (node
->str
) + 1;
22157 /* A helper function for dwarf2out_finish called through
22158 htab_traverse. Output the indexed string. */
22161 output_index_string (void **h
, void *v
)
22163 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22164 unsigned int *cur_idx
= (unsigned int *) v
;
22166 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22168 /* Assert that the strings are output in the same order as their
22169 indexes were assigned. */
22170 gcc_assert (*cur_idx
== node
->index
);
22171 assemble_string (node
->str
, strlen (node
->str
) + 1);
22177 /* A helper function for dwarf2out_finish called through
22178 htab_traverse. Emit one queued .debug_str string. */
22181 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22183 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22185 node
->form
= find_string_form (node
);
22186 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22188 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22189 assemble_string (node
->str
, strlen (node
->str
) + 1);
22195 /* Output the indexed string table. */
22198 output_indirect_strings (void)
22200 switch_to_section (debug_str_section
);
22201 if (!dwarf_split_debug_info
)
22202 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22205 unsigned int offset
= 0;
22206 unsigned int cur_idx
= 0;
22208 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
22210 switch_to_section (debug_str_offsets_section
);
22211 htab_traverse_noresize (debug_str_hash
,
22212 output_index_string_offset
,
22214 switch_to_section (debug_str_dwo_section
);
22215 htab_traverse_noresize (debug_str_hash
,
22216 output_index_string
,
22221 /* Callback for htab_traverse to assign an index to an entry in the
22222 table, and to write that entry to the .debug_addr section. */
22225 output_addr_table_entry (void **slot
, void *data
)
22227 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22228 unsigned int *cur_index
= (unsigned int *)data
;
22230 if (entry
->refcount
== 0)
22232 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22233 || entry
->index
== NOT_INDEXED
);
22237 gcc_assert (entry
->index
== *cur_index
);
22240 switch (entry
->kind
)
22243 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22244 "0x%x", entry
->index
);
22246 case ate_kind_rtx_dtprel
:
22247 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22248 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22251 fputc ('\n', asm_out_file
);
22253 case ate_kind_label
:
22254 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22255 "0x%x", entry
->index
);
22258 gcc_unreachable ();
22263 /* Produce the .debug_addr section. */
22266 output_addr_table (void)
22268 unsigned int index
= 0;
22269 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22272 switch_to_section (debug_addr_section
);
22273 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22276 #if ENABLE_ASSERT_CHECKING
22277 /* Verify that all marks are clear. */
22280 verify_marks_clear (dw_die_ref die
)
22284 gcc_assert (! die
->die_mark
);
22285 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22287 #endif /* ENABLE_ASSERT_CHECKING */
22289 /* Clear the marks for a die and its children.
22290 Be cool if the mark isn't set. */
22293 prune_unmark_dies (dw_die_ref die
)
22299 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22302 /* Given DIE that we're marking as used, find any other dies
22303 it references as attributes and mark them as used. */
22306 prune_unused_types_walk_attribs (dw_die_ref die
)
22311 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22313 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22315 /* A reference to another DIE.
22316 Make sure that it will get emitted.
22317 If it was broken out into a comdat group, don't follow it. */
22318 if (! AT_ref (a
)->comdat_type_p
22319 || a
->dw_attr
== DW_AT_specification
)
22320 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22322 /* Set the string's refcount to 0 so that prune_unused_types_mark
22323 accounts properly for it. */
22324 if (AT_class (a
) == dw_val_class_str
)
22325 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22329 /* Mark the generic parameters and arguments children DIEs of DIE. */
22332 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22336 if (die
== NULL
|| die
->die_child
== NULL
)
22338 c
= die
->die_child
;
22341 if (is_template_parameter (c
))
22342 prune_unused_types_mark (c
, 1);
22344 } while (c
&& c
!= die
->die_child
);
22347 /* Mark DIE as being used. If DOKIDS is true, then walk down
22348 to DIE's children. */
22351 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22355 if (die
->die_mark
== 0)
22357 /* We haven't done this node yet. Mark it as used. */
22359 /* If this is the DIE of a generic type instantiation,
22360 mark the children DIEs that describe its generic parms and
22362 prune_unused_types_mark_generic_parms_dies (die
);
22364 /* We also have to mark its parents as used.
22365 (But we don't want to mark our parent's kids due to this,
22366 unless it is a class.) */
22367 if (die
->die_parent
)
22368 prune_unused_types_mark (die
->die_parent
,
22369 class_scope_p (die
->die_parent
));
22371 /* Mark any referenced nodes. */
22372 prune_unused_types_walk_attribs (die
);
22374 /* If this node is a specification,
22375 also mark the definition, if it exists. */
22376 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22377 prune_unused_types_mark (die
->die_definition
, 1);
22380 if (dokids
&& die
->die_mark
!= 2)
22382 /* We need to walk the children, but haven't done so yet.
22383 Remember that we've walked the kids. */
22386 /* If this is an array type, we need to make sure our
22387 kids get marked, even if they're types. If we're
22388 breaking out types into comdat sections, do this
22389 for all type definitions. */
22390 if (die
->die_tag
== DW_TAG_array_type
22391 || (use_debug_types
22392 && is_type_die (die
) && ! is_declaration_die (die
)))
22393 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22395 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22399 /* For local classes, look if any static member functions were emitted
22400 and if so, mark them. */
22403 prune_unused_types_walk_local_classes (dw_die_ref die
)
22407 if (die
->die_mark
== 2)
22410 switch (die
->die_tag
)
22412 case DW_TAG_structure_type
:
22413 case DW_TAG_union_type
:
22414 case DW_TAG_class_type
:
22417 case DW_TAG_subprogram
:
22418 if (!get_AT_flag (die
, DW_AT_declaration
)
22419 || die
->die_definition
!= NULL
)
22420 prune_unused_types_mark (die
, 1);
22427 /* Mark children. */
22428 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22431 /* Walk the tree DIE and mark types that we actually use. */
22434 prune_unused_types_walk (dw_die_ref die
)
22438 /* Don't do anything if this node is already marked and
22439 children have been marked as well. */
22440 if (die
->die_mark
== 2)
22443 switch (die
->die_tag
)
22445 case DW_TAG_structure_type
:
22446 case DW_TAG_union_type
:
22447 case DW_TAG_class_type
:
22448 if (die
->die_perennial_p
)
22451 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22452 if (c
->die_tag
== DW_TAG_subprogram
)
22455 /* Finding used static member functions inside of classes
22456 is needed just for local classes, because for other classes
22457 static member function DIEs with DW_AT_specification
22458 are emitted outside of the DW_TAG_*_type. If we ever change
22459 it, we'd need to call this even for non-local classes. */
22461 prune_unused_types_walk_local_classes (die
);
22463 /* It's a type node --- don't mark it. */
22466 case DW_TAG_const_type
:
22467 case DW_TAG_packed_type
:
22468 case DW_TAG_pointer_type
:
22469 case DW_TAG_reference_type
:
22470 case DW_TAG_rvalue_reference_type
:
22471 case DW_TAG_volatile_type
:
22472 case DW_TAG_typedef
:
22473 case DW_TAG_array_type
:
22474 case DW_TAG_interface_type
:
22475 case DW_TAG_friend
:
22476 case DW_TAG_variant_part
:
22477 case DW_TAG_enumeration_type
:
22478 case DW_TAG_subroutine_type
:
22479 case DW_TAG_string_type
:
22480 case DW_TAG_set_type
:
22481 case DW_TAG_subrange_type
:
22482 case DW_TAG_ptr_to_member_type
:
22483 case DW_TAG_file_type
:
22484 if (die
->die_perennial_p
)
22487 /* It's a type node --- don't mark it. */
22491 /* Mark everything else. */
22495 if (die
->die_mark
== 0)
22499 /* Now, mark any dies referenced from here. */
22500 prune_unused_types_walk_attribs (die
);
22505 /* Mark children. */
22506 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22509 /* Increment the string counts on strings referred to from DIE's
22513 prune_unused_types_update_strings (dw_die_ref die
)
22518 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22519 if (AT_class (a
) == dw_val_class_str
)
22521 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22523 /* Avoid unnecessarily putting strings that are used less than
22524 twice in the hash table. */
22526 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22529 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22530 htab_hash_string (s
->str
),
22532 gcc_assert (*slot
== NULL
);
22538 /* Remove from the tree DIE any dies that aren't marked. */
22541 prune_unused_types_prune (dw_die_ref die
)
22545 gcc_assert (die
->die_mark
);
22546 prune_unused_types_update_strings (die
);
22548 if (! die
->die_child
)
22551 c
= die
->die_child
;
22553 dw_die_ref prev
= c
;
22554 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22555 if (c
== die
->die_child
)
22557 /* No marked children between 'prev' and the end of the list. */
22559 /* No marked children at all. */
22560 die
->die_child
= NULL
;
22563 prev
->die_sib
= c
->die_sib
;
22564 die
->die_child
= prev
;
22569 if (c
!= prev
->die_sib
)
22571 prune_unused_types_prune (c
);
22572 } while (c
!= die
->die_child
);
22575 /* Remove dies representing declarations that we never use. */
22578 prune_unused_types (void)
22581 limbo_die_node
*node
;
22582 comdat_type_node
*ctnode
;
22584 dw_die_ref base_type
;
22586 #if ENABLE_ASSERT_CHECKING
22587 /* All the marks should already be clear. */
22588 verify_marks_clear (comp_unit_die ());
22589 for (node
= limbo_die_list
; node
; node
= node
->next
)
22590 verify_marks_clear (node
->die
);
22591 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22592 verify_marks_clear (ctnode
->root_die
);
22593 #endif /* ENABLE_ASSERT_CHECKING */
22595 /* Mark types that are used in global variables. */
22596 premark_types_used_by_global_vars ();
22598 /* Set the mark on nodes that are actually used. */
22599 prune_unused_types_walk (comp_unit_die ());
22600 for (node
= limbo_die_list
; node
; node
= node
->next
)
22601 prune_unused_types_walk (node
->die
);
22602 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22604 prune_unused_types_walk (ctnode
->root_die
);
22605 prune_unused_types_mark (ctnode
->type_die
, 1);
22608 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22609 are unusual in that they are pubnames that are the children of pubtypes.
22610 They should only be marked via their parent DW_TAG_enumeration_type die,
22611 not as roots in themselves. */
22612 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22613 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22614 prune_unused_types_mark (pub
->die
, 1);
22615 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22616 prune_unused_types_mark (base_type
, 1);
22618 if (debug_str_hash
)
22619 htab_empty (debug_str_hash
);
22620 if (skeleton_debug_str_hash
)
22621 htab_empty (skeleton_debug_str_hash
);
22622 prune_unused_types_prune (comp_unit_die ());
22623 for (node
= limbo_die_list
; node
; node
= node
->next
)
22624 prune_unused_types_prune (node
->die
);
22625 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22626 prune_unused_types_prune (ctnode
->root_die
);
22628 /* Leave the marks clear. */
22629 prune_unmark_dies (comp_unit_die ());
22630 for (node
= limbo_die_list
; node
; node
= node
->next
)
22631 prune_unmark_dies (node
->die
);
22632 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22633 prune_unmark_dies (ctnode
->root_die
);
22636 /* Set the parameter to true if there are any relative pathnames in
22639 file_table_relative_p (void ** slot
, void *param
)
22641 bool *p
= (bool *) param
;
22642 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22643 if (!IS_ABSOLUTE_PATH (d
->filename
))
22651 /* Helpers to manipulate hash table of comdat type units. */
22653 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
22655 typedef comdat_type_node value_type
;
22656 typedef comdat_type_node compare_type
;
22657 static inline hashval_t
hash (const value_type
*);
22658 static inline bool equal (const value_type
*, const compare_type
*);
22662 comdat_type_hasher::hash (const value_type
*type_node
)
22665 memcpy (&h
, type_node
->signature
, sizeof (h
));
22670 comdat_type_hasher::equal (const value_type
*type_node_1
,
22671 const compare_type
*type_node_2
)
22673 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22674 DWARF_TYPE_SIGNATURE_SIZE
));
22677 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22678 to the location it would have been added, should we know its
22679 DECL_ASSEMBLER_NAME when we added other attributes. This will
22680 probably improve compactness of debug info, removing equivalent
22681 abbrevs, and hide any differences caused by deferring the
22682 computation of the assembler name, triggered by e.g. PCH. */
22685 move_linkage_attr (dw_die_ref die
)
22687 unsigned ix
= vec_safe_length (die
->die_attr
);
22688 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22690 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22691 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22695 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22697 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22701 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22703 die
->die_attr
->pop ();
22704 die
->die_attr
->quick_insert (ix
, linkage
);
22708 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22709 referenced from typed stack ops and count how often they are used. */
22712 mark_base_types (dw_loc_descr_ref loc
)
22714 dw_die_ref base_type
= NULL
;
22716 for (; loc
; loc
= loc
->dw_loc_next
)
22718 switch (loc
->dw_loc_opc
)
22720 case DW_OP_GNU_regval_type
:
22721 case DW_OP_GNU_deref_type
:
22722 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22724 case DW_OP_GNU_convert
:
22725 case DW_OP_GNU_reinterpret
:
22726 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22729 case DW_OP_GNU_const_type
:
22730 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22732 case DW_OP_GNU_entry_value
:
22733 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22738 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22739 if (base_type
->die_mark
)
22740 base_type
->die_mark
++;
22743 base_types
.safe_push (base_type
);
22744 base_type
->die_mark
= 1;
22749 /* Comparison function for sorting marked base types. */
22752 base_type_cmp (const void *x
, const void *y
)
22754 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22755 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22756 unsigned int byte_size1
, byte_size2
;
22757 unsigned int encoding1
, encoding2
;
22758 if (dx
->die_mark
> dy
->die_mark
)
22760 if (dx
->die_mark
< dy
->die_mark
)
22762 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22763 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22764 if (byte_size1
< byte_size2
)
22766 if (byte_size1
> byte_size2
)
22768 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22769 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22770 if (encoding1
< encoding2
)
22772 if (encoding1
> encoding2
)
22777 /* Move base types marked by mark_base_types as early as possible
22778 in the CU, sorted by decreasing usage count both to make the
22779 uleb128 references as small as possible and to make sure they
22780 will have die_offset already computed by calc_die_sizes when
22781 sizes of typed stack loc ops is computed. */
22784 move_marked_base_types (void)
22787 dw_die_ref base_type
, die
, c
;
22789 if (base_types
.is_empty ())
22792 /* Sort by decreasing usage count, they will be added again in that
22794 base_types
.qsort (base_type_cmp
);
22795 die
= comp_unit_die ();
22796 c
= die
->die_child
;
22799 dw_die_ref prev
= c
;
22801 while (c
->die_mark
)
22803 remove_child_with_prev (c
, prev
);
22804 /* As base types got marked, there must be at least
22805 one node other than DW_TAG_base_type. */
22806 gcc_assert (c
!= c
->die_sib
);
22810 while (c
!= die
->die_child
);
22811 gcc_assert (die
->die_child
);
22812 c
= die
->die_child
;
22813 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22815 base_type
->die_mark
= 0;
22816 base_type
->die_sib
= c
->die_sib
;
22817 c
->die_sib
= base_type
;
22822 /* Helper function for resolve_addr, attempt to resolve
22823 one CONST_STRING, return non-zero if not successful. Similarly verify that
22824 SYMBOL_REFs refer to variables emitted in the current CU. */
22827 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22831 if (GET_CODE (rtl
) == CONST_STRING
)
22833 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22834 tree t
= build_string (len
, XSTR (rtl
, 0));
22835 tree tlen
= size_int (len
- 1);
22837 = build_array_type (char_type_node
, build_index_type (tlen
));
22838 rtl
= lookup_constant_def (t
);
22839 if (!rtl
|| !MEM_P (rtl
))
22841 rtl
= XEXP (rtl
, 0);
22842 if (GET_CODE (rtl
) == SYMBOL_REF
22843 && SYMBOL_REF_DECL (rtl
)
22844 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22846 vec_safe_push (used_rtx_array
, rtl
);
22851 if (GET_CODE (rtl
) == SYMBOL_REF
22852 && SYMBOL_REF_DECL (rtl
))
22854 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22856 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22859 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22863 if (GET_CODE (rtl
) == CONST
22864 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22870 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
22871 if possible, and create DW_TAG_dwarf_procedure that can be referenced
22872 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
22875 string_cst_pool_decl (tree t
)
22877 rtx rtl
= output_constant_def (t
, 1);
22878 unsigned char *array
;
22879 dw_loc_descr_ref l
;
22884 if (!rtl
|| !MEM_P (rtl
))
22886 rtl
= XEXP (rtl
, 0);
22887 if (GET_CODE (rtl
) != SYMBOL_REF
22888 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
22891 decl
= SYMBOL_REF_DECL (rtl
);
22892 if (!lookup_decl_die (decl
))
22894 len
= TREE_STRING_LENGTH (t
);
22895 vec_safe_push (used_rtx_array
, rtl
);
22896 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
22897 array
= (unsigned char *) ggc_alloc_atomic (len
);
22898 memcpy (array
, TREE_STRING_POINTER (t
), len
);
22899 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
22900 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
22901 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
22902 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
22903 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
22904 add_AT_loc (ref
, DW_AT_location
, l
);
22905 equate_decl_number_to_die (decl
, ref
);
22910 /* Helper function of resolve_addr_in_expr. LOC is
22911 a DW_OP_addr followed by DW_OP_stack_value, either at the start
22912 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
22913 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
22914 with DW_OP_GNU_implicit_pointer if possible
22915 and return true, if unsuccessful, return false. */
22918 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
22920 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
22921 HOST_WIDE_INT offset
= 0;
22922 dw_die_ref ref
= NULL
;
22925 if (GET_CODE (rtl
) == CONST
22926 && GET_CODE (XEXP (rtl
, 0)) == PLUS
22927 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
22929 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
22930 rtl
= XEXP (XEXP (rtl
, 0), 0);
22932 if (GET_CODE (rtl
) == CONST_STRING
)
22934 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22935 tree t
= build_string (len
, XSTR (rtl
, 0));
22936 tree tlen
= size_int (len
- 1);
22939 = build_array_type (char_type_node
, build_index_type (tlen
));
22940 rtl
= string_cst_pool_decl (t
);
22944 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
22946 decl
= SYMBOL_REF_DECL (rtl
);
22947 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
22949 ref
= lookup_decl_die (decl
);
22950 if (ref
&& (get_AT (ref
, DW_AT_location
)
22951 || get_AT (ref
, DW_AT_const_value
)))
22953 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
22954 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22955 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
22956 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22957 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22958 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22959 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
22967 /* Helper function for resolve_addr, handle one location
22968 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22969 the location list couldn't be resolved. */
22972 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22974 dw_loc_descr_ref keep
= NULL
;
22975 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
22976 switch (loc
->dw_loc_opc
)
22979 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22982 || prev
->dw_loc_opc
== DW_OP_piece
22983 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
22984 && loc
->dw_loc_next
22985 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
22987 && optimize_one_addr_into_implicit_ptr (loc
))
22992 case DW_OP_GNU_addr_index
:
22993 case DW_OP_GNU_const_index
:
22994 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22995 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22996 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
23000 case DW_OP_const4u
:
23001 case DW_OP_const8u
:
23003 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
23006 case DW_OP_plus_uconst
:
23007 if (size_of_loc_descr (loc
)
23008 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
23010 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
23012 dw_loc_descr_ref repl
23013 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
23014 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
23015 add_loc_descr (&repl
, loc
->dw_loc_next
);
23019 case DW_OP_implicit_value
:
23020 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
23021 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
23024 case DW_OP_GNU_implicit_pointer
:
23025 case DW_OP_GNU_parameter_ref
:
23026 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
23029 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
23032 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23033 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23034 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23037 case DW_OP_GNU_const_type
:
23038 case DW_OP_GNU_regval_type
:
23039 case DW_OP_GNU_deref_type
:
23040 case DW_OP_GNU_convert
:
23041 case DW_OP_GNU_reinterpret
:
23042 while (loc
->dw_loc_next
23043 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
23045 dw_die_ref base1
, base2
;
23046 unsigned enc1
, enc2
, size1
, size2
;
23047 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23048 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23049 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23050 else if (loc
->dw_loc_oprnd1
.val_class
23051 == dw_val_class_unsigned_const
)
23054 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23055 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
23056 == dw_val_class_unsigned_const
)
23058 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23059 gcc_assert (base1
->die_tag
== DW_TAG_base_type
23060 && base2
->die_tag
== DW_TAG_base_type
);
23061 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
23062 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
23063 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
23064 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
23066 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
23067 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
23071 /* Optimize away next DW_OP_GNU_convert after
23072 adjusting LOC's base type die reference. */
23073 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23074 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23075 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
23077 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
23078 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23081 /* Don't change integer DW_OP_GNU_convert after e.g. floating
23082 point typed stack entry. */
23083 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
23084 keep
= loc
->dw_loc_next
;
23094 /* Helper function of resolve_addr. DIE had DW_AT_location of
23095 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
23096 and DW_OP_addr couldn't be resolved. resolve_addr has already
23097 removed the DW_AT_location attribute. This function attempts to
23098 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
23099 to it or DW_AT_const_value attribute, if possible. */
23102 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
23104 if (TREE_CODE (decl
) != VAR_DECL
23105 || lookup_decl_die (decl
) != die
23106 || DECL_EXTERNAL (decl
)
23107 || !TREE_STATIC (decl
)
23108 || DECL_INITIAL (decl
) == NULL_TREE
23109 || DECL_P (DECL_INITIAL (decl
))
23110 || get_AT (die
, DW_AT_const_value
))
23113 tree init
= DECL_INITIAL (decl
);
23114 HOST_WIDE_INT offset
= 0;
23115 /* For variables that have been optimized away and thus
23116 don't have a memory location, see if we can emit
23117 DW_AT_const_value instead. */
23118 if (tree_add_const_value_attribute (die
, init
))
23122 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
23123 and ADDR_EXPR refers to a decl that has DW_AT_location or
23124 DW_AT_const_value (but isn't addressable, otherwise
23125 resolving the original DW_OP_addr wouldn't fail), see if
23126 we can add DW_OP_GNU_implicit_pointer. */
23128 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
23129 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
23131 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
23132 init
= TREE_OPERAND (init
, 0);
23135 if (TREE_CODE (init
) != ADDR_EXPR
)
23137 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
23138 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
23139 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
23140 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
23141 && TREE_OPERAND (init
, 0) != decl
))
23144 dw_loc_descr_ref l
;
23146 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
23148 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
23151 decl
= SYMBOL_REF_DECL (rtl
);
23154 decl
= TREE_OPERAND (init
, 0);
23155 ref
= lookup_decl_die (decl
);
23157 || (!get_AT (ref
, DW_AT_location
)
23158 && !get_AT (ref
, DW_AT_const_value
)))
23160 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
23161 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23162 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23163 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23164 add_AT_loc (die
, DW_AT_location
, l
);
23168 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23169 an address in .rodata section if the string literal is emitted there,
23170 or remove the containing location list or replace DW_AT_const_value
23171 with DW_AT_location and empty location expression, if it isn't found
23172 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23173 to something that has been emitted in the current CU. */
23176 resolve_addr (dw_die_ref die
)
23180 dw_loc_list_ref
*curr
, *start
, loc
;
23183 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23184 switch (AT_class (a
))
23186 case dw_val_class_loc_list
:
23187 start
= curr
= AT_loc_list_ptr (a
);
23190 /* The same list can be referenced more than once. See if we have
23191 already recorded the result from a previous pass. */
23193 *curr
= loc
->dw_loc_next
;
23194 else if (!loc
->resolved_addr
)
23196 /* As things stand, we do not expect or allow one die to
23197 reference a suffix of another die's location list chain.
23198 References must be identical or completely separate.
23199 There is therefore no need to cache the result of this
23200 pass on any list other than the first; doing so
23201 would lead to unnecessary writes. */
23204 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23205 if (!resolve_addr_in_expr ((*curr
)->expr
))
23207 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23208 dw_loc_descr_ref l
= (*curr
)->expr
;
23210 if (next
&& (*curr
)->ll_symbol
)
23212 gcc_assert (!next
->ll_symbol
);
23213 next
->ll_symbol
= (*curr
)->ll_symbol
;
23215 if (dwarf_split_debug_info
)
23216 remove_loc_list_addr_table_entries (l
);
23221 mark_base_types ((*curr
)->expr
);
23222 curr
= &(*curr
)->dw_loc_next
;
23226 loc
->resolved_addr
= 1;
23230 loc
->dw_loc_next
= *start
;
23235 remove_AT (die
, a
->dw_attr
);
23239 case dw_val_class_loc
:
23241 dw_loc_descr_ref l
= AT_loc (a
);
23242 /* For -gdwarf-2 don't attempt to optimize
23243 DW_AT_data_member_location containing
23244 DW_OP_plus_uconst - older consumers might
23245 rely on it being that op instead of a more complex,
23246 but shorter, location description. */
23247 if ((dwarf_version
> 2
23248 || a
->dw_attr
!= DW_AT_data_member_location
23250 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23251 || l
->dw_loc_next
!= NULL
)
23252 && !resolve_addr_in_expr (l
))
23254 if (dwarf_split_debug_info
)
23255 remove_loc_list_addr_table_entries (l
);
23257 && l
->dw_loc_next
== NULL
23258 && l
->dw_loc_opc
== DW_OP_addr
23259 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
23260 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
23261 && a
->dw_attr
== DW_AT_location
)
23263 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
23264 remove_AT (die
, a
->dw_attr
);
23266 optimize_location_into_implicit_ptr (die
, decl
);
23269 remove_AT (die
, a
->dw_attr
);
23273 mark_base_types (l
);
23276 case dw_val_class_addr
:
23277 if (a
->dw_attr
== DW_AT_const_value
23278 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23280 if (AT_index (a
) != NOT_INDEXED
)
23281 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23282 remove_AT (die
, a
->dw_attr
);
23285 if (die
->die_tag
== DW_TAG_GNU_call_site
23286 && a
->dw_attr
== DW_AT_abstract_origin
)
23288 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23289 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23291 && DECL_EXTERNAL (tdecl
)
23292 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23294 force_decl_die (tdecl
);
23295 tdie
= lookup_decl_die (tdecl
);
23299 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23300 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23301 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23305 if (AT_index (a
) != NOT_INDEXED
)
23306 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23307 remove_AT (die
, a
->dw_attr
);
23316 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23319 /* Helper routines for optimize_location_lists.
23320 This pass tries to share identical local lists in .debug_loc
23323 /* Iteratively hash operands of LOC opcode. */
23326 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23328 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23329 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23331 switch (loc
->dw_loc_opc
)
23333 case DW_OP_const4u
:
23334 case DW_OP_const8u
:
23338 case DW_OP_const1u
:
23339 case DW_OP_const1s
:
23340 case DW_OP_const2u
:
23341 case DW_OP_const2s
:
23342 case DW_OP_const4s
:
23343 case DW_OP_const8s
:
23347 case DW_OP_plus_uconst
:
23383 case DW_OP_deref_size
:
23384 case DW_OP_xderef_size
:
23385 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23392 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23393 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23394 hash
= iterative_hash_object (offset
, hash
);
23397 case DW_OP_implicit_value
:
23398 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23399 switch (val2
->val_class
)
23401 case dw_val_class_const
:
23402 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23404 case dw_val_class_vec
:
23406 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23407 unsigned int len
= val2
->v
.val_vec
.length
;
23409 hash
= iterative_hash_object (elt_size
, hash
);
23410 hash
= iterative_hash_object (len
, hash
);
23411 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23412 len
* elt_size
, hash
);
23415 case dw_val_class_const_double
:
23416 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23417 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23419 case dw_val_class_addr
:
23420 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23423 gcc_unreachable ();
23427 case DW_OP_bit_piece
:
23428 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23429 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23435 unsigned char dtprel
= 0xd1;
23436 hash
= iterative_hash_object (dtprel
, hash
);
23438 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23440 case DW_OP_GNU_addr_index
:
23441 case DW_OP_GNU_const_index
:
23445 unsigned char dtprel
= 0xd1;
23446 hash
= iterative_hash_object (dtprel
, hash
);
23448 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23451 case DW_OP_GNU_implicit_pointer
:
23452 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23454 case DW_OP_GNU_entry_value
:
23455 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23457 case DW_OP_GNU_regval_type
:
23458 case DW_OP_GNU_deref_type
:
23460 unsigned int byte_size
23461 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23462 unsigned int encoding
23463 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23464 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23465 hash
= iterative_hash_object (byte_size
, hash
);
23466 hash
= iterative_hash_object (encoding
, hash
);
23469 case DW_OP_GNU_convert
:
23470 case DW_OP_GNU_reinterpret
:
23471 if (val1
->val_class
== dw_val_class_unsigned_const
)
23473 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23477 case DW_OP_GNU_const_type
:
23479 unsigned int byte_size
23480 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23481 unsigned int encoding
23482 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23483 hash
= iterative_hash_object (byte_size
, hash
);
23484 hash
= iterative_hash_object (encoding
, hash
);
23485 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23487 hash
= iterative_hash_object (val2
->val_class
, hash
);
23488 switch (val2
->val_class
)
23490 case dw_val_class_const
:
23491 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23493 case dw_val_class_vec
:
23495 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23496 unsigned int len
= val2
->v
.val_vec
.length
;
23498 hash
= iterative_hash_object (elt_size
, hash
);
23499 hash
= iterative_hash_object (len
, hash
);
23500 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23501 len
* elt_size
, hash
);
23504 case dw_val_class_const_double
:
23505 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23506 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23509 gcc_unreachable ();
23515 /* Other codes have no operands. */
23521 /* Iteratively hash the whole DWARF location expression LOC. */
23523 static inline hashval_t
23524 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23526 dw_loc_descr_ref l
;
23527 bool sizes_computed
= false;
23528 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23529 size_of_locs (loc
);
23531 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23533 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23534 hash
= iterative_hash_object (opc
, hash
);
23535 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23537 size_of_locs (loc
);
23538 sizes_computed
= true;
23540 hash
= hash_loc_operands (l
, hash
);
23545 /* Compute hash of the whole location list LIST_HEAD. */
23548 hash_loc_list (dw_loc_list_ref list_head
)
23550 dw_loc_list_ref curr
= list_head
;
23551 hashval_t hash
= 0;
23553 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23555 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23556 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23558 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23560 hash
= hash_locs (curr
->expr
, hash
);
23562 list_head
->hash
= hash
;
23565 /* Return true if X and Y opcodes have the same operands. */
23568 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23570 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23571 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23572 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23573 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23575 switch (x
->dw_loc_opc
)
23577 case DW_OP_const4u
:
23578 case DW_OP_const8u
:
23582 case DW_OP_const1u
:
23583 case DW_OP_const1s
:
23584 case DW_OP_const2u
:
23585 case DW_OP_const2s
:
23586 case DW_OP_const4s
:
23587 case DW_OP_const8s
:
23591 case DW_OP_plus_uconst
:
23627 case DW_OP_deref_size
:
23628 case DW_OP_xderef_size
:
23629 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23632 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23633 can cause irrelevant differences in dw_loc_addr. */
23634 gcc_assert (valx1
->val_class
== dw_val_class_loc
23635 && valy1
->val_class
== dw_val_class_loc
23636 && (dwarf_split_debug_info
23637 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23638 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23639 case DW_OP_implicit_value
:
23640 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23641 || valx2
->val_class
!= valy2
->val_class
)
23643 switch (valx2
->val_class
)
23645 case dw_val_class_const
:
23646 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23647 case dw_val_class_vec
:
23648 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23649 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23650 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23651 valx2
->v
.val_vec
.elt_size
23652 * valx2
->v
.val_vec
.length
) == 0;
23653 case dw_val_class_const_double
:
23654 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23655 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23656 case dw_val_class_addr
:
23657 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23659 gcc_unreachable ();
23662 case DW_OP_bit_piece
:
23663 return valx1
->v
.val_int
== valy1
->v
.val_int
23664 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23667 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23668 case DW_OP_GNU_addr_index
:
23669 case DW_OP_GNU_const_index
:
23671 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23672 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23673 return rtx_equal_p (ax1
, ay1
);
23675 case DW_OP_GNU_implicit_pointer
:
23676 return valx1
->val_class
== dw_val_class_die_ref
23677 && valx1
->val_class
== valy1
->val_class
23678 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23679 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23680 case DW_OP_GNU_entry_value
:
23681 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23682 case DW_OP_GNU_const_type
:
23683 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23684 || valx2
->val_class
!= valy2
->val_class
)
23686 switch (valx2
->val_class
)
23688 case dw_val_class_const
:
23689 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23690 case dw_val_class_vec
:
23691 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23692 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23693 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23694 valx2
->v
.val_vec
.elt_size
23695 * valx2
->v
.val_vec
.length
) == 0;
23696 case dw_val_class_const_double
:
23697 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23698 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23700 gcc_unreachable ();
23702 case DW_OP_GNU_regval_type
:
23703 case DW_OP_GNU_deref_type
:
23704 return valx1
->v
.val_int
== valy1
->v
.val_int
23705 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23706 case DW_OP_GNU_convert
:
23707 case DW_OP_GNU_reinterpret
:
23708 if (valx1
->val_class
!= valy1
->val_class
)
23710 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23711 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23712 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23713 case DW_OP_GNU_parameter_ref
:
23714 return valx1
->val_class
== dw_val_class_die_ref
23715 && valx1
->val_class
== valy1
->val_class
23716 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23718 /* Other codes have no operands. */
23723 /* Return true if DWARF location expressions X and Y are the same. */
23726 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23728 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23729 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23730 || x
->dtprel
!= y
->dtprel
23731 || !compare_loc_operands (x
, y
))
23733 return x
== NULL
&& y
== NULL
;
23736 /* Hashtable helpers. */
23738 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
23740 typedef dw_loc_list_struct value_type
;
23741 typedef dw_loc_list_struct compare_type
;
23742 static inline hashval_t
hash (const value_type
*);
23743 static inline bool equal (const value_type
*, const compare_type
*);
23746 /* Return precomputed hash of location list X. */
23749 loc_list_hasher::hash (const value_type
*x
)
23754 /* Return true if location lists A and B are the same. */
23757 loc_list_hasher::equal (const value_type
*a
, const compare_type
*b
)
23761 if (a
->hash
!= b
->hash
)
23763 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23764 if (strcmp (a
->begin
, b
->begin
) != 0
23765 || strcmp (a
->end
, b
->end
) != 0
23766 || (a
->section
== NULL
) != (b
->section
== NULL
)
23767 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23768 || !compare_locs (a
->expr
, b
->expr
))
23770 return a
== NULL
&& b
== NULL
;
23773 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
23776 /* Recursively optimize location lists referenced from DIE
23777 children and share them whenever possible. */
23780 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type htab
)
23785 dw_loc_list_struct
**slot
;
23787 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23788 if (AT_class (a
) == dw_val_class_loc_list
)
23790 dw_loc_list_ref list
= AT_loc_list (a
);
23791 /* TODO: perform some optimizations here, before hashing
23792 it and storing into the hash table. */
23793 hash_loc_list (list
);
23794 slot
= htab
.find_slot_with_hash (list
, list
->hash
, INSERT
);
23798 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
23801 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23805 /* Recursively assign each location list a unique index into the debug_addr
23809 index_location_lists (dw_die_ref die
)
23815 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23816 if (AT_class (a
) == dw_val_class_loc_list
)
23818 dw_loc_list_ref list
= AT_loc_list (a
);
23819 dw_loc_list_ref curr
;
23820 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23822 /* Don't index an entry that has already been indexed
23823 or won't be output. */
23824 if (curr
->begin_entry
!= NULL
23825 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23829 = add_addr_table_entry (xstrdup (curr
->begin
),
23834 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23837 /* Optimize location lists referenced from DIE
23838 children and share them whenever possible. */
23841 optimize_location_lists (dw_die_ref die
)
23843 loc_list_hash_type htab
;
23845 optimize_location_lists_1 (die
, htab
);
23849 /* Output stuff that dwarf requires at the end of every file,
23850 and generate the DWARF-2 debugging info. */
23853 dwarf2out_finish (const char *filename
)
23855 limbo_die_node
*node
, *next_node
;
23856 comdat_type_node
*ctnode
;
23857 hash_table
<comdat_type_hasher
> comdat_type_table
;
23859 dw_die_ref main_comp_unit_die
;
23861 /* PCH might result in DW_AT_producer string being restored from the
23862 header compilation, so always fill it with empty string initially
23863 and overwrite only here. */
23864 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23865 producer_string
= gen_producer_string ();
23866 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23867 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23869 gen_scheduled_generic_parms_dies ();
23870 gen_remaining_tmpl_value_param_die_attribute ();
23872 /* Add the name for the main input file now. We delayed this from
23873 dwarf2out_init to avoid complications with PCH. */
23874 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23875 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23876 add_comp_dir_attribute (comp_unit_die ());
23877 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23880 htab_traverse (file_table
, file_table_relative_p
, &p
);
23882 add_comp_dir_attribute (comp_unit_die ());
23885 if (deferred_locations_list
)
23886 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23888 add_location_or_const_value_attribute (
23889 (*deferred_locations_list
)[i
].die
,
23890 (*deferred_locations_list
)[i
].variable
,
23895 /* Traverse the limbo die list, and add parent/child links. The only
23896 dies without parents that should be here are concrete instances of
23897 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23898 For concrete instances, we can get the parent die from the abstract
23900 for (node
= limbo_die_list
; node
; node
= next_node
)
23902 dw_die_ref die
= node
->die
;
23903 next_node
= node
->next
;
23905 if (die
->die_parent
== NULL
)
23907 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23909 if (origin
&& origin
->die_parent
)
23910 add_child_die (origin
->die_parent
, die
);
23911 else if (is_cu_die (die
))
23913 else if (seen_error ())
23914 /* It's OK to be confused by errors in the input. */
23915 add_child_die (comp_unit_die (), die
);
23918 /* In certain situations, the lexical block containing a
23919 nested function can be optimized away, which results
23920 in the nested function die being orphaned. Likewise
23921 with the return type of that nested function. Force
23922 this to be a child of the containing function.
23924 It may happen that even the containing function got fully
23925 inlined and optimized out. In that case we are lost and
23926 assign the empty child. This should not be big issue as
23927 the function is likely unreachable too. */
23928 gcc_assert (node
->created_for
);
23930 if (DECL_P (node
->created_for
))
23931 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23932 else if (TYPE_P (node
->created_for
))
23933 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23935 origin
= comp_unit_die ();
23937 add_child_die (origin
, die
);
23942 limbo_die_list
= NULL
;
23944 #if ENABLE_ASSERT_CHECKING
23946 dw_die_ref die
= comp_unit_die (), c
;
23947 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23950 resolve_addr (comp_unit_die ());
23951 move_marked_base_types ();
23953 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23955 tree decl
= node
->created_for
;
23956 /* When generating LTO bytecode we can not generate new assembler
23957 names at this point and all important decls got theirs via
23959 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23960 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23962 add_linkage_attr (node
->die
, decl
);
23963 move_linkage_attr (node
->die
);
23967 deferred_asm_name
= NULL
;
23969 /* Walk through the list of incomplete types again, trying once more to
23970 emit full debugging info for them. */
23971 retry_incomplete_types ();
23973 if (flag_eliminate_unused_debug_types
)
23974 prune_unused_types ();
23976 /* Generate separate COMDAT sections for type DIEs. */
23977 if (use_debug_types
)
23979 break_out_comdat_types (comp_unit_die ());
23981 /* Each new type_unit DIE was added to the limbo die list when created.
23982 Since these have all been added to comdat_type_list, clear the
23984 limbo_die_list
= NULL
;
23986 /* For each new comdat type unit, copy declarations for incomplete
23987 types to make the new unit self-contained (i.e., no direct
23988 references to the main compile unit). */
23989 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23990 copy_decls_for_unworthy_types (ctnode
->root_die
);
23991 copy_decls_for_unworthy_types (comp_unit_die ());
23993 /* In the process of copying declarations from one unit to another,
23994 we may have left some declarations behind that are no longer
23995 referenced. Prune them. */
23996 prune_unused_types ();
23999 /* Generate separate CUs for each of the include files we've seen.
24000 They will go into limbo_die_list. */
24001 if (flag_eliminate_dwarf2_dups
)
24002 break_out_includes (comp_unit_die ());
24004 /* Traverse the DIE's and add add sibling attributes to those DIE's
24005 that have children. */
24006 add_sibling_attributes (comp_unit_die ());
24007 for (node
= limbo_die_list
; node
; node
= node
->next
)
24008 add_sibling_attributes (node
->die
);
24009 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24010 add_sibling_attributes (ctnode
->root_die
);
24012 /* When splitting DWARF info, we put some attributes in the
24013 skeleton compile_unit DIE that remains in the .o, while
24014 most attributes go in the DWO compile_unit_die. */
24015 if (dwarf_split_debug_info
)
24016 main_comp_unit_die
= gen_compile_unit_die (NULL
);
24018 main_comp_unit_die
= comp_unit_die ();
24020 /* Output a terminator label for the .text section. */
24021 switch_to_section (text_section
);
24022 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
24023 if (cold_text_section
)
24025 switch_to_section (cold_text_section
);
24026 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
24029 /* We can only use the low/high_pc attributes if all of the code was
24031 if (!have_multiple_function_sections
24032 || (dwarf_version
< 3 && dwarf_strict
))
24034 /* Don't add if the CU has no associated code. */
24035 if (text_section_used
)
24036 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
24037 text_end_label
, true);
24043 bool range_list_added
= false;
24045 if (text_section_used
)
24046 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
24047 text_end_label
, &range_list_added
, true);
24048 if (cold_text_section_used
)
24049 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
24050 cold_end_label
, &range_list_added
, true);
24052 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
24054 if (DECL_IGNORED_P (fde
->decl
))
24056 if (!fde
->in_std_section
)
24057 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
24058 fde
->dw_fde_end
, &range_list_added
,
24060 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
24061 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
24062 fde
->dw_fde_second_end
, &range_list_added
,
24066 if (range_list_added
)
24068 /* We need to give .debug_loc and .debug_ranges an appropriate
24069 "base address". Use zero so that these addresses become
24070 absolute. Historically, we've emitted the unexpected
24071 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
24072 Emit both to give time for other tools to adapt. */
24073 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
24074 if (! dwarf_strict
&& dwarf_version
< 4)
24075 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
24081 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
24082 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
24083 debug_line_section_label
);
24086 add_AT_macptr (comp_unit_die (),
24087 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
24088 macinfo_section_label
);
24090 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
24092 /* optimize_location_lists calculates the size of the lists,
24093 so index them first, and assign indices to the entries.
24094 Although optimize_location_lists will remove entries from
24095 the table, it only does so for duplicates, and therefore
24096 only reduces ref_counts to 1. */
24097 unsigned int index
= 0;
24098 index_location_lists (comp_unit_die ());
24099 htab_traverse_noresize (addr_index_table
,
24100 index_addr_table_entry
, &index
);
24102 if (have_location_lists
)
24103 optimize_location_lists (comp_unit_die ());
24105 save_macinfo_strings ();
24107 if (dwarf_split_debug_info
)
24109 unsigned int index
= 0;
24111 /* Add attributes common to skeleton compile_units and
24112 type_units. Because these attributes include strings, it
24113 must be done before freezing the string table. Top-level
24114 skeleton die attrs are added when the skeleton type unit is
24115 created, so ensure it is created by this point. */
24116 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
24117 (void) get_skeleton_type_unit ();
24118 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
24121 /* Output all of the compilation units. We put the main one last so that
24122 the offsets are available to output_pubnames. */
24123 for (node
= limbo_die_list
; node
; node
= node
->next
)
24124 output_comp_unit (node
->die
, 0);
24126 comdat_type_table
.create (100);
24127 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24129 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
24131 /* Don't output duplicate types. */
24132 if (*slot
!= HTAB_EMPTY_ENTRY
)
24135 /* Add a pointer to the line table for the main compilation unit
24136 so that the debugger can make sense of DW_AT_decl_file
24138 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
24139 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
24140 (!dwarf_split_debug_info
24141 ? debug_line_section_label
24142 : debug_skeleton_line_section_label
));
24144 output_comdat_type_unit (ctnode
);
24147 comdat_type_table
.dispose ();
24149 /* The AT_pubnames attribute needs to go in all skeleton dies, including
24150 both the main_cu and all skeleton TUs. Making this call unconditional
24151 would end up either adding a second copy of the AT_pubnames attribute, or
24152 requiring a special case in add_top_level_skeleton_die_attrs. */
24153 if (!dwarf_split_debug_info
)
24154 add_AT_pubnames (comp_unit_die ());
24156 if (dwarf_split_debug_info
)
24159 unsigned char checksum
[16];
24160 struct md5_ctx ctx
;
24162 /* Compute a checksum of the comp_unit to use as the dwo_id. */
24163 md5_init_ctx (&ctx
);
24165 die_checksum (comp_unit_die (), &ctx
, &mark
);
24166 unmark_all_dies (comp_unit_die ());
24167 md5_finish_ctx (&ctx
, checksum
);
24169 /* Use the first 8 bytes of the checksum as the dwo_id,
24170 and add it to both comp-unit DIEs. */
24171 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
24172 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
24174 /* Add the base offset of the ranges table to the skeleton
24176 if (ranges_table_in_use
)
24177 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
24178 ranges_section_label
);
24180 switch_to_section (debug_addr_section
);
24181 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
24182 output_addr_table ();
24185 /* Output the main compilation unit if non-empty or if .debug_macinfo
24186 or .debug_macro will be emitted. */
24187 output_comp_unit (comp_unit_die (), have_macinfo
);
24189 if (dwarf_split_debug_info
&& info_section_emitted
)
24190 output_skeleton_debug_sections (main_comp_unit_die
);
24192 /* Output the abbreviation table. */
24193 if (abbrev_die_table_in_use
!= 1)
24195 switch_to_section (debug_abbrev_section
);
24196 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
24197 output_abbrev_section ();
24200 /* Output location list section if necessary. */
24201 if (have_location_lists
)
24203 /* Output the location lists info. */
24204 switch_to_section (debug_loc_section
);
24205 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
24206 output_location_lists (comp_unit_die ());
24209 output_pubtables ();
24211 /* Output the address range information if a CU (.debug_info section)
24212 was emitted. We output an empty table even if we had no functions
24213 to put in it. This because the consumer has no way to tell the
24214 difference between an empty table that we omitted and failure to
24215 generate a table that would have contained data. */
24216 if (info_section_emitted
)
24218 unsigned long aranges_length
= size_of_aranges ();
24220 switch_to_section (debug_aranges_section
);
24221 output_aranges (aranges_length
);
24224 /* Output ranges section if necessary. */
24225 if (ranges_table_in_use
)
24227 switch_to_section (debug_ranges_section
);
24228 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24232 /* Have to end the macro section. */
24235 switch_to_section (debug_macinfo_section
);
24236 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24238 dw2_asm_output_data (1, 0, "End compilation unit");
24241 /* Output the source line correspondence table. We must do this
24242 even if there is no line information. Otherwise, on an empty
24243 translation unit, we will generate a present, but empty,
24244 .debug_info section. IRIX 6.5 `nm' will then complain when
24245 examining the file. This is done late so that any filenames
24246 used by the debug_info section are marked as 'used'. */
24247 switch_to_section (debug_line_section
);
24248 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24249 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24250 output_line_info (false);
24252 if (dwarf_split_debug_info
&& info_section_emitted
)
24254 switch_to_section (debug_skeleton_line_section
);
24255 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24256 output_line_info (true);
24259 /* If we emitted any indirect strings, output the string table too. */
24260 if (debug_str_hash
|| skeleton_debug_str_hash
)
24261 output_indirect_strings ();
24264 #include "gt-dwarf2out.h"