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"
66 #include "hard-reg-set.h"
68 #include "insn-config.h"
75 #include "dwarf2out.h"
76 #include "dwarf2asm.h"
81 #include "diagnostic.h"
82 #include "tree-pretty-print.h"
85 #include "common/common-target.h"
86 #include "langhooks.h"
96 #include "gdb/gdb-index.h"
98 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
99 static rtx last_var_location_insn
;
100 static rtx cached_next_real_insn
;
102 #ifdef VMS_DEBUGGING_INFO
103 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
105 /* Define this macro to be a nonzero value if the directory specifications
106 which are output in the debug info should end with a separator. */
107 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
108 /* Define this macro to evaluate to a nonzero value if GCC should refrain
109 from generating indirect strings in DWARF2 debug information, for instance
110 if your target is stuck with an old version of GDB that is unable to
111 process them properly or uses VMS Debug. */
112 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
114 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
115 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
118 /* ??? Poison these here until it can be done generically. They've been
119 totally replaced in this file; make sure it stays that way. */
120 #undef DWARF2_UNWIND_INFO
121 #undef DWARF2_FRAME_INFO
122 #if (GCC_VERSION >= 3000)
123 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
126 /* The size of the target's pointer type. */
128 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
131 /* Array of RTXes referenced by the debugging information, which therefore
132 must be kept around forever. */
133 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
135 /* A pointer to the base of a list of incomplete types which might be
136 completed at some later time. incomplete_types_list needs to be a
137 vec<tree, va_gc> *because we want to tell the garbage collector about
139 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
141 /* A pointer to the base of a table of references to declaration
142 scopes. This table is a display which tracks the nesting
143 of declaration scopes at the current scope and containing
144 scopes. This table is used to find the proper place to
145 define type declaration DIE's. */
146 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
148 /* Pointers to various DWARF2 sections. */
149 static GTY(()) section
*debug_info_section
;
150 static GTY(()) section
*debug_skeleton_info_section
;
151 static GTY(()) section
*debug_abbrev_section
;
152 static GTY(()) section
*debug_skeleton_abbrev_section
;
153 static GTY(()) section
*debug_aranges_section
;
154 static GTY(()) section
*debug_addr_section
;
155 static GTY(()) section
*debug_macinfo_section
;
156 static GTY(()) section
*debug_line_section
;
157 static GTY(()) section
*debug_skeleton_line_section
;
158 static GTY(()) section
*debug_loc_section
;
159 static GTY(()) section
*debug_pubnames_section
;
160 static GTY(()) section
*debug_pubtypes_section
;
161 static GTY(()) section
*debug_str_section
;
162 static GTY(()) section
*debug_str_dwo_section
;
163 static GTY(()) section
*debug_str_offsets_section
;
164 static GTY(()) section
*debug_ranges_section
;
165 static GTY(()) section
*debug_frame_section
;
167 /* Maximum size (in bytes) of an artificially generated label. */
168 #define MAX_ARTIFICIAL_LABEL_BYTES 30
170 /* According to the (draft) DWARF 3 specification, the initial length
171 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
172 bytes are 0xffffffff, followed by the length stored in the next 8
175 However, the SGI/MIPS ABI uses an initial length which is equal to
176 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
178 #ifndef DWARF_INITIAL_LENGTH_SIZE
179 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
182 /* Round SIZE up to the nearest BOUNDARY. */
183 #define DWARF_ROUND(SIZE,BOUNDARY) \
184 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
186 /* CIE identifier. */
187 #if HOST_BITS_PER_WIDE_INT >= 64
188 #define DWARF_CIE_ID \
189 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
191 #define DWARF_CIE_ID DW_CIE_ID
195 /* A vector for a table that contains frame description
196 information for each routine. */
197 #define NOT_INDEXED (-1U)
198 #define NO_INDEX_ASSIGNED (-2U)
200 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
202 struct GTY(()) indirect_string_node
{
204 unsigned int refcount
;
205 enum dwarf_form form
;
210 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
212 /* With split_debug_info, both the comp_dir and dwo_name go in the
213 main object file, rather than the dwo, similar to the force_direct
214 parameter elsewhere but with additional complications:
216 1) The string is needed in both the main object file and the dwo.
217 That is, the comp_dir and dwo_name will appear in both places.
219 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
220 DW_FORM_GNU_str_index.
222 3) GCC chooses the form to use late, depending on the size and
225 Rather than forcing the all debug string handling functions and
226 callers to deal with these complications, simply use a separate,
227 special-cased string table for any attribute that should go in the
228 main object file. This limits the complexity to just the places
231 static GTY ((param_is (struct indirect_string_node
)))
232 htab_t skeleton_debug_str_hash
;
234 static GTY(()) int dw2_string_counter
;
236 /* True if the compilation unit places functions in more than one section. */
237 static GTY(()) bool have_multiple_function_sections
= false;
239 /* Whether the default text and cold text sections have been used at all. */
241 static GTY(()) bool text_section_used
= false;
242 static GTY(()) bool cold_text_section_used
= false;
244 /* The default cold text section. */
245 static GTY(()) section
*cold_text_section
;
247 /* Forward declarations for functions defined in this file. */
249 static char *stripattributes (const char *);
250 static void output_call_frame_info (int);
251 static void dwarf2out_note_section_used (void);
253 /* Personality decl of current unit. Used only when assembler does not support
255 static GTY(()) rtx current_unit_personality
;
257 /* Data and reference forms for relocatable data. */
258 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
259 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
261 #ifndef DEBUG_FRAME_SECTION
262 #define DEBUG_FRAME_SECTION ".debug_frame"
265 #ifndef FUNC_BEGIN_LABEL
266 #define FUNC_BEGIN_LABEL "LFB"
269 #ifndef FUNC_END_LABEL
270 #define FUNC_END_LABEL "LFE"
273 #ifndef PROLOGUE_END_LABEL
274 #define PROLOGUE_END_LABEL "LPE"
277 #ifndef EPILOGUE_BEGIN_LABEL
278 #define EPILOGUE_BEGIN_LABEL "LEB"
281 #ifndef FRAME_BEGIN_LABEL
282 #define FRAME_BEGIN_LABEL "Lframe"
284 #define CIE_AFTER_SIZE_LABEL "LSCIE"
285 #define CIE_END_LABEL "LECIE"
286 #define FDE_LABEL "LSFDE"
287 #define FDE_AFTER_SIZE_LABEL "LASFDE"
288 #define FDE_END_LABEL "LEFDE"
289 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
290 #define LINE_NUMBER_END_LABEL "LELT"
291 #define LN_PROLOG_AS_LABEL "LASLTP"
292 #define LN_PROLOG_END_LABEL "LELTP"
293 #define DIE_LABEL_PREFIX "DW"
295 /* Match the base name of a file to the base name of a compilation unit. */
298 matches_main_base (const char *path
)
300 /* Cache the last query. */
301 static const char *last_path
= NULL
;
302 static int last_match
= 0;
303 if (path
!= last_path
)
306 int length
= base_of_path (path
, &base
);
308 last_match
= (length
== main_input_baselength
309 && memcmp (base
, main_input_basename
, length
) == 0);
314 #ifdef DEBUG_DEBUG_STRUCT
317 dump_struct_debug (tree type
, enum debug_info_usage usage
,
318 enum debug_struct_file criterion
, int generic
,
319 int matches
, int result
)
321 /* Find the type name. */
322 tree type_decl
= TYPE_STUB_DECL (type
);
324 const char *name
= 0;
325 if (TREE_CODE (t
) == TYPE_DECL
)
328 name
= IDENTIFIER_POINTER (t
);
330 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
332 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
333 matches
? "bas" : "hdr",
334 generic
? "gen" : "ord",
335 usage
== DINFO_USAGE_DFN
? ";" :
336 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
338 (void*) type_decl
, name
);
341 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
342 dump_struct_debug (type, usage, criterion, generic, matches, result)
346 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
352 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
354 enum debug_struct_file criterion
;
356 bool generic
= lang_hooks
.types
.generic_p (type
);
359 criterion
= debug_struct_generic
[usage
];
361 criterion
= debug_struct_ordinary
[usage
];
363 if (criterion
== DINFO_STRUCT_FILE_NONE
)
364 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
365 if (criterion
== DINFO_STRUCT_FILE_ANY
)
366 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
368 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
370 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
371 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
373 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
374 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
375 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
378 /* Return a pointer to a copy of the section string name S with all
379 attributes stripped off, and an asterisk prepended (for assemble_name). */
382 stripattributes (const char *s
)
384 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
389 while (*s
&& *s
!= ',')
396 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
397 switch to the data section instead, and write out a synthetic start label
398 for collect2 the first time around. */
401 switch_to_eh_frame_section (bool back
)
405 #ifdef EH_FRAME_SECTION_NAME
406 if (eh_frame_section
== 0)
410 if (EH_TABLES_CAN_BE_READ_ONLY
)
416 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
418 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
420 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
423 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
424 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
425 && (per_encoding
& 0x70) != DW_EH_PE_absptr
426 && (per_encoding
& 0x70) != DW_EH_PE_aligned
427 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
428 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
429 ? 0 : SECTION_WRITE
);
432 flags
= SECTION_WRITE
;
433 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
435 #endif /* EH_FRAME_SECTION_NAME */
437 if (eh_frame_section
)
438 switch_to_section (eh_frame_section
);
441 /* We have no special eh_frame section. Put the information in
442 the data section and emit special labels to guide collect2. */
443 switch_to_section (data_section
);
447 label
= get_file_function_name ("F");
448 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
449 targetm
.asm_out
.globalize_label (asm_out_file
,
450 IDENTIFIER_POINTER (label
));
451 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
456 /* Switch [BACK] to the eh or debug frame table section, depending on
460 switch_to_frame_table_section (int for_eh
, bool back
)
463 switch_to_eh_frame_section (back
);
466 if (!debug_frame_section
)
467 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
468 SECTION_DEBUG
, NULL
);
469 switch_to_section (debug_frame_section
);
473 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
475 enum dw_cfi_oprnd_type
476 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
481 case DW_CFA_GNU_window_save
:
482 case DW_CFA_remember_state
:
483 case DW_CFA_restore_state
:
484 return dw_cfi_oprnd_unused
;
487 case DW_CFA_advance_loc1
:
488 case DW_CFA_advance_loc2
:
489 case DW_CFA_advance_loc4
:
490 case DW_CFA_MIPS_advance_loc8
:
491 return dw_cfi_oprnd_addr
;
494 case DW_CFA_offset_extended
:
496 case DW_CFA_offset_extended_sf
:
497 case DW_CFA_def_cfa_sf
:
499 case DW_CFA_restore_extended
:
500 case DW_CFA_undefined
:
501 case DW_CFA_same_value
:
502 case DW_CFA_def_cfa_register
:
503 case DW_CFA_register
:
504 case DW_CFA_expression
:
505 return dw_cfi_oprnd_reg_num
;
507 case DW_CFA_def_cfa_offset
:
508 case DW_CFA_GNU_args_size
:
509 case DW_CFA_def_cfa_offset_sf
:
510 return dw_cfi_oprnd_offset
;
512 case DW_CFA_def_cfa_expression
:
513 return dw_cfi_oprnd_loc
;
520 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
522 enum dw_cfi_oprnd_type
523 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
528 case DW_CFA_def_cfa_sf
:
530 case DW_CFA_offset_extended_sf
:
531 case DW_CFA_offset_extended
:
532 return dw_cfi_oprnd_offset
;
534 case DW_CFA_register
:
535 return dw_cfi_oprnd_reg_num
;
537 case DW_CFA_expression
:
538 return dw_cfi_oprnd_loc
;
541 return dw_cfi_oprnd_unused
;
545 /* Output one FDE. */
548 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
549 char *section_start_label
, int fde_encoding
, char *augmentation
,
550 bool any_lsda_needed
, int lsda_encoding
)
552 const char *begin
, *end
;
553 static unsigned int j
;
556 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
558 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
560 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
561 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
562 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
563 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
564 " indicating 64-bit DWARF extension");
565 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
567 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
570 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
572 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
573 debug_frame_section
, "FDE CIE offset");
575 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
576 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
580 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
581 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
582 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
583 "FDE initial location");
584 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
585 end
, begin
, "FDE address range");
589 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
590 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
597 int size
= size_of_encoded_value (lsda_encoding
);
599 if (lsda_encoding
== DW_EH_PE_aligned
)
601 int offset
= ( 4 /* Length */
603 + 2 * size_of_encoded_value (fde_encoding
)
604 + 1 /* Augmentation size */ );
605 int pad
= -offset
& (PTR_SIZE
- 1);
608 gcc_assert (size_of_uleb128 (size
) == 1);
611 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
613 if (fde
->uses_eh_lsda
)
615 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
616 fde
->funcdef_number
);
617 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
618 gen_rtx_SYMBOL_REF (Pmode
, l1
),
620 "Language Specific Data Area");
624 if (lsda_encoding
== DW_EH_PE_aligned
)
625 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
626 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
627 "Language Specific Data Area (none)");
631 dw2_asm_output_data_uleb128 (0, "Augmentation size");
634 /* Loop through the Call Frame Instructions associated with this FDE. */
635 fde
->dw_fde_current_label
= begin
;
637 size_t from
, until
, i
;
640 until
= vec_safe_length (fde
->dw_fde_cfi
);
642 if (fde
->dw_fde_second_begin
== NULL
)
645 until
= fde
->dw_fde_switch_cfi_index
;
647 from
= fde
->dw_fde_switch_cfi_index
;
649 for (i
= from
; i
< until
; i
++)
650 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
653 /* If we are to emit a ref/link from function bodies to their frame tables,
654 do it now. This is typically performed to make sure that tables
655 associated with functions are dragged with them and not discarded in
656 garbage collecting links. We need to do this on a per function basis to
657 cope with -ffunction-sections. */
659 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
660 /* Switch to the function section, emit the ref to the tables, and
661 switch *back* into the table section. */
662 switch_to_section (function_section (fde
->decl
));
663 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
664 switch_to_frame_table_section (for_eh
, true);
667 /* Pad the FDE out to an address sized boundary. */
668 ASM_OUTPUT_ALIGN (asm_out_file
,
669 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
670 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
675 /* Return true if frame description entry FDE is needed for EH. */
678 fde_needed_for_eh_p (dw_fde_ref fde
)
680 if (flag_asynchronous_unwind_tables
)
683 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
686 if (fde
->uses_eh_lsda
)
689 /* If exceptions are enabled, we have collected nothrow info. */
690 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
696 /* Output the call frame information used to record information
697 that relates to calculating the frame pointer, and records the
698 location of saved registers. */
701 output_call_frame_info (int for_eh
)
706 char l1
[20], l2
[20], section_start_label
[20];
707 bool any_lsda_needed
= false;
708 char augmentation
[6];
709 int augmentation_size
;
710 int fde_encoding
= DW_EH_PE_absptr
;
711 int per_encoding
= DW_EH_PE_absptr
;
712 int lsda_encoding
= DW_EH_PE_absptr
;
714 rtx personality
= NULL
;
717 /* Don't emit a CIE if there won't be any FDEs. */
721 /* Nothing to do if the assembler's doing it all. */
722 if (dwarf2out_do_cfi_asm ())
725 /* If we don't have any functions we'll want to unwind out of, don't emit
726 any EH unwind information. If we make FDEs linkonce, we may have to
727 emit an empty label for an FDE that wouldn't otherwise be emitted. We
728 want to avoid having an FDE kept around when the function it refers to
729 is discarded. Example where this matters: a primary function template
730 in C++ requires EH information, an explicit specialization doesn't. */
733 bool any_eh_needed
= false;
735 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
737 if (fde
->uses_eh_lsda
)
738 any_eh_needed
= any_lsda_needed
= true;
739 else if (fde_needed_for_eh_p (fde
))
740 any_eh_needed
= true;
741 else if (TARGET_USES_WEAK_UNWIND_INFO
)
742 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
749 /* We're going to be generating comments, so turn on app. */
753 /* Switch to the proper frame section, first time. */
754 switch_to_frame_table_section (for_eh
, false);
756 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
757 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
759 /* Output the CIE. */
760 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
761 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
762 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
763 dw2_asm_output_data (4, 0xffffffff,
764 "Initial length escape value indicating 64-bit DWARF extension");
765 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
766 "Length of Common Information Entry");
767 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
769 /* Now that the CIE pointer is PC-relative for EH,
770 use 0 to identify the CIE. */
771 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
772 (for_eh
? 0 : DWARF_CIE_ID
),
773 "CIE Identifier Tag");
775 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
776 use CIE version 1, unless that would produce incorrect results
777 due to overflowing the return register column. */
778 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
780 if (return_reg
>= 256 || dwarf_version
> 2)
782 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
785 augmentation_size
= 0;
787 personality
= current_unit_personality
;
793 z Indicates that a uleb128 is present to size the
794 augmentation section.
795 L Indicates the encoding (and thus presence) of
796 an LSDA pointer in the FDE augmentation.
797 R Indicates a non-default pointer encoding for
799 P Indicates the presence of an encoding + language
800 personality routine in the CIE augmentation. */
802 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
803 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
804 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
806 p
= augmentation
+ 1;
810 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
811 assemble_external_libcall (personality
);
816 augmentation_size
+= 1;
818 if (fde_encoding
!= DW_EH_PE_absptr
)
821 augmentation_size
+= 1;
823 if (p
> augmentation
+ 1)
825 augmentation
[0] = 'z';
829 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
830 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
832 int offset
= ( 4 /* Length */
834 + 1 /* CIE version */
835 + strlen (augmentation
) + 1 /* Augmentation */
836 + size_of_uleb128 (1) /* Code alignment */
837 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
839 + 1 /* Augmentation size */
840 + 1 /* Personality encoding */ );
841 int pad
= -offset
& (PTR_SIZE
- 1);
843 augmentation_size
+= pad
;
845 /* Augmentations should be small, so there's scarce need to
846 iterate for a solution. Die if we exceed one uleb128 byte. */
847 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
851 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
852 if (dw_cie_version
>= 4)
854 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
855 dw2_asm_output_data (1, 0, "CIE Segment Size");
857 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
858 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
859 "CIE Data Alignment Factor");
861 if (dw_cie_version
== 1)
862 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
864 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
868 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
871 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
872 eh_data_format_name (per_encoding
));
873 dw2_asm_output_encoded_addr_rtx (per_encoding
,
879 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
880 eh_data_format_name (lsda_encoding
));
882 if (fde_encoding
!= DW_EH_PE_absptr
)
883 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
884 eh_data_format_name (fde_encoding
));
887 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
888 output_cfi (cfi
, NULL
, for_eh
);
890 /* Pad the CIE out to an address sized boundary. */
891 ASM_OUTPUT_ALIGN (asm_out_file
,
892 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
893 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
895 /* Loop through all of the FDE's. */
896 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
900 /* Don't emit EH unwind info for leaf functions that don't need it. */
901 if (for_eh
&& !fde_needed_for_eh_p (fde
))
904 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
905 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
906 augmentation
, any_lsda_needed
, lsda_encoding
);
909 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
910 dw2_asm_output_data (4, 0, "End of Table");
912 /* Turn off app to make assembly quicker. */
917 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
920 dwarf2out_do_cfi_startproc (bool second
)
924 rtx personality
= get_personality_function (current_function_decl
);
926 fprintf (asm_out_file
, "\t.cfi_startproc\n");
930 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
933 /* ??? The GAS support isn't entirely consistent. We have to
934 handle indirect support ourselves, but PC-relative is done
935 in the assembler. Further, the assembler can't handle any
936 of the weirder relocation types. */
937 if (enc
& DW_EH_PE_indirect
)
938 ref
= dw2_force_const_mem (ref
, true);
940 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
941 output_addr_const (asm_out_file
, ref
);
942 fputc ('\n', asm_out_file
);
945 if (crtl
->uses_eh_lsda
)
949 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
950 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
951 FUNC_LABEL_ID (cfun
));
952 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
953 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
955 if (enc
& DW_EH_PE_indirect
)
956 ref
= dw2_force_const_mem (ref
, true);
958 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
959 output_addr_const (asm_out_file
, ref
);
960 fputc ('\n', asm_out_file
);
964 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
965 this allocation may be done before pass_final. */
968 dwarf2out_alloc_current_fde (void)
972 fde
= ggc_alloc_cleared_dw_fde_node ();
973 fde
->decl
= current_function_decl
;
974 fde
->funcdef_number
= FUNC_LABEL_ID (cfun
);
975 fde
->fde_index
= vec_safe_length (fde_vec
);
976 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
977 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
978 fde
->nothrow
= crtl
->nothrow
;
979 fde
->drap_reg
= INVALID_REGNUM
;
980 fde
->vdrap_reg
= INVALID_REGNUM
;
982 /* Record the FDE associated with this function. */
984 vec_safe_push (fde_vec
, fde
);
989 /* Output a marker (i.e. a label) for the beginning of a function, before
993 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
994 const char *file ATTRIBUTE_UNUSED
)
996 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1002 current_function_func_begin_label
= NULL
;
1004 do_frame
= dwarf2out_do_frame ();
1006 /* ??? current_function_func_begin_label is also used by except.c for
1007 call-site information. We must emit this label if it might be used. */
1009 && (!flag_exceptions
1010 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1013 fnsec
= function_section (current_function_decl
);
1014 switch_to_section (fnsec
);
1015 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1016 FUNC_LABEL_ID (cfun
));
1017 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1018 FUNC_LABEL_ID (cfun
));
1019 dup_label
= xstrdup (label
);
1020 current_function_func_begin_label
= dup_label
;
1022 /* We can elide the fde allocation if we're not emitting debug info. */
1026 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1027 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1028 would include pass_dwarf2_frame. If we've not created the FDE yet,
1032 fde
= dwarf2out_alloc_current_fde ();
1034 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1035 fde
->dw_fde_begin
= dup_label
;
1036 fde
->dw_fde_current_label
= dup_label
;
1037 fde
->in_std_section
= (fnsec
== text_section
1038 || (cold_text_section
&& fnsec
== cold_text_section
));
1040 /* We only want to output line number information for the genuine dwarf2
1041 prologue case, not the eh frame case. */
1042 #ifdef DWARF2_DEBUGGING_INFO
1044 dwarf2out_source_line (line
, file
, 0, true);
1047 if (dwarf2out_do_cfi_asm ())
1048 dwarf2out_do_cfi_startproc (false);
1051 rtx personality
= get_personality_function (current_function_decl
);
1052 if (!current_unit_personality
)
1053 current_unit_personality
= personality
;
1055 /* We cannot keep a current personality per function as without CFI
1056 asm, at the point where we emit the CFI data, there is no current
1057 function anymore. */
1058 if (personality
&& current_unit_personality
!= personality
)
1059 sorry ("multiple EH personalities are supported only with assemblers "
1060 "supporting .cfi_personality directive");
1064 /* Output a marker (i.e. a label) for the end of the generated code
1065 for a function prologue. This gets called *after* the prologue code has
1069 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1070 const char *file ATTRIBUTE_UNUSED
)
1072 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1074 /* Output a label to mark the endpoint of the code generated for this
1076 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1077 FUNC_LABEL_ID (cfun
));
1078 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1079 FUNC_LABEL_ID (cfun
));
1080 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1083 /* Output a marker (i.e. a label) for the beginning of the generated code
1084 for a function epilogue. This gets called *before* the prologue code has
1088 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1089 const char *file ATTRIBUTE_UNUSED
)
1091 dw_fde_ref fde
= cfun
->fde
;
1092 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1094 if (fde
->dw_fde_vms_begin_epilogue
)
1097 /* Output a label to mark the endpoint of the code generated for this
1099 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1100 FUNC_LABEL_ID (cfun
));
1101 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1102 FUNC_LABEL_ID (cfun
));
1103 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1106 /* Output a marker (i.e. a label) for the absolute end of the generated code
1107 for a function definition. This gets called *after* the epilogue code has
1111 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1112 const char *file ATTRIBUTE_UNUSED
)
1115 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1117 last_var_location_insn
= NULL_RTX
;
1118 cached_next_real_insn
= NULL_RTX
;
1120 if (dwarf2out_do_cfi_asm ())
1121 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1123 /* Output a label to mark the endpoint of the code generated for this
1125 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1126 FUNC_LABEL_ID (cfun
));
1127 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1129 gcc_assert (fde
!= NULL
);
1130 if (fde
->dw_fde_second_begin
== NULL
)
1131 fde
->dw_fde_end
= xstrdup (label
);
1135 dwarf2out_frame_finish (void)
1137 /* Output call frame information. */
1138 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1139 output_call_frame_info (0);
1141 /* Output another copy for the unwinder. */
1142 if ((flag_unwind_tables
|| flag_exceptions
)
1143 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1144 output_call_frame_info (1);
1147 /* Note that the current function section is being used for code. */
1150 dwarf2out_note_section_used (void)
1152 section
*sec
= current_function_section ();
1153 if (sec
== text_section
)
1154 text_section_used
= true;
1155 else if (sec
== cold_text_section
)
1156 cold_text_section_used
= true;
1159 static void var_location_switch_text_section (void);
1160 static void set_cur_line_info_table (section
*);
1163 dwarf2out_switch_text_section (void)
1166 dw_fde_ref fde
= cfun
->fde
;
1168 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1170 if (!in_cold_section_p
)
1172 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1173 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1174 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1178 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1179 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1180 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1182 have_multiple_function_sections
= true;
1184 /* There is no need to mark used sections when not debugging. */
1185 if (cold_text_section
!= NULL
)
1186 dwarf2out_note_section_used ();
1188 if (dwarf2out_do_cfi_asm ())
1189 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1191 /* Now do the real section switch. */
1192 sect
= current_function_section ();
1193 switch_to_section (sect
);
1195 fde
->second_in_std_section
1196 = (sect
== text_section
1197 || (cold_text_section
&& sect
== cold_text_section
));
1199 if (dwarf2out_do_cfi_asm ())
1200 dwarf2out_do_cfi_startproc (true);
1202 var_location_switch_text_section ();
1204 if (cold_text_section
!= NULL
)
1205 set_cur_line_info_table (sect
);
1208 /* And now, the subset of the debugging information support code necessary
1209 for emitting location expressions. */
1211 /* Data about a single source file. */
1212 struct GTY(()) dwarf_file_data
{
1213 const char * filename
;
1217 typedef struct GTY(()) deferred_locations_struct
1221 } deferred_locations
;
1224 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1227 /* Describe an entry into the .debug_addr section. */
1231 ate_kind_rtx_dtprel
,
1235 typedef struct GTY(()) addr_table_entry_struct
{
1237 unsigned int refcount
;
1239 union addr_table_entry_struct_union
1241 rtx
GTY ((tag ("0"))) rtl
;
1242 char * GTY ((tag ("1"))) label
;
1244 GTY ((desc ("%1.kind"))) addr
;
1248 /* Location lists are ranges + location descriptions for that range,
1249 so you can track variables that are in different places over
1250 their entire life. */
1251 typedef struct GTY(()) dw_loc_list_struct
{
1252 dw_loc_list_ref dw_loc_next
;
1253 const char *begin
; /* Label and addr_entry for start of range */
1254 addr_table_entry
*begin_entry
;
1255 const char *end
; /* Label for end of range */
1256 char *ll_symbol
; /* Label for beginning of location list.
1257 Only on head of list */
1258 const char *section
; /* Section this loclist is relative to */
1259 dw_loc_descr_ref expr
;
1261 /* True if all addresses in this and subsequent lists are known to be
1264 /* True if this list has been replaced by dw_loc_next. */
1267 /* True if the range should be emitted even if begin and end
1272 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1274 /* Convert a DWARF stack opcode into its string name. */
1277 dwarf_stack_op_name (unsigned int op
)
1279 const char *name
= get_DW_OP_name (op
);
1284 return "OP_<unknown>";
1287 /* Return a pointer to a newly allocated location description. Location
1288 descriptions are simple expression terms that can be strung
1289 together to form more complicated location (address) descriptions. */
1291 static inline dw_loc_descr_ref
1292 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1293 unsigned HOST_WIDE_INT oprnd2
)
1295 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1297 descr
->dw_loc_opc
= op
;
1298 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1299 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1300 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1301 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1302 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1303 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1308 /* Return a pointer to a newly allocated location description for
1311 static inline dw_loc_descr_ref
1312 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1315 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1318 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1321 /* Add a location description term to a location description expression. */
1324 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1326 dw_loc_descr_ref
*d
;
1328 /* Find the end of the chain. */
1329 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1335 /* Compare two location operands for exact equality. */
1338 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1340 if (a
->val_class
!= b
->val_class
)
1342 switch (a
->val_class
)
1344 case dw_val_class_none
:
1346 case dw_val_class_addr
:
1347 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1349 case dw_val_class_offset
:
1350 case dw_val_class_unsigned_const
:
1351 case dw_val_class_const
:
1352 case dw_val_class_range_list
:
1353 case dw_val_class_lineptr
:
1354 case dw_val_class_macptr
:
1355 /* These are all HOST_WIDE_INT, signed or unsigned. */
1356 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1358 case dw_val_class_loc
:
1359 return a
->v
.val_loc
== b
->v
.val_loc
;
1360 case dw_val_class_loc_list
:
1361 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1362 case dw_val_class_die_ref
:
1363 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1364 case dw_val_class_fde_ref
:
1365 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1366 case dw_val_class_lbl_id
:
1367 case dw_val_class_high_pc
:
1368 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1369 case dw_val_class_str
:
1370 return a
->v
.val_str
== b
->v
.val_str
;
1371 case dw_val_class_flag
:
1372 return a
->v
.val_flag
== b
->v
.val_flag
;
1373 case dw_val_class_file
:
1374 return a
->v
.val_file
== b
->v
.val_file
;
1375 case dw_val_class_decl_ref
:
1376 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1378 case dw_val_class_const_double
:
1379 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1380 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1382 case dw_val_class_vec
:
1384 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1385 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1387 return (a_len
== b_len
1388 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1391 case dw_val_class_data8
:
1392 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1394 case dw_val_class_vms_delta
:
1395 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1396 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1401 /* Compare two location atoms for exact equality. */
1404 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1406 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1409 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1410 address size, but since we always allocate cleared storage it
1411 should be zero for other types of locations. */
1412 if (a
->dtprel
!= b
->dtprel
)
1415 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1416 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1419 /* Compare two complete location expressions for exact equality. */
1422 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1428 if (a
== NULL
|| b
== NULL
)
1430 if (!loc_descr_equal_p_1 (a
, b
))
1439 /* Add a constant OFFSET to a location expression. */
1442 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1444 dw_loc_descr_ref loc
;
1447 gcc_assert (*list_head
!= NULL
);
1452 /* Find the end of the chain. */
1453 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1457 if (loc
->dw_loc_opc
== DW_OP_fbreg
1458 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1459 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1460 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1461 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1463 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1464 offset. Don't optimize if an signed integer overflow would happen. */
1466 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1467 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1470 else if (offset
> 0)
1471 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1475 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1476 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1480 /* Add a constant OFFSET to a location list. */
1483 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1486 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1487 loc_descr_plus_const (&d
->expr
, offset
);
1490 #define DWARF_REF_SIZE \
1491 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1493 static unsigned long int get_base_type_offset (dw_die_ref
);
1495 /* Return the size of a location descriptor. */
1497 static unsigned long
1498 size_of_loc_descr (dw_loc_descr_ref loc
)
1500 unsigned long size
= 1;
1502 switch (loc
->dw_loc_opc
)
1505 size
+= DWARF2_ADDR_SIZE
;
1507 case DW_OP_GNU_addr_index
:
1508 case DW_OP_GNU_const_index
:
1509 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1510 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1529 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1532 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1537 case DW_OP_plus_uconst
:
1538 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1576 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1579 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1582 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1585 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1586 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1589 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1591 case DW_OP_bit_piece
:
1592 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1593 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1595 case DW_OP_deref_size
:
1596 case DW_OP_xderef_size
:
1605 case DW_OP_call_ref
:
1606 size
+= DWARF_REF_SIZE
;
1608 case DW_OP_implicit_value
:
1609 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1610 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1612 case DW_OP_GNU_implicit_pointer
:
1613 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1615 case DW_OP_GNU_entry_value
:
1617 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1618 size
+= size_of_uleb128 (op_size
) + op_size
;
1621 case DW_OP_GNU_const_type
:
1624 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1625 size
+= size_of_uleb128 (o
) + 1;
1626 switch (loc
->dw_loc_oprnd2
.val_class
)
1628 case dw_val_class_vec
:
1629 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1630 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1632 case dw_val_class_const
:
1633 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1635 case dw_val_class_const_double
:
1636 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1643 case DW_OP_GNU_regval_type
:
1646 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1647 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1648 + size_of_uleb128 (o
);
1651 case DW_OP_GNU_deref_type
:
1654 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1655 size
+= 1 + size_of_uleb128 (o
);
1658 case DW_OP_GNU_convert
:
1659 case DW_OP_GNU_reinterpret
:
1660 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1661 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1665 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1666 size
+= size_of_uleb128 (o
);
1669 case DW_OP_GNU_parameter_ref
:
1679 /* Return the size of a series of location descriptors. */
1682 size_of_locs (dw_loc_descr_ref loc
)
1687 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1688 field, to avoid writing to a PCH file. */
1689 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1691 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1693 size
+= size_of_loc_descr (l
);
1698 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1700 l
->dw_loc_addr
= size
;
1701 size
+= size_of_loc_descr (l
);
1707 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1708 static void get_ref_die_offset_label (char *, dw_die_ref
);
1709 static unsigned long int get_ref_die_offset (dw_die_ref
);
1711 /* Output location description stack opcode's operands (if any).
1712 The for_eh_or_skip parameter controls whether register numbers are
1713 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1714 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1715 info). This should be suppressed for the cases that have not been converted
1716 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1719 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1721 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1722 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1724 switch (loc
->dw_loc_opc
)
1726 #ifdef DWARF2_DEBUGGING_INFO
1729 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1734 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1735 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1737 fputc ('\n', asm_out_file
);
1742 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1747 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1748 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1750 fputc ('\n', asm_out_file
);
1755 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1756 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1763 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1764 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1766 dw2_asm_output_data (2, offset
, NULL
);
1769 case DW_OP_implicit_value
:
1770 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1771 switch (val2
->val_class
)
1773 case dw_val_class_const
:
1774 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1776 case dw_val_class_vec
:
1778 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1779 unsigned int len
= val2
->v
.val_vec
.length
;
1783 if (elt_size
> sizeof (HOST_WIDE_INT
))
1788 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1791 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1792 "fp or vector constant word %u", i
);
1795 case dw_val_class_const_double
:
1797 unsigned HOST_WIDE_INT first
, second
;
1799 if (WORDS_BIG_ENDIAN
)
1801 first
= val2
->v
.val_double
.high
;
1802 second
= val2
->v
.val_double
.low
;
1806 first
= val2
->v
.val_double
.low
;
1807 second
= val2
->v
.val_double
.high
;
1809 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1811 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1815 case dw_val_class_addr
:
1816 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1817 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1832 case DW_OP_implicit_value
:
1833 /* We currently don't make any attempt to make sure these are
1834 aligned properly like we do for the main unwind info, so
1835 don't support emitting things larger than a byte if we're
1836 only doing unwinding. */
1841 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1844 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1847 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1850 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1852 case DW_OP_plus_uconst
:
1853 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1887 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1891 unsigned r
= val1
->v
.val_unsigned
;
1892 if (for_eh_or_skip
>= 0)
1893 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1894 gcc_assert (size_of_uleb128 (r
)
1895 == size_of_uleb128 (val1
->v
.val_unsigned
));
1896 dw2_asm_output_data_uleb128 (r
, NULL
);
1900 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1904 unsigned r
= val1
->v
.val_unsigned
;
1905 if (for_eh_or_skip
>= 0)
1906 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1907 gcc_assert (size_of_uleb128 (r
)
1908 == size_of_uleb128 (val1
->v
.val_unsigned
));
1909 dw2_asm_output_data_uleb128 (r
, NULL
);
1910 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1914 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1916 case DW_OP_bit_piece
:
1917 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1918 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1920 case DW_OP_deref_size
:
1921 case DW_OP_xderef_size
:
1922 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1928 if (targetm
.asm_out
.output_dwarf_dtprel
)
1930 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1933 fputc ('\n', asm_out_file
);
1940 #ifdef DWARF2_DEBUGGING_INFO
1941 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1948 case DW_OP_GNU_addr_index
:
1949 case DW_OP_GNU_const_index
:
1950 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1951 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1952 "(index into .debug_addr)");
1955 case DW_OP_GNU_implicit_pointer
:
1957 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1958 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1959 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1960 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1961 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1962 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1966 case DW_OP_GNU_entry_value
:
1967 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1968 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1971 case DW_OP_GNU_const_type
:
1973 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1975 dw2_asm_output_data_uleb128 (o
, NULL
);
1976 switch (val2
->val_class
)
1978 case dw_val_class_const
:
1979 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1980 dw2_asm_output_data (1, l
, NULL
);
1981 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1983 case dw_val_class_vec
:
1985 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1986 unsigned int len
= val2
->v
.val_vec
.length
;
1991 dw2_asm_output_data (1, l
, NULL
);
1992 if (elt_size
> sizeof (HOST_WIDE_INT
))
1997 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2000 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2001 "fp or vector constant word %u", i
);
2004 case dw_val_class_const_double
:
2006 unsigned HOST_WIDE_INT first
, second
;
2007 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2009 dw2_asm_output_data (1, 2 * l
, NULL
);
2010 if (WORDS_BIG_ENDIAN
)
2012 first
= val2
->v
.val_double
.high
;
2013 second
= val2
->v
.val_double
.low
;
2017 first
= val2
->v
.val_double
.low
;
2018 second
= val2
->v
.val_double
.high
;
2020 dw2_asm_output_data (l
, first
, NULL
);
2021 dw2_asm_output_data (l
, second
, NULL
);
2029 case DW_OP_GNU_regval_type
:
2031 unsigned r
= val1
->v
.val_unsigned
;
2032 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2034 if (for_eh_or_skip
>= 0)
2036 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2037 gcc_assert (size_of_uleb128 (r
)
2038 == size_of_uleb128 (val1
->v
.val_unsigned
));
2040 dw2_asm_output_data_uleb128 (r
, NULL
);
2041 dw2_asm_output_data_uleb128 (o
, NULL
);
2044 case DW_OP_GNU_deref_type
:
2046 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2048 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2049 dw2_asm_output_data_uleb128 (o
, NULL
);
2052 case DW_OP_GNU_convert
:
2053 case DW_OP_GNU_reinterpret
:
2054 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2055 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2058 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2060 dw2_asm_output_data_uleb128 (o
, NULL
);
2064 case DW_OP_GNU_parameter_ref
:
2067 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2068 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2069 dw2_asm_output_data (4, o
, NULL
);
2074 /* Other codes have no operands. */
2079 /* Output a sequence of location operations.
2080 The for_eh_or_skip parameter controls whether register numbers are
2081 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2082 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2083 info). This should be suppressed for the cases that have not been converted
2084 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2087 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2089 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2091 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2092 /* Output the opcode. */
2093 if (for_eh_or_skip
>= 0
2094 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2096 unsigned r
= (opc
- DW_OP_breg0
);
2097 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2098 gcc_assert (r
<= 31);
2099 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2101 else if (for_eh_or_skip
>= 0
2102 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2104 unsigned r
= (opc
- DW_OP_reg0
);
2105 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2106 gcc_assert (r
<= 31);
2107 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2110 dw2_asm_output_data (1, opc
,
2111 "%s", dwarf_stack_op_name (opc
));
2113 /* Output the operand(s) (if any). */
2114 output_loc_operands (loc
, for_eh_or_skip
);
2118 /* Output location description stack opcode's operands (if any).
2119 The output is single bytes on a line, suitable for .cfi_escape. */
2122 output_loc_operands_raw (dw_loc_descr_ref loc
)
2124 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2125 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2127 switch (loc
->dw_loc_opc
)
2130 case DW_OP_GNU_addr_index
:
2131 case DW_OP_GNU_const_index
:
2132 case DW_OP_implicit_value
:
2133 /* We cannot output addresses in .cfi_escape, only bytes. */
2139 case DW_OP_deref_size
:
2140 case DW_OP_xderef_size
:
2141 fputc (',', asm_out_file
);
2142 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2147 fputc (',', asm_out_file
);
2148 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2153 fputc (',', asm_out_file
);
2154 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2159 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2160 fputc (',', asm_out_file
);
2161 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2169 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2170 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2172 fputc (',', asm_out_file
);
2173 dw2_asm_output_data_raw (2, offset
);
2179 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2180 gcc_assert (size_of_uleb128 (r
)
2181 == size_of_uleb128 (val1
->v
.val_unsigned
));
2182 fputc (',', asm_out_file
);
2183 dw2_asm_output_data_uleb128_raw (r
);
2188 case DW_OP_plus_uconst
:
2190 fputc (',', asm_out_file
);
2191 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2194 case DW_OP_bit_piece
:
2195 fputc (',', asm_out_file
);
2196 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2197 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2234 fputc (',', asm_out_file
);
2235 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2240 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2241 gcc_assert (size_of_uleb128 (r
)
2242 == size_of_uleb128 (val1
->v
.val_unsigned
));
2243 fputc (',', asm_out_file
);
2244 dw2_asm_output_data_uleb128_raw (r
);
2245 fputc (',', asm_out_file
);
2246 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2250 case DW_OP_GNU_implicit_pointer
:
2251 case DW_OP_GNU_entry_value
:
2252 case DW_OP_GNU_const_type
:
2253 case DW_OP_GNU_regval_type
:
2254 case DW_OP_GNU_deref_type
:
2255 case DW_OP_GNU_convert
:
2256 case DW_OP_GNU_reinterpret
:
2257 case DW_OP_GNU_parameter_ref
:
2262 /* Other codes have no operands. */
2268 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2272 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2273 /* Output the opcode. */
2274 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2276 unsigned r
= (opc
- DW_OP_breg0
);
2277 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2278 gcc_assert (r
<= 31);
2279 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2281 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2283 unsigned r
= (opc
- DW_OP_reg0
);
2284 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2285 gcc_assert (r
<= 31);
2286 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2288 /* Output the opcode. */
2289 fprintf (asm_out_file
, "%#x", opc
);
2290 output_loc_operands_raw (loc
);
2292 if (!loc
->dw_loc_next
)
2294 loc
= loc
->dw_loc_next
;
2296 fputc (',', asm_out_file
);
2300 /* This function builds a dwarf location descriptor sequence from a
2301 dw_cfa_location, adding the given OFFSET to the result of the
2304 struct dw_loc_descr_struct
*
2305 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2307 struct dw_loc_descr_struct
*head
, *tmp
;
2309 offset
+= cfa
->offset
;
2313 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2314 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2315 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2316 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2317 add_loc_descr (&head
, tmp
);
2320 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2321 add_loc_descr (&head
, tmp
);
2325 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2330 /* This function builds a dwarf location descriptor sequence for
2331 the address at OFFSET from the CFA when stack is aligned to
2334 struct dw_loc_descr_struct
*
2335 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2336 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2338 struct dw_loc_descr_struct
*head
;
2339 unsigned int dwarf_fp
2340 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2342 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2343 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2345 head
= new_reg_loc_descr (dwarf_fp
, 0);
2346 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2347 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2348 loc_descr_plus_const (&head
, offset
);
2351 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2355 /* And now, the support for symbolic debugging information. */
2357 /* .debug_str support. */
2358 static int output_indirect_string (void **, void *);
2360 static void dwarf2out_init (const char *);
2361 static void dwarf2out_finish (const char *);
2362 static void dwarf2out_assembly_start (void);
2363 static void dwarf2out_define (unsigned int, const char *);
2364 static void dwarf2out_undef (unsigned int, const char *);
2365 static void dwarf2out_start_source_file (unsigned, const char *);
2366 static void dwarf2out_end_source_file (unsigned);
2367 static void dwarf2out_function_decl (tree
);
2368 static void dwarf2out_begin_block (unsigned, unsigned);
2369 static void dwarf2out_end_block (unsigned, unsigned);
2370 static bool dwarf2out_ignore_block (const_tree
);
2371 static void dwarf2out_global_decl (tree
);
2372 static void dwarf2out_type_decl (tree
, int);
2373 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2374 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2376 static void dwarf2out_abstract_function (tree
);
2377 static void dwarf2out_var_location (rtx
);
2378 static void dwarf2out_begin_function (tree
);
2379 static void dwarf2out_end_function (unsigned int);
2380 static void dwarf2out_set_name (tree
, tree
);
2382 /* The debug hooks structure. */
2384 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2388 dwarf2out_assembly_start
,
2391 dwarf2out_start_source_file
,
2392 dwarf2out_end_source_file
,
2393 dwarf2out_begin_block
,
2394 dwarf2out_end_block
,
2395 dwarf2out_ignore_block
,
2396 dwarf2out_source_line
,
2397 dwarf2out_begin_prologue
,
2398 #if VMS_DEBUGGING_INFO
2399 dwarf2out_vms_end_prologue
,
2400 dwarf2out_vms_begin_epilogue
,
2402 debug_nothing_int_charstar
,
2403 debug_nothing_int_charstar
,
2405 dwarf2out_end_epilogue
,
2406 dwarf2out_begin_function
,
2407 dwarf2out_end_function
, /* end_function */
2408 dwarf2out_function_decl
, /* function_decl */
2409 dwarf2out_global_decl
,
2410 dwarf2out_type_decl
, /* type_decl */
2411 dwarf2out_imported_module_or_decl
,
2412 debug_nothing_tree
, /* deferred_inline_function */
2413 /* The DWARF 2 backend tries to reduce debugging bloat by not
2414 emitting the abstract description of inline functions until
2415 something tries to reference them. */
2416 dwarf2out_abstract_function
, /* outlining_inline_function */
2417 debug_nothing_rtx
, /* label */
2418 debug_nothing_int
, /* handle_pch */
2419 dwarf2out_var_location
,
2420 dwarf2out_switch_text_section
,
2422 1, /* start_end_main_source_file */
2423 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2426 const struct gcc_debug_hooks auto_profile_debug_hooks
=
2428 debug_nothing_charstar
,
2429 debug_nothing_charstar
,
2431 debug_nothing_int_charstar
,
2432 debug_nothing_int_charstar
,
2433 debug_nothing_int_charstar
,
2435 debug_nothing_int_int
, /* begin_block */
2436 debug_nothing_int_int
, /* end_block */
2437 dwarf2out_ignore_block
, /* ignore_block */
2438 debug_nothing_int_charstar_int_bool
, /* source_line */
2439 debug_nothing_int_charstar
, /* begin_prologue */
2440 debug_nothing_int_charstar
, /* end_prologue */
2441 debug_nothing_int_charstar
, /* begin_epilogue */
2442 debug_nothing_int_charstar
, /* end_epilogue */
2443 debug_nothing_tree
, /* begin_function */
2444 debug_nothing_int
, /* end_function */
2445 debug_nothing_tree
, /* function_decl */
2446 debug_nothing_tree
, /* global_decl */
2447 debug_nothing_tree_int
, /* type_decl */
2448 debug_nothing_tree_tree_tree_bool
, /* imported_module_or_decl */
2449 debug_nothing_tree
, /* deferred_inline_function */
2450 debug_nothing_tree
, /* outlining_inline_function */
2451 debug_nothing_rtx
, /* label */
2452 debug_nothing_int
, /* handle_pch */
2453 debug_nothing_rtx
, /* var_location */
2454 debug_nothing_void
, /* switch_text_section */
2455 debug_nothing_tree_tree
, /* set_name */
2456 0, /* start_end_main_source_file */
2457 TYPE_SYMTAB_IS_ADDRESS
/* tree_type_symtab_field */
2461 /* NOTE: In the comments in this file, many references are made to
2462 "Debugging Information Entries". This term is abbreviated as `DIE'
2463 throughout the remainder of this file. */
2465 /* An internal representation of the DWARF output is built, and then
2466 walked to generate the DWARF debugging info. The walk of the internal
2467 representation is done after the entire program has been compiled.
2468 The types below are used to describe the internal representation. */
2470 /* Whether to put type DIEs into their own section .debug_types instead
2471 of making them part of the .debug_info section. Only supported for
2472 Dwarf V4 or higher and the user didn't disable them through
2473 -fno-debug-types-section. It is more efficient to put them in a
2474 separate comdat sections since the linker will then be able to
2475 remove duplicates. But not all tools support .debug_types sections
2478 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2480 /* Various DIE's use offsets relative to the beginning of the
2481 .debug_info section to refer to each other. */
2483 typedef long int dw_offset
;
2485 /* Define typedefs here to avoid circular dependencies. */
2487 typedef struct dw_attr_struct
*dw_attr_ref
;
2488 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2489 typedef struct pubname_struct
*pubname_ref
;
2490 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2491 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2492 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2494 /* The entries in the line_info table more-or-less mirror the opcodes
2495 that are used in the real dwarf line table. Arrays of these entries
2496 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2499 enum dw_line_info_opcode
{
2500 /* Emit DW_LNE_set_address; the operand is the label index. */
2503 /* Emit a row to the matrix with the given line. This may be done
2504 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2508 /* Emit a DW_LNS_set_file. */
2511 /* Emit a DW_LNS_set_column. */
2514 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2517 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2518 LI_set_prologue_end
,
2519 LI_set_epilogue_begin
,
2521 /* Emit a DW_LNE_set_discriminator. */
2522 LI_set_discriminator
2525 typedef struct GTY(()) dw_line_info_struct
{
2526 enum dw_line_info_opcode opcode
;
2528 } dw_line_info_entry
;
2531 typedef struct GTY(()) dw_line_info_table_struct
{
2532 /* The label that marks the end of this section. */
2533 const char *end_label
;
2535 /* The values for the last row of the matrix, as collected in the table.
2536 These are used to minimize the changes to the next row. */
2537 unsigned int file_num
;
2538 unsigned int line_num
;
2539 unsigned int column_num
;
2544 vec
<dw_line_info_entry
, va_gc
> *entries
;
2545 } dw_line_info_table
;
2547 typedef dw_line_info_table
*dw_line_info_table_p
;
2550 /* Each DIE attribute has a field specifying the attribute kind,
2551 a link to the next attribute in the chain, and an attribute value.
2552 Attributes are typically linked below the DIE they modify. */
2554 typedef struct GTY(()) dw_attr_struct
{
2555 enum dwarf_attribute dw_attr
;
2556 dw_val_node dw_attr_val
;
2561 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2562 The children of each node form a circular list linked by
2563 die_sib. die_child points to the node *before* the "first" child node. */
2565 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2566 union die_symbol_or_type_node
2568 const char * GTY ((tag ("0"))) die_symbol
;
2569 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2571 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2572 vec
<dw_attr_node
, va_gc
> *die_attr
;
2573 dw_die_ref die_parent
;
2574 dw_die_ref die_child
;
2576 dw_die_ref die_definition
; /* ref from a specification to its definition */
2577 dw_offset die_offset
;
2578 unsigned long die_abbrev
;
2580 unsigned int decl_id
;
2581 enum dwarf_tag die_tag
;
2582 /* Die is used and must not be pruned as unused. */
2583 BOOL_BITFIELD die_perennial_p
: 1;
2584 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2585 /* Lots of spare bits. */
2589 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2590 #define FOR_EACH_CHILD(die, c, expr) do { \
2591 c = die->die_child; \
2595 } while (c != die->die_child); \
2598 /* The pubname structure */
2600 typedef struct GTY(()) pubname_struct
{
2607 struct GTY(()) dw_ranges_struct
{
2608 /* If this is positive, it's a block number, otherwise it's a
2609 bitwise-negated index into dw_ranges_by_label. */
2613 /* A structure to hold a macinfo entry. */
2615 typedef struct GTY(()) macinfo_struct
{
2617 unsigned HOST_WIDE_INT lineno
;
2623 struct GTY(()) dw_ranges_by_label_struct
{
2628 /* The comdat type node structure. */
2629 typedef struct GTY(()) comdat_type_struct
2631 dw_die_ref root_die
;
2632 dw_die_ref type_die
;
2633 dw_die_ref skeleton_die
;
2634 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2635 struct comdat_type_struct
*next
;
2639 /* The limbo die list structure. */
2640 typedef struct GTY(()) limbo_die_struct
{
2643 struct limbo_die_struct
*next
;
2647 typedef struct skeleton_chain_struct
2651 struct skeleton_chain_struct
*parent
;
2653 skeleton_chain_node
;
2655 /* Define a macro which returns nonzero for a TYPE_DECL which was
2656 implicitly generated for a type.
2658 Note that, unlike the C front-end (which generates a NULL named
2659 TYPE_DECL node for each complete tagged type, each array type,
2660 and each function type node created) the C++ front-end generates
2661 a _named_ TYPE_DECL node for each tagged type node created.
2662 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2663 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2664 front-end, but for each type, tagged or not. */
2666 #define TYPE_DECL_IS_STUB(decl) \
2667 (DECL_NAME (decl) == NULL_TREE \
2668 || (DECL_ARTIFICIAL (decl) \
2669 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2670 /* This is necessary for stub decls that \
2671 appear in nested inline functions. */ \
2672 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2673 && (decl_ultimate_origin (decl) \
2674 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2676 /* Information concerning the compilation unit's programming
2677 language, and compiler version. */
2679 /* Fixed size portion of the DWARF compilation unit header. */
2680 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2681 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2683 /* Fixed size portion of the DWARF comdat type unit header. */
2684 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2685 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2686 + DWARF_OFFSET_SIZE)
2688 /* Fixed size portion of public names info. */
2689 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2691 /* Fixed size portion of the address range info. */
2692 #define DWARF_ARANGES_HEADER_SIZE \
2693 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2694 DWARF2_ADDR_SIZE * 2) \
2695 - DWARF_INITIAL_LENGTH_SIZE)
2697 /* Size of padding portion in the address range info. It must be
2698 aligned to twice the pointer size. */
2699 #define DWARF_ARANGES_PAD_SIZE \
2700 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2701 DWARF2_ADDR_SIZE * 2) \
2702 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2704 /* Use assembler line directives if available. */
2705 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2706 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2707 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2709 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2713 /* Minimum line offset in a special line info. opcode.
2714 This value was chosen to give a reasonable range of values. */
2715 #define DWARF_LINE_BASE -10
2717 /* First special line opcode - leave room for the standard opcodes. */
2718 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2720 /* Range of line offsets in a special line info. opcode. */
2721 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2723 /* Flag that indicates the initial value of the is_stmt_start flag.
2724 In the present implementation, we do not mark any lines as
2725 the beginning of a source statement, because that information
2726 is not made available by the GCC front-end. */
2727 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2729 /* Maximum number of operations per instruction bundle. */
2730 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2731 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2734 /* This location is used by calc_die_sizes() to keep track
2735 the offset of each DIE within the .debug_info section. */
2736 static unsigned long next_die_offset
;
2738 /* Record the root of the DIE's built for the current compilation unit. */
2739 static GTY(()) dw_die_ref single_comp_unit_die
;
2741 /* A list of type DIEs that have been separated into comdat sections. */
2742 static GTY(()) comdat_type_node
*comdat_type_list
;
2744 /* A list of DIEs with a NULL parent waiting to be relocated. */
2745 static GTY(()) limbo_die_node
*limbo_die_list
;
2747 /* A list of DIEs for which we may have to generate
2748 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2749 static GTY(()) limbo_die_node
*deferred_asm_name
;
2751 /* Filenames referenced by this compilation unit. */
2752 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2754 /* A hash table of references to DIE's that describe declarations.
2755 The key is a DECL_UID() which is a unique number identifying each decl. */
2756 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2758 /* A hash table of references to DIE's that describe COMMON blocks.
2759 The key is DECL_UID() ^ die_parent. */
2760 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2762 typedef struct GTY(()) die_arg_entry_struct
{
2768 /* Node of the variable location list. */
2769 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2770 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2771 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2772 in mode of the EXPR_LIST node and first EXPR_LIST operand
2773 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2774 location or NULL for padding. For larger bitsizes,
2775 mode is 0 and first operand is a CONCAT with bitsize
2776 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2777 NULL as second operand. */
2779 const char * GTY (()) label
;
2780 struct var_loc_node
* GTY (()) next
;
2783 /* Variable location list. */
2784 struct GTY (()) var_loc_list_def
{
2785 struct var_loc_node
* GTY (()) first
;
2787 /* Pointer to the last but one or last element of the
2788 chained list. If the list is empty, both first and
2789 last are NULL, if the list contains just one node
2790 or the last node certainly is not redundant, it points
2791 to the last node, otherwise points to the last but one.
2792 Do not mark it for GC because it is marked through the chain. */
2793 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2795 /* Pointer to the last element before section switch,
2796 if NULL, either sections weren't switched or first
2797 is after section switch. */
2798 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2800 /* DECL_UID of the variable decl. */
2801 unsigned int decl_id
;
2803 typedef struct var_loc_list_def var_loc_list
;
2805 /* Call argument location list. */
2806 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2807 rtx
GTY (()) call_arg_loc_note
;
2808 const char * GTY (()) label
;
2809 tree
GTY (()) block
;
2811 rtx
GTY (()) symbol_ref
;
2812 struct call_arg_loc_node
* GTY (()) next
;
2816 /* Table of decl location linked lists. */
2817 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2819 /* Head and tail of call_arg_loc chain. */
2820 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2821 static struct call_arg_loc_node
*call_arg_loc_last
;
2823 /* Number of call sites in the current function. */
2824 static int call_site_count
= -1;
2825 /* Number of tail call sites in the current function. */
2826 static int tail_call_site_count
= -1;
2828 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2830 static vec
<dw_die_ref
> block_map
;
2832 /* A cached location list. */
2833 struct GTY (()) cached_dw_loc_list_def
{
2834 /* The DECL_UID of the decl that this entry describes. */
2835 unsigned int decl_id
;
2837 /* The cached location list. */
2838 dw_loc_list_ref loc_list
;
2840 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2842 /* Table of cached location lists. */
2843 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2845 /* A pointer to the base of a list of references to DIE's that
2846 are uniquely identified by their tag, presence/absence of
2847 children DIE's, and list of attribute/value pairs. */
2848 static GTY((length ("abbrev_die_table_allocated")))
2849 dw_die_ref
*abbrev_die_table
;
2851 /* Number of elements currently allocated for abbrev_die_table. */
2852 static GTY(()) unsigned abbrev_die_table_allocated
;
2854 /* Number of elements in type_die_table currently in use. */
2855 static GTY(()) unsigned abbrev_die_table_in_use
;
2857 /* Size (in elements) of increments by which we may expand the
2858 abbrev_die_table. */
2859 #define ABBREV_DIE_TABLE_INCREMENT 256
2861 /* A global counter for generating labels for line number data. */
2862 static unsigned int line_info_label_num
;
2864 /* The current table to which we should emit line number information
2865 for the current function. This will be set up at the beginning of
2866 assembly for the function. */
2867 static dw_line_info_table
*cur_line_info_table
;
2869 /* The two default tables of line number info. */
2870 static GTY(()) dw_line_info_table
*text_section_line_info
;
2871 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2873 /* The set of all non-default tables of line number info. */
2874 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2876 /* A flag to tell pubnames/types export if there is an info section to
2878 static bool info_section_emitted
;
2880 /* A pointer to the base of a table that contains a list of publicly
2881 accessible names. */
2882 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2884 /* A pointer to the base of a table that contains a list of publicly
2885 accessible types. */
2886 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2888 /* A pointer to the base of a table that contains a list of macro
2889 defines/undefines (and file start/end markers). */
2890 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2892 /* True if .debug_macinfo or .debug_macros section is going to be
2894 #define have_macinfo \
2895 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2896 && !macinfo_table->is_empty ())
2898 /* Array of dies for which we should generate .debug_ranges info. */
2899 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2901 /* Number of elements currently allocated for ranges_table. */
2902 static GTY(()) unsigned ranges_table_allocated
;
2904 /* Number of elements in ranges_table currently in use. */
2905 static GTY(()) unsigned ranges_table_in_use
;
2907 /* Array of pairs of labels referenced in ranges_table. */
2908 static GTY ((length ("ranges_by_label_allocated")))
2909 dw_ranges_by_label_ref ranges_by_label
;
2911 /* Number of elements currently allocated for ranges_by_label. */
2912 static GTY(()) unsigned ranges_by_label_allocated
;
2914 /* Number of elements in ranges_by_label currently in use. */
2915 static GTY(()) unsigned ranges_by_label_in_use
;
2917 /* Size (in elements) of increments by which we may expand the
2919 #define RANGES_TABLE_INCREMENT 64
2921 /* Whether we have location lists that need outputting */
2922 static GTY(()) bool have_location_lists
;
2924 /* Unique label counter. */
2925 static GTY(()) unsigned int loclabel_num
;
2927 /* Unique label counter for point-of-call tables. */
2928 static GTY(()) unsigned int poc_label_num
;
2930 /* Record whether the function being analyzed contains inlined functions. */
2931 static int current_function_has_inlines
;
2933 /* The last file entry emitted by maybe_emit_file(). */
2934 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2936 /* Number of internal labels generated by gen_internal_sym(). */
2937 static GTY(()) int label_num
;
2939 /* Cached result of previous call to lookup_filename. */
2940 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2942 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2944 /* Instances of generic types for which we need to generate debug
2945 info that describe their generic parameters and arguments. That
2946 generation needs to happen once all types are properly laid out so
2947 we do it at the end of compilation. */
2948 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2950 /* Offset from the "steady-state frame pointer" to the frame base,
2951 within the current function. */
2952 static HOST_WIDE_INT frame_pointer_fb_offset
;
2953 static bool frame_pointer_fb_offset_valid
;
2955 static vec
<dw_die_ref
> base_types
;
2957 /* Forward declarations for functions defined in this file. */
2959 static int is_pseudo_reg (const_rtx
);
2960 static tree
type_main_variant (tree
);
2961 static int is_tagged_type (const_tree
);
2962 static const char *dwarf_tag_name (unsigned);
2963 static const char *dwarf_attr_name (unsigned);
2964 static const char *dwarf_form_name (unsigned);
2965 static tree
decl_ultimate_origin (const_tree
);
2966 static tree
decl_class_context (tree
);
2967 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2968 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2969 static inline unsigned int AT_index (dw_attr_ref
);
2970 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2971 static inline unsigned AT_flag (dw_attr_ref
);
2972 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2973 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2974 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2975 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2976 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2977 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2978 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2979 unsigned int, unsigned char *);
2980 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2981 static hashval_t
debug_str_do_hash (const void *);
2982 static int debug_str_eq (const void *, const void *);
2983 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2984 static inline const char *AT_string (dw_attr_ref
);
2985 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2986 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2987 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2988 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2989 static inline int AT_ref_external (dw_attr_ref
);
2990 static inline void set_AT_ref_external (dw_attr_ref
, int);
2991 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2992 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2993 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2994 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2996 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2997 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2998 static void remove_addr_table_entry (addr_table_entry
*);
2999 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3000 static inline rtx
AT_addr (dw_attr_ref
);
3001 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3002 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3003 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3004 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3005 unsigned HOST_WIDE_INT
);
3006 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3007 unsigned long, bool);
3008 static inline const char *AT_lbl (dw_attr_ref
);
3009 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3010 static const char *get_AT_low_pc (dw_die_ref
);
3011 static const char *get_AT_hi_pc (dw_die_ref
);
3012 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3013 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3014 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3015 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3016 static bool is_cxx (void);
3017 static bool is_fortran (void);
3018 static bool is_ada (void);
3019 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3020 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3021 static void add_child_die (dw_die_ref
, dw_die_ref
);
3022 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3023 static dw_die_ref
lookup_type_die (tree
);
3024 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3025 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3026 static void equate_type_number_to_die (tree
, dw_die_ref
);
3027 static hashval_t
decl_die_table_hash (const void *);
3028 static int decl_die_table_eq (const void *, const void *);
3029 static dw_die_ref
lookup_decl_die (tree
);
3030 static hashval_t
common_block_die_table_hash (const void *);
3031 static int common_block_die_table_eq (const void *, const void *);
3032 static hashval_t
decl_loc_table_hash (const void *);
3033 static int decl_loc_table_eq (const void *, const void *);
3034 static var_loc_list
*lookup_decl_loc (const_tree
);
3035 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3036 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3037 static void print_spaces (FILE *);
3038 static void print_die (dw_die_ref
, FILE *);
3039 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3040 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3041 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3042 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3043 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3044 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3045 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3046 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3047 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3048 struct md5_ctx
*, int *);
3049 struct checksum_attributes
;
3050 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3051 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3052 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3053 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3054 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3055 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3056 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3057 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3058 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3059 static void compute_section_prefix (dw_die_ref
);
3060 static int is_type_die (dw_die_ref
);
3061 static int is_comdat_die (dw_die_ref
);
3062 static int is_symbol_die (dw_die_ref
);
3063 static inline bool is_template_instantiation (dw_die_ref
);
3064 static void assign_symbol_names (dw_die_ref
);
3065 static void break_out_includes (dw_die_ref
);
3066 static int is_declaration_die (dw_die_ref
);
3067 static int should_move_die_to_comdat (dw_die_ref
);
3068 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3069 static dw_die_ref
clone_die (dw_die_ref
);
3070 static dw_die_ref
clone_tree (dw_die_ref
);
3071 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3072 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3073 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3074 static dw_die_ref
generate_skeleton (dw_die_ref
);
3075 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3078 static void break_out_comdat_types (dw_die_ref
);
3079 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
3080 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
3081 static void copy_decls_for_unworthy_types (dw_die_ref
);
3083 static hashval_t
htab_cu_hash (const void *);
3084 static int htab_cu_eq (const void *, const void *);
3085 static void htab_cu_del (void *);
3086 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
3087 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
3088 static void add_sibling_attributes (dw_die_ref
);
3089 static void build_abbrev_table (dw_die_ref
, htab_t
);
3090 static void output_location_lists (dw_die_ref
);
3091 static int constant_size (unsigned HOST_WIDE_INT
);
3092 static unsigned long size_of_die (dw_die_ref
);
3093 static void calc_die_sizes (dw_die_ref
);
3094 static void calc_base_type_die_sizes (void);
3095 static void mark_dies (dw_die_ref
);
3096 static void unmark_dies (dw_die_ref
);
3097 static void unmark_all_dies (dw_die_ref
);
3098 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3099 static unsigned long size_of_aranges (void);
3100 static enum dwarf_form
value_format (dw_attr_ref
);
3101 static void output_value_format (dw_attr_ref
);
3102 static void output_abbrev_section (void);
3103 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3104 static void output_die_symbol (dw_die_ref
);
3105 static void output_die (dw_die_ref
);
3106 static void output_compilation_unit_header (void);
3107 static void output_comp_unit (dw_die_ref
, int);
3108 static void output_comdat_type_unit (comdat_type_node
*);
3109 static const char *dwarf2_name (tree
, int);
3110 static void add_pubname (tree
, dw_die_ref
);
3111 static void add_enumerator_pubname (const char *, dw_die_ref
);
3112 static void add_pubname_string (const char *, dw_die_ref
);
3113 static void add_pubtype (tree
, dw_die_ref
);
3114 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3115 static void output_aranges (unsigned long);
3116 static unsigned int add_ranges_num (int);
3117 static unsigned int add_ranges (const_tree
);
3118 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3120 static void output_ranges (void);
3121 static dw_line_info_table
*new_line_info_table (void);
3122 static void output_line_info (bool);
3123 static void output_file_names (void);
3124 static dw_die_ref
base_type_die (tree
);
3125 static int is_base_type (tree
);
3126 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3127 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3128 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3129 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3130 static int type_is_enum (const_tree
);
3131 static unsigned int dbx_reg_number (const_rtx
);
3132 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3133 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3134 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3135 enum var_init_status
);
3136 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3137 enum var_init_status
);
3138 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3139 enum var_init_status
);
3140 static int is_based_loc (const_rtx
);
3141 static int resolve_one_addr (rtx
*, void *);
3142 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3143 enum var_init_status
);
3144 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3145 enum var_init_status
);
3146 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3147 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3148 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3149 static tree
field_type (const_tree
);
3150 static unsigned int simple_type_align_in_bits (const_tree
);
3151 static unsigned int simple_decl_align_in_bits (const_tree
);
3152 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3153 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3154 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3156 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3157 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3158 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3159 static void insert_double (double_int
, unsigned char *);
3160 static void insert_float (const_rtx
, unsigned char *);
3161 static rtx
rtl_for_decl_location (tree
);
3162 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3163 enum dwarf_attribute
);
3164 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3165 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3166 static void add_name_attribute (dw_die_ref
, const char *);
3167 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3168 static void add_comp_dir_attribute (dw_die_ref
);
3169 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3170 static void add_subscript_info (dw_die_ref
, tree
, bool);
3171 static void add_byte_size_attribute (dw_die_ref
, tree
);
3172 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3173 static void add_bit_size_attribute (dw_die_ref
, tree
);
3174 static void add_prototyped_attribute (dw_die_ref
, tree
);
3175 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3176 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3177 static void add_src_coords_attributes (dw_die_ref
, tree
);
3178 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3179 static void push_decl_scope (tree
);
3180 static void pop_decl_scope (void);
3181 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3182 static inline int local_scope_p (dw_die_ref
);
3183 static inline int class_scope_p (dw_die_ref
);
3184 static inline int class_or_namespace_scope_p (dw_die_ref
);
3185 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3186 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3187 static const char *type_tag (const_tree
);
3188 static tree
member_declared_type (const_tree
);
3190 static const char *decl_start_label (tree
);
3192 static void gen_array_type_die (tree
, dw_die_ref
);
3193 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3195 static void gen_entry_point_die (tree
, dw_die_ref
);
3197 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3198 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3199 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3200 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3201 static void gen_formal_types_die (tree
, dw_die_ref
);
3202 static void gen_subprogram_die (tree
, dw_die_ref
);
3203 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3204 static void gen_const_die (tree
, dw_die_ref
);
3205 static void gen_label_die (tree
, dw_die_ref
);
3206 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3207 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3208 static void gen_field_die (tree
, dw_die_ref
);
3209 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3210 static dw_die_ref
gen_compile_unit_die (const char *);
3211 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3212 static void gen_member_die (tree
, dw_die_ref
);
3213 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3214 enum debug_info_usage
);
3215 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3216 static void gen_typedef_die (tree
, dw_die_ref
);
3217 static void gen_type_die (tree
, dw_die_ref
);
3218 static void gen_block_die (tree
, dw_die_ref
, int);
3219 static void decls_for_scope (tree
, dw_die_ref
, int);
3220 static inline int is_redundant_typedef (const_tree
);
3221 static bool is_naming_typedef_decl (const_tree
);
3222 static inline dw_die_ref
get_context_die (tree
);
3223 static void gen_namespace_die (tree
, dw_die_ref
);
3224 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3225 static dw_die_ref
force_decl_die (tree
);
3226 static dw_die_ref
force_type_die (tree
);
3227 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3228 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3229 static struct dwarf_file_data
* lookup_filename (const char *);
3230 static void retry_incomplete_types (void);
3231 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3232 static void gen_generic_params_dies (tree
);
3233 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3234 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3235 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3236 static int file_info_cmp (const void *, const void *);
3237 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3238 const char *, const char *);
3239 static void output_loc_list (dw_loc_list_ref
);
3240 static char *gen_internal_sym (const char *);
3241 static bool want_pubnames (void);
3243 static void prune_unmark_dies (dw_die_ref
);
3244 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3245 static void prune_unused_types_mark (dw_die_ref
, int);
3246 static void prune_unused_types_walk (dw_die_ref
);
3247 static void prune_unused_types_walk_attribs (dw_die_ref
);
3248 static void prune_unused_types_prune (dw_die_ref
);
3249 static void prune_unused_types (void);
3250 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3251 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3252 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3253 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3254 const char *, const char *);
3255 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3256 static void gen_remaining_tmpl_value_param_die_attribute (void);
3257 static bool generic_type_p (tree
);
3258 static void schedule_generic_params_dies_gen (tree t
);
3259 static void gen_scheduled_generic_parms_dies (void);
3261 static const char *comp_dir_string (void);
3263 static hashval_t
hash_loc_operands (dw_loc_descr_ref
, hashval_t
);
3265 /* enum for tracking thread-local variables whose address is really an offset
3266 relative to the TLS pointer, which will need link-time relocation, but will
3267 not need relocation by the DWARF consumer. */
3275 /* Return the operator to use for an address of a variable. For dtprel_true, we
3276 use DW_OP_const*. For regular variables, which need both link-time
3277 relocation and consumer-level relocation (e.g., to account for shared objects
3278 loaded at a random address), we use DW_OP_addr*. */
3280 static inline enum dwarf_location_atom
3281 dw_addr_op (enum dtprel_bool dtprel
)
3283 if (dtprel
== dtprel_true
)
3284 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3285 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3287 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3290 /* Return a pointer to a newly allocated address location description. If
3291 dwarf_split_debug_info is true, then record the address with the appropriate
3293 static inline dw_loc_descr_ref
3294 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3296 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3298 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3299 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3300 ref
->dtprel
= dtprel
;
3301 if (dwarf_split_debug_info
)
3302 ref
->dw_loc_oprnd1
.val_entry
3303 = add_addr_table_entry (addr
,
3304 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3306 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3311 /* Section names used to hold DWARF debugging information. */
3313 #ifndef DEBUG_INFO_SECTION
3314 #define DEBUG_INFO_SECTION ".debug_info"
3316 #ifndef DEBUG_DWO_INFO_SECTION
3317 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3319 #ifndef DEBUG_ABBREV_SECTION
3320 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3322 #ifndef DEBUG_DWO_ABBREV_SECTION
3323 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3325 #ifndef DEBUG_ARANGES_SECTION
3326 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3328 #ifndef DEBUG_ADDR_SECTION
3329 #define DEBUG_ADDR_SECTION ".debug_addr"
3331 #ifndef DEBUG_NORM_MACINFO_SECTION
3332 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3334 #ifndef DEBUG_DWO_MACINFO_SECTION
3335 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3337 #ifndef DEBUG_MACINFO_SECTION
3338 #define DEBUG_MACINFO_SECTION \
3339 (!dwarf_split_debug_info \
3340 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3342 #ifndef DEBUG_NORM_MACRO_SECTION
3343 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3345 #ifndef DEBUG_DWO_MACRO_SECTION
3346 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3348 #ifndef DEBUG_MACRO_SECTION
3349 #define DEBUG_MACRO_SECTION \
3350 (!dwarf_split_debug_info \
3351 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3353 #ifndef DEBUG_LINE_SECTION
3354 #define DEBUG_LINE_SECTION ".debug_line"
3356 #ifndef DEBUG_DWO_LINE_SECTION
3357 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3359 #ifndef DEBUG_LOC_SECTION
3360 #define DEBUG_LOC_SECTION ".debug_loc"
3362 #ifndef DEBUG_DWO_LOC_SECTION
3363 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3365 #ifndef DEBUG_PUBNAMES_SECTION
3366 #define DEBUG_PUBNAMES_SECTION \
3367 ((debug_generate_pub_sections == 2) \
3368 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3370 #ifndef DEBUG_PUBTYPES_SECTION
3371 #define DEBUG_PUBTYPES_SECTION \
3372 ((debug_generate_pub_sections == 2) \
3373 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3375 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3376 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3377 #ifndef DEBUG_STR_OFFSETS_SECTION
3378 #define DEBUG_STR_OFFSETS_SECTION \
3379 (!dwarf_split_debug_info \
3380 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3382 #ifndef DEBUG_STR_DWO_SECTION
3383 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3385 #ifndef DEBUG_STR_SECTION
3386 #define DEBUG_STR_SECTION ".debug_str"
3388 #ifndef DEBUG_RANGES_SECTION
3389 #define DEBUG_RANGES_SECTION ".debug_ranges"
3392 /* Standard ELF section names for compiled code and data. */
3393 #ifndef TEXT_SECTION_NAME
3394 #define TEXT_SECTION_NAME ".text"
3397 /* Section flags for .debug_macinfo/.debug_macro section. */
3398 #define DEBUG_MACRO_SECTION_FLAGS \
3399 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3401 /* Section flags for .debug_str section. */
3402 #define DEBUG_STR_SECTION_FLAGS \
3403 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3404 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3407 /* Section flags for .debug_str.dwo section. */
3408 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3410 /* Labels we insert at beginning sections we can reference instead of
3411 the section names themselves. */
3413 #ifndef TEXT_SECTION_LABEL
3414 #define TEXT_SECTION_LABEL "Ltext"
3416 #ifndef COLD_TEXT_SECTION_LABEL
3417 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3419 #ifndef DEBUG_LINE_SECTION_LABEL
3420 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3422 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3423 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3425 #ifndef DEBUG_INFO_SECTION_LABEL
3426 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3428 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3429 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3431 #ifndef DEBUG_ABBREV_SECTION_LABEL
3432 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3434 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3435 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3437 #ifndef DEBUG_ADDR_SECTION_LABEL
3438 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3440 #ifndef DEBUG_LOC_SECTION_LABEL
3441 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3443 #ifndef DEBUG_RANGES_SECTION_LABEL
3444 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3446 #ifndef DEBUG_MACINFO_SECTION_LABEL
3447 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3449 #ifndef DEBUG_MACRO_SECTION_LABEL
3450 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3452 #define SKELETON_COMP_DIE_ABBREV 1
3453 #define SKELETON_TYPE_DIE_ABBREV 2
3455 /* Definitions of defaults for formats and names of various special
3456 (artificial) labels which may be generated within this file (when the -g
3457 options is used and DWARF2_DEBUGGING_INFO is in effect.
3458 If necessary, these may be overridden from within the tm.h file, but
3459 typically, overriding these defaults is unnecessary. */
3461 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3462 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3463 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3464 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3465 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3466 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3467 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3468 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3469 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3470 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3471 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3472 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3473 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3474 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3476 #ifndef TEXT_END_LABEL
3477 #define TEXT_END_LABEL "Letext"
3479 #ifndef COLD_END_LABEL
3480 #define COLD_END_LABEL "Letext_cold"
3482 #ifndef BLOCK_BEGIN_LABEL
3483 #define BLOCK_BEGIN_LABEL "LBB"
3485 #ifndef BLOCK_END_LABEL
3486 #define BLOCK_END_LABEL "LBE"
3488 #ifndef LINE_CODE_LABEL
3489 #define LINE_CODE_LABEL "LM"
3493 /* Return the root of the DIE's built for the current compilation unit. */
3495 comp_unit_die (void)
3497 if (!single_comp_unit_die
)
3498 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3499 return single_comp_unit_die
;
3502 /* We allow a language front-end to designate a function that is to be
3503 called to "demangle" any name before it is put into a DIE. */
3505 static const char *(*demangle_name_func
) (const char *);
3508 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3510 demangle_name_func
= func
;
3513 /* Test if rtl node points to a pseudo register. */
3516 is_pseudo_reg (const_rtx rtl
)
3518 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3519 || (GET_CODE (rtl
) == SUBREG
3520 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3523 /* Return a reference to a type, with its const and volatile qualifiers
3527 type_main_variant (tree type
)
3529 type
= TYPE_MAIN_VARIANT (type
);
3531 /* ??? There really should be only one main variant among any group of
3532 variants of a given type (and all of the MAIN_VARIANT values for all
3533 members of the group should point to that one type) but sometimes the C
3534 front-end messes this up for array types, so we work around that bug
3536 if (TREE_CODE (type
) == ARRAY_TYPE
)
3537 while (type
!= TYPE_MAIN_VARIANT (type
))
3538 type
= TYPE_MAIN_VARIANT (type
);
3543 /* Return nonzero if the given type node represents a tagged type. */
3546 is_tagged_type (const_tree type
)
3548 enum tree_code code
= TREE_CODE (type
);
3550 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3551 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3554 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3557 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3559 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3562 /* Return die_offset of a DIE reference to a base type. */
3564 static unsigned long int
3565 get_base_type_offset (dw_die_ref ref
)
3567 if (ref
->die_offset
)
3568 return ref
->die_offset
;
3569 if (comp_unit_die ()->die_abbrev
)
3571 calc_base_type_die_sizes ();
3572 gcc_assert (ref
->die_offset
);
3574 return ref
->die_offset
;
3577 /* Return die_offset of a DIE reference other than base type. */
3579 static unsigned long int
3580 get_ref_die_offset (dw_die_ref ref
)
3582 gcc_assert (ref
->die_offset
);
3583 return ref
->die_offset
;
3586 /* Convert a DIE tag into its string name. */
3589 dwarf_tag_name (unsigned int tag
)
3591 const char *name
= get_DW_TAG_name (tag
);
3596 return "DW_TAG_<unknown>";
3599 /* Convert a DWARF attribute code into its string name. */
3602 dwarf_attr_name (unsigned int attr
)
3608 #if VMS_DEBUGGING_INFO
3609 case DW_AT_HP_prologue
:
3610 return "DW_AT_HP_prologue";
3612 case DW_AT_MIPS_loop_unroll_factor
:
3613 return "DW_AT_MIPS_loop_unroll_factor";
3616 #if VMS_DEBUGGING_INFO
3617 case DW_AT_HP_epilogue
:
3618 return "DW_AT_HP_epilogue";
3620 case DW_AT_MIPS_stride
:
3621 return "DW_AT_MIPS_stride";
3625 name
= get_DW_AT_name (attr
);
3630 return "DW_AT_<unknown>";
3633 /* Convert a DWARF value form code into its string name. */
3636 dwarf_form_name (unsigned int form
)
3638 const char *name
= get_DW_FORM_name (form
);
3643 return "DW_FORM_<unknown>";
3646 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3647 instance of an inlined instance of a decl which is local to an inline
3648 function, so we have to trace all of the way back through the origin chain
3649 to find out what sort of node actually served as the original seed for the
3653 decl_ultimate_origin (const_tree decl
)
3655 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3658 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3659 nodes in the function to point to themselves; ignore that if
3660 we're trying to output the abstract instance of this function. */
3661 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3664 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3665 most distant ancestor, this should never happen. */
3666 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3668 return DECL_ABSTRACT_ORIGIN (decl
);
3671 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3672 of a virtual function may refer to a base class, so we check the 'this'
3676 decl_class_context (tree decl
)
3678 tree context
= NULL_TREE
;
3680 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3681 context
= DECL_CONTEXT (decl
);
3683 context
= TYPE_MAIN_VARIANT
3684 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3686 if (context
&& !TYPE_P (context
))
3687 context
= NULL_TREE
;
3692 /* Add an attribute/value pair to a DIE. */
3695 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3697 /* Maybe this should be an assert? */
3701 vec_safe_reserve (die
->die_attr
, 1);
3702 vec_safe_push (die
->die_attr
, *attr
);
3705 static inline enum dw_val_class
3706 AT_class (dw_attr_ref a
)
3708 return a
->dw_attr_val
.val_class
;
3711 /* Return the index for any attribute that will be referenced with a
3712 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3713 are stored in dw_attr_val.v.val_str for reference counting
3716 static inline unsigned int
3717 AT_index (dw_attr_ref a
)
3719 if (AT_class (a
) == dw_val_class_str
)
3720 return a
->dw_attr_val
.v
.val_str
->index
;
3721 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3722 return a
->dw_attr_val
.val_entry
->index
;
3726 /* Add a flag value attribute to a DIE. */
3729 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3733 attr
.dw_attr
= attr_kind
;
3734 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3735 attr
.dw_attr_val
.val_entry
= NULL
;
3736 attr
.dw_attr_val
.v
.val_flag
= flag
;
3737 add_dwarf_attr (die
, &attr
);
3740 static inline unsigned
3741 AT_flag (dw_attr_ref a
)
3743 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3744 return a
->dw_attr_val
.v
.val_flag
;
3747 /* Add a signed integer attribute value to a DIE. */
3750 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3754 attr
.dw_attr
= attr_kind
;
3755 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3756 attr
.dw_attr_val
.val_entry
= NULL
;
3757 attr
.dw_attr_val
.v
.val_int
= int_val
;
3758 add_dwarf_attr (die
, &attr
);
3761 static inline HOST_WIDE_INT
3762 AT_int (dw_attr_ref a
)
3764 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3765 return a
->dw_attr_val
.v
.val_int
;
3768 /* Add an unsigned integer attribute value to a DIE. */
3771 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3772 unsigned HOST_WIDE_INT unsigned_val
)
3776 attr
.dw_attr
= attr_kind
;
3777 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3778 attr
.dw_attr_val
.val_entry
= NULL
;
3779 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3780 add_dwarf_attr (die
, &attr
);
3783 static inline unsigned HOST_WIDE_INT
3784 AT_unsigned (dw_attr_ref a
)
3786 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3787 return a
->dw_attr_val
.v
.val_unsigned
;
3790 /* Add an unsigned double integer attribute value to a DIE. */
3793 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3794 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3798 attr
.dw_attr
= attr_kind
;
3799 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3800 attr
.dw_attr_val
.val_entry
= NULL
;
3801 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3802 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3803 add_dwarf_attr (die
, &attr
);
3806 /* Add a floating point attribute value to a DIE and return it. */
3809 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3810 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3814 attr
.dw_attr
= attr_kind
;
3815 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3816 attr
.dw_attr_val
.val_entry
= NULL
;
3817 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3818 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3819 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3820 add_dwarf_attr (die
, &attr
);
3823 /* Add an 8-byte data attribute value to a DIE. */
3826 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3827 unsigned char data8
[8])
3831 attr
.dw_attr
= attr_kind
;
3832 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3833 attr
.dw_attr_val
.val_entry
= NULL
;
3834 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3835 add_dwarf_attr (die
, &attr
);
3838 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3839 dwarf_split_debug_info, address attributes in dies destined for the
3840 final executable have force_direct set to avoid using indexed
3844 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3850 lbl_id
= xstrdup (lbl_low
);
3851 attr
.dw_attr
= DW_AT_low_pc
;
3852 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3853 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3854 if (dwarf_split_debug_info
&& !force_direct
)
3855 attr
.dw_attr_val
.val_entry
3856 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3858 attr
.dw_attr_val
.val_entry
= NULL
;
3859 add_dwarf_attr (die
, &attr
);
3861 attr
.dw_attr
= DW_AT_high_pc
;
3862 if (dwarf_version
< 4)
3863 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3865 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3866 lbl_id
= xstrdup (lbl_high
);
3867 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3868 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3869 && dwarf_split_debug_info
&& !force_direct
)
3870 attr
.dw_attr_val
.val_entry
3871 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3873 attr
.dw_attr_val
.val_entry
= NULL
;
3874 add_dwarf_attr (die
, &attr
);
3877 /* Hash and equality functions for debug_str_hash. */
3880 debug_str_do_hash (const void *x
)
3882 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3886 debug_str_eq (const void *x1
, const void *x2
)
3888 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3889 (const char *)x2
) == 0;
3892 /* Add STR to the given string hash table. */
3894 static struct indirect_string_node
*
3895 find_AT_string_in_table (const char *str
, htab_t table
)
3897 struct indirect_string_node
*node
;
3900 slot
= htab_find_slot_with_hash (table
, str
,
3901 htab_hash_string (str
), INSERT
);
3904 node
= ggc_alloc_cleared_indirect_string_node ();
3905 node
->str
= ggc_strdup (str
);
3909 node
= (struct indirect_string_node
*) *slot
;
3915 /* Add STR to the indirect string hash table. */
3917 static struct indirect_string_node
*
3918 find_AT_string (const char *str
)
3920 if (! debug_str_hash
)
3921 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3922 debug_str_eq
, NULL
);
3924 return find_AT_string_in_table (str
, debug_str_hash
);
3927 /* Add a string attribute value to a DIE. */
3930 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3933 struct indirect_string_node
*node
;
3935 node
= find_AT_string (str
);
3937 attr
.dw_attr
= attr_kind
;
3938 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3939 attr
.dw_attr_val
.val_entry
= NULL
;
3940 attr
.dw_attr_val
.v
.val_str
= node
;
3941 add_dwarf_attr (die
, &attr
);
3944 static inline const char *
3945 AT_string (dw_attr_ref a
)
3947 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3948 return a
->dw_attr_val
.v
.val_str
->str
;
3951 /* Call this function directly to bypass AT_string_form's logic to put
3952 the string inline in the die. */
3955 set_indirect_string (struct indirect_string_node
*node
)
3958 /* Already indirect is a no op. */
3959 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3961 gcc_assert (node
->label
);
3964 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3965 ++dw2_string_counter
;
3966 node
->label
= xstrdup (label
);
3968 if (!dwarf_split_debug_info
)
3970 node
->form
= DW_FORM_strp
;
3971 node
->index
= NOT_INDEXED
;
3975 node
->form
= DW_FORM_GNU_str_index
;
3976 node
->index
= NO_INDEX_ASSIGNED
;
3980 /* Find out whether a string should be output inline in DIE
3981 or out-of-line in .debug_str section. */
3983 static enum dwarf_form
3984 find_string_form (struct indirect_string_node
*node
)
3991 len
= strlen (node
->str
) + 1;
3993 /* If the string is shorter or equal to the size of the reference, it is
3994 always better to put it inline. */
3995 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3996 return node
->form
= DW_FORM_string
;
3998 /* If we cannot expect the linker to merge strings in .debug_str
3999 section, only put it into .debug_str if it is worth even in this
4001 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4002 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4003 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4004 return node
->form
= DW_FORM_string
;
4006 set_indirect_string (node
);
4011 /* Find out whether the string referenced from the attribute should be
4012 output inline in DIE or out-of-line in .debug_str section. */
4014 static enum dwarf_form
4015 AT_string_form (dw_attr_ref a
)
4017 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4018 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4021 /* Add a DIE reference attribute value to a DIE. */
4024 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4028 #ifdef ENABLE_CHECKING
4029 gcc_assert (targ_die
!= NULL
);
4031 /* With LTO we can end up trying to reference something we didn't create
4032 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4033 if (targ_die
== NULL
)
4037 attr
.dw_attr
= attr_kind
;
4038 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4039 attr
.dw_attr_val
.val_entry
= NULL
;
4040 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4041 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4042 add_dwarf_attr (die
, &attr
);
4045 /* Change DIE reference REF to point to NEW_DIE instead. */
4048 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4050 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4051 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4052 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4055 /* Add an AT_specification attribute to a DIE, and also make the back
4056 pointer from the specification to the definition. */
4059 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4061 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4062 gcc_assert (!targ_die
->die_definition
);
4063 targ_die
->die_definition
= die
;
4066 static inline dw_die_ref
4067 AT_ref (dw_attr_ref a
)
4069 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4070 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4074 AT_ref_external (dw_attr_ref a
)
4076 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4077 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4083 set_AT_ref_external (dw_attr_ref a
, int i
)
4085 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4086 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4089 /* Add an FDE reference attribute value to a DIE. */
4092 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4096 attr
.dw_attr
= attr_kind
;
4097 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4098 attr
.dw_attr_val
.val_entry
= NULL
;
4099 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4100 add_dwarf_attr (die
, &attr
);
4103 /* Add a location description attribute value to a DIE. */
4106 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4110 attr
.dw_attr
= attr_kind
;
4111 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4112 attr
.dw_attr_val
.val_entry
= NULL
;
4113 attr
.dw_attr_val
.v
.val_loc
= loc
;
4114 add_dwarf_attr (die
, &attr
);
4117 static inline dw_loc_descr_ref
4118 AT_loc (dw_attr_ref a
)
4120 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4121 return a
->dw_attr_val
.v
.val_loc
;
4125 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4129 attr
.dw_attr
= attr_kind
;
4130 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4131 attr
.dw_attr_val
.val_entry
= NULL
;
4132 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4133 add_dwarf_attr (die
, &attr
);
4134 have_location_lists
= true;
4137 static inline dw_loc_list_ref
4138 AT_loc_list (dw_attr_ref a
)
4140 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4141 return a
->dw_attr_val
.v
.val_loc_list
;
4144 static inline dw_loc_list_ref
*
4145 AT_loc_list_ptr (dw_attr_ref a
)
4147 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4148 return &a
->dw_attr_val
.v
.val_loc_list
;
4151 /* Table of entries into the .debug_addr section. */
4153 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4155 /* Hash an address_table_entry. */
4158 addr_table_entry_do_hash (const void *x
)
4160 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4164 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4165 case ate_kind_rtx_dtprel
:
4166 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4167 case ate_kind_label
:
4168 return htab_hash_string (a
->addr
.label
);
4174 /* Determine equality for two address_table_entries. */
4177 addr_table_entry_eq (const void *x1
, const void *x2
)
4179 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4180 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4182 if (a1
->kind
!= a2
->kind
)
4187 case ate_kind_rtx_dtprel
:
4188 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4189 case ate_kind_label
:
4190 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4196 /* Initialize an addr_table_entry. */
4199 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4205 case ate_kind_rtx_dtprel
:
4206 e
->addr
.rtl
= (rtx
) addr
;
4208 case ate_kind_label
:
4209 e
->addr
.label
= (char *) addr
;
4213 e
->index
= NO_INDEX_ASSIGNED
;
4216 /* Add attr to the address table entry to the table. Defer setting an
4217 index until output time. */
4219 static addr_table_entry
*
4220 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4222 addr_table_entry
*node
;
4223 addr_table_entry finder
;
4226 gcc_assert (dwarf_split_debug_info
);
4227 if (! addr_index_table
)
4228 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4229 addr_table_entry_eq
, NULL
);
4230 init_addr_table_entry (&finder
, kind
, addr
);
4231 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4233 if (*slot
== HTAB_EMPTY_ENTRY
)
4235 node
= ggc_alloc_cleared_addr_table_entry ();
4236 init_addr_table_entry (node
, kind
, addr
);
4240 node
= (addr_table_entry
*) *slot
;
4246 /* Remove an entry from the addr table by decrementing its refcount.
4247 Strictly, decrementing the refcount would be enough, but the
4248 assertion that the entry is actually in the table has found
4252 remove_addr_table_entry (addr_table_entry
*entry
)
4254 addr_table_entry
*node
;
4256 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4257 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4258 /* After an index is assigned, the table is frozen. */
4259 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4263 /* Given a location list, remove all addresses it refers to from the
4267 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4269 for (; descr
; descr
= descr
->dw_loc_next
)
4270 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4272 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4273 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4277 /* A helper function for dwarf2out_finish called through
4278 htab_traverse. Assign an addr_table_entry its index. All entries
4279 must be collected into the table when this function is called,
4280 because the indexing code relies on htab_traverse to traverse nodes
4281 in the same order for each run. */
4284 index_addr_table_entry (void **h
, void *v
)
4286 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4287 unsigned int *index
= (unsigned int *) v
;
4289 /* Don't index unreferenced nodes. */
4290 if (node
->refcount
== 0)
4293 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
4294 node
->index
= *index
;
4300 /* Add an address constant attribute value to a DIE. When using
4301 dwarf_split_debug_info, address attributes in dies destined for the
4302 final executable should be direct references--setting the parameter
4303 force_direct ensures this behavior. */
4306 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4311 attr
.dw_attr
= attr_kind
;
4312 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4313 attr
.dw_attr_val
.v
.val_addr
= addr
;
4314 if (dwarf_split_debug_info
&& !force_direct
)
4315 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4317 attr
.dw_attr_val
.val_entry
= NULL
;
4318 add_dwarf_attr (die
, &attr
);
4321 /* Get the RTX from to an address DIE attribute. */
4324 AT_addr (dw_attr_ref a
)
4326 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4327 return a
->dw_attr_val
.v
.val_addr
;
4330 /* Add a file attribute value to a DIE. */
4333 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4334 struct dwarf_file_data
*fd
)
4338 attr
.dw_attr
= attr_kind
;
4339 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4340 attr
.dw_attr_val
.val_entry
= NULL
;
4341 attr
.dw_attr_val
.v
.val_file
= fd
;
4342 add_dwarf_attr (die
, &attr
);
4345 /* Get the dwarf_file_data from a file DIE attribute. */
4347 static inline struct dwarf_file_data
*
4348 AT_file (dw_attr_ref a
)
4350 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4351 return a
->dw_attr_val
.v
.val_file
;
4354 /* Add a vms delta attribute value to a DIE. */
4357 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4358 const char *lbl1
, const char *lbl2
)
4362 attr
.dw_attr
= attr_kind
;
4363 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4364 attr
.dw_attr_val
.val_entry
= NULL
;
4365 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4366 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4367 add_dwarf_attr (die
, &attr
);
4370 /* Add a label identifier attribute value to a DIE. */
4373 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4378 attr
.dw_attr
= attr_kind
;
4379 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4380 attr
.dw_attr_val
.val_entry
= NULL
;
4381 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4382 if (dwarf_split_debug_info
)
4383 attr
.dw_attr_val
.val_entry
4384 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4386 add_dwarf_attr (die
, &attr
);
4389 /* Add a section offset attribute value to a DIE, an offset into the
4390 debug_line section. */
4393 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4398 attr
.dw_attr
= attr_kind
;
4399 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4400 attr
.dw_attr_val
.val_entry
= NULL
;
4401 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4402 add_dwarf_attr (die
, &attr
);
4405 /* Add a section offset attribute value to a DIE, an offset into the
4406 debug_macinfo section. */
4409 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4414 attr
.dw_attr
= attr_kind
;
4415 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4416 attr
.dw_attr_val
.val_entry
= NULL
;
4417 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4418 add_dwarf_attr (die
, &attr
);
4421 /* Add an offset attribute value to a DIE. */
4424 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4425 unsigned HOST_WIDE_INT offset
)
4429 attr
.dw_attr
= attr_kind
;
4430 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4431 attr
.dw_attr_val
.val_entry
= NULL
;
4432 attr
.dw_attr_val
.v
.val_offset
= offset
;
4433 add_dwarf_attr (die
, &attr
);
4436 /* Add a range_list attribute value to a DIE. When using
4437 dwarf_split_debug_info, address attributes in dies destined for the
4438 final executable should be direct references--setting the parameter
4439 force_direct ensures this behavior. */
4441 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4442 #define RELOCATED_OFFSET (NULL)
4445 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4446 long unsigned int offset
, bool force_direct
)
4450 attr
.dw_attr
= attr_kind
;
4451 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4452 /* For the range_list attribute, use val_entry to store whether the
4453 offset should follow split-debug-info or normal semantics. This
4454 value is read in output_range_list_offset. */
4455 if (dwarf_split_debug_info
&& !force_direct
)
4456 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4458 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4459 attr
.dw_attr_val
.v
.val_offset
= offset
;
4460 add_dwarf_attr (die
, &attr
);
4463 /* Return the start label of a delta attribute. */
4465 static inline const char *
4466 AT_vms_delta1 (dw_attr_ref a
)
4468 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4469 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4472 /* Return the end label of a delta attribute. */
4474 static inline const char *
4475 AT_vms_delta2 (dw_attr_ref a
)
4477 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4478 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4481 static inline const char *
4482 AT_lbl (dw_attr_ref a
)
4484 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4485 || AT_class (a
) == dw_val_class_lineptr
4486 || AT_class (a
) == dw_val_class_macptr
4487 || AT_class (a
) == dw_val_class_high_pc
));
4488 return a
->dw_attr_val
.v
.val_lbl_id
;
4491 /* Get the attribute of type attr_kind. */
4494 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4498 dw_die_ref spec
= NULL
;
4503 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4504 if (a
->dw_attr
== attr_kind
)
4506 else if (a
->dw_attr
== DW_AT_specification
4507 || a
->dw_attr
== DW_AT_abstract_origin
)
4511 return get_AT (spec
, attr_kind
);
4516 /* Returns the parent of the declaration of DIE. */
4519 get_die_parent (dw_die_ref die
)
4526 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4527 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4530 return die
->die_parent
;
4533 /* Return the "low pc" attribute value, typically associated with a subprogram
4534 DIE. Return null if the "low pc" attribute is either not present, or if it
4535 cannot be represented as an assembler label identifier. */
4537 static inline const char *
4538 get_AT_low_pc (dw_die_ref die
)
4540 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4542 return a
? AT_lbl (a
) : NULL
;
4545 /* Return the "high pc" attribute value, typically associated with a subprogram
4546 DIE. Return null if the "high pc" attribute is either not present, or if it
4547 cannot be represented as an assembler label identifier. */
4549 static inline const char *
4550 get_AT_hi_pc (dw_die_ref die
)
4552 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4554 return a
? AT_lbl (a
) : NULL
;
4557 /* Return the value of the string attribute designated by ATTR_KIND, or
4558 NULL if it is not present. */
4560 static inline const char *
4561 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4563 dw_attr_ref a
= get_AT (die
, attr_kind
);
4565 return a
? AT_string (a
) : NULL
;
4568 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4569 if it is not present. */
4572 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4574 dw_attr_ref a
= get_AT (die
, attr_kind
);
4576 return a
? AT_flag (a
) : 0;
4579 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4580 if it is not present. */
4582 static inline unsigned
4583 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4585 dw_attr_ref a
= get_AT (die
, attr_kind
);
4587 return a
? AT_unsigned (a
) : 0;
4590 static inline dw_die_ref
4591 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4593 dw_attr_ref a
= get_AT (die
, attr_kind
);
4595 return a
? AT_ref (a
) : NULL
;
4598 static inline struct dwarf_file_data
*
4599 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4601 dw_attr_ref a
= get_AT (die
, attr_kind
);
4603 return a
? AT_file (a
) : NULL
;
4606 /* Return TRUE if the language is C++. */
4611 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4613 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4616 /* Return TRUE if the language is Java. */
4621 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4623 return lang
== DW_LANG_Java
;
4626 /* Return TRUE if the language is Fortran. */
4631 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4633 return (lang
== DW_LANG_Fortran77
4634 || lang
== DW_LANG_Fortran90
4635 || lang
== DW_LANG_Fortran95
);
4638 /* Return TRUE if the language is Ada. */
4643 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4645 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4648 /* Remove the specified attribute if present. */
4651 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4659 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4660 if (a
->dw_attr
== attr_kind
)
4662 if (AT_class (a
) == dw_val_class_str
)
4663 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4664 a
->dw_attr_val
.v
.val_str
->refcount
--;
4666 /* vec::ordered_remove should help reduce the number of abbrevs
4668 die
->die_attr
->ordered_remove (ix
);
4673 /* Remove CHILD from its parent. PREV must have the property that
4674 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4677 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4679 gcc_assert (child
->die_parent
== prev
->die_parent
);
4680 gcc_assert (prev
->die_sib
== child
);
4683 gcc_assert (child
->die_parent
->die_child
== child
);
4687 prev
->die_sib
= child
->die_sib
;
4688 if (child
->die_parent
->die_child
== child
)
4689 child
->die_parent
->die_child
= prev
;
4692 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4693 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4696 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4698 dw_die_ref parent
= old_child
->die_parent
;
4700 gcc_assert (parent
== prev
->die_parent
);
4701 gcc_assert (prev
->die_sib
== old_child
);
4703 new_child
->die_parent
= parent
;
4704 if (prev
== old_child
)
4706 gcc_assert (parent
->die_child
== old_child
);
4707 new_child
->die_sib
= new_child
;
4711 prev
->die_sib
= new_child
;
4712 new_child
->die_sib
= old_child
->die_sib
;
4714 if (old_child
->die_parent
->die_child
== old_child
)
4715 old_child
->die_parent
->die_child
= new_child
;
4718 /* Move all children from OLD_PARENT to NEW_PARENT. */
4721 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4724 new_parent
->die_child
= old_parent
->die_child
;
4725 old_parent
->die_child
= NULL
;
4726 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4729 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4733 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4739 dw_die_ref prev
= c
;
4741 while (c
->die_tag
== tag
)
4743 remove_child_with_prev (c
, prev
);
4744 /* Might have removed every child. */
4745 if (c
== c
->die_sib
)
4749 } while (c
!= die
->die_child
);
4752 /* Add a CHILD_DIE as the last child of DIE. */
4755 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4757 /* FIXME this should probably be an assert. */
4758 if (! die
|| ! child_die
)
4760 gcc_assert (die
!= child_die
);
4762 child_die
->die_parent
= die
;
4765 child_die
->die_sib
= die
->die_child
->die_sib
;
4766 die
->die_child
->die_sib
= child_die
;
4769 child_die
->die_sib
= child_die
;
4770 die
->die_child
= child_die
;
4773 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4774 is the specification, to the end of PARENT's list of children.
4775 This is done by removing and re-adding it. */
4778 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4782 /* We want the declaration DIE from inside the class, not the
4783 specification DIE at toplevel. */
4784 if (child
->die_parent
!= parent
)
4786 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4792 gcc_assert (child
->die_parent
== parent
4793 || (child
->die_parent
4794 == get_AT_ref (parent
, DW_AT_specification
)));
4796 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4797 if (p
->die_sib
== child
)
4799 remove_child_with_prev (child
, p
);
4803 add_child_die (parent
, child
);
4806 /* Return a pointer to a newly created DIE node. */
4808 static inline dw_die_ref
4809 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4811 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4813 die
->die_tag
= tag_value
;
4815 if (parent_die
!= NULL
)
4816 add_child_die (parent_die
, die
);
4819 limbo_die_node
*limbo_node
;
4821 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4822 limbo_node
->die
= die
;
4823 limbo_node
->created_for
= t
;
4824 limbo_node
->next
= limbo_die_list
;
4825 limbo_die_list
= limbo_node
;
4831 /* Return the DIE associated with the given type specifier. */
4833 static inline dw_die_ref
4834 lookup_type_die (tree type
)
4836 return TYPE_SYMTAB_DIE (type
);
4839 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4840 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4841 anonymous type instead the one of the naming typedef. */
4843 static inline dw_die_ref
4844 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4847 && TREE_CODE (type
) == RECORD_TYPE
4849 && type_die
->die_tag
== DW_TAG_typedef
4850 && is_naming_typedef_decl (TYPE_NAME (type
)))
4851 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4855 /* Like lookup_type_die, but if type is an anonymous type named by a
4856 typedef[1], return the DIE of the anonymous type instead the one of
4857 the naming typedef. This is because in gen_typedef_die, we did
4858 equate the anonymous struct named by the typedef with the DIE of
4859 the naming typedef. So by default, lookup_type_die on an anonymous
4860 struct yields the DIE of the naming typedef.
4862 [1]: Read the comment of is_naming_typedef_decl to learn about what
4863 a naming typedef is. */
4865 static inline dw_die_ref
4866 lookup_type_die_strip_naming_typedef (tree type
)
4868 dw_die_ref die
= lookup_type_die (type
);
4869 return strip_naming_typedef (type
, die
);
4872 /* Equate a DIE to a given type specifier. */
4875 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4877 TYPE_SYMTAB_DIE (type
) = type_die
;
4880 /* Returns a hash value for X (which really is a die_struct). */
4883 decl_die_table_hash (const void *x
)
4885 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4888 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4891 decl_die_table_eq (const void *x
, const void *y
)
4893 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4896 /* Return the DIE associated with a given declaration. */
4898 static inline dw_die_ref
4899 lookup_decl_die (tree decl
)
4901 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4904 /* Returns a hash value for X (which really is a var_loc_list). */
4907 decl_loc_table_hash (const void *x
)
4909 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4912 /* Return nonzero if decl_id of var_loc_list X is the same as
4916 decl_loc_table_eq (const void *x
, const void *y
)
4918 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4921 /* Return the var_loc list associated with a given declaration. */
4923 static inline var_loc_list
*
4924 lookup_decl_loc (const_tree decl
)
4926 if (!decl_loc_table
)
4928 return (var_loc_list
*)
4929 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4932 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4935 cached_dw_loc_list_table_hash (const void *x
)
4937 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4940 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4944 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4946 return (((const cached_dw_loc_list
*) x
)->decl_id
4947 == DECL_UID ((const_tree
) y
));
4950 /* Equate a DIE to a particular declaration. */
4953 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4955 unsigned int decl_id
= DECL_UID (decl
);
4958 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4960 decl_die
->decl_id
= decl_id
;
4963 /* Return how many bits covers PIECE EXPR_LIST. */
4966 decl_piece_bitsize (rtx piece
)
4968 int ret
= (int) GET_MODE (piece
);
4971 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4972 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4973 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4976 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4979 decl_piece_varloc_ptr (rtx piece
)
4981 if ((int) GET_MODE (piece
))
4982 return &XEXP (piece
, 0);
4984 return &XEXP (XEXP (piece
, 0), 1);
4987 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4988 Next is the chain of following piece nodes. */
4991 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4993 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4994 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4996 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5001 /* Return rtx that should be stored into loc field for
5002 LOC_NOTE and BITPOS/BITSIZE. */
5005 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5006 HOST_WIDE_INT bitsize
)
5010 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5012 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5017 /* This function either modifies location piece list *DEST in
5018 place (if SRC and INNER is NULL), or copies location piece list
5019 *SRC to *DEST while modifying it. Location BITPOS is modified
5020 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5021 not copied and if needed some padding around it is added.
5022 When modifying in place, DEST should point to EXPR_LIST where
5023 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5024 to the start of the whole list and INNER points to the EXPR_LIST
5025 where earlier pieces cover PIECE_BITPOS bits. */
5028 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5029 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5030 HOST_WIDE_INT bitsize
, rtx loc_note
)
5033 bool copy
= inner
!= NULL
;
5037 /* First copy all nodes preceding the current bitpos. */
5038 while (src
!= inner
)
5040 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5041 decl_piece_bitsize (*src
), NULL_RTX
);
5042 dest
= &XEXP (*dest
, 1);
5043 src
= &XEXP (*src
, 1);
5046 /* Add padding if needed. */
5047 if (bitpos
!= piece_bitpos
)
5049 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5050 copy
? NULL_RTX
: *dest
);
5051 dest
= &XEXP (*dest
, 1);
5053 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5056 /* A piece with correct bitpos and bitsize already exist,
5057 just update the location for it and return. */
5058 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5061 /* Add the piece that changed. */
5062 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5063 dest
= &XEXP (*dest
, 1);
5064 /* Skip over pieces that overlap it. */
5065 diff
= bitpos
- piece_bitpos
+ bitsize
;
5068 while (diff
> 0 && *src
)
5071 diff
-= decl_piece_bitsize (piece
);
5073 src
= &XEXP (piece
, 1);
5076 *src
= XEXP (piece
, 1);
5077 free_EXPR_LIST_node (piece
);
5080 /* Add padding if needed. */
5081 if (diff
< 0 && *src
)
5085 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5086 dest
= &XEXP (*dest
, 1);
5090 /* Finally copy all nodes following it. */
5093 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5094 decl_piece_bitsize (*src
), NULL_RTX
);
5095 dest
= &XEXP (*dest
, 1);
5096 src
= &XEXP (*src
, 1);
5100 /* Add a variable location node to the linked list for DECL. */
5102 static struct var_loc_node
*
5103 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5105 unsigned int decl_id
;
5108 struct var_loc_node
*loc
= NULL
;
5109 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5111 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
5113 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5115 && (handled_component_p (realdecl
)
5116 || (TREE_CODE (realdecl
) == MEM_REF
5117 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
)))
5119 HOST_WIDE_INT maxsize
;
5122 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5123 if (!DECL_P (innerdecl
)
5124 || DECL_IGNORED_P (innerdecl
)
5125 || TREE_STATIC (innerdecl
)
5127 || bitpos
+ bitsize
> 256
5128 || bitsize
!= maxsize
)
5134 decl_id
= DECL_UID (decl
);
5135 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5138 temp
= ggc_alloc_cleared_var_loc_list ();
5139 temp
->decl_id
= decl_id
;
5143 temp
= (var_loc_list
*) *slot
;
5145 /* For PARM_DECLs try to keep around the original incoming value,
5146 even if that means we'll emit a zero-range .debug_loc entry. */
5148 && temp
->first
== temp
->last
5149 && TREE_CODE (decl
) == PARM_DECL
5150 && GET_CODE (temp
->first
->loc
) == NOTE
5151 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5152 && DECL_INCOMING_RTL (decl
)
5153 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5154 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5155 == GET_CODE (DECL_INCOMING_RTL (decl
))
5156 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5158 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5159 NOTE_VAR_LOCATION_LOC (loc_note
))
5160 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5161 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5163 loc
= ggc_alloc_cleared_var_loc_node ();
5164 temp
->first
->next
= loc
;
5166 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5168 else if (temp
->last
)
5170 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5171 rtx
*piece_loc
= NULL
, last_loc_note
;
5172 int piece_bitpos
= 0;
5176 gcc_assert (last
->next
== NULL
);
5178 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5180 piece_loc
= &last
->loc
;
5183 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5184 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5186 piece_bitpos
+= cur_bitsize
;
5187 piece_loc
= &XEXP (*piece_loc
, 1);
5191 /* TEMP->LAST here is either pointer to the last but one or
5192 last element in the chained list, LAST is pointer to the
5194 if (label
&& strcmp (last
->label
, label
) == 0)
5196 /* For SRA optimized variables if there weren't any real
5197 insns since last note, just modify the last node. */
5198 if (piece_loc
!= NULL
)
5200 adjust_piece_list (piece_loc
, NULL
, NULL
,
5201 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5204 /* If the last note doesn't cover any instructions, remove it. */
5205 if (temp
->last
!= last
)
5207 temp
->last
->next
= NULL
;
5210 gcc_assert (strcmp (last
->label
, label
) != 0);
5214 gcc_assert (temp
->first
== temp
->last
5215 || (temp
->first
->next
== temp
->last
5216 && TREE_CODE (decl
) == PARM_DECL
));
5217 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5218 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5222 if (bitsize
== -1 && NOTE_P (last
->loc
))
5223 last_loc_note
= last
->loc
;
5224 else if (piece_loc
!= NULL
5225 && *piece_loc
!= NULL_RTX
5226 && piece_bitpos
== bitpos
5227 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5228 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5230 last_loc_note
= NULL_RTX
;
5231 /* If the current location is the same as the end of the list,
5232 and either both or neither of the locations is uninitialized,
5233 we have nothing to do. */
5234 if (last_loc_note
== NULL_RTX
5235 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5236 NOTE_VAR_LOCATION_LOC (loc_note
)))
5237 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5238 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5239 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5240 == VAR_INIT_STATUS_UNINITIALIZED
)
5241 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5242 == VAR_INIT_STATUS_UNINITIALIZED
))))
5244 /* Add LOC to the end of list and update LAST. If the last
5245 element of the list has been removed above, reuse its
5246 memory for the new node, otherwise allocate a new one. */
5250 memset (loc
, '\0', sizeof (*loc
));
5253 loc
= ggc_alloc_cleared_var_loc_node ();
5254 if (bitsize
== -1 || piece_loc
== NULL
)
5255 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5257 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5258 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5260 /* Ensure TEMP->LAST will point either to the new last but one
5261 element of the chain, or to the last element in it. */
5262 if (last
!= temp
->last
)
5270 loc
= ggc_alloc_cleared_var_loc_node ();
5273 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5278 /* Keep track of the number of spaces used to indent the
5279 output of the debugging routines that print the structure of
5280 the DIE internal representation. */
5281 static int print_indent
;
5283 /* Indent the line the number of spaces given by print_indent. */
5286 print_spaces (FILE *outfile
)
5288 fprintf (outfile
, "%*s", print_indent
, "");
5291 /* Print a type signature in hex. */
5294 print_signature (FILE *outfile
, char *sig
)
5298 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5299 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5302 /* Print the information associated with a given DIE, and its children.
5303 This routine is a debugging aid only. */
5306 print_die (dw_die_ref die
, FILE *outfile
)
5312 print_spaces (outfile
);
5313 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5314 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5316 print_spaces (outfile
);
5317 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5318 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5319 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5321 if (die
->comdat_type_p
)
5323 print_spaces (outfile
);
5324 fprintf (outfile
, " signature: ");
5325 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5326 fprintf (outfile
, "\n");
5329 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5331 print_spaces (outfile
);
5332 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5334 switch (AT_class (a
))
5336 case dw_val_class_addr
:
5337 fprintf (outfile
, "address");
5339 case dw_val_class_offset
:
5340 fprintf (outfile
, "offset");
5342 case dw_val_class_loc
:
5343 fprintf (outfile
, "location descriptor");
5345 case dw_val_class_loc_list
:
5346 fprintf (outfile
, "location list -> label:%s",
5347 AT_loc_list (a
)->ll_symbol
);
5349 case dw_val_class_range_list
:
5350 fprintf (outfile
, "range list");
5352 case dw_val_class_const
:
5353 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5355 case dw_val_class_unsigned_const
:
5356 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5358 case dw_val_class_const_double
:
5359 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5360 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5361 a
->dw_attr_val
.v
.val_double
.high
,
5362 a
->dw_attr_val
.v
.val_double
.low
);
5364 case dw_val_class_vec
:
5365 fprintf (outfile
, "floating-point or vector constant");
5367 case dw_val_class_flag
:
5368 fprintf (outfile
, "%u", AT_flag (a
));
5370 case dw_val_class_die_ref
:
5371 if (AT_ref (a
) != NULL
)
5373 if (AT_ref (a
)->comdat_type_p
)
5375 fprintf (outfile
, "die -> signature: ");
5376 print_signature (outfile
,
5377 AT_ref (a
)->die_id
.die_type_node
->signature
);
5379 else if (AT_ref (a
)->die_id
.die_symbol
)
5380 fprintf (outfile
, "die -> label: %s",
5381 AT_ref (a
)->die_id
.die_symbol
);
5383 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5384 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5387 fprintf (outfile
, "die -> <null>");
5389 case dw_val_class_vms_delta
:
5390 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5391 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5393 case dw_val_class_lbl_id
:
5394 case dw_val_class_lineptr
:
5395 case dw_val_class_macptr
:
5396 case dw_val_class_high_pc
:
5397 fprintf (outfile
, "label: %s", AT_lbl (a
));
5399 case dw_val_class_str
:
5400 if (AT_string (a
) != NULL
)
5401 fprintf (outfile
, "\"%s\"", AT_string (a
));
5403 fprintf (outfile
, "<null>");
5405 case dw_val_class_file
:
5406 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5407 AT_file (a
)->emitted_number
);
5409 case dw_val_class_data8
:
5413 for (i
= 0; i
< 8; i
++)
5414 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5421 fprintf (outfile
, "\n");
5424 if (die
->die_child
!= NULL
)
5427 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5430 if (print_indent
== 0)
5431 fprintf (outfile
, "\n");
5434 /* Print the information collected for a given DIE. */
5437 debug_dwarf_die (dw_die_ref die
)
5439 print_die (die
, stderr
);
5442 /* Print all DWARF information collected for the compilation unit.
5443 This routine is a debugging aid only. */
5449 print_die (comp_unit_die (), stderr
);
5452 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5453 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5454 DIE that marks the start of the DIEs for this include file. */
5457 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5459 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5460 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5462 new_unit
->die_sib
= old_unit
;
5466 /* Close an include-file CU and reopen the enclosing one. */
5469 pop_compile_unit (dw_die_ref old_unit
)
5471 dw_die_ref new_unit
= old_unit
->die_sib
;
5473 old_unit
->die_sib
= NULL
;
5477 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5478 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5479 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5481 /* Calculate the checksum of a location expression. */
5484 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5489 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5491 hash
= hash_loc_operands (loc
, hash
);
5495 /* Calculate the checksum of an attribute. */
5498 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5500 dw_loc_descr_ref loc
;
5503 CHECKSUM (at
->dw_attr
);
5505 /* We don't care that this was compiled with a different compiler
5506 snapshot; if the output is the same, that's what matters. */
5507 if (at
->dw_attr
== DW_AT_producer
)
5510 switch (AT_class (at
))
5512 case dw_val_class_const
:
5513 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5515 case dw_val_class_unsigned_const
:
5516 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5518 case dw_val_class_const_double
:
5519 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5521 case dw_val_class_vec
:
5522 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5523 (at
->dw_attr_val
.v
.val_vec
.length
5524 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5526 case dw_val_class_flag
:
5527 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5529 case dw_val_class_str
:
5530 CHECKSUM_STRING (AT_string (at
));
5533 case dw_val_class_addr
:
5535 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5536 CHECKSUM_STRING (XSTR (r
, 0));
5539 case dw_val_class_offset
:
5540 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5543 case dw_val_class_loc
:
5544 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5545 loc_checksum (loc
, ctx
);
5548 case dw_val_class_die_ref
:
5549 die_checksum (AT_ref (at
), ctx
, mark
);
5552 case dw_val_class_fde_ref
:
5553 case dw_val_class_vms_delta
:
5554 case dw_val_class_lbl_id
:
5555 case dw_val_class_lineptr
:
5556 case dw_val_class_macptr
:
5557 case dw_val_class_high_pc
:
5560 case dw_val_class_file
:
5561 CHECKSUM_STRING (AT_file (at
)->filename
);
5564 case dw_val_class_data8
:
5565 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5573 /* Calculate the checksum of a DIE. */
5576 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5582 /* To avoid infinite recursion. */
5585 CHECKSUM (die
->die_mark
);
5588 die
->die_mark
= ++(*mark
);
5590 CHECKSUM (die
->die_tag
);
5592 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5593 attr_checksum (a
, ctx
, mark
);
5595 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5599 #undef CHECKSUM_BLOCK
5600 #undef CHECKSUM_STRING
5602 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5603 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5604 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5605 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5606 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5607 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5608 #define CHECKSUM_ATTR(FOO) \
5609 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5611 /* Calculate the checksum of a number in signed LEB128 format. */
5614 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5621 byte
= (value
& 0x7f);
5623 more
= !((value
== 0 && (byte
& 0x40) == 0)
5624 || (value
== -1 && (byte
& 0x40) != 0));
5633 /* Calculate the checksum of a number in unsigned LEB128 format. */
5636 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5640 unsigned char byte
= (value
& 0x7f);
5643 /* More bytes to follow. */
5651 /* Checksum the context of the DIE. This adds the names of any
5652 surrounding namespaces or structures to the checksum. */
5655 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5659 int tag
= die
->die_tag
;
5661 if (tag
!= DW_TAG_namespace
5662 && tag
!= DW_TAG_structure_type
5663 && tag
!= DW_TAG_class_type
)
5666 name
= get_AT_string (die
, DW_AT_name
);
5668 spec
= get_AT_ref (die
, DW_AT_specification
);
5672 if (die
->die_parent
!= NULL
)
5673 checksum_die_context (die
->die_parent
, ctx
);
5675 CHECKSUM_ULEB128 ('C');
5676 CHECKSUM_ULEB128 (tag
);
5678 CHECKSUM_STRING (name
);
5681 /* Calculate the checksum of a location expression. */
5684 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5686 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5687 were emitted as a DW_FORM_sdata instead of a location expression. */
5688 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5690 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5691 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5695 /* Otherwise, just checksum the raw location expression. */
5700 CHECKSUM_ULEB128 (loc
->dtprel
);
5701 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5702 hash
= hash_loc_operands (loc
, hash
);
5704 loc
= loc
->dw_loc_next
;
5708 /* Calculate the checksum of an attribute. */
5711 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5712 struct md5_ctx
*ctx
, int *mark
)
5714 dw_loc_descr_ref loc
;
5717 if (AT_class (at
) == dw_val_class_die_ref
)
5719 dw_die_ref target_die
= AT_ref (at
);
5721 /* For pointer and reference types, we checksum only the (qualified)
5722 name of the target type (if there is a name). For friend entries,
5723 we checksum only the (qualified) name of the target type or function.
5724 This allows the checksum to remain the same whether the target type
5725 is complete or not. */
5726 if ((at
->dw_attr
== DW_AT_type
5727 && (tag
== DW_TAG_pointer_type
5728 || tag
== DW_TAG_reference_type
5729 || tag
== DW_TAG_rvalue_reference_type
5730 || tag
== DW_TAG_ptr_to_member_type
))
5731 || (at
->dw_attr
== DW_AT_friend
5732 && tag
== DW_TAG_friend
))
5734 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5736 if (name_attr
!= NULL
)
5738 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5742 CHECKSUM_ULEB128 ('N');
5743 CHECKSUM_ULEB128 (at
->dw_attr
);
5744 if (decl
->die_parent
!= NULL
)
5745 checksum_die_context (decl
->die_parent
, ctx
);
5746 CHECKSUM_ULEB128 ('E');
5747 CHECKSUM_STRING (AT_string (name_attr
));
5752 /* For all other references to another DIE, we check to see if the
5753 target DIE has already been visited. If it has, we emit a
5754 backward reference; if not, we descend recursively. */
5755 if (target_die
->die_mark
> 0)
5757 CHECKSUM_ULEB128 ('R');
5758 CHECKSUM_ULEB128 (at
->dw_attr
);
5759 CHECKSUM_ULEB128 (target_die
->die_mark
);
5763 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5767 target_die
->die_mark
= ++(*mark
);
5768 CHECKSUM_ULEB128 ('T');
5769 CHECKSUM_ULEB128 (at
->dw_attr
);
5770 if (decl
->die_parent
!= NULL
)
5771 checksum_die_context (decl
->die_parent
, ctx
);
5772 die_checksum_ordered (target_die
, ctx
, mark
);
5777 CHECKSUM_ULEB128 ('A');
5778 CHECKSUM_ULEB128 (at
->dw_attr
);
5780 switch (AT_class (at
))
5782 case dw_val_class_const
:
5783 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5784 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5787 case dw_val_class_unsigned_const
:
5788 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5789 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5792 case dw_val_class_const_double
:
5793 CHECKSUM_ULEB128 (DW_FORM_block
);
5794 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5795 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5798 case dw_val_class_vec
:
5799 CHECKSUM_ULEB128 (DW_FORM_block
);
5800 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
5801 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
5802 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5803 (at
->dw_attr_val
.v
.val_vec
.length
5804 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5807 case dw_val_class_flag
:
5808 CHECKSUM_ULEB128 (DW_FORM_flag
);
5809 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5812 case dw_val_class_str
:
5813 CHECKSUM_ULEB128 (DW_FORM_string
);
5814 CHECKSUM_STRING (AT_string (at
));
5817 case dw_val_class_addr
:
5819 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5820 CHECKSUM_ULEB128 (DW_FORM_string
);
5821 CHECKSUM_STRING (XSTR (r
, 0));
5824 case dw_val_class_offset
:
5825 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5826 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5829 case dw_val_class_loc
:
5830 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5831 loc_checksum_ordered (loc
, ctx
);
5834 case dw_val_class_fde_ref
:
5835 case dw_val_class_lbl_id
:
5836 case dw_val_class_lineptr
:
5837 case dw_val_class_macptr
:
5838 case dw_val_class_high_pc
:
5841 case dw_val_class_file
:
5842 CHECKSUM_ULEB128 (DW_FORM_string
);
5843 CHECKSUM_STRING (AT_file (at
)->filename
);
5846 case dw_val_class_data8
:
5847 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5855 struct checksum_attributes
5857 dw_attr_ref at_name
;
5858 dw_attr_ref at_type
;
5859 dw_attr_ref at_friend
;
5860 dw_attr_ref at_accessibility
;
5861 dw_attr_ref at_address_class
;
5862 dw_attr_ref at_allocated
;
5863 dw_attr_ref at_artificial
;
5864 dw_attr_ref at_associated
;
5865 dw_attr_ref at_binary_scale
;
5866 dw_attr_ref at_bit_offset
;
5867 dw_attr_ref at_bit_size
;
5868 dw_attr_ref at_bit_stride
;
5869 dw_attr_ref at_byte_size
;
5870 dw_attr_ref at_byte_stride
;
5871 dw_attr_ref at_const_value
;
5872 dw_attr_ref at_containing_type
;
5873 dw_attr_ref at_count
;
5874 dw_attr_ref at_data_location
;
5875 dw_attr_ref at_data_member_location
;
5876 dw_attr_ref at_decimal_scale
;
5877 dw_attr_ref at_decimal_sign
;
5878 dw_attr_ref at_default_value
;
5879 dw_attr_ref at_digit_count
;
5880 dw_attr_ref at_discr
;
5881 dw_attr_ref at_discr_list
;
5882 dw_attr_ref at_discr_value
;
5883 dw_attr_ref at_encoding
;
5884 dw_attr_ref at_endianity
;
5885 dw_attr_ref at_explicit
;
5886 dw_attr_ref at_is_optional
;
5887 dw_attr_ref at_location
;
5888 dw_attr_ref at_lower_bound
;
5889 dw_attr_ref at_mutable
;
5890 dw_attr_ref at_ordering
;
5891 dw_attr_ref at_picture_string
;
5892 dw_attr_ref at_prototyped
;
5893 dw_attr_ref at_small
;
5894 dw_attr_ref at_segment
;
5895 dw_attr_ref at_string_length
;
5896 dw_attr_ref at_threads_scaled
;
5897 dw_attr_ref at_upper_bound
;
5898 dw_attr_ref at_use_location
;
5899 dw_attr_ref at_use_UTF8
;
5900 dw_attr_ref at_variable_parameter
;
5901 dw_attr_ref at_virtuality
;
5902 dw_attr_ref at_visibility
;
5903 dw_attr_ref at_vtable_elem_location
;
5906 /* Collect the attributes that we will want to use for the checksum. */
5909 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5914 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5925 attrs
->at_friend
= a
;
5927 case DW_AT_accessibility
:
5928 attrs
->at_accessibility
= a
;
5930 case DW_AT_address_class
:
5931 attrs
->at_address_class
= a
;
5933 case DW_AT_allocated
:
5934 attrs
->at_allocated
= a
;
5936 case DW_AT_artificial
:
5937 attrs
->at_artificial
= a
;
5939 case DW_AT_associated
:
5940 attrs
->at_associated
= a
;
5942 case DW_AT_binary_scale
:
5943 attrs
->at_binary_scale
= a
;
5945 case DW_AT_bit_offset
:
5946 attrs
->at_bit_offset
= a
;
5948 case DW_AT_bit_size
:
5949 attrs
->at_bit_size
= a
;
5951 case DW_AT_bit_stride
:
5952 attrs
->at_bit_stride
= a
;
5954 case DW_AT_byte_size
:
5955 attrs
->at_byte_size
= a
;
5957 case DW_AT_byte_stride
:
5958 attrs
->at_byte_stride
= a
;
5960 case DW_AT_const_value
:
5961 attrs
->at_const_value
= a
;
5963 case DW_AT_containing_type
:
5964 attrs
->at_containing_type
= a
;
5967 attrs
->at_count
= a
;
5969 case DW_AT_data_location
:
5970 attrs
->at_data_location
= a
;
5972 case DW_AT_data_member_location
:
5973 attrs
->at_data_member_location
= a
;
5975 case DW_AT_decimal_scale
:
5976 attrs
->at_decimal_scale
= a
;
5978 case DW_AT_decimal_sign
:
5979 attrs
->at_decimal_sign
= a
;
5981 case DW_AT_default_value
:
5982 attrs
->at_default_value
= a
;
5984 case DW_AT_digit_count
:
5985 attrs
->at_digit_count
= a
;
5988 attrs
->at_discr
= a
;
5990 case DW_AT_discr_list
:
5991 attrs
->at_discr_list
= a
;
5993 case DW_AT_discr_value
:
5994 attrs
->at_discr_value
= a
;
5996 case DW_AT_encoding
:
5997 attrs
->at_encoding
= a
;
5999 case DW_AT_endianity
:
6000 attrs
->at_endianity
= a
;
6002 case DW_AT_explicit
:
6003 attrs
->at_explicit
= a
;
6005 case DW_AT_is_optional
:
6006 attrs
->at_is_optional
= a
;
6008 case DW_AT_location
:
6009 attrs
->at_location
= a
;
6011 case DW_AT_lower_bound
:
6012 attrs
->at_lower_bound
= a
;
6015 attrs
->at_mutable
= a
;
6017 case DW_AT_ordering
:
6018 attrs
->at_ordering
= a
;
6020 case DW_AT_picture_string
:
6021 attrs
->at_picture_string
= a
;
6023 case DW_AT_prototyped
:
6024 attrs
->at_prototyped
= a
;
6027 attrs
->at_small
= a
;
6030 attrs
->at_segment
= a
;
6032 case DW_AT_string_length
:
6033 attrs
->at_string_length
= a
;
6035 case DW_AT_threads_scaled
:
6036 attrs
->at_threads_scaled
= a
;
6038 case DW_AT_upper_bound
:
6039 attrs
->at_upper_bound
= a
;
6041 case DW_AT_use_location
:
6042 attrs
->at_use_location
= a
;
6044 case DW_AT_use_UTF8
:
6045 attrs
->at_use_UTF8
= a
;
6047 case DW_AT_variable_parameter
:
6048 attrs
->at_variable_parameter
= a
;
6050 case DW_AT_virtuality
:
6051 attrs
->at_virtuality
= a
;
6053 case DW_AT_visibility
:
6054 attrs
->at_visibility
= a
;
6056 case DW_AT_vtable_elem_location
:
6057 attrs
->at_vtable_elem_location
= a
;
6065 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6068 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6072 struct checksum_attributes attrs
;
6074 CHECKSUM_ULEB128 ('D');
6075 CHECKSUM_ULEB128 (die
->die_tag
);
6077 memset (&attrs
, 0, sizeof (attrs
));
6079 decl
= get_AT_ref (die
, DW_AT_specification
);
6081 collect_checksum_attributes (&attrs
, decl
);
6082 collect_checksum_attributes (&attrs
, die
);
6084 CHECKSUM_ATTR (attrs
.at_name
);
6085 CHECKSUM_ATTR (attrs
.at_accessibility
);
6086 CHECKSUM_ATTR (attrs
.at_address_class
);
6087 CHECKSUM_ATTR (attrs
.at_allocated
);
6088 CHECKSUM_ATTR (attrs
.at_artificial
);
6089 CHECKSUM_ATTR (attrs
.at_associated
);
6090 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6091 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6092 CHECKSUM_ATTR (attrs
.at_bit_size
);
6093 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6094 CHECKSUM_ATTR (attrs
.at_byte_size
);
6095 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6096 CHECKSUM_ATTR (attrs
.at_const_value
);
6097 CHECKSUM_ATTR (attrs
.at_containing_type
);
6098 CHECKSUM_ATTR (attrs
.at_count
);
6099 CHECKSUM_ATTR (attrs
.at_data_location
);
6100 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6101 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6102 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6103 CHECKSUM_ATTR (attrs
.at_default_value
);
6104 CHECKSUM_ATTR (attrs
.at_digit_count
);
6105 CHECKSUM_ATTR (attrs
.at_discr
);
6106 CHECKSUM_ATTR (attrs
.at_discr_list
);
6107 CHECKSUM_ATTR (attrs
.at_discr_value
);
6108 CHECKSUM_ATTR (attrs
.at_encoding
);
6109 CHECKSUM_ATTR (attrs
.at_endianity
);
6110 CHECKSUM_ATTR (attrs
.at_explicit
);
6111 CHECKSUM_ATTR (attrs
.at_is_optional
);
6112 CHECKSUM_ATTR (attrs
.at_location
);
6113 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6114 CHECKSUM_ATTR (attrs
.at_mutable
);
6115 CHECKSUM_ATTR (attrs
.at_ordering
);
6116 CHECKSUM_ATTR (attrs
.at_picture_string
);
6117 CHECKSUM_ATTR (attrs
.at_prototyped
);
6118 CHECKSUM_ATTR (attrs
.at_small
);
6119 CHECKSUM_ATTR (attrs
.at_segment
);
6120 CHECKSUM_ATTR (attrs
.at_string_length
);
6121 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6122 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6123 CHECKSUM_ATTR (attrs
.at_use_location
);
6124 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6125 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6126 CHECKSUM_ATTR (attrs
.at_virtuality
);
6127 CHECKSUM_ATTR (attrs
.at_visibility
);
6128 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6129 CHECKSUM_ATTR (attrs
.at_type
);
6130 CHECKSUM_ATTR (attrs
.at_friend
);
6132 /* Checksum the child DIEs. */
6135 dw_attr_ref name_attr
;
6138 name_attr
= get_AT (c
, DW_AT_name
);
6139 if (is_template_instantiation (c
))
6141 /* Ignore instantiations of member type and function templates. */
6143 else if (name_attr
!= NULL
6144 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6146 /* Use a shallow checksum for named nested types and member
6148 CHECKSUM_ULEB128 ('S');
6149 CHECKSUM_ULEB128 (c
->die_tag
);
6150 CHECKSUM_STRING (AT_string (name_attr
));
6154 /* Use a deep checksum for other children. */
6155 /* Mark this DIE so it gets processed when unmarking. */
6156 if (c
->die_mark
== 0)
6158 die_checksum_ordered (c
, ctx
, mark
);
6160 } while (c
!= die
->die_child
);
6162 CHECKSUM_ULEB128 (0);
6166 #undef CHECKSUM_STRING
6167 #undef CHECKSUM_ATTR
6168 #undef CHECKSUM_LEB128
6169 #undef CHECKSUM_ULEB128
6171 /* Generate the type signature for DIE. This is computed by generating an
6172 MD5 checksum over the DIE's tag, its relevant attributes, and its
6173 children. Attributes that are references to other DIEs are processed
6174 by recursion, using the MARK field to prevent infinite recursion.
6175 If the DIE is nested inside a namespace or another type, we also
6176 need to include that context in the signature. The lower 64 bits
6177 of the resulting MD5 checksum comprise the signature. */
6180 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6184 unsigned char checksum
[16];
6189 name
= get_AT_string (die
, DW_AT_name
);
6190 decl
= get_AT_ref (die
, DW_AT_specification
);
6191 parent
= get_die_parent (die
);
6193 /* First, compute a signature for just the type name (and its surrounding
6194 context, if any. This is stored in the type unit DIE for link-time
6195 ODR (one-definition rule) checking. */
6197 if (is_cxx() && name
!= NULL
)
6199 md5_init_ctx (&ctx
);
6201 /* Checksum the names of surrounding namespaces and structures. */
6203 checksum_die_context (parent
, &ctx
);
6205 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
6206 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
6207 md5_finish_ctx (&ctx
, checksum
);
6209 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6212 /* Next, compute the complete type signature. */
6214 md5_init_ctx (&ctx
);
6216 die
->die_mark
= mark
;
6218 /* Checksum the names of surrounding namespaces and structures. */
6220 checksum_die_context (parent
, &ctx
);
6222 /* Checksum the DIE and its children. */
6223 die_checksum_ordered (die
, &ctx
, &mark
);
6224 unmark_all_dies (die
);
6225 md5_finish_ctx (&ctx
, checksum
);
6227 /* Store the signature in the type node and link the type DIE and the
6228 type node together. */
6229 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6230 DWARF_TYPE_SIGNATURE_SIZE
);
6231 die
->comdat_type_p
= true;
6232 die
->die_id
.die_type_node
= type_node
;
6233 type_node
->type_die
= die
;
6235 /* If the DIE is a specification, link its declaration to the type node
6239 decl
->comdat_type_p
= true;
6240 decl
->die_id
.die_type_node
= type_node
;
6244 /* Do the location expressions look same? */
6246 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6248 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6249 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6250 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6253 /* Do the values look the same? */
6255 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6257 dw_loc_descr_ref loc1
, loc2
;
6260 if (v1
->val_class
!= v2
->val_class
)
6263 switch (v1
->val_class
)
6265 case dw_val_class_const
:
6266 return v1
->v
.val_int
== v2
->v
.val_int
;
6267 case dw_val_class_unsigned_const
:
6268 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6269 case dw_val_class_const_double
:
6270 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6271 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6272 case dw_val_class_vec
:
6273 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6274 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6276 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6277 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6280 case dw_val_class_flag
:
6281 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6282 case dw_val_class_str
:
6283 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6285 case dw_val_class_addr
:
6286 r1
= v1
->v
.val_addr
;
6287 r2
= v2
->v
.val_addr
;
6288 if (GET_CODE (r1
) != GET_CODE (r2
))
6290 return !rtx_equal_p (r1
, r2
);
6292 case dw_val_class_offset
:
6293 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6295 case dw_val_class_loc
:
6296 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6298 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6299 if (!same_loc_p (loc1
, loc2
, mark
))
6301 return !loc1
&& !loc2
;
6303 case dw_val_class_die_ref
:
6304 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6306 case dw_val_class_fde_ref
:
6307 case dw_val_class_vms_delta
:
6308 case dw_val_class_lbl_id
:
6309 case dw_val_class_lineptr
:
6310 case dw_val_class_macptr
:
6311 case dw_val_class_high_pc
:
6314 case dw_val_class_file
:
6315 return v1
->v
.val_file
== v2
->v
.val_file
;
6317 case dw_val_class_data8
:
6318 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6325 /* Do the attributes look the same? */
6328 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6330 if (at1
->dw_attr
!= at2
->dw_attr
)
6333 /* We don't care that this was compiled with a different compiler
6334 snapshot; if the output is the same, that's what matters. */
6335 if (at1
->dw_attr
== DW_AT_producer
)
6338 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6341 /* Do the dies look the same? */
6344 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6350 /* To avoid infinite recursion. */
6352 return die1
->die_mark
== die2
->die_mark
;
6353 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6355 if (die1
->die_tag
!= die2
->die_tag
)
6358 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6361 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6362 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6365 c1
= die1
->die_child
;
6366 c2
= die2
->die_child
;
6375 if (!same_die_p (c1
, c2
, mark
))
6379 if (c1
== die1
->die_child
)
6381 if (c2
== die2
->die_child
)
6391 /* Do the dies look the same? Wrapper around same_die_p. */
6394 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6397 int ret
= same_die_p (die1
, die2
, &mark
);
6399 unmark_all_dies (die1
);
6400 unmark_all_dies (die2
);
6405 /* The prefix to attach to symbols on DIEs in the current comdat debug
6407 static const char *comdat_symbol_id
;
6409 /* The index of the current symbol within the current comdat CU. */
6410 static unsigned int comdat_symbol_number
;
6412 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6413 children, and set comdat_symbol_id accordingly. */
6416 compute_section_prefix (dw_die_ref unit_die
)
6418 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6419 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6420 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6423 unsigned char checksum
[16];
6426 /* Compute the checksum of the DIE, then append part of it as hex digits to
6427 the name filename of the unit. */
6429 md5_init_ctx (&ctx
);
6431 die_checksum (unit_die
, &ctx
, &mark
);
6432 unmark_all_dies (unit_die
);
6433 md5_finish_ctx (&ctx
, checksum
);
6435 sprintf (name
, "%s.", base
);
6436 clean_symbol_name (name
);
6438 p
= name
+ strlen (name
);
6439 for (i
= 0; i
< 4; i
++)
6441 sprintf (p
, "%.2x", checksum
[i
]);
6445 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6446 comdat_symbol_number
= 0;
6449 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6452 is_type_die (dw_die_ref die
)
6454 switch (die
->die_tag
)
6456 case DW_TAG_array_type
:
6457 case DW_TAG_class_type
:
6458 case DW_TAG_interface_type
:
6459 case DW_TAG_enumeration_type
:
6460 case DW_TAG_pointer_type
:
6461 case DW_TAG_reference_type
:
6462 case DW_TAG_rvalue_reference_type
:
6463 case DW_TAG_string_type
:
6464 case DW_TAG_structure_type
:
6465 case DW_TAG_subroutine_type
:
6466 case DW_TAG_union_type
:
6467 case DW_TAG_ptr_to_member_type
:
6468 case DW_TAG_set_type
:
6469 case DW_TAG_subrange_type
:
6470 case DW_TAG_base_type
:
6471 case DW_TAG_const_type
:
6472 case DW_TAG_file_type
:
6473 case DW_TAG_packed_type
:
6474 case DW_TAG_volatile_type
:
6475 case DW_TAG_typedef
:
6482 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6483 Basically, we want to choose the bits that are likely to be shared between
6484 compilations (types) and leave out the bits that are specific to individual
6485 compilations (functions). */
6488 is_comdat_die (dw_die_ref c
)
6490 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6491 we do for stabs. The advantage is a greater likelihood of sharing between
6492 objects that don't include headers in the same order (and therefore would
6493 put the base types in a different comdat). jason 8/28/00 */
6495 if (c
->die_tag
== DW_TAG_base_type
)
6498 if (c
->die_tag
== DW_TAG_pointer_type
6499 || c
->die_tag
== DW_TAG_reference_type
6500 || c
->die_tag
== DW_TAG_rvalue_reference_type
6501 || c
->die_tag
== DW_TAG_const_type
6502 || c
->die_tag
== DW_TAG_volatile_type
)
6504 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6506 return t
? is_comdat_die (t
) : 0;
6509 return is_type_die (c
);
6512 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6513 compilation unit. */
6516 is_symbol_die (dw_die_ref c
)
6518 return (is_type_die (c
)
6519 || is_declaration_die (c
)
6520 || c
->die_tag
== DW_TAG_namespace
6521 || c
->die_tag
== DW_TAG_module
);
6524 /* Returns true iff C is a compile-unit DIE. */
6527 is_cu_die (dw_die_ref c
)
6529 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6532 /* Returns true iff C is a unit DIE of some sort. */
6535 is_unit_die (dw_die_ref c
)
6537 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6538 || c
->die_tag
== DW_TAG_partial_unit
6539 || c
->die_tag
== DW_TAG_type_unit
);
6542 /* Returns true iff C is a namespace DIE. */
6545 is_namespace_die (dw_die_ref c
)
6547 return c
&& c
->die_tag
== DW_TAG_namespace
;
6550 /* Returns true iff C is a class or structure DIE. */
6553 is_class_die (dw_die_ref c
)
6555 return c
&& (c
->die_tag
== DW_TAG_class_type
6556 || c
->die_tag
== DW_TAG_structure_type
);
6559 /* Return non-zero if this DIE is a template parameter. */
6562 is_template_parameter (dw_die_ref die
)
6564 switch (die
->die_tag
)
6566 case DW_TAG_template_type_param
:
6567 case DW_TAG_template_value_param
:
6568 case DW_TAG_GNU_template_template_param
:
6569 case DW_TAG_GNU_template_parameter_pack
:
6576 /* Return non-zero if this DIE represents a template instantiation. */
6579 is_template_instantiation (dw_die_ref die
)
6583 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6585 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6590 gen_internal_sym (const char *prefix
)
6594 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6595 return xstrdup (buf
);
6598 /* Assign symbols to all worthy DIEs under DIE. */
6601 assign_symbol_names (dw_die_ref die
)
6605 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6607 if (comdat_symbol_id
)
6609 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6611 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6612 comdat_symbol_id
, comdat_symbol_number
++);
6613 die
->die_id
.die_symbol
= xstrdup (p
);
6616 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6619 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6622 struct cu_hash_table_entry
6625 unsigned min_comdat_num
, max_comdat_num
;
6626 struct cu_hash_table_entry
*next
;
6629 /* Routines to manipulate hash table of CUs. */
6631 htab_cu_hash (const void *of
)
6633 const struct cu_hash_table_entry
*const entry
=
6634 (const struct cu_hash_table_entry
*) of
;
6636 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6640 htab_cu_eq (const void *of1
, const void *of2
)
6642 const struct cu_hash_table_entry
*const entry1
=
6643 (const struct cu_hash_table_entry
*) of1
;
6644 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6646 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6650 htab_cu_del (void *what
)
6652 struct cu_hash_table_entry
*next
,
6653 *entry
= (struct cu_hash_table_entry
*) what
;
6663 /* Check whether we have already seen this CU and set up SYM_NUM
6666 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6668 struct cu_hash_table_entry dummy
;
6669 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6671 dummy
.max_comdat_num
= 0;
6673 slot
= (struct cu_hash_table_entry
**)
6674 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6678 for (; entry
; last
= entry
, entry
= entry
->next
)
6680 if (same_die_p_wrap (cu
, entry
->cu
))
6686 *sym_num
= entry
->min_comdat_num
;
6690 entry
= XCNEW (struct cu_hash_table_entry
);
6692 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6693 entry
->next
= *slot
;
6699 /* Record SYM_NUM to record of CU in HTABLE. */
6701 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6703 struct cu_hash_table_entry
**slot
, *entry
;
6705 slot
= (struct cu_hash_table_entry
**)
6706 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6710 entry
->max_comdat_num
= sym_num
;
6713 /* Traverse the DIE (which is always comp_unit_die), and set up
6714 additional compilation units for each of the include files we see
6715 bracketed by BINCL/EINCL. */
6718 break_out_includes (dw_die_ref die
)
6721 dw_die_ref unit
= NULL
;
6722 limbo_die_node
*node
, **pnode
;
6723 htab_t cu_hash_table
;
6727 dw_die_ref prev
= c
;
6729 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6730 || (unit
&& is_comdat_die (c
)))
6732 dw_die_ref next
= c
->die_sib
;
6734 /* This DIE is for a secondary CU; remove it from the main one. */
6735 remove_child_with_prev (c
, prev
);
6737 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6738 unit
= push_new_compile_unit (unit
, c
);
6739 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6740 unit
= pop_compile_unit (unit
);
6742 add_child_die (unit
, c
);
6744 if (c
== die
->die_child
)
6747 } while (c
!= die
->die_child
);
6750 /* We can only use this in debugging, since the frontend doesn't check
6751 to make sure that we leave every include file we enter. */
6755 assign_symbol_names (die
);
6756 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6757 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6763 compute_section_prefix (node
->die
);
6764 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6765 &comdat_symbol_number
);
6766 assign_symbol_names (node
->die
);
6768 *pnode
= node
->next
;
6771 pnode
= &node
->next
;
6772 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6773 comdat_symbol_number
);
6776 htab_delete (cu_hash_table
);
6779 /* Return non-zero if this DIE is a declaration. */
6782 is_declaration_die (dw_die_ref die
)
6787 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6788 if (a
->dw_attr
== DW_AT_declaration
)
6794 /* Return non-zero if this DIE is nested inside a subprogram. */
6797 is_nested_in_subprogram (dw_die_ref die
)
6799 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6803 return local_scope_p (decl
);
6806 /* Return non-zero if this DIE contains a defining declaration of a
6810 contains_subprogram_definition (dw_die_ref die
)
6814 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6816 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6820 /* Return non-zero if this is a type DIE that should be moved to a
6821 COMDAT .debug_types section. */
6824 should_move_die_to_comdat (dw_die_ref die
)
6826 switch (die
->die_tag
)
6828 case DW_TAG_class_type
:
6829 case DW_TAG_structure_type
:
6830 case DW_TAG_enumeration_type
:
6831 case DW_TAG_union_type
:
6832 /* Don't move declarations, inlined instances, types nested in a
6833 subprogram, or types that contain subprogram definitions. */
6834 if (is_declaration_die (die
)
6835 || get_AT (die
, DW_AT_abstract_origin
)
6836 || is_nested_in_subprogram (die
)
6837 || contains_subprogram_definition (die
))
6840 case DW_TAG_array_type
:
6841 case DW_TAG_interface_type
:
6842 case DW_TAG_pointer_type
:
6843 case DW_TAG_reference_type
:
6844 case DW_TAG_rvalue_reference_type
:
6845 case DW_TAG_string_type
:
6846 case DW_TAG_subroutine_type
:
6847 case DW_TAG_ptr_to_member_type
:
6848 case DW_TAG_set_type
:
6849 case DW_TAG_subrange_type
:
6850 case DW_TAG_base_type
:
6851 case DW_TAG_const_type
:
6852 case DW_TAG_file_type
:
6853 case DW_TAG_packed_type
:
6854 case DW_TAG_volatile_type
:
6855 case DW_TAG_typedef
:
6861 /* Make a clone of DIE. */
6864 clone_die (dw_die_ref die
)
6870 clone
= ggc_alloc_cleared_die_node ();
6871 clone
->die_tag
= die
->die_tag
;
6873 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6874 add_dwarf_attr (clone
, a
);
6879 /* Make a clone of the tree rooted at DIE. */
6882 clone_tree (dw_die_ref die
)
6885 dw_die_ref clone
= clone_die (die
);
6887 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
6892 /* Make a clone of DIE as a declaration. */
6895 clone_as_declaration (dw_die_ref die
)
6902 /* If the DIE is already a declaration, just clone it. */
6903 if (is_declaration_die (die
))
6904 return clone_die (die
);
6906 /* If the DIE is a specification, just clone its declaration DIE. */
6907 decl
= get_AT_ref (die
, DW_AT_specification
);
6910 clone
= clone_die (decl
);
6911 if (die
->comdat_type_p
)
6912 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6916 clone
= ggc_alloc_cleared_die_node ();
6917 clone
->die_tag
= die
->die_tag
;
6919 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6921 /* We don't want to copy over all attributes.
6922 For example we don't want DW_AT_byte_size because otherwise we will no
6923 longer have a declaration and GDB will treat it as a definition. */
6927 case DW_AT_abstract_origin
:
6928 case DW_AT_artificial
:
6929 case DW_AT_containing_type
:
6930 case DW_AT_external
:
6933 case DW_AT_virtuality
:
6934 case DW_AT_linkage_name
:
6935 case DW_AT_MIPS_linkage_name
:
6936 add_dwarf_attr (clone
, a
);
6938 case DW_AT_byte_size
:
6944 if (die
->comdat_type_p
)
6945 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6947 add_AT_flag (clone
, DW_AT_declaration
, 1);
6951 /* Copy the declaration context to the new type unit DIE. This includes
6952 any surrounding namespace or type declarations. If the DIE has an
6953 AT_specification attribute, it also includes attributes and children
6954 attached to the specification, and returns a pointer to the original
6955 parent of the declaration DIE. Returns NULL otherwise. */
6958 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
6961 dw_die_ref new_decl
;
6962 dw_die_ref orig_parent
= NULL
;
6964 decl
= get_AT_ref (die
, DW_AT_specification
);
6973 /* The original DIE will be changed to a declaration, and must
6974 be moved to be a child of the original declaration DIE. */
6975 orig_parent
= decl
->die_parent
;
6977 /* Copy the type node pointer from the new DIE to the original
6978 declaration DIE so we can forward references later. */
6979 decl
->comdat_type_p
= true;
6980 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
6982 remove_AT (die
, DW_AT_specification
);
6984 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
6986 if (a
->dw_attr
!= DW_AT_name
6987 && a
->dw_attr
!= DW_AT_declaration
6988 && a
->dw_attr
!= DW_AT_external
)
6989 add_dwarf_attr (die
, a
);
6992 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
6995 if (decl
->die_parent
!= NULL
6996 && !is_unit_die (decl
->die_parent
))
6998 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
6999 if (new_decl
!= NULL
)
7001 remove_AT (new_decl
, DW_AT_signature
);
7002 add_AT_specification (die
, new_decl
);
7009 /* Generate the skeleton ancestor tree for the given NODE, then clone
7010 the DIE and add the clone into the tree. */
7013 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7015 if (node
->new_die
!= NULL
)
7018 node
->new_die
= clone_as_declaration (node
->old_die
);
7020 if (node
->parent
!= NULL
)
7022 generate_skeleton_ancestor_tree (node
->parent
);
7023 add_child_die (node
->parent
->new_die
, node
->new_die
);
7027 /* Generate a skeleton tree of DIEs containing any declarations that are
7028 found in the original tree. We traverse the tree looking for declaration
7029 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7032 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7034 skeleton_chain_node node
;
7037 dw_die_ref prev
= NULL
;
7038 dw_die_ref next
= NULL
;
7040 node
.parent
= parent
;
7042 first
= c
= parent
->old_die
->die_child
;
7046 if (prev
== NULL
|| prev
->die_sib
== c
)
7049 next
= (c
== first
? NULL
: c
->die_sib
);
7051 node
.new_die
= NULL
;
7052 if (is_declaration_die (c
))
7054 if (is_template_instantiation (c
))
7056 /* Instantiated templates do not need to be cloned into the
7057 type unit. Just move the DIE and its children back to
7058 the skeleton tree (in the main CU). */
7059 remove_child_with_prev (c
, prev
);
7060 add_child_die (parent
->new_die
, c
);
7065 /* Clone the existing DIE, move the original to the skeleton
7066 tree (which is in the main CU), and put the clone, with
7067 all the original's children, where the original came from
7068 (which is about to be moved to the type unit). */
7069 dw_die_ref clone
= clone_die (c
);
7070 move_all_children (c
, clone
);
7072 /* If the original has a DW_AT_object_pointer attribute,
7073 it would now point to a child DIE just moved to the
7074 cloned tree, so we need to remove that attribute from
7076 remove_AT (c
, DW_AT_object_pointer
);
7078 replace_child (c
, clone
, prev
);
7079 generate_skeleton_ancestor_tree (parent
);
7080 add_child_die (parent
->new_die
, c
);
7085 generate_skeleton_bottom_up (&node
);
7086 } while (next
!= NULL
);
7089 /* Wrapper function for generate_skeleton_bottom_up. */
7092 generate_skeleton (dw_die_ref die
)
7094 skeleton_chain_node node
;
7097 node
.new_die
= NULL
;
7100 /* If this type definition is nested inside another type,
7101 and is not an instantiation of a template, always leave
7102 at least a declaration in its place. */
7103 if (die
->die_parent
!= NULL
7104 && is_type_die (die
->die_parent
)
7105 && !is_template_instantiation (die
))
7106 node
.new_die
= clone_as_declaration (die
);
7108 generate_skeleton_bottom_up (&node
);
7109 return node
.new_die
;
7112 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7113 declaration. The original DIE is moved to a new compile unit so that
7114 existing references to it follow it to the new location. If any of the
7115 original DIE's descendants is a declaration, we need to replace the
7116 original DIE with a skeleton tree and move the declarations back into the
7120 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7123 dw_die_ref skeleton
, orig_parent
;
7125 /* Copy the declaration context to the type unit DIE. If the returned
7126 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7128 orig_parent
= copy_declaration_context (unit
, child
);
7130 skeleton
= generate_skeleton (child
);
7131 if (skeleton
== NULL
)
7132 remove_child_with_prev (child
, prev
);
7135 skeleton
->comdat_type_p
= true;
7136 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7138 /* If the original DIE was a specification, we need to put
7139 the skeleton under the parent DIE of the declaration.
7140 This leaves the original declaration in the tree, but
7141 it will be pruned later since there are no longer any
7142 references to it. */
7143 if (orig_parent
!= NULL
)
7145 remove_child_with_prev (child
, prev
);
7146 add_child_die (orig_parent
, skeleton
);
7149 replace_child (child
, skeleton
, prev
);
7155 /* Traverse the DIE and set up additional .debug_types sections for each
7156 type worthy of being placed in a COMDAT section. */
7159 break_out_comdat_types (dw_die_ref die
)
7163 dw_die_ref prev
= NULL
;
7164 dw_die_ref next
= NULL
;
7165 dw_die_ref unit
= NULL
;
7167 first
= c
= die
->die_child
;
7171 if (prev
== NULL
|| prev
->die_sib
== c
)
7174 next
= (c
== first
? NULL
: c
->die_sib
);
7175 if (should_move_die_to_comdat (c
))
7177 dw_die_ref replacement
;
7178 comdat_type_node_ref type_node
;
7180 /* Break out nested types into their own type units. */
7181 break_out_comdat_types (c
);
7183 /* Create a new type unit DIE as the root for the new tree, and
7184 add it to the list of comdat types. */
7185 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7186 add_AT_unsigned (unit
, DW_AT_language
,
7187 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7188 type_node
= ggc_alloc_cleared_comdat_type_node ();
7189 type_node
->root_die
= unit
;
7190 type_node
->next
= comdat_type_list
;
7191 comdat_type_list
= type_node
;
7193 /* Generate the type signature. */
7194 generate_type_signature (c
, type_node
);
7196 /* Copy the declaration context, attributes, and children of the
7197 declaration into the new type unit DIE, then remove this DIE
7198 from the main CU (or replace it with a skeleton if necessary). */
7199 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7200 type_node
->skeleton_die
= replacement
;
7202 /* Add the DIE to the new compunit. */
7203 add_child_die (unit
, c
);
7205 if (replacement
!= NULL
)
7208 else if (c
->die_tag
== DW_TAG_namespace
7209 || c
->die_tag
== DW_TAG_class_type
7210 || c
->die_tag
== DW_TAG_structure_type
7211 || c
->die_tag
== DW_TAG_union_type
)
7213 /* Look for nested types that can be broken out. */
7214 break_out_comdat_types (c
);
7216 } while (next
!= NULL
);
7219 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7221 struct decl_table_entry
7227 /* Routines to manipulate hash table of copied declarations. */
7230 htab_decl_hash (const void *of
)
7232 const struct decl_table_entry
*const entry
=
7233 (const struct decl_table_entry
*) of
;
7235 return htab_hash_pointer (entry
->orig
);
7239 htab_decl_eq (const void *of1
, const void *of2
)
7241 const struct decl_table_entry
*const entry1
=
7242 (const struct decl_table_entry
*) of1
;
7243 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
7245 return entry1
->orig
== entry2
;
7249 htab_decl_del (void *what
)
7251 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
7256 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7257 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7258 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7259 to check if the ancestor has already been copied into UNIT. */
7262 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7264 dw_die_ref parent
= die
->die_parent
;
7265 dw_die_ref new_parent
= unit
;
7268 struct decl_table_entry
*entry
= NULL
;
7272 /* Check if the entry has already been copied to UNIT. */
7273 slot
= htab_find_slot_with_hash (decl_table
, die
,
7274 htab_hash_pointer (die
), INSERT
);
7275 if (*slot
!= HTAB_EMPTY_ENTRY
)
7277 entry
= (struct decl_table_entry
*) *slot
;
7281 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7282 entry
= XCNEW (struct decl_table_entry
);
7290 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7293 if (!is_unit_die (parent
))
7294 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7297 copy
= clone_as_declaration (die
);
7298 add_child_die (new_parent
, copy
);
7300 if (decl_table
!= NULL
)
7302 /* Record the pointer to the copy. */
7309 /* Like clone_tree, but copy DW_TAG_subprogram DIEs as declarations.
7310 Enter all the cloned children into the hash table decl_table. */
7313 clone_tree_partial (dw_die_ref die
, htab_t decl_table
)
7317 struct decl_table_entry
*entry
;
7320 if (die
->die_tag
== DW_TAG_subprogram
)
7321 clone
= clone_as_declaration (die
);
7323 clone
= clone_die (die
);
7325 slot
= htab_find_slot_with_hash (decl_table
, die
,
7326 htab_hash_pointer (die
), INSERT
);
7327 /* Assert that DIE isn't in the hash table yet. If it would be there
7328 before, the ancestors would be necessarily there as well, therefore
7329 clone_tree_partial wouldn't be called. */
7330 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7331 entry
= XCNEW (struct decl_table_entry
);
7333 entry
->copy
= clone
;
7336 if (die
->die_tag
!= DW_TAG_subprogram
)
7337 FOR_EACH_CHILD (die
, c
,
7338 add_child_die (clone
, clone_tree_partial (c
, decl_table
)));
7343 /* Walk the DIE and its children, looking for references to incomplete
7344 or trivial types that are unmarked (i.e., that are not in the current
7348 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7354 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7356 if (AT_class (a
) == dw_val_class_die_ref
)
7358 dw_die_ref targ
= AT_ref (a
);
7360 struct decl_table_entry
*entry
;
7362 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7365 slot
= htab_find_slot_with_hash (decl_table
, targ
,
7366 htab_hash_pointer (targ
), INSERT
);
7368 if (*slot
!= HTAB_EMPTY_ENTRY
)
7370 /* TARG has already been copied, so we just need to
7371 modify the reference to point to the copy. */
7372 entry
= (struct decl_table_entry
*) *slot
;
7373 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7377 dw_die_ref parent
= unit
;
7378 dw_die_ref copy
= clone_die (targ
);
7380 /* Record in DECL_TABLE that TARG has been copied.
7381 Need to do this now, before the recursive call,
7382 because DECL_TABLE may be expanded and SLOT
7383 would no longer be a valid pointer. */
7384 entry
= XCNEW (struct decl_table_entry
);
7389 /* If TARG is not a declaration DIE, we need to copy its
7391 if (!is_declaration_die (targ
))
7395 add_child_die (copy
,
7396 clone_tree_partial (c
, decl_table
)));
7399 /* Make sure the cloned tree is marked as part of the
7403 /* If TARG has surrounding context, copy its ancestor tree
7404 into the new type unit. */
7405 if (targ
->die_parent
!= NULL
7406 && !is_unit_die (targ
->die_parent
))
7407 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7410 add_child_die (parent
, copy
);
7411 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7413 /* Make sure the newly-copied DIE is walked. If it was
7414 installed in a previously-added context, it won't
7415 get visited otherwise. */
7418 /* Find the highest point of the newly-added tree,
7419 mark each node along the way, and walk from there. */
7420 parent
->die_mark
= 1;
7421 while (parent
->die_parent
7422 && parent
->die_parent
->die_mark
== 0)
7424 parent
= parent
->die_parent
;
7425 parent
->die_mark
= 1;
7427 copy_decls_walk (unit
, parent
, decl_table
);
7433 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7436 /* Copy declarations for "unworthy" types into the new comdat section.
7437 Incomplete types, modified types, and certain other types aren't broken
7438 out into comdat sections of their own, so they don't have a signature,
7439 and we need to copy the declaration into the same section so that we
7440 don't have an external reference. */
7443 copy_decls_for_unworthy_types (dw_die_ref unit
)
7448 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
7449 copy_decls_walk (unit
, unit
, decl_table
);
7450 htab_delete (decl_table
);
7454 /* Traverse the DIE and add a sibling attribute if it may have the
7455 effect of speeding up access to siblings. To save some space,
7456 avoid generating sibling attributes for DIE's without children. */
7459 add_sibling_attributes (dw_die_ref die
)
7463 if (! die
->die_child
)
7466 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7467 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7469 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7472 /* Output all location lists for the DIE and its children. */
7475 output_location_lists (dw_die_ref die
)
7481 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7482 if (AT_class (a
) == dw_val_class_loc_list
)
7483 output_loc_list (AT_loc_list (a
));
7485 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7488 /* We want to limit the number of external references, because they are
7489 larger than local references: a relocation takes multiple words, and
7490 even a sig8 reference is always eight bytes, whereas a local reference
7491 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7492 So if we encounter multiple external references to the same type DIE, we
7493 make a local typedef stub for it and redirect all references there.
7495 This is the element of the hash table for keeping track of these
7505 /* Hash an external_ref. */
7508 hash_external_ref (const void *p
)
7510 const struct external_ref
*r
= (const struct external_ref
*)p
;
7511 dw_die_ref die
= r
->type
;
7514 if (! die
->comdat_type_p
)
7515 h
= htab_hash_string (die
->die_id
.die_symbol
);
7518 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7519 memcpy (&h
, type_node
->signature
, sizeof (h
));
7524 /* Compare external_refs. */
7527 external_ref_eq (const void *p1
, const void *p2
)
7529 const struct external_ref
*r1
= (const struct external_ref
*)p1
;
7530 const struct external_ref
*r2
= (const struct external_ref
*)p2
;
7531 return r1
->type
== r2
->type
;
7534 /* Return a pointer to the external_ref for references to DIE. */
7536 static struct external_ref
*
7537 lookup_external_ref (htab_t map
, dw_die_ref die
)
7539 struct external_ref ref
, *ref_p
;
7543 slot
= htab_find_slot (map
, &ref
, INSERT
);
7544 if (*slot
!= HTAB_EMPTY_ENTRY
)
7545 return (struct external_ref
*) *slot
;
7547 ref_p
= XCNEW (struct external_ref
);
7553 /* Subroutine of optimize_external_refs, below.
7555 If we see a type skeleton, record it as our stub. If we see external
7556 references, remember how many we've seen. */
7559 optimize_external_refs_1 (dw_die_ref die
, htab_t map
)
7564 struct external_ref
*ref_p
;
7566 if (is_type_die (die
)
7567 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7569 /* This is a local skeleton; use it for local references. */
7570 ref_p
= lookup_external_ref (map
, c
);
7574 /* Scan the DIE references, and remember any that refer to DIEs from
7575 other CUs (i.e. those which are not marked). */
7576 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7577 if (AT_class (a
) == dw_val_class_die_ref
7578 && (c
= AT_ref (a
))->die_mark
== 0
7581 ref_p
= lookup_external_ref (map
, c
);
7585 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7588 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7589 points to an external_ref, DATA is the CU we're processing. If we don't
7590 already have a local stub, and we have multiple refs, build a stub. */
7593 build_local_stub (void **slot
, void *data
)
7595 struct external_ref
*ref_p
= (struct external_ref
*)*slot
;
7597 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7599 /* We have multiple references to this type, so build a small stub.
7600 Both of these forms are a bit dodgy from the perspective of the
7601 DWARF standard, since technically they should have names. */
7602 dw_die_ref cu
= (dw_die_ref
) data
;
7603 dw_die_ref type
= ref_p
->type
;
7604 dw_die_ref stub
= NULL
;
7606 if (type
->comdat_type_p
)
7608 /* If we refer to this type via sig8, use AT_signature. */
7609 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7610 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7614 /* Otherwise, use a typedef with no name. */
7615 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7616 add_AT_die_ref (stub
, DW_AT_type
, type
);
7625 /* DIE is a unit; look through all the DIE references to see if there are
7626 any external references to types, and if so, create local stubs for
7627 them which will be applied in build_abbrev_table. This is useful because
7628 references to local DIEs are smaller. */
7631 optimize_external_refs (dw_die_ref die
)
7633 htab_t map
= htab_create (10, hash_external_ref
, external_ref_eq
, free
);
7634 optimize_external_refs_1 (die
, map
);
7635 htab_traverse (map
, build_local_stub
, die
);
7639 /* The format of each DIE (and its attribute value pairs) is encoded in an
7640 abbreviation table. This routine builds the abbreviation table and assigns
7641 a unique abbreviation id for each abbreviation entry. The children of each
7642 die are visited recursively. */
7645 build_abbrev_table (dw_die_ref die
, htab_t extern_map
)
7647 unsigned long abbrev_id
;
7648 unsigned int n_alloc
;
7653 /* Scan the DIE references, and replace any that refer to
7654 DIEs from other CUs (i.e. those which are not marked) with
7655 the local stubs we built in optimize_external_refs. */
7656 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7657 if (AT_class (a
) == dw_val_class_die_ref
7658 && (c
= AT_ref (a
))->die_mark
== 0)
7660 struct external_ref
*ref_p
;
7661 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7663 ref_p
= lookup_external_ref (extern_map
, c
);
7664 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7665 change_AT_die_ref (a
, ref_p
->stub
);
7667 /* We aren't changing this reference, so mark it external. */
7668 set_AT_ref_external (a
, 1);
7671 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7673 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7674 dw_attr_ref die_a
, abbrev_a
;
7678 if (abbrev
->die_tag
!= die
->die_tag
)
7680 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7683 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7686 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7688 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7689 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7690 || (value_format (abbrev_a
) != value_format (die_a
)))
7700 if (abbrev_id
>= abbrev_die_table_in_use
)
7702 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7704 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7705 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7708 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7709 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7710 abbrev_die_table_allocated
= n_alloc
;
7713 ++abbrev_die_table_in_use
;
7714 abbrev_die_table
[abbrev_id
] = die
;
7717 die
->die_abbrev
= abbrev_id
;
7718 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7721 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7724 constant_size (unsigned HOST_WIDE_INT value
)
7731 log
= floor_log2 (value
);
7734 log
= 1 << (floor_log2 (log
) + 1);
7739 /* Return the size of a DIE as it is represented in the
7740 .debug_info section. */
7742 static unsigned long
7743 size_of_die (dw_die_ref die
)
7745 unsigned long size
= 0;
7748 enum dwarf_form form
;
7750 size
+= size_of_uleb128 (die
->die_abbrev
);
7751 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7753 switch (AT_class (a
))
7755 case dw_val_class_addr
:
7756 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7758 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7759 size
+= size_of_uleb128 (AT_index (a
));
7762 size
+= DWARF2_ADDR_SIZE
;
7764 case dw_val_class_offset
:
7765 size
+= DWARF_OFFSET_SIZE
;
7767 case dw_val_class_loc
:
7769 unsigned long lsize
= size_of_locs (AT_loc (a
));
7772 if (dwarf_version
>= 4)
7773 size
+= size_of_uleb128 (lsize
);
7775 size
+= constant_size (lsize
);
7779 case dw_val_class_loc_list
:
7780 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7782 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7783 size
+= size_of_uleb128 (AT_index (a
));
7786 size
+= DWARF_OFFSET_SIZE
;
7788 case dw_val_class_range_list
:
7789 size
+= DWARF_OFFSET_SIZE
;
7791 case dw_val_class_const
:
7792 size
+= size_of_sleb128 (AT_int (a
));
7794 case dw_val_class_unsigned_const
:
7796 int csize
= constant_size (AT_unsigned (a
));
7797 if (dwarf_version
== 3
7798 && a
->dw_attr
== DW_AT_data_member_location
7800 size
+= size_of_uleb128 (AT_unsigned (a
));
7805 case dw_val_class_const_double
:
7806 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7807 if (HOST_BITS_PER_WIDE_INT
>= 64)
7810 case dw_val_class_vec
:
7811 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7812 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7813 + a
->dw_attr_val
.v
.val_vec
.length
7814 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7816 case dw_val_class_flag
:
7817 if (dwarf_version
>= 4)
7818 /* Currently all add_AT_flag calls pass in 1 as last argument,
7819 so DW_FORM_flag_present can be used. If that ever changes,
7820 we'll need to use DW_FORM_flag and have some optimization
7821 in build_abbrev_table that will change those to
7822 DW_FORM_flag_present if it is set to 1 in all DIEs using
7823 the same abbrev entry. */
7824 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7828 case dw_val_class_die_ref
:
7829 if (AT_ref_external (a
))
7831 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7832 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7833 is sized by target address length, whereas in DWARF3
7834 it's always sized as an offset. */
7835 if (use_debug_types
)
7836 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7837 else if (dwarf_version
== 2)
7838 size
+= DWARF2_ADDR_SIZE
;
7840 size
+= DWARF_OFFSET_SIZE
;
7843 size
+= DWARF_OFFSET_SIZE
;
7845 case dw_val_class_fde_ref
:
7846 size
+= DWARF_OFFSET_SIZE
;
7848 case dw_val_class_lbl_id
:
7849 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7851 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7852 size
+= size_of_uleb128 (AT_index (a
));
7855 size
+= DWARF2_ADDR_SIZE
;
7857 case dw_val_class_lineptr
:
7858 case dw_val_class_macptr
:
7859 size
+= DWARF_OFFSET_SIZE
;
7861 case dw_val_class_str
:
7862 form
= AT_string_form (a
);
7863 if (form
== DW_FORM_strp
)
7864 size
+= DWARF_OFFSET_SIZE
;
7865 else if (form
== DW_FORM_GNU_str_index
)
7866 size
+= size_of_uleb128 (AT_index (a
));
7868 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7870 case dw_val_class_file
:
7871 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7873 case dw_val_class_data8
:
7876 case dw_val_class_vms_delta
:
7877 size
+= DWARF_OFFSET_SIZE
;
7879 case dw_val_class_high_pc
:
7880 size
+= DWARF2_ADDR_SIZE
;
7890 /* Size the debugging information associated with a given DIE. Visits the
7891 DIE's children recursively. Updates the global variable next_die_offset, on
7892 each time through. Uses the current value of next_die_offset to update the
7893 die_offset field in each DIE. */
7896 calc_die_sizes (dw_die_ref die
)
7900 gcc_assert (die
->die_offset
== 0
7901 || (unsigned long int) die
->die_offset
== next_die_offset
);
7902 die
->die_offset
= next_die_offset
;
7903 next_die_offset
+= size_of_die (die
);
7905 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7907 if (die
->die_child
!= NULL
)
7908 /* Count the null byte used to terminate sibling lists. */
7909 next_die_offset
+= 1;
7912 /* Size just the base type children at the start of the CU.
7913 This is needed because build_abbrev needs to size locs
7914 and sizing of type based stack ops needs to know die_offset
7915 values for the base types. */
7918 calc_base_type_die_sizes (void)
7920 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7922 dw_die_ref base_type
;
7923 #if ENABLE_ASSERT_CHECKING
7924 dw_die_ref prev
= comp_unit_die ()->die_child
;
7927 die_offset
+= size_of_die (comp_unit_die ());
7928 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7930 #if ENABLE_ASSERT_CHECKING
7931 gcc_assert (base_type
->die_offset
== 0
7932 && prev
->die_sib
== base_type
7933 && base_type
->die_child
== NULL
7934 && base_type
->die_abbrev
);
7937 base_type
->die_offset
= die_offset
;
7938 die_offset
+= size_of_die (base_type
);
7942 /* Set the marks for a die and its children. We do this so
7943 that we know whether or not a reference needs to use FORM_ref_addr; only
7944 DIEs in the same CU will be marked. We used to clear out the offset
7945 and use that as the flag, but ran into ordering problems. */
7948 mark_dies (dw_die_ref die
)
7952 gcc_assert (!die
->die_mark
);
7955 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7958 /* Clear the marks for a die and its children. */
7961 unmark_dies (dw_die_ref die
)
7965 if (! use_debug_types
)
7966 gcc_assert (die
->die_mark
);
7969 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7972 /* Clear the marks for a die, its children and referred dies. */
7975 unmark_all_dies (dw_die_ref die
)
7985 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7987 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7988 if (AT_class (a
) == dw_val_class_die_ref
)
7989 unmark_all_dies (AT_ref (a
));
7992 /* Calculate if the entry should appear in the final output file. It may be
7993 from a pruned a type. */
7996 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
7998 /* By limiting gnu pubnames to definitions only, gold can generate a
7999 gdb index without entries for declarations, which don't include
8000 enough information to be useful. */
8001 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8004 if (table
== pubname_table
)
8006 /* Enumerator names are part of the pubname table, but the
8007 parent DW_TAG_enumeration_type die may have been pruned.
8008 Don't output them if that is the case. */
8009 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8010 (p
->die
->die_parent
== NULL
8011 || !p
->die
->die_parent
->die_perennial_p
))
8014 /* Everything else in the pubname table is included. */
8018 /* The pubtypes table shouldn't include types that have been
8020 return (p
->die
->die_offset
!= 0
8021 || !flag_eliminate_unused_debug_types
);
8024 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8025 generated for the compilation unit. */
8027 static unsigned long
8028 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8033 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8035 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8036 FOR_EACH_VEC_ELT (*names
, i
, p
)
8037 if (include_pubname_in_output (names
, p
))
8038 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8040 size
+= DWARF_OFFSET_SIZE
;
8044 /* Return the size of the information in the .debug_aranges section. */
8046 static unsigned long
8047 size_of_aranges (void)
8051 size
= DWARF_ARANGES_HEADER_SIZE
;
8053 /* Count the address/length pair for this compilation unit. */
8054 if (text_section_used
)
8055 size
+= 2 * DWARF2_ADDR_SIZE
;
8056 if (cold_text_section_used
)
8057 size
+= 2 * DWARF2_ADDR_SIZE
;
8058 if (have_multiple_function_sections
)
8063 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8065 if (DECL_IGNORED_P (fde
->decl
))
8067 if (!fde
->in_std_section
)
8068 size
+= 2 * DWARF2_ADDR_SIZE
;
8069 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8070 size
+= 2 * DWARF2_ADDR_SIZE
;
8074 /* Count the two zero words used to terminated the address range table. */
8075 size
+= 2 * DWARF2_ADDR_SIZE
;
8079 /* Select the encoding of an attribute value. */
8081 static enum dwarf_form
8082 value_format (dw_attr_ref a
)
8084 switch (AT_class (a
))
8086 case dw_val_class_addr
:
8087 /* Only very few attributes allow DW_FORM_addr. */
8092 case DW_AT_entry_pc
:
8093 case DW_AT_trampoline
:
8094 return (AT_index (a
) == NOT_INDEXED
8095 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8099 switch (DWARF2_ADDR_SIZE
)
8102 return DW_FORM_data1
;
8104 return DW_FORM_data2
;
8106 return DW_FORM_data4
;
8108 return DW_FORM_data8
;
8112 case dw_val_class_range_list
:
8113 case dw_val_class_loc_list
:
8114 if (dwarf_version
>= 4)
8115 return DW_FORM_sec_offset
;
8117 case dw_val_class_vms_delta
:
8118 case dw_val_class_offset
:
8119 switch (DWARF_OFFSET_SIZE
)
8122 return DW_FORM_data4
;
8124 return DW_FORM_data8
;
8128 case dw_val_class_loc
:
8129 if (dwarf_version
>= 4)
8130 return DW_FORM_exprloc
;
8131 switch (constant_size (size_of_locs (AT_loc (a
))))
8134 return DW_FORM_block1
;
8136 return DW_FORM_block2
;
8138 return DW_FORM_block4
;
8142 case dw_val_class_const
:
8143 return DW_FORM_sdata
;
8144 case dw_val_class_unsigned_const
:
8145 switch (constant_size (AT_unsigned (a
)))
8148 return DW_FORM_data1
;
8150 return DW_FORM_data2
;
8152 /* In DWARF3 DW_AT_data_member_location with
8153 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8154 constant, so we need to use DW_FORM_udata if we need
8155 a large constant. */
8156 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8157 return DW_FORM_udata
;
8158 return DW_FORM_data4
;
8160 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8161 return DW_FORM_udata
;
8162 return DW_FORM_data8
;
8166 case dw_val_class_const_double
:
8167 switch (HOST_BITS_PER_WIDE_INT
)
8170 return DW_FORM_data2
;
8172 return DW_FORM_data4
;
8174 return DW_FORM_data8
;
8177 return DW_FORM_block1
;
8179 case dw_val_class_vec
:
8180 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8181 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8184 return DW_FORM_block1
;
8186 return DW_FORM_block2
;
8188 return DW_FORM_block4
;
8192 case dw_val_class_flag
:
8193 if (dwarf_version
>= 4)
8195 /* Currently all add_AT_flag calls pass in 1 as last argument,
8196 so DW_FORM_flag_present can be used. If that ever changes,
8197 we'll need to use DW_FORM_flag and have some optimization
8198 in build_abbrev_table that will change those to
8199 DW_FORM_flag_present if it is set to 1 in all DIEs using
8200 the same abbrev entry. */
8201 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8202 return DW_FORM_flag_present
;
8204 return DW_FORM_flag
;
8205 case dw_val_class_die_ref
:
8206 if (AT_ref_external (a
))
8207 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8210 case dw_val_class_fde_ref
:
8211 return DW_FORM_data
;
8212 case dw_val_class_lbl_id
:
8213 return (AT_index (a
) == NOT_INDEXED
8214 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8215 case dw_val_class_lineptr
:
8216 case dw_val_class_macptr
:
8217 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8218 case dw_val_class_str
:
8219 return AT_string_form (a
);
8220 case dw_val_class_file
:
8221 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8224 return DW_FORM_data1
;
8226 return DW_FORM_data2
;
8228 return DW_FORM_data4
;
8233 case dw_val_class_data8
:
8234 return DW_FORM_data8
;
8236 case dw_val_class_high_pc
:
8237 switch (DWARF2_ADDR_SIZE
)
8240 return DW_FORM_data1
;
8242 return DW_FORM_data2
;
8244 return DW_FORM_data4
;
8246 return DW_FORM_data8
;
8256 /* Output the encoding of an attribute value. */
8259 output_value_format (dw_attr_ref a
)
8261 enum dwarf_form form
= value_format (a
);
8263 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8266 /* Given a die and id, produce the appropriate abbreviations. */
8269 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8274 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8275 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8276 dwarf_tag_name (abbrev
->die_tag
));
8278 if (abbrev
->die_child
!= NULL
)
8279 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8281 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8283 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8285 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8286 dwarf_attr_name (a_attr
->dw_attr
));
8287 output_value_format (a_attr
);
8290 dw2_asm_output_data (1, 0, NULL
);
8291 dw2_asm_output_data (1, 0, NULL
);
8295 /* Output the .debug_abbrev section which defines the DIE abbreviation
8299 output_abbrev_section (void)
8301 unsigned long abbrev_id
;
8303 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8304 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8306 /* Terminate the table. */
8307 dw2_asm_output_data (1, 0, NULL
);
8310 /* Output a symbol we can use to refer to this DIE from another CU. */
8313 output_die_symbol (dw_die_ref die
)
8315 const char *sym
= die
->die_id
.die_symbol
;
8317 gcc_assert (!die
->comdat_type_p
);
8322 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8323 /* We make these global, not weak; if the target doesn't support
8324 .linkonce, it doesn't support combining the sections, so debugging
8326 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8328 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8331 /* Return a new location list, given the begin and end range, and the
8334 static inline dw_loc_list_ref
8335 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8336 const char *section
)
8338 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8340 retlist
->begin
= begin
;
8341 retlist
->begin_entry
= NULL
;
8343 retlist
->expr
= expr
;
8344 retlist
->section
= section
;
8349 /* Generate a new internal symbol for this location list node, if it
8350 hasn't got one yet. */
8353 gen_llsym (dw_loc_list_ref list
)
8355 gcc_assert (!list
->ll_symbol
);
8356 list
->ll_symbol
= gen_internal_sym ("LLST");
8359 /* Output the location list given to us. */
8362 output_loc_list (dw_loc_list_ref list_head
)
8364 dw_loc_list_ref curr
= list_head
;
8366 if (list_head
->emitted
)
8368 list_head
->emitted
= true;
8370 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8372 /* Walk the location list, and output each range + expression. */
8373 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8376 /* Don't output an entry that starts and ends at the same address. */
8377 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8379 size
= size_of_locs (curr
->expr
);
8380 /* If the expression is too large, drop it on the floor. We could
8381 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8382 in the expression, but >= 64KB expressions for a single value
8383 in a single range are unlikely very useful. */
8386 if (dwarf_split_debug_info
)
8388 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8389 "Location list start/length entry (%s)",
8390 list_head
->ll_symbol
);
8391 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8392 "Location list range start index (%s)",
8394 /* The length field is 4 bytes. If we ever need to support
8395 an 8-byte length, we can add a new DW_LLE code or fall back
8396 to DW_LLE_GNU_start_end_entry. */
8397 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8398 "Location list range length (%s)",
8399 list_head
->ll_symbol
);
8401 else if (!have_multiple_function_sections
)
8403 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8404 "Location list begin address (%s)",
8405 list_head
->ll_symbol
);
8406 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8407 "Location list end address (%s)",
8408 list_head
->ll_symbol
);
8412 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8413 "Location list begin address (%s)",
8414 list_head
->ll_symbol
);
8415 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8416 "Location list end address (%s)",
8417 list_head
->ll_symbol
);
8420 /* Output the block length for this list of location operations. */
8421 gcc_assert (size
<= 0xffff);
8422 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8424 output_loc_sequence (curr
->expr
, -1);
8427 if (dwarf_split_debug_info
)
8428 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8429 "Location list terminator (%s)",
8430 list_head
->ll_symbol
);
8433 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8434 "Location list terminator begin (%s)",
8435 list_head
->ll_symbol
);
8436 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8437 "Location list terminator end (%s)",
8438 list_head
->ll_symbol
);
8442 /* Output a range_list offset into the debug_range section. Emit a
8443 relocated reference if val_entry is NULL, otherwise, emit an
8444 indirect reference. */
8447 output_range_list_offset (dw_attr_ref a
)
8449 const char *name
= dwarf_attr_name (a
->dw_attr
);
8451 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8453 char *p
= strchr (ranges_section_label
, '\0');
8454 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8455 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8456 debug_ranges_section
, "%s", name
);
8460 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8461 "%s (offset from %s)", name
, ranges_section_label
);
8464 /* Output the offset into the debug_loc section. */
8467 output_loc_list_offset (dw_attr_ref a
)
8469 char *sym
= AT_loc_list (a
)->ll_symbol
;
8472 if (dwarf_split_debug_info
)
8473 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8474 "%s", dwarf_attr_name (a
->dw_attr
));
8476 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8477 "%s", dwarf_attr_name (a
->dw_attr
));
8480 /* Output an attribute's index or value appropriately. */
8483 output_attr_index_or_value (dw_attr_ref a
)
8485 const char *name
= dwarf_attr_name (a
->dw_attr
);
8487 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8489 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8492 switch (AT_class (a
))
8494 case dw_val_class_addr
:
8495 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8497 case dw_val_class_high_pc
:
8498 case dw_val_class_lbl_id
:
8499 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8501 case dw_val_class_loc_list
:
8502 output_loc_list_offset (a
);
8509 /* Output a type signature. */
8512 output_signature (const char *sig
, const char *name
)
8516 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8517 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8520 /* Output the DIE and its attributes. Called recursively to generate
8521 the definitions of each child DIE. */
8524 output_die (dw_die_ref die
)
8531 /* If someone in another CU might refer to us, set up a symbol for
8532 them to point to. */
8533 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8534 output_die_symbol (die
);
8536 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8537 (unsigned long)die
->die_offset
,
8538 dwarf_tag_name (die
->die_tag
));
8540 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8542 const char *name
= dwarf_attr_name (a
->dw_attr
);
8544 switch (AT_class (a
))
8546 case dw_val_class_addr
:
8547 output_attr_index_or_value (a
);
8550 case dw_val_class_offset
:
8551 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8555 case dw_val_class_range_list
:
8556 output_range_list_offset (a
);
8559 case dw_val_class_loc
:
8560 size
= size_of_locs (AT_loc (a
));
8562 /* Output the block length for this list of location operations. */
8563 if (dwarf_version
>= 4)
8564 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8566 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8568 output_loc_sequence (AT_loc (a
), -1);
8571 case dw_val_class_const
:
8572 /* ??? It would be slightly more efficient to use a scheme like is
8573 used for unsigned constants below, but gdb 4.x does not sign
8574 extend. Gdb 5.x does sign extend. */
8575 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8578 case dw_val_class_unsigned_const
:
8580 int csize
= constant_size (AT_unsigned (a
));
8581 if (dwarf_version
== 3
8582 && a
->dw_attr
== DW_AT_data_member_location
8584 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8586 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8590 case dw_val_class_const_double
:
8592 unsigned HOST_WIDE_INT first
, second
;
8594 if (HOST_BITS_PER_WIDE_INT
>= 64)
8595 dw2_asm_output_data (1,
8596 HOST_BITS_PER_DOUBLE_INT
8597 / HOST_BITS_PER_CHAR
,
8600 if (WORDS_BIG_ENDIAN
)
8602 first
= a
->dw_attr_val
.v
.val_double
.high
;
8603 second
= a
->dw_attr_val
.v
.val_double
.low
;
8607 first
= a
->dw_attr_val
.v
.val_double
.low
;
8608 second
= a
->dw_attr_val
.v
.val_double
.high
;
8611 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8613 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8618 case dw_val_class_vec
:
8620 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8621 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8625 dw2_asm_output_data (constant_size (len
* elt_size
),
8626 len
* elt_size
, "%s", name
);
8627 if (elt_size
> sizeof (HOST_WIDE_INT
))
8632 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8635 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8636 "fp or vector constant word %u", i
);
8640 case dw_val_class_flag
:
8641 if (dwarf_version
>= 4)
8643 /* Currently all add_AT_flag calls pass in 1 as last argument,
8644 so DW_FORM_flag_present can be used. If that ever changes,
8645 we'll need to use DW_FORM_flag and have some optimization
8646 in build_abbrev_table that will change those to
8647 DW_FORM_flag_present if it is set to 1 in all DIEs using
8648 the same abbrev entry. */
8649 gcc_assert (AT_flag (a
) == 1);
8651 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8652 ASM_COMMENT_START
, name
);
8655 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8658 case dw_val_class_loc_list
:
8659 output_attr_index_or_value (a
);
8662 case dw_val_class_die_ref
:
8663 if (AT_ref_external (a
))
8665 if (AT_ref (a
)->comdat_type_p
)
8667 comdat_type_node_ref type_node
=
8668 AT_ref (a
)->die_id
.die_type_node
;
8670 gcc_assert (type_node
);
8671 output_signature (type_node
->signature
, name
);
8675 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8679 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8680 length, whereas in DWARF3 it's always sized as an
8682 if (dwarf_version
== 2)
8683 size
= DWARF2_ADDR_SIZE
;
8685 size
= DWARF_OFFSET_SIZE
;
8686 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8692 gcc_assert (AT_ref (a
)->die_offset
);
8693 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8698 case dw_val_class_fde_ref
:
8702 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8703 a
->dw_attr_val
.v
.val_fde_index
* 2);
8704 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8709 case dw_val_class_vms_delta
:
8710 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8711 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8715 case dw_val_class_lbl_id
:
8716 output_attr_index_or_value (a
);
8719 case dw_val_class_lineptr
:
8720 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8721 debug_line_section
, "%s", name
);
8724 case dw_val_class_macptr
:
8725 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8726 debug_macinfo_section
, "%s", name
);
8729 case dw_val_class_str
:
8730 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8731 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8732 a
->dw_attr_val
.v
.val_str
->label
,
8734 "%s: \"%s\"", name
, AT_string (a
));
8735 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8736 dw2_asm_output_data_uleb128 (AT_index (a
),
8737 "%s: \"%s\"", name
, AT_string (a
));
8739 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8742 case dw_val_class_file
:
8744 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8746 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8747 a
->dw_attr_val
.v
.val_file
->filename
);
8751 case dw_val_class_data8
:
8755 for (i
= 0; i
< 8; i
++)
8756 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8757 i
== 0 ? "%s" : NULL
, name
);
8761 case dw_val_class_high_pc
:
8762 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8763 get_AT_low_pc (die
), "DW_AT_high_pc");
8771 FOR_EACH_CHILD (die
, c
, output_die (c
));
8773 /* Add null byte to terminate sibling list. */
8774 if (die
->die_child
!= NULL
)
8775 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8776 (unsigned long) die
->die_offset
);
8779 /* Output the compilation unit that appears at the beginning of the
8780 .debug_info section, and precedes the DIE descriptions. */
8783 output_compilation_unit_header (void)
8785 int ver
= dwarf_version
;
8787 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8788 dw2_asm_output_data (4, 0xffffffff,
8789 "Initial length escape value indicating 64-bit DWARF extension");
8790 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8791 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8792 "Length of Compilation Unit Info");
8793 dw2_asm_output_data (2, ver
, "DWARF version number");
8794 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8795 debug_abbrev_section
,
8796 "Offset Into Abbrev. Section");
8797 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8800 /* Output the compilation unit DIE and its children. */
8803 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8805 const char *secname
, *oldsym
;
8809 /* Unless we are outputting main CU, we may throw away empty ones. */
8810 if (!output_if_empty
&& die
->die_child
== NULL
)
8813 /* Even if there are no children of this DIE, we must output the information
8814 about the compilation unit. Otherwise, on an empty translation unit, we
8815 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8816 will then complain when examining the file. First mark all the DIEs in
8817 this CU so we know which get local refs. */
8820 extern_map
= optimize_external_refs (die
);
8822 build_abbrev_table (die
, extern_map
);
8824 htab_delete (extern_map
);
8826 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8827 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8828 calc_die_sizes (die
);
8830 oldsym
= die
->die_id
.die_symbol
;
8833 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8835 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8837 die
->die_id
.die_symbol
= NULL
;
8838 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8842 switch_to_section (debug_info_section
);
8843 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8844 info_section_emitted
= true;
8847 /* Output debugging information. */
8848 output_compilation_unit_header ();
8851 /* Leave the marks on the main CU, so we can check them in
8856 die
->die_id
.die_symbol
= oldsym
;
8860 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8861 and .debug_pubtypes. This is configured per-target, but can be
8862 overridden by the -gpubnames or -gno-pubnames options. */
8865 want_pubnames (void)
8867 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8869 if (debug_generate_pub_sections
!= -1)
8870 return debug_generate_pub_sections
;
8871 return targetm
.want_debug_pub_sections
;
8874 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8877 add_AT_pubnames (dw_die_ref die
)
8879 if (want_pubnames ())
8880 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8883 /* Add a string attribute value to a skeleton DIE. */
8886 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8890 struct indirect_string_node
*node
;
8892 if (! skeleton_debug_str_hash
)
8893 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
8894 debug_str_eq
, NULL
);
8896 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
8897 find_string_form (node
);
8898 if (node
->form
== DW_FORM_GNU_str_index
)
8899 node
->form
= DW_FORM_strp
;
8901 attr
.dw_attr
= attr_kind
;
8902 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
8903 attr
.dw_attr_val
.val_entry
= NULL
;
8904 attr
.dw_attr_val
.v
.val_str
= node
;
8905 add_dwarf_attr (die
, &attr
);
8908 /* Helper function to generate top-level dies for skeleton debug_info and
8912 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8914 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8915 const char *comp_dir
= comp_dir_string ();
8917 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8918 if (comp_dir
!= NULL
)
8919 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
8920 add_AT_pubnames (die
);
8921 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8924 /* Return the single type-unit die for skeleton type units. */
8927 get_skeleton_type_unit (void)
8929 /* For dwarf_split_debug_sections with use_type info, all type units in the
8930 skeleton sections have identical dies (but different headers). This
8931 single die will be output many times. */
8933 static dw_die_ref skeleton_type_unit
= NULL
;
8935 if (skeleton_type_unit
== NULL
)
8937 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8938 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8939 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8941 return skeleton_type_unit
;
8944 /* Output skeleton debug sections that point to the dwo file. */
8947 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8949 /* These attributes will be found in the full debug_info section. */
8950 remove_AT (comp_unit
, DW_AT_producer
);
8951 remove_AT (comp_unit
, DW_AT_language
);
8953 switch_to_section (debug_skeleton_info_section
);
8954 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8956 /* Produce the skeleton compilation-unit header. This one differs enough from
8957 a normal CU header that it's better not to call output_compilation_unit
8959 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8960 dw2_asm_output_data (4, 0xffffffff,
8961 "Initial length escape value indicating 64-bit DWARF extension");
8963 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8964 DWARF_COMPILE_UNIT_HEADER_SIZE
8965 - DWARF_INITIAL_LENGTH_SIZE
8966 + size_of_die (comp_unit
),
8967 "Length of Compilation Unit Info");
8968 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8969 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8970 debug_abbrev_section
,
8971 "Offset Into Abbrev. Section");
8972 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8974 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8975 output_die (comp_unit
);
8977 /* Build the skeleton debug_abbrev section. */
8978 switch_to_section (debug_skeleton_abbrev_section
);
8979 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8981 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8982 if (use_debug_types
)
8983 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8985 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8988 /* Output a comdat type unit DIE and its children. */
8991 output_comdat_type_unit (comdat_type_node
*node
)
8993 const char *secname
;
8996 #if defined (OBJECT_FORMAT_ELF)
9001 /* First mark all the DIEs in this CU so we know which get local refs. */
9002 mark_dies (node
->root_die
);
9004 extern_map
= optimize_external_refs (node
->root_die
);
9006 build_abbrev_table (node
->root_die
, extern_map
);
9008 htab_delete (extern_map
);
9010 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9011 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9012 calc_die_sizes (node
->root_die
);
9014 #if defined (OBJECT_FORMAT_ELF)
9015 if (!dwarf_split_debug_info
)
9016 secname
= ".debug_types";
9018 secname
= ".debug_types.dwo";
9020 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9021 sprintf (tmp
, "wt.");
9022 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9023 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9024 comdat_key
= get_identifier (tmp
);
9025 targetm
.asm_out
.named_section (secname
,
9026 SECTION_DEBUG
| SECTION_LINKONCE
,
9029 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9030 sprintf (tmp
, ".gnu.linkonce.wt.");
9031 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9032 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9034 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9037 /* Output debugging information. */
9038 output_compilation_unit_header ();
9039 output_signature (node
->signature
, "Type Signature");
9040 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9041 "Offset to Type DIE");
9042 output_die (node
->root_die
);
9044 unmark_dies (node
->root_die
);
9046 #if defined (OBJECT_FORMAT_ELF)
9047 if (dwarf_split_debug_info
)
9049 /* Produce the skeleton type-unit header. */
9050 const char *secname
= ".debug_types";
9052 targetm
.asm_out
.named_section (secname
,
9053 SECTION_DEBUG
| SECTION_LINKONCE
,
9055 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9056 dw2_asm_output_data (4, 0xffffffff,
9057 "Initial length escape value indicating 64-bit DWARF extension");
9059 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9060 DWARF_COMPILE_UNIT_HEADER_SIZE
9061 - DWARF_INITIAL_LENGTH_SIZE
9062 + size_of_die (get_skeleton_type_unit ())
9063 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
9064 "Length of Type Unit Info");
9065 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9066 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9067 debug_skeleton_abbrev_section_label
,
9068 debug_abbrev_section
,
9069 "Offset Into Abbrev. Section");
9070 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9071 output_signature (node
->signature
, "Type Signature");
9072 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
9074 output_die (get_skeleton_type_unit ());
9079 /* Return the DWARF2/3 pubname associated with a decl. */
9082 dwarf2_name (tree decl
, int scope
)
9084 if (DECL_NAMELESS (decl
))
9086 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9089 /* Add a new entry to .debug_pubnames if appropriate. */
9092 add_pubname_string (const char *str
, dw_die_ref die
)
9097 e
.name
= xstrdup (str
);
9098 vec_safe_push (pubname_table
, e
);
9102 add_pubname (tree decl
, dw_die_ref die
)
9104 if (!want_pubnames ())
9107 /* Don't add items to the table when we expect that the consumer will have
9108 just read the enclosing die. For example, if the consumer is looking at a
9109 class_member, it will either be inside the class already, or will have just
9110 looked up the class to find the member. Either way, searching the class is
9111 faster than searching the index. */
9112 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9113 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9115 const char *name
= dwarf2_name (decl
, 1);
9118 add_pubname_string (name
, die
);
9122 /* Add an enumerator to the pubnames section. */
9125 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9129 gcc_assert (scope_name
);
9130 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9132 vec_safe_push (pubname_table
, e
);
9135 /* Add a new entry to .debug_pubtypes if appropriate. */
9138 add_pubtype (tree decl
, dw_die_ref die
)
9142 if (!want_pubnames ())
9145 if ((TREE_PUBLIC (decl
)
9146 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9147 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9150 const char *scope_name
= "";
9151 const char *sep
= is_cxx () ? "::" : ".";
9154 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9155 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9157 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9158 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9159 scope_name
= concat (scope_name
, sep
, NULL
);
9165 name
= type_tag (decl
);
9167 name
= lang_hooks
.dwarf_name (decl
, 1);
9169 /* If we don't have a name for the type, there's no point in adding
9171 if (name
!= NULL
&& name
[0] != '\0')
9174 e
.name
= concat (scope_name
, name
, NULL
);
9175 vec_safe_push (pubtype_table
, e
);
9178 /* Although it might be more consistent to add the pubinfo for the
9179 enumerators as their dies are created, they should only be added if the
9180 enum type meets the criteria above. So rather than re-check the parent
9181 enum type whenever an enumerator die is created, just output them all
9182 here. This isn't protected by the name conditional because anonymous
9183 enums don't have names. */
9184 if (die
->die_tag
== DW_TAG_enumeration_type
)
9188 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9193 /* Output a single entry in the pubnames table. */
9196 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9198 dw_die_ref die
= entry
->die
;
9199 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9201 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9203 if (debug_generate_pub_sections
== 2)
9205 /* This logic follows gdb's method for determining the value of the flag
9207 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9208 switch (die
->die_tag
)
9210 case DW_TAG_typedef
:
9211 case DW_TAG_base_type
:
9212 case DW_TAG_subrange_type
:
9213 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9214 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9216 case DW_TAG_enumerator
:
9217 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9218 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9219 if (!is_cxx () && !is_java ())
9220 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9222 case DW_TAG_subprogram
:
9223 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9224 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9226 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9228 case DW_TAG_constant
:
9229 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9230 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9231 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9233 case DW_TAG_variable
:
9234 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9235 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9236 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9238 case DW_TAG_namespace
:
9239 case DW_TAG_imported_declaration
:
9240 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9242 case DW_TAG_class_type
:
9243 case DW_TAG_interface_type
:
9244 case DW_TAG_structure_type
:
9245 case DW_TAG_union_type
:
9246 case DW_TAG_enumeration_type
:
9247 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9248 if (!is_cxx () && !is_java ())
9249 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9252 /* An unusual tag. Leave the flag-byte empty. */
9255 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9259 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9263 /* Output the public names table used to speed up access to externally
9264 visible names; or the public types table used to find type definitions. */
9267 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9270 unsigned long pubnames_length
= size_of_pubnames (names
);
9273 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9274 dw2_asm_output_data (4, 0xffffffff,
9275 "Initial length escape value indicating 64-bit DWARF extension");
9276 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9278 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9279 dw2_asm_output_data (2, 2, "DWARF Version");
9281 if (dwarf_split_debug_info
)
9282 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9283 debug_skeleton_info_section
,
9284 "Offset of Compilation Unit Info");
9286 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9288 "Offset of Compilation Unit Info");
9289 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9290 "Compilation Unit Length");
9292 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9294 if (include_pubname_in_output (names
, pub
))
9296 dw_offset die_offset
= pub
->die
->die_offset
;
9298 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9299 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9300 gcc_assert (pub
->die
->die_mark
);
9302 /* If we're putting types in their own .debug_types sections,
9303 the .debug_pubtypes table will still point to the compile
9304 unit (not the type unit), so we want to use the offset of
9305 the skeleton DIE (if there is one). */
9306 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9308 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9310 if (type_node
!= NULL
)
9311 die_offset
= (type_node
->skeleton_die
!= NULL
9312 ? type_node
->skeleton_die
->die_offset
9313 : comp_unit_die ()->die_offset
);
9316 output_pubname (die_offset
, pub
);
9320 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9323 /* Output public names and types tables if necessary. */
9326 output_pubtables (void)
9328 if (!want_pubnames () || !info_section_emitted
)
9331 switch_to_section (debug_pubnames_section
);
9332 output_pubnames (pubname_table
);
9333 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9334 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9335 simply won't look for the section. */
9336 switch_to_section (debug_pubtypes_section
);
9337 output_pubnames (pubtype_table
);
9341 /* Output the information that goes into the .debug_aranges table.
9342 Namely, define the beginning and ending address range of the
9343 text section generated for this compilation unit. */
9346 output_aranges (unsigned long aranges_length
)
9350 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9351 dw2_asm_output_data (4, 0xffffffff,
9352 "Initial length escape value indicating 64-bit DWARF extension");
9353 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9354 "Length of Address Ranges Info");
9355 /* Version number for aranges is still 2, even in DWARF3. */
9356 dw2_asm_output_data (2, 2, "DWARF Version");
9357 if (dwarf_split_debug_info
)
9358 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9359 debug_skeleton_info_section
,
9360 "Offset of Compilation Unit Info");
9362 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9364 "Offset of Compilation Unit Info");
9365 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9366 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9368 /* We need to align to twice the pointer size here. */
9369 if (DWARF_ARANGES_PAD_SIZE
)
9371 /* Pad using a 2 byte words so that padding is correct for any
9373 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9374 2 * DWARF2_ADDR_SIZE
);
9375 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9376 dw2_asm_output_data (2, 0, NULL
);
9379 /* It is necessary not to output these entries if the sections were
9380 not used; if the sections were not used, the length will be 0 and
9381 the address may end up as 0 if the section is discarded by ld
9382 --gc-sections, leaving an invalid (0, 0) entry that can be
9383 confused with the terminator. */
9384 if (text_section_used
)
9386 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9387 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9388 text_section_label
, "Length");
9390 if (cold_text_section_used
)
9392 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9394 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9395 cold_text_section_label
, "Length");
9398 if (have_multiple_function_sections
)
9403 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9405 if (DECL_IGNORED_P (fde
->decl
))
9407 if (!fde
->in_std_section
)
9409 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9411 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9412 fde
->dw_fde_begin
, "Length");
9414 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9416 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9418 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9419 fde
->dw_fde_second_begin
, "Length");
9424 /* Output the terminator words. */
9425 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9426 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9429 /* Add a new entry to .debug_ranges. Return the offset at which it
9433 add_ranges_num (int num
)
9435 unsigned int in_use
= ranges_table_in_use
;
9437 if (in_use
== ranges_table_allocated
)
9439 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9440 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9441 ranges_table_allocated
);
9442 memset (ranges_table
+ ranges_table_in_use
, 0,
9443 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9446 ranges_table
[in_use
].num
= num
;
9447 ranges_table_in_use
= in_use
+ 1;
9449 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9452 /* Add a new entry to .debug_ranges corresponding to a block, or a
9453 range terminator if BLOCK is NULL. */
9456 add_ranges (const_tree block
)
9458 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9461 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9462 When using dwarf_split_debug_info, address attributes in dies destined
9463 for the final executable should be direct references--setting the
9464 parameter force_direct ensures this behavior. */
9467 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9468 bool *added
, bool force_direct
)
9470 unsigned int in_use
= ranges_by_label_in_use
;
9471 unsigned int offset
;
9473 if (in_use
== ranges_by_label_allocated
)
9475 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9476 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9478 ranges_by_label_allocated
);
9479 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9480 RANGES_TABLE_INCREMENT
9481 * sizeof (struct dw_ranges_by_label_struct
));
9484 ranges_by_label
[in_use
].begin
= begin
;
9485 ranges_by_label
[in_use
].end
= end
;
9486 ranges_by_label_in_use
= in_use
+ 1;
9488 offset
= add_ranges_num (-(int)in_use
- 1);
9491 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9497 output_ranges (void)
9500 static const char *const start_fmt
= "Offset %#x";
9501 const char *fmt
= start_fmt
;
9503 for (i
= 0; i
< ranges_table_in_use
; i
++)
9505 int block_num
= ranges_table
[i
].num
;
9509 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9510 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9512 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9513 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9515 /* If all code is in the text section, then the compilation
9516 unit base address defaults to DW_AT_low_pc, which is the
9517 base of the text section. */
9518 if (!have_multiple_function_sections
)
9520 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9522 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9523 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9524 text_section_label
, NULL
);
9527 /* Otherwise, the compilation unit base address is zero,
9528 which allows us to use absolute addresses, and not worry
9529 about whether the target supports cross-section
9533 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9534 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9535 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9541 /* Negative block_num stands for an index into ranges_by_label. */
9542 else if (block_num
< 0)
9544 int lab_idx
= - block_num
- 1;
9546 if (!have_multiple_function_sections
)
9550 /* If we ever use add_ranges_by_labels () for a single
9551 function section, all we have to do is to take out
9553 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9554 ranges_by_label
[lab_idx
].begin
,
9556 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9557 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9558 ranges_by_label
[lab_idx
].end
,
9559 text_section_label
, NULL
);
9564 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9565 ranges_by_label
[lab_idx
].begin
,
9566 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9567 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9568 ranges_by_label
[lab_idx
].end
,
9574 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9575 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9581 /* Data structure containing information about input files. */
9584 const char *path
; /* Complete file name. */
9585 const char *fname
; /* File name part. */
9586 int length
; /* Length of entire string. */
9587 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9588 int dir_idx
; /* Index in directory table. */
9591 /* Data structure containing information about directories with source
9595 const char *path
; /* Path including directory name. */
9596 int length
; /* Path length. */
9597 int prefix
; /* Index of directory entry which is a prefix. */
9598 int count
; /* Number of files in this directory. */
9599 int dir_idx
; /* Index of directory used as base. */
9602 /* Callback function for file_info comparison. We sort by looking at
9603 the directories in the path. */
9606 file_info_cmp (const void *p1
, const void *p2
)
9608 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9609 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9610 const unsigned char *cp1
;
9611 const unsigned char *cp2
;
9613 /* Take care of file names without directories. We need to make sure that
9614 we return consistent values to qsort since some will get confused if
9615 we return the same value when identical operands are passed in opposite
9616 orders. So if neither has a directory, return 0 and otherwise return
9617 1 or -1 depending on which one has the directory. */
9618 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9619 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9621 cp1
= (const unsigned char *) s1
->path
;
9622 cp2
= (const unsigned char *) s2
->path
;
9628 /* Reached the end of the first path? If so, handle like above. */
9629 if ((cp1
== (const unsigned char *) s1
->fname
)
9630 || (cp2
== (const unsigned char *) s2
->fname
))
9631 return ((cp2
== (const unsigned char *) s2
->fname
)
9632 - (cp1
== (const unsigned char *) s1
->fname
));
9634 /* Character of current path component the same? */
9635 else if (*cp1
!= *cp2
)
9640 struct file_name_acquire_data
9642 struct file_info
*files
;
9647 /* Traversal function for the hash table. */
9650 file_name_acquire (void ** slot
, void *data
)
9652 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9653 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9654 struct file_info
*fi
;
9657 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9659 if (! d
->emitted_number
)
9662 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9664 fi
= fnad
->files
+ fnad
->used_files
++;
9666 /* Skip all leading "./". */
9668 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9671 /* Create a new array entry. */
9673 fi
->length
= strlen (f
);
9676 /* Search for the file name part. */
9677 f
= strrchr (f
, DIR_SEPARATOR
);
9678 #if defined (DIR_SEPARATOR_2)
9680 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9684 if (f
== NULL
|| f
< g
)
9690 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9694 /* Output the directory table and the file name table. We try to minimize
9695 the total amount of memory needed. A heuristic is used to avoid large
9696 slowdowns with many input files. */
9699 output_file_names (void)
9701 struct file_name_acquire_data fnad
;
9703 struct file_info
*files
;
9704 struct dir_info
*dirs
;
9712 if (!last_emitted_file
)
9714 dw2_asm_output_data (1, 0, "End directory table");
9715 dw2_asm_output_data (1, 0, "End file name table");
9719 numfiles
= last_emitted_file
->emitted_number
;
9721 /* Allocate the various arrays we need. */
9722 files
= XALLOCAVEC (struct file_info
, numfiles
);
9723 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9726 fnad
.used_files
= 0;
9727 fnad
.max_files
= numfiles
;
9728 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9729 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9731 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9733 /* Find all the different directories used. */
9734 dirs
[0].path
= files
[0].path
;
9735 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9736 dirs
[0].prefix
= -1;
9738 dirs
[0].dir_idx
= 0;
9739 files
[0].dir_idx
= 0;
9742 for (i
= 1; i
< numfiles
; i
++)
9743 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9744 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9745 dirs
[ndirs
- 1].length
) == 0)
9747 /* Same directory as last entry. */
9748 files
[i
].dir_idx
= ndirs
- 1;
9749 ++dirs
[ndirs
- 1].count
;
9755 /* This is a new directory. */
9756 dirs
[ndirs
].path
= files
[i
].path
;
9757 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9758 dirs
[ndirs
].count
= 1;
9759 dirs
[ndirs
].dir_idx
= ndirs
;
9760 files
[i
].dir_idx
= ndirs
;
9762 /* Search for a prefix. */
9763 dirs
[ndirs
].prefix
= -1;
9764 for (j
= 0; j
< ndirs
; j
++)
9765 if (dirs
[j
].length
< dirs
[ndirs
].length
9766 && dirs
[j
].length
> 1
9767 && (dirs
[ndirs
].prefix
== -1
9768 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9769 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9770 dirs
[ndirs
].prefix
= j
;
9775 /* Now to the actual work. We have to find a subset of the directories which
9776 allow expressing the file name using references to the directory table
9777 with the least amount of characters. We do not do an exhaustive search
9778 where we would have to check out every combination of every single
9779 possible prefix. Instead we use a heuristic which provides nearly optimal
9780 results in most cases and never is much off. */
9781 saved
= XALLOCAVEC (int, ndirs
);
9782 savehere
= XALLOCAVEC (int, ndirs
);
9784 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9785 for (i
= 0; i
< ndirs
; i
++)
9790 /* We can always save some space for the current directory. But this
9791 does not mean it will be enough to justify adding the directory. */
9792 savehere
[i
] = dirs
[i
].length
;
9793 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9795 for (j
= i
+ 1; j
< ndirs
; j
++)
9798 if (saved
[j
] < dirs
[i
].length
)
9800 /* Determine whether the dirs[i] path is a prefix of the
9805 while (k
!= -1 && k
!= (int) i
)
9810 /* Yes it is. We can possibly save some memory by
9811 writing the filenames in dirs[j] relative to
9813 savehere
[j
] = dirs
[i
].length
;
9814 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9819 /* Check whether we can save enough to justify adding the dirs[i]
9821 if (total
> dirs
[i
].length
+ 1)
9823 /* It's worthwhile adding. */
9824 for (j
= i
; j
< ndirs
; j
++)
9825 if (savehere
[j
] > 0)
9827 /* Remember how much we saved for this directory so far. */
9828 saved
[j
] = savehere
[j
];
9830 /* Remember the prefix directory. */
9831 dirs
[j
].dir_idx
= i
;
9836 /* Emit the directory name table. */
9837 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9838 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9839 dw2_asm_output_nstring (dirs
[i
].path
,
9841 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9842 "Directory Entry: %#x", i
+ idx_offset
);
9844 dw2_asm_output_data (1, 0, "End directory table");
9846 /* We have to emit them in the order of emitted_number since that's
9847 used in the debug info generation. To do this efficiently we
9848 generate a back-mapping of the indices first. */
9849 backmap
= XALLOCAVEC (int, numfiles
);
9850 for (i
= 0; i
< numfiles
; i
++)
9851 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9853 /* Now write all the file names. */
9854 for (i
= 0; i
< numfiles
; i
++)
9856 int file_idx
= backmap
[i
];
9857 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9859 #ifdef VMS_DEBUGGING_INFO
9860 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9862 /* Setting these fields can lead to debugger miscomparisons,
9863 but VMS Debug requires them to be set correctly. */
9868 int maxfilelen
= strlen (files
[file_idx
].path
)
9869 + dirs
[dir_idx
].length
9870 + MAX_VMS_VERSION_LEN
+ 1;
9871 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9873 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9874 snprintf (filebuf
, maxfilelen
, "%s;%d",
9875 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9877 dw2_asm_output_nstring
9878 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9880 /* Include directory index. */
9881 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9883 /* Modification time. */
9884 dw2_asm_output_data_uleb128
9885 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9889 /* File length in bytes. */
9890 dw2_asm_output_data_uleb128
9891 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9895 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9896 "File Entry: %#x", (unsigned) i
+ 1);
9898 /* Include directory index. */
9899 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9901 /* Modification time. */
9902 dw2_asm_output_data_uleb128 (0, NULL
);
9904 /* File length in bytes. */
9905 dw2_asm_output_data_uleb128 (0, NULL
);
9906 #endif /* VMS_DEBUGGING_INFO */
9909 dw2_asm_output_data (1, 0, "End file name table");
9913 /* Output one line number table into the .debug_line section. */
9916 output_one_line_info_table (dw_line_info_table
*table
)
9918 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9919 unsigned int current_line
= 1;
9920 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9921 dw_line_info_entry
*ent
;
9924 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9926 switch (ent
->opcode
)
9928 case LI_set_address
:
9929 /* ??? Unfortunately, we have little choice here currently, and
9930 must always use the most general form. GCC does not know the
9931 address delta itself, so we can't use DW_LNS_advance_pc. Many
9932 ports do have length attributes which will give an upper bound
9933 on the address range. We could perhaps use length attributes
9934 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9935 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9937 /* This can handle any delta. This takes
9938 4+DWARF2_ADDR_SIZE bytes. */
9939 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9940 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9941 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9942 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9946 if (ent
->val
== current_line
)
9948 /* We still need to start a new row, so output a copy insn. */
9949 dw2_asm_output_data (1, DW_LNS_copy
,
9950 "copy line %u", current_line
);
9954 int line_offset
= ent
->val
- current_line
;
9955 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9957 current_line
= ent
->val
;
9958 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9960 /* This can handle deltas from -10 to 234, using the current
9961 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9962 This takes 1 byte. */
9963 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9964 "line %u", current_line
);
9968 /* This can handle any delta. This takes at least 4 bytes,
9969 depending on the value being encoded. */
9970 dw2_asm_output_data (1, DW_LNS_advance_line
,
9971 "advance to line %u", current_line
);
9972 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9973 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9979 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9980 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9984 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9985 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9988 case LI_negate_stmt
:
9989 current_is_stmt
= !current_is_stmt
;
9990 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9991 "is_stmt %d", current_is_stmt
);
9994 case LI_set_prologue_end
:
9995 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9996 "set prologue end");
9999 case LI_set_epilogue_begin
:
10000 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10001 "set epilogue begin");
10004 case LI_set_discriminator
:
10005 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10006 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10007 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10008 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10013 /* Emit debug info for the address of the end of the table. */
10014 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10015 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10016 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10017 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10019 dw2_asm_output_data (1, 0, "end sequence");
10020 dw2_asm_output_data_uleb128 (1, NULL
);
10021 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10024 /* Output the source line number correspondence information. This
10025 information goes into the .debug_line section. */
10028 output_line_info (bool prologue_only
)
10030 char l1
[20], l2
[20], p1
[20], p2
[20];
10031 int ver
= dwarf_version
;
10032 bool saw_one
= false;
10035 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10036 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10037 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10038 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10040 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10041 dw2_asm_output_data (4, 0xffffffff,
10042 "Initial length escape value indicating 64-bit DWARF extension");
10043 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10044 "Length of Source Line Info");
10045 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10047 dw2_asm_output_data (2, ver
, "DWARF Version");
10048 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10049 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10051 /* Define the architecture-dependent minimum instruction length (in bytes).
10052 In this implementation of DWARF, this field is used for information
10053 purposes only. Since GCC generates assembly language, we have no
10054 a priori knowledge of how many instruction bytes are generated for each
10055 source line, and therefore can use only the DW_LNE_set_address and
10056 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10057 this as '1', which is "correct enough" for all architectures,
10058 and don't let the target override. */
10059 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10062 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10063 "Maximum Operations Per Instruction");
10064 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10065 "Default is_stmt_start flag");
10066 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10067 "Line Base Value (Special Opcodes)");
10068 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10069 "Line Range Value (Special Opcodes)");
10070 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10071 "Special Opcode Base");
10073 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10078 case DW_LNS_advance_pc
:
10079 case DW_LNS_advance_line
:
10080 case DW_LNS_set_file
:
10081 case DW_LNS_set_column
:
10082 case DW_LNS_fixed_advance_pc
:
10083 case DW_LNS_set_isa
:
10091 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10095 /* Write out the information about the files we use. */
10096 output_file_names ();
10097 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10100 /* Output the marker for the end of the line number info. */
10101 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10105 if (separate_line_info
)
10107 dw_line_info_table
*table
;
10110 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10113 output_one_line_info_table (table
);
10117 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10119 output_one_line_info_table (cold_text_section_line_info
);
10123 /* ??? Some Darwin linkers crash on a .debug_line section with no
10124 sequences. Further, merely a DW_LNE_end_sequence entry is not
10125 sufficient -- the address column must also be initialized.
10126 Make sure to output at least one set_address/end_sequence pair,
10127 choosing .text since that section is always present. */
10128 if (text_section_line_info
->in_use
|| !saw_one
)
10129 output_one_line_info_table (text_section_line_info
);
10131 /* Output the marker for the end of the line number info. */
10132 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10135 /* Given a pointer to a tree node for some base type, return a pointer to
10136 a DIE that describes the given type.
10138 This routine must only be called for GCC type nodes that correspond to
10139 Dwarf base (fundamental) types. */
10142 base_type_die (tree type
)
10144 dw_die_ref base_type_result
;
10145 enum dwarf_type encoding
;
10147 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10150 /* If this is a subtype that should not be emitted as a subrange type,
10151 use the base type. See subrange_type_for_debug_p. */
10152 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10153 type
= TREE_TYPE (type
);
10155 switch (TREE_CODE (type
))
10158 if ((dwarf_version
>= 4 || !dwarf_strict
)
10159 && TYPE_NAME (type
)
10160 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10161 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10162 && DECL_NAME (TYPE_NAME (type
)))
10164 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10165 if (strcmp (name
, "char16_t") == 0
10166 || strcmp (name
, "char32_t") == 0)
10168 encoding
= DW_ATE_UTF
;
10172 if (TYPE_STRING_FLAG (type
))
10174 if (TYPE_UNSIGNED (type
))
10175 encoding
= DW_ATE_unsigned_char
;
10177 encoding
= DW_ATE_signed_char
;
10179 else if (TYPE_UNSIGNED (type
))
10180 encoding
= DW_ATE_unsigned
;
10182 encoding
= DW_ATE_signed
;
10186 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10188 if (dwarf_version
>= 3 || !dwarf_strict
)
10189 encoding
= DW_ATE_decimal_float
;
10191 encoding
= DW_ATE_lo_user
;
10194 encoding
= DW_ATE_float
;
10197 case FIXED_POINT_TYPE
:
10198 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10199 encoding
= DW_ATE_lo_user
;
10200 else if (TYPE_UNSIGNED (type
))
10201 encoding
= DW_ATE_unsigned_fixed
;
10203 encoding
= DW_ATE_signed_fixed
;
10206 /* Dwarf2 doesn't know anything about complex ints, so use
10207 a user defined type for it. */
10209 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10210 encoding
= DW_ATE_complex_float
;
10212 encoding
= DW_ATE_lo_user
;
10216 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10217 encoding
= DW_ATE_boolean
;
10221 /* No other TREE_CODEs are Dwarf fundamental types. */
10222 gcc_unreachable ();
10225 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10227 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10228 int_size_in_bytes (type
));
10229 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10230 add_pubtype (type
, base_type_result
);
10232 return base_type_result
;
10235 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10236 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10239 is_base_type (tree type
)
10241 switch (TREE_CODE (type
))
10247 case FIXED_POINT_TYPE
:
10255 case QUAL_UNION_TYPE
:
10256 case ENUMERAL_TYPE
:
10257 case FUNCTION_TYPE
:
10260 case REFERENCE_TYPE
:
10268 gcc_unreachable ();
10274 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10275 node, return the size in bits for the type if it is a constant, or else
10276 return the alignment for the type if the type's size is not constant, or
10277 else return BITS_PER_WORD if the type actually turns out to be an
10278 ERROR_MARK node. */
10280 static inline unsigned HOST_WIDE_INT
10281 simple_type_size_in_bits (const_tree type
)
10283 if (TREE_CODE (type
) == ERROR_MARK
)
10284 return BITS_PER_WORD
;
10285 else if (TYPE_SIZE (type
) == NULL_TREE
)
10287 else if (host_integerp (TYPE_SIZE (type
), 1))
10288 return tree_low_cst (TYPE_SIZE (type
), 1);
10290 return TYPE_ALIGN (type
);
10293 /* Similarly, but return a double_int instead of UHWI. */
10295 static inline double_int
10296 double_int_type_size_in_bits (const_tree type
)
10298 if (TREE_CODE (type
) == ERROR_MARK
)
10299 return double_int::from_uhwi (BITS_PER_WORD
);
10300 else if (TYPE_SIZE (type
) == NULL_TREE
)
10301 return double_int_zero
;
10302 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10303 return tree_to_double_int (TYPE_SIZE (type
));
10305 return double_int::from_uhwi (TYPE_ALIGN (type
));
10308 /* Given a pointer to a tree node for a subrange type, return a pointer
10309 to a DIE that describes the given type. */
10312 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10314 dw_die_ref subrange_die
;
10315 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10317 if (context_die
== NULL
)
10318 context_die
= comp_unit_die ();
10320 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10322 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10324 /* The size of the subrange type and its base type do not match,
10325 so we need to generate a size attribute for the subrange type. */
10326 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10330 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10332 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10334 return subrange_die
;
10337 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10338 entry that chains various modifiers in front of the given type. */
10341 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10342 dw_die_ref context_die
)
10344 enum tree_code code
= TREE_CODE (type
);
10345 dw_die_ref mod_type_die
;
10346 dw_die_ref sub_die
= NULL
;
10347 tree item_type
= NULL
;
10348 tree qualified_type
;
10349 tree name
, low
, high
;
10350 dw_die_ref mod_scope
;
10352 if (code
== ERROR_MARK
)
10355 /* See if we already have the appropriately qualified variant of
10358 = get_qualified_type (type
,
10359 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10360 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10362 if (qualified_type
== sizetype
10363 && TYPE_NAME (qualified_type
)
10364 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10366 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10368 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10369 && TYPE_PRECISION (t
)
10370 == TYPE_PRECISION (qualified_type
)
10371 && TYPE_UNSIGNED (t
)
10372 == TYPE_UNSIGNED (qualified_type
));
10373 qualified_type
= t
;
10376 /* If we do, then we can just use its DIE, if it exists. */
10377 if (qualified_type
)
10379 mod_type_die
= lookup_type_die (qualified_type
);
10381 return mod_type_die
;
10384 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10386 /* Handle C typedef types. */
10387 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10388 && !DECL_ARTIFICIAL (name
))
10390 tree dtype
= TREE_TYPE (name
);
10392 if (qualified_type
== dtype
)
10394 /* For a named type, use the typedef. */
10395 gen_type_die (qualified_type
, context_die
);
10396 return lookup_type_die (qualified_type
);
10398 else if (is_const_type
< TYPE_READONLY (dtype
)
10399 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10400 || (is_const_type
<= TYPE_READONLY (dtype
)
10401 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10402 && DECL_ORIGINAL_TYPE (name
) != type
))
10403 /* cv-unqualified version of named type. Just use the unnamed
10404 type to which it refers. */
10405 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10406 is_const_type
, is_volatile_type
,
10408 /* Else cv-qualified version of named type; fall through. */
10411 mod_scope
= scope_die_for (type
, context_die
);
10414 /* If both is_const_type and is_volatile_type, prefer the path
10415 which leads to a qualified type. */
10416 && (!is_volatile_type
10417 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10418 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10420 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10421 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10423 else if (is_volatile_type
)
10425 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10426 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10428 else if (code
== POINTER_TYPE
)
10430 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10431 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10432 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10433 item_type
= TREE_TYPE (type
);
10434 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10435 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10436 TYPE_ADDR_SPACE (item_type
));
10438 else if (code
== REFERENCE_TYPE
)
10440 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10441 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10444 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10445 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10446 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10447 item_type
= TREE_TYPE (type
);
10448 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10449 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10450 TYPE_ADDR_SPACE (item_type
));
10452 else if (code
== INTEGER_TYPE
10453 && TREE_TYPE (type
) != NULL_TREE
10454 && subrange_type_for_debug_p (type
, &low
, &high
))
10456 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10457 item_type
= TREE_TYPE (type
);
10459 else if (is_base_type (type
))
10460 mod_type_die
= base_type_die (type
);
10463 gen_type_die (type
, context_die
);
10465 /* We have to get the type_main_variant here (and pass that to the
10466 `lookup_type_die' routine) because the ..._TYPE node we have
10467 might simply be a *copy* of some original type node (where the
10468 copy was created to help us keep track of typedef names) and
10469 that copy might have a different TYPE_UID from the original
10471 if (TREE_CODE (type
) != VECTOR_TYPE
)
10472 return lookup_type_die (type_main_variant (type
));
10474 /* Vectors have the debugging information in the type,
10475 not the main variant. */
10476 return lookup_type_die (type
);
10479 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10480 don't output a DW_TAG_typedef, since there isn't one in the
10481 user's program; just attach a DW_AT_name to the type.
10482 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10483 if the base type already has the same name. */
10485 && ((TREE_CODE (name
) != TYPE_DECL
10486 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10487 || (!is_const_type
&& !is_volatile_type
)))
10488 || (TREE_CODE (name
) == TYPE_DECL
10489 && TREE_TYPE (name
) == qualified_type
10490 && DECL_NAME (name
))))
10492 if (TREE_CODE (name
) == TYPE_DECL
)
10493 /* Could just call add_name_and_src_coords_attributes here,
10494 but since this is a builtin type it doesn't have any
10495 useful source coordinates anyway. */
10496 name
= DECL_NAME (name
);
10497 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10499 /* This probably indicates a bug. */
10500 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10502 name
= TYPE_NAME (type
);
10504 && TREE_CODE (name
) == TYPE_DECL
)
10505 name
= DECL_NAME (name
);
10506 add_name_attribute (mod_type_die
,
10507 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10510 if (qualified_type
)
10511 equate_type_number_to_die (qualified_type
, mod_type_die
);
10514 /* We must do this after the equate_type_number_to_die call, in case
10515 this is a recursive type. This ensures that the modified_type_die
10516 recursion will terminate even if the type is recursive. Recursive
10517 types are possible in Ada. */
10518 sub_die
= modified_type_die (item_type
,
10519 TYPE_READONLY (item_type
),
10520 TYPE_VOLATILE (item_type
),
10523 if (sub_die
!= NULL
)
10524 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10526 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10527 if (TYPE_ARTIFICIAL (type
))
10528 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10530 return mod_type_die
;
10533 /* Generate DIEs for the generic parameters of T.
10534 T must be either a generic type or a generic function.
10535 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10538 gen_generic_params_dies (tree t
)
10542 dw_die_ref die
= NULL
;
10544 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10548 die
= lookup_type_die (t
);
10549 else if (DECL_P (t
))
10550 die
= lookup_decl_die (t
);
10554 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10556 /* T has no generic parameter. It means T is neither a generic type
10557 or function. End of story. */
10560 parms_num
= TREE_VEC_LENGTH (parms
);
10561 args
= lang_hooks
.get_innermost_generic_args (t
);
10562 for (i
= 0; i
< parms_num
; i
++)
10564 tree parm
, arg
, arg_pack_elems
;
10566 parm
= TREE_VEC_ELT (parms
, i
);
10567 arg
= TREE_VEC_ELT (args
, i
);
10568 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10569 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10571 if (parm
&& TREE_VALUE (parm
) && arg
)
10573 /* If PARM represents a template parameter pack,
10574 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10575 by DW_TAG_template_*_parameter DIEs for the argument
10576 pack elements of ARG. Note that ARG would then be
10577 an argument pack. */
10578 if (arg_pack_elems
)
10579 template_parameter_pack_die (TREE_VALUE (parm
),
10583 generic_parameter_die (TREE_VALUE (parm
), arg
,
10584 true /* Emit DW_AT_name */, die
);
10589 /* Create and return a DIE for PARM which should be
10590 the representation of a generic type parameter.
10591 For instance, in the C++ front end, PARM would be a template parameter.
10592 ARG is the argument to PARM.
10593 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10595 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10596 as a child node. */
10599 generic_parameter_die (tree parm
, tree arg
,
10601 dw_die_ref parent_die
)
10603 dw_die_ref tmpl_die
= NULL
;
10604 const char *name
= NULL
;
10606 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10609 /* We support non-type generic parameters and arguments,
10610 type generic parameters and arguments, as well as
10611 generic generic parameters (a.k.a. template template parameters in C++)
10613 if (TREE_CODE (parm
) == PARM_DECL
)
10614 /* PARM is a nontype generic parameter */
10615 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10616 else if (TREE_CODE (parm
) == TYPE_DECL
)
10617 /* PARM is a type generic parameter. */
10618 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10619 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10620 /* PARM is a generic generic parameter.
10621 Its DIE is a GNU extension. It shall have a
10622 DW_AT_name attribute to represent the name of the template template
10623 parameter, and a DW_AT_GNU_template_name attribute to represent the
10624 name of the template template argument. */
10625 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10628 gcc_unreachable ();
10634 /* If PARM is a generic parameter pack, it means we are
10635 emitting debug info for a template argument pack element.
10636 In other terms, ARG is a template argument pack element.
10637 In that case, we don't emit any DW_AT_name attribute for
10641 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10643 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10646 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10648 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10649 TMPL_DIE should have a child DW_AT_type attribute that is set
10650 to the type of the argument to PARM, which is ARG.
10651 If PARM is a type generic parameter, TMPL_DIE should have a
10652 child DW_AT_type that is set to ARG. */
10653 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10654 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10655 TREE_THIS_VOLATILE (tmpl_type
),
10660 /* So TMPL_DIE is a DIE representing a
10661 a generic generic template parameter, a.k.a template template
10662 parameter in C++ and arg is a template. */
10664 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10665 to the name of the argument. */
10666 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10668 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10671 if (TREE_CODE (parm
) == PARM_DECL
)
10672 /* So PARM is a non-type generic parameter.
10673 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10674 attribute of TMPL_DIE which value represents the value
10676 We must be careful here:
10677 The value of ARG might reference some function decls.
10678 We might currently be emitting debug info for a generic
10679 type and types are emitted before function decls, we don't
10680 know if the function decls referenced by ARG will actually be
10681 emitted after cgraph computations.
10682 So must defer the generation of the DW_AT_const_value to
10683 after cgraph is ready. */
10684 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10690 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10691 PARM_PACK must be a template parameter pack. The returned DIE
10692 will be child DIE of PARENT_DIE. */
10695 template_parameter_pack_die (tree parm_pack
,
10696 tree parm_pack_args
,
10697 dw_die_ref parent_die
)
10702 gcc_assert (parent_die
&& parm_pack
);
10704 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10705 add_name_and_src_coords_attributes (die
, parm_pack
);
10706 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10707 generic_parameter_die (parm_pack
,
10708 TREE_VEC_ELT (parm_pack_args
, j
),
10709 false /* Don't emit DW_AT_name */,
10714 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10715 an enumerated type. */
10718 type_is_enum (const_tree type
)
10720 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10723 /* Return the DBX register number described by a given RTL node. */
10725 static unsigned int
10726 dbx_reg_number (const_rtx rtl
)
10728 unsigned regno
= REGNO (rtl
);
10730 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10732 #ifdef LEAF_REG_REMAP
10733 if (crtl
->uses_only_leaf_regs
)
10735 int leaf_reg
= LEAF_REG_REMAP (regno
);
10736 if (leaf_reg
!= -1)
10737 regno
= (unsigned) leaf_reg
;
10741 regno
= DBX_REGISTER_NUMBER (regno
);
10742 gcc_assert (regno
!= INVALID_REGNUM
);
10746 /* Optionally add a DW_OP_piece term to a location description expression.
10747 DW_OP_piece is only added if the location description expression already
10748 doesn't end with DW_OP_piece. */
10751 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10753 dw_loc_descr_ref loc
;
10755 if (*list_head
!= NULL
)
10757 /* Find the end of the chain. */
10758 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10761 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10762 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10766 /* Return a location descriptor that designates a machine register or
10767 zero if there is none. */
10769 static dw_loc_descr_ref
10770 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10774 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10777 /* We only use "frame base" when we're sure we're talking about the
10778 post-prologue local stack frame. We do this by *not* running
10779 register elimination until this point, and recognizing the special
10780 argument pointer and soft frame pointer rtx's.
10781 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10782 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10783 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10785 dw_loc_descr_ref result
= NULL
;
10787 if (dwarf_version
>= 4 || !dwarf_strict
)
10789 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10792 add_loc_descr (&result
,
10793 new_loc_descr (DW_OP_stack_value
, 0, 0));
10798 regs
= targetm
.dwarf_register_span (rtl
);
10800 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10801 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10804 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10805 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10807 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10811 /* Return a location descriptor that designates a machine register for
10812 a given hard register number. */
10814 static dw_loc_descr_ref
10815 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10817 dw_loc_descr_ref reg_loc_descr
;
10821 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10823 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10825 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10826 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10828 return reg_loc_descr
;
10831 /* Given an RTL of a register, return a location descriptor that
10832 designates a value that spans more than one register. */
10834 static dw_loc_descr_ref
10835 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10836 enum var_init_status initialized
)
10838 int nregs
, size
, i
;
10840 dw_loc_descr_ref loc_result
= NULL
;
10843 #ifdef LEAF_REG_REMAP
10844 if (crtl
->uses_only_leaf_regs
)
10846 int leaf_reg
= LEAF_REG_REMAP (reg
);
10847 if (leaf_reg
!= -1)
10848 reg
= (unsigned) leaf_reg
;
10851 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10852 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10854 /* Simple, contiguous registers. */
10855 if (regs
== NULL_RTX
)
10857 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10862 dw_loc_descr_ref t
;
10864 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10865 VAR_INIT_STATUS_INITIALIZED
);
10866 add_loc_descr (&loc_result
, t
);
10867 add_loc_descr_op_piece (&loc_result
, size
);
10873 /* Now onto stupid register sets in non contiguous locations. */
10875 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10877 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10880 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10882 dw_loc_descr_ref t
;
10884 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
10885 VAR_INIT_STATUS_INITIALIZED
);
10886 add_loc_descr (&loc_result
, t
);
10887 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10888 add_loc_descr_op_piece (&loc_result
, size
);
10891 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10892 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10896 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10898 /* Return a location descriptor that designates a constant i,
10899 as a compound operation from constant (i >> shift), constant shift
10902 static dw_loc_descr_ref
10903 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10905 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10906 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10907 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10911 /* Return a location descriptor that designates a constant. */
10913 static dw_loc_descr_ref
10914 int_loc_descriptor (HOST_WIDE_INT i
)
10916 enum dwarf_location_atom op
;
10918 /* Pick the smallest representation of a constant, rather than just
10919 defaulting to the LEB encoding. */
10922 int clz
= clz_hwi (i
);
10923 int ctz
= ctz_hwi (i
);
10925 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10926 else if (i
<= 0xff)
10927 op
= DW_OP_const1u
;
10928 else if (i
<= 0xffff)
10929 op
= DW_OP_const2u
;
10930 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10931 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10932 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10933 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10934 while DW_OP_const4u is 5 bytes. */
10935 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10936 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10937 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10938 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10939 while DW_OP_const4u is 5 bytes. */
10940 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10941 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10942 op
= DW_OP_const4u
;
10943 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10944 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10945 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10946 while DW_OP_constu of constant >= 0x100000000 takes at least
10948 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10949 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10950 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10951 >= HOST_BITS_PER_WIDE_INT
)
10952 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10953 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10954 while DW_OP_constu takes in this case at least 6 bytes. */
10955 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10956 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10957 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10958 && size_of_uleb128 (i
) > 6)
10959 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10960 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10967 op
= DW_OP_const1s
;
10968 else if (i
>= -0x8000)
10969 op
= DW_OP_const2s
;
10970 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10972 if (size_of_int_loc_descriptor (i
) < 5)
10974 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10975 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10978 op
= DW_OP_const4s
;
10982 if (size_of_int_loc_descriptor (i
)
10983 < (unsigned long) 1 + size_of_sleb128 (i
))
10985 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10986 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10993 return new_loc_descr (op
, i
, 0);
10996 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10997 without actually allocating it. */
10999 static unsigned long
11000 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11002 return size_of_int_loc_descriptor (i
>> shift
)
11003 + size_of_int_loc_descriptor (shift
)
11007 /* Return size_of_locs (int_loc_descriptor (i)) without
11008 actually allocating it. */
11010 static unsigned long
11011 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11020 else if (i
<= 0xff)
11022 else if (i
<= 0xffff)
11026 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11027 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11028 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11030 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11031 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11032 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11034 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11036 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11037 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11038 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11039 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11041 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11042 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11043 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11045 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11046 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11048 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11057 else if (i
>= -0x8000)
11059 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11061 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11063 s
= size_of_int_loc_descriptor (-i
) + 1;
11071 unsigned long r
= 1 + size_of_sleb128 (i
);
11072 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11074 s
= size_of_int_loc_descriptor (-i
) + 1;
11083 /* Return loc description representing "address" of integer value.
11084 This can appear only as toplevel expression. */
11086 static dw_loc_descr_ref
11087 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11090 dw_loc_descr_ref loc_result
= NULL
;
11092 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11095 litsize
= size_of_int_loc_descriptor (i
);
11096 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11097 is more compact. For DW_OP_stack_value we need:
11098 litsize + 1 (DW_OP_stack_value)
11099 and for DW_OP_implicit_value:
11100 1 (DW_OP_implicit_value) + 1 (length) + size. */
11101 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11103 loc_result
= int_loc_descriptor (i
);
11104 add_loc_descr (&loc_result
,
11105 new_loc_descr (DW_OP_stack_value
, 0, 0));
11109 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11111 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11112 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11116 /* Return a location descriptor that designates a base+offset location. */
11118 static dw_loc_descr_ref
11119 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11120 enum var_init_status initialized
)
11122 unsigned int regno
;
11123 dw_loc_descr_ref result
;
11124 dw_fde_ref fde
= cfun
->fde
;
11126 /* We only use "frame base" when we're sure we're talking about the
11127 post-prologue local stack frame. We do this by *not* running
11128 register elimination until this point, and recognizing the special
11129 argument pointer and soft frame pointer rtx's. */
11130 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11132 rtx elim
= (ira_use_lra_p
11133 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11134 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11138 if (GET_CODE (elim
) == PLUS
)
11140 offset
+= INTVAL (XEXP (elim
, 1));
11141 elim
= XEXP (elim
, 0);
11143 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11144 && (elim
== hard_frame_pointer_rtx
11145 || elim
== stack_pointer_rtx
))
11146 || elim
== (frame_pointer_needed
11147 ? hard_frame_pointer_rtx
11148 : stack_pointer_rtx
));
11150 /* If drap register is used to align stack, use frame
11151 pointer + offset to access stack variables. If stack
11152 is aligned without drap, use stack pointer + offset to
11153 access stack variables. */
11154 if (crtl
->stack_realign_tried
11155 && reg
== frame_pointer_rtx
)
11158 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11159 ? HARD_FRAME_POINTER_REGNUM
11161 return new_reg_loc_descr (base_reg
, offset
);
11164 gcc_assert (frame_pointer_fb_offset_valid
);
11165 offset
+= frame_pointer_fb_offset
;
11166 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11170 regno
= REGNO (reg
);
11171 #ifdef LEAF_REG_REMAP
11172 if (crtl
->uses_only_leaf_regs
)
11174 int leaf_reg
= LEAF_REG_REMAP (regno
);
11175 if (leaf_reg
!= -1)
11176 regno
= (unsigned) leaf_reg
;
11179 regno
= DWARF_FRAME_REGNUM (regno
);
11181 if (!optimize
&& fde
11182 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11184 /* Use cfa+offset to represent the location of arguments passed
11185 on the stack when drap is used to align stack.
11186 Only do this when not optimizing, for optimized code var-tracking
11187 is supposed to track where the arguments live and the register
11188 used as vdrap or drap in some spot might be used for something
11189 else in other part of the routine. */
11190 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11194 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11197 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11199 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11200 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11205 /* Return true if this RTL expression describes a base+offset calculation. */
11208 is_based_loc (const_rtx rtl
)
11210 return (GET_CODE (rtl
) == PLUS
11211 && ((REG_P (XEXP (rtl
, 0))
11212 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11213 && CONST_INT_P (XEXP (rtl
, 1)))));
11216 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11219 static dw_loc_descr_ref
11220 tls_mem_loc_descriptor (rtx mem
)
11223 dw_loc_descr_ref loc_result
;
11225 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11228 base
= get_base_address (MEM_EXPR (mem
));
11230 || TREE_CODE (base
) != VAR_DECL
11231 || !DECL_THREAD_LOCAL_P (base
))
11234 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11235 if (loc_result
== NULL
)
11238 if (MEM_OFFSET (mem
))
11239 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11244 /* Output debug info about reason why we failed to expand expression as dwarf
11248 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11250 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11252 fprintf (dump_file
, "Failed to expand as dwarf: ");
11254 print_generic_expr (dump_file
, expr
, dump_flags
);
11257 fprintf (dump_file
, "\n");
11258 print_rtl (dump_file
, rtl
);
11260 fprintf (dump_file
, "\nReason: %s\n", reason
);
11264 /* Helper function for const_ok_for_output, called either directly
11265 or via for_each_rtx. */
11268 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11272 if (GET_CODE (rtl
) == UNSPEC
)
11274 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11275 we can't express it in the debug info. */
11276 #ifdef ENABLE_CHECKING
11277 /* Don't complain about TLS UNSPECs, those are just too hard to
11278 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11279 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11280 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11281 if (XVECLEN (rtl
, 0) == 0
11282 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11283 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11284 inform (current_function_decl
11285 ? DECL_SOURCE_LOCATION (current_function_decl
)
11286 : UNKNOWN_LOCATION
,
11287 #if NUM_UNSPEC_VALUES > 0
11288 "non-delegitimized UNSPEC %s (%d) found in variable location",
11289 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11290 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11293 "non-delegitimized UNSPEC %d found in variable location",
11297 expansion_failed (NULL_TREE
, rtl
,
11298 "UNSPEC hasn't been delegitimized.\n");
11302 if (targetm
.const_not_ok_for_debug_p (rtl
))
11304 expansion_failed (NULL_TREE
, rtl
,
11305 "Expression rejected for debug by the backend.\n");
11309 if (GET_CODE (rtl
) != SYMBOL_REF
)
11312 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11315 get_pool_constant_mark (rtl
, &marked
);
11316 /* If all references to this pool constant were optimized away,
11317 it was not output and thus we can't represent it. */
11320 expansion_failed (NULL_TREE
, rtl
,
11321 "Constant was removed from constant pool.\n");
11326 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11329 /* Avoid references to external symbols in debug info, on several targets
11330 the linker might even refuse to link when linking a shared library,
11331 and in many other cases the relocations for .debug_info/.debug_loc are
11332 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11333 to be defined within the same shared library or executable are fine. */
11334 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11336 tree decl
= SYMBOL_REF_DECL (rtl
);
11338 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11340 expansion_failed (NULL_TREE
, rtl
,
11341 "Symbol not defined in current TU.\n");
11349 /* Return true if constant RTL can be emitted in DW_OP_addr or
11350 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11351 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11354 const_ok_for_output (rtx rtl
)
11356 if (GET_CODE (rtl
) == SYMBOL_REF
)
11357 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11359 if (GET_CODE (rtl
) == CONST
)
11360 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11365 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11366 if possible, NULL otherwise. */
11369 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11371 dw_die_ref type_die
;
11372 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11376 switch (TREE_CODE (type
))
11384 type_die
= lookup_type_die (type
);
11386 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11387 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11392 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11393 type matching MODE, or, if MODE is narrower than or as wide as
11394 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11397 static dw_loc_descr_ref
11398 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11400 enum machine_mode outer_mode
= mode
;
11401 dw_die_ref type_die
;
11402 dw_loc_descr_ref cvt
;
11404 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11406 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11409 type_die
= base_type_for_mode (outer_mode
, 1);
11410 if (type_die
== NULL
)
11412 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11413 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11414 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11415 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11416 add_loc_descr (&op
, cvt
);
11420 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11422 static dw_loc_descr_ref
11423 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11424 dw_loc_descr_ref op1
)
11426 dw_loc_descr_ref ret
= op0
;
11427 add_loc_descr (&ret
, op1
);
11428 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11429 if (STORE_FLAG_VALUE
!= 1)
11431 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11432 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11437 /* Return location descriptor for signed comparison OP RTL. */
11439 static dw_loc_descr_ref
11440 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11441 enum machine_mode mem_mode
)
11443 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11444 dw_loc_descr_ref op0
, op1
;
11447 if (op_mode
== VOIDmode
)
11448 op_mode
= GET_MODE (XEXP (rtl
, 1));
11449 if (op_mode
== VOIDmode
)
11453 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11454 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11457 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11458 VAR_INIT_STATUS_INITIALIZED
);
11459 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11460 VAR_INIT_STATUS_INITIALIZED
);
11462 if (op0
== NULL
|| op1
== NULL
)
11465 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11466 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11467 return compare_loc_descriptor (op
, op0
, op1
);
11469 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11471 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11472 dw_loc_descr_ref cvt
;
11474 if (type_die
== NULL
)
11476 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11477 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11478 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11479 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11480 add_loc_descr (&op0
, cvt
);
11481 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11482 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11483 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11484 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11485 add_loc_descr (&op1
, cvt
);
11486 return compare_loc_descriptor (op
, op0
, op1
);
11489 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11490 /* For eq/ne, if the operands are known to be zero-extended,
11491 there is no need to do the fancy shifting up. */
11492 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11494 dw_loc_descr_ref last0
, last1
;
11495 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11497 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11499 /* deref_size zero extends, and for constants we can check
11500 whether they are zero extended or not. */
11501 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11502 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11503 || (CONST_INT_P (XEXP (rtl
, 0))
11504 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11505 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11506 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11507 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11508 || (CONST_INT_P (XEXP (rtl
, 1))
11509 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11510 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11511 return compare_loc_descriptor (op
, op0
, op1
);
11513 /* EQ/NE comparison against constant in narrower type than
11514 DWARF2_ADDR_SIZE can be performed either as
11515 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11518 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11519 DW_OP_{eq,ne}. Pick whatever is shorter. */
11520 if (CONST_INT_P (XEXP (rtl
, 1))
11521 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11522 && (size_of_int_loc_descriptor (shift
) + 1
11523 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11524 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11525 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11526 & GET_MODE_MASK (op_mode
))))
11528 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11529 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11530 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11531 & GET_MODE_MASK (op_mode
));
11532 return compare_loc_descriptor (op
, op0
, op1
);
11535 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11536 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11537 if (CONST_INT_P (XEXP (rtl
, 1)))
11538 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11541 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11542 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11544 return compare_loc_descriptor (op
, op0
, op1
);
11547 /* Return location descriptor for unsigned comparison OP RTL. */
11549 static dw_loc_descr_ref
11550 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11551 enum machine_mode mem_mode
)
11553 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11554 dw_loc_descr_ref op0
, op1
;
11556 if (op_mode
== VOIDmode
)
11557 op_mode
= GET_MODE (XEXP (rtl
, 1));
11558 if (op_mode
== VOIDmode
)
11560 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11563 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11566 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11567 VAR_INIT_STATUS_INITIALIZED
);
11568 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11569 VAR_INIT_STATUS_INITIALIZED
);
11571 if (op0
== NULL
|| op1
== NULL
)
11574 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11576 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11577 dw_loc_descr_ref last0
, last1
;
11578 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11580 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11582 if (CONST_INT_P (XEXP (rtl
, 0)))
11583 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11584 /* deref_size zero extends, so no need to mask it again. */
11585 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11586 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11588 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11589 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11591 if (CONST_INT_P (XEXP (rtl
, 1)))
11592 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11593 /* deref_size zero extends, so no need to mask it again. */
11594 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11595 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11597 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11598 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11601 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11603 HOST_WIDE_INT bias
= 1;
11604 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11605 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11606 if (CONST_INT_P (XEXP (rtl
, 1)))
11607 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11608 + INTVAL (XEXP (rtl
, 1)));
11610 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11613 return compare_loc_descriptor (op
, op0
, op1
);
11616 /* Return location descriptor for {U,S}{MIN,MAX}. */
11618 static dw_loc_descr_ref
11619 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11620 enum machine_mode mem_mode
)
11622 enum dwarf_location_atom op
;
11623 dw_loc_descr_ref op0
, op1
, ret
;
11624 dw_loc_descr_ref bra_node
, drop_node
;
11627 && (GET_MODE_CLASS (mode
) != MODE_INT
11628 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11631 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11632 VAR_INIT_STATUS_INITIALIZED
);
11633 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11634 VAR_INIT_STATUS_INITIALIZED
);
11636 if (op0
== NULL
|| op1
== NULL
)
11639 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11640 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11641 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11642 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11644 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11646 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11647 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11648 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11649 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11650 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11652 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11654 HOST_WIDE_INT bias
= 1;
11655 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11656 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11657 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11660 else if (GET_MODE_CLASS (mode
) == MODE_INT
11661 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11663 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11664 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11665 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11666 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11667 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11669 else if (GET_MODE_CLASS (mode
) == MODE_INT
11670 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11672 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11673 dw_loc_descr_ref cvt
;
11674 if (type_die
== NULL
)
11676 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11677 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11678 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11679 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11680 add_loc_descr (&op0
, cvt
);
11681 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11682 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11683 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11684 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11685 add_loc_descr (&op1
, cvt
);
11688 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11693 add_loc_descr (&ret
, op1
);
11694 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11695 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11696 add_loc_descr (&ret
, bra_node
);
11697 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11698 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11699 add_loc_descr (&ret
, drop_node
);
11700 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11701 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11702 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11703 && GET_MODE_CLASS (mode
) == MODE_INT
11704 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11705 ret
= convert_descriptor_to_mode (mode
, ret
);
11709 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11710 but after converting arguments to type_die, afterwards
11711 convert back to unsigned. */
11713 static dw_loc_descr_ref
11714 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11715 enum machine_mode mode
, enum machine_mode mem_mode
)
11717 dw_loc_descr_ref cvt
, op0
, op1
;
11719 if (type_die
== NULL
)
11721 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11722 VAR_INIT_STATUS_INITIALIZED
);
11723 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11724 VAR_INIT_STATUS_INITIALIZED
);
11725 if (op0
== NULL
|| op1
== NULL
)
11727 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11728 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11729 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11730 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11731 add_loc_descr (&op0
, cvt
);
11732 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11733 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11734 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11735 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11736 add_loc_descr (&op1
, cvt
);
11737 add_loc_descr (&op0
, op1
);
11738 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11739 return convert_descriptor_to_mode (mode
, op0
);
11742 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11743 const0 is DW_OP_lit0 or corresponding typed constant,
11744 const1 is DW_OP_lit1 or corresponding typed constant
11745 and constMSB is constant with just the MSB bit set
11747 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11748 L1: const0 DW_OP_swap
11749 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11750 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11755 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11756 L1: const0 DW_OP_swap
11757 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11758 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11763 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11764 L1: const1 DW_OP_swap
11765 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11766 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11770 static dw_loc_descr_ref
11771 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11772 enum machine_mode mem_mode
)
11774 dw_loc_descr_ref op0
, ret
, tmp
;
11775 HOST_WIDE_INT valv
;
11776 dw_loc_descr_ref l1jump
, l1label
;
11777 dw_loc_descr_ref l2jump
, l2label
;
11778 dw_loc_descr_ref l3jump
, l3label
;
11779 dw_loc_descr_ref l4jump
, l4label
;
11782 if (GET_MODE_CLASS (mode
) != MODE_INT
11783 || GET_MODE (XEXP (rtl
, 0)) != mode
11784 || (GET_CODE (rtl
) == CLZ
11785 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11788 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11789 VAR_INIT_STATUS_INITIALIZED
);
11793 if (GET_CODE (rtl
) == CLZ
)
11795 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11796 valv
= GET_MODE_BITSIZE (mode
);
11798 else if (GET_CODE (rtl
) == FFS
)
11800 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11801 valv
= GET_MODE_BITSIZE (mode
);
11802 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11803 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11804 add_loc_descr (&ret
, l1jump
);
11805 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11806 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11807 VAR_INIT_STATUS_INITIALIZED
);
11810 add_loc_descr (&ret
, tmp
);
11811 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11812 add_loc_descr (&ret
, l4jump
);
11813 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11814 ? const1_rtx
: const0_rtx
,
11816 VAR_INIT_STATUS_INITIALIZED
);
11817 if (l1label
== NULL
)
11819 add_loc_descr (&ret
, l1label
);
11820 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11821 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11822 add_loc_descr (&ret
, l2label
);
11823 if (GET_CODE (rtl
) != CLZ
)
11825 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11826 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11827 << (GET_MODE_BITSIZE (mode
) - 1));
11829 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11830 << (GET_MODE_BITSIZE (mode
)
11831 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11832 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11833 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11834 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11835 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11837 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11838 VAR_INIT_STATUS_INITIALIZED
);
11841 add_loc_descr (&ret
, tmp
);
11842 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11843 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11844 add_loc_descr (&ret
, l3jump
);
11845 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11846 VAR_INIT_STATUS_INITIALIZED
);
11849 add_loc_descr (&ret
, tmp
);
11850 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11851 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11852 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11853 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11854 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11855 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11856 add_loc_descr (&ret
, l2jump
);
11857 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11858 add_loc_descr (&ret
, l3label
);
11859 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11860 add_loc_descr (&ret
, l4label
);
11861 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11862 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11863 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11864 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11865 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11866 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11867 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11868 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11872 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11873 const1 is DW_OP_lit1 or corresponding typed constant):
11875 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11876 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11880 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11881 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11884 static dw_loc_descr_ref
11885 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11886 enum machine_mode mem_mode
)
11888 dw_loc_descr_ref op0
, ret
, tmp
;
11889 dw_loc_descr_ref l1jump
, l1label
;
11890 dw_loc_descr_ref l2jump
, l2label
;
11892 if (GET_MODE_CLASS (mode
) != MODE_INT
11893 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11896 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11897 VAR_INIT_STATUS_INITIALIZED
);
11901 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11902 VAR_INIT_STATUS_INITIALIZED
);
11905 add_loc_descr (&ret
, tmp
);
11906 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11907 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11908 add_loc_descr (&ret
, l1label
);
11909 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11910 add_loc_descr (&ret
, l2jump
);
11911 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11912 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11913 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11914 VAR_INIT_STATUS_INITIALIZED
);
11917 add_loc_descr (&ret
, tmp
);
11918 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11919 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11920 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11921 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11922 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11923 VAR_INIT_STATUS_INITIALIZED
);
11924 add_loc_descr (&ret
, tmp
);
11925 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11926 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11927 add_loc_descr (&ret
, l1jump
);
11928 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11929 add_loc_descr (&ret
, l2label
);
11930 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11931 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11932 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11933 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11937 /* BSWAP (constS is initial shift count, either 56 or 24):
11939 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11940 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11941 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11942 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11943 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11945 static dw_loc_descr_ref
11946 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11947 enum machine_mode mem_mode
)
11949 dw_loc_descr_ref op0
, ret
, tmp
;
11950 dw_loc_descr_ref l1jump
, l1label
;
11951 dw_loc_descr_ref l2jump
, l2label
;
11953 if (GET_MODE_CLASS (mode
) != MODE_INT
11954 || BITS_PER_UNIT
!= 8
11955 || (GET_MODE_BITSIZE (mode
) != 32
11956 && GET_MODE_BITSIZE (mode
) != 64))
11959 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11960 VAR_INIT_STATUS_INITIALIZED
);
11965 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11967 VAR_INIT_STATUS_INITIALIZED
);
11970 add_loc_descr (&ret
, tmp
);
11971 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11972 VAR_INIT_STATUS_INITIALIZED
);
11975 add_loc_descr (&ret
, tmp
);
11976 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11977 add_loc_descr (&ret
, l1label
);
11978 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11980 VAR_INIT_STATUS_INITIALIZED
);
11981 add_loc_descr (&ret
, tmp
);
11982 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11983 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11984 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11985 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11986 VAR_INIT_STATUS_INITIALIZED
);
11989 add_loc_descr (&ret
, tmp
);
11990 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11991 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11992 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11993 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11994 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11995 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11996 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11997 VAR_INIT_STATUS_INITIALIZED
);
11998 add_loc_descr (&ret
, tmp
);
11999 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
12000 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12001 add_loc_descr (&ret
, l2jump
);
12002 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
12003 VAR_INIT_STATUS_INITIALIZED
);
12004 add_loc_descr (&ret
, tmp
);
12005 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12006 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12007 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12008 add_loc_descr (&ret
, l1jump
);
12009 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12010 add_loc_descr (&ret
, l2label
);
12011 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12012 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12013 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12014 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12015 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12016 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12020 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12021 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12022 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12023 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12025 ROTATERT is similar:
12026 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12027 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12028 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12030 static dw_loc_descr_ref
12031 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12032 enum machine_mode mem_mode
)
12034 rtx rtlop1
= XEXP (rtl
, 1);
12035 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12038 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12041 if (GET_MODE (rtlop1
) != VOIDmode
12042 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12043 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12044 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12045 VAR_INIT_STATUS_INITIALIZED
);
12046 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12047 VAR_INIT_STATUS_INITIALIZED
);
12048 if (op0
== NULL
|| op1
== NULL
)
12050 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12051 for (i
= 0; i
< 2; i
++)
12053 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12054 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12056 VAR_INIT_STATUS_INITIALIZED
);
12057 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12058 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12060 : HOST_BITS_PER_WIDE_INT
== 64
12061 ? DW_OP_const8u
: DW_OP_constu
,
12062 GET_MODE_MASK (mode
), 0);
12065 if (mask
[i
] == NULL
)
12067 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12070 add_loc_descr (&ret
, op1
);
12071 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12072 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12073 if (GET_CODE (rtl
) == ROTATERT
)
12075 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12076 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12077 GET_MODE_BITSIZE (mode
), 0));
12079 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12080 if (mask
[0] != NULL
)
12081 add_loc_descr (&ret
, mask
[0]);
12082 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12083 if (mask
[1] != NULL
)
12085 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12086 add_loc_descr (&ret
, mask
[1]);
12087 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12089 if (GET_CODE (rtl
) == ROTATE
)
12091 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12092 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12093 GET_MODE_BITSIZE (mode
), 0));
12095 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12096 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12100 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12101 for DEBUG_PARAMETER_REF RTL. */
12103 static dw_loc_descr_ref
12104 parameter_ref_descriptor (rtx rtl
)
12106 dw_loc_descr_ref ret
;
12111 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12112 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12113 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12116 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12117 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12118 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12122 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12123 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12128 /* The following routine converts the RTL for a variable or parameter
12129 (resident in memory) into an equivalent Dwarf representation of a
12130 mechanism for getting the address of that same variable onto the top of a
12131 hypothetical "address evaluation" stack.
12133 When creating memory location descriptors, we are effectively transforming
12134 the RTL for a memory-resident object into its Dwarf postfix expression
12135 equivalent. This routine recursively descends an RTL tree, turning
12136 it into Dwarf postfix code as it goes.
12138 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12140 MEM_MODE is the mode of the memory reference, needed to handle some
12141 autoincrement addressing modes.
12143 Return 0 if we can't represent the location. */
12146 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12147 enum machine_mode mem_mode
,
12148 enum var_init_status initialized
)
12150 dw_loc_descr_ref mem_loc_result
= NULL
;
12151 enum dwarf_location_atom op
;
12152 dw_loc_descr_ref op0
, op1
;
12153 rtx inner
= NULL_RTX
;
12155 if (mode
== VOIDmode
)
12156 mode
= GET_MODE (rtl
);
12158 /* Note that for a dynamically sized array, the location we will generate a
12159 description of here will be the lowest numbered location which is
12160 actually within the array. That's *not* necessarily the same as the
12161 zeroth element of the array. */
12163 rtl
= targetm
.delegitimize_address (rtl
);
12165 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12168 switch (GET_CODE (rtl
))
12173 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12176 /* The case of a subreg may arise when we have a local (register)
12177 variable or a formal (register) parameter which doesn't quite fill
12178 up an entire register. For now, just assume that it is
12179 legitimate to make the Dwarf info refer to the whole register which
12180 contains the given subreg. */
12181 if (!subreg_lowpart_p (rtl
))
12183 inner
= SUBREG_REG (rtl
);
12185 if (inner
== NULL_RTX
)
12186 inner
= XEXP (rtl
, 0);
12187 if (GET_MODE_CLASS (mode
) == MODE_INT
12188 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12189 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12190 #ifdef POINTERS_EXTEND_UNSIGNED
12191 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12194 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12196 mem_loc_result
= mem_loc_descriptor (inner
,
12198 mem_mode
, initialized
);
12203 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12205 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12206 && (GET_MODE_CLASS (mode
) != MODE_INT
12207 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12211 dw_die_ref type_die
;
12212 dw_loc_descr_ref cvt
;
12214 mem_loc_result
= mem_loc_descriptor (inner
,
12216 mem_mode
, initialized
);
12217 if (mem_loc_result
== NULL
)
12219 type_die
= base_type_for_mode (mode
,
12220 GET_MODE_CLASS (mode
) == MODE_INT
);
12221 if (type_die
== NULL
)
12223 mem_loc_result
= NULL
;
12226 if (GET_MODE_SIZE (mode
)
12227 != GET_MODE_SIZE (GET_MODE (inner
)))
12228 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12230 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12231 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12232 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12233 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12234 add_loc_descr (&mem_loc_result
, cvt
);
12239 if (GET_MODE_CLASS (mode
) != MODE_INT
12240 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12241 && rtl
!= arg_pointer_rtx
12242 && rtl
!= frame_pointer_rtx
12243 #ifdef POINTERS_EXTEND_UNSIGNED
12244 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12248 dw_die_ref type_die
;
12249 unsigned int dbx_regnum
;
12253 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12255 type_die
= base_type_for_mode (mode
,
12256 GET_MODE_CLASS (mode
) == MODE_INT
);
12257 if (type_die
== NULL
)
12260 dbx_regnum
= dbx_reg_number (rtl
);
12261 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12263 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12265 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12266 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12267 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12270 /* Whenever a register number forms a part of the description of the
12271 method for calculating the (dynamic) address of a memory resident
12272 object, DWARF rules require the register number be referred to as
12273 a "base register". This distinction is not based in any way upon
12274 what category of register the hardware believes the given register
12275 belongs to. This is strictly DWARF terminology we're dealing with
12276 here. Note that in cases where the location of a memory-resident
12277 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12278 OP_CONST (0)) the actual DWARF location descriptor that we generate
12279 may just be OP_BASEREG (basereg). This may look deceptively like
12280 the object in question was allocated to a register (rather than in
12281 memory) so DWARF consumers need to be aware of the subtle
12282 distinction between OP_REG and OP_BASEREG. */
12283 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12284 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12285 else if (stack_realign_drap
12287 && crtl
->args
.internal_arg_pointer
== rtl
12288 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12290 /* If RTL is internal_arg_pointer, which has been optimized
12291 out, use DRAP instead. */
12292 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12293 VAR_INIT_STATUS_INITIALIZED
);
12299 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12301 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12302 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12305 else if (GET_CODE (rtl
) == ZERO_EXTEND
12306 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12307 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12308 < HOST_BITS_PER_WIDE_INT
12309 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12310 to expand zero extend as two shifts instead of
12312 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12314 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12315 mem_loc_result
= op0
;
12316 add_loc_descr (&mem_loc_result
,
12317 int_loc_descriptor (GET_MODE_MASK (imode
)));
12318 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12320 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12322 int shift
= DWARF2_ADDR_SIZE
12323 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12324 shift
*= BITS_PER_UNIT
;
12325 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12329 mem_loc_result
= op0
;
12330 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12331 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12332 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12333 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12335 else if (!dwarf_strict
)
12337 dw_die_ref type_die1
, type_die2
;
12338 dw_loc_descr_ref cvt
;
12340 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12341 GET_CODE (rtl
) == ZERO_EXTEND
);
12342 if (type_die1
== NULL
)
12344 type_die2
= base_type_for_mode (mode
, 1);
12345 if (type_die2
== NULL
)
12347 mem_loc_result
= op0
;
12348 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12349 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12350 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12351 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12352 add_loc_descr (&mem_loc_result
, cvt
);
12353 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12354 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12355 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12356 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12357 add_loc_descr (&mem_loc_result
, cvt
);
12363 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12364 if (new_rtl
!= rtl
)
12366 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12368 if (mem_loc_result
!= NULL
)
12369 return mem_loc_result
;
12372 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12373 get_address_mode (rtl
), mode
,
12374 VAR_INIT_STATUS_INITIALIZED
);
12375 if (mem_loc_result
== NULL
)
12376 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12377 if (mem_loc_result
!= NULL
)
12379 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12380 || GET_MODE_CLASS (mode
) != MODE_INT
)
12382 dw_die_ref type_die
;
12383 dw_loc_descr_ref deref
;
12388 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12389 if (type_die
== NULL
)
12391 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12392 GET_MODE_SIZE (mode
), 0);
12393 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12394 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12395 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12396 add_loc_descr (&mem_loc_result
, deref
);
12398 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12399 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12401 add_loc_descr (&mem_loc_result
,
12402 new_loc_descr (DW_OP_deref_size
,
12403 GET_MODE_SIZE (mode
), 0));
12408 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12411 /* Some ports can transform a symbol ref into a label ref, because
12412 the symbol ref is too far away and has to be dumped into a constant
12416 if (GET_MODE_CLASS (mode
) != MODE_INT
12417 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12418 #ifdef POINTERS_EXTEND_UNSIGNED
12419 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12423 if (GET_CODE (rtl
) == SYMBOL_REF
12424 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12426 dw_loc_descr_ref temp
;
12428 /* If this is not defined, we have no way to emit the data. */
12429 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12432 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12434 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12435 add_loc_descr (&mem_loc_result
, temp
);
12440 if (!const_ok_for_output (rtl
))
12444 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12445 vec_safe_push (used_rtx_array
, rtl
);
12451 case DEBUG_IMPLICIT_PTR
:
12452 expansion_failed (NULL_TREE
, rtl
,
12453 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12459 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12461 if (GET_MODE_CLASS (mode
) != MODE_INT
12462 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12463 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12464 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12467 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12468 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12470 op0
= one_reg_loc_descriptor (dbx_regnum
,
12471 VAR_INIT_STATUS_INITIALIZED
);
12474 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12475 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12477 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12478 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12479 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12483 gcc_unreachable ();
12486 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12487 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12488 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12491 case DEBUG_PARAMETER_REF
:
12492 mem_loc_result
= parameter_ref_descriptor (rtl
);
12496 /* Extract the PLUS expression nested inside and fall into
12497 PLUS code below. */
12498 rtl
= XEXP (rtl
, 1);
12503 /* Turn these into a PLUS expression and fall into the PLUS code
12505 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12506 GEN_INT (GET_CODE (rtl
) == PRE_INC
12507 ? GET_MODE_UNIT_SIZE (mem_mode
)
12508 : -GET_MODE_UNIT_SIZE (mem_mode
)));
12510 /* ... fall through ... */
12514 if (is_based_loc (rtl
)
12515 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12516 || XEXP (rtl
, 0) == arg_pointer_rtx
12517 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12518 && GET_MODE_CLASS (mode
) == MODE_INT
)
12519 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12520 INTVAL (XEXP (rtl
, 1)),
12521 VAR_INIT_STATUS_INITIALIZED
);
12524 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12525 VAR_INIT_STATUS_INITIALIZED
);
12526 if (mem_loc_result
== 0)
12529 if (CONST_INT_P (XEXP (rtl
, 1))
12530 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12531 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12534 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12535 VAR_INIT_STATUS_INITIALIZED
);
12538 add_loc_descr (&mem_loc_result
, op1
);
12539 add_loc_descr (&mem_loc_result
,
12540 new_loc_descr (DW_OP_plus
, 0, 0));
12545 /* If a pseudo-reg is optimized away, it is possible for it to
12546 be replaced with a MEM containing a multiply or shift. */
12557 && GET_MODE_CLASS (mode
) == MODE_INT
12558 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12560 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12561 base_type_for_mode (mode
, 0),
12585 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12587 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12588 VAR_INIT_STATUS_INITIALIZED
);
12590 rtx rtlop1
= XEXP (rtl
, 1);
12591 if (GET_MODE (rtlop1
) != VOIDmode
12592 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12593 < GET_MODE_BITSIZE (mode
))
12594 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12595 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12596 VAR_INIT_STATUS_INITIALIZED
);
12599 if (op0
== 0 || op1
== 0)
12602 mem_loc_result
= op0
;
12603 add_loc_descr (&mem_loc_result
, op1
);
12604 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12620 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12621 VAR_INIT_STATUS_INITIALIZED
);
12622 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12623 VAR_INIT_STATUS_INITIALIZED
);
12625 if (op0
== 0 || op1
== 0)
12628 mem_loc_result
= op0
;
12629 add_loc_descr (&mem_loc_result
, op1
);
12630 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12634 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12636 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12637 base_type_for_mode (mode
, 0),
12642 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12643 VAR_INIT_STATUS_INITIALIZED
);
12644 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12645 VAR_INIT_STATUS_INITIALIZED
);
12647 if (op0
== 0 || op1
== 0)
12650 mem_loc_result
= op0
;
12651 add_loc_descr (&mem_loc_result
, op1
);
12652 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12653 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12654 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12655 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12656 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12660 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12662 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12667 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12668 base_type_for_mode (mode
, 1),
12686 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12687 VAR_INIT_STATUS_INITIALIZED
);
12692 mem_loc_result
= op0
;
12693 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12697 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12698 #ifdef POINTERS_EXTEND_UNSIGNED
12700 && mem_mode
!= VOIDmode
12701 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12705 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12709 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12710 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12712 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12713 enum machine_mode amode
;
12714 if (type_die
== NULL
)
12716 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12718 if (INTVAL (rtl
) >= 0
12719 && amode
!= BLKmode
12720 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12721 /* const DW_OP_GNU_convert <XXX> vs.
12722 DW_OP_GNU_const_type <XXX, 1, const>. */
12723 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12724 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12726 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12727 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12728 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12729 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12730 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12731 add_loc_descr (&mem_loc_result
, op0
);
12732 return mem_loc_result
;
12734 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12736 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12737 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12738 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12739 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12740 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12743 mem_loc_result
->dw_loc_oprnd2
.val_class
12744 = dw_val_class_const_double
;
12745 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12746 = double_int::from_shwi (INTVAL (rtl
));
12754 dw_die_ref type_die
;
12756 /* Note that a CONST_DOUBLE rtx could represent either an integer
12757 or a floating-point constant. A CONST_DOUBLE is used whenever
12758 the constant requires more than one word in order to be
12759 adequately represented. We output CONST_DOUBLEs as blocks. */
12760 if (mode
== VOIDmode
12761 || (GET_MODE (rtl
) == VOIDmode
12762 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12764 type_die
= base_type_for_mode (mode
,
12765 GET_MODE_CLASS (mode
) == MODE_INT
);
12766 if (type_die
== NULL
)
12768 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12769 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12770 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12771 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12772 if (SCALAR_FLOAT_MODE_P (mode
))
12774 unsigned int length
= GET_MODE_SIZE (mode
);
12775 unsigned char *array
12776 = (unsigned char*) ggc_alloc_atomic (length
);
12778 insert_float (rtl
, array
);
12779 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12780 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12781 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12782 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12786 mem_loc_result
->dw_loc_oprnd2
.val_class
12787 = dw_val_class_const_double
;
12788 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12789 = rtx_to_double_int (rtl
);
12795 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12799 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12803 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12807 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12811 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12815 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12819 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12823 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12827 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12831 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12836 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12841 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12846 if (CONST_INT_P (XEXP (rtl
, 1))
12847 && CONST_INT_P (XEXP (rtl
, 2))
12848 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12849 + (unsigned) INTVAL (XEXP (rtl
, 2))
12850 <= GET_MODE_BITSIZE (mode
))
12851 && GET_MODE_CLASS (mode
) == MODE_INT
12852 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12853 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12856 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12857 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12860 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12864 mem_loc_result
= op0
;
12865 size
= INTVAL (XEXP (rtl
, 1));
12866 shift
= INTVAL (XEXP (rtl
, 2));
12867 if (BITS_BIG_ENDIAN
)
12868 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12870 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12872 add_loc_descr (&mem_loc_result
,
12873 int_loc_descriptor (DWARF2_ADDR_SIZE
12875 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12877 if (size
!= (int) DWARF2_ADDR_SIZE
)
12879 add_loc_descr (&mem_loc_result
,
12880 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12881 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12888 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12889 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12890 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12891 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12892 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12893 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12894 VAR_INIT_STATUS_INITIALIZED
);
12895 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12896 VAR_INIT_STATUS_INITIALIZED
);
12897 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12900 mem_loc_result
= op1
;
12901 add_loc_descr (&mem_loc_result
, op2
);
12902 add_loc_descr (&mem_loc_result
, op0
);
12903 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12904 add_loc_descr (&mem_loc_result
, bra_node
);
12905 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12906 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12907 add_loc_descr (&mem_loc_result
, drop_node
);
12908 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12909 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12914 case FLOAT_TRUNCATE
:
12916 case UNSIGNED_FLOAT
:
12921 dw_die_ref type_die
;
12922 dw_loc_descr_ref cvt
;
12924 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12925 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12928 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12929 && (GET_CODE (rtl
) == FLOAT
12930 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12931 <= DWARF2_ADDR_SIZE
))
12933 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12934 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12935 if (type_die
== NULL
)
12937 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12938 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12939 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12940 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12941 add_loc_descr (&op0
, cvt
);
12943 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12944 if (type_die
== NULL
)
12946 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12947 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12948 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12949 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12950 add_loc_descr (&op0
, cvt
);
12951 if (GET_MODE_CLASS (mode
) == MODE_INT
12952 && (GET_CODE (rtl
) == FIX
12953 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12955 op0
= convert_descriptor_to_mode (mode
, op0
);
12959 mem_loc_result
= op0
;
12966 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12971 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12975 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12980 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12984 /* In theory, we could implement the above. */
12985 /* DWARF cannot represent the unsigned compare operations
13010 case FRACT_CONVERT
:
13011 case UNSIGNED_FRACT_CONVERT
:
13013 case UNSIGNED_SAT_FRACT
:
13019 case VEC_DUPLICATE
:
13023 case STRICT_LOW_PART
:
13028 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13029 can't express it in the debug info. This can happen e.g. with some
13034 resolve_one_addr (&rtl
, NULL
);
13038 #ifdef ENABLE_CHECKING
13039 print_rtl (stderr
, rtl
);
13040 gcc_unreachable ();
13046 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13047 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13049 return mem_loc_result
;
13052 /* Return a descriptor that describes the concatenation of two locations.
13053 This is typically a complex variable. */
13055 static dw_loc_descr_ref
13056 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13058 dw_loc_descr_ref cc_loc_result
= NULL
;
13059 dw_loc_descr_ref x0_ref
13060 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13061 dw_loc_descr_ref x1_ref
13062 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13064 if (x0_ref
== 0 || x1_ref
== 0)
13067 cc_loc_result
= x0_ref
;
13068 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13070 add_loc_descr (&cc_loc_result
, x1_ref
);
13071 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13073 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13074 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13076 return cc_loc_result
;
13079 /* Return a descriptor that describes the concatenation of N
13082 static dw_loc_descr_ref
13083 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13086 dw_loc_descr_ref cc_loc_result
= NULL
;
13087 unsigned int n
= XVECLEN (concatn
, 0);
13089 for (i
= 0; i
< n
; ++i
)
13091 dw_loc_descr_ref ref
;
13092 rtx x
= XVECEXP (concatn
, 0, i
);
13094 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13098 add_loc_descr (&cc_loc_result
, ref
);
13099 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13102 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13103 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13105 return cc_loc_result
;
13108 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13109 for DEBUG_IMPLICIT_PTR RTL. */
13111 static dw_loc_descr_ref
13112 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13114 dw_loc_descr_ref ret
;
13119 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13120 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13121 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13122 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13123 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13124 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13127 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13128 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13129 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13133 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13134 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13139 /* Output a proper Dwarf location descriptor for a variable or parameter
13140 which is either allocated in a register or in a memory location. For a
13141 register, we just generate an OP_REG and the register number. For a
13142 memory location we provide a Dwarf postfix expression describing how to
13143 generate the (dynamic) address of the object onto the address stack.
13145 MODE is mode of the decl if this loc_descriptor is going to be used in
13146 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13147 allowed, VOIDmode otherwise.
13149 If we don't know how to describe it, return 0. */
13151 static dw_loc_descr_ref
13152 loc_descriptor (rtx rtl
, enum machine_mode mode
,
13153 enum var_init_status initialized
)
13155 dw_loc_descr_ref loc_result
= NULL
;
13157 switch (GET_CODE (rtl
))
13160 /* The case of a subreg may arise when we have a local (register)
13161 variable or a formal (register) parameter which doesn't quite fill
13162 up an entire register. For now, just assume that it is
13163 legitimate to make the Dwarf info refer to the whole register which
13164 contains the given subreg. */
13165 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13166 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13167 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13173 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13177 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13178 GET_MODE (rtl
), initialized
);
13179 if (loc_result
== NULL
)
13180 loc_result
= tls_mem_loc_descriptor (rtl
);
13181 if (loc_result
== NULL
)
13183 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13184 if (new_rtl
!= rtl
)
13185 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13190 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13195 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13200 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13202 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13203 if (GET_CODE (loc
) == EXPR_LIST
)
13204 loc
= XEXP (loc
, 0);
13205 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13209 rtl
= XEXP (rtl
, 1);
13214 rtvec par_elems
= XVEC (rtl
, 0);
13215 int num_elem
= GET_NUM_ELEM (par_elems
);
13216 enum machine_mode mode
;
13219 /* Create the first one, so we have something to add to. */
13220 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13221 VOIDmode
, initialized
);
13222 if (loc_result
== NULL
)
13224 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13225 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13226 for (i
= 1; i
< num_elem
; i
++)
13228 dw_loc_descr_ref temp
;
13230 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13231 VOIDmode
, initialized
);
13234 add_loc_descr (&loc_result
, temp
);
13235 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13236 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13242 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13243 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13248 if (mode
== VOIDmode
)
13249 mode
= GET_MODE (rtl
);
13251 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13253 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13255 /* Note that a CONST_DOUBLE rtx could represent either an integer
13256 or a floating-point constant. A CONST_DOUBLE is used whenever
13257 the constant requires more than one word in order to be
13258 adequately represented. We output CONST_DOUBLEs as blocks. */
13259 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13260 GET_MODE_SIZE (mode
), 0);
13261 if (SCALAR_FLOAT_MODE_P (mode
))
13263 unsigned int length
= GET_MODE_SIZE (mode
);
13264 unsigned char *array
13265 = (unsigned char*) ggc_alloc_atomic (length
);
13267 insert_float (rtl
, array
);
13268 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13269 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13270 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13271 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13275 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13276 loc_result
->dw_loc_oprnd2
.v
.val_double
13277 = rtx_to_double_int (rtl
);
13283 if (mode
== VOIDmode
)
13284 mode
= GET_MODE (rtl
);
13286 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13288 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13289 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13290 unsigned char *array
= (unsigned char *)
13291 ggc_alloc_atomic (length
* elt_size
);
13295 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13296 switch (GET_MODE_CLASS (mode
))
13298 case MODE_VECTOR_INT
:
13299 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13301 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13302 double_int val
= rtx_to_double_int (elt
);
13304 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13305 insert_int (val
.to_shwi (), elt_size
, p
);
13308 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13309 insert_double (val
, p
);
13314 case MODE_VECTOR_FLOAT
:
13315 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13317 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13318 insert_float (elt
, p
);
13323 gcc_unreachable ();
13326 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13327 length
* elt_size
, 0);
13328 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13329 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13330 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13331 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13336 if (mode
== VOIDmode
13337 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13338 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13339 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13341 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13346 if (!const_ok_for_output (rtl
))
13349 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13350 && (dwarf_version
>= 4 || !dwarf_strict
))
13352 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13353 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13354 vec_safe_push (used_rtx_array
, rtl
);
13358 case DEBUG_IMPLICIT_PTR
:
13359 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13363 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13364 && CONST_INT_P (XEXP (rtl
, 1)))
13367 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13373 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13374 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13375 && dwarf_version
>= 4)
13376 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13378 /* Value expression. */
13379 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13381 add_loc_descr (&loc_result
,
13382 new_loc_descr (DW_OP_stack_value
, 0, 0));
13390 /* We need to figure out what section we should use as the base for the
13391 address ranges where a given location is valid.
13392 1. If this particular DECL has a section associated with it, use that.
13393 2. If this function has a section associated with it, use that.
13394 3. Otherwise, use the text section.
13395 XXX: If you split a variable across multiple sections, we won't notice. */
13397 static const char *
13398 secname_for_decl (const_tree decl
)
13400 const char *secname
;
13402 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13404 tree sectree
= DECL_SECTION_NAME (decl
);
13405 secname
= TREE_STRING_POINTER (sectree
);
13407 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13409 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13410 secname
= TREE_STRING_POINTER (sectree
);
13412 else if (cfun
&& in_cold_section_p
)
13413 secname
= crtl
->subsections
.cold_section_label
;
13415 secname
= text_section_label
;
13420 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13423 decl_by_reference_p (tree decl
)
13425 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13426 || TREE_CODE (decl
) == VAR_DECL
)
13427 && DECL_BY_REFERENCE (decl
));
13430 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13433 static dw_loc_descr_ref
13434 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13435 enum var_init_status initialized
)
13437 int have_address
= 0;
13438 dw_loc_descr_ref descr
;
13439 enum machine_mode mode
;
13441 if (want_address
!= 2)
13443 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13445 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13447 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13448 if (GET_CODE (varloc
) == EXPR_LIST
)
13449 varloc
= XEXP (varloc
, 0);
13450 mode
= GET_MODE (varloc
);
13451 if (MEM_P (varloc
))
13453 rtx addr
= XEXP (varloc
, 0);
13454 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13455 mode
, initialized
);
13460 rtx x
= avoid_constant_pool_reference (varloc
);
13462 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13467 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13474 if (GET_CODE (varloc
) == VAR_LOCATION
)
13475 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13477 mode
= DECL_MODE (loc
);
13478 descr
= loc_descriptor (varloc
, mode
, initialized
);
13485 if (want_address
== 2 && !have_address
13486 && (dwarf_version
>= 4 || !dwarf_strict
))
13488 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13490 expansion_failed (loc
, NULL_RTX
,
13491 "DWARF address size mismatch");
13494 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13497 /* Show if we can't fill the request for an address. */
13498 if (want_address
&& !have_address
)
13500 expansion_failed (loc
, NULL_RTX
,
13501 "Want address and only have value");
13505 /* If we've got an address and don't want one, dereference. */
13506 if (!want_address
&& have_address
)
13508 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13509 enum dwarf_location_atom op
;
13511 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13513 expansion_failed (loc
, NULL_RTX
,
13514 "DWARF address size mismatch");
13517 else if (size
== DWARF2_ADDR_SIZE
)
13520 op
= DW_OP_deref_size
;
13522 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13528 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13529 if it is not possible. */
13531 static dw_loc_descr_ref
13532 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13534 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13535 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13536 else if (dwarf_version
>= 3 || !dwarf_strict
)
13537 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13542 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13543 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13545 static dw_loc_descr_ref
13546 dw_sra_loc_expr (tree decl
, rtx loc
)
13549 unsigned int padsize
= 0;
13550 dw_loc_descr_ref descr
, *descr_tail
;
13551 unsigned HOST_WIDE_INT decl_size
;
13553 enum var_init_status initialized
;
13555 if (DECL_SIZE (decl
) == NULL
13556 || !host_integerp (DECL_SIZE (decl
), 1))
13559 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13561 descr_tail
= &descr
;
13563 for (p
= loc
; p
; p
= XEXP (p
, 1))
13565 unsigned int bitsize
= decl_piece_bitsize (p
);
13566 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13567 dw_loc_descr_ref cur_descr
;
13568 dw_loc_descr_ref
*tail
, last
= NULL
;
13569 unsigned int opsize
= 0;
13571 if (loc_note
== NULL_RTX
13572 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13574 padsize
+= bitsize
;
13577 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13578 varloc
= NOTE_VAR_LOCATION (loc_note
);
13579 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13580 if (cur_descr
== NULL
)
13582 padsize
+= bitsize
;
13586 /* Check that cur_descr either doesn't use
13587 DW_OP_*piece operations, or their sum is equal
13588 to bitsize. Otherwise we can't embed it. */
13589 for (tail
= &cur_descr
; *tail
!= NULL
;
13590 tail
= &(*tail
)->dw_loc_next
)
13591 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13593 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13597 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13599 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13603 if (last
!= NULL
&& opsize
!= bitsize
)
13605 padsize
+= bitsize
;
13606 /* Discard the current piece of the descriptor and release any
13607 addr_table entries it uses. */
13608 remove_loc_list_addr_table_entries (cur_descr
);
13612 /* If there is a hole, add DW_OP_*piece after empty DWARF
13613 expression, which means that those bits are optimized out. */
13616 if (padsize
> decl_size
)
13618 remove_loc_list_addr_table_entries (cur_descr
);
13619 goto discard_descr
;
13621 decl_size
-= padsize
;
13622 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13623 if (*descr_tail
== NULL
)
13625 remove_loc_list_addr_table_entries (cur_descr
);
13626 goto discard_descr
;
13628 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13631 *descr_tail
= cur_descr
;
13633 if (bitsize
> decl_size
)
13634 goto discard_descr
;
13635 decl_size
-= bitsize
;
13638 HOST_WIDE_INT offset
= 0;
13639 if (GET_CODE (varloc
) == VAR_LOCATION
13640 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13642 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13643 if (GET_CODE (varloc
) == EXPR_LIST
)
13644 varloc
= XEXP (varloc
, 0);
13648 if (GET_CODE (varloc
) == CONST
13649 || GET_CODE (varloc
) == SIGN_EXTEND
13650 || GET_CODE (varloc
) == ZERO_EXTEND
)
13651 varloc
= XEXP (varloc
, 0);
13652 else if (GET_CODE (varloc
) == SUBREG
)
13653 varloc
= SUBREG_REG (varloc
);
13658 /* DW_OP_bit_size offset should be zero for register
13659 or implicit location descriptions and empty location
13660 descriptions, but for memory addresses needs big endian
13662 if (MEM_P (varloc
))
13664 unsigned HOST_WIDE_INT memsize
13665 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13666 if (memsize
!= bitsize
)
13668 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13669 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13670 goto discard_descr
;
13671 if (memsize
< bitsize
)
13672 goto discard_descr
;
13673 if (BITS_BIG_ENDIAN
)
13674 offset
= memsize
- bitsize
;
13678 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13679 if (*descr_tail
== NULL
)
13680 goto discard_descr
;
13681 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13685 /* If there were any non-empty expressions, add padding till the end of
13687 if (descr
!= NULL
&& decl_size
!= 0)
13689 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13690 if (*descr_tail
== NULL
)
13691 goto discard_descr
;
13696 /* Discard the descriptor and release any addr_table entries it uses. */
13697 remove_loc_list_addr_table_entries (descr
);
13701 /* Return the dwarf representation of the location list LOC_LIST of
13702 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13705 static dw_loc_list_ref
13706 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13708 const char *endname
, *secname
;
13710 enum var_init_status initialized
;
13711 struct var_loc_node
*node
;
13712 dw_loc_descr_ref descr
;
13713 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13714 dw_loc_list_ref list
= NULL
;
13715 dw_loc_list_ref
*listp
= &list
;
13717 /* Now that we know what section we are using for a base,
13718 actually construct the list of locations.
13719 The first location information is what is passed to the
13720 function that creates the location list, and the remaining
13721 locations just get added on to that list.
13722 Note that we only know the start address for a location
13723 (IE location changes), so to build the range, we use
13724 the range [current location start, next location start].
13725 This means we have to special case the last node, and generate
13726 a range of [last location start, end of function label]. */
13728 secname
= secname_for_decl (decl
);
13730 for (node
= loc_list
->first
; node
; node
= node
->next
)
13731 if (GET_CODE (node
->loc
) == EXPR_LIST
13732 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13734 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13736 /* This requires DW_OP_{,bit_}piece, which is not usable
13737 inside DWARF expressions. */
13738 if (want_address
!= 2)
13740 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13746 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13747 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13748 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13752 bool range_across_switch
= false;
13753 /* If section switch happens in between node->label
13754 and node->next->label (or end of function) and
13755 we can't emit it as a single entry list,
13756 emit two ranges, first one ending at the end
13757 of first partition and second one starting at the
13758 beginning of second partition. */
13759 if (node
== loc_list
->last_before_switch
13760 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13761 && current_function_decl
)
13763 endname
= cfun
->fde
->dw_fde_end
;
13764 range_across_switch
= true;
13766 /* The variable has a location between NODE->LABEL and
13767 NODE->NEXT->LABEL. */
13768 else if (node
->next
)
13769 endname
= node
->next
->label
;
13770 /* If the variable has a location at the last label
13771 it keeps its location until the end of function. */
13772 else if (!current_function_decl
)
13773 endname
= text_end_label
;
13776 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13777 FUNC_LABEL_ID (cfun
));
13778 endname
= ggc_strdup (label_id
);
13781 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13782 if (TREE_CODE (decl
) == PARM_DECL
13783 && node
== loc_list
->first
13784 && GET_CODE (node
->loc
) == NOTE
13785 && strcmp (node
->label
, endname
) == 0)
13786 (*listp
)->force
= true;
13787 listp
= &(*listp
)->dw_loc_next
;
13789 if (range_across_switch
)
13791 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13792 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13795 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13796 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13797 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13800 gcc_assert (descr
);
13801 /* The variable has a location between NODE->LABEL and
13802 NODE->NEXT->LABEL. */
13804 endname
= node
->next
->label
;
13806 endname
= cfun
->fde
->dw_fde_second_end
;
13807 *listp
= new_loc_list (descr
,
13808 cfun
->fde
->dw_fde_second_begin
,
13810 listp
= &(*listp
)->dw_loc_next
;
13815 /* Try to avoid the overhead of a location list emitting a location
13816 expression instead, but only if we didn't have more than one
13817 location entry in the first place. If some entries were not
13818 representable, we don't want to pretend a single entry that was
13819 applies to the entire scope in which the variable is
13821 if (list
&& loc_list
->first
->next
)
13827 /* Return if the loc_list has only single element and thus can be represented
13828 as location description. */
13831 single_element_loc_list_p (dw_loc_list_ref list
)
13833 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13834 return !list
->ll_symbol
;
13837 /* To each location in list LIST add loc descr REF. */
13840 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13842 dw_loc_descr_ref copy
;
13843 add_loc_descr (&list
->expr
, ref
);
13844 list
= list
->dw_loc_next
;
13847 copy
= ggc_alloc_dw_loc_descr_node ();
13848 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13849 add_loc_descr (&list
->expr
, copy
);
13850 while (copy
->dw_loc_next
)
13852 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13853 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13854 copy
->dw_loc_next
= new_copy
;
13857 list
= list
->dw_loc_next
;
13861 /* Given two lists RET and LIST
13862 produce location list that is result of adding expression in LIST
13863 to expression in RET on each position in program.
13864 Might be destructive on both RET and LIST.
13866 TODO: We handle only simple cases of RET or LIST having at most one
13867 element. General case would inolve sorting the lists in program order
13868 and merging them that will need some additional work.
13869 Adding that will improve quality of debug info especially for SRA-ed
13873 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13882 if (!list
->dw_loc_next
)
13884 add_loc_descr_to_each (*ret
, list
->expr
);
13887 if (!(*ret
)->dw_loc_next
)
13889 add_loc_descr_to_each (list
, (*ret
)->expr
);
13893 expansion_failed (NULL_TREE
, NULL_RTX
,
13894 "Don't know how to merge two non-trivial"
13895 " location lists.\n");
13900 /* LOC is constant expression. Try a luck, look it up in constant
13901 pool and return its loc_descr of its address. */
13903 static dw_loc_descr_ref
13904 cst_pool_loc_descr (tree loc
)
13906 /* Get an RTL for this, if something has been emitted. */
13907 rtx rtl
= lookup_constant_def (loc
);
13909 if (!rtl
|| !MEM_P (rtl
))
13914 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13916 /* TODO: We might get more coverage if we was actually delaying expansion
13917 of all expressions till end of compilation when constant pools are fully
13919 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13921 expansion_failed (loc
, NULL_RTX
,
13922 "CST value in contant pool but not marked.");
13925 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13926 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13929 /* Return dw_loc_list representing address of addr_expr LOC
13930 by looking for inner INDIRECT_REF expression and turning
13931 it into simple arithmetics. */
13933 static dw_loc_list_ref
13934 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13937 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13938 enum machine_mode mode
;
13939 int unsignedp
, volatilep
= 0;
13940 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13942 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13943 &bitsize
, &bitpos
, &offset
, &mode
,
13944 &unsignedp
, &volatilep
, false);
13946 if (bitpos
% BITS_PER_UNIT
)
13948 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13951 if (!INDIRECT_REF_P (obj
))
13953 expansion_failed (obj
,
13954 NULL_RTX
, "no indirect ref in inner refrence");
13957 if (!offset
&& !bitpos
)
13958 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13960 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13961 && (dwarf_version
>= 4 || !dwarf_strict
))
13963 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13968 /* Variable offset. */
13969 list_ret1
= loc_list_from_tree (offset
, 0);
13970 if (list_ret1
== 0)
13972 add_loc_list (&list_ret
, list_ret1
);
13975 add_loc_descr_to_each (list_ret
,
13976 new_loc_descr (DW_OP_plus
, 0, 0));
13978 bytepos
= bitpos
/ BITS_PER_UNIT
;
13980 add_loc_descr_to_each (list_ret
,
13981 new_loc_descr (DW_OP_plus_uconst
,
13983 else if (bytepos
< 0)
13984 loc_list_plus_const (list_ret
, bytepos
);
13985 add_loc_descr_to_each (list_ret
,
13986 new_loc_descr (DW_OP_stack_value
, 0, 0));
13992 /* Generate Dwarf location list representing LOC.
13993 If WANT_ADDRESS is false, expression computing LOC will be computed
13994 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13995 if WANT_ADDRESS is 2, expression computing address useable in location
13996 will be returned (i.e. DW_OP_reg can be used
13997 to refer to register values). */
13999 static dw_loc_list_ref
14000 loc_list_from_tree (tree loc
, int want_address
)
14002 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
14003 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14004 int have_address
= 0;
14005 enum dwarf_location_atom op
;
14007 /* ??? Most of the time we do not take proper care for sign/zero
14008 extending the values properly. Hopefully this won't be a real
14011 switch (TREE_CODE (loc
))
14014 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14017 case PLACEHOLDER_EXPR
:
14018 /* This case involves extracting fields from an object to determine the
14019 position of other fields. We don't try to encode this here. The
14020 only user of this is Ada, which encodes the needed information using
14021 the names of types. */
14022 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
14026 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14027 /* There are no opcodes for these operations. */
14030 case PREINCREMENT_EXPR
:
14031 case PREDECREMENT_EXPR
:
14032 case POSTINCREMENT_EXPR
:
14033 case POSTDECREMENT_EXPR
:
14034 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14035 /* There are no opcodes for these operations. */
14039 /* If we already want an address, see if there is INDIRECT_REF inside
14040 e.g. for &this->field. */
14043 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14044 (loc
, want_address
== 2);
14047 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14048 && (ret
= cst_pool_loc_descr (loc
)))
14051 /* Otherwise, process the argument and look for the address. */
14052 if (!list_ret
&& !ret
)
14053 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
14057 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14063 if (DECL_THREAD_LOCAL_P (loc
))
14066 enum dwarf_location_atom tls_op
;
14067 enum dtprel_bool dtprel
= dtprel_false
;
14069 if (targetm
.have_tls
)
14071 /* If this is not defined, we have no way to emit the
14073 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14076 /* The way DW_OP_GNU_push_tls_address is specified, we
14077 can only look up addresses of objects in the current
14078 module. We used DW_OP_addr as first op, but that's
14079 wrong, because DW_OP_addr is relocated by the debug
14080 info consumer, while DW_OP_GNU_push_tls_address
14081 operand shouldn't be. */
14082 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14084 dtprel
= dtprel_true
;
14085 tls_op
= DW_OP_GNU_push_tls_address
;
14089 if (!targetm
.emutls
.debug_form_tls_address
14090 || !(dwarf_version
>= 3 || !dwarf_strict
))
14092 /* We stuffed the control variable into the DECL_VALUE_EXPR
14093 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14094 no longer appear in gimple code. We used the control
14095 variable in specific so that we could pick it up here. */
14096 loc
= DECL_VALUE_EXPR (loc
);
14097 tls_op
= DW_OP_form_tls_address
;
14100 rtl
= rtl_for_decl_location (loc
);
14101 if (rtl
== NULL_RTX
)
14106 rtl
= XEXP (rtl
, 0);
14107 if (! CONSTANT_P (rtl
))
14110 ret
= new_addr_loc_descr (rtl
, dtprel
);
14111 ret1
= new_loc_descr (tls_op
, 0, 0);
14112 add_loc_descr (&ret
, ret1
);
14121 if (DECL_HAS_VALUE_EXPR_P (loc
))
14122 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14126 case FUNCTION_DECL
:
14129 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14131 if (loc_list
&& loc_list
->first
)
14133 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14134 have_address
= want_address
!= 0;
14137 rtl
= rtl_for_decl_location (loc
);
14138 if (rtl
== NULL_RTX
)
14140 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14143 else if (CONST_INT_P (rtl
))
14145 HOST_WIDE_INT val
= INTVAL (rtl
);
14146 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14147 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14148 ret
= int_loc_descriptor (val
);
14150 else if (GET_CODE (rtl
) == CONST_STRING
)
14152 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14155 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14156 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14159 enum machine_mode mode
, mem_mode
;
14161 /* Certain constructs can only be represented at top-level. */
14162 if (want_address
== 2)
14164 ret
= loc_descriptor (rtl
, VOIDmode
,
14165 VAR_INIT_STATUS_INITIALIZED
);
14170 mode
= GET_MODE (rtl
);
14171 mem_mode
= VOIDmode
;
14175 mode
= get_address_mode (rtl
);
14176 rtl
= XEXP (rtl
, 0);
14179 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14180 VAR_INIT_STATUS_INITIALIZED
);
14183 expansion_failed (loc
, rtl
,
14184 "failed to produce loc descriptor for rtl");
14191 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14195 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14199 case COMPOUND_EXPR
:
14200 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14203 case VIEW_CONVERT_EXPR
:
14206 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14208 case COMPONENT_REF
:
14209 case BIT_FIELD_REF
:
14211 case ARRAY_RANGE_REF
:
14212 case REALPART_EXPR
:
14213 case IMAGPART_EXPR
:
14216 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14217 enum machine_mode mode
;
14218 int unsignedp
, volatilep
= 0;
14220 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14221 &unsignedp
, &volatilep
, false);
14223 gcc_assert (obj
!= loc
);
14225 list_ret
= loc_list_from_tree (obj
,
14227 && !bitpos
&& !offset
? 2 : 1);
14228 /* TODO: We can extract value of the small expression via shifting even
14229 for nonzero bitpos. */
14232 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14234 expansion_failed (loc
, NULL_RTX
,
14235 "bitfield access");
14239 if (offset
!= NULL_TREE
)
14241 /* Variable offset. */
14242 list_ret1
= loc_list_from_tree (offset
, 0);
14243 if (list_ret1
== 0)
14245 add_loc_list (&list_ret
, list_ret1
);
14248 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14251 bytepos
= bitpos
/ BITS_PER_UNIT
;
14253 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14254 else if (bytepos
< 0)
14255 loc_list_plus_const (list_ret
, bytepos
);
14262 if ((want_address
|| !host_integerp (loc
, 0))
14263 && (ret
= cst_pool_loc_descr (loc
)))
14265 else if (want_address
== 2
14266 && host_integerp (loc
, 0)
14267 && (ret
= address_of_int_loc_descriptor
14268 (int_size_in_bytes (TREE_TYPE (loc
)),
14269 tree_low_cst (loc
, 0))))
14271 else if (host_integerp (loc
, 0))
14272 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
14275 expansion_failed (loc
, NULL_RTX
,
14276 "Integer operand is not host integer");
14285 if ((ret
= cst_pool_loc_descr (loc
)))
14288 /* We can construct small constants here using int_loc_descriptor. */
14289 expansion_failed (loc
, NULL_RTX
,
14290 "constructor or constant not in constant pool");
14293 case TRUTH_AND_EXPR
:
14294 case TRUTH_ANDIF_EXPR
:
14299 case TRUTH_XOR_EXPR
:
14304 case TRUTH_OR_EXPR
:
14305 case TRUTH_ORIF_EXPR
:
14310 case FLOOR_DIV_EXPR
:
14311 case CEIL_DIV_EXPR
:
14312 case ROUND_DIV_EXPR
:
14313 case TRUNC_DIV_EXPR
:
14314 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14323 case FLOOR_MOD_EXPR
:
14324 case CEIL_MOD_EXPR
:
14325 case ROUND_MOD_EXPR
:
14326 case TRUNC_MOD_EXPR
:
14327 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14332 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14333 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14334 if (list_ret
== 0 || list_ret1
== 0)
14337 add_loc_list (&list_ret
, list_ret1
);
14340 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14341 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14342 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14343 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14344 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14356 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14359 case POINTER_PLUS_EXPR
:
14361 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14363 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14367 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14375 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14382 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14389 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14396 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14411 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14412 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14413 if (list_ret
== 0 || list_ret1
== 0)
14416 add_loc_list (&list_ret
, list_ret1
);
14419 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14422 case TRUTH_NOT_EXPR
:
14436 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14440 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14446 const enum tree_code code
=
14447 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14449 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14450 build2 (code
, integer_type_node
,
14451 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14452 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14455 /* ... fall through ... */
14459 dw_loc_descr_ref lhs
14460 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14461 dw_loc_list_ref rhs
14462 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14463 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14465 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14466 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14469 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14470 add_loc_descr_to_each (list_ret
, bra_node
);
14472 add_loc_list (&list_ret
, rhs
);
14473 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14474 add_loc_descr_to_each (list_ret
, jump_node
);
14476 add_loc_descr_to_each (list_ret
, lhs
);
14477 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14478 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14480 /* ??? Need a node to point the skip at. Use a nop. */
14481 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14482 add_loc_descr_to_each (list_ret
, tmp
);
14483 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14484 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14488 case FIX_TRUNC_EXPR
:
14492 /* Leave front-end specific codes as simply unknown. This comes
14493 up, for instance, with the C STMT_EXPR. */
14494 if ((unsigned int) TREE_CODE (loc
)
14495 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14497 expansion_failed (loc
, NULL_RTX
,
14498 "language specific tree node");
14502 #ifdef ENABLE_CHECKING
14503 /* Otherwise this is a generic code; we should just lists all of
14504 these explicitly. We forgot one. */
14505 gcc_unreachable ();
14507 /* In a release build, we want to degrade gracefully: better to
14508 generate incomplete debugging information than to crash. */
14513 if (!ret
&& !list_ret
)
14516 if (want_address
== 2 && !have_address
14517 && (dwarf_version
>= 4 || !dwarf_strict
))
14519 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14521 expansion_failed (loc
, NULL_RTX
,
14522 "DWARF address size mismatch");
14526 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14528 add_loc_descr_to_each (list_ret
,
14529 new_loc_descr (DW_OP_stack_value
, 0, 0));
14532 /* Show if we can't fill the request for an address. */
14533 if (want_address
&& !have_address
)
14535 expansion_failed (loc
, NULL_RTX
,
14536 "Want address and only have value");
14540 gcc_assert (!ret
|| !list_ret
);
14542 /* If we've got an address and don't want one, dereference. */
14543 if (!want_address
&& have_address
)
14545 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14547 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14549 expansion_failed (loc
, NULL_RTX
,
14550 "DWARF address size mismatch");
14553 else if (size
== DWARF2_ADDR_SIZE
)
14556 op
= DW_OP_deref_size
;
14559 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14561 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14564 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14569 /* Same as above but return only single location expression. */
14570 static dw_loc_descr_ref
14571 loc_descriptor_from_tree (tree loc
, int want_address
)
14573 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14576 if (ret
->dw_loc_next
)
14578 expansion_failed (loc
, NULL_RTX
,
14579 "Location list where only loc descriptor needed");
14585 /* Given a value, round it up to the lowest multiple of `boundary'
14586 which is not less than the value itself. */
14588 static inline HOST_WIDE_INT
14589 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14591 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14594 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14595 pointer to the declared type for the relevant field variable, or return
14596 `integer_type_node' if the given node turns out to be an
14597 ERROR_MARK node. */
14600 field_type (const_tree decl
)
14604 if (TREE_CODE (decl
) == ERROR_MARK
)
14605 return integer_type_node
;
14607 type
= DECL_BIT_FIELD_TYPE (decl
);
14608 if (type
== NULL_TREE
)
14609 type
= TREE_TYPE (decl
);
14614 /* Given a pointer to a tree node, return the alignment in bits for
14615 it, or else return BITS_PER_WORD if the node actually turns out to
14616 be an ERROR_MARK node. */
14618 static inline unsigned
14619 simple_type_align_in_bits (const_tree type
)
14621 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14624 static inline unsigned
14625 simple_decl_align_in_bits (const_tree decl
)
14627 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14630 /* Return the result of rounding T up to ALIGN. */
14632 static inline double_int
14633 round_up_to_align (double_int t
, unsigned int align
)
14635 double_int alignd
= double_int::from_uhwi (align
);
14637 t
+= double_int_minus_one
;
14638 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14643 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14644 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14645 or return 0 if we are unable to determine what that offset is, either
14646 because the argument turns out to be a pointer to an ERROR_MARK node, or
14647 because the offset is actually variable. (We can't handle the latter case
14650 static HOST_WIDE_INT
14651 field_byte_offset (const_tree decl
)
14653 double_int object_offset_in_bits
;
14654 double_int object_offset_in_bytes
;
14655 double_int bitpos_int
;
14657 if (TREE_CODE (decl
) == ERROR_MARK
)
14660 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14662 /* We cannot yet cope with fields whose positions are variable, so
14663 for now, when we see such things, we simply return 0. Someday, we may
14664 be able to handle such cases, but it will be damn difficult. */
14665 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14668 bitpos_int
= tree_to_double_int (bit_position (decl
));
14670 #ifdef PCC_BITFIELD_TYPE_MATTERS
14671 if (PCC_BITFIELD_TYPE_MATTERS
)
14674 tree field_size_tree
;
14675 double_int deepest_bitpos
;
14676 double_int field_size_in_bits
;
14677 unsigned int type_align_in_bits
;
14678 unsigned int decl_align_in_bits
;
14679 double_int type_size_in_bits
;
14681 type
= field_type (decl
);
14682 type_size_in_bits
= double_int_type_size_in_bits (type
);
14683 type_align_in_bits
= simple_type_align_in_bits (type
);
14685 field_size_tree
= DECL_SIZE (decl
);
14687 /* The size could be unspecified if there was an error, or for
14688 a flexible array member. */
14689 if (!field_size_tree
)
14690 field_size_tree
= bitsize_zero_node
;
14692 /* If the size of the field is not constant, use the type size. */
14693 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14694 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14696 field_size_in_bits
= type_size_in_bits
;
14698 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14700 /* The GCC front-end doesn't make any attempt to keep track of the
14701 starting bit offset (relative to the start of the containing
14702 structure type) of the hypothetical "containing object" for a
14703 bit-field. Thus, when computing the byte offset value for the
14704 start of the "containing object" of a bit-field, we must deduce
14705 this information on our own. This can be rather tricky to do in
14706 some cases. For example, handling the following structure type
14707 definition when compiling for an i386/i486 target (which only
14708 aligns long long's to 32-bit boundaries) can be very tricky:
14710 struct S { int field1; long long field2:31; };
14712 Fortunately, there is a simple rule-of-thumb which can be used
14713 in such cases. When compiling for an i386/i486, GCC will
14714 allocate 8 bytes for the structure shown above. It decides to
14715 do this based upon one simple rule for bit-field allocation.
14716 GCC allocates each "containing object" for each bit-field at
14717 the first (i.e. lowest addressed) legitimate alignment boundary
14718 (based upon the required minimum alignment for the declared
14719 type of the field) which it can possibly use, subject to the
14720 condition that there is still enough available space remaining
14721 in the containing object (when allocated at the selected point)
14722 to fully accommodate all of the bits of the bit-field itself.
14724 This simple rule makes it obvious why GCC allocates 8 bytes for
14725 each object of the structure type shown above. When looking
14726 for a place to allocate the "containing object" for `field2',
14727 the compiler simply tries to allocate a 64-bit "containing
14728 object" at each successive 32-bit boundary (starting at zero)
14729 until it finds a place to allocate that 64- bit field such that
14730 at least 31 contiguous (and previously unallocated) bits remain
14731 within that selected 64 bit field. (As it turns out, for the
14732 example above, the compiler finds it is OK to allocate the
14733 "containing object" 64-bit field at bit-offset zero within the
14736 Here we attempt to work backwards from the limited set of facts
14737 we're given, and we try to deduce from those facts, where GCC
14738 must have believed that the containing object started (within
14739 the structure type). The value we deduce is then used (by the
14740 callers of this routine) to generate DW_AT_location and
14741 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14742 the case of DW_AT_location, regular fields as well). */
14744 /* Figure out the bit-distance from the start of the structure to
14745 the "deepest" bit of the bit-field. */
14746 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14748 /* This is the tricky part. Use some fancy footwork to deduce
14749 where the lowest addressed bit of the containing object must
14751 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14753 /* Round up to type_align by default. This works best for
14755 object_offset_in_bits
14756 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14758 if (object_offset_in_bits
.ugt (bitpos_int
))
14760 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14762 /* Round up to decl_align instead. */
14763 object_offset_in_bits
14764 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14768 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14769 object_offset_in_bits
= bitpos_int
;
14771 object_offset_in_bytes
14772 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14773 true, TRUNC_DIV_EXPR
);
14774 return object_offset_in_bytes
.to_shwi ();
14777 /* The following routines define various Dwarf attributes and any data
14778 associated with them. */
14780 /* Add a location description attribute value to a DIE.
14782 This emits location attributes suitable for whole variables and
14783 whole parameters. Note that the location attributes for struct fields are
14784 generated by the routine `data_member_location_attribute' below. */
14787 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14788 dw_loc_list_ref descr
)
14792 if (single_element_loc_list_p (descr
))
14793 add_AT_loc (die
, attr_kind
, descr
->expr
);
14795 add_AT_loc_list (die
, attr_kind
, descr
);
14798 /* Add DW_AT_accessibility attribute to DIE if needed. */
14801 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14803 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14804 children, otherwise the default is DW_ACCESS_public. In DWARF2
14805 the default has always been DW_ACCESS_public. */
14806 if (TREE_PROTECTED (decl
))
14807 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14808 else if (TREE_PRIVATE (decl
))
14810 if (dwarf_version
== 2
14811 || die
->die_parent
== NULL
14812 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14813 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14815 else if (dwarf_version
> 2
14817 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14818 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14821 /* Attach the specialized form of location attribute used for data members of
14822 struct and union types. In the special case of a FIELD_DECL node which
14823 represents a bit-field, the "offset" part of this special location
14824 descriptor must indicate the distance in bytes from the lowest-addressed
14825 byte of the containing struct or union type to the lowest-addressed byte of
14826 the "containing object" for the bit-field. (See the `field_byte_offset'
14829 For any given bit-field, the "containing object" is a hypothetical object
14830 (of some integral or enum type) within which the given bit-field lives. The
14831 type of this hypothetical "containing object" is always the same as the
14832 declared type of the individual bit-field itself (for GCC anyway... the
14833 DWARF spec doesn't actually mandate this). Note that it is the size (in
14834 bytes) of the hypothetical "containing object" which will be given in the
14835 DW_AT_byte_size attribute for this bit-field. (See the
14836 `byte_size_attribute' function below.) It is also used when calculating the
14837 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14838 function below.) */
14841 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14843 HOST_WIDE_INT offset
;
14844 dw_loc_descr_ref loc_descr
= 0;
14846 if (TREE_CODE (decl
) == TREE_BINFO
)
14848 /* We're working on the TAG_inheritance for a base class. */
14849 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14851 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14852 aren't at a fixed offset from all (sub)objects of the same
14853 type. We need to extract the appropriate offset from our
14854 vtable. The following dwarf expression means
14856 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14858 This is specific to the V3 ABI, of course. */
14860 dw_loc_descr_ref tmp
;
14862 /* Make a copy of the object address. */
14863 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14864 add_loc_descr (&loc_descr
, tmp
);
14866 /* Extract the vtable address. */
14867 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14868 add_loc_descr (&loc_descr
, tmp
);
14870 /* Calculate the address of the offset. */
14871 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14872 gcc_assert (offset
< 0);
14874 tmp
= int_loc_descriptor (-offset
);
14875 add_loc_descr (&loc_descr
, tmp
);
14876 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14877 add_loc_descr (&loc_descr
, tmp
);
14879 /* Extract the offset. */
14880 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14881 add_loc_descr (&loc_descr
, tmp
);
14883 /* Add it to the object address. */
14884 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14885 add_loc_descr (&loc_descr
, tmp
);
14888 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14891 offset
= field_byte_offset (decl
);
14895 if (dwarf_version
> 2)
14897 /* Don't need to output a location expression, just the constant. */
14899 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14901 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14906 enum dwarf_location_atom op
;
14908 /* The DWARF2 standard says that we should assume that the structure
14909 address is already on the stack, so we can specify a structure
14910 field address by using DW_OP_plus_uconst. */
14911 op
= DW_OP_plus_uconst
;
14912 loc_descr
= new_loc_descr (op
, offset
, 0);
14916 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14919 /* Writes integer values to dw_vec_const array. */
14922 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14926 *dest
++ = val
& 0xff;
14932 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14934 static HOST_WIDE_INT
14935 extract_int (const unsigned char *src
, unsigned int size
)
14937 HOST_WIDE_INT val
= 0;
14943 val
|= *--src
& 0xff;
14949 /* Writes double_int values to dw_vec_const array. */
14952 insert_double (double_int val
, unsigned char *dest
)
14954 unsigned char *p0
= dest
;
14955 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14957 if (WORDS_BIG_ENDIAN
)
14963 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14964 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14967 /* Writes floating point values to dw_vec_const array. */
14970 insert_float (const_rtx rtl
, unsigned char *array
)
14972 REAL_VALUE_TYPE rv
;
14976 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14977 real_to_target (val
, &rv
, GET_MODE (rtl
));
14979 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14980 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14982 insert_int (val
[i
], 4, array
);
14987 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14988 does not have a "location" either in memory or in a register. These
14989 things can arise in GNU C when a constant is passed as an actual parameter
14990 to an inlined function. They can also arise in C++ where declared
14991 constants do not necessarily get memory "homes". */
14994 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14996 switch (GET_CODE (rtl
))
15000 HOST_WIDE_INT val
= INTVAL (rtl
);
15003 add_AT_int (die
, DW_AT_const_value
, val
);
15005 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15010 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15011 floating-point constant. A CONST_DOUBLE is used whenever the
15012 constant requires more than one word in order to be adequately
15015 enum machine_mode mode
= GET_MODE (rtl
);
15017 if (SCALAR_FLOAT_MODE_P (mode
))
15019 unsigned int length
= GET_MODE_SIZE (mode
);
15020 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
15022 insert_float (rtl
, array
);
15023 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15026 add_AT_double (die
, DW_AT_const_value
,
15027 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15033 enum machine_mode mode
= GET_MODE (rtl
);
15034 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15035 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15036 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
15037 (length
* elt_size
);
15041 switch (GET_MODE_CLASS (mode
))
15043 case MODE_VECTOR_INT
:
15044 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15046 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15047 double_int val
= rtx_to_double_int (elt
);
15049 if (elt_size
<= sizeof (HOST_WIDE_INT
))
15050 insert_int (val
.to_shwi (), elt_size
, p
);
15053 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
15054 insert_double (val
, p
);
15059 case MODE_VECTOR_FLOAT
:
15060 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15062 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15063 insert_float (elt
, p
);
15068 gcc_unreachable ();
15071 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15076 if (dwarf_version
>= 4 || !dwarf_strict
)
15078 dw_loc_descr_ref loc_result
;
15079 resolve_one_addr (&rtl
, NULL
);
15081 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15082 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15083 add_AT_loc (die
, DW_AT_location
, loc_result
);
15084 vec_safe_push (used_rtx_array
, rtl
);
15090 if (CONSTANT_P (XEXP (rtl
, 0)))
15091 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15094 if (!const_ok_for_output (rtl
))
15097 if (dwarf_version
>= 4 || !dwarf_strict
)
15102 /* In cases where an inlined instance of an inline function is passed
15103 the address of an `auto' variable (which is local to the caller) we
15104 can get a situation where the DECL_RTL of the artificial local
15105 variable (for the inlining) which acts as a stand-in for the
15106 corresponding formal parameter (of the inline function) will look
15107 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15108 exactly a compile-time constant expression, but it isn't the address
15109 of the (artificial) local variable either. Rather, it represents the
15110 *value* which the artificial local variable always has during its
15111 lifetime. We currently have no way to represent such quasi-constant
15112 values in Dwarf, so for now we just punt and generate nothing. */
15120 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15121 && MEM_READONLY_P (rtl
)
15122 && GET_MODE (rtl
) == BLKmode
)
15124 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15130 /* No other kinds of rtx should be possible here. */
15131 gcc_unreachable ();
15136 /* Determine whether the evaluation of EXPR references any variables
15137 or functions which aren't otherwise used (and therefore may not be
15140 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15141 void * data ATTRIBUTE_UNUSED
)
15143 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15144 *walk_subtrees
= 0;
15146 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15147 && ! TREE_ASM_WRITTEN (*tp
))
15149 /* ??? The C++ FE emits debug information for using decls, so
15150 putting gcc_unreachable here falls over. See PR31899. For now
15151 be conservative. */
15152 else if (!cgraph_global_info_ready
15153 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15155 else if (TREE_CODE (*tp
) == VAR_DECL
)
15157 struct varpool_node
*node
= varpool_get_node (*tp
);
15158 if (!node
|| !node
->analyzed
)
15161 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15162 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15164 /* The call graph machinery must have finished analyzing,
15165 optimizing and gimplifying the CU by now.
15166 So if *TP has no call graph node associated
15167 to it, it means *TP will not be emitted. */
15168 if (!cgraph_get_node (*tp
))
15171 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15177 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15178 for use in a later add_const_value_attribute call. */
15181 rtl_for_decl_init (tree init
, tree type
)
15183 rtx rtl
= NULL_RTX
;
15187 /* If a variable is initialized with a string constant without embedded
15188 zeros, build CONST_STRING. */
15189 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15191 tree enttype
= TREE_TYPE (type
);
15192 tree domain
= TYPE_DOMAIN (type
);
15193 enum machine_mode mode
= TYPE_MODE (enttype
);
15195 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15197 && integer_zerop (TYPE_MIN_VALUE (domain
))
15198 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15199 TREE_STRING_LENGTH (init
) - 1) == 0
15200 && ((size_t) TREE_STRING_LENGTH (init
)
15201 == strlen (TREE_STRING_POINTER (init
)) + 1))
15203 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15204 ggc_strdup (TREE_STRING_POINTER (init
)));
15205 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15206 MEM_READONLY_P (rtl
) = 1;
15209 /* Other aggregates, and complex values, could be represented using
15211 else if (AGGREGATE_TYPE_P (type
)
15212 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15213 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15214 || TREE_CODE (type
) == COMPLEX_TYPE
)
15216 /* Vectors only work if their mode is supported by the target.
15217 FIXME: generic vectors ought to work too. */
15218 else if (TREE_CODE (type
) == VECTOR_TYPE
15219 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15221 /* If the initializer is something that we know will expand into an
15222 immediate RTL constant, expand it now. We must be careful not to
15223 reference variables which won't be output. */
15224 else if (initializer_constant_valid_p (init
, type
)
15225 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15227 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15229 if (TREE_CODE (type
) == VECTOR_TYPE
)
15230 switch (TREE_CODE (init
))
15235 if (TREE_CONSTANT (init
))
15237 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15238 bool constant_p
= true;
15240 unsigned HOST_WIDE_INT ix
;
15242 /* Even when ctor is constant, it might contain non-*_CST
15243 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15244 belong into VECTOR_CST nodes. */
15245 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15246 if (!CONSTANT_CLASS_P (value
))
15248 constant_p
= false;
15254 init
= build_vector_from_ctor (type
, elts
);
15264 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15266 /* If expand_expr returns a MEM, it wasn't immediate. */
15267 gcc_assert (!rtl
|| !MEM_P (rtl
));
15273 /* Generate RTL for the variable DECL to represent its location. */
15276 rtl_for_decl_location (tree decl
)
15280 /* Here we have to decide where we are going to say the parameter "lives"
15281 (as far as the debugger is concerned). We only have a couple of
15282 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15284 DECL_RTL normally indicates where the parameter lives during most of the
15285 activation of the function. If optimization is enabled however, this
15286 could be either NULL or else a pseudo-reg. Both of those cases indicate
15287 that the parameter doesn't really live anywhere (as far as the code
15288 generation parts of GCC are concerned) during most of the function's
15289 activation. That will happen (for example) if the parameter is never
15290 referenced within the function.
15292 We could just generate a location descriptor here for all non-NULL
15293 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15294 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15295 where DECL_RTL is NULL or is a pseudo-reg.
15297 Note however that we can only get away with using DECL_INCOMING_RTL as
15298 a backup substitute for DECL_RTL in certain limited cases. In cases
15299 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15300 we can be sure that the parameter was passed using the same type as it is
15301 declared to have within the function, and that its DECL_INCOMING_RTL
15302 points us to a place where a value of that type is passed.
15304 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15305 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15306 because in these cases DECL_INCOMING_RTL points us to a value of some
15307 type which is *different* from the type of the parameter itself. Thus,
15308 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15309 such cases, the debugger would end up (for example) trying to fetch a
15310 `float' from a place which actually contains the first part of a
15311 `double'. That would lead to really incorrect and confusing
15312 output at debug-time.
15314 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15315 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15316 are a couple of exceptions however. On little-endian machines we can
15317 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15318 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15319 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15320 when (on a little-endian machine) a non-prototyped function has a
15321 parameter declared to be of type `short' or `char'. In such cases,
15322 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15323 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15324 passed `int' value. If the debugger then uses that address to fetch
15325 a `short' or a `char' (on a little-endian machine) the result will be
15326 the correct data, so we allow for such exceptional cases below.
15328 Note that our goal here is to describe the place where the given formal
15329 parameter lives during most of the function's activation (i.e. between the
15330 end of the prologue and the start of the epilogue). We'll do that as best
15331 as we can. Note however that if the given formal parameter is modified
15332 sometime during the execution of the function, then a stack backtrace (at
15333 debug-time) will show the function as having been called with the *new*
15334 value rather than the value which was originally passed in. This happens
15335 rarely enough that it is not a major problem, but it *is* a problem, and
15336 I'd like to fix it.
15338 A future version of dwarf2out.c may generate two additional attributes for
15339 any given DW_TAG_formal_parameter DIE which will describe the "passed
15340 type" and the "passed location" for the given formal parameter in addition
15341 to the attributes we now generate to indicate the "declared type" and the
15342 "active location" for each parameter. This additional set of attributes
15343 could be used by debuggers for stack backtraces. Separately, note that
15344 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15345 This happens (for example) for inlined-instances of inline function formal
15346 parameters which are never referenced. This really shouldn't be
15347 happening. All PARM_DECL nodes should get valid non-NULL
15348 DECL_INCOMING_RTL values. FIXME. */
15350 /* Use DECL_RTL as the "location" unless we find something better. */
15351 rtl
= DECL_RTL_IF_SET (decl
);
15353 /* When generating abstract instances, ignore everything except
15354 constants, symbols living in memory, and symbols living in
15355 fixed registers. */
15356 if (! reload_completed
)
15359 && (CONSTANT_P (rtl
)
15361 && CONSTANT_P (XEXP (rtl
, 0)))
15363 && TREE_CODE (decl
) == VAR_DECL
15364 && TREE_STATIC (decl
))))
15366 rtl
= targetm
.delegitimize_address (rtl
);
15371 else if (TREE_CODE (decl
) == PARM_DECL
)
15373 if (rtl
== NULL_RTX
15374 || is_pseudo_reg (rtl
)
15376 && is_pseudo_reg (XEXP (rtl
, 0))
15377 && DECL_INCOMING_RTL (decl
)
15378 && MEM_P (DECL_INCOMING_RTL (decl
))
15379 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15381 tree declared_type
= TREE_TYPE (decl
);
15382 tree passed_type
= DECL_ARG_TYPE (decl
);
15383 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15384 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15386 /* This decl represents a formal parameter which was optimized out.
15387 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15388 all cases where (rtl == NULL_RTX) just below. */
15389 if (dmode
== pmode
)
15390 rtl
= DECL_INCOMING_RTL (decl
);
15391 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15392 && SCALAR_INT_MODE_P (dmode
)
15393 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15394 && DECL_INCOMING_RTL (decl
))
15396 rtx inc
= DECL_INCOMING_RTL (decl
);
15399 else if (MEM_P (inc
))
15401 if (BYTES_BIG_ENDIAN
)
15402 rtl
= adjust_address_nv (inc
, dmode
,
15403 GET_MODE_SIZE (pmode
)
15404 - GET_MODE_SIZE (dmode
));
15411 /* If the parm was passed in registers, but lives on the stack, then
15412 make a big endian correction if the mode of the type of the
15413 parameter is not the same as the mode of the rtl. */
15414 /* ??? This is the same series of checks that are made in dbxout.c before
15415 we reach the big endian correction code there. It isn't clear if all
15416 of these checks are necessary here, but keeping them all is the safe
15418 else if (MEM_P (rtl
)
15419 && XEXP (rtl
, 0) != const0_rtx
15420 && ! CONSTANT_P (XEXP (rtl
, 0))
15421 /* Not passed in memory. */
15422 && !MEM_P (DECL_INCOMING_RTL (decl
))
15423 /* Not passed by invisible reference. */
15424 && (!REG_P (XEXP (rtl
, 0))
15425 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15426 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15427 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15428 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15431 /* Big endian correction check. */
15432 && BYTES_BIG_ENDIAN
15433 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15434 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15437 enum machine_mode addr_mode
= get_address_mode (rtl
);
15438 int offset
= (UNITS_PER_WORD
15439 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15441 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15442 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15445 else if (TREE_CODE (decl
) == VAR_DECL
15448 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15449 && BYTES_BIG_ENDIAN
)
15451 enum machine_mode addr_mode
= get_address_mode (rtl
);
15452 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15453 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15455 /* If a variable is declared "register" yet is smaller than
15456 a register, then if we store the variable to memory, it
15457 looks like we're storing a register-sized value, when in
15458 fact we are not. We need to adjust the offset of the
15459 storage location to reflect the actual value's bytes,
15460 else gdb will not be able to display it. */
15462 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15463 plus_constant (addr_mode
, XEXP (rtl
, 0),
15467 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15468 and will have been substituted directly into all expressions that use it.
15469 C does not have such a concept, but C++ and other languages do. */
15470 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15471 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15474 rtl
= targetm
.delegitimize_address (rtl
);
15476 /* If we don't look past the constant pool, we risk emitting a
15477 reference to a constant pool entry that isn't referenced from
15478 code, and thus is not emitted. */
15480 rtl
= avoid_constant_pool_reference (rtl
);
15482 /* Try harder to get a rtl. If this symbol ends up not being emitted
15483 in the current CU, resolve_addr will remove the expression referencing
15485 if (rtl
== NULL_RTX
15486 && TREE_CODE (decl
) == VAR_DECL
15487 && !DECL_EXTERNAL (decl
)
15488 && TREE_STATIC (decl
)
15489 && DECL_NAME (decl
)
15490 && !DECL_HARD_REGISTER (decl
)
15491 && DECL_MODE (decl
) != VOIDmode
)
15493 rtl
= make_decl_rtl_for_debug (decl
);
15495 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15496 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15503 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15504 returned. If so, the decl for the COMMON block is returned, and the
15505 value is the offset into the common block for the symbol. */
15508 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15510 tree val_expr
, cvar
;
15511 enum machine_mode mode
;
15512 HOST_WIDE_INT bitsize
, bitpos
;
15514 int unsignedp
, volatilep
= 0;
15516 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15517 it does not have a value (the offset into the common area), or if it
15518 is thread local (as opposed to global) then it isn't common, and shouldn't
15519 be handled as such. */
15520 if (TREE_CODE (decl
) != VAR_DECL
15521 || !TREE_STATIC (decl
)
15522 || !DECL_HAS_VALUE_EXPR_P (decl
)
15526 val_expr
= DECL_VALUE_EXPR (decl
);
15527 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15530 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15531 &mode
, &unsignedp
, &volatilep
, true);
15533 if (cvar
== NULL_TREE
15534 || TREE_CODE (cvar
) != VAR_DECL
15535 || DECL_ARTIFICIAL (cvar
)
15536 || !TREE_PUBLIC (cvar
))
15540 if (offset
!= NULL
)
15542 if (!host_integerp (offset
, 0))
15544 *value
= tree_low_cst (offset
, 0);
15547 *value
+= bitpos
/ BITS_PER_UNIT
;
15552 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15553 data attribute for a variable or a parameter. We generate the
15554 DW_AT_const_value attribute only in those cases where the given variable
15555 or parameter does not have a true "location" either in memory or in a
15556 register. This can happen (for example) when a constant is passed as an
15557 actual argument in a call to an inline function. (It's possible that
15558 these things can crop up in other ways also.) Note that one type of
15559 constant value which can be passed into an inlined function is a constant
15560 pointer. This can happen for example if an actual argument in an inlined
15561 function call evaluates to a compile-time constant address.
15563 CACHE_P is true if it is worth caching the location list for DECL,
15564 so that future calls can reuse it rather than regenerate it from scratch.
15565 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15566 since we will need to refer to them each time the function is inlined. */
15569 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15570 enum dwarf_attribute attr
)
15573 dw_loc_list_ref list
;
15574 var_loc_list
*loc_list
;
15575 cached_dw_loc_list
*cache
;
15578 if (TREE_CODE (decl
) == ERROR_MARK
)
15581 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15582 || TREE_CODE (decl
) == RESULT_DECL
);
15584 /* Try to get some constant RTL for this decl, and use that as the value of
15587 rtl
= rtl_for_decl_location (decl
);
15588 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15589 && add_const_value_attribute (die
, rtl
))
15592 /* See if we have single element location list that is equivalent to
15593 a constant value. That way we are better to use add_const_value_attribute
15594 rather than expanding constant value equivalent. */
15595 loc_list
= lookup_decl_loc (decl
);
15598 && loc_list
->first
->next
== NULL
15599 && NOTE_P (loc_list
->first
->loc
)
15600 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15601 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15603 struct var_loc_node
*node
;
15605 node
= loc_list
->first
;
15606 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15607 if (GET_CODE (rtl
) == EXPR_LIST
)
15608 rtl
= XEXP (rtl
, 0);
15609 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15610 && add_const_value_attribute (die
, rtl
))
15613 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15614 list several times. See if we've already cached the contents. */
15616 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15620 cache
= (cached_dw_loc_list
*)
15621 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15623 list
= cache
->loc_list
;
15627 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15628 /* It is usually worth caching this result if the decl is from
15629 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15630 if (cache_p
&& list
&& list
->dw_loc_next
)
15632 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15633 DECL_UID (decl
), INSERT
);
15634 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15635 cache
->decl_id
= DECL_UID (decl
);
15636 cache
->loc_list
= list
;
15642 add_AT_location_description (die
, attr
, list
);
15645 /* None of that worked, so it must not really have a location;
15646 try adding a constant value attribute from the DECL_INITIAL. */
15647 return tree_add_const_value_attribute_for_decl (die
, decl
);
15650 /* Add VARIABLE and DIE into deferred locations list. */
15653 defer_location (tree variable
, dw_die_ref die
)
15655 deferred_locations entry
;
15656 entry
.variable
= variable
;
15658 vec_safe_push (deferred_locations_list
, entry
);
15661 /* Helper function for tree_add_const_value_attribute. Natively encode
15662 initializer INIT into an array. Return true if successful. */
15665 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15669 if (init
== NULL_TREE
)
15673 switch (TREE_CODE (init
))
15676 type
= TREE_TYPE (init
);
15677 if (TREE_CODE (type
) == ARRAY_TYPE
)
15679 tree enttype
= TREE_TYPE (type
);
15680 enum machine_mode mode
= TYPE_MODE (enttype
);
15682 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15684 if (int_size_in_bytes (type
) != size
)
15686 if (size
> TREE_STRING_LENGTH (init
))
15688 memcpy (array
, TREE_STRING_POINTER (init
),
15689 TREE_STRING_LENGTH (init
));
15690 memset (array
+ TREE_STRING_LENGTH (init
),
15691 '\0', size
- TREE_STRING_LENGTH (init
));
15694 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15699 type
= TREE_TYPE (init
);
15700 if (int_size_in_bytes (type
) != size
)
15702 if (TREE_CODE (type
) == ARRAY_TYPE
)
15704 HOST_WIDE_INT min_index
;
15705 unsigned HOST_WIDE_INT cnt
;
15706 int curpos
= 0, fieldsize
;
15707 constructor_elt
*ce
;
15709 if (TYPE_DOMAIN (type
) == NULL_TREE
15710 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15713 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15714 if (fieldsize
<= 0)
15717 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15718 memset (array
, '\0', size
);
15719 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15721 tree val
= ce
->value
;
15722 tree index
= ce
->index
;
15724 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15725 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15728 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15733 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15736 curpos
= pos
+ fieldsize
;
15737 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15739 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15740 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15741 while (count
-- > 0)
15744 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15745 curpos
+= fieldsize
;
15748 gcc_assert (curpos
<= size
);
15752 else if (TREE_CODE (type
) == RECORD_TYPE
15753 || TREE_CODE (type
) == UNION_TYPE
)
15755 tree field
= NULL_TREE
;
15756 unsigned HOST_WIDE_INT cnt
;
15757 constructor_elt
*ce
;
15759 if (int_size_in_bytes (type
) != size
)
15762 if (TREE_CODE (type
) == RECORD_TYPE
)
15763 field
= TYPE_FIELDS (type
);
15765 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15767 tree val
= ce
->value
;
15768 int pos
, fieldsize
;
15770 if (ce
->index
!= 0)
15776 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15779 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15780 && TYPE_DOMAIN (TREE_TYPE (field
))
15781 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15783 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15784 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15786 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15787 pos
= int_byte_position (field
);
15788 gcc_assert (pos
+ fieldsize
<= size
);
15790 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15796 case VIEW_CONVERT_EXPR
:
15797 case NON_LVALUE_EXPR
:
15798 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15800 return native_encode_expr (init
, array
, size
) == size
;
15804 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15805 attribute is the const value T. */
15808 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15811 tree type
= TREE_TYPE (t
);
15814 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15818 gcc_assert (!DECL_P (init
));
15820 rtl
= rtl_for_decl_init (init
, type
);
15822 return add_const_value_attribute (die
, rtl
);
15823 /* If the host and target are sane, try harder. */
15824 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15825 && initializer_constant_valid_p (init
, type
))
15827 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15828 if (size
> 0 && (int) size
== size
)
15830 unsigned char *array
= (unsigned char *)
15831 ggc_alloc_cleared_atomic (size
);
15833 if (native_encode_initializer (init
, array
, size
))
15835 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15843 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15844 attribute is the const value of T, where T is an integral constant
15845 variable with static storage duration
15846 (so it can't be a PARM_DECL or a RESULT_DECL). */
15849 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15853 || (TREE_CODE (decl
) != VAR_DECL
15854 && TREE_CODE (decl
) != CONST_DECL
)
15855 || (TREE_CODE (decl
) == VAR_DECL
15856 && !TREE_STATIC (decl
)))
15859 if (TREE_READONLY (decl
)
15860 && ! TREE_THIS_VOLATILE (decl
)
15861 && DECL_INITIAL (decl
))
15866 /* Don't add DW_AT_const_value if abstract origin already has one. */
15867 if (get_AT (var_die
, DW_AT_const_value
))
15870 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15873 /* Convert the CFI instructions for the current function into a
15874 location list. This is used for DW_AT_frame_base when we targeting
15875 a dwarf2 consumer that does not support the dwarf3
15876 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15879 static dw_loc_list_ref
15880 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15884 dw_loc_list_ref list
, *list_tail
;
15886 dw_cfa_location last_cfa
, next_cfa
;
15887 const char *start_label
, *last_label
, *section
;
15888 dw_cfa_location remember
;
15891 gcc_assert (fde
!= NULL
);
15893 section
= secname_for_decl (current_function_decl
);
15897 memset (&next_cfa
, 0, sizeof (next_cfa
));
15898 next_cfa
.reg
= INVALID_REGNUM
;
15899 remember
= next_cfa
;
15901 start_label
= fde
->dw_fde_begin
;
15903 /* ??? Bald assumption that the CIE opcode list does not contain
15904 advance opcodes. */
15905 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15906 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15908 last_cfa
= next_cfa
;
15909 last_label
= start_label
;
15911 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15913 /* If the first partition contained no CFI adjustments, the
15914 CIE opcodes apply to the whole first partition. */
15915 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15916 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15917 list_tail
=&(*list_tail
)->dw_loc_next
;
15918 start_label
= last_label
= fde
->dw_fde_second_begin
;
15921 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15923 switch (cfi
->dw_cfi_opc
)
15925 case DW_CFA_set_loc
:
15926 case DW_CFA_advance_loc1
:
15927 case DW_CFA_advance_loc2
:
15928 case DW_CFA_advance_loc4
:
15929 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15931 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15932 start_label
, last_label
, section
);
15934 list_tail
= &(*list_tail
)->dw_loc_next
;
15935 last_cfa
= next_cfa
;
15936 start_label
= last_label
;
15938 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15941 case DW_CFA_advance_loc
:
15942 /* The encoding is complex enough that we should never emit this. */
15943 gcc_unreachable ();
15946 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15949 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15951 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15953 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15954 start_label
, last_label
, section
);
15956 list_tail
= &(*list_tail
)->dw_loc_next
;
15957 last_cfa
= next_cfa
;
15958 start_label
= last_label
;
15960 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15961 start_label
, fde
->dw_fde_end
, section
);
15962 list_tail
= &(*list_tail
)->dw_loc_next
;
15963 start_label
= last_label
= fde
->dw_fde_second_begin
;
15967 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15969 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15970 start_label
, last_label
, section
);
15971 list_tail
= &(*list_tail
)->dw_loc_next
;
15972 start_label
= last_label
;
15975 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15977 fde
->dw_fde_second_begin
15978 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15981 if (list
&& list
->dw_loc_next
)
15987 /* Compute a displacement from the "steady-state frame pointer" to the
15988 frame base (often the same as the CFA), and store it in
15989 frame_pointer_fb_offset. OFFSET is added to the displacement
15990 before the latter is negated. */
15993 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15997 #ifdef FRAME_POINTER_CFA_OFFSET
15998 reg
= frame_pointer_rtx
;
15999 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
16001 reg
= arg_pointer_rtx
;
16002 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16005 elim
= (ira_use_lra_p
16006 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16007 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16008 if (GET_CODE (elim
) == PLUS
)
16010 offset
+= INTVAL (XEXP (elim
, 1));
16011 elim
= XEXP (elim
, 0);
16014 frame_pointer_fb_offset
= -offset
;
16016 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16017 in which to eliminate. This is because it's stack pointer isn't
16018 directly accessible as a register within the ISA. To work around
16019 this, assume that while we cannot provide a proper value for
16020 frame_pointer_fb_offset, we won't need one either. */
16021 frame_pointer_fb_offset_valid
16022 = ((SUPPORTS_STACK_ALIGNMENT
16023 && (elim
== hard_frame_pointer_rtx
16024 || elim
== stack_pointer_rtx
))
16025 || elim
== (frame_pointer_needed
16026 ? hard_frame_pointer_rtx
16027 : stack_pointer_rtx
));
16030 /* Generate a DW_AT_name attribute given some string value to be included as
16031 the value of the attribute. */
16034 add_name_attribute (dw_die_ref die
, const char *name_string
)
16036 if (name_string
!= NULL
&& *name_string
!= 0)
16038 if (demangle_name_func
)
16039 name_string
= (*demangle_name_func
) (name_string
);
16041 add_AT_string (die
, DW_AT_name
, name_string
);
16045 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16046 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16047 of TYPE accordingly.
16049 ??? This is a temporary measure until after we're able to generate
16050 regular DWARF for the complex Ada type system. */
16053 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16054 dw_die_ref context_die
)
16057 dw_die_ref dtype_die
;
16059 if (!lang_hooks
.types
.descriptive_type
)
16062 dtype
= lang_hooks
.types
.descriptive_type (type
);
16066 dtype_die
= lookup_type_die (dtype
);
16069 gen_type_die (dtype
, context_die
);
16070 dtype_die
= lookup_type_die (dtype
);
16071 gcc_assert (dtype_die
);
16074 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16077 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16079 static const char *
16080 comp_dir_string (void)
16084 static const char *cached_wd
= NULL
;
16086 if (cached_wd
!= NULL
)
16089 wd
= get_src_pwd ();
16093 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16097 wdlen
= strlen (wd
);
16098 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
16100 wd1
[wdlen
] = DIR_SEPARATOR
;
16101 wd1
[wdlen
+ 1] = 0;
16105 cached_wd
= remap_debug_filename (wd
);
16109 /* Generate a DW_AT_comp_dir attribute for DIE. */
16112 add_comp_dir_attribute (dw_die_ref die
)
16114 const char * wd
= comp_dir_string ();
16116 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16119 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16123 lower_bound_default (void)
16125 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16130 case DW_LANG_C_plus_plus
:
16132 case DW_LANG_ObjC_plus_plus
:
16135 case DW_LANG_Fortran77
:
16136 case DW_LANG_Fortran90
:
16137 case DW_LANG_Fortran95
:
16141 case DW_LANG_Python
:
16142 return dwarf_version
>= 4 ? 0 : -1;
16143 case DW_LANG_Ada95
:
16144 case DW_LANG_Ada83
:
16145 case DW_LANG_Cobol74
:
16146 case DW_LANG_Cobol85
:
16147 case DW_LANG_Pascal83
:
16148 case DW_LANG_Modula2
:
16150 return dwarf_version
>= 4 ? 1 : -1;
16156 /* Given a tree node describing an array bound (either lower or upper) output
16157 a representation for that bound. */
16160 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16162 switch (TREE_CODE (bound
))
16167 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16170 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16173 /* Use the default if possible. */
16174 if (bound_attr
== DW_AT_lower_bound
16175 && host_integerp (bound
, 0)
16176 && (dflt
= lower_bound_default ()) != -1
16177 && tree_low_cst (bound
, 0) == dflt
)
16180 /* Otherwise represent the bound as an unsigned value with the
16181 precision of its type. The precision and signedness of the
16182 type will be necessary to re-interpret it unambiguously. */
16183 else if (prec
< HOST_BITS_PER_WIDE_INT
)
16185 unsigned HOST_WIDE_INT mask
16186 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
16187 add_AT_unsigned (subrange_die
, bound_attr
,
16188 TREE_INT_CST_LOW (bound
) & mask
);
16190 else if (prec
== HOST_BITS_PER_WIDE_INT
16191 || TREE_INT_CST_HIGH (bound
) == 0)
16192 add_AT_unsigned (subrange_die
, bound_attr
,
16193 TREE_INT_CST_LOW (bound
));
16195 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
16196 TREE_INT_CST_LOW (bound
));
16201 case VIEW_CONVERT_EXPR
:
16202 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16212 dw_die_ref decl_die
= lookup_decl_die (bound
);
16214 /* ??? Can this happen, or should the variable have been bound
16215 first? Probably it can, since I imagine that we try to create
16216 the types of parameters in the order in which they exist in
16217 the list, and won't have created a forward reference to a
16218 later parameter. */
16219 if (decl_die
!= NULL
)
16221 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16229 /* Otherwise try to create a stack operation procedure to
16230 evaluate the value of the array bound. */
16232 dw_die_ref ctx
, decl_die
;
16233 dw_loc_list_ref list
;
16235 list
= loc_list_from_tree (bound
, 2);
16236 if (list
== NULL
|| single_element_loc_list_p (list
))
16238 /* If DW_AT_*bound is not a reference nor constant, it is
16239 a DWARF expression rather than location description.
16240 For that loc_list_from_tree (bound, 0) is needed.
16241 If that fails to give a single element list,
16242 fall back to outputting this as a reference anyway. */
16243 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16244 if (list2
&& single_element_loc_list_p (list2
))
16246 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16253 if (current_function_decl
== 0)
16254 ctx
= comp_unit_die ();
16256 ctx
= lookup_decl_die (current_function_decl
);
16258 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16259 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16260 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16261 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16262 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16268 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16269 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16270 Note that the block of subscript information for an array type also
16271 includes information about the element type of the given array type. */
16274 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16276 unsigned dimension_number
;
16278 dw_die_ref subrange_die
;
16280 for (dimension_number
= 0;
16281 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16282 type
= TREE_TYPE (type
), dimension_number
++)
16284 tree domain
= TYPE_DOMAIN (type
);
16286 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16289 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16290 and (in GNU C only) variable bounds. Handle all three forms
16292 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16295 /* We have an array type with specified bounds. */
16296 lower
= TYPE_MIN_VALUE (domain
);
16297 upper
= TYPE_MAX_VALUE (domain
);
16299 /* Define the index type. */
16300 if (TREE_TYPE (domain
))
16302 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16303 TREE_TYPE field. We can't emit debug info for this
16304 because it is an unnamed integral type. */
16305 if (TREE_CODE (domain
) == INTEGER_TYPE
16306 && TYPE_NAME (domain
) == NULL_TREE
16307 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16308 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16311 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16315 /* ??? If upper is NULL, the array has unspecified length,
16316 but it does have a lower bound. This happens with Fortran
16318 Since the debugger is definitely going to need to know N
16319 to produce useful results, go ahead and output the lower
16320 bound solo, and hope the debugger can cope. */
16322 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16324 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16327 /* Otherwise we have an array type with an unspecified length. The
16328 DWARF-2 spec does not say how to handle this; let's just leave out the
16334 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16336 dw_die_ref decl_die
;
16339 switch (TREE_CODE (tree_node
))
16344 case ENUMERAL_TYPE
:
16347 case QUAL_UNION_TYPE
:
16348 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16349 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16351 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16354 size
= int_size_in_bytes (tree_node
);
16357 /* For a data member of a struct or union, the DW_AT_byte_size is
16358 generally given as the number of bytes normally allocated for an
16359 object of the *declared* type of the member itself. This is true
16360 even for bit-fields. */
16361 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16364 gcc_unreachable ();
16367 /* Note that `size' might be -1 when we get to this point. If it is, that
16368 indicates that the byte size of the entity in question is variable. We
16369 have no good way of expressing this fact in Dwarf at the present time,
16370 so just let the -1 pass on through. */
16371 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16374 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16375 which specifies the distance in bits from the highest order bit of the
16376 "containing object" for the bit-field to the highest order bit of the
16379 For any given bit-field, the "containing object" is a hypothetical object
16380 (of some integral or enum type) within which the given bit-field lives. The
16381 type of this hypothetical "containing object" is always the same as the
16382 declared type of the individual bit-field itself. The determination of the
16383 exact location of the "containing object" for a bit-field is rather
16384 complicated. It's handled by the `field_byte_offset' function (above).
16386 Note that it is the size (in bytes) of the hypothetical "containing object"
16387 which will be given in the DW_AT_byte_size attribute for this bit-field.
16388 (See `byte_size_attribute' above). */
16391 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16393 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16394 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16395 HOST_WIDE_INT bitpos_int
;
16396 HOST_WIDE_INT highest_order_object_bit_offset
;
16397 HOST_WIDE_INT highest_order_field_bit_offset
;
16398 HOST_WIDE_INT bit_offset
;
16400 /* Must be a field and a bit field. */
16401 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16403 /* We can't yet handle bit-fields whose offsets are variable, so if we
16404 encounter such things, just return without generating any attribute
16405 whatsoever. Likewise for variable or too large size. */
16406 if (! host_integerp (bit_position (decl
), 0)
16407 || ! host_integerp (DECL_SIZE (decl
), 1))
16410 bitpos_int
= int_bit_position (decl
);
16412 /* Note that the bit offset is always the distance (in bits) from the
16413 highest-order bit of the "containing object" to the highest-order bit of
16414 the bit-field itself. Since the "high-order end" of any object or field
16415 is different on big-endian and little-endian machines, the computation
16416 below must take account of these differences. */
16417 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16418 highest_order_field_bit_offset
= bitpos_int
;
16420 if (! BYTES_BIG_ENDIAN
)
16422 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16423 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16427 = (! BYTES_BIG_ENDIAN
16428 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16429 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16431 if (bit_offset
< 0)
16432 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16434 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16437 /* For a FIELD_DECL node which represents a bit field, output an attribute
16438 which specifies the length in bits of the given field. */
16441 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16443 /* Must be a field and a bit field. */
16444 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16445 && DECL_BIT_FIELD_TYPE (decl
));
16447 if (host_integerp (DECL_SIZE (decl
), 1))
16448 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16451 /* If the compiled language is ANSI C, then add a 'prototyped'
16452 attribute, if arg types are given for the parameters of a function. */
16455 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16457 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16458 && prototype_p (func_type
))
16459 add_AT_flag (die
, DW_AT_prototyped
, 1);
16462 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16463 by looking in either the type declaration or object declaration
16466 static inline dw_die_ref
16467 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16469 dw_die_ref origin_die
= NULL
;
16471 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16473 /* We may have gotten separated from the block for the inlined
16474 function, if we're in an exception handler or some such; make
16475 sure that the abstract function has been written out.
16477 Doing this for nested functions is wrong, however; functions are
16478 distinct units, and our context might not even be inline. */
16482 fn
= TYPE_STUB_DECL (fn
);
16484 fn
= decl_function_context (fn
);
16486 dwarf2out_abstract_function (fn
);
16489 if (DECL_P (origin
))
16490 origin_die
= lookup_decl_die (origin
);
16491 else if (TYPE_P (origin
))
16492 origin_die
= lookup_type_die (origin
);
16494 /* XXX: Functions that are never lowered don't always have correct block
16495 trees (in the case of java, they simply have no block tree, in some other
16496 languages). For these functions, there is nothing we can really do to
16497 output correct debug info for inlined functions in all cases. Rather
16498 than die, we'll just produce deficient debug info now, in that we will
16499 have variables without a proper abstract origin. In the future, when all
16500 functions are lowered, we should re-add a gcc_assert (origin_die)
16504 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16508 /* We do not currently support the pure_virtual attribute. */
16511 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16513 if (DECL_VINDEX (func_decl
))
16515 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16517 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16518 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16519 new_loc_descr (DW_OP_constu
,
16520 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16523 /* GNU extension: Record what type this method came from originally. */
16524 if (debug_info_level
> DINFO_LEVEL_TERSE
16525 && DECL_CONTEXT (func_decl
))
16526 add_AT_die_ref (die
, DW_AT_containing_type
,
16527 lookup_type_die (DECL_CONTEXT (func_decl
)));
16531 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16532 given decl. This used to be a vendor extension until after DWARF 4
16533 standardized it. */
16536 add_linkage_attr (dw_die_ref die
, tree decl
)
16538 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16540 /* Mimic what assemble_name_raw does with a leading '*'. */
16541 if (name
[0] == '*')
16544 if (dwarf_version
>= 4)
16545 add_AT_string (die
, DW_AT_linkage_name
, name
);
16547 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16550 /* Add source coordinate attributes for the given decl. */
16553 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16555 expanded_location s
;
16557 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16559 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16560 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16561 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16564 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16567 add_linkage_name (dw_die_ref die
, tree decl
)
16569 if (debug_info_level
> DINFO_LEVEL_NONE
16570 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16571 && TREE_PUBLIC (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 FUNC_LABEL_ID (cfun
));
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 (host_integerp (val
, 0))
17068 return int_loc_descriptor (tree_low_cst (val
, 0));
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 (host_integerp (TREE_OPERAND (val
, 1), 1)
17085 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
17088 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17091 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
17097 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17100 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
17103 add_loc_descr (&loc
, loc2
);
17104 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17126 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17127 tree val
, tree base_decl
)
17129 dw_loc_descr_ref loc
;
17131 if (host_integerp (val
, 0))
17133 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
17137 loc
= descr_info_loc (val
, base_decl
);
17141 add_AT_loc (die
, attr
, loc
);
17144 /* This routine generates DIE for array with hidden descriptor, details
17145 are filled into *info by a langhook. */
17148 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17149 dw_die_ref context_die
)
17151 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17152 dw_die_ref array_die
;
17155 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17156 add_name_attribute (array_die
, type_tag (type
));
17157 equate_type_number_to_die (type
, array_die
);
17159 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17161 && info
->ndimensions
>= 2)
17162 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17164 if (info
->data_location
)
17165 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17167 if (info
->associated
)
17168 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17170 if (info
->allocated
)
17171 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17174 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17176 dw_die_ref subrange_die
17177 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17179 if (info
->dimen
[dim
].lower_bound
)
17181 /* If it is the default value, omit it. */
17184 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
17185 && (dflt
= lower_bound_default ()) != -1
17186 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
17189 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17190 info
->dimen
[dim
].lower_bound
,
17193 if (info
->dimen
[dim
].upper_bound
)
17194 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17195 info
->dimen
[dim
].upper_bound
,
17197 if (info
->dimen
[dim
].stride
)
17198 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17199 info
->dimen
[dim
].stride
,
17203 gen_type_die (info
->element_type
, context_die
);
17204 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17206 if (get_AT (array_die
, DW_AT_name
))
17207 add_pubtype (type
, array_die
);
17212 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17214 tree origin
= decl_ultimate_origin (decl
);
17215 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17217 if (origin
!= NULL
)
17218 add_abstract_origin_attribute (decl_die
, origin
);
17221 add_name_and_src_coords_attributes (decl_die
, decl
);
17222 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17223 0, 0, context_die
);
17226 if (DECL_ABSTRACT (decl
))
17227 equate_decl_number_to_die (decl
, decl_die
);
17229 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17233 /* Walk through the list of incomplete types again, trying once more to
17234 emit full debugging info for them. */
17237 retry_incomplete_types (void)
17241 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17242 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17243 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17246 /* Determine what tag to use for a record type. */
17248 static enum dwarf_tag
17249 record_type_tag (tree type
)
17251 if (! lang_hooks
.types
.classify_record
)
17252 return DW_TAG_structure_type
;
17254 switch (lang_hooks
.types
.classify_record (type
))
17256 case RECORD_IS_STRUCT
:
17257 return DW_TAG_structure_type
;
17259 case RECORD_IS_CLASS
:
17260 return DW_TAG_class_type
;
17262 case RECORD_IS_INTERFACE
:
17263 if (dwarf_version
>= 3 || !dwarf_strict
)
17264 return DW_TAG_interface_type
;
17265 return DW_TAG_structure_type
;
17268 gcc_unreachable ();
17272 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17273 include all of the information about the enumeration values also. Each
17274 enumerated type name/value is listed as a child of the enumerated type
17278 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17280 dw_die_ref type_die
= lookup_type_die (type
);
17282 if (type_die
== NULL
)
17284 type_die
= new_die (DW_TAG_enumeration_type
,
17285 scope_die_for (type
, context_die
), type
);
17286 equate_type_number_to_die (type
, type_die
);
17287 add_name_attribute (type_die
, type_tag (type
));
17288 if (dwarf_version
>= 4 || !dwarf_strict
)
17290 if (ENUM_IS_SCOPED (type
))
17291 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17292 if (ENUM_IS_OPAQUE (type
))
17293 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17296 else if (! TYPE_SIZE (type
))
17299 remove_AT (type_die
, DW_AT_declaration
);
17301 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17302 given enum type is incomplete, do not generate the DW_AT_byte_size
17303 attribute or the DW_AT_element_list attribute. */
17304 if (TYPE_SIZE (type
))
17308 TREE_ASM_WRITTEN (type
) = 1;
17309 add_byte_size_attribute (type_die
, type
);
17310 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17312 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17313 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17316 /* If the first reference to this type was as the return type of an
17317 inline function, then it may not have a parent. Fix this now. */
17318 if (type_die
->die_parent
== NULL
)
17319 add_child_die (scope_die_for (type
, context_die
), type_die
);
17321 for (link
= TYPE_VALUES (type
);
17322 link
!= NULL
; link
= TREE_CHAIN (link
))
17324 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17325 tree value
= TREE_VALUE (link
);
17327 add_name_attribute (enum_die
,
17328 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17330 if (TREE_CODE (value
) == CONST_DECL
)
17331 value
= DECL_INITIAL (value
);
17333 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (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. */
17340 add_AT_int (enum_die
, DW_AT_const_value
,
17341 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
17344 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17345 if (TYPE_ARTIFICIAL (type
))
17346 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17349 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17351 add_pubtype (type
, type_die
);
17356 /* Generate a DIE to represent either a real live formal parameter decl or to
17357 represent just the type of some formal parameter position in some function
17360 Note that this routine is a bit unusual because its argument may be a
17361 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17362 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17363 node. If it's the former then this function is being called to output a
17364 DIE to represent a formal parameter object (or some inlining thereof). If
17365 it's the latter, then this function is only being called to output a
17366 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17367 argument type of some subprogram type.
17368 If EMIT_NAME_P is true, name and source coordinate attributes
17372 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17373 dw_die_ref context_die
)
17375 tree node_or_origin
= node
? node
: origin
;
17376 tree ultimate_origin
;
17377 dw_die_ref parm_die
17378 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17380 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17382 case tcc_declaration
:
17383 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17384 if (node
|| ultimate_origin
)
17385 origin
= ultimate_origin
;
17386 if (origin
!= NULL
)
17387 add_abstract_origin_attribute (parm_die
, origin
);
17388 else if (emit_name_p
)
17389 add_name_and_src_coords_attributes (parm_die
, node
);
17391 || (! DECL_ABSTRACT (node_or_origin
)
17392 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17393 decl_function_context
17394 (node_or_origin
))))
17396 tree type
= TREE_TYPE (node_or_origin
);
17397 if (decl_by_reference_p (node_or_origin
))
17398 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17401 add_type_attribute (parm_die
, type
,
17402 TREE_READONLY (node_or_origin
),
17403 TREE_THIS_VOLATILE (node_or_origin
),
17406 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17407 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17409 if (node
&& node
!= origin
)
17410 equate_decl_number_to_die (node
, parm_die
);
17411 if (! DECL_ABSTRACT (node_or_origin
))
17412 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17413 node
== NULL
, DW_AT_location
);
17418 /* We were called with some kind of a ..._TYPE node. */
17419 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17423 gcc_unreachable ();
17429 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17430 children DW_TAG_formal_parameter DIEs representing the arguments of the
17433 PARM_PACK must be a function parameter pack.
17434 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17435 must point to the subsequent arguments of the function PACK_ARG belongs to.
17436 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17437 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17438 following the last one for which a DIE was generated. */
17441 gen_formal_parameter_pack_die (tree parm_pack
,
17443 dw_die_ref subr_die
,
17447 dw_die_ref parm_pack_die
;
17449 gcc_assert (parm_pack
17450 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17453 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17454 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17456 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17458 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17461 gen_formal_parameter_die (arg
, NULL
,
17462 false /* Don't emit name attribute. */,
17467 return parm_pack_die
;
17470 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17471 at the end of an (ANSI prototyped) formal parameters list. */
17474 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17476 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17479 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17480 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17481 parameters as specified in some function type specification (except for
17482 those which appear as part of a function *definition*). */
17485 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17488 tree formal_type
= NULL
;
17489 tree first_parm_type
;
17492 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17494 arg
= DECL_ARGUMENTS (function_or_method_type
);
17495 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17500 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17502 /* Make our first pass over the list of formal parameter types and output a
17503 DW_TAG_formal_parameter DIE for each one. */
17504 for (link
= first_parm_type
; link
; )
17506 dw_die_ref parm_die
;
17508 formal_type
= TREE_VALUE (link
);
17509 if (formal_type
== void_type_node
)
17512 /* Output a (nameless) DIE to represent the formal parameter itself. */
17513 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17514 true /* Emit name attribute. */,
17516 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17517 && link
== first_parm_type
)
17519 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17520 if (dwarf_version
>= 3 || !dwarf_strict
)
17521 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17523 else if (arg
&& DECL_ARTIFICIAL (arg
))
17524 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17526 link
= TREE_CHAIN (link
);
17528 arg
= DECL_CHAIN (arg
);
17531 /* If this function type has an ellipsis, add a
17532 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17533 if (formal_type
!= void_type_node
)
17534 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17536 /* Make our second (and final) pass over the list of formal parameter types
17537 and output DIEs to represent those types (as necessary). */
17538 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17539 link
&& TREE_VALUE (link
);
17540 link
= TREE_CHAIN (link
))
17541 gen_type_die (TREE_VALUE (link
), context_die
);
17544 /* We want to generate the DIE for TYPE so that we can generate the
17545 die for MEMBER, which has been defined; we will need to refer back
17546 to the member declaration nested within TYPE. If we're trying to
17547 generate minimal debug info for TYPE, processing TYPE won't do the
17548 trick; we need to attach the member declaration by hand. */
17551 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17553 gen_type_die (type
, context_die
);
17555 /* If we're trying to avoid duplicate debug info, we may not have
17556 emitted the member decl for this function. Emit it now. */
17557 if (TYPE_STUB_DECL (type
)
17558 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17559 && ! lookup_decl_die (member
))
17561 dw_die_ref type_die
;
17562 gcc_assert (!decl_ultimate_origin (member
));
17564 push_decl_scope (type
);
17565 type_die
= lookup_type_die_strip_naming_typedef (type
);
17566 if (TREE_CODE (member
) == FUNCTION_DECL
)
17567 gen_subprogram_die (member
, type_die
);
17568 else if (TREE_CODE (member
) == FIELD_DECL
)
17570 /* Ignore the nameless fields that are used to skip bits but handle
17571 C++ anonymous unions and structs. */
17572 if (DECL_NAME (member
) != NULL_TREE
17573 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17574 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17576 gen_type_die (member_declared_type (member
), type_die
);
17577 gen_field_die (member
, type_die
);
17581 gen_variable_die (member
, NULL_TREE
, type_die
);
17587 /* Forward declare these functions, because they are mutually recursive
17588 with their set_block_* pairing functions. */
17589 static void set_decl_origin_self (tree
);
17590 static void set_decl_abstract_flags (tree
, int);
17592 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17593 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17594 that it points to the node itself, thus indicating that the node is its
17595 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17596 the given node is NULL, recursively descend the decl/block tree which
17597 it is the root of, and for each other ..._DECL or BLOCK node contained
17598 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17599 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17600 values to point to themselves. */
17603 set_block_origin_self (tree stmt
)
17605 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17607 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17612 for (local_decl
= BLOCK_VARS (stmt
);
17613 local_decl
!= NULL_TREE
;
17614 local_decl
= DECL_CHAIN (local_decl
))
17615 if (! DECL_EXTERNAL (local_decl
))
17616 set_decl_origin_self (local_decl
); /* Potential recursion. */
17622 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17623 subblock
!= NULL_TREE
;
17624 subblock
= BLOCK_CHAIN (subblock
))
17625 set_block_origin_self (subblock
); /* Recurse. */
17630 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17631 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17632 node to so that it points to the node itself, thus indicating that the
17633 node represents its own (abstract) origin. Additionally, if the
17634 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17635 the decl/block tree of which the given node is the root of, and for
17636 each other ..._DECL or BLOCK node contained therein whose
17637 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17638 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17639 point to themselves. */
17642 set_decl_origin_self (tree decl
)
17644 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17646 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17647 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17651 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17652 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17653 if (DECL_INITIAL (decl
) != NULL_TREE
17654 && DECL_INITIAL (decl
) != error_mark_node
)
17655 set_block_origin_self (DECL_INITIAL (decl
));
17660 /* Given a pointer to some BLOCK node, and a boolean value to set the
17661 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17662 the given block, and for all local decls and all local sub-blocks
17663 (recursively) which are contained therein. */
17666 set_block_abstract_flags (tree stmt
, int setting
)
17672 BLOCK_ABSTRACT (stmt
) = setting
;
17674 for (local_decl
= BLOCK_VARS (stmt
);
17675 local_decl
!= NULL_TREE
;
17676 local_decl
= DECL_CHAIN (local_decl
))
17677 if (! DECL_EXTERNAL (local_decl
))
17678 set_decl_abstract_flags (local_decl
, setting
);
17680 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17682 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17683 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17684 || TREE_CODE (local_decl
) == PARM_DECL
)
17685 set_decl_abstract_flags (local_decl
, setting
);
17688 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17689 subblock
!= NULL_TREE
;
17690 subblock
= BLOCK_CHAIN (subblock
))
17691 set_block_abstract_flags (subblock
, setting
);
17694 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17695 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17696 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17697 set the abstract flags for all of the parameters, local vars, local
17698 blocks and sub-blocks (recursively) to the same setting. */
17701 set_decl_abstract_flags (tree decl
, int setting
)
17703 DECL_ABSTRACT (decl
) = setting
;
17704 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17708 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17709 DECL_ABSTRACT (arg
) = setting
;
17710 if (DECL_INITIAL (decl
) != NULL_TREE
17711 && DECL_INITIAL (decl
) != error_mark_node
)
17712 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17716 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17717 may later generate inlined and/or out-of-line instances of. */
17720 dwarf2out_abstract_function (tree decl
)
17722 dw_die_ref old_die
;
17726 htab_t old_decl_loc_table
;
17727 htab_t old_cached_dw_loc_list_table
;
17728 int old_call_site_count
, old_tail_call_site_count
;
17729 struct call_arg_loc_node
*old_call_arg_locations
;
17731 /* Make sure we have the actual abstract inline, not a clone. */
17732 decl
= DECL_ORIGIN (decl
);
17734 old_die
= lookup_decl_die (decl
);
17735 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17736 /* We've already generated the abstract instance. */
17739 /* We can be called while recursively when seeing block defining inlined subroutine
17740 DIE. Be sure to not clobber the outer location table nor use it or we would
17741 get locations in abstract instantces. */
17742 old_decl_loc_table
= decl_loc_table
;
17743 decl_loc_table
= NULL
;
17744 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17745 cached_dw_loc_list_table
= NULL
;
17746 old_call_arg_locations
= call_arg_locations
;
17747 call_arg_locations
= NULL
;
17748 old_call_site_count
= call_site_count
;
17749 call_site_count
= -1;
17750 old_tail_call_site_count
= tail_call_site_count
;
17751 tail_call_site_count
= -1;
17753 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17754 we don't get confused by DECL_ABSTRACT. */
17755 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17757 context
= decl_class_context (decl
);
17759 gen_type_die_for_member
17760 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17763 /* Pretend we've just finished compiling this function. */
17764 save_fn
= current_function_decl
;
17765 current_function_decl
= decl
;
17767 was_abstract
= DECL_ABSTRACT (decl
);
17768 set_decl_abstract_flags (decl
, 1);
17769 dwarf2out_decl (decl
);
17770 if (! was_abstract
)
17771 set_decl_abstract_flags (decl
, 0);
17773 current_function_decl
= save_fn
;
17774 decl_loc_table
= old_decl_loc_table
;
17775 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17776 call_arg_locations
= old_call_arg_locations
;
17777 call_site_count
= old_call_site_count
;
17778 tail_call_site_count
= old_tail_call_site_count
;
17781 /* Helper function of premark_used_types() which gets called through
17784 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17785 marked as unused by prune_unused_types. */
17788 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17793 type
= (tree
) *slot
;
17794 die
= lookup_type_die (type
);
17796 die
->die_perennial_p
= 1;
17800 /* Helper function of premark_types_used_by_global_vars which gets called
17801 through htab_traverse.
17803 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17804 marked as unused by prune_unused_types. The DIE of the type is marked
17805 only if the global variable using the type will actually be emitted. */
17808 premark_types_used_by_global_vars_helper (void **slot
,
17809 void *data ATTRIBUTE_UNUSED
)
17811 struct types_used_by_vars_entry
*entry
;
17814 entry
= (struct types_used_by_vars_entry
*) *slot
;
17815 gcc_assert (entry
->type
!= NULL
17816 && entry
->var_decl
!= NULL
);
17817 die
= lookup_type_die (entry
->type
);
17820 /* Ask cgraph if the global variable really is to be emitted.
17821 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17822 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17823 if (node
&& node
->analyzed
)
17825 die
->die_perennial_p
= 1;
17826 /* Keep the parent DIEs as well. */
17827 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17828 die
->die_perennial_p
= 1;
17834 /* Mark all members of used_types_hash as perennial. */
17837 premark_used_types (struct function
*fun
)
17839 if (fun
&& fun
->used_types_hash
)
17840 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17843 /* Mark all members of types_used_by_vars_entry as perennial. */
17846 premark_types_used_by_global_vars (void)
17848 if (types_used_by_vars_hash
)
17849 htab_traverse (types_used_by_vars_hash
,
17850 premark_types_used_by_global_vars_helper
, NULL
);
17853 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17854 for CA_LOC call arg loc node. */
17857 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17858 struct call_arg_loc_node
*ca_loc
)
17860 dw_die_ref stmt_die
= NULL
, die
;
17861 tree block
= ca_loc
->block
;
17864 && block
!= DECL_INITIAL (decl
)
17865 && TREE_CODE (block
) == BLOCK
)
17867 if (block_map
.length () > BLOCK_NUMBER (block
))
17868 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17871 block
= BLOCK_SUPERCONTEXT (block
);
17873 if (stmt_die
== NULL
)
17874 stmt_die
= subr_die
;
17875 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17876 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17877 if (ca_loc
->tail_call_p
)
17878 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17879 if (ca_loc
->symbol_ref
)
17881 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17883 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17885 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17890 /* Generate a DIE to represent a declared function (either file-scope or
17894 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17896 tree origin
= decl_ultimate_origin (decl
);
17897 dw_die_ref subr_die
;
17899 dw_die_ref old_die
= lookup_decl_die (decl
);
17900 int declaration
= (current_function_decl
!= decl
17901 || class_or_namespace_scope_p (context_die
));
17903 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17905 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17906 started to generate the abstract instance of an inline, decided to output
17907 its containing class, and proceeded to emit the declaration of the inline
17908 from the member list for the class. If so, DECLARATION takes priority;
17909 we'll get back to the abstract instance when done with the class. */
17911 /* The class-scope declaration DIE must be the primary DIE. */
17912 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17915 gcc_assert (!old_die
);
17918 /* Now that the C++ front end lazily declares artificial member fns, we
17919 might need to retrofit the declaration into its class. */
17920 if (!declaration
&& !origin
&& !old_die
17921 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17922 && !class_or_namespace_scope_p (context_die
)
17923 && debug_info_level
> DINFO_LEVEL_TERSE
)
17924 old_die
= force_decl_die (decl
);
17926 if (origin
!= NULL
)
17928 gcc_assert (!declaration
|| local_scope_p (context_die
));
17930 /* Fixup die_parent for the abstract instance of a nested
17931 inline function. */
17932 if (old_die
&& old_die
->die_parent
== NULL
)
17933 add_child_die (context_die
, old_die
);
17935 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17936 add_abstract_origin_attribute (subr_die
, origin
);
17937 /* This is where the actual code for a cloned function is.
17938 Let's emit linkage name attribute for it. This helps
17939 debuggers to e.g, set breakpoints into
17940 constructors/destructors when the user asks "break
17942 add_linkage_name (subr_die
, decl
);
17946 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17947 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17949 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17950 /* We can have a normal definition following an inline one in the
17951 case of redefinition of GNU C extern inlines.
17952 It seems reasonable to use AT_specification in this case. */
17953 && !get_AT (old_die
, DW_AT_inline
))
17955 /* Detect and ignore this case, where we are trying to output
17956 something we have already output. */
17960 /* If the definition comes from the same place as the declaration,
17961 maybe use the old DIE. We always want the DIE for this function
17962 that has the *_pc attributes to be under comp_unit_die so the
17963 debugger can find it. We also need to do this for abstract
17964 instances of inlines, since the spec requires the out-of-line copy
17965 to have the same parent. For local class methods, this doesn't
17966 apply; we just use the old DIE. */
17967 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17968 && (DECL_ARTIFICIAL (decl
)
17969 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17970 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17971 == (unsigned) s
.line
))))
17973 subr_die
= old_die
;
17975 /* Clear out the declaration attribute and the formal parameters.
17976 Do not remove all children, because it is possible that this
17977 declaration die was forced using force_decl_die(). In such
17978 cases die that forced declaration die (e.g. TAG_imported_module)
17979 is one of the children that we do not want to remove. */
17980 remove_AT (subr_die
, DW_AT_declaration
);
17981 remove_AT (subr_die
, DW_AT_object_pointer
);
17982 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17986 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17987 add_AT_specification (subr_die
, old_die
);
17988 add_pubname (decl
, subr_die
);
17989 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17990 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17991 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17992 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17997 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17999 if (TREE_PUBLIC (decl
))
18000 add_AT_flag (subr_die
, DW_AT_external
, 1);
18002 add_name_and_src_coords_attributes (subr_die
, decl
);
18003 add_pubname (decl
, subr_die
);
18004 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18006 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18007 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18008 0, 0, context_die
);
18011 add_pure_or_virtual_attribute (subr_die
, decl
);
18012 if (DECL_ARTIFICIAL (decl
))
18013 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18015 add_accessibility_attribute (subr_die
, decl
);
18020 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18022 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18024 /* If this is an explicit function declaration then generate
18025 a DW_AT_explicit attribute. */
18026 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18027 && (dwarf_version
>= 3 || !dwarf_strict
))
18028 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18030 /* The first time we see a member function, it is in the context of
18031 the class to which it belongs. We make sure of this by emitting
18032 the class first. The next time is the definition, which is
18033 handled above. The two may come from the same source text.
18035 Note that force_decl_die() forces function declaration die. It is
18036 later reused to represent definition. */
18037 equate_decl_number_to_die (decl
, subr_die
);
18040 else if (DECL_ABSTRACT (decl
))
18042 if (DECL_DECLARED_INLINE_P (decl
))
18044 if (cgraph_function_possibly_inlined_p (decl
))
18045 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18047 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18051 if (cgraph_function_possibly_inlined_p (decl
))
18052 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18054 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18057 if (DECL_DECLARED_INLINE_P (decl
)
18058 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18059 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18061 equate_decl_number_to_die (decl
, subr_die
);
18063 else if (!DECL_EXTERNAL (decl
))
18065 HOST_WIDE_INT cfa_fb_offset
;
18066 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18068 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18069 equate_decl_number_to_die (decl
, subr_die
);
18071 gcc_checking_assert (fun
);
18072 if (!flag_reorder_blocks_and_partition
)
18074 dw_fde_ref fde
= fun
->fde
;
18075 if (fde
->dw_fde_begin
)
18077 /* We have already generated the labels. */
18078 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18079 fde
->dw_fde_end
, false);
18083 /* Create start/end labels and add the range. */
18084 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18085 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18086 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18087 FUNC_LABEL_ID (cfun
));
18088 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18089 FUNC_LABEL_ID (cfun
));
18090 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18094 #if VMS_DEBUGGING_INFO
18095 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18096 Section 2.3 Prologue and Epilogue Attributes:
18097 When a breakpoint is set on entry to a function, it is generally
18098 desirable for execution to be suspended, not on the very first
18099 instruction of the function, but rather at a point after the
18100 function's frame has been set up, after any language defined local
18101 declaration processing has been completed, and before execution of
18102 the first statement of the function begins. Debuggers generally
18103 cannot properly determine where this point is. Similarly for a
18104 breakpoint set on exit from a function. The prologue and epilogue
18105 attributes allow a compiler to communicate the location(s) to use. */
18108 if (fde
->dw_fde_vms_end_prologue
)
18109 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18110 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18112 if (fde
->dw_fde_vms_begin_epilogue
)
18113 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18114 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18121 /* Generate pubnames entries for the split function code ranges. */
18122 dw_fde_ref fde
= fun
->fde
;
18124 if (fde
->dw_fde_second_begin
)
18126 if (dwarf_version
>= 3 || !dwarf_strict
)
18128 /* We should use ranges for non-contiguous code section
18129 addresses. Use the actual code range for the initial
18130 section, since the HOT/COLD labels might precede an
18131 alignment offset. */
18132 bool range_list_added
= false;
18133 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18134 fde
->dw_fde_end
, &range_list_added
,
18136 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18137 fde
->dw_fde_second_end
,
18138 &range_list_added
, false);
18139 if (range_list_added
)
18144 /* There is no real support in DW2 for this .. so we make
18145 a work-around. First, emit the pub name for the segment
18146 containing the function label. Then make and emit a
18147 simplified subprogram DIE for the second segment with the
18148 name pre-fixed by __hot/cold_sect_of_. We use the same
18149 linkage name for the second die so that gdb will find both
18150 sections when given "b foo". */
18151 const char *name
= NULL
;
18152 tree decl_name
= DECL_NAME (decl
);
18153 dw_die_ref seg_die
;
18155 /* Do the 'primary' section. */
18156 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18157 fde
->dw_fde_end
, false);
18159 /* Build a minimal DIE for the secondary section. */
18160 seg_die
= new_die (DW_TAG_subprogram
,
18161 subr_die
->die_parent
, decl
);
18163 if (TREE_PUBLIC (decl
))
18164 add_AT_flag (seg_die
, DW_AT_external
, 1);
18166 if (decl_name
!= NULL
18167 && IDENTIFIER_POINTER (decl_name
) != NULL
)
18169 name
= dwarf2_name (decl
, 1);
18170 if (! DECL_ARTIFICIAL (decl
))
18171 add_src_coords_attributes (seg_die
, decl
);
18173 add_linkage_name (seg_die
, decl
);
18175 gcc_assert (name
!= NULL
);
18176 add_pure_or_virtual_attribute (seg_die
, decl
);
18177 if (DECL_ARTIFICIAL (decl
))
18178 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
18180 name
= concat ("__second_sect_of_", name
, NULL
);
18181 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
18182 fde
->dw_fde_second_end
, false);
18183 add_name_attribute (seg_die
, name
);
18184 if (want_pubnames ())
18185 add_pubname_string (name
, seg_die
);
18189 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
18193 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18195 /* We define the "frame base" as the function's CFA. This is more
18196 convenient for several reasons: (1) It's stable across the prologue
18197 and epilogue, which makes it better than just a frame pointer,
18198 (2) With dwarf3, there exists a one-byte encoding that allows us
18199 to reference the .debug_frame data by proxy, but failing that,
18200 (3) We can at least reuse the code inspection and interpretation
18201 code that determines the CFA position at various points in the
18203 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18205 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18206 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18210 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18211 if (list
->dw_loc_next
)
18212 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18214 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18217 /* Compute a displacement from the "steady-state frame pointer" to
18218 the CFA. The former is what all stack slots and argument slots
18219 will reference in the rtl; the latter is what we've told the
18220 debugger about. We'll need to adjust all frame_base references
18221 by this displacement. */
18222 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18224 if (fun
->static_chain_decl
)
18225 add_AT_location_description (subr_die
, DW_AT_static_link
,
18226 loc_list_from_tree (fun
->static_chain_decl
, 2));
18229 /* Generate child dies for template paramaters. */
18230 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18231 gen_generic_params_dies (decl
);
18233 /* Now output descriptions of the arguments for this function. This gets
18234 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18235 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18236 `...' at the end of the formal parameter list. In order to find out if
18237 there was a trailing ellipsis or not, we must instead look at the type
18238 associated with the FUNCTION_DECL. This will be a node of type
18239 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18240 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18241 an ellipsis at the end. */
18243 /* In the case where we are describing a mere function declaration, all we
18244 need to do here (and all we *can* do here) is to describe the *types* of
18245 its formal parameters. */
18246 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18248 else if (declaration
)
18249 gen_formal_types_die (decl
, subr_die
);
18252 /* Generate DIEs to represent all known formal parameters. */
18253 tree parm
= DECL_ARGUMENTS (decl
);
18254 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18255 tree generic_decl_parm
= generic_decl
18256 ? DECL_ARGUMENTS (generic_decl
)
18259 /* Now we want to walk the list of parameters of the function and
18260 emit their relevant DIEs.
18262 We consider the case of DECL being an instance of a generic function
18263 as well as it being a normal function.
18265 If DECL is an instance of a generic function we walk the
18266 parameters of the generic function declaration _and_ the parameters of
18267 DECL itself. This is useful because we want to emit specific DIEs for
18268 function parameter packs and those are declared as part of the
18269 generic function declaration. In that particular case,
18270 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18271 That DIE has children DIEs representing the set of arguments
18272 of the pack. Note that the set of pack arguments can be empty.
18273 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18276 Otherwise, we just consider the parameters of DECL. */
18277 while (generic_decl_parm
|| parm
)
18279 if (generic_decl_parm
18280 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18281 gen_formal_parameter_pack_die (generic_decl_parm
,
18286 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18288 if (parm
== DECL_ARGUMENTS (decl
)
18289 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18291 && (dwarf_version
>= 3 || !dwarf_strict
))
18292 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18294 parm
= DECL_CHAIN (parm
);
18297 if (generic_decl_parm
)
18298 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18301 /* Decide whether we need an unspecified_parameters DIE at the end.
18302 There are 2 more cases to do this for: 1) the ansi ... declaration -
18303 this is detectable when the end of the arg list is not a
18304 void_type_node 2) an unprototyped function declaration (not a
18305 definition). This just means that we have no info about the
18306 parameters at all. */
18307 if (prototype_p (TREE_TYPE (decl
)))
18309 /* This is the prototyped case, check for.... */
18310 if (stdarg_p (TREE_TYPE (decl
)))
18311 gen_unspecified_parameters_die (decl
, subr_die
);
18313 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18314 gen_unspecified_parameters_die (decl
, subr_die
);
18317 /* Output Dwarf info for all of the stuff within the body of the function
18318 (if it has one - it may be just a declaration). */
18319 outer_scope
= DECL_INITIAL (decl
);
18321 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18322 a function. This BLOCK actually represents the outermost binding contour
18323 for the function, i.e. the contour in which the function's formal
18324 parameters and labels get declared. Curiously, it appears that the front
18325 end doesn't actually put the PARM_DECL nodes for the current function onto
18326 the BLOCK_VARS list for this outer scope, but are strung off of the
18327 DECL_ARGUMENTS list for the function instead.
18329 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18330 the LABEL_DECL nodes for the function however, and we output DWARF info
18331 for those in decls_for_scope. Just within the `outer_scope' there will be
18332 a BLOCK node representing the function's outermost pair of curly braces,
18333 and any blocks used for the base and member initializers of a C++
18334 constructor function. */
18335 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18337 int call_site_note_count
= 0;
18338 int tail_call_site_note_count
= 0;
18340 /* Emit a DW_TAG_variable DIE for a named return value. */
18341 if (DECL_NAME (DECL_RESULT (decl
)))
18342 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18344 current_function_has_inlines
= 0;
18345 decls_for_scope (outer_scope
, subr_die
, 0);
18347 if (call_arg_locations
&& !dwarf_strict
)
18349 struct call_arg_loc_node
*ca_loc
;
18350 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18352 dw_die_ref die
= NULL
;
18353 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18356 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18357 arg
; arg
= next_arg
)
18359 dw_loc_descr_ref reg
, val
;
18360 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18361 dw_die_ref cdie
, tdie
= NULL
;
18363 next_arg
= XEXP (arg
, 1);
18364 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18366 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18367 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18368 && REGNO (XEXP (XEXP (arg
, 0), 0))
18369 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18370 next_arg
= XEXP (next_arg
, 1);
18371 if (mode
== VOIDmode
)
18373 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18374 if (mode
== VOIDmode
)
18375 mode
= GET_MODE (XEXP (arg
, 0));
18377 if (mode
== VOIDmode
|| mode
== BLKmode
)
18379 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18381 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18382 tloc
= XEXP (XEXP (arg
, 0), 1);
18385 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18386 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18388 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18389 tlocc
= XEXP (XEXP (arg
, 0), 1);
18393 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18394 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18395 VAR_INIT_STATUS_INITIALIZED
);
18396 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18398 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18399 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18400 get_address_mode (mem
),
18402 VAR_INIT_STATUS_INITIALIZED
);
18404 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18405 == DEBUG_PARAMETER_REF
)
18408 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18409 tdie
= lookup_decl_die (tdecl
);
18416 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18417 != DEBUG_PARAMETER_REF
)
18419 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18421 VAR_INIT_STATUS_INITIALIZED
);
18425 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18426 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18429 add_AT_loc (cdie
, DW_AT_location
, reg
);
18430 else if (tdie
!= NULL
)
18431 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18432 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18433 if (next_arg
!= XEXP (arg
, 1))
18435 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18436 if (mode
== VOIDmode
)
18437 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18438 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18441 VAR_INIT_STATUS_INITIALIZED
);
18443 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18447 && (ca_loc
->symbol_ref
|| tloc
))
18448 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18449 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18451 dw_loc_descr_ref tval
= NULL
;
18453 if (tloc
!= NULL_RTX
)
18454 tval
= mem_loc_descriptor (tloc
,
18455 GET_MODE (tloc
) == VOIDmode
18456 ? Pmode
: GET_MODE (tloc
),
18458 VAR_INIT_STATUS_INITIALIZED
);
18460 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18461 else if (tlocc
!= NULL_RTX
)
18463 tval
= mem_loc_descriptor (tlocc
,
18464 GET_MODE (tlocc
) == VOIDmode
18465 ? Pmode
: GET_MODE (tlocc
),
18467 VAR_INIT_STATUS_INITIALIZED
);
18469 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18475 call_site_note_count
++;
18476 if (ca_loc
->tail_call_p
)
18477 tail_call_site_note_count
++;
18481 call_arg_locations
= NULL
;
18482 call_arg_loc_last
= NULL
;
18483 if (tail_call_site_count
>= 0
18484 && tail_call_site_count
== tail_call_site_note_count
18487 if (call_site_count
>= 0
18488 && call_site_count
== call_site_note_count
)
18489 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18491 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18493 call_site_count
= -1;
18494 tail_call_site_count
= -1;
18496 /* Add the calling convention attribute if requested. */
18497 add_calling_convention_attribute (subr_die
, decl
);
18501 /* Returns a hash value for X (which really is a die_struct). */
18504 common_block_die_table_hash (const void *x
)
18506 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18507 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18510 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18511 as decl_id and die_parent of die_struct Y. */
18514 common_block_die_table_eq (const void *x
, const void *y
)
18516 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18517 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18518 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18521 /* Generate a DIE to represent a declared data object.
18522 Either DECL or ORIGIN must be non-null. */
18525 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18527 HOST_WIDE_INT off
= 0;
18529 tree decl_or_origin
= decl
? decl
: origin
;
18530 tree ultimate_origin
;
18531 dw_die_ref var_die
;
18532 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18533 dw_die_ref origin_die
;
18534 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18535 || class_or_namespace_scope_p (context_die
));
18536 bool specialization_p
= false;
18538 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18539 if (decl
|| ultimate_origin
)
18540 origin
= ultimate_origin
;
18541 com_decl
= fortran_common (decl_or_origin
, &off
);
18543 /* Symbol in common gets emitted as a child of the common block, in the form
18544 of a data member. */
18547 dw_die_ref com_die
;
18548 dw_loc_list_ref loc
;
18549 die_node com_die_arg
;
18551 var_die
= lookup_decl_die (decl_or_origin
);
18554 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18556 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18561 /* Optimize the common case. */
18562 if (single_element_loc_list_p (loc
)
18563 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18564 && loc
->expr
->dw_loc_next
== NULL
18565 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18568 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18569 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18570 = plus_constant (GET_MODE (x
), x
, off
);
18573 loc_list_plus_const (loc
, off
);
18575 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18576 remove_AT (var_die
, DW_AT_declaration
);
18582 if (common_block_die_table
== NULL
)
18583 common_block_die_table
18584 = htab_create_ggc (10, common_block_die_table_hash
,
18585 common_block_die_table_eq
, NULL
);
18587 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18588 com_die_arg
.die_parent
= context_die
;
18589 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18590 loc
= loc_list_from_tree (com_decl
, 2);
18591 if (com_die
== NULL
)
18594 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18597 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18598 add_name_and_src_coords_attributes (com_die
, com_decl
);
18601 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18602 /* Avoid sharing the same loc descriptor between
18603 DW_TAG_common_block and DW_TAG_variable. */
18604 loc
= loc_list_from_tree (com_decl
, 2);
18606 else if (DECL_EXTERNAL (decl
))
18607 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18608 if (want_pubnames ())
18609 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18610 com_die
->decl_id
= DECL_UID (com_decl
);
18611 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18612 *slot
= (void *) com_die
;
18614 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18616 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18617 loc
= loc_list_from_tree (com_decl
, 2);
18618 remove_AT (com_die
, DW_AT_declaration
);
18620 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18621 add_name_and_src_coords_attributes (var_die
, decl
);
18622 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18623 TREE_THIS_VOLATILE (decl
), context_die
);
18624 add_AT_flag (var_die
, DW_AT_external
, 1);
18629 /* Optimize the common case. */
18630 if (single_element_loc_list_p (loc
)
18631 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18632 && loc
->expr
->dw_loc_next
== NULL
18633 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18635 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18636 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18637 = plus_constant (GET_MODE (x
), x
, off
);
18640 loc_list_plus_const (loc
, off
);
18642 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18644 else if (DECL_EXTERNAL (decl
))
18645 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18646 equate_decl_number_to_die (decl
, var_die
);
18650 /* If the compiler emitted a definition for the DECL declaration
18651 and if we already emitted a DIE for it, don't emit a second
18652 DIE for it again. Allow re-declarations of DECLs that are
18653 inside functions, though. */
18654 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18657 /* For static data members, the declaration in the class is supposed
18658 to have DW_TAG_member tag; the specification should still be
18659 DW_TAG_variable referencing the DW_TAG_member DIE. */
18660 if (declaration
&& class_scope_p (context_die
))
18661 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18663 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18666 if (origin
!= NULL
)
18667 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18669 /* Loop unrolling can create multiple blocks that refer to the same
18670 static variable, so we must test for the DW_AT_declaration flag.
18672 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18673 copy decls and set the DECL_ABSTRACT flag on them instead of
18676 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18678 ??? The declare_in_namespace support causes us to get two DIEs for one
18679 variable, both of which are declarations. We want to avoid considering
18680 one to be a specification, so we must test that this DIE is not a
18682 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18683 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18685 /* This is a definition of a C++ class level static. */
18686 add_AT_specification (var_die
, old_die
);
18687 specialization_p
= true;
18688 if (DECL_NAME (decl
))
18690 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18691 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18693 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18694 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18696 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18697 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18699 if (old_die
->die_tag
== DW_TAG_member
)
18700 add_linkage_name (var_die
, decl
);
18704 add_name_and_src_coords_attributes (var_die
, decl
);
18706 if ((origin
== NULL
&& !specialization_p
)
18708 && !DECL_ABSTRACT (decl_or_origin
)
18709 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18710 decl_function_context
18711 (decl_or_origin
))))
18713 tree type
= TREE_TYPE (decl_or_origin
);
18715 if (decl_by_reference_p (decl_or_origin
))
18716 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18718 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18719 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18722 if (origin
== NULL
&& !specialization_p
)
18724 if (TREE_PUBLIC (decl
))
18725 add_AT_flag (var_die
, DW_AT_external
, 1);
18727 if (DECL_ARTIFICIAL (decl
))
18728 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18730 add_accessibility_attribute (var_die
, decl
);
18734 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18736 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18737 equate_decl_number_to_die (decl
, var_die
);
18740 && (! DECL_ABSTRACT (decl_or_origin
)
18741 /* Local static vars are shared between all clones/inlines,
18742 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18744 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18745 && TREE_STATIC (decl_or_origin
)
18746 && DECL_RTL_SET_P (decl_or_origin
)))
18747 /* When abstract origin already has DW_AT_location attribute, no need
18748 to add it again. */
18749 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18751 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18752 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18753 defer_location (decl_or_origin
, var_die
);
18755 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18756 decl
== NULL
, DW_AT_location
);
18757 add_pubname (decl_or_origin
, var_die
);
18760 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18763 /* Generate a DIE to represent a named constant. */
18766 gen_const_die (tree decl
, dw_die_ref context_die
)
18768 dw_die_ref const_die
;
18769 tree type
= TREE_TYPE (decl
);
18771 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18772 add_name_and_src_coords_attributes (const_die
, decl
);
18773 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18774 if (TREE_PUBLIC (decl
))
18775 add_AT_flag (const_die
, DW_AT_external
, 1);
18776 if (DECL_ARTIFICIAL (decl
))
18777 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18778 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18781 /* Generate a DIE to represent a label identifier. */
18784 gen_label_die (tree decl
, dw_die_ref context_die
)
18786 tree origin
= decl_ultimate_origin (decl
);
18787 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18789 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18791 if (origin
!= NULL
)
18792 add_abstract_origin_attribute (lbl_die
, origin
);
18794 add_name_and_src_coords_attributes (lbl_die
, decl
);
18796 if (DECL_ABSTRACT (decl
))
18797 equate_decl_number_to_die (decl
, lbl_die
);
18800 insn
= DECL_RTL_IF_SET (decl
);
18802 /* Deleted labels are programmer specified labels which have been
18803 eliminated because of various optimizations. We still emit them
18804 here so that it is possible to put breakpoints on them. */
18808 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18810 /* When optimization is enabled (via -O) some parts of the compiler
18811 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18812 represent source-level labels which were explicitly declared by
18813 the user. This really shouldn't be happening though, so catch
18814 it if it ever does happen. */
18815 gcc_assert (!INSN_DELETED_P (insn
));
18817 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18818 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18822 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18823 && CODE_LABEL_NUMBER (insn
) != -1)
18825 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18826 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18831 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18832 attributes to the DIE for a block STMT, to describe where the inlined
18833 function was called from. This is similar to add_src_coords_attributes. */
18836 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18838 location_t locus
= BLOCK_SOURCE_LOCATION (stmt
);
18839 expanded_location s
= expand_location (locus
);
18841 if (dwarf_version
>= 3 || !dwarf_strict
)
18843 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18844 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18845 unsigned discr
= get_discriminator_from_locus (locus
);
18847 add_AT_unsigned (die
, DW_AT_GNU_discriminator
, discr
);
18852 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18853 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18856 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18858 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18860 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18861 && (dwarf_version
>= 3 || !dwarf_strict
))
18863 tree chain
, superblock
= NULL_TREE
;
18865 dw_attr_ref attr
= NULL
;
18867 if (inlined_function_outer_scope_p (stmt
))
18869 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18870 BLOCK_NUMBER (stmt
));
18871 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18874 /* Optimize duplicate .debug_ranges lists or even tails of
18875 lists. If this BLOCK has same ranges as its supercontext,
18876 lookup DW_AT_ranges attribute in the supercontext (and
18877 recursively so), verify that the ranges_table contains the
18878 right values and use it instead of adding a new .debug_range. */
18879 for (chain
= stmt
, pdie
= die
;
18880 BLOCK_SAME_RANGE (chain
);
18881 chain
= BLOCK_SUPERCONTEXT (chain
))
18883 dw_attr_ref new_attr
;
18885 pdie
= pdie
->die_parent
;
18888 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18890 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18891 if (new_attr
== NULL
18892 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18895 superblock
= BLOCK_SUPERCONTEXT (chain
);
18898 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18899 / 2 / DWARF2_ADDR_SIZE
].num
18900 == BLOCK_NUMBER (superblock
))
18901 && BLOCK_FRAGMENT_CHAIN (superblock
))
18903 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18904 / 2 / DWARF2_ADDR_SIZE
;
18905 unsigned long supercnt
= 0, thiscnt
= 0;
18906 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18907 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18910 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18911 == BLOCK_NUMBER (chain
));
18913 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18914 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18915 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18917 gcc_assert (supercnt
>= thiscnt
);
18918 add_AT_range_list (die
, DW_AT_ranges
,
18919 ((off
+ supercnt
- thiscnt
)
18920 * 2 * DWARF2_ADDR_SIZE
),
18925 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18927 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18930 add_ranges (chain
);
18931 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18938 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18939 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18940 BLOCK_NUMBER (stmt
));
18941 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18942 BLOCK_NUMBER (stmt
));
18943 add_AT_low_high_pc (die
, label
, label_high
, false);
18947 /* Generate a DIE for a lexical block. */
18950 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18952 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18954 if (call_arg_locations
)
18956 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18957 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18958 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18961 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18962 add_high_low_attributes (stmt
, stmt_die
);
18964 decls_for_scope (stmt
, stmt_die
, depth
);
18967 /* Generate a DIE for an inlined subprogram. */
18970 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18974 /* The instance of function that is effectively being inlined shall not
18976 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18978 decl
= block_ultimate_origin (stmt
);
18980 /* Emit info for the abstract instance first, if we haven't yet. We
18981 must emit this even if the block is abstract, otherwise when we
18982 emit the block below (or elsewhere), we may end up trying to emit
18983 a die whose origin die hasn't been emitted, and crashing. */
18984 dwarf2out_abstract_function (decl
);
18986 if (! BLOCK_ABSTRACT (stmt
))
18988 dw_die_ref subr_die
18989 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18991 if (call_arg_locations
)
18993 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18994 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18995 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18997 add_abstract_origin_attribute (subr_die
, decl
);
18998 if (TREE_ASM_WRITTEN (stmt
))
18999 add_high_low_attributes (stmt
, subr_die
);
19000 add_call_src_coords_attributes (stmt
, subr_die
);
19002 decls_for_scope (stmt
, subr_die
, depth
);
19003 current_function_has_inlines
= 1;
19007 /* Generate a DIE for a field in a record, or structure. */
19010 gen_field_die (tree decl
, dw_die_ref context_die
)
19012 dw_die_ref decl_die
;
19014 if (TREE_TYPE (decl
) == error_mark_node
)
19017 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19018 add_name_and_src_coords_attributes (decl_die
, decl
);
19019 add_type_attribute (decl_die
, member_declared_type (decl
),
19020 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
19023 if (DECL_BIT_FIELD_TYPE (decl
))
19025 add_byte_size_attribute (decl_die
, decl
);
19026 add_bit_size_attribute (decl_die
, decl
);
19027 add_bit_offset_attribute (decl_die
, decl
);
19030 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19031 add_data_member_location_attribute (decl_die
, decl
);
19033 if (DECL_ARTIFICIAL (decl
))
19034 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19036 add_accessibility_attribute (decl_die
, decl
);
19038 /* Equate decl number to die, so that we can look up this decl later on. */
19039 equate_decl_number_to_die (decl
, decl_die
);
19043 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19044 Use modified_type_die instead.
19045 We keep this code here just in case these types of DIEs may be needed to
19046 represent certain things in other languages (e.g. Pascal) someday. */
19049 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19052 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19054 equate_type_number_to_die (type
, ptr_die
);
19055 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19056 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19059 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19060 Use modified_type_die instead.
19061 We keep this code here just in case these types of DIEs may be needed to
19062 represent certain things in other languages (e.g. Pascal) someday. */
19065 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19067 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19069 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19070 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19072 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19074 equate_type_number_to_die (type
, ref_die
);
19075 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
19076 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19080 /* Generate a DIE for a pointer to a member type. */
19083 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
19086 = new_die (DW_TAG_ptr_to_member_type
,
19087 scope_die_for (type
, context_die
), type
);
19089 equate_type_number_to_die (type
, ptr_die
);
19090 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
19091 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
19092 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19095 typedef const char *dchar_p
; /* For DEF_VEC_P. */
19097 static char *producer_string
;
19099 /* Return a heap allocated producer string including command line options
19100 if -grecord-gcc-switches. */
19103 gen_producer_string (void)
19106 vec
<dchar_p
> switches
= vNULL
;
19107 const char *language_string
= lang_hooks
.name
;
19108 char *producer
, *tail
;
19110 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
19111 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
19113 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
19114 switch (save_decoded_options
[j
].opt_index
)
19121 case OPT_auxbase_strip
:
19130 case OPT_SPECIAL_unknown
:
19131 case OPT_SPECIAL_ignore
:
19132 case OPT_SPECIAL_program_name
:
19133 case OPT_SPECIAL_input_file
:
19134 case OPT_grecord_gcc_switches
:
19135 case OPT_gno_record_gcc_switches
:
19136 case OPT__output_pch_
:
19137 case OPT_fdiagnostics_show_location_
:
19138 case OPT_fdiagnostics_show_option
:
19139 case OPT_fdiagnostics_show_caret
:
19140 case OPT_fverbose_asm
:
19142 case OPT__sysroot_
:
19144 case OPT_nostdinc__
:
19145 /* Ignore these. */
19148 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
19149 & CL_NO_DWARF_RECORD
)
19151 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
19153 switch (save_decoded_options
[j
].canonical_option
[0][1])
19160 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
19167 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
19168 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
19172 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
19174 sprintf (tail
, "%s %s", language_string
, version_string
);
19177 FOR_EACH_VEC_ELT (switches
, j
, p
)
19181 memcpy (tail
+ 1, p
, len
);
19186 switches
.release ();
19190 /* Generate the DIE for the compilation unit. */
19193 gen_compile_unit_die (const char *filename
)
19196 const char *language_string
= lang_hooks
.name
;
19199 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19203 add_name_attribute (die
, filename
);
19204 /* Don't add cwd for <built-in>. */
19205 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19206 add_comp_dir_attribute (die
);
19209 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19211 /* If our producer is LTO try to figure out a common language to use
19212 from the global list of translation units. */
19213 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19217 const char *common_lang
= NULL
;
19219 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19221 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19224 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19225 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19227 else if (strncmp (common_lang
, "GNU C", 5) == 0
19228 && strncmp(TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19229 /* Mixing C and C++ is ok, use C++ in that case. */
19230 common_lang
= "GNU C++";
19233 /* Fall back to C. */
19234 common_lang
= NULL
;
19240 language_string
= common_lang
;
19243 language
= DW_LANG_C89
;
19244 if (strcmp (language_string
, "GNU C++") == 0)
19245 language
= DW_LANG_C_plus_plus
;
19246 else if (strcmp (language_string
, "GNU F77") == 0)
19247 language
= DW_LANG_Fortran77
;
19248 else if (strcmp (language_string
, "GNU Pascal") == 0)
19249 language
= DW_LANG_Pascal83
;
19250 else if (dwarf_version
>= 3 || !dwarf_strict
)
19252 if (strcmp (language_string
, "GNU Ada") == 0)
19253 language
= DW_LANG_Ada95
;
19254 else if (strcmp (language_string
, "GNU Fortran") == 0)
19255 language
= DW_LANG_Fortran95
;
19256 else if (strcmp (language_string
, "GNU Java") == 0)
19257 language
= DW_LANG_Java
;
19258 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19259 language
= DW_LANG_ObjC
;
19260 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19261 language
= DW_LANG_ObjC_plus_plus
;
19262 else if (dwarf_version
>= 5 || !dwarf_strict
)
19264 if (strcmp (language_string
, "GNU Go") == 0)
19265 language
= DW_LANG_Go
;
19268 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19269 else if (strcmp (language_string
, "GNU Fortran") == 0)
19270 language
= DW_LANG_Fortran90
;
19272 add_AT_unsigned (die
, DW_AT_language
, language
);
19276 case DW_LANG_Fortran77
:
19277 case DW_LANG_Fortran90
:
19278 case DW_LANG_Fortran95
:
19279 /* Fortran has case insensitive identifiers and the front-end
19280 lowercases everything. */
19281 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19284 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19290 /* Generate the DIE for a base class. */
19293 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19295 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19297 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19298 add_data_member_location_attribute (die
, binfo
);
19300 if (BINFO_VIRTUAL_P (binfo
))
19301 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19303 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19304 children, otherwise the default is DW_ACCESS_public. In DWARF2
19305 the default has always been DW_ACCESS_private. */
19306 if (access
== access_public_node
)
19308 if (dwarf_version
== 2
19309 || context_die
->die_tag
== DW_TAG_class_type
)
19310 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19312 else if (access
== access_protected_node
)
19313 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19314 else if (dwarf_version
> 2
19315 && context_die
->die_tag
!= DW_TAG_class_type
)
19316 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19319 /* Generate a DIE for a class member. */
19322 gen_member_die (tree type
, dw_die_ref context_die
)
19325 tree binfo
= TYPE_BINFO (type
);
19328 /* If this is not an incomplete type, output descriptions of each of its
19329 members. Note that as we output the DIEs necessary to represent the
19330 members of this record or union type, we will also be trying to output
19331 DIEs to represent the *types* of those members. However the `type'
19332 function (above) will specifically avoid generating type DIEs for member
19333 types *within* the list of member DIEs for this (containing) type except
19334 for those types (of members) which are explicitly marked as also being
19335 members of this (containing) type themselves. The g++ front- end can
19336 force any given type to be treated as a member of some other (containing)
19337 type by setting the TYPE_CONTEXT of the given (member) type to point to
19338 the TREE node representing the appropriate (containing) type. */
19340 /* First output info about the base classes. */
19343 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19347 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19348 gen_inheritance_die (base
,
19349 (accesses
? (*accesses
)[i
] : access_public_node
),
19353 /* Now output info about the data members and type members. */
19354 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19356 /* If we thought we were generating minimal debug info for TYPE
19357 and then changed our minds, some of the member declarations
19358 may have already been defined. Don't define them again, but
19359 do put them in the right order. */
19361 child
= lookup_decl_die (member
);
19363 splice_child_die (context_die
, child
);
19365 gen_decl_die (member
, NULL
, context_die
);
19368 /* Now output info about the function members (if any). */
19369 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19371 /* Don't include clones in the member list. */
19372 if (DECL_ABSTRACT_ORIGIN (member
))
19375 child
= lookup_decl_die (member
);
19377 splice_child_die (context_die
, child
);
19379 gen_decl_die (member
, NULL
, context_die
);
19383 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19384 is set, we pretend that the type was never defined, so we only get the
19385 member DIEs needed by later specification DIEs. */
19388 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19389 enum debug_info_usage usage
)
19391 dw_die_ref type_die
= lookup_type_die (type
);
19392 dw_die_ref scope_die
= 0;
19394 int complete
= (TYPE_SIZE (type
)
19395 && (! TYPE_STUB_DECL (type
)
19396 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19397 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19398 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19400 if (type_die
&& ! complete
)
19403 if (TYPE_CONTEXT (type
) != NULL_TREE
19404 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19405 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19408 scope_die
= scope_die_for (type
, context_die
);
19410 /* Generate child dies for template paramaters. */
19411 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19412 schedule_generic_params_dies_gen (type
);
19414 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19415 /* First occurrence of type or toplevel definition of nested class. */
19417 dw_die_ref old_die
= type_die
;
19419 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19420 ? record_type_tag (type
) : DW_TAG_union_type
,
19422 equate_type_number_to_die (type
, type_die
);
19424 add_AT_specification (type_die
, old_die
);
19426 add_name_attribute (type_die
, type_tag (type
));
19429 remove_AT (type_die
, DW_AT_declaration
);
19431 /* If this type has been completed, then give it a byte_size attribute and
19432 then give a list of members. */
19433 if (complete
&& !ns_decl
)
19435 /* Prevent infinite recursion in cases where the type of some member of
19436 this type is expressed in terms of this type itself. */
19437 TREE_ASM_WRITTEN (type
) = 1;
19438 add_byte_size_attribute (type_die
, type
);
19439 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19441 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19442 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19445 /* If the first reference to this type was as the return type of an
19446 inline function, then it may not have a parent. Fix this now. */
19447 if (type_die
->die_parent
== NULL
)
19448 add_child_die (scope_die
, type_die
);
19450 push_decl_scope (type
);
19451 gen_member_die (type
, type_die
);
19454 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19455 if (TYPE_ARTIFICIAL (type
))
19456 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19458 /* GNU extension: Record what type our vtable lives in. */
19459 if (TYPE_VFIELD (type
))
19461 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19463 gen_type_die (vtype
, context_die
);
19464 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19465 lookup_type_die (vtype
));
19470 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19472 /* We don't need to do this for function-local types. */
19473 if (TYPE_STUB_DECL (type
)
19474 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19475 vec_safe_push (incomplete_types
, type
);
19478 if (get_AT (type_die
, DW_AT_name
))
19479 add_pubtype (type
, type_die
);
19482 /* Generate a DIE for a subroutine _type_. */
19485 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19487 tree return_type
= TREE_TYPE (type
);
19488 dw_die_ref subr_die
19489 = new_die (DW_TAG_subroutine_type
,
19490 scope_die_for (type
, context_die
), type
);
19492 equate_type_number_to_die (type
, subr_die
);
19493 add_prototyped_attribute (subr_die
, type
);
19494 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19495 gen_formal_types_die (type
, subr_die
);
19497 if (get_AT (subr_die
, DW_AT_name
))
19498 add_pubtype (type
, subr_die
);
19501 /* Generate a DIE for a type definition. */
19504 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19506 dw_die_ref type_die
;
19509 if (TREE_ASM_WRITTEN (decl
))
19512 TREE_ASM_WRITTEN (decl
) = 1;
19513 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19514 origin
= decl_ultimate_origin (decl
);
19515 if (origin
!= NULL
)
19516 add_abstract_origin_attribute (type_die
, origin
);
19521 add_name_and_src_coords_attributes (type_die
, decl
);
19522 if (DECL_ORIGINAL_TYPE (decl
))
19524 type
= DECL_ORIGINAL_TYPE (decl
);
19526 gcc_assert (type
!= TREE_TYPE (decl
));
19527 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19531 type
= TREE_TYPE (decl
);
19533 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19535 /* Here, we are in the case of decl being a typedef naming
19536 an anonymous type, e.g:
19537 typedef struct {...} foo;
19538 In that case TREE_TYPE (decl) is not a typedef variant
19539 type and TYPE_NAME of the anonymous type is set to the
19540 TYPE_DECL of the typedef. This construct is emitted by
19543 TYPE is the anonymous struct named by the typedef
19544 DECL. As we need the DW_AT_type attribute of the
19545 DW_TAG_typedef to point to the DIE of TYPE, let's
19546 generate that DIE right away. add_type_attribute
19547 called below will then pick (via lookup_type_die) that
19548 anonymous struct DIE. */
19549 if (!TREE_ASM_WRITTEN (type
))
19550 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19552 /* This is a GNU Extension. We are adding a
19553 DW_AT_linkage_name attribute to the DIE of the
19554 anonymous struct TYPE. The value of that attribute
19555 is the name of the typedef decl naming the anonymous
19556 struct. This greatly eases the work of consumers of
19557 this debug info. */
19558 add_linkage_attr (lookup_type_die (type
), decl
);
19562 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19563 TREE_THIS_VOLATILE (decl
), context_die
);
19565 if (is_naming_typedef_decl (decl
))
19566 /* We want that all subsequent calls to lookup_type_die with
19567 TYPE in argument yield the DW_TAG_typedef we have just
19569 equate_type_number_to_die (type
, type_die
);
19571 add_accessibility_attribute (type_die
, decl
);
19574 if (DECL_ABSTRACT (decl
))
19575 equate_decl_number_to_die (decl
, type_die
);
19577 if (get_AT (type_die
, DW_AT_name
))
19578 add_pubtype (decl
, type_die
);
19581 /* Generate a DIE for a struct, class, enum or union type. */
19584 gen_tagged_type_die (tree type
,
19585 dw_die_ref context_die
,
19586 enum debug_info_usage usage
)
19590 if (type
== NULL_TREE
19591 || !is_tagged_type (type
))
19594 /* If this is a nested type whose containing class hasn't been written
19595 out yet, writing it out will cover this one, too. This does not apply
19596 to instantiations of member class templates; they need to be added to
19597 the containing class as they are generated. FIXME: This hurts the
19598 idea of combining type decls from multiple TUs, since we can't predict
19599 what set of template instantiations we'll get. */
19600 if (TYPE_CONTEXT (type
)
19601 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19602 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19604 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19606 if (TREE_ASM_WRITTEN (type
))
19609 /* If that failed, attach ourselves to the stub. */
19610 push_decl_scope (TYPE_CONTEXT (type
));
19611 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19614 else if (TYPE_CONTEXT (type
) != NULL_TREE
19615 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19617 /* If this type is local to a function that hasn't been written
19618 out yet, use a NULL context for now; it will be fixed up in
19619 decls_for_scope. */
19620 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19621 /* A declaration DIE doesn't count; nested types need to go in the
19623 if (context_die
&& is_declaration_die (context_die
))
19624 context_die
= NULL
;
19629 context_die
= declare_in_namespace (type
, context_die
);
19633 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19635 /* This might have been written out by the call to
19636 declare_in_namespace. */
19637 if (!TREE_ASM_WRITTEN (type
))
19638 gen_enumeration_type_die (type
, context_die
);
19641 gen_struct_or_union_type_die (type
, context_die
, usage
);
19646 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19647 it up if it is ever completed. gen_*_type_die will set it for us
19648 when appropriate. */
19651 /* Generate a type description DIE. */
19654 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19655 enum debug_info_usage usage
)
19657 struct array_descr_info info
;
19659 if (type
== NULL_TREE
|| type
== error_mark_node
)
19662 if (TYPE_NAME (type
) != NULL_TREE
19663 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19664 && is_redundant_typedef (TYPE_NAME (type
))
19665 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19666 /* The DECL of this type is a typedef we don't want to emit debug
19667 info for but we want debug info for its underlying typedef.
19668 This can happen for e.g, the injected-class-name of a C++
19670 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19672 /* If TYPE is a typedef type variant, let's generate debug info
19673 for the parent typedef which TYPE is a type of. */
19674 if (typedef_variant_p (type
))
19676 if (TREE_ASM_WRITTEN (type
))
19679 /* Prevent broken recursion; we can't hand off to the same type. */
19680 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19682 /* Give typedefs the right scope. */
19683 context_die
= scope_die_for (type
, context_die
);
19685 TREE_ASM_WRITTEN (type
) = 1;
19687 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19691 /* If type is an anonymous tagged type named by a typedef, let's
19692 generate debug info for the typedef. */
19693 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19695 /* Use the DIE of the containing namespace as the parent DIE of
19696 the type description DIE we want to generate. */
19697 if (DECL_CONTEXT (TYPE_NAME (type
))
19698 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19699 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19701 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19705 /* If this is an array type with hidden descriptor, handle it first. */
19706 if (!TREE_ASM_WRITTEN (type
)
19707 && lang_hooks
.types
.get_array_descr_info
19708 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19709 && (dwarf_version
>= 3 || !dwarf_strict
))
19711 gen_descr_array_type_die (type
, &info
, context_die
);
19712 TREE_ASM_WRITTEN (type
) = 1;
19716 /* We are going to output a DIE to represent the unqualified version
19717 of this type (i.e. without any const or volatile qualifiers) so
19718 get the main variant (i.e. the unqualified version) of this type
19719 now. (Vectors are special because the debugging info is in the
19720 cloned type itself). */
19721 if (TREE_CODE (type
) != VECTOR_TYPE
)
19722 type
= type_main_variant (type
);
19724 if (TREE_ASM_WRITTEN (type
))
19727 switch (TREE_CODE (type
))
19733 case REFERENCE_TYPE
:
19734 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19735 ensures that the gen_type_die recursion will terminate even if the
19736 type is recursive. Recursive types are possible in Ada. */
19737 /* ??? We could perhaps do this for all types before the switch
19739 TREE_ASM_WRITTEN (type
) = 1;
19741 /* For these types, all that is required is that we output a DIE (or a
19742 set of DIEs) to represent the "basis" type. */
19743 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19744 DINFO_USAGE_IND_USE
);
19748 /* This code is used for C++ pointer-to-data-member types.
19749 Output a description of the relevant class type. */
19750 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19751 DINFO_USAGE_IND_USE
);
19753 /* Output a description of the type of the object pointed to. */
19754 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19755 DINFO_USAGE_IND_USE
);
19757 /* Now output a DIE to represent this pointer-to-data-member type
19759 gen_ptr_to_mbr_type_die (type
, context_die
);
19762 case FUNCTION_TYPE
:
19763 /* Force out return type (in case it wasn't forced out already). */
19764 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19765 DINFO_USAGE_DIR_USE
);
19766 gen_subroutine_type_die (type
, context_die
);
19770 /* Force out return type (in case it wasn't forced out already). */
19771 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19772 DINFO_USAGE_DIR_USE
);
19773 gen_subroutine_type_die (type
, context_die
);
19777 gen_array_type_die (type
, context_die
);
19781 gen_array_type_die (type
, context_die
);
19784 case ENUMERAL_TYPE
:
19787 case QUAL_UNION_TYPE
:
19788 gen_tagged_type_die (type
, context_die
, usage
);
19794 case FIXED_POINT_TYPE
:
19797 /* No DIEs needed for fundamental types. */
19802 /* Just use DW_TAG_unspecified_type. */
19804 dw_die_ref type_die
= lookup_type_die (type
);
19805 if (type_die
== NULL
)
19807 tree name
= TYPE_NAME (type
);
19808 if (TREE_CODE (name
) == TYPE_DECL
)
19809 name
= DECL_NAME (name
);
19810 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19811 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19812 equate_type_number_to_die (type
, type_die
);
19818 gcc_unreachable ();
19821 TREE_ASM_WRITTEN (type
) = 1;
19825 gen_type_die (tree type
, dw_die_ref context_die
)
19827 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19830 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19831 things which are local to the given block. */
19834 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19836 int must_output_die
= 0;
19839 /* Ignore blocks that are NULL. */
19840 if (stmt
== NULL_TREE
)
19843 inlined_func
= inlined_function_outer_scope_p (stmt
);
19845 /* If the block is one fragment of a non-contiguous block, do not
19846 process the variables, since they will have been done by the
19847 origin block. Do process subblocks. */
19848 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19852 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19853 gen_block_die (sub
, context_die
, depth
+ 1);
19858 /* Determine if we need to output any Dwarf DIEs at all to represent this
19861 /* The outer scopes for inlinings *must* always be represented. We
19862 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19863 must_output_die
= 1;
19866 /* Determine if this block directly contains any "significant"
19867 local declarations which we will need to output DIEs for. */
19868 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19869 /* We are not in terse mode so *any* local declaration counts
19870 as being a "significant" one. */
19871 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19872 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19873 && (TREE_USED (stmt
)
19874 || TREE_ASM_WRITTEN (stmt
)
19875 || BLOCK_ABSTRACT (stmt
)));
19876 else if ((TREE_USED (stmt
)
19877 || TREE_ASM_WRITTEN (stmt
)
19878 || BLOCK_ABSTRACT (stmt
))
19879 && !dwarf2out_ignore_block (stmt
))
19880 must_output_die
= 1;
19883 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19884 DIE for any block which contains no significant local declarations at
19885 all. Rather, in such cases we just call `decls_for_scope' so that any
19886 needed Dwarf info for any sub-blocks will get properly generated. Note
19887 that in terse mode, our definition of what constitutes a "significant"
19888 local declaration gets restricted to include only inlined function
19889 instances and local (nested) function definitions. */
19890 if (must_output_die
)
19894 /* If STMT block is abstract, that means we have been called
19895 indirectly from dwarf2out_abstract_function.
19896 That function rightfully marks the descendent blocks (of
19897 the abstract function it is dealing with) as being abstract,
19898 precisely to prevent us from emitting any
19899 DW_TAG_inlined_subroutine DIE as a descendent
19900 of an abstract function instance. So in that case, we should
19901 not call gen_inlined_subroutine_die.
19903 Later though, when cgraph asks dwarf2out to emit info
19904 for the concrete instance of the function decl into which
19905 the concrete instance of STMT got inlined, the later will lead
19906 to the generation of a DW_TAG_inlined_subroutine DIE. */
19907 if (! BLOCK_ABSTRACT (stmt
))
19908 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19911 gen_lexical_block_die (stmt
, context_die
, depth
);
19914 decls_for_scope (stmt
, context_die
, depth
);
19917 /* Process variable DECL (or variable with origin ORIGIN) within
19918 block STMT and add it to CONTEXT_DIE. */
19920 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19923 tree decl_or_origin
= decl
? decl
: origin
;
19925 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19926 die
= lookup_decl_die (decl_or_origin
);
19927 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19928 && TYPE_DECL_IS_STUB (decl_or_origin
))
19929 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19933 if (die
!= NULL
&& die
->die_parent
== NULL
)
19934 add_child_die (context_die
, die
);
19935 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19936 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19937 stmt
, context_die
);
19939 gen_decl_die (decl
, origin
, context_die
);
19942 /* Generate all of the decls declared within a given scope and (recursively)
19943 all of its sub-blocks. */
19946 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19952 /* Ignore NULL blocks. */
19953 if (stmt
== NULL_TREE
)
19956 /* Output the DIEs to represent all of the data objects and typedefs
19957 declared directly within this block but not within any nested
19958 sub-blocks. Also, nested function and tag DIEs have been
19959 generated with a parent of NULL; fix that up now. We don't
19960 have to do this if we're at -g1. */
19961 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19963 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19964 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19965 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19966 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19970 /* Even if we're at -g1, we need to process the subblocks in order to get
19971 inlined call information. */
19973 /* Output the DIEs to represent all sub-blocks (and the items declared
19974 therein) of this block. */
19975 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19977 subblocks
= BLOCK_CHAIN (subblocks
))
19978 gen_block_die (subblocks
, context_die
, depth
+ 1);
19981 /* Is this a typedef we can avoid emitting? */
19984 is_redundant_typedef (const_tree decl
)
19986 if (TYPE_DECL_IS_STUB (decl
))
19989 if (DECL_ARTIFICIAL (decl
)
19990 && DECL_CONTEXT (decl
)
19991 && is_tagged_type (DECL_CONTEXT (decl
))
19992 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19993 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19994 /* Also ignore the artificial member typedef for the class name. */
20000 /* Return TRUE if TYPE is a typedef that names a type for linkage
20001 purposes. This kind of typedefs is produced by the C++ FE for
20004 typedef struct {...} foo;
20006 In that case, there is no typedef variant type produced for foo.
20007 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20011 is_naming_typedef_decl (const_tree decl
)
20013 if (decl
== NULL_TREE
20014 || TREE_CODE (decl
) != TYPE_DECL
20015 || !is_tagged_type (TREE_TYPE (decl
))
20016 || DECL_IS_BUILTIN (decl
)
20017 || is_redundant_typedef (decl
)
20018 /* It looks like Ada produces TYPE_DECLs that are very similar
20019 to C++ naming typedefs but that have different
20020 semantics. Let's be specific to c++ for now. */
20024 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20025 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20026 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20027 != TYPE_NAME (TREE_TYPE (decl
))));
20030 /* Returns the DIE for a context. */
20032 static inline dw_die_ref
20033 get_context_die (tree context
)
20037 /* Find die that represents this context. */
20038 if (TYPE_P (context
))
20040 context
= TYPE_MAIN_VARIANT (context
);
20041 return strip_naming_typedef (context
, force_type_die (context
));
20044 return force_decl_die (context
);
20046 return comp_unit_die ();
20049 /* Returns the DIE for decl. A DIE will always be returned. */
20052 force_decl_die (tree decl
)
20054 dw_die_ref decl_die
;
20055 unsigned saved_external_flag
;
20056 tree save_fn
= NULL_TREE
;
20057 decl_die
= lookup_decl_die (decl
);
20060 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20062 decl_die
= lookup_decl_die (decl
);
20066 switch (TREE_CODE (decl
))
20068 case FUNCTION_DECL
:
20069 /* Clear current_function_decl, so that gen_subprogram_die thinks
20070 that this is a declaration. At this point, we just want to force
20071 declaration die. */
20072 save_fn
= current_function_decl
;
20073 current_function_decl
= NULL_TREE
;
20074 gen_subprogram_die (decl
, context_die
);
20075 current_function_decl
= save_fn
;
20079 /* Set external flag to force declaration die. Restore it after
20080 gen_decl_die() call. */
20081 saved_external_flag
= DECL_EXTERNAL (decl
);
20082 DECL_EXTERNAL (decl
) = 1;
20083 gen_decl_die (decl
, NULL
, context_die
);
20084 DECL_EXTERNAL (decl
) = saved_external_flag
;
20087 case NAMESPACE_DECL
:
20088 if (dwarf_version
>= 3 || !dwarf_strict
)
20089 dwarf2out_decl (decl
);
20091 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20092 decl_die
= comp_unit_die ();
20095 case TRANSLATION_UNIT_DECL
:
20096 decl_die
= comp_unit_die ();
20100 gcc_unreachable ();
20103 /* We should be able to find the DIE now. */
20105 decl_die
= lookup_decl_die (decl
);
20106 gcc_assert (decl_die
);
20112 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20113 always returned. */
20116 force_type_die (tree type
)
20118 dw_die_ref type_die
;
20120 type_die
= lookup_type_die (type
);
20123 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20125 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20126 TYPE_VOLATILE (type
), context_die
);
20127 gcc_assert (type_die
);
20132 /* Force out any required namespaces to be able to output DECL,
20133 and return the new context_die for it, if it's changed. */
20136 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20138 tree context
= (DECL_P (thing
)
20139 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20140 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20141 /* Force out the namespace. */
20142 context_die
= force_decl_die (context
);
20144 return context_die
;
20147 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20148 type) within its namespace, if appropriate.
20150 For compatibility with older debuggers, namespace DIEs only contain
20151 declarations; all definitions are emitted at CU scope. */
20154 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20156 dw_die_ref ns_context
;
20158 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20159 return context_die
;
20161 /* If this decl is from an inlined function, then don't try to emit it in its
20162 namespace, as we will get confused. It would have already been emitted
20163 when the abstract instance of the inline function was emitted anyways. */
20164 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20165 return context_die
;
20167 ns_context
= setup_namespace_context (thing
, context_die
);
20169 if (ns_context
!= context_die
)
20173 if (DECL_P (thing
))
20174 gen_decl_die (thing
, NULL
, ns_context
);
20176 gen_type_die (thing
, ns_context
);
20178 return context_die
;
20181 /* Generate a DIE for a namespace or namespace alias. */
20184 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20186 dw_die_ref namespace_die
;
20188 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20189 they are an alias of. */
20190 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20192 /* Output a real namespace or module. */
20193 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20194 namespace_die
= new_die (is_fortran ()
20195 ? DW_TAG_module
: DW_TAG_namespace
,
20196 context_die
, decl
);
20197 /* For Fortran modules defined in different CU don't add src coords. */
20198 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20200 const char *name
= dwarf2_name (decl
, 0);
20202 add_name_attribute (namespace_die
, name
);
20205 add_name_and_src_coords_attributes (namespace_die
, decl
);
20206 if (DECL_EXTERNAL (decl
))
20207 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20208 equate_decl_number_to_die (decl
, namespace_die
);
20212 /* Output a namespace alias. */
20214 /* Force out the namespace we are an alias of, if necessary. */
20215 dw_die_ref origin_die
20216 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20218 if (DECL_FILE_SCOPE_P (decl
)
20219 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20220 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20221 /* Now create the namespace alias DIE. */
20222 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20223 add_name_and_src_coords_attributes (namespace_die
, decl
);
20224 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20225 equate_decl_number_to_die (decl
, namespace_die
);
20227 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20228 if (want_pubnames ())
20229 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20232 /* Generate Dwarf debug information for a decl described by DECL.
20233 The return value is currently only meaningful for PARM_DECLs,
20234 for all other decls it returns NULL. */
20237 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20239 tree decl_or_origin
= decl
? decl
: origin
;
20240 tree class_origin
= NULL
, ultimate_origin
;
20242 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20245 switch (TREE_CODE (decl_or_origin
))
20251 if (!is_fortran () && !is_ada ())
20253 /* The individual enumerators of an enum type get output when we output
20254 the Dwarf representation of the relevant enum type itself. */
20258 /* Emit its type. */
20259 gen_type_die (TREE_TYPE (decl
), context_die
);
20261 /* And its containing namespace. */
20262 context_die
= declare_in_namespace (decl
, context_die
);
20264 gen_const_die (decl
, context_die
);
20267 case FUNCTION_DECL
:
20268 /* Don't output any DIEs to represent mere function declarations,
20269 unless they are class members or explicit block externs. */
20270 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20271 && DECL_FILE_SCOPE_P (decl_or_origin
)
20272 && (current_function_decl
== NULL_TREE
20273 || DECL_ARTIFICIAL (decl_or_origin
)))
20278 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20279 on local redeclarations of global functions. That seems broken. */
20280 if (current_function_decl
!= decl
)
20281 /* This is only a declaration. */;
20284 /* If we're emitting a clone, emit info for the abstract instance. */
20285 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20286 dwarf2out_abstract_function (origin
20287 ? DECL_ORIGIN (origin
)
20288 : DECL_ABSTRACT_ORIGIN (decl
));
20290 /* If we're emitting an out-of-line copy of an inline function,
20291 emit info for the abstract instance and set up to refer to it. */
20292 else if (cgraph_function_possibly_inlined_p (decl
)
20293 && ! DECL_ABSTRACT (decl
)
20294 && ! class_or_namespace_scope_p (context_die
)
20295 /* dwarf2out_abstract_function won't emit a die if this is just
20296 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20297 that case, because that works only if we have a die. */
20298 && DECL_INITIAL (decl
) != NULL_TREE
)
20300 dwarf2out_abstract_function (decl
);
20301 set_decl_origin_self (decl
);
20304 /* Otherwise we're emitting the primary DIE for this decl. */
20305 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20307 /* Before we describe the FUNCTION_DECL itself, make sure that we
20308 have its containing type. */
20310 origin
= decl_class_context (decl
);
20311 if (origin
!= NULL_TREE
)
20312 gen_type_die (origin
, context_die
);
20314 /* And its return type. */
20315 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20317 /* And its virtual context. */
20318 if (DECL_VINDEX (decl
) != NULL_TREE
)
20319 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20321 /* Make sure we have a member DIE for decl. */
20322 if (origin
!= NULL_TREE
)
20323 gen_type_die_for_member (origin
, decl
, context_die
);
20325 /* And its containing namespace. */
20326 context_die
= declare_in_namespace (decl
, context_die
);
20329 /* Now output a DIE to represent the function itself. */
20331 gen_subprogram_die (decl
, context_die
);
20335 /* If we are in terse mode, don't generate any DIEs to represent any
20336 actual typedefs. */
20337 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20340 /* In the special case of a TYPE_DECL node representing the declaration
20341 of some type tag, if the given TYPE_DECL is marked as having been
20342 instantiated from some other (original) TYPE_DECL node (e.g. one which
20343 was generated within the original definition of an inline function) we
20344 used to generate a special (abbreviated) DW_TAG_structure_type,
20345 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20346 should be actually referencing those DIEs, as variable DIEs with that
20347 type would be emitted already in the abstract origin, so it was always
20348 removed during unused type prunning. Don't add anything in this
20350 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20353 if (is_redundant_typedef (decl
))
20354 gen_type_die (TREE_TYPE (decl
), context_die
);
20356 /* Output a DIE to represent the typedef itself. */
20357 gen_typedef_die (decl
, context_die
);
20361 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20362 gen_label_die (decl
, context_die
);
20367 /* If we are in terse mode, don't generate any DIEs to represent any
20368 variable declarations or definitions. */
20369 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20372 /* Output any DIEs that are needed to specify the type of this data
20374 if (decl_by_reference_p (decl_or_origin
))
20375 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20377 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20379 /* And its containing type. */
20380 class_origin
= decl_class_context (decl_or_origin
);
20381 if (class_origin
!= NULL_TREE
)
20382 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20384 /* And its containing namespace. */
20385 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20387 /* Now output the DIE to represent the data object itself. This gets
20388 complicated because of the possibility that the VAR_DECL really
20389 represents an inlined instance of a formal parameter for an inline
20391 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20392 if (ultimate_origin
!= NULL_TREE
20393 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20394 gen_formal_parameter_die (decl
, origin
,
20395 true /* Emit name attribute. */,
20398 gen_variable_die (decl
, origin
, context_die
);
20402 /* Ignore the nameless fields that are used to skip bits but handle C++
20403 anonymous unions and structs. */
20404 if (DECL_NAME (decl
) != NULL_TREE
20405 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20406 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20408 gen_type_die (member_declared_type (decl
), context_die
);
20409 gen_field_die (decl
, context_die
);
20414 if (DECL_BY_REFERENCE (decl_or_origin
))
20415 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20417 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20418 return gen_formal_parameter_die (decl
, origin
,
20419 true /* Emit name attribute. */,
20422 case NAMESPACE_DECL
:
20423 case IMPORTED_DECL
:
20424 if (dwarf_version
>= 3 || !dwarf_strict
)
20425 gen_namespace_die (decl
, context_die
);
20429 /* Probably some frontend-internal decl. Assume we don't care. */
20430 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20437 /* Output debug information for global decl DECL. Called from toplev.c after
20438 compilation proper has finished. */
20441 dwarf2out_global_decl (tree decl
)
20443 /* Output DWARF2 information for file-scope tentative data object
20444 declarations, file-scope (extern) function declarations (which
20445 had no corresponding body) and file-scope tagged type declarations
20446 and definitions which have not yet been forced out. */
20447 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20448 dwarf2out_decl (decl
);
20451 /* Output debug information for type decl DECL. Called from toplev.c
20452 and from language front ends (to record built-in types). */
20454 dwarf2out_type_decl (tree decl
, int local
)
20457 dwarf2out_decl (decl
);
20460 /* Output debug information for imported module or decl DECL.
20461 NAME is non-NULL name in the lexical block if the decl has been renamed.
20462 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20463 that DECL belongs to.
20464 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20466 dwarf2out_imported_module_or_decl_1 (tree decl
,
20468 tree lexical_block
,
20469 dw_die_ref lexical_block_die
)
20471 expanded_location xloc
;
20472 dw_die_ref imported_die
= NULL
;
20473 dw_die_ref at_import_die
;
20475 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20477 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20478 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20482 xloc
= expand_location (input_location
);
20484 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20486 at_import_die
= force_type_die (TREE_TYPE (decl
));
20487 /* For namespace N { typedef void T; } using N::T; base_type_die
20488 returns NULL, but DW_TAG_imported_declaration requires
20489 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20490 if (!at_import_die
)
20492 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20493 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20494 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20495 gcc_assert (at_import_die
);
20500 at_import_die
= lookup_decl_die (decl
);
20501 if (!at_import_die
)
20503 /* If we're trying to avoid duplicate debug info, we may not have
20504 emitted the member decl for this field. Emit it now. */
20505 if (TREE_CODE (decl
) == FIELD_DECL
)
20507 tree type
= DECL_CONTEXT (decl
);
20509 if (TYPE_CONTEXT (type
)
20510 && TYPE_P (TYPE_CONTEXT (type
))
20511 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20512 DINFO_USAGE_DIR_USE
))
20514 gen_type_die_for_member (type
, decl
,
20515 get_context_die (TYPE_CONTEXT (type
)));
20517 at_import_die
= force_decl_die (decl
);
20521 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20523 if (dwarf_version
>= 3 || !dwarf_strict
)
20524 imported_die
= new_die (DW_TAG_imported_module
,
20531 imported_die
= new_die (DW_TAG_imported_declaration
,
20535 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20536 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20538 add_AT_string (imported_die
, DW_AT_name
,
20539 IDENTIFIER_POINTER (name
));
20540 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20543 /* Output debug information for imported module or decl DECL.
20544 NAME is non-NULL name in context if the decl has been renamed.
20545 CHILD is true if decl is one of the renamed decls as part of
20546 importing whole module. */
20549 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20552 /* dw_die_ref at_import_die; */
20553 dw_die_ref scope_die
;
20555 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20560 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20561 We need decl DIE for reference and scope die. First, get DIE for the decl
20564 /* Get the scope die for decl context. Use comp_unit_die for global module
20565 or decl. If die is not found for non globals, force new die. */
20567 && TYPE_P (context
)
20568 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20571 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20574 scope_die
= get_context_die (context
);
20578 gcc_assert (scope_die
->die_child
);
20579 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20580 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20581 scope_die
= scope_die
->die_child
;
20584 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20585 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20589 /* Write the debugging output for DECL. */
20592 dwarf2out_decl (tree decl
)
20594 dw_die_ref context_die
;
20596 /* In LIPO mode, we may output some functions whose type is defined
20597 in another function that will not be output. This can result in
20598 undefined location list symbols in the debug type info.
20599 Here we disable the output of the type info for this case.
20600 It is safe since this function and its debug info should never
20602 if (L_IPO_COMP_MODE
)
20604 tree decl_context
, orig_decl
;
20606 decl_context
= DECL_CONTEXT (decl
);
20607 while (decl_context
&&
20608 TREE_CODE (decl_context
) != TRANSLATION_UNIT_DECL
)
20610 struct cgraph_node
*node
;
20612 /* Refer to cgraph_mark_functions_to_output() in cgraphunit.c,
20613 if cgraph_is_aux_decl_external() is true,
20614 this function will not be output in LIPO mode. */
20615 if (TREE_CODE (decl_context
) == FUNCTION_DECL
&&
20616 TREE_PUBLIC (decl_context
) &&
20617 (node
= cgraph_get_node (decl_context
)) &&
20618 cgraph_is_aux_decl_external (node
))
20621 if (TYPE_P (decl_context
))
20623 decl_context
= TYPE_CONTEXT (decl_context
);
20627 orig_decl
= DECL_ORIGIN (decl_context
);
20628 while (orig_decl
!= DECL_ORIGIN (orig_decl
))
20629 orig_decl
= DECL_ORIGIN (orig_decl
);
20631 decl_context
= DECL_CONTEXT (orig_decl
);
20635 context_die
= comp_unit_die ();
20637 switch (TREE_CODE (decl
))
20642 case FUNCTION_DECL
:
20643 /* What we would really like to do here is to filter out all mere
20644 file-scope declarations of file-scope functions which are never
20645 referenced later within this translation unit (and keep all of ones
20646 that *are* referenced later on) but we aren't clairvoyant, so we have
20647 no idea which functions will be referenced in the future (i.e. later
20648 on within the current translation unit). So here we just ignore all
20649 file-scope function declarations which are not also definitions. If
20650 and when the debugger needs to know something about these functions,
20651 it will have to hunt around and find the DWARF information associated
20652 with the definition of the function.
20654 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20655 nodes represent definitions and which ones represent mere
20656 declarations. We have to check DECL_INITIAL instead. That's because
20657 the C front-end supports some weird semantics for "extern inline"
20658 function definitions. These can get inlined within the current
20659 translation unit (and thus, we need to generate Dwarf info for their
20660 abstract instances so that the Dwarf info for the concrete inlined
20661 instances can have something to refer to) but the compiler never
20662 generates any out-of-lines instances of such things (despite the fact
20663 that they *are* definitions).
20665 The important point is that the C front-end marks these "extern
20666 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20667 them anyway. Note that the C++ front-end also plays some similar games
20668 for inline function definitions appearing within include files which
20669 also contain `#pragma interface' pragmas.
20671 If we are called from dwarf2out_abstract_function output a DIE
20672 anyway. We can end up here this way with early inlining and LTO
20673 where the inlined function is output in a different LTRANS unit
20675 if (DECL_INITIAL (decl
) == NULL_TREE
20676 && ! DECL_ABSTRACT (decl
))
20679 /* If we're a nested function, initially use a parent of NULL; if we're
20680 a plain function, this will be fixed up in decls_for_scope. If
20681 we're a method, it will be ignored, since we already have a DIE. */
20682 if (decl_function_context (decl
)
20683 /* But if we're in terse mode, we don't care about scope. */
20684 && debug_info_level
> DINFO_LEVEL_TERSE
)
20685 context_die
= NULL
;
20689 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20690 declaration and if the declaration was never even referenced from
20691 within this entire compilation unit. We suppress these DIEs in
20692 order to save space in the .debug section (by eliminating entries
20693 which are probably useless). Note that we must not suppress
20694 block-local extern declarations (whether used or not) because that
20695 would screw-up the debugger's name lookup mechanism and cause it to
20696 miss things which really ought to be in scope at a given point. */
20697 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20700 /* For local statics lookup proper context die. */
20701 if (TREE_STATIC (decl
)
20702 && DECL_CONTEXT (decl
)
20703 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20704 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20706 /* If we are in terse mode, don't generate any DIEs to represent any
20707 variable declarations or definitions. */
20708 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20713 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20715 if (!is_fortran () && !is_ada ())
20717 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20718 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20721 case NAMESPACE_DECL
:
20722 case IMPORTED_DECL
:
20723 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20725 if (lookup_decl_die (decl
) != NULL
)
20730 /* Don't emit stubs for types unless they are needed by other DIEs. */
20731 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20734 /* Don't bother trying to generate any DIEs to represent any of the
20735 normal built-in types for the language we are compiling. */
20736 if (DECL_IS_BUILTIN (decl
))
20739 /* If we are in terse mode, don't generate any DIEs for types. */
20740 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20743 /* If we're a function-scope tag, initially use a parent of NULL;
20744 this will be fixed up in decls_for_scope. */
20745 if (decl_function_context (decl
))
20746 context_die
= NULL
;
20754 gen_decl_die (decl
, NULL
, context_die
);
20757 /* Write the debugging output for DECL. */
20760 dwarf2out_function_decl (tree decl
)
20762 dwarf2out_decl (decl
);
20763 call_arg_locations
= NULL
;
20764 call_arg_loc_last
= NULL
;
20765 call_site_count
= -1;
20766 tail_call_site_count
= -1;
20767 block_map
.release ();
20768 htab_empty (decl_loc_table
);
20769 htab_empty (cached_dw_loc_list_table
);
20772 /* Output a marker (i.e. a label) for the beginning of the generated code for
20773 a lexical block. */
20776 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20777 unsigned int blocknum
)
20779 switch_to_section (current_function_section ());
20780 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20783 /* Output a marker (i.e. a label) for the end of the generated code for a
20787 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20789 switch_to_section (current_function_section ());
20790 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20793 /* Returns nonzero if it is appropriate not to emit any debugging
20794 information for BLOCK, because it doesn't contain any instructions.
20796 Don't allow this for blocks with nested functions or local classes
20797 as we would end up with orphans, and in the presence of scheduling
20798 we may end up calling them anyway. */
20801 dwarf2out_ignore_block (const_tree block
)
20806 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20807 if (TREE_CODE (decl
) == FUNCTION_DECL
20808 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20810 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20812 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20813 if (TREE_CODE (decl
) == FUNCTION_DECL
20814 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20821 /* Hash table routines for file_hash. */
20824 file_table_eq (const void *p1_p
, const void *p2_p
)
20826 const struct dwarf_file_data
*const p1
=
20827 (const struct dwarf_file_data
*) p1_p
;
20828 const char *const p2
= (const char *) p2_p
;
20829 return filename_cmp (p1
->filename
, p2
) == 0;
20833 file_table_hash (const void *p_p
)
20835 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20836 return htab_hash_string (p
->filename
);
20839 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20840 dwarf2out.c) and return its "index". The index of each (known) filename is
20841 just a unique number which is associated with only that one filename. We
20842 need such numbers for the sake of generating labels (in the .debug_sfnames
20843 section) and references to those files numbers (in the .debug_srcinfo
20844 and.debug_macinfo sections). If the filename given as an argument is not
20845 found in our current list, add it to the list and assign it the next
20846 available unique index number. In order to speed up searches, we remember
20847 the index of the filename was looked up last. This handles the majority of
20850 static struct dwarf_file_data
*
20851 lookup_filename (const char *file_name
)
20854 struct dwarf_file_data
* created
;
20856 /* Check to see if the file name that was searched on the previous
20857 call matches this file name. If so, return the index. */
20858 if (file_table_last_lookup
20859 && (file_name
== file_table_last_lookup
->filename
20860 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20861 return file_table_last_lookup
;
20863 /* Didn't match the previous lookup, search the table. */
20864 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20865 htab_hash_string (file_name
), INSERT
);
20867 return (struct dwarf_file_data
*) *slot
;
20869 created
= ggc_alloc_dwarf_file_data ();
20870 created
->filename
= file_name
;
20871 created
->emitted_number
= 0;
20876 /* If the assembler will construct the file table, then translate the compiler
20877 internal file table number into the assembler file table number, and emit
20878 a .file directive if we haven't already emitted one yet. The file table
20879 numbers are different because we prune debug info for unused variables and
20880 types, which may include filenames. */
20883 maybe_emit_file (struct dwarf_file_data
* fd
)
20885 if (! fd
->emitted_number
)
20887 if (last_emitted_file
)
20888 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20890 fd
->emitted_number
= 1;
20891 last_emitted_file
= fd
;
20893 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20895 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20896 output_quoted_string (asm_out_file
,
20897 remap_debug_filename (fd
->filename
));
20898 fputc ('\n', asm_out_file
);
20902 return fd
->emitted_number
;
20905 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20906 That generation should happen after function debug info has been
20907 generated. The value of the attribute is the constant value of ARG. */
20910 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20912 die_arg_entry entry
;
20917 if (!tmpl_value_parm_die_table
)
20918 vec_alloc (tmpl_value_parm_die_table
, 32);
20922 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20925 /* Return TRUE if T is an instance of generic type, FALSE
20929 generic_type_p (tree t
)
20931 if (t
== NULL_TREE
|| !TYPE_P (t
))
20933 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20936 /* Schedule the generation of the generic parameter dies for the
20937 instance of generic type T. The proper generation itself is later
20938 done by gen_scheduled_generic_parms_dies. */
20941 schedule_generic_params_dies_gen (tree t
)
20943 if (!generic_type_p (t
))
20946 if (!generic_type_instances
)
20947 vec_alloc (generic_type_instances
, 256);
20949 vec_safe_push (generic_type_instances
, t
);
20952 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20953 by append_entry_to_tmpl_value_parm_die_table. This function must
20954 be called after function DIEs have been generated. */
20957 gen_remaining_tmpl_value_param_die_attribute (void)
20959 if (tmpl_value_parm_die_table
)
20964 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20965 tree_add_const_value_attribute (e
->die
, e
->arg
);
20969 /* Generate generic parameters DIEs for instances of generic types
20970 that have been previously scheduled by
20971 schedule_generic_params_dies_gen. This function must be called
20972 after all the types of the CU have been laid out. */
20975 gen_scheduled_generic_parms_dies (void)
20980 if (!generic_type_instances
)
20983 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20984 if (COMPLETE_TYPE_P (t
))
20985 gen_generic_params_dies (t
);
20989 /* Replace DW_AT_name for the decl with name. */
20992 dwarf2out_set_name (tree decl
, tree name
)
20998 die
= TYPE_SYMTAB_DIE (decl
);
21002 dname
= dwarf2_name (name
, 0);
21006 attr
= get_AT (die
, DW_AT_name
);
21009 struct indirect_string_node
*node
;
21011 node
= find_AT_string (dname
);
21012 /* replace the string. */
21013 attr
->dw_attr_val
.v
.val_str
= node
;
21017 add_name_attribute (die
, dname
);
21020 /* True if before or during processing of the first function being emitted. */
21021 static bool in_first_function_p
= true;
21022 /* True if loc_note during dwarf2out_var_location call might still be
21023 before first real instruction at address equal to .Ltext0. */
21024 static bool maybe_at_text_label_p
= true;
21025 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
21026 static unsigned int first_loclabel_num_not_at_text_label
;
21028 /* Called by the final INSN scan whenever we see a var location. We
21029 use it to drop labels in the right places, and throw the location in
21030 our lookup table. */
21033 dwarf2out_var_location (rtx loc_note
)
21035 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
21036 struct var_loc_node
*newloc
;
21037 rtx next_real
, next_note
;
21038 static const char *last_label
;
21039 static const char *last_postcall_label
;
21040 static bool last_in_cold_section_p
;
21041 static rtx expected_next_loc_note
;
21045 if (!NOTE_P (loc_note
))
21047 if (CALL_P (loc_note
))
21050 if (SIBLING_CALL_P (loc_note
))
21051 tail_call_site_count
++;
21056 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
21057 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21060 /* Optimize processing a large consecutive sequence of location
21061 notes so we don't spend too much time in next_real_insn. If the
21062 next insn is another location note, remember the next_real_insn
21063 calculation for next time. */
21064 next_real
= cached_next_real_insn
;
21067 if (expected_next_loc_note
!= loc_note
)
21068 next_real
= NULL_RTX
;
21071 next_note
= NEXT_INSN (loc_note
);
21073 || INSN_DELETED_P (next_note
)
21074 || GET_CODE (next_note
) != NOTE
21075 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
21076 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
21077 next_note
= NULL_RTX
;
21080 next_real
= next_real_insn (loc_note
);
21084 expected_next_loc_note
= next_note
;
21085 cached_next_real_insn
= next_real
;
21088 cached_next_real_insn
= NULL_RTX
;
21090 /* If there are no instructions which would be affected by this note,
21091 don't do anything. */
21093 && next_real
== NULL_RTX
21094 && !NOTE_DURING_CALL_P (loc_note
))
21097 if (next_real
== NULL_RTX
)
21098 next_real
= get_last_insn ();
21100 /* If there were any real insns between note we processed last time
21101 and this note (or if it is the first note), clear
21102 last_{,postcall_}label so that they are not reused this time. */
21103 if (last_var_location_insn
== NULL_RTX
21104 || last_var_location_insn
!= next_real
21105 || last_in_cold_section_p
!= in_cold_section_p
)
21108 last_postcall_label
= NULL
;
21113 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21114 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21115 NOTE_DURING_CALL_P (loc_note
)
21116 ? last_postcall_label
: last_label
);
21117 if (newloc
== NULL
)
21126 /* If there were no real insns between note we processed last time
21127 and this note, use the label we emitted last time. Otherwise
21128 create a new label and emit it. */
21129 if (last_label
== NULL
)
21131 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21132 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21134 last_label
= ggc_strdup (loclabel
);
21135 /* See if loclabel might be equal to .Ltext0. If yes,
21136 bump first_loclabel_num_not_at_text_label. */
21137 if (!have_multiple_function_sections
21138 && in_first_function_p
21139 && maybe_at_text_label_p
)
21141 static rtx last_start
;
21143 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
21144 if (insn
== last_start
)
21146 else if (!NONDEBUG_INSN_P (insn
))
21150 rtx body
= PATTERN (insn
);
21151 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
21153 /* Inline asm could occupy zero bytes. */
21154 else if (GET_CODE (body
) == ASM_INPUT
21155 || asm_noperands (body
) >= 0)
21157 #ifdef HAVE_attr_length
21158 else if (get_attr_min_length (insn
) == 0)
21163 /* Assume insn has non-zero length. */
21164 maybe_at_text_label_p
= false;
21168 if (maybe_at_text_label_p
)
21170 last_start
= loc_note
;
21171 first_loclabel_num_not_at_text_label
= loclabel_num
;
21178 struct call_arg_loc_node
*ca_loc
21179 = ggc_alloc_cleared_call_arg_loc_node ();
21180 rtx prev
= prev_real_insn (loc_note
), x
;
21181 ca_loc
->call_arg_loc_note
= loc_note
;
21182 ca_loc
->next
= NULL
;
21183 ca_loc
->label
= last_label
;
21186 || (NONJUMP_INSN_P (prev
)
21187 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21188 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21189 if (!CALL_P (prev
))
21190 prev
= XVECEXP (PATTERN (prev
), 0, 0);
21191 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
21192 x
= get_call_rtx_from (PATTERN (prev
));
21195 x
= XEXP (XEXP (x
, 0), 0);
21196 if (GET_CODE (x
) == SYMBOL_REF
21197 && SYMBOL_REF_DECL (x
)
21198 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21199 ca_loc
->symbol_ref
= x
;
21201 ca_loc
->block
= insn_scope (prev
);
21202 if (call_arg_locations
)
21203 call_arg_loc_last
->next
= ca_loc
;
21205 call_arg_locations
= ca_loc
;
21206 call_arg_loc_last
= ca_loc
;
21208 else if (!NOTE_DURING_CALL_P (loc_note
))
21209 newloc
->label
= last_label
;
21212 if (!last_postcall_label
)
21214 sprintf (loclabel
, "%s-1", last_label
);
21215 last_postcall_label
= ggc_strdup (loclabel
);
21217 newloc
->label
= last_postcall_label
;
21220 last_var_location_insn
= next_real
;
21221 last_in_cold_section_p
= in_cold_section_p
;
21224 /* Note in one location list that text section has changed. */
21227 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
21229 var_loc_list
*list
= (var_loc_list
*) *slot
;
21231 list
->last_before_switch
21232 = list
->last
->next
? list
->last
->next
: list
->last
;
21236 /* Note in all location lists that text section has changed. */
21239 var_location_switch_text_section (void)
21241 if (decl_loc_table
== NULL
)
21244 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
21247 /* Create a new line number table. */
21249 static dw_line_info_table
*
21250 new_line_info_table (void)
21252 dw_line_info_table
*table
;
21254 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
21255 table
->file_num
= 1;
21256 table
->line_num
= 1;
21257 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21262 /* Lookup the "current" table into which we emit line info, so
21263 that we don't have to do it for every source line. */
21266 set_cur_line_info_table (section
*sec
)
21268 dw_line_info_table
*table
;
21270 if (sec
== text_section
)
21271 table
= text_section_line_info
;
21272 else if (sec
== cold_text_section
)
21274 table
= cold_text_section_line_info
;
21277 cold_text_section_line_info
= table
= new_line_info_table ();
21278 table
->end_label
= cold_end_label
;
21283 const char *end_label
;
21285 if (flag_reorder_blocks_and_partition
)
21287 if (in_cold_section_p
)
21288 end_label
= crtl
->subsections
.cold_section_end_label
;
21290 end_label
= crtl
->subsections
.hot_section_end_label
;
21294 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21295 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21296 FUNC_LABEL_ID (cfun
));
21297 end_label
= ggc_strdup (label
);
21300 table
= new_line_info_table ();
21301 table
->end_label
= end_label
;
21303 vec_safe_push (separate_line_info
, table
);
21306 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21307 table
->is_stmt
= (cur_line_info_table
21308 ? cur_line_info_table
->is_stmt
21309 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21310 cur_line_info_table
= table
;
21314 /* We need to reset the locations at the beginning of each
21315 function. We can't do this in the end_function hook, because the
21316 declarations that use the locations won't have been output when
21317 that hook is called. Also compute have_multiple_function_sections here. */
21320 dwarf2out_begin_function (tree fun
)
21322 section
*sec
= function_section (fun
);
21324 if (sec
!= text_section
)
21325 have_multiple_function_sections
= true;
21327 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21329 gcc_assert (current_function_decl
== fun
);
21330 cold_text_section
= unlikely_text_section ();
21331 switch_to_section (cold_text_section
);
21332 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21333 switch_to_section (sec
);
21336 dwarf2out_note_section_used ();
21337 call_site_count
= 0;
21338 tail_call_site_count
= 0;
21340 set_cur_line_info_table (sec
);
21343 /* Helper function of dwarf2out_end_function, called only after emitting
21344 the very first function into assembly. Check if some .debug_loc range
21345 might end with a .LVL* label that could be equal to .Ltext0.
21346 In that case we must force using absolute addresses in .debug_loc ranges,
21347 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21348 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21350 Set have_multiple_function_sections to true in that case and
21351 terminate htab traversal. */
21354 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21356 var_loc_list
*entry
;
21357 struct var_loc_node
*node
;
21359 entry
= (var_loc_list
*) *slot
;
21360 node
= entry
->first
;
21361 if (node
&& node
->next
&& node
->next
->label
)
21364 const char *label
= node
->next
->label
;
21365 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21367 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21369 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21370 if (strcmp (label
, loclabel
) == 0)
21372 have_multiple_function_sections
= true;
21380 /* Hook called after emitting a function into assembly.
21381 This does something only for the very first function emitted. */
21384 dwarf2out_end_function (unsigned int)
21386 if (in_first_function_p
21387 && !have_multiple_function_sections
21388 && first_loclabel_num_not_at_text_label
21390 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21392 in_first_function_p
= false;
21393 maybe_at_text_label_p
= false;
21396 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21399 push_dw_line_info_entry (dw_line_info_table
*table
,
21400 enum dw_line_info_opcode opcode
, unsigned int val
)
21402 dw_line_info_entry e
;
21405 vec_safe_push (table
->entries
, e
);
21408 /* Output a label to mark the beginning of a source code line entry
21409 and record information relating to this source line, in
21410 'line_info_table' for later output of the .debug_line section. */
21411 /* ??? The discriminator parameter ought to be unsigned. */
21414 dwarf2out_source_line (unsigned int line
, const char *filename
,
21415 int discriminator
, bool is_stmt
)
21417 unsigned int file_num
;
21418 dw_line_info_table
*table
;
21420 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
21423 /* The discriminator column was added in dwarf4. Simplify the below
21424 by simply removing it if we're not supposed to output it. */
21425 if (dwarf_version
< 4 && dwarf_strict
)
21428 table
= cur_line_info_table
;
21429 file_num
= maybe_emit_file (lookup_filename (filename
));
21431 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21432 the debugger has used the second (possibly duplicate) line number
21433 at the beginning of the function to mark the end of the prologue.
21434 We could eliminate any other duplicates within the function. For
21435 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21436 that second line number entry. */
21437 /* Recall that this end-of-prologue indication is *not* the same thing
21438 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21439 to which the hook corresponds, follows the last insn that was
21440 emitted by gen_prologue. What we need is to precede the first insn
21441 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21442 insn that corresponds to something the user wrote. These may be
21443 very different locations once scheduling is enabled. */
21445 if (0 && file_num
== table
->file_num
21446 && line
== table
->line_num
21447 && discriminator
== table
->discrim_num
21448 && is_stmt
== table
->is_stmt
)
21451 switch_to_section (current_function_section ());
21453 /* If requested, emit something human-readable. */
21454 if (flag_debug_asm
)
21455 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21457 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21459 /* Emit the .loc directive understood by GNU as. */
21460 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21461 file_num, line, is_stmt, discriminator */
21462 fputs ("\t.loc ", asm_out_file
);
21463 fprint_ul (asm_out_file
, file_num
);
21464 putc (' ', asm_out_file
);
21465 fprint_ul (asm_out_file
, line
);
21466 putc (' ', asm_out_file
);
21467 putc ('0', asm_out_file
);
21469 if (is_stmt
!= table
->is_stmt
)
21471 fputs (" is_stmt ", asm_out_file
);
21472 putc (is_stmt
? '1' : '0', asm_out_file
);
21474 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21476 gcc_assert (discriminator
> 0);
21477 fputs (" discriminator ", asm_out_file
);
21478 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21480 putc ('\n', asm_out_file
);
21484 unsigned int label_num
= ++line_info_label_num
;
21486 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21488 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21489 if (file_num
!= table
->file_num
)
21490 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21491 if (discriminator
!= table
->discrim_num
)
21492 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21493 if (is_stmt
!= table
->is_stmt
)
21494 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21495 push_dw_line_info_entry (table
, LI_set_line
, line
);
21498 table
->file_num
= file_num
;
21499 table
->line_num
= line
;
21500 table
->discrim_num
= discriminator
;
21501 table
->is_stmt
= is_stmt
;
21502 table
->in_use
= true;
21505 /* Record the beginning of a new source file. */
21508 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21510 if (flag_eliminate_dwarf2_dups
)
21512 /* Record the beginning of the file for break_out_includes. */
21513 dw_die_ref bincl_die
;
21515 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21516 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21519 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21522 e
.code
= DW_MACINFO_start_file
;
21524 e
.info
= ggc_strdup (filename
);
21525 vec_safe_push (macinfo_table
, e
);
21529 /* Record the end of a source file. */
21532 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21534 if (flag_eliminate_dwarf2_dups
)
21535 /* Record the end of the file for break_out_includes. */
21536 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21538 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21541 e
.code
= DW_MACINFO_end_file
;
21544 vec_safe_push (macinfo_table
, e
);
21548 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21549 the tail part of the directive line, i.e. the part which is past the
21550 initial whitespace, #, whitespace, directive-name, whitespace part. */
21553 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21554 const char *buffer ATTRIBUTE_UNUSED
)
21556 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21559 /* Insert a dummy first entry to be able to optimize the whole
21560 predefined macro block using DW_MACRO_GNU_transparent_include. */
21561 if (macinfo_table
->is_empty () && lineno
<= 1)
21566 vec_safe_push (macinfo_table
, e
);
21568 e
.code
= DW_MACINFO_define
;
21570 e
.info
= ggc_strdup (buffer
);
21571 vec_safe_push (macinfo_table
, e
);
21575 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21576 the tail part of the directive line, i.e. the part which is past the
21577 initial whitespace, #, whitespace, directive-name, whitespace part. */
21580 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21581 const char *buffer ATTRIBUTE_UNUSED
)
21583 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21586 /* Insert a dummy first entry to be able to optimize the whole
21587 predefined macro block using DW_MACRO_GNU_transparent_include. */
21588 if (macinfo_table
->is_empty () && lineno
<= 1)
21593 vec_safe_push (macinfo_table
, e
);
21595 e
.code
= DW_MACINFO_undef
;
21597 e
.info
= ggc_strdup (buffer
);
21598 vec_safe_push (macinfo_table
, e
);
21602 /* Routines to manipulate hash table of CUs. */
21605 htab_macinfo_hash (const void *of
)
21607 const macinfo_entry
*const entry
=
21608 (const macinfo_entry
*) of
;
21610 return htab_hash_string (entry
->info
);
21614 htab_macinfo_eq (const void *of1
, const void *of2
)
21616 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
21617 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
21619 return !strcmp (entry1
->info
, entry2
->info
);
21622 /* Output a single .debug_macinfo entry. */
21625 output_macinfo_op (macinfo_entry
*ref
)
21629 struct indirect_string_node
*node
;
21630 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21631 struct dwarf_file_data
*fd
;
21635 case DW_MACINFO_start_file
:
21636 fd
= lookup_filename (ref
->info
);
21637 file_num
= maybe_emit_file (fd
);
21638 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21639 dw2_asm_output_data_uleb128 (ref
->lineno
,
21640 "Included from line number %lu",
21641 (unsigned long) ref
->lineno
);
21642 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21644 case DW_MACINFO_end_file
:
21645 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21647 case DW_MACINFO_define
:
21648 case DW_MACINFO_undef
:
21649 len
= strlen (ref
->info
) + 1;
21651 && len
> DWARF_OFFSET_SIZE
21652 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21653 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21655 ref
->code
= ref
->code
== DW_MACINFO_define
21656 ? DW_MACRO_GNU_define_indirect
21657 : DW_MACRO_GNU_undef_indirect
;
21658 output_macinfo_op (ref
);
21661 dw2_asm_output_data (1, ref
->code
,
21662 ref
->code
== DW_MACINFO_define
21663 ? "Define macro" : "Undefine macro");
21664 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21665 (unsigned long) ref
->lineno
);
21666 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21668 case DW_MACRO_GNU_define_indirect
:
21669 case DW_MACRO_GNU_undef_indirect
:
21670 node
= find_AT_string (ref
->info
);
21672 && ((node
->form
== DW_FORM_strp
)
21673 || (node
->form
== DW_FORM_GNU_str_index
)));
21674 dw2_asm_output_data (1, ref
->code
,
21675 ref
->code
== DW_MACRO_GNU_define_indirect
21676 ? "Define macro indirect"
21677 : "Undefine macro indirect");
21678 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21679 (unsigned long) ref
->lineno
);
21680 if (node
->form
== DW_FORM_strp
)
21681 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21682 debug_str_section
, "The macro: \"%s\"",
21685 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21688 case DW_MACRO_GNU_transparent_include
:
21689 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21690 ASM_GENERATE_INTERNAL_LABEL (label
,
21691 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21692 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21695 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21696 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21701 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21702 other compilation unit .debug_macinfo sections. IDX is the first
21703 index of a define/undef, return the number of ops that should be
21704 emitted in a comdat .debug_macinfo section and emit
21705 a DW_MACRO_GNU_transparent_include entry referencing it.
21706 If the define/undef entry should be emitted normally, return 0. */
21709 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21710 htab_t
*macinfo_htab
)
21712 macinfo_entry
*first
, *second
, *cur
, *inc
;
21713 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21714 unsigned char checksum
[16];
21715 struct md5_ctx ctx
;
21716 char *grp_name
, *tail
;
21718 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21721 first
= &(*macinfo_table
)[idx
];
21722 second
= &(*macinfo_table
)[idx
+ 1];
21724 /* Optimize only if there are at least two consecutive define/undef ops,
21725 and either all of them are before first DW_MACINFO_start_file
21726 with lineno {0,1} (i.e. predefined macro block), or all of them are
21727 in some included header file. */
21728 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21730 if (vec_safe_is_empty (files
))
21732 if (first
->lineno
> 1 || second
->lineno
> 1)
21735 else if (first
->lineno
== 0)
21738 /* Find the last define/undef entry that can be grouped together
21739 with first and at the same time compute md5 checksum of their
21740 codes, linenumbers and strings. */
21741 md5_init_ctx (&ctx
);
21742 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21743 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21745 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21749 unsigned char code
= cur
->code
;
21750 md5_process_bytes (&code
, 1, &ctx
);
21751 checksum_uleb128 (cur
->lineno
, &ctx
);
21752 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21754 md5_finish_ctx (&ctx
, checksum
);
21757 /* From the containing include filename (if any) pick up just
21758 usable characters from its basename. */
21759 if (vec_safe_is_empty (files
))
21762 base
= lbasename (files
->last ().info
);
21763 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21764 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21765 encoded_filename_len
++;
21766 /* Count . at the end. */
21767 if (encoded_filename_len
)
21768 encoded_filename_len
++;
21770 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21771 linebuf_len
= strlen (linebuf
);
21773 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21774 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21776 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21777 tail
= grp_name
+ 4;
21778 if (encoded_filename_len
)
21780 for (i
= 0; base
[i
]; i
++)
21781 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21785 memcpy (tail
, linebuf
, linebuf_len
);
21786 tail
+= linebuf_len
;
21788 for (i
= 0; i
< 16; i
++)
21789 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21791 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21792 in the empty vector entry before the first define/undef. */
21793 inc
= &(*macinfo_table
)[idx
- 1];
21794 inc
->code
= DW_MACRO_GNU_transparent_include
;
21796 inc
->info
= ggc_strdup (grp_name
);
21797 if (*macinfo_htab
== NULL
)
21798 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
21799 /* Avoid emitting duplicates. */
21800 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
21805 /* If such an entry has been used before, just emit
21806 a DW_MACRO_GNU_transparent_include op. */
21807 inc
= (macinfo_entry
*) *slot
;
21808 output_macinfo_op (inc
);
21809 /* And clear all macinfo_entry in the range to avoid emitting them
21810 in the second pass. */
21811 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21820 inc
->lineno
= htab_elements (*macinfo_htab
);
21821 output_macinfo_op (inc
);
21826 /* Save any strings needed by the macinfo table in the debug str
21827 table. All strings must be collected into the table by the time
21828 index_string is called. */
21831 save_macinfo_strings (void)
21835 macinfo_entry
*ref
;
21837 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21841 /* Match the logic in output_macinfo_op to decide on
21842 indirect strings. */
21843 case DW_MACINFO_define
:
21844 case DW_MACINFO_undef
:
21845 len
= strlen (ref
->info
) + 1;
21847 && len
> DWARF_OFFSET_SIZE
21848 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21849 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21850 set_indirect_string (find_AT_string (ref
->info
));
21852 case DW_MACRO_GNU_define_indirect
:
21853 case DW_MACRO_GNU_undef_indirect
:
21854 set_indirect_string (find_AT_string (ref
->info
));
21862 /* Output macinfo section(s). */
21865 output_macinfo (void)
21868 unsigned long length
= vec_safe_length (macinfo_table
);
21869 macinfo_entry
*ref
;
21870 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21871 htab_t macinfo_htab
= NULL
;
21876 /* output_macinfo* uses these interchangeably. */
21877 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21878 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21879 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21880 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21882 /* For .debug_macro emit the section header. */
21885 dw2_asm_output_data (2, 4, "DWARF macro version number");
21886 if (DWARF_OFFSET_SIZE
== 8)
21887 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21889 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21890 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21891 (!dwarf_split_debug_info
? debug_line_section_label
21892 : debug_skeleton_line_section_label
),
21893 debug_line_section
, NULL
);
21896 /* In the first loop, it emits the primary .debug_macinfo section
21897 and after each emitted op the macinfo_entry is cleared.
21898 If a longer range of define/undef ops can be optimized using
21899 DW_MACRO_GNU_transparent_include, the
21900 DW_MACRO_GNU_transparent_include op is emitted and kept in
21901 the vector before the first define/undef in the range and the
21902 whole range of define/undef ops is not emitted and kept. */
21903 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21907 case DW_MACINFO_start_file
:
21908 vec_safe_push (files
, *ref
);
21910 case DW_MACINFO_end_file
:
21911 if (!vec_safe_is_empty (files
))
21914 case DW_MACINFO_define
:
21915 case DW_MACINFO_undef
:
21917 && HAVE_COMDAT_GROUP
21918 && vec_safe_length (files
) != 1
21921 && (*macinfo_table
)[i
- 1].code
== 0)
21923 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21932 /* A dummy entry may be inserted at the beginning to be able
21933 to optimize the whole block of predefined macros. */
21939 output_macinfo_op (ref
);
21944 if (macinfo_htab
== NULL
)
21947 htab_delete (macinfo_htab
);
21949 /* If any DW_MACRO_GNU_transparent_include were used, on those
21950 DW_MACRO_GNU_transparent_include entries terminate the
21951 current chain and switch to a new comdat .debug_macinfo
21952 section and emit the define/undef entries within it. */
21953 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21958 case DW_MACRO_GNU_transparent_include
:
21960 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21961 tree comdat_key
= get_identifier (ref
->info
);
21962 /* Terminate the previous .debug_macinfo section. */
21963 dw2_asm_output_data (1, 0, "End compilation unit");
21964 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21966 | SECTION_LINKONCE
,
21968 ASM_GENERATE_INTERNAL_LABEL (label
,
21969 DEBUG_MACRO_SECTION_LABEL
,
21971 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21974 dw2_asm_output_data (2, 4, "DWARF macro version number");
21975 if (DWARF_OFFSET_SIZE
== 8)
21976 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21978 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21981 case DW_MACINFO_define
:
21982 case DW_MACINFO_undef
:
21983 output_macinfo_op (ref
);
21988 gcc_unreachable ();
21992 /* Set up for Dwarf output at the start of compilation. */
21995 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21997 /* Allocate the file_table. */
21998 file_table
= htab_create_ggc (50, file_table_hash
,
21999 file_table_eq
, NULL
);
22001 /* Allocate the decl_die_table. */
22002 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
22003 decl_die_table_eq
, NULL
);
22005 /* Allocate the decl_loc_table. */
22006 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
22007 decl_loc_table_eq
, NULL
);
22009 /* Allocate the cached_dw_loc_list_table. */
22010 cached_dw_loc_list_table
22011 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
22012 cached_dw_loc_list_table_eq
, NULL
);
22014 /* Allocate the initial hunk of the decl_scope_table. */
22015 vec_alloc (decl_scope_table
, 256);
22017 /* Allocate the initial hunk of the abbrev_die_table. */
22018 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
22019 (ABBREV_DIE_TABLE_INCREMENT
);
22020 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
22021 /* Zero-th entry is allocated, but unused. */
22022 abbrev_die_table_in_use
= 1;
22024 /* Allocate the pubtypes and pubnames vectors. */
22025 vec_alloc (pubname_table
, 32);
22026 vec_alloc (pubtype_table
, 32);
22028 vec_alloc (incomplete_types
, 64);
22030 vec_alloc (used_rtx_array
, 32);
22032 if (!dwarf_split_debug_info
)
22034 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
22035 SECTION_DEBUG
, NULL
);
22036 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22037 SECTION_DEBUG
, NULL
);
22038 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
22039 SECTION_DEBUG
, NULL
);
22043 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
22044 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22045 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
22046 SECTION_DEBUG
| SECTION_EXCLUDE
,
22048 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
22049 SECTION_DEBUG
, NULL
);
22050 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
22051 SECTION_DEBUG
, NULL
);
22052 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22053 SECTION_DEBUG
, NULL
);
22054 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
22055 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
22057 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
22058 the main .o, but the skeleton_line goes into the split off dwo. */
22059 debug_skeleton_line_section
22060 = get_section (DEBUG_DWO_LINE_SECTION
,
22061 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22062 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
22063 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
22064 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
22065 SECTION_DEBUG
| SECTION_EXCLUDE
,
22067 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
22068 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
22069 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
22070 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22071 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
22072 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
22074 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
22075 SECTION_DEBUG
, NULL
);
22076 debug_macinfo_section
= get_section (dwarf_strict
22077 ? DEBUG_MACINFO_SECTION
22078 : DEBUG_MACRO_SECTION
,
22079 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
22080 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
22081 SECTION_DEBUG
, NULL
);
22082 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
22083 SECTION_DEBUG
, NULL
);
22084 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
22085 SECTION_DEBUG
, NULL
);
22086 debug_str_section
= get_section (DEBUG_STR_SECTION
,
22087 DEBUG_STR_SECTION_FLAGS
, NULL
);
22088 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
22089 SECTION_DEBUG
, NULL
);
22090 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
22091 SECTION_DEBUG
, NULL
);
22093 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
22094 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
22095 DEBUG_ABBREV_SECTION_LABEL
, 0);
22096 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
22097 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
22098 COLD_TEXT_SECTION_LABEL
, 0);
22099 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
22101 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
22102 DEBUG_INFO_SECTION_LABEL
, 0);
22103 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
22104 DEBUG_LINE_SECTION_LABEL
, 0);
22105 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
22106 DEBUG_RANGES_SECTION_LABEL
, 0);
22107 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
22108 DEBUG_ADDR_SECTION_LABEL
, 0);
22109 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
22111 ? DEBUG_MACINFO_SECTION_LABEL
22112 : DEBUG_MACRO_SECTION_LABEL
, 0);
22113 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
22115 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22116 vec_alloc (macinfo_table
, 64);
22118 switch_to_section (text_section
);
22119 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
22121 /* Make sure the line number table for .text always exists. */
22122 text_section_line_info
= new_line_info_table ();
22123 text_section_line_info
->end_label
= text_end_label
;
22126 /* Called before compile () starts outputtting functions, variables
22127 and toplevel asms into assembly. */
22130 dwarf2out_assembly_start (void)
22132 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22133 && dwarf2out_do_cfi_asm ()
22134 && (!(flag_unwind_tables
|| flag_exceptions
)
22135 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
22136 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
22139 /* A helper function for dwarf2out_finish called through
22140 htab_traverse. Assign a string its index. All strings must be
22141 collected into the table by the time index_string is called,
22142 because the indexing code relies on htab_traverse to traverse nodes
22143 in the same order for each run. */
22146 index_string (void **h
, void *v
)
22148 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22149 unsigned int *index
= (unsigned int *) v
;
22151 find_string_form (node
);
22152 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22154 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
22155 node
->index
= *index
;
22161 /* A helper function for output_indirect_strings called through
22162 htab_traverse. Output the offset to a string and update the
22166 output_index_string_offset (void **h
, void *v
)
22168 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22169 unsigned int *offset
= (unsigned int *) v
;
22171 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22173 /* Assert that this node has been assigned an index. */
22174 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
22175 && node
->index
!= NOT_INDEXED
);
22176 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
22177 "indexed string 0x%x: %s", node
->index
, node
->str
);
22178 *offset
+= strlen (node
->str
) + 1;
22183 /* A helper function for dwarf2out_finish called through
22184 htab_traverse. Output the indexed string. */
22187 output_index_string (void **h
, void *v
)
22189 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22190 unsigned int *cur_idx
= (unsigned int *) v
;
22192 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22194 /* Assert that the strings are output in the same order as their
22195 indexes were assigned. */
22196 gcc_assert (*cur_idx
== node
->index
);
22197 assemble_string (node
->str
, strlen (node
->str
) + 1);
22203 /* A helper function for dwarf2out_finish called through
22204 htab_traverse. Emit one queued .debug_str string. */
22207 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22209 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22211 node
->form
= find_string_form (node
);
22212 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22214 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22215 assemble_string (node
->str
, strlen (node
->str
) + 1);
22221 /* Output the indexed string table. */
22224 output_indirect_strings (void)
22226 switch_to_section (debug_str_section
);
22227 if (!dwarf_split_debug_info
)
22228 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22231 unsigned int offset
= 0;
22232 unsigned int cur_idx
= 0;
22234 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
22236 switch_to_section (debug_str_offsets_section
);
22237 htab_traverse_noresize (debug_str_hash
,
22238 output_index_string_offset
,
22240 switch_to_section (debug_str_dwo_section
);
22241 htab_traverse_noresize (debug_str_hash
,
22242 output_index_string
,
22247 /* Callback for htab_traverse to assign an index to an entry in the
22248 table, and to write that entry to the .debug_addr section. */
22251 output_addr_table_entry (void **slot
, void *data
)
22253 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22254 unsigned int *cur_index
= (unsigned int *)data
;
22256 if (entry
->refcount
== 0)
22258 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22259 || entry
->index
== NOT_INDEXED
);
22263 gcc_assert (entry
->index
== *cur_index
);
22266 switch (entry
->kind
)
22269 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22270 "0x%x", entry
->index
);
22272 case ate_kind_rtx_dtprel
:
22273 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22274 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22277 fputc ('\n', asm_out_file
);
22279 case ate_kind_label
:
22280 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22281 "0x%x", entry
->index
);
22284 gcc_unreachable ();
22289 /* Produce the .debug_addr section. */
22292 output_addr_table (void)
22294 unsigned int index
= 0;
22295 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22298 switch_to_section (debug_addr_section
);
22299 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22302 #if ENABLE_ASSERT_CHECKING
22303 /* Verify that all marks are clear. */
22306 verify_marks_clear (dw_die_ref die
)
22310 gcc_assert (! die
->die_mark
);
22311 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22313 #endif /* ENABLE_ASSERT_CHECKING */
22315 /* Clear the marks for a die and its children.
22316 Be cool if the mark isn't set. */
22319 prune_unmark_dies (dw_die_ref die
)
22325 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22328 /* Given DIE that we're marking as used, find any other dies
22329 it references as attributes and mark them as used. */
22332 prune_unused_types_walk_attribs (dw_die_ref die
)
22337 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22339 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22341 /* A reference to another DIE.
22342 Make sure that it will get emitted.
22343 If it was broken out into a comdat group, don't follow it. */
22344 if (! AT_ref (a
)->comdat_type_p
22345 || a
->dw_attr
== DW_AT_specification
)
22346 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22348 /* Set the string's refcount to 0 so that prune_unused_types_mark
22349 accounts properly for it. */
22350 if (AT_class (a
) == dw_val_class_str
)
22351 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22355 /* Mark the generic parameters and arguments children DIEs of DIE. */
22358 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22362 if (die
== NULL
|| die
->die_child
== NULL
)
22364 c
= die
->die_child
;
22367 if (is_template_parameter (c
))
22368 prune_unused_types_mark (c
, 1);
22370 } while (c
&& c
!= die
->die_child
);
22373 /* Mark DIE as being used. If DOKIDS is true, then walk down
22374 to DIE's children. */
22377 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22381 if (die
->die_mark
== 0)
22383 /* We haven't done this node yet. Mark it as used. */
22385 /* If this is the DIE of a generic type instantiation,
22386 mark the children DIEs that describe its generic parms and
22388 prune_unused_types_mark_generic_parms_dies (die
);
22390 /* We also have to mark its parents as used.
22391 (But we don't want to mark our parent's kids due to this,
22392 unless it is a class.) */
22393 if (die
->die_parent
)
22394 prune_unused_types_mark (die
->die_parent
,
22395 class_scope_p (die
->die_parent
));
22397 /* Mark any referenced nodes. */
22398 prune_unused_types_walk_attribs (die
);
22400 /* If this node is a specification,
22401 also mark the definition, if it exists. */
22402 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22403 prune_unused_types_mark (die
->die_definition
, 1);
22406 if (dokids
&& die
->die_mark
!= 2)
22408 /* We need to walk the children, but haven't done so yet.
22409 Remember that we've walked the kids. */
22412 /* If this is an array type, we need to make sure our
22413 kids get marked, even if they're types. If we're
22414 breaking out types into comdat sections, do this
22415 for all type definitions. */
22416 if (die
->die_tag
== DW_TAG_array_type
22417 || (use_debug_types
22418 && is_type_die (die
) && ! is_declaration_die (die
)))
22419 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22421 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22425 /* For local classes, look if any static member functions were emitted
22426 and if so, mark them. */
22429 prune_unused_types_walk_local_classes (dw_die_ref die
)
22433 if (die
->die_mark
== 2)
22436 switch (die
->die_tag
)
22438 case DW_TAG_structure_type
:
22439 case DW_TAG_union_type
:
22440 case DW_TAG_class_type
:
22443 case DW_TAG_subprogram
:
22444 if (!get_AT_flag (die
, DW_AT_declaration
)
22445 || die
->die_definition
!= NULL
)
22446 prune_unused_types_mark (die
, 1);
22453 /* Mark children. */
22454 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22457 /* Walk the tree DIE and mark types that we actually use. */
22460 prune_unused_types_walk (dw_die_ref die
)
22464 /* Don't do anything if this node is already marked and
22465 children have been marked as well. */
22466 if (die
->die_mark
== 2)
22469 switch (die
->die_tag
)
22471 case DW_TAG_structure_type
:
22472 case DW_TAG_union_type
:
22473 case DW_TAG_class_type
:
22474 if (die
->die_perennial_p
)
22477 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22478 if (c
->die_tag
== DW_TAG_subprogram
)
22481 /* Finding used static member functions inside of classes
22482 is needed just for local classes, because for other classes
22483 static member function DIEs with DW_AT_specification
22484 are emitted outside of the DW_TAG_*_type. If we ever change
22485 it, we'd need to call this even for non-local classes. */
22487 prune_unused_types_walk_local_classes (die
);
22489 /* It's a type node --- don't mark it. */
22492 case DW_TAG_const_type
:
22493 case DW_TAG_packed_type
:
22494 case DW_TAG_pointer_type
:
22495 case DW_TAG_reference_type
:
22496 case DW_TAG_rvalue_reference_type
:
22497 case DW_TAG_volatile_type
:
22498 case DW_TAG_typedef
:
22499 case DW_TAG_array_type
:
22500 case DW_TAG_interface_type
:
22501 case DW_TAG_friend
:
22502 case DW_TAG_variant_part
:
22503 case DW_TAG_enumeration_type
:
22504 case DW_TAG_subroutine_type
:
22505 case DW_TAG_string_type
:
22506 case DW_TAG_set_type
:
22507 case DW_TAG_subrange_type
:
22508 case DW_TAG_ptr_to_member_type
:
22509 case DW_TAG_file_type
:
22510 if (die
->die_perennial_p
)
22513 /* It's a type node --- don't mark it. */
22517 /* Mark everything else. */
22521 if (die
->die_mark
== 0)
22525 /* Now, mark any dies referenced from here. */
22526 prune_unused_types_walk_attribs (die
);
22531 /* Mark children. */
22532 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22535 /* Increment the string counts on strings referred to from DIE's
22539 prune_unused_types_update_strings (dw_die_ref die
)
22544 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22545 if (AT_class (a
) == dw_val_class_str
)
22547 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22549 /* Avoid unnecessarily putting strings that are used less than
22550 twice in the hash table. */
22552 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22555 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22556 htab_hash_string (s
->str
),
22558 gcc_assert (*slot
== NULL
);
22564 /* Remove from the tree DIE any dies that aren't marked. */
22567 prune_unused_types_prune (dw_die_ref die
)
22571 gcc_assert (die
->die_mark
);
22572 prune_unused_types_update_strings (die
);
22574 if (! die
->die_child
)
22577 c
= die
->die_child
;
22579 dw_die_ref prev
= c
;
22580 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22581 if (c
== die
->die_child
)
22583 /* No marked children between 'prev' and the end of the list. */
22585 /* No marked children at all. */
22586 die
->die_child
= NULL
;
22589 prev
->die_sib
= c
->die_sib
;
22590 die
->die_child
= prev
;
22595 if (c
!= prev
->die_sib
)
22597 prune_unused_types_prune (c
);
22598 } while (c
!= die
->die_child
);
22601 /* Remove dies representing declarations that we never use. */
22604 prune_unused_types (void)
22607 limbo_die_node
*node
;
22608 comdat_type_node
*ctnode
;
22610 dw_die_ref base_type
;
22612 #if ENABLE_ASSERT_CHECKING
22613 /* All the marks should already be clear. */
22614 verify_marks_clear (comp_unit_die ());
22615 for (node
= limbo_die_list
; node
; node
= node
->next
)
22616 verify_marks_clear (node
->die
);
22617 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22618 verify_marks_clear (ctnode
->root_die
);
22619 #endif /* ENABLE_ASSERT_CHECKING */
22621 /* Mark types that are used in global variables. */
22622 premark_types_used_by_global_vars ();
22624 /* Set the mark on nodes that are actually used. */
22625 prune_unused_types_walk (comp_unit_die ());
22626 for (node
= limbo_die_list
; node
; node
= node
->next
)
22627 prune_unused_types_walk (node
->die
);
22628 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22630 prune_unused_types_walk (ctnode
->root_die
);
22631 prune_unused_types_mark (ctnode
->type_die
, 1);
22634 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22635 are unusual in that they are pubnames that are the children of pubtypes.
22636 They should only be marked via their parent DW_TAG_enumeration_type die,
22637 not as roots in themselves. */
22638 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22639 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22640 prune_unused_types_mark (pub
->die
, 1);
22641 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22642 prune_unused_types_mark (base_type
, 1);
22644 if (debug_str_hash
)
22645 htab_empty (debug_str_hash
);
22646 if (skeleton_debug_str_hash
)
22647 htab_empty (skeleton_debug_str_hash
);
22648 prune_unused_types_prune (comp_unit_die ());
22649 for (node
= limbo_die_list
; node
; node
= node
->next
)
22650 prune_unused_types_prune (node
->die
);
22651 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22652 prune_unused_types_prune (ctnode
->root_die
);
22654 /* Leave the marks clear. */
22655 prune_unmark_dies (comp_unit_die ());
22656 for (node
= limbo_die_list
; node
; node
= node
->next
)
22657 prune_unmark_dies (node
->die
);
22658 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22659 prune_unmark_dies (ctnode
->root_die
);
22662 /* Set the parameter to true if there are any relative pathnames in
22665 file_table_relative_p (void ** slot
, void *param
)
22667 bool *p
= (bool *) param
;
22668 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22669 if (!IS_ABSOLUTE_PATH (d
->filename
))
22677 /* Routines to manipulate hash table of comdat type units. */
22680 htab_ct_hash (const void *of
)
22683 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
22685 memcpy (&h
, type_node
->signature
, sizeof (h
));
22690 htab_ct_eq (const void *of1
, const void *of2
)
22692 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
22693 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
22695 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22696 DWARF_TYPE_SIGNATURE_SIZE
));
22699 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22700 to the location it would have been added, should we know its
22701 DECL_ASSEMBLER_NAME when we added other attributes. This will
22702 probably improve compactness of debug info, removing equivalent
22703 abbrevs, and hide any differences caused by deferring the
22704 computation of the assembler name, triggered by e.g. PCH. */
22707 move_linkage_attr (dw_die_ref die
)
22709 unsigned ix
= vec_safe_length (die
->die_attr
);
22710 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22712 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22713 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22717 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22719 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22723 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22725 die
->die_attr
->pop ();
22726 die
->die_attr
->quick_insert (ix
, linkage
);
22730 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22731 referenced from typed stack ops and count how often they are used. */
22734 mark_base_types (dw_loc_descr_ref loc
)
22736 dw_die_ref base_type
= NULL
;
22738 for (; loc
; loc
= loc
->dw_loc_next
)
22740 switch (loc
->dw_loc_opc
)
22742 case DW_OP_GNU_regval_type
:
22743 case DW_OP_GNU_deref_type
:
22744 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22746 case DW_OP_GNU_convert
:
22747 case DW_OP_GNU_reinterpret
:
22748 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22751 case DW_OP_GNU_const_type
:
22752 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22754 case DW_OP_GNU_entry_value
:
22755 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22760 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22761 if (base_type
->die_mark
)
22762 base_type
->die_mark
++;
22765 base_types
.safe_push (base_type
);
22766 base_type
->die_mark
= 1;
22771 /* Comparison function for sorting marked base types. */
22774 base_type_cmp (const void *x
, const void *y
)
22776 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22777 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22778 unsigned int byte_size1
, byte_size2
;
22779 unsigned int encoding1
, encoding2
;
22780 if (dx
->die_mark
> dy
->die_mark
)
22782 if (dx
->die_mark
< dy
->die_mark
)
22784 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22785 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22786 if (byte_size1
< byte_size2
)
22788 if (byte_size1
> byte_size2
)
22790 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22791 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22792 if (encoding1
< encoding2
)
22794 if (encoding1
> encoding2
)
22799 /* Move base types marked by mark_base_types as early as possible
22800 in the CU, sorted by decreasing usage count both to make the
22801 uleb128 references as small as possible and to make sure they
22802 will have die_offset already computed by calc_die_sizes when
22803 sizes of typed stack loc ops is computed. */
22806 move_marked_base_types (void)
22809 dw_die_ref base_type
, die
, c
;
22811 if (base_types
.is_empty ())
22814 /* Sort by decreasing usage count, they will be added again in that
22816 base_types
.qsort (base_type_cmp
);
22817 die
= comp_unit_die ();
22818 c
= die
->die_child
;
22821 dw_die_ref prev
= c
;
22823 while (c
->die_mark
)
22825 remove_child_with_prev (c
, prev
);
22826 /* As base types got marked, there must be at least
22827 one node other than DW_TAG_base_type. */
22828 gcc_assert (c
!= c
->die_sib
);
22832 while (c
!= die
->die_child
);
22833 gcc_assert (die
->die_child
);
22834 c
= die
->die_child
;
22835 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22837 base_type
->die_mark
= 0;
22838 base_type
->die_sib
= c
->die_sib
;
22839 c
->die_sib
= base_type
;
22844 /* Helper function for resolve_addr, attempt to resolve
22845 one CONST_STRING, return non-zero if not successful. Similarly verify that
22846 SYMBOL_REFs refer to variables emitted in the current CU. */
22849 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22853 if (GET_CODE (rtl
) == CONST_STRING
)
22855 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22856 tree t
= build_string (len
, XSTR (rtl
, 0));
22857 tree tlen
= size_int (len
- 1);
22859 = build_array_type (char_type_node
, build_index_type (tlen
));
22860 rtl
= lookup_constant_def (t
);
22861 if (!rtl
|| !MEM_P (rtl
))
22863 rtl
= XEXP (rtl
, 0);
22864 vec_safe_push (used_rtx_array
, rtl
);
22869 if (GET_CODE (rtl
) == SYMBOL_REF
22870 && SYMBOL_REF_DECL (rtl
))
22872 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22874 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22877 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22881 if (GET_CODE (rtl
) == CONST
22882 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22888 /* Helper function for resolve_addr, handle one location
22889 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22890 the location list couldn't be resolved. */
22893 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22895 dw_loc_descr_ref keep
= NULL
;
22896 for (; loc
; loc
= loc
->dw_loc_next
)
22897 switch (loc
->dw_loc_opc
)
22900 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22903 case DW_OP_GNU_addr_index
:
22904 case DW_OP_GNU_const_index
:
22906 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22907 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22908 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22913 case DW_OP_const4u
:
22914 case DW_OP_const8u
:
22916 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22919 case DW_OP_plus_uconst
:
22920 if (size_of_loc_descr (loc
)
22921 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22923 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22925 dw_loc_descr_ref repl
22926 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22927 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
22928 add_loc_descr (&repl
, loc
->dw_loc_next
);
22932 case DW_OP_implicit_value
:
22933 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22934 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
22937 case DW_OP_GNU_implicit_pointer
:
22938 case DW_OP_GNU_parameter_ref
:
22939 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22942 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22945 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22946 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22947 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22950 case DW_OP_GNU_const_type
:
22951 case DW_OP_GNU_regval_type
:
22952 case DW_OP_GNU_deref_type
:
22953 case DW_OP_GNU_convert
:
22954 case DW_OP_GNU_reinterpret
:
22955 while (loc
->dw_loc_next
22956 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
22958 dw_die_ref base1
, base2
;
22959 unsigned enc1
, enc2
, size1
, size2
;
22960 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22961 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22962 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22963 else if (loc
->dw_loc_oprnd1
.val_class
22964 == dw_val_class_unsigned_const
)
22967 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22968 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
22969 == dw_val_class_unsigned_const
)
22971 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22972 gcc_assert (base1
->die_tag
== DW_TAG_base_type
22973 && base2
->die_tag
== DW_TAG_base_type
);
22974 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
22975 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
22976 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
22977 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
22979 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
22980 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
22984 /* Optimize away next DW_OP_GNU_convert after
22985 adjusting LOC's base type die reference. */
22986 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22987 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22988 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
22990 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
22991 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22994 /* Don't change integer DW_OP_GNU_convert after e.g. floating
22995 point typed stack entry. */
22996 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
22997 keep
= loc
->dw_loc_next
;
23007 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23008 an address in .rodata section if the string literal is emitted there,
23009 or remove the containing location list or replace DW_AT_const_value
23010 with DW_AT_location and empty location expression, if it isn't found
23011 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23012 to something that has been emitted in the current CU. */
23015 resolve_addr (dw_die_ref die
)
23019 dw_loc_list_ref
*curr
, *start
, loc
;
23022 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23023 switch (AT_class (a
))
23025 case dw_val_class_loc_list
:
23026 start
= curr
= AT_loc_list_ptr (a
);
23029 /* The same list can be referenced more than once. See if we have
23030 already recorded the result from a previous pass. */
23032 *curr
= loc
->dw_loc_next
;
23033 else if (!loc
->resolved_addr
)
23035 /* As things stand, we do not expect or allow one die to
23036 reference a suffix of another die's location list chain.
23037 References must be identical or completely separate.
23038 There is therefore no need to cache the result of this
23039 pass on any list other than the first; doing so
23040 would lead to unnecessary writes. */
23043 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23044 if (!resolve_addr_in_expr ((*curr
)->expr
))
23046 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23047 dw_loc_descr_ref l
= (*curr
)->expr
;
23049 if (next
&& (*curr
)->ll_symbol
)
23051 gcc_assert (!next
->ll_symbol
);
23052 next
->ll_symbol
= (*curr
)->ll_symbol
;
23054 if (dwarf_split_debug_info
)
23055 remove_loc_list_addr_table_entries (l
);
23060 mark_base_types ((*curr
)->expr
);
23061 curr
= &(*curr
)->dw_loc_next
;
23065 loc
->resolved_addr
= 1;
23069 loc
->dw_loc_next
= *start
;
23074 remove_AT (die
, a
->dw_attr
);
23078 case dw_val_class_loc
:
23080 dw_loc_descr_ref l
= AT_loc (a
);
23081 /* For -gdwarf-2 don't attempt to optimize
23082 DW_AT_data_member_location containing
23083 DW_OP_plus_uconst - older consumers might
23084 rely on it being that op instead of a more complex,
23085 but shorter, location description. */
23086 if ((dwarf_version
> 2
23087 || a
->dw_attr
!= DW_AT_data_member_location
23089 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23090 || l
->dw_loc_next
!= NULL
)
23091 && !resolve_addr_in_expr (l
))
23093 if (dwarf_split_debug_info
)
23094 remove_loc_list_addr_table_entries (l
);
23095 remove_AT (die
, a
->dw_attr
);
23099 mark_base_types (l
);
23102 case dw_val_class_addr
:
23103 if (a
->dw_attr
== DW_AT_const_value
23104 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23106 if (AT_index (a
) != NOT_INDEXED
)
23107 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23108 remove_AT (die
, a
->dw_attr
);
23111 if (die
->die_tag
== DW_TAG_GNU_call_site
23112 && a
->dw_attr
== DW_AT_abstract_origin
)
23114 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23115 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23117 && DECL_EXTERNAL (tdecl
)
23118 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23120 force_decl_die (tdecl
);
23121 tdie
= lookup_decl_die (tdecl
);
23125 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23126 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23127 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23131 if (AT_index (a
) != NOT_INDEXED
)
23132 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23133 remove_AT (die
, a
->dw_attr
);
23142 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23145 /* Helper routines for optimize_location_lists.
23146 This pass tries to share identical local lists in .debug_loc
23149 /* Iteratively hash operands of LOC opcode. */
23152 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23154 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23155 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23157 switch (loc
->dw_loc_opc
)
23159 case DW_OP_const4u
:
23160 case DW_OP_const8u
:
23164 case DW_OP_const1u
:
23165 case DW_OP_const1s
:
23166 case DW_OP_const2u
:
23167 case DW_OP_const2s
:
23168 case DW_OP_const4s
:
23169 case DW_OP_const8s
:
23173 case DW_OP_plus_uconst
:
23209 case DW_OP_deref_size
:
23210 case DW_OP_xderef_size
:
23211 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23218 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23219 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23220 hash
= iterative_hash_object (offset
, hash
);
23223 case DW_OP_implicit_value
:
23224 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23225 switch (val2
->val_class
)
23227 case dw_val_class_const
:
23228 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23230 case dw_val_class_vec
:
23232 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23233 unsigned int len
= val2
->v
.val_vec
.length
;
23235 hash
= iterative_hash_object (elt_size
, hash
);
23236 hash
= iterative_hash_object (len
, hash
);
23237 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23238 len
* elt_size
, hash
);
23241 case dw_val_class_const_double
:
23242 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23243 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23245 case dw_val_class_addr
:
23246 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23249 gcc_unreachable ();
23253 case DW_OP_bit_piece
:
23254 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23255 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23261 unsigned char dtprel
= 0xd1;
23262 hash
= iterative_hash_object (dtprel
, hash
);
23264 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23266 case DW_OP_GNU_addr_index
:
23267 case DW_OP_GNU_const_index
:
23271 unsigned char dtprel
= 0xd1;
23272 hash
= iterative_hash_object (dtprel
, hash
);
23274 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23277 case DW_OP_GNU_implicit_pointer
:
23278 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23280 case DW_OP_GNU_entry_value
:
23281 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23283 case DW_OP_GNU_regval_type
:
23284 case DW_OP_GNU_deref_type
:
23286 unsigned int byte_size
23287 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23288 unsigned int encoding
23289 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23290 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23291 hash
= iterative_hash_object (byte_size
, hash
);
23292 hash
= iterative_hash_object (encoding
, hash
);
23295 case DW_OP_GNU_convert
:
23296 case DW_OP_GNU_reinterpret
:
23297 if (val1
->val_class
== dw_val_class_unsigned_const
)
23299 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23303 case DW_OP_GNU_const_type
:
23305 unsigned int byte_size
23306 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23307 unsigned int encoding
23308 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23309 hash
= iterative_hash_object (byte_size
, hash
);
23310 hash
= iterative_hash_object (encoding
, hash
);
23311 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23313 hash
= iterative_hash_object (val2
->val_class
, hash
);
23314 switch (val2
->val_class
)
23316 case dw_val_class_const
:
23317 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23319 case dw_val_class_vec
:
23321 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23322 unsigned int len
= val2
->v
.val_vec
.length
;
23324 hash
= iterative_hash_object (elt_size
, hash
);
23325 hash
= iterative_hash_object (len
, hash
);
23326 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23327 len
* elt_size
, hash
);
23330 case dw_val_class_const_double
:
23331 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23332 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23335 gcc_unreachable ();
23341 /* Other codes have no operands. */
23347 /* Iteratively hash the whole DWARF location expression LOC. */
23349 static inline hashval_t
23350 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23352 dw_loc_descr_ref l
;
23353 bool sizes_computed
= false;
23354 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23355 size_of_locs (loc
);
23357 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23359 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23360 hash
= iterative_hash_object (opc
, hash
);
23361 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23363 size_of_locs (loc
);
23364 sizes_computed
= true;
23366 hash
= hash_loc_operands (l
, hash
);
23371 /* Compute hash of the whole location list LIST_HEAD. */
23374 hash_loc_list (dw_loc_list_ref list_head
)
23376 dw_loc_list_ref curr
= list_head
;
23377 hashval_t hash
= 0;
23379 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23381 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23382 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23384 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23386 hash
= hash_locs (curr
->expr
, hash
);
23388 list_head
->hash
= hash
;
23391 /* Return true if X and Y opcodes have the same operands. */
23394 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23396 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23397 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23398 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23399 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23401 switch (x
->dw_loc_opc
)
23403 case DW_OP_const4u
:
23404 case DW_OP_const8u
:
23408 case DW_OP_const1u
:
23409 case DW_OP_const1s
:
23410 case DW_OP_const2u
:
23411 case DW_OP_const2s
:
23412 case DW_OP_const4s
:
23413 case DW_OP_const8s
:
23417 case DW_OP_plus_uconst
:
23453 case DW_OP_deref_size
:
23454 case DW_OP_xderef_size
:
23455 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23458 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23459 can cause irrelevant differences in dw_loc_addr. */
23460 gcc_assert (valx1
->val_class
== dw_val_class_loc
23461 && valy1
->val_class
== dw_val_class_loc
23462 && (dwarf_split_debug_info
23463 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23464 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23465 case DW_OP_implicit_value
:
23466 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23467 || valx2
->val_class
!= valy2
->val_class
)
23469 switch (valx2
->val_class
)
23471 case dw_val_class_const
:
23472 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23473 case dw_val_class_vec
:
23474 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23475 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23476 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23477 valx2
->v
.val_vec
.elt_size
23478 * valx2
->v
.val_vec
.length
) == 0;
23479 case dw_val_class_const_double
:
23480 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23481 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23482 case dw_val_class_addr
:
23483 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23485 gcc_unreachable ();
23488 case DW_OP_bit_piece
:
23489 return valx1
->v
.val_int
== valy1
->v
.val_int
23490 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23493 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23494 case DW_OP_GNU_addr_index
:
23495 case DW_OP_GNU_const_index
:
23497 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23498 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23499 return rtx_equal_p (ax1
, ay1
);
23501 case DW_OP_GNU_implicit_pointer
:
23502 return valx1
->val_class
== dw_val_class_die_ref
23503 && valx1
->val_class
== valy1
->val_class
23504 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23505 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23506 case DW_OP_GNU_entry_value
:
23507 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23508 case DW_OP_GNU_const_type
:
23509 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23510 || valx2
->val_class
!= valy2
->val_class
)
23512 switch (valx2
->val_class
)
23514 case dw_val_class_const
:
23515 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23516 case dw_val_class_vec
:
23517 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23518 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23519 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23520 valx2
->v
.val_vec
.elt_size
23521 * valx2
->v
.val_vec
.length
) == 0;
23522 case dw_val_class_const_double
:
23523 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23524 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23526 gcc_unreachable ();
23528 case DW_OP_GNU_regval_type
:
23529 case DW_OP_GNU_deref_type
:
23530 return valx1
->v
.val_int
== valy1
->v
.val_int
23531 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23532 case DW_OP_GNU_convert
:
23533 case DW_OP_GNU_reinterpret
:
23534 if (valx1
->val_class
!= valy1
->val_class
)
23536 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23537 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23538 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23539 case DW_OP_GNU_parameter_ref
:
23540 return valx1
->val_class
== dw_val_class_die_ref
23541 && valx1
->val_class
== valy1
->val_class
23542 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23544 /* Other codes have no operands. */
23549 /* Return true if DWARF location expressions X and Y are the same. */
23552 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23554 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23555 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23556 || x
->dtprel
!= y
->dtprel
23557 || !compare_loc_operands (x
, y
))
23559 return x
== NULL
&& y
== NULL
;
23562 /* Return precomputed hash of location list X. */
23565 loc_list_hash (const void *x
)
23567 return ((const struct dw_loc_list_struct
*) x
)->hash
;
23570 /* Return 1 if location lists X and Y are the same. */
23573 loc_list_eq (const void *x
, const void *y
)
23575 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
23576 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
23579 if (a
->hash
!= b
->hash
)
23581 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23582 if (strcmp (a
->begin
, b
->begin
) != 0
23583 || strcmp (a
->end
, b
->end
) != 0
23584 || (a
->section
== NULL
) != (b
->section
== NULL
)
23585 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23586 || !compare_locs (a
->expr
, b
->expr
))
23588 return a
== NULL
&& b
== NULL
;
23591 /* Recursively optimize location lists referenced from DIE
23592 children and share them whenever possible. */
23595 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
23602 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23603 if (AT_class (a
) == dw_val_class_loc_list
)
23605 dw_loc_list_ref list
= AT_loc_list (a
);
23606 /* TODO: perform some optimizations here, before hashing
23607 it and storing into the hash table. */
23608 hash_loc_list (list
);
23609 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
23612 *slot
= (void *) list
;
23614 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
23617 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23621 /* Recursively assign each location list a unique index into the debug_addr
23625 index_location_lists (dw_die_ref die
)
23631 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23632 if (AT_class (a
) == dw_val_class_loc_list
)
23634 dw_loc_list_ref list
= AT_loc_list (a
);
23635 dw_loc_list_ref curr
;
23636 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23638 /* Don't index an entry that has already been indexed
23639 or won't be output. */
23640 if (curr
->begin_entry
!= NULL
23641 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23645 = add_addr_table_entry (xstrdup (curr
->begin
),
23650 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23653 /* Optimize location lists referenced from DIE
23654 children and share them whenever possible. */
23657 optimize_location_lists (dw_die_ref die
)
23659 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
23660 optimize_location_lists_1 (die
, htab
);
23661 htab_delete (htab
);
23664 /* Output stuff that dwarf requires at the end of every file,
23665 and generate the DWARF-2 debugging info. */
23668 dwarf2out_finish (const char *filename
)
23670 limbo_die_node
*node
, *next_node
;
23671 comdat_type_node
*ctnode
;
23672 htab_t comdat_type_table
;
23674 dw_die_ref main_comp_unit_die
;
23676 /* PCH might result in DW_AT_producer string being restored from the
23677 header compilation, so always fill it with empty string initially
23678 and overwrite only here. */
23679 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23680 producer_string
= gen_producer_string ();
23681 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23682 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23684 gen_scheduled_generic_parms_dies ();
23685 gen_remaining_tmpl_value_param_die_attribute ();
23687 /* Add the name for the main input file now. We delayed this from
23688 dwarf2out_init to avoid complications with PCH. */
23689 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23690 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23691 add_comp_dir_attribute (comp_unit_die ());
23692 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23695 htab_traverse (file_table
, file_table_relative_p
, &p
);
23697 add_comp_dir_attribute (comp_unit_die ());
23700 if (deferred_locations_list
)
23701 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23703 add_location_or_const_value_attribute (
23704 (*deferred_locations_list
)[i
].die
,
23705 (*deferred_locations_list
)[i
].variable
,
23710 /* Traverse the limbo die list, and add parent/child links. The only
23711 dies without parents that should be here are concrete instances of
23712 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23713 For concrete instances, we can get the parent die from the abstract
23715 for (node
= limbo_die_list
; node
; node
= next_node
)
23717 dw_die_ref die
= node
->die
;
23718 next_node
= node
->next
;
23720 if (die
->die_parent
== NULL
)
23722 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23724 if (origin
&& origin
->die_parent
)
23725 add_child_die (origin
->die_parent
, die
);
23726 else if (is_cu_die (die
))
23728 else if (seen_error ())
23729 /* It's OK to be confused by errors in the input. */
23730 add_child_die (comp_unit_die (), die
);
23733 /* In certain situations, the lexical block containing a
23734 nested function can be optimized away, which results
23735 in the nested function die being orphaned. Likewise
23736 with the return type of that nested function. Force
23737 this to be a child of the containing function.
23739 It may happen that even the containing function got fully
23740 inlined and optimized out. In that case we are lost and
23741 assign the empty child. This should not be big issue as
23742 the function is likely unreachable too. */
23743 gcc_assert (node
->created_for
);
23745 if (DECL_P (node
->created_for
))
23746 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23747 else if (TYPE_P (node
->created_for
))
23748 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23750 origin
= comp_unit_die ();
23752 add_child_die (origin
, die
);
23757 limbo_die_list
= NULL
;
23759 #if ENABLE_ASSERT_CHECKING
23761 dw_die_ref die
= comp_unit_die (), c
;
23762 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23765 resolve_addr (comp_unit_die ());
23766 move_marked_base_types ();
23768 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23770 tree decl
= node
->created_for
;
23771 /* When generating LTO bytecode we can not generate new assembler
23772 names at this point and all important decls got theirs via
23774 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23775 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23777 add_linkage_attr (node
->die
, decl
);
23778 move_linkage_attr (node
->die
);
23782 deferred_asm_name
= NULL
;
23784 /* Walk through the list of incomplete types again, trying once more to
23785 emit full debugging info for them. */
23786 retry_incomplete_types ();
23788 if (flag_eliminate_unused_debug_types
)
23789 prune_unused_types ();
23791 /* Generate separate COMDAT sections for type DIEs. */
23792 if (use_debug_types
)
23794 break_out_comdat_types (comp_unit_die ());
23796 /* Each new type_unit DIE was added to the limbo die list when created.
23797 Since these have all been added to comdat_type_list, clear the
23799 limbo_die_list
= NULL
;
23801 /* For each new comdat type unit, copy declarations for incomplete
23802 types to make the new unit self-contained (i.e., no direct
23803 references to the main compile unit). */
23804 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23805 copy_decls_for_unworthy_types (ctnode
->root_die
);
23806 copy_decls_for_unworthy_types (comp_unit_die ());
23808 /* In the process of copying declarations from one unit to another,
23809 we may have left some declarations behind that are no longer
23810 referenced. Prune them. */
23811 prune_unused_types ();
23814 /* Generate separate CUs for each of the include files we've seen.
23815 They will go into limbo_die_list. */
23816 if (flag_eliminate_dwarf2_dups
)
23817 break_out_includes (comp_unit_die ());
23819 /* Traverse the DIE's and add add sibling attributes to those DIE's
23820 that have children. */
23821 add_sibling_attributes (comp_unit_die ());
23822 for (node
= limbo_die_list
; node
; node
= node
->next
)
23823 add_sibling_attributes (node
->die
);
23824 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23825 add_sibling_attributes (ctnode
->root_die
);
23827 /* When splitting DWARF info, we put some attributes in the
23828 skeleton compile_unit DIE that remains in the .o, while
23829 most attributes go in the DWO compile_unit_die. */
23830 if (dwarf_split_debug_info
)
23831 main_comp_unit_die
= gen_compile_unit_die (NULL
);
23833 main_comp_unit_die
= comp_unit_die ();
23835 /* Output a terminator label for the .text section. */
23836 switch_to_section (text_section
);
23837 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23838 if (cold_text_section
)
23840 switch_to_section (cold_text_section
);
23841 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23844 /* We can only use the low/high_pc attributes if all of the code was
23846 if (!have_multiple_function_sections
23847 || (dwarf_version
< 3 && dwarf_strict
))
23849 /* Don't add if the CU has no associated code. */
23850 if (text_section_used
)
23851 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
23852 text_end_label
, true);
23858 bool range_list_added
= false;
23860 if (text_section_used
)
23861 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
23862 text_end_label
, &range_list_added
, true);
23863 if (cold_text_section_used
)
23864 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
23865 cold_end_label
, &range_list_added
, true);
23867 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
23869 if (DECL_IGNORED_P (fde
->decl
))
23871 if (!fde
->in_std_section
)
23872 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
23873 fde
->dw_fde_end
, &range_list_added
,
23875 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23876 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
23877 fde
->dw_fde_second_end
, &range_list_added
,
23881 if (range_list_added
)
23883 /* We need to give .debug_loc and .debug_ranges an appropriate
23884 "base address". Use zero so that these addresses become
23885 absolute. Historically, we've emitted the unexpected
23886 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23887 Emit both to give time for other tools to adapt. */
23888 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
23889 if (! dwarf_strict
&& dwarf_version
< 4)
23890 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
23896 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
23897 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
23898 debug_line_section_label
);
23901 add_AT_macptr (comp_unit_die (),
23902 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
23903 macinfo_section_label
);
23905 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
23907 /* optimize_location_lists calculates the size of the lists,
23908 so index them first, and assign indices to the entries.
23909 Although optimize_location_lists will remove entries from
23910 the table, it only does so for duplicates, and therefore
23911 only reduces ref_counts to 1. */
23912 unsigned int index
= 0;
23913 index_location_lists (comp_unit_die ());
23914 htab_traverse_noresize (addr_index_table
,
23915 index_addr_table_entry
, &index
);
23917 if (have_location_lists
)
23918 optimize_location_lists (comp_unit_die ());
23920 save_macinfo_strings ();
23922 if (dwarf_split_debug_info
)
23924 unsigned int index
= 0;
23926 /* Add attributes common to skeleton compile_units and
23927 type_units. Because these attributes include strings, it
23928 must be done before freezing the string table. Top-level
23929 skeleton die attrs are added when the skeleton type unit is
23930 created, so ensure it is created by this point. */
23931 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
23932 (void) get_skeleton_type_unit ();
23933 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
23936 /* Output all of the compilation units. We put the main one last so that
23937 the offsets are available to output_pubnames. */
23938 for (node
= limbo_die_list
; node
; node
= node
->next
)
23939 output_comp_unit (node
->die
, 0);
23941 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
23942 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23944 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
23946 /* Don't output duplicate types. */
23947 if (*slot
!= HTAB_EMPTY_ENTRY
)
23950 /* Add a pointer to the line table for the main compilation unit
23951 so that the debugger can make sense of DW_AT_decl_file
23953 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
23954 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23955 (!dwarf_split_debug_info
23956 ? debug_line_section_label
23957 : debug_skeleton_line_section_label
));
23959 output_comdat_type_unit (ctnode
);
23962 htab_delete (comdat_type_table
);
23964 /* The AT_pubnames attribute needs to go in all skeleton dies, including
23965 both the main_cu and all skeleton TUs. Making this call unconditional
23966 would end up either adding a second copy of the AT_pubnames attribute, or
23967 requiring a special case in add_top_level_skeleton_die_attrs. */
23968 if (!dwarf_split_debug_info
)
23969 add_AT_pubnames (comp_unit_die ());
23971 if (dwarf_split_debug_info
)
23974 unsigned char checksum
[16];
23975 struct md5_ctx ctx
;
23977 /* Compute a checksum of the comp_unit to use as the dwo_id. */
23978 md5_init_ctx (&ctx
);
23980 die_checksum (comp_unit_die (), &ctx
, &mark
);
23981 unmark_all_dies (comp_unit_die ());
23982 md5_finish_ctx (&ctx
, checksum
);
23984 /* Use the first 8 bytes of the checksum as the dwo_id,
23985 and add it to both comp-unit DIEs. */
23986 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
23987 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
23989 /* Add the base offset of the ranges table to the skeleton
23991 if (ranges_table_in_use
)
23992 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
23993 ranges_section_label
);
23995 switch_to_section (debug_addr_section
);
23996 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
23997 output_addr_table ();
24000 /* Output the main compilation unit if non-empty or if .debug_macinfo
24001 or .debug_macro will be emitted. */
24002 output_comp_unit (comp_unit_die (), have_macinfo
);
24004 if (dwarf_split_debug_info
&& info_section_emitted
)
24005 output_skeleton_debug_sections (main_comp_unit_die
);
24007 /* Output the abbreviation table. */
24008 if (abbrev_die_table_in_use
!= 1)
24010 switch_to_section (debug_abbrev_section
);
24011 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
24012 output_abbrev_section ();
24015 /* Output location list section if necessary. */
24016 if (have_location_lists
)
24018 /* Output the location lists info. */
24019 switch_to_section (debug_loc_section
);
24020 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
24021 output_location_lists (comp_unit_die ());
24024 output_pubtables ();
24026 /* Output the address range information if a CU (.debug_info section)
24027 was emitted. We output an empty table even if we had no functions
24028 to put in it. This because the consumer has no way to tell the
24029 difference between an empty table that we omitted and failure to
24030 generate a table that would have contained data. */
24031 if (info_section_emitted
)
24033 unsigned long aranges_length
= size_of_aranges ();
24035 switch_to_section (debug_aranges_section
);
24036 output_aranges (aranges_length
);
24039 /* Output ranges section if necessary. */
24040 if (ranges_table_in_use
)
24042 switch_to_section (debug_ranges_section
);
24043 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24047 /* Have to end the macro section. */
24050 switch_to_section (debug_macinfo_section
);
24051 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24053 dw2_asm_output_data (1, 0, "End compilation unit");
24056 /* Output the source line correspondence table. We must do this
24057 even if there is no line information. Otherwise, on an empty
24058 translation unit, we will generate a present, but empty,
24059 .debug_info section. IRIX 6.5 `nm' will then complain when
24060 examining the file. This is done late so that any filenames
24061 used by the debug_info section are marked as 'used'. */
24062 switch_to_section (debug_line_section
);
24063 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24064 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24065 output_line_info (false);
24067 if (dwarf_split_debug_info
&& info_section_emitted
)
24069 switch_to_section (debug_skeleton_line_section
);
24070 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24071 output_line_info (true);
24074 /* If we emitted any indirect strings, output the string table too. */
24075 if (debug_str_hash
|| skeleton_debug_str_hash
)
24076 output_indirect_strings ();
24079 #include "gt-dwarf2out.h"