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 if (table
== pubname_table
)
8000 /* Enumerator names are part of the pubname table, but the
8001 parent DW_TAG_enumeration_type die may have been pruned.
8002 Don't output them if that is the case. */
8003 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8004 (p
->die
->die_parent
== NULL
8005 || !p
->die
->die_parent
->die_perennial_p
))
8008 /* Everything else in the pubname table is included. */
8012 /* The pubtypes table shouldn't include types that have been
8014 return (p
->die
->die_offset
!= 0
8015 || !flag_eliminate_unused_debug_types
);
8018 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8019 generated for the compilation unit. */
8021 static unsigned long
8022 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8027 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8029 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8030 FOR_EACH_VEC_ELT (*names
, i
, p
)
8031 if (include_pubname_in_output (names
, p
))
8032 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8034 size
+= DWARF_OFFSET_SIZE
;
8038 /* Return the size of the information in the .debug_aranges section. */
8040 static unsigned long
8041 size_of_aranges (void)
8045 size
= DWARF_ARANGES_HEADER_SIZE
;
8047 /* Count the address/length pair for this compilation unit. */
8048 if (text_section_used
)
8049 size
+= 2 * DWARF2_ADDR_SIZE
;
8050 if (cold_text_section_used
)
8051 size
+= 2 * DWARF2_ADDR_SIZE
;
8052 if (have_multiple_function_sections
)
8057 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8059 if (DECL_IGNORED_P (fde
->decl
))
8061 if (!fde
->in_std_section
)
8062 size
+= 2 * DWARF2_ADDR_SIZE
;
8063 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8064 size
+= 2 * DWARF2_ADDR_SIZE
;
8068 /* Count the two zero words used to terminated the address range table. */
8069 size
+= 2 * DWARF2_ADDR_SIZE
;
8073 /* Select the encoding of an attribute value. */
8075 static enum dwarf_form
8076 value_format (dw_attr_ref a
)
8078 switch (AT_class (a
))
8080 case dw_val_class_addr
:
8081 /* Only very few attributes allow DW_FORM_addr. */
8086 case DW_AT_entry_pc
:
8087 case DW_AT_trampoline
:
8088 return (AT_index (a
) == NOT_INDEXED
8089 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8093 switch (DWARF2_ADDR_SIZE
)
8096 return DW_FORM_data1
;
8098 return DW_FORM_data2
;
8100 return DW_FORM_data4
;
8102 return DW_FORM_data8
;
8106 case dw_val_class_range_list
:
8107 case dw_val_class_loc_list
:
8108 if (dwarf_version
>= 4)
8109 return DW_FORM_sec_offset
;
8111 case dw_val_class_vms_delta
:
8112 case dw_val_class_offset
:
8113 switch (DWARF_OFFSET_SIZE
)
8116 return DW_FORM_data4
;
8118 return DW_FORM_data8
;
8122 case dw_val_class_loc
:
8123 if (dwarf_version
>= 4)
8124 return DW_FORM_exprloc
;
8125 switch (constant_size (size_of_locs (AT_loc (a
))))
8128 return DW_FORM_block1
;
8130 return DW_FORM_block2
;
8132 return DW_FORM_block4
;
8136 case dw_val_class_const
:
8137 return DW_FORM_sdata
;
8138 case dw_val_class_unsigned_const
:
8139 switch (constant_size (AT_unsigned (a
)))
8142 return DW_FORM_data1
;
8144 return DW_FORM_data2
;
8146 /* In DWARF3 DW_AT_data_member_location with
8147 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8148 constant, so we need to use DW_FORM_udata if we need
8149 a large constant. */
8150 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8151 return DW_FORM_udata
;
8152 return DW_FORM_data4
;
8154 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8155 return DW_FORM_udata
;
8156 return DW_FORM_data8
;
8160 case dw_val_class_const_double
:
8161 switch (HOST_BITS_PER_WIDE_INT
)
8164 return DW_FORM_data2
;
8166 return DW_FORM_data4
;
8168 return DW_FORM_data8
;
8171 return DW_FORM_block1
;
8173 case dw_val_class_vec
:
8174 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8175 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8178 return DW_FORM_block1
;
8180 return DW_FORM_block2
;
8182 return DW_FORM_block4
;
8186 case dw_val_class_flag
:
8187 if (dwarf_version
>= 4)
8189 /* Currently all add_AT_flag calls pass in 1 as last argument,
8190 so DW_FORM_flag_present can be used. If that ever changes,
8191 we'll need to use DW_FORM_flag and have some optimization
8192 in build_abbrev_table that will change those to
8193 DW_FORM_flag_present if it is set to 1 in all DIEs using
8194 the same abbrev entry. */
8195 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8196 return DW_FORM_flag_present
;
8198 return DW_FORM_flag
;
8199 case dw_val_class_die_ref
:
8200 if (AT_ref_external (a
))
8201 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8204 case dw_val_class_fde_ref
:
8205 return DW_FORM_data
;
8206 case dw_val_class_lbl_id
:
8207 return (AT_index (a
) == NOT_INDEXED
8208 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8209 case dw_val_class_lineptr
:
8210 case dw_val_class_macptr
:
8211 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8212 case dw_val_class_str
:
8213 return AT_string_form (a
);
8214 case dw_val_class_file
:
8215 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8218 return DW_FORM_data1
;
8220 return DW_FORM_data2
;
8222 return DW_FORM_data4
;
8227 case dw_val_class_data8
:
8228 return DW_FORM_data8
;
8230 case dw_val_class_high_pc
:
8231 switch (DWARF2_ADDR_SIZE
)
8234 return DW_FORM_data1
;
8236 return DW_FORM_data2
;
8238 return DW_FORM_data4
;
8240 return DW_FORM_data8
;
8250 /* Output the encoding of an attribute value. */
8253 output_value_format (dw_attr_ref a
)
8255 enum dwarf_form form
= value_format (a
);
8257 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8260 /* Given a die and id, produce the appropriate abbreviations. */
8263 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8268 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8269 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8270 dwarf_tag_name (abbrev
->die_tag
));
8272 if (abbrev
->die_child
!= NULL
)
8273 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8275 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8277 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8279 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8280 dwarf_attr_name (a_attr
->dw_attr
));
8281 output_value_format (a_attr
);
8284 dw2_asm_output_data (1, 0, NULL
);
8285 dw2_asm_output_data (1, 0, NULL
);
8289 /* Output the .debug_abbrev section which defines the DIE abbreviation
8293 output_abbrev_section (void)
8295 unsigned long abbrev_id
;
8297 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8298 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8300 /* Terminate the table. */
8301 dw2_asm_output_data (1, 0, NULL
);
8304 /* Output a symbol we can use to refer to this DIE from another CU. */
8307 output_die_symbol (dw_die_ref die
)
8309 const char *sym
= die
->die_id
.die_symbol
;
8311 gcc_assert (!die
->comdat_type_p
);
8316 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8317 /* We make these global, not weak; if the target doesn't support
8318 .linkonce, it doesn't support combining the sections, so debugging
8320 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8322 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8325 /* Return a new location list, given the begin and end range, and the
8328 static inline dw_loc_list_ref
8329 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8330 const char *section
)
8332 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8334 retlist
->begin
= begin
;
8335 retlist
->begin_entry
= NULL
;
8337 retlist
->expr
= expr
;
8338 retlist
->section
= section
;
8343 /* Generate a new internal symbol for this location list node, if it
8344 hasn't got one yet. */
8347 gen_llsym (dw_loc_list_ref list
)
8349 gcc_assert (!list
->ll_symbol
);
8350 list
->ll_symbol
= gen_internal_sym ("LLST");
8353 /* Output the location list given to us. */
8356 output_loc_list (dw_loc_list_ref list_head
)
8358 dw_loc_list_ref curr
= list_head
;
8360 if (list_head
->emitted
)
8362 list_head
->emitted
= true;
8364 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8366 /* Walk the location list, and output each range + expression. */
8367 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8370 /* Don't output an entry that starts and ends at the same address. */
8371 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8373 size
= size_of_locs (curr
->expr
);
8374 /* If the expression is too large, drop it on the floor. We could
8375 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8376 in the expression, but >= 64KB expressions for a single value
8377 in a single range are unlikely very useful. */
8380 if (dwarf_split_debug_info
)
8382 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8383 "Location list start/length entry (%s)",
8384 list_head
->ll_symbol
);
8385 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8386 "Location list range start index (%s)",
8388 /* The length field is 4 bytes. If we ever need to support
8389 an 8-byte length, we can add a new DW_LLE code or fall back
8390 to DW_LLE_GNU_start_end_entry. */
8391 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8392 "Location list range length (%s)",
8393 list_head
->ll_symbol
);
8395 else if (!have_multiple_function_sections
)
8397 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8398 "Location list begin address (%s)",
8399 list_head
->ll_symbol
);
8400 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8401 "Location list end address (%s)",
8402 list_head
->ll_symbol
);
8406 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8407 "Location list begin address (%s)",
8408 list_head
->ll_symbol
);
8409 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8410 "Location list end address (%s)",
8411 list_head
->ll_symbol
);
8414 /* Output the block length for this list of location operations. */
8415 gcc_assert (size
<= 0xffff);
8416 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8418 output_loc_sequence (curr
->expr
, -1);
8421 if (dwarf_split_debug_info
)
8422 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8423 "Location list terminator (%s)",
8424 list_head
->ll_symbol
);
8427 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8428 "Location list terminator begin (%s)",
8429 list_head
->ll_symbol
);
8430 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8431 "Location list terminator end (%s)",
8432 list_head
->ll_symbol
);
8436 /* Output a range_list offset into the debug_range section. Emit a
8437 relocated reference if val_entry is NULL, otherwise, emit an
8438 indirect reference. */
8441 output_range_list_offset (dw_attr_ref a
)
8443 const char *name
= dwarf_attr_name (a
->dw_attr
);
8445 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8447 char *p
= strchr (ranges_section_label
, '\0');
8448 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8449 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8450 debug_ranges_section
, "%s", name
);
8454 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8455 "%s (offset from %s)", name
, ranges_section_label
);
8458 /* Output the offset into the debug_loc section. */
8461 output_loc_list_offset (dw_attr_ref a
)
8463 char *sym
= AT_loc_list (a
)->ll_symbol
;
8466 if (dwarf_split_debug_info
)
8467 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8468 "%s", dwarf_attr_name (a
->dw_attr
));
8470 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8471 "%s", dwarf_attr_name (a
->dw_attr
));
8474 /* Output an attribute's index or value appropriately. */
8477 output_attr_index_or_value (dw_attr_ref a
)
8479 const char *name
= dwarf_attr_name (a
->dw_attr
);
8481 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8483 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8486 switch (AT_class (a
))
8488 case dw_val_class_addr
:
8489 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8491 case dw_val_class_high_pc
:
8492 case dw_val_class_lbl_id
:
8493 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8495 case dw_val_class_loc_list
:
8496 output_loc_list_offset (a
);
8503 /* Output a type signature. */
8506 output_signature (const char *sig
, const char *name
)
8510 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8511 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8514 /* Output the DIE and its attributes. Called recursively to generate
8515 the definitions of each child DIE. */
8518 output_die (dw_die_ref die
)
8525 /* If someone in another CU might refer to us, set up a symbol for
8526 them to point to. */
8527 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8528 output_die_symbol (die
);
8530 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8531 (unsigned long)die
->die_offset
,
8532 dwarf_tag_name (die
->die_tag
));
8534 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8536 const char *name
= dwarf_attr_name (a
->dw_attr
);
8538 switch (AT_class (a
))
8540 case dw_val_class_addr
:
8541 output_attr_index_or_value (a
);
8544 case dw_val_class_offset
:
8545 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8549 case dw_val_class_range_list
:
8550 output_range_list_offset (a
);
8553 case dw_val_class_loc
:
8554 size
= size_of_locs (AT_loc (a
));
8556 /* Output the block length for this list of location operations. */
8557 if (dwarf_version
>= 4)
8558 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8560 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8562 output_loc_sequence (AT_loc (a
), -1);
8565 case dw_val_class_const
:
8566 /* ??? It would be slightly more efficient to use a scheme like is
8567 used for unsigned constants below, but gdb 4.x does not sign
8568 extend. Gdb 5.x does sign extend. */
8569 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8572 case dw_val_class_unsigned_const
:
8574 int csize
= constant_size (AT_unsigned (a
));
8575 if (dwarf_version
== 3
8576 && a
->dw_attr
== DW_AT_data_member_location
8578 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8580 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8584 case dw_val_class_const_double
:
8586 unsigned HOST_WIDE_INT first
, second
;
8588 if (HOST_BITS_PER_WIDE_INT
>= 64)
8589 dw2_asm_output_data (1,
8590 HOST_BITS_PER_DOUBLE_INT
8591 / HOST_BITS_PER_CHAR
,
8594 if (WORDS_BIG_ENDIAN
)
8596 first
= a
->dw_attr_val
.v
.val_double
.high
;
8597 second
= a
->dw_attr_val
.v
.val_double
.low
;
8601 first
= a
->dw_attr_val
.v
.val_double
.low
;
8602 second
= a
->dw_attr_val
.v
.val_double
.high
;
8605 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8607 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8612 case dw_val_class_vec
:
8614 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8615 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8619 dw2_asm_output_data (constant_size (len
* elt_size
),
8620 len
* elt_size
, "%s", name
);
8621 if (elt_size
> sizeof (HOST_WIDE_INT
))
8626 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8629 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8630 "fp or vector constant word %u", i
);
8634 case dw_val_class_flag
:
8635 if (dwarf_version
>= 4)
8637 /* Currently all add_AT_flag calls pass in 1 as last argument,
8638 so DW_FORM_flag_present can be used. If that ever changes,
8639 we'll need to use DW_FORM_flag and have some optimization
8640 in build_abbrev_table that will change those to
8641 DW_FORM_flag_present if it is set to 1 in all DIEs using
8642 the same abbrev entry. */
8643 gcc_assert (AT_flag (a
) == 1);
8645 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8646 ASM_COMMENT_START
, name
);
8649 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8652 case dw_val_class_loc_list
:
8653 output_attr_index_or_value (a
);
8656 case dw_val_class_die_ref
:
8657 if (AT_ref_external (a
))
8659 if (AT_ref (a
)->comdat_type_p
)
8661 comdat_type_node_ref type_node
=
8662 AT_ref (a
)->die_id
.die_type_node
;
8664 gcc_assert (type_node
);
8665 output_signature (type_node
->signature
, name
);
8669 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8673 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8674 length, whereas in DWARF3 it's always sized as an
8676 if (dwarf_version
== 2)
8677 size
= DWARF2_ADDR_SIZE
;
8679 size
= DWARF_OFFSET_SIZE
;
8680 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8686 gcc_assert (AT_ref (a
)->die_offset
);
8687 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8692 case dw_val_class_fde_ref
:
8696 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8697 a
->dw_attr_val
.v
.val_fde_index
* 2);
8698 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8703 case dw_val_class_vms_delta
:
8704 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8705 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8709 case dw_val_class_lbl_id
:
8710 output_attr_index_or_value (a
);
8713 case dw_val_class_lineptr
:
8714 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8715 debug_line_section
, "%s", name
);
8718 case dw_val_class_macptr
:
8719 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8720 debug_macinfo_section
, "%s", name
);
8723 case dw_val_class_str
:
8724 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8725 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8726 a
->dw_attr_val
.v
.val_str
->label
,
8728 "%s: \"%s\"", name
, AT_string (a
));
8729 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8730 dw2_asm_output_data_uleb128 (AT_index (a
),
8731 "%s: \"%s\"", name
, AT_string (a
));
8733 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8736 case dw_val_class_file
:
8738 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8740 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8741 a
->dw_attr_val
.v
.val_file
->filename
);
8745 case dw_val_class_data8
:
8749 for (i
= 0; i
< 8; i
++)
8750 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8751 i
== 0 ? "%s" : NULL
, name
);
8755 case dw_val_class_high_pc
:
8756 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8757 get_AT_low_pc (die
), "DW_AT_high_pc");
8765 FOR_EACH_CHILD (die
, c
, output_die (c
));
8767 /* Add null byte to terminate sibling list. */
8768 if (die
->die_child
!= NULL
)
8769 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8770 (unsigned long) die
->die_offset
);
8773 /* Output the compilation unit that appears at the beginning of the
8774 .debug_info section, and precedes the DIE descriptions. */
8777 output_compilation_unit_header (void)
8779 int ver
= dwarf_version
;
8781 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8782 dw2_asm_output_data (4, 0xffffffff,
8783 "Initial length escape value indicating 64-bit DWARF extension");
8784 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8785 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8786 "Length of Compilation Unit Info");
8787 dw2_asm_output_data (2, ver
, "DWARF version number");
8788 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8789 debug_abbrev_section
,
8790 "Offset Into Abbrev. Section");
8791 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8794 /* Output the compilation unit DIE and its children. */
8797 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8799 const char *secname
, *oldsym
;
8803 /* Unless we are outputting main CU, we may throw away empty ones. */
8804 if (!output_if_empty
&& die
->die_child
== NULL
)
8807 /* Even if there are no children of this DIE, we must output the information
8808 about the compilation unit. Otherwise, on an empty translation unit, we
8809 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8810 will then complain when examining the file. First mark all the DIEs in
8811 this CU so we know which get local refs. */
8814 extern_map
= optimize_external_refs (die
);
8816 build_abbrev_table (die
, extern_map
);
8818 htab_delete (extern_map
);
8820 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8821 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8822 calc_die_sizes (die
);
8824 oldsym
= die
->die_id
.die_symbol
;
8827 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8829 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8831 die
->die_id
.die_symbol
= NULL
;
8832 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8836 switch_to_section (debug_info_section
);
8837 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8838 info_section_emitted
= true;
8841 /* Output debugging information. */
8842 output_compilation_unit_header ();
8845 /* Leave the marks on the main CU, so we can check them in
8850 die
->die_id
.die_symbol
= oldsym
;
8854 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8855 and .debug_pubtypes. This is configured per-target, but can be
8856 overridden by the -gpubnames or -gno-pubnames options. */
8859 want_pubnames (void)
8861 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8863 if (debug_generate_pub_sections
!= -1)
8864 return debug_generate_pub_sections
;
8865 return targetm
.want_debug_pub_sections
;
8868 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8871 add_AT_pubnames (dw_die_ref die
)
8873 if (want_pubnames ())
8874 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8877 /* Add a string attribute value to a skeleton DIE. */
8880 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8884 struct indirect_string_node
*node
;
8886 if (! skeleton_debug_str_hash
)
8887 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
8888 debug_str_eq
, NULL
);
8890 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
8891 find_string_form (node
);
8892 if (node
->form
== DW_FORM_GNU_str_index
)
8893 node
->form
= DW_FORM_strp
;
8895 attr
.dw_attr
= attr_kind
;
8896 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
8897 attr
.dw_attr_val
.val_entry
= NULL
;
8898 attr
.dw_attr_val
.v
.val_str
= node
;
8899 add_dwarf_attr (die
, &attr
);
8902 /* Helper function to generate top-level dies for skeleton debug_info and
8906 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8908 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8909 const char *comp_dir
= comp_dir_string ();
8911 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8912 if (comp_dir
!= NULL
)
8913 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
8914 add_AT_pubnames (die
);
8915 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8918 /* Return the single type-unit die for skeleton type units. */
8921 get_skeleton_type_unit (void)
8923 /* For dwarf_split_debug_sections with use_type info, all type units in the
8924 skeleton sections have identical dies (but different headers). This
8925 single die will be output many times. */
8927 static dw_die_ref skeleton_type_unit
= NULL
;
8929 if (skeleton_type_unit
== NULL
)
8931 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8932 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8933 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8935 return skeleton_type_unit
;
8938 /* Output skeleton debug sections that point to the dwo file. */
8941 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8943 /* These attributes will be found in the full debug_info section. */
8944 remove_AT (comp_unit
, DW_AT_producer
);
8945 remove_AT (comp_unit
, DW_AT_language
);
8947 switch_to_section (debug_skeleton_info_section
);
8948 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8950 /* Produce the skeleton compilation-unit header. This one differs enough from
8951 a normal CU header that it's better not to call output_compilation_unit
8953 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8954 dw2_asm_output_data (4, 0xffffffff,
8955 "Initial length escape value indicating 64-bit DWARF extension");
8957 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8958 DWARF_COMPILE_UNIT_HEADER_SIZE
8959 - DWARF_INITIAL_LENGTH_SIZE
8960 + size_of_die (comp_unit
),
8961 "Length of Compilation Unit Info");
8962 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8963 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8964 debug_abbrev_section
,
8965 "Offset Into Abbrev. Section");
8966 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8968 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8969 output_die (comp_unit
);
8971 /* Build the skeleton debug_abbrev section. */
8972 switch_to_section (debug_skeleton_abbrev_section
);
8973 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8975 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8976 if (use_debug_types
)
8977 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8979 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8982 /* Output a comdat type unit DIE and its children. */
8985 output_comdat_type_unit (comdat_type_node
*node
)
8987 const char *secname
;
8990 #if defined (OBJECT_FORMAT_ELF)
8995 /* First mark all the DIEs in this CU so we know which get local refs. */
8996 mark_dies (node
->root_die
);
8998 extern_map
= optimize_external_refs (node
->root_die
);
9000 build_abbrev_table (node
->root_die
, extern_map
);
9002 htab_delete (extern_map
);
9004 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9005 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9006 calc_die_sizes (node
->root_die
);
9008 #if defined (OBJECT_FORMAT_ELF)
9009 if (!dwarf_split_debug_info
)
9010 secname
= ".debug_types";
9012 secname
= ".debug_types.dwo";
9014 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9015 sprintf (tmp
, "wt.");
9016 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9017 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9018 comdat_key
= get_identifier (tmp
);
9019 targetm
.asm_out
.named_section (secname
,
9020 SECTION_DEBUG
| SECTION_LINKONCE
,
9023 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9024 sprintf (tmp
, ".gnu.linkonce.wt.");
9025 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9026 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9028 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9031 /* Output debugging information. */
9032 output_compilation_unit_header ();
9033 output_signature (node
->signature
, "Type Signature");
9034 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9035 "Offset to Type DIE");
9036 output_die (node
->root_die
);
9038 unmark_dies (node
->root_die
);
9040 #if defined (OBJECT_FORMAT_ELF)
9041 if (dwarf_split_debug_info
)
9043 /* Produce the skeleton type-unit header. */
9044 const char *secname
= ".debug_types";
9046 targetm
.asm_out
.named_section (secname
,
9047 SECTION_DEBUG
| SECTION_LINKONCE
,
9049 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9050 dw2_asm_output_data (4, 0xffffffff,
9051 "Initial length escape value indicating 64-bit DWARF extension");
9053 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9054 DWARF_COMPILE_UNIT_HEADER_SIZE
9055 - DWARF_INITIAL_LENGTH_SIZE
9056 + size_of_die (get_skeleton_type_unit ())
9057 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
9058 "Length of Type Unit Info");
9059 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9060 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9061 debug_skeleton_abbrev_section_label
,
9062 debug_abbrev_section
,
9063 "Offset Into Abbrev. Section");
9064 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9065 output_signature (node
->signature
, "Type Signature");
9066 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
9068 output_die (get_skeleton_type_unit ());
9073 /* Return the DWARF2/3 pubname associated with a decl. */
9076 dwarf2_name (tree decl
, int scope
)
9078 if (DECL_NAMELESS (decl
))
9080 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9083 /* Add a new entry to .debug_pubnames if appropriate. */
9086 add_pubname_string (const char *str
, dw_die_ref die
)
9091 e
.name
= xstrdup (str
);
9092 vec_safe_push (pubname_table
, e
);
9096 add_pubname (tree decl
, dw_die_ref die
)
9098 if (!want_pubnames ())
9101 /* Don't add items to the table when we expect that the consumer will have
9102 just read the enclosing die. For example, if the consumer is looking at a
9103 class_member, it will either be inside the class already, or will have just
9104 looked up the class to find the member. Either way, searching the class is
9105 faster than searching the index. */
9106 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9107 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9109 const char *name
= dwarf2_name (decl
, 1);
9112 add_pubname_string (name
, die
);
9116 /* Add an enumerator to the pubnames section. */
9119 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9123 gcc_assert (scope_name
);
9124 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9126 vec_safe_push (pubname_table
, e
);
9129 /* Add a new entry to .debug_pubtypes if appropriate. */
9132 add_pubtype (tree decl
, dw_die_ref die
)
9136 if (!want_pubnames ())
9139 if ((TREE_PUBLIC (decl
)
9140 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9141 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9144 const char *scope_name
= "";
9145 const char *sep
= is_cxx () ? "::" : ".";
9148 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9149 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9151 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9152 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9153 scope_name
= concat (scope_name
, sep
, NULL
);
9159 name
= type_tag (decl
);
9161 name
= lang_hooks
.dwarf_name (decl
, 1);
9163 /* If we don't have a name for the type, there's no point in adding
9165 if (name
!= NULL
&& name
[0] != '\0')
9168 e
.name
= concat (scope_name
, name
, NULL
);
9169 vec_safe_push (pubtype_table
, e
);
9172 /* Although it might be more consistent to add the pubinfo for the
9173 enumerators as their dies are created, they should only be added if the
9174 enum type meets the criteria above. So rather than re-check the parent
9175 enum type whenever an enumerator die is created, just output them all
9176 here. This isn't protected by the name conditional because anonymous
9177 enums don't have names. */
9178 if (die
->die_tag
== DW_TAG_enumeration_type
)
9182 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9187 /* Output a single entry in the pubnames table. */
9190 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9192 dw_die_ref die
= entry
->die
;
9193 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9195 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9197 if (debug_generate_pub_sections
== 2)
9199 /* This logic follows gdb's method for determining the value of the flag
9201 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9202 switch (die
->die_tag
)
9204 case DW_TAG_typedef
:
9205 case DW_TAG_base_type
:
9206 case DW_TAG_subrange_type
:
9207 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9208 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9210 case DW_TAG_enumerator
:
9211 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9212 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9213 if (!is_cxx () && !is_java ())
9214 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9216 case DW_TAG_subprogram
:
9217 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9218 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9220 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9222 case DW_TAG_constant
:
9223 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9224 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9225 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9227 case DW_TAG_variable
:
9228 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9229 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9230 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9232 case DW_TAG_namespace
:
9233 case DW_TAG_imported_declaration
:
9234 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9236 case DW_TAG_class_type
:
9237 case DW_TAG_interface_type
:
9238 case DW_TAG_structure_type
:
9239 case DW_TAG_union_type
:
9240 case DW_TAG_enumeration_type
:
9241 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9242 if (!is_cxx () && !is_java ())
9243 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9248 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9252 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9256 /* Output the public names table used to speed up access to externally
9257 visible names; or the public types table used to find type definitions. */
9260 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9263 unsigned long pubnames_length
= size_of_pubnames (names
);
9266 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9267 dw2_asm_output_data (4, 0xffffffff,
9268 "Initial length escape value indicating 64-bit DWARF extension");
9269 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9271 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9272 dw2_asm_output_data (2, 2, "DWARF Version");
9274 if (dwarf_split_debug_info
)
9275 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9276 debug_skeleton_info_section
,
9277 "Offset of Compilation Unit Info");
9279 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9281 "Offset of Compilation Unit Info");
9282 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9283 "Compilation Unit Length");
9285 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9287 if (include_pubname_in_output (names
, pub
))
9289 dw_offset die_offset
= pub
->die
->die_offset
;
9291 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9292 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9293 gcc_assert (pub
->die
->die_mark
);
9295 /* If we're putting types in their own .debug_types sections,
9296 the .debug_pubtypes table will still point to the compile
9297 unit (not the type unit), so we want to use the offset of
9298 the skeleton DIE (if there is one). */
9299 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9301 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9303 if (type_node
!= NULL
)
9304 die_offset
= (type_node
->skeleton_die
!= NULL
9305 ? type_node
->skeleton_die
->die_offset
9309 output_pubname (die_offset
, pub
);
9313 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9316 /* Output public names and types tables if necessary. */
9319 output_pubtables (void)
9321 if (!want_pubnames () || !info_section_emitted
)
9324 switch_to_section (debug_pubnames_section
);
9325 output_pubnames (pubname_table
);
9326 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9327 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9328 simply won't look for the section. */
9329 switch_to_section (debug_pubtypes_section
);
9330 output_pubnames (pubtype_table
);
9334 /* Output the information that goes into the .debug_aranges table.
9335 Namely, define the beginning and ending address range of the
9336 text section generated for this compilation unit. */
9339 output_aranges (unsigned long aranges_length
)
9343 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9344 dw2_asm_output_data (4, 0xffffffff,
9345 "Initial length escape value indicating 64-bit DWARF extension");
9346 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9347 "Length of Address Ranges Info");
9348 /* Version number for aranges is still 2, even in DWARF3. */
9349 dw2_asm_output_data (2, 2, "DWARF Version");
9350 if (dwarf_split_debug_info
)
9351 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9352 debug_skeleton_info_section
,
9353 "Offset of Compilation Unit Info");
9355 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9357 "Offset of Compilation Unit Info");
9358 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9359 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9361 /* We need to align to twice the pointer size here. */
9362 if (DWARF_ARANGES_PAD_SIZE
)
9364 /* Pad using a 2 byte words so that padding is correct for any
9366 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9367 2 * DWARF2_ADDR_SIZE
);
9368 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9369 dw2_asm_output_data (2, 0, NULL
);
9372 /* It is necessary not to output these entries if the sections were
9373 not used; if the sections were not used, the length will be 0 and
9374 the address may end up as 0 if the section is discarded by ld
9375 --gc-sections, leaving an invalid (0, 0) entry that can be
9376 confused with the terminator. */
9377 if (text_section_used
)
9379 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9380 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9381 text_section_label
, "Length");
9383 if (cold_text_section_used
)
9385 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9387 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9388 cold_text_section_label
, "Length");
9391 if (have_multiple_function_sections
)
9396 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9398 if (DECL_IGNORED_P (fde
->decl
))
9400 if (!fde
->in_std_section
)
9402 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9404 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9405 fde
->dw_fde_begin
, "Length");
9407 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9409 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9411 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9412 fde
->dw_fde_second_begin
, "Length");
9417 /* Output the terminator words. */
9418 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9419 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9422 /* Add a new entry to .debug_ranges. Return the offset at which it
9426 add_ranges_num (int num
)
9428 unsigned int in_use
= ranges_table_in_use
;
9430 if (in_use
== ranges_table_allocated
)
9432 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9433 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9434 ranges_table_allocated
);
9435 memset (ranges_table
+ ranges_table_in_use
, 0,
9436 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9439 ranges_table
[in_use
].num
= num
;
9440 ranges_table_in_use
= in_use
+ 1;
9442 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9445 /* Add a new entry to .debug_ranges corresponding to a block, or a
9446 range terminator if BLOCK is NULL. */
9449 add_ranges (const_tree block
)
9451 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9454 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9455 When using dwarf_split_debug_info, address attributes in dies destined
9456 for the final executable should be direct references--setting the
9457 parameter force_direct ensures this behavior. */
9460 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9461 bool *added
, bool force_direct
)
9463 unsigned int in_use
= ranges_by_label_in_use
;
9464 unsigned int offset
;
9466 if (in_use
== ranges_by_label_allocated
)
9468 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9469 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9471 ranges_by_label_allocated
);
9472 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9473 RANGES_TABLE_INCREMENT
9474 * sizeof (struct dw_ranges_by_label_struct
));
9477 ranges_by_label
[in_use
].begin
= begin
;
9478 ranges_by_label
[in_use
].end
= end
;
9479 ranges_by_label_in_use
= in_use
+ 1;
9481 offset
= add_ranges_num (-(int)in_use
- 1);
9484 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9490 output_ranges (void)
9493 static const char *const start_fmt
= "Offset %#x";
9494 const char *fmt
= start_fmt
;
9496 for (i
= 0; i
< ranges_table_in_use
; i
++)
9498 int block_num
= ranges_table
[i
].num
;
9502 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9503 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9505 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9506 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9508 /* If all code is in the text section, then the compilation
9509 unit base address defaults to DW_AT_low_pc, which is the
9510 base of the text section. */
9511 if (!have_multiple_function_sections
)
9513 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9515 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9516 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9517 text_section_label
, NULL
);
9520 /* Otherwise, the compilation unit base address is zero,
9521 which allows us to use absolute addresses, and not worry
9522 about whether the target supports cross-section
9526 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9527 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9528 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9534 /* Negative block_num stands for an index into ranges_by_label. */
9535 else if (block_num
< 0)
9537 int lab_idx
= - block_num
- 1;
9539 if (!have_multiple_function_sections
)
9543 /* If we ever use add_ranges_by_labels () for a single
9544 function section, all we have to do is to take out
9546 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9547 ranges_by_label
[lab_idx
].begin
,
9549 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9550 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9551 ranges_by_label
[lab_idx
].end
,
9552 text_section_label
, NULL
);
9557 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9558 ranges_by_label
[lab_idx
].begin
,
9559 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9560 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9561 ranges_by_label
[lab_idx
].end
,
9567 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9568 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9574 /* Data structure containing information about input files. */
9577 const char *path
; /* Complete file name. */
9578 const char *fname
; /* File name part. */
9579 int length
; /* Length of entire string. */
9580 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9581 int dir_idx
; /* Index in directory table. */
9584 /* Data structure containing information about directories with source
9588 const char *path
; /* Path including directory name. */
9589 int length
; /* Path length. */
9590 int prefix
; /* Index of directory entry which is a prefix. */
9591 int count
; /* Number of files in this directory. */
9592 int dir_idx
; /* Index of directory used as base. */
9595 /* Callback function for file_info comparison. We sort by looking at
9596 the directories in the path. */
9599 file_info_cmp (const void *p1
, const void *p2
)
9601 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9602 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9603 const unsigned char *cp1
;
9604 const unsigned char *cp2
;
9606 /* Take care of file names without directories. We need to make sure that
9607 we return consistent values to qsort since some will get confused if
9608 we return the same value when identical operands are passed in opposite
9609 orders. So if neither has a directory, return 0 and otherwise return
9610 1 or -1 depending on which one has the directory. */
9611 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9612 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9614 cp1
= (const unsigned char *) s1
->path
;
9615 cp2
= (const unsigned char *) s2
->path
;
9621 /* Reached the end of the first path? If so, handle like above. */
9622 if ((cp1
== (const unsigned char *) s1
->fname
)
9623 || (cp2
== (const unsigned char *) s2
->fname
))
9624 return ((cp2
== (const unsigned char *) s2
->fname
)
9625 - (cp1
== (const unsigned char *) s1
->fname
));
9627 /* Character of current path component the same? */
9628 else if (*cp1
!= *cp2
)
9633 struct file_name_acquire_data
9635 struct file_info
*files
;
9640 /* Traversal function for the hash table. */
9643 file_name_acquire (void ** slot
, void *data
)
9645 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9646 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9647 struct file_info
*fi
;
9650 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9652 if (! d
->emitted_number
)
9655 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9657 fi
= fnad
->files
+ fnad
->used_files
++;
9659 /* Skip all leading "./". */
9661 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9664 /* Create a new array entry. */
9666 fi
->length
= strlen (f
);
9669 /* Search for the file name part. */
9670 f
= strrchr (f
, DIR_SEPARATOR
);
9671 #if defined (DIR_SEPARATOR_2)
9673 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9677 if (f
== NULL
|| f
< g
)
9683 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9687 /* Output the directory table and the file name table. We try to minimize
9688 the total amount of memory needed. A heuristic is used to avoid large
9689 slowdowns with many input files. */
9692 output_file_names (void)
9694 struct file_name_acquire_data fnad
;
9696 struct file_info
*files
;
9697 struct dir_info
*dirs
;
9705 if (!last_emitted_file
)
9707 dw2_asm_output_data (1, 0, "End directory table");
9708 dw2_asm_output_data (1, 0, "End file name table");
9712 numfiles
= last_emitted_file
->emitted_number
;
9714 /* Allocate the various arrays we need. */
9715 files
= XALLOCAVEC (struct file_info
, numfiles
);
9716 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9719 fnad
.used_files
= 0;
9720 fnad
.max_files
= numfiles
;
9721 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9722 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9724 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9726 /* Find all the different directories used. */
9727 dirs
[0].path
= files
[0].path
;
9728 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9729 dirs
[0].prefix
= -1;
9731 dirs
[0].dir_idx
= 0;
9732 files
[0].dir_idx
= 0;
9735 for (i
= 1; i
< numfiles
; i
++)
9736 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9737 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9738 dirs
[ndirs
- 1].length
) == 0)
9740 /* Same directory as last entry. */
9741 files
[i
].dir_idx
= ndirs
- 1;
9742 ++dirs
[ndirs
- 1].count
;
9748 /* This is a new directory. */
9749 dirs
[ndirs
].path
= files
[i
].path
;
9750 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9751 dirs
[ndirs
].count
= 1;
9752 dirs
[ndirs
].dir_idx
= ndirs
;
9753 files
[i
].dir_idx
= ndirs
;
9755 /* Search for a prefix. */
9756 dirs
[ndirs
].prefix
= -1;
9757 for (j
= 0; j
< ndirs
; j
++)
9758 if (dirs
[j
].length
< dirs
[ndirs
].length
9759 && dirs
[j
].length
> 1
9760 && (dirs
[ndirs
].prefix
== -1
9761 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9762 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9763 dirs
[ndirs
].prefix
= j
;
9768 /* Now to the actual work. We have to find a subset of the directories which
9769 allow expressing the file name using references to the directory table
9770 with the least amount of characters. We do not do an exhaustive search
9771 where we would have to check out every combination of every single
9772 possible prefix. Instead we use a heuristic which provides nearly optimal
9773 results in most cases and never is much off. */
9774 saved
= XALLOCAVEC (int, ndirs
);
9775 savehere
= XALLOCAVEC (int, ndirs
);
9777 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9778 for (i
= 0; i
< ndirs
; i
++)
9783 /* We can always save some space for the current directory. But this
9784 does not mean it will be enough to justify adding the directory. */
9785 savehere
[i
] = dirs
[i
].length
;
9786 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9788 for (j
= i
+ 1; j
< ndirs
; j
++)
9791 if (saved
[j
] < dirs
[i
].length
)
9793 /* Determine whether the dirs[i] path is a prefix of the
9798 while (k
!= -1 && k
!= (int) i
)
9803 /* Yes it is. We can possibly save some memory by
9804 writing the filenames in dirs[j] relative to
9806 savehere
[j
] = dirs
[i
].length
;
9807 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9812 /* Check whether we can save enough to justify adding the dirs[i]
9814 if (total
> dirs
[i
].length
+ 1)
9816 /* It's worthwhile adding. */
9817 for (j
= i
; j
< ndirs
; j
++)
9818 if (savehere
[j
] > 0)
9820 /* Remember how much we saved for this directory so far. */
9821 saved
[j
] = savehere
[j
];
9823 /* Remember the prefix directory. */
9824 dirs
[j
].dir_idx
= i
;
9829 /* Emit the directory name table. */
9830 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9831 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9832 dw2_asm_output_nstring (dirs
[i
].path
,
9834 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9835 "Directory Entry: %#x", i
+ idx_offset
);
9837 dw2_asm_output_data (1, 0, "End directory table");
9839 /* We have to emit them in the order of emitted_number since that's
9840 used in the debug info generation. To do this efficiently we
9841 generate a back-mapping of the indices first. */
9842 backmap
= XALLOCAVEC (int, numfiles
);
9843 for (i
= 0; i
< numfiles
; i
++)
9844 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9846 /* Now write all the file names. */
9847 for (i
= 0; i
< numfiles
; i
++)
9849 int file_idx
= backmap
[i
];
9850 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9852 #ifdef VMS_DEBUGGING_INFO
9853 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9855 /* Setting these fields can lead to debugger miscomparisons,
9856 but VMS Debug requires them to be set correctly. */
9861 int maxfilelen
= strlen (files
[file_idx
].path
)
9862 + dirs
[dir_idx
].length
9863 + MAX_VMS_VERSION_LEN
+ 1;
9864 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9866 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9867 snprintf (filebuf
, maxfilelen
, "%s;%d",
9868 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9870 dw2_asm_output_nstring
9871 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9873 /* Include directory index. */
9874 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9876 /* Modification time. */
9877 dw2_asm_output_data_uleb128
9878 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9882 /* File length in bytes. */
9883 dw2_asm_output_data_uleb128
9884 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9888 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9889 "File Entry: %#x", (unsigned) i
+ 1);
9891 /* Include directory index. */
9892 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9894 /* Modification time. */
9895 dw2_asm_output_data_uleb128 (0, NULL
);
9897 /* File length in bytes. */
9898 dw2_asm_output_data_uleb128 (0, NULL
);
9899 #endif /* VMS_DEBUGGING_INFO */
9902 dw2_asm_output_data (1, 0, "End file name table");
9906 /* Output one line number table into the .debug_line section. */
9909 output_one_line_info_table (dw_line_info_table
*table
)
9911 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9912 unsigned int current_line
= 1;
9913 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9914 dw_line_info_entry
*ent
;
9917 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9919 switch (ent
->opcode
)
9921 case LI_set_address
:
9922 /* ??? Unfortunately, we have little choice here currently, and
9923 must always use the most general form. GCC does not know the
9924 address delta itself, so we can't use DW_LNS_advance_pc. Many
9925 ports do have length attributes which will give an upper bound
9926 on the address range. We could perhaps use length attributes
9927 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9928 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9930 /* This can handle any delta. This takes
9931 4+DWARF2_ADDR_SIZE bytes. */
9932 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9933 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9934 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9935 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9939 if (ent
->val
== current_line
)
9941 /* We still need to start a new row, so output a copy insn. */
9942 dw2_asm_output_data (1, DW_LNS_copy
,
9943 "copy line %u", current_line
);
9947 int line_offset
= ent
->val
- current_line
;
9948 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9950 current_line
= ent
->val
;
9951 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9953 /* This can handle deltas from -10 to 234, using the current
9954 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9955 This takes 1 byte. */
9956 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9957 "line %u", current_line
);
9961 /* This can handle any delta. This takes at least 4 bytes,
9962 depending on the value being encoded. */
9963 dw2_asm_output_data (1, DW_LNS_advance_line
,
9964 "advance to line %u", current_line
);
9965 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9966 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9972 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9973 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9977 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9978 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9981 case LI_negate_stmt
:
9982 current_is_stmt
= !current_is_stmt
;
9983 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9984 "is_stmt %d", current_is_stmt
);
9987 case LI_set_prologue_end
:
9988 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9989 "set prologue end");
9992 case LI_set_epilogue_begin
:
9993 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9994 "set epilogue begin");
9997 case LI_set_discriminator
:
9998 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9999 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10000 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10001 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10006 /* Emit debug info for the address of the end of the table. */
10007 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10008 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10009 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10010 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10012 dw2_asm_output_data (1, 0, "end sequence");
10013 dw2_asm_output_data_uleb128 (1, NULL
);
10014 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10017 /* Output the source line number correspondence information. This
10018 information goes into the .debug_line section. */
10021 output_line_info (bool prologue_only
)
10023 char l1
[20], l2
[20], p1
[20], p2
[20];
10024 int ver
= dwarf_version
;
10025 bool saw_one
= false;
10028 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10029 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10030 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10031 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10033 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10034 dw2_asm_output_data (4, 0xffffffff,
10035 "Initial length escape value indicating 64-bit DWARF extension");
10036 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10037 "Length of Source Line Info");
10038 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10040 dw2_asm_output_data (2, ver
, "DWARF Version");
10041 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10042 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10044 /* Define the architecture-dependent minimum instruction length (in bytes).
10045 In this implementation of DWARF, this field is used for information
10046 purposes only. Since GCC generates assembly language, we have no
10047 a priori knowledge of how many instruction bytes are generated for each
10048 source line, and therefore can use only the DW_LNE_set_address and
10049 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10050 this as '1', which is "correct enough" for all architectures,
10051 and don't let the target override. */
10052 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10055 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10056 "Maximum Operations Per Instruction");
10057 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10058 "Default is_stmt_start flag");
10059 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10060 "Line Base Value (Special Opcodes)");
10061 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10062 "Line Range Value (Special Opcodes)");
10063 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10064 "Special Opcode Base");
10066 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10071 case DW_LNS_advance_pc
:
10072 case DW_LNS_advance_line
:
10073 case DW_LNS_set_file
:
10074 case DW_LNS_set_column
:
10075 case DW_LNS_fixed_advance_pc
:
10076 case DW_LNS_set_isa
:
10084 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10088 /* Write out the information about the files we use. */
10089 output_file_names ();
10090 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10093 /* Output the marker for the end of the line number info. */
10094 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10098 if (separate_line_info
)
10100 dw_line_info_table
*table
;
10103 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10106 output_one_line_info_table (table
);
10110 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10112 output_one_line_info_table (cold_text_section_line_info
);
10116 /* ??? Some Darwin linkers crash on a .debug_line section with no
10117 sequences. Further, merely a DW_LNE_end_sequence entry is not
10118 sufficient -- the address column must also be initialized.
10119 Make sure to output at least one set_address/end_sequence pair,
10120 choosing .text since that section is always present. */
10121 if (text_section_line_info
->in_use
|| !saw_one
)
10122 output_one_line_info_table (text_section_line_info
);
10124 /* Output the marker for the end of the line number info. */
10125 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10128 /* Given a pointer to a tree node for some base type, return a pointer to
10129 a DIE that describes the given type.
10131 This routine must only be called for GCC type nodes that correspond to
10132 Dwarf base (fundamental) types. */
10135 base_type_die (tree type
)
10137 dw_die_ref base_type_result
;
10138 enum dwarf_type encoding
;
10140 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10143 /* If this is a subtype that should not be emitted as a subrange type,
10144 use the base type. See subrange_type_for_debug_p. */
10145 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10146 type
= TREE_TYPE (type
);
10148 switch (TREE_CODE (type
))
10151 if ((dwarf_version
>= 4 || !dwarf_strict
)
10152 && TYPE_NAME (type
)
10153 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10154 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10155 && DECL_NAME (TYPE_NAME (type
)))
10157 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10158 if (strcmp (name
, "char16_t") == 0
10159 || strcmp (name
, "char32_t") == 0)
10161 encoding
= DW_ATE_UTF
;
10165 if (TYPE_STRING_FLAG (type
))
10167 if (TYPE_UNSIGNED (type
))
10168 encoding
= DW_ATE_unsigned_char
;
10170 encoding
= DW_ATE_signed_char
;
10172 else if (TYPE_UNSIGNED (type
))
10173 encoding
= DW_ATE_unsigned
;
10175 encoding
= DW_ATE_signed
;
10179 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10181 if (dwarf_version
>= 3 || !dwarf_strict
)
10182 encoding
= DW_ATE_decimal_float
;
10184 encoding
= DW_ATE_lo_user
;
10187 encoding
= DW_ATE_float
;
10190 case FIXED_POINT_TYPE
:
10191 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10192 encoding
= DW_ATE_lo_user
;
10193 else if (TYPE_UNSIGNED (type
))
10194 encoding
= DW_ATE_unsigned_fixed
;
10196 encoding
= DW_ATE_signed_fixed
;
10199 /* Dwarf2 doesn't know anything about complex ints, so use
10200 a user defined type for it. */
10202 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10203 encoding
= DW_ATE_complex_float
;
10205 encoding
= DW_ATE_lo_user
;
10209 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10210 encoding
= DW_ATE_boolean
;
10214 /* No other TREE_CODEs are Dwarf fundamental types. */
10215 gcc_unreachable ();
10218 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10220 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10221 int_size_in_bytes (type
));
10222 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10223 add_pubtype (type
, base_type_result
);
10225 return base_type_result
;
10228 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10229 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10232 is_base_type (tree type
)
10234 switch (TREE_CODE (type
))
10240 case FIXED_POINT_TYPE
:
10248 case QUAL_UNION_TYPE
:
10249 case ENUMERAL_TYPE
:
10250 case FUNCTION_TYPE
:
10253 case REFERENCE_TYPE
:
10261 gcc_unreachable ();
10267 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10268 node, return the size in bits for the type if it is a constant, or else
10269 return the alignment for the type if the type's size is not constant, or
10270 else return BITS_PER_WORD if the type actually turns out to be an
10271 ERROR_MARK node. */
10273 static inline unsigned HOST_WIDE_INT
10274 simple_type_size_in_bits (const_tree type
)
10276 if (TREE_CODE (type
) == ERROR_MARK
)
10277 return BITS_PER_WORD
;
10278 else if (TYPE_SIZE (type
) == NULL_TREE
)
10280 else if (host_integerp (TYPE_SIZE (type
), 1))
10281 return tree_low_cst (TYPE_SIZE (type
), 1);
10283 return TYPE_ALIGN (type
);
10286 /* Similarly, but return a double_int instead of UHWI. */
10288 static inline double_int
10289 double_int_type_size_in_bits (const_tree type
)
10291 if (TREE_CODE (type
) == ERROR_MARK
)
10292 return double_int::from_uhwi (BITS_PER_WORD
);
10293 else if (TYPE_SIZE (type
) == NULL_TREE
)
10294 return double_int_zero
;
10295 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10296 return tree_to_double_int (TYPE_SIZE (type
));
10298 return double_int::from_uhwi (TYPE_ALIGN (type
));
10301 /* Given a pointer to a tree node for a subrange type, return a pointer
10302 to a DIE that describes the given type. */
10305 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10307 dw_die_ref subrange_die
;
10308 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10310 if (context_die
== NULL
)
10311 context_die
= comp_unit_die ();
10313 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10315 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10317 /* The size of the subrange type and its base type do not match,
10318 so we need to generate a size attribute for the subrange type. */
10319 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10323 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10325 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10327 return subrange_die
;
10330 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10331 entry that chains various modifiers in front of the given type. */
10334 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10335 dw_die_ref context_die
)
10337 enum tree_code code
= TREE_CODE (type
);
10338 dw_die_ref mod_type_die
;
10339 dw_die_ref sub_die
= NULL
;
10340 tree item_type
= NULL
;
10341 tree qualified_type
;
10342 tree name
, low
, high
;
10343 dw_die_ref mod_scope
;
10345 if (code
== ERROR_MARK
)
10348 /* See if we already have the appropriately qualified variant of
10351 = get_qualified_type (type
,
10352 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10353 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10355 if (qualified_type
== sizetype
10356 && TYPE_NAME (qualified_type
)
10357 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10359 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10361 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10362 && TYPE_PRECISION (t
)
10363 == TYPE_PRECISION (qualified_type
)
10364 && TYPE_UNSIGNED (t
)
10365 == TYPE_UNSIGNED (qualified_type
));
10366 qualified_type
= t
;
10369 /* If we do, then we can just use its DIE, if it exists. */
10370 if (qualified_type
)
10372 mod_type_die
= lookup_type_die (qualified_type
);
10374 return mod_type_die
;
10377 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10379 /* Handle C typedef types. */
10380 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10381 && !DECL_ARTIFICIAL (name
))
10383 tree dtype
= TREE_TYPE (name
);
10385 if (qualified_type
== dtype
)
10387 /* For a named type, use the typedef. */
10388 gen_type_die (qualified_type
, context_die
);
10389 return lookup_type_die (qualified_type
);
10391 else if (is_const_type
< TYPE_READONLY (dtype
)
10392 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10393 || (is_const_type
<= TYPE_READONLY (dtype
)
10394 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10395 && DECL_ORIGINAL_TYPE (name
) != type
))
10396 /* cv-unqualified version of named type. Just use the unnamed
10397 type to which it refers. */
10398 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10399 is_const_type
, is_volatile_type
,
10401 /* Else cv-qualified version of named type; fall through. */
10404 mod_scope
= scope_die_for (type
, context_die
);
10407 /* If both is_const_type and is_volatile_type, prefer the path
10408 which leads to a qualified type. */
10409 && (!is_volatile_type
10410 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10411 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10413 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10414 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10416 else if (is_volatile_type
)
10418 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10419 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10421 else if (code
== POINTER_TYPE
)
10423 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10424 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10425 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10426 item_type
= TREE_TYPE (type
);
10427 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10428 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10429 TYPE_ADDR_SPACE (item_type
));
10431 else if (code
== REFERENCE_TYPE
)
10433 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10434 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10437 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10438 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10439 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10440 item_type
= TREE_TYPE (type
);
10441 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10442 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10443 TYPE_ADDR_SPACE (item_type
));
10445 else if (code
== INTEGER_TYPE
10446 && TREE_TYPE (type
) != NULL_TREE
10447 && subrange_type_for_debug_p (type
, &low
, &high
))
10449 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10450 item_type
= TREE_TYPE (type
);
10452 else if (is_base_type (type
))
10453 mod_type_die
= base_type_die (type
);
10456 gen_type_die (type
, context_die
);
10458 /* We have to get the type_main_variant here (and pass that to the
10459 `lookup_type_die' routine) because the ..._TYPE node we have
10460 might simply be a *copy* of some original type node (where the
10461 copy was created to help us keep track of typedef names) and
10462 that copy might have a different TYPE_UID from the original
10464 if (TREE_CODE (type
) != VECTOR_TYPE
)
10465 return lookup_type_die (type_main_variant (type
));
10467 /* Vectors have the debugging information in the type,
10468 not the main variant. */
10469 return lookup_type_die (type
);
10472 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10473 don't output a DW_TAG_typedef, since there isn't one in the
10474 user's program; just attach a DW_AT_name to the type.
10475 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10476 if the base type already has the same name. */
10478 && ((TREE_CODE (name
) != TYPE_DECL
10479 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10480 || (!is_const_type
&& !is_volatile_type
)))
10481 || (TREE_CODE (name
) == TYPE_DECL
10482 && TREE_TYPE (name
) == qualified_type
10483 && DECL_NAME (name
))))
10485 if (TREE_CODE (name
) == TYPE_DECL
)
10486 /* Could just call add_name_and_src_coords_attributes here,
10487 but since this is a builtin type it doesn't have any
10488 useful source coordinates anyway. */
10489 name
= DECL_NAME (name
);
10490 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10492 /* This probably indicates a bug. */
10493 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10495 name
= TYPE_NAME (type
);
10497 && TREE_CODE (name
) == TYPE_DECL
)
10498 name
= DECL_NAME (name
);
10499 add_name_attribute (mod_type_die
,
10500 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10503 if (qualified_type
)
10504 equate_type_number_to_die (qualified_type
, mod_type_die
);
10507 /* We must do this after the equate_type_number_to_die call, in case
10508 this is a recursive type. This ensures that the modified_type_die
10509 recursion will terminate even if the type is recursive. Recursive
10510 types are possible in Ada. */
10511 sub_die
= modified_type_die (item_type
,
10512 TYPE_READONLY (item_type
),
10513 TYPE_VOLATILE (item_type
),
10516 if (sub_die
!= NULL
)
10517 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10519 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10520 if (TYPE_ARTIFICIAL (type
))
10521 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10523 return mod_type_die
;
10526 /* Generate DIEs for the generic parameters of T.
10527 T must be either a generic type or a generic function.
10528 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10531 gen_generic_params_dies (tree t
)
10535 dw_die_ref die
= NULL
;
10537 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10541 die
= lookup_type_die (t
);
10542 else if (DECL_P (t
))
10543 die
= lookup_decl_die (t
);
10547 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10549 /* T has no generic parameter. It means T is neither a generic type
10550 or function. End of story. */
10553 parms_num
= TREE_VEC_LENGTH (parms
);
10554 args
= lang_hooks
.get_innermost_generic_args (t
);
10555 for (i
= 0; i
< parms_num
; i
++)
10557 tree parm
, arg
, arg_pack_elems
;
10559 parm
= TREE_VEC_ELT (parms
, i
);
10560 arg
= TREE_VEC_ELT (args
, i
);
10561 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10562 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10564 if (parm
&& TREE_VALUE (parm
) && arg
)
10566 /* If PARM represents a template parameter pack,
10567 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10568 by DW_TAG_template_*_parameter DIEs for the argument
10569 pack elements of ARG. Note that ARG would then be
10570 an argument pack. */
10571 if (arg_pack_elems
)
10572 template_parameter_pack_die (TREE_VALUE (parm
),
10576 generic_parameter_die (TREE_VALUE (parm
), arg
,
10577 true /* Emit DW_AT_name */, die
);
10582 /* Create and return a DIE for PARM which should be
10583 the representation of a generic type parameter.
10584 For instance, in the C++ front end, PARM would be a template parameter.
10585 ARG is the argument to PARM.
10586 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10588 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10589 as a child node. */
10592 generic_parameter_die (tree parm
, tree arg
,
10594 dw_die_ref parent_die
)
10596 dw_die_ref tmpl_die
= NULL
;
10597 const char *name
= NULL
;
10599 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10602 /* We support non-type generic parameters and arguments,
10603 type generic parameters and arguments, as well as
10604 generic generic parameters (a.k.a. template template parameters in C++)
10606 if (TREE_CODE (parm
) == PARM_DECL
)
10607 /* PARM is a nontype generic parameter */
10608 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10609 else if (TREE_CODE (parm
) == TYPE_DECL
)
10610 /* PARM is a type generic parameter. */
10611 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10612 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10613 /* PARM is a generic generic parameter.
10614 Its DIE is a GNU extension. It shall have a
10615 DW_AT_name attribute to represent the name of the template template
10616 parameter, and a DW_AT_GNU_template_name attribute to represent the
10617 name of the template template argument. */
10618 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10621 gcc_unreachable ();
10627 /* If PARM is a generic parameter pack, it means we are
10628 emitting debug info for a template argument pack element.
10629 In other terms, ARG is a template argument pack element.
10630 In that case, we don't emit any DW_AT_name attribute for
10634 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10636 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10639 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10641 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10642 TMPL_DIE should have a child DW_AT_type attribute that is set
10643 to the type of the argument to PARM, which is ARG.
10644 If PARM is a type generic parameter, TMPL_DIE should have a
10645 child DW_AT_type that is set to ARG. */
10646 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10647 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10648 TREE_THIS_VOLATILE (tmpl_type
),
10653 /* So TMPL_DIE is a DIE representing a
10654 a generic generic template parameter, a.k.a template template
10655 parameter in C++ and arg is a template. */
10657 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10658 to the name of the argument. */
10659 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10661 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10664 if (TREE_CODE (parm
) == PARM_DECL
)
10665 /* So PARM is a non-type generic parameter.
10666 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10667 attribute of TMPL_DIE which value represents the value
10669 We must be careful here:
10670 The value of ARG might reference some function decls.
10671 We might currently be emitting debug info for a generic
10672 type and types are emitted before function decls, we don't
10673 know if the function decls referenced by ARG will actually be
10674 emitted after cgraph computations.
10675 So must defer the generation of the DW_AT_const_value to
10676 after cgraph is ready. */
10677 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10683 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10684 PARM_PACK must be a template parameter pack. The returned DIE
10685 will be child DIE of PARENT_DIE. */
10688 template_parameter_pack_die (tree parm_pack
,
10689 tree parm_pack_args
,
10690 dw_die_ref parent_die
)
10695 gcc_assert (parent_die
&& parm_pack
);
10697 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10698 add_name_and_src_coords_attributes (die
, parm_pack
);
10699 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10700 generic_parameter_die (parm_pack
,
10701 TREE_VEC_ELT (parm_pack_args
, j
),
10702 false /* Don't emit DW_AT_name */,
10707 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10708 an enumerated type. */
10711 type_is_enum (const_tree type
)
10713 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10716 /* Return the DBX register number described by a given RTL node. */
10718 static unsigned int
10719 dbx_reg_number (const_rtx rtl
)
10721 unsigned regno
= REGNO (rtl
);
10723 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10725 #ifdef LEAF_REG_REMAP
10726 if (crtl
->uses_only_leaf_regs
)
10728 int leaf_reg
= LEAF_REG_REMAP (regno
);
10729 if (leaf_reg
!= -1)
10730 regno
= (unsigned) leaf_reg
;
10734 regno
= DBX_REGISTER_NUMBER (regno
);
10735 gcc_assert (regno
!= INVALID_REGNUM
);
10739 /* Optionally add a DW_OP_piece term to a location description expression.
10740 DW_OP_piece is only added if the location description expression already
10741 doesn't end with DW_OP_piece. */
10744 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10746 dw_loc_descr_ref loc
;
10748 if (*list_head
!= NULL
)
10750 /* Find the end of the chain. */
10751 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10754 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10755 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10759 /* Return a location descriptor that designates a machine register or
10760 zero if there is none. */
10762 static dw_loc_descr_ref
10763 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10767 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10770 /* We only use "frame base" when we're sure we're talking about the
10771 post-prologue local stack frame. We do this by *not* running
10772 register elimination until this point, and recognizing the special
10773 argument pointer and soft frame pointer rtx's.
10774 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10775 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10776 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10778 dw_loc_descr_ref result
= NULL
;
10780 if (dwarf_version
>= 4 || !dwarf_strict
)
10782 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10785 add_loc_descr (&result
,
10786 new_loc_descr (DW_OP_stack_value
, 0, 0));
10791 regs
= targetm
.dwarf_register_span (rtl
);
10793 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10794 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10797 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10798 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10800 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10804 /* Return a location descriptor that designates a machine register for
10805 a given hard register number. */
10807 static dw_loc_descr_ref
10808 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10810 dw_loc_descr_ref reg_loc_descr
;
10814 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10816 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10818 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10819 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10821 return reg_loc_descr
;
10824 /* Given an RTL of a register, return a location descriptor that
10825 designates a value that spans more than one register. */
10827 static dw_loc_descr_ref
10828 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10829 enum var_init_status initialized
)
10831 int nregs
, size
, i
;
10833 dw_loc_descr_ref loc_result
= NULL
;
10836 #ifdef LEAF_REG_REMAP
10837 if (crtl
->uses_only_leaf_regs
)
10839 int leaf_reg
= LEAF_REG_REMAP (reg
);
10840 if (leaf_reg
!= -1)
10841 reg
= (unsigned) leaf_reg
;
10844 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10845 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10847 /* Simple, contiguous registers. */
10848 if (regs
== NULL_RTX
)
10850 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10855 dw_loc_descr_ref t
;
10857 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10858 VAR_INIT_STATUS_INITIALIZED
);
10859 add_loc_descr (&loc_result
, t
);
10860 add_loc_descr_op_piece (&loc_result
, size
);
10866 /* Now onto stupid register sets in non contiguous locations. */
10868 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10870 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10873 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10875 dw_loc_descr_ref t
;
10877 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
10878 VAR_INIT_STATUS_INITIALIZED
);
10879 add_loc_descr (&loc_result
, t
);
10880 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10881 add_loc_descr_op_piece (&loc_result
, size
);
10884 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10885 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10889 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10891 /* Return a location descriptor that designates a constant i,
10892 as a compound operation from constant (i >> shift), constant shift
10895 static dw_loc_descr_ref
10896 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10898 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10899 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10900 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10904 /* Return a location descriptor that designates a constant. */
10906 static dw_loc_descr_ref
10907 int_loc_descriptor (HOST_WIDE_INT i
)
10909 enum dwarf_location_atom op
;
10911 /* Pick the smallest representation of a constant, rather than just
10912 defaulting to the LEB encoding. */
10915 int clz
= clz_hwi (i
);
10916 int ctz
= ctz_hwi (i
);
10918 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10919 else if (i
<= 0xff)
10920 op
= DW_OP_const1u
;
10921 else if (i
<= 0xffff)
10922 op
= DW_OP_const2u
;
10923 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10924 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10925 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10926 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10927 while DW_OP_const4u is 5 bytes. */
10928 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10929 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10930 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10931 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10932 while DW_OP_const4u is 5 bytes. */
10933 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10934 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10935 op
= DW_OP_const4u
;
10936 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10937 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10938 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10939 while DW_OP_constu of constant >= 0x100000000 takes at least
10941 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10942 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10943 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10944 >= HOST_BITS_PER_WIDE_INT
)
10945 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10946 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10947 while DW_OP_constu takes in this case at least 6 bytes. */
10948 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10949 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10950 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10951 && size_of_uleb128 (i
) > 6)
10952 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10953 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10960 op
= DW_OP_const1s
;
10961 else if (i
>= -0x8000)
10962 op
= DW_OP_const2s
;
10963 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10965 if (size_of_int_loc_descriptor (i
) < 5)
10967 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10968 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10971 op
= DW_OP_const4s
;
10975 if (size_of_int_loc_descriptor (i
)
10976 < (unsigned long) 1 + size_of_sleb128 (i
))
10978 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10979 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10986 return new_loc_descr (op
, i
, 0);
10989 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10990 without actually allocating it. */
10992 static unsigned long
10993 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10995 return size_of_int_loc_descriptor (i
>> shift
)
10996 + size_of_int_loc_descriptor (shift
)
11000 /* Return size_of_locs (int_loc_descriptor (i)) without
11001 actually allocating it. */
11003 static unsigned long
11004 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11013 else if (i
<= 0xff)
11015 else if (i
<= 0xffff)
11019 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11020 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11021 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11023 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11024 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11025 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11027 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11029 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11030 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11031 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11032 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11034 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11035 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11036 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11038 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11039 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11041 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11050 else if (i
>= -0x8000)
11052 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11054 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11056 s
= size_of_int_loc_descriptor (-i
) + 1;
11064 unsigned long r
= 1 + size_of_sleb128 (i
);
11065 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11067 s
= size_of_int_loc_descriptor (-i
) + 1;
11076 /* Return loc description representing "address" of integer value.
11077 This can appear only as toplevel expression. */
11079 static dw_loc_descr_ref
11080 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11083 dw_loc_descr_ref loc_result
= NULL
;
11085 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11088 litsize
= size_of_int_loc_descriptor (i
);
11089 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11090 is more compact. For DW_OP_stack_value we need:
11091 litsize + 1 (DW_OP_stack_value)
11092 and for DW_OP_implicit_value:
11093 1 (DW_OP_implicit_value) + 1 (length) + size. */
11094 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11096 loc_result
= int_loc_descriptor (i
);
11097 add_loc_descr (&loc_result
,
11098 new_loc_descr (DW_OP_stack_value
, 0, 0));
11102 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11104 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11105 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11109 /* Return a location descriptor that designates a base+offset location. */
11111 static dw_loc_descr_ref
11112 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11113 enum var_init_status initialized
)
11115 unsigned int regno
;
11116 dw_loc_descr_ref result
;
11117 dw_fde_ref fde
= cfun
->fde
;
11119 /* We only use "frame base" when we're sure we're talking about the
11120 post-prologue local stack frame. We do this by *not* running
11121 register elimination until this point, and recognizing the special
11122 argument pointer and soft frame pointer rtx's. */
11123 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11125 rtx elim
= (ira_use_lra_p
11126 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11127 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11131 if (GET_CODE (elim
) == PLUS
)
11133 offset
+= INTVAL (XEXP (elim
, 1));
11134 elim
= XEXP (elim
, 0);
11136 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11137 && (elim
== hard_frame_pointer_rtx
11138 || elim
== stack_pointer_rtx
))
11139 || elim
== (frame_pointer_needed
11140 ? hard_frame_pointer_rtx
11141 : stack_pointer_rtx
));
11143 /* If drap register is used to align stack, use frame
11144 pointer + offset to access stack variables. If stack
11145 is aligned without drap, use stack pointer + offset to
11146 access stack variables. */
11147 if (crtl
->stack_realign_tried
11148 && reg
== frame_pointer_rtx
)
11151 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11152 ? HARD_FRAME_POINTER_REGNUM
11154 return new_reg_loc_descr (base_reg
, offset
);
11157 gcc_assert (frame_pointer_fb_offset_valid
);
11158 offset
+= frame_pointer_fb_offset
;
11159 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11163 regno
= REGNO (reg
);
11164 #ifdef LEAF_REG_REMAP
11165 if (crtl
->uses_only_leaf_regs
)
11167 int leaf_reg
= LEAF_REG_REMAP (regno
);
11168 if (leaf_reg
!= -1)
11169 regno
= (unsigned) leaf_reg
;
11172 regno
= DWARF_FRAME_REGNUM (regno
);
11174 if (!optimize
&& fde
11175 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11177 /* Use cfa+offset to represent the location of arguments passed
11178 on the stack when drap is used to align stack.
11179 Only do this when not optimizing, for optimized code var-tracking
11180 is supposed to track where the arguments live and the register
11181 used as vdrap or drap in some spot might be used for something
11182 else in other part of the routine. */
11183 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11187 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11190 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11192 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11193 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11198 /* Return true if this RTL expression describes a base+offset calculation. */
11201 is_based_loc (const_rtx rtl
)
11203 return (GET_CODE (rtl
) == PLUS
11204 && ((REG_P (XEXP (rtl
, 0))
11205 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11206 && CONST_INT_P (XEXP (rtl
, 1)))));
11209 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11212 static dw_loc_descr_ref
11213 tls_mem_loc_descriptor (rtx mem
)
11216 dw_loc_descr_ref loc_result
;
11218 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11221 base
= get_base_address (MEM_EXPR (mem
));
11223 || TREE_CODE (base
) != VAR_DECL
11224 || !DECL_THREAD_LOCAL_P (base
))
11227 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11228 if (loc_result
== NULL
)
11231 if (MEM_OFFSET (mem
))
11232 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11237 /* Output debug info about reason why we failed to expand expression as dwarf
11241 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11243 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11245 fprintf (dump_file
, "Failed to expand as dwarf: ");
11247 print_generic_expr (dump_file
, expr
, dump_flags
);
11250 fprintf (dump_file
, "\n");
11251 print_rtl (dump_file
, rtl
);
11253 fprintf (dump_file
, "\nReason: %s\n", reason
);
11257 /* Helper function for const_ok_for_output, called either directly
11258 or via for_each_rtx. */
11261 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11265 if (GET_CODE (rtl
) == UNSPEC
)
11267 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11268 we can't express it in the debug info. */
11269 #ifdef ENABLE_CHECKING
11270 /* Don't complain about TLS UNSPECs, those are just too hard to
11271 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11272 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11273 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11274 if (XVECLEN (rtl
, 0) == 0
11275 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11276 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11277 inform (current_function_decl
11278 ? DECL_SOURCE_LOCATION (current_function_decl
)
11279 : UNKNOWN_LOCATION
,
11280 #if NUM_UNSPEC_VALUES > 0
11281 "non-delegitimized UNSPEC %s (%d) found in variable location",
11282 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11283 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11286 "non-delegitimized UNSPEC %d found in variable location",
11290 expansion_failed (NULL_TREE
, rtl
,
11291 "UNSPEC hasn't been delegitimized.\n");
11295 if (targetm
.const_not_ok_for_debug_p (rtl
))
11297 expansion_failed (NULL_TREE
, rtl
,
11298 "Expression rejected for debug by the backend.\n");
11302 if (GET_CODE (rtl
) != SYMBOL_REF
)
11305 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11308 get_pool_constant_mark (rtl
, &marked
);
11309 /* If all references to this pool constant were optimized away,
11310 it was not output and thus we can't represent it. */
11313 expansion_failed (NULL_TREE
, rtl
,
11314 "Constant was removed from constant pool.\n");
11319 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11322 /* Avoid references to external symbols in debug info, on several targets
11323 the linker might even refuse to link when linking a shared library,
11324 and in many other cases the relocations for .debug_info/.debug_loc are
11325 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11326 to be defined within the same shared library or executable are fine. */
11327 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11329 tree decl
= SYMBOL_REF_DECL (rtl
);
11331 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11333 expansion_failed (NULL_TREE
, rtl
,
11334 "Symbol not defined in current TU.\n");
11342 /* Return true if constant RTL can be emitted in DW_OP_addr or
11343 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11344 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11347 const_ok_for_output (rtx rtl
)
11349 if (GET_CODE (rtl
) == SYMBOL_REF
)
11350 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11352 if (GET_CODE (rtl
) == CONST
)
11353 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11358 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11359 if possible, NULL otherwise. */
11362 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11364 dw_die_ref type_die
;
11365 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11369 switch (TREE_CODE (type
))
11377 type_die
= lookup_type_die (type
);
11379 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11380 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11385 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11386 type matching MODE, or, if MODE is narrower than or as wide as
11387 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11390 static dw_loc_descr_ref
11391 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11393 enum machine_mode outer_mode
= mode
;
11394 dw_die_ref type_die
;
11395 dw_loc_descr_ref cvt
;
11397 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11399 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11402 type_die
= base_type_for_mode (outer_mode
, 1);
11403 if (type_die
== NULL
)
11405 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11406 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11407 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11408 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11409 add_loc_descr (&op
, cvt
);
11413 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11415 static dw_loc_descr_ref
11416 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11417 dw_loc_descr_ref op1
)
11419 dw_loc_descr_ref ret
= op0
;
11420 add_loc_descr (&ret
, op1
);
11421 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11422 if (STORE_FLAG_VALUE
!= 1)
11424 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11425 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11430 /* Return location descriptor for signed comparison OP RTL. */
11432 static dw_loc_descr_ref
11433 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11434 enum machine_mode mem_mode
)
11436 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11437 dw_loc_descr_ref op0
, op1
;
11440 if (op_mode
== VOIDmode
)
11441 op_mode
= GET_MODE (XEXP (rtl
, 1));
11442 if (op_mode
== VOIDmode
)
11446 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11447 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11450 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11451 VAR_INIT_STATUS_INITIALIZED
);
11452 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11453 VAR_INIT_STATUS_INITIALIZED
);
11455 if (op0
== NULL
|| op1
== NULL
)
11458 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11459 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11460 return compare_loc_descriptor (op
, op0
, op1
);
11462 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11464 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11465 dw_loc_descr_ref cvt
;
11467 if (type_die
== NULL
)
11469 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11470 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11471 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11472 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11473 add_loc_descr (&op0
, cvt
);
11474 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11475 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11476 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11477 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11478 add_loc_descr (&op1
, cvt
);
11479 return compare_loc_descriptor (op
, op0
, op1
);
11482 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11483 /* For eq/ne, if the operands are known to be zero-extended,
11484 there is no need to do the fancy shifting up. */
11485 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11487 dw_loc_descr_ref last0
, last1
;
11488 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11490 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11492 /* deref_size zero extends, and for constants we can check
11493 whether they are zero extended or not. */
11494 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11495 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11496 || (CONST_INT_P (XEXP (rtl
, 0))
11497 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11498 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11499 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11500 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11501 || (CONST_INT_P (XEXP (rtl
, 1))
11502 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11503 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11504 return compare_loc_descriptor (op
, op0
, op1
);
11506 /* EQ/NE comparison against constant in narrower type than
11507 DWARF2_ADDR_SIZE can be performed either as
11508 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11511 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11512 DW_OP_{eq,ne}. Pick whatever is shorter. */
11513 if (CONST_INT_P (XEXP (rtl
, 1))
11514 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11515 && (size_of_int_loc_descriptor (shift
) + 1
11516 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11517 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11518 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11519 & GET_MODE_MASK (op_mode
))))
11521 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11522 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11523 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11524 & GET_MODE_MASK (op_mode
));
11525 return compare_loc_descriptor (op
, op0
, op1
);
11528 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11529 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11530 if (CONST_INT_P (XEXP (rtl
, 1)))
11531 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11534 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11535 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11537 return compare_loc_descriptor (op
, op0
, op1
);
11540 /* Return location descriptor for unsigned comparison OP RTL. */
11542 static dw_loc_descr_ref
11543 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11544 enum machine_mode mem_mode
)
11546 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11547 dw_loc_descr_ref op0
, op1
;
11549 if (op_mode
== VOIDmode
)
11550 op_mode
= GET_MODE (XEXP (rtl
, 1));
11551 if (op_mode
== VOIDmode
)
11553 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11556 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11559 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11560 VAR_INIT_STATUS_INITIALIZED
);
11561 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11562 VAR_INIT_STATUS_INITIALIZED
);
11564 if (op0
== NULL
|| op1
== NULL
)
11567 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11569 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11570 dw_loc_descr_ref last0
, last1
;
11571 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11573 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11575 if (CONST_INT_P (XEXP (rtl
, 0)))
11576 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11577 /* deref_size zero extends, so no need to mask it again. */
11578 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11579 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11581 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11582 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11584 if (CONST_INT_P (XEXP (rtl
, 1)))
11585 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11586 /* deref_size zero extends, so no need to mask it again. */
11587 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11588 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11590 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11591 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11594 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11596 HOST_WIDE_INT bias
= 1;
11597 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11598 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11599 if (CONST_INT_P (XEXP (rtl
, 1)))
11600 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11601 + INTVAL (XEXP (rtl
, 1)));
11603 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11606 return compare_loc_descriptor (op
, op0
, op1
);
11609 /* Return location descriptor for {U,S}{MIN,MAX}. */
11611 static dw_loc_descr_ref
11612 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11613 enum machine_mode mem_mode
)
11615 enum dwarf_location_atom op
;
11616 dw_loc_descr_ref op0
, op1
, ret
;
11617 dw_loc_descr_ref bra_node
, drop_node
;
11620 && (GET_MODE_CLASS (mode
) != MODE_INT
11621 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11624 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11625 VAR_INIT_STATUS_INITIALIZED
);
11626 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11627 VAR_INIT_STATUS_INITIALIZED
);
11629 if (op0
== NULL
|| op1
== NULL
)
11632 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11633 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11634 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11635 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11637 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11639 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11640 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11641 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11642 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11643 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11645 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11647 HOST_WIDE_INT bias
= 1;
11648 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11649 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11650 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11653 else if (GET_MODE_CLASS (mode
) == MODE_INT
11654 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11656 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11657 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11658 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11659 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11660 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11662 else if (GET_MODE_CLASS (mode
) == MODE_INT
11663 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11665 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11666 dw_loc_descr_ref cvt
;
11667 if (type_die
== NULL
)
11669 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11670 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11671 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11672 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11673 add_loc_descr (&op0
, cvt
);
11674 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11675 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11676 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11677 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11678 add_loc_descr (&op1
, cvt
);
11681 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11686 add_loc_descr (&ret
, op1
);
11687 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11688 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11689 add_loc_descr (&ret
, bra_node
);
11690 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11691 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11692 add_loc_descr (&ret
, drop_node
);
11693 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11694 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11695 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11696 && GET_MODE_CLASS (mode
) == MODE_INT
11697 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11698 ret
= convert_descriptor_to_mode (mode
, ret
);
11702 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11703 but after converting arguments to type_die, afterwards
11704 convert back to unsigned. */
11706 static dw_loc_descr_ref
11707 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11708 enum machine_mode mode
, enum machine_mode mem_mode
)
11710 dw_loc_descr_ref cvt
, op0
, op1
;
11712 if (type_die
== NULL
)
11714 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11715 VAR_INIT_STATUS_INITIALIZED
);
11716 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11717 VAR_INIT_STATUS_INITIALIZED
);
11718 if (op0
== NULL
|| op1
== NULL
)
11720 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11721 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11722 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11723 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11724 add_loc_descr (&op0
, cvt
);
11725 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11726 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11727 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11728 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11729 add_loc_descr (&op1
, cvt
);
11730 add_loc_descr (&op0
, op1
);
11731 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11732 return convert_descriptor_to_mode (mode
, op0
);
11735 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11736 const0 is DW_OP_lit0 or corresponding typed constant,
11737 const1 is DW_OP_lit1 or corresponding typed constant
11738 and constMSB is constant with just the MSB bit set
11740 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11741 L1: const0 DW_OP_swap
11742 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11743 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11748 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11749 L1: const0 DW_OP_swap
11750 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11751 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11756 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11757 L1: const1 DW_OP_swap
11758 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11759 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11763 static dw_loc_descr_ref
11764 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11765 enum machine_mode mem_mode
)
11767 dw_loc_descr_ref op0
, ret
, tmp
;
11768 HOST_WIDE_INT valv
;
11769 dw_loc_descr_ref l1jump
, l1label
;
11770 dw_loc_descr_ref l2jump
, l2label
;
11771 dw_loc_descr_ref l3jump
, l3label
;
11772 dw_loc_descr_ref l4jump
, l4label
;
11775 if (GET_MODE_CLASS (mode
) != MODE_INT
11776 || GET_MODE (XEXP (rtl
, 0)) != mode
11777 || (GET_CODE (rtl
) == CLZ
11778 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11781 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11782 VAR_INIT_STATUS_INITIALIZED
);
11786 if (GET_CODE (rtl
) == CLZ
)
11788 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11789 valv
= GET_MODE_BITSIZE (mode
);
11791 else if (GET_CODE (rtl
) == FFS
)
11793 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11794 valv
= GET_MODE_BITSIZE (mode
);
11795 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11796 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11797 add_loc_descr (&ret
, l1jump
);
11798 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11799 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11800 VAR_INIT_STATUS_INITIALIZED
);
11803 add_loc_descr (&ret
, tmp
);
11804 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11805 add_loc_descr (&ret
, l4jump
);
11806 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11807 ? const1_rtx
: const0_rtx
,
11809 VAR_INIT_STATUS_INITIALIZED
);
11810 if (l1label
== NULL
)
11812 add_loc_descr (&ret
, l1label
);
11813 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11814 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11815 add_loc_descr (&ret
, l2label
);
11816 if (GET_CODE (rtl
) != CLZ
)
11818 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11819 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11820 << (GET_MODE_BITSIZE (mode
) - 1));
11822 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11823 << (GET_MODE_BITSIZE (mode
)
11824 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11825 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11826 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11827 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11828 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11830 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11831 VAR_INIT_STATUS_INITIALIZED
);
11834 add_loc_descr (&ret
, tmp
);
11835 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11836 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11837 add_loc_descr (&ret
, l3jump
);
11838 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11839 VAR_INIT_STATUS_INITIALIZED
);
11842 add_loc_descr (&ret
, tmp
);
11843 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11844 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11845 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11846 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11847 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11848 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11849 add_loc_descr (&ret
, l2jump
);
11850 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11851 add_loc_descr (&ret
, l3label
);
11852 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11853 add_loc_descr (&ret
, l4label
);
11854 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11855 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11856 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11857 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11858 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11859 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11860 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11861 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11865 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11866 const1 is DW_OP_lit1 or corresponding typed constant):
11868 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11869 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11873 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11874 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11877 static dw_loc_descr_ref
11878 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11879 enum machine_mode mem_mode
)
11881 dw_loc_descr_ref op0
, ret
, tmp
;
11882 dw_loc_descr_ref l1jump
, l1label
;
11883 dw_loc_descr_ref l2jump
, l2label
;
11885 if (GET_MODE_CLASS (mode
) != MODE_INT
11886 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11889 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11890 VAR_INIT_STATUS_INITIALIZED
);
11894 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11895 VAR_INIT_STATUS_INITIALIZED
);
11898 add_loc_descr (&ret
, tmp
);
11899 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11900 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11901 add_loc_descr (&ret
, l1label
);
11902 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11903 add_loc_descr (&ret
, l2jump
);
11904 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11905 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11906 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11907 VAR_INIT_STATUS_INITIALIZED
);
11910 add_loc_descr (&ret
, tmp
);
11911 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11912 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11913 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11914 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11915 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11916 VAR_INIT_STATUS_INITIALIZED
);
11917 add_loc_descr (&ret
, tmp
);
11918 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11919 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11920 add_loc_descr (&ret
, l1jump
);
11921 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11922 add_loc_descr (&ret
, l2label
);
11923 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11924 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11925 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11926 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11930 /* BSWAP (constS is initial shift count, either 56 or 24):
11932 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11933 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11934 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11935 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11936 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11938 static dw_loc_descr_ref
11939 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11940 enum machine_mode mem_mode
)
11942 dw_loc_descr_ref op0
, ret
, tmp
;
11943 dw_loc_descr_ref l1jump
, l1label
;
11944 dw_loc_descr_ref l2jump
, l2label
;
11946 if (GET_MODE_CLASS (mode
) != MODE_INT
11947 || BITS_PER_UNIT
!= 8
11948 || (GET_MODE_BITSIZE (mode
) != 32
11949 && GET_MODE_BITSIZE (mode
) != 64))
11952 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11953 VAR_INIT_STATUS_INITIALIZED
);
11958 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11960 VAR_INIT_STATUS_INITIALIZED
);
11963 add_loc_descr (&ret
, tmp
);
11964 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11965 VAR_INIT_STATUS_INITIALIZED
);
11968 add_loc_descr (&ret
, tmp
);
11969 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11970 add_loc_descr (&ret
, l1label
);
11971 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11973 VAR_INIT_STATUS_INITIALIZED
);
11974 add_loc_descr (&ret
, tmp
);
11975 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11976 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11977 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11978 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11979 VAR_INIT_STATUS_INITIALIZED
);
11982 add_loc_descr (&ret
, tmp
);
11983 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11984 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11985 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11986 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11987 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11988 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11989 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11990 VAR_INIT_STATUS_INITIALIZED
);
11991 add_loc_descr (&ret
, tmp
);
11992 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11993 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11994 add_loc_descr (&ret
, l2jump
);
11995 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11996 VAR_INIT_STATUS_INITIALIZED
);
11997 add_loc_descr (&ret
, tmp
);
11998 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11999 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12000 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12001 add_loc_descr (&ret
, l1jump
);
12002 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12003 add_loc_descr (&ret
, l2label
);
12004 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12005 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12006 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12007 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12008 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12009 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12013 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12014 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12015 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12016 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12018 ROTATERT is similar:
12019 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12020 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12021 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12023 static dw_loc_descr_ref
12024 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12025 enum machine_mode mem_mode
)
12027 rtx rtlop1
= XEXP (rtl
, 1);
12028 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12031 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12034 if (GET_MODE (rtlop1
) != VOIDmode
12035 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12036 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12037 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12038 VAR_INIT_STATUS_INITIALIZED
);
12039 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12040 VAR_INIT_STATUS_INITIALIZED
);
12041 if (op0
== NULL
|| op1
== NULL
)
12043 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12044 for (i
= 0; i
< 2; i
++)
12046 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12047 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12049 VAR_INIT_STATUS_INITIALIZED
);
12050 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12051 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12053 : HOST_BITS_PER_WIDE_INT
== 64
12054 ? DW_OP_const8u
: DW_OP_constu
,
12055 GET_MODE_MASK (mode
), 0);
12058 if (mask
[i
] == NULL
)
12060 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12063 add_loc_descr (&ret
, op1
);
12064 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12065 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12066 if (GET_CODE (rtl
) == ROTATERT
)
12068 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12069 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12070 GET_MODE_BITSIZE (mode
), 0));
12072 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12073 if (mask
[0] != NULL
)
12074 add_loc_descr (&ret
, mask
[0]);
12075 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12076 if (mask
[1] != NULL
)
12078 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12079 add_loc_descr (&ret
, mask
[1]);
12080 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12082 if (GET_CODE (rtl
) == ROTATE
)
12084 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12085 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12086 GET_MODE_BITSIZE (mode
), 0));
12088 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12089 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12093 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12094 for DEBUG_PARAMETER_REF RTL. */
12096 static dw_loc_descr_ref
12097 parameter_ref_descriptor (rtx rtl
)
12099 dw_loc_descr_ref ret
;
12104 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12105 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12106 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12109 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12110 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12111 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12115 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12116 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12121 /* The following routine converts the RTL for a variable or parameter
12122 (resident in memory) into an equivalent Dwarf representation of a
12123 mechanism for getting the address of that same variable onto the top of a
12124 hypothetical "address evaluation" stack.
12126 When creating memory location descriptors, we are effectively transforming
12127 the RTL for a memory-resident object into its Dwarf postfix expression
12128 equivalent. This routine recursively descends an RTL tree, turning
12129 it into Dwarf postfix code as it goes.
12131 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12133 MEM_MODE is the mode of the memory reference, needed to handle some
12134 autoincrement addressing modes.
12136 Return 0 if we can't represent the location. */
12139 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12140 enum machine_mode mem_mode
,
12141 enum var_init_status initialized
)
12143 dw_loc_descr_ref mem_loc_result
= NULL
;
12144 enum dwarf_location_atom op
;
12145 dw_loc_descr_ref op0
, op1
;
12146 rtx inner
= NULL_RTX
;
12148 if (mode
== VOIDmode
)
12149 mode
= GET_MODE (rtl
);
12151 /* Note that for a dynamically sized array, the location we will generate a
12152 description of here will be the lowest numbered location which is
12153 actually within the array. That's *not* necessarily the same as the
12154 zeroth element of the array. */
12156 rtl
= targetm
.delegitimize_address (rtl
);
12158 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12161 switch (GET_CODE (rtl
))
12166 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12169 /* The case of a subreg may arise when we have a local (register)
12170 variable or a formal (register) parameter which doesn't quite fill
12171 up an entire register. For now, just assume that it is
12172 legitimate to make the Dwarf info refer to the whole register which
12173 contains the given subreg. */
12174 if (!subreg_lowpart_p (rtl
))
12176 inner
= SUBREG_REG (rtl
);
12178 if (inner
== NULL_RTX
)
12179 inner
= XEXP (rtl
, 0);
12180 if (GET_MODE_CLASS (mode
) == MODE_INT
12181 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12182 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12183 #ifdef POINTERS_EXTEND_UNSIGNED
12184 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12187 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12189 mem_loc_result
= mem_loc_descriptor (inner
,
12191 mem_mode
, initialized
);
12196 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12198 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12199 && (GET_MODE_CLASS (mode
) != MODE_INT
12200 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12204 dw_die_ref type_die
;
12205 dw_loc_descr_ref cvt
;
12207 mem_loc_result
= mem_loc_descriptor (inner
,
12209 mem_mode
, initialized
);
12210 if (mem_loc_result
== NULL
)
12212 type_die
= base_type_for_mode (mode
,
12213 GET_MODE_CLASS (mode
) == MODE_INT
);
12214 if (type_die
== NULL
)
12216 mem_loc_result
= NULL
;
12219 if (GET_MODE_SIZE (mode
)
12220 != GET_MODE_SIZE (GET_MODE (inner
)))
12221 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12223 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12224 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12225 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12226 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12227 add_loc_descr (&mem_loc_result
, cvt
);
12232 if (GET_MODE_CLASS (mode
) != MODE_INT
12233 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12234 && rtl
!= arg_pointer_rtx
12235 && rtl
!= frame_pointer_rtx
12236 #ifdef POINTERS_EXTEND_UNSIGNED
12237 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12241 dw_die_ref type_die
;
12242 unsigned int dbx_regnum
;
12246 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12248 type_die
= base_type_for_mode (mode
,
12249 GET_MODE_CLASS (mode
) == MODE_INT
);
12250 if (type_die
== NULL
)
12253 dbx_regnum
= dbx_reg_number (rtl
);
12254 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12256 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12258 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12259 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12260 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12263 /* Whenever a register number forms a part of the description of the
12264 method for calculating the (dynamic) address of a memory resident
12265 object, DWARF rules require the register number be referred to as
12266 a "base register". This distinction is not based in any way upon
12267 what category of register the hardware believes the given register
12268 belongs to. This is strictly DWARF terminology we're dealing with
12269 here. Note that in cases where the location of a memory-resident
12270 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12271 OP_CONST (0)) the actual DWARF location descriptor that we generate
12272 may just be OP_BASEREG (basereg). This may look deceptively like
12273 the object in question was allocated to a register (rather than in
12274 memory) so DWARF consumers need to be aware of the subtle
12275 distinction between OP_REG and OP_BASEREG. */
12276 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12277 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12278 else if (stack_realign_drap
12280 && crtl
->args
.internal_arg_pointer
== rtl
12281 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12283 /* If RTL is internal_arg_pointer, which has been optimized
12284 out, use DRAP instead. */
12285 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12286 VAR_INIT_STATUS_INITIALIZED
);
12292 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12294 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12295 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12298 else if (GET_CODE (rtl
) == ZERO_EXTEND
12299 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12300 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12301 < HOST_BITS_PER_WIDE_INT
12302 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12303 to expand zero extend as two shifts instead of
12305 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12307 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12308 mem_loc_result
= op0
;
12309 add_loc_descr (&mem_loc_result
,
12310 int_loc_descriptor (GET_MODE_MASK (imode
)));
12311 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12313 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12315 int shift
= DWARF2_ADDR_SIZE
12316 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12317 shift
*= BITS_PER_UNIT
;
12318 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12322 mem_loc_result
= op0
;
12323 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12324 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12325 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12326 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12328 else if (!dwarf_strict
)
12330 dw_die_ref type_die1
, type_die2
;
12331 dw_loc_descr_ref cvt
;
12333 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12334 GET_CODE (rtl
) == ZERO_EXTEND
);
12335 if (type_die1
== NULL
)
12337 type_die2
= base_type_for_mode (mode
, 1);
12338 if (type_die2
== NULL
)
12340 mem_loc_result
= op0
;
12341 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12342 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12343 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12344 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12345 add_loc_descr (&mem_loc_result
, cvt
);
12346 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12347 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12348 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12349 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12350 add_loc_descr (&mem_loc_result
, cvt
);
12356 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12357 if (new_rtl
!= rtl
)
12359 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12361 if (mem_loc_result
!= NULL
)
12362 return mem_loc_result
;
12365 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12366 get_address_mode (rtl
), mode
,
12367 VAR_INIT_STATUS_INITIALIZED
);
12368 if (mem_loc_result
== NULL
)
12369 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12370 if (mem_loc_result
!= NULL
)
12372 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12373 || GET_MODE_CLASS (mode
) != MODE_INT
)
12375 dw_die_ref type_die
;
12376 dw_loc_descr_ref deref
;
12381 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12382 if (type_die
== NULL
)
12384 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12385 GET_MODE_SIZE (mode
), 0);
12386 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12387 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12388 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12389 add_loc_descr (&mem_loc_result
, deref
);
12391 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12392 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12394 add_loc_descr (&mem_loc_result
,
12395 new_loc_descr (DW_OP_deref_size
,
12396 GET_MODE_SIZE (mode
), 0));
12401 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12404 /* Some ports can transform a symbol ref into a label ref, because
12405 the symbol ref is too far away and has to be dumped into a constant
12409 if (GET_MODE_CLASS (mode
) != MODE_INT
12410 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12411 #ifdef POINTERS_EXTEND_UNSIGNED
12412 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12416 if (GET_CODE (rtl
) == SYMBOL_REF
12417 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12419 dw_loc_descr_ref temp
;
12421 /* If this is not defined, we have no way to emit the data. */
12422 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12425 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12427 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12428 add_loc_descr (&mem_loc_result
, temp
);
12433 if (!const_ok_for_output (rtl
))
12437 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12438 vec_safe_push (used_rtx_array
, rtl
);
12444 case DEBUG_IMPLICIT_PTR
:
12445 expansion_failed (NULL_TREE
, rtl
,
12446 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12452 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12454 if (GET_MODE_CLASS (mode
) != MODE_INT
12455 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12456 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12457 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12460 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12461 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12463 op0
= one_reg_loc_descriptor (dbx_regnum
,
12464 VAR_INIT_STATUS_INITIALIZED
);
12467 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12468 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12470 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12471 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12472 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12476 gcc_unreachable ();
12479 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12480 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12481 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12484 case DEBUG_PARAMETER_REF
:
12485 mem_loc_result
= parameter_ref_descriptor (rtl
);
12489 /* Extract the PLUS expression nested inside and fall into
12490 PLUS code below. */
12491 rtl
= XEXP (rtl
, 1);
12496 /* Turn these into a PLUS expression and fall into the PLUS code
12498 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12499 GEN_INT (GET_CODE (rtl
) == PRE_INC
12500 ? GET_MODE_UNIT_SIZE (mem_mode
)
12501 : -GET_MODE_UNIT_SIZE (mem_mode
)));
12503 /* ... fall through ... */
12507 if (is_based_loc (rtl
)
12508 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12509 || XEXP (rtl
, 0) == arg_pointer_rtx
12510 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12511 && GET_MODE_CLASS (mode
) == MODE_INT
)
12512 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12513 INTVAL (XEXP (rtl
, 1)),
12514 VAR_INIT_STATUS_INITIALIZED
);
12517 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12518 VAR_INIT_STATUS_INITIALIZED
);
12519 if (mem_loc_result
== 0)
12522 if (CONST_INT_P (XEXP (rtl
, 1))
12523 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12524 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12527 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12528 VAR_INIT_STATUS_INITIALIZED
);
12531 add_loc_descr (&mem_loc_result
, op1
);
12532 add_loc_descr (&mem_loc_result
,
12533 new_loc_descr (DW_OP_plus
, 0, 0));
12538 /* If a pseudo-reg is optimized away, it is possible for it to
12539 be replaced with a MEM containing a multiply or shift. */
12550 && GET_MODE_CLASS (mode
) == MODE_INT
12551 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12553 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12554 base_type_for_mode (mode
, 0),
12578 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12580 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12581 VAR_INIT_STATUS_INITIALIZED
);
12583 rtx rtlop1
= XEXP (rtl
, 1);
12584 if (GET_MODE (rtlop1
) != VOIDmode
12585 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12586 < GET_MODE_BITSIZE (mode
))
12587 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12588 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12589 VAR_INIT_STATUS_INITIALIZED
);
12592 if (op0
== 0 || op1
== 0)
12595 mem_loc_result
= op0
;
12596 add_loc_descr (&mem_loc_result
, op1
);
12597 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12613 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12614 VAR_INIT_STATUS_INITIALIZED
);
12615 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12616 VAR_INIT_STATUS_INITIALIZED
);
12618 if (op0
== 0 || op1
== 0)
12621 mem_loc_result
= op0
;
12622 add_loc_descr (&mem_loc_result
, op1
);
12623 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12627 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12629 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12630 base_type_for_mode (mode
, 0),
12635 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12636 VAR_INIT_STATUS_INITIALIZED
);
12637 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12638 VAR_INIT_STATUS_INITIALIZED
);
12640 if (op0
== 0 || op1
== 0)
12643 mem_loc_result
= op0
;
12644 add_loc_descr (&mem_loc_result
, op1
);
12645 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12646 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12647 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12648 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12649 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12653 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12655 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12660 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12661 base_type_for_mode (mode
, 1),
12679 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12680 VAR_INIT_STATUS_INITIALIZED
);
12685 mem_loc_result
= op0
;
12686 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12690 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12691 #ifdef POINTERS_EXTEND_UNSIGNED
12693 && mem_mode
!= VOIDmode
12694 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12698 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12702 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12703 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12705 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12706 enum machine_mode amode
;
12707 if (type_die
== NULL
)
12709 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12711 if (INTVAL (rtl
) >= 0
12712 && amode
!= BLKmode
12713 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12714 /* const DW_OP_GNU_convert <XXX> vs.
12715 DW_OP_GNU_const_type <XXX, 1, const>. */
12716 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12717 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12719 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12720 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12721 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12722 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12723 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12724 add_loc_descr (&mem_loc_result
, op0
);
12725 return mem_loc_result
;
12727 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12729 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12730 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12731 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12732 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12733 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12736 mem_loc_result
->dw_loc_oprnd2
.val_class
12737 = dw_val_class_const_double
;
12738 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12739 = double_int::from_shwi (INTVAL (rtl
));
12747 dw_die_ref type_die
;
12749 /* Note that a CONST_DOUBLE rtx could represent either an integer
12750 or a floating-point constant. A CONST_DOUBLE is used whenever
12751 the constant requires more than one word in order to be
12752 adequately represented. We output CONST_DOUBLEs as blocks. */
12753 if (mode
== VOIDmode
12754 || (GET_MODE (rtl
) == VOIDmode
12755 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12757 type_die
= base_type_for_mode (mode
,
12758 GET_MODE_CLASS (mode
) == MODE_INT
);
12759 if (type_die
== NULL
)
12761 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12762 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12763 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12764 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12765 if (SCALAR_FLOAT_MODE_P (mode
))
12767 unsigned int length
= GET_MODE_SIZE (mode
);
12768 unsigned char *array
12769 = (unsigned char*) ggc_alloc_atomic (length
);
12771 insert_float (rtl
, array
);
12772 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12773 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12774 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12775 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12779 mem_loc_result
->dw_loc_oprnd2
.val_class
12780 = dw_val_class_const_double
;
12781 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12782 = rtx_to_double_int (rtl
);
12788 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12792 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12796 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12800 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12804 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12808 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12812 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12816 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12820 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12824 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12829 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12834 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12839 if (CONST_INT_P (XEXP (rtl
, 1))
12840 && CONST_INT_P (XEXP (rtl
, 2))
12841 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12842 + (unsigned) INTVAL (XEXP (rtl
, 2))
12843 <= GET_MODE_BITSIZE (mode
))
12844 && GET_MODE_CLASS (mode
) == MODE_INT
12845 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12846 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12849 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12850 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12853 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12857 mem_loc_result
= op0
;
12858 size
= INTVAL (XEXP (rtl
, 1));
12859 shift
= INTVAL (XEXP (rtl
, 2));
12860 if (BITS_BIG_ENDIAN
)
12861 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12863 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12865 add_loc_descr (&mem_loc_result
,
12866 int_loc_descriptor (DWARF2_ADDR_SIZE
12868 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12870 if (size
!= (int) DWARF2_ADDR_SIZE
)
12872 add_loc_descr (&mem_loc_result
,
12873 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12874 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12881 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12882 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12883 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12884 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12885 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12886 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12887 VAR_INIT_STATUS_INITIALIZED
);
12888 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12889 VAR_INIT_STATUS_INITIALIZED
);
12890 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12893 mem_loc_result
= op1
;
12894 add_loc_descr (&mem_loc_result
, op2
);
12895 add_loc_descr (&mem_loc_result
, op0
);
12896 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12897 add_loc_descr (&mem_loc_result
, bra_node
);
12898 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12899 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12900 add_loc_descr (&mem_loc_result
, drop_node
);
12901 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12902 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12907 case FLOAT_TRUNCATE
:
12909 case UNSIGNED_FLOAT
:
12914 dw_die_ref type_die
;
12915 dw_loc_descr_ref cvt
;
12917 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12918 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12921 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12922 && (GET_CODE (rtl
) == FLOAT
12923 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12924 <= DWARF2_ADDR_SIZE
))
12926 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12927 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12928 if (type_die
== NULL
)
12930 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12931 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12932 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12933 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12934 add_loc_descr (&op0
, cvt
);
12936 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12937 if (type_die
== NULL
)
12939 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12940 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12941 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12942 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12943 add_loc_descr (&op0
, cvt
);
12944 if (GET_MODE_CLASS (mode
) == MODE_INT
12945 && (GET_CODE (rtl
) == FIX
12946 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12948 op0
= convert_descriptor_to_mode (mode
, op0
);
12952 mem_loc_result
= op0
;
12959 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12964 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12968 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12973 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12977 /* In theory, we could implement the above. */
12978 /* DWARF cannot represent the unsigned compare operations
13003 case FRACT_CONVERT
:
13004 case UNSIGNED_FRACT_CONVERT
:
13006 case UNSIGNED_SAT_FRACT
:
13012 case VEC_DUPLICATE
:
13016 case STRICT_LOW_PART
:
13021 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13022 can't express it in the debug info. This can happen e.g. with some
13027 resolve_one_addr (&rtl
, NULL
);
13031 #ifdef ENABLE_CHECKING
13032 print_rtl (stderr
, rtl
);
13033 gcc_unreachable ();
13039 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13040 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13042 return mem_loc_result
;
13045 /* Return a descriptor that describes the concatenation of two locations.
13046 This is typically a complex variable. */
13048 static dw_loc_descr_ref
13049 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13051 dw_loc_descr_ref cc_loc_result
= NULL
;
13052 dw_loc_descr_ref x0_ref
13053 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13054 dw_loc_descr_ref x1_ref
13055 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13057 if (x0_ref
== 0 || x1_ref
== 0)
13060 cc_loc_result
= x0_ref
;
13061 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13063 add_loc_descr (&cc_loc_result
, x1_ref
);
13064 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13066 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13067 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13069 return cc_loc_result
;
13072 /* Return a descriptor that describes the concatenation of N
13075 static dw_loc_descr_ref
13076 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13079 dw_loc_descr_ref cc_loc_result
= NULL
;
13080 unsigned int n
= XVECLEN (concatn
, 0);
13082 for (i
= 0; i
< n
; ++i
)
13084 dw_loc_descr_ref ref
;
13085 rtx x
= XVECEXP (concatn
, 0, i
);
13087 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13091 add_loc_descr (&cc_loc_result
, ref
);
13092 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13095 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13096 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13098 return cc_loc_result
;
13101 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13102 for DEBUG_IMPLICIT_PTR RTL. */
13104 static dw_loc_descr_ref
13105 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13107 dw_loc_descr_ref ret
;
13112 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13113 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13114 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13115 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13116 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13117 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13120 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13121 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13122 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13126 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13127 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13132 /* Output a proper Dwarf location descriptor for a variable or parameter
13133 which is either allocated in a register or in a memory location. For a
13134 register, we just generate an OP_REG and the register number. For a
13135 memory location we provide a Dwarf postfix expression describing how to
13136 generate the (dynamic) address of the object onto the address stack.
13138 MODE is mode of the decl if this loc_descriptor is going to be used in
13139 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13140 allowed, VOIDmode otherwise.
13142 If we don't know how to describe it, return 0. */
13144 static dw_loc_descr_ref
13145 loc_descriptor (rtx rtl
, enum machine_mode mode
,
13146 enum var_init_status initialized
)
13148 dw_loc_descr_ref loc_result
= NULL
;
13150 switch (GET_CODE (rtl
))
13153 /* The case of a subreg may arise when we have a local (register)
13154 variable or a formal (register) parameter which doesn't quite fill
13155 up an entire register. For now, just assume that it is
13156 legitimate to make the Dwarf info refer to the whole register which
13157 contains the given subreg. */
13158 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13159 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13160 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13166 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13170 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13171 GET_MODE (rtl
), initialized
);
13172 if (loc_result
== NULL
)
13173 loc_result
= tls_mem_loc_descriptor (rtl
);
13174 if (loc_result
== NULL
)
13176 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13177 if (new_rtl
!= rtl
)
13178 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13183 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13188 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13193 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13195 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13196 if (GET_CODE (loc
) == EXPR_LIST
)
13197 loc
= XEXP (loc
, 0);
13198 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13202 rtl
= XEXP (rtl
, 1);
13207 rtvec par_elems
= XVEC (rtl
, 0);
13208 int num_elem
= GET_NUM_ELEM (par_elems
);
13209 enum machine_mode mode
;
13212 /* Create the first one, so we have something to add to. */
13213 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13214 VOIDmode
, initialized
);
13215 if (loc_result
== NULL
)
13217 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13218 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13219 for (i
= 1; i
< num_elem
; i
++)
13221 dw_loc_descr_ref temp
;
13223 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13224 VOIDmode
, initialized
);
13227 add_loc_descr (&loc_result
, temp
);
13228 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13229 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13235 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13236 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13241 if (mode
== VOIDmode
)
13242 mode
= GET_MODE (rtl
);
13244 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13246 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13248 /* Note that a CONST_DOUBLE rtx could represent either an integer
13249 or a floating-point constant. A CONST_DOUBLE is used whenever
13250 the constant requires more than one word in order to be
13251 adequately represented. We output CONST_DOUBLEs as blocks. */
13252 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13253 GET_MODE_SIZE (mode
), 0);
13254 if (SCALAR_FLOAT_MODE_P (mode
))
13256 unsigned int length
= GET_MODE_SIZE (mode
);
13257 unsigned char *array
13258 = (unsigned char*) ggc_alloc_atomic (length
);
13260 insert_float (rtl
, array
);
13261 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13262 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13263 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13264 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13268 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13269 loc_result
->dw_loc_oprnd2
.v
.val_double
13270 = rtx_to_double_int (rtl
);
13276 if (mode
== VOIDmode
)
13277 mode
= GET_MODE (rtl
);
13279 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13281 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13282 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13283 unsigned char *array
= (unsigned char *)
13284 ggc_alloc_atomic (length
* elt_size
);
13288 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13289 switch (GET_MODE_CLASS (mode
))
13291 case MODE_VECTOR_INT
:
13292 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13294 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13295 double_int val
= rtx_to_double_int (elt
);
13297 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13298 insert_int (val
.to_shwi (), elt_size
, p
);
13301 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13302 insert_double (val
, p
);
13307 case MODE_VECTOR_FLOAT
:
13308 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13310 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13311 insert_float (elt
, p
);
13316 gcc_unreachable ();
13319 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13320 length
* elt_size
, 0);
13321 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13322 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13323 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13324 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13329 if (mode
== VOIDmode
13330 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13331 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13332 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13334 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13339 if (!const_ok_for_output (rtl
))
13342 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13343 && (dwarf_version
>= 4 || !dwarf_strict
))
13345 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13346 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13347 vec_safe_push (used_rtx_array
, rtl
);
13351 case DEBUG_IMPLICIT_PTR
:
13352 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13356 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13357 && CONST_INT_P (XEXP (rtl
, 1)))
13360 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13366 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13367 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13368 && dwarf_version
>= 4)
13369 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13371 /* Value expression. */
13372 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13374 add_loc_descr (&loc_result
,
13375 new_loc_descr (DW_OP_stack_value
, 0, 0));
13383 /* We need to figure out what section we should use as the base for the
13384 address ranges where a given location is valid.
13385 1. If this particular DECL has a section associated with it, use that.
13386 2. If this function has a section associated with it, use that.
13387 3. Otherwise, use the text section.
13388 XXX: If you split a variable across multiple sections, we won't notice. */
13390 static const char *
13391 secname_for_decl (const_tree decl
)
13393 const char *secname
;
13395 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13397 tree sectree
= DECL_SECTION_NAME (decl
);
13398 secname
= TREE_STRING_POINTER (sectree
);
13400 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13402 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13403 secname
= TREE_STRING_POINTER (sectree
);
13405 else if (cfun
&& in_cold_section_p
)
13406 secname
= crtl
->subsections
.cold_section_label
;
13408 secname
= text_section_label
;
13413 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13416 decl_by_reference_p (tree decl
)
13418 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13419 || TREE_CODE (decl
) == VAR_DECL
)
13420 && DECL_BY_REFERENCE (decl
));
13423 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13426 static dw_loc_descr_ref
13427 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13428 enum var_init_status initialized
)
13430 int have_address
= 0;
13431 dw_loc_descr_ref descr
;
13432 enum machine_mode mode
;
13434 if (want_address
!= 2)
13436 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13438 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13440 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13441 if (GET_CODE (varloc
) == EXPR_LIST
)
13442 varloc
= XEXP (varloc
, 0);
13443 mode
= GET_MODE (varloc
);
13444 if (MEM_P (varloc
))
13446 rtx addr
= XEXP (varloc
, 0);
13447 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13448 mode
, initialized
);
13453 rtx x
= avoid_constant_pool_reference (varloc
);
13455 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13460 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13467 if (GET_CODE (varloc
) == VAR_LOCATION
)
13468 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13470 mode
= DECL_MODE (loc
);
13471 descr
= loc_descriptor (varloc
, mode
, initialized
);
13478 if (want_address
== 2 && !have_address
13479 && (dwarf_version
>= 4 || !dwarf_strict
))
13481 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13483 expansion_failed (loc
, NULL_RTX
,
13484 "DWARF address size mismatch");
13487 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13490 /* Show if we can't fill the request for an address. */
13491 if (want_address
&& !have_address
)
13493 expansion_failed (loc
, NULL_RTX
,
13494 "Want address and only have value");
13498 /* If we've got an address and don't want one, dereference. */
13499 if (!want_address
&& have_address
)
13501 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13502 enum dwarf_location_atom op
;
13504 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13506 expansion_failed (loc
, NULL_RTX
,
13507 "DWARF address size mismatch");
13510 else if (size
== DWARF2_ADDR_SIZE
)
13513 op
= DW_OP_deref_size
;
13515 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13521 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13522 if it is not possible. */
13524 static dw_loc_descr_ref
13525 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13527 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13528 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13529 else if (dwarf_version
>= 3 || !dwarf_strict
)
13530 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13535 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13536 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13538 static dw_loc_descr_ref
13539 dw_sra_loc_expr (tree decl
, rtx loc
)
13542 unsigned int padsize
= 0;
13543 dw_loc_descr_ref descr
, *descr_tail
;
13544 unsigned HOST_WIDE_INT decl_size
;
13546 enum var_init_status initialized
;
13548 if (DECL_SIZE (decl
) == NULL
13549 || !host_integerp (DECL_SIZE (decl
), 1))
13552 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13554 descr_tail
= &descr
;
13556 for (p
= loc
; p
; p
= XEXP (p
, 1))
13558 unsigned int bitsize
= decl_piece_bitsize (p
);
13559 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13560 dw_loc_descr_ref cur_descr
;
13561 dw_loc_descr_ref
*tail
, last
= NULL
;
13562 unsigned int opsize
= 0;
13564 if (loc_note
== NULL_RTX
13565 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13567 padsize
+= bitsize
;
13570 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13571 varloc
= NOTE_VAR_LOCATION (loc_note
);
13572 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13573 if (cur_descr
== NULL
)
13575 padsize
+= bitsize
;
13579 /* Check that cur_descr either doesn't use
13580 DW_OP_*piece operations, or their sum is equal
13581 to bitsize. Otherwise we can't embed it. */
13582 for (tail
= &cur_descr
; *tail
!= NULL
;
13583 tail
= &(*tail
)->dw_loc_next
)
13584 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13586 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13590 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13592 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13596 if (last
!= NULL
&& opsize
!= bitsize
)
13598 padsize
+= bitsize
;
13602 /* If there is a hole, add DW_OP_*piece after empty DWARF
13603 expression, which means that those bits are optimized out. */
13606 if (padsize
> decl_size
)
13608 decl_size
-= padsize
;
13609 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13610 if (*descr_tail
== NULL
)
13612 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13615 *descr_tail
= cur_descr
;
13617 if (bitsize
> decl_size
)
13619 decl_size
-= bitsize
;
13622 HOST_WIDE_INT offset
= 0;
13623 if (GET_CODE (varloc
) == VAR_LOCATION
13624 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13626 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13627 if (GET_CODE (varloc
) == EXPR_LIST
)
13628 varloc
= XEXP (varloc
, 0);
13632 if (GET_CODE (varloc
) == CONST
13633 || GET_CODE (varloc
) == SIGN_EXTEND
13634 || GET_CODE (varloc
) == ZERO_EXTEND
)
13635 varloc
= XEXP (varloc
, 0);
13636 else if (GET_CODE (varloc
) == SUBREG
)
13637 varloc
= SUBREG_REG (varloc
);
13642 /* DW_OP_bit_size offset should be zero for register
13643 or implicit location descriptions and empty location
13644 descriptions, but for memory addresses needs big endian
13646 if (MEM_P (varloc
))
13648 unsigned HOST_WIDE_INT memsize
13649 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13650 if (memsize
!= bitsize
)
13652 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13653 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13655 if (memsize
< bitsize
)
13657 if (BITS_BIG_ENDIAN
)
13658 offset
= memsize
- bitsize
;
13662 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13663 if (*descr_tail
== NULL
)
13665 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13669 /* If there were any non-empty expressions, add padding till the end of
13671 if (descr
!= NULL
&& decl_size
!= 0)
13673 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13674 if (*descr_tail
== NULL
)
13680 /* Return the dwarf representation of the location list LOC_LIST of
13681 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13684 static dw_loc_list_ref
13685 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13687 const char *endname
, *secname
;
13689 enum var_init_status initialized
;
13690 struct var_loc_node
*node
;
13691 dw_loc_descr_ref descr
;
13692 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13693 dw_loc_list_ref list
= NULL
;
13694 dw_loc_list_ref
*listp
= &list
;
13696 /* Now that we know what section we are using for a base,
13697 actually construct the list of locations.
13698 The first location information is what is passed to the
13699 function that creates the location list, and the remaining
13700 locations just get added on to that list.
13701 Note that we only know the start address for a location
13702 (IE location changes), so to build the range, we use
13703 the range [current location start, next location start].
13704 This means we have to special case the last node, and generate
13705 a range of [last location start, end of function label]. */
13707 secname
= secname_for_decl (decl
);
13709 for (node
= loc_list
->first
; node
; node
= node
->next
)
13710 if (GET_CODE (node
->loc
) == EXPR_LIST
13711 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13713 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13715 /* This requires DW_OP_{,bit_}piece, which is not usable
13716 inside DWARF expressions. */
13717 if (want_address
!= 2)
13719 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13725 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13726 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13727 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13731 bool range_across_switch
= false;
13732 /* If section switch happens in between node->label
13733 and node->next->label (or end of function) and
13734 we can't emit it as a single entry list,
13735 emit two ranges, first one ending at the end
13736 of first partition and second one starting at the
13737 beginning of second partition. */
13738 if (node
== loc_list
->last_before_switch
13739 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13740 && current_function_decl
)
13742 endname
= cfun
->fde
->dw_fde_end
;
13743 range_across_switch
= true;
13745 /* The variable has a location between NODE->LABEL and
13746 NODE->NEXT->LABEL. */
13747 else if (node
->next
)
13748 endname
= node
->next
->label
;
13749 /* If the variable has a location at the last label
13750 it keeps its location until the end of function. */
13751 else if (!current_function_decl
)
13752 endname
= text_end_label
;
13755 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13756 FUNC_LABEL_ID (cfun
));
13757 endname
= ggc_strdup (label_id
);
13760 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13761 if (TREE_CODE (decl
) == PARM_DECL
13762 && node
== loc_list
->first
13763 && GET_CODE (node
->loc
) == NOTE
13764 && strcmp (node
->label
, endname
) == 0)
13765 (*listp
)->force
= true;
13766 listp
= &(*listp
)->dw_loc_next
;
13768 if (range_across_switch
)
13770 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13771 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13774 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13775 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13776 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13779 gcc_assert (descr
);
13780 /* The variable has a location between NODE->LABEL and
13781 NODE->NEXT->LABEL. */
13783 endname
= node
->next
->label
;
13785 endname
= cfun
->fde
->dw_fde_second_end
;
13786 *listp
= new_loc_list (descr
,
13787 cfun
->fde
->dw_fde_second_begin
,
13789 listp
= &(*listp
)->dw_loc_next
;
13794 /* Try to avoid the overhead of a location list emitting a location
13795 expression instead, but only if we didn't have more than one
13796 location entry in the first place. If some entries were not
13797 representable, we don't want to pretend a single entry that was
13798 applies to the entire scope in which the variable is
13800 if (list
&& loc_list
->first
->next
)
13806 /* Return if the loc_list has only single element and thus can be represented
13807 as location description. */
13810 single_element_loc_list_p (dw_loc_list_ref list
)
13812 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13813 return !list
->ll_symbol
;
13816 /* To each location in list LIST add loc descr REF. */
13819 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13821 dw_loc_descr_ref copy
;
13822 add_loc_descr (&list
->expr
, ref
);
13823 list
= list
->dw_loc_next
;
13826 copy
= ggc_alloc_dw_loc_descr_node ();
13827 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13828 add_loc_descr (&list
->expr
, copy
);
13829 while (copy
->dw_loc_next
)
13831 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13832 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13833 copy
->dw_loc_next
= new_copy
;
13836 list
= list
->dw_loc_next
;
13840 /* Given two lists RET and LIST
13841 produce location list that is result of adding expression in LIST
13842 to expression in RET on each position in program.
13843 Might be destructive on both RET and LIST.
13845 TODO: We handle only simple cases of RET or LIST having at most one
13846 element. General case would inolve sorting the lists in program order
13847 and merging them that will need some additional work.
13848 Adding that will improve quality of debug info especially for SRA-ed
13852 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13861 if (!list
->dw_loc_next
)
13863 add_loc_descr_to_each (*ret
, list
->expr
);
13866 if (!(*ret
)->dw_loc_next
)
13868 add_loc_descr_to_each (list
, (*ret
)->expr
);
13872 expansion_failed (NULL_TREE
, NULL_RTX
,
13873 "Don't know how to merge two non-trivial"
13874 " location lists.\n");
13879 /* LOC is constant expression. Try a luck, look it up in constant
13880 pool and return its loc_descr of its address. */
13882 static dw_loc_descr_ref
13883 cst_pool_loc_descr (tree loc
)
13885 /* Get an RTL for this, if something has been emitted. */
13886 rtx rtl
= lookup_constant_def (loc
);
13888 if (!rtl
|| !MEM_P (rtl
))
13893 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13895 /* TODO: We might get more coverage if we was actually delaying expansion
13896 of all expressions till end of compilation when constant pools are fully
13898 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13900 expansion_failed (loc
, NULL_RTX
,
13901 "CST value in contant pool but not marked.");
13904 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13905 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13908 /* Return dw_loc_list representing address of addr_expr LOC
13909 by looking for inner INDIRECT_REF expression and turning
13910 it into simple arithmetics. */
13912 static dw_loc_list_ref
13913 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13916 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13917 enum machine_mode mode
;
13918 int unsignedp
, volatilep
= 0;
13919 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13921 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13922 &bitsize
, &bitpos
, &offset
, &mode
,
13923 &unsignedp
, &volatilep
, false);
13925 if (bitpos
% BITS_PER_UNIT
)
13927 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13930 if (!INDIRECT_REF_P (obj
))
13932 expansion_failed (obj
,
13933 NULL_RTX
, "no indirect ref in inner refrence");
13936 if (!offset
&& !bitpos
)
13937 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13939 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13940 && (dwarf_version
>= 4 || !dwarf_strict
))
13942 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13947 /* Variable offset. */
13948 list_ret1
= loc_list_from_tree (offset
, 0);
13949 if (list_ret1
== 0)
13951 add_loc_list (&list_ret
, list_ret1
);
13954 add_loc_descr_to_each (list_ret
,
13955 new_loc_descr (DW_OP_plus
, 0, 0));
13957 bytepos
= bitpos
/ BITS_PER_UNIT
;
13959 add_loc_descr_to_each (list_ret
,
13960 new_loc_descr (DW_OP_plus_uconst
,
13962 else if (bytepos
< 0)
13963 loc_list_plus_const (list_ret
, bytepos
);
13964 add_loc_descr_to_each (list_ret
,
13965 new_loc_descr (DW_OP_stack_value
, 0, 0));
13971 /* Generate Dwarf location list representing LOC.
13972 If WANT_ADDRESS is false, expression computing LOC will be computed
13973 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13974 if WANT_ADDRESS is 2, expression computing address useable in location
13975 will be returned (i.e. DW_OP_reg can be used
13976 to refer to register values). */
13978 static dw_loc_list_ref
13979 loc_list_from_tree (tree loc
, int want_address
)
13981 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13982 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13983 int have_address
= 0;
13984 enum dwarf_location_atom op
;
13986 /* ??? Most of the time we do not take proper care for sign/zero
13987 extending the values properly. Hopefully this won't be a real
13990 switch (TREE_CODE (loc
))
13993 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13996 case PLACEHOLDER_EXPR
:
13997 /* This case involves extracting fields from an object to determine the
13998 position of other fields. We don't try to encode this here. The
13999 only user of this is Ada, which encodes the needed information using
14000 the names of types. */
14001 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
14005 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14006 /* There are no opcodes for these operations. */
14009 case PREINCREMENT_EXPR
:
14010 case PREDECREMENT_EXPR
:
14011 case POSTINCREMENT_EXPR
:
14012 case POSTDECREMENT_EXPR
:
14013 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14014 /* There are no opcodes for these operations. */
14018 /* If we already want an address, see if there is INDIRECT_REF inside
14019 e.g. for &this->field. */
14022 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14023 (loc
, want_address
== 2);
14026 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14027 && (ret
= cst_pool_loc_descr (loc
)))
14030 /* Otherwise, process the argument and look for the address. */
14031 if (!list_ret
&& !ret
)
14032 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
14036 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14042 if (DECL_THREAD_LOCAL_P (loc
))
14045 enum dwarf_location_atom tls_op
;
14046 enum dtprel_bool dtprel
= dtprel_false
;
14048 if (targetm
.have_tls
)
14050 /* If this is not defined, we have no way to emit the
14052 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14055 /* The way DW_OP_GNU_push_tls_address is specified, we
14056 can only look up addresses of objects in the current
14057 module. We used DW_OP_addr as first op, but that's
14058 wrong, because DW_OP_addr is relocated by the debug
14059 info consumer, while DW_OP_GNU_push_tls_address
14060 operand shouldn't be. */
14061 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14063 dtprel
= dtprel_true
;
14064 tls_op
= DW_OP_GNU_push_tls_address
;
14068 if (!targetm
.emutls
.debug_form_tls_address
14069 || !(dwarf_version
>= 3 || !dwarf_strict
))
14071 /* We stuffed the control variable into the DECL_VALUE_EXPR
14072 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14073 no longer appear in gimple code. We used the control
14074 variable in specific so that we could pick it up here. */
14075 loc
= DECL_VALUE_EXPR (loc
);
14076 tls_op
= DW_OP_form_tls_address
;
14079 rtl
= rtl_for_decl_location (loc
);
14080 if (rtl
== NULL_RTX
)
14085 rtl
= XEXP (rtl
, 0);
14086 if (! CONSTANT_P (rtl
))
14089 ret
= new_addr_loc_descr (rtl
, dtprel
);
14090 ret1
= new_loc_descr (tls_op
, 0, 0);
14091 add_loc_descr (&ret
, ret1
);
14100 if (DECL_HAS_VALUE_EXPR_P (loc
))
14101 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14105 case FUNCTION_DECL
:
14108 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14110 if (loc_list
&& loc_list
->first
)
14112 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14113 have_address
= want_address
!= 0;
14116 rtl
= rtl_for_decl_location (loc
);
14117 if (rtl
== NULL_RTX
)
14119 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14122 else if (CONST_INT_P (rtl
))
14124 HOST_WIDE_INT val
= INTVAL (rtl
);
14125 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14126 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14127 ret
= int_loc_descriptor (val
);
14129 else if (GET_CODE (rtl
) == CONST_STRING
)
14131 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14134 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14135 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14138 enum machine_mode mode
, mem_mode
;
14140 /* Certain constructs can only be represented at top-level. */
14141 if (want_address
== 2)
14143 ret
= loc_descriptor (rtl
, VOIDmode
,
14144 VAR_INIT_STATUS_INITIALIZED
);
14149 mode
= GET_MODE (rtl
);
14150 mem_mode
= VOIDmode
;
14154 mode
= get_address_mode (rtl
);
14155 rtl
= XEXP (rtl
, 0);
14158 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14159 VAR_INIT_STATUS_INITIALIZED
);
14162 expansion_failed (loc
, rtl
,
14163 "failed to produce loc descriptor for rtl");
14170 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14174 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14178 case COMPOUND_EXPR
:
14179 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14182 case VIEW_CONVERT_EXPR
:
14185 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14187 case COMPONENT_REF
:
14188 case BIT_FIELD_REF
:
14190 case ARRAY_RANGE_REF
:
14191 case REALPART_EXPR
:
14192 case IMAGPART_EXPR
:
14195 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14196 enum machine_mode mode
;
14197 int unsignedp
, volatilep
= 0;
14199 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14200 &unsignedp
, &volatilep
, false);
14202 gcc_assert (obj
!= loc
);
14204 list_ret
= loc_list_from_tree (obj
,
14206 && !bitpos
&& !offset
? 2 : 1);
14207 /* TODO: We can extract value of the small expression via shifting even
14208 for nonzero bitpos. */
14211 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14213 expansion_failed (loc
, NULL_RTX
,
14214 "bitfield access");
14218 if (offset
!= NULL_TREE
)
14220 /* Variable offset. */
14221 list_ret1
= loc_list_from_tree (offset
, 0);
14222 if (list_ret1
== 0)
14224 add_loc_list (&list_ret
, list_ret1
);
14227 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14230 bytepos
= bitpos
/ BITS_PER_UNIT
;
14232 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14233 else if (bytepos
< 0)
14234 loc_list_plus_const (list_ret
, bytepos
);
14241 if ((want_address
|| !host_integerp (loc
, 0))
14242 && (ret
= cst_pool_loc_descr (loc
)))
14244 else if (want_address
== 2
14245 && host_integerp (loc
, 0)
14246 && (ret
= address_of_int_loc_descriptor
14247 (int_size_in_bytes (TREE_TYPE (loc
)),
14248 tree_low_cst (loc
, 0))))
14250 else if (host_integerp (loc
, 0))
14251 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
14254 expansion_failed (loc
, NULL_RTX
,
14255 "Integer operand is not host integer");
14264 if ((ret
= cst_pool_loc_descr (loc
)))
14267 /* We can construct small constants here using int_loc_descriptor. */
14268 expansion_failed (loc
, NULL_RTX
,
14269 "constructor or constant not in constant pool");
14272 case TRUTH_AND_EXPR
:
14273 case TRUTH_ANDIF_EXPR
:
14278 case TRUTH_XOR_EXPR
:
14283 case TRUTH_OR_EXPR
:
14284 case TRUTH_ORIF_EXPR
:
14289 case FLOOR_DIV_EXPR
:
14290 case CEIL_DIV_EXPR
:
14291 case ROUND_DIV_EXPR
:
14292 case TRUNC_DIV_EXPR
:
14293 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14302 case FLOOR_MOD_EXPR
:
14303 case CEIL_MOD_EXPR
:
14304 case ROUND_MOD_EXPR
:
14305 case TRUNC_MOD_EXPR
:
14306 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14311 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14312 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14313 if (list_ret
== 0 || list_ret1
== 0)
14316 add_loc_list (&list_ret
, list_ret1
);
14319 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14320 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14321 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14322 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14323 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14335 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14338 case POINTER_PLUS_EXPR
:
14340 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14342 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14346 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14354 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14361 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14368 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14375 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14390 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14391 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14392 if (list_ret
== 0 || list_ret1
== 0)
14395 add_loc_list (&list_ret
, list_ret1
);
14398 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14401 case TRUTH_NOT_EXPR
:
14415 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14419 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14425 const enum tree_code code
=
14426 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14428 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14429 build2 (code
, integer_type_node
,
14430 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14431 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14434 /* ... fall through ... */
14438 dw_loc_descr_ref lhs
14439 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14440 dw_loc_list_ref rhs
14441 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14442 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14444 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14445 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14448 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14449 add_loc_descr_to_each (list_ret
, bra_node
);
14451 add_loc_list (&list_ret
, rhs
);
14452 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14453 add_loc_descr_to_each (list_ret
, jump_node
);
14455 add_loc_descr_to_each (list_ret
, lhs
);
14456 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14457 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14459 /* ??? Need a node to point the skip at. Use a nop. */
14460 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14461 add_loc_descr_to_each (list_ret
, tmp
);
14462 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14463 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14467 case FIX_TRUNC_EXPR
:
14471 /* Leave front-end specific codes as simply unknown. This comes
14472 up, for instance, with the C STMT_EXPR. */
14473 if ((unsigned int) TREE_CODE (loc
)
14474 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14476 expansion_failed (loc
, NULL_RTX
,
14477 "language specific tree node");
14481 #ifdef ENABLE_CHECKING
14482 /* Otherwise this is a generic code; we should just lists all of
14483 these explicitly. We forgot one. */
14484 gcc_unreachable ();
14486 /* In a release build, we want to degrade gracefully: better to
14487 generate incomplete debugging information than to crash. */
14492 if (!ret
&& !list_ret
)
14495 if (want_address
== 2 && !have_address
14496 && (dwarf_version
>= 4 || !dwarf_strict
))
14498 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14500 expansion_failed (loc
, NULL_RTX
,
14501 "DWARF address size mismatch");
14505 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14507 add_loc_descr_to_each (list_ret
,
14508 new_loc_descr (DW_OP_stack_value
, 0, 0));
14511 /* Show if we can't fill the request for an address. */
14512 if (want_address
&& !have_address
)
14514 expansion_failed (loc
, NULL_RTX
,
14515 "Want address and only have value");
14519 gcc_assert (!ret
|| !list_ret
);
14521 /* If we've got an address and don't want one, dereference. */
14522 if (!want_address
&& have_address
)
14524 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14526 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14528 expansion_failed (loc
, NULL_RTX
,
14529 "DWARF address size mismatch");
14532 else if (size
== DWARF2_ADDR_SIZE
)
14535 op
= DW_OP_deref_size
;
14538 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14540 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14543 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14548 /* Same as above but return only single location expression. */
14549 static dw_loc_descr_ref
14550 loc_descriptor_from_tree (tree loc
, int want_address
)
14552 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14555 if (ret
->dw_loc_next
)
14557 expansion_failed (loc
, NULL_RTX
,
14558 "Location list where only loc descriptor needed");
14564 /* Given a value, round it up to the lowest multiple of `boundary'
14565 which is not less than the value itself. */
14567 static inline HOST_WIDE_INT
14568 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14570 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14573 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14574 pointer to the declared type for the relevant field variable, or return
14575 `integer_type_node' if the given node turns out to be an
14576 ERROR_MARK node. */
14579 field_type (const_tree decl
)
14583 if (TREE_CODE (decl
) == ERROR_MARK
)
14584 return integer_type_node
;
14586 type
= DECL_BIT_FIELD_TYPE (decl
);
14587 if (type
== NULL_TREE
)
14588 type
= TREE_TYPE (decl
);
14593 /* Given a pointer to a tree node, return the alignment in bits for
14594 it, or else return BITS_PER_WORD if the node actually turns out to
14595 be an ERROR_MARK node. */
14597 static inline unsigned
14598 simple_type_align_in_bits (const_tree type
)
14600 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14603 static inline unsigned
14604 simple_decl_align_in_bits (const_tree decl
)
14606 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14609 /* Return the result of rounding T up to ALIGN. */
14611 static inline double_int
14612 round_up_to_align (double_int t
, unsigned int align
)
14614 double_int alignd
= double_int::from_uhwi (align
);
14616 t
+= double_int_minus_one
;
14617 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14622 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14623 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14624 or return 0 if we are unable to determine what that offset is, either
14625 because the argument turns out to be a pointer to an ERROR_MARK node, or
14626 because the offset is actually variable. (We can't handle the latter case
14629 static HOST_WIDE_INT
14630 field_byte_offset (const_tree decl
)
14632 double_int object_offset_in_bits
;
14633 double_int object_offset_in_bytes
;
14634 double_int bitpos_int
;
14636 if (TREE_CODE (decl
) == ERROR_MARK
)
14639 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14641 /* We cannot yet cope with fields whose positions are variable, so
14642 for now, when we see such things, we simply return 0. Someday, we may
14643 be able to handle such cases, but it will be damn difficult. */
14644 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14647 bitpos_int
= tree_to_double_int (bit_position (decl
));
14649 #ifdef PCC_BITFIELD_TYPE_MATTERS
14650 if (PCC_BITFIELD_TYPE_MATTERS
)
14653 tree field_size_tree
;
14654 double_int deepest_bitpos
;
14655 double_int field_size_in_bits
;
14656 unsigned int type_align_in_bits
;
14657 unsigned int decl_align_in_bits
;
14658 double_int type_size_in_bits
;
14660 type
= field_type (decl
);
14661 type_size_in_bits
= double_int_type_size_in_bits (type
);
14662 type_align_in_bits
= simple_type_align_in_bits (type
);
14664 field_size_tree
= DECL_SIZE (decl
);
14666 /* The size could be unspecified if there was an error, or for
14667 a flexible array member. */
14668 if (!field_size_tree
)
14669 field_size_tree
= bitsize_zero_node
;
14671 /* If the size of the field is not constant, use the type size. */
14672 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14673 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14675 field_size_in_bits
= type_size_in_bits
;
14677 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14679 /* The GCC front-end doesn't make any attempt to keep track of the
14680 starting bit offset (relative to the start of the containing
14681 structure type) of the hypothetical "containing object" for a
14682 bit-field. Thus, when computing the byte offset value for the
14683 start of the "containing object" of a bit-field, we must deduce
14684 this information on our own. This can be rather tricky to do in
14685 some cases. For example, handling the following structure type
14686 definition when compiling for an i386/i486 target (which only
14687 aligns long long's to 32-bit boundaries) can be very tricky:
14689 struct S { int field1; long long field2:31; };
14691 Fortunately, there is a simple rule-of-thumb which can be used
14692 in such cases. When compiling for an i386/i486, GCC will
14693 allocate 8 bytes for the structure shown above. It decides to
14694 do this based upon one simple rule for bit-field allocation.
14695 GCC allocates each "containing object" for each bit-field at
14696 the first (i.e. lowest addressed) legitimate alignment boundary
14697 (based upon the required minimum alignment for the declared
14698 type of the field) which it can possibly use, subject to the
14699 condition that there is still enough available space remaining
14700 in the containing object (when allocated at the selected point)
14701 to fully accommodate all of the bits of the bit-field itself.
14703 This simple rule makes it obvious why GCC allocates 8 bytes for
14704 each object of the structure type shown above. When looking
14705 for a place to allocate the "containing object" for `field2',
14706 the compiler simply tries to allocate a 64-bit "containing
14707 object" at each successive 32-bit boundary (starting at zero)
14708 until it finds a place to allocate that 64- bit field such that
14709 at least 31 contiguous (and previously unallocated) bits remain
14710 within that selected 64 bit field. (As it turns out, for the
14711 example above, the compiler finds it is OK to allocate the
14712 "containing object" 64-bit field at bit-offset zero within the
14715 Here we attempt to work backwards from the limited set of facts
14716 we're given, and we try to deduce from those facts, where GCC
14717 must have believed that the containing object started (within
14718 the structure type). The value we deduce is then used (by the
14719 callers of this routine) to generate DW_AT_location and
14720 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14721 the case of DW_AT_location, regular fields as well). */
14723 /* Figure out the bit-distance from the start of the structure to
14724 the "deepest" bit of the bit-field. */
14725 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14727 /* This is the tricky part. Use some fancy footwork to deduce
14728 where the lowest addressed bit of the containing object must
14730 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14732 /* Round up to type_align by default. This works best for
14734 object_offset_in_bits
14735 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14737 if (object_offset_in_bits
.ugt (bitpos_int
))
14739 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14741 /* Round up to decl_align instead. */
14742 object_offset_in_bits
14743 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14747 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14748 object_offset_in_bits
= bitpos_int
;
14750 object_offset_in_bytes
14751 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14752 true, TRUNC_DIV_EXPR
);
14753 return object_offset_in_bytes
.to_shwi ();
14756 /* The following routines define various Dwarf attributes and any data
14757 associated with them. */
14759 /* Add a location description attribute value to a DIE.
14761 This emits location attributes suitable for whole variables and
14762 whole parameters. Note that the location attributes for struct fields are
14763 generated by the routine `data_member_location_attribute' below. */
14766 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14767 dw_loc_list_ref descr
)
14771 if (single_element_loc_list_p (descr
))
14772 add_AT_loc (die
, attr_kind
, descr
->expr
);
14774 add_AT_loc_list (die
, attr_kind
, descr
);
14777 /* Add DW_AT_accessibility attribute to DIE if needed. */
14780 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14782 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14783 children, otherwise the default is DW_ACCESS_public. In DWARF2
14784 the default has always been DW_ACCESS_public. */
14785 if (TREE_PROTECTED (decl
))
14786 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14787 else if (TREE_PRIVATE (decl
))
14789 if (dwarf_version
== 2
14790 || die
->die_parent
== NULL
14791 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14792 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14794 else if (dwarf_version
> 2
14796 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14797 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14800 /* Attach the specialized form of location attribute used for data members of
14801 struct and union types. In the special case of a FIELD_DECL node which
14802 represents a bit-field, the "offset" part of this special location
14803 descriptor must indicate the distance in bytes from the lowest-addressed
14804 byte of the containing struct or union type to the lowest-addressed byte of
14805 the "containing object" for the bit-field. (See the `field_byte_offset'
14808 For any given bit-field, the "containing object" is a hypothetical object
14809 (of some integral or enum type) within which the given bit-field lives. The
14810 type of this hypothetical "containing object" is always the same as the
14811 declared type of the individual bit-field itself (for GCC anyway... the
14812 DWARF spec doesn't actually mandate this). Note that it is the size (in
14813 bytes) of the hypothetical "containing object" which will be given in the
14814 DW_AT_byte_size attribute for this bit-field. (See the
14815 `byte_size_attribute' function below.) It is also used when calculating the
14816 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14817 function below.) */
14820 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14822 HOST_WIDE_INT offset
;
14823 dw_loc_descr_ref loc_descr
= 0;
14825 if (TREE_CODE (decl
) == TREE_BINFO
)
14827 /* We're working on the TAG_inheritance for a base class. */
14828 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14830 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14831 aren't at a fixed offset from all (sub)objects of the same
14832 type. We need to extract the appropriate offset from our
14833 vtable. The following dwarf expression means
14835 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14837 This is specific to the V3 ABI, of course. */
14839 dw_loc_descr_ref tmp
;
14841 /* Make a copy of the object address. */
14842 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14843 add_loc_descr (&loc_descr
, tmp
);
14845 /* Extract the vtable address. */
14846 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14847 add_loc_descr (&loc_descr
, tmp
);
14849 /* Calculate the address of the offset. */
14850 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14851 gcc_assert (offset
< 0);
14853 tmp
= int_loc_descriptor (-offset
);
14854 add_loc_descr (&loc_descr
, tmp
);
14855 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14856 add_loc_descr (&loc_descr
, tmp
);
14858 /* Extract the offset. */
14859 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14860 add_loc_descr (&loc_descr
, tmp
);
14862 /* Add it to the object address. */
14863 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14864 add_loc_descr (&loc_descr
, tmp
);
14867 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14870 offset
= field_byte_offset (decl
);
14874 if (dwarf_version
> 2)
14876 /* Don't need to output a location expression, just the constant. */
14878 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14880 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14885 enum dwarf_location_atom op
;
14887 /* The DWARF2 standard says that we should assume that the structure
14888 address is already on the stack, so we can specify a structure
14889 field address by using DW_OP_plus_uconst. */
14890 op
= DW_OP_plus_uconst
;
14891 loc_descr
= new_loc_descr (op
, offset
, 0);
14895 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14898 /* Writes integer values to dw_vec_const array. */
14901 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14905 *dest
++ = val
& 0xff;
14911 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14913 static HOST_WIDE_INT
14914 extract_int (const unsigned char *src
, unsigned int size
)
14916 HOST_WIDE_INT val
= 0;
14922 val
|= *--src
& 0xff;
14928 /* Writes double_int values to dw_vec_const array. */
14931 insert_double (double_int val
, unsigned char *dest
)
14933 unsigned char *p0
= dest
;
14934 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14936 if (WORDS_BIG_ENDIAN
)
14942 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14943 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14946 /* Writes floating point values to dw_vec_const array. */
14949 insert_float (const_rtx rtl
, unsigned char *array
)
14951 REAL_VALUE_TYPE rv
;
14955 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14956 real_to_target (val
, &rv
, GET_MODE (rtl
));
14958 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14959 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14961 insert_int (val
[i
], 4, array
);
14966 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14967 does not have a "location" either in memory or in a register. These
14968 things can arise in GNU C when a constant is passed as an actual parameter
14969 to an inlined function. They can also arise in C++ where declared
14970 constants do not necessarily get memory "homes". */
14973 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14975 switch (GET_CODE (rtl
))
14979 HOST_WIDE_INT val
= INTVAL (rtl
);
14982 add_AT_int (die
, DW_AT_const_value
, val
);
14984 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14989 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14990 floating-point constant. A CONST_DOUBLE is used whenever the
14991 constant requires more than one word in order to be adequately
14994 enum machine_mode mode
= GET_MODE (rtl
);
14996 if (SCALAR_FLOAT_MODE_P (mode
))
14998 unsigned int length
= GET_MODE_SIZE (mode
);
14999 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
15001 insert_float (rtl
, array
);
15002 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15005 add_AT_double (die
, DW_AT_const_value
,
15006 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15012 enum machine_mode mode
= GET_MODE (rtl
);
15013 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15014 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15015 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
15016 (length
* elt_size
);
15020 switch (GET_MODE_CLASS (mode
))
15022 case MODE_VECTOR_INT
:
15023 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15025 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15026 double_int val
= rtx_to_double_int (elt
);
15028 if (elt_size
<= sizeof (HOST_WIDE_INT
))
15029 insert_int (val
.to_shwi (), elt_size
, p
);
15032 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
15033 insert_double (val
, p
);
15038 case MODE_VECTOR_FLOAT
:
15039 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15041 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15042 insert_float (elt
, p
);
15047 gcc_unreachable ();
15050 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15055 if (dwarf_version
>= 4 || !dwarf_strict
)
15057 dw_loc_descr_ref loc_result
;
15058 resolve_one_addr (&rtl
, NULL
);
15060 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15061 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15062 add_AT_loc (die
, DW_AT_location
, loc_result
);
15063 vec_safe_push (used_rtx_array
, rtl
);
15069 if (CONSTANT_P (XEXP (rtl
, 0)))
15070 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15073 if (!const_ok_for_output (rtl
))
15076 if (dwarf_version
>= 4 || !dwarf_strict
)
15081 /* In cases where an inlined instance of an inline function is passed
15082 the address of an `auto' variable (which is local to the caller) we
15083 can get a situation where the DECL_RTL of the artificial local
15084 variable (for the inlining) which acts as a stand-in for the
15085 corresponding formal parameter (of the inline function) will look
15086 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15087 exactly a compile-time constant expression, but it isn't the address
15088 of the (artificial) local variable either. Rather, it represents the
15089 *value* which the artificial local variable always has during its
15090 lifetime. We currently have no way to represent such quasi-constant
15091 values in Dwarf, so for now we just punt and generate nothing. */
15099 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15100 && MEM_READONLY_P (rtl
)
15101 && GET_MODE (rtl
) == BLKmode
)
15103 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15109 /* No other kinds of rtx should be possible here. */
15110 gcc_unreachable ();
15115 /* Determine whether the evaluation of EXPR references any variables
15116 or functions which aren't otherwise used (and therefore may not be
15119 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15120 void * data ATTRIBUTE_UNUSED
)
15122 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15123 *walk_subtrees
= 0;
15125 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15126 && ! TREE_ASM_WRITTEN (*tp
))
15128 /* ??? The C++ FE emits debug information for using decls, so
15129 putting gcc_unreachable here falls over. See PR31899. For now
15130 be conservative. */
15131 else if (!cgraph_global_info_ready
15132 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15134 else if (TREE_CODE (*tp
) == VAR_DECL
)
15136 struct varpool_node
*node
= varpool_get_node (*tp
);
15137 if (!node
|| !node
->analyzed
)
15140 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15141 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15143 /* The call graph machinery must have finished analyzing,
15144 optimizing and gimplifying the CU by now.
15145 So if *TP has no call graph node associated
15146 to it, it means *TP will not be emitted. */
15147 if (!cgraph_get_node (*tp
))
15150 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15156 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15157 for use in a later add_const_value_attribute call. */
15160 rtl_for_decl_init (tree init
, tree type
)
15162 rtx rtl
= NULL_RTX
;
15166 /* If a variable is initialized with a string constant without embedded
15167 zeros, build CONST_STRING. */
15168 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15170 tree enttype
= TREE_TYPE (type
);
15171 tree domain
= TYPE_DOMAIN (type
);
15172 enum machine_mode mode
= TYPE_MODE (enttype
);
15174 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15176 && integer_zerop (TYPE_MIN_VALUE (domain
))
15177 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15178 TREE_STRING_LENGTH (init
) - 1) == 0
15179 && ((size_t) TREE_STRING_LENGTH (init
)
15180 == strlen (TREE_STRING_POINTER (init
)) + 1))
15182 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15183 ggc_strdup (TREE_STRING_POINTER (init
)));
15184 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15185 MEM_READONLY_P (rtl
) = 1;
15188 /* Other aggregates, and complex values, could be represented using
15190 else if (AGGREGATE_TYPE_P (type
)
15191 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15192 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15193 || TREE_CODE (type
) == COMPLEX_TYPE
)
15195 /* Vectors only work if their mode is supported by the target.
15196 FIXME: generic vectors ought to work too. */
15197 else if (TREE_CODE (type
) == VECTOR_TYPE
15198 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15200 /* If the initializer is something that we know will expand into an
15201 immediate RTL constant, expand it now. We must be careful not to
15202 reference variables which won't be output. */
15203 else if (initializer_constant_valid_p (init
, type
)
15204 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15206 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15208 if (TREE_CODE (type
) == VECTOR_TYPE
)
15209 switch (TREE_CODE (init
))
15214 if (TREE_CONSTANT (init
))
15216 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15217 bool constant_p
= true;
15219 unsigned HOST_WIDE_INT ix
;
15221 /* Even when ctor is constant, it might contain non-*_CST
15222 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15223 belong into VECTOR_CST nodes. */
15224 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15225 if (!CONSTANT_CLASS_P (value
))
15227 constant_p
= false;
15233 init
= build_vector_from_ctor (type
, elts
);
15243 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15245 /* If expand_expr returns a MEM, it wasn't immediate. */
15246 gcc_assert (!rtl
|| !MEM_P (rtl
));
15252 /* Generate RTL for the variable DECL to represent its location. */
15255 rtl_for_decl_location (tree decl
)
15259 /* Here we have to decide where we are going to say the parameter "lives"
15260 (as far as the debugger is concerned). We only have a couple of
15261 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15263 DECL_RTL normally indicates where the parameter lives during most of the
15264 activation of the function. If optimization is enabled however, this
15265 could be either NULL or else a pseudo-reg. Both of those cases indicate
15266 that the parameter doesn't really live anywhere (as far as the code
15267 generation parts of GCC are concerned) during most of the function's
15268 activation. That will happen (for example) if the parameter is never
15269 referenced within the function.
15271 We could just generate a location descriptor here for all non-NULL
15272 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15273 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15274 where DECL_RTL is NULL or is a pseudo-reg.
15276 Note however that we can only get away with using DECL_INCOMING_RTL as
15277 a backup substitute for DECL_RTL in certain limited cases. In cases
15278 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15279 we can be sure that the parameter was passed using the same type as it is
15280 declared to have within the function, and that its DECL_INCOMING_RTL
15281 points us to a place where a value of that type is passed.
15283 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15284 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15285 because in these cases DECL_INCOMING_RTL points us to a value of some
15286 type which is *different* from the type of the parameter itself. Thus,
15287 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15288 such cases, the debugger would end up (for example) trying to fetch a
15289 `float' from a place which actually contains the first part of a
15290 `double'. That would lead to really incorrect and confusing
15291 output at debug-time.
15293 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15294 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15295 are a couple of exceptions however. On little-endian machines we can
15296 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15297 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15298 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15299 when (on a little-endian machine) a non-prototyped function has a
15300 parameter declared to be of type `short' or `char'. In such cases,
15301 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15302 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15303 passed `int' value. If the debugger then uses that address to fetch
15304 a `short' or a `char' (on a little-endian machine) the result will be
15305 the correct data, so we allow for such exceptional cases below.
15307 Note that our goal here is to describe the place where the given formal
15308 parameter lives during most of the function's activation (i.e. between the
15309 end of the prologue and the start of the epilogue). We'll do that as best
15310 as we can. Note however that if the given formal parameter is modified
15311 sometime during the execution of the function, then a stack backtrace (at
15312 debug-time) will show the function as having been called with the *new*
15313 value rather than the value which was originally passed in. This happens
15314 rarely enough that it is not a major problem, but it *is* a problem, and
15315 I'd like to fix it.
15317 A future version of dwarf2out.c may generate two additional attributes for
15318 any given DW_TAG_formal_parameter DIE which will describe the "passed
15319 type" and the "passed location" for the given formal parameter in addition
15320 to the attributes we now generate to indicate the "declared type" and the
15321 "active location" for each parameter. This additional set of attributes
15322 could be used by debuggers for stack backtraces. Separately, note that
15323 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15324 This happens (for example) for inlined-instances of inline function formal
15325 parameters which are never referenced. This really shouldn't be
15326 happening. All PARM_DECL nodes should get valid non-NULL
15327 DECL_INCOMING_RTL values. FIXME. */
15329 /* Use DECL_RTL as the "location" unless we find something better. */
15330 rtl
= DECL_RTL_IF_SET (decl
);
15332 /* When generating abstract instances, ignore everything except
15333 constants, symbols living in memory, and symbols living in
15334 fixed registers. */
15335 if (! reload_completed
)
15338 && (CONSTANT_P (rtl
)
15340 && CONSTANT_P (XEXP (rtl
, 0)))
15342 && TREE_CODE (decl
) == VAR_DECL
15343 && TREE_STATIC (decl
))))
15345 rtl
= targetm
.delegitimize_address (rtl
);
15350 else if (TREE_CODE (decl
) == PARM_DECL
)
15352 if (rtl
== NULL_RTX
15353 || is_pseudo_reg (rtl
)
15355 && is_pseudo_reg (XEXP (rtl
, 0))
15356 && DECL_INCOMING_RTL (decl
)
15357 && MEM_P (DECL_INCOMING_RTL (decl
))
15358 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15360 tree declared_type
= TREE_TYPE (decl
);
15361 tree passed_type
= DECL_ARG_TYPE (decl
);
15362 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15363 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15365 /* This decl represents a formal parameter which was optimized out.
15366 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15367 all cases where (rtl == NULL_RTX) just below. */
15368 if (dmode
== pmode
)
15369 rtl
= DECL_INCOMING_RTL (decl
);
15370 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15371 && SCALAR_INT_MODE_P (dmode
)
15372 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15373 && DECL_INCOMING_RTL (decl
))
15375 rtx inc
= DECL_INCOMING_RTL (decl
);
15378 else if (MEM_P (inc
))
15380 if (BYTES_BIG_ENDIAN
)
15381 rtl
= adjust_address_nv (inc
, dmode
,
15382 GET_MODE_SIZE (pmode
)
15383 - GET_MODE_SIZE (dmode
));
15390 /* If the parm was passed in registers, but lives on the stack, then
15391 make a big endian correction if the mode of the type of the
15392 parameter is not the same as the mode of the rtl. */
15393 /* ??? This is the same series of checks that are made in dbxout.c before
15394 we reach the big endian correction code there. It isn't clear if all
15395 of these checks are necessary here, but keeping them all is the safe
15397 else if (MEM_P (rtl
)
15398 && XEXP (rtl
, 0) != const0_rtx
15399 && ! CONSTANT_P (XEXP (rtl
, 0))
15400 /* Not passed in memory. */
15401 && !MEM_P (DECL_INCOMING_RTL (decl
))
15402 /* Not passed by invisible reference. */
15403 && (!REG_P (XEXP (rtl
, 0))
15404 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15405 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15406 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15407 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15410 /* Big endian correction check. */
15411 && BYTES_BIG_ENDIAN
15412 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15413 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15416 enum machine_mode addr_mode
= get_address_mode (rtl
);
15417 int offset
= (UNITS_PER_WORD
15418 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15420 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15421 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15424 else if (TREE_CODE (decl
) == VAR_DECL
15427 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15428 && BYTES_BIG_ENDIAN
)
15430 enum machine_mode addr_mode
= get_address_mode (rtl
);
15431 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15432 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15434 /* If a variable is declared "register" yet is smaller than
15435 a register, then if we store the variable to memory, it
15436 looks like we're storing a register-sized value, when in
15437 fact we are not. We need to adjust the offset of the
15438 storage location to reflect the actual value's bytes,
15439 else gdb will not be able to display it. */
15441 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15442 plus_constant (addr_mode
, XEXP (rtl
, 0),
15446 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15447 and will have been substituted directly into all expressions that use it.
15448 C does not have such a concept, but C++ and other languages do. */
15449 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15450 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15453 rtl
= targetm
.delegitimize_address (rtl
);
15455 /* If we don't look past the constant pool, we risk emitting a
15456 reference to a constant pool entry that isn't referenced from
15457 code, and thus is not emitted. */
15459 rtl
= avoid_constant_pool_reference (rtl
);
15461 /* Try harder to get a rtl. If this symbol ends up not being emitted
15462 in the current CU, resolve_addr will remove the expression referencing
15464 if (rtl
== NULL_RTX
15465 && TREE_CODE (decl
) == VAR_DECL
15466 && !DECL_EXTERNAL (decl
)
15467 && TREE_STATIC (decl
)
15468 && DECL_NAME (decl
)
15469 && !DECL_HARD_REGISTER (decl
)
15470 && DECL_MODE (decl
) != VOIDmode
)
15472 rtl
= make_decl_rtl_for_debug (decl
);
15474 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15475 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15482 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15483 returned. If so, the decl for the COMMON block is returned, and the
15484 value is the offset into the common block for the symbol. */
15487 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15489 tree val_expr
, cvar
;
15490 enum machine_mode mode
;
15491 HOST_WIDE_INT bitsize
, bitpos
;
15493 int unsignedp
, volatilep
= 0;
15495 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15496 it does not have a value (the offset into the common area), or if it
15497 is thread local (as opposed to global) then it isn't common, and shouldn't
15498 be handled as such. */
15499 if (TREE_CODE (decl
) != VAR_DECL
15500 || !TREE_STATIC (decl
)
15501 || !DECL_HAS_VALUE_EXPR_P (decl
)
15505 val_expr
= DECL_VALUE_EXPR (decl
);
15506 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15509 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15510 &mode
, &unsignedp
, &volatilep
, true);
15512 if (cvar
== NULL_TREE
15513 || TREE_CODE (cvar
) != VAR_DECL
15514 || DECL_ARTIFICIAL (cvar
)
15515 || !TREE_PUBLIC (cvar
))
15519 if (offset
!= NULL
)
15521 if (!host_integerp (offset
, 0))
15523 *value
= tree_low_cst (offset
, 0);
15526 *value
+= bitpos
/ BITS_PER_UNIT
;
15531 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15532 data attribute for a variable or a parameter. We generate the
15533 DW_AT_const_value attribute only in those cases where the given variable
15534 or parameter does not have a true "location" either in memory or in a
15535 register. This can happen (for example) when a constant is passed as an
15536 actual argument in a call to an inline function. (It's possible that
15537 these things can crop up in other ways also.) Note that one type of
15538 constant value which can be passed into an inlined function is a constant
15539 pointer. This can happen for example if an actual argument in an inlined
15540 function call evaluates to a compile-time constant address.
15542 CACHE_P is true if it is worth caching the location list for DECL,
15543 so that future calls can reuse it rather than regenerate it from scratch.
15544 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15545 since we will need to refer to them each time the function is inlined. */
15548 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15549 enum dwarf_attribute attr
)
15552 dw_loc_list_ref list
;
15553 var_loc_list
*loc_list
;
15554 cached_dw_loc_list
*cache
;
15557 if (TREE_CODE (decl
) == ERROR_MARK
)
15560 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15561 || TREE_CODE (decl
) == RESULT_DECL
);
15563 /* Try to get some constant RTL for this decl, and use that as the value of
15566 rtl
= rtl_for_decl_location (decl
);
15567 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15568 && add_const_value_attribute (die
, rtl
))
15571 /* See if we have single element location list that is equivalent to
15572 a constant value. That way we are better to use add_const_value_attribute
15573 rather than expanding constant value equivalent. */
15574 loc_list
= lookup_decl_loc (decl
);
15577 && loc_list
->first
->next
== NULL
15578 && NOTE_P (loc_list
->first
->loc
)
15579 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15580 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15582 struct var_loc_node
*node
;
15584 node
= loc_list
->first
;
15585 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15586 if (GET_CODE (rtl
) == EXPR_LIST
)
15587 rtl
= XEXP (rtl
, 0);
15588 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15589 && add_const_value_attribute (die
, rtl
))
15592 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15593 list several times. See if we've already cached the contents. */
15595 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15599 cache
= (cached_dw_loc_list
*)
15600 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15602 list
= cache
->loc_list
;
15606 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15607 /* It is usually worth caching this result if the decl is from
15608 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15609 if (cache_p
&& list
&& list
->dw_loc_next
)
15611 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15612 DECL_UID (decl
), INSERT
);
15613 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15614 cache
->decl_id
= DECL_UID (decl
);
15615 cache
->loc_list
= list
;
15621 add_AT_location_description (die
, attr
, list
);
15624 /* None of that worked, so it must not really have a location;
15625 try adding a constant value attribute from the DECL_INITIAL. */
15626 return tree_add_const_value_attribute_for_decl (die
, decl
);
15629 /* Add VARIABLE and DIE into deferred locations list. */
15632 defer_location (tree variable
, dw_die_ref die
)
15634 deferred_locations entry
;
15635 entry
.variable
= variable
;
15637 vec_safe_push (deferred_locations_list
, entry
);
15640 /* Helper function for tree_add_const_value_attribute. Natively encode
15641 initializer INIT into an array. Return true if successful. */
15644 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15648 if (init
== NULL_TREE
)
15652 switch (TREE_CODE (init
))
15655 type
= TREE_TYPE (init
);
15656 if (TREE_CODE (type
) == ARRAY_TYPE
)
15658 tree enttype
= TREE_TYPE (type
);
15659 enum machine_mode mode
= TYPE_MODE (enttype
);
15661 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15663 if (int_size_in_bytes (type
) != size
)
15665 if (size
> TREE_STRING_LENGTH (init
))
15667 memcpy (array
, TREE_STRING_POINTER (init
),
15668 TREE_STRING_LENGTH (init
));
15669 memset (array
+ TREE_STRING_LENGTH (init
),
15670 '\0', size
- TREE_STRING_LENGTH (init
));
15673 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15678 type
= TREE_TYPE (init
);
15679 if (int_size_in_bytes (type
) != size
)
15681 if (TREE_CODE (type
) == ARRAY_TYPE
)
15683 HOST_WIDE_INT min_index
;
15684 unsigned HOST_WIDE_INT cnt
;
15685 int curpos
= 0, fieldsize
;
15686 constructor_elt
*ce
;
15688 if (TYPE_DOMAIN (type
) == NULL_TREE
15689 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15692 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15693 if (fieldsize
<= 0)
15696 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15697 memset (array
, '\0', size
);
15698 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15700 tree val
= ce
->value
;
15701 tree index
= ce
->index
;
15703 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15704 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15707 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15712 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15715 curpos
= pos
+ fieldsize
;
15716 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15718 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15719 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15720 while (count
-- > 0)
15723 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15724 curpos
+= fieldsize
;
15727 gcc_assert (curpos
<= size
);
15731 else if (TREE_CODE (type
) == RECORD_TYPE
15732 || TREE_CODE (type
) == UNION_TYPE
)
15734 tree field
= NULL_TREE
;
15735 unsigned HOST_WIDE_INT cnt
;
15736 constructor_elt
*ce
;
15738 if (int_size_in_bytes (type
) != size
)
15741 if (TREE_CODE (type
) == RECORD_TYPE
)
15742 field
= TYPE_FIELDS (type
);
15744 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15746 tree val
= ce
->value
;
15747 int pos
, fieldsize
;
15749 if (ce
->index
!= 0)
15755 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15758 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15759 && TYPE_DOMAIN (TREE_TYPE (field
))
15760 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15762 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15763 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15765 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15766 pos
= int_byte_position (field
);
15767 gcc_assert (pos
+ fieldsize
<= size
);
15769 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15775 case VIEW_CONVERT_EXPR
:
15776 case NON_LVALUE_EXPR
:
15777 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15779 return native_encode_expr (init
, array
, size
) == size
;
15783 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15784 attribute is the const value T. */
15787 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15790 tree type
= TREE_TYPE (t
);
15793 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15797 gcc_assert (!DECL_P (init
));
15799 rtl
= rtl_for_decl_init (init
, type
);
15801 return add_const_value_attribute (die
, rtl
);
15802 /* If the host and target are sane, try harder. */
15803 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15804 && initializer_constant_valid_p (init
, type
))
15806 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15807 if (size
> 0 && (int) size
== size
)
15809 unsigned char *array
= (unsigned char *)
15810 ggc_alloc_cleared_atomic (size
);
15812 if (native_encode_initializer (init
, array
, size
))
15814 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15822 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15823 attribute is the const value of T, where T is an integral constant
15824 variable with static storage duration
15825 (so it can't be a PARM_DECL or a RESULT_DECL). */
15828 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15832 || (TREE_CODE (decl
) != VAR_DECL
15833 && TREE_CODE (decl
) != CONST_DECL
)
15834 || (TREE_CODE (decl
) == VAR_DECL
15835 && !TREE_STATIC (decl
)))
15838 if (TREE_READONLY (decl
)
15839 && ! TREE_THIS_VOLATILE (decl
)
15840 && DECL_INITIAL (decl
))
15845 /* Don't add DW_AT_const_value if abstract origin already has one. */
15846 if (get_AT (var_die
, DW_AT_const_value
))
15849 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15852 /* Convert the CFI instructions for the current function into a
15853 location list. This is used for DW_AT_frame_base when we targeting
15854 a dwarf2 consumer that does not support the dwarf3
15855 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15858 static dw_loc_list_ref
15859 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15863 dw_loc_list_ref list
, *list_tail
;
15865 dw_cfa_location last_cfa
, next_cfa
;
15866 const char *start_label
, *last_label
, *section
;
15867 dw_cfa_location remember
;
15870 gcc_assert (fde
!= NULL
);
15872 section
= secname_for_decl (current_function_decl
);
15876 memset (&next_cfa
, 0, sizeof (next_cfa
));
15877 next_cfa
.reg
= INVALID_REGNUM
;
15878 remember
= next_cfa
;
15880 start_label
= fde
->dw_fde_begin
;
15882 /* ??? Bald assumption that the CIE opcode list does not contain
15883 advance opcodes. */
15884 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15885 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15887 last_cfa
= next_cfa
;
15888 last_label
= start_label
;
15890 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15892 /* If the first partition contained no CFI adjustments, the
15893 CIE opcodes apply to the whole first partition. */
15894 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15895 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15896 list_tail
=&(*list_tail
)->dw_loc_next
;
15897 start_label
= last_label
= fde
->dw_fde_second_begin
;
15900 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15902 switch (cfi
->dw_cfi_opc
)
15904 case DW_CFA_set_loc
:
15905 case DW_CFA_advance_loc1
:
15906 case DW_CFA_advance_loc2
:
15907 case DW_CFA_advance_loc4
:
15908 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15910 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15911 start_label
, last_label
, section
);
15913 list_tail
= &(*list_tail
)->dw_loc_next
;
15914 last_cfa
= next_cfa
;
15915 start_label
= last_label
;
15917 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15920 case DW_CFA_advance_loc
:
15921 /* The encoding is complex enough that we should never emit this. */
15922 gcc_unreachable ();
15925 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15928 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15930 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15932 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15933 start_label
, last_label
, section
);
15935 list_tail
= &(*list_tail
)->dw_loc_next
;
15936 last_cfa
= next_cfa
;
15937 start_label
= last_label
;
15939 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15940 start_label
, fde
->dw_fde_end
, section
);
15941 list_tail
= &(*list_tail
)->dw_loc_next
;
15942 start_label
= last_label
= fde
->dw_fde_second_begin
;
15946 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15948 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15949 start_label
, last_label
, section
);
15950 list_tail
= &(*list_tail
)->dw_loc_next
;
15951 start_label
= last_label
;
15954 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15956 fde
->dw_fde_second_begin
15957 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15960 if (list
&& list
->dw_loc_next
)
15966 /* Compute a displacement from the "steady-state frame pointer" to the
15967 frame base (often the same as the CFA), and store it in
15968 frame_pointer_fb_offset. OFFSET is added to the displacement
15969 before the latter is negated. */
15972 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15976 #ifdef FRAME_POINTER_CFA_OFFSET
15977 reg
= frame_pointer_rtx
;
15978 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15980 reg
= arg_pointer_rtx
;
15981 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15984 elim
= (ira_use_lra_p
15985 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15986 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15987 if (GET_CODE (elim
) == PLUS
)
15989 offset
+= INTVAL (XEXP (elim
, 1));
15990 elim
= XEXP (elim
, 0);
15993 frame_pointer_fb_offset
= -offset
;
15995 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15996 in which to eliminate. This is because it's stack pointer isn't
15997 directly accessible as a register within the ISA. To work around
15998 this, assume that while we cannot provide a proper value for
15999 frame_pointer_fb_offset, we won't need one either. */
16000 frame_pointer_fb_offset_valid
16001 = ((SUPPORTS_STACK_ALIGNMENT
16002 && (elim
== hard_frame_pointer_rtx
16003 || elim
== stack_pointer_rtx
))
16004 || elim
== (frame_pointer_needed
16005 ? hard_frame_pointer_rtx
16006 : stack_pointer_rtx
));
16009 /* Generate a DW_AT_name attribute given some string value to be included as
16010 the value of the attribute. */
16013 add_name_attribute (dw_die_ref die
, const char *name_string
)
16015 if (name_string
!= NULL
&& *name_string
!= 0)
16017 if (demangle_name_func
)
16018 name_string
= (*demangle_name_func
) (name_string
);
16020 add_AT_string (die
, DW_AT_name
, name_string
);
16024 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16025 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16026 of TYPE accordingly.
16028 ??? This is a temporary measure until after we're able to generate
16029 regular DWARF for the complex Ada type system. */
16032 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16033 dw_die_ref context_die
)
16036 dw_die_ref dtype_die
;
16038 if (!lang_hooks
.types
.descriptive_type
)
16041 dtype
= lang_hooks
.types
.descriptive_type (type
);
16045 dtype_die
= lookup_type_die (dtype
);
16048 gen_type_die (dtype
, context_die
);
16049 dtype_die
= lookup_type_die (dtype
);
16050 gcc_assert (dtype_die
);
16053 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16056 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16058 static const char *
16059 comp_dir_string (void)
16063 static const char *cached_wd
= NULL
;
16065 if (cached_wd
!= NULL
)
16068 wd
= get_src_pwd ();
16072 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16076 wdlen
= strlen (wd
);
16077 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
16079 wd1
[wdlen
] = DIR_SEPARATOR
;
16080 wd1
[wdlen
+ 1] = 0;
16084 cached_wd
= remap_debug_filename (wd
);
16088 /* Generate a DW_AT_comp_dir attribute for DIE. */
16091 add_comp_dir_attribute (dw_die_ref die
)
16093 const char * wd
= comp_dir_string ();
16095 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16098 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16102 lower_bound_default (void)
16104 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16109 case DW_LANG_C_plus_plus
:
16111 case DW_LANG_ObjC_plus_plus
:
16114 case DW_LANG_Fortran77
:
16115 case DW_LANG_Fortran90
:
16116 case DW_LANG_Fortran95
:
16120 case DW_LANG_Python
:
16121 return dwarf_version
>= 4 ? 0 : -1;
16122 case DW_LANG_Ada95
:
16123 case DW_LANG_Ada83
:
16124 case DW_LANG_Cobol74
:
16125 case DW_LANG_Cobol85
:
16126 case DW_LANG_Pascal83
:
16127 case DW_LANG_Modula2
:
16129 return dwarf_version
>= 4 ? 1 : -1;
16135 /* Given a tree node describing an array bound (either lower or upper) output
16136 a representation for that bound. */
16139 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16141 switch (TREE_CODE (bound
))
16146 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16149 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16152 /* Use the default if possible. */
16153 if (bound_attr
== DW_AT_lower_bound
16154 && host_integerp (bound
, 0)
16155 && (dflt
= lower_bound_default ()) != -1
16156 && tree_low_cst (bound
, 0) == dflt
)
16159 /* Otherwise represent the bound as an unsigned value with the
16160 precision of its type. The precision and signedness of the
16161 type will be necessary to re-interpret it unambiguously. */
16162 else if (prec
< HOST_BITS_PER_WIDE_INT
)
16164 unsigned HOST_WIDE_INT mask
16165 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
16166 add_AT_unsigned (subrange_die
, bound_attr
,
16167 TREE_INT_CST_LOW (bound
) & mask
);
16169 else if (prec
== HOST_BITS_PER_WIDE_INT
16170 || TREE_INT_CST_HIGH (bound
) == 0)
16171 add_AT_unsigned (subrange_die
, bound_attr
,
16172 TREE_INT_CST_LOW (bound
));
16174 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
16175 TREE_INT_CST_LOW (bound
));
16180 case VIEW_CONVERT_EXPR
:
16181 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16191 dw_die_ref decl_die
= lookup_decl_die (bound
);
16193 /* ??? Can this happen, or should the variable have been bound
16194 first? Probably it can, since I imagine that we try to create
16195 the types of parameters in the order in which they exist in
16196 the list, and won't have created a forward reference to a
16197 later parameter. */
16198 if (decl_die
!= NULL
)
16200 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16208 /* Otherwise try to create a stack operation procedure to
16209 evaluate the value of the array bound. */
16211 dw_die_ref ctx
, decl_die
;
16212 dw_loc_list_ref list
;
16214 list
= loc_list_from_tree (bound
, 2);
16215 if (list
== NULL
|| single_element_loc_list_p (list
))
16217 /* If DW_AT_*bound is not a reference nor constant, it is
16218 a DWARF expression rather than location description.
16219 For that loc_list_from_tree (bound, 0) is needed.
16220 If that fails to give a single element list,
16221 fall back to outputting this as a reference anyway. */
16222 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16223 if (list2
&& single_element_loc_list_p (list2
))
16225 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16232 if (current_function_decl
== 0)
16233 ctx
= comp_unit_die ();
16235 ctx
= lookup_decl_die (current_function_decl
);
16237 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16238 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16239 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16240 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16241 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16247 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16248 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16249 Note that the block of subscript information for an array type also
16250 includes information about the element type of the given array type. */
16253 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16255 unsigned dimension_number
;
16257 dw_die_ref subrange_die
;
16259 for (dimension_number
= 0;
16260 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16261 type
= TREE_TYPE (type
), dimension_number
++)
16263 tree domain
= TYPE_DOMAIN (type
);
16265 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16268 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16269 and (in GNU C only) variable bounds. Handle all three forms
16271 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16274 /* We have an array type with specified bounds. */
16275 lower
= TYPE_MIN_VALUE (domain
);
16276 upper
= TYPE_MAX_VALUE (domain
);
16278 /* Define the index type. */
16279 if (TREE_TYPE (domain
))
16281 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16282 TREE_TYPE field. We can't emit debug info for this
16283 because it is an unnamed integral type. */
16284 if (TREE_CODE (domain
) == INTEGER_TYPE
16285 && TYPE_NAME (domain
) == NULL_TREE
16286 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16287 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16290 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16294 /* ??? If upper is NULL, the array has unspecified length,
16295 but it does have a lower bound. This happens with Fortran
16297 Since the debugger is definitely going to need to know N
16298 to produce useful results, go ahead and output the lower
16299 bound solo, and hope the debugger can cope. */
16301 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16303 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16306 /* Otherwise we have an array type with an unspecified length. The
16307 DWARF-2 spec does not say how to handle this; let's just leave out the
16313 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16315 dw_die_ref decl_die
;
16318 switch (TREE_CODE (tree_node
))
16323 case ENUMERAL_TYPE
:
16326 case QUAL_UNION_TYPE
:
16327 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16328 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16330 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16333 size
= int_size_in_bytes (tree_node
);
16336 /* For a data member of a struct or union, the DW_AT_byte_size is
16337 generally given as the number of bytes normally allocated for an
16338 object of the *declared* type of the member itself. This is true
16339 even for bit-fields. */
16340 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16343 gcc_unreachable ();
16346 /* Note that `size' might be -1 when we get to this point. If it is, that
16347 indicates that the byte size of the entity in question is variable. We
16348 have no good way of expressing this fact in Dwarf at the present time,
16349 so just let the -1 pass on through. */
16350 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16353 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16354 which specifies the distance in bits from the highest order bit of the
16355 "containing object" for the bit-field to the highest order bit of the
16358 For any given bit-field, the "containing object" is a hypothetical object
16359 (of some integral or enum type) within which the given bit-field lives. The
16360 type of this hypothetical "containing object" is always the same as the
16361 declared type of the individual bit-field itself. The determination of the
16362 exact location of the "containing object" for a bit-field is rather
16363 complicated. It's handled by the `field_byte_offset' function (above).
16365 Note that it is the size (in bytes) of the hypothetical "containing object"
16366 which will be given in the DW_AT_byte_size attribute for this bit-field.
16367 (See `byte_size_attribute' above). */
16370 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16372 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16373 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16374 HOST_WIDE_INT bitpos_int
;
16375 HOST_WIDE_INT highest_order_object_bit_offset
;
16376 HOST_WIDE_INT highest_order_field_bit_offset
;
16377 HOST_WIDE_INT bit_offset
;
16379 /* Must be a field and a bit field. */
16380 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16382 /* We can't yet handle bit-fields whose offsets are variable, so if we
16383 encounter such things, just return without generating any attribute
16384 whatsoever. Likewise for variable or too large size. */
16385 if (! host_integerp (bit_position (decl
), 0)
16386 || ! host_integerp (DECL_SIZE (decl
), 1))
16389 bitpos_int
= int_bit_position (decl
);
16391 /* Note that the bit offset is always the distance (in bits) from the
16392 highest-order bit of the "containing object" to the highest-order bit of
16393 the bit-field itself. Since the "high-order end" of any object or field
16394 is different on big-endian and little-endian machines, the computation
16395 below must take account of these differences. */
16396 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16397 highest_order_field_bit_offset
= bitpos_int
;
16399 if (! BYTES_BIG_ENDIAN
)
16401 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16402 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16406 = (! BYTES_BIG_ENDIAN
16407 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16408 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16410 if (bit_offset
< 0)
16411 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16413 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16416 /* For a FIELD_DECL node which represents a bit field, output an attribute
16417 which specifies the length in bits of the given field. */
16420 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16422 /* Must be a field and a bit field. */
16423 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16424 && DECL_BIT_FIELD_TYPE (decl
));
16426 if (host_integerp (DECL_SIZE (decl
), 1))
16427 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16430 /* If the compiled language is ANSI C, then add a 'prototyped'
16431 attribute, if arg types are given for the parameters of a function. */
16434 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16436 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16437 && prototype_p (func_type
))
16438 add_AT_flag (die
, DW_AT_prototyped
, 1);
16441 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16442 by looking in either the type declaration or object declaration
16445 static inline dw_die_ref
16446 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16448 dw_die_ref origin_die
= NULL
;
16450 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16452 /* We may have gotten separated from the block for the inlined
16453 function, if we're in an exception handler or some such; make
16454 sure that the abstract function has been written out.
16456 Doing this for nested functions is wrong, however; functions are
16457 distinct units, and our context might not even be inline. */
16461 fn
= TYPE_STUB_DECL (fn
);
16463 fn
= decl_function_context (fn
);
16465 dwarf2out_abstract_function (fn
);
16468 if (DECL_P (origin
))
16469 origin_die
= lookup_decl_die (origin
);
16470 else if (TYPE_P (origin
))
16471 origin_die
= lookup_type_die (origin
);
16473 /* XXX: Functions that are never lowered don't always have correct block
16474 trees (in the case of java, they simply have no block tree, in some other
16475 languages). For these functions, there is nothing we can really do to
16476 output correct debug info for inlined functions in all cases. Rather
16477 than die, we'll just produce deficient debug info now, in that we will
16478 have variables without a proper abstract origin. In the future, when all
16479 functions are lowered, we should re-add a gcc_assert (origin_die)
16483 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16487 /* We do not currently support the pure_virtual attribute. */
16490 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16492 if (DECL_VINDEX (func_decl
))
16494 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16496 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16497 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16498 new_loc_descr (DW_OP_constu
,
16499 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16502 /* GNU extension: Record what type this method came from originally. */
16503 if (debug_info_level
> DINFO_LEVEL_TERSE
16504 && DECL_CONTEXT (func_decl
))
16505 add_AT_die_ref (die
, DW_AT_containing_type
,
16506 lookup_type_die (DECL_CONTEXT (func_decl
)));
16510 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16511 given decl. This used to be a vendor extension until after DWARF 4
16512 standardized it. */
16515 add_linkage_attr (dw_die_ref die
, tree decl
)
16517 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16519 /* Mimic what assemble_name_raw does with a leading '*'. */
16520 if (name
[0] == '*')
16523 if (dwarf_version
>= 4)
16524 add_AT_string (die
, DW_AT_linkage_name
, name
);
16526 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16529 /* Add source coordinate attributes for the given decl. */
16532 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16534 expanded_location s
;
16536 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16538 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16539 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16540 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16543 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16546 add_linkage_name (dw_die_ref die
, tree decl
)
16548 if (debug_info_level
> DINFO_LEVEL_NONE
16549 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16550 && TREE_PUBLIC (decl
)
16551 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16552 && die
->die_tag
!= DW_TAG_member
)
16554 /* Defer until we have an assembler name set. */
16555 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16557 limbo_die_node
*asm_name
;
16559 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16560 asm_name
->die
= die
;
16561 asm_name
->created_for
= decl
;
16562 asm_name
->next
= deferred_asm_name
;
16563 deferred_asm_name
= asm_name
;
16565 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16566 add_linkage_attr (die
, decl
);
16570 /* Add a DW_AT_name attribute and source coordinate attribute for the
16571 given decl, but only if it actually has a name. */
16574 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16578 decl_name
= DECL_NAME (decl
);
16579 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16581 const char *name
= dwarf2_name (decl
, 0);
16583 add_name_attribute (die
, name
);
16584 if (! DECL_ARTIFICIAL (decl
))
16585 add_src_coords_attributes (die
, decl
);
16587 add_linkage_name (die
, decl
);
16590 #ifdef VMS_DEBUGGING_INFO
16591 /* Get the function's name, as described by its RTL. This may be different
16592 from the DECL_NAME name used in the source file. */
16593 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16595 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16596 XEXP (DECL_RTL (decl
), 0), false);
16597 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16599 #endif /* VMS_DEBUGGING_INFO */
16602 #ifdef VMS_DEBUGGING_INFO
16603 /* Output the debug main pointer die for VMS */
16606 dwarf2out_vms_debug_main_pointer (void)
16608 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16611 /* Allocate the VMS debug main subprogram die. */
16612 die
= ggc_alloc_cleared_die_node ();
16613 die
->die_tag
= DW_TAG_subprogram
;
16614 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16615 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16616 FUNC_LABEL_ID (cfun
));
16617 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16619 /* Make it the first child of comp_unit_die (). */
16620 die
->die_parent
= comp_unit_die ();
16621 if (comp_unit_die ()->die_child
)
16623 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16624 comp_unit_die ()->die_child
->die_sib
= die
;
16628 die
->die_sib
= die
;
16629 comp_unit_die ()->die_child
= die
;
16632 #endif /* VMS_DEBUGGING_INFO */
16634 /* Push a new declaration scope. */
16637 push_decl_scope (tree scope
)
16639 vec_safe_push (decl_scope_table
, scope
);
16642 /* Pop a declaration scope. */
16645 pop_decl_scope (void)
16647 decl_scope_table
->pop ();
16650 /* walk_tree helper function for uses_local_type, below. */
16653 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16656 *walk_subtrees
= 0;
16659 tree name
= TYPE_NAME (*tp
);
16660 if (name
&& DECL_P (name
) && decl_function_context (name
))
16666 /* If TYPE involves a function-local type (including a local typedef to a
16667 non-local type), returns that type; otherwise returns NULL_TREE. */
16670 uses_local_type (tree type
)
16672 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16676 /* Return the DIE for the scope that immediately contains this type.
16677 Non-named types that do not involve a function-local type get global
16678 scope. Named types nested in namespaces or other types get their
16679 containing scope. All other types (i.e. function-local named types) get
16680 the current active scope. */
16683 scope_die_for (tree t
, dw_die_ref context_die
)
16685 dw_die_ref scope_die
= NULL
;
16686 tree containing_scope
;
16688 /* Non-types always go in the current scope. */
16689 gcc_assert (TYPE_P (t
));
16691 /* Use the scope of the typedef, rather than the scope of the type
16693 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16694 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16696 containing_scope
= TYPE_CONTEXT (t
);
16698 /* Use the containing namespace if there is one. */
16699 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16701 if (context_die
== lookup_decl_die (containing_scope
))
16703 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16704 context_die
= get_context_die (containing_scope
);
16706 containing_scope
= NULL_TREE
;
16709 /* Ignore function type "scopes" from the C frontend. They mean that
16710 a tagged type is local to a parmlist of a function declarator, but
16711 that isn't useful to DWARF. */
16712 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16713 containing_scope
= NULL_TREE
;
16715 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16717 /* If T uses a local type keep it local as well, to avoid references
16718 to function-local DIEs from outside the function. */
16719 if (current_function_decl
&& uses_local_type (t
))
16720 scope_die
= context_die
;
16722 scope_die
= comp_unit_die ();
16724 else if (TYPE_P (containing_scope
))
16726 /* For types, we can just look up the appropriate DIE. */
16727 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16728 scope_die
= get_context_die (containing_scope
);
16731 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16732 if (scope_die
== NULL
)
16733 scope_die
= comp_unit_die ();
16737 scope_die
= context_die
;
16742 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16745 local_scope_p (dw_die_ref context_die
)
16747 for (; context_die
; context_die
= context_die
->die_parent
)
16748 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16749 || context_die
->die_tag
== DW_TAG_subprogram
)
16755 /* Returns nonzero if CONTEXT_DIE is a class. */
16758 class_scope_p (dw_die_ref context_die
)
16760 return (context_die
16761 && (context_die
->die_tag
== DW_TAG_structure_type
16762 || context_die
->die_tag
== DW_TAG_class_type
16763 || context_die
->die_tag
== DW_TAG_interface_type
16764 || context_die
->die_tag
== DW_TAG_union_type
));
16767 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16768 whether or not to treat a DIE in this context as a declaration. */
16771 class_or_namespace_scope_p (dw_die_ref context_die
)
16773 return (class_scope_p (context_die
)
16774 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16777 /* Many forms of DIEs require a "type description" attribute. This
16778 routine locates the proper "type descriptor" die for the type given
16779 by 'type', and adds a DW_AT_type attribute below the given die. */
16782 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16783 int decl_volatile
, dw_die_ref context_die
)
16785 enum tree_code code
= TREE_CODE (type
);
16786 dw_die_ref type_die
= NULL
;
16788 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16789 or fixed-point type, use the inner type. This is because we have no
16790 support for unnamed types in base_type_die. This can happen if this is
16791 an Ada subrange type. Correct solution is emit a subrange type die. */
16792 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16793 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16794 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16796 if (code
== ERROR_MARK
16797 /* Handle a special case. For functions whose return type is void, we
16798 generate *no* type attribute. (Note that no object may have type
16799 `void', so this only applies to function return types). */
16800 || code
== VOID_TYPE
)
16803 type_die
= modified_type_die (type
,
16804 decl_const
|| TYPE_READONLY (type
),
16805 decl_volatile
|| TYPE_VOLATILE (type
),
16808 if (type_die
!= NULL
)
16809 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16812 /* Given an object die, add the calling convention attribute for the
16813 function call type. */
16815 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16817 enum dwarf_calling_convention value
= DW_CC_normal
;
16819 value
= ((enum dwarf_calling_convention
)
16820 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16823 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16825 /* DWARF 2 doesn't provide a way to identify a program's source-level
16826 entry point. DW_AT_calling_convention attributes are only meant
16827 to describe functions' calling conventions. However, lacking a
16828 better way to signal the Fortran main program, we used this for
16829 a long time, following existing custom. Now, DWARF 4 has
16830 DW_AT_main_subprogram, which we add below, but some tools still
16831 rely on the old way, which we thus keep. */
16832 value
= DW_CC_program
;
16834 if (dwarf_version
>= 4 || !dwarf_strict
)
16835 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16838 /* Only add the attribute if the backend requests it, and
16839 is not DW_CC_normal. */
16840 if (value
&& (value
!= DW_CC_normal
))
16841 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16844 /* Given a tree pointer to a struct, class, union, or enum type node, return
16845 a pointer to the (string) tag name for the given type, or zero if the type
16846 was declared without a tag. */
16848 static const char *
16849 type_tag (const_tree type
)
16851 const char *name
= 0;
16853 if (TYPE_NAME (type
) != 0)
16857 /* Find the IDENTIFIER_NODE for the type name. */
16858 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16859 && !TYPE_NAMELESS (type
))
16860 t
= TYPE_NAME (type
);
16862 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16863 a TYPE_DECL node, regardless of whether or not a `typedef' was
16865 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16866 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16868 /* We want to be extra verbose. Don't call dwarf_name if
16869 DECL_NAME isn't set. The default hook for decl_printable_name
16870 doesn't like that, and in this context it's correct to return
16871 0, instead of "<anonymous>" or the like. */
16872 if (DECL_NAME (TYPE_NAME (type
))
16873 && !DECL_NAMELESS (TYPE_NAME (type
)))
16874 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16877 /* Now get the name as a string, or invent one. */
16878 if (!name
&& t
!= 0)
16879 name
= IDENTIFIER_POINTER (t
);
16882 return (name
== 0 || *name
== '\0') ? 0 : name
;
16885 /* Return the type associated with a data member, make a special check
16886 for bit field types. */
16889 member_declared_type (const_tree member
)
16891 return (DECL_BIT_FIELD_TYPE (member
)
16892 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16895 /* Get the decl's label, as described by its RTL. This may be different
16896 from the DECL_NAME name used in the source file. */
16899 static const char *
16900 decl_start_label (tree decl
)
16903 const char *fnname
;
16905 x
= DECL_RTL (decl
);
16906 gcc_assert (MEM_P (x
));
16909 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16911 fnname
= XSTR (x
, 0);
16916 /* These routines generate the internal representation of the DIE's for
16917 the compilation unit. Debugging information is collected by walking
16918 the declaration trees passed in from dwarf2out_decl(). */
16921 gen_array_type_die (tree type
, dw_die_ref context_die
)
16923 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16924 dw_die_ref array_die
;
16926 /* GNU compilers represent multidimensional array types as sequences of one
16927 dimensional array types whose element types are themselves array types.
16928 We sometimes squish that down to a single array_type DIE with multiple
16929 subscripts in the Dwarf debugging info. The draft Dwarf specification
16930 say that we are allowed to do this kind of compression in C, because
16931 there is no difference between an array of arrays and a multidimensional
16932 array. We don't do this for Ada to remain as close as possible to the
16933 actual representation, which is especially important against the language
16934 flexibilty wrt arrays of variable size. */
16936 bool collapse_nested_arrays
= !is_ada ();
16939 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16940 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16941 if (TYPE_STRING_FLAG (type
)
16942 && TREE_CODE (type
) == ARRAY_TYPE
16944 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16946 HOST_WIDE_INT size
;
16948 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16949 add_name_attribute (array_die
, type_tag (type
));
16950 equate_type_number_to_die (type
, array_die
);
16951 size
= int_size_in_bytes (type
);
16953 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16954 else if (TYPE_DOMAIN (type
) != NULL_TREE
16955 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16956 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16958 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16959 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16961 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16962 if (loc
&& size
> 0)
16964 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16965 if (size
!= DWARF2_ADDR_SIZE
)
16966 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16972 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16973 add_name_attribute (array_die
, type_tag (type
));
16974 equate_type_number_to_die (type
, array_die
);
16976 if (TREE_CODE (type
) == VECTOR_TYPE
)
16977 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16979 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16981 && TREE_CODE (type
) == ARRAY_TYPE
16982 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16983 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16984 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16987 /* We default the array ordering. SDB will probably do
16988 the right things even if DW_AT_ordering is not present. It's not even
16989 an issue until we start to get into multidimensional arrays anyway. If
16990 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16991 then we'll have to put the DW_AT_ordering attribute back in. (But if
16992 and when we find out that we need to put these in, we will only do so
16993 for multidimensional arrays. */
16994 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16997 if (TREE_CODE (type
) == VECTOR_TYPE
)
16999 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17000 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17001 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
17002 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17003 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
17006 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17008 /* Add representation of the type of the elements of this array type and
17009 emit the corresponding DIE if we haven't done it already. */
17010 element_type
= TREE_TYPE (type
);
17011 if (collapse_nested_arrays
)
17012 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17014 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17016 element_type
= TREE_TYPE (element_type
);
17019 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
17021 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17022 if (TYPE_ARTIFICIAL (type
))
17023 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17025 if (get_AT (array_die
, DW_AT_name
))
17026 add_pubtype (type
, array_die
);
17029 static dw_loc_descr_ref
17030 descr_info_loc (tree val
, tree base_decl
)
17032 HOST_WIDE_INT size
;
17033 dw_loc_descr_ref loc
, loc2
;
17034 enum dwarf_location_atom op
;
17036 if (val
== base_decl
)
17037 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
17039 switch (TREE_CODE (val
))
17042 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17044 return loc_descriptor_from_tree (val
, 0);
17046 if (host_integerp (val
, 0))
17047 return int_loc_descriptor (tree_low_cst (val
, 0));
17050 size
= int_size_in_bytes (TREE_TYPE (val
));
17053 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17056 if (size
== DWARF2_ADDR_SIZE
)
17057 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
17059 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
17061 case POINTER_PLUS_EXPR
:
17063 if (host_integerp (TREE_OPERAND (val
, 1), 1)
17064 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
17067 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17070 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
17076 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17079 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
17082 add_loc_descr (&loc
, loc2
);
17083 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17105 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17106 tree val
, tree base_decl
)
17108 dw_loc_descr_ref loc
;
17110 if (host_integerp (val
, 0))
17112 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
17116 loc
= descr_info_loc (val
, base_decl
);
17120 add_AT_loc (die
, attr
, loc
);
17123 /* This routine generates DIE for array with hidden descriptor, details
17124 are filled into *info by a langhook. */
17127 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17128 dw_die_ref context_die
)
17130 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17131 dw_die_ref array_die
;
17134 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17135 add_name_attribute (array_die
, type_tag (type
));
17136 equate_type_number_to_die (type
, array_die
);
17138 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17140 && info
->ndimensions
>= 2)
17141 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17143 if (info
->data_location
)
17144 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17146 if (info
->associated
)
17147 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17149 if (info
->allocated
)
17150 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17153 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17155 dw_die_ref subrange_die
17156 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17158 if (info
->dimen
[dim
].lower_bound
)
17160 /* If it is the default value, omit it. */
17163 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
17164 && (dflt
= lower_bound_default ()) != -1
17165 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
17168 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17169 info
->dimen
[dim
].lower_bound
,
17172 if (info
->dimen
[dim
].upper_bound
)
17173 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17174 info
->dimen
[dim
].upper_bound
,
17176 if (info
->dimen
[dim
].stride
)
17177 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17178 info
->dimen
[dim
].stride
,
17182 gen_type_die (info
->element_type
, context_die
);
17183 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17185 if (get_AT (array_die
, DW_AT_name
))
17186 add_pubtype (type
, array_die
);
17191 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17193 tree origin
= decl_ultimate_origin (decl
);
17194 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17196 if (origin
!= NULL
)
17197 add_abstract_origin_attribute (decl_die
, origin
);
17200 add_name_and_src_coords_attributes (decl_die
, decl
);
17201 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17202 0, 0, context_die
);
17205 if (DECL_ABSTRACT (decl
))
17206 equate_decl_number_to_die (decl
, decl_die
);
17208 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17212 /* Walk through the list of incomplete types again, trying once more to
17213 emit full debugging info for them. */
17216 retry_incomplete_types (void)
17220 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17221 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17222 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17225 /* Determine what tag to use for a record type. */
17227 static enum dwarf_tag
17228 record_type_tag (tree type
)
17230 if (! lang_hooks
.types
.classify_record
)
17231 return DW_TAG_structure_type
;
17233 switch (lang_hooks
.types
.classify_record (type
))
17235 case RECORD_IS_STRUCT
:
17236 return DW_TAG_structure_type
;
17238 case RECORD_IS_CLASS
:
17239 return DW_TAG_class_type
;
17241 case RECORD_IS_INTERFACE
:
17242 if (dwarf_version
>= 3 || !dwarf_strict
)
17243 return DW_TAG_interface_type
;
17244 return DW_TAG_structure_type
;
17247 gcc_unreachable ();
17251 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17252 include all of the information about the enumeration values also. Each
17253 enumerated type name/value is listed as a child of the enumerated type
17257 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17259 dw_die_ref type_die
= lookup_type_die (type
);
17261 if (type_die
== NULL
)
17263 type_die
= new_die (DW_TAG_enumeration_type
,
17264 scope_die_for (type
, context_die
), type
);
17265 equate_type_number_to_die (type
, type_die
);
17266 add_name_attribute (type_die
, type_tag (type
));
17267 if (dwarf_version
>= 4 || !dwarf_strict
)
17269 if (ENUM_IS_SCOPED (type
))
17270 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17271 if (ENUM_IS_OPAQUE (type
))
17272 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17275 else if (! TYPE_SIZE (type
))
17278 remove_AT (type_die
, DW_AT_declaration
);
17280 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17281 given enum type is incomplete, do not generate the DW_AT_byte_size
17282 attribute or the DW_AT_element_list attribute. */
17283 if (TYPE_SIZE (type
))
17287 TREE_ASM_WRITTEN (type
) = 1;
17288 add_byte_size_attribute (type_die
, type
);
17289 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17291 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17292 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17295 /* If the first reference to this type was as the return type of an
17296 inline function, then it may not have a parent. Fix this now. */
17297 if (type_die
->die_parent
== NULL
)
17298 add_child_die (scope_die_for (type
, context_die
), type_die
);
17300 for (link
= TYPE_VALUES (type
);
17301 link
!= NULL
; link
= TREE_CHAIN (link
))
17303 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17304 tree value
= TREE_VALUE (link
);
17306 add_name_attribute (enum_die
,
17307 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17309 if (TREE_CODE (value
) == CONST_DECL
)
17310 value
= DECL_INITIAL (value
);
17312 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
17313 /* DWARF2 does not provide a way of indicating whether or
17314 not enumeration constants are signed or unsigned. GDB
17315 always assumes the values are signed, so we output all
17316 values as if they were signed. That means that
17317 enumeration constants with very large unsigned values
17318 will appear to have negative values in the debugger. */
17319 add_AT_int (enum_die
, DW_AT_const_value
,
17320 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
17323 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17324 if (TYPE_ARTIFICIAL (type
))
17325 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17328 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17330 add_pubtype (type
, type_die
);
17335 /* Generate a DIE to represent either a real live formal parameter decl or to
17336 represent just the type of some formal parameter position in some function
17339 Note that this routine is a bit unusual because its argument may be a
17340 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17341 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17342 node. If it's the former then this function is being called to output a
17343 DIE to represent a formal parameter object (or some inlining thereof). If
17344 it's the latter, then this function is only being called to output a
17345 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17346 argument type of some subprogram type.
17347 If EMIT_NAME_P is true, name and source coordinate attributes
17351 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17352 dw_die_ref context_die
)
17354 tree node_or_origin
= node
? node
: origin
;
17355 tree ultimate_origin
;
17356 dw_die_ref parm_die
17357 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17359 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17361 case tcc_declaration
:
17362 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17363 if (node
|| ultimate_origin
)
17364 origin
= ultimate_origin
;
17365 if (origin
!= NULL
)
17366 add_abstract_origin_attribute (parm_die
, origin
);
17367 else if (emit_name_p
)
17368 add_name_and_src_coords_attributes (parm_die
, node
);
17370 || (! DECL_ABSTRACT (node_or_origin
)
17371 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17372 decl_function_context
17373 (node_or_origin
))))
17375 tree type
= TREE_TYPE (node_or_origin
);
17376 if (decl_by_reference_p (node_or_origin
))
17377 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17380 add_type_attribute (parm_die
, type
,
17381 TREE_READONLY (node_or_origin
),
17382 TREE_THIS_VOLATILE (node_or_origin
),
17385 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17386 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17388 if (node
&& node
!= origin
)
17389 equate_decl_number_to_die (node
, parm_die
);
17390 if (! DECL_ABSTRACT (node_or_origin
))
17391 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17392 node
== NULL
, DW_AT_location
);
17397 /* We were called with some kind of a ..._TYPE node. */
17398 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17402 gcc_unreachable ();
17408 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17409 children DW_TAG_formal_parameter DIEs representing the arguments of the
17412 PARM_PACK must be a function parameter pack.
17413 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17414 must point to the subsequent arguments of the function PACK_ARG belongs to.
17415 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17416 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17417 following the last one for which a DIE was generated. */
17420 gen_formal_parameter_pack_die (tree parm_pack
,
17422 dw_die_ref subr_die
,
17426 dw_die_ref parm_pack_die
;
17428 gcc_assert (parm_pack
17429 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17432 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17433 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17435 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17437 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17440 gen_formal_parameter_die (arg
, NULL
,
17441 false /* Don't emit name attribute. */,
17446 return parm_pack_die
;
17449 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17450 at the end of an (ANSI prototyped) formal parameters list. */
17453 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17455 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17458 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17459 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17460 parameters as specified in some function type specification (except for
17461 those which appear as part of a function *definition*). */
17464 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17467 tree formal_type
= NULL
;
17468 tree first_parm_type
;
17471 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17473 arg
= DECL_ARGUMENTS (function_or_method_type
);
17474 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17479 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17481 /* Make our first pass over the list of formal parameter types and output a
17482 DW_TAG_formal_parameter DIE for each one. */
17483 for (link
= first_parm_type
; link
; )
17485 dw_die_ref parm_die
;
17487 formal_type
= TREE_VALUE (link
);
17488 if (formal_type
== void_type_node
)
17491 /* Output a (nameless) DIE to represent the formal parameter itself. */
17492 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17493 true /* Emit name attribute. */,
17495 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17496 && link
== first_parm_type
)
17498 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17499 if (dwarf_version
>= 3 || !dwarf_strict
)
17500 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17502 else if (arg
&& DECL_ARTIFICIAL (arg
))
17503 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17505 link
= TREE_CHAIN (link
);
17507 arg
= DECL_CHAIN (arg
);
17510 /* If this function type has an ellipsis, add a
17511 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17512 if (formal_type
!= void_type_node
)
17513 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17515 /* Make our second (and final) pass over the list of formal parameter types
17516 and output DIEs to represent those types (as necessary). */
17517 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17518 link
&& TREE_VALUE (link
);
17519 link
= TREE_CHAIN (link
))
17520 gen_type_die (TREE_VALUE (link
), context_die
);
17523 /* We want to generate the DIE for TYPE so that we can generate the
17524 die for MEMBER, which has been defined; we will need to refer back
17525 to the member declaration nested within TYPE. If we're trying to
17526 generate minimal debug info for TYPE, processing TYPE won't do the
17527 trick; we need to attach the member declaration by hand. */
17530 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17532 gen_type_die (type
, context_die
);
17534 /* If we're trying to avoid duplicate debug info, we may not have
17535 emitted the member decl for this function. Emit it now. */
17536 if (TYPE_STUB_DECL (type
)
17537 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17538 && ! lookup_decl_die (member
))
17540 dw_die_ref type_die
;
17541 gcc_assert (!decl_ultimate_origin (member
));
17543 push_decl_scope (type
);
17544 type_die
= lookup_type_die_strip_naming_typedef (type
);
17545 if (TREE_CODE (member
) == FUNCTION_DECL
)
17546 gen_subprogram_die (member
, type_die
);
17547 else if (TREE_CODE (member
) == FIELD_DECL
)
17549 /* Ignore the nameless fields that are used to skip bits but handle
17550 C++ anonymous unions and structs. */
17551 if (DECL_NAME (member
) != NULL_TREE
17552 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17553 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17555 gen_type_die (member_declared_type (member
), type_die
);
17556 gen_field_die (member
, type_die
);
17560 gen_variable_die (member
, NULL_TREE
, type_die
);
17566 /* Forward declare these functions, because they are mutually recursive
17567 with their set_block_* pairing functions. */
17568 static void set_decl_origin_self (tree
);
17569 static void set_decl_abstract_flags (tree
, int);
17571 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17572 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17573 that it points to the node itself, thus indicating that the node is its
17574 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17575 the given node is NULL, recursively descend the decl/block tree which
17576 it is the root of, and for each other ..._DECL or BLOCK node contained
17577 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17578 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17579 values to point to themselves. */
17582 set_block_origin_self (tree stmt
)
17584 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17586 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17591 for (local_decl
= BLOCK_VARS (stmt
);
17592 local_decl
!= NULL_TREE
;
17593 local_decl
= DECL_CHAIN (local_decl
))
17594 if (! DECL_EXTERNAL (local_decl
))
17595 set_decl_origin_self (local_decl
); /* Potential recursion. */
17601 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17602 subblock
!= NULL_TREE
;
17603 subblock
= BLOCK_CHAIN (subblock
))
17604 set_block_origin_self (subblock
); /* Recurse. */
17609 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17610 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17611 node to so that it points to the node itself, thus indicating that the
17612 node represents its own (abstract) origin. Additionally, if the
17613 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17614 the decl/block tree of which the given node is the root of, and for
17615 each other ..._DECL or BLOCK node contained therein whose
17616 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17617 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17618 point to themselves. */
17621 set_decl_origin_self (tree decl
)
17623 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17625 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17626 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17630 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17631 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17632 if (DECL_INITIAL (decl
) != NULL_TREE
17633 && DECL_INITIAL (decl
) != error_mark_node
)
17634 set_block_origin_self (DECL_INITIAL (decl
));
17639 /* Given a pointer to some BLOCK node, and a boolean value to set the
17640 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17641 the given block, and for all local decls and all local sub-blocks
17642 (recursively) which are contained therein. */
17645 set_block_abstract_flags (tree stmt
, int setting
)
17651 BLOCK_ABSTRACT (stmt
) = setting
;
17653 for (local_decl
= BLOCK_VARS (stmt
);
17654 local_decl
!= NULL_TREE
;
17655 local_decl
= DECL_CHAIN (local_decl
))
17656 if (! DECL_EXTERNAL (local_decl
))
17657 set_decl_abstract_flags (local_decl
, setting
);
17659 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17661 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17662 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17663 || TREE_CODE (local_decl
) == PARM_DECL
)
17664 set_decl_abstract_flags (local_decl
, setting
);
17667 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17668 subblock
!= NULL_TREE
;
17669 subblock
= BLOCK_CHAIN (subblock
))
17670 set_block_abstract_flags (subblock
, setting
);
17673 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17674 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17675 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17676 set the abstract flags for all of the parameters, local vars, local
17677 blocks and sub-blocks (recursively) to the same setting. */
17680 set_decl_abstract_flags (tree decl
, int setting
)
17682 DECL_ABSTRACT (decl
) = setting
;
17683 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17687 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17688 DECL_ABSTRACT (arg
) = setting
;
17689 if (DECL_INITIAL (decl
) != NULL_TREE
17690 && DECL_INITIAL (decl
) != error_mark_node
)
17691 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17695 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17696 may later generate inlined and/or out-of-line instances of. */
17699 dwarf2out_abstract_function (tree decl
)
17701 dw_die_ref old_die
;
17705 htab_t old_decl_loc_table
;
17706 htab_t old_cached_dw_loc_list_table
;
17707 int old_call_site_count
, old_tail_call_site_count
;
17708 struct call_arg_loc_node
*old_call_arg_locations
;
17710 /* Make sure we have the actual abstract inline, not a clone. */
17711 decl
= DECL_ORIGIN (decl
);
17713 old_die
= lookup_decl_die (decl
);
17714 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17715 /* We've already generated the abstract instance. */
17718 /* We can be called while recursively when seeing block defining inlined subroutine
17719 DIE. Be sure to not clobber the outer location table nor use it or we would
17720 get locations in abstract instantces. */
17721 old_decl_loc_table
= decl_loc_table
;
17722 decl_loc_table
= NULL
;
17723 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17724 cached_dw_loc_list_table
= NULL
;
17725 old_call_arg_locations
= call_arg_locations
;
17726 call_arg_locations
= NULL
;
17727 old_call_site_count
= call_site_count
;
17728 call_site_count
= -1;
17729 old_tail_call_site_count
= tail_call_site_count
;
17730 tail_call_site_count
= -1;
17732 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17733 we don't get confused by DECL_ABSTRACT. */
17734 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17736 context
= decl_class_context (decl
);
17738 gen_type_die_for_member
17739 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17742 /* Pretend we've just finished compiling this function. */
17743 save_fn
= current_function_decl
;
17744 current_function_decl
= decl
;
17746 was_abstract
= DECL_ABSTRACT (decl
);
17747 set_decl_abstract_flags (decl
, 1);
17748 dwarf2out_decl (decl
);
17749 if (! was_abstract
)
17750 set_decl_abstract_flags (decl
, 0);
17752 current_function_decl
= save_fn
;
17753 decl_loc_table
= old_decl_loc_table
;
17754 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17755 call_arg_locations
= old_call_arg_locations
;
17756 call_site_count
= old_call_site_count
;
17757 tail_call_site_count
= old_tail_call_site_count
;
17760 /* Helper function of premark_used_types() which gets called through
17763 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17764 marked as unused by prune_unused_types. */
17767 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17772 type
= (tree
) *slot
;
17773 die
= lookup_type_die (type
);
17775 die
->die_perennial_p
= 1;
17779 /* Helper function of premark_types_used_by_global_vars which gets called
17780 through htab_traverse.
17782 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17783 marked as unused by prune_unused_types. The DIE of the type is marked
17784 only if the global variable using the type will actually be emitted. */
17787 premark_types_used_by_global_vars_helper (void **slot
,
17788 void *data ATTRIBUTE_UNUSED
)
17790 struct types_used_by_vars_entry
*entry
;
17793 entry
= (struct types_used_by_vars_entry
*) *slot
;
17794 gcc_assert (entry
->type
!= NULL
17795 && entry
->var_decl
!= NULL
);
17796 die
= lookup_type_die (entry
->type
);
17799 /* Ask cgraph if the global variable really is to be emitted.
17800 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17801 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17802 if (node
&& node
->analyzed
)
17804 die
->die_perennial_p
= 1;
17805 /* Keep the parent DIEs as well. */
17806 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17807 die
->die_perennial_p
= 1;
17813 /* Mark all members of used_types_hash as perennial. */
17816 premark_used_types (struct function
*fun
)
17818 if (fun
&& fun
->used_types_hash
)
17819 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17822 /* Mark all members of types_used_by_vars_entry as perennial. */
17825 premark_types_used_by_global_vars (void)
17827 if (types_used_by_vars_hash
)
17828 htab_traverse (types_used_by_vars_hash
,
17829 premark_types_used_by_global_vars_helper
, NULL
);
17832 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17833 for CA_LOC call arg loc node. */
17836 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17837 struct call_arg_loc_node
*ca_loc
)
17839 dw_die_ref stmt_die
= NULL
, die
;
17840 tree block
= ca_loc
->block
;
17843 && block
!= DECL_INITIAL (decl
)
17844 && TREE_CODE (block
) == BLOCK
)
17846 if (block_map
.length () > BLOCK_NUMBER (block
))
17847 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17850 block
= BLOCK_SUPERCONTEXT (block
);
17852 if (stmt_die
== NULL
)
17853 stmt_die
= subr_die
;
17854 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17855 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17856 if (ca_loc
->tail_call_p
)
17857 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17858 if (ca_loc
->symbol_ref
)
17860 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17862 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17864 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17869 /* Generate a DIE to represent a declared function (either file-scope or
17873 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17875 tree origin
= decl_ultimate_origin (decl
);
17876 dw_die_ref subr_die
;
17878 dw_die_ref old_die
= lookup_decl_die (decl
);
17879 int declaration
= (current_function_decl
!= decl
17880 || class_or_namespace_scope_p (context_die
));
17882 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17884 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17885 started to generate the abstract instance of an inline, decided to output
17886 its containing class, and proceeded to emit the declaration of the inline
17887 from the member list for the class. If so, DECLARATION takes priority;
17888 we'll get back to the abstract instance when done with the class. */
17890 /* The class-scope declaration DIE must be the primary DIE. */
17891 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17894 gcc_assert (!old_die
);
17897 /* Now that the C++ front end lazily declares artificial member fns, we
17898 might need to retrofit the declaration into its class. */
17899 if (!declaration
&& !origin
&& !old_die
17900 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17901 && !class_or_namespace_scope_p (context_die
)
17902 && debug_info_level
> DINFO_LEVEL_TERSE
)
17903 old_die
= force_decl_die (decl
);
17905 if (origin
!= NULL
)
17907 gcc_assert (!declaration
|| local_scope_p (context_die
));
17909 /* Fixup die_parent for the abstract instance of a nested
17910 inline function. */
17911 if (old_die
&& old_die
->die_parent
== NULL
)
17912 add_child_die (context_die
, old_die
);
17914 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17915 add_abstract_origin_attribute (subr_die
, origin
);
17916 /* This is where the actual code for a cloned function is.
17917 Let's emit linkage name attribute for it. This helps
17918 debuggers to e.g, set breakpoints into
17919 constructors/destructors when the user asks "break
17921 add_linkage_name (subr_die
, decl
);
17925 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17926 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17928 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17929 /* We can have a normal definition following an inline one in the
17930 case of redefinition of GNU C extern inlines.
17931 It seems reasonable to use AT_specification in this case. */
17932 && !get_AT (old_die
, DW_AT_inline
))
17934 /* Detect and ignore this case, where we are trying to output
17935 something we have already output. */
17939 /* If the definition comes from the same place as the declaration,
17940 maybe use the old DIE. We always want the DIE for this function
17941 that has the *_pc attributes to be under comp_unit_die so the
17942 debugger can find it. We also need to do this for abstract
17943 instances of inlines, since the spec requires the out-of-line copy
17944 to have the same parent. For local class methods, this doesn't
17945 apply; we just use the old DIE. */
17946 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17947 && (DECL_ARTIFICIAL (decl
)
17948 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17949 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17950 == (unsigned) s
.line
))))
17952 subr_die
= old_die
;
17954 /* Clear out the declaration attribute and the formal parameters.
17955 Do not remove all children, because it is possible that this
17956 declaration die was forced using force_decl_die(). In such
17957 cases die that forced declaration die (e.g. TAG_imported_module)
17958 is one of the children that we do not want to remove. */
17959 remove_AT (subr_die
, DW_AT_declaration
);
17960 remove_AT (subr_die
, DW_AT_object_pointer
);
17961 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17965 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17966 add_AT_specification (subr_die
, old_die
);
17967 add_pubname (decl
, subr_die
);
17968 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17969 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17970 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17971 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17976 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17978 if (TREE_PUBLIC (decl
))
17979 add_AT_flag (subr_die
, DW_AT_external
, 1);
17981 add_name_and_src_coords_attributes (subr_die
, decl
);
17982 add_pubname (decl
, subr_die
);
17983 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17985 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17986 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17987 0, 0, context_die
);
17990 add_pure_or_virtual_attribute (subr_die
, decl
);
17991 if (DECL_ARTIFICIAL (decl
))
17992 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17994 add_accessibility_attribute (subr_die
, decl
);
17999 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18001 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18003 /* If this is an explicit function declaration then generate
18004 a DW_AT_explicit attribute. */
18005 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18006 && (dwarf_version
>= 3 || !dwarf_strict
))
18007 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18009 /* The first time we see a member function, it is in the context of
18010 the class to which it belongs. We make sure of this by emitting
18011 the class first. The next time is the definition, which is
18012 handled above. The two may come from the same source text.
18014 Note that force_decl_die() forces function declaration die. It is
18015 later reused to represent definition. */
18016 equate_decl_number_to_die (decl
, subr_die
);
18019 else if (DECL_ABSTRACT (decl
))
18021 if (DECL_DECLARED_INLINE_P (decl
))
18023 if (cgraph_function_possibly_inlined_p (decl
))
18024 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18026 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18030 if (cgraph_function_possibly_inlined_p (decl
))
18031 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18033 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18036 if (DECL_DECLARED_INLINE_P (decl
)
18037 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18038 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18040 equate_decl_number_to_die (decl
, subr_die
);
18042 else if (!DECL_EXTERNAL (decl
))
18044 HOST_WIDE_INT cfa_fb_offset
;
18045 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18047 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18048 equate_decl_number_to_die (decl
, subr_die
);
18050 gcc_checking_assert (fun
);
18051 if (!flag_reorder_blocks_and_partition
)
18053 dw_fde_ref fde
= fun
->fde
;
18054 if (fde
->dw_fde_begin
)
18056 /* We have already generated the labels. */
18057 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18058 fde
->dw_fde_end
, false);
18062 /* Create start/end labels and add the range. */
18063 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18064 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18065 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18066 FUNC_LABEL_ID (cfun
));
18067 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18068 FUNC_LABEL_ID (cfun
));
18069 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18073 #if VMS_DEBUGGING_INFO
18074 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18075 Section 2.3 Prologue and Epilogue Attributes:
18076 When a breakpoint is set on entry to a function, it is generally
18077 desirable for execution to be suspended, not on the very first
18078 instruction of the function, but rather at a point after the
18079 function's frame has been set up, after any language defined local
18080 declaration processing has been completed, and before execution of
18081 the first statement of the function begins. Debuggers generally
18082 cannot properly determine where this point is. Similarly for a
18083 breakpoint set on exit from a function. The prologue and epilogue
18084 attributes allow a compiler to communicate the location(s) to use. */
18087 if (fde
->dw_fde_vms_end_prologue
)
18088 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18089 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18091 if (fde
->dw_fde_vms_begin_epilogue
)
18092 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18093 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18100 /* Generate pubnames entries for the split function code ranges. */
18101 dw_fde_ref fde
= fun
->fde
;
18103 if (fde
->dw_fde_second_begin
)
18105 if (dwarf_version
>= 3 || !dwarf_strict
)
18107 /* We should use ranges for non-contiguous code section
18108 addresses. Use the actual code range for the initial
18109 section, since the HOT/COLD labels might precede an
18110 alignment offset. */
18111 bool range_list_added
= false;
18112 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18113 fde
->dw_fde_end
, &range_list_added
,
18115 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18116 fde
->dw_fde_second_end
,
18117 &range_list_added
, false);
18118 if (range_list_added
)
18123 /* There is no real support in DW2 for this .. so we make
18124 a work-around. First, emit the pub name for the segment
18125 containing the function label. Then make and emit a
18126 simplified subprogram DIE for the second segment with the
18127 name pre-fixed by __hot/cold_sect_of_. We use the same
18128 linkage name for the second die so that gdb will find both
18129 sections when given "b foo". */
18130 const char *name
= NULL
;
18131 tree decl_name
= DECL_NAME (decl
);
18132 dw_die_ref seg_die
;
18134 /* Do the 'primary' section. */
18135 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18136 fde
->dw_fde_end
, false);
18138 /* Build a minimal DIE for the secondary section. */
18139 seg_die
= new_die (DW_TAG_subprogram
,
18140 subr_die
->die_parent
, decl
);
18142 if (TREE_PUBLIC (decl
))
18143 add_AT_flag (seg_die
, DW_AT_external
, 1);
18145 if (decl_name
!= NULL
18146 && IDENTIFIER_POINTER (decl_name
) != NULL
)
18148 name
= dwarf2_name (decl
, 1);
18149 if (! DECL_ARTIFICIAL (decl
))
18150 add_src_coords_attributes (seg_die
, decl
);
18152 add_linkage_name (seg_die
, decl
);
18154 gcc_assert (name
!= NULL
);
18155 add_pure_or_virtual_attribute (seg_die
, decl
);
18156 if (DECL_ARTIFICIAL (decl
))
18157 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
18159 name
= concat ("__second_sect_of_", name
, NULL
);
18160 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
18161 fde
->dw_fde_second_end
, false);
18162 add_name_attribute (seg_die
, name
);
18163 if (want_pubnames ())
18164 add_pubname_string (name
, seg_die
);
18168 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
18172 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18174 /* We define the "frame base" as the function's CFA. This is more
18175 convenient for several reasons: (1) It's stable across the prologue
18176 and epilogue, which makes it better than just a frame pointer,
18177 (2) With dwarf3, there exists a one-byte encoding that allows us
18178 to reference the .debug_frame data by proxy, but failing that,
18179 (3) We can at least reuse the code inspection and interpretation
18180 code that determines the CFA position at various points in the
18182 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18184 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18185 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18189 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18190 if (list
->dw_loc_next
)
18191 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18193 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18196 /* Compute a displacement from the "steady-state frame pointer" to
18197 the CFA. The former is what all stack slots and argument slots
18198 will reference in the rtl; the latter is what we've told the
18199 debugger about. We'll need to adjust all frame_base references
18200 by this displacement. */
18201 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18203 if (fun
->static_chain_decl
)
18204 add_AT_location_description (subr_die
, DW_AT_static_link
,
18205 loc_list_from_tree (fun
->static_chain_decl
, 2));
18208 /* Generate child dies for template paramaters. */
18209 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18210 gen_generic_params_dies (decl
);
18212 /* Now output descriptions of the arguments for this function. This gets
18213 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18214 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18215 `...' at the end of the formal parameter list. In order to find out if
18216 there was a trailing ellipsis or not, we must instead look at the type
18217 associated with the FUNCTION_DECL. This will be a node of type
18218 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18219 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18220 an ellipsis at the end. */
18222 /* In the case where we are describing a mere function declaration, all we
18223 need to do here (and all we *can* do here) is to describe the *types* of
18224 its formal parameters. */
18225 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18227 else if (declaration
)
18228 gen_formal_types_die (decl
, subr_die
);
18231 /* Generate DIEs to represent all known formal parameters. */
18232 tree parm
= DECL_ARGUMENTS (decl
);
18233 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18234 tree generic_decl_parm
= generic_decl
18235 ? DECL_ARGUMENTS (generic_decl
)
18238 /* Now we want to walk the list of parameters of the function and
18239 emit their relevant DIEs.
18241 We consider the case of DECL being an instance of a generic function
18242 as well as it being a normal function.
18244 If DECL is an instance of a generic function we walk the
18245 parameters of the generic function declaration _and_ the parameters of
18246 DECL itself. This is useful because we want to emit specific DIEs for
18247 function parameter packs and those are declared as part of the
18248 generic function declaration. In that particular case,
18249 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18250 That DIE has children DIEs representing the set of arguments
18251 of the pack. Note that the set of pack arguments can be empty.
18252 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18255 Otherwise, we just consider the parameters of DECL. */
18256 while (generic_decl_parm
|| parm
)
18258 if (generic_decl_parm
18259 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18260 gen_formal_parameter_pack_die (generic_decl_parm
,
18265 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18267 if (parm
== DECL_ARGUMENTS (decl
)
18268 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18270 && (dwarf_version
>= 3 || !dwarf_strict
))
18271 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18273 parm
= DECL_CHAIN (parm
);
18276 if (generic_decl_parm
)
18277 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18280 /* Decide whether we need an unspecified_parameters DIE at the end.
18281 There are 2 more cases to do this for: 1) the ansi ... declaration -
18282 this is detectable when the end of the arg list is not a
18283 void_type_node 2) an unprototyped function declaration (not a
18284 definition). This just means that we have no info about the
18285 parameters at all. */
18286 if (prototype_p (TREE_TYPE (decl
)))
18288 /* This is the prototyped case, check for.... */
18289 if (stdarg_p (TREE_TYPE (decl
)))
18290 gen_unspecified_parameters_die (decl
, subr_die
);
18292 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18293 gen_unspecified_parameters_die (decl
, subr_die
);
18296 /* Output Dwarf info for all of the stuff within the body of the function
18297 (if it has one - it may be just a declaration). */
18298 outer_scope
= DECL_INITIAL (decl
);
18300 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18301 a function. This BLOCK actually represents the outermost binding contour
18302 for the function, i.e. the contour in which the function's formal
18303 parameters and labels get declared. Curiously, it appears that the front
18304 end doesn't actually put the PARM_DECL nodes for the current function onto
18305 the BLOCK_VARS list for this outer scope, but are strung off of the
18306 DECL_ARGUMENTS list for the function instead.
18308 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18309 the LABEL_DECL nodes for the function however, and we output DWARF info
18310 for those in decls_for_scope. Just within the `outer_scope' there will be
18311 a BLOCK node representing the function's outermost pair of curly braces,
18312 and any blocks used for the base and member initializers of a C++
18313 constructor function. */
18314 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18316 int call_site_note_count
= 0;
18317 int tail_call_site_note_count
= 0;
18319 /* Emit a DW_TAG_variable DIE for a named return value. */
18320 if (DECL_NAME (DECL_RESULT (decl
)))
18321 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18323 current_function_has_inlines
= 0;
18324 decls_for_scope (outer_scope
, subr_die
, 0);
18326 if (call_arg_locations
&& !dwarf_strict
)
18328 struct call_arg_loc_node
*ca_loc
;
18329 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18331 dw_die_ref die
= NULL
;
18332 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18335 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18336 arg
; arg
= next_arg
)
18338 dw_loc_descr_ref reg
, val
;
18339 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18340 dw_die_ref cdie
, tdie
= NULL
;
18342 next_arg
= XEXP (arg
, 1);
18343 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18345 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18346 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18347 && REGNO (XEXP (XEXP (arg
, 0), 0))
18348 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18349 next_arg
= XEXP (next_arg
, 1);
18350 if (mode
== VOIDmode
)
18352 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18353 if (mode
== VOIDmode
)
18354 mode
= GET_MODE (XEXP (arg
, 0));
18356 if (mode
== VOIDmode
|| mode
== BLKmode
)
18358 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18360 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18361 tloc
= XEXP (XEXP (arg
, 0), 1);
18364 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18365 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18367 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18368 tlocc
= XEXP (XEXP (arg
, 0), 1);
18372 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18373 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18374 VAR_INIT_STATUS_INITIALIZED
);
18375 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18377 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18378 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18379 get_address_mode (mem
),
18381 VAR_INIT_STATUS_INITIALIZED
);
18383 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18384 == DEBUG_PARAMETER_REF
)
18387 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18388 tdie
= lookup_decl_die (tdecl
);
18395 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18396 != DEBUG_PARAMETER_REF
)
18398 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18400 VAR_INIT_STATUS_INITIALIZED
);
18404 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18405 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18408 add_AT_loc (cdie
, DW_AT_location
, reg
);
18409 else if (tdie
!= NULL
)
18410 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18411 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18412 if (next_arg
!= XEXP (arg
, 1))
18414 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18415 if (mode
== VOIDmode
)
18416 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18417 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18420 VAR_INIT_STATUS_INITIALIZED
);
18422 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18426 && (ca_loc
->symbol_ref
|| tloc
))
18427 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18428 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18430 dw_loc_descr_ref tval
= NULL
;
18432 if (tloc
!= NULL_RTX
)
18433 tval
= mem_loc_descriptor (tloc
,
18434 GET_MODE (tloc
) == VOIDmode
18435 ? Pmode
: GET_MODE (tloc
),
18437 VAR_INIT_STATUS_INITIALIZED
);
18439 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18440 else if (tlocc
!= NULL_RTX
)
18442 tval
= mem_loc_descriptor (tlocc
,
18443 GET_MODE (tlocc
) == VOIDmode
18444 ? Pmode
: GET_MODE (tlocc
),
18446 VAR_INIT_STATUS_INITIALIZED
);
18448 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18454 call_site_note_count
++;
18455 if (ca_loc
->tail_call_p
)
18456 tail_call_site_note_count
++;
18460 call_arg_locations
= NULL
;
18461 call_arg_loc_last
= NULL
;
18462 if (tail_call_site_count
>= 0
18463 && tail_call_site_count
== tail_call_site_note_count
18466 if (call_site_count
>= 0
18467 && call_site_count
== call_site_note_count
)
18468 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18470 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18472 call_site_count
= -1;
18473 tail_call_site_count
= -1;
18475 /* Add the calling convention attribute if requested. */
18476 add_calling_convention_attribute (subr_die
, decl
);
18480 /* Returns a hash value for X (which really is a die_struct). */
18483 common_block_die_table_hash (const void *x
)
18485 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18486 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18489 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18490 as decl_id and die_parent of die_struct Y. */
18493 common_block_die_table_eq (const void *x
, const void *y
)
18495 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18496 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18497 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18500 /* Generate a DIE to represent a declared data object.
18501 Either DECL or ORIGIN must be non-null. */
18504 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18506 HOST_WIDE_INT off
= 0;
18508 tree decl_or_origin
= decl
? decl
: origin
;
18509 tree ultimate_origin
;
18510 dw_die_ref var_die
;
18511 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18512 dw_die_ref origin_die
;
18513 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18514 || class_or_namespace_scope_p (context_die
));
18515 bool specialization_p
= false;
18517 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18518 if (decl
|| ultimate_origin
)
18519 origin
= ultimate_origin
;
18520 com_decl
= fortran_common (decl_or_origin
, &off
);
18522 /* Symbol in common gets emitted as a child of the common block, in the form
18523 of a data member. */
18526 dw_die_ref com_die
;
18527 dw_loc_list_ref loc
;
18528 die_node com_die_arg
;
18530 var_die
= lookup_decl_die (decl_or_origin
);
18533 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18535 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18540 /* Optimize the common case. */
18541 if (single_element_loc_list_p (loc
)
18542 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18543 && loc
->expr
->dw_loc_next
== NULL
18544 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18547 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18548 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18549 = plus_constant (GET_MODE (x
), x
, off
);
18552 loc_list_plus_const (loc
, off
);
18554 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18555 remove_AT (var_die
, DW_AT_declaration
);
18561 if (common_block_die_table
== NULL
)
18562 common_block_die_table
18563 = htab_create_ggc (10, common_block_die_table_hash
,
18564 common_block_die_table_eq
, NULL
);
18566 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18567 com_die_arg
.die_parent
= context_die
;
18568 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18569 loc
= loc_list_from_tree (com_decl
, 2);
18570 if (com_die
== NULL
)
18573 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18576 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18577 add_name_and_src_coords_attributes (com_die
, com_decl
);
18580 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18581 /* Avoid sharing the same loc descriptor between
18582 DW_TAG_common_block and DW_TAG_variable. */
18583 loc
= loc_list_from_tree (com_decl
, 2);
18585 else if (DECL_EXTERNAL (decl
))
18586 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18587 if (want_pubnames ())
18588 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18589 com_die
->decl_id
= DECL_UID (com_decl
);
18590 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18591 *slot
= (void *) com_die
;
18593 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18595 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18596 loc
= loc_list_from_tree (com_decl
, 2);
18597 remove_AT (com_die
, DW_AT_declaration
);
18599 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18600 add_name_and_src_coords_attributes (var_die
, decl
);
18601 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18602 TREE_THIS_VOLATILE (decl
), context_die
);
18603 add_AT_flag (var_die
, DW_AT_external
, 1);
18608 /* Optimize the common case. */
18609 if (single_element_loc_list_p (loc
)
18610 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18611 && loc
->expr
->dw_loc_next
== NULL
18612 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18614 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18615 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18616 = plus_constant (GET_MODE (x
), x
, off
);
18619 loc_list_plus_const (loc
, off
);
18621 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18623 else if (DECL_EXTERNAL (decl
))
18624 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18625 equate_decl_number_to_die (decl
, var_die
);
18629 /* If the compiler emitted a definition for the DECL declaration
18630 and if we already emitted a DIE for it, don't emit a second
18631 DIE for it again. Allow re-declarations of DECLs that are
18632 inside functions, though. */
18633 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18636 /* For static data members, the declaration in the class is supposed
18637 to have DW_TAG_member tag; the specification should still be
18638 DW_TAG_variable referencing the DW_TAG_member DIE. */
18639 if (declaration
&& class_scope_p (context_die
))
18640 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18642 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18645 if (origin
!= NULL
)
18646 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18648 /* Loop unrolling can create multiple blocks that refer to the same
18649 static variable, so we must test for the DW_AT_declaration flag.
18651 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18652 copy decls and set the DECL_ABSTRACT flag on them instead of
18655 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18657 ??? The declare_in_namespace support causes us to get two DIEs for one
18658 variable, both of which are declarations. We want to avoid considering
18659 one to be a specification, so we must test that this DIE is not a
18661 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18662 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18664 /* This is a definition of a C++ class level static. */
18665 add_AT_specification (var_die
, old_die
);
18666 specialization_p
= true;
18667 if (DECL_NAME (decl
))
18669 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18670 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18672 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18673 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18675 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18676 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18678 if (old_die
->die_tag
== DW_TAG_member
)
18679 add_linkage_name (var_die
, decl
);
18683 add_name_and_src_coords_attributes (var_die
, decl
);
18685 if ((origin
== NULL
&& !specialization_p
)
18687 && !DECL_ABSTRACT (decl_or_origin
)
18688 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18689 decl_function_context
18690 (decl_or_origin
))))
18692 tree type
= TREE_TYPE (decl_or_origin
);
18694 if (decl_by_reference_p (decl_or_origin
))
18695 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18697 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18698 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18701 if (origin
== NULL
&& !specialization_p
)
18703 if (TREE_PUBLIC (decl
))
18704 add_AT_flag (var_die
, DW_AT_external
, 1);
18706 if (DECL_ARTIFICIAL (decl
))
18707 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18709 add_accessibility_attribute (var_die
, decl
);
18713 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18715 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18716 equate_decl_number_to_die (decl
, var_die
);
18719 && (! DECL_ABSTRACT (decl_or_origin
)
18720 /* Local static vars are shared between all clones/inlines,
18721 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18723 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18724 && TREE_STATIC (decl_or_origin
)
18725 && DECL_RTL_SET_P (decl_or_origin
)))
18726 /* When abstract origin already has DW_AT_location attribute, no need
18727 to add it again. */
18728 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18730 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18731 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18732 defer_location (decl_or_origin
, var_die
);
18734 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18735 decl
== NULL
, DW_AT_location
);
18736 add_pubname (decl_or_origin
, var_die
);
18739 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18742 /* Generate a DIE to represent a named constant. */
18745 gen_const_die (tree decl
, dw_die_ref context_die
)
18747 dw_die_ref const_die
;
18748 tree type
= TREE_TYPE (decl
);
18750 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18751 add_name_and_src_coords_attributes (const_die
, decl
);
18752 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18753 if (TREE_PUBLIC (decl
))
18754 add_AT_flag (const_die
, DW_AT_external
, 1);
18755 if (DECL_ARTIFICIAL (decl
))
18756 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18757 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18760 /* Generate a DIE to represent a label identifier. */
18763 gen_label_die (tree decl
, dw_die_ref context_die
)
18765 tree origin
= decl_ultimate_origin (decl
);
18766 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18768 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18770 if (origin
!= NULL
)
18771 add_abstract_origin_attribute (lbl_die
, origin
);
18773 add_name_and_src_coords_attributes (lbl_die
, decl
);
18775 if (DECL_ABSTRACT (decl
))
18776 equate_decl_number_to_die (decl
, lbl_die
);
18779 insn
= DECL_RTL_IF_SET (decl
);
18781 /* Deleted labels are programmer specified labels which have been
18782 eliminated because of various optimizations. We still emit them
18783 here so that it is possible to put breakpoints on them. */
18787 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18789 /* When optimization is enabled (via -O) some parts of the compiler
18790 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18791 represent source-level labels which were explicitly declared by
18792 the user. This really shouldn't be happening though, so catch
18793 it if it ever does happen. */
18794 gcc_assert (!INSN_DELETED_P (insn
));
18796 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18797 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18801 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18802 && CODE_LABEL_NUMBER (insn
) != -1)
18804 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18805 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18810 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18811 attributes to the DIE for a block STMT, to describe where the inlined
18812 function was called from. This is similar to add_src_coords_attributes. */
18815 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18817 location_t locus
= BLOCK_SOURCE_LOCATION (stmt
);
18818 expanded_location s
= expand_location (locus
);
18820 if (dwarf_version
>= 3 || !dwarf_strict
)
18822 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18823 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18824 unsigned discr
= get_discriminator_from_locus (locus
);
18826 add_AT_unsigned (die
, DW_AT_GNU_discriminator
, discr
);
18831 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18832 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18835 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18837 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18839 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18840 && (dwarf_version
>= 3 || !dwarf_strict
))
18842 tree chain
, superblock
= NULL_TREE
;
18844 dw_attr_ref attr
= NULL
;
18846 if (inlined_function_outer_scope_p (stmt
))
18848 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18849 BLOCK_NUMBER (stmt
));
18850 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18853 /* Optimize duplicate .debug_ranges lists or even tails of
18854 lists. If this BLOCK has same ranges as its supercontext,
18855 lookup DW_AT_ranges attribute in the supercontext (and
18856 recursively so), verify that the ranges_table contains the
18857 right values and use it instead of adding a new .debug_range. */
18858 for (chain
= stmt
, pdie
= die
;
18859 BLOCK_SAME_RANGE (chain
);
18860 chain
= BLOCK_SUPERCONTEXT (chain
))
18862 dw_attr_ref new_attr
;
18864 pdie
= pdie
->die_parent
;
18867 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18869 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18870 if (new_attr
== NULL
18871 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18874 superblock
= BLOCK_SUPERCONTEXT (chain
);
18877 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18878 / 2 / DWARF2_ADDR_SIZE
].num
18879 == BLOCK_NUMBER (superblock
))
18880 && BLOCK_FRAGMENT_CHAIN (superblock
))
18882 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18883 / 2 / DWARF2_ADDR_SIZE
;
18884 unsigned long supercnt
= 0, thiscnt
= 0;
18885 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18886 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18889 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18890 == BLOCK_NUMBER (chain
));
18892 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18893 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18894 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18896 gcc_assert (supercnt
>= thiscnt
);
18897 add_AT_range_list (die
, DW_AT_ranges
,
18898 ((off
+ supercnt
- thiscnt
)
18899 * 2 * DWARF2_ADDR_SIZE
),
18904 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18906 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18909 add_ranges (chain
);
18910 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18917 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18918 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18919 BLOCK_NUMBER (stmt
));
18920 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18921 BLOCK_NUMBER (stmt
));
18922 add_AT_low_high_pc (die
, label
, label_high
, false);
18926 /* Generate a DIE for a lexical block. */
18929 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18931 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18933 if (call_arg_locations
)
18935 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18936 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18937 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18940 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18941 add_high_low_attributes (stmt
, stmt_die
);
18943 decls_for_scope (stmt
, stmt_die
, depth
);
18946 /* Generate a DIE for an inlined subprogram. */
18949 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18953 /* The instance of function that is effectively being inlined shall not
18955 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18957 decl
= block_ultimate_origin (stmt
);
18959 /* Emit info for the abstract instance first, if we haven't yet. We
18960 must emit this even if the block is abstract, otherwise when we
18961 emit the block below (or elsewhere), we may end up trying to emit
18962 a die whose origin die hasn't been emitted, and crashing. */
18963 dwarf2out_abstract_function (decl
);
18965 if (! BLOCK_ABSTRACT (stmt
))
18967 dw_die_ref subr_die
18968 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18970 if (call_arg_locations
)
18972 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18973 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18974 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18976 add_abstract_origin_attribute (subr_die
, decl
);
18977 if (TREE_ASM_WRITTEN (stmt
))
18978 add_high_low_attributes (stmt
, subr_die
);
18979 add_call_src_coords_attributes (stmt
, subr_die
);
18981 decls_for_scope (stmt
, subr_die
, depth
);
18982 current_function_has_inlines
= 1;
18986 /* Generate a DIE for a field in a record, or structure. */
18989 gen_field_die (tree decl
, dw_die_ref context_die
)
18991 dw_die_ref decl_die
;
18993 if (TREE_TYPE (decl
) == error_mark_node
)
18996 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18997 add_name_and_src_coords_attributes (decl_die
, decl
);
18998 add_type_attribute (decl_die
, member_declared_type (decl
),
18999 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
19002 if (DECL_BIT_FIELD_TYPE (decl
))
19004 add_byte_size_attribute (decl_die
, decl
);
19005 add_bit_size_attribute (decl_die
, decl
);
19006 add_bit_offset_attribute (decl_die
, decl
);
19009 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19010 add_data_member_location_attribute (decl_die
, decl
);
19012 if (DECL_ARTIFICIAL (decl
))
19013 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19015 add_accessibility_attribute (decl_die
, decl
);
19017 /* Equate decl number to die, so that we can look up this decl later on. */
19018 equate_decl_number_to_die (decl
, decl_die
);
19022 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19023 Use modified_type_die instead.
19024 We keep this code here just in case these types of DIEs may be needed to
19025 represent certain things in other languages (e.g. Pascal) someday. */
19028 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19031 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19033 equate_type_number_to_die (type
, ptr_die
);
19034 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19035 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19038 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19039 Use modified_type_die instead.
19040 We keep this code here just in case these types of DIEs may be needed to
19041 represent certain things in other languages (e.g. Pascal) someday. */
19044 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19046 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19048 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19049 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19051 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19053 equate_type_number_to_die (type
, ref_die
);
19054 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
19055 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19059 /* Generate a DIE for a pointer to a member type. */
19062 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
19065 = new_die (DW_TAG_ptr_to_member_type
,
19066 scope_die_for (type
, context_die
), type
);
19068 equate_type_number_to_die (type
, ptr_die
);
19069 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
19070 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
19071 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19074 typedef const char *dchar_p
; /* For DEF_VEC_P. */
19076 static char *producer_string
;
19078 /* Return a heap allocated producer string including command line options
19079 if -grecord-gcc-switches. */
19082 gen_producer_string (void)
19085 vec
<dchar_p
> switches
= vNULL
;
19086 const char *language_string
= lang_hooks
.name
;
19087 char *producer
, *tail
;
19089 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
19090 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
19092 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
19093 switch (save_decoded_options
[j
].opt_index
)
19100 case OPT_auxbase_strip
:
19109 case OPT_SPECIAL_unknown
:
19110 case OPT_SPECIAL_ignore
:
19111 case OPT_SPECIAL_program_name
:
19112 case OPT_SPECIAL_input_file
:
19113 case OPT_grecord_gcc_switches
:
19114 case OPT_gno_record_gcc_switches
:
19115 case OPT__output_pch_
:
19116 case OPT_fdiagnostics_show_location_
:
19117 case OPT_fdiagnostics_show_option
:
19118 case OPT_fdiagnostics_show_caret
:
19119 case OPT_fverbose_asm
:
19121 case OPT__sysroot_
:
19123 case OPT_nostdinc__
:
19124 /* Ignore these. */
19127 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
19128 & CL_NO_DWARF_RECORD
)
19130 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
19132 switch (save_decoded_options
[j
].canonical_option
[0][1])
19139 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
19146 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
19147 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
19151 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
19153 sprintf (tail
, "%s %s", language_string
, version_string
);
19156 FOR_EACH_VEC_ELT (switches
, j
, p
)
19160 memcpy (tail
+ 1, p
, len
);
19165 switches
.release ();
19169 /* Generate the DIE for the compilation unit. */
19172 gen_compile_unit_die (const char *filename
)
19175 const char *language_string
= lang_hooks
.name
;
19178 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19182 add_name_attribute (die
, filename
);
19183 /* Don't add cwd for <built-in>. */
19184 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19185 add_comp_dir_attribute (die
);
19188 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19190 /* If our producer is LTO try to figure out a common language to use
19191 from the global list of translation units. */
19192 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19196 const char *common_lang
= NULL
;
19198 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19200 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19203 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19204 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19206 else if (strncmp (common_lang
, "GNU C", 5) == 0
19207 && strncmp(TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19208 /* Mixing C and C++ is ok, use C++ in that case. */
19209 common_lang
= "GNU C++";
19212 /* Fall back to C. */
19213 common_lang
= NULL
;
19219 language_string
= common_lang
;
19222 language
= DW_LANG_C89
;
19223 if (strcmp (language_string
, "GNU C++") == 0)
19224 language
= DW_LANG_C_plus_plus
;
19225 else if (strcmp (language_string
, "GNU F77") == 0)
19226 language
= DW_LANG_Fortran77
;
19227 else if (strcmp (language_string
, "GNU Pascal") == 0)
19228 language
= DW_LANG_Pascal83
;
19229 else if (dwarf_version
>= 3 || !dwarf_strict
)
19231 if (strcmp (language_string
, "GNU Ada") == 0)
19232 language
= DW_LANG_Ada95
;
19233 else if (strcmp (language_string
, "GNU Fortran") == 0)
19234 language
= DW_LANG_Fortran95
;
19235 else if (strcmp (language_string
, "GNU Java") == 0)
19236 language
= DW_LANG_Java
;
19237 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19238 language
= DW_LANG_ObjC
;
19239 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19240 language
= DW_LANG_ObjC_plus_plus
;
19241 else if (dwarf_version
>= 5 || !dwarf_strict
)
19243 if (strcmp (language_string
, "GNU Go") == 0)
19244 language
= DW_LANG_Go
;
19247 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19248 else if (strcmp (language_string
, "GNU Fortran") == 0)
19249 language
= DW_LANG_Fortran90
;
19251 add_AT_unsigned (die
, DW_AT_language
, language
);
19255 case DW_LANG_Fortran77
:
19256 case DW_LANG_Fortran90
:
19257 case DW_LANG_Fortran95
:
19258 /* Fortran has case insensitive identifiers and the front-end
19259 lowercases everything. */
19260 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19263 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19269 /* Generate the DIE for a base class. */
19272 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19274 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19276 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19277 add_data_member_location_attribute (die
, binfo
);
19279 if (BINFO_VIRTUAL_P (binfo
))
19280 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19282 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19283 children, otherwise the default is DW_ACCESS_public. In DWARF2
19284 the default has always been DW_ACCESS_private. */
19285 if (access
== access_public_node
)
19287 if (dwarf_version
== 2
19288 || context_die
->die_tag
== DW_TAG_class_type
)
19289 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19291 else if (access
== access_protected_node
)
19292 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19293 else if (dwarf_version
> 2
19294 && context_die
->die_tag
!= DW_TAG_class_type
)
19295 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19298 /* Generate a DIE for a class member. */
19301 gen_member_die (tree type
, dw_die_ref context_die
)
19304 tree binfo
= TYPE_BINFO (type
);
19307 /* If this is not an incomplete type, output descriptions of each of its
19308 members. Note that as we output the DIEs necessary to represent the
19309 members of this record or union type, we will also be trying to output
19310 DIEs to represent the *types* of those members. However the `type'
19311 function (above) will specifically avoid generating type DIEs for member
19312 types *within* the list of member DIEs for this (containing) type except
19313 for those types (of members) which are explicitly marked as also being
19314 members of this (containing) type themselves. The g++ front- end can
19315 force any given type to be treated as a member of some other (containing)
19316 type by setting the TYPE_CONTEXT of the given (member) type to point to
19317 the TREE node representing the appropriate (containing) type. */
19319 /* First output info about the base classes. */
19322 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19326 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19327 gen_inheritance_die (base
,
19328 (accesses
? (*accesses
)[i
] : access_public_node
),
19332 /* Now output info about the data members and type members. */
19333 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19335 /* If we thought we were generating minimal debug info for TYPE
19336 and then changed our minds, some of the member declarations
19337 may have already been defined. Don't define them again, but
19338 do put them in the right order. */
19340 child
= lookup_decl_die (member
);
19342 splice_child_die (context_die
, child
);
19344 gen_decl_die (member
, NULL
, context_die
);
19347 /* Now output info about the function members (if any). */
19348 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19350 /* Don't include clones in the member list. */
19351 if (DECL_ABSTRACT_ORIGIN (member
))
19354 child
= lookup_decl_die (member
);
19356 splice_child_die (context_die
, child
);
19358 gen_decl_die (member
, NULL
, context_die
);
19362 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19363 is set, we pretend that the type was never defined, so we only get the
19364 member DIEs needed by later specification DIEs. */
19367 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19368 enum debug_info_usage usage
)
19370 dw_die_ref type_die
= lookup_type_die (type
);
19371 dw_die_ref scope_die
= 0;
19373 int complete
= (TYPE_SIZE (type
)
19374 && (! TYPE_STUB_DECL (type
)
19375 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19376 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19377 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19379 if (type_die
&& ! complete
)
19382 if (TYPE_CONTEXT (type
) != NULL_TREE
19383 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19384 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19387 scope_die
= scope_die_for (type
, context_die
);
19389 /* Generate child dies for template paramaters. */
19390 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19391 schedule_generic_params_dies_gen (type
);
19393 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19394 /* First occurrence of type or toplevel definition of nested class. */
19396 dw_die_ref old_die
= type_die
;
19398 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19399 ? record_type_tag (type
) : DW_TAG_union_type
,
19401 equate_type_number_to_die (type
, type_die
);
19403 add_AT_specification (type_die
, old_die
);
19405 add_name_attribute (type_die
, type_tag (type
));
19408 remove_AT (type_die
, DW_AT_declaration
);
19410 /* If this type has been completed, then give it a byte_size attribute and
19411 then give a list of members. */
19412 if (complete
&& !ns_decl
)
19414 /* Prevent infinite recursion in cases where the type of some member of
19415 this type is expressed in terms of this type itself. */
19416 TREE_ASM_WRITTEN (type
) = 1;
19417 add_byte_size_attribute (type_die
, type
);
19418 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19420 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19421 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19424 /* If the first reference to this type was as the return type of an
19425 inline function, then it may not have a parent. Fix this now. */
19426 if (type_die
->die_parent
== NULL
)
19427 add_child_die (scope_die
, type_die
);
19429 push_decl_scope (type
);
19430 gen_member_die (type
, type_die
);
19433 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19434 if (TYPE_ARTIFICIAL (type
))
19435 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19437 /* GNU extension: Record what type our vtable lives in. */
19438 if (TYPE_VFIELD (type
))
19440 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19442 gen_type_die (vtype
, context_die
);
19443 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19444 lookup_type_die (vtype
));
19449 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19451 /* We don't need to do this for function-local types. */
19452 if (TYPE_STUB_DECL (type
)
19453 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19454 vec_safe_push (incomplete_types
, type
);
19457 if (get_AT (type_die
, DW_AT_name
))
19458 add_pubtype (type
, type_die
);
19461 /* Generate a DIE for a subroutine _type_. */
19464 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19466 tree return_type
= TREE_TYPE (type
);
19467 dw_die_ref subr_die
19468 = new_die (DW_TAG_subroutine_type
,
19469 scope_die_for (type
, context_die
), type
);
19471 equate_type_number_to_die (type
, subr_die
);
19472 add_prototyped_attribute (subr_die
, type
);
19473 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19474 gen_formal_types_die (type
, subr_die
);
19476 if (get_AT (subr_die
, DW_AT_name
))
19477 add_pubtype (type
, subr_die
);
19480 /* Generate a DIE for a type definition. */
19483 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19485 dw_die_ref type_die
;
19488 if (TREE_ASM_WRITTEN (decl
))
19491 TREE_ASM_WRITTEN (decl
) = 1;
19492 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19493 origin
= decl_ultimate_origin (decl
);
19494 if (origin
!= NULL
)
19495 add_abstract_origin_attribute (type_die
, origin
);
19500 add_name_and_src_coords_attributes (type_die
, decl
);
19501 if (DECL_ORIGINAL_TYPE (decl
))
19503 type
= DECL_ORIGINAL_TYPE (decl
);
19505 gcc_assert (type
!= TREE_TYPE (decl
));
19506 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19510 type
= TREE_TYPE (decl
);
19512 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19514 /* Here, we are in the case of decl being a typedef naming
19515 an anonymous type, e.g:
19516 typedef struct {...} foo;
19517 In that case TREE_TYPE (decl) is not a typedef variant
19518 type and TYPE_NAME of the anonymous type is set to the
19519 TYPE_DECL of the typedef. This construct is emitted by
19522 TYPE is the anonymous struct named by the typedef
19523 DECL. As we need the DW_AT_type attribute of the
19524 DW_TAG_typedef to point to the DIE of TYPE, let's
19525 generate that DIE right away. add_type_attribute
19526 called below will then pick (via lookup_type_die) that
19527 anonymous struct DIE. */
19528 if (!TREE_ASM_WRITTEN (type
))
19529 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19531 /* This is a GNU Extension. We are adding a
19532 DW_AT_linkage_name attribute to the DIE of the
19533 anonymous struct TYPE. The value of that attribute
19534 is the name of the typedef decl naming the anonymous
19535 struct. This greatly eases the work of consumers of
19536 this debug info. */
19537 add_linkage_attr (lookup_type_die (type
), decl
);
19541 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19542 TREE_THIS_VOLATILE (decl
), context_die
);
19544 if (is_naming_typedef_decl (decl
))
19545 /* We want that all subsequent calls to lookup_type_die with
19546 TYPE in argument yield the DW_TAG_typedef we have just
19548 equate_type_number_to_die (type
, type_die
);
19550 add_accessibility_attribute (type_die
, decl
);
19553 if (DECL_ABSTRACT (decl
))
19554 equate_decl_number_to_die (decl
, type_die
);
19556 if (get_AT (type_die
, DW_AT_name
))
19557 add_pubtype (decl
, type_die
);
19560 /* Generate a DIE for a struct, class, enum or union type. */
19563 gen_tagged_type_die (tree type
,
19564 dw_die_ref context_die
,
19565 enum debug_info_usage usage
)
19569 if (type
== NULL_TREE
19570 || !is_tagged_type (type
))
19573 /* If this is a nested type whose containing class hasn't been written
19574 out yet, writing it out will cover this one, too. This does not apply
19575 to instantiations of member class templates; they need to be added to
19576 the containing class as they are generated. FIXME: This hurts the
19577 idea of combining type decls from multiple TUs, since we can't predict
19578 what set of template instantiations we'll get. */
19579 if (TYPE_CONTEXT (type
)
19580 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19581 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19583 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19585 if (TREE_ASM_WRITTEN (type
))
19588 /* If that failed, attach ourselves to the stub. */
19589 push_decl_scope (TYPE_CONTEXT (type
));
19590 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19593 else if (TYPE_CONTEXT (type
) != NULL_TREE
19594 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19596 /* If this type is local to a function that hasn't been written
19597 out yet, use a NULL context for now; it will be fixed up in
19598 decls_for_scope. */
19599 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19600 /* A declaration DIE doesn't count; nested types need to go in the
19602 if (context_die
&& is_declaration_die (context_die
))
19603 context_die
= NULL
;
19608 context_die
= declare_in_namespace (type
, context_die
);
19612 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19614 /* This might have been written out by the call to
19615 declare_in_namespace. */
19616 if (!TREE_ASM_WRITTEN (type
))
19617 gen_enumeration_type_die (type
, context_die
);
19620 gen_struct_or_union_type_die (type
, context_die
, usage
);
19625 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19626 it up if it is ever completed. gen_*_type_die will set it for us
19627 when appropriate. */
19630 /* Generate a type description DIE. */
19633 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19634 enum debug_info_usage usage
)
19636 struct array_descr_info info
;
19638 if (type
== NULL_TREE
|| type
== error_mark_node
)
19641 if (TYPE_NAME (type
) != NULL_TREE
19642 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19643 && is_redundant_typedef (TYPE_NAME (type
))
19644 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19645 /* The DECL of this type is a typedef we don't want to emit debug
19646 info for but we want debug info for its underlying typedef.
19647 This can happen for e.g, the injected-class-name of a C++
19649 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19651 /* If TYPE is a typedef type variant, let's generate debug info
19652 for the parent typedef which TYPE is a type of. */
19653 if (typedef_variant_p (type
))
19655 if (TREE_ASM_WRITTEN (type
))
19658 /* Prevent broken recursion; we can't hand off to the same type. */
19659 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19661 /* Give typedefs the right scope. */
19662 context_die
= scope_die_for (type
, context_die
);
19664 TREE_ASM_WRITTEN (type
) = 1;
19666 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19670 /* If type is an anonymous tagged type named by a typedef, let's
19671 generate debug info for the typedef. */
19672 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19674 /* Use the DIE of the containing namespace as the parent DIE of
19675 the type description DIE we want to generate. */
19676 if (DECL_CONTEXT (TYPE_NAME (type
))
19677 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19678 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19680 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19684 /* If this is an array type with hidden descriptor, handle it first. */
19685 if (!TREE_ASM_WRITTEN (type
)
19686 && lang_hooks
.types
.get_array_descr_info
19687 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19688 && (dwarf_version
>= 3 || !dwarf_strict
))
19690 gen_descr_array_type_die (type
, &info
, context_die
);
19691 TREE_ASM_WRITTEN (type
) = 1;
19695 /* We are going to output a DIE to represent the unqualified version
19696 of this type (i.e. without any const or volatile qualifiers) so
19697 get the main variant (i.e. the unqualified version) of this type
19698 now. (Vectors are special because the debugging info is in the
19699 cloned type itself). */
19700 if (TREE_CODE (type
) != VECTOR_TYPE
)
19701 type
= type_main_variant (type
);
19703 if (TREE_ASM_WRITTEN (type
))
19706 switch (TREE_CODE (type
))
19712 case REFERENCE_TYPE
:
19713 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19714 ensures that the gen_type_die recursion will terminate even if the
19715 type is recursive. Recursive types are possible in Ada. */
19716 /* ??? We could perhaps do this for all types before the switch
19718 TREE_ASM_WRITTEN (type
) = 1;
19720 /* For these types, all that is required is that we output a DIE (or a
19721 set of DIEs) to represent the "basis" type. */
19722 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19723 DINFO_USAGE_IND_USE
);
19727 /* This code is used for C++ pointer-to-data-member types.
19728 Output a description of the relevant class type. */
19729 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19730 DINFO_USAGE_IND_USE
);
19732 /* Output a description of the type of the object pointed to. */
19733 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19734 DINFO_USAGE_IND_USE
);
19736 /* Now output a DIE to represent this pointer-to-data-member type
19738 gen_ptr_to_mbr_type_die (type
, context_die
);
19741 case FUNCTION_TYPE
:
19742 /* Force out return type (in case it wasn't forced out already). */
19743 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19744 DINFO_USAGE_DIR_USE
);
19745 gen_subroutine_type_die (type
, context_die
);
19749 /* Force out return type (in case it wasn't forced out already). */
19750 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19751 DINFO_USAGE_DIR_USE
);
19752 gen_subroutine_type_die (type
, context_die
);
19756 gen_array_type_die (type
, context_die
);
19760 gen_array_type_die (type
, context_die
);
19763 case ENUMERAL_TYPE
:
19766 case QUAL_UNION_TYPE
:
19767 gen_tagged_type_die (type
, context_die
, usage
);
19773 case FIXED_POINT_TYPE
:
19776 /* No DIEs needed for fundamental types. */
19781 /* Just use DW_TAG_unspecified_type. */
19783 dw_die_ref type_die
= lookup_type_die (type
);
19784 if (type_die
== NULL
)
19786 tree name
= TYPE_NAME (type
);
19787 if (TREE_CODE (name
) == TYPE_DECL
)
19788 name
= DECL_NAME (name
);
19789 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19790 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19791 equate_type_number_to_die (type
, type_die
);
19797 gcc_unreachable ();
19800 TREE_ASM_WRITTEN (type
) = 1;
19804 gen_type_die (tree type
, dw_die_ref context_die
)
19806 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19809 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19810 things which are local to the given block. */
19813 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19815 int must_output_die
= 0;
19818 /* Ignore blocks that are NULL. */
19819 if (stmt
== NULL_TREE
)
19822 inlined_func
= inlined_function_outer_scope_p (stmt
);
19824 /* If the block is one fragment of a non-contiguous block, do not
19825 process the variables, since they will have been done by the
19826 origin block. Do process subblocks. */
19827 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19831 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19832 gen_block_die (sub
, context_die
, depth
+ 1);
19837 /* Determine if we need to output any Dwarf DIEs at all to represent this
19840 /* The outer scopes for inlinings *must* always be represented. We
19841 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19842 must_output_die
= 1;
19845 /* Determine if this block directly contains any "significant"
19846 local declarations which we will need to output DIEs for. */
19847 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19848 /* We are not in terse mode so *any* local declaration counts
19849 as being a "significant" one. */
19850 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19851 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19852 && (TREE_USED (stmt
)
19853 || TREE_ASM_WRITTEN (stmt
)
19854 || BLOCK_ABSTRACT (stmt
)));
19855 else if ((TREE_USED (stmt
)
19856 || TREE_ASM_WRITTEN (stmt
)
19857 || BLOCK_ABSTRACT (stmt
))
19858 && !dwarf2out_ignore_block (stmt
))
19859 must_output_die
= 1;
19862 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19863 DIE for any block which contains no significant local declarations at
19864 all. Rather, in such cases we just call `decls_for_scope' so that any
19865 needed Dwarf info for any sub-blocks will get properly generated. Note
19866 that in terse mode, our definition of what constitutes a "significant"
19867 local declaration gets restricted to include only inlined function
19868 instances and local (nested) function definitions. */
19869 if (must_output_die
)
19873 /* If STMT block is abstract, that means we have been called
19874 indirectly from dwarf2out_abstract_function.
19875 That function rightfully marks the descendent blocks (of
19876 the abstract function it is dealing with) as being abstract,
19877 precisely to prevent us from emitting any
19878 DW_TAG_inlined_subroutine DIE as a descendent
19879 of an abstract function instance. So in that case, we should
19880 not call gen_inlined_subroutine_die.
19882 Later though, when cgraph asks dwarf2out to emit info
19883 for the concrete instance of the function decl into which
19884 the concrete instance of STMT got inlined, the later will lead
19885 to the generation of a DW_TAG_inlined_subroutine DIE. */
19886 if (! BLOCK_ABSTRACT (stmt
))
19887 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19890 gen_lexical_block_die (stmt
, context_die
, depth
);
19893 decls_for_scope (stmt
, context_die
, depth
);
19896 /* Process variable DECL (or variable with origin ORIGIN) within
19897 block STMT and add it to CONTEXT_DIE. */
19899 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19902 tree decl_or_origin
= decl
? decl
: origin
;
19904 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19905 die
= lookup_decl_die (decl_or_origin
);
19906 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19907 && TYPE_DECL_IS_STUB (decl_or_origin
))
19908 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19912 if (die
!= NULL
&& die
->die_parent
== NULL
)
19913 add_child_die (context_die
, die
);
19914 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19915 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19916 stmt
, context_die
);
19918 gen_decl_die (decl
, origin
, context_die
);
19921 /* Generate all of the decls declared within a given scope and (recursively)
19922 all of its sub-blocks. */
19925 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19931 /* Ignore NULL blocks. */
19932 if (stmt
== NULL_TREE
)
19935 /* Output the DIEs to represent all of the data objects and typedefs
19936 declared directly within this block but not within any nested
19937 sub-blocks. Also, nested function and tag DIEs have been
19938 generated with a parent of NULL; fix that up now. We don't
19939 have to do this if we're at -g1. */
19940 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19942 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19943 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19944 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19945 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19949 /* Even if we're at -g1, we need to process the subblocks in order to get
19950 inlined call information. */
19952 /* Output the DIEs to represent all sub-blocks (and the items declared
19953 therein) of this block. */
19954 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19956 subblocks
= BLOCK_CHAIN (subblocks
))
19957 gen_block_die (subblocks
, context_die
, depth
+ 1);
19960 /* Is this a typedef we can avoid emitting? */
19963 is_redundant_typedef (const_tree decl
)
19965 if (TYPE_DECL_IS_STUB (decl
))
19968 if (DECL_ARTIFICIAL (decl
)
19969 && DECL_CONTEXT (decl
)
19970 && is_tagged_type (DECL_CONTEXT (decl
))
19971 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19972 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19973 /* Also ignore the artificial member typedef for the class name. */
19979 /* Return TRUE if TYPE is a typedef that names a type for linkage
19980 purposes. This kind of typedefs is produced by the C++ FE for
19983 typedef struct {...} foo;
19985 In that case, there is no typedef variant type produced for foo.
19986 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19990 is_naming_typedef_decl (const_tree decl
)
19992 if (decl
== NULL_TREE
19993 || TREE_CODE (decl
) != TYPE_DECL
19994 || !is_tagged_type (TREE_TYPE (decl
))
19995 || DECL_IS_BUILTIN (decl
)
19996 || is_redundant_typedef (decl
)
19997 /* It looks like Ada produces TYPE_DECLs that are very similar
19998 to C++ naming typedefs but that have different
19999 semantics. Let's be specific to c++ for now. */
20003 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20004 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20005 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20006 != TYPE_NAME (TREE_TYPE (decl
))));
20009 /* Returns the DIE for a context. */
20011 static inline dw_die_ref
20012 get_context_die (tree context
)
20016 /* Find die that represents this context. */
20017 if (TYPE_P (context
))
20019 context
= TYPE_MAIN_VARIANT (context
);
20020 return strip_naming_typedef (context
, force_type_die (context
));
20023 return force_decl_die (context
);
20025 return comp_unit_die ();
20028 /* Returns the DIE for decl. A DIE will always be returned. */
20031 force_decl_die (tree decl
)
20033 dw_die_ref decl_die
;
20034 unsigned saved_external_flag
;
20035 tree save_fn
= NULL_TREE
;
20036 decl_die
= lookup_decl_die (decl
);
20039 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20041 decl_die
= lookup_decl_die (decl
);
20045 switch (TREE_CODE (decl
))
20047 case FUNCTION_DECL
:
20048 /* Clear current_function_decl, so that gen_subprogram_die thinks
20049 that this is a declaration. At this point, we just want to force
20050 declaration die. */
20051 save_fn
= current_function_decl
;
20052 current_function_decl
= NULL_TREE
;
20053 gen_subprogram_die (decl
, context_die
);
20054 current_function_decl
= save_fn
;
20058 /* Set external flag to force declaration die. Restore it after
20059 gen_decl_die() call. */
20060 saved_external_flag
= DECL_EXTERNAL (decl
);
20061 DECL_EXTERNAL (decl
) = 1;
20062 gen_decl_die (decl
, NULL
, context_die
);
20063 DECL_EXTERNAL (decl
) = saved_external_flag
;
20066 case NAMESPACE_DECL
:
20067 if (dwarf_version
>= 3 || !dwarf_strict
)
20068 dwarf2out_decl (decl
);
20070 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20071 decl_die
= comp_unit_die ();
20074 case TRANSLATION_UNIT_DECL
:
20075 decl_die
= comp_unit_die ();
20079 gcc_unreachable ();
20082 /* We should be able to find the DIE now. */
20084 decl_die
= lookup_decl_die (decl
);
20085 gcc_assert (decl_die
);
20091 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20092 always returned. */
20095 force_type_die (tree type
)
20097 dw_die_ref type_die
;
20099 type_die
= lookup_type_die (type
);
20102 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20104 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20105 TYPE_VOLATILE (type
), context_die
);
20106 gcc_assert (type_die
);
20111 /* Force out any required namespaces to be able to output DECL,
20112 and return the new context_die for it, if it's changed. */
20115 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20117 tree context
= (DECL_P (thing
)
20118 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20119 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20120 /* Force out the namespace. */
20121 context_die
= force_decl_die (context
);
20123 return context_die
;
20126 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20127 type) within its namespace, if appropriate.
20129 For compatibility with older debuggers, namespace DIEs only contain
20130 declarations; all definitions are emitted at CU scope. */
20133 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20135 dw_die_ref ns_context
;
20137 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20138 return context_die
;
20140 /* If this decl is from an inlined function, then don't try to emit it in its
20141 namespace, as we will get confused. It would have already been emitted
20142 when the abstract instance of the inline function was emitted anyways. */
20143 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20144 return context_die
;
20146 ns_context
= setup_namespace_context (thing
, context_die
);
20148 if (ns_context
!= context_die
)
20152 if (DECL_P (thing
))
20153 gen_decl_die (thing
, NULL
, ns_context
);
20155 gen_type_die (thing
, ns_context
);
20157 return context_die
;
20160 /* Generate a DIE for a namespace or namespace alias. */
20163 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20165 dw_die_ref namespace_die
;
20167 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20168 they are an alias of. */
20169 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20171 /* Output a real namespace or module. */
20172 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20173 namespace_die
= new_die (is_fortran ()
20174 ? DW_TAG_module
: DW_TAG_namespace
,
20175 context_die
, decl
);
20176 /* For Fortran modules defined in different CU don't add src coords. */
20177 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20179 const char *name
= dwarf2_name (decl
, 0);
20181 add_name_attribute (namespace_die
, name
);
20184 add_name_and_src_coords_attributes (namespace_die
, decl
);
20185 if (DECL_EXTERNAL (decl
))
20186 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20187 equate_decl_number_to_die (decl
, namespace_die
);
20191 /* Output a namespace alias. */
20193 /* Force out the namespace we are an alias of, if necessary. */
20194 dw_die_ref origin_die
20195 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20197 if (DECL_FILE_SCOPE_P (decl
)
20198 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20199 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20200 /* Now create the namespace alias DIE. */
20201 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20202 add_name_and_src_coords_attributes (namespace_die
, decl
);
20203 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20204 equate_decl_number_to_die (decl
, namespace_die
);
20206 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20207 if (want_pubnames ())
20208 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20211 /* Generate Dwarf debug information for a decl described by DECL.
20212 The return value is currently only meaningful for PARM_DECLs,
20213 for all other decls it returns NULL. */
20216 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20218 tree decl_or_origin
= decl
? decl
: origin
;
20219 tree class_origin
= NULL
, ultimate_origin
;
20221 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20224 switch (TREE_CODE (decl_or_origin
))
20230 if (!is_fortran () && !is_ada ())
20232 /* The individual enumerators of an enum type get output when we output
20233 the Dwarf representation of the relevant enum type itself. */
20237 /* Emit its type. */
20238 gen_type_die (TREE_TYPE (decl
), context_die
);
20240 /* And its containing namespace. */
20241 context_die
= declare_in_namespace (decl
, context_die
);
20243 gen_const_die (decl
, context_die
);
20246 case FUNCTION_DECL
:
20247 /* Don't output any DIEs to represent mere function declarations,
20248 unless they are class members or explicit block externs. */
20249 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20250 && DECL_FILE_SCOPE_P (decl_or_origin
)
20251 && (current_function_decl
== NULL_TREE
20252 || DECL_ARTIFICIAL (decl_or_origin
)))
20257 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20258 on local redeclarations of global functions. That seems broken. */
20259 if (current_function_decl
!= decl
)
20260 /* This is only a declaration. */;
20263 /* If we're emitting a clone, emit info for the abstract instance. */
20264 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20265 dwarf2out_abstract_function (origin
20266 ? DECL_ORIGIN (origin
)
20267 : DECL_ABSTRACT_ORIGIN (decl
));
20269 /* If we're emitting an out-of-line copy of an inline function,
20270 emit info for the abstract instance and set up to refer to it. */
20271 else if (cgraph_function_possibly_inlined_p (decl
)
20272 && ! DECL_ABSTRACT (decl
)
20273 && ! class_or_namespace_scope_p (context_die
)
20274 /* dwarf2out_abstract_function won't emit a die if this is just
20275 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20276 that case, because that works only if we have a die. */
20277 && DECL_INITIAL (decl
) != NULL_TREE
)
20279 dwarf2out_abstract_function (decl
);
20280 set_decl_origin_self (decl
);
20283 /* Otherwise we're emitting the primary DIE for this decl. */
20284 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20286 /* Before we describe the FUNCTION_DECL itself, make sure that we
20287 have its containing type. */
20289 origin
= decl_class_context (decl
);
20290 if (origin
!= NULL_TREE
)
20291 gen_type_die (origin
, context_die
);
20293 /* And its return type. */
20294 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20296 /* And its virtual context. */
20297 if (DECL_VINDEX (decl
) != NULL_TREE
)
20298 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20300 /* Make sure we have a member DIE for decl. */
20301 if (origin
!= NULL_TREE
)
20302 gen_type_die_for_member (origin
, decl
, context_die
);
20304 /* And its containing namespace. */
20305 context_die
= declare_in_namespace (decl
, context_die
);
20308 /* Now output a DIE to represent the function itself. */
20310 gen_subprogram_die (decl
, context_die
);
20314 /* If we are in terse mode, don't generate any DIEs to represent any
20315 actual typedefs. */
20316 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20319 /* In the special case of a TYPE_DECL node representing the declaration
20320 of some type tag, if the given TYPE_DECL is marked as having been
20321 instantiated from some other (original) TYPE_DECL node (e.g. one which
20322 was generated within the original definition of an inline function) we
20323 used to generate a special (abbreviated) DW_TAG_structure_type,
20324 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20325 should be actually referencing those DIEs, as variable DIEs with that
20326 type would be emitted already in the abstract origin, so it was always
20327 removed during unused type prunning. Don't add anything in this
20329 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20332 if (is_redundant_typedef (decl
))
20333 gen_type_die (TREE_TYPE (decl
), context_die
);
20335 /* Output a DIE to represent the typedef itself. */
20336 gen_typedef_die (decl
, context_die
);
20340 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20341 gen_label_die (decl
, context_die
);
20346 /* If we are in terse mode, don't generate any DIEs to represent any
20347 variable declarations or definitions. */
20348 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20351 /* Output any DIEs that are needed to specify the type of this data
20353 if (decl_by_reference_p (decl_or_origin
))
20354 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20356 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20358 /* And its containing type. */
20359 class_origin
= decl_class_context (decl_or_origin
);
20360 if (class_origin
!= NULL_TREE
)
20361 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20363 /* And its containing namespace. */
20364 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20366 /* Now output the DIE to represent the data object itself. This gets
20367 complicated because of the possibility that the VAR_DECL really
20368 represents an inlined instance of a formal parameter for an inline
20370 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20371 if (ultimate_origin
!= NULL_TREE
20372 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20373 gen_formal_parameter_die (decl
, origin
,
20374 true /* Emit name attribute. */,
20377 gen_variable_die (decl
, origin
, context_die
);
20381 /* Ignore the nameless fields that are used to skip bits but handle C++
20382 anonymous unions and structs. */
20383 if (DECL_NAME (decl
) != NULL_TREE
20384 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20385 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20387 gen_type_die (member_declared_type (decl
), context_die
);
20388 gen_field_die (decl
, context_die
);
20393 if (DECL_BY_REFERENCE (decl_or_origin
))
20394 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20396 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20397 return gen_formal_parameter_die (decl
, origin
,
20398 true /* Emit name attribute. */,
20401 case NAMESPACE_DECL
:
20402 case IMPORTED_DECL
:
20403 if (dwarf_version
>= 3 || !dwarf_strict
)
20404 gen_namespace_die (decl
, context_die
);
20408 /* Probably some frontend-internal decl. Assume we don't care. */
20409 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20416 /* Output debug information for global decl DECL. Called from toplev.c after
20417 compilation proper has finished. */
20420 dwarf2out_global_decl (tree decl
)
20422 /* Output DWARF2 information for file-scope tentative data object
20423 declarations, file-scope (extern) function declarations (which
20424 had no corresponding body) and file-scope tagged type declarations
20425 and definitions which have not yet been forced out. */
20426 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20427 dwarf2out_decl (decl
);
20430 /* Output debug information for type decl DECL. Called from toplev.c
20431 and from language front ends (to record built-in types). */
20433 dwarf2out_type_decl (tree decl
, int local
)
20436 dwarf2out_decl (decl
);
20439 /* Output debug information for imported module or decl DECL.
20440 NAME is non-NULL name in the lexical block if the decl has been renamed.
20441 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20442 that DECL belongs to.
20443 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20445 dwarf2out_imported_module_or_decl_1 (tree decl
,
20447 tree lexical_block
,
20448 dw_die_ref lexical_block_die
)
20450 expanded_location xloc
;
20451 dw_die_ref imported_die
= NULL
;
20452 dw_die_ref at_import_die
;
20454 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20456 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20457 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20461 xloc
= expand_location (input_location
);
20463 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20465 at_import_die
= force_type_die (TREE_TYPE (decl
));
20466 /* For namespace N { typedef void T; } using N::T; base_type_die
20467 returns NULL, but DW_TAG_imported_declaration requires
20468 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20469 if (!at_import_die
)
20471 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20472 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20473 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20474 gcc_assert (at_import_die
);
20479 at_import_die
= lookup_decl_die (decl
);
20480 if (!at_import_die
)
20482 /* If we're trying to avoid duplicate debug info, we may not have
20483 emitted the member decl for this field. Emit it now. */
20484 if (TREE_CODE (decl
) == FIELD_DECL
)
20486 tree type
= DECL_CONTEXT (decl
);
20488 if (TYPE_CONTEXT (type
)
20489 && TYPE_P (TYPE_CONTEXT (type
))
20490 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20491 DINFO_USAGE_DIR_USE
))
20493 gen_type_die_for_member (type
, decl
,
20494 get_context_die (TYPE_CONTEXT (type
)));
20496 at_import_die
= force_decl_die (decl
);
20500 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20502 if (dwarf_version
>= 3 || !dwarf_strict
)
20503 imported_die
= new_die (DW_TAG_imported_module
,
20510 imported_die
= new_die (DW_TAG_imported_declaration
,
20514 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20515 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20517 add_AT_string (imported_die
, DW_AT_name
,
20518 IDENTIFIER_POINTER (name
));
20519 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20522 /* Output debug information for imported module or decl DECL.
20523 NAME is non-NULL name in context if the decl has been renamed.
20524 CHILD is true if decl is one of the renamed decls as part of
20525 importing whole module. */
20528 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20531 /* dw_die_ref at_import_die; */
20532 dw_die_ref scope_die
;
20534 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20539 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20540 We need decl DIE for reference and scope die. First, get DIE for the decl
20543 /* Get the scope die for decl context. Use comp_unit_die for global module
20544 or decl. If die is not found for non globals, force new die. */
20546 && TYPE_P (context
)
20547 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20550 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20553 scope_die
= get_context_die (context
);
20557 gcc_assert (scope_die
->die_child
);
20558 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20559 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20560 scope_die
= scope_die
->die_child
;
20563 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20564 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20568 /* Write the debugging output for DECL. */
20571 dwarf2out_decl (tree decl
)
20573 dw_die_ref context_die
;
20575 /* In LIPO mode, we may output some functions whose type is defined
20576 in another function that will not be output. This can result in
20577 undefined location list symbols in the debug type info.
20578 Here we disable the output of the type info for this case.
20579 It is safe since this function and its debug info should never
20581 if (L_IPO_COMP_MODE
)
20583 tree decl_context
, orig_decl
;
20585 decl_context
= DECL_CONTEXT (decl
);
20586 while (decl_context
&&
20587 TREE_CODE (decl_context
) != TRANSLATION_UNIT_DECL
)
20589 struct cgraph_node
*node
;
20591 /* Refer to cgraph_mark_functions_to_output() in cgraphunit.c,
20592 if cgraph_is_aux_decl_external() is true,
20593 this function will not be output in LIPO mode. */
20594 if (TREE_CODE (decl_context
) == FUNCTION_DECL
&&
20595 TREE_PUBLIC (decl_context
) &&
20596 (node
= cgraph_get_node (decl_context
)) &&
20597 cgraph_is_aux_decl_external (node
))
20600 if (TYPE_P (decl_context
))
20602 decl_context
= TYPE_CONTEXT (decl_context
);
20606 orig_decl
= DECL_ORIGIN (decl_context
);
20607 while (orig_decl
!= DECL_ORIGIN (orig_decl
))
20608 orig_decl
= DECL_ORIGIN (orig_decl
);
20610 decl_context
= DECL_CONTEXT (orig_decl
);
20614 context_die
= comp_unit_die ();
20616 switch (TREE_CODE (decl
))
20621 case FUNCTION_DECL
:
20622 /* What we would really like to do here is to filter out all mere
20623 file-scope declarations of file-scope functions which are never
20624 referenced later within this translation unit (and keep all of ones
20625 that *are* referenced later on) but we aren't clairvoyant, so we have
20626 no idea which functions will be referenced in the future (i.e. later
20627 on within the current translation unit). So here we just ignore all
20628 file-scope function declarations which are not also definitions. If
20629 and when the debugger needs to know something about these functions,
20630 it will have to hunt around and find the DWARF information associated
20631 with the definition of the function.
20633 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20634 nodes represent definitions and which ones represent mere
20635 declarations. We have to check DECL_INITIAL instead. That's because
20636 the C front-end supports some weird semantics for "extern inline"
20637 function definitions. These can get inlined within the current
20638 translation unit (and thus, we need to generate Dwarf info for their
20639 abstract instances so that the Dwarf info for the concrete inlined
20640 instances can have something to refer to) but the compiler never
20641 generates any out-of-lines instances of such things (despite the fact
20642 that they *are* definitions).
20644 The important point is that the C front-end marks these "extern
20645 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20646 them anyway. Note that the C++ front-end also plays some similar games
20647 for inline function definitions appearing within include files which
20648 also contain `#pragma interface' pragmas.
20650 If we are called from dwarf2out_abstract_function output a DIE
20651 anyway. We can end up here this way with early inlining and LTO
20652 where the inlined function is output in a different LTRANS unit
20654 if (DECL_INITIAL (decl
) == NULL_TREE
20655 && ! DECL_ABSTRACT (decl
))
20658 /* If we're a nested function, initially use a parent of NULL; if we're
20659 a plain function, this will be fixed up in decls_for_scope. If
20660 we're a method, it will be ignored, since we already have a DIE. */
20661 if (decl_function_context (decl
)
20662 /* But if we're in terse mode, we don't care about scope. */
20663 && debug_info_level
> DINFO_LEVEL_TERSE
)
20664 context_die
= NULL
;
20668 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20669 declaration and if the declaration was never even referenced from
20670 within this entire compilation unit. We suppress these DIEs in
20671 order to save space in the .debug section (by eliminating entries
20672 which are probably useless). Note that we must not suppress
20673 block-local extern declarations (whether used or not) because that
20674 would screw-up the debugger's name lookup mechanism and cause it to
20675 miss things which really ought to be in scope at a given point. */
20676 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20679 /* For local statics lookup proper context die. */
20680 if (TREE_STATIC (decl
)
20681 && DECL_CONTEXT (decl
)
20682 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20683 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20685 /* If we are in terse mode, don't generate any DIEs to represent any
20686 variable declarations or definitions. */
20687 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20692 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20694 if (!is_fortran () && !is_ada ())
20696 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20697 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20700 case NAMESPACE_DECL
:
20701 case IMPORTED_DECL
:
20702 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20704 if (lookup_decl_die (decl
) != NULL
)
20709 /* Don't emit stubs for types unless they are needed by other DIEs. */
20710 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20713 /* Don't bother trying to generate any DIEs to represent any of the
20714 normal built-in types for the language we are compiling. */
20715 if (DECL_IS_BUILTIN (decl
))
20718 /* If we are in terse mode, don't generate any DIEs for types. */
20719 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20722 /* If we're a function-scope tag, initially use a parent of NULL;
20723 this will be fixed up in decls_for_scope. */
20724 if (decl_function_context (decl
))
20725 context_die
= NULL
;
20733 gen_decl_die (decl
, NULL
, context_die
);
20736 /* Write the debugging output for DECL. */
20739 dwarf2out_function_decl (tree decl
)
20741 dwarf2out_decl (decl
);
20742 call_arg_locations
= NULL
;
20743 call_arg_loc_last
= NULL
;
20744 call_site_count
= -1;
20745 tail_call_site_count
= -1;
20746 block_map
.release ();
20747 htab_empty (decl_loc_table
);
20748 htab_empty (cached_dw_loc_list_table
);
20751 /* Output a marker (i.e. a label) for the beginning of the generated code for
20752 a lexical block. */
20755 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20756 unsigned int blocknum
)
20758 switch_to_section (current_function_section ());
20759 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20762 /* Output a marker (i.e. a label) for the end of the generated code for a
20766 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20768 switch_to_section (current_function_section ());
20769 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20772 /* Returns nonzero if it is appropriate not to emit any debugging
20773 information for BLOCK, because it doesn't contain any instructions.
20775 Don't allow this for blocks with nested functions or local classes
20776 as we would end up with orphans, and in the presence of scheduling
20777 we may end up calling them anyway. */
20780 dwarf2out_ignore_block (const_tree block
)
20785 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20786 if (TREE_CODE (decl
) == FUNCTION_DECL
20787 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20789 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20791 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20792 if (TREE_CODE (decl
) == FUNCTION_DECL
20793 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20800 /* Hash table routines for file_hash. */
20803 file_table_eq (const void *p1_p
, const void *p2_p
)
20805 const struct dwarf_file_data
*const p1
=
20806 (const struct dwarf_file_data
*) p1_p
;
20807 const char *const p2
= (const char *) p2_p
;
20808 return filename_cmp (p1
->filename
, p2
) == 0;
20812 file_table_hash (const void *p_p
)
20814 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20815 return htab_hash_string (p
->filename
);
20818 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20819 dwarf2out.c) and return its "index". The index of each (known) filename is
20820 just a unique number which is associated with only that one filename. We
20821 need such numbers for the sake of generating labels (in the .debug_sfnames
20822 section) and references to those files numbers (in the .debug_srcinfo
20823 and.debug_macinfo sections). If the filename given as an argument is not
20824 found in our current list, add it to the list and assign it the next
20825 available unique index number. In order to speed up searches, we remember
20826 the index of the filename was looked up last. This handles the majority of
20829 static struct dwarf_file_data
*
20830 lookup_filename (const char *file_name
)
20833 struct dwarf_file_data
* created
;
20835 /* Check to see if the file name that was searched on the previous
20836 call matches this file name. If so, return the index. */
20837 if (file_table_last_lookup
20838 && (file_name
== file_table_last_lookup
->filename
20839 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20840 return file_table_last_lookup
;
20842 /* Didn't match the previous lookup, search the table. */
20843 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20844 htab_hash_string (file_name
), INSERT
);
20846 return (struct dwarf_file_data
*) *slot
;
20848 created
= ggc_alloc_dwarf_file_data ();
20849 created
->filename
= file_name
;
20850 created
->emitted_number
= 0;
20855 /* If the assembler will construct the file table, then translate the compiler
20856 internal file table number into the assembler file table number, and emit
20857 a .file directive if we haven't already emitted one yet. The file table
20858 numbers are different because we prune debug info for unused variables and
20859 types, which may include filenames. */
20862 maybe_emit_file (struct dwarf_file_data
* fd
)
20864 if (! fd
->emitted_number
)
20866 if (last_emitted_file
)
20867 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20869 fd
->emitted_number
= 1;
20870 last_emitted_file
= fd
;
20872 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20874 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20875 output_quoted_string (asm_out_file
,
20876 remap_debug_filename (fd
->filename
));
20877 fputc ('\n', asm_out_file
);
20881 return fd
->emitted_number
;
20884 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20885 That generation should happen after function debug info has been
20886 generated. The value of the attribute is the constant value of ARG. */
20889 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20891 die_arg_entry entry
;
20896 if (!tmpl_value_parm_die_table
)
20897 vec_alloc (tmpl_value_parm_die_table
, 32);
20901 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20904 /* Return TRUE if T is an instance of generic type, FALSE
20908 generic_type_p (tree t
)
20910 if (t
== NULL_TREE
|| !TYPE_P (t
))
20912 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20915 /* Schedule the generation of the generic parameter dies for the
20916 instance of generic type T. The proper generation itself is later
20917 done by gen_scheduled_generic_parms_dies. */
20920 schedule_generic_params_dies_gen (tree t
)
20922 if (!generic_type_p (t
))
20925 if (!generic_type_instances
)
20926 vec_alloc (generic_type_instances
, 256);
20928 vec_safe_push (generic_type_instances
, t
);
20931 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20932 by append_entry_to_tmpl_value_parm_die_table. This function must
20933 be called after function DIEs have been generated. */
20936 gen_remaining_tmpl_value_param_die_attribute (void)
20938 if (tmpl_value_parm_die_table
)
20943 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20944 tree_add_const_value_attribute (e
->die
, e
->arg
);
20948 /* Generate generic parameters DIEs for instances of generic types
20949 that have been previously scheduled by
20950 schedule_generic_params_dies_gen. This function must be called
20951 after all the types of the CU have been laid out. */
20954 gen_scheduled_generic_parms_dies (void)
20959 if (!generic_type_instances
)
20962 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20963 if (COMPLETE_TYPE_P (t
))
20964 gen_generic_params_dies (t
);
20968 /* Replace DW_AT_name for the decl with name. */
20971 dwarf2out_set_name (tree decl
, tree name
)
20977 die
= TYPE_SYMTAB_DIE (decl
);
20981 dname
= dwarf2_name (name
, 0);
20985 attr
= get_AT (die
, DW_AT_name
);
20988 struct indirect_string_node
*node
;
20990 node
= find_AT_string (dname
);
20991 /* replace the string. */
20992 attr
->dw_attr_val
.v
.val_str
= node
;
20996 add_name_attribute (die
, dname
);
20999 /* True if before or during processing of the first function being emitted. */
21000 static bool in_first_function_p
= true;
21001 /* True if loc_note during dwarf2out_var_location call might still be
21002 before first real instruction at address equal to .Ltext0. */
21003 static bool maybe_at_text_label_p
= true;
21004 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
21005 static unsigned int first_loclabel_num_not_at_text_label
;
21007 /* Called by the final INSN scan whenever we see a var location. We
21008 use it to drop labels in the right places, and throw the location in
21009 our lookup table. */
21012 dwarf2out_var_location (rtx loc_note
)
21014 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
21015 struct var_loc_node
*newloc
;
21016 rtx next_real
, next_note
;
21017 static const char *last_label
;
21018 static const char *last_postcall_label
;
21019 static bool last_in_cold_section_p
;
21020 static rtx expected_next_loc_note
;
21024 if (!NOTE_P (loc_note
))
21026 if (CALL_P (loc_note
))
21029 if (SIBLING_CALL_P (loc_note
))
21030 tail_call_site_count
++;
21035 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
21036 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21039 /* Optimize processing a large consecutive sequence of location
21040 notes so we don't spend too much time in next_real_insn. If the
21041 next insn is another location note, remember the next_real_insn
21042 calculation for next time. */
21043 next_real
= cached_next_real_insn
;
21046 if (expected_next_loc_note
!= loc_note
)
21047 next_real
= NULL_RTX
;
21050 next_note
= NEXT_INSN (loc_note
);
21052 || INSN_DELETED_P (next_note
)
21053 || GET_CODE (next_note
) != NOTE
21054 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
21055 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
21056 next_note
= NULL_RTX
;
21059 next_real
= next_real_insn (loc_note
);
21063 expected_next_loc_note
= next_note
;
21064 cached_next_real_insn
= next_real
;
21067 cached_next_real_insn
= NULL_RTX
;
21069 /* If there are no instructions which would be affected by this note,
21070 don't do anything. */
21072 && next_real
== NULL_RTX
21073 && !NOTE_DURING_CALL_P (loc_note
))
21076 if (next_real
== NULL_RTX
)
21077 next_real
= get_last_insn ();
21079 /* If there were any real insns between note we processed last time
21080 and this note (or if it is the first note), clear
21081 last_{,postcall_}label so that they are not reused this time. */
21082 if (last_var_location_insn
== NULL_RTX
21083 || last_var_location_insn
!= next_real
21084 || last_in_cold_section_p
!= in_cold_section_p
)
21087 last_postcall_label
= NULL
;
21092 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21093 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21094 NOTE_DURING_CALL_P (loc_note
)
21095 ? last_postcall_label
: last_label
);
21096 if (newloc
== NULL
)
21105 /* If there were no real insns between note we processed last time
21106 and this note, use the label we emitted last time. Otherwise
21107 create a new label and emit it. */
21108 if (last_label
== NULL
)
21110 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21111 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21113 last_label
= ggc_strdup (loclabel
);
21114 /* See if loclabel might be equal to .Ltext0. If yes,
21115 bump first_loclabel_num_not_at_text_label. */
21116 if (!have_multiple_function_sections
21117 && in_first_function_p
21118 && maybe_at_text_label_p
)
21120 static rtx last_start
;
21122 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
21123 if (insn
== last_start
)
21125 else if (!NONDEBUG_INSN_P (insn
))
21129 rtx body
= PATTERN (insn
);
21130 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
21132 /* Inline asm could occupy zero bytes. */
21133 else if (GET_CODE (body
) == ASM_INPUT
21134 || asm_noperands (body
) >= 0)
21136 #ifdef HAVE_attr_length
21137 else if (get_attr_min_length (insn
) == 0)
21142 /* Assume insn has non-zero length. */
21143 maybe_at_text_label_p
= false;
21147 if (maybe_at_text_label_p
)
21149 last_start
= loc_note
;
21150 first_loclabel_num_not_at_text_label
= loclabel_num
;
21157 struct call_arg_loc_node
*ca_loc
21158 = ggc_alloc_cleared_call_arg_loc_node ();
21159 rtx prev
= prev_real_insn (loc_note
), x
;
21160 ca_loc
->call_arg_loc_note
= loc_note
;
21161 ca_loc
->next
= NULL
;
21162 ca_loc
->label
= last_label
;
21165 || (NONJUMP_INSN_P (prev
)
21166 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21167 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21168 if (!CALL_P (prev
))
21169 prev
= XVECEXP (PATTERN (prev
), 0, 0);
21170 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
21171 x
= get_call_rtx_from (PATTERN (prev
));
21174 x
= XEXP (XEXP (x
, 0), 0);
21175 if (GET_CODE (x
) == SYMBOL_REF
21176 && SYMBOL_REF_DECL (x
)
21177 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21178 ca_loc
->symbol_ref
= x
;
21180 ca_loc
->block
= insn_scope (prev
);
21181 if (call_arg_locations
)
21182 call_arg_loc_last
->next
= ca_loc
;
21184 call_arg_locations
= ca_loc
;
21185 call_arg_loc_last
= ca_loc
;
21187 else if (!NOTE_DURING_CALL_P (loc_note
))
21188 newloc
->label
= last_label
;
21191 if (!last_postcall_label
)
21193 sprintf (loclabel
, "%s-1", last_label
);
21194 last_postcall_label
= ggc_strdup (loclabel
);
21196 newloc
->label
= last_postcall_label
;
21199 last_var_location_insn
= next_real
;
21200 last_in_cold_section_p
= in_cold_section_p
;
21203 /* Note in one location list that text section has changed. */
21206 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
21208 var_loc_list
*list
= (var_loc_list
*) *slot
;
21210 list
->last_before_switch
21211 = list
->last
->next
? list
->last
->next
: list
->last
;
21215 /* Note in all location lists that text section has changed. */
21218 var_location_switch_text_section (void)
21220 if (decl_loc_table
== NULL
)
21223 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
21226 /* Create a new line number table. */
21228 static dw_line_info_table
*
21229 new_line_info_table (void)
21231 dw_line_info_table
*table
;
21233 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
21234 table
->file_num
= 1;
21235 table
->line_num
= 1;
21236 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21241 /* Lookup the "current" table into which we emit line info, so
21242 that we don't have to do it for every source line. */
21245 set_cur_line_info_table (section
*sec
)
21247 dw_line_info_table
*table
;
21249 if (sec
== text_section
)
21250 table
= text_section_line_info
;
21251 else if (sec
== cold_text_section
)
21253 table
= cold_text_section_line_info
;
21256 cold_text_section_line_info
= table
= new_line_info_table ();
21257 table
->end_label
= cold_end_label
;
21262 const char *end_label
;
21264 if (flag_reorder_blocks_and_partition
)
21266 if (in_cold_section_p
)
21267 end_label
= crtl
->subsections
.cold_section_end_label
;
21269 end_label
= crtl
->subsections
.hot_section_end_label
;
21273 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21274 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21275 FUNC_LABEL_ID (cfun
));
21276 end_label
= ggc_strdup (label
);
21279 table
= new_line_info_table ();
21280 table
->end_label
= end_label
;
21282 vec_safe_push (separate_line_info
, table
);
21285 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21286 table
->is_stmt
= (cur_line_info_table
21287 ? cur_line_info_table
->is_stmt
21288 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21289 cur_line_info_table
= table
;
21293 /* We need to reset the locations at the beginning of each
21294 function. We can't do this in the end_function hook, because the
21295 declarations that use the locations won't have been output when
21296 that hook is called. Also compute have_multiple_function_sections here. */
21299 dwarf2out_begin_function (tree fun
)
21301 section
*sec
= function_section (fun
);
21303 if (sec
!= text_section
)
21304 have_multiple_function_sections
= true;
21306 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21308 gcc_assert (current_function_decl
== fun
);
21309 cold_text_section
= unlikely_text_section ();
21310 switch_to_section (cold_text_section
);
21311 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21312 switch_to_section (sec
);
21315 dwarf2out_note_section_used ();
21316 call_site_count
= 0;
21317 tail_call_site_count
= 0;
21319 set_cur_line_info_table (sec
);
21322 /* Helper function of dwarf2out_end_function, called only after emitting
21323 the very first function into assembly. Check if some .debug_loc range
21324 might end with a .LVL* label that could be equal to .Ltext0.
21325 In that case we must force using absolute addresses in .debug_loc ranges,
21326 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21327 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21329 Set have_multiple_function_sections to true in that case and
21330 terminate htab traversal. */
21333 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21335 var_loc_list
*entry
;
21336 struct var_loc_node
*node
;
21338 entry
= (var_loc_list
*) *slot
;
21339 node
= entry
->first
;
21340 if (node
&& node
->next
&& node
->next
->label
)
21343 const char *label
= node
->next
->label
;
21344 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21346 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21348 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21349 if (strcmp (label
, loclabel
) == 0)
21351 have_multiple_function_sections
= true;
21359 /* Hook called after emitting a function into assembly.
21360 This does something only for the very first function emitted. */
21363 dwarf2out_end_function (unsigned int)
21365 if (in_first_function_p
21366 && !have_multiple_function_sections
21367 && first_loclabel_num_not_at_text_label
21369 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21371 in_first_function_p
= false;
21372 maybe_at_text_label_p
= false;
21375 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21378 push_dw_line_info_entry (dw_line_info_table
*table
,
21379 enum dw_line_info_opcode opcode
, unsigned int val
)
21381 dw_line_info_entry e
;
21384 vec_safe_push (table
->entries
, e
);
21387 /* Output a label to mark the beginning of a source code line entry
21388 and record information relating to this source line, in
21389 'line_info_table' for later output of the .debug_line section. */
21390 /* ??? The discriminator parameter ought to be unsigned. */
21393 dwarf2out_source_line (unsigned int line
, const char *filename
,
21394 int discriminator
, bool is_stmt
)
21396 unsigned int file_num
;
21397 dw_line_info_table
*table
;
21399 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
21402 /* The discriminator column was added in dwarf4. Simplify the below
21403 by simply removing it if we're not supposed to output it. */
21404 if (dwarf_version
< 4 && dwarf_strict
)
21407 table
= cur_line_info_table
;
21408 file_num
= maybe_emit_file (lookup_filename (filename
));
21410 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21411 the debugger has used the second (possibly duplicate) line number
21412 at the beginning of the function to mark the end of the prologue.
21413 We could eliminate any other duplicates within the function. For
21414 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21415 that second line number entry. */
21416 /* Recall that this end-of-prologue indication is *not* the same thing
21417 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21418 to which the hook corresponds, follows the last insn that was
21419 emitted by gen_prologue. What we need is to precede the first insn
21420 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21421 insn that corresponds to something the user wrote. These may be
21422 very different locations once scheduling is enabled. */
21424 if (0 && file_num
== table
->file_num
21425 && line
== table
->line_num
21426 && discriminator
== table
->discrim_num
21427 && is_stmt
== table
->is_stmt
)
21430 switch_to_section (current_function_section ());
21432 /* If requested, emit something human-readable. */
21433 if (flag_debug_asm
)
21434 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21436 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21438 /* Emit the .loc directive understood by GNU as. */
21439 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21440 file_num, line, is_stmt, discriminator */
21441 fputs ("\t.loc ", asm_out_file
);
21442 fprint_ul (asm_out_file
, file_num
);
21443 putc (' ', asm_out_file
);
21444 fprint_ul (asm_out_file
, line
);
21445 putc (' ', asm_out_file
);
21446 putc ('0', asm_out_file
);
21448 if (is_stmt
!= table
->is_stmt
)
21450 fputs (" is_stmt ", asm_out_file
);
21451 putc (is_stmt
? '1' : '0', asm_out_file
);
21453 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21455 gcc_assert (discriminator
> 0);
21456 fputs (" discriminator ", asm_out_file
);
21457 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21459 putc ('\n', asm_out_file
);
21463 unsigned int label_num
= ++line_info_label_num
;
21465 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21467 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21468 if (file_num
!= table
->file_num
)
21469 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21470 if (discriminator
!= table
->discrim_num
)
21471 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21472 if (is_stmt
!= table
->is_stmt
)
21473 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21474 push_dw_line_info_entry (table
, LI_set_line
, line
);
21477 table
->file_num
= file_num
;
21478 table
->line_num
= line
;
21479 table
->discrim_num
= discriminator
;
21480 table
->is_stmt
= is_stmt
;
21481 table
->in_use
= true;
21484 /* Record the beginning of a new source file. */
21487 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21489 if (flag_eliminate_dwarf2_dups
)
21491 /* Record the beginning of the file for break_out_includes. */
21492 dw_die_ref bincl_die
;
21494 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21495 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21498 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21501 e
.code
= DW_MACINFO_start_file
;
21503 e
.info
= ggc_strdup (filename
);
21504 vec_safe_push (macinfo_table
, e
);
21508 /* Record the end of a source file. */
21511 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21513 if (flag_eliminate_dwarf2_dups
)
21514 /* Record the end of the file for break_out_includes. */
21515 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21517 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21520 e
.code
= DW_MACINFO_end_file
;
21523 vec_safe_push (macinfo_table
, e
);
21527 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21528 the tail part of the directive line, i.e. the part which is past the
21529 initial whitespace, #, whitespace, directive-name, whitespace part. */
21532 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21533 const char *buffer ATTRIBUTE_UNUSED
)
21535 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21538 /* Insert a dummy first entry to be able to optimize the whole
21539 predefined macro block using DW_MACRO_GNU_transparent_include. */
21540 if (macinfo_table
->is_empty () && lineno
<= 1)
21545 vec_safe_push (macinfo_table
, e
);
21547 e
.code
= DW_MACINFO_define
;
21549 e
.info
= ggc_strdup (buffer
);
21550 vec_safe_push (macinfo_table
, e
);
21554 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21555 the tail part of the directive line, i.e. the part which is past the
21556 initial whitespace, #, whitespace, directive-name, whitespace part. */
21559 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21560 const char *buffer ATTRIBUTE_UNUSED
)
21562 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21565 /* Insert a dummy first entry to be able to optimize the whole
21566 predefined macro block using DW_MACRO_GNU_transparent_include. */
21567 if (macinfo_table
->is_empty () && lineno
<= 1)
21572 vec_safe_push (macinfo_table
, e
);
21574 e
.code
= DW_MACINFO_undef
;
21576 e
.info
= ggc_strdup (buffer
);
21577 vec_safe_push (macinfo_table
, e
);
21581 /* Routines to manipulate hash table of CUs. */
21584 htab_macinfo_hash (const void *of
)
21586 const macinfo_entry
*const entry
=
21587 (const macinfo_entry
*) of
;
21589 return htab_hash_string (entry
->info
);
21593 htab_macinfo_eq (const void *of1
, const void *of2
)
21595 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
21596 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
21598 return !strcmp (entry1
->info
, entry2
->info
);
21601 /* Output a single .debug_macinfo entry. */
21604 output_macinfo_op (macinfo_entry
*ref
)
21608 struct indirect_string_node
*node
;
21609 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21610 struct dwarf_file_data
*fd
;
21614 case DW_MACINFO_start_file
:
21615 fd
= lookup_filename (ref
->info
);
21616 file_num
= maybe_emit_file (fd
);
21617 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21618 dw2_asm_output_data_uleb128 (ref
->lineno
,
21619 "Included from line number %lu",
21620 (unsigned long) ref
->lineno
);
21621 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21623 case DW_MACINFO_end_file
:
21624 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21626 case DW_MACINFO_define
:
21627 case DW_MACINFO_undef
:
21628 len
= strlen (ref
->info
) + 1;
21630 && len
> DWARF_OFFSET_SIZE
21631 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21632 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21634 ref
->code
= ref
->code
== DW_MACINFO_define
21635 ? DW_MACRO_GNU_define_indirect
21636 : DW_MACRO_GNU_undef_indirect
;
21637 output_macinfo_op (ref
);
21640 dw2_asm_output_data (1, ref
->code
,
21641 ref
->code
== DW_MACINFO_define
21642 ? "Define macro" : "Undefine macro");
21643 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21644 (unsigned long) ref
->lineno
);
21645 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21647 case DW_MACRO_GNU_define_indirect
:
21648 case DW_MACRO_GNU_undef_indirect
:
21649 node
= find_AT_string (ref
->info
);
21651 && ((node
->form
== DW_FORM_strp
)
21652 || (node
->form
== DW_FORM_GNU_str_index
)));
21653 dw2_asm_output_data (1, ref
->code
,
21654 ref
->code
== DW_MACRO_GNU_define_indirect
21655 ? "Define macro indirect"
21656 : "Undefine macro indirect");
21657 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21658 (unsigned long) ref
->lineno
);
21659 if (node
->form
== DW_FORM_strp
)
21660 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21661 debug_str_section
, "The macro: \"%s\"",
21664 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21667 case DW_MACRO_GNU_transparent_include
:
21668 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21669 ASM_GENERATE_INTERNAL_LABEL (label
,
21670 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21671 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21674 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21675 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21680 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21681 other compilation unit .debug_macinfo sections. IDX is the first
21682 index of a define/undef, return the number of ops that should be
21683 emitted in a comdat .debug_macinfo section and emit
21684 a DW_MACRO_GNU_transparent_include entry referencing it.
21685 If the define/undef entry should be emitted normally, return 0. */
21688 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21689 htab_t
*macinfo_htab
)
21691 macinfo_entry
*first
, *second
, *cur
, *inc
;
21692 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21693 unsigned char checksum
[16];
21694 struct md5_ctx ctx
;
21695 char *grp_name
, *tail
;
21697 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21700 first
= &(*macinfo_table
)[idx
];
21701 second
= &(*macinfo_table
)[idx
+ 1];
21703 /* Optimize only if there are at least two consecutive define/undef ops,
21704 and either all of them are before first DW_MACINFO_start_file
21705 with lineno {0,1} (i.e. predefined macro block), or all of them are
21706 in some included header file. */
21707 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21709 if (vec_safe_is_empty (files
))
21711 if (first
->lineno
> 1 || second
->lineno
> 1)
21714 else if (first
->lineno
== 0)
21717 /* Find the last define/undef entry that can be grouped together
21718 with first and at the same time compute md5 checksum of their
21719 codes, linenumbers and strings. */
21720 md5_init_ctx (&ctx
);
21721 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21722 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21724 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21728 unsigned char code
= cur
->code
;
21729 md5_process_bytes (&code
, 1, &ctx
);
21730 checksum_uleb128 (cur
->lineno
, &ctx
);
21731 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21733 md5_finish_ctx (&ctx
, checksum
);
21736 /* From the containing include filename (if any) pick up just
21737 usable characters from its basename. */
21738 if (vec_safe_is_empty (files
))
21741 base
= lbasename (files
->last ().info
);
21742 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21743 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21744 encoded_filename_len
++;
21745 /* Count . at the end. */
21746 if (encoded_filename_len
)
21747 encoded_filename_len
++;
21749 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21750 linebuf_len
= strlen (linebuf
);
21752 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21753 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21755 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21756 tail
= grp_name
+ 4;
21757 if (encoded_filename_len
)
21759 for (i
= 0; base
[i
]; i
++)
21760 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21764 memcpy (tail
, linebuf
, linebuf_len
);
21765 tail
+= linebuf_len
;
21767 for (i
= 0; i
< 16; i
++)
21768 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21770 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21771 in the empty vector entry before the first define/undef. */
21772 inc
= &(*macinfo_table
)[idx
- 1];
21773 inc
->code
= DW_MACRO_GNU_transparent_include
;
21775 inc
->info
= ggc_strdup (grp_name
);
21776 if (*macinfo_htab
== NULL
)
21777 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
21778 /* Avoid emitting duplicates. */
21779 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
21784 /* If such an entry has been used before, just emit
21785 a DW_MACRO_GNU_transparent_include op. */
21786 inc
= (macinfo_entry
*) *slot
;
21787 output_macinfo_op (inc
);
21788 /* And clear all macinfo_entry in the range to avoid emitting them
21789 in the second pass. */
21790 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21799 inc
->lineno
= htab_elements (*macinfo_htab
);
21800 output_macinfo_op (inc
);
21805 /* Save any strings needed by the macinfo table in the debug str
21806 table. All strings must be collected into the table by the time
21807 index_string is called. */
21810 save_macinfo_strings (void)
21814 macinfo_entry
*ref
;
21816 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21820 /* Match the logic in output_macinfo_op to decide on
21821 indirect strings. */
21822 case DW_MACINFO_define
:
21823 case DW_MACINFO_undef
:
21824 len
= strlen (ref
->info
) + 1;
21826 && len
> DWARF_OFFSET_SIZE
21827 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21828 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21829 set_indirect_string (find_AT_string (ref
->info
));
21831 case DW_MACRO_GNU_define_indirect
:
21832 case DW_MACRO_GNU_undef_indirect
:
21833 set_indirect_string (find_AT_string (ref
->info
));
21841 /* Output macinfo section(s). */
21844 output_macinfo (void)
21847 unsigned long length
= vec_safe_length (macinfo_table
);
21848 macinfo_entry
*ref
;
21849 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21850 htab_t macinfo_htab
= NULL
;
21855 /* output_macinfo* uses these interchangeably. */
21856 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21857 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21858 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21859 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21861 /* For .debug_macro emit the section header. */
21864 dw2_asm_output_data (2, 4, "DWARF macro version number");
21865 if (DWARF_OFFSET_SIZE
== 8)
21866 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21868 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21869 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21870 (!dwarf_split_debug_info
? debug_line_section_label
21871 : debug_skeleton_line_section_label
),
21872 debug_line_section
, NULL
);
21875 /* In the first loop, it emits the primary .debug_macinfo section
21876 and after each emitted op the macinfo_entry is cleared.
21877 If a longer range of define/undef ops can be optimized using
21878 DW_MACRO_GNU_transparent_include, the
21879 DW_MACRO_GNU_transparent_include op is emitted and kept in
21880 the vector before the first define/undef in the range and the
21881 whole range of define/undef ops is not emitted and kept. */
21882 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21886 case DW_MACINFO_start_file
:
21887 vec_safe_push (files
, *ref
);
21889 case DW_MACINFO_end_file
:
21890 if (!vec_safe_is_empty (files
))
21893 case DW_MACINFO_define
:
21894 case DW_MACINFO_undef
:
21896 && HAVE_COMDAT_GROUP
21897 && vec_safe_length (files
) != 1
21900 && (*macinfo_table
)[i
- 1].code
== 0)
21902 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21911 /* A dummy entry may be inserted at the beginning to be able
21912 to optimize the whole block of predefined macros. */
21918 output_macinfo_op (ref
);
21923 if (macinfo_htab
== NULL
)
21926 htab_delete (macinfo_htab
);
21928 /* If any DW_MACRO_GNU_transparent_include were used, on those
21929 DW_MACRO_GNU_transparent_include entries terminate the
21930 current chain and switch to a new comdat .debug_macinfo
21931 section and emit the define/undef entries within it. */
21932 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21937 case DW_MACRO_GNU_transparent_include
:
21939 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21940 tree comdat_key
= get_identifier (ref
->info
);
21941 /* Terminate the previous .debug_macinfo section. */
21942 dw2_asm_output_data (1, 0, "End compilation unit");
21943 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21945 | SECTION_LINKONCE
,
21947 ASM_GENERATE_INTERNAL_LABEL (label
,
21948 DEBUG_MACRO_SECTION_LABEL
,
21950 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21953 dw2_asm_output_data (2, 4, "DWARF macro version number");
21954 if (DWARF_OFFSET_SIZE
== 8)
21955 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21957 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21960 case DW_MACINFO_define
:
21961 case DW_MACINFO_undef
:
21962 output_macinfo_op (ref
);
21967 gcc_unreachable ();
21971 /* Set up for Dwarf output at the start of compilation. */
21974 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21976 /* Allocate the file_table. */
21977 file_table
= htab_create_ggc (50, file_table_hash
,
21978 file_table_eq
, NULL
);
21980 /* Allocate the decl_die_table. */
21981 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21982 decl_die_table_eq
, NULL
);
21984 /* Allocate the decl_loc_table. */
21985 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21986 decl_loc_table_eq
, NULL
);
21988 /* Allocate the cached_dw_loc_list_table. */
21989 cached_dw_loc_list_table
21990 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21991 cached_dw_loc_list_table_eq
, NULL
);
21993 /* Allocate the initial hunk of the decl_scope_table. */
21994 vec_alloc (decl_scope_table
, 256);
21996 /* Allocate the initial hunk of the abbrev_die_table. */
21997 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21998 (ABBREV_DIE_TABLE_INCREMENT
);
21999 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
22000 /* Zero-th entry is allocated, but unused. */
22001 abbrev_die_table_in_use
= 1;
22003 /* Allocate the pubtypes and pubnames vectors. */
22004 vec_alloc (pubname_table
, 32);
22005 vec_alloc (pubtype_table
, 32);
22007 vec_alloc (incomplete_types
, 64);
22009 vec_alloc (used_rtx_array
, 32);
22011 if (!dwarf_split_debug_info
)
22013 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
22014 SECTION_DEBUG
, NULL
);
22015 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22016 SECTION_DEBUG
, NULL
);
22017 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
22018 SECTION_DEBUG
, NULL
);
22022 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
22023 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22024 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
22025 SECTION_DEBUG
| SECTION_EXCLUDE
,
22027 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
22028 SECTION_DEBUG
, NULL
);
22029 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
22030 SECTION_DEBUG
, NULL
);
22031 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22032 SECTION_DEBUG
, NULL
);
22033 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
22034 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
22036 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
22037 the main .o, but the skeleton_line goes into the split off dwo. */
22038 debug_skeleton_line_section
22039 = get_section (DEBUG_DWO_LINE_SECTION
,
22040 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22041 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
22042 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
22043 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
22044 SECTION_DEBUG
| SECTION_EXCLUDE
,
22046 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
22047 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
22048 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
22049 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22050 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
22051 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
22053 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
22054 SECTION_DEBUG
, NULL
);
22055 debug_macinfo_section
= get_section (dwarf_strict
22056 ? DEBUG_MACINFO_SECTION
22057 : DEBUG_MACRO_SECTION
,
22058 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
22059 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
22060 SECTION_DEBUG
, NULL
);
22061 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
22062 SECTION_DEBUG
, NULL
);
22063 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
22064 SECTION_DEBUG
, NULL
);
22065 debug_str_section
= get_section (DEBUG_STR_SECTION
,
22066 DEBUG_STR_SECTION_FLAGS
, NULL
);
22067 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
22068 SECTION_DEBUG
, NULL
);
22069 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
22070 SECTION_DEBUG
, NULL
);
22072 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
22073 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
22074 DEBUG_ABBREV_SECTION_LABEL
, 0);
22075 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
22076 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
22077 COLD_TEXT_SECTION_LABEL
, 0);
22078 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
22080 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
22081 DEBUG_INFO_SECTION_LABEL
, 0);
22082 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
22083 DEBUG_LINE_SECTION_LABEL
, 0);
22084 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
22085 DEBUG_RANGES_SECTION_LABEL
, 0);
22086 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
22087 DEBUG_ADDR_SECTION_LABEL
, 0);
22088 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
22090 ? DEBUG_MACINFO_SECTION_LABEL
22091 : DEBUG_MACRO_SECTION_LABEL
, 0);
22092 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
22094 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22095 vec_alloc (macinfo_table
, 64);
22097 switch_to_section (text_section
);
22098 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
22100 /* Make sure the line number table for .text always exists. */
22101 text_section_line_info
= new_line_info_table ();
22102 text_section_line_info
->end_label
= text_end_label
;
22105 /* Called before compile () starts outputtting functions, variables
22106 and toplevel asms into assembly. */
22109 dwarf2out_assembly_start (void)
22111 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22112 && dwarf2out_do_cfi_asm ()
22113 && (!(flag_unwind_tables
|| flag_exceptions
)
22114 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
22115 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
22118 /* A helper function for dwarf2out_finish called through
22119 htab_traverse. Assign a string its index. All strings must be
22120 collected into the table by the time index_string is called,
22121 because the indexing code relies on htab_traverse to traverse nodes
22122 in the same order for each run. */
22125 index_string (void **h
, void *v
)
22127 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22128 unsigned int *index
= (unsigned int *) v
;
22130 find_string_form (node
);
22131 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22133 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
22134 node
->index
= *index
;
22140 /* A helper function for output_indirect_strings called through
22141 htab_traverse. Output the offset to a string and update the
22145 output_index_string_offset (void **h
, void *v
)
22147 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22148 unsigned int *offset
= (unsigned int *) v
;
22150 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22152 /* Assert that this node has been assigned an index. */
22153 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
22154 && node
->index
!= NOT_INDEXED
);
22155 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
22156 "indexed string 0x%x: %s", node
->index
, node
->str
);
22157 *offset
+= strlen (node
->str
) + 1;
22162 /* A helper function for dwarf2out_finish called through
22163 htab_traverse. Output the indexed string. */
22166 output_index_string (void **h
, void *v
)
22168 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22169 unsigned int *cur_idx
= (unsigned int *) v
;
22171 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22173 /* Assert that the strings are output in the same order as their
22174 indexes were assigned. */
22175 gcc_assert (*cur_idx
== node
->index
);
22176 assemble_string (node
->str
, strlen (node
->str
) + 1);
22182 /* A helper function for dwarf2out_finish called through
22183 htab_traverse. Emit one queued .debug_str string. */
22186 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22188 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22190 node
->form
= find_string_form (node
);
22191 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22193 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22194 assemble_string (node
->str
, strlen (node
->str
) + 1);
22200 /* Output the indexed string table. */
22203 output_indirect_strings (void)
22205 switch_to_section (debug_str_section
);
22206 if (!dwarf_split_debug_info
)
22207 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22210 unsigned int offset
= 0;
22211 unsigned int cur_idx
= 0;
22213 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
22215 switch_to_section (debug_str_offsets_section
);
22216 htab_traverse_noresize (debug_str_hash
,
22217 output_index_string_offset
,
22219 switch_to_section (debug_str_dwo_section
);
22220 htab_traverse_noresize (debug_str_hash
,
22221 output_index_string
,
22226 /* Callback for htab_traverse to assign an index to an entry in the
22227 table, and to write that entry to the .debug_addr section. */
22230 output_addr_table_entry (void **slot
, void *data
)
22232 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22233 unsigned int *cur_index
= (unsigned int *)data
;
22235 if (entry
->refcount
== 0)
22237 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22238 || entry
->index
== NOT_INDEXED
);
22242 gcc_assert (entry
->index
== *cur_index
);
22245 switch (entry
->kind
)
22248 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22249 "0x%x", entry
->index
);
22251 case ate_kind_rtx_dtprel
:
22252 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22253 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22256 fputc ('\n', asm_out_file
);
22258 case ate_kind_label
:
22259 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22260 "0x%x", entry
->index
);
22263 gcc_unreachable ();
22268 /* Produce the .debug_addr section. */
22271 output_addr_table (void)
22273 unsigned int index
= 0;
22274 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22277 switch_to_section (debug_addr_section
);
22278 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22281 #if ENABLE_ASSERT_CHECKING
22282 /* Verify that all marks are clear. */
22285 verify_marks_clear (dw_die_ref die
)
22289 gcc_assert (! die
->die_mark
);
22290 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22292 #endif /* ENABLE_ASSERT_CHECKING */
22294 /* Clear the marks for a die and its children.
22295 Be cool if the mark isn't set. */
22298 prune_unmark_dies (dw_die_ref die
)
22304 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22307 /* Given DIE that we're marking as used, find any other dies
22308 it references as attributes and mark them as used. */
22311 prune_unused_types_walk_attribs (dw_die_ref die
)
22316 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22318 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22320 /* A reference to another DIE.
22321 Make sure that it will get emitted.
22322 If it was broken out into a comdat group, don't follow it. */
22323 if (! AT_ref (a
)->comdat_type_p
22324 || a
->dw_attr
== DW_AT_specification
)
22325 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22327 /* Set the string's refcount to 0 so that prune_unused_types_mark
22328 accounts properly for it. */
22329 if (AT_class (a
) == dw_val_class_str
)
22330 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22334 /* Mark the generic parameters and arguments children DIEs of DIE. */
22337 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22341 if (die
== NULL
|| die
->die_child
== NULL
)
22343 c
= die
->die_child
;
22346 if (is_template_parameter (c
))
22347 prune_unused_types_mark (c
, 1);
22349 } while (c
&& c
!= die
->die_child
);
22352 /* Mark DIE as being used. If DOKIDS is true, then walk down
22353 to DIE's children. */
22356 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22360 if (die
->die_mark
== 0)
22362 /* We haven't done this node yet. Mark it as used. */
22364 /* If this is the DIE of a generic type instantiation,
22365 mark the children DIEs that describe its generic parms and
22367 prune_unused_types_mark_generic_parms_dies (die
);
22369 /* We also have to mark its parents as used.
22370 (But we don't want to mark our parent's kids due to this,
22371 unless it is a class.) */
22372 if (die
->die_parent
)
22373 prune_unused_types_mark (die
->die_parent
,
22374 class_scope_p (die
->die_parent
));
22376 /* Mark any referenced nodes. */
22377 prune_unused_types_walk_attribs (die
);
22379 /* If this node is a specification,
22380 also mark the definition, if it exists. */
22381 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22382 prune_unused_types_mark (die
->die_definition
, 1);
22385 if (dokids
&& die
->die_mark
!= 2)
22387 /* We need to walk the children, but haven't done so yet.
22388 Remember that we've walked the kids. */
22391 /* If this is an array type, we need to make sure our
22392 kids get marked, even if they're types. If we're
22393 breaking out types into comdat sections, do this
22394 for all type definitions. */
22395 if (die
->die_tag
== DW_TAG_array_type
22396 || (use_debug_types
22397 && is_type_die (die
) && ! is_declaration_die (die
)))
22398 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22400 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22404 /* For local classes, look if any static member functions were emitted
22405 and if so, mark them. */
22408 prune_unused_types_walk_local_classes (dw_die_ref die
)
22412 if (die
->die_mark
== 2)
22415 switch (die
->die_tag
)
22417 case DW_TAG_structure_type
:
22418 case DW_TAG_union_type
:
22419 case DW_TAG_class_type
:
22422 case DW_TAG_subprogram
:
22423 if (!get_AT_flag (die
, DW_AT_declaration
)
22424 || die
->die_definition
!= NULL
)
22425 prune_unused_types_mark (die
, 1);
22432 /* Mark children. */
22433 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22436 /* Walk the tree DIE and mark types that we actually use. */
22439 prune_unused_types_walk (dw_die_ref die
)
22443 /* Don't do anything if this node is already marked and
22444 children have been marked as well. */
22445 if (die
->die_mark
== 2)
22448 switch (die
->die_tag
)
22450 case DW_TAG_structure_type
:
22451 case DW_TAG_union_type
:
22452 case DW_TAG_class_type
:
22453 if (die
->die_perennial_p
)
22456 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22457 if (c
->die_tag
== DW_TAG_subprogram
)
22460 /* Finding used static member functions inside of classes
22461 is needed just for local classes, because for other classes
22462 static member function DIEs with DW_AT_specification
22463 are emitted outside of the DW_TAG_*_type. If we ever change
22464 it, we'd need to call this even for non-local classes. */
22466 prune_unused_types_walk_local_classes (die
);
22468 /* It's a type node --- don't mark it. */
22471 case DW_TAG_const_type
:
22472 case DW_TAG_packed_type
:
22473 case DW_TAG_pointer_type
:
22474 case DW_TAG_reference_type
:
22475 case DW_TAG_rvalue_reference_type
:
22476 case DW_TAG_volatile_type
:
22477 case DW_TAG_typedef
:
22478 case DW_TAG_array_type
:
22479 case DW_TAG_interface_type
:
22480 case DW_TAG_friend
:
22481 case DW_TAG_variant_part
:
22482 case DW_TAG_enumeration_type
:
22483 case DW_TAG_subroutine_type
:
22484 case DW_TAG_string_type
:
22485 case DW_TAG_set_type
:
22486 case DW_TAG_subrange_type
:
22487 case DW_TAG_ptr_to_member_type
:
22488 case DW_TAG_file_type
:
22489 if (die
->die_perennial_p
)
22492 /* It's a type node --- don't mark it. */
22496 /* Mark everything else. */
22500 if (die
->die_mark
== 0)
22504 /* Now, mark any dies referenced from here. */
22505 prune_unused_types_walk_attribs (die
);
22510 /* Mark children. */
22511 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22514 /* Increment the string counts on strings referred to from DIE's
22518 prune_unused_types_update_strings (dw_die_ref die
)
22523 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22524 if (AT_class (a
) == dw_val_class_str
)
22526 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22528 /* Avoid unnecessarily putting strings that are used less than
22529 twice in the hash table. */
22531 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22534 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22535 htab_hash_string (s
->str
),
22537 gcc_assert (*slot
== NULL
);
22543 /* Remove from the tree DIE any dies that aren't marked. */
22546 prune_unused_types_prune (dw_die_ref die
)
22550 gcc_assert (die
->die_mark
);
22551 prune_unused_types_update_strings (die
);
22553 if (! die
->die_child
)
22556 c
= die
->die_child
;
22558 dw_die_ref prev
= c
;
22559 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22560 if (c
== die
->die_child
)
22562 /* No marked children between 'prev' and the end of the list. */
22564 /* No marked children at all. */
22565 die
->die_child
= NULL
;
22568 prev
->die_sib
= c
->die_sib
;
22569 die
->die_child
= prev
;
22574 if (c
!= prev
->die_sib
)
22576 prune_unused_types_prune (c
);
22577 } while (c
!= die
->die_child
);
22580 /* Remove dies representing declarations that we never use. */
22583 prune_unused_types (void)
22586 limbo_die_node
*node
;
22587 comdat_type_node
*ctnode
;
22589 dw_die_ref base_type
;
22591 #if ENABLE_ASSERT_CHECKING
22592 /* All the marks should already be clear. */
22593 verify_marks_clear (comp_unit_die ());
22594 for (node
= limbo_die_list
; node
; node
= node
->next
)
22595 verify_marks_clear (node
->die
);
22596 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22597 verify_marks_clear (ctnode
->root_die
);
22598 #endif /* ENABLE_ASSERT_CHECKING */
22600 /* Mark types that are used in global variables. */
22601 premark_types_used_by_global_vars ();
22603 /* Set the mark on nodes that are actually used. */
22604 prune_unused_types_walk (comp_unit_die ());
22605 for (node
= limbo_die_list
; node
; node
= node
->next
)
22606 prune_unused_types_walk (node
->die
);
22607 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22609 prune_unused_types_walk (ctnode
->root_die
);
22610 prune_unused_types_mark (ctnode
->type_die
, 1);
22613 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22614 are unusual in that they are pubnames that are the children of pubtypes.
22615 They should only be marked via their parent DW_TAG_enumeration_type die,
22616 not as roots in themselves. */
22617 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22618 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22619 prune_unused_types_mark (pub
->die
, 1);
22620 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22621 prune_unused_types_mark (base_type
, 1);
22623 if (debug_str_hash
)
22624 htab_empty (debug_str_hash
);
22625 if (skeleton_debug_str_hash
)
22626 htab_empty (skeleton_debug_str_hash
);
22627 prune_unused_types_prune (comp_unit_die ());
22628 for (node
= limbo_die_list
; node
; node
= node
->next
)
22629 prune_unused_types_prune (node
->die
);
22630 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22631 prune_unused_types_prune (ctnode
->root_die
);
22633 /* Leave the marks clear. */
22634 prune_unmark_dies (comp_unit_die ());
22635 for (node
= limbo_die_list
; node
; node
= node
->next
)
22636 prune_unmark_dies (node
->die
);
22637 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22638 prune_unmark_dies (ctnode
->root_die
);
22641 /* Set the parameter to true if there are any relative pathnames in
22644 file_table_relative_p (void ** slot
, void *param
)
22646 bool *p
= (bool *) param
;
22647 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22648 if (!IS_ABSOLUTE_PATH (d
->filename
))
22656 /* Routines to manipulate hash table of comdat type units. */
22659 htab_ct_hash (const void *of
)
22662 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
22664 memcpy (&h
, type_node
->signature
, sizeof (h
));
22669 htab_ct_eq (const void *of1
, const void *of2
)
22671 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
22672 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
22674 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22675 DWARF_TYPE_SIGNATURE_SIZE
));
22678 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22679 to the location it would have been added, should we know its
22680 DECL_ASSEMBLER_NAME when we added other attributes. This will
22681 probably improve compactness of debug info, removing equivalent
22682 abbrevs, and hide any differences caused by deferring the
22683 computation of the assembler name, triggered by e.g. PCH. */
22686 move_linkage_attr (dw_die_ref die
)
22688 unsigned ix
= vec_safe_length (die
->die_attr
);
22689 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22691 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22692 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22696 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22698 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22702 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22704 die
->die_attr
->pop ();
22705 die
->die_attr
->quick_insert (ix
, linkage
);
22709 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22710 referenced from typed stack ops and count how often they are used. */
22713 mark_base_types (dw_loc_descr_ref loc
)
22715 dw_die_ref base_type
= NULL
;
22717 for (; loc
; loc
= loc
->dw_loc_next
)
22719 switch (loc
->dw_loc_opc
)
22721 case DW_OP_GNU_regval_type
:
22722 case DW_OP_GNU_deref_type
:
22723 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22725 case DW_OP_GNU_convert
:
22726 case DW_OP_GNU_reinterpret
:
22727 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22730 case DW_OP_GNU_const_type
:
22731 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22733 case DW_OP_GNU_entry_value
:
22734 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22739 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22740 if (base_type
->die_mark
)
22741 base_type
->die_mark
++;
22744 base_types
.safe_push (base_type
);
22745 base_type
->die_mark
= 1;
22750 /* Comparison function for sorting marked base types. */
22753 base_type_cmp (const void *x
, const void *y
)
22755 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22756 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22757 unsigned int byte_size1
, byte_size2
;
22758 unsigned int encoding1
, encoding2
;
22759 if (dx
->die_mark
> dy
->die_mark
)
22761 if (dx
->die_mark
< dy
->die_mark
)
22763 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22764 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22765 if (byte_size1
< byte_size2
)
22767 if (byte_size1
> byte_size2
)
22769 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22770 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22771 if (encoding1
< encoding2
)
22773 if (encoding1
> encoding2
)
22778 /* Move base types marked by mark_base_types as early as possible
22779 in the CU, sorted by decreasing usage count both to make the
22780 uleb128 references as small as possible and to make sure they
22781 will have die_offset already computed by calc_die_sizes when
22782 sizes of typed stack loc ops is computed. */
22785 move_marked_base_types (void)
22788 dw_die_ref base_type
, die
, c
;
22790 if (base_types
.is_empty ())
22793 /* Sort by decreasing usage count, they will be added again in that
22795 base_types
.qsort (base_type_cmp
);
22796 die
= comp_unit_die ();
22797 c
= die
->die_child
;
22800 dw_die_ref prev
= c
;
22802 while (c
->die_mark
)
22804 remove_child_with_prev (c
, prev
);
22805 /* As base types got marked, there must be at least
22806 one node other than DW_TAG_base_type. */
22807 gcc_assert (c
!= c
->die_sib
);
22811 while (c
!= die
->die_child
);
22812 gcc_assert (die
->die_child
);
22813 c
= die
->die_child
;
22814 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22816 base_type
->die_mark
= 0;
22817 base_type
->die_sib
= c
->die_sib
;
22818 c
->die_sib
= base_type
;
22823 /* Helper function for resolve_addr, attempt to resolve
22824 one CONST_STRING, return non-zero if not successful. Similarly verify that
22825 SYMBOL_REFs refer to variables emitted in the current CU. */
22828 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22832 if (GET_CODE (rtl
) == CONST_STRING
)
22834 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22835 tree t
= build_string (len
, XSTR (rtl
, 0));
22836 tree tlen
= size_int (len
- 1);
22838 = build_array_type (char_type_node
, build_index_type (tlen
));
22839 rtl
= lookup_constant_def (t
);
22840 if (!rtl
|| !MEM_P (rtl
))
22842 rtl
= XEXP (rtl
, 0);
22843 vec_safe_push (used_rtx_array
, rtl
);
22848 if (GET_CODE (rtl
) == SYMBOL_REF
22849 && SYMBOL_REF_DECL (rtl
))
22851 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22853 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22856 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22860 if (GET_CODE (rtl
) == CONST
22861 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22867 /* Helper function for resolve_addr, handle one location
22868 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22869 the location list couldn't be resolved. */
22872 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22874 dw_loc_descr_ref keep
= NULL
;
22875 for (; loc
; loc
= loc
->dw_loc_next
)
22876 switch (loc
->dw_loc_opc
)
22879 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22882 case DW_OP_GNU_addr_index
:
22883 case DW_OP_GNU_const_index
:
22885 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22886 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22887 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22892 case DW_OP_const4u
:
22893 case DW_OP_const8u
:
22895 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22898 case DW_OP_plus_uconst
:
22899 if (size_of_loc_descr (loc
)
22900 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22902 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22904 dw_loc_descr_ref repl
22905 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22906 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
22907 add_loc_descr (&repl
, loc
->dw_loc_next
);
22911 case DW_OP_implicit_value
:
22912 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22913 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
22916 case DW_OP_GNU_implicit_pointer
:
22917 case DW_OP_GNU_parameter_ref
:
22918 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22921 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22924 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22925 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22926 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22929 case DW_OP_GNU_const_type
:
22930 case DW_OP_GNU_regval_type
:
22931 case DW_OP_GNU_deref_type
:
22932 case DW_OP_GNU_convert
:
22933 case DW_OP_GNU_reinterpret
:
22934 while (loc
->dw_loc_next
22935 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
22937 dw_die_ref base1
, base2
;
22938 unsigned enc1
, enc2
, size1
, size2
;
22939 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22940 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22941 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22942 else if (loc
->dw_loc_oprnd1
.val_class
22943 == dw_val_class_unsigned_const
)
22946 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22947 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
22948 == dw_val_class_unsigned_const
)
22950 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22951 gcc_assert (base1
->die_tag
== DW_TAG_base_type
22952 && base2
->die_tag
== DW_TAG_base_type
);
22953 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
22954 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
22955 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
22956 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
22958 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
22959 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
22963 /* Optimize away next DW_OP_GNU_convert after
22964 adjusting LOC's base type die reference. */
22965 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22966 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22967 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
22969 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
22970 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22973 /* Don't change integer DW_OP_GNU_convert after e.g. floating
22974 point typed stack entry. */
22975 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
22976 keep
= loc
->dw_loc_next
;
22986 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22987 an address in .rodata section if the string literal is emitted there,
22988 or remove the containing location list or replace DW_AT_const_value
22989 with DW_AT_location and empty location expression, if it isn't found
22990 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22991 to something that has been emitted in the current CU. */
22994 resolve_addr (dw_die_ref die
)
22998 dw_loc_list_ref
*curr
, *start
, loc
;
23001 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23002 switch (AT_class (a
))
23004 case dw_val_class_loc_list
:
23005 start
= curr
= AT_loc_list_ptr (a
);
23008 /* The same list can be referenced more than once. See if we have
23009 already recorded the result from a previous pass. */
23011 *curr
= loc
->dw_loc_next
;
23012 else if (!loc
->resolved_addr
)
23014 /* As things stand, we do not expect or allow one die to
23015 reference a suffix of another die's location list chain.
23016 References must be identical or completely separate.
23017 There is therefore no need to cache the result of this
23018 pass on any list other than the first; doing so
23019 would lead to unnecessary writes. */
23022 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23023 if (!resolve_addr_in_expr ((*curr
)->expr
))
23025 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23026 dw_loc_descr_ref l
= (*curr
)->expr
;
23028 if (next
&& (*curr
)->ll_symbol
)
23030 gcc_assert (!next
->ll_symbol
);
23031 next
->ll_symbol
= (*curr
)->ll_symbol
;
23033 if (dwarf_split_debug_info
)
23034 remove_loc_list_addr_table_entries (l
);
23039 mark_base_types ((*curr
)->expr
);
23040 curr
= &(*curr
)->dw_loc_next
;
23044 loc
->resolved_addr
= 1;
23048 loc
->dw_loc_next
= *start
;
23053 remove_AT (die
, a
->dw_attr
);
23057 case dw_val_class_loc
:
23059 dw_loc_descr_ref l
= AT_loc (a
);
23060 /* For -gdwarf-2 don't attempt to optimize
23061 DW_AT_data_member_location containing
23062 DW_OP_plus_uconst - older consumers might
23063 rely on it being that op instead of a more complex,
23064 but shorter, location description. */
23065 if ((dwarf_version
> 2
23066 || a
->dw_attr
!= DW_AT_data_member_location
23068 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23069 || l
->dw_loc_next
!= NULL
)
23070 && !resolve_addr_in_expr (l
))
23072 if (dwarf_split_debug_info
)
23073 remove_loc_list_addr_table_entries (l
);
23074 remove_AT (die
, a
->dw_attr
);
23078 mark_base_types (l
);
23081 case dw_val_class_addr
:
23082 if (a
->dw_attr
== DW_AT_const_value
23083 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23085 if (AT_index (a
) != NOT_INDEXED
)
23086 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23087 remove_AT (die
, a
->dw_attr
);
23090 if (die
->die_tag
== DW_TAG_GNU_call_site
23091 && a
->dw_attr
== DW_AT_abstract_origin
)
23093 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23094 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23096 && DECL_EXTERNAL (tdecl
)
23097 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23099 force_decl_die (tdecl
);
23100 tdie
= lookup_decl_die (tdecl
);
23104 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23105 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23106 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23110 if (AT_index (a
) != NOT_INDEXED
)
23111 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23112 remove_AT (die
, a
->dw_attr
);
23121 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23124 /* Helper routines for optimize_location_lists.
23125 This pass tries to share identical local lists in .debug_loc
23128 /* Iteratively hash operands of LOC opcode. */
23131 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23133 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23134 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23136 switch (loc
->dw_loc_opc
)
23138 case DW_OP_const4u
:
23139 case DW_OP_const8u
:
23143 case DW_OP_const1u
:
23144 case DW_OP_const1s
:
23145 case DW_OP_const2u
:
23146 case DW_OP_const2s
:
23147 case DW_OP_const4s
:
23148 case DW_OP_const8s
:
23152 case DW_OP_plus_uconst
:
23188 case DW_OP_deref_size
:
23189 case DW_OP_xderef_size
:
23190 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23197 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23198 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23199 hash
= iterative_hash_object (offset
, hash
);
23202 case DW_OP_implicit_value
:
23203 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23204 switch (val2
->val_class
)
23206 case dw_val_class_const
:
23207 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23209 case dw_val_class_vec
:
23211 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23212 unsigned int len
= val2
->v
.val_vec
.length
;
23214 hash
= iterative_hash_object (elt_size
, hash
);
23215 hash
= iterative_hash_object (len
, hash
);
23216 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23217 len
* elt_size
, hash
);
23220 case dw_val_class_const_double
:
23221 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23222 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23224 case dw_val_class_addr
:
23225 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23228 gcc_unreachable ();
23232 case DW_OP_bit_piece
:
23233 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23234 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23240 unsigned char dtprel
= 0xd1;
23241 hash
= iterative_hash_object (dtprel
, hash
);
23243 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23245 case DW_OP_GNU_addr_index
:
23246 case DW_OP_GNU_const_index
:
23250 unsigned char dtprel
= 0xd1;
23251 hash
= iterative_hash_object (dtprel
, hash
);
23253 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23256 case DW_OP_GNU_implicit_pointer
:
23257 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23259 case DW_OP_GNU_entry_value
:
23260 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23262 case DW_OP_GNU_regval_type
:
23263 case DW_OP_GNU_deref_type
:
23265 unsigned int byte_size
23266 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23267 unsigned int encoding
23268 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23269 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23270 hash
= iterative_hash_object (byte_size
, hash
);
23271 hash
= iterative_hash_object (encoding
, hash
);
23274 case DW_OP_GNU_convert
:
23275 case DW_OP_GNU_reinterpret
:
23276 if (val1
->val_class
== dw_val_class_unsigned_const
)
23278 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23282 case DW_OP_GNU_const_type
:
23284 unsigned int byte_size
23285 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23286 unsigned int encoding
23287 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23288 hash
= iterative_hash_object (byte_size
, hash
);
23289 hash
= iterative_hash_object (encoding
, hash
);
23290 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23292 hash
= iterative_hash_object (val2
->val_class
, hash
);
23293 switch (val2
->val_class
)
23295 case dw_val_class_const
:
23296 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23298 case dw_val_class_vec
:
23300 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23301 unsigned int len
= val2
->v
.val_vec
.length
;
23303 hash
= iterative_hash_object (elt_size
, hash
);
23304 hash
= iterative_hash_object (len
, hash
);
23305 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23306 len
* elt_size
, hash
);
23309 case dw_val_class_const_double
:
23310 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23311 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23314 gcc_unreachable ();
23320 /* Other codes have no operands. */
23326 /* Iteratively hash the whole DWARF location expression LOC. */
23328 static inline hashval_t
23329 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23331 dw_loc_descr_ref l
;
23332 bool sizes_computed
= false;
23333 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23334 size_of_locs (loc
);
23336 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23338 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23339 hash
= iterative_hash_object (opc
, hash
);
23340 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23342 size_of_locs (loc
);
23343 sizes_computed
= true;
23345 hash
= hash_loc_operands (l
, hash
);
23350 /* Compute hash of the whole location list LIST_HEAD. */
23353 hash_loc_list (dw_loc_list_ref list_head
)
23355 dw_loc_list_ref curr
= list_head
;
23356 hashval_t hash
= 0;
23358 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23360 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23361 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23363 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23365 hash
= hash_locs (curr
->expr
, hash
);
23367 list_head
->hash
= hash
;
23370 /* Return true if X and Y opcodes have the same operands. */
23373 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23375 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23376 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23377 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23378 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23380 switch (x
->dw_loc_opc
)
23382 case DW_OP_const4u
:
23383 case DW_OP_const8u
:
23387 case DW_OP_const1u
:
23388 case DW_OP_const1s
:
23389 case DW_OP_const2u
:
23390 case DW_OP_const2s
:
23391 case DW_OP_const4s
:
23392 case DW_OP_const8s
:
23396 case DW_OP_plus_uconst
:
23432 case DW_OP_deref_size
:
23433 case DW_OP_xderef_size
:
23434 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23437 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23438 can cause irrelevant differences in dw_loc_addr. */
23439 gcc_assert (valx1
->val_class
== dw_val_class_loc
23440 && valy1
->val_class
== dw_val_class_loc
23441 && (dwarf_split_debug_info
23442 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23443 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23444 case DW_OP_implicit_value
:
23445 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23446 || valx2
->val_class
!= valy2
->val_class
)
23448 switch (valx2
->val_class
)
23450 case dw_val_class_const
:
23451 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23452 case dw_val_class_vec
:
23453 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23454 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23455 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23456 valx2
->v
.val_vec
.elt_size
23457 * valx2
->v
.val_vec
.length
) == 0;
23458 case dw_val_class_const_double
:
23459 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23460 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23461 case dw_val_class_addr
:
23462 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23464 gcc_unreachable ();
23467 case DW_OP_bit_piece
:
23468 return valx1
->v
.val_int
== valy1
->v
.val_int
23469 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23472 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23473 case DW_OP_GNU_addr_index
:
23474 case DW_OP_GNU_const_index
:
23476 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23477 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23478 return rtx_equal_p (ax1
, ay1
);
23480 case DW_OP_GNU_implicit_pointer
:
23481 return valx1
->val_class
== dw_val_class_die_ref
23482 && valx1
->val_class
== valy1
->val_class
23483 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23484 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23485 case DW_OP_GNU_entry_value
:
23486 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23487 case DW_OP_GNU_const_type
:
23488 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23489 || valx2
->val_class
!= valy2
->val_class
)
23491 switch (valx2
->val_class
)
23493 case dw_val_class_const
:
23494 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23495 case dw_val_class_vec
:
23496 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23497 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23498 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23499 valx2
->v
.val_vec
.elt_size
23500 * valx2
->v
.val_vec
.length
) == 0;
23501 case dw_val_class_const_double
:
23502 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23503 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23505 gcc_unreachable ();
23507 case DW_OP_GNU_regval_type
:
23508 case DW_OP_GNU_deref_type
:
23509 return valx1
->v
.val_int
== valy1
->v
.val_int
23510 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23511 case DW_OP_GNU_convert
:
23512 case DW_OP_GNU_reinterpret
:
23513 if (valx1
->val_class
!= valy1
->val_class
)
23515 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23516 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23517 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23518 case DW_OP_GNU_parameter_ref
:
23519 return valx1
->val_class
== dw_val_class_die_ref
23520 && valx1
->val_class
== valy1
->val_class
23521 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23523 /* Other codes have no operands. */
23528 /* Return true if DWARF location expressions X and Y are the same. */
23531 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23533 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23534 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23535 || x
->dtprel
!= y
->dtprel
23536 || !compare_loc_operands (x
, y
))
23538 return x
== NULL
&& y
== NULL
;
23541 /* Return precomputed hash of location list X. */
23544 loc_list_hash (const void *x
)
23546 return ((const struct dw_loc_list_struct
*) x
)->hash
;
23549 /* Return 1 if location lists X and Y are the same. */
23552 loc_list_eq (const void *x
, const void *y
)
23554 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
23555 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
23558 if (a
->hash
!= b
->hash
)
23560 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23561 if (strcmp (a
->begin
, b
->begin
) != 0
23562 || strcmp (a
->end
, b
->end
) != 0
23563 || (a
->section
== NULL
) != (b
->section
== NULL
)
23564 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23565 || !compare_locs (a
->expr
, b
->expr
))
23567 return a
== NULL
&& b
== NULL
;
23570 /* Recursively optimize location lists referenced from DIE
23571 children and share them whenever possible. */
23574 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
23581 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23582 if (AT_class (a
) == dw_val_class_loc_list
)
23584 dw_loc_list_ref list
= AT_loc_list (a
);
23585 /* TODO: perform some optimizations here, before hashing
23586 it and storing into the hash table. */
23587 hash_loc_list (list
);
23588 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
23591 *slot
= (void *) list
;
23593 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
23596 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23600 /* Recursively assign each location list a unique index into the debug_addr
23604 index_location_lists (dw_die_ref die
)
23610 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23611 if (AT_class (a
) == dw_val_class_loc_list
)
23613 dw_loc_list_ref list
= AT_loc_list (a
);
23614 dw_loc_list_ref curr
;
23615 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23617 /* Don't index an entry that has already been indexed
23618 or won't be output. */
23619 if (curr
->begin_entry
!= NULL
23620 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23624 = add_addr_table_entry (xstrdup (curr
->begin
),
23629 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23632 /* Optimize location lists referenced from DIE
23633 children and share them whenever possible. */
23636 optimize_location_lists (dw_die_ref die
)
23638 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
23639 optimize_location_lists_1 (die
, htab
);
23640 htab_delete (htab
);
23643 /* Output stuff that dwarf requires at the end of every file,
23644 and generate the DWARF-2 debugging info. */
23647 dwarf2out_finish (const char *filename
)
23649 limbo_die_node
*node
, *next_node
;
23650 comdat_type_node
*ctnode
;
23651 htab_t comdat_type_table
;
23653 dw_die_ref main_comp_unit_die
;
23655 /* PCH might result in DW_AT_producer string being restored from the
23656 header compilation, so always fill it with empty string initially
23657 and overwrite only here. */
23658 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23659 producer_string
= gen_producer_string ();
23660 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23661 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23663 gen_scheduled_generic_parms_dies ();
23664 gen_remaining_tmpl_value_param_die_attribute ();
23666 /* Add the name for the main input file now. We delayed this from
23667 dwarf2out_init to avoid complications with PCH. */
23668 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23669 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23670 add_comp_dir_attribute (comp_unit_die ());
23671 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23674 htab_traverse (file_table
, file_table_relative_p
, &p
);
23676 add_comp_dir_attribute (comp_unit_die ());
23679 if (deferred_locations_list
)
23680 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23682 add_location_or_const_value_attribute (
23683 (*deferred_locations_list
)[i
].die
,
23684 (*deferred_locations_list
)[i
].variable
,
23689 /* Traverse the limbo die list, and add parent/child links. The only
23690 dies without parents that should be here are concrete instances of
23691 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23692 For concrete instances, we can get the parent die from the abstract
23694 for (node
= limbo_die_list
; node
; node
= next_node
)
23696 dw_die_ref die
= node
->die
;
23697 next_node
= node
->next
;
23699 if (die
->die_parent
== NULL
)
23701 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23703 if (origin
&& origin
->die_parent
)
23704 add_child_die (origin
->die_parent
, die
);
23705 else if (is_cu_die (die
))
23707 else if (seen_error ())
23708 /* It's OK to be confused by errors in the input. */
23709 add_child_die (comp_unit_die (), die
);
23712 /* In certain situations, the lexical block containing a
23713 nested function can be optimized away, which results
23714 in the nested function die being orphaned. Likewise
23715 with the return type of that nested function. Force
23716 this to be a child of the containing function.
23718 It may happen that even the containing function got fully
23719 inlined and optimized out. In that case we are lost and
23720 assign the empty child. This should not be big issue as
23721 the function is likely unreachable too. */
23722 gcc_assert (node
->created_for
);
23724 if (DECL_P (node
->created_for
))
23725 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23726 else if (TYPE_P (node
->created_for
))
23727 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23729 origin
= comp_unit_die ();
23731 add_child_die (origin
, die
);
23736 limbo_die_list
= NULL
;
23738 #if ENABLE_ASSERT_CHECKING
23740 dw_die_ref die
= comp_unit_die (), c
;
23741 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23744 resolve_addr (comp_unit_die ());
23745 move_marked_base_types ();
23747 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23749 tree decl
= node
->created_for
;
23750 /* When generating LTO bytecode we can not generate new assembler
23751 names at this point and all important decls got theirs via
23753 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23754 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23756 add_linkage_attr (node
->die
, decl
);
23757 move_linkage_attr (node
->die
);
23761 deferred_asm_name
= NULL
;
23763 /* Walk through the list of incomplete types again, trying once more to
23764 emit full debugging info for them. */
23765 retry_incomplete_types ();
23767 if (flag_eliminate_unused_debug_types
)
23768 prune_unused_types ();
23770 /* Generate separate COMDAT sections for type DIEs. */
23771 if (use_debug_types
)
23773 break_out_comdat_types (comp_unit_die ());
23775 /* Each new type_unit DIE was added to the limbo die list when created.
23776 Since these have all been added to comdat_type_list, clear the
23778 limbo_die_list
= NULL
;
23780 /* For each new comdat type unit, copy declarations for incomplete
23781 types to make the new unit self-contained (i.e., no direct
23782 references to the main compile unit). */
23783 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23784 copy_decls_for_unworthy_types (ctnode
->root_die
);
23785 copy_decls_for_unworthy_types (comp_unit_die ());
23787 /* In the process of copying declarations from one unit to another,
23788 we may have left some declarations behind that are no longer
23789 referenced. Prune them. */
23790 prune_unused_types ();
23793 /* Generate separate CUs for each of the include files we've seen.
23794 They will go into limbo_die_list. */
23795 if (flag_eliminate_dwarf2_dups
)
23796 break_out_includes (comp_unit_die ());
23798 /* Traverse the DIE's and add add sibling attributes to those DIE's
23799 that have children. */
23800 add_sibling_attributes (comp_unit_die ());
23801 for (node
= limbo_die_list
; node
; node
= node
->next
)
23802 add_sibling_attributes (node
->die
);
23803 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23804 add_sibling_attributes (ctnode
->root_die
);
23806 /* When splitting DWARF info, we put some attributes in the
23807 skeleton compile_unit DIE that remains in the .o, while
23808 most attributes go in the DWO compile_unit_die. */
23809 if (dwarf_split_debug_info
)
23810 main_comp_unit_die
= gen_compile_unit_die (NULL
);
23812 main_comp_unit_die
= comp_unit_die ();
23814 /* Output a terminator label for the .text section. */
23815 switch_to_section (text_section
);
23816 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23817 if (cold_text_section
)
23819 switch_to_section (cold_text_section
);
23820 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23823 /* We can only use the low/high_pc attributes if all of the code was
23825 if (!have_multiple_function_sections
23826 || (dwarf_version
< 3 && dwarf_strict
))
23828 /* Don't add if the CU has no associated code. */
23829 if (text_section_used
)
23830 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
23831 text_end_label
, true);
23837 bool range_list_added
= false;
23839 if (text_section_used
)
23840 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
23841 text_end_label
, &range_list_added
, true);
23842 if (cold_text_section_used
)
23843 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
23844 cold_end_label
, &range_list_added
, true);
23846 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
23848 if (DECL_IGNORED_P (fde
->decl
))
23850 if (!fde
->in_std_section
)
23851 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
23852 fde
->dw_fde_end
, &range_list_added
,
23854 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23855 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
23856 fde
->dw_fde_second_end
, &range_list_added
,
23860 if (range_list_added
)
23862 /* We need to give .debug_loc and .debug_ranges an appropriate
23863 "base address". Use zero so that these addresses become
23864 absolute. Historically, we've emitted the unexpected
23865 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23866 Emit both to give time for other tools to adapt. */
23867 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
23868 if (! dwarf_strict
&& dwarf_version
< 4)
23869 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
23875 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
23876 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
23877 debug_line_section_label
);
23880 add_AT_macptr (comp_unit_die (),
23881 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
23882 macinfo_section_label
);
23884 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
23886 /* optimize_location_lists calculates the size of the lists,
23887 so index them first, and assign indices to the entries.
23888 Although optimize_location_lists will remove entries from
23889 the table, it only does so for duplicates, and therefore
23890 only reduces ref_counts to 1. */
23891 unsigned int index
= 0;
23892 index_location_lists (comp_unit_die ());
23893 htab_traverse_noresize (addr_index_table
,
23894 index_addr_table_entry
, &index
);
23896 if (have_location_lists
)
23897 optimize_location_lists (comp_unit_die ());
23899 save_macinfo_strings ();
23901 if (dwarf_split_debug_info
)
23903 unsigned int index
= 0;
23905 /* Add attributes common to skeleton compile_units and
23906 type_units. Because these attributes include strings, it
23907 must be done before freezing the string table. Top-level
23908 skeleton die attrs are added when the skeleton type unit is
23909 created, so ensure it is created by this point. */
23910 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
23911 (void) get_skeleton_type_unit ();
23912 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
23915 /* Output all of the compilation units. We put the main one last so that
23916 the offsets are available to output_pubnames. */
23917 for (node
= limbo_die_list
; node
; node
= node
->next
)
23918 output_comp_unit (node
->die
, 0);
23920 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
23921 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23923 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
23925 /* Don't output duplicate types. */
23926 if (*slot
!= HTAB_EMPTY_ENTRY
)
23929 /* Add a pointer to the line table for the main compilation unit
23930 so that the debugger can make sense of DW_AT_decl_file
23932 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
23933 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23934 (!dwarf_split_debug_info
23935 ? debug_line_section_label
23936 : debug_skeleton_line_section_label
));
23938 output_comdat_type_unit (ctnode
);
23941 htab_delete (comdat_type_table
);
23943 /* The AT_pubnames attribute needs to go in all skeleton dies, including
23944 both the main_cu and all skeleton TUs. Making this call unconditional
23945 would end up either adding a second copy of the AT_pubnames attribute, or
23946 requiring a special case in add_top_level_skeleton_die_attrs. */
23947 if (!dwarf_split_debug_info
)
23948 add_AT_pubnames (comp_unit_die ());
23950 if (dwarf_split_debug_info
)
23953 unsigned char checksum
[16];
23954 struct md5_ctx ctx
;
23956 /* Compute a checksum of the comp_unit to use as the dwo_id. */
23957 md5_init_ctx (&ctx
);
23959 die_checksum (comp_unit_die (), &ctx
, &mark
);
23960 unmark_all_dies (comp_unit_die ());
23961 md5_finish_ctx (&ctx
, checksum
);
23963 /* Use the first 8 bytes of the checksum as the dwo_id,
23964 and add it to both comp-unit DIEs. */
23965 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
23966 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
23968 /* Add the base offset of the ranges table to the skeleton
23970 if (ranges_table_in_use
)
23971 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
23972 ranges_section_label
);
23974 switch_to_section (debug_addr_section
);
23975 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
23976 output_addr_table ();
23979 /* Output the main compilation unit if non-empty or if .debug_macinfo
23980 or .debug_macro will be emitted. */
23981 output_comp_unit (comp_unit_die (), have_macinfo
);
23983 if (dwarf_split_debug_info
&& info_section_emitted
)
23984 output_skeleton_debug_sections (main_comp_unit_die
);
23986 /* Output the abbreviation table. */
23987 if (abbrev_die_table_in_use
!= 1)
23989 switch_to_section (debug_abbrev_section
);
23990 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
23991 output_abbrev_section ();
23994 /* Output location list section if necessary. */
23995 if (have_location_lists
)
23997 /* Output the location lists info. */
23998 switch_to_section (debug_loc_section
);
23999 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
24000 output_location_lists (comp_unit_die ());
24003 output_pubtables ();
24005 /* Output the address range information if a CU (.debug_info section)
24006 was emitted. We output an empty table even if we had no functions
24007 to put in it. This because the consumer has no way to tell the
24008 difference between an empty table that we omitted and failure to
24009 generate a table that would have contained data. */
24010 if (info_section_emitted
)
24012 unsigned long aranges_length
= size_of_aranges ();
24014 switch_to_section (debug_aranges_section
);
24015 output_aranges (aranges_length
);
24018 /* Output ranges section if necessary. */
24019 if (ranges_table_in_use
)
24021 switch_to_section (debug_ranges_section
);
24022 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24026 /* Have to end the macro section. */
24029 switch_to_section (debug_macinfo_section
);
24030 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24032 dw2_asm_output_data (1, 0, "End compilation unit");
24035 /* Output the source line correspondence table. We must do this
24036 even if there is no line information. Otherwise, on an empty
24037 translation unit, we will generate a present, but empty,
24038 .debug_info section. IRIX 6.5 `nm' will then complain when
24039 examining the file. This is done late so that any filenames
24040 used by the debug_info section are marked as 'used'. */
24041 switch_to_section (debug_line_section
);
24042 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24043 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24044 output_line_info (false);
24046 if (dwarf_split_debug_info
&& info_section_emitted
)
24048 switch_to_section (debug_skeleton_line_section
);
24049 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24050 output_line_info (true);
24053 /* If we emitted any indirect strings, output the string table too. */
24054 if (debug_str_hash
|| skeleton_debug_str_hash
)
24055 output_indirect_strings ();
24058 #include "gt-dwarf2out.h"