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"
87 #include "hash-table.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 (type_decl
!= NULL
)
372 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
373 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
375 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
376 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
379 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
382 /* Return a pointer to a copy of the section string name S with all
383 attributes stripped off, and an asterisk prepended (for assemble_name). */
386 stripattributes (const char *s
)
388 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
393 while (*s
&& *s
!= ',')
400 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
401 switch to the data section instead, and write out a synthetic start label
402 for collect2 the first time around. */
405 switch_to_eh_frame_section (bool back
)
409 #ifdef EH_FRAME_SECTION_NAME
410 if (eh_frame_section
== 0)
414 if (EH_TABLES_CAN_BE_READ_ONLY
)
420 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
422 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
424 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
427 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
428 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
429 && (per_encoding
& 0x70) != DW_EH_PE_absptr
430 && (per_encoding
& 0x70) != DW_EH_PE_aligned
431 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
432 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
433 ? 0 : SECTION_WRITE
);
436 flags
= SECTION_WRITE
;
437 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
439 #endif /* EH_FRAME_SECTION_NAME */
441 if (eh_frame_section
)
442 switch_to_section (eh_frame_section
);
445 /* We have no special eh_frame section. Put the information in
446 the data section and emit special labels to guide collect2. */
447 switch_to_section (data_section
);
451 label
= get_file_function_name ("F");
452 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
453 targetm
.asm_out
.globalize_label (asm_out_file
,
454 IDENTIFIER_POINTER (label
));
455 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
460 /* Switch [BACK] to the eh or debug frame table section, depending on
464 switch_to_frame_table_section (int for_eh
, bool back
)
467 switch_to_eh_frame_section (back
);
470 if (!debug_frame_section
)
471 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
472 SECTION_DEBUG
, NULL
);
473 switch_to_section (debug_frame_section
);
477 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
479 enum dw_cfi_oprnd_type
480 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
485 case DW_CFA_GNU_window_save
:
486 case DW_CFA_remember_state
:
487 case DW_CFA_restore_state
:
488 return dw_cfi_oprnd_unused
;
491 case DW_CFA_advance_loc1
:
492 case DW_CFA_advance_loc2
:
493 case DW_CFA_advance_loc4
:
494 case DW_CFA_MIPS_advance_loc8
:
495 return dw_cfi_oprnd_addr
;
498 case DW_CFA_offset_extended
:
500 case DW_CFA_offset_extended_sf
:
501 case DW_CFA_def_cfa_sf
:
503 case DW_CFA_restore_extended
:
504 case DW_CFA_undefined
:
505 case DW_CFA_same_value
:
506 case DW_CFA_def_cfa_register
:
507 case DW_CFA_register
:
508 case DW_CFA_expression
:
509 return dw_cfi_oprnd_reg_num
;
511 case DW_CFA_def_cfa_offset
:
512 case DW_CFA_GNU_args_size
:
513 case DW_CFA_def_cfa_offset_sf
:
514 return dw_cfi_oprnd_offset
;
516 case DW_CFA_def_cfa_expression
:
517 return dw_cfi_oprnd_loc
;
524 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
526 enum dw_cfi_oprnd_type
527 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
532 case DW_CFA_def_cfa_sf
:
534 case DW_CFA_offset_extended_sf
:
535 case DW_CFA_offset_extended
:
536 return dw_cfi_oprnd_offset
;
538 case DW_CFA_register
:
539 return dw_cfi_oprnd_reg_num
;
541 case DW_CFA_expression
:
542 return dw_cfi_oprnd_loc
;
545 return dw_cfi_oprnd_unused
;
549 /* Output one FDE. */
552 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
553 char *section_start_label
, int fde_encoding
, char *augmentation
,
554 bool any_lsda_needed
, int lsda_encoding
)
556 const char *begin
, *end
;
557 static unsigned int j
;
560 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
562 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
564 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
565 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
566 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
567 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
568 " indicating 64-bit DWARF extension");
569 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
571 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
574 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
576 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
577 debug_frame_section
, "FDE CIE offset");
579 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
580 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
584 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
585 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
586 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
587 "FDE initial location");
588 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
589 end
, begin
, "FDE address range");
593 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
594 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
601 int size
= size_of_encoded_value (lsda_encoding
);
603 if (lsda_encoding
== DW_EH_PE_aligned
)
605 int offset
= ( 4 /* Length */
607 + 2 * size_of_encoded_value (fde_encoding
)
608 + 1 /* Augmentation size */ );
609 int pad
= -offset
& (PTR_SIZE
- 1);
612 gcc_assert (size_of_uleb128 (size
) == 1);
615 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
617 if (fde
->uses_eh_lsda
)
619 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
620 fde
->funcdef_number
);
621 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
622 gen_rtx_SYMBOL_REF (Pmode
, l1
),
624 "Language Specific Data Area");
628 if (lsda_encoding
== DW_EH_PE_aligned
)
629 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
630 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
631 "Language Specific Data Area (none)");
635 dw2_asm_output_data_uleb128 (0, "Augmentation size");
638 /* Loop through the Call Frame Instructions associated with this FDE. */
639 fde
->dw_fde_current_label
= begin
;
641 size_t from
, until
, i
;
644 until
= vec_safe_length (fde
->dw_fde_cfi
);
646 if (fde
->dw_fde_second_begin
== NULL
)
649 until
= fde
->dw_fde_switch_cfi_index
;
651 from
= fde
->dw_fde_switch_cfi_index
;
653 for (i
= from
; i
< until
; i
++)
654 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
657 /* If we are to emit a ref/link from function bodies to their frame tables,
658 do it now. This is typically performed to make sure that tables
659 associated with functions are dragged with them and not discarded in
660 garbage collecting links. We need to do this on a per function basis to
661 cope with -ffunction-sections. */
663 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
664 /* Switch to the function section, emit the ref to the tables, and
665 switch *back* into the table section. */
666 switch_to_section (function_section (fde
->decl
));
667 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
668 switch_to_frame_table_section (for_eh
, true);
671 /* Pad the FDE out to an address sized boundary. */
672 ASM_OUTPUT_ALIGN (asm_out_file
,
673 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
674 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
679 /* Return true if frame description entry FDE is needed for EH. */
682 fde_needed_for_eh_p (dw_fde_ref fde
)
684 if (flag_asynchronous_unwind_tables
)
687 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
690 if (fde
->uses_eh_lsda
)
693 /* If exceptions are enabled, we have collected nothrow info. */
694 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
700 /* Output the call frame information used to record information
701 that relates to calculating the frame pointer, and records the
702 location of saved registers. */
705 output_call_frame_info (int for_eh
)
710 char l1
[20], l2
[20], section_start_label
[20];
711 bool any_lsda_needed
= false;
712 char augmentation
[6];
713 int augmentation_size
;
714 int fde_encoding
= DW_EH_PE_absptr
;
715 int per_encoding
= DW_EH_PE_absptr
;
716 int lsda_encoding
= DW_EH_PE_absptr
;
718 rtx personality
= NULL
;
721 /* Don't emit a CIE if there won't be any FDEs. */
725 /* Nothing to do if the assembler's doing it all. */
726 if (dwarf2out_do_cfi_asm ())
729 /* If we don't have any functions we'll want to unwind out of, don't emit
730 any EH unwind information. If we make FDEs linkonce, we may have to
731 emit an empty label for an FDE that wouldn't otherwise be emitted. We
732 want to avoid having an FDE kept around when the function it refers to
733 is discarded. Example where this matters: a primary function template
734 in C++ requires EH information, an explicit specialization doesn't. */
737 bool any_eh_needed
= false;
739 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
741 if (fde
->uses_eh_lsda
)
742 any_eh_needed
= any_lsda_needed
= true;
743 else if (fde_needed_for_eh_p (fde
))
744 any_eh_needed
= true;
745 else if (TARGET_USES_WEAK_UNWIND_INFO
)
746 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
753 /* We're going to be generating comments, so turn on app. */
757 /* Switch to the proper frame section, first time. */
758 switch_to_frame_table_section (for_eh
, false);
760 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
761 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
763 /* Output the CIE. */
764 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
765 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
766 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
767 dw2_asm_output_data (4, 0xffffffff,
768 "Initial length escape value indicating 64-bit DWARF extension");
769 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
770 "Length of Common Information Entry");
771 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
773 /* Now that the CIE pointer is PC-relative for EH,
774 use 0 to identify the CIE. */
775 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
776 (for_eh
? 0 : DWARF_CIE_ID
),
777 "CIE Identifier Tag");
779 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
780 use CIE version 1, unless that would produce incorrect results
781 due to overflowing the return register column. */
782 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
784 if (return_reg
>= 256 || dwarf_version
> 2)
786 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
789 augmentation_size
= 0;
791 personality
= current_unit_personality
;
797 z Indicates that a uleb128 is present to size the
798 augmentation section.
799 L Indicates the encoding (and thus presence) of
800 an LSDA pointer in the FDE augmentation.
801 R Indicates a non-default pointer encoding for
803 P Indicates the presence of an encoding + language
804 personality routine in the CIE augmentation. */
806 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
807 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
808 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
810 p
= augmentation
+ 1;
814 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
815 assemble_external_libcall (personality
);
820 augmentation_size
+= 1;
822 if (fde_encoding
!= DW_EH_PE_absptr
)
825 augmentation_size
+= 1;
827 if (p
> augmentation
+ 1)
829 augmentation
[0] = 'z';
833 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
834 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
836 int offset
= ( 4 /* Length */
838 + 1 /* CIE version */
839 + strlen (augmentation
) + 1 /* Augmentation */
840 + size_of_uleb128 (1) /* Code alignment */
841 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
843 + 1 /* Augmentation size */
844 + 1 /* Personality encoding */ );
845 int pad
= -offset
& (PTR_SIZE
- 1);
847 augmentation_size
+= pad
;
849 /* Augmentations should be small, so there's scarce need to
850 iterate for a solution. Die if we exceed one uleb128 byte. */
851 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
855 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
856 if (dw_cie_version
>= 4)
858 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
859 dw2_asm_output_data (1, 0, "CIE Segment Size");
861 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
862 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
863 "CIE Data Alignment Factor");
865 if (dw_cie_version
== 1)
866 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
868 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
872 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
875 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
876 eh_data_format_name (per_encoding
));
877 dw2_asm_output_encoded_addr_rtx (per_encoding
,
883 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
884 eh_data_format_name (lsda_encoding
));
886 if (fde_encoding
!= DW_EH_PE_absptr
)
887 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
888 eh_data_format_name (fde_encoding
));
891 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
892 output_cfi (cfi
, NULL
, for_eh
);
894 /* Pad the CIE out to an address sized boundary. */
895 ASM_OUTPUT_ALIGN (asm_out_file
,
896 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
897 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
899 /* Loop through all of the FDE's. */
900 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
904 /* Don't emit EH unwind info for leaf functions that don't need it. */
905 if (for_eh
&& !fde_needed_for_eh_p (fde
))
908 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
909 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
910 augmentation
, any_lsda_needed
, lsda_encoding
);
913 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
914 dw2_asm_output_data (4, 0, "End of Table");
916 /* Turn off app to make assembly quicker. */
921 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
924 dwarf2out_do_cfi_startproc (bool second
)
928 rtx personality
= get_personality_function (current_function_decl
);
930 fprintf (asm_out_file
, "\t.cfi_startproc\n");
934 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
937 /* ??? The GAS support isn't entirely consistent. We have to
938 handle indirect support ourselves, but PC-relative is done
939 in the assembler. Further, the assembler can't handle any
940 of the weirder relocation types. */
941 if (enc
& DW_EH_PE_indirect
)
942 ref
= dw2_force_const_mem (ref
, true);
944 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
945 output_addr_const (asm_out_file
, ref
);
946 fputc ('\n', asm_out_file
);
949 if (crtl
->uses_eh_lsda
)
953 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
954 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
955 current_function_funcdef_no
);
956 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
957 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
959 if (enc
& DW_EH_PE_indirect
)
960 ref
= dw2_force_const_mem (ref
, true);
962 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
963 output_addr_const (asm_out_file
, ref
);
964 fputc ('\n', asm_out_file
);
968 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
969 this allocation may be done before pass_final. */
972 dwarf2out_alloc_current_fde (void)
976 fde
= ggc_alloc_cleared_dw_fde_node ();
977 fde
->decl
= current_function_decl
;
978 fde
->funcdef_number
= current_function_funcdef_no
;
979 fde
->fde_index
= vec_safe_length (fde_vec
);
980 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
981 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
982 fde
->nothrow
= crtl
->nothrow
;
983 fde
->drap_reg
= INVALID_REGNUM
;
984 fde
->vdrap_reg
= INVALID_REGNUM
;
986 /* Record the FDE associated with this function. */
988 vec_safe_push (fde_vec
, fde
);
993 /* Output a marker (i.e. a label) for the beginning of a function, before
997 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
998 const char *file ATTRIBUTE_UNUSED
)
1000 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1006 current_function_func_begin_label
= NULL
;
1008 do_frame
= dwarf2out_do_frame ();
1010 /* ??? current_function_func_begin_label is also used by except.c for
1011 call-site information. We must emit this label if it might be used. */
1013 && (!flag_exceptions
1014 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1017 fnsec
= function_section (current_function_decl
);
1018 switch_to_section (fnsec
);
1019 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1020 current_function_funcdef_no
);
1021 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1022 current_function_funcdef_no
);
1023 dup_label
= xstrdup (label
);
1024 current_function_func_begin_label
= dup_label
;
1026 /* We can elide the fde allocation if we're not emitting debug info. */
1030 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1031 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1032 would include pass_dwarf2_frame. If we've not created the FDE yet,
1036 fde
= dwarf2out_alloc_current_fde ();
1038 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1039 fde
->dw_fde_begin
= dup_label
;
1040 fde
->dw_fde_current_label
= dup_label
;
1041 fde
->in_std_section
= (fnsec
== text_section
1042 || (cold_text_section
&& fnsec
== cold_text_section
));
1044 /* We only want to output line number information for the genuine dwarf2
1045 prologue case, not the eh frame case. */
1046 #ifdef DWARF2_DEBUGGING_INFO
1048 dwarf2out_source_line (line
, file
, 0, true);
1051 if (dwarf2out_do_cfi_asm ())
1052 dwarf2out_do_cfi_startproc (false);
1055 rtx personality
= get_personality_function (current_function_decl
);
1056 if (!current_unit_personality
)
1057 current_unit_personality
= personality
;
1059 /* We cannot keep a current personality per function as without CFI
1060 asm, at the point where we emit the CFI data, there is no current
1061 function anymore. */
1062 if (personality
&& current_unit_personality
!= personality
)
1063 sorry ("multiple EH personalities are supported only with assemblers "
1064 "supporting .cfi_personality directive");
1068 /* Output a marker (i.e. a label) for the end of the generated code
1069 for a function prologue. This gets called *after* the prologue code has
1073 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1074 const char *file ATTRIBUTE_UNUSED
)
1076 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1078 /* Output a label to mark the endpoint of the code generated for this
1080 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1081 current_function_funcdef_no
);
1082 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1083 current_function_funcdef_no
);
1084 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1087 /* Output a marker (i.e. a label) for the beginning of the generated code
1088 for a function epilogue. This gets called *before* the prologue code has
1092 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1093 const char *file ATTRIBUTE_UNUSED
)
1095 dw_fde_ref fde
= cfun
->fde
;
1096 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1098 if (fde
->dw_fde_vms_begin_epilogue
)
1101 /* Output a label to mark the endpoint of the code generated for this
1103 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1104 current_function_funcdef_no
);
1105 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1106 current_function_funcdef_no
);
1107 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1110 /* Output a marker (i.e. a label) for the absolute end of the generated code
1111 for a function definition. This gets called *after* the epilogue code has
1115 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1116 const char *file ATTRIBUTE_UNUSED
)
1119 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1121 last_var_location_insn
= NULL_RTX
;
1122 cached_next_real_insn
= NULL_RTX
;
1124 if (dwarf2out_do_cfi_asm ())
1125 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1127 /* Output a label to mark the endpoint of the code generated for this
1129 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1130 current_function_funcdef_no
);
1131 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1133 gcc_assert (fde
!= NULL
);
1134 if (fde
->dw_fde_second_begin
== NULL
)
1135 fde
->dw_fde_end
= xstrdup (label
);
1139 dwarf2out_frame_finish (void)
1141 /* Output call frame information. */
1142 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1143 output_call_frame_info (0);
1145 /* Output another copy for the unwinder. */
1146 if ((flag_unwind_tables
|| flag_exceptions
)
1147 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1148 output_call_frame_info (1);
1151 /* Note that the current function section is being used for code. */
1154 dwarf2out_note_section_used (void)
1156 section
*sec
= current_function_section ();
1157 if (sec
== text_section
)
1158 text_section_used
= true;
1159 else if (sec
== cold_text_section
)
1160 cold_text_section_used
= true;
1163 static void var_location_switch_text_section (void);
1164 static void set_cur_line_info_table (section
*);
1167 dwarf2out_switch_text_section (void)
1170 dw_fde_ref fde
= cfun
->fde
;
1172 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1174 if (!in_cold_section_p
)
1176 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1177 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1178 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1182 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1183 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1184 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1186 have_multiple_function_sections
= true;
1188 /* There is no need to mark used sections when not debugging. */
1189 if (cold_text_section
!= NULL
)
1190 dwarf2out_note_section_used ();
1192 if (dwarf2out_do_cfi_asm ())
1193 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1195 /* Now do the real section switch. */
1196 sect
= current_function_section ();
1197 switch_to_section (sect
);
1199 fde
->second_in_std_section
1200 = (sect
== text_section
1201 || (cold_text_section
&& sect
== cold_text_section
));
1203 if (dwarf2out_do_cfi_asm ())
1204 dwarf2out_do_cfi_startproc (true);
1206 var_location_switch_text_section ();
1208 if (cold_text_section
!= NULL
)
1209 set_cur_line_info_table (sect
);
1212 /* And now, the subset of the debugging information support code necessary
1213 for emitting location expressions. */
1215 /* Data about a single source file. */
1216 struct GTY(()) dwarf_file_data
{
1217 const char * filename
;
1221 typedef struct GTY(()) deferred_locations_struct
1225 } deferred_locations
;
1228 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1231 /* Describe an entry into the .debug_addr section. */
1235 ate_kind_rtx_dtprel
,
1239 typedef struct GTY(()) addr_table_entry_struct
{
1241 unsigned int refcount
;
1243 union addr_table_entry_struct_union
1245 rtx
GTY ((tag ("0"))) rtl
;
1246 char * GTY ((tag ("1"))) label
;
1248 GTY ((desc ("%1.kind"))) addr
;
1252 /* Location lists are ranges + location descriptions for that range,
1253 so you can track variables that are in different places over
1254 their entire life. */
1255 typedef struct GTY(()) dw_loc_list_struct
{
1256 dw_loc_list_ref dw_loc_next
;
1257 const char *begin
; /* Label and addr_entry for start of range */
1258 addr_table_entry
*begin_entry
;
1259 const char *end
; /* Label for end of range */
1260 char *ll_symbol
; /* Label for beginning of location list.
1261 Only on head of list */
1262 const char *section
; /* Section this loclist is relative to */
1263 dw_loc_descr_ref expr
;
1265 /* True if all addresses in this and subsequent lists are known to be
1268 /* True if this list has been replaced by dw_loc_next. */
1271 /* True if the range should be emitted even if begin and end
1276 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1278 /* Convert a DWARF stack opcode into its string name. */
1281 dwarf_stack_op_name (unsigned int op
)
1283 const char *name
= get_DW_OP_name (op
);
1288 return "OP_<unknown>";
1291 /* Return a pointer to a newly allocated location description. Location
1292 descriptions are simple expression terms that can be strung
1293 together to form more complicated location (address) descriptions. */
1295 static inline dw_loc_descr_ref
1296 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1297 unsigned HOST_WIDE_INT oprnd2
)
1299 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1301 descr
->dw_loc_opc
= op
;
1302 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1303 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1304 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1305 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1306 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1307 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1312 /* Return a pointer to a newly allocated location description for
1315 static inline dw_loc_descr_ref
1316 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1319 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1322 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1325 /* Add a location description term to a location description expression. */
1328 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1330 dw_loc_descr_ref
*d
;
1332 /* Find the end of the chain. */
1333 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1339 /* Compare two location operands for exact equality. */
1342 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1344 if (a
->val_class
!= b
->val_class
)
1346 switch (a
->val_class
)
1348 case dw_val_class_none
:
1350 case dw_val_class_addr
:
1351 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1353 case dw_val_class_offset
:
1354 case dw_val_class_unsigned_const
:
1355 case dw_val_class_const
:
1356 case dw_val_class_range_list
:
1357 case dw_val_class_lineptr
:
1358 case dw_val_class_macptr
:
1359 /* These are all HOST_WIDE_INT, signed or unsigned. */
1360 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1362 case dw_val_class_loc
:
1363 return a
->v
.val_loc
== b
->v
.val_loc
;
1364 case dw_val_class_loc_list
:
1365 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1366 case dw_val_class_die_ref
:
1367 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1368 case dw_val_class_fde_ref
:
1369 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1370 case dw_val_class_lbl_id
:
1371 case dw_val_class_high_pc
:
1372 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1373 case dw_val_class_str
:
1374 return a
->v
.val_str
== b
->v
.val_str
;
1375 case dw_val_class_flag
:
1376 return a
->v
.val_flag
== b
->v
.val_flag
;
1377 case dw_val_class_file
:
1378 return a
->v
.val_file
== b
->v
.val_file
;
1379 case dw_val_class_decl_ref
:
1380 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1382 case dw_val_class_const_double
:
1383 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1384 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1386 case dw_val_class_vec
:
1388 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1389 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1391 return (a_len
== b_len
1392 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1395 case dw_val_class_data8
:
1396 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1398 case dw_val_class_vms_delta
:
1399 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1400 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1405 /* Compare two location atoms for exact equality. */
1408 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1410 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1413 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1414 address size, but since we always allocate cleared storage it
1415 should be zero for other types of locations. */
1416 if (a
->dtprel
!= b
->dtprel
)
1419 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1420 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1423 /* Compare two complete location expressions for exact equality. */
1426 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1432 if (a
== NULL
|| b
== NULL
)
1434 if (!loc_descr_equal_p_1 (a
, b
))
1443 /* Add a constant OFFSET to a location expression. */
1446 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1448 dw_loc_descr_ref loc
;
1451 gcc_assert (*list_head
!= NULL
);
1456 /* Find the end of the chain. */
1457 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1461 if (loc
->dw_loc_opc
== DW_OP_fbreg
1462 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1463 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1464 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1465 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1467 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1468 offset. Don't optimize if an signed integer overflow would happen. */
1470 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1471 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1474 else if (offset
> 0)
1475 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1479 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1480 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1484 /* Add a constant OFFSET to a location list. */
1487 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1490 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1491 loc_descr_plus_const (&d
->expr
, offset
);
1494 #define DWARF_REF_SIZE \
1495 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1497 static unsigned long int get_base_type_offset (dw_die_ref
);
1499 /* Return the size of a location descriptor. */
1501 static unsigned long
1502 size_of_loc_descr (dw_loc_descr_ref loc
)
1504 unsigned long size
= 1;
1506 switch (loc
->dw_loc_opc
)
1509 size
+= DWARF2_ADDR_SIZE
;
1511 case DW_OP_GNU_addr_index
:
1512 case DW_OP_GNU_const_index
:
1513 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1514 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1533 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1536 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1541 case DW_OP_plus_uconst
:
1542 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1580 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1583 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1586 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1589 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1590 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1593 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1595 case DW_OP_bit_piece
:
1596 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1597 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1599 case DW_OP_deref_size
:
1600 case DW_OP_xderef_size
:
1609 case DW_OP_call_ref
:
1610 size
+= DWARF_REF_SIZE
;
1612 case DW_OP_implicit_value
:
1613 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1614 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1616 case DW_OP_GNU_implicit_pointer
:
1617 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1619 case DW_OP_GNU_entry_value
:
1621 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1622 size
+= size_of_uleb128 (op_size
) + op_size
;
1625 case DW_OP_GNU_const_type
:
1628 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1629 size
+= size_of_uleb128 (o
) + 1;
1630 switch (loc
->dw_loc_oprnd2
.val_class
)
1632 case dw_val_class_vec
:
1633 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1634 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1636 case dw_val_class_const
:
1637 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1639 case dw_val_class_const_double
:
1640 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1647 case DW_OP_GNU_regval_type
:
1650 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1651 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1652 + size_of_uleb128 (o
);
1655 case DW_OP_GNU_deref_type
:
1658 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1659 size
+= 1 + size_of_uleb128 (o
);
1662 case DW_OP_GNU_convert
:
1663 case DW_OP_GNU_reinterpret
:
1664 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1665 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1669 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1670 size
+= size_of_uleb128 (o
);
1673 case DW_OP_GNU_parameter_ref
:
1683 /* Return the size of a series of location descriptors. */
1686 size_of_locs (dw_loc_descr_ref loc
)
1691 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1692 field, to avoid writing to a PCH file. */
1693 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1695 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1697 size
+= size_of_loc_descr (l
);
1702 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1704 l
->dw_loc_addr
= size
;
1705 size
+= size_of_loc_descr (l
);
1711 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1712 static void get_ref_die_offset_label (char *, dw_die_ref
);
1713 static unsigned long int get_ref_die_offset (dw_die_ref
);
1715 /* Output location description stack opcode's operands (if any).
1716 The for_eh_or_skip parameter controls whether register numbers are
1717 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1718 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1719 info). This should be suppressed for the cases that have not been converted
1720 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1723 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1725 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1726 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1728 switch (loc
->dw_loc_opc
)
1730 #ifdef DWARF2_DEBUGGING_INFO
1733 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1738 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1739 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1741 fputc ('\n', asm_out_file
);
1746 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1751 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1752 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1754 fputc ('\n', asm_out_file
);
1759 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1760 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1767 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1768 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1770 dw2_asm_output_data (2, offset
, NULL
);
1773 case DW_OP_implicit_value
:
1774 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1775 switch (val2
->val_class
)
1777 case dw_val_class_const
:
1778 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1780 case dw_val_class_vec
:
1782 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1783 unsigned int len
= val2
->v
.val_vec
.length
;
1787 if (elt_size
> sizeof (HOST_WIDE_INT
))
1792 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1795 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1796 "fp or vector constant word %u", i
);
1799 case dw_val_class_const_double
:
1801 unsigned HOST_WIDE_INT first
, second
;
1803 if (WORDS_BIG_ENDIAN
)
1805 first
= val2
->v
.val_double
.high
;
1806 second
= val2
->v
.val_double
.low
;
1810 first
= val2
->v
.val_double
.low
;
1811 second
= val2
->v
.val_double
.high
;
1813 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1815 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1819 case dw_val_class_addr
:
1820 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1821 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1836 case DW_OP_implicit_value
:
1837 /* We currently don't make any attempt to make sure these are
1838 aligned properly like we do for the main unwind info, so
1839 don't support emitting things larger than a byte if we're
1840 only doing unwinding. */
1845 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1848 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1851 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1854 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1856 case DW_OP_plus_uconst
:
1857 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1891 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1895 unsigned r
= val1
->v
.val_unsigned
;
1896 if (for_eh_or_skip
>= 0)
1897 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1898 gcc_assert (size_of_uleb128 (r
)
1899 == size_of_uleb128 (val1
->v
.val_unsigned
));
1900 dw2_asm_output_data_uleb128 (r
, NULL
);
1904 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1908 unsigned r
= val1
->v
.val_unsigned
;
1909 if (for_eh_or_skip
>= 0)
1910 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1911 gcc_assert (size_of_uleb128 (r
)
1912 == size_of_uleb128 (val1
->v
.val_unsigned
));
1913 dw2_asm_output_data_uleb128 (r
, NULL
);
1914 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1918 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1920 case DW_OP_bit_piece
:
1921 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1922 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1924 case DW_OP_deref_size
:
1925 case DW_OP_xderef_size
:
1926 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1932 if (targetm
.asm_out
.output_dwarf_dtprel
)
1934 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1937 fputc ('\n', asm_out_file
);
1944 #ifdef DWARF2_DEBUGGING_INFO
1945 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1952 case DW_OP_GNU_addr_index
:
1953 case DW_OP_GNU_const_index
:
1954 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1955 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1956 "(index into .debug_addr)");
1959 case DW_OP_GNU_implicit_pointer
:
1961 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1962 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1963 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1964 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1965 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1966 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1970 case DW_OP_GNU_entry_value
:
1971 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1972 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1975 case DW_OP_GNU_const_type
:
1977 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1979 dw2_asm_output_data_uleb128 (o
, NULL
);
1980 switch (val2
->val_class
)
1982 case dw_val_class_const
:
1983 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1984 dw2_asm_output_data (1, l
, NULL
);
1985 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1987 case dw_val_class_vec
:
1989 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1990 unsigned int len
= val2
->v
.val_vec
.length
;
1995 dw2_asm_output_data (1, l
, NULL
);
1996 if (elt_size
> sizeof (HOST_WIDE_INT
))
2001 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2004 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2005 "fp or vector constant word %u", i
);
2008 case dw_val_class_const_double
:
2010 unsigned HOST_WIDE_INT first
, second
;
2011 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2013 dw2_asm_output_data (1, 2 * l
, NULL
);
2014 if (WORDS_BIG_ENDIAN
)
2016 first
= val2
->v
.val_double
.high
;
2017 second
= val2
->v
.val_double
.low
;
2021 first
= val2
->v
.val_double
.low
;
2022 second
= val2
->v
.val_double
.high
;
2024 dw2_asm_output_data (l
, first
, NULL
);
2025 dw2_asm_output_data (l
, second
, NULL
);
2033 case DW_OP_GNU_regval_type
:
2035 unsigned r
= val1
->v
.val_unsigned
;
2036 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2038 if (for_eh_or_skip
>= 0)
2040 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2041 gcc_assert (size_of_uleb128 (r
)
2042 == size_of_uleb128 (val1
->v
.val_unsigned
));
2044 dw2_asm_output_data_uleb128 (r
, NULL
);
2045 dw2_asm_output_data_uleb128 (o
, NULL
);
2048 case DW_OP_GNU_deref_type
:
2050 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2052 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2053 dw2_asm_output_data_uleb128 (o
, NULL
);
2056 case DW_OP_GNU_convert
:
2057 case DW_OP_GNU_reinterpret
:
2058 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2059 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2062 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2064 dw2_asm_output_data_uleb128 (o
, NULL
);
2068 case DW_OP_GNU_parameter_ref
:
2071 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2072 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2073 dw2_asm_output_data (4, o
, NULL
);
2078 /* Other codes have no operands. */
2083 /* Output a sequence of location operations.
2084 The for_eh_or_skip parameter controls whether register numbers are
2085 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2086 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2087 info). This should be suppressed for the cases that have not been converted
2088 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2091 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2093 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2095 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2096 /* Output the opcode. */
2097 if (for_eh_or_skip
>= 0
2098 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2100 unsigned r
= (opc
- DW_OP_breg0
);
2101 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2102 gcc_assert (r
<= 31);
2103 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2105 else if (for_eh_or_skip
>= 0
2106 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2108 unsigned r
= (opc
- DW_OP_reg0
);
2109 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2110 gcc_assert (r
<= 31);
2111 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2114 dw2_asm_output_data (1, opc
,
2115 "%s", dwarf_stack_op_name (opc
));
2117 /* Output the operand(s) (if any). */
2118 output_loc_operands (loc
, for_eh_or_skip
);
2122 /* Output location description stack opcode's operands (if any).
2123 The output is single bytes on a line, suitable for .cfi_escape. */
2126 output_loc_operands_raw (dw_loc_descr_ref loc
)
2128 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2129 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2131 switch (loc
->dw_loc_opc
)
2134 case DW_OP_GNU_addr_index
:
2135 case DW_OP_GNU_const_index
:
2136 case DW_OP_implicit_value
:
2137 /* We cannot output addresses in .cfi_escape, only bytes. */
2143 case DW_OP_deref_size
:
2144 case DW_OP_xderef_size
:
2145 fputc (',', asm_out_file
);
2146 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2151 fputc (',', asm_out_file
);
2152 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2157 fputc (',', asm_out_file
);
2158 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2163 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2164 fputc (',', asm_out_file
);
2165 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2173 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2174 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2176 fputc (',', asm_out_file
);
2177 dw2_asm_output_data_raw (2, offset
);
2183 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2184 gcc_assert (size_of_uleb128 (r
)
2185 == size_of_uleb128 (val1
->v
.val_unsigned
));
2186 fputc (',', asm_out_file
);
2187 dw2_asm_output_data_uleb128_raw (r
);
2192 case DW_OP_plus_uconst
:
2194 fputc (',', asm_out_file
);
2195 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2198 case DW_OP_bit_piece
:
2199 fputc (',', asm_out_file
);
2200 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2201 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2238 fputc (',', asm_out_file
);
2239 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2244 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2245 gcc_assert (size_of_uleb128 (r
)
2246 == size_of_uleb128 (val1
->v
.val_unsigned
));
2247 fputc (',', asm_out_file
);
2248 dw2_asm_output_data_uleb128_raw (r
);
2249 fputc (',', asm_out_file
);
2250 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2254 case DW_OP_GNU_implicit_pointer
:
2255 case DW_OP_GNU_entry_value
:
2256 case DW_OP_GNU_const_type
:
2257 case DW_OP_GNU_regval_type
:
2258 case DW_OP_GNU_deref_type
:
2259 case DW_OP_GNU_convert
:
2260 case DW_OP_GNU_reinterpret
:
2261 case DW_OP_GNU_parameter_ref
:
2266 /* Other codes have no operands. */
2272 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2276 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2277 /* Output the opcode. */
2278 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2280 unsigned r
= (opc
- DW_OP_breg0
);
2281 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2282 gcc_assert (r
<= 31);
2283 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2285 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2287 unsigned r
= (opc
- DW_OP_reg0
);
2288 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2289 gcc_assert (r
<= 31);
2290 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2292 /* Output the opcode. */
2293 fprintf (asm_out_file
, "%#x", opc
);
2294 output_loc_operands_raw (loc
);
2296 if (!loc
->dw_loc_next
)
2298 loc
= loc
->dw_loc_next
;
2300 fputc (',', asm_out_file
);
2304 /* This function builds a dwarf location descriptor sequence from a
2305 dw_cfa_location, adding the given OFFSET to the result of the
2308 struct dw_loc_descr_struct
*
2309 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2311 struct dw_loc_descr_struct
*head
, *tmp
;
2313 offset
+= cfa
->offset
;
2317 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2318 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2319 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2320 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2321 add_loc_descr (&head
, tmp
);
2324 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2325 add_loc_descr (&head
, tmp
);
2329 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2334 /* This function builds a dwarf location descriptor sequence for
2335 the address at OFFSET from the CFA when stack is aligned to
2338 struct dw_loc_descr_struct
*
2339 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2340 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2342 struct dw_loc_descr_struct
*head
;
2343 unsigned int dwarf_fp
2344 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2346 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2347 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2349 head
= new_reg_loc_descr (dwarf_fp
, 0);
2350 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2351 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2352 loc_descr_plus_const (&head
, offset
);
2355 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2359 /* And now, the support for symbolic debugging information. */
2361 /* .debug_str support. */
2362 static int output_indirect_string (void **, void *);
2364 static void dwarf2out_init (const char *);
2365 static void dwarf2out_finish (const char *);
2366 static void dwarf2out_assembly_start (void);
2367 static void dwarf2out_define (unsigned int, const char *);
2368 static void dwarf2out_undef (unsigned int, const char *);
2369 static void dwarf2out_start_source_file (unsigned, const char *);
2370 static void dwarf2out_end_source_file (unsigned);
2371 static void dwarf2out_function_decl (tree
);
2372 static void dwarf2out_begin_block (unsigned, unsigned);
2373 static void dwarf2out_end_block (unsigned, unsigned);
2374 static bool dwarf2out_ignore_block (const_tree
);
2375 static void dwarf2out_global_decl (tree
);
2376 static void dwarf2out_type_decl (tree
, int);
2377 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2378 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2380 static void dwarf2out_abstract_function (tree
);
2381 static void dwarf2out_var_location (rtx
);
2382 static void dwarf2out_begin_function (tree
);
2383 static void dwarf2out_end_function (unsigned int);
2384 static void dwarf2out_set_name (tree
, tree
);
2386 /* The debug hooks structure. */
2388 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2392 dwarf2out_assembly_start
,
2395 dwarf2out_start_source_file
,
2396 dwarf2out_end_source_file
,
2397 dwarf2out_begin_block
,
2398 dwarf2out_end_block
,
2399 dwarf2out_ignore_block
,
2400 dwarf2out_source_line
,
2401 dwarf2out_begin_prologue
,
2402 #if VMS_DEBUGGING_INFO
2403 dwarf2out_vms_end_prologue
,
2404 dwarf2out_vms_begin_epilogue
,
2406 debug_nothing_int_charstar
,
2407 debug_nothing_int_charstar
,
2409 dwarf2out_end_epilogue
,
2410 dwarf2out_begin_function
,
2411 dwarf2out_end_function
, /* end_function */
2412 dwarf2out_function_decl
, /* function_decl */
2413 dwarf2out_global_decl
,
2414 dwarf2out_type_decl
, /* type_decl */
2415 dwarf2out_imported_module_or_decl
,
2416 debug_nothing_tree
, /* deferred_inline_function */
2417 /* The DWARF 2 backend tries to reduce debugging bloat by not
2418 emitting the abstract description of inline functions until
2419 something tries to reference them. */
2420 dwarf2out_abstract_function
, /* outlining_inline_function */
2421 debug_nothing_rtx
, /* label */
2422 debug_nothing_int
, /* handle_pch */
2423 dwarf2out_var_location
,
2424 dwarf2out_switch_text_section
,
2426 1, /* start_end_main_source_file */
2427 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2430 /* NOTE: In the comments in this file, many references are made to
2431 "Debugging Information Entries". This term is abbreviated as `DIE'
2432 throughout the remainder of this file. */
2434 /* An internal representation of the DWARF output is built, and then
2435 walked to generate the DWARF debugging info. The walk of the internal
2436 representation is done after the entire program has been compiled.
2437 The types below are used to describe the internal representation. */
2439 /* Whether to put type DIEs into their own section .debug_types instead
2440 of making them part of the .debug_info section. Only supported for
2441 Dwarf V4 or higher and the user didn't disable them through
2442 -fno-debug-types-section. It is more efficient to put them in a
2443 separate comdat sections since the linker will then be able to
2444 remove duplicates. But not all tools support .debug_types sections
2447 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2449 /* Various DIE's use offsets relative to the beginning of the
2450 .debug_info section to refer to each other. */
2452 typedef long int dw_offset
;
2454 /* Define typedefs here to avoid circular dependencies. */
2456 typedef struct dw_attr_struct
*dw_attr_ref
;
2457 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2458 typedef struct pubname_struct
*pubname_ref
;
2459 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2460 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2461 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2463 /* The entries in the line_info table more-or-less mirror the opcodes
2464 that are used in the real dwarf line table. Arrays of these entries
2465 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2468 enum dw_line_info_opcode
{
2469 /* Emit DW_LNE_set_address; the operand is the label index. */
2472 /* Emit a row to the matrix with the given line. This may be done
2473 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2477 /* Emit a DW_LNS_set_file. */
2480 /* Emit a DW_LNS_set_column. */
2483 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2486 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2487 LI_set_prologue_end
,
2488 LI_set_epilogue_begin
,
2490 /* Emit a DW_LNE_set_discriminator. */
2491 LI_set_discriminator
2494 typedef struct GTY(()) dw_line_info_struct
{
2495 enum dw_line_info_opcode opcode
;
2497 } dw_line_info_entry
;
2500 typedef struct GTY(()) dw_line_info_table_struct
{
2501 /* The label that marks the end of this section. */
2502 const char *end_label
;
2504 /* The values for the last row of the matrix, as collected in the table.
2505 These are used to minimize the changes to the next row. */
2506 unsigned int file_num
;
2507 unsigned int line_num
;
2508 unsigned int column_num
;
2513 vec
<dw_line_info_entry
, va_gc
> *entries
;
2514 } dw_line_info_table
;
2516 typedef dw_line_info_table
*dw_line_info_table_p
;
2519 /* Each DIE attribute has a field specifying the attribute kind,
2520 a link to the next attribute in the chain, and an attribute value.
2521 Attributes are typically linked below the DIE they modify. */
2523 typedef struct GTY(()) dw_attr_struct
{
2524 enum dwarf_attribute dw_attr
;
2525 dw_val_node dw_attr_val
;
2530 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2531 The children of each node form a circular list linked by
2532 die_sib. die_child points to the node *before* the "first" child node. */
2534 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2535 union die_symbol_or_type_node
2537 const char * GTY ((tag ("0"))) die_symbol
;
2538 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2540 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2541 vec
<dw_attr_node
, va_gc
> *die_attr
;
2542 dw_die_ref die_parent
;
2543 dw_die_ref die_child
;
2545 dw_die_ref die_definition
; /* ref from a specification to its definition */
2546 dw_offset die_offset
;
2547 unsigned long die_abbrev
;
2549 unsigned int decl_id
;
2550 enum dwarf_tag die_tag
;
2551 /* Die is used and must not be pruned as unused. */
2552 BOOL_BITFIELD die_perennial_p
: 1;
2553 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2554 /* Lots of spare bits. */
2558 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2559 #define FOR_EACH_CHILD(die, c, expr) do { \
2560 c = die->die_child; \
2564 } while (c != die->die_child); \
2567 /* The pubname structure */
2569 typedef struct GTY(()) pubname_struct
{
2576 struct GTY(()) dw_ranges_struct
{
2577 /* If this is positive, it's a block number, otherwise it's a
2578 bitwise-negated index into dw_ranges_by_label. */
2582 /* A structure to hold a macinfo entry. */
2584 typedef struct GTY(()) macinfo_struct
{
2586 unsigned HOST_WIDE_INT lineno
;
2592 struct GTY(()) dw_ranges_by_label_struct
{
2597 /* The comdat type node structure. */
2598 typedef struct GTY(()) comdat_type_struct
2600 dw_die_ref root_die
;
2601 dw_die_ref type_die
;
2602 dw_die_ref skeleton_die
;
2603 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2604 struct comdat_type_struct
*next
;
2608 /* The limbo die list structure. */
2609 typedef struct GTY(()) limbo_die_struct
{
2612 struct limbo_die_struct
*next
;
2616 typedef struct skeleton_chain_struct
2620 struct skeleton_chain_struct
*parent
;
2622 skeleton_chain_node
;
2624 /* Define a macro which returns nonzero for a TYPE_DECL which was
2625 implicitly generated for a type.
2627 Note that, unlike the C front-end (which generates a NULL named
2628 TYPE_DECL node for each complete tagged type, each array type,
2629 and each function type node created) the C++ front-end generates
2630 a _named_ TYPE_DECL node for each tagged type node created.
2631 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2632 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2633 front-end, but for each type, tagged or not. */
2635 #define TYPE_DECL_IS_STUB(decl) \
2636 (DECL_NAME (decl) == NULL_TREE \
2637 || (DECL_ARTIFICIAL (decl) \
2638 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2639 /* This is necessary for stub decls that \
2640 appear in nested inline functions. */ \
2641 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2642 && (decl_ultimate_origin (decl) \
2643 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2645 /* Information concerning the compilation unit's programming
2646 language, and compiler version. */
2648 /* Fixed size portion of the DWARF compilation unit header. */
2649 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2650 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2652 /* Fixed size portion of the DWARF comdat type unit header. */
2653 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2654 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2655 + DWARF_OFFSET_SIZE)
2657 /* Fixed size portion of public names info. */
2658 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2660 /* Fixed size portion of the address range info. */
2661 #define DWARF_ARANGES_HEADER_SIZE \
2662 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2663 DWARF2_ADDR_SIZE * 2) \
2664 - DWARF_INITIAL_LENGTH_SIZE)
2666 /* Size of padding portion in the address range info. It must be
2667 aligned to twice the pointer size. */
2668 #define DWARF_ARANGES_PAD_SIZE \
2669 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2670 DWARF2_ADDR_SIZE * 2) \
2671 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2673 /* Use assembler line directives if available. */
2674 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2675 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2676 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2678 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2682 /* Minimum line offset in a special line info. opcode.
2683 This value was chosen to give a reasonable range of values. */
2684 #define DWARF_LINE_BASE -10
2686 /* First special line opcode - leave room for the standard opcodes. */
2687 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2689 /* Range of line offsets in a special line info. opcode. */
2690 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2692 /* Flag that indicates the initial value of the is_stmt_start flag.
2693 In the present implementation, we do not mark any lines as
2694 the beginning of a source statement, because that information
2695 is not made available by the GCC front-end. */
2696 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2698 /* Maximum number of operations per instruction bundle. */
2699 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2700 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2703 /* This location is used by calc_die_sizes() to keep track
2704 the offset of each DIE within the .debug_info section. */
2705 static unsigned long next_die_offset
;
2707 /* Record the root of the DIE's built for the current compilation unit. */
2708 static GTY(()) dw_die_ref single_comp_unit_die
;
2710 /* A list of type DIEs that have been separated into comdat sections. */
2711 static GTY(()) comdat_type_node
*comdat_type_list
;
2713 /* A list of DIEs with a NULL parent waiting to be relocated. */
2714 static GTY(()) limbo_die_node
*limbo_die_list
;
2716 /* A list of DIEs for which we may have to generate
2717 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2718 static GTY(()) limbo_die_node
*deferred_asm_name
;
2720 /* Filenames referenced by this compilation unit. */
2721 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2723 /* A hash table of references to DIE's that describe declarations.
2724 The key is a DECL_UID() which is a unique number identifying each decl. */
2725 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2727 /* A hash table of references to DIE's that describe COMMON blocks.
2728 The key is DECL_UID() ^ die_parent. */
2729 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2731 typedef struct GTY(()) die_arg_entry_struct
{
2737 /* Node of the variable location list. */
2738 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2739 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2740 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2741 in mode of the EXPR_LIST node and first EXPR_LIST operand
2742 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2743 location or NULL for padding. For larger bitsizes,
2744 mode is 0 and first operand is a CONCAT with bitsize
2745 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2746 NULL as second operand. */
2748 const char * GTY (()) label
;
2749 struct var_loc_node
* GTY (()) next
;
2752 /* Variable location list. */
2753 struct GTY (()) var_loc_list_def
{
2754 struct var_loc_node
* GTY (()) first
;
2756 /* Pointer to the last but one or last element of the
2757 chained list. If the list is empty, both first and
2758 last are NULL, if the list contains just one node
2759 or the last node certainly is not redundant, it points
2760 to the last node, otherwise points to the last but one.
2761 Do not mark it for GC because it is marked through the chain. */
2762 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2764 /* Pointer to the last element before section switch,
2765 if NULL, either sections weren't switched or first
2766 is after section switch. */
2767 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2769 /* DECL_UID of the variable decl. */
2770 unsigned int decl_id
;
2772 typedef struct var_loc_list_def var_loc_list
;
2774 /* Call argument location list. */
2775 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2776 rtx
GTY (()) call_arg_loc_note
;
2777 const char * GTY (()) label
;
2778 tree
GTY (()) block
;
2780 rtx
GTY (()) symbol_ref
;
2781 struct call_arg_loc_node
* GTY (()) next
;
2785 /* Table of decl location linked lists. */
2786 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2788 /* Head and tail of call_arg_loc chain. */
2789 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2790 static struct call_arg_loc_node
*call_arg_loc_last
;
2792 /* Number of call sites in the current function. */
2793 static int call_site_count
= -1;
2794 /* Number of tail call sites in the current function. */
2795 static int tail_call_site_count
= -1;
2797 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2799 static vec
<dw_die_ref
> block_map
;
2801 /* A cached location list. */
2802 struct GTY (()) cached_dw_loc_list_def
{
2803 /* The DECL_UID of the decl that this entry describes. */
2804 unsigned int decl_id
;
2806 /* The cached location list. */
2807 dw_loc_list_ref loc_list
;
2809 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2811 /* Table of cached location lists. */
2812 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2814 /* A pointer to the base of a list of references to DIE's that
2815 are uniquely identified by their tag, presence/absence of
2816 children DIE's, and list of attribute/value pairs. */
2817 static GTY((length ("abbrev_die_table_allocated")))
2818 dw_die_ref
*abbrev_die_table
;
2820 /* Number of elements currently allocated for abbrev_die_table. */
2821 static GTY(()) unsigned abbrev_die_table_allocated
;
2823 /* Number of elements in type_die_table currently in use. */
2824 static GTY(()) unsigned abbrev_die_table_in_use
;
2826 /* Size (in elements) of increments by which we may expand the
2827 abbrev_die_table. */
2828 #define ABBREV_DIE_TABLE_INCREMENT 256
2830 /* A global counter for generating labels for line number data. */
2831 static unsigned int line_info_label_num
;
2833 /* The current table to which we should emit line number information
2834 for the current function. This will be set up at the beginning of
2835 assembly for the function. */
2836 static dw_line_info_table
*cur_line_info_table
;
2838 /* The two default tables of line number info. */
2839 static GTY(()) dw_line_info_table
*text_section_line_info
;
2840 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2842 /* The set of all non-default tables of line number info. */
2843 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2845 /* A flag to tell pubnames/types export if there is an info section to
2847 static bool info_section_emitted
;
2849 /* A pointer to the base of a table that contains a list of publicly
2850 accessible names. */
2851 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2853 /* A pointer to the base of a table that contains a list of publicly
2854 accessible types. */
2855 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2857 /* A pointer to the base of a table that contains a list of macro
2858 defines/undefines (and file start/end markers). */
2859 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2861 /* True if .debug_macinfo or .debug_macros section is going to be
2863 #define have_macinfo \
2864 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2865 && !macinfo_table->is_empty ())
2867 /* Array of dies for which we should generate .debug_ranges info. */
2868 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2870 /* Number of elements currently allocated for ranges_table. */
2871 static GTY(()) unsigned ranges_table_allocated
;
2873 /* Number of elements in ranges_table currently in use. */
2874 static GTY(()) unsigned ranges_table_in_use
;
2876 /* Array of pairs of labels referenced in ranges_table. */
2877 static GTY ((length ("ranges_by_label_allocated")))
2878 dw_ranges_by_label_ref ranges_by_label
;
2880 /* Number of elements currently allocated for ranges_by_label. */
2881 static GTY(()) unsigned ranges_by_label_allocated
;
2883 /* Number of elements in ranges_by_label currently in use. */
2884 static GTY(()) unsigned ranges_by_label_in_use
;
2886 /* Size (in elements) of increments by which we may expand the
2888 #define RANGES_TABLE_INCREMENT 64
2890 /* Whether we have location lists that need outputting */
2891 static GTY(()) bool have_location_lists
;
2893 /* Unique label counter. */
2894 static GTY(()) unsigned int loclabel_num
;
2896 /* Unique label counter for point-of-call tables. */
2897 static GTY(()) unsigned int poc_label_num
;
2899 /* Record whether the function being analyzed contains inlined functions. */
2900 static int current_function_has_inlines
;
2902 /* The last file entry emitted by maybe_emit_file(). */
2903 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2905 /* Number of internal labels generated by gen_internal_sym(). */
2906 static GTY(()) int label_num
;
2908 /* Cached result of previous call to lookup_filename. */
2909 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2911 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2913 /* Instances of generic types for which we need to generate debug
2914 info that describe their generic parameters and arguments. That
2915 generation needs to happen once all types are properly laid out so
2916 we do it at the end of compilation. */
2917 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2919 /* Offset from the "steady-state frame pointer" to the frame base,
2920 within the current function. */
2921 static HOST_WIDE_INT frame_pointer_fb_offset
;
2922 static bool frame_pointer_fb_offset_valid
;
2924 static vec
<dw_die_ref
> base_types
;
2926 /* Forward declarations for functions defined in this file. */
2928 static int is_pseudo_reg (const_rtx
);
2929 static tree
type_main_variant (tree
);
2930 static int is_tagged_type (const_tree
);
2931 static const char *dwarf_tag_name (unsigned);
2932 static const char *dwarf_attr_name (unsigned);
2933 static const char *dwarf_form_name (unsigned);
2934 static tree
decl_ultimate_origin (const_tree
);
2935 static tree
decl_class_context (tree
);
2936 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2937 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2938 static inline unsigned int AT_index (dw_attr_ref
);
2939 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2940 static inline unsigned AT_flag (dw_attr_ref
);
2941 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2942 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2943 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2944 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2945 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2946 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2947 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2948 unsigned int, unsigned char *);
2949 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2950 static hashval_t
debug_str_do_hash (const void *);
2951 static int debug_str_eq (const void *, const void *);
2952 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2953 static inline const char *AT_string (dw_attr_ref
);
2954 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2955 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2956 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2957 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2958 static inline int AT_ref_external (dw_attr_ref
);
2959 static inline void set_AT_ref_external (dw_attr_ref
, int);
2960 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2961 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2962 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2963 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2965 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2966 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2967 static void remove_addr_table_entry (addr_table_entry
*);
2968 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
2969 static inline rtx
AT_addr (dw_attr_ref
);
2970 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2971 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2972 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2973 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2974 unsigned HOST_WIDE_INT
);
2975 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2976 unsigned long, bool);
2977 static inline const char *AT_lbl (dw_attr_ref
);
2978 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2979 static const char *get_AT_low_pc (dw_die_ref
);
2980 static const char *get_AT_hi_pc (dw_die_ref
);
2981 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2982 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2983 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2984 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2985 static bool is_cxx (void);
2986 static bool is_fortran (void);
2987 static bool is_ada (void);
2988 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2989 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2990 static void add_child_die (dw_die_ref
, dw_die_ref
);
2991 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2992 static dw_die_ref
lookup_type_die (tree
);
2993 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2994 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
2995 static void equate_type_number_to_die (tree
, dw_die_ref
);
2996 static hashval_t
decl_die_table_hash (const void *);
2997 static int decl_die_table_eq (const void *, const void *);
2998 static dw_die_ref
lookup_decl_die (tree
);
2999 static hashval_t
common_block_die_table_hash (const void *);
3000 static int common_block_die_table_eq (const void *, const void *);
3001 static hashval_t
decl_loc_table_hash (const void *);
3002 static int decl_loc_table_eq (const void *, const void *);
3003 static var_loc_list
*lookup_decl_loc (const_tree
);
3004 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3005 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3006 static void print_spaces (FILE *);
3007 static void print_die (dw_die_ref
, FILE *);
3008 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3009 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3010 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3011 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3012 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3013 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3014 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3015 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3016 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3017 struct md5_ctx
*, int *);
3018 struct checksum_attributes
;
3019 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3020 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3021 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3022 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3023 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3024 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3025 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3026 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3027 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3028 static void compute_section_prefix (dw_die_ref
);
3029 static int is_type_die (dw_die_ref
);
3030 static int is_comdat_die (dw_die_ref
);
3031 static int is_symbol_die (dw_die_ref
);
3032 static inline bool is_template_instantiation (dw_die_ref
);
3033 static void assign_symbol_names (dw_die_ref
);
3034 static void break_out_includes (dw_die_ref
);
3035 static int is_declaration_die (dw_die_ref
);
3036 static int should_move_die_to_comdat (dw_die_ref
);
3037 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3038 static dw_die_ref
clone_die (dw_die_ref
);
3039 static dw_die_ref
clone_tree (dw_die_ref
);
3040 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3041 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3042 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3043 static dw_die_ref
generate_skeleton (dw_die_ref
);
3044 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3047 static void break_out_comdat_types (dw_die_ref
);
3048 static void copy_decls_for_unworthy_types (dw_die_ref
);
3050 static void add_sibling_attributes (dw_die_ref
);
3051 static void output_location_lists (dw_die_ref
);
3052 static int constant_size (unsigned HOST_WIDE_INT
);
3053 static unsigned long size_of_die (dw_die_ref
);
3054 static void calc_die_sizes (dw_die_ref
);
3055 static void calc_base_type_die_sizes (void);
3056 static void mark_dies (dw_die_ref
);
3057 static void unmark_dies (dw_die_ref
);
3058 static void unmark_all_dies (dw_die_ref
);
3059 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3060 static unsigned long size_of_aranges (void);
3061 static enum dwarf_form
value_format (dw_attr_ref
);
3062 static void output_value_format (dw_attr_ref
);
3063 static void output_abbrev_section (void);
3064 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3065 static void output_die_symbol (dw_die_ref
);
3066 static void output_die (dw_die_ref
);
3067 static void output_compilation_unit_header (void);
3068 static void output_comp_unit (dw_die_ref
, int);
3069 static void output_comdat_type_unit (comdat_type_node
*);
3070 static const char *dwarf2_name (tree
, int);
3071 static void add_pubname (tree
, dw_die_ref
);
3072 static void add_enumerator_pubname (const char *, dw_die_ref
);
3073 static void add_pubname_string (const char *, dw_die_ref
);
3074 static void add_pubtype (tree
, dw_die_ref
);
3075 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3076 static void output_aranges (unsigned long);
3077 static unsigned int add_ranges_num (int);
3078 static unsigned int add_ranges (const_tree
);
3079 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3081 static void output_ranges (void);
3082 static dw_line_info_table
*new_line_info_table (void);
3083 static void output_line_info (bool);
3084 static void output_file_names (void);
3085 static dw_die_ref
base_type_die (tree
);
3086 static int is_base_type (tree
);
3087 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3088 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3089 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3090 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3091 static int type_is_enum (const_tree
);
3092 static unsigned int dbx_reg_number (const_rtx
);
3093 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3094 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3095 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3096 enum var_init_status
);
3097 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3098 enum var_init_status
);
3099 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3100 enum var_init_status
);
3101 static int is_based_loc (const_rtx
);
3102 static int resolve_one_addr (rtx
*, void *);
3103 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3104 enum var_init_status
);
3105 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3106 enum var_init_status
);
3107 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3108 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3109 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3110 static tree
field_type (const_tree
);
3111 static unsigned int simple_type_align_in_bits (const_tree
);
3112 static unsigned int simple_decl_align_in_bits (const_tree
);
3113 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3114 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3115 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3117 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3118 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3119 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3120 static void insert_double (double_int
, unsigned char *);
3121 static void insert_float (const_rtx
, unsigned char *);
3122 static rtx
rtl_for_decl_location (tree
);
3123 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3124 enum dwarf_attribute
);
3125 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3126 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3127 static void add_name_attribute (dw_die_ref
, const char *);
3128 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3129 static void add_comp_dir_attribute (dw_die_ref
);
3130 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3131 static void add_subscript_info (dw_die_ref
, tree
, bool);
3132 static void add_byte_size_attribute (dw_die_ref
, tree
);
3133 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3134 static void add_bit_size_attribute (dw_die_ref
, tree
);
3135 static void add_prototyped_attribute (dw_die_ref
, tree
);
3136 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3137 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3138 static void add_src_coords_attributes (dw_die_ref
, tree
);
3139 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3140 static void push_decl_scope (tree
);
3141 static void pop_decl_scope (void);
3142 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3143 static inline int local_scope_p (dw_die_ref
);
3144 static inline int class_scope_p (dw_die_ref
);
3145 static inline int class_or_namespace_scope_p (dw_die_ref
);
3146 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3147 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3148 static const char *type_tag (const_tree
);
3149 static tree
member_declared_type (const_tree
);
3151 static const char *decl_start_label (tree
);
3153 static void gen_array_type_die (tree
, dw_die_ref
);
3154 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3156 static void gen_entry_point_die (tree
, dw_die_ref
);
3158 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3159 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3160 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3161 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3162 static void gen_formal_types_die (tree
, dw_die_ref
);
3163 static void gen_subprogram_die (tree
, dw_die_ref
);
3164 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3165 static void gen_const_die (tree
, dw_die_ref
);
3166 static void gen_label_die (tree
, dw_die_ref
);
3167 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3168 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3169 static void gen_field_die (tree
, dw_die_ref
);
3170 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3171 static dw_die_ref
gen_compile_unit_die (const char *);
3172 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3173 static void gen_member_die (tree
, dw_die_ref
);
3174 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3175 enum debug_info_usage
);
3176 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3177 static void gen_typedef_die (tree
, dw_die_ref
);
3178 static void gen_type_die (tree
, dw_die_ref
);
3179 static void gen_block_die (tree
, dw_die_ref
, int);
3180 static void decls_for_scope (tree
, dw_die_ref
, int);
3181 static inline int is_redundant_typedef (const_tree
);
3182 static bool is_naming_typedef_decl (const_tree
);
3183 static inline dw_die_ref
get_context_die (tree
);
3184 static void gen_namespace_die (tree
, dw_die_ref
);
3185 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3186 static dw_die_ref
force_decl_die (tree
);
3187 static dw_die_ref
force_type_die (tree
);
3188 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3189 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3190 static struct dwarf_file_data
* lookup_filename (const char *);
3191 static void retry_incomplete_types (void);
3192 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3193 static void gen_generic_params_dies (tree
);
3194 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3195 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3196 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3197 static int file_info_cmp (const void *, const void *);
3198 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3199 const char *, const char *);
3200 static void output_loc_list (dw_loc_list_ref
);
3201 static char *gen_internal_sym (const char *);
3202 static bool want_pubnames (void);
3204 static void prune_unmark_dies (dw_die_ref
);
3205 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3206 static void prune_unused_types_mark (dw_die_ref
, int);
3207 static void prune_unused_types_walk (dw_die_ref
);
3208 static void prune_unused_types_walk_attribs (dw_die_ref
);
3209 static void prune_unused_types_prune (dw_die_ref
);
3210 static void prune_unused_types (void);
3211 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3212 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3213 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3214 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3215 const char *, const char *);
3216 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3217 static void gen_remaining_tmpl_value_param_die_attribute (void);
3218 static bool generic_type_p (tree
);
3219 static void schedule_generic_params_dies_gen (tree t
);
3220 static void gen_scheduled_generic_parms_dies (void);
3222 static const char *comp_dir_string (void);
3224 static hashval_t
hash_loc_operands (dw_loc_descr_ref
, hashval_t
);
3226 /* enum for tracking thread-local variables whose address is really an offset
3227 relative to the TLS pointer, which will need link-time relocation, but will
3228 not need relocation by the DWARF consumer. */
3236 /* Return the operator to use for an address of a variable. For dtprel_true, we
3237 use DW_OP_const*. For regular variables, which need both link-time
3238 relocation and consumer-level relocation (e.g., to account for shared objects
3239 loaded at a random address), we use DW_OP_addr*. */
3241 static inline enum dwarf_location_atom
3242 dw_addr_op (enum dtprel_bool dtprel
)
3244 if (dtprel
== dtprel_true
)
3245 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3246 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3248 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3251 /* Return a pointer to a newly allocated address location description. If
3252 dwarf_split_debug_info is true, then record the address with the appropriate
3254 static inline dw_loc_descr_ref
3255 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3257 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3259 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3260 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3261 ref
->dtprel
= dtprel
;
3262 if (dwarf_split_debug_info
)
3263 ref
->dw_loc_oprnd1
.val_entry
3264 = add_addr_table_entry (addr
,
3265 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3267 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3272 /* Section names used to hold DWARF debugging information. */
3274 #ifndef DEBUG_INFO_SECTION
3275 #define DEBUG_INFO_SECTION ".debug_info"
3277 #ifndef DEBUG_DWO_INFO_SECTION
3278 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3280 #ifndef DEBUG_ABBREV_SECTION
3281 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3283 #ifndef DEBUG_DWO_ABBREV_SECTION
3284 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3286 #ifndef DEBUG_ARANGES_SECTION
3287 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3289 #ifndef DEBUG_ADDR_SECTION
3290 #define DEBUG_ADDR_SECTION ".debug_addr"
3292 #ifndef DEBUG_NORM_MACINFO_SECTION
3293 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3295 #ifndef DEBUG_DWO_MACINFO_SECTION
3296 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3298 #ifndef DEBUG_MACINFO_SECTION
3299 #define DEBUG_MACINFO_SECTION \
3300 (!dwarf_split_debug_info \
3301 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3303 #ifndef DEBUG_NORM_MACRO_SECTION
3304 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3306 #ifndef DEBUG_DWO_MACRO_SECTION
3307 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3309 #ifndef DEBUG_MACRO_SECTION
3310 #define DEBUG_MACRO_SECTION \
3311 (!dwarf_split_debug_info \
3312 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3314 #ifndef DEBUG_LINE_SECTION
3315 #define DEBUG_LINE_SECTION ".debug_line"
3317 #ifndef DEBUG_DWO_LINE_SECTION
3318 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3320 #ifndef DEBUG_LOC_SECTION
3321 #define DEBUG_LOC_SECTION ".debug_loc"
3323 #ifndef DEBUG_DWO_LOC_SECTION
3324 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3326 #ifndef DEBUG_PUBNAMES_SECTION
3327 #define DEBUG_PUBNAMES_SECTION \
3328 ((debug_generate_pub_sections == 2) \
3329 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3331 #ifndef DEBUG_PUBTYPES_SECTION
3332 #define DEBUG_PUBTYPES_SECTION \
3333 ((debug_generate_pub_sections == 2) \
3334 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3336 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3337 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3338 #ifndef DEBUG_STR_OFFSETS_SECTION
3339 #define DEBUG_STR_OFFSETS_SECTION \
3340 (!dwarf_split_debug_info \
3341 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3343 #ifndef DEBUG_STR_DWO_SECTION
3344 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3346 #ifndef DEBUG_STR_SECTION
3347 #define DEBUG_STR_SECTION ".debug_str"
3349 #ifndef DEBUG_RANGES_SECTION
3350 #define DEBUG_RANGES_SECTION ".debug_ranges"
3353 /* Standard ELF section names for compiled code and data. */
3354 #ifndef TEXT_SECTION_NAME
3355 #define TEXT_SECTION_NAME ".text"
3358 /* Section flags for .debug_macinfo/.debug_macro section. */
3359 #define DEBUG_MACRO_SECTION_FLAGS \
3360 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3362 /* Section flags for .debug_str section. */
3363 #define DEBUG_STR_SECTION_FLAGS \
3364 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3365 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3368 /* Section flags for .debug_str.dwo section. */
3369 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3371 /* Labels we insert at beginning sections we can reference instead of
3372 the section names themselves. */
3374 #ifndef TEXT_SECTION_LABEL
3375 #define TEXT_SECTION_LABEL "Ltext"
3377 #ifndef COLD_TEXT_SECTION_LABEL
3378 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3380 #ifndef DEBUG_LINE_SECTION_LABEL
3381 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3383 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3384 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3386 #ifndef DEBUG_INFO_SECTION_LABEL
3387 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3389 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3390 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3392 #ifndef DEBUG_ABBREV_SECTION_LABEL
3393 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3395 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3396 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3398 #ifndef DEBUG_ADDR_SECTION_LABEL
3399 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3401 #ifndef DEBUG_LOC_SECTION_LABEL
3402 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3404 #ifndef DEBUG_RANGES_SECTION_LABEL
3405 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3407 #ifndef DEBUG_MACINFO_SECTION_LABEL
3408 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3410 #ifndef DEBUG_MACRO_SECTION_LABEL
3411 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3413 #define SKELETON_COMP_DIE_ABBREV 1
3414 #define SKELETON_TYPE_DIE_ABBREV 2
3416 /* Definitions of defaults for formats and names of various special
3417 (artificial) labels which may be generated within this file (when the -g
3418 options is used and DWARF2_DEBUGGING_INFO is in effect.
3419 If necessary, these may be overridden from within the tm.h file, but
3420 typically, overriding these defaults is unnecessary. */
3422 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3423 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3424 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3425 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3426 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3427 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3428 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3429 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3430 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3431 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3432 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3433 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3434 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3435 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3437 #ifndef TEXT_END_LABEL
3438 #define TEXT_END_LABEL "Letext"
3440 #ifndef COLD_END_LABEL
3441 #define COLD_END_LABEL "Letext_cold"
3443 #ifndef BLOCK_BEGIN_LABEL
3444 #define BLOCK_BEGIN_LABEL "LBB"
3446 #ifndef BLOCK_END_LABEL
3447 #define BLOCK_END_LABEL "LBE"
3449 #ifndef LINE_CODE_LABEL
3450 #define LINE_CODE_LABEL "LM"
3454 /* Return the root of the DIE's built for the current compilation unit. */
3456 comp_unit_die (void)
3458 if (!single_comp_unit_die
)
3459 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3460 return single_comp_unit_die
;
3463 /* We allow a language front-end to designate a function that is to be
3464 called to "demangle" any name before it is put into a DIE. */
3466 static const char *(*demangle_name_func
) (const char *);
3469 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3471 demangle_name_func
= func
;
3474 /* Test if rtl node points to a pseudo register. */
3477 is_pseudo_reg (const_rtx rtl
)
3479 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3480 || (GET_CODE (rtl
) == SUBREG
3481 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3484 /* Return a reference to a type, with its const and volatile qualifiers
3488 type_main_variant (tree type
)
3490 type
= TYPE_MAIN_VARIANT (type
);
3492 /* ??? There really should be only one main variant among any group of
3493 variants of a given type (and all of the MAIN_VARIANT values for all
3494 members of the group should point to that one type) but sometimes the C
3495 front-end messes this up for array types, so we work around that bug
3497 if (TREE_CODE (type
) == ARRAY_TYPE
)
3498 while (type
!= TYPE_MAIN_VARIANT (type
))
3499 type
= TYPE_MAIN_VARIANT (type
);
3504 /* Return nonzero if the given type node represents a tagged type. */
3507 is_tagged_type (const_tree type
)
3509 enum tree_code code
= TREE_CODE (type
);
3511 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3512 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3515 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3518 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3520 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3523 /* Return die_offset of a DIE reference to a base type. */
3525 static unsigned long int
3526 get_base_type_offset (dw_die_ref ref
)
3528 if (ref
->die_offset
)
3529 return ref
->die_offset
;
3530 if (comp_unit_die ()->die_abbrev
)
3532 calc_base_type_die_sizes ();
3533 gcc_assert (ref
->die_offset
);
3535 return ref
->die_offset
;
3538 /* Return die_offset of a DIE reference other than base type. */
3540 static unsigned long int
3541 get_ref_die_offset (dw_die_ref ref
)
3543 gcc_assert (ref
->die_offset
);
3544 return ref
->die_offset
;
3547 /* Convert a DIE tag into its string name. */
3550 dwarf_tag_name (unsigned int tag
)
3552 const char *name
= get_DW_TAG_name (tag
);
3557 return "DW_TAG_<unknown>";
3560 /* Convert a DWARF attribute code into its string name. */
3563 dwarf_attr_name (unsigned int attr
)
3569 #if VMS_DEBUGGING_INFO
3570 case DW_AT_HP_prologue
:
3571 return "DW_AT_HP_prologue";
3573 case DW_AT_MIPS_loop_unroll_factor
:
3574 return "DW_AT_MIPS_loop_unroll_factor";
3577 #if VMS_DEBUGGING_INFO
3578 case DW_AT_HP_epilogue
:
3579 return "DW_AT_HP_epilogue";
3581 case DW_AT_MIPS_stride
:
3582 return "DW_AT_MIPS_stride";
3586 name
= get_DW_AT_name (attr
);
3591 return "DW_AT_<unknown>";
3594 /* Convert a DWARF value form code into its string name. */
3597 dwarf_form_name (unsigned int form
)
3599 const char *name
= get_DW_FORM_name (form
);
3604 return "DW_FORM_<unknown>";
3607 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3608 instance of an inlined instance of a decl which is local to an inline
3609 function, so we have to trace all of the way back through the origin chain
3610 to find out what sort of node actually served as the original seed for the
3614 decl_ultimate_origin (const_tree decl
)
3616 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3619 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3620 nodes in the function to point to themselves; ignore that if
3621 we're trying to output the abstract instance of this function. */
3622 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3625 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3626 most distant ancestor, this should never happen. */
3627 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3629 return DECL_ABSTRACT_ORIGIN (decl
);
3632 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3633 of a virtual function may refer to a base class, so we check the 'this'
3637 decl_class_context (tree decl
)
3639 tree context
= NULL_TREE
;
3641 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3642 context
= DECL_CONTEXT (decl
);
3644 context
= TYPE_MAIN_VARIANT
3645 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3647 if (context
&& !TYPE_P (context
))
3648 context
= NULL_TREE
;
3653 /* Add an attribute/value pair to a DIE. */
3656 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3658 /* Maybe this should be an assert? */
3662 vec_safe_reserve (die
->die_attr
, 1);
3663 vec_safe_push (die
->die_attr
, *attr
);
3666 static inline enum dw_val_class
3667 AT_class (dw_attr_ref a
)
3669 return a
->dw_attr_val
.val_class
;
3672 /* Return the index for any attribute that will be referenced with a
3673 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3674 are stored in dw_attr_val.v.val_str for reference counting
3677 static inline unsigned int
3678 AT_index (dw_attr_ref a
)
3680 if (AT_class (a
) == dw_val_class_str
)
3681 return a
->dw_attr_val
.v
.val_str
->index
;
3682 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3683 return a
->dw_attr_val
.val_entry
->index
;
3687 /* Add a flag value attribute to a DIE. */
3690 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3694 attr
.dw_attr
= attr_kind
;
3695 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3696 attr
.dw_attr_val
.val_entry
= NULL
;
3697 attr
.dw_attr_val
.v
.val_flag
= flag
;
3698 add_dwarf_attr (die
, &attr
);
3701 static inline unsigned
3702 AT_flag (dw_attr_ref a
)
3704 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3705 return a
->dw_attr_val
.v
.val_flag
;
3708 /* Add a signed integer attribute value to a DIE. */
3711 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3715 attr
.dw_attr
= attr_kind
;
3716 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3717 attr
.dw_attr_val
.val_entry
= NULL
;
3718 attr
.dw_attr_val
.v
.val_int
= int_val
;
3719 add_dwarf_attr (die
, &attr
);
3722 static inline HOST_WIDE_INT
3723 AT_int (dw_attr_ref a
)
3725 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3726 return a
->dw_attr_val
.v
.val_int
;
3729 /* Add an unsigned integer attribute value to a DIE. */
3732 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3733 unsigned HOST_WIDE_INT unsigned_val
)
3737 attr
.dw_attr
= attr_kind
;
3738 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3739 attr
.dw_attr_val
.val_entry
= NULL
;
3740 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3741 add_dwarf_attr (die
, &attr
);
3744 static inline unsigned HOST_WIDE_INT
3745 AT_unsigned (dw_attr_ref a
)
3747 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3748 return a
->dw_attr_val
.v
.val_unsigned
;
3751 /* Add an unsigned double integer attribute value to a DIE. */
3754 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3755 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3759 attr
.dw_attr
= attr_kind
;
3760 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3761 attr
.dw_attr_val
.val_entry
= NULL
;
3762 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3763 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3764 add_dwarf_attr (die
, &attr
);
3767 /* Add a floating point attribute value to a DIE and return it. */
3770 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3771 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3775 attr
.dw_attr
= attr_kind
;
3776 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3777 attr
.dw_attr_val
.val_entry
= NULL
;
3778 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3779 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3780 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3781 add_dwarf_attr (die
, &attr
);
3784 /* Add an 8-byte data attribute value to a DIE. */
3787 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3788 unsigned char data8
[8])
3792 attr
.dw_attr
= attr_kind
;
3793 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3794 attr
.dw_attr_val
.val_entry
= NULL
;
3795 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3796 add_dwarf_attr (die
, &attr
);
3799 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3800 dwarf_split_debug_info, address attributes in dies destined for the
3801 final executable have force_direct set to avoid using indexed
3805 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3811 lbl_id
= xstrdup (lbl_low
);
3812 attr
.dw_attr
= DW_AT_low_pc
;
3813 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3814 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3815 if (dwarf_split_debug_info
&& !force_direct
)
3816 attr
.dw_attr_val
.val_entry
3817 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3819 attr
.dw_attr_val
.val_entry
= NULL
;
3820 add_dwarf_attr (die
, &attr
);
3822 attr
.dw_attr
= DW_AT_high_pc
;
3823 if (dwarf_version
< 4)
3824 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3826 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3827 lbl_id
= xstrdup (lbl_high
);
3828 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3829 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3830 && dwarf_split_debug_info
&& !force_direct
)
3831 attr
.dw_attr_val
.val_entry
3832 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3834 attr
.dw_attr_val
.val_entry
= NULL
;
3835 add_dwarf_attr (die
, &attr
);
3838 /* Hash and equality functions for debug_str_hash. */
3841 debug_str_do_hash (const void *x
)
3843 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3847 debug_str_eq (const void *x1
, const void *x2
)
3849 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3850 (const char *)x2
) == 0;
3853 /* Add STR to the given string hash table. */
3855 static struct indirect_string_node
*
3856 find_AT_string_in_table (const char *str
, htab_t table
)
3858 struct indirect_string_node
*node
;
3861 slot
= htab_find_slot_with_hash (table
, str
,
3862 htab_hash_string (str
), INSERT
);
3865 node
= ggc_alloc_cleared_indirect_string_node ();
3866 node
->str
= ggc_strdup (str
);
3870 node
= (struct indirect_string_node
*) *slot
;
3876 /* Add STR to the indirect string hash table. */
3878 static struct indirect_string_node
*
3879 find_AT_string (const char *str
)
3881 if (! debug_str_hash
)
3882 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3883 debug_str_eq
, NULL
);
3885 return find_AT_string_in_table (str
, debug_str_hash
);
3888 /* Add a string attribute value to a DIE. */
3891 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3894 struct indirect_string_node
*node
;
3896 node
= find_AT_string (str
);
3898 attr
.dw_attr
= attr_kind
;
3899 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3900 attr
.dw_attr_val
.val_entry
= NULL
;
3901 attr
.dw_attr_val
.v
.val_str
= node
;
3902 add_dwarf_attr (die
, &attr
);
3905 static inline const char *
3906 AT_string (dw_attr_ref a
)
3908 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3909 return a
->dw_attr_val
.v
.val_str
->str
;
3912 /* Call this function directly to bypass AT_string_form's logic to put
3913 the string inline in the die. */
3916 set_indirect_string (struct indirect_string_node
*node
)
3919 /* Already indirect is a no op. */
3920 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3922 gcc_assert (node
->label
);
3925 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3926 ++dw2_string_counter
;
3927 node
->label
= xstrdup (label
);
3929 if (!dwarf_split_debug_info
)
3931 node
->form
= DW_FORM_strp
;
3932 node
->index
= NOT_INDEXED
;
3936 node
->form
= DW_FORM_GNU_str_index
;
3937 node
->index
= NO_INDEX_ASSIGNED
;
3941 /* Find out whether a string should be output inline in DIE
3942 or out-of-line in .debug_str section. */
3944 static enum dwarf_form
3945 find_string_form (struct indirect_string_node
*node
)
3952 len
= strlen (node
->str
) + 1;
3954 /* If the string is shorter or equal to the size of the reference, it is
3955 always better to put it inline. */
3956 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3957 return node
->form
= DW_FORM_string
;
3959 /* If we cannot expect the linker to merge strings in .debug_str
3960 section, only put it into .debug_str if it is worth even in this
3962 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3963 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3964 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3965 return node
->form
= DW_FORM_string
;
3967 set_indirect_string (node
);
3972 /* Find out whether the string referenced from the attribute should be
3973 output inline in DIE or out-of-line in .debug_str section. */
3975 static enum dwarf_form
3976 AT_string_form (dw_attr_ref a
)
3978 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3979 return find_string_form (a
->dw_attr_val
.v
.val_str
);
3982 /* Add a DIE reference attribute value to a DIE. */
3985 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3989 #ifdef ENABLE_CHECKING
3990 gcc_assert (targ_die
!= NULL
);
3992 /* With LTO we can end up trying to reference something we didn't create
3993 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3994 if (targ_die
== NULL
)
3998 attr
.dw_attr
= attr_kind
;
3999 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4000 attr
.dw_attr_val
.val_entry
= NULL
;
4001 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4002 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4003 add_dwarf_attr (die
, &attr
);
4006 /* Change DIE reference REF to point to NEW_DIE instead. */
4009 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4011 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4012 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4013 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4016 /* Add an AT_specification attribute to a DIE, and also make the back
4017 pointer from the specification to the definition. */
4020 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4022 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4023 gcc_assert (!targ_die
->die_definition
);
4024 targ_die
->die_definition
= die
;
4027 static inline dw_die_ref
4028 AT_ref (dw_attr_ref a
)
4030 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4031 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4035 AT_ref_external (dw_attr_ref a
)
4037 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4038 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4044 set_AT_ref_external (dw_attr_ref a
, int i
)
4046 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4047 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4050 /* Add an FDE reference attribute value to a DIE. */
4053 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4057 attr
.dw_attr
= attr_kind
;
4058 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4059 attr
.dw_attr_val
.val_entry
= NULL
;
4060 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4061 add_dwarf_attr (die
, &attr
);
4064 /* Add a location description attribute value to a DIE. */
4067 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4071 attr
.dw_attr
= attr_kind
;
4072 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4073 attr
.dw_attr_val
.val_entry
= NULL
;
4074 attr
.dw_attr_val
.v
.val_loc
= loc
;
4075 add_dwarf_attr (die
, &attr
);
4078 static inline dw_loc_descr_ref
4079 AT_loc (dw_attr_ref a
)
4081 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4082 return a
->dw_attr_val
.v
.val_loc
;
4086 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4090 attr
.dw_attr
= attr_kind
;
4091 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4092 attr
.dw_attr_val
.val_entry
= NULL
;
4093 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4094 add_dwarf_attr (die
, &attr
);
4095 have_location_lists
= true;
4098 static inline dw_loc_list_ref
4099 AT_loc_list (dw_attr_ref a
)
4101 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4102 return a
->dw_attr_val
.v
.val_loc_list
;
4105 static inline dw_loc_list_ref
*
4106 AT_loc_list_ptr (dw_attr_ref a
)
4108 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4109 return &a
->dw_attr_val
.v
.val_loc_list
;
4112 /* Table of entries into the .debug_addr section. */
4114 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4116 /* Hash an address_table_entry. */
4119 addr_table_entry_do_hash (const void *x
)
4121 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4125 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4126 case ate_kind_rtx_dtprel
:
4127 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4128 case ate_kind_label
:
4129 return htab_hash_string (a
->addr
.label
);
4135 /* Determine equality for two address_table_entries. */
4138 addr_table_entry_eq (const void *x1
, const void *x2
)
4140 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4141 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4143 if (a1
->kind
!= a2
->kind
)
4148 case ate_kind_rtx_dtprel
:
4149 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4150 case ate_kind_label
:
4151 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4157 /* Initialize an addr_table_entry. */
4160 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4166 case ate_kind_rtx_dtprel
:
4167 e
->addr
.rtl
= (rtx
) addr
;
4169 case ate_kind_label
:
4170 e
->addr
.label
= (char *) addr
;
4174 e
->index
= NO_INDEX_ASSIGNED
;
4177 /* Add attr to the address table entry to the table. Defer setting an
4178 index until output time. */
4180 static addr_table_entry
*
4181 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4183 addr_table_entry
*node
;
4184 addr_table_entry finder
;
4187 gcc_assert (dwarf_split_debug_info
);
4188 if (! addr_index_table
)
4189 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4190 addr_table_entry_eq
, NULL
);
4191 init_addr_table_entry (&finder
, kind
, addr
);
4192 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4194 if (*slot
== HTAB_EMPTY_ENTRY
)
4196 node
= ggc_alloc_cleared_addr_table_entry ();
4197 init_addr_table_entry (node
, kind
, addr
);
4201 node
= (addr_table_entry
*) *slot
;
4207 /* Remove an entry from the addr table by decrementing its refcount.
4208 Strictly, decrementing the refcount would be enough, but the
4209 assertion that the entry is actually in the table has found
4213 remove_addr_table_entry (addr_table_entry
*entry
)
4215 addr_table_entry
*node
;
4217 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4218 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4219 /* After an index is assigned, the table is frozen. */
4220 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4224 /* Given a location list, remove all addresses it refers to from the
4228 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4230 for (; descr
; descr
= descr
->dw_loc_next
)
4231 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4233 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4234 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4238 /* A helper function for dwarf2out_finish called through
4239 htab_traverse. Assign an addr_table_entry its index. All entries
4240 must be collected into the table when this function is called,
4241 because the indexing code relies on htab_traverse to traverse nodes
4242 in the same order for each run. */
4245 index_addr_table_entry (void **h
, void *v
)
4247 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4248 unsigned int *index
= (unsigned int *) v
;
4250 /* Don't index unreferenced nodes. */
4251 if (node
->refcount
== 0)
4254 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4255 node
->index
= *index
;
4261 /* Add an address constant attribute value to a DIE. When using
4262 dwarf_split_debug_info, address attributes in dies destined for the
4263 final executable should be direct references--setting the parameter
4264 force_direct ensures this behavior. */
4267 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4272 attr
.dw_attr
= attr_kind
;
4273 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4274 attr
.dw_attr_val
.v
.val_addr
= addr
;
4275 if (dwarf_split_debug_info
&& !force_direct
)
4276 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4278 attr
.dw_attr_val
.val_entry
= NULL
;
4279 add_dwarf_attr (die
, &attr
);
4282 /* Get the RTX from to an address DIE attribute. */
4285 AT_addr (dw_attr_ref a
)
4287 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4288 return a
->dw_attr_val
.v
.val_addr
;
4291 /* Add a file attribute value to a DIE. */
4294 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4295 struct dwarf_file_data
*fd
)
4299 attr
.dw_attr
= attr_kind
;
4300 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4301 attr
.dw_attr_val
.val_entry
= NULL
;
4302 attr
.dw_attr_val
.v
.val_file
= fd
;
4303 add_dwarf_attr (die
, &attr
);
4306 /* Get the dwarf_file_data from a file DIE attribute. */
4308 static inline struct dwarf_file_data
*
4309 AT_file (dw_attr_ref a
)
4311 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4312 return a
->dw_attr_val
.v
.val_file
;
4315 /* Add a vms delta attribute value to a DIE. */
4318 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4319 const char *lbl1
, const char *lbl2
)
4323 attr
.dw_attr
= attr_kind
;
4324 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4325 attr
.dw_attr_val
.val_entry
= NULL
;
4326 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4327 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4328 add_dwarf_attr (die
, &attr
);
4331 /* Add a label identifier attribute value to a DIE. */
4334 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4339 attr
.dw_attr
= attr_kind
;
4340 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4341 attr
.dw_attr_val
.val_entry
= NULL
;
4342 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4343 if (dwarf_split_debug_info
)
4344 attr
.dw_attr_val
.val_entry
4345 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4347 add_dwarf_attr (die
, &attr
);
4350 /* Add a section offset attribute value to a DIE, an offset into the
4351 debug_line section. */
4354 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4359 attr
.dw_attr
= attr_kind
;
4360 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4361 attr
.dw_attr_val
.val_entry
= NULL
;
4362 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4363 add_dwarf_attr (die
, &attr
);
4366 /* Add a section offset attribute value to a DIE, an offset into the
4367 debug_macinfo section. */
4370 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4375 attr
.dw_attr
= attr_kind
;
4376 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4377 attr
.dw_attr_val
.val_entry
= NULL
;
4378 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4379 add_dwarf_attr (die
, &attr
);
4382 /* Add an offset attribute value to a DIE. */
4385 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4386 unsigned HOST_WIDE_INT offset
)
4390 attr
.dw_attr
= attr_kind
;
4391 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4392 attr
.dw_attr_val
.val_entry
= NULL
;
4393 attr
.dw_attr_val
.v
.val_offset
= offset
;
4394 add_dwarf_attr (die
, &attr
);
4397 /* Add a range_list attribute value to a DIE. When using
4398 dwarf_split_debug_info, address attributes in dies destined for the
4399 final executable should be direct references--setting the parameter
4400 force_direct ensures this behavior. */
4402 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4403 #define RELOCATED_OFFSET (NULL)
4406 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4407 long unsigned int offset
, bool force_direct
)
4411 attr
.dw_attr
= attr_kind
;
4412 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4413 /* For the range_list attribute, use val_entry to store whether the
4414 offset should follow split-debug-info or normal semantics. This
4415 value is read in output_range_list_offset. */
4416 if (dwarf_split_debug_info
&& !force_direct
)
4417 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4419 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4420 attr
.dw_attr_val
.v
.val_offset
= offset
;
4421 add_dwarf_attr (die
, &attr
);
4424 /* Return the start label of a delta attribute. */
4426 static inline const char *
4427 AT_vms_delta1 (dw_attr_ref a
)
4429 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4430 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4433 /* Return the end label of a delta attribute. */
4435 static inline const char *
4436 AT_vms_delta2 (dw_attr_ref a
)
4438 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4439 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4442 static inline const char *
4443 AT_lbl (dw_attr_ref a
)
4445 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4446 || AT_class (a
) == dw_val_class_lineptr
4447 || AT_class (a
) == dw_val_class_macptr
4448 || AT_class (a
) == dw_val_class_high_pc
));
4449 return a
->dw_attr_val
.v
.val_lbl_id
;
4452 /* Get the attribute of type attr_kind. */
4455 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4459 dw_die_ref spec
= NULL
;
4464 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4465 if (a
->dw_attr
== attr_kind
)
4467 else if (a
->dw_attr
== DW_AT_specification
4468 || a
->dw_attr
== DW_AT_abstract_origin
)
4472 return get_AT (spec
, attr_kind
);
4477 /* Returns the parent of the declaration of DIE. */
4480 get_die_parent (dw_die_ref die
)
4487 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4488 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4491 return die
->die_parent
;
4494 /* Return the "low pc" attribute value, typically associated with a subprogram
4495 DIE. Return null if the "low pc" attribute is either not present, or if it
4496 cannot be represented as an assembler label identifier. */
4498 static inline const char *
4499 get_AT_low_pc (dw_die_ref die
)
4501 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4503 return a
? AT_lbl (a
) : NULL
;
4506 /* Return the "high pc" attribute value, typically associated with a subprogram
4507 DIE. Return null if the "high pc" attribute is either not present, or if it
4508 cannot be represented as an assembler label identifier. */
4510 static inline const char *
4511 get_AT_hi_pc (dw_die_ref die
)
4513 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4515 return a
? AT_lbl (a
) : NULL
;
4518 /* Return the value of the string attribute designated by ATTR_KIND, or
4519 NULL if it is not present. */
4521 static inline const char *
4522 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4524 dw_attr_ref a
= get_AT (die
, attr_kind
);
4526 return a
? AT_string (a
) : NULL
;
4529 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4530 if it is not present. */
4533 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4535 dw_attr_ref a
= get_AT (die
, attr_kind
);
4537 return a
? AT_flag (a
) : 0;
4540 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4541 if it is not present. */
4543 static inline unsigned
4544 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4546 dw_attr_ref a
= get_AT (die
, attr_kind
);
4548 return a
? AT_unsigned (a
) : 0;
4551 static inline dw_die_ref
4552 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4554 dw_attr_ref a
= get_AT (die
, attr_kind
);
4556 return a
? AT_ref (a
) : NULL
;
4559 static inline struct dwarf_file_data
*
4560 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4562 dw_attr_ref a
= get_AT (die
, attr_kind
);
4564 return a
? AT_file (a
) : NULL
;
4567 /* Return TRUE if the language is C++. */
4572 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4574 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4577 /* Return TRUE if the language is Java. */
4582 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4584 return lang
== DW_LANG_Java
;
4587 /* Return TRUE if the language is Fortran. */
4592 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4594 return (lang
== DW_LANG_Fortran77
4595 || lang
== DW_LANG_Fortran90
4596 || lang
== DW_LANG_Fortran95
);
4599 /* Return TRUE if the language is Ada. */
4604 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4606 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4609 /* Remove the specified attribute if present. */
4612 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4620 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4621 if (a
->dw_attr
== attr_kind
)
4623 if (AT_class (a
) == dw_val_class_str
)
4624 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4625 a
->dw_attr_val
.v
.val_str
->refcount
--;
4627 /* vec::ordered_remove should help reduce the number of abbrevs
4629 die
->die_attr
->ordered_remove (ix
);
4634 /* Remove CHILD from its parent. PREV must have the property that
4635 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4638 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4640 gcc_assert (child
->die_parent
== prev
->die_parent
);
4641 gcc_assert (prev
->die_sib
== child
);
4644 gcc_assert (child
->die_parent
->die_child
== child
);
4648 prev
->die_sib
= child
->die_sib
;
4649 if (child
->die_parent
->die_child
== child
)
4650 child
->die_parent
->die_child
= prev
;
4653 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4654 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4657 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4659 dw_die_ref parent
= old_child
->die_parent
;
4661 gcc_assert (parent
== prev
->die_parent
);
4662 gcc_assert (prev
->die_sib
== old_child
);
4664 new_child
->die_parent
= parent
;
4665 if (prev
== old_child
)
4667 gcc_assert (parent
->die_child
== old_child
);
4668 new_child
->die_sib
= new_child
;
4672 prev
->die_sib
= new_child
;
4673 new_child
->die_sib
= old_child
->die_sib
;
4675 if (old_child
->die_parent
->die_child
== old_child
)
4676 old_child
->die_parent
->die_child
= new_child
;
4679 /* Move all children from OLD_PARENT to NEW_PARENT. */
4682 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4685 new_parent
->die_child
= old_parent
->die_child
;
4686 old_parent
->die_child
= NULL
;
4687 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4690 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4694 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4700 dw_die_ref prev
= c
;
4702 while (c
->die_tag
== tag
)
4704 remove_child_with_prev (c
, prev
);
4705 /* Might have removed every child. */
4706 if (c
== c
->die_sib
)
4710 } while (c
!= die
->die_child
);
4713 /* Add a CHILD_DIE as the last child of DIE. */
4716 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4718 /* FIXME this should probably be an assert. */
4719 if (! die
|| ! child_die
)
4721 gcc_assert (die
!= child_die
);
4723 child_die
->die_parent
= die
;
4726 child_die
->die_sib
= die
->die_child
->die_sib
;
4727 die
->die_child
->die_sib
= child_die
;
4730 child_die
->die_sib
= child_die
;
4731 die
->die_child
= child_die
;
4734 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4735 is the specification, to the end of PARENT's list of children.
4736 This is done by removing and re-adding it. */
4739 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4743 /* We want the declaration DIE from inside the class, not the
4744 specification DIE at toplevel. */
4745 if (child
->die_parent
!= parent
)
4747 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4753 gcc_assert (child
->die_parent
== parent
4754 || (child
->die_parent
4755 == get_AT_ref (parent
, DW_AT_specification
)));
4757 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4758 if (p
->die_sib
== child
)
4760 remove_child_with_prev (child
, p
);
4764 add_child_die (parent
, child
);
4767 /* Return a pointer to a newly created DIE node. */
4769 static inline dw_die_ref
4770 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4772 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4774 die
->die_tag
= tag_value
;
4776 if (parent_die
!= NULL
)
4777 add_child_die (parent_die
, die
);
4780 limbo_die_node
*limbo_node
;
4782 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4783 limbo_node
->die
= die
;
4784 limbo_node
->created_for
= t
;
4785 limbo_node
->next
= limbo_die_list
;
4786 limbo_die_list
= limbo_node
;
4792 /* Return the DIE associated with the given type specifier. */
4794 static inline dw_die_ref
4795 lookup_type_die (tree type
)
4797 return TYPE_SYMTAB_DIE (type
);
4800 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4801 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4802 anonymous type instead the one of the naming typedef. */
4804 static inline dw_die_ref
4805 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4808 && TREE_CODE (type
) == RECORD_TYPE
4810 && type_die
->die_tag
== DW_TAG_typedef
4811 && is_naming_typedef_decl (TYPE_NAME (type
)))
4812 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4816 /* Like lookup_type_die, but if type is an anonymous type named by a
4817 typedef[1], return the DIE of the anonymous type instead the one of
4818 the naming typedef. This is because in gen_typedef_die, we did
4819 equate the anonymous struct named by the typedef with the DIE of
4820 the naming typedef. So by default, lookup_type_die on an anonymous
4821 struct yields the DIE of the naming typedef.
4823 [1]: Read the comment of is_naming_typedef_decl to learn about what
4824 a naming typedef is. */
4826 static inline dw_die_ref
4827 lookup_type_die_strip_naming_typedef (tree type
)
4829 dw_die_ref die
= lookup_type_die (type
);
4830 return strip_naming_typedef (type
, die
);
4833 /* Equate a DIE to a given type specifier. */
4836 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4838 TYPE_SYMTAB_DIE (type
) = type_die
;
4841 /* Returns a hash value for X (which really is a die_struct). */
4844 decl_die_table_hash (const void *x
)
4846 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4849 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4852 decl_die_table_eq (const void *x
, const void *y
)
4854 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4857 /* Return the DIE associated with a given declaration. */
4859 static inline dw_die_ref
4860 lookup_decl_die (tree decl
)
4862 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4865 /* Returns a hash value for X (which really is a var_loc_list). */
4868 decl_loc_table_hash (const void *x
)
4870 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4873 /* Return nonzero if decl_id of var_loc_list X is the same as
4877 decl_loc_table_eq (const void *x
, const void *y
)
4879 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4882 /* Return the var_loc list associated with a given declaration. */
4884 static inline var_loc_list
*
4885 lookup_decl_loc (const_tree decl
)
4887 if (!decl_loc_table
)
4889 return (var_loc_list
*)
4890 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4893 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4896 cached_dw_loc_list_table_hash (const void *x
)
4898 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4901 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4905 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4907 return (((const cached_dw_loc_list
*) x
)->decl_id
4908 == DECL_UID ((const_tree
) y
));
4911 /* Equate a DIE to a particular declaration. */
4914 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4916 unsigned int decl_id
= DECL_UID (decl
);
4919 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4921 decl_die
->decl_id
= decl_id
;
4924 /* Return how many bits covers PIECE EXPR_LIST. */
4927 decl_piece_bitsize (rtx piece
)
4929 int ret
= (int) GET_MODE (piece
);
4932 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4933 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4934 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4937 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4940 decl_piece_varloc_ptr (rtx piece
)
4942 if ((int) GET_MODE (piece
))
4943 return &XEXP (piece
, 0);
4945 return &XEXP (XEXP (piece
, 0), 1);
4948 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4949 Next is the chain of following piece nodes. */
4952 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4954 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4955 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4957 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4962 /* Return rtx that should be stored into loc field for
4963 LOC_NOTE and BITPOS/BITSIZE. */
4966 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4967 HOST_WIDE_INT bitsize
)
4971 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4973 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4978 /* This function either modifies location piece list *DEST in
4979 place (if SRC and INNER is NULL), or copies location piece list
4980 *SRC to *DEST while modifying it. Location BITPOS is modified
4981 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4982 not copied and if needed some padding around it is added.
4983 When modifying in place, DEST should point to EXPR_LIST where
4984 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4985 to the start of the whole list and INNER points to the EXPR_LIST
4986 where earlier pieces cover PIECE_BITPOS bits. */
4989 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4990 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4991 HOST_WIDE_INT bitsize
, rtx loc_note
)
4994 bool copy
= inner
!= NULL
;
4998 /* First copy all nodes preceding the current bitpos. */
4999 while (src
!= inner
)
5001 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5002 decl_piece_bitsize (*src
), NULL_RTX
);
5003 dest
= &XEXP (*dest
, 1);
5004 src
= &XEXP (*src
, 1);
5007 /* Add padding if needed. */
5008 if (bitpos
!= piece_bitpos
)
5010 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5011 copy
? NULL_RTX
: *dest
);
5012 dest
= &XEXP (*dest
, 1);
5014 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5017 /* A piece with correct bitpos and bitsize already exist,
5018 just update the location for it and return. */
5019 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5022 /* Add the piece that changed. */
5023 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5024 dest
= &XEXP (*dest
, 1);
5025 /* Skip over pieces that overlap it. */
5026 diff
= bitpos
- piece_bitpos
+ bitsize
;
5029 while (diff
> 0 && *src
)
5032 diff
-= decl_piece_bitsize (piece
);
5034 src
= &XEXP (piece
, 1);
5037 *src
= XEXP (piece
, 1);
5038 free_EXPR_LIST_node (piece
);
5041 /* Add padding if needed. */
5042 if (diff
< 0 && *src
)
5046 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5047 dest
= &XEXP (*dest
, 1);
5051 /* Finally copy all nodes following it. */
5054 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5055 decl_piece_bitsize (*src
), NULL_RTX
);
5056 dest
= &XEXP (*dest
, 1);
5057 src
= &XEXP (*src
, 1);
5061 /* Add a variable location node to the linked list for DECL. */
5063 static struct var_loc_node
*
5064 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5066 unsigned int decl_id
;
5069 struct var_loc_node
*loc
= NULL
;
5070 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5072 if (TREE_CODE (decl
) == VAR_DECL
5073 && DECL_HAS_DEBUG_EXPR_P (decl
))
5075 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5076 if (handled_component_p (realdecl
)
5077 || (TREE_CODE (realdecl
) == MEM_REF
5078 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5080 HOST_WIDE_INT maxsize
;
5083 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5084 if (!DECL_P (innerdecl
)
5085 || DECL_IGNORED_P (innerdecl
)
5086 || TREE_STATIC (innerdecl
)
5088 || bitpos
+ bitsize
> 256
5089 || bitsize
!= maxsize
)
5095 decl_id
= DECL_UID (decl
);
5096 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5099 temp
= ggc_alloc_cleared_var_loc_list ();
5100 temp
->decl_id
= decl_id
;
5104 temp
= (var_loc_list
*) *slot
;
5106 /* For PARM_DECLs try to keep around the original incoming value,
5107 even if that means we'll emit a zero-range .debug_loc entry. */
5109 && temp
->first
== temp
->last
5110 && TREE_CODE (decl
) == PARM_DECL
5111 && NOTE_P (temp
->first
->loc
)
5112 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5113 && DECL_INCOMING_RTL (decl
)
5114 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5115 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5116 == GET_CODE (DECL_INCOMING_RTL (decl
))
5117 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5119 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5120 NOTE_VAR_LOCATION_LOC (loc_note
))
5121 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5122 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5124 loc
= ggc_alloc_cleared_var_loc_node ();
5125 temp
->first
->next
= loc
;
5127 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5129 else if (temp
->last
)
5131 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5132 rtx
*piece_loc
= NULL
, last_loc_note
;
5133 int piece_bitpos
= 0;
5137 gcc_assert (last
->next
== NULL
);
5139 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5141 piece_loc
= &last
->loc
;
5144 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5145 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5147 piece_bitpos
+= cur_bitsize
;
5148 piece_loc
= &XEXP (*piece_loc
, 1);
5152 /* TEMP->LAST here is either pointer to the last but one or
5153 last element in the chained list, LAST is pointer to the
5155 if (label
&& strcmp (last
->label
, label
) == 0)
5157 /* For SRA optimized variables if there weren't any real
5158 insns since last note, just modify the last node. */
5159 if (piece_loc
!= NULL
)
5161 adjust_piece_list (piece_loc
, NULL
, NULL
,
5162 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5165 /* If the last note doesn't cover any instructions, remove it. */
5166 if (temp
->last
!= last
)
5168 temp
->last
->next
= NULL
;
5171 gcc_assert (strcmp (last
->label
, label
) != 0);
5175 gcc_assert (temp
->first
== temp
->last
5176 || (temp
->first
->next
== temp
->last
5177 && TREE_CODE (decl
) == PARM_DECL
));
5178 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5179 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5183 if (bitsize
== -1 && NOTE_P (last
->loc
))
5184 last_loc_note
= last
->loc
;
5185 else if (piece_loc
!= NULL
5186 && *piece_loc
!= NULL_RTX
5187 && piece_bitpos
== bitpos
5188 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5189 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5191 last_loc_note
= NULL_RTX
;
5192 /* If the current location is the same as the end of the list,
5193 and either both or neither of the locations is uninitialized,
5194 we have nothing to do. */
5195 if (last_loc_note
== NULL_RTX
5196 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5197 NOTE_VAR_LOCATION_LOC (loc_note
)))
5198 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5199 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5200 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5201 == VAR_INIT_STATUS_UNINITIALIZED
)
5202 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5203 == VAR_INIT_STATUS_UNINITIALIZED
))))
5205 /* Add LOC to the end of list and update LAST. If the last
5206 element of the list has been removed above, reuse its
5207 memory for the new node, otherwise allocate a new one. */
5211 memset (loc
, '\0', sizeof (*loc
));
5214 loc
= ggc_alloc_cleared_var_loc_node ();
5215 if (bitsize
== -1 || piece_loc
== NULL
)
5216 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5218 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5219 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5221 /* Ensure TEMP->LAST will point either to the new last but one
5222 element of the chain, or to the last element in it. */
5223 if (last
!= temp
->last
)
5231 loc
= ggc_alloc_cleared_var_loc_node ();
5234 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5239 /* Keep track of the number of spaces used to indent the
5240 output of the debugging routines that print the structure of
5241 the DIE internal representation. */
5242 static int print_indent
;
5244 /* Indent the line the number of spaces given by print_indent. */
5247 print_spaces (FILE *outfile
)
5249 fprintf (outfile
, "%*s", print_indent
, "");
5252 /* Print a type signature in hex. */
5255 print_signature (FILE *outfile
, char *sig
)
5259 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5260 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5263 /* Print the information associated with a given DIE, and its children.
5264 This routine is a debugging aid only. */
5267 print_die (dw_die_ref die
, FILE *outfile
)
5273 print_spaces (outfile
);
5274 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5275 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5277 print_spaces (outfile
);
5278 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5279 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5280 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5282 if (die
->comdat_type_p
)
5284 print_spaces (outfile
);
5285 fprintf (outfile
, " signature: ");
5286 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5287 fprintf (outfile
, "\n");
5290 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5292 print_spaces (outfile
);
5293 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5295 switch (AT_class (a
))
5297 case dw_val_class_addr
:
5298 fprintf (outfile
, "address");
5300 case dw_val_class_offset
:
5301 fprintf (outfile
, "offset");
5303 case dw_val_class_loc
:
5304 fprintf (outfile
, "location descriptor");
5306 case dw_val_class_loc_list
:
5307 fprintf (outfile
, "location list -> label:%s",
5308 AT_loc_list (a
)->ll_symbol
);
5310 case dw_val_class_range_list
:
5311 fprintf (outfile
, "range list");
5313 case dw_val_class_const
:
5314 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5316 case dw_val_class_unsigned_const
:
5317 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5319 case dw_val_class_const_double
:
5320 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5321 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5322 a
->dw_attr_val
.v
.val_double
.high
,
5323 a
->dw_attr_val
.v
.val_double
.low
);
5325 case dw_val_class_vec
:
5326 fprintf (outfile
, "floating-point or vector constant");
5328 case dw_val_class_flag
:
5329 fprintf (outfile
, "%u", AT_flag (a
));
5331 case dw_val_class_die_ref
:
5332 if (AT_ref (a
) != NULL
)
5334 if (AT_ref (a
)->comdat_type_p
)
5336 fprintf (outfile
, "die -> signature: ");
5337 print_signature (outfile
,
5338 AT_ref (a
)->die_id
.die_type_node
->signature
);
5340 else if (AT_ref (a
)->die_id
.die_symbol
)
5341 fprintf (outfile
, "die -> label: %s",
5342 AT_ref (a
)->die_id
.die_symbol
);
5344 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5345 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5348 fprintf (outfile
, "die -> <null>");
5350 case dw_val_class_vms_delta
:
5351 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5352 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5354 case dw_val_class_lbl_id
:
5355 case dw_val_class_lineptr
:
5356 case dw_val_class_macptr
:
5357 case dw_val_class_high_pc
:
5358 fprintf (outfile
, "label: %s", AT_lbl (a
));
5360 case dw_val_class_str
:
5361 if (AT_string (a
) != NULL
)
5362 fprintf (outfile
, "\"%s\"", AT_string (a
));
5364 fprintf (outfile
, "<null>");
5366 case dw_val_class_file
:
5367 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5368 AT_file (a
)->emitted_number
);
5370 case dw_val_class_data8
:
5374 for (i
= 0; i
< 8; i
++)
5375 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5382 fprintf (outfile
, "\n");
5385 if (die
->die_child
!= NULL
)
5388 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5391 if (print_indent
== 0)
5392 fprintf (outfile
, "\n");
5395 /* Print the information collected for a given DIE. */
5398 debug_dwarf_die (dw_die_ref die
)
5400 print_die (die
, stderr
);
5404 debug (die_struct
&ref
)
5406 print_die (&ref
, stderr
);
5410 debug (die_struct
*ptr
)
5415 fprintf (stderr
, "<nil>\n");
5419 /* Print all DWARF information collected for the compilation unit.
5420 This routine is a debugging aid only. */
5426 print_die (comp_unit_die (), stderr
);
5429 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5430 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5431 DIE that marks the start of the DIEs for this include file. */
5434 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5436 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5437 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5439 new_unit
->die_sib
= old_unit
;
5443 /* Close an include-file CU and reopen the enclosing one. */
5446 pop_compile_unit (dw_die_ref old_unit
)
5448 dw_die_ref new_unit
= old_unit
->die_sib
;
5450 old_unit
->die_sib
= NULL
;
5454 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5455 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5456 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5458 /* Calculate the checksum of a location expression. */
5461 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5466 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5468 hash
= hash_loc_operands (loc
, hash
);
5472 /* Calculate the checksum of an attribute. */
5475 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5477 dw_loc_descr_ref loc
;
5480 CHECKSUM (at
->dw_attr
);
5482 /* We don't care that this was compiled with a different compiler
5483 snapshot; if the output is the same, that's what matters. */
5484 if (at
->dw_attr
== DW_AT_producer
)
5487 switch (AT_class (at
))
5489 case dw_val_class_const
:
5490 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5492 case dw_val_class_unsigned_const
:
5493 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5495 case dw_val_class_const_double
:
5496 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5498 case dw_val_class_vec
:
5499 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5500 (at
->dw_attr_val
.v
.val_vec
.length
5501 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5503 case dw_val_class_flag
:
5504 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5506 case dw_val_class_str
:
5507 CHECKSUM_STRING (AT_string (at
));
5510 case dw_val_class_addr
:
5512 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5513 CHECKSUM_STRING (XSTR (r
, 0));
5516 case dw_val_class_offset
:
5517 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5520 case dw_val_class_loc
:
5521 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5522 loc_checksum (loc
, ctx
);
5525 case dw_val_class_die_ref
:
5526 die_checksum (AT_ref (at
), ctx
, mark
);
5529 case dw_val_class_fde_ref
:
5530 case dw_val_class_vms_delta
:
5531 case dw_val_class_lbl_id
:
5532 case dw_val_class_lineptr
:
5533 case dw_val_class_macptr
:
5534 case dw_val_class_high_pc
:
5537 case dw_val_class_file
:
5538 CHECKSUM_STRING (AT_file (at
)->filename
);
5541 case dw_val_class_data8
:
5542 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5550 /* Calculate the checksum of a DIE. */
5553 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5559 /* To avoid infinite recursion. */
5562 CHECKSUM (die
->die_mark
);
5565 die
->die_mark
= ++(*mark
);
5567 CHECKSUM (die
->die_tag
);
5569 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5570 attr_checksum (a
, ctx
, mark
);
5572 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5576 #undef CHECKSUM_BLOCK
5577 #undef CHECKSUM_STRING
5579 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5580 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5581 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5582 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5583 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5584 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5585 #define CHECKSUM_ATTR(FOO) \
5586 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5588 /* Calculate the checksum of a number in signed LEB128 format. */
5591 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5598 byte
= (value
& 0x7f);
5600 more
= !((value
== 0 && (byte
& 0x40) == 0)
5601 || (value
== -1 && (byte
& 0x40) != 0));
5610 /* Calculate the checksum of a number in unsigned LEB128 format. */
5613 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5617 unsigned char byte
= (value
& 0x7f);
5620 /* More bytes to follow. */
5628 /* Checksum the context of the DIE. This adds the names of any
5629 surrounding namespaces or structures to the checksum. */
5632 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5636 int tag
= die
->die_tag
;
5638 if (tag
!= DW_TAG_namespace
5639 && tag
!= DW_TAG_structure_type
5640 && tag
!= DW_TAG_class_type
)
5643 name
= get_AT_string (die
, DW_AT_name
);
5645 spec
= get_AT_ref (die
, DW_AT_specification
);
5649 if (die
->die_parent
!= NULL
)
5650 checksum_die_context (die
->die_parent
, ctx
);
5652 CHECKSUM_ULEB128 ('C');
5653 CHECKSUM_ULEB128 (tag
);
5655 CHECKSUM_STRING (name
);
5658 /* Calculate the checksum of a location expression. */
5661 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5663 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5664 were emitted as a DW_FORM_sdata instead of a location expression. */
5665 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5667 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5668 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5672 /* Otherwise, just checksum the raw location expression. */
5677 CHECKSUM_ULEB128 (loc
->dtprel
);
5678 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5679 hash
= hash_loc_operands (loc
, hash
);
5681 loc
= loc
->dw_loc_next
;
5685 /* Calculate the checksum of an attribute. */
5688 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5689 struct md5_ctx
*ctx
, int *mark
)
5691 dw_loc_descr_ref loc
;
5694 if (AT_class (at
) == dw_val_class_die_ref
)
5696 dw_die_ref target_die
= AT_ref (at
);
5698 /* For pointer and reference types, we checksum only the (qualified)
5699 name of the target type (if there is a name). For friend entries,
5700 we checksum only the (qualified) name of the target type or function.
5701 This allows the checksum to remain the same whether the target type
5702 is complete or not. */
5703 if ((at
->dw_attr
== DW_AT_type
5704 && (tag
== DW_TAG_pointer_type
5705 || tag
== DW_TAG_reference_type
5706 || tag
== DW_TAG_rvalue_reference_type
5707 || tag
== DW_TAG_ptr_to_member_type
))
5708 || (at
->dw_attr
== DW_AT_friend
5709 && tag
== DW_TAG_friend
))
5711 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5713 if (name_attr
!= NULL
)
5715 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5719 CHECKSUM_ULEB128 ('N');
5720 CHECKSUM_ULEB128 (at
->dw_attr
);
5721 if (decl
->die_parent
!= NULL
)
5722 checksum_die_context (decl
->die_parent
, ctx
);
5723 CHECKSUM_ULEB128 ('E');
5724 CHECKSUM_STRING (AT_string (name_attr
));
5729 /* For all other references to another DIE, we check to see if the
5730 target DIE has already been visited. If it has, we emit a
5731 backward reference; if not, we descend recursively. */
5732 if (target_die
->die_mark
> 0)
5734 CHECKSUM_ULEB128 ('R');
5735 CHECKSUM_ULEB128 (at
->dw_attr
);
5736 CHECKSUM_ULEB128 (target_die
->die_mark
);
5740 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5744 target_die
->die_mark
= ++(*mark
);
5745 CHECKSUM_ULEB128 ('T');
5746 CHECKSUM_ULEB128 (at
->dw_attr
);
5747 if (decl
->die_parent
!= NULL
)
5748 checksum_die_context (decl
->die_parent
, ctx
);
5749 die_checksum_ordered (target_die
, ctx
, mark
);
5754 CHECKSUM_ULEB128 ('A');
5755 CHECKSUM_ULEB128 (at
->dw_attr
);
5757 switch (AT_class (at
))
5759 case dw_val_class_const
:
5760 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5761 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5764 case dw_val_class_unsigned_const
:
5765 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5766 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5769 case dw_val_class_const_double
:
5770 CHECKSUM_ULEB128 (DW_FORM_block
);
5771 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5772 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5775 case dw_val_class_vec
:
5776 CHECKSUM_ULEB128 (DW_FORM_block
);
5777 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
5778 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
5779 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5780 (at
->dw_attr_val
.v
.val_vec
.length
5781 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5784 case dw_val_class_flag
:
5785 CHECKSUM_ULEB128 (DW_FORM_flag
);
5786 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5789 case dw_val_class_str
:
5790 CHECKSUM_ULEB128 (DW_FORM_string
);
5791 CHECKSUM_STRING (AT_string (at
));
5794 case dw_val_class_addr
:
5796 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5797 CHECKSUM_ULEB128 (DW_FORM_string
);
5798 CHECKSUM_STRING (XSTR (r
, 0));
5801 case dw_val_class_offset
:
5802 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5803 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5806 case dw_val_class_loc
:
5807 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5808 loc_checksum_ordered (loc
, ctx
);
5811 case dw_val_class_fde_ref
:
5812 case dw_val_class_lbl_id
:
5813 case dw_val_class_lineptr
:
5814 case dw_val_class_macptr
:
5815 case dw_val_class_high_pc
:
5818 case dw_val_class_file
:
5819 CHECKSUM_ULEB128 (DW_FORM_string
);
5820 CHECKSUM_STRING (AT_file (at
)->filename
);
5823 case dw_val_class_data8
:
5824 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5832 struct checksum_attributes
5834 dw_attr_ref at_name
;
5835 dw_attr_ref at_type
;
5836 dw_attr_ref at_friend
;
5837 dw_attr_ref at_accessibility
;
5838 dw_attr_ref at_address_class
;
5839 dw_attr_ref at_allocated
;
5840 dw_attr_ref at_artificial
;
5841 dw_attr_ref at_associated
;
5842 dw_attr_ref at_binary_scale
;
5843 dw_attr_ref at_bit_offset
;
5844 dw_attr_ref at_bit_size
;
5845 dw_attr_ref at_bit_stride
;
5846 dw_attr_ref at_byte_size
;
5847 dw_attr_ref at_byte_stride
;
5848 dw_attr_ref at_const_value
;
5849 dw_attr_ref at_containing_type
;
5850 dw_attr_ref at_count
;
5851 dw_attr_ref at_data_location
;
5852 dw_attr_ref at_data_member_location
;
5853 dw_attr_ref at_decimal_scale
;
5854 dw_attr_ref at_decimal_sign
;
5855 dw_attr_ref at_default_value
;
5856 dw_attr_ref at_digit_count
;
5857 dw_attr_ref at_discr
;
5858 dw_attr_ref at_discr_list
;
5859 dw_attr_ref at_discr_value
;
5860 dw_attr_ref at_encoding
;
5861 dw_attr_ref at_endianity
;
5862 dw_attr_ref at_explicit
;
5863 dw_attr_ref at_is_optional
;
5864 dw_attr_ref at_location
;
5865 dw_attr_ref at_lower_bound
;
5866 dw_attr_ref at_mutable
;
5867 dw_attr_ref at_ordering
;
5868 dw_attr_ref at_picture_string
;
5869 dw_attr_ref at_prototyped
;
5870 dw_attr_ref at_small
;
5871 dw_attr_ref at_segment
;
5872 dw_attr_ref at_string_length
;
5873 dw_attr_ref at_threads_scaled
;
5874 dw_attr_ref at_upper_bound
;
5875 dw_attr_ref at_use_location
;
5876 dw_attr_ref at_use_UTF8
;
5877 dw_attr_ref at_variable_parameter
;
5878 dw_attr_ref at_virtuality
;
5879 dw_attr_ref at_visibility
;
5880 dw_attr_ref at_vtable_elem_location
;
5883 /* Collect the attributes that we will want to use for the checksum. */
5886 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5891 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5902 attrs
->at_friend
= a
;
5904 case DW_AT_accessibility
:
5905 attrs
->at_accessibility
= a
;
5907 case DW_AT_address_class
:
5908 attrs
->at_address_class
= a
;
5910 case DW_AT_allocated
:
5911 attrs
->at_allocated
= a
;
5913 case DW_AT_artificial
:
5914 attrs
->at_artificial
= a
;
5916 case DW_AT_associated
:
5917 attrs
->at_associated
= a
;
5919 case DW_AT_binary_scale
:
5920 attrs
->at_binary_scale
= a
;
5922 case DW_AT_bit_offset
:
5923 attrs
->at_bit_offset
= a
;
5925 case DW_AT_bit_size
:
5926 attrs
->at_bit_size
= a
;
5928 case DW_AT_bit_stride
:
5929 attrs
->at_bit_stride
= a
;
5931 case DW_AT_byte_size
:
5932 attrs
->at_byte_size
= a
;
5934 case DW_AT_byte_stride
:
5935 attrs
->at_byte_stride
= a
;
5937 case DW_AT_const_value
:
5938 attrs
->at_const_value
= a
;
5940 case DW_AT_containing_type
:
5941 attrs
->at_containing_type
= a
;
5944 attrs
->at_count
= a
;
5946 case DW_AT_data_location
:
5947 attrs
->at_data_location
= a
;
5949 case DW_AT_data_member_location
:
5950 attrs
->at_data_member_location
= a
;
5952 case DW_AT_decimal_scale
:
5953 attrs
->at_decimal_scale
= a
;
5955 case DW_AT_decimal_sign
:
5956 attrs
->at_decimal_sign
= a
;
5958 case DW_AT_default_value
:
5959 attrs
->at_default_value
= a
;
5961 case DW_AT_digit_count
:
5962 attrs
->at_digit_count
= a
;
5965 attrs
->at_discr
= a
;
5967 case DW_AT_discr_list
:
5968 attrs
->at_discr_list
= a
;
5970 case DW_AT_discr_value
:
5971 attrs
->at_discr_value
= a
;
5973 case DW_AT_encoding
:
5974 attrs
->at_encoding
= a
;
5976 case DW_AT_endianity
:
5977 attrs
->at_endianity
= a
;
5979 case DW_AT_explicit
:
5980 attrs
->at_explicit
= a
;
5982 case DW_AT_is_optional
:
5983 attrs
->at_is_optional
= a
;
5985 case DW_AT_location
:
5986 attrs
->at_location
= a
;
5988 case DW_AT_lower_bound
:
5989 attrs
->at_lower_bound
= a
;
5992 attrs
->at_mutable
= a
;
5994 case DW_AT_ordering
:
5995 attrs
->at_ordering
= a
;
5997 case DW_AT_picture_string
:
5998 attrs
->at_picture_string
= a
;
6000 case DW_AT_prototyped
:
6001 attrs
->at_prototyped
= a
;
6004 attrs
->at_small
= a
;
6007 attrs
->at_segment
= a
;
6009 case DW_AT_string_length
:
6010 attrs
->at_string_length
= a
;
6012 case DW_AT_threads_scaled
:
6013 attrs
->at_threads_scaled
= a
;
6015 case DW_AT_upper_bound
:
6016 attrs
->at_upper_bound
= a
;
6018 case DW_AT_use_location
:
6019 attrs
->at_use_location
= a
;
6021 case DW_AT_use_UTF8
:
6022 attrs
->at_use_UTF8
= a
;
6024 case DW_AT_variable_parameter
:
6025 attrs
->at_variable_parameter
= a
;
6027 case DW_AT_virtuality
:
6028 attrs
->at_virtuality
= a
;
6030 case DW_AT_visibility
:
6031 attrs
->at_visibility
= a
;
6033 case DW_AT_vtable_elem_location
:
6034 attrs
->at_vtable_elem_location
= a
;
6042 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6045 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6049 struct checksum_attributes attrs
;
6051 CHECKSUM_ULEB128 ('D');
6052 CHECKSUM_ULEB128 (die
->die_tag
);
6054 memset (&attrs
, 0, sizeof (attrs
));
6056 decl
= get_AT_ref (die
, DW_AT_specification
);
6058 collect_checksum_attributes (&attrs
, decl
);
6059 collect_checksum_attributes (&attrs
, die
);
6061 CHECKSUM_ATTR (attrs
.at_name
);
6062 CHECKSUM_ATTR (attrs
.at_accessibility
);
6063 CHECKSUM_ATTR (attrs
.at_address_class
);
6064 CHECKSUM_ATTR (attrs
.at_allocated
);
6065 CHECKSUM_ATTR (attrs
.at_artificial
);
6066 CHECKSUM_ATTR (attrs
.at_associated
);
6067 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6068 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6069 CHECKSUM_ATTR (attrs
.at_bit_size
);
6070 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6071 CHECKSUM_ATTR (attrs
.at_byte_size
);
6072 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6073 CHECKSUM_ATTR (attrs
.at_const_value
);
6074 CHECKSUM_ATTR (attrs
.at_containing_type
);
6075 CHECKSUM_ATTR (attrs
.at_count
);
6076 CHECKSUM_ATTR (attrs
.at_data_location
);
6077 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6078 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6079 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6080 CHECKSUM_ATTR (attrs
.at_default_value
);
6081 CHECKSUM_ATTR (attrs
.at_digit_count
);
6082 CHECKSUM_ATTR (attrs
.at_discr
);
6083 CHECKSUM_ATTR (attrs
.at_discr_list
);
6084 CHECKSUM_ATTR (attrs
.at_discr_value
);
6085 CHECKSUM_ATTR (attrs
.at_encoding
);
6086 CHECKSUM_ATTR (attrs
.at_endianity
);
6087 CHECKSUM_ATTR (attrs
.at_explicit
);
6088 CHECKSUM_ATTR (attrs
.at_is_optional
);
6089 CHECKSUM_ATTR (attrs
.at_location
);
6090 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6091 CHECKSUM_ATTR (attrs
.at_mutable
);
6092 CHECKSUM_ATTR (attrs
.at_ordering
);
6093 CHECKSUM_ATTR (attrs
.at_picture_string
);
6094 CHECKSUM_ATTR (attrs
.at_prototyped
);
6095 CHECKSUM_ATTR (attrs
.at_small
);
6096 CHECKSUM_ATTR (attrs
.at_segment
);
6097 CHECKSUM_ATTR (attrs
.at_string_length
);
6098 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6099 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6100 CHECKSUM_ATTR (attrs
.at_use_location
);
6101 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6102 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6103 CHECKSUM_ATTR (attrs
.at_virtuality
);
6104 CHECKSUM_ATTR (attrs
.at_visibility
);
6105 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6106 CHECKSUM_ATTR (attrs
.at_type
);
6107 CHECKSUM_ATTR (attrs
.at_friend
);
6109 /* Checksum the child DIEs. */
6112 dw_attr_ref name_attr
;
6115 name_attr
= get_AT (c
, DW_AT_name
);
6116 if (is_template_instantiation (c
))
6118 /* Ignore instantiations of member type and function templates. */
6120 else if (name_attr
!= NULL
6121 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6123 /* Use a shallow checksum for named nested types and member
6125 CHECKSUM_ULEB128 ('S');
6126 CHECKSUM_ULEB128 (c
->die_tag
);
6127 CHECKSUM_STRING (AT_string (name_attr
));
6131 /* Use a deep checksum for other children. */
6132 /* Mark this DIE so it gets processed when unmarking. */
6133 if (c
->die_mark
== 0)
6135 die_checksum_ordered (c
, ctx
, mark
);
6137 } while (c
!= die
->die_child
);
6139 CHECKSUM_ULEB128 (0);
6142 /* Add a type name and tag to a hash. */
6144 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6146 CHECKSUM_ULEB128 (tag
);
6147 CHECKSUM_STRING (name
);
6151 #undef CHECKSUM_STRING
6152 #undef CHECKSUM_ATTR
6153 #undef CHECKSUM_LEB128
6154 #undef CHECKSUM_ULEB128
6156 /* Generate the type signature for DIE. This is computed by generating an
6157 MD5 checksum over the DIE's tag, its relevant attributes, and its
6158 children. Attributes that are references to other DIEs are processed
6159 by recursion, using the MARK field to prevent infinite recursion.
6160 If the DIE is nested inside a namespace or another type, we also
6161 need to include that context in the signature. The lower 64 bits
6162 of the resulting MD5 checksum comprise the signature. */
6165 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6169 unsigned char checksum
[16];
6174 name
= get_AT_string (die
, DW_AT_name
);
6175 decl
= get_AT_ref (die
, DW_AT_specification
);
6176 parent
= get_die_parent (die
);
6178 /* First, compute a signature for just the type name (and its surrounding
6179 context, if any. This is stored in the type unit DIE for link-time
6180 ODR (one-definition rule) checking. */
6182 if (is_cxx () && name
!= NULL
)
6184 md5_init_ctx (&ctx
);
6186 /* Checksum the names of surrounding namespaces and structures. */
6188 checksum_die_context (parent
, &ctx
);
6190 /* Checksum the current DIE. */
6191 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6192 md5_finish_ctx (&ctx
, checksum
);
6194 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6197 /* Next, compute the complete type signature. */
6199 md5_init_ctx (&ctx
);
6201 die
->die_mark
= mark
;
6203 /* Checksum the names of surrounding namespaces and structures. */
6205 checksum_die_context (parent
, &ctx
);
6207 /* Checksum the DIE and its children. */
6208 die_checksum_ordered (die
, &ctx
, &mark
);
6209 unmark_all_dies (die
);
6210 md5_finish_ctx (&ctx
, checksum
);
6212 /* Store the signature in the type node and link the type DIE and the
6213 type node together. */
6214 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6215 DWARF_TYPE_SIGNATURE_SIZE
);
6216 die
->comdat_type_p
= true;
6217 die
->die_id
.die_type_node
= type_node
;
6218 type_node
->type_die
= die
;
6220 /* If the DIE is a specification, link its declaration to the type node
6224 decl
->comdat_type_p
= true;
6225 decl
->die_id
.die_type_node
= type_node
;
6229 /* Do the location expressions look same? */
6231 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6233 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6234 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6235 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6238 /* Do the values look the same? */
6240 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6242 dw_loc_descr_ref loc1
, loc2
;
6245 if (v1
->val_class
!= v2
->val_class
)
6248 switch (v1
->val_class
)
6250 case dw_val_class_const
:
6251 return v1
->v
.val_int
== v2
->v
.val_int
;
6252 case dw_val_class_unsigned_const
:
6253 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6254 case dw_val_class_const_double
:
6255 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6256 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6257 case dw_val_class_vec
:
6258 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6259 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6261 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6262 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6265 case dw_val_class_flag
:
6266 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6267 case dw_val_class_str
:
6268 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6270 case dw_val_class_addr
:
6271 r1
= v1
->v
.val_addr
;
6272 r2
= v2
->v
.val_addr
;
6273 if (GET_CODE (r1
) != GET_CODE (r2
))
6275 return !rtx_equal_p (r1
, r2
);
6277 case dw_val_class_offset
:
6278 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6280 case dw_val_class_loc
:
6281 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6283 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6284 if (!same_loc_p (loc1
, loc2
, mark
))
6286 return !loc1
&& !loc2
;
6288 case dw_val_class_die_ref
:
6289 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6291 case dw_val_class_fde_ref
:
6292 case dw_val_class_vms_delta
:
6293 case dw_val_class_lbl_id
:
6294 case dw_val_class_lineptr
:
6295 case dw_val_class_macptr
:
6296 case dw_val_class_high_pc
:
6299 case dw_val_class_file
:
6300 return v1
->v
.val_file
== v2
->v
.val_file
;
6302 case dw_val_class_data8
:
6303 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6310 /* Do the attributes look the same? */
6313 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6315 if (at1
->dw_attr
!= at2
->dw_attr
)
6318 /* We don't care that this was compiled with a different compiler
6319 snapshot; if the output is the same, that's what matters. */
6320 if (at1
->dw_attr
== DW_AT_producer
)
6323 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6326 /* Do the dies look the same? */
6329 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6335 /* To avoid infinite recursion. */
6337 return die1
->die_mark
== die2
->die_mark
;
6338 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6340 if (die1
->die_tag
!= die2
->die_tag
)
6343 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6346 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6347 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6350 c1
= die1
->die_child
;
6351 c2
= die2
->die_child
;
6360 if (!same_die_p (c1
, c2
, mark
))
6364 if (c1
== die1
->die_child
)
6366 if (c2
== die2
->die_child
)
6376 /* Do the dies look the same? Wrapper around same_die_p. */
6379 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6382 int ret
= same_die_p (die1
, die2
, &mark
);
6384 unmark_all_dies (die1
);
6385 unmark_all_dies (die2
);
6390 /* The prefix to attach to symbols on DIEs in the current comdat debug
6392 static const char *comdat_symbol_id
;
6394 /* The index of the current symbol within the current comdat CU. */
6395 static unsigned int comdat_symbol_number
;
6397 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6398 children, and set comdat_symbol_id accordingly. */
6401 compute_section_prefix (dw_die_ref unit_die
)
6403 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6404 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6405 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6408 unsigned char checksum
[16];
6411 /* Compute the checksum of the DIE, then append part of it as hex digits to
6412 the name filename of the unit. */
6414 md5_init_ctx (&ctx
);
6416 die_checksum (unit_die
, &ctx
, &mark
);
6417 unmark_all_dies (unit_die
);
6418 md5_finish_ctx (&ctx
, checksum
);
6420 sprintf (name
, "%s.", base
);
6421 clean_symbol_name (name
);
6423 p
= name
+ strlen (name
);
6424 for (i
= 0; i
< 4; i
++)
6426 sprintf (p
, "%.2x", checksum
[i
]);
6430 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6431 comdat_symbol_number
= 0;
6434 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6437 is_type_die (dw_die_ref die
)
6439 switch (die
->die_tag
)
6441 case DW_TAG_array_type
:
6442 case DW_TAG_class_type
:
6443 case DW_TAG_interface_type
:
6444 case DW_TAG_enumeration_type
:
6445 case DW_TAG_pointer_type
:
6446 case DW_TAG_reference_type
:
6447 case DW_TAG_rvalue_reference_type
:
6448 case DW_TAG_string_type
:
6449 case DW_TAG_structure_type
:
6450 case DW_TAG_subroutine_type
:
6451 case DW_TAG_union_type
:
6452 case DW_TAG_ptr_to_member_type
:
6453 case DW_TAG_set_type
:
6454 case DW_TAG_subrange_type
:
6455 case DW_TAG_base_type
:
6456 case DW_TAG_const_type
:
6457 case DW_TAG_file_type
:
6458 case DW_TAG_packed_type
:
6459 case DW_TAG_volatile_type
:
6460 case DW_TAG_typedef
:
6467 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6468 Basically, we want to choose the bits that are likely to be shared between
6469 compilations (types) and leave out the bits that are specific to individual
6470 compilations (functions). */
6473 is_comdat_die (dw_die_ref c
)
6475 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6476 we do for stabs. The advantage is a greater likelihood of sharing between
6477 objects that don't include headers in the same order (and therefore would
6478 put the base types in a different comdat). jason 8/28/00 */
6480 if (c
->die_tag
== DW_TAG_base_type
)
6483 if (c
->die_tag
== DW_TAG_pointer_type
6484 || c
->die_tag
== DW_TAG_reference_type
6485 || c
->die_tag
== DW_TAG_rvalue_reference_type
6486 || c
->die_tag
== DW_TAG_const_type
6487 || c
->die_tag
== DW_TAG_volatile_type
)
6489 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6491 return t
? is_comdat_die (t
) : 0;
6494 return is_type_die (c
);
6497 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6498 compilation unit. */
6501 is_symbol_die (dw_die_ref c
)
6503 return (is_type_die (c
)
6504 || is_declaration_die (c
)
6505 || c
->die_tag
== DW_TAG_namespace
6506 || c
->die_tag
== DW_TAG_module
);
6509 /* Returns true iff C is a compile-unit DIE. */
6512 is_cu_die (dw_die_ref c
)
6514 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6517 /* Returns true iff C is a unit DIE of some sort. */
6520 is_unit_die (dw_die_ref c
)
6522 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6523 || c
->die_tag
== DW_TAG_partial_unit
6524 || c
->die_tag
== DW_TAG_type_unit
);
6527 /* Returns true iff C is a namespace DIE. */
6530 is_namespace_die (dw_die_ref c
)
6532 return c
&& c
->die_tag
== DW_TAG_namespace
;
6535 /* Returns true iff C is a class or structure DIE. */
6538 is_class_die (dw_die_ref c
)
6540 return c
&& (c
->die_tag
== DW_TAG_class_type
6541 || c
->die_tag
== DW_TAG_structure_type
);
6544 /* Return non-zero if this DIE is a template parameter. */
6547 is_template_parameter (dw_die_ref die
)
6549 switch (die
->die_tag
)
6551 case DW_TAG_template_type_param
:
6552 case DW_TAG_template_value_param
:
6553 case DW_TAG_GNU_template_template_param
:
6554 case DW_TAG_GNU_template_parameter_pack
:
6561 /* Return non-zero if this DIE represents a template instantiation. */
6564 is_template_instantiation (dw_die_ref die
)
6568 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6570 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6575 gen_internal_sym (const char *prefix
)
6579 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6580 return xstrdup (buf
);
6583 /* Assign symbols to all worthy DIEs under DIE. */
6586 assign_symbol_names (dw_die_ref die
)
6590 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6592 if (comdat_symbol_id
)
6594 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6596 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6597 comdat_symbol_id
, comdat_symbol_number
++);
6598 die
->die_id
.die_symbol
= xstrdup (p
);
6601 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6604 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6607 struct cu_hash_table_entry
6610 unsigned min_comdat_num
, max_comdat_num
;
6611 struct cu_hash_table_entry
*next
;
6614 /* Helpers to manipulate hash table of CUs. */
6616 struct cu_hash_table_entry_hasher
6618 typedef cu_hash_table_entry value_type
;
6619 typedef die_struct compare_type
;
6620 static inline hashval_t
hash (const value_type
*);
6621 static inline bool equal (const value_type
*, const compare_type
*);
6622 static inline void remove (value_type
*);
6626 cu_hash_table_entry_hasher::hash (const value_type
*entry
)
6628 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6632 cu_hash_table_entry_hasher::equal (const value_type
*entry1
,
6633 const compare_type
*entry2
)
6635 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6639 cu_hash_table_entry_hasher::remove (value_type
*entry
)
6641 struct cu_hash_table_entry
*next
;
6651 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6653 /* Check whether we have already seen this CU and set up SYM_NUM
6656 check_duplicate_cu (dw_die_ref cu
, cu_hash_type htable
, unsigned int *sym_num
)
6658 struct cu_hash_table_entry dummy
;
6659 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6661 dummy
.max_comdat_num
= 0;
6663 slot
= htable
.find_slot_with_hash (cu
,
6664 htab_hash_string (cu
->die_id
.die_symbol
),
6668 for (; entry
; last
= entry
, entry
= entry
->next
)
6670 if (same_die_p_wrap (cu
, entry
->cu
))
6676 *sym_num
= entry
->min_comdat_num
;
6680 entry
= XCNEW (struct cu_hash_table_entry
);
6682 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6683 entry
->next
= *slot
;
6689 /* Record SYM_NUM to record of CU in HTABLE. */
6691 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type htable
,
6692 unsigned int sym_num
)
6694 struct cu_hash_table_entry
**slot
, *entry
;
6696 slot
= htable
.find_slot_with_hash (cu
,
6697 htab_hash_string (cu
->die_id
.die_symbol
),
6701 entry
->max_comdat_num
= sym_num
;
6704 /* Traverse the DIE (which is always comp_unit_die), and set up
6705 additional compilation units for each of the include files we see
6706 bracketed by BINCL/EINCL. */
6709 break_out_includes (dw_die_ref die
)
6712 dw_die_ref unit
= NULL
;
6713 limbo_die_node
*node
, **pnode
;
6714 cu_hash_type cu_hash_table
;
6718 dw_die_ref prev
= c
;
6720 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6721 || (unit
&& is_comdat_die (c
)))
6723 dw_die_ref next
= c
->die_sib
;
6725 /* This DIE is for a secondary CU; remove it from the main one. */
6726 remove_child_with_prev (c
, prev
);
6728 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6729 unit
= push_new_compile_unit (unit
, c
);
6730 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6731 unit
= pop_compile_unit (unit
);
6733 add_child_die (unit
, c
);
6735 if (c
== die
->die_child
)
6738 } while (c
!= die
->die_child
);
6741 /* We can only use this in debugging, since the frontend doesn't check
6742 to make sure that we leave every include file we enter. */
6746 assign_symbol_names (die
);
6747 cu_hash_table
.create (10);
6748 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6754 compute_section_prefix (node
->die
);
6755 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6756 &comdat_symbol_number
);
6757 assign_symbol_names (node
->die
);
6759 *pnode
= node
->next
;
6762 pnode
= &node
->next
;
6763 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6764 comdat_symbol_number
);
6767 cu_hash_table
.dispose ();
6770 /* Return non-zero if this DIE is a declaration. */
6773 is_declaration_die (dw_die_ref die
)
6778 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6779 if (a
->dw_attr
== DW_AT_declaration
)
6785 /* Return non-zero if this DIE is nested inside a subprogram. */
6788 is_nested_in_subprogram (dw_die_ref die
)
6790 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6794 return local_scope_p (decl
);
6797 /* Return non-zero if this DIE contains a defining declaration of a
6801 contains_subprogram_definition (dw_die_ref die
)
6805 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6807 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
6811 /* Return non-zero if this is a type DIE that should be moved to a
6812 COMDAT .debug_types section. */
6815 should_move_die_to_comdat (dw_die_ref die
)
6817 switch (die
->die_tag
)
6819 case DW_TAG_class_type
:
6820 case DW_TAG_structure_type
:
6821 case DW_TAG_enumeration_type
:
6822 case DW_TAG_union_type
:
6823 /* Don't move declarations, inlined instances, or types nested in a
6825 if (is_declaration_die (die
)
6826 || get_AT (die
, DW_AT_abstract_origin
)
6827 || is_nested_in_subprogram (die
))
6829 /* A type definition should never contain a subprogram definition. */
6830 gcc_assert (!contains_subprogram_definition (die
));
6832 case DW_TAG_array_type
:
6833 case DW_TAG_interface_type
:
6834 case DW_TAG_pointer_type
:
6835 case DW_TAG_reference_type
:
6836 case DW_TAG_rvalue_reference_type
:
6837 case DW_TAG_string_type
:
6838 case DW_TAG_subroutine_type
:
6839 case DW_TAG_ptr_to_member_type
:
6840 case DW_TAG_set_type
:
6841 case DW_TAG_subrange_type
:
6842 case DW_TAG_base_type
:
6843 case DW_TAG_const_type
:
6844 case DW_TAG_file_type
:
6845 case DW_TAG_packed_type
:
6846 case DW_TAG_volatile_type
:
6847 case DW_TAG_typedef
:
6853 /* Make a clone of DIE. */
6856 clone_die (dw_die_ref die
)
6862 clone
= ggc_alloc_cleared_die_node ();
6863 clone
->die_tag
= die
->die_tag
;
6865 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6866 add_dwarf_attr (clone
, a
);
6871 /* Make a clone of the tree rooted at DIE. */
6874 clone_tree (dw_die_ref die
)
6877 dw_die_ref clone
= clone_die (die
);
6879 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
6884 /* Make a clone of DIE as a declaration. */
6887 clone_as_declaration (dw_die_ref die
)
6894 /* If the DIE is already a declaration, just clone it. */
6895 if (is_declaration_die (die
))
6896 return clone_die (die
);
6898 /* If the DIE is a specification, just clone its declaration DIE. */
6899 decl
= get_AT_ref (die
, DW_AT_specification
);
6902 clone
= clone_die (decl
);
6903 if (die
->comdat_type_p
)
6904 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6908 clone
= ggc_alloc_cleared_die_node ();
6909 clone
->die_tag
= die
->die_tag
;
6911 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6913 /* We don't want to copy over all attributes.
6914 For example we don't want DW_AT_byte_size because otherwise we will no
6915 longer have a declaration and GDB will treat it as a definition. */
6919 case DW_AT_artificial
:
6920 case DW_AT_containing_type
:
6921 case DW_AT_external
:
6924 case DW_AT_virtuality
:
6925 case DW_AT_linkage_name
:
6926 case DW_AT_MIPS_linkage_name
:
6927 add_dwarf_attr (clone
, a
);
6929 case DW_AT_byte_size
:
6935 if (die
->comdat_type_p
)
6936 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6938 add_AT_flag (clone
, DW_AT_declaration
, 1);
6943 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
6945 struct decl_table_entry
6951 /* Helpers to manipulate hash table of copied declarations. */
6953 /* Hashtable helpers. */
6955 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
6957 typedef decl_table_entry value_type
;
6958 typedef die_struct compare_type
;
6959 static inline hashval_t
hash (const value_type
*);
6960 static inline bool equal (const value_type
*, const compare_type
*);
6964 decl_table_entry_hasher::hash (const value_type
*entry
)
6966 return htab_hash_pointer (entry
->orig
);
6970 decl_table_entry_hasher::equal (const value_type
*entry1
,
6971 const compare_type
*entry2
)
6973 return entry1
->orig
== entry2
;
6976 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
6978 /* Copy DIE and its ancestors, up to, but not including, the compile unit
6979 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
6980 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
6981 to check if the ancestor has already been copied into UNIT. */
6984 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
6986 dw_die_ref parent
= die
->die_parent
;
6987 dw_die_ref new_parent
= unit
;
6989 decl_table_entry
**slot
= NULL
;
6990 struct decl_table_entry
*entry
= NULL
;
6992 if (decl_table
.is_created ())
6994 /* Check if the entry has already been copied to UNIT. */
6995 slot
= decl_table
.find_slot_with_hash (die
, htab_hash_pointer (die
),
6997 if (*slot
!= HTAB_EMPTY_ENTRY
)
7003 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7004 entry
= XCNEW (struct decl_table_entry
);
7012 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7015 if (!is_unit_die (parent
))
7016 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7019 copy
= clone_as_declaration (die
);
7020 add_child_die (new_parent
, copy
);
7022 if (decl_table
.is_created ())
7024 /* Record the pointer to the copy. */
7030 /* Copy the declaration context to the new type unit DIE. This includes
7031 any surrounding namespace or type declarations. If the DIE has an
7032 AT_specification attribute, it also includes attributes and children
7033 attached to the specification, and returns a pointer to the original
7034 parent of the declaration DIE. Returns NULL otherwise. */
7037 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7040 dw_die_ref new_decl
;
7041 dw_die_ref orig_parent
= NULL
;
7043 decl
= get_AT_ref (die
, DW_AT_specification
);
7052 /* The original DIE will be changed to a declaration, and must
7053 be moved to be a child of the original declaration DIE. */
7054 orig_parent
= decl
->die_parent
;
7056 /* Copy the type node pointer from the new DIE to the original
7057 declaration DIE so we can forward references later. */
7058 decl
->comdat_type_p
= true;
7059 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7061 remove_AT (die
, DW_AT_specification
);
7063 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7065 if (a
->dw_attr
!= DW_AT_name
7066 && a
->dw_attr
!= DW_AT_declaration
7067 && a
->dw_attr
!= DW_AT_external
)
7068 add_dwarf_attr (die
, a
);
7071 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7074 if (decl
->die_parent
!= NULL
7075 && !is_unit_die (decl
->die_parent
))
7077 new_decl
= copy_ancestor_tree (unit
, decl
, decl_hash_type ());
7078 if (new_decl
!= NULL
)
7080 remove_AT (new_decl
, DW_AT_signature
);
7081 add_AT_specification (die
, new_decl
);
7088 /* Generate the skeleton ancestor tree for the given NODE, then clone
7089 the DIE and add the clone into the tree. */
7092 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7094 if (node
->new_die
!= NULL
)
7097 node
->new_die
= clone_as_declaration (node
->old_die
);
7099 if (node
->parent
!= NULL
)
7101 generate_skeleton_ancestor_tree (node
->parent
);
7102 add_child_die (node
->parent
->new_die
, node
->new_die
);
7106 /* Generate a skeleton tree of DIEs containing any declarations that are
7107 found in the original tree. We traverse the tree looking for declaration
7108 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7111 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7113 skeleton_chain_node node
;
7116 dw_die_ref prev
= NULL
;
7117 dw_die_ref next
= NULL
;
7119 node
.parent
= parent
;
7121 first
= c
= parent
->old_die
->die_child
;
7125 if (prev
== NULL
|| prev
->die_sib
== c
)
7128 next
= (c
== first
? NULL
: c
->die_sib
);
7130 node
.new_die
= NULL
;
7131 if (is_declaration_die (c
))
7133 if (is_template_instantiation (c
))
7135 /* Instantiated templates do not need to be cloned into the
7136 type unit. Just move the DIE and its children back to
7137 the skeleton tree (in the main CU). */
7138 remove_child_with_prev (c
, prev
);
7139 add_child_die (parent
->new_die
, c
);
7144 /* Clone the existing DIE, move the original to the skeleton
7145 tree (which is in the main CU), and put the clone, with
7146 all the original's children, where the original came from
7147 (which is about to be moved to the type unit). */
7148 dw_die_ref clone
= clone_die (c
);
7149 move_all_children (c
, clone
);
7151 replace_child (c
, clone
, prev
);
7152 generate_skeleton_ancestor_tree (parent
);
7153 add_child_die (parent
->new_die
, c
);
7158 generate_skeleton_bottom_up (&node
);
7159 } while (next
!= NULL
);
7162 /* Wrapper function for generate_skeleton_bottom_up. */
7165 generate_skeleton (dw_die_ref die
)
7167 skeleton_chain_node node
;
7170 node
.new_die
= NULL
;
7173 /* If this type definition is nested inside another type,
7174 and is not an instantiation of a template, always leave
7175 at least a declaration in its place. */
7176 if (die
->die_parent
!= NULL
7177 && is_type_die (die
->die_parent
)
7178 && !is_template_instantiation (die
))
7179 node
.new_die
= clone_as_declaration (die
);
7181 generate_skeleton_bottom_up (&node
);
7182 return node
.new_die
;
7185 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7186 declaration. The original DIE is moved to a new compile unit so that
7187 existing references to it follow it to the new location. If any of the
7188 original DIE's descendants is a declaration, we need to replace the
7189 original DIE with a skeleton tree and move the declarations back into the
7193 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7196 dw_die_ref skeleton
, orig_parent
;
7198 /* Copy the declaration context to the type unit DIE. If the returned
7199 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7201 orig_parent
= copy_declaration_context (unit
, child
);
7203 skeleton
= generate_skeleton (child
);
7204 if (skeleton
== NULL
)
7205 remove_child_with_prev (child
, prev
);
7208 skeleton
->comdat_type_p
= true;
7209 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7211 /* If the original DIE was a specification, we need to put
7212 the skeleton under the parent DIE of the declaration.
7213 This leaves the original declaration in the tree, but
7214 it will be pruned later since there are no longer any
7215 references to it. */
7216 if (orig_parent
!= NULL
)
7218 remove_child_with_prev (child
, prev
);
7219 add_child_die (orig_parent
, skeleton
);
7222 replace_child (child
, skeleton
, prev
);
7228 /* Traverse the DIE and set up additional .debug_types sections for each
7229 type worthy of being placed in a COMDAT section. */
7232 break_out_comdat_types (dw_die_ref die
)
7236 dw_die_ref prev
= NULL
;
7237 dw_die_ref next
= NULL
;
7238 dw_die_ref unit
= NULL
;
7240 first
= c
= die
->die_child
;
7244 if (prev
== NULL
|| prev
->die_sib
== c
)
7247 next
= (c
== first
? NULL
: c
->die_sib
);
7248 if (should_move_die_to_comdat (c
))
7250 dw_die_ref replacement
;
7251 comdat_type_node_ref type_node
;
7253 /* Break out nested types into their own type units. */
7254 break_out_comdat_types (c
);
7256 /* Create a new type unit DIE as the root for the new tree, and
7257 add it to the list of comdat types. */
7258 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7259 add_AT_unsigned (unit
, DW_AT_language
,
7260 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7261 type_node
= ggc_alloc_cleared_comdat_type_node ();
7262 type_node
->root_die
= unit
;
7263 type_node
->next
= comdat_type_list
;
7264 comdat_type_list
= type_node
;
7266 /* Generate the type signature. */
7267 generate_type_signature (c
, type_node
);
7269 /* Copy the declaration context, attributes, and children of the
7270 declaration into the new type unit DIE, then remove this DIE
7271 from the main CU (or replace it with a skeleton if necessary). */
7272 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7273 type_node
->skeleton_die
= replacement
;
7275 /* Add the DIE to the new compunit. */
7276 add_child_die (unit
, c
);
7278 if (replacement
!= NULL
)
7281 else if (c
->die_tag
== DW_TAG_namespace
7282 || c
->die_tag
== DW_TAG_class_type
7283 || c
->die_tag
== DW_TAG_structure_type
7284 || c
->die_tag
== DW_TAG_union_type
)
7286 /* Look for nested types that can be broken out. */
7287 break_out_comdat_types (c
);
7289 } while (next
!= NULL
);
7292 /* Like clone_tree, but additionally enter all the children into
7293 the hash table decl_table. */
7296 clone_tree_hash (dw_die_ref die
, decl_hash_type decl_table
)
7299 dw_die_ref clone
= clone_die (die
);
7300 struct decl_table_entry
*entry
;
7301 decl_table_entry
**slot
= decl_table
.find_slot_with_hash (die
,
7302 htab_hash_pointer (die
), INSERT
);
7303 /* Assert that DIE isn't in the hash table yet. If it would be there
7304 before, the ancestors would be necessarily there as well, therefore
7305 clone_tree_hash wouldn't be called. */
7306 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7307 entry
= XCNEW (struct decl_table_entry
);
7309 entry
->copy
= clone
;
7312 FOR_EACH_CHILD (die
, c
,
7313 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7318 /* Walk the DIE and its children, looking for references to incomplete
7319 or trivial types that are unmarked (i.e., that are not in the current
7323 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
7329 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7331 if (AT_class (a
) == dw_val_class_die_ref
)
7333 dw_die_ref targ
= AT_ref (a
);
7334 decl_table_entry
**slot
;
7335 struct decl_table_entry
*entry
;
7337 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7340 slot
= decl_table
.find_slot_with_hash (targ
, htab_hash_pointer (targ
),
7343 if (*slot
!= HTAB_EMPTY_ENTRY
)
7345 /* TARG has already been copied, so we just need to
7346 modify the reference to point to the copy. */
7348 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7352 dw_die_ref parent
= unit
;
7353 dw_die_ref copy
= clone_die (targ
);
7355 /* Record in DECL_TABLE that TARG has been copied.
7356 Need to do this now, before the recursive call,
7357 because DECL_TABLE may be expanded and SLOT
7358 would no longer be a valid pointer. */
7359 entry
= XCNEW (struct decl_table_entry
);
7364 FOR_EACH_CHILD (targ
, c
,
7365 add_child_die (copy
,
7366 clone_tree_hash (c
, decl_table
)));
7368 /* Make sure the cloned tree is marked as part of the
7372 /* If TARG has surrounding context, copy its ancestor tree
7373 into the new type unit. */
7374 if (targ
->die_parent
!= NULL
7375 && !is_unit_die (targ
->die_parent
))
7376 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7379 add_child_die (parent
, copy
);
7380 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7382 /* Make sure the newly-copied DIE is walked. If it was
7383 installed in a previously-added context, it won't
7384 get visited otherwise. */
7387 /* Find the highest point of the newly-added tree,
7388 mark each node along the way, and walk from there. */
7389 parent
->die_mark
= 1;
7390 while (parent
->die_parent
7391 && parent
->die_parent
->die_mark
== 0)
7393 parent
= parent
->die_parent
;
7394 parent
->die_mark
= 1;
7396 copy_decls_walk (unit
, parent
, decl_table
);
7402 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7405 /* Copy declarations for "unworthy" types into the new comdat section.
7406 Incomplete types, modified types, and certain other types aren't broken
7407 out into comdat sections of their own, so they don't have a signature,
7408 and we need to copy the declaration into the same section so that we
7409 don't have an external reference. */
7412 copy_decls_for_unworthy_types (dw_die_ref unit
)
7414 decl_hash_type decl_table
;
7417 decl_table
.create (10);
7418 copy_decls_walk (unit
, unit
, decl_table
);
7419 decl_table
.dispose ();
7423 /* Traverse the DIE and add a sibling attribute if it may have the
7424 effect of speeding up access to siblings. To save some space,
7425 avoid generating sibling attributes for DIE's without children. */
7428 add_sibling_attributes (dw_die_ref die
)
7432 if (! die
->die_child
)
7435 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7436 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7438 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7441 /* Output all location lists for the DIE and its children. */
7444 output_location_lists (dw_die_ref die
)
7450 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7451 if (AT_class (a
) == dw_val_class_loc_list
)
7452 output_loc_list (AT_loc_list (a
));
7454 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7457 /* We want to limit the number of external references, because they are
7458 larger than local references: a relocation takes multiple words, and
7459 even a sig8 reference is always eight bytes, whereas a local reference
7460 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7461 So if we encounter multiple external references to the same type DIE, we
7462 make a local typedef stub for it and redirect all references there.
7464 This is the element of the hash table for keeping track of these
7474 /* Hashtable helpers. */
7476 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7478 typedef external_ref value_type
;
7479 typedef external_ref compare_type
;
7480 static inline hashval_t
hash (const value_type
*);
7481 static inline bool equal (const value_type
*, const compare_type
*);
7485 external_ref_hasher::hash (const value_type
*r
)
7487 dw_die_ref die
= r
->type
;
7490 /* We can't use the address of the DIE for hashing, because
7491 that will make the order of the stub DIEs non-deterministic. */
7492 if (! die
->comdat_type_p
)
7493 /* We have a symbol; use it to compute a hash. */
7494 h
= htab_hash_string (die
->die_id
.die_symbol
);
7497 /* We have a type signature; use a subset of the bits as the hash.
7498 The 8-byte signature is at least as large as hashval_t. */
7499 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7500 memcpy (&h
, type_node
->signature
, sizeof (h
));
7506 external_ref_hasher::equal (const value_type
*r1
, const compare_type
*r2
)
7508 return r1
->type
== r2
->type
;
7511 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7513 /* Return a pointer to the external_ref for references to DIE. */
7515 static struct external_ref
*
7516 lookup_external_ref (external_ref_hash_type map
, dw_die_ref die
)
7518 struct external_ref ref
, *ref_p
;
7519 external_ref
**slot
;
7522 slot
= map
.find_slot (&ref
, INSERT
);
7523 if (*slot
!= HTAB_EMPTY_ENTRY
)
7526 ref_p
= XCNEW (struct external_ref
);
7532 /* Subroutine of optimize_external_refs, below.
7534 If we see a type skeleton, record it as our stub. If we see external
7535 references, remember how many we've seen. */
7538 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type map
)
7543 struct external_ref
*ref_p
;
7545 if (is_type_die (die
)
7546 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7548 /* This is a local skeleton; use it for local references. */
7549 ref_p
= lookup_external_ref (map
, c
);
7553 /* Scan the DIE references, and remember any that refer to DIEs from
7554 other CUs (i.e. those which are not marked). */
7555 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7556 if (AT_class (a
) == dw_val_class_die_ref
7557 && (c
= AT_ref (a
))->die_mark
== 0
7560 ref_p
= lookup_external_ref (map
, c
);
7564 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7567 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7568 points to an external_ref, DATA is the CU we're processing. If we don't
7569 already have a local stub, and we have multiple refs, build a stub. */
7572 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7574 struct external_ref
*ref_p
= *slot
;
7576 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7578 /* We have multiple references to this type, so build a small stub.
7579 Both of these forms are a bit dodgy from the perspective of the
7580 DWARF standard, since technically they should have names. */
7581 dw_die_ref cu
= data
;
7582 dw_die_ref type
= ref_p
->type
;
7583 dw_die_ref stub
= NULL
;
7585 if (type
->comdat_type_p
)
7587 /* If we refer to this type via sig8, use AT_signature. */
7588 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7589 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7593 /* Otherwise, use a typedef with no name. */
7594 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7595 add_AT_die_ref (stub
, DW_AT_type
, type
);
7604 /* DIE is a unit; look through all the DIE references to see if there are
7605 any external references to types, and if so, create local stubs for
7606 them which will be applied in build_abbrev_table. This is useful because
7607 references to local DIEs are smaller. */
7609 static external_ref_hash_type
7610 optimize_external_refs (dw_die_ref die
)
7612 external_ref_hash_type map
;
7614 optimize_external_refs_1 (die
, map
);
7615 map
.traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7619 /* The format of each DIE (and its attribute value pairs) is encoded in an
7620 abbreviation table. This routine builds the abbreviation table and assigns
7621 a unique abbreviation id for each abbreviation entry. The children of each
7622 die are visited recursively. */
7625 build_abbrev_table (dw_die_ref die
, external_ref_hash_type extern_map
)
7627 unsigned long abbrev_id
;
7628 unsigned int n_alloc
;
7633 /* Scan the DIE references, and replace any that refer to
7634 DIEs from other CUs (i.e. those which are not marked) with
7635 the local stubs we built in optimize_external_refs. */
7636 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7637 if (AT_class (a
) == dw_val_class_die_ref
7638 && (c
= AT_ref (a
))->die_mark
== 0)
7640 struct external_ref
*ref_p
;
7641 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7643 ref_p
= lookup_external_ref (extern_map
, c
);
7644 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7645 change_AT_die_ref (a
, ref_p
->stub
);
7647 /* We aren't changing this reference, so mark it external. */
7648 set_AT_ref_external (a
, 1);
7651 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7653 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7654 dw_attr_ref die_a
, abbrev_a
;
7658 if (abbrev
->die_tag
!= die
->die_tag
)
7660 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7663 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7666 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7668 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7669 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7670 || (value_format (abbrev_a
) != value_format (die_a
)))
7680 if (abbrev_id
>= abbrev_die_table_in_use
)
7682 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7684 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7685 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7688 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7689 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7690 abbrev_die_table_allocated
= n_alloc
;
7693 ++abbrev_die_table_in_use
;
7694 abbrev_die_table
[abbrev_id
] = die
;
7697 die
->die_abbrev
= abbrev_id
;
7698 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7701 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7704 constant_size (unsigned HOST_WIDE_INT value
)
7711 log
= floor_log2 (value
);
7714 log
= 1 << (floor_log2 (log
) + 1);
7719 /* Return the size of a DIE as it is represented in the
7720 .debug_info section. */
7722 static unsigned long
7723 size_of_die (dw_die_ref die
)
7725 unsigned long size
= 0;
7728 enum dwarf_form form
;
7730 size
+= size_of_uleb128 (die
->die_abbrev
);
7731 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7733 switch (AT_class (a
))
7735 case dw_val_class_addr
:
7736 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7738 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7739 size
+= size_of_uleb128 (AT_index (a
));
7742 size
+= DWARF2_ADDR_SIZE
;
7744 case dw_val_class_offset
:
7745 size
+= DWARF_OFFSET_SIZE
;
7747 case dw_val_class_loc
:
7749 unsigned long lsize
= size_of_locs (AT_loc (a
));
7752 if (dwarf_version
>= 4)
7753 size
+= size_of_uleb128 (lsize
);
7755 size
+= constant_size (lsize
);
7759 case dw_val_class_loc_list
:
7760 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7762 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7763 size
+= size_of_uleb128 (AT_index (a
));
7766 size
+= DWARF_OFFSET_SIZE
;
7768 case dw_val_class_range_list
:
7769 size
+= DWARF_OFFSET_SIZE
;
7771 case dw_val_class_const
:
7772 size
+= size_of_sleb128 (AT_int (a
));
7774 case dw_val_class_unsigned_const
:
7776 int csize
= constant_size (AT_unsigned (a
));
7777 if (dwarf_version
== 3
7778 && a
->dw_attr
== DW_AT_data_member_location
7780 size
+= size_of_uleb128 (AT_unsigned (a
));
7785 case dw_val_class_const_double
:
7786 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7787 if (HOST_BITS_PER_WIDE_INT
>= 64)
7790 case dw_val_class_vec
:
7791 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7792 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7793 + a
->dw_attr_val
.v
.val_vec
.length
7794 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7796 case dw_val_class_flag
:
7797 if (dwarf_version
>= 4)
7798 /* Currently all add_AT_flag calls pass in 1 as last argument,
7799 so DW_FORM_flag_present can be used. If that ever changes,
7800 we'll need to use DW_FORM_flag and have some optimization
7801 in build_abbrev_table that will change those to
7802 DW_FORM_flag_present if it is set to 1 in all DIEs using
7803 the same abbrev entry. */
7804 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7808 case dw_val_class_die_ref
:
7809 if (AT_ref_external (a
))
7811 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7812 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7813 is sized by target address length, whereas in DWARF3
7814 it's always sized as an offset. */
7815 if (use_debug_types
)
7816 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7817 else if (dwarf_version
== 2)
7818 size
+= DWARF2_ADDR_SIZE
;
7820 size
+= DWARF_OFFSET_SIZE
;
7823 size
+= DWARF_OFFSET_SIZE
;
7825 case dw_val_class_fde_ref
:
7826 size
+= DWARF_OFFSET_SIZE
;
7828 case dw_val_class_lbl_id
:
7829 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7831 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7832 size
+= size_of_uleb128 (AT_index (a
));
7835 size
+= DWARF2_ADDR_SIZE
;
7837 case dw_val_class_lineptr
:
7838 case dw_val_class_macptr
:
7839 size
+= DWARF_OFFSET_SIZE
;
7841 case dw_val_class_str
:
7842 form
= AT_string_form (a
);
7843 if (form
== DW_FORM_strp
)
7844 size
+= DWARF_OFFSET_SIZE
;
7845 else if (form
== DW_FORM_GNU_str_index
)
7846 size
+= size_of_uleb128 (AT_index (a
));
7848 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7850 case dw_val_class_file
:
7851 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7853 case dw_val_class_data8
:
7856 case dw_val_class_vms_delta
:
7857 size
+= DWARF_OFFSET_SIZE
;
7859 case dw_val_class_high_pc
:
7860 size
+= DWARF2_ADDR_SIZE
;
7870 /* Size the debugging information associated with a given DIE. Visits the
7871 DIE's children recursively. Updates the global variable next_die_offset, on
7872 each time through. Uses the current value of next_die_offset to update the
7873 die_offset field in each DIE. */
7876 calc_die_sizes (dw_die_ref die
)
7880 gcc_assert (die
->die_offset
== 0
7881 || (unsigned long int) die
->die_offset
== next_die_offset
);
7882 die
->die_offset
= next_die_offset
;
7883 next_die_offset
+= size_of_die (die
);
7885 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7887 if (die
->die_child
!= NULL
)
7888 /* Count the null byte used to terminate sibling lists. */
7889 next_die_offset
+= 1;
7892 /* Size just the base type children at the start of the CU.
7893 This is needed because build_abbrev needs to size locs
7894 and sizing of type based stack ops needs to know die_offset
7895 values for the base types. */
7898 calc_base_type_die_sizes (void)
7900 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7902 dw_die_ref base_type
;
7903 #if ENABLE_ASSERT_CHECKING
7904 dw_die_ref prev
= comp_unit_die ()->die_child
;
7907 die_offset
+= size_of_die (comp_unit_die ());
7908 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7910 #if ENABLE_ASSERT_CHECKING
7911 gcc_assert (base_type
->die_offset
== 0
7912 && prev
->die_sib
== base_type
7913 && base_type
->die_child
== NULL
7914 && base_type
->die_abbrev
);
7917 base_type
->die_offset
= die_offset
;
7918 die_offset
+= size_of_die (base_type
);
7922 /* Set the marks for a die and its children. We do this so
7923 that we know whether or not a reference needs to use FORM_ref_addr; only
7924 DIEs in the same CU will be marked. We used to clear out the offset
7925 and use that as the flag, but ran into ordering problems. */
7928 mark_dies (dw_die_ref die
)
7932 gcc_assert (!die
->die_mark
);
7935 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7938 /* Clear the marks for a die and its children. */
7941 unmark_dies (dw_die_ref die
)
7945 if (! use_debug_types
)
7946 gcc_assert (die
->die_mark
);
7949 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7952 /* Clear the marks for a die, its children and referred dies. */
7955 unmark_all_dies (dw_die_ref die
)
7965 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7967 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7968 if (AT_class (a
) == dw_val_class_die_ref
)
7969 unmark_all_dies (AT_ref (a
));
7972 /* Calculate if the entry should appear in the final output file. It may be
7973 from a pruned a type. */
7976 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
7978 /* By limiting gnu pubnames to definitions only, gold can generate a
7979 gdb index without entries for declarations, which don't include
7980 enough information to be useful. */
7981 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
7984 if (table
== pubname_table
)
7986 /* Enumerator names are part of the pubname table, but the
7987 parent DW_TAG_enumeration_type die may have been pruned.
7988 Don't output them if that is the case. */
7989 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
7990 (p
->die
->die_parent
== NULL
7991 || !p
->die
->die_parent
->die_perennial_p
))
7994 /* Everything else in the pubname table is included. */
7998 /* The pubtypes table shouldn't include types that have been
8000 return (p
->die
->die_offset
!= 0
8001 || !flag_eliminate_unused_debug_types
);
8004 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8005 generated for the compilation unit. */
8007 static unsigned long
8008 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8013 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8015 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8016 FOR_EACH_VEC_ELT (*names
, i
, p
)
8017 if (include_pubname_in_output (names
, p
))
8018 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8020 size
+= DWARF_OFFSET_SIZE
;
8024 /* Return the size of the information in the .debug_aranges section. */
8026 static unsigned long
8027 size_of_aranges (void)
8031 size
= DWARF_ARANGES_HEADER_SIZE
;
8033 /* Count the address/length pair for this compilation unit. */
8034 if (text_section_used
)
8035 size
+= 2 * DWARF2_ADDR_SIZE
;
8036 if (cold_text_section_used
)
8037 size
+= 2 * DWARF2_ADDR_SIZE
;
8038 if (have_multiple_function_sections
)
8043 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8045 if (DECL_IGNORED_P (fde
->decl
))
8047 if (!fde
->in_std_section
)
8048 size
+= 2 * DWARF2_ADDR_SIZE
;
8049 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8050 size
+= 2 * DWARF2_ADDR_SIZE
;
8054 /* Count the two zero words used to terminated the address range table. */
8055 size
+= 2 * DWARF2_ADDR_SIZE
;
8059 /* Select the encoding of an attribute value. */
8061 static enum dwarf_form
8062 value_format (dw_attr_ref a
)
8064 switch (AT_class (a
))
8066 case dw_val_class_addr
:
8067 /* Only very few attributes allow DW_FORM_addr. */
8072 case DW_AT_entry_pc
:
8073 case DW_AT_trampoline
:
8074 return (AT_index (a
) == NOT_INDEXED
8075 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8079 switch (DWARF2_ADDR_SIZE
)
8082 return DW_FORM_data1
;
8084 return DW_FORM_data2
;
8086 return DW_FORM_data4
;
8088 return DW_FORM_data8
;
8092 case dw_val_class_range_list
:
8093 case dw_val_class_loc_list
:
8094 if (dwarf_version
>= 4)
8095 return DW_FORM_sec_offset
;
8097 case dw_val_class_vms_delta
:
8098 case dw_val_class_offset
:
8099 switch (DWARF_OFFSET_SIZE
)
8102 return DW_FORM_data4
;
8104 return DW_FORM_data8
;
8108 case dw_val_class_loc
:
8109 if (dwarf_version
>= 4)
8110 return DW_FORM_exprloc
;
8111 switch (constant_size (size_of_locs (AT_loc (a
))))
8114 return DW_FORM_block1
;
8116 return DW_FORM_block2
;
8118 return DW_FORM_block4
;
8122 case dw_val_class_const
:
8123 return DW_FORM_sdata
;
8124 case dw_val_class_unsigned_const
:
8125 switch (constant_size (AT_unsigned (a
)))
8128 return DW_FORM_data1
;
8130 return DW_FORM_data2
;
8132 /* In DWARF3 DW_AT_data_member_location with
8133 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8134 constant, so we need to use DW_FORM_udata if we need
8135 a large constant. */
8136 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8137 return DW_FORM_udata
;
8138 return DW_FORM_data4
;
8140 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8141 return DW_FORM_udata
;
8142 return DW_FORM_data8
;
8146 case dw_val_class_const_double
:
8147 switch (HOST_BITS_PER_WIDE_INT
)
8150 return DW_FORM_data2
;
8152 return DW_FORM_data4
;
8154 return DW_FORM_data8
;
8157 return DW_FORM_block1
;
8159 case dw_val_class_vec
:
8160 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8161 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8164 return DW_FORM_block1
;
8166 return DW_FORM_block2
;
8168 return DW_FORM_block4
;
8172 case dw_val_class_flag
:
8173 if (dwarf_version
>= 4)
8175 /* Currently all add_AT_flag calls pass in 1 as last argument,
8176 so DW_FORM_flag_present can be used. If that ever changes,
8177 we'll need to use DW_FORM_flag and have some optimization
8178 in build_abbrev_table that will change those to
8179 DW_FORM_flag_present if it is set to 1 in all DIEs using
8180 the same abbrev entry. */
8181 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8182 return DW_FORM_flag_present
;
8184 return DW_FORM_flag
;
8185 case dw_val_class_die_ref
:
8186 if (AT_ref_external (a
))
8187 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8190 case dw_val_class_fde_ref
:
8191 return DW_FORM_data
;
8192 case dw_val_class_lbl_id
:
8193 return (AT_index (a
) == NOT_INDEXED
8194 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8195 case dw_val_class_lineptr
:
8196 case dw_val_class_macptr
:
8197 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8198 case dw_val_class_str
:
8199 return AT_string_form (a
);
8200 case dw_val_class_file
:
8201 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8204 return DW_FORM_data1
;
8206 return DW_FORM_data2
;
8208 return DW_FORM_data4
;
8213 case dw_val_class_data8
:
8214 return DW_FORM_data8
;
8216 case dw_val_class_high_pc
:
8217 switch (DWARF2_ADDR_SIZE
)
8220 return DW_FORM_data1
;
8222 return DW_FORM_data2
;
8224 return DW_FORM_data4
;
8226 return DW_FORM_data8
;
8236 /* Output the encoding of an attribute value. */
8239 output_value_format (dw_attr_ref a
)
8241 enum dwarf_form form
= value_format (a
);
8243 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8246 /* Given a die and id, produce the appropriate abbreviations. */
8249 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8254 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8255 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8256 dwarf_tag_name (abbrev
->die_tag
));
8258 if (abbrev
->die_child
!= NULL
)
8259 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8261 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8263 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8265 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8266 dwarf_attr_name (a_attr
->dw_attr
));
8267 output_value_format (a_attr
);
8270 dw2_asm_output_data (1, 0, NULL
);
8271 dw2_asm_output_data (1, 0, NULL
);
8275 /* Output the .debug_abbrev section which defines the DIE abbreviation
8279 output_abbrev_section (void)
8281 unsigned long abbrev_id
;
8283 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8284 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8286 /* Terminate the table. */
8287 dw2_asm_output_data (1, 0, NULL
);
8290 /* Output a symbol we can use to refer to this DIE from another CU. */
8293 output_die_symbol (dw_die_ref die
)
8295 const char *sym
= die
->die_id
.die_symbol
;
8297 gcc_assert (!die
->comdat_type_p
);
8302 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8303 /* We make these global, not weak; if the target doesn't support
8304 .linkonce, it doesn't support combining the sections, so debugging
8306 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8308 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8311 /* Return a new location list, given the begin and end range, and the
8314 static inline dw_loc_list_ref
8315 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8316 const char *section
)
8318 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8320 retlist
->begin
= begin
;
8321 retlist
->begin_entry
= NULL
;
8323 retlist
->expr
= expr
;
8324 retlist
->section
= section
;
8329 /* Generate a new internal symbol for this location list node, if it
8330 hasn't got one yet. */
8333 gen_llsym (dw_loc_list_ref list
)
8335 gcc_assert (!list
->ll_symbol
);
8336 list
->ll_symbol
= gen_internal_sym ("LLST");
8339 /* Output the location list given to us. */
8342 output_loc_list (dw_loc_list_ref list_head
)
8344 dw_loc_list_ref curr
= list_head
;
8346 if (list_head
->emitted
)
8348 list_head
->emitted
= true;
8350 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8352 /* Walk the location list, and output each range + expression. */
8353 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8356 /* Don't output an entry that starts and ends at the same address. */
8357 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8359 size
= size_of_locs (curr
->expr
);
8360 /* If the expression is too large, drop it on the floor. We could
8361 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8362 in the expression, but >= 64KB expressions for a single value
8363 in a single range are unlikely very useful. */
8366 if (dwarf_split_debug_info
)
8368 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8369 "Location list start/length entry (%s)",
8370 list_head
->ll_symbol
);
8371 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8372 "Location list range start index (%s)",
8374 /* The length field is 4 bytes. If we ever need to support
8375 an 8-byte length, we can add a new DW_LLE code or fall back
8376 to DW_LLE_GNU_start_end_entry. */
8377 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8378 "Location list range length (%s)",
8379 list_head
->ll_symbol
);
8381 else if (!have_multiple_function_sections
)
8383 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8384 "Location list begin address (%s)",
8385 list_head
->ll_symbol
);
8386 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8387 "Location list end address (%s)",
8388 list_head
->ll_symbol
);
8392 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8393 "Location list begin address (%s)",
8394 list_head
->ll_symbol
);
8395 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8396 "Location list end address (%s)",
8397 list_head
->ll_symbol
);
8400 /* Output the block length for this list of location operations. */
8401 gcc_assert (size
<= 0xffff);
8402 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8404 output_loc_sequence (curr
->expr
, -1);
8407 if (dwarf_split_debug_info
)
8408 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8409 "Location list terminator (%s)",
8410 list_head
->ll_symbol
);
8413 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8414 "Location list terminator begin (%s)",
8415 list_head
->ll_symbol
);
8416 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8417 "Location list terminator end (%s)",
8418 list_head
->ll_symbol
);
8422 /* Output a range_list offset into the debug_range section. Emit a
8423 relocated reference if val_entry is NULL, otherwise, emit an
8424 indirect reference. */
8427 output_range_list_offset (dw_attr_ref a
)
8429 const char *name
= dwarf_attr_name (a
->dw_attr
);
8431 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8433 char *p
= strchr (ranges_section_label
, '\0');
8434 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8435 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8436 debug_ranges_section
, "%s", name
);
8440 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8441 "%s (offset from %s)", name
, ranges_section_label
);
8444 /* Output the offset into the debug_loc section. */
8447 output_loc_list_offset (dw_attr_ref a
)
8449 char *sym
= AT_loc_list (a
)->ll_symbol
;
8452 if (dwarf_split_debug_info
)
8453 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8454 "%s", dwarf_attr_name (a
->dw_attr
));
8456 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8457 "%s", dwarf_attr_name (a
->dw_attr
));
8460 /* Output an attribute's index or value appropriately. */
8463 output_attr_index_or_value (dw_attr_ref a
)
8465 const char *name
= dwarf_attr_name (a
->dw_attr
);
8467 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8469 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8472 switch (AT_class (a
))
8474 case dw_val_class_addr
:
8475 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8477 case dw_val_class_high_pc
:
8478 case dw_val_class_lbl_id
:
8479 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8481 case dw_val_class_loc_list
:
8482 output_loc_list_offset (a
);
8489 /* Output a type signature. */
8492 output_signature (const char *sig
, const char *name
)
8496 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8497 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8500 /* Output the DIE and its attributes. Called recursively to generate
8501 the definitions of each child DIE. */
8504 output_die (dw_die_ref die
)
8511 /* If someone in another CU might refer to us, set up a symbol for
8512 them to point to. */
8513 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8514 output_die_symbol (die
);
8516 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8517 (unsigned long)die
->die_offset
,
8518 dwarf_tag_name (die
->die_tag
));
8520 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8522 const char *name
= dwarf_attr_name (a
->dw_attr
);
8524 switch (AT_class (a
))
8526 case dw_val_class_addr
:
8527 output_attr_index_or_value (a
);
8530 case dw_val_class_offset
:
8531 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8535 case dw_val_class_range_list
:
8536 output_range_list_offset (a
);
8539 case dw_val_class_loc
:
8540 size
= size_of_locs (AT_loc (a
));
8542 /* Output the block length for this list of location operations. */
8543 if (dwarf_version
>= 4)
8544 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8546 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8548 output_loc_sequence (AT_loc (a
), -1);
8551 case dw_val_class_const
:
8552 /* ??? It would be slightly more efficient to use a scheme like is
8553 used for unsigned constants below, but gdb 4.x does not sign
8554 extend. Gdb 5.x does sign extend. */
8555 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8558 case dw_val_class_unsigned_const
:
8560 int csize
= constant_size (AT_unsigned (a
));
8561 if (dwarf_version
== 3
8562 && a
->dw_attr
== DW_AT_data_member_location
8564 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8566 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8570 case dw_val_class_const_double
:
8572 unsigned HOST_WIDE_INT first
, second
;
8574 if (HOST_BITS_PER_WIDE_INT
>= 64)
8575 dw2_asm_output_data (1,
8576 HOST_BITS_PER_DOUBLE_INT
8577 / HOST_BITS_PER_CHAR
,
8580 if (WORDS_BIG_ENDIAN
)
8582 first
= a
->dw_attr_val
.v
.val_double
.high
;
8583 second
= a
->dw_attr_val
.v
.val_double
.low
;
8587 first
= a
->dw_attr_val
.v
.val_double
.low
;
8588 second
= a
->dw_attr_val
.v
.val_double
.high
;
8591 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8593 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8598 case dw_val_class_vec
:
8600 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8601 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8605 dw2_asm_output_data (constant_size (len
* elt_size
),
8606 len
* elt_size
, "%s", name
);
8607 if (elt_size
> sizeof (HOST_WIDE_INT
))
8612 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8615 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8616 "fp or vector constant word %u", i
);
8620 case dw_val_class_flag
:
8621 if (dwarf_version
>= 4)
8623 /* Currently all add_AT_flag calls pass in 1 as last argument,
8624 so DW_FORM_flag_present can be used. If that ever changes,
8625 we'll need to use DW_FORM_flag and have some optimization
8626 in build_abbrev_table that will change those to
8627 DW_FORM_flag_present if it is set to 1 in all DIEs using
8628 the same abbrev entry. */
8629 gcc_assert (AT_flag (a
) == 1);
8631 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8632 ASM_COMMENT_START
, name
);
8635 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8638 case dw_val_class_loc_list
:
8639 output_attr_index_or_value (a
);
8642 case dw_val_class_die_ref
:
8643 if (AT_ref_external (a
))
8645 if (AT_ref (a
)->comdat_type_p
)
8647 comdat_type_node_ref type_node
=
8648 AT_ref (a
)->die_id
.die_type_node
;
8650 gcc_assert (type_node
);
8651 output_signature (type_node
->signature
, name
);
8655 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8659 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8660 length, whereas in DWARF3 it's always sized as an
8662 if (dwarf_version
== 2)
8663 size
= DWARF2_ADDR_SIZE
;
8665 size
= DWARF_OFFSET_SIZE
;
8666 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8672 gcc_assert (AT_ref (a
)->die_offset
);
8673 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8678 case dw_val_class_fde_ref
:
8682 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8683 a
->dw_attr_val
.v
.val_fde_index
* 2);
8684 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8689 case dw_val_class_vms_delta
:
8690 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8691 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8695 case dw_val_class_lbl_id
:
8696 output_attr_index_or_value (a
);
8699 case dw_val_class_lineptr
:
8700 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8701 debug_line_section
, "%s", name
);
8704 case dw_val_class_macptr
:
8705 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8706 debug_macinfo_section
, "%s", name
);
8709 case dw_val_class_str
:
8710 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8711 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8712 a
->dw_attr_val
.v
.val_str
->label
,
8714 "%s: \"%s\"", name
, AT_string (a
));
8715 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8716 dw2_asm_output_data_uleb128 (AT_index (a
),
8717 "%s: \"%s\"", name
, AT_string (a
));
8719 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8722 case dw_val_class_file
:
8724 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8726 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8727 a
->dw_attr_val
.v
.val_file
->filename
);
8731 case dw_val_class_data8
:
8735 for (i
= 0; i
< 8; i
++)
8736 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8737 i
== 0 ? "%s" : NULL
, name
);
8741 case dw_val_class_high_pc
:
8742 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8743 get_AT_low_pc (die
), "DW_AT_high_pc");
8751 FOR_EACH_CHILD (die
, c
, output_die (c
));
8753 /* Add null byte to terminate sibling list. */
8754 if (die
->die_child
!= NULL
)
8755 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8756 (unsigned long) die
->die_offset
);
8759 /* Output the compilation unit that appears at the beginning of the
8760 .debug_info section, and precedes the DIE descriptions. */
8763 output_compilation_unit_header (void)
8765 int ver
= dwarf_version
;
8767 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8768 dw2_asm_output_data (4, 0xffffffff,
8769 "Initial length escape value indicating 64-bit DWARF extension");
8770 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8771 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8772 "Length of Compilation Unit Info");
8773 dw2_asm_output_data (2, ver
, "DWARF version number");
8774 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8775 debug_abbrev_section
,
8776 "Offset Into Abbrev. Section");
8777 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8780 /* Output the compilation unit DIE and its children. */
8783 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8785 const char *secname
, *oldsym
;
8787 external_ref_hash_type extern_map
;
8789 /* Unless we are outputting main CU, we may throw away empty ones. */
8790 if (!output_if_empty
&& die
->die_child
== NULL
)
8793 /* Even if there are no children of this DIE, we must output the information
8794 about the compilation unit. Otherwise, on an empty translation unit, we
8795 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8796 will then complain when examining the file. First mark all the DIEs in
8797 this CU so we know which get local refs. */
8800 extern_map
= optimize_external_refs (die
);
8802 build_abbrev_table (die
, extern_map
);
8804 extern_map
.dispose ();
8806 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8807 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8808 calc_die_sizes (die
);
8810 oldsym
= die
->die_id
.die_symbol
;
8813 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8815 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8817 die
->die_id
.die_symbol
= NULL
;
8818 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8822 switch_to_section (debug_info_section
);
8823 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8824 info_section_emitted
= true;
8827 /* Output debugging information. */
8828 output_compilation_unit_header ();
8831 /* Leave the marks on the main CU, so we can check them in
8836 die
->die_id
.die_symbol
= oldsym
;
8840 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8841 and .debug_pubtypes. This is configured per-target, but can be
8842 overridden by the -gpubnames or -gno-pubnames options. */
8845 want_pubnames (void)
8847 if (debug_generate_pub_sections
!= -1)
8848 return debug_generate_pub_sections
;
8849 return targetm
.want_debug_pub_sections
;
8852 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8855 add_AT_pubnames (dw_die_ref die
)
8857 if (want_pubnames ())
8858 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8861 /* Add a string attribute value to a skeleton DIE. */
8864 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8868 struct indirect_string_node
*node
;
8870 if (! skeleton_debug_str_hash
)
8871 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
8872 debug_str_eq
, NULL
);
8874 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
8875 find_string_form (node
);
8876 if (node
->form
== DW_FORM_GNU_str_index
)
8877 node
->form
= DW_FORM_strp
;
8879 attr
.dw_attr
= attr_kind
;
8880 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
8881 attr
.dw_attr_val
.val_entry
= NULL
;
8882 attr
.dw_attr_val
.v
.val_str
= node
;
8883 add_dwarf_attr (die
, &attr
);
8886 /* Helper function to generate top-level dies for skeleton debug_info and
8890 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8892 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8893 const char *comp_dir
= comp_dir_string ();
8895 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8896 if (comp_dir
!= NULL
)
8897 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
8898 add_AT_pubnames (die
);
8899 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8902 /* Return the single type-unit die for skeleton type units. */
8905 get_skeleton_type_unit (void)
8907 /* For dwarf_split_debug_sections with use_type info, all type units in the
8908 skeleton sections have identical dies (but different headers). This
8909 single die will be output many times. */
8911 static dw_die_ref skeleton_type_unit
= NULL
;
8913 if (skeleton_type_unit
== NULL
)
8915 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8916 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8917 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8919 return skeleton_type_unit
;
8922 /* Output skeleton debug sections that point to the dwo file. */
8925 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8927 /* These attributes will be found in the full debug_info section. */
8928 remove_AT (comp_unit
, DW_AT_producer
);
8929 remove_AT (comp_unit
, DW_AT_language
);
8931 switch_to_section (debug_skeleton_info_section
);
8932 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8934 /* Produce the skeleton compilation-unit header. This one differs enough from
8935 a normal CU header that it's better not to call output_compilation_unit
8937 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8938 dw2_asm_output_data (4, 0xffffffff,
8939 "Initial length escape value indicating 64-bit DWARF extension");
8941 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8942 DWARF_COMPILE_UNIT_HEADER_SIZE
8943 - DWARF_INITIAL_LENGTH_SIZE
8944 + size_of_die (comp_unit
),
8945 "Length of Compilation Unit Info");
8946 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8947 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8948 debug_abbrev_section
,
8949 "Offset Into Abbrev. Section");
8950 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8952 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8953 output_die (comp_unit
);
8955 /* Build the skeleton debug_abbrev section. */
8956 switch_to_section (debug_skeleton_abbrev_section
);
8957 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8959 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8960 if (use_debug_types
)
8961 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8963 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8966 /* Output a comdat type unit DIE and its children. */
8969 output_comdat_type_unit (comdat_type_node
*node
)
8971 const char *secname
;
8974 #if defined (OBJECT_FORMAT_ELF)
8977 external_ref_hash_type extern_map
;
8979 /* First mark all the DIEs in this CU so we know which get local refs. */
8980 mark_dies (node
->root_die
);
8982 extern_map
= optimize_external_refs (node
->root_die
);
8984 build_abbrev_table (node
->root_die
, extern_map
);
8986 extern_map
.dispose ();
8988 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8989 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8990 calc_die_sizes (node
->root_die
);
8992 #if defined (OBJECT_FORMAT_ELF)
8993 if (!dwarf_split_debug_info
)
8994 secname
= ".debug_types";
8996 secname
= ".debug_types.dwo";
8998 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8999 sprintf (tmp
, "wt.");
9000 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9001 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9002 comdat_key
= get_identifier (tmp
);
9003 targetm
.asm_out
.named_section (secname
,
9004 SECTION_DEBUG
| SECTION_LINKONCE
,
9007 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9008 sprintf (tmp
, ".gnu.linkonce.wt.");
9009 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9010 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9012 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9015 /* Output debugging information. */
9016 output_compilation_unit_header ();
9017 output_signature (node
->signature
, "Type Signature");
9018 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9019 "Offset to Type DIE");
9020 output_die (node
->root_die
);
9022 unmark_dies (node
->root_die
);
9024 #if defined (OBJECT_FORMAT_ELF)
9025 if (dwarf_split_debug_info
)
9027 /* Produce the skeleton type-unit header. */
9028 const char *secname
= ".debug_types";
9030 targetm
.asm_out
.named_section (secname
,
9031 SECTION_DEBUG
| SECTION_LINKONCE
,
9033 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9034 dw2_asm_output_data (4, 0xffffffff,
9035 "Initial length escape value indicating 64-bit DWARF extension");
9037 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9038 DWARF_COMPILE_UNIT_HEADER_SIZE
9039 - DWARF_INITIAL_LENGTH_SIZE
9040 + size_of_die (get_skeleton_type_unit ())
9041 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
9042 "Length of Type Unit Info");
9043 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9044 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9045 debug_skeleton_abbrev_section_label
,
9046 debug_abbrev_section
,
9047 "Offset Into Abbrev. Section");
9048 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9049 output_signature (node
->signature
, "Type Signature");
9050 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
9052 output_die (get_skeleton_type_unit ());
9057 /* Return the DWARF2/3 pubname associated with a decl. */
9060 dwarf2_name (tree decl
, int scope
)
9062 if (DECL_NAMELESS (decl
))
9064 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9067 /* Add a new entry to .debug_pubnames if appropriate. */
9070 add_pubname_string (const char *str
, dw_die_ref die
)
9075 e
.name
= xstrdup (str
);
9076 vec_safe_push (pubname_table
, e
);
9080 add_pubname (tree decl
, dw_die_ref die
)
9082 if (!want_pubnames ())
9085 /* Don't add items to the table when we expect that the consumer will have
9086 just read the enclosing die. For example, if the consumer is looking at a
9087 class_member, it will either be inside the class already, or will have just
9088 looked up the class to find the member. Either way, searching the class is
9089 faster than searching the index. */
9090 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9091 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9093 const char *name
= dwarf2_name (decl
, 1);
9096 add_pubname_string (name
, die
);
9100 /* Add an enumerator to the pubnames section. */
9103 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9107 gcc_assert (scope_name
);
9108 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9110 vec_safe_push (pubname_table
, e
);
9113 /* Add a new entry to .debug_pubtypes if appropriate. */
9116 add_pubtype (tree decl
, dw_die_ref die
)
9120 if (!want_pubnames ())
9123 if ((TREE_PUBLIC (decl
)
9124 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9125 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9128 const char *scope_name
= "";
9129 const char *sep
= is_cxx () ? "::" : ".";
9132 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9133 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9135 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9136 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9137 scope_name
= concat (scope_name
, sep
, NULL
);
9143 name
= type_tag (decl
);
9145 name
= lang_hooks
.dwarf_name (decl
, 1);
9147 /* If we don't have a name for the type, there's no point in adding
9149 if (name
!= NULL
&& name
[0] != '\0')
9152 e
.name
= concat (scope_name
, name
, NULL
);
9153 vec_safe_push (pubtype_table
, e
);
9156 /* Although it might be more consistent to add the pubinfo for the
9157 enumerators as their dies are created, they should only be added if the
9158 enum type meets the criteria above. So rather than re-check the parent
9159 enum type whenever an enumerator die is created, just output them all
9160 here. This isn't protected by the name conditional because anonymous
9161 enums don't have names. */
9162 if (die
->die_tag
== DW_TAG_enumeration_type
)
9166 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9171 /* Output a single entry in the pubnames table. */
9174 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9176 dw_die_ref die
= entry
->die
;
9177 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9179 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9181 if (debug_generate_pub_sections
== 2)
9183 /* This logic follows gdb's method for determining the value of the flag
9185 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9186 switch (die
->die_tag
)
9188 case DW_TAG_typedef
:
9189 case DW_TAG_base_type
:
9190 case DW_TAG_subrange_type
:
9191 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9192 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9194 case DW_TAG_enumerator
:
9195 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9196 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9197 if (!is_cxx () && !is_java ())
9198 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9200 case DW_TAG_subprogram
:
9201 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9202 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9204 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9206 case DW_TAG_constant
:
9207 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9208 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9209 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9211 case DW_TAG_variable
:
9212 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9213 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9214 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9216 case DW_TAG_namespace
:
9217 case DW_TAG_imported_declaration
:
9218 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9220 case DW_TAG_class_type
:
9221 case DW_TAG_interface_type
:
9222 case DW_TAG_structure_type
:
9223 case DW_TAG_union_type
:
9224 case DW_TAG_enumeration_type
:
9225 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9226 if (!is_cxx () && !is_java ())
9227 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9230 /* An unusual tag. Leave the flag-byte empty. */
9233 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9237 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9241 /* Output the public names table used to speed up access to externally
9242 visible names; or the public types table used to find type definitions. */
9245 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9248 unsigned long pubnames_length
= size_of_pubnames (names
);
9251 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9252 dw2_asm_output_data (4, 0xffffffff,
9253 "Initial length escape value indicating 64-bit DWARF extension");
9254 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9256 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9257 dw2_asm_output_data (2, 2, "DWARF Version");
9259 if (dwarf_split_debug_info
)
9260 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9261 debug_skeleton_info_section
,
9262 "Offset of Compilation Unit Info");
9264 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9266 "Offset of Compilation Unit Info");
9267 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9268 "Compilation Unit Length");
9270 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9272 if (include_pubname_in_output (names
, pub
))
9274 dw_offset die_offset
= pub
->die
->die_offset
;
9276 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9277 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9278 gcc_assert (pub
->die
->die_mark
);
9280 /* If we're putting types in their own .debug_types sections,
9281 the .debug_pubtypes table will still point to the compile
9282 unit (not the type unit), so we want to use the offset of
9283 the skeleton DIE (if there is one). */
9284 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9286 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9288 if (type_node
!= NULL
)
9289 die_offset
= (type_node
->skeleton_die
!= NULL
9290 ? type_node
->skeleton_die
->die_offset
9294 output_pubname (die_offset
, pub
);
9298 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9301 /* Output public names and types tables if necessary. */
9304 output_pubtables (void)
9306 if (!want_pubnames () || !info_section_emitted
)
9309 switch_to_section (debug_pubnames_section
);
9310 output_pubnames (pubname_table
);
9311 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9312 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9313 simply won't look for the section. */
9314 switch_to_section (debug_pubtypes_section
);
9315 output_pubnames (pubtype_table
);
9319 /* Output the information that goes into the .debug_aranges table.
9320 Namely, define the beginning and ending address range of the
9321 text section generated for this compilation unit. */
9324 output_aranges (unsigned long aranges_length
)
9328 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9329 dw2_asm_output_data (4, 0xffffffff,
9330 "Initial length escape value indicating 64-bit DWARF extension");
9331 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9332 "Length of Address Ranges Info");
9333 /* Version number for aranges is still 2, even in DWARF3. */
9334 dw2_asm_output_data (2, 2, "DWARF Version");
9335 if (dwarf_split_debug_info
)
9336 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9337 debug_skeleton_info_section
,
9338 "Offset of Compilation Unit Info");
9340 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9342 "Offset of Compilation Unit Info");
9343 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9344 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9346 /* We need to align to twice the pointer size here. */
9347 if (DWARF_ARANGES_PAD_SIZE
)
9349 /* Pad using a 2 byte words so that padding is correct for any
9351 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9352 2 * DWARF2_ADDR_SIZE
);
9353 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9354 dw2_asm_output_data (2, 0, NULL
);
9357 /* It is necessary not to output these entries if the sections were
9358 not used; if the sections were not used, the length will be 0 and
9359 the address may end up as 0 if the section is discarded by ld
9360 --gc-sections, leaving an invalid (0, 0) entry that can be
9361 confused with the terminator. */
9362 if (text_section_used
)
9364 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9365 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9366 text_section_label
, "Length");
9368 if (cold_text_section_used
)
9370 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9372 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9373 cold_text_section_label
, "Length");
9376 if (have_multiple_function_sections
)
9381 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9383 if (DECL_IGNORED_P (fde
->decl
))
9385 if (!fde
->in_std_section
)
9387 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9389 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9390 fde
->dw_fde_begin
, "Length");
9392 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9394 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9396 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9397 fde
->dw_fde_second_begin
, "Length");
9402 /* Output the terminator words. */
9403 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9404 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9407 /* Add a new entry to .debug_ranges. Return the offset at which it
9411 add_ranges_num (int num
)
9413 unsigned int in_use
= ranges_table_in_use
;
9415 if (in_use
== ranges_table_allocated
)
9417 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9418 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9419 ranges_table_allocated
);
9420 memset (ranges_table
+ ranges_table_in_use
, 0,
9421 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9424 ranges_table
[in_use
].num
= num
;
9425 ranges_table_in_use
= in_use
+ 1;
9427 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9430 /* Add a new entry to .debug_ranges corresponding to a block, or a
9431 range terminator if BLOCK is NULL. */
9434 add_ranges (const_tree block
)
9436 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9439 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9440 When using dwarf_split_debug_info, address attributes in dies destined
9441 for the final executable should be direct references--setting the
9442 parameter force_direct ensures this behavior. */
9445 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9446 bool *added
, bool force_direct
)
9448 unsigned int in_use
= ranges_by_label_in_use
;
9449 unsigned int offset
;
9451 if (in_use
== ranges_by_label_allocated
)
9453 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9454 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9456 ranges_by_label_allocated
);
9457 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9458 RANGES_TABLE_INCREMENT
9459 * sizeof (struct dw_ranges_by_label_struct
));
9462 ranges_by_label
[in_use
].begin
= begin
;
9463 ranges_by_label
[in_use
].end
= end
;
9464 ranges_by_label_in_use
= in_use
+ 1;
9466 offset
= add_ranges_num (-(int)in_use
- 1);
9469 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9475 output_ranges (void)
9478 static const char *const start_fmt
= "Offset %#x";
9479 const char *fmt
= start_fmt
;
9481 for (i
= 0; i
< ranges_table_in_use
; i
++)
9483 int block_num
= ranges_table
[i
].num
;
9487 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9488 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9490 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9491 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9493 /* If all code is in the text section, then the compilation
9494 unit base address defaults to DW_AT_low_pc, which is the
9495 base of the text section. */
9496 if (!have_multiple_function_sections
)
9498 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9500 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9501 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9502 text_section_label
, NULL
);
9505 /* Otherwise, the compilation unit base address is zero,
9506 which allows us to use absolute addresses, and not worry
9507 about whether the target supports cross-section
9511 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9512 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9513 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9519 /* Negative block_num stands for an index into ranges_by_label. */
9520 else if (block_num
< 0)
9522 int lab_idx
= - block_num
- 1;
9524 if (!have_multiple_function_sections
)
9528 /* If we ever use add_ranges_by_labels () for a single
9529 function section, all we have to do is to take out
9531 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9532 ranges_by_label
[lab_idx
].begin
,
9534 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9535 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9536 ranges_by_label
[lab_idx
].end
,
9537 text_section_label
, NULL
);
9542 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9543 ranges_by_label
[lab_idx
].begin
,
9544 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9545 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9546 ranges_by_label
[lab_idx
].end
,
9552 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9553 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9559 /* Data structure containing information about input files. */
9562 const char *path
; /* Complete file name. */
9563 const char *fname
; /* File name part. */
9564 int length
; /* Length of entire string. */
9565 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9566 int dir_idx
; /* Index in directory table. */
9569 /* Data structure containing information about directories with source
9573 const char *path
; /* Path including directory name. */
9574 int length
; /* Path length. */
9575 int prefix
; /* Index of directory entry which is a prefix. */
9576 int count
; /* Number of files in this directory. */
9577 int dir_idx
; /* Index of directory used as base. */
9580 /* Callback function for file_info comparison. We sort by looking at
9581 the directories in the path. */
9584 file_info_cmp (const void *p1
, const void *p2
)
9586 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9587 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9588 const unsigned char *cp1
;
9589 const unsigned char *cp2
;
9591 /* Take care of file names without directories. We need to make sure that
9592 we return consistent values to qsort since some will get confused if
9593 we return the same value when identical operands are passed in opposite
9594 orders. So if neither has a directory, return 0 and otherwise return
9595 1 or -1 depending on which one has the directory. */
9596 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9597 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9599 cp1
= (const unsigned char *) s1
->path
;
9600 cp2
= (const unsigned char *) s2
->path
;
9606 /* Reached the end of the first path? If so, handle like above. */
9607 if ((cp1
== (const unsigned char *) s1
->fname
)
9608 || (cp2
== (const unsigned char *) s2
->fname
))
9609 return ((cp2
== (const unsigned char *) s2
->fname
)
9610 - (cp1
== (const unsigned char *) s1
->fname
));
9612 /* Character of current path component the same? */
9613 else if (*cp1
!= *cp2
)
9618 struct file_name_acquire_data
9620 struct file_info
*files
;
9625 /* Traversal function for the hash table. */
9628 file_name_acquire (void ** slot
, void *data
)
9630 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9631 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9632 struct file_info
*fi
;
9635 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9637 if (! d
->emitted_number
)
9640 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9642 fi
= fnad
->files
+ fnad
->used_files
++;
9644 /* Skip all leading "./". */
9646 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9649 /* Create a new array entry. */
9651 fi
->length
= strlen (f
);
9654 /* Search for the file name part. */
9655 f
= strrchr (f
, DIR_SEPARATOR
);
9656 #if defined (DIR_SEPARATOR_2)
9658 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9662 if (f
== NULL
|| f
< g
)
9668 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9672 /* Output the directory table and the file name table. We try to minimize
9673 the total amount of memory needed. A heuristic is used to avoid large
9674 slowdowns with many input files. */
9677 output_file_names (void)
9679 struct file_name_acquire_data fnad
;
9681 struct file_info
*files
;
9682 struct dir_info
*dirs
;
9690 if (!last_emitted_file
)
9692 dw2_asm_output_data (1, 0, "End directory table");
9693 dw2_asm_output_data (1, 0, "End file name table");
9697 numfiles
= last_emitted_file
->emitted_number
;
9699 /* Allocate the various arrays we need. */
9700 files
= XALLOCAVEC (struct file_info
, numfiles
);
9701 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9704 fnad
.used_files
= 0;
9705 fnad
.max_files
= numfiles
;
9706 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9707 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9709 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9711 /* Find all the different directories used. */
9712 dirs
[0].path
= files
[0].path
;
9713 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9714 dirs
[0].prefix
= -1;
9716 dirs
[0].dir_idx
= 0;
9717 files
[0].dir_idx
= 0;
9720 for (i
= 1; i
< numfiles
; i
++)
9721 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9722 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9723 dirs
[ndirs
- 1].length
) == 0)
9725 /* Same directory as last entry. */
9726 files
[i
].dir_idx
= ndirs
- 1;
9727 ++dirs
[ndirs
- 1].count
;
9733 /* This is a new directory. */
9734 dirs
[ndirs
].path
= files
[i
].path
;
9735 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9736 dirs
[ndirs
].count
= 1;
9737 dirs
[ndirs
].dir_idx
= ndirs
;
9738 files
[i
].dir_idx
= ndirs
;
9740 /* Search for a prefix. */
9741 dirs
[ndirs
].prefix
= -1;
9742 for (j
= 0; j
< ndirs
; j
++)
9743 if (dirs
[j
].length
< dirs
[ndirs
].length
9744 && dirs
[j
].length
> 1
9745 && (dirs
[ndirs
].prefix
== -1
9746 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9747 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9748 dirs
[ndirs
].prefix
= j
;
9753 /* Now to the actual work. We have to find a subset of the directories which
9754 allow expressing the file name using references to the directory table
9755 with the least amount of characters. We do not do an exhaustive search
9756 where we would have to check out every combination of every single
9757 possible prefix. Instead we use a heuristic which provides nearly optimal
9758 results in most cases and never is much off. */
9759 saved
= XALLOCAVEC (int, ndirs
);
9760 savehere
= XALLOCAVEC (int, ndirs
);
9762 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9763 for (i
= 0; i
< ndirs
; i
++)
9768 /* We can always save some space for the current directory. But this
9769 does not mean it will be enough to justify adding the directory. */
9770 savehere
[i
] = dirs
[i
].length
;
9771 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9773 for (j
= i
+ 1; j
< ndirs
; j
++)
9776 if (saved
[j
] < dirs
[i
].length
)
9778 /* Determine whether the dirs[i] path is a prefix of the
9783 while (k
!= -1 && k
!= (int) i
)
9788 /* Yes it is. We can possibly save some memory by
9789 writing the filenames in dirs[j] relative to
9791 savehere
[j
] = dirs
[i
].length
;
9792 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9797 /* Check whether we can save enough to justify adding the dirs[i]
9799 if (total
> dirs
[i
].length
+ 1)
9801 /* It's worthwhile adding. */
9802 for (j
= i
; j
< ndirs
; j
++)
9803 if (savehere
[j
] > 0)
9805 /* Remember how much we saved for this directory so far. */
9806 saved
[j
] = savehere
[j
];
9808 /* Remember the prefix directory. */
9809 dirs
[j
].dir_idx
= i
;
9814 /* Emit the directory name table. */
9815 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9816 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9817 dw2_asm_output_nstring (dirs
[i
].path
,
9819 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9820 "Directory Entry: %#x", i
+ idx_offset
);
9822 dw2_asm_output_data (1, 0, "End directory table");
9824 /* We have to emit them in the order of emitted_number since that's
9825 used in the debug info generation. To do this efficiently we
9826 generate a back-mapping of the indices first. */
9827 backmap
= XALLOCAVEC (int, numfiles
);
9828 for (i
= 0; i
< numfiles
; i
++)
9829 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9831 /* Now write all the file names. */
9832 for (i
= 0; i
< numfiles
; i
++)
9834 int file_idx
= backmap
[i
];
9835 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9837 #ifdef VMS_DEBUGGING_INFO
9838 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9840 /* Setting these fields can lead to debugger miscomparisons,
9841 but VMS Debug requires them to be set correctly. */
9846 int maxfilelen
= strlen (files
[file_idx
].path
)
9847 + dirs
[dir_idx
].length
9848 + MAX_VMS_VERSION_LEN
+ 1;
9849 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9851 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9852 snprintf (filebuf
, maxfilelen
, "%s;%d",
9853 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9855 dw2_asm_output_nstring
9856 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9858 /* Include directory index. */
9859 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9861 /* Modification time. */
9862 dw2_asm_output_data_uleb128
9863 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9867 /* File length in bytes. */
9868 dw2_asm_output_data_uleb128
9869 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9873 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9874 "File Entry: %#x", (unsigned) i
+ 1);
9876 /* Include directory index. */
9877 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9879 /* Modification time. */
9880 dw2_asm_output_data_uleb128 (0, NULL
);
9882 /* File length in bytes. */
9883 dw2_asm_output_data_uleb128 (0, NULL
);
9884 #endif /* VMS_DEBUGGING_INFO */
9887 dw2_asm_output_data (1, 0, "End file name table");
9891 /* Output one line number table into the .debug_line section. */
9894 output_one_line_info_table (dw_line_info_table
*table
)
9896 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9897 unsigned int current_line
= 1;
9898 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9899 dw_line_info_entry
*ent
;
9902 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9904 switch (ent
->opcode
)
9906 case LI_set_address
:
9907 /* ??? Unfortunately, we have little choice here currently, and
9908 must always use the most general form. GCC does not know the
9909 address delta itself, so we can't use DW_LNS_advance_pc. Many
9910 ports do have length attributes which will give an upper bound
9911 on the address range. We could perhaps use length attributes
9912 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9913 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9915 /* This can handle any delta. This takes
9916 4+DWARF2_ADDR_SIZE bytes. */
9917 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9918 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9919 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9920 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9924 if (ent
->val
== current_line
)
9926 /* We still need to start a new row, so output a copy insn. */
9927 dw2_asm_output_data (1, DW_LNS_copy
,
9928 "copy line %u", current_line
);
9932 int line_offset
= ent
->val
- current_line
;
9933 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9935 current_line
= ent
->val
;
9936 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9938 /* This can handle deltas from -10 to 234, using the current
9939 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9940 This takes 1 byte. */
9941 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9942 "line %u", current_line
);
9946 /* This can handle any delta. This takes at least 4 bytes,
9947 depending on the value being encoded. */
9948 dw2_asm_output_data (1, DW_LNS_advance_line
,
9949 "advance to line %u", current_line
);
9950 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9951 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9957 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9958 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9962 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9963 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9966 case LI_negate_stmt
:
9967 current_is_stmt
= !current_is_stmt
;
9968 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9969 "is_stmt %d", current_is_stmt
);
9972 case LI_set_prologue_end
:
9973 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9974 "set prologue end");
9977 case LI_set_epilogue_begin
:
9978 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9979 "set epilogue begin");
9982 case LI_set_discriminator
:
9983 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9984 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9985 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9986 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9991 /* Emit debug info for the address of the end of the table. */
9992 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9993 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9994 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9995 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9997 dw2_asm_output_data (1, 0, "end sequence");
9998 dw2_asm_output_data_uleb128 (1, NULL
);
9999 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10002 /* Output the source line number correspondence information. This
10003 information goes into the .debug_line section. */
10006 output_line_info (bool prologue_only
)
10008 char l1
[20], l2
[20], p1
[20], p2
[20];
10009 int ver
= dwarf_version
;
10010 bool saw_one
= false;
10013 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10014 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10015 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10016 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10018 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10019 dw2_asm_output_data (4, 0xffffffff,
10020 "Initial length escape value indicating 64-bit DWARF extension");
10021 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10022 "Length of Source Line Info");
10023 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10025 dw2_asm_output_data (2, ver
, "DWARF Version");
10026 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10027 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10029 /* Define the architecture-dependent minimum instruction length (in bytes).
10030 In this implementation of DWARF, this field is used for information
10031 purposes only. Since GCC generates assembly language, we have no
10032 a priori knowledge of how many instruction bytes are generated for each
10033 source line, and therefore can use only the DW_LNE_set_address and
10034 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10035 this as '1', which is "correct enough" for all architectures,
10036 and don't let the target override. */
10037 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10040 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10041 "Maximum Operations Per Instruction");
10042 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10043 "Default is_stmt_start flag");
10044 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10045 "Line Base Value (Special Opcodes)");
10046 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10047 "Line Range Value (Special Opcodes)");
10048 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10049 "Special Opcode Base");
10051 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10056 case DW_LNS_advance_pc
:
10057 case DW_LNS_advance_line
:
10058 case DW_LNS_set_file
:
10059 case DW_LNS_set_column
:
10060 case DW_LNS_fixed_advance_pc
:
10061 case DW_LNS_set_isa
:
10069 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10073 /* Write out the information about the files we use. */
10074 output_file_names ();
10075 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10078 /* Output the marker for the end of the line number info. */
10079 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10083 if (separate_line_info
)
10085 dw_line_info_table
*table
;
10088 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10091 output_one_line_info_table (table
);
10095 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10097 output_one_line_info_table (cold_text_section_line_info
);
10101 /* ??? Some Darwin linkers crash on a .debug_line section with no
10102 sequences. Further, merely a DW_LNE_end_sequence entry is not
10103 sufficient -- the address column must also be initialized.
10104 Make sure to output at least one set_address/end_sequence pair,
10105 choosing .text since that section is always present. */
10106 if (text_section_line_info
->in_use
|| !saw_one
)
10107 output_one_line_info_table (text_section_line_info
);
10109 /* Output the marker for the end of the line number info. */
10110 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10113 /* Given a pointer to a tree node for some base type, return a pointer to
10114 a DIE that describes the given type.
10116 This routine must only be called for GCC type nodes that correspond to
10117 Dwarf base (fundamental) types. */
10120 base_type_die (tree type
)
10122 dw_die_ref base_type_result
;
10123 enum dwarf_type encoding
;
10125 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10128 /* If this is a subtype that should not be emitted as a subrange type,
10129 use the base type. See subrange_type_for_debug_p. */
10130 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10131 type
= TREE_TYPE (type
);
10133 switch (TREE_CODE (type
))
10136 if ((dwarf_version
>= 4 || !dwarf_strict
)
10137 && TYPE_NAME (type
)
10138 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10139 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10140 && DECL_NAME (TYPE_NAME (type
)))
10142 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10143 if (strcmp (name
, "char16_t") == 0
10144 || strcmp (name
, "char32_t") == 0)
10146 encoding
= DW_ATE_UTF
;
10150 if (TYPE_STRING_FLAG (type
))
10152 if (TYPE_UNSIGNED (type
))
10153 encoding
= DW_ATE_unsigned_char
;
10155 encoding
= DW_ATE_signed_char
;
10157 else if (TYPE_UNSIGNED (type
))
10158 encoding
= DW_ATE_unsigned
;
10160 encoding
= DW_ATE_signed
;
10164 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10166 if (dwarf_version
>= 3 || !dwarf_strict
)
10167 encoding
= DW_ATE_decimal_float
;
10169 encoding
= DW_ATE_lo_user
;
10172 encoding
= DW_ATE_float
;
10175 case FIXED_POINT_TYPE
:
10176 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10177 encoding
= DW_ATE_lo_user
;
10178 else if (TYPE_UNSIGNED (type
))
10179 encoding
= DW_ATE_unsigned_fixed
;
10181 encoding
= DW_ATE_signed_fixed
;
10184 /* Dwarf2 doesn't know anything about complex ints, so use
10185 a user defined type for it. */
10187 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10188 encoding
= DW_ATE_complex_float
;
10190 encoding
= DW_ATE_lo_user
;
10194 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10195 encoding
= DW_ATE_boolean
;
10199 /* No other TREE_CODEs are Dwarf fundamental types. */
10200 gcc_unreachable ();
10203 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10205 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10206 int_size_in_bytes (type
));
10207 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10208 add_pubtype (type
, base_type_result
);
10210 return base_type_result
;
10213 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10214 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10217 is_base_type (tree type
)
10219 switch (TREE_CODE (type
))
10225 case FIXED_POINT_TYPE
:
10233 case QUAL_UNION_TYPE
:
10234 case ENUMERAL_TYPE
:
10235 case FUNCTION_TYPE
:
10238 case REFERENCE_TYPE
:
10246 gcc_unreachable ();
10252 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10253 node, return the size in bits for the type if it is a constant, or else
10254 return the alignment for the type if the type's size is not constant, or
10255 else return BITS_PER_WORD if the type actually turns out to be an
10256 ERROR_MARK node. */
10258 static inline unsigned HOST_WIDE_INT
10259 simple_type_size_in_bits (const_tree type
)
10261 if (TREE_CODE (type
) == ERROR_MARK
)
10262 return BITS_PER_WORD
;
10263 else if (TYPE_SIZE (type
) == NULL_TREE
)
10265 else if (host_integerp (TYPE_SIZE (type
), 1))
10266 return tree_low_cst (TYPE_SIZE (type
), 1);
10268 return TYPE_ALIGN (type
);
10271 /* Similarly, but return a double_int instead of UHWI. */
10273 static inline double_int
10274 double_int_type_size_in_bits (const_tree type
)
10276 if (TREE_CODE (type
) == ERROR_MARK
)
10277 return double_int::from_uhwi (BITS_PER_WORD
);
10278 else if (TYPE_SIZE (type
) == NULL_TREE
)
10279 return double_int_zero
;
10280 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10281 return tree_to_double_int (TYPE_SIZE (type
));
10283 return double_int::from_uhwi (TYPE_ALIGN (type
));
10286 /* Given a pointer to a tree node for a subrange type, return a pointer
10287 to a DIE that describes the given type. */
10290 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10292 dw_die_ref subrange_die
;
10293 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10295 if (context_die
== NULL
)
10296 context_die
= comp_unit_die ();
10298 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10300 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10302 /* The size of the subrange type and its base type do not match,
10303 so we need to generate a size attribute for the subrange type. */
10304 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10308 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10310 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10312 return subrange_die
;
10315 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10316 entry that chains various modifiers in front of the given type. */
10319 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10320 dw_die_ref context_die
)
10322 enum tree_code code
= TREE_CODE (type
);
10323 dw_die_ref mod_type_die
;
10324 dw_die_ref sub_die
= NULL
;
10325 tree item_type
= NULL
;
10326 tree qualified_type
;
10327 tree name
, low
, high
;
10328 dw_die_ref mod_scope
;
10330 if (code
== ERROR_MARK
)
10333 /* See if we already have the appropriately qualified variant of
10336 = get_qualified_type (type
,
10337 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10338 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10340 if (qualified_type
== sizetype
10341 && TYPE_NAME (qualified_type
)
10342 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10344 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10346 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10347 && TYPE_PRECISION (t
)
10348 == TYPE_PRECISION (qualified_type
)
10349 && TYPE_UNSIGNED (t
)
10350 == TYPE_UNSIGNED (qualified_type
));
10351 qualified_type
= t
;
10354 /* If we do, then we can just use its DIE, if it exists. */
10355 if (qualified_type
)
10357 mod_type_die
= lookup_type_die (qualified_type
);
10359 return mod_type_die
;
10362 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10364 /* Handle C typedef types. */
10365 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10366 && !DECL_ARTIFICIAL (name
))
10368 tree dtype
= TREE_TYPE (name
);
10370 if (qualified_type
== dtype
)
10372 /* For a named type, use the typedef. */
10373 gen_type_die (qualified_type
, context_die
);
10374 return lookup_type_die (qualified_type
);
10376 else if (is_const_type
< TYPE_READONLY (dtype
)
10377 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10378 || (is_const_type
<= TYPE_READONLY (dtype
)
10379 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10380 && DECL_ORIGINAL_TYPE (name
) != type
))
10381 /* cv-unqualified version of named type. Just use the unnamed
10382 type to which it refers. */
10383 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10384 is_const_type
, is_volatile_type
,
10386 /* Else cv-qualified version of named type; fall through. */
10389 mod_scope
= scope_die_for (type
, context_die
);
10392 /* If both is_const_type and is_volatile_type, prefer the path
10393 which leads to a qualified type. */
10394 && (!is_volatile_type
10395 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10396 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10398 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10399 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10401 else if (is_volatile_type
)
10403 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10404 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10406 else if (code
== POINTER_TYPE
)
10408 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10409 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10410 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10411 item_type
= TREE_TYPE (type
);
10412 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10413 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10414 TYPE_ADDR_SPACE (item_type
));
10416 else if (code
== REFERENCE_TYPE
)
10418 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10419 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10422 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10423 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10424 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10425 item_type
= TREE_TYPE (type
);
10426 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10427 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10428 TYPE_ADDR_SPACE (item_type
));
10430 else if (code
== INTEGER_TYPE
10431 && TREE_TYPE (type
) != NULL_TREE
10432 && subrange_type_for_debug_p (type
, &low
, &high
))
10434 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10435 item_type
= TREE_TYPE (type
);
10437 else if (is_base_type (type
))
10438 mod_type_die
= base_type_die (type
);
10441 gen_type_die (type
, context_die
);
10443 /* We have to get the type_main_variant here (and pass that to the
10444 `lookup_type_die' routine) because the ..._TYPE node we have
10445 might simply be a *copy* of some original type node (where the
10446 copy was created to help us keep track of typedef names) and
10447 that copy might have a different TYPE_UID from the original
10449 if (TREE_CODE (type
) != VECTOR_TYPE
)
10450 return lookup_type_die (type_main_variant (type
));
10452 /* Vectors have the debugging information in the type,
10453 not the main variant. */
10454 return lookup_type_die (type
);
10457 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10458 don't output a DW_TAG_typedef, since there isn't one in the
10459 user's program; just attach a DW_AT_name to the type.
10460 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10461 if the base type already has the same name. */
10463 && ((TREE_CODE (name
) != TYPE_DECL
10464 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10465 || (!is_const_type
&& !is_volatile_type
)))
10466 || (TREE_CODE (name
) == TYPE_DECL
10467 && TREE_TYPE (name
) == qualified_type
10468 && DECL_NAME (name
))))
10470 if (TREE_CODE (name
) == TYPE_DECL
)
10471 /* Could just call add_name_and_src_coords_attributes here,
10472 but since this is a builtin type it doesn't have any
10473 useful source coordinates anyway. */
10474 name
= DECL_NAME (name
);
10475 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10477 /* This probably indicates a bug. */
10478 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10480 name
= TYPE_NAME (type
);
10482 && TREE_CODE (name
) == TYPE_DECL
)
10483 name
= DECL_NAME (name
);
10484 add_name_attribute (mod_type_die
,
10485 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10488 if (qualified_type
)
10489 equate_type_number_to_die (qualified_type
, mod_type_die
);
10492 /* We must do this after the equate_type_number_to_die call, in case
10493 this is a recursive type. This ensures that the modified_type_die
10494 recursion will terminate even if the type is recursive. Recursive
10495 types are possible in Ada. */
10496 sub_die
= modified_type_die (item_type
,
10497 TYPE_READONLY (item_type
),
10498 TYPE_VOLATILE (item_type
),
10501 if (sub_die
!= NULL
)
10502 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10504 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10505 if (TYPE_ARTIFICIAL (type
))
10506 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10508 return mod_type_die
;
10511 /* Generate DIEs for the generic parameters of T.
10512 T must be either a generic type or a generic function.
10513 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10516 gen_generic_params_dies (tree t
)
10520 dw_die_ref die
= NULL
;
10523 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10527 die
= lookup_type_die (t
);
10528 else if (DECL_P (t
))
10529 die
= lookup_decl_die (t
);
10533 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10535 /* T has no generic parameter. It means T is neither a generic type
10536 or function. End of story. */
10539 parms_num
= TREE_VEC_LENGTH (parms
);
10540 args
= lang_hooks
.get_innermost_generic_args (t
);
10541 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10542 non_default
= int_cst_value (TREE_CHAIN (args
));
10544 non_default
= TREE_VEC_LENGTH (args
);
10545 for (i
= 0; i
< parms_num
; i
++)
10547 tree parm
, arg
, arg_pack_elems
;
10548 dw_die_ref parm_die
;
10550 parm
= TREE_VEC_ELT (parms
, i
);
10551 arg
= TREE_VEC_ELT (args
, i
);
10552 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10553 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10555 if (parm
&& TREE_VALUE (parm
) && arg
)
10557 /* If PARM represents a template parameter pack,
10558 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10559 by DW_TAG_template_*_parameter DIEs for the argument
10560 pack elements of ARG. Note that ARG would then be
10561 an argument pack. */
10562 if (arg_pack_elems
)
10563 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10567 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10568 true /* emit name */, die
);
10569 if (i
>= non_default
)
10570 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10575 /* Create and return a DIE for PARM which should be
10576 the representation of a generic type parameter.
10577 For instance, in the C++ front end, PARM would be a template parameter.
10578 ARG is the argument to PARM.
10579 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10581 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10582 as a child node. */
10585 generic_parameter_die (tree parm
, tree arg
,
10587 dw_die_ref parent_die
)
10589 dw_die_ref tmpl_die
= NULL
;
10590 const char *name
= NULL
;
10592 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10595 /* We support non-type generic parameters and arguments,
10596 type generic parameters and arguments, as well as
10597 generic generic parameters (a.k.a. template template parameters in C++)
10599 if (TREE_CODE (parm
) == PARM_DECL
)
10600 /* PARM is a nontype generic parameter */
10601 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10602 else if (TREE_CODE (parm
) == TYPE_DECL
)
10603 /* PARM is a type generic parameter. */
10604 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10605 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10606 /* PARM is a generic generic parameter.
10607 Its DIE is a GNU extension. It shall have a
10608 DW_AT_name attribute to represent the name of the template template
10609 parameter, and a DW_AT_GNU_template_name attribute to represent the
10610 name of the template template argument. */
10611 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10614 gcc_unreachable ();
10620 /* If PARM is a generic parameter pack, it means we are
10621 emitting debug info for a template argument pack element.
10622 In other terms, ARG is a template argument pack element.
10623 In that case, we don't emit any DW_AT_name attribute for
10627 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10629 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10632 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10634 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10635 TMPL_DIE should have a child DW_AT_type attribute that is set
10636 to the type of the argument to PARM, which is ARG.
10637 If PARM is a type generic parameter, TMPL_DIE should have a
10638 child DW_AT_type that is set to ARG. */
10639 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10640 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10641 TREE_THIS_VOLATILE (tmpl_type
),
10646 /* So TMPL_DIE is a DIE representing a
10647 a generic generic template parameter, a.k.a template template
10648 parameter in C++ and arg is a template. */
10650 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10651 to the name of the argument. */
10652 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10654 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10657 if (TREE_CODE (parm
) == PARM_DECL
)
10658 /* So PARM is a non-type generic parameter.
10659 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10660 attribute of TMPL_DIE which value represents the value
10662 We must be careful here:
10663 The value of ARG might reference some function decls.
10664 We might currently be emitting debug info for a generic
10665 type and types are emitted before function decls, we don't
10666 know if the function decls referenced by ARG will actually be
10667 emitted after cgraph computations.
10668 So must defer the generation of the DW_AT_const_value to
10669 after cgraph is ready. */
10670 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10676 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10677 PARM_PACK must be a template parameter pack. The returned DIE
10678 will be child DIE of PARENT_DIE. */
10681 template_parameter_pack_die (tree parm_pack
,
10682 tree parm_pack_args
,
10683 dw_die_ref parent_die
)
10688 gcc_assert (parent_die
&& parm_pack
);
10690 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10691 add_name_and_src_coords_attributes (die
, parm_pack
);
10692 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10693 generic_parameter_die (parm_pack
,
10694 TREE_VEC_ELT (parm_pack_args
, j
),
10695 false /* Don't emit DW_AT_name */,
10700 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10701 an enumerated type. */
10704 type_is_enum (const_tree type
)
10706 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10709 /* Return the DBX register number described by a given RTL node. */
10711 static unsigned int
10712 dbx_reg_number (const_rtx rtl
)
10714 unsigned regno
= REGNO (rtl
);
10716 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10718 #ifdef LEAF_REG_REMAP
10719 if (crtl
->uses_only_leaf_regs
)
10721 int leaf_reg
= LEAF_REG_REMAP (regno
);
10722 if (leaf_reg
!= -1)
10723 regno
= (unsigned) leaf_reg
;
10727 regno
= DBX_REGISTER_NUMBER (regno
);
10728 gcc_assert (regno
!= INVALID_REGNUM
);
10732 /* Optionally add a DW_OP_piece term to a location description expression.
10733 DW_OP_piece is only added if the location description expression already
10734 doesn't end with DW_OP_piece. */
10737 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10739 dw_loc_descr_ref loc
;
10741 if (*list_head
!= NULL
)
10743 /* Find the end of the chain. */
10744 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10747 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10748 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10752 /* Return a location descriptor that designates a machine register or
10753 zero if there is none. */
10755 static dw_loc_descr_ref
10756 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10760 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10763 /* We only use "frame base" when we're sure we're talking about the
10764 post-prologue local stack frame. We do this by *not* running
10765 register elimination until this point, and recognizing the special
10766 argument pointer and soft frame pointer rtx's.
10767 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10768 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10769 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10771 dw_loc_descr_ref result
= NULL
;
10773 if (dwarf_version
>= 4 || !dwarf_strict
)
10775 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10778 add_loc_descr (&result
,
10779 new_loc_descr (DW_OP_stack_value
, 0, 0));
10784 regs
= targetm
.dwarf_register_span (rtl
);
10786 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10787 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10790 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10791 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10793 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10797 /* Return a location descriptor that designates a machine register for
10798 a given hard register number. */
10800 static dw_loc_descr_ref
10801 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10803 dw_loc_descr_ref reg_loc_descr
;
10807 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10809 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10811 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10812 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10814 return reg_loc_descr
;
10817 /* Given an RTL of a register, return a location descriptor that
10818 designates a value that spans more than one register. */
10820 static dw_loc_descr_ref
10821 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10822 enum var_init_status initialized
)
10825 dw_loc_descr_ref loc_result
= NULL
;
10827 /* Simple, contiguous registers. */
10828 if (regs
== NULL_RTX
)
10830 unsigned reg
= REGNO (rtl
);
10833 #ifdef LEAF_REG_REMAP
10834 if (crtl
->uses_only_leaf_regs
)
10836 int leaf_reg
= LEAF_REG_REMAP (reg
);
10837 if (leaf_reg
!= -1)
10838 reg
= (unsigned) leaf_reg
;
10842 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10843 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10845 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10850 dw_loc_descr_ref t
;
10852 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10853 VAR_INIT_STATUS_INITIALIZED
);
10854 add_loc_descr (&loc_result
, t
);
10855 add_loc_descr_op_piece (&loc_result
, size
);
10861 /* Now onto stupid register sets in non contiguous locations. */
10863 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10865 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10868 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10870 dw_loc_descr_ref t
;
10872 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
10873 VAR_INIT_STATUS_INITIALIZED
);
10874 add_loc_descr (&loc_result
, t
);
10875 add_loc_descr_op_piece (&loc_result
, size
);
10878 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10879 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10883 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10885 /* Return a location descriptor that designates a constant i,
10886 as a compound operation from constant (i >> shift), constant shift
10889 static dw_loc_descr_ref
10890 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10892 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10893 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10894 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10898 /* Return a location descriptor that designates a constant. */
10900 static dw_loc_descr_ref
10901 int_loc_descriptor (HOST_WIDE_INT i
)
10903 enum dwarf_location_atom op
;
10905 /* Pick the smallest representation of a constant, rather than just
10906 defaulting to the LEB encoding. */
10909 int clz
= clz_hwi (i
);
10910 int ctz
= ctz_hwi (i
);
10912 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10913 else if (i
<= 0xff)
10914 op
= DW_OP_const1u
;
10915 else if (i
<= 0xffff)
10916 op
= DW_OP_const2u
;
10917 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10918 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10919 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10920 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10921 while DW_OP_const4u is 5 bytes. */
10922 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10923 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10924 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10925 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10926 while DW_OP_const4u is 5 bytes. */
10927 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10928 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10929 op
= DW_OP_const4u
;
10930 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10931 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10932 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10933 while DW_OP_constu of constant >= 0x100000000 takes at least
10935 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10936 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10937 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10938 >= HOST_BITS_PER_WIDE_INT
)
10939 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10940 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10941 while DW_OP_constu takes in this case at least 6 bytes. */
10942 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10943 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10944 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10945 && size_of_uleb128 (i
) > 6)
10946 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10947 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10954 op
= DW_OP_const1s
;
10955 else if (i
>= -0x8000)
10956 op
= DW_OP_const2s
;
10957 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10959 if (size_of_int_loc_descriptor (i
) < 5)
10961 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10962 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10965 op
= DW_OP_const4s
;
10969 if (size_of_int_loc_descriptor (i
)
10970 < (unsigned long) 1 + size_of_sleb128 (i
))
10972 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10973 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10980 return new_loc_descr (op
, i
, 0);
10983 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10984 without actually allocating it. */
10986 static unsigned long
10987 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10989 return size_of_int_loc_descriptor (i
>> shift
)
10990 + size_of_int_loc_descriptor (shift
)
10994 /* Return size_of_locs (int_loc_descriptor (i)) without
10995 actually allocating it. */
10997 static unsigned long
10998 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11007 else if (i
<= 0xff)
11009 else if (i
<= 0xffff)
11013 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11014 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11015 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11017 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11018 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11019 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11021 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11023 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11024 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11025 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11026 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11028 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11029 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11030 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11032 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11033 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11035 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11044 else if (i
>= -0x8000)
11046 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11048 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11050 s
= size_of_int_loc_descriptor (-i
) + 1;
11058 unsigned long r
= 1 + size_of_sleb128 (i
);
11059 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11061 s
= size_of_int_loc_descriptor (-i
) + 1;
11070 /* Return loc description representing "address" of integer value.
11071 This can appear only as toplevel expression. */
11073 static dw_loc_descr_ref
11074 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11077 dw_loc_descr_ref loc_result
= NULL
;
11079 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11082 litsize
= size_of_int_loc_descriptor (i
);
11083 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11084 is more compact. For DW_OP_stack_value we need:
11085 litsize + 1 (DW_OP_stack_value)
11086 and for DW_OP_implicit_value:
11087 1 (DW_OP_implicit_value) + 1 (length) + size. */
11088 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11090 loc_result
= int_loc_descriptor (i
);
11091 add_loc_descr (&loc_result
,
11092 new_loc_descr (DW_OP_stack_value
, 0, 0));
11096 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11098 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11099 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11103 /* Return a location descriptor that designates a base+offset location. */
11105 static dw_loc_descr_ref
11106 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11107 enum var_init_status initialized
)
11109 unsigned int regno
;
11110 dw_loc_descr_ref result
;
11111 dw_fde_ref fde
= cfun
->fde
;
11113 /* We only use "frame base" when we're sure we're talking about the
11114 post-prologue local stack frame. We do this by *not* running
11115 register elimination until this point, and recognizing the special
11116 argument pointer and soft frame pointer rtx's. */
11117 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11119 rtx elim
= (ira_use_lra_p
11120 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11121 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11125 if (GET_CODE (elim
) == PLUS
)
11127 offset
+= INTVAL (XEXP (elim
, 1));
11128 elim
= XEXP (elim
, 0);
11130 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11131 && (elim
== hard_frame_pointer_rtx
11132 || elim
== stack_pointer_rtx
))
11133 || elim
== (frame_pointer_needed
11134 ? hard_frame_pointer_rtx
11135 : stack_pointer_rtx
));
11137 /* If drap register is used to align stack, use frame
11138 pointer + offset to access stack variables. If stack
11139 is aligned without drap, use stack pointer + offset to
11140 access stack variables. */
11141 if (crtl
->stack_realign_tried
11142 && reg
== frame_pointer_rtx
)
11145 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11146 ? HARD_FRAME_POINTER_REGNUM
11148 return new_reg_loc_descr (base_reg
, offset
);
11151 gcc_assert (frame_pointer_fb_offset_valid
);
11152 offset
+= frame_pointer_fb_offset
;
11153 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11157 regno
= REGNO (reg
);
11158 #ifdef LEAF_REG_REMAP
11159 if (crtl
->uses_only_leaf_regs
)
11161 int leaf_reg
= LEAF_REG_REMAP (regno
);
11162 if (leaf_reg
!= -1)
11163 regno
= (unsigned) leaf_reg
;
11166 regno
= DWARF_FRAME_REGNUM (regno
);
11168 if (!optimize
&& fde
11169 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11171 /* Use cfa+offset to represent the location of arguments passed
11172 on the stack when drap is used to align stack.
11173 Only do this when not optimizing, for optimized code var-tracking
11174 is supposed to track where the arguments live and the register
11175 used as vdrap or drap in some spot might be used for something
11176 else in other part of the routine. */
11177 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11181 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11184 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11186 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11187 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11192 /* Return true if this RTL expression describes a base+offset calculation. */
11195 is_based_loc (const_rtx rtl
)
11197 return (GET_CODE (rtl
) == PLUS
11198 && ((REG_P (XEXP (rtl
, 0))
11199 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11200 && CONST_INT_P (XEXP (rtl
, 1)))));
11203 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11206 static dw_loc_descr_ref
11207 tls_mem_loc_descriptor (rtx mem
)
11210 dw_loc_descr_ref loc_result
;
11212 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11215 base
= get_base_address (MEM_EXPR (mem
));
11217 || TREE_CODE (base
) != VAR_DECL
11218 || !DECL_THREAD_LOCAL_P (base
))
11221 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11222 if (loc_result
== NULL
)
11225 if (MEM_OFFSET (mem
))
11226 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11231 /* Output debug info about reason why we failed to expand expression as dwarf
11235 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11237 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11239 fprintf (dump_file
, "Failed to expand as dwarf: ");
11241 print_generic_expr (dump_file
, expr
, dump_flags
);
11244 fprintf (dump_file
, "\n");
11245 print_rtl (dump_file
, rtl
);
11247 fprintf (dump_file
, "\nReason: %s\n", reason
);
11251 /* Helper function for const_ok_for_output, called either directly
11252 or via for_each_rtx. */
11255 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11259 if (GET_CODE (rtl
) == UNSPEC
)
11261 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11262 we can't express it in the debug info. */
11263 #ifdef ENABLE_CHECKING
11264 /* Don't complain about TLS UNSPECs, those are just too hard to
11265 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11266 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11267 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11268 if (XVECLEN (rtl
, 0) == 0
11269 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11270 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11271 inform (current_function_decl
11272 ? DECL_SOURCE_LOCATION (current_function_decl
)
11273 : UNKNOWN_LOCATION
,
11274 #if NUM_UNSPEC_VALUES > 0
11275 "non-delegitimized UNSPEC %s (%d) found in variable location",
11276 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11277 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11280 "non-delegitimized UNSPEC %d found in variable location",
11284 expansion_failed (NULL_TREE
, rtl
,
11285 "UNSPEC hasn't been delegitimized.\n");
11289 if (targetm
.const_not_ok_for_debug_p (rtl
))
11291 expansion_failed (NULL_TREE
, rtl
,
11292 "Expression rejected for debug by the backend.\n");
11296 if (GET_CODE (rtl
) != SYMBOL_REF
)
11299 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11302 get_pool_constant_mark (rtl
, &marked
);
11303 /* If all references to this pool constant were optimized away,
11304 it was not output and thus we can't represent it. */
11307 expansion_failed (NULL_TREE
, rtl
,
11308 "Constant was removed from constant pool.\n");
11313 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11316 /* Avoid references to external symbols in debug info, on several targets
11317 the linker might even refuse to link when linking a shared library,
11318 and in many other cases the relocations for .debug_info/.debug_loc are
11319 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11320 to be defined within the same shared library or executable are fine. */
11321 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11323 tree decl
= SYMBOL_REF_DECL (rtl
);
11325 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11327 expansion_failed (NULL_TREE
, rtl
,
11328 "Symbol not defined in current TU.\n");
11336 /* Return true if constant RTL can be emitted in DW_OP_addr or
11337 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11338 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11341 const_ok_for_output (rtx rtl
)
11343 if (GET_CODE (rtl
) == SYMBOL_REF
)
11344 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11346 if (GET_CODE (rtl
) == CONST
)
11347 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11352 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11353 if possible, NULL otherwise. */
11356 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11358 dw_die_ref type_die
;
11359 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11363 switch (TREE_CODE (type
))
11371 type_die
= lookup_type_die (type
);
11373 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11374 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11379 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11380 type matching MODE, or, if MODE is narrower than or as wide as
11381 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11384 static dw_loc_descr_ref
11385 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11387 enum machine_mode outer_mode
= mode
;
11388 dw_die_ref type_die
;
11389 dw_loc_descr_ref cvt
;
11391 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11393 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11396 type_die
= base_type_for_mode (outer_mode
, 1);
11397 if (type_die
== NULL
)
11399 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11400 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11401 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11402 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11403 add_loc_descr (&op
, cvt
);
11407 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11409 static dw_loc_descr_ref
11410 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11411 dw_loc_descr_ref op1
)
11413 dw_loc_descr_ref ret
= op0
;
11414 add_loc_descr (&ret
, op1
);
11415 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11416 if (STORE_FLAG_VALUE
!= 1)
11418 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11419 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11424 /* Return location descriptor for signed comparison OP RTL. */
11426 static dw_loc_descr_ref
11427 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11428 enum machine_mode mem_mode
)
11430 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11431 dw_loc_descr_ref op0
, op1
;
11434 if (op_mode
== VOIDmode
)
11435 op_mode
= GET_MODE (XEXP (rtl
, 1));
11436 if (op_mode
== VOIDmode
)
11440 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11441 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11444 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11445 VAR_INIT_STATUS_INITIALIZED
);
11446 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11447 VAR_INIT_STATUS_INITIALIZED
);
11449 if (op0
== NULL
|| op1
== NULL
)
11452 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11453 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11454 return compare_loc_descriptor (op
, op0
, op1
);
11456 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11458 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11459 dw_loc_descr_ref cvt
;
11461 if (type_die
== NULL
)
11463 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11464 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11465 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11466 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11467 add_loc_descr (&op0
, cvt
);
11468 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11469 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11470 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11471 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11472 add_loc_descr (&op1
, cvt
);
11473 return compare_loc_descriptor (op
, op0
, op1
);
11476 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11477 /* For eq/ne, if the operands are known to be zero-extended,
11478 there is no need to do the fancy shifting up. */
11479 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11481 dw_loc_descr_ref last0
, last1
;
11482 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11484 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11486 /* deref_size zero extends, and for constants we can check
11487 whether they are zero extended or not. */
11488 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11489 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11490 || (CONST_INT_P (XEXP (rtl
, 0))
11491 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11492 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11493 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11494 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11495 || (CONST_INT_P (XEXP (rtl
, 1))
11496 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11497 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11498 return compare_loc_descriptor (op
, op0
, op1
);
11500 /* EQ/NE comparison against constant in narrower type than
11501 DWARF2_ADDR_SIZE can be performed either as
11502 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11505 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11506 DW_OP_{eq,ne}. Pick whatever is shorter. */
11507 if (CONST_INT_P (XEXP (rtl
, 1))
11508 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11509 && (size_of_int_loc_descriptor (shift
) + 1
11510 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11511 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11512 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11513 & GET_MODE_MASK (op_mode
))))
11515 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11516 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11517 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11518 & GET_MODE_MASK (op_mode
));
11519 return compare_loc_descriptor (op
, op0
, op1
);
11522 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11523 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11524 if (CONST_INT_P (XEXP (rtl
, 1)))
11525 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11528 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11529 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11531 return compare_loc_descriptor (op
, op0
, op1
);
11534 /* Return location descriptor for unsigned comparison OP RTL. */
11536 static dw_loc_descr_ref
11537 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11538 enum machine_mode mem_mode
)
11540 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11541 dw_loc_descr_ref op0
, op1
;
11543 if (op_mode
== VOIDmode
)
11544 op_mode
= GET_MODE (XEXP (rtl
, 1));
11545 if (op_mode
== VOIDmode
)
11547 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11550 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11553 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11554 VAR_INIT_STATUS_INITIALIZED
);
11555 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11556 VAR_INIT_STATUS_INITIALIZED
);
11558 if (op0
== NULL
|| op1
== NULL
)
11561 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11563 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11564 dw_loc_descr_ref last0
, last1
;
11565 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11567 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11569 if (CONST_INT_P (XEXP (rtl
, 0)))
11570 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11571 /* deref_size zero extends, so no need to mask it again. */
11572 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11573 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11575 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11576 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11578 if (CONST_INT_P (XEXP (rtl
, 1)))
11579 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11580 /* deref_size zero extends, so no need to mask it again. */
11581 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11582 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11584 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11585 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11588 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11590 HOST_WIDE_INT bias
= 1;
11591 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11592 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11593 if (CONST_INT_P (XEXP (rtl
, 1)))
11594 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11595 + INTVAL (XEXP (rtl
, 1)));
11597 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11600 return compare_loc_descriptor (op
, op0
, op1
);
11603 /* Return location descriptor for {U,S}{MIN,MAX}. */
11605 static dw_loc_descr_ref
11606 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11607 enum machine_mode mem_mode
)
11609 enum dwarf_location_atom op
;
11610 dw_loc_descr_ref op0
, op1
, ret
;
11611 dw_loc_descr_ref bra_node
, drop_node
;
11614 && (GET_MODE_CLASS (mode
) != MODE_INT
11615 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11618 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11619 VAR_INIT_STATUS_INITIALIZED
);
11620 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11621 VAR_INIT_STATUS_INITIALIZED
);
11623 if (op0
== NULL
|| op1
== NULL
)
11626 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11627 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11628 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11629 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11631 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11633 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11634 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11635 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11636 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11637 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11639 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11641 HOST_WIDE_INT bias
= 1;
11642 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11643 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11644 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11647 else if (GET_MODE_CLASS (mode
) == MODE_INT
11648 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11650 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11651 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11652 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11653 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11654 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11656 else if (GET_MODE_CLASS (mode
) == MODE_INT
11657 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11659 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11660 dw_loc_descr_ref cvt
;
11661 if (type_die
== NULL
)
11663 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11664 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11665 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11666 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11667 add_loc_descr (&op0
, cvt
);
11668 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11669 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11670 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11671 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11672 add_loc_descr (&op1
, cvt
);
11675 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11680 add_loc_descr (&ret
, op1
);
11681 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11682 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11683 add_loc_descr (&ret
, bra_node
);
11684 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11685 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11686 add_loc_descr (&ret
, drop_node
);
11687 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11688 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11689 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11690 && GET_MODE_CLASS (mode
) == MODE_INT
11691 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11692 ret
= convert_descriptor_to_mode (mode
, ret
);
11696 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11697 but after converting arguments to type_die, afterwards
11698 convert back to unsigned. */
11700 static dw_loc_descr_ref
11701 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11702 enum machine_mode mode
, enum machine_mode mem_mode
)
11704 dw_loc_descr_ref cvt
, op0
, op1
;
11706 if (type_die
== NULL
)
11708 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11709 VAR_INIT_STATUS_INITIALIZED
);
11710 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11711 VAR_INIT_STATUS_INITIALIZED
);
11712 if (op0
== NULL
|| op1
== NULL
)
11714 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11715 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11716 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11717 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11718 add_loc_descr (&op0
, cvt
);
11719 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11720 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11721 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11722 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11723 add_loc_descr (&op1
, cvt
);
11724 add_loc_descr (&op0
, op1
);
11725 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11726 return convert_descriptor_to_mode (mode
, op0
);
11729 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11730 const0 is DW_OP_lit0 or corresponding typed constant,
11731 const1 is DW_OP_lit1 or corresponding typed constant
11732 and constMSB is constant with just the MSB bit set
11734 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11735 L1: const0 DW_OP_swap
11736 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11737 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11742 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11743 L1: const0 DW_OP_swap
11744 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11745 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11750 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11751 L1: const1 DW_OP_swap
11752 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11753 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11757 static dw_loc_descr_ref
11758 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11759 enum machine_mode mem_mode
)
11761 dw_loc_descr_ref op0
, ret
, tmp
;
11762 HOST_WIDE_INT valv
;
11763 dw_loc_descr_ref l1jump
, l1label
;
11764 dw_loc_descr_ref l2jump
, l2label
;
11765 dw_loc_descr_ref l3jump
, l3label
;
11766 dw_loc_descr_ref l4jump
, l4label
;
11769 if (GET_MODE_CLASS (mode
) != MODE_INT
11770 || GET_MODE (XEXP (rtl
, 0)) != mode
11771 || (GET_CODE (rtl
) == CLZ
11772 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11775 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11776 VAR_INIT_STATUS_INITIALIZED
);
11780 if (GET_CODE (rtl
) == CLZ
)
11782 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11783 valv
= GET_MODE_BITSIZE (mode
);
11785 else if (GET_CODE (rtl
) == FFS
)
11787 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11788 valv
= GET_MODE_BITSIZE (mode
);
11789 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11790 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11791 add_loc_descr (&ret
, l1jump
);
11792 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11793 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11794 VAR_INIT_STATUS_INITIALIZED
);
11797 add_loc_descr (&ret
, tmp
);
11798 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11799 add_loc_descr (&ret
, l4jump
);
11800 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11801 ? const1_rtx
: const0_rtx
,
11803 VAR_INIT_STATUS_INITIALIZED
);
11804 if (l1label
== NULL
)
11806 add_loc_descr (&ret
, l1label
);
11807 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11808 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11809 add_loc_descr (&ret
, l2label
);
11810 if (GET_CODE (rtl
) != CLZ
)
11812 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11813 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11814 << (GET_MODE_BITSIZE (mode
) - 1));
11816 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11817 << (GET_MODE_BITSIZE (mode
)
11818 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11819 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11820 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11821 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11822 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11824 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11825 VAR_INIT_STATUS_INITIALIZED
);
11828 add_loc_descr (&ret
, tmp
);
11829 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11830 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11831 add_loc_descr (&ret
, l3jump
);
11832 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11833 VAR_INIT_STATUS_INITIALIZED
);
11836 add_loc_descr (&ret
, tmp
);
11837 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11838 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11839 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11840 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11841 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11842 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11843 add_loc_descr (&ret
, l2jump
);
11844 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11845 add_loc_descr (&ret
, l3label
);
11846 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11847 add_loc_descr (&ret
, l4label
);
11848 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11849 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11850 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11851 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11852 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11853 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11854 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11855 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11859 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11860 const1 is DW_OP_lit1 or corresponding typed constant):
11862 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11863 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11867 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11868 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11871 static dw_loc_descr_ref
11872 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11873 enum machine_mode mem_mode
)
11875 dw_loc_descr_ref op0
, ret
, tmp
;
11876 dw_loc_descr_ref l1jump
, l1label
;
11877 dw_loc_descr_ref l2jump
, l2label
;
11879 if (GET_MODE_CLASS (mode
) != MODE_INT
11880 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11883 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11884 VAR_INIT_STATUS_INITIALIZED
);
11888 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11889 VAR_INIT_STATUS_INITIALIZED
);
11892 add_loc_descr (&ret
, tmp
);
11893 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11894 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11895 add_loc_descr (&ret
, l1label
);
11896 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11897 add_loc_descr (&ret
, l2jump
);
11898 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11899 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11900 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11901 VAR_INIT_STATUS_INITIALIZED
);
11904 add_loc_descr (&ret
, tmp
);
11905 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11906 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11907 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11908 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11909 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11910 VAR_INIT_STATUS_INITIALIZED
);
11911 add_loc_descr (&ret
, tmp
);
11912 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11913 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11914 add_loc_descr (&ret
, l1jump
);
11915 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11916 add_loc_descr (&ret
, l2label
);
11917 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11918 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11919 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11920 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11924 /* BSWAP (constS is initial shift count, either 56 or 24):
11926 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11927 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11928 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11929 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11930 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11932 static dw_loc_descr_ref
11933 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11934 enum machine_mode mem_mode
)
11936 dw_loc_descr_ref op0
, ret
, tmp
;
11937 dw_loc_descr_ref l1jump
, l1label
;
11938 dw_loc_descr_ref l2jump
, l2label
;
11940 if (GET_MODE_CLASS (mode
) != MODE_INT
11941 || BITS_PER_UNIT
!= 8
11942 || (GET_MODE_BITSIZE (mode
) != 32
11943 && GET_MODE_BITSIZE (mode
) != 64))
11946 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11947 VAR_INIT_STATUS_INITIALIZED
);
11952 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11954 VAR_INIT_STATUS_INITIALIZED
);
11957 add_loc_descr (&ret
, tmp
);
11958 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11959 VAR_INIT_STATUS_INITIALIZED
);
11962 add_loc_descr (&ret
, tmp
);
11963 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11964 add_loc_descr (&ret
, l1label
);
11965 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11967 VAR_INIT_STATUS_INITIALIZED
);
11968 add_loc_descr (&ret
, tmp
);
11969 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11970 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11971 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11972 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11973 VAR_INIT_STATUS_INITIALIZED
);
11976 add_loc_descr (&ret
, tmp
);
11977 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11978 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11979 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11980 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11981 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11982 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11983 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11984 VAR_INIT_STATUS_INITIALIZED
);
11985 add_loc_descr (&ret
, tmp
);
11986 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11987 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11988 add_loc_descr (&ret
, l2jump
);
11989 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11990 VAR_INIT_STATUS_INITIALIZED
);
11991 add_loc_descr (&ret
, tmp
);
11992 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11993 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11994 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11995 add_loc_descr (&ret
, l1jump
);
11996 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11997 add_loc_descr (&ret
, l2label
);
11998 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11999 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12000 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12001 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12002 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12003 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12007 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12008 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12009 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12010 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12012 ROTATERT is similar:
12013 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12014 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12015 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12017 static dw_loc_descr_ref
12018 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12019 enum machine_mode mem_mode
)
12021 rtx rtlop1
= XEXP (rtl
, 1);
12022 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12025 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12028 if (GET_MODE (rtlop1
) != VOIDmode
12029 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12030 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12031 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12032 VAR_INIT_STATUS_INITIALIZED
);
12033 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12034 VAR_INIT_STATUS_INITIALIZED
);
12035 if (op0
== NULL
|| op1
== NULL
)
12037 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12038 for (i
= 0; i
< 2; i
++)
12040 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12041 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12043 VAR_INIT_STATUS_INITIALIZED
);
12044 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12045 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12047 : HOST_BITS_PER_WIDE_INT
== 64
12048 ? DW_OP_const8u
: DW_OP_constu
,
12049 GET_MODE_MASK (mode
), 0);
12052 if (mask
[i
] == NULL
)
12054 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12057 add_loc_descr (&ret
, op1
);
12058 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12059 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12060 if (GET_CODE (rtl
) == ROTATERT
)
12062 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12063 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12064 GET_MODE_BITSIZE (mode
), 0));
12066 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12067 if (mask
[0] != NULL
)
12068 add_loc_descr (&ret
, mask
[0]);
12069 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12070 if (mask
[1] != NULL
)
12072 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12073 add_loc_descr (&ret
, mask
[1]);
12074 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12076 if (GET_CODE (rtl
) == ROTATE
)
12078 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12079 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12080 GET_MODE_BITSIZE (mode
), 0));
12082 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12083 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12087 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12088 for DEBUG_PARAMETER_REF RTL. */
12090 static dw_loc_descr_ref
12091 parameter_ref_descriptor (rtx rtl
)
12093 dw_loc_descr_ref ret
;
12098 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12099 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12100 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12103 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12104 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12105 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12109 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12110 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12115 /* The following routine converts the RTL for a variable or parameter
12116 (resident in memory) into an equivalent Dwarf representation of a
12117 mechanism for getting the address of that same variable onto the top of a
12118 hypothetical "address evaluation" stack.
12120 When creating memory location descriptors, we are effectively transforming
12121 the RTL for a memory-resident object into its Dwarf postfix expression
12122 equivalent. This routine recursively descends an RTL tree, turning
12123 it into Dwarf postfix code as it goes.
12125 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12127 MEM_MODE is the mode of the memory reference, needed to handle some
12128 autoincrement addressing modes.
12130 Return 0 if we can't represent the location. */
12133 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12134 enum machine_mode mem_mode
,
12135 enum var_init_status initialized
)
12137 dw_loc_descr_ref mem_loc_result
= NULL
;
12138 enum dwarf_location_atom op
;
12139 dw_loc_descr_ref op0
, op1
;
12140 rtx inner
= NULL_RTX
;
12142 if (mode
== VOIDmode
)
12143 mode
= GET_MODE (rtl
);
12145 /* Note that for a dynamically sized array, the location we will generate a
12146 description of here will be the lowest numbered location which is
12147 actually within the array. That's *not* necessarily the same as the
12148 zeroth element of the array. */
12150 rtl
= targetm
.delegitimize_address (rtl
);
12152 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12155 switch (GET_CODE (rtl
))
12160 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12163 /* The case of a subreg may arise when we have a local (register)
12164 variable or a formal (register) parameter which doesn't quite fill
12165 up an entire register. For now, just assume that it is
12166 legitimate to make the Dwarf info refer to the whole register which
12167 contains the given subreg. */
12168 if (!subreg_lowpart_p (rtl
))
12170 inner
= SUBREG_REG (rtl
);
12172 if (inner
== NULL_RTX
)
12173 inner
= XEXP (rtl
, 0);
12174 if (GET_MODE_CLASS (mode
) == MODE_INT
12175 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12176 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12177 #ifdef POINTERS_EXTEND_UNSIGNED
12178 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12181 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12183 mem_loc_result
= mem_loc_descriptor (inner
,
12185 mem_mode
, initialized
);
12190 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12192 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12193 && (GET_MODE_CLASS (mode
) != MODE_INT
12194 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12198 dw_die_ref type_die
;
12199 dw_loc_descr_ref cvt
;
12201 mem_loc_result
= mem_loc_descriptor (inner
,
12203 mem_mode
, initialized
);
12204 if (mem_loc_result
== NULL
)
12206 type_die
= base_type_for_mode (mode
,
12207 GET_MODE_CLASS (mode
) == MODE_INT
);
12208 if (type_die
== NULL
)
12210 mem_loc_result
= NULL
;
12213 if (GET_MODE_SIZE (mode
)
12214 != GET_MODE_SIZE (GET_MODE (inner
)))
12215 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12217 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12218 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12219 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12220 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12221 add_loc_descr (&mem_loc_result
, cvt
);
12226 if (GET_MODE_CLASS (mode
) != MODE_INT
12227 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12228 && rtl
!= arg_pointer_rtx
12229 && rtl
!= frame_pointer_rtx
12230 #ifdef POINTERS_EXTEND_UNSIGNED
12231 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12235 dw_die_ref type_die
;
12236 unsigned int dbx_regnum
;
12240 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12242 type_die
= base_type_for_mode (mode
,
12243 GET_MODE_CLASS (mode
) == MODE_INT
);
12244 if (type_die
== NULL
)
12247 dbx_regnum
= dbx_reg_number (rtl
);
12248 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12250 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12252 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12253 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12254 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12257 /* Whenever a register number forms a part of the description of the
12258 method for calculating the (dynamic) address of a memory resident
12259 object, DWARF rules require the register number be referred to as
12260 a "base register". This distinction is not based in any way upon
12261 what category of register the hardware believes the given register
12262 belongs to. This is strictly DWARF terminology we're dealing with
12263 here. Note that in cases where the location of a memory-resident
12264 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12265 OP_CONST (0)) the actual DWARF location descriptor that we generate
12266 may just be OP_BASEREG (basereg). This may look deceptively like
12267 the object in question was allocated to a register (rather than in
12268 memory) so DWARF consumers need to be aware of the subtle
12269 distinction between OP_REG and OP_BASEREG. */
12270 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12271 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12272 else if (stack_realign_drap
12274 && crtl
->args
.internal_arg_pointer
== rtl
12275 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12277 /* If RTL is internal_arg_pointer, which has been optimized
12278 out, use DRAP instead. */
12279 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12280 VAR_INIT_STATUS_INITIALIZED
);
12286 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12288 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12289 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12292 else if (GET_CODE (rtl
) == ZERO_EXTEND
12293 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12294 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12295 < HOST_BITS_PER_WIDE_INT
12296 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12297 to expand zero extend as two shifts instead of
12299 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12301 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12302 mem_loc_result
= op0
;
12303 add_loc_descr (&mem_loc_result
,
12304 int_loc_descriptor (GET_MODE_MASK (imode
)));
12305 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12307 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12309 int shift
= DWARF2_ADDR_SIZE
12310 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12311 shift
*= BITS_PER_UNIT
;
12312 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12316 mem_loc_result
= op0
;
12317 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12318 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12319 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12320 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12322 else if (!dwarf_strict
)
12324 dw_die_ref type_die1
, type_die2
;
12325 dw_loc_descr_ref cvt
;
12327 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12328 GET_CODE (rtl
) == ZERO_EXTEND
);
12329 if (type_die1
== NULL
)
12331 type_die2
= base_type_for_mode (mode
, 1);
12332 if (type_die2
== NULL
)
12334 mem_loc_result
= op0
;
12335 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12336 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12337 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12338 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12339 add_loc_descr (&mem_loc_result
, cvt
);
12340 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12341 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12342 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12343 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12344 add_loc_descr (&mem_loc_result
, cvt
);
12350 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12351 if (new_rtl
!= rtl
)
12353 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12355 if (mem_loc_result
!= NULL
)
12356 return mem_loc_result
;
12359 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12360 get_address_mode (rtl
), mode
,
12361 VAR_INIT_STATUS_INITIALIZED
);
12362 if (mem_loc_result
== NULL
)
12363 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12364 if (mem_loc_result
!= NULL
)
12366 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12367 || GET_MODE_CLASS (mode
) != MODE_INT
)
12369 dw_die_ref type_die
;
12370 dw_loc_descr_ref deref
;
12375 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12376 if (type_die
== NULL
)
12378 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12379 GET_MODE_SIZE (mode
), 0);
12380 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12381 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12382 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12383 add_loc_descr (&mem_loc_result
, deref
);
12385 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12386 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12388 add_loc_descr (&mem_loc_result
,
12389 new_loc_descr (DW_OP_deref_size
,
12390 GET_MODE_SIZE (mode
), 0));
12395 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12398 /* Some ports can transform a symbol ref into a label ref, because
12399 the symbol ref is too far away and has to be dumped into a constant
12403 if (GET_MODE_CLASS (mode
) != MODE_INT
12404 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12405 #ifdef POINTERS_EXTEND_UNSIGNED
12406 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12410 if (GET_CODE (rtl
) == SYMBOL_REF
12411 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12413 dw_loc_descr_ref temp
;
12415 /* If this is not defined, we have no way to emit the data. */
12416 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12419 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12421 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12422 add_loc_descr (&mem_loc_result
, temp
);
12427 if (!const_ok_for_output (rtl
))
12431 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12432 vec_safe_push (used_rtx_array
, rtl
);
12438 case DEBUG_IMPLICIT_PTR
:
12439 expansion_failed (NULL_TREE
, rtl
,
12440 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12446 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12448 if (GET_MODE_CLASS (mode
) != MODE_INT
12449 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12450 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12451 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12454 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12455 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12457 op0
= one_reg_loc_descriptor (dbx_regnum
,
12458 VAR_INIT_STATUS_INITIALIZED
);
12461 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12462 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12464 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12465 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12466 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12470 gcc_unreachable ();
12473 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12474 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12475 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12478 case DEBUG_PARAMETER_REF
:
12479 mem_loc_result
= parameter_ref_descriptor (rtl
);
12483 /* Extract the PLUS expression nested inside and fall into
12484 PLUS code below. */
12485 rtl
= XEXP (rtl
, 1);
12490 /* Turn these into a PLUS expression and fall into the PLUS code
12492 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12493 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12494 ? GET_MODE_UNIT_SIZE (mem_mode
)
12495 : -GET_MODE_UNIT_SIZE (mem_mode
),
12498 /* ... fall through ... */
12502 if (is_based_loc (rtl
)
12503 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12504 || XEXP (rtl
, 0) == arg_pointer_rtx
12505 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12506 && GET_MODE_CLASS (mode
) == MODE_INT
)
12507 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12508 INTVAL (XEXP (rtl
, 1)),
12509 VAR_INIT_STATUS_INITIALIZED
);
12512 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12513 VAR_INIT_STATUS_INITIALIZED
);
12514 if (mem_loc_result
== 0)
12517 if (CONST_INT_P (XEXP (rtl
, 1))
12518 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12519 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12522 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12523 VAR_INIT_STATUS_INITIALIZED
);
12526 add_loc_descr (&mem_loc_result
, op1
);
12527 add_loc_descr (&mem_loc_result
,
12528 new_loc_descr (DW_OP_plus
, 0, 0));
12533 /* If a pseudo-reg is optimized away, it is possible for it to
12534 be replaced with a MEM containing a multiply or shift. */
12545 && GET_MODE_CLASS (mode
) == MODE_INT
12546 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12548 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12549 base_type_for_mode (mode
, 0),
12573 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12575 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12576 VAR_INIT_STATUS_INITIALIZED
);
12578 rtx rtlop1
= XEXP (rtl
, 1);
12579 if (GET_MODE (rtlop1
) != VOIDmode
12580 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12581 < GET_MODE_BITSIZE (mode
))
12582 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12583 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12584 VAR_INIT_STATUS_INITIALIZED
);
12587 if (op0
== 0 || op1
== 0)
12590 mem_loc_result
= op0
;
12591 add_loc_descr (&mem_loc_result
, op1
);
12592 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12608 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12609 VAR_INIT_STATUS_INITIALIZED
);
12610 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12611 VAR_INIT_STATUS_INITIALIZED
);
12613 if (op0
== 0 || op1
== 0)
12616 mem_loc_result
= op0
;
12617 add_loc_descr (&mem_loc_result
, op1
);
12618 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12622 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12624 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12625 base_type_for_mode (mode
, 0),
12630 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12631 VAR_INIT_STATUS_INITIALIZED
);
12632 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12633 VAR_INIT_STATUS_INITIALIZED
);
12635 if (op0
== 0 || op1
== 0)
12638 mem_loc_result
= op0
;
12639 add_loc_descr (&mem_loc_result
, op1
);
12640 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12641 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12642 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12643 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12644 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12648 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12650 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12655 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12656 base_type_for_mode (mode
, 1),
12674 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12675 VAR_INIT_STATUS_INITIALIZED
);
12680 mem_loc_result
= op0
;
12681 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12685 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12686 #ifdef POINTERS_EXTEND_UNSIGNED
12688 && mem_mode
!= VOIDmode
12689 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12693 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12697 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12698 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12700 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12701 enum machine_mode amode
;
12702 if (type_die
== NULL
)
12704 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12706 if (INTVAL (rtl
) >= 0
12707 && amode
!= BLKmode
12708 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12709 /* const DW_OP_GNU_convert <XXX> vs.
12710 DW_OP_GNU_const_type <XXX, 1, const>. */
12711 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12712 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12714 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12715 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12716 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12717 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12718 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12719 add_loc_descr (&mem_loc_result
, op0
);
12720 return mem_loc_result
;
12722 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12724 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12725 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12726 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12727 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12728 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12731 mem_loc_result
->dw_loc_oprnd2
.val_class
12732 = dw_val_class_const_double
;
12733 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12734 = double_int::from_shwi (INTVAL (rtl
));
12742 dw_die_ref type_die
;
12744 /* Note that a CONST_DOUBLE rtx could represent either an integer
12745 or a floating-point constant. A CONST_DOUBLE is used whenever
12746 the constant requires more than one word in order to be
12747 adequately represented. We output CONST_DOUBLEs as blocks. */
12748 if (mode
== VOIDmode
12749 || (GET_MODE (rtl
) == VOIDmode
12750 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12752 type_die
= base_type_for_mode (mode
,
12753 GET_MODE_CLASS (mode
) == MODE_INT
);
12754 if (type_die
== NULL
)
12756 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12757 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12758 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12759 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12760 if (SCALAR_FLOAT_MODE_P (mode
))
12762 unsigned int length
= GET_MODE_SIZE (mode
);
12763 unsigned char *array
12764 = (unsigned char*) ggc_alloc_atomic (length
);
12766 insert_float (rtl
, array
);
12767 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12768 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12769 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12770 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12774 mem_loc_result
->dw_loc_oprnd2
.val_class
12775 = dw_val_class_const_double
;
12776 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12777 = rtx_to_double_int (rtl
);
12783 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12787 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12791 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12795 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12799 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12803 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12807 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12811 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12815 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12819 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12824 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12829 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12834 if (CONST_INT_P (XEXP (rtl
, 1))
12835 && CONST_INT_P (XEXP (rtl
, 2))
12836 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12837 + (unsigned) INTVAL (XEXP (rtl
, 2))
12838 <= GET_MODE_BITSIZE (mode
))
12839 && GET_MODE_CLASS (mode
) == MODE_INT
12840 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12841 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12844 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12845 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12848 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12852 mem_loc_result
= op0
;
12853 size
= INTVAL (XEXP (rtl
, 1));
12854 shift
= INTVAL (XEXP (rtl
, 2));
12855 if (BITS_BIG_ENDIAN
)
12856 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12858 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12860 add_loc_descr (&mem_loc_result
,
12861 int_loc_descriptor (DWARF2_ADDR_SIZE
12863 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12865 if (size
!= (int) DWARF2_ADDR_SIZE
)
12867 add_loc_descr (&mem_loc_result
,
12868 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12869 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12876 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12877 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12878 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12879 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12880 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12881 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12882 VAR_INIT_STATUS_INITIALIZED
);
12883 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12884 VAR_INIT_STATUS_INITIALIZED
);
12885 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12888 mem_loc_result
= op1
;
12889 add_loc_descr (&mem_loc_result
, op2
);
12890 add_loc_descr (&mem_loc_result
, op0
);
12891 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12892 add_loc_descr (&mem_loc_result
, bra_node
);
12893 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12894 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12895 add_loc_descr (&mem_loc_result
, drop_node
);
12896 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12897 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12902 case FLOAT_TRUNCATE
:
12904 case UNSIGNED_FLOAT
:
12909 dw_die_ref type_die
;
12910 dw_loc_descr_ref cvt
;
12912 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12913 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12916 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12917 && (GET_CODE (rtl
) == FLOAT
12918 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12919 <= DWARF2_ADDR_SIZE
))
12921 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12922 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12923 if (type_die
== NULL
)
12925 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12926 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12927 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12928 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12929 add_loc_descr (&op0
, cvt
);
12931 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12932 if (type_die
== NULL
)
12934 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12935 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12936 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12937 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12938 add_loc_descr (&op0
, cvt
);
12939 if (GET_MODE_CLASS (mode
) == MODE_INT
12940 && (GET_CODE (rtl
) == FIX
12941 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12943 op0
= convert_descriptor_to_mode (mode
, op0
);
12947 mem_loc_result
= op0
;
12954 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12959 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12963 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12968 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12972 /* In theory, we could implement the above. */
12973 /* DWARF cannot represent the unsigned compare operations
12998 case FRACT_CONVERT
:
12999 case UNSIGNED_FRACT_CONVERT
:
13001 case UNSIGNED_SAT_FRACT
:
13007 case VEC_DUPLICATE
:
13011 case STRICT_LOW_PART
:
13016 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13017 can't express it in the debug info. This can happen e.g. with some
13022 resolve_one_addr (&rtl
, NULL
);
13026 #ifdef ENABLE_CHECKING
13027 print_rtl (stderr
, rtl
);
13028 gcc_unreachable ();
13034 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13035 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13037 return mem_loc_result
;
13040 /* Return a descriptor that describes the concatenation of two locations.
13041 This is typically a complex variable. */
13043 static dw_loc_descr_ref
13044 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13046 dw_loc_descr_ref cc_loc_result
= NULL
;
13047 dw_loc_descr_ref x0_ref
13048 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13049 dw_loc_descr_ref x1_ref
13050 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13052 if (x0_ref
== 0 || x1_ref
== 0)
13055 cc_loc_result
= x0_ref
;
13056 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13058 add_loc_descr (&cc_loc_result
, x1_ref
);
13059 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13061 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13062 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13064 return cc_loc_result
;
13067 /* Return a descriptor that describes the concatenation of N
13070 static dw_loc_descr_ref
13071 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13074 dw_loc_descr_ref cc_loc_result
= NULL
;
13075 unsigned int n
= XVECLEN (concatn
, 0);
13077 for (i
= 0; i
< n
; ++i
)
13079 dw_loc_descr_ref ref
;
13080 rtx x
= XVECEXP (concatn
, 0, i
);
13082 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13086 add_loc_descr (&cc_loc_result
, ref
);
13087 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13090 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13091 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13093 return cc_loc_result
;
13096 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13097 for DEBUG_IMPLICIT_PTR RTL. */
13099 static dw_loc_descr_ref
13100 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13102 dw_loc_descr_ref ret
;
13107 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13108 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13109 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13110 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13111 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13112 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13115 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13116 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13117 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13121 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13122 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13127 /* Output a proper Dwarf location descriptor for a variable or parameter
13128 which is either allocated in a register or in a memory location. For a
13129 register, we just generate an OP_REG and the register number. For a
13130 memory location we provide a Dwarf postfix expression describing how to
13131 generate the (dynamic) address of the object onto the address stack.
13133 MODE is mode of the decl if this loc_descriptor is going to be used in
13134 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13135 allowed, VOIDmode otherwise.
13137 If we don't know how to describe it, return 0. */
13139 static dw_loc_descr_ref
13140 loc_descriptor (rtx rtl
, enum machine_mode mode
,
13141 enum var_init_status initialized
)
13143 dw_loc_descr_ref loc_result
= NULL
;
13145 switch (GET_CODE (rtl
))
13148 /* The case of a subreg may arise when we have a local (register)
13149 variable or a formal (register) parameter which doesn't quite fill
13150 up an entire register. For now, just assume that it is
13151 legitimate to make the Dwarf info refer to the whole register which
13152 contains the given subreg. */
13153 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13154 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13155 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13161 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13165 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13166 GET_MODE (rtl
), initialized
);
13167 if (loc_result
== NULL
)
13168 loc_result
= tls_mem_loc_descriptor (rtl
);
13169 if (loc_result
== NULL
)
13171 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13172 if (new_rtl
!= rtl
)
13173 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13178 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13183 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13188 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13190 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13191 if (GET_CODE (loc
) == EXPR_LIST
)
13192 loc
= XEXP (loc
, 0);
13193 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13197 rtl
= XEXP (rtl
, 1);
13202 rtvec par_elems
= XVEC (rtl
, 0);
13203 int num_elem
= GET_NUM_ELEM (par_elems
);
13204 enum machine_mode mode
;
13207 /* Create the first one, so we have something to add to. */
13208 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13209 VOIDmode
, initialized
);
13210 if (loc_result
== NULL
)
13212 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13213 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13214 for (i
= 1; i
< num_elem
; i
++)
13216 dw_loc_descr_ref temp
;
13218 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13219 VOIDmode
, initialized
);
13222 add_loc_descr (&loc_result
, temp
);
13223 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13224 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13230 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13231 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13236 if (mode
== VOIDmode
)
13237 mode
= GET_MODE (rtl
);
13239 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13241 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13243 /* Note that a CONST_DOUBLE rtx could represent either an integer
13244 or a floating-point constant. A CONST_DOUBLE is used whenever
13245 the constant requires more than one word in order to be
13246 adequately represented. We output CONST_DOUBLEs as blocks. */
13247 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13248 GET_MODE_SIZE (mode
), 0);
13249 if (SCALAR_FLOAT_MODE_P (mode
))
13251 unsigned int length
= GET_MODE_SIZE (mode
);
13252 unsigned char *array
13253 = (unsigned char*) ggc_alloc_atomic (length
);
13255 insert_float (rtl
, array
);
13256 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13257 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13258 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13259 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13263 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13264 loc_result
->dw_loc_oprnd2
.v
.val_double
13265 = rtx_to_double_int (rtl
);
13271 if (mode
== VOIDmode
)
13272 mode
= GET_MODE (rtl
);
13274 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13276 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13277 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13278 unsigned char *array
= (unsigned char *)
13279 ggc_alloc_atomic (length
* elt_size
);
13283 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13284 switch (GET_MODE_CLASS (mode
))
13286 case MODE_VECTOR_INT
:
13287 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13289 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13290 double_int val
= rtx_to_double_int (elt
);
13292 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13293 insert_int (val
.to_shwi (), elt_size
, p
);
13296 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13297 insert_double (val
, p
);
13302 case MODE_VECTOR_FLOAT
:
13303 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13305 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13306 insert_float (elt
, p
);
13311 gcc_unreachable ();
13314 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13315 length
* elt_size
, 0);
13316 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13317 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13318 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13319 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13324 if (mode
== VOIDmode
13325 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13326 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13327 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13329 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13334 if (!const_ok_for_output (rtl
))
13337 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13338 && (dwarf_version
>= 4 || !dwarf_strict
))
13340 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13341 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13342 vec_safe_push (used_rtx_array
, rtl
);
13346 case DEBUG_IMPLICIT_PTR
:
13347 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13351 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13352 && CONST_INT_P (XEXP (rtl
, 1)))
13355 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13361 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13362 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13363 && dwarf_version
>= 4)
13364 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13366 /* Value expression. */
13367 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13369 add_loc_descr (&loc_result
,
13370 new_loc_descr (DW_OP_stack_value
, 0, 0));
13378 /* We need to figure out what section we should use as the base for the
13379 address ranges where a given location is valid.
13380 1. If this particular DECL has a section associated with it, use that.
13381 2. If this function has a section associated with it, use that.
13382 3. Otherwise, use the text section.
13383 XXX: If you split a variable across multiple sections, we won't notice. */
13385 static const char *
13386 secname_for_decl (const_tree decl
)
13388 const char *secname
;
13390 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13392 tree sectree
= DECL_SECTION_NAME (decl
);
13393 secname
= TREE_STRING_POINTER (sectree
);
13395 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13397 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13398 secname
= TREE_STRING_POINTER (sectree
);
13400 else if (cfun
&& in_cold_section_p
)
13401 secname
= crtl
->subsections
.cold_section_label
;
13403 secname
= text_section_label
;
13408 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13411 decl_by_reference_p (tree decl
)
13413 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13414 || TREE_CODE (decl
) == VAR_DECL
)
13415 && DECL_BY_REFERENCE (decl
));
13418 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13421 static dw_loc_descr_ref
13422 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13423 enum var_init_status initialized
)
13425 int have_address
= 0;
13426 dw_loc_descr_ref descr
;
13427 enum machine_mode mode
;
13429 if (want_address
!= 2)
13431 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13433 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13435 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13436 if (GET_CODE (varloc
) == EXPR_LIST
)
13437 varloc
= XEXP (varloc
, 0);
13438 mode
= GET_MODE (varloc
);
13439 if (MEM_P (varloc
))
13441 rtx addr
= XEXP (varloc
, 0);
13442 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13443 mode
, initialized
);
13448 rtx x
= avoid_constant_pool_reference (varloc
);
13450 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13455 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13462 if (GET_CODE (varloc
) == VAR_LOCATION
)
13463 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13465 mode
= DECL_MODE (loc
);
13466 descr
= loc_descriptor (varloc
, mode
, initialized
);
13473 if (want_address
== 2 && !have_address
13474 && (dwarf_version
>= 4 || !dwarf_strict
))
13476 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13478 expansion_failed (loc
, NULL_RTX
,
13479 "DWARF address size mismatch");
13482 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13485 /* Show if we can't fill the request for an address. */
13486 if (want_address
&& !have_address
)
13488 expansion_failed (loc
, NULL_RTX
,
13489 "Want address and only have value");
13493 /* If we've got an address and don't want one, dereference. */
13494 if (!want_address
&& have_address
)
13496 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13497 enum dwarf_location_atom op
;
13499 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13501 expansion_failed (loc
, NULL_RTX
,
13502 "DWARF address size mismatch");
13505 else if (size
== DWARF2_ADDR_SIZE
)
13508 op
= DW_OP_deref_size
;
13510 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13516 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13517 if it is not possible. */
13519 static dw_loc_descr_ref
13520 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13522 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13523 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13524 else if (dwarf_version
>= 3 || !dwarf_strict
)
13525 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13530 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13531 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13533 static dw_loc_descr_ref
13534 dw_sra_loc_expr (tree decl
, rtx loc
)
13537 unsigned int padsize
= 0;
13538 dw_loc_descr_ref descr
, *descr_tail
;
13539 unsigned HOST_WIDE_INT decl_size
;
13541 enum var_init_status initialized
;
13543 if (DECL_SIZE (decl
) == NULL
13544 || !host_integerp (DECL_SIZE (decl
), 1))
13547 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13549 descr_tail
= &descr
;
13551 for (p
= loc
; p
; p
= XEXP (p
, 1))
13553 unsigned int bitsize
= decl_piece_bitsize (p
);
13554 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13555 dw_loc_descr_ref cur_descr
;
13556 dw_loc_descr_ref
*tail
, last
= NULL
;
13557 unsigned int opsize
= 0;
13559 if (loc_note
== NULL_RTX
13560 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13562 padsize
+= bitsize
;
13565 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13566 varloc
= NOTE_VAR_LOCATION (loc_note
);
13567 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13568 if (cur_descr
== NULL
)
13570 padsize
+= bitsize
;
13574 /* Check that cur_descr either doesn't use
13575 DW_OP_*piece operations, or their sum is equal
13576 to bitsize. Otherwise we can't embed it. */
13577 for (tail
= &cur_descr
; *tail
!= NULL
;
13578 tail
= &(*tail
)->dw_loc_next
)
13579 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13581 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13585 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13587 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13591 if (last
!= NULL
&& opsize
!= bitsize
)
13593 padsize
+= bitsize
;
13594 /* Discard the current piece of the descriptor and release any
13595 addr_table entries it uses. */
13596 remove_loc_list_addr_table_entries (cur_descr
);
13600 /* If there is a hole, add DW_OP_*piece after empty DWARF
13601 expression, which means that those bits are optimized out. */
13604 if (padsize
> decl_size
)
13606 remove_loc_list_addr_table_entries (cur_descr
);
13607 goto discard_descr
;
13609 decl_size
-= padsize
;
13610 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13611 if (*descr_tail
== NULL
)
13613 remove_loc_list_addr_table_entries (cur_descr
);
13614 goto discard_descr
;
13616 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13619 *descr_tail
= cur_descr
;
13621 if (bitsize
> decl_size
)
13622 goto discard_descr
;
13623 decl_size
-= bitsize
;
13626 HOST_WIDE_INT offset
= 0;
13627 if (GET_CODE (varloc
) == VAR_LOCATION
13628 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13630 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13631 if (GET_CODE (varloc
) == EXPR_LIST
)
13632 varloc
= XEXP (varloc
, 0);
13636 if (GET_CODE (varloc
) == CONST
13637 || GET_CODE (varloc
) == SIGN_EXTEND
13638 || GET_CODE (varloc
) == ZERO_EXTEND
)
13639 varloc
= XEXP (varloc
, 0);
13640 else if (GET_CODE (varloc
) == SUBREG
)
13641 varloc
= SUBREG_REG (varloc
);
13646 /* DW_OP_bit_size offset should be zero for register
13647 or implicit location descriptions and empty location
13648 descriptions, but for memory addresses needs big endian
13650 if (MEM_P (varloc
))
13652 unsigned HOST_WIDE_INT memsize
13653 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13654 if (memsize
!= bitsize
)
13656 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13657 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13658 goto discard_descr
;
13659 if (memsize
< bitsize
)
13660 goto discard_descr
;
13661 if (BITS_BIG_ENDIAN
)
13662 offset
= memsize
- bitsize
;
13666 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13667 if (*descr_tail
== NULL
)
13668 goto discard_descr
;
13669 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13673 /* If there were any non-empty expressions, add padding till the end of
13675 if (descr
!= NULL
&& decl_size
!= 0)
13677 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13678 if (*descr_tail
== NULL
)
13679 goto discard_descr
;
13684 /* Discard the descriptor and release any addr_table entries it uses. */
13685 remove_loc_list_addr_table_entries (descr
);
13689 /* Return the dwarf representation of the location list LOC_LIST of
13690 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13693 static dw_loc_list_ref
13694 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13696 const char *endname
, *secname
;
13698 enum var_init_status initialized
;
13699 struct var_loc_node
*node
;
13700 dw_loc_descr_ref descr
;
13701 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13702 dw_loc_list_ref list
= NULL
;
13703 dw_loc_list_ref
*listp
= &list
;
13705 /* Now that we know what section we are using for a base,
13706 actually construct the list of locations.
13707 The first location information is what is passed to the
13708 function that creates the location list, and the remaining
13709 locations just get added on to that list.
13710 Note that we only know the start address for a location
13711 (IE location changes), so to build the range, we use
13712 the range [current location start, next location start].
13713 This means we have to special case the last node, and generate
13714 a range of [last location start, end of function label]. */
13716 secname
= secname_for_decl (decl
);
13718 for (node
= loc_list
->first
; node
; node
= node
->next
)
13719 if (GET_CODE (node
->loc
) == EXPR_LIST
13720 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13722 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13724 /* This requires DW_OP_{,bit_}piece, which is not usable
13725 inside DWARF expressions. */
13726 if (want_address
!= 2)
13728 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13734 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13735 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13736 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13740 bool range_across_switch
= false;
13741 /* If section switch happens in between node->label
13742 and node->next->label (or end of function) and
13743 we can't emit it as a single entry list,
13744 emit two ranges, first one ending at the end
13745 of first partition and second one starting at the
13746 beginning of second partition. */
13747 if (node
== loc_list
->last_before_switch
13748 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13749 && current_function_decl
)
13751 endname
= cfun
->fde
->dw_fde_end
;
13752 range_across_switch
= true;
13754 /* The variable has a location between NODE->LABEL and
13755 NODE->NEXT->LABEL. */
13756 else if (node
->next
)
13757 endname
= node
->next
->label
;
13758 /* If the variable has a location at the last label
13759 it keeps its location until the end of function. */
13760 else if (!current_function_decl
)
13761 endname
= text_end_label
;
13764 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13765 current_function_funcdef_no
);
13766 endname
= ggc_strdup (label_id
);
13769 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13770 if (TREE_CODE (decl
) == PARM_DECL
13771 && node
== loc_list
->first
13772 && NOTE_P (node
->loc
)
13773 && strcmp (node
->label
, endname
) == 0)
13774 (*listp
)->force
= true;
13775 listp
= &(*listp
)->dw_loc_next
;
13777 if (range_across_switch
)
13779 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13780 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13783 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13784 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13785 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13788 gcc_assert (descr
);
13789 /* The variable has a location between NODE->LABEL and
13790 NODE->NEXT->LABEL. */
13792 endname
= node
->next
->label
;
13794 endname
= cfun
->fde
->dw_fde_second_end
;
13795 *listp
= new_loc_list (descr
,
13796 cfun
->fde
->dw_fde_second_begin
,
13798 listp
= &(*listp
)->dw_loc_next
;
13803 /* Try to avoid the overhead of a location list emitting a location
13804 expression instead, but only if we didn't have more than one
13805 location entry in the first place. If some entries were not
13806 representable, we don't want to pretend a single entry that was
13807 applies to the entire scope in which the variable is
13809 if (list
&& loc_list
->first
->next
)
13815 /* Return if the loc_list has only single element and thus can be represented
13816 as location description. */
13819 single_element_loc_list_p (dw_loc_list_ref list
)
13821 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13822 return !list
->ll_symbol
;
13825 /* To each location in list LIST add loc descr REF. */
13828 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13830 dw_loc_descr_ref copy
;
13831 add_loc_descr (&list
->expr
, ref
);
13832 list
= list
->dw_loc_next
;
13835 copy
= ggc_alloc_dw_loc_descr_node ();
13836 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13837 add_loc_descr (&list
->expr
, copy
);
13838 while (copy
->dw_loc_next
)
13840 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13841 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13842 copy
->dw_loc_next
= new_copy
;
13845 list
= list
->dw_loc_next
;
13849 /* Given two lists RET and LIST
13850 produce location list that is result of adding expression in LIST
13851 to expression in RET on each position in program.
13852 Might be destructive on both RET and LIST.
13854 TODO: We handle only simple cases of RET or LIST having at most one
13855 element. General case would inolve sorting the lists in program order
13856 and merging them that will need some additional work.
13857 Adding that will improve quality of debug info especially for SRA-ed
13861 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13870 if (!list
->dw_loc_next
)
13872 add_loc_descr_to_each (*ret
, list
->expr
);
13875 if (!(*ret
)->dw_loc_next
)
13877 add_loc_descr_to_each (list
, (*ret
)->expr
);
13881 expansion_failed (NULL_TREE
, NULL_RTX
,
13882 "Don't know how to merge two non-trivial"
13883 " location lists.\n");
13888 /* LOC is constant expression. Try a luck, look it up in constant
13889 pool and return its loc_descr of its address. */
13891 static dw_loc_descr_ref
13892 cst_pool_loc_descr (tree loc
)
13894 /* Get an RTL for this, if something has been emitted. */
13895 rtx rtl
= lookup_constant_def (loc
);
13897 if (!rtl
|| !MEM_P (rtl
))
13902 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13904 /* TODO: We might get more coverage if we was actually delaying expansion
13905 of all expressions till end of compilation when constant pools are fully
13907 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13909 expansion_failed (loc
, NULL_RTX
,
13910 "CST value in contant pool but not marked.");
13913 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13914 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13917 /* Return dw_loc_list representing address of addr_expr LOC
13918 by looking for inner INDIRECT_REF expression and turning
13919 it into simple arithmetics. */
13921 static dw_loc_list_ref
13922 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13925 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13926 enum machine_mode mode
;
13927 int unsignedp
, volatilep
= 0;
13928 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13930 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13931 &bitsize
, &bitpos
, &offset
, &mode
,
13932 &unsignedp
, &volatilep
, false);
13934 if (bitpos
% BITS_PER_UNIT
)
13936 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13939 if (!INDIRECT_REF_P (obj
))
13941 expansion_failed (obj
,
13942 NULL_RTX
, "no indirect ref in inner refrence");
13945 if (!offset
&& !bitpos
)
13946 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13948 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13949 && (dwarf_version
>= 4 || !dwarf_strict
))
13951 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13956 /* Variable offset. */
13957 list_ret1
= loc_list_from_tree (offset
, 0);
13958 if (list_ret1
== 0)
13960 add_loc_list (&list_ret
, list_ret1
);
13963 add_loc_descr_to_each (list_ret
,
13964 new_loc_descr (DW_OP_plus
, 0, 0));
13966 bytepos
= bitpos
/ BITS_PER_UNIT
;
13968 add_loc_descr_to_each (list_ret
,
13969 new_loc_descr (DW_OP_plus_uconst
,
13971 else if (bytepos
< 0)
13972 loc_list_plus_const (list_ret
, bytepos
);
13973 add_loc_descr_to_each (list_ret
,
13974 new_loc_descr (DW_OP_stack_value
, 0, 0));
13980 /* Generate Dwarf location list representing LOC.
13981 If WANT_ADDRESS is false, expression computing LOC will be computed
13982 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13983 if WANT_ADDRESS is 2, expression computing address useable in location
13984 will be returned (i.e. DW_OP_reg can be used
13985 to refer to register values). */
13987 static dw_loc_list_ref
13988 loc_list_from_tree (tree loc
, int want_address
)
13990 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13991 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13992 int have_address
= 0;
13993 enum dwarf_location_atom op
;
13995 /* ??? Most of the time we do not take proper care for sign/zero
13996 extending the values properly. Hopefully this won't be a real
13999 switch (TREE_CODE (loc
))
14002 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14005 case PLACEHOLDER_EXPR
:
14006 /* This case involves extracting fields from an object to determine the
14007 position of other fields. We don't try to encode this here. The
14008 only user of this is Ada, which encodes the needed information using
14009 the names of types. */
14010 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
14014 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14015 /* There are no opcodes for these operations. */
14018 case PREINCREMENT_EXPR
:
14019 case PREDECREMENT_EXPR
:
14020 case POSTINCREMENT_EXPR
:
14021 case POSTDECREMENT_EXPR
:
14022 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14023 /* There are no opcodes for these operations. */
14027 /* If we already want an address, see if there is INDIRECT_REF inside
14028 e.g. for &this->field. */
14031 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14032 (loc
, want_address
== 2);
14035 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14036 && (ret
= cst_pool_loc_descr (loc
)))
14039 /* Otherwise, process the argument and look for the address. */
14040 if (!list_ret
&& !ret
)
14041 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
14045 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14051 if (DECL_THREAD_LOCAL_P (loc
))
14054 enum dwarf_location_atom tls_op
;
14055 enum dtprel_bool dtprel
= dtprel_false
;
14057 if (targetm
.have_tls
)
14059 /* If this is not defined, we have no way to emit the
14061 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14064 /* The way DW_OP_GNU_push_tls_address is specified, we
14065 can only look up addresses of objects in the current
14066 module. We used DW_OP_addr as first op, but that's
14067 wrong, because DW_OP_addr is relocated by the debug
14068 info consumer, while DW_OP_GNU_push_tls_address
14069 operand shouldn't be. */
14070 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14072 dtprel
= dtprel_true
;
14073 tls_op
= DW_OP_GNU_push_tls_address
;
14077 if (!targetm
.emutls
.debug_form_tls_address
14078 || !(dwarf_version
>= 3 || !dwarf_strict
))
14080 /* We stuffed the control variable into the DECL_VALUE_EXPR
14081 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14082 no longer appear in gimple code. We used the control
14083 variable in specific so that we could pick it up here. */
14084 loc
= DECL_VALUE_EXPR (loc
);
14085 tls_op
= DW_OP_form_tls_address
;
14088 rtl
= rtl_for_decl_location (loc
);
14089 if (rtl
== NULL_RTX
)
14094 rtl
= XEXP (rtl
, 0);
14095 if (! CONSTANT_P (rtl
))
14098 ret
= new_addr_loc_descr (rtl
, dtprel
);
14099 ret1
= new_loc_descr (tls_op
, 0, 0);
14100 add_loc_descr (&ret
, ret1
);
14109 if (DECL_HAS_VALUE_EXPR_P (loc
))
14110 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14114 case FUNCTION_DECL
:
14117 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14119 if (loc_list
&& loc_list
->first
)
14121 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14122 have_address
= want_address
!= 0;
14125 rtl
= rtl_for_decl_location (loc
);
14126 if (rtl
== NULL_RTX
)
14128 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14131 else if (CONST_INT_P (rtl
))
14133 HOST_WIDE_INT val
= INTVAL (rtl
);
14134 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14135 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14136 ret
= int_loc_descriptor (val
);
14138 else if (GET_CODE (rtl
) == CONST_STRING
)
14140 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14143 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14144 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14147 enum machine_mode mode
, mem_mode
;
14149 /* Certain constructs can only be represented at top-level. */
14150 if (want_address
== 2)
14152 ret
= loc_descriptor (rtl
, VOIDmode
,
14153 VAR_INIT_STATUS_INITIALIZED
);
14158 mode
= GET_MODE (rtl
);
14159 mem_mode
= VOIDmode
;
14163 mode
= get_address_mode (rtl
);
14164 rtl
= XEXP (rtl
, 0);
14167 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14168 VAR_INIT_STATUS_INITIALIZED
);
14171 expansion_failed (loc
, rtl
,
14172 "failed to produce loc descriptor for rtl");
14179 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14183 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14187 case COMPOUND_EXPR
:
14188 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14191 case VIEW_CONVERT_EXPR
:
14194 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14196 case COMPONENT_REF
:
14197 case BIT_FIELD_REF
:
14199 case ARRAY_RANGE_REF
:
14200 case REALPART_EXPR
:
14201 case IMAGPART_EXPR
:
14204 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14205 enum machine_mode mode
;
14206 int unsignedp
, volatilep
= 0;
14208 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14209 &unsignedp
, &volatilep
, false);
14211 gcc_assert (obj
!= loc
);
14213 list_ret
= loc_list_from_tree (obj
,
14215 && !bitpos
&& !offset
? 2 : 1);
14216 /* TODO: We can extract value of the small expression via shifting even
14217 for nonzero bitpos. */
14220 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14222 expansion_failed (loc
, NULL_RTX
,
14223 "bitfield access");
14227 if (offset
!= NULL_TREE
)
14229 /* Variable offset. */
14230 list_ret1
= loc_list_from_tree (offset
, 0);
14231 if (list_ret1
== 0)
14233 add_loc_list (&list_ret
, list_ret1
);
14236 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14239 bytepos
= bitpos
/ BITS_PER_UNIT
;
14241 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14242 else if (bytepos
< 0)
14243 loc_list_plus_const (list_ret
, bytepos
);
14250 if ((want_address
|| !host_integerp (loc
, 0))
14251 && (ret
= cst_pool_loc_descr (loc
)))
14253 else if (want_address
== 2
14254 && host_integerp (loc
, 0)
14255 && (ret
= address_of_int_loc_descriptor
14256 (int_size_in_bytes (TREE_TYPE (loc
)),
14257 tree_low_cst (loc
, 0))))
14259 else if (host_integerp (loc
, 0))
14260 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
14263 expansion_failed (loc
, NULL_RTX
,
14264 "Integer operand is not host integer");
14273 if ((ret
= cst_pool_loc_descr (loc
)))
14276 /* We can construct small constants here using int_loc_descriptor. */
14277 expansion_failed (loc
, NULL_RTX
,
14278 "constructor or constant not in constant pool");
14281 case TRUTH_AND_EXPR
:
14282 case TRUTH_ANDIF_EXPR
:
14287 case TRUTH_XOR_EXPR
:
14292 case TRUTH_OR_EXPR
:
14293 case TRUTH_ORIF_EXPR
:
14298 case FLOOR_DIV_EXPR
:
14299 case CEIL_DIV_EXPR
:
14300 case ROUND_DIV_EXPR
:
14301 case TRUNC_DIV_EXPR
:
14302 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14311 case FLOOR_MOD_EXPR
:
14312 case CEIL_MOD_EXPR
:
14313 case ROUND_MOD_EXPR
:
14314 case TRUNC_MOD_EXPR
:
14315 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14320 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14321 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14322 if (list_ret
== 0 || list_ret1
== 0)
14325 add_loc_list (&list_ret
, list_ret1
);
14328 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14329 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14330 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14331 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14332 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14344 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14347 case POINTER_PLUS_EXPR
:
14349 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14351 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14355 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14363 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14370 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14377 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14384 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14399 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14400 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14401 if (list_ret
== 0 || list_ret1
== 0)
14404 add_loc_list (&list_ret
, list_ret1
);
14407 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14410 case TRUTH_NOT_EXPR
:
14424 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14428 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14434 const enum tree_code code
=
14435 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14437 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14438 build2 (code
, integer_type_node
,
14439 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14440 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14443 /* ... fall through ... */
14447 dw_loc_descr_ref lhs
14448 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14449 dw_loc_list_ref rhs
14450 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14451 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14453 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14454 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14457 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14458 add_loc_descr_to_each (list_ret
, bra_node
);
14460 add_loc_list (&list_ret
, rhs
);
14461 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14462 add_loc_descr_to_each (list_ret
, jump_node
);
14464 add_loc_descr_to_each (list_ret
, lhs
);
14465 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14466 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14468 /* ??? Need a node to point the skip at. Use a nop. */
14469 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14470 add_loc_descr_to_each (list_ret
, tmp
);
14471 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14472 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14476 case FIX_TRUNC_EXPR
:
14480 /* Leave front-end specific codes as simply unknown. This comes
14481 up, for instance, with the C STMT_EXPR. */
14482 if ((unsigned int) TREE_CODE (loc
)
14483 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14485 expansion_failed (loc
, NULL_RTX
,
14486 "language specific tree node");
14490 #ifdef ENABLE_CHECKING
14491 /* Otherwise this is a generic code; we should just lists all of
14492 these explicitly. We forgot one. */
14493 gcc_unreachable ();
14495 /* In a release build, we want to degrade gracefully: better to
14496 generate incomplete debugging information than to crash. */
14501 if (!ret
&& !list_ret
)
14504 if (want_address
== 2 && !have_address
14505 && (dwarf_version
>= 4 || !dwarf_strict
))
14507 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14509 expansion_failed (loc
, NULL_RTX
,
14510 "DWARF address size mismatch");
14514 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14516 add_loc_descr_to_each (list_ret
,
14517 new_loc_descr (DW_OP_stack_value
, 0, 0));
14520 /* Show if we can't fill the request for an address. */
14521 if (want_address
&& !have_address
)
14523 expansion_failed (loc
, NULL_RTX
,
14524 "Want address and only have value");
14528 gcc_assert (!ret
|| !list_ret
);
14530 /* If we've got an address and don't want one, dereference. */
14531 if (!want_address
&& have_address
)
14533 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14535 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14537 expansion_failed (loc
, NULL_RTX
,
14538 "DWARF address size mismatch");
14541 else if (size
== DWARF2_ADDR_SIZE
)
14544 op
= DW_OP_deref_size
;
14547 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14549 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14552 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14557 /* Same as above but return only single location expression. */
14558 static dw_loc_descr_ref
14559 loc_descriptor_from_tree (tree loc
, int want_address
)
14561 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14564 if (ret
->dw_loc_next
)
14566 expansion_failed (loc
, NULL_RTX
,
14567 "Location list where only loc descriptor needed");
14573 /* Given a value, round it up to the lowest multiple of `boundary'
14574 which is not less than the value itself. */
14576 static inline HOST_WIDE_INT
14577 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14579 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14582 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14583 pointer to the declared type for the relevant field variable, or return
14584 `integer_type_node' if the given node turns out to be an
14585 ERROR_MARK node. */
14588 field_type (const_tree decl
)
14592 if (TREE_CODE (decl
) == ERROR_MARK
)
14593 return integer_type_node
;
14595 type
= DECL_BIT_FIELD_TYPE (decl
);
14596 if (type
== NULL_TREE
)
14597 type
= TREE_TYPE (decl
);
14602 /* Given a pointer to a tree node, return the alignment in bits for
14603 it, or else return BITS_PER_WORD if the node actually turns out to
14604 be an ERROR_MARK node. */
14606 static inline unsigned
14607 simple_type_align_in_bits (const_tree type
)
14609 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14612 static inline unsigned
14613 simple_decl_align_in_bits (const_tree decl
)
14615 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14618 /* Return the result of rounding T up to ALIGN. */
14620 static inline double_int
14621 round_up_to_align (double_int t
, unsigned int align
)
14623 double_int alignd
= double_int::from_uhwi (align
);
14625 t
+= double_int_minus_one
;
14626 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14631 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14632 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14633 or return 0 if we are unable to determine what that offset is, either
14634 because the argument turns out to be a pointer to an ERROR_MARK node, or
14635 because the offset is actually variable. (We can't handle the latter case
14638 static HOST_WIDE_INT
14639 field_byte_offset (const_tree decl
)
14641 double_int object_offset_in_bits
;
14642 double_int object_offset_in_bytes
;
14643 double_int bitpos_int
;
14645 if (TREE_CODE (decl
) == ERROR_MARK
)
14648 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14650 /* We cannot yet cope with fields whose positions are variable, so
14651 for now, when we see such things, we simply return 0. Someday, we may
14652 be able to handle such cases, but it will be damn difficult. */
14653 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14656 bitpos_int
= tree_to_double_int (bit_position (decl
));
14658 #ifdef PCC_BITFIELD_TYPE_MATTERS
14659 if (PCC_BITFIELD_TYPE_MATTERS
)
14662 tree field_size_tree
;
14663 double_int deepest_bitpos
;
14664 double_int field_size_in_bits
;
14665 unsigned int type_align_in_bits
;
14666 unsigned int decl_align_in_bits
;
14667 double_int type_size_in_bits
;
14669 type
= field_type (decl
);
14670 type_size_in_bits
= double_int_type_size_in_bits (type
);
14671 type_align_in_bits
= simple_type_align_in_bits (type
);
14673 field_size_tree
= DECL_SIZE (decl
);
14675 /* The size could be unspecified if there was an error, or for
14676 a flexible array member. */
14677 if (!field_size_tree
)
14678 field_size_tree
= bitsize_zero_node
;
14680 /* If the size of the field is not constant, use the type size. */
14681 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14682 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14684 field_size_in_bits
= type_size_in_bits
;
14686 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14688 /* The GCC front-end doesn't make any attempt to keep track of the
14689 starting bit offset (relative to the start of the containing
14690 structure type) of the hypothetical "containing object" for a
14691 bit-field. Thus, when computing the byte offset value for the
14692 start of the "containing object" of a bit-field, we must deduce
14693 this information on our own. This can be rather tricky to do in
14694 some cases. For example, handling the following structure type
14695 definition when compiling for an i386/i486 target (which only
14696 aligns long long's to 32-bit boundaries) can be very tricky:
14698 struct S { int field1; long long field2:31; };
14700 Fortunately, there is a simple rule-of-thumb which can be used
14701 in such cases. When compiling for an i386/i486, GCC will
14702 allocate 8 bytes for the structure shown above. It decides to
14703 do this based upon one simple rule for bit-field allocation.
14704 GCC allocates each "containing object" for each bit-field at
14705 the first (i.e. lowest addressed) legitimate alignment boundary
14706 (based upon the required minimum alignment for the declared
14707 type of the field) which it can possibly use, subject to the
14708 condition that there is still enough available space remaining
14709 in the containing object (when allocated at the selected point)
14710 to fully accommodate all of the bits of the bit-field itself.
14712 This simple rule makes it obvious why GCC allocates 8 bytes for
14713 each object of the structure type shown above. When looking
14714 for a place to allocate the "containing object" for `field2',
14715 the compiler simply tries to allocate a 64-bit "containing
14716 object" at each successive 32-bit boundary (starting at zero)
14717 until it finds a place to allocate that 64- bit field such that
14718 at least 31 contiguous (and previously unallocated) bits remain
14719 within that selected 64 bit field. (As it turns out, for the
14720 example above, the compiler finds it is OK to allocate the
14721 "containing object" 64-bit field at bit-offset zero within the
14724 Here we attempt to work backwards from the limited set of facts
14725 we're given, and we try to deduce from those facts, where GCC
14726 must have believed that the containing object started (within
14727 the structure type). The value we deduce is then used (by the
14728 callers of this routine) to generate DW_AT_location and
14729 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14730 the case of DW_AT_location, regular fields as well). */
14732 /* Figure out the bit-distance from the start of the structure to
14733 the "deepest" bit of the bit-field. */
14734 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14736 /* This is the tricky part. Use some fancy footwork to deduce
14737 where the lowest addressed bit of the containing object must
14739 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14741 /* Round up to type_align by default. This works best for
14743 object_offset_in_bits
14744 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14746 if (object_offset_in_bits
.ugt (bitpos_int
))
14748 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14750 /* Round up to decl_align instead. */
14751 object_offset_in_bits
14752 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14756 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14757 object_offset_in_bits
= bitpos_int
;
14759 object_offset_in_bytes
14760 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14761 true, TRUNC_DIV_EXPR
);
14762 return object_offset_in_bytes
.to_shwi ();
14765 /* The following routines define various Dwarf attributes and any data
14766 associated with them. */
14768 /* Add a location description attribute value to a DIE.
14770 This emits location attributes suitable for whole variables and
14771 whole parameters. Note that the location attributes for struct fields are
14772 generated by the routine `data_member_location_attribute' below. */
14775 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14776 dw_loc_list_ref descr
)
14780 if (single_element_loc_list_p (descr
))
14781 add_AT_loc (die
, attr_kind
, descr
->expr
);
14783 add_AT_loc_list (die
, attr_kind
, descr
);
14786 /* Add DW_AT_accessibility attribute to DIE if needed. */
14789 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14791 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14792 children, otherwise the default is DW_ACCESS_public. In DWARF2
14793 the default has always been DW_ACCESS_public. */
14794 if (TREE_PROTECTED (decl
))
14795 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14796 else if (TREE_PRIVATE (decl
))
14798 if (dwarf_version
== 2
14799 || die
->die_parent
== NULL
14800 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14801 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14803 else if (dwarf_version
> 2
14805 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14806 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14809 /* Attach the specialized form of location attribute used for data members of
14810 struct and union types. In the special case of a FIELD_DECL node which
14811 represents a bit-field, the "offset" part of this special location
14812 descriptor must indicate the distance in bytes from the lowest-addressed
14813 byte of the containing struct or union type to the lowest-addressed byte of
14814 the "containing object" for the bit-field. (See the `field_byte_offset'
14817 For any given bit-field, the "containing object" is a hypothetical object
14818 (of some integral or enum type) within which the given bit-field lives. The
14819 type of this hypothetical "containing object" is always the same as the
14820 declared type of the individual bit-field itself (for GCC anyway... the
14821 DWARF spec doesn't actually mandate this). Note that it is the size (in
14822 bytes) of the hypothetical "containing object" which will be given in the
14823 DW_AT_byte_size attribute for this bit-field. (See the
14824 `byte_size_attribute' function below.) It is also used when calculating the
14825 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14826 function below.) */
14829 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14831 HOST_WIDE_INT offset
;
14832 dw_loc_descr_ref loc_descr
= 0;
14834 if (TREE_CODE (decl
) == TREE_BINFO
)
14836 /* We're working on the TAG_inheritance for a base class. */
14837 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14839 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14840 aren't at a fixed offset from all (sub)objects of the same
14841 type. We need to extract the appropriate offset from our
14842 vtable. The following dwarf expression means
14844 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14846 This is specific to the V3 ABI, of course. */
14848 dw_loc_descr_ref tmp
;
14850 /* Make a copy of the object address. */
14851 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14852 add_loc_descr (&loc_descr
, tmp
);
14854 /* Extract the vtable address. */
14855 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14856 add_loc_descr (&loc_descr
, tmp
);
14858 /* Calculate the address of the offset. */
14859 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14860 gcc_assert (offset
< 0);
14862 tmp
= int_loc_descriptor (-offset
);
14863 add_loc_descr (&loc_descr
, tmp
);
14864 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14865 add_loc_descr (&loc_descr
, tmp
);
14867 /* Extract the offset. */
14868 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14869 add_loc_descr (&loc_descr
, tmp
);
14871 /* Add it to the object address. */
14872 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14873 add_loc_descr (&loc_descr
, tmp
);
14876 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14879 offset
= field_byte_offset (decl
);
14883 if (dwarf_version
> 2)
14885 /* Don't need to output a location expression, just the constant. */
14887 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14889 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14894 enum dwarf_location_atom op
;
14896 /* The DWARF2 standard says that we should assume that the structure
14897 address is already on the stack, so we can specify a structure
14898 field address by using DW_OP_plus_uconst. */
14899 op
= DW_OP_plus_uconst
;
14900 loc_descr
= new_loc_descr (op
, offset
, 0);
14904 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14907 /* Writes integer values to dw_vec_const array. */
14910 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14914 *dest
++ = val
& 0xff;
14920 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14922 static HOST_WIDE_INT
14923 extract_int (const unsigned char *src
, unsigned int size
)
14925 HOST_WIDE_INT val
= 0;
14931 val
|= *--src
& 0xff;
14937 /* Writes double_int values to dw_vec_const array. */
14940 insert_double (double_int val
, unsigned char *dest
)
14942 unsigned char *p0
= dest
;
14943 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14945 if (WORDS_BIG_ENDIAN
)
14951 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14952 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14955 /* Writes floating point values to dw_vec_const array. */
14958 insert_float (const_rtx rtl
, unsigned char *array
)
14960 REAL_VALUE_TYPE rv
;
14964 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14965 real_to_target (val
, &rv
, GET_MODE (rtl
));
14967 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14968 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14970 insert_int (val
[i
], 4, array
);
14975 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14976 does not have a "location" either in memory or in a register. These
14977 things can arise in GNU C when a constant is passed as an actual parameter
14978 to an inlined function. They can also arise in C++ where declared
14979 constants do not necessarily get memory "homes". */
14982 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14984 switch (GET_CODE (rtl
))
14988 HOST_WIDE_INT val
= INTVAL (rtl
);
14991 add_AT_int (die
, DW_AT_const_value
, val
);
14993 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14998 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14999 floating-point constant. A CONST_DOUBLE is used whenever the
15000 constant requires more than one word in order to be adequately
15003 enum machine_mode mode
= GET_MODE (rtl
);
15005 if (SCALAR_FLOAT_MODE_P (mode
))
15007 unsigned int length
= GET_MODE_SIZE (mode
);
15008 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
15010 insert_float (rtl
, array
);
15011 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15014 add_AT_double (die
, DW_AT_const_value
,
15015 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15021 enum machine_mode mode
= GET_MODE (rtl
);
15022 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15023 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15024 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
15025 (length
* elt_size
);
15029 switch (GET_MODE_CLASS (mode
))
15031 case MODE_VECTOR_INT
:
15032 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15034 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15035 double_int val
= rtx_to_double_int (elt
);
15037 if (elt_size
<= sizeof (HOST_WIDE_INT
))
15038 insert_int (val
.to_shwi (), elt_size
, p
);
15041 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
15042 insert_double (val
, p
);
15047 case MODE_VECTOR_FLOAT
:
15048 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15050 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15051 insert_float (elt
, p
);
15056 gcc_unreachable ();
15059 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15064 if (dwarf_version
>= 4 || !dwarf_strict
)
15066 dw_loc_descr_ref loc_result
;
15067 resolve_one_addr (&rtl
, NULL
);
15069 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15070 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15071 add_AT_loc (die
, DW_AT_location
, loc_result
);
15072 vec_safe_push (used_rtx_array
, rtl
);
15078 if (CONSTANT_P (XEXP (rtl
, 0)))
15079 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15082 if (!const_ok_for_output (rtl
))
15085 if (dwarf_version
>= 4 || !dwarf_strict
)
15090 /* In cases where an inlined instance of an inline function is passed
15091 the address of an `auto' variable (which is local to the caller) we
15092 can get a situation where the DECL_RTL of the artificial local
15093 variable (for the inlining) which acts as a stand-in for the
15094 corresponding formal parameter (of the inline function) will look
15095 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15096 exactly a compile-time constant expression, but it isn't the address
15097 of the (artificial) local variable either. Rather, it represents the
15098 *value* which the artificial local variable always has during its
15099 lifetime. We currently have no way to represent such quasi-constant
15100 values in Dwarf, so for now we just punt and generate nothing. */
15108 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15109 && MEM_READONLY_P (rtl
)
15110 && GET_MODE (rtl
) == BLKmode
)
15112 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15118 /* No other kinds of rtx should be possible here. */
15119 gcc_unreachable ();
15124 /* Determine whether the evaluation of EXPR references any variables
15125 or functions which aren't otherwise used (and therefore may not be
15128 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15129 void * data ATTRIBUTE_UNUSED
)
15131 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15132 *walk_subtrees
= 0;
15134 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15135 && ! TREE_ASM_WRITTEN (*tp
))
15137 /* ??? The C++ FE emits debug information for using decls, so
15138 putting gcc_unreachable here falls over. See PR31899. For now
15139 be conservative. */
15140 else if (!cgraph_global_info_ready
15141 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15143 else if (TREE_CODE (*tp
) == VAR_DECL
)
15145 struct varpool_node
*node
= varpool_get_node (*tp
);
15146 if (!node
|| !node
->symbol
.definition
)
15149 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15150 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15152 /* The call graph machinery must have finished analyzing,
15153 optimizing and gimplifying the CU by now.
15154 So if *TP has no call graph node associated
15155 to it, it means *TP will not be emitted. */
15156 if (!cgraph_get_node (*tp
))
15159 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15165 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15166 for use in a later add_const_value_attribute call. */
15169 rtl_for_decl_init (tree init
, tree type
)
15171 rtx rtl
= NULL_RTX
;
15175 /* If a variable is initialized with a string constant without embedded
15176 zeros, build CONST_STRING. */
15177 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15179 tree enttype
= TREE_TYPE (type
);
15180 tree domain
= TYPE_DOMAIN (type
);
15181 enum machine_mode mode
= TYPE_MODE (enttype
);
15183 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15185 && integer_zerop (TYPE_MIN_VALUE (domain
))
15186 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15187 TREE_STRING_LENGTH (init
) - 1) == 0
15188 && ((size_t) TREE_STRING_LENGTH (init
)
15189 == strlen (TREE_STRING_POINTER (init
)) + 1))
15191 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15192 ggc_strdup (TREE_STRING_POINTER (init
)));
15193 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15194 MEM_READONLY_P (rtl
) = 1;
15197 /* Other aggregates, and complex values, could be represented using
15199 else if (AGGREGATE_TYPE_P (type
)
15200 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15201 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15202 || TREE_CODE (type
) == COMPLEX_TYPE
)
15204 /* Vectors only work if their mode is supported by the target.
15205 FIXME: generic vectors ought to work too. */
15206 else if (TREE_CODE (type
) == VECTOR_TYPE
15207 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15209 /* If the initializer is something that we know will expand into an
15210 immediate RTL constant, expand it now. We must be careful not to
15211 reference variables which won't be output. */
15212 else if (initializer_constant_valid_p (init
, type
)
15213 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15215 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15217 if (TREE_CODE (type
) == VECTOR_TYPE
)
15218 switch (TREE_CODE (init
))
15223 if (TREE_CONSTANT (init
))
15225 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15226 bool constant_p
= true;
15228 unsigned HOST_WIDE_INT ix
;
15230 /* Even when ctor is constant, it might contain non-*_CST
15231 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15232 belong into VECTOR_CST nodes. */
15233 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15234 if (!CONSTANT_CLASS_P (value
))
15236 constant_p
= false;
15242 init
= build_vector_from_ctor (type
, elts
);
15252 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15254 /* If expand_expr returns a MEM, it wasn't immediate. */
15255 gcc_assert (!rtl
|| !MEM_P (rtl
));
15261 /* Generate RTL for the variable DECL to represent its location. */
15264 rtl_for_decl_location (tree decl
)
15268 /* Here we have to decide where we are going to say the parameter "lives"
15269 (as far as the debugger is concerned). We only have a couple of
15270 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15272 DECL_RTL normally indicates where the parameter lives during most of the
15273 activation of the function. If optimization is enabled however, this
15274 could be either NULL or else a pseudo-reg. Both of those cases indicate
15275 that the parameter doesn't really live anywhere (as far as the code
15276 generation parts of GCC are concerned) during most of the function's
15277 activation. That will happen (for example) if the parameter is never
15278 referenced within the function.
15280 We could just generate a location descriptor here for all non-NULL
15281 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15282 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15283 where DECL_RTL is NULL or is a pseudo-reg.
15285 Note however that we can only get away with using DECL_INCOMING_RTL as
15286 a backup substitute for DECL_RTL in certain limited cases. In cases
15287 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15288 we can be sure that the parameter was passed using the same type as it is
15289 declared to have within the function, and that its DECL_INCOMING_RTL
15290 points us to a place where a value of that type is passed.
15292 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15293 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15294 because in these cases DECL_INCOMING_RTL points us to a value of some
15295 type which is *different* from the type of the parameter itself. Thus,
15296 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15297 such cases, the debugger would end up (for example) trying to fetch a
15298 `float' from a place which actually contains the first part of a
15299 `double'. That would lead to really incorrect and confusing
15300 output at debug-time.
15302 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15303 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15304 are a couple of exceptions however. On little-endian machines we can
15305 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15306 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15307 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15308 when (on a little-endian machine) a non-prototyped function has a
15309 parameter declared to be of type `short' or `char'. In such cases,
15310 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15311 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15312 passed `int' value. If the debugger then uses that address to fetch
15313 a `short' or a `char' (on a little-endian machine) the result will be
15314 the correct data, so we allow for such exceptional cases below.
15316 Note that our goal here is to describe the place where the given formal
15317 parameter lives during most of the function's activation (i.e. between the
15318 end of the prologue and the start of the epilogue). We'll do that as best
15319 as we can. Note however that if the given formal parameter is modified
15320 sometime during the execution of the function, then a stack backtrace (at
15321 debug-time) will show the function as having been called with the *new*
15322 value rather than the value which was originally passed in. This happens
15323 rarely enough that it is not a major problem, but it *is* a problem, and
15324 I'd like to fix it.
15326 A future version of dwarf2out.c may generate two additional attributes for
15327 any given DW_TAG_formal_parameter DIE which will describe the "passed
15328 type" and the "passed location" for the given formal parameter in addition
15329 to the attributes we now generate to indicate the "declared type" and the
15330 "active location" for each parameter. This additional set of attributes
15331 could be used by debuggers for stack backtraces. Separately, note that
15332 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15333 This happens (for example) for inlined-instances of inline function formal
15334 parameters which are never referenced. This really shouldn't be
15335 happening. All PARM_DECL nodes should get valid non-NULL
15336 DECL_INCOMING_RTL values. FIXME. */
15338 /* Use DECL_RTL as the "location" unless we find something better. */
15339 rtl
= DECL_RTL_IF_SET (decl
);
15341 /* When generating abstract instances, ignore everything except
15342 constants, symbols living in memory, and symbols living in
15343 fixed registers. */
15344 if (! reload_completed
)
15347 && (CONSTANT_P (rtl
)
15349 && CONSTANT_P (XEXP (rtl
, 0)))
15351 && TREE_CODE (decl
) == VAR_DECL
15352 && TREE_STATIC (decl
))))
15354 rtl
= targetm
.delegitimize_address (rtl
);
15359 else if (TREE_CODE (decl
) == PARM_DECL
)
15361 if (rtl
== NULL_RTX
15362 || is_pseudo_reg (rtl
)
15364 && is_pseudo_reg (XEXP (rtl
, 0))
15365 && DECL_INCOMING_RTL (decl
)
15366 && MEM_P (DECL_INCOMING_RTL (decl
))
15367 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15369 tree declared_type
= TREE_TYPE (decl
);
15370 tree passed_type
= DECL_ARG_TYPE (decl
);
15371 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15372 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15374 /* This decl represents a formal parameter which was optimized out.
15375 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15376 all cases where (rtl == NULL_RTX) just below. */
15377 if (dmode
== pmode
)
15378 rtl
= DECL_INCOMING_RTL (decl
);
15379 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15380 && SCALAR_INT_MODE_P (dmode
)
15381 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15382 && DECL_INCOMING_RTL (decl
))
15384 rtx inc
= DECL_INCOMING_RTL (decl
);
15387 else if (MEM_P (inc
))
15389 if (BYTES_BIG_ENDIAN
)
15390 rtl
= adjust_address_nv (inc
, dmode
,
15391 GET_MODE_SIZE (pmode
)
15392 - GET_MODE_SIZE (dmode
));
15399 /* If the parm was passed in registers, but lives on the stack, then
15400 make a big endian correction if the mode of the type of the
15401 parameter is not the same as the mode of the rtl. */
15402 /* ??? This is the same series of checks that are made in dbxout.c before
15403 we reach the big endian correction code there. It isn't clear if all
15404 of these checks are necessary here, but keeping them all is the safe
15406 else if (MEM_P (rtl
)
15407 && XEXP (rtl
, 0) != const0_rtx
15408 && ! CONSTANT_P (XEXP (rtl
, 0))
15409 /* Not passed in memory. */
15410 && !MEM_P (DECL_INCOMING_RTL (decl
))
15411 /* Not passed by invisible reference. */
15412 && (!REG_P (XEXP (rtl
, 0))
15413 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15414 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15415 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15416 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15419 /* Big endian correction check. */
15420 && BYTES_BIG_ENDIAN
15421 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15422 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15425 enum machine_mode addr_mode
= get_address_mode (rtl
);
15426 int offset
= (UNITS_PER_WORD
15427 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15429 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15430 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15433 else if (TREE_CODE (decl
) == VAR_DECL
15436 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15437 && BYTES_BIG_ENDIAN
)
15439 enum machine_mode addr_mode
= get_address_mode (rtl
);
15440 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15441 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15443 /* If a variable is declared "register" yet is smaller than
15444 a register, then if we store the variable to memory, it
15445 looks like we're storing a register-sized value, when in
15446 fact we are not. We need to adjust the offset of the
15447 storage location to reflect the actual value's bytes,
15448 else gdb will not be able to display it. */
15450 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15451 plus_constant (addr_mode
, XEXP (rtl
, 0),
15455 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15456 and will have been substituted directly into all expressions that use it.
15457 C does not have such a concept, but C++ and other languages do. */
15458 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15459 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15462 rtl
= targetm
.delegitimize_address (rtl
);
15464 /* If we don't look past the constant pool, we risk emitting a
15465 reference to a constant pool entry that isn't referenced from
15466 code, and thus is not emitted. */
15468 rtl
= avoid_constant_pool_reference (rtl
);
15470 /* Try harder to get a rtl. If this symbol ends up not being emitted
15471 in the current CU, resolve_addr will remove the expression referencing
15473 if (rtl
== NULL_RTX
15474 && TREE_CODE (decl
) == VAR_DECL
15475 && !DECL_EXTERNAL (decl
)
15476 && TREE_STATIC (decl
)
15477 && DECL_NAME (decl
)
15478 && !DECL_HARD_REGISTER (decl
)
15479 && DECL_MODE (decl
) != VOIDmode
)
15481 rtl
= make_decl_rtl_for_debug (decl
);
15483 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15484 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15491 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15492 returned. If so, the decl for the COMMON block is returned, and the
15493 value is the offset into the common block for the symbol. */
15496 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15498 tree val_expr
, cvar
;
15499 enum machine_mode mode
;
15500 HOST_WIDE_INT bitsize
, bitpos
;
15502 int unsignedp
, volatilep
= 0;
15504 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15505 it does not have a value (the offset into the common area), or if it
15506 is thread local (as opposed to global) then it isn't common, and shouldn't
15507 be handled as such. */
15508 if (TREE_CODE (decl
) != VAR_DECL
15509 || !TREE_STATIC (decl
)
15510 || !DECL_HAS_VALUE_EXPR_P (decl
)
15514 val_expr
= DECL_VALUE_EXPR (decl
);
15515 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15518 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15519 &mode
, &unsignedp
, &volatilep
, true);
15521 if (cvar
== NULL_TREE
15522 || TREE_CODE (cvar
) != VAR_DECL
15523 || DECL_ARTIFICIAL (cvar
)
15524 || !TREE_PUBLIC (cvar
))
15528 if (offset
!= NULL
)
15530 if (!host_integerp (offset
, 0))
15532 *value
= tree_low_cst (offset
, 0);
15535 *value
+= bitpos
/ BITS_PER_UNIT
;
15540 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15541 data attribute for a variable or a parameter. We generate the
15542 DW_AT_const_value attribute only in those cases where the given variable
15543 or parameter does not have a true "location" either in memory or in a
15544 register. This can happen (for example) when a constant is passed as an
15545 actual argument in a call to an inline function. (It's possible that
15546 these things can crop up in other ways also.) Note that one type of
15547 constant value which can be passed into an inlined function is a constant
15548 pointer. This can happen for example if an actual argument in an inlined
15549 function call evaluates to a compile-time constant address.
15551 CACHE_P is true if it is worth caching the location list for DECL,
15552 so that future calls can reuse it rather than regenerate it from scratch.
15553 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15554 since we will need to refer to them each time the function is inlined. */
15557 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15558 enum dwarf_attribute attr
)
15561 dw_loc_list_ref list
;
15562 var_loc_list
*loc_list
;
15563 cached_dw_loc_list
*cache
;
15566 if (TREE_CODE (decl
) == ERROR_MARK
)
15569 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15570 || TREE_CODE (decl
) == RESULT_DECL
);
15572 /* Try to get some constant RTL for this decl, and use that as the value of
15575 rtl
= rtl_for_decl_location (decl
);
15576 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15577 && add_const_value_attribute (die
, rtl
))
15580 /* See if we have single element location list that is equivalent to
15581 a constant value. That way we are better to use add_const_value_attribute
15582 rather than expanding constant value equivalent. */
15583 loc_list
= lookup_decl_loc (decl
);
15586 && loc_list
->first
->next
== NULL
15587 && NOTE_P (loc_list
->first
->loc
)
15588 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15589 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15591 struct var_loc_node
*node
;
15593 node
= loc_list
->first
;
15594 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15595 if (GET_CODE (rtl
) == EXPR_LIST
)
15596 rtl
= XEXP (rtl
, 0);
15597 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15598 && add_const_value_attribute (die
, rtl
))
15601 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15602 list several times. See if we've already cached the contents. */
15604 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15608 cache
= (cached_dw_loc_list
*)
15609 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15611 list
= cache
->loc_list
;
15615 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15616 /* It is usually worth caching this result if the decl is from
15617 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15618 if (cache_p
&& list
&& list
->dw_loc_next
)
15620 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15621 DECL_UID (decl
), INSERT
);
15622 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15623 cache
->decl_id
= DECL_UID (decl
);
15624 cache
->loc_list
= list
;
15630 add_AT_location_description (die
, attr
, list
);
15633 /* None of that worked, so it must not really have a location;
15634 try adding a constant value attribute from the DECL_INITIAL. */
15635 return tree_add_const_value_attribute_for_decl (die
, decl
);
15638 /* Add VARIABLE and DIE into deferred locations list. */
15641 defer_location (tree variable
, dw_die_ref die
)
15643 deferred_locations entry
;
15644 entry
.variable
= variable
;
15646 vec_safe_push (deferred_locations_list
, entry
);
15649 /* Helper function for tree_add_const_value_attribute. Natively encode
15650 initializer INIT into an array. Return true if successful. */
15653 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15657 if (init
== NULL_TREE
)
15661 switch (TREE_CODE (init
))
15664 type
= TREE_TYPE (init
);
15665 if (TREE_CODE (type
) == ARRAY_TYPE
)
15667 tree enttype
= TREE_TYPE (type
);
15668 enum machine_mode mode
= TYPE_MODE (enttype
);
15670 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15672 if (int_size_in_bytes (type
) != size
)
15674 if (size
> TREE_STRING_LENGTH (init
))
15676 memcpy (array
, TREE_STRING_POINTER (init
),
15677 TREE_STRING_LENGTH (init
));
15678 memset (array
+ TREE_STRING_LENGTH (init
),
15679 '\0', size
- TREE_STRING_LENGTH (init
));
15682 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15687 type
= TREE_TYPE (init
);
15688 if (int_size_in_bytes (type
) != size
)
15690 if (TREE_CODE (type
) == ARRAY_TYPE
)
15692 HOST_WIDE_INT min_index
;
15693 unsigned HOST_WIDE_INT cnt
;
15694 int curpos
= 0, fieldsize
;
15695 constructor_elt
*ce
;
15697 if (TYPE_DOMAIN (type
) == NULL_TREE
15698 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15701 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15702 if (fieldsize
<= 0)
15705 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15706 memset (array
, '\0', size
);
15707 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15709 tree val
= ce
->value
;
15710 tree index
= ce
->index
;
15712 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15713 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15716 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15721 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15724 curpos
= pos
+ fieldsize
;
15725 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15727 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15728 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15729 while (count
-- > 0)
15732 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15733 curpos
+= fieldsize
;
15736 gcc_assert (curpos
<= size
);
15740 else if (TREE_CODE (type
) == RECORD_TYPE
15741 || TREE_CODE (type
) == UNION_TYPE
)
15743 tree field
= NULL_TREE
;
15744 unsigned HOST_WIDE_INT cnt
;
15745 constructor_elt
*ce
;
15747 if (int_size_in_bytes (type
) != size
)
15750 if (TREE_CODE (type
) == RECORD_TYPE
)
15751 field
= TYPE_FIELDS (type
);
15753 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15755 tree val
= ce
->value
;
15756 int pos
, fieldsize
;
15758 if (ce
->index
!= 0)
15764 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15767 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15768 && TYPE_DOMAIN (TREE_TYPE (field
))
15769 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15771 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15772 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15774 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15775 pos
= int_byte_position (field
);
15776 gcc_assert (pos
+ fieldsize
<= size
);
15778 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15784 case VIEW_CONVERT_EXPR
:
15785 case NON_LVALUE_EXPR
:
15786 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15788 return native_encode_expr (init
, array
, size
) == size
;
15792 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15793 attribute is the const value T. */
15796 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15799 tree type
= TREE_TYPE (t
);
15802 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15806 gcc_assert (!DECL_P (init
));
15808 rtl
= rtl_for_decl_init (init
, type
);
15810 return add_const_value_attribute (die
, rtl
);
15811 /* If the host and target are sane, try harder. */
15812 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15813 && initializer_constant_valid_p (init
, type
))
15815 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15816 if (size
> 0 && (int) size
== size
)
15818 unsigned char *array
= (unsigned char *)
15819 ggc_alloc_cleared_atomic (size
);
15821 if (native_encode_initializer (init
, array
, size
))
15823 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15832 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15833 attribute is the const value of T, where T is an integral constant
15834 variable with static storage duration
15835 (so it can't be a PARM_DECL or a RESULT_DECL). */
15838 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15842 || (TREE_CODE (decl
) != VAR_DECL
15843 && TREE_CODE (decl
) != CONST_DECL
)
15844 || (TREE_CODE (decl
) == VAR_DECL
15845 && !TREE_STATIC (decl
)))
15848 if (TREE_READONLY (decl
)
15849 && ! TREE_THIS_VOLATILE (decl
)
15850 && DECL_INITIAL (decl
))
15855 /* Don't add DW_AT_const_value if abstract origin already has one. */
15856 if (get_AT (var_die
, DW_AT_const_value
))
15859 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15862 /* Convert the CFI instructions for the current function into a
15863 location list. This is used for DW_AT_frame_base when we targeting
15864 a dwarf2 consumer that does not support the dwarf3
15865 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15868 static dw_loc_list_ref
15869 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15873 dw_loc_list_ref list
, *list_tail
;
15875 dw_cfa_location last_cfa
, next_cfa
;
15876 const char *start_label
, *last_label
, *section
;
15877 dw_cfa_location remember
;
15880 gcc_assert (fde
!= NULL
);
15882 section
= secname_for_decl (current_function_decl
);
15886 memset (&next_cfa
, 0, sizeof (next_cfa
));
15887 next_cfa
.reg
= INVALID_REGNUM
;
15888 remember
= next_cfa
;
15890 start_label
= fde
->dw_fde_begin
;
15892 /* ??? Bald assumption that the CIE opcode list does not contain
15893 advance opcodes. */
15894 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15895 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15897 last_cfa
= next_cfa
;
15898 last_label
= start_label
;
15900 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15902 /* If the first partition contained no CFI adjustments, the
15903 CIE opcodes apply to the whole first partition. */
15904 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15905 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15906 list_tail
=&(*list_tail
)->dw_loc_next
;
15907 start_label
= last_label
= fde
->dw_fde_second_begin
;
15910 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15912 switch (cfi
->dw_cfi_opc
)
15914 case DW_CFA_set_loc
:
15915 case DW_CFA_advance_loc1
:
15916 case DW_CFA_advance_loc2
:
15917 case DW_CFA_advance_loc4
:
15918 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15920 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15921 start_label
, last_label
, section
);
15923 list_tail
= &(*list_tail
)->dw_loc_next
;
15924 last_cfa
= next_cfa
;
15925 start_label
= last_label
;
15927 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15930 case DW_CFA_advance_loc
:
15931 /* The encoding is complex enough that we should never emit this. */
15932 gcc_unreachable ();
15935 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15938 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15940 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15942 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15943 start_label
, last_label
, section
);
15945 list_tail
= &(*list_tail
)->dw_loc_next
;
15946 last_cfa
= next_cfa
;
15947 start_label
= last_label
;
15949 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15950 start_label
, fde
->dw_fde_end
, section
);
15951 list_tail
= &(*list_tail
)->dw_loc_next
;
15952 start_label
= last_label
= fde
->dw_fde_second_begin
;
15956 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15958 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15959 start_label
, last_label
, section
);
15960 list_tail
= &(*list_tail
)->dw_loc_next
;
15961 start_label
= last_label
;
15964 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15966 fde
->dw_fde_second_begin
15967 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15970 if (list
&& list
->dw_loc_next
)
15976 /* Compute a displacement from the "steady-state frame pointer" to the
15977 frame base (often the same as the CFA), and store it in
15978 frame_pointer_fb_offset. OFFSET is added to the displacement
15979 before the latter is negated. */
15982 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15986 #ifdef FRAME_POINTER_CFA_OFFSET
15987 reg
= frame_pointer_rtx
;
15988 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15990 reg
= arg_pointer_rtx
;
15991 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15994 elim
= (ira_use_lra_p
15995 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15996 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15997 if (GET_CODE (elim
) == PLUS
)
15999 offset
+= INTVAL (XEXP (elim
, 1));
16000 elim
= XEXP (elim
, 0);
16003 frame_pointer_fb_offset
= -offset
;
16005 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16006 in which to eliminate. This is because it's stack pointer isn't
16007 directly accessible as a register within the ISA. To work around
16008 this, assume that while we cannot provide a proper value for
16009 frame_pointer_fb_offset, we won't need one either. */
16010 frame_pointer_fb_offset_valid
16011 = ((SUPPORTS_STACK_ALIGNMENT
16012 && (elim
== hard_frame_pointer_rtx
16013 || elim
== stack_pointer_rtx
))
16014 || elim
== (frame_pointer_needed
16015 ? hard_frame_pointer_rtx
16016 : stack_pointer_rtx
));
16019 /* Generate a DW_AT_name attribute given some string value to be included as
16020 the value of the attribute. */
16023 add_name_attribute (dw_die_ref die
, const char *name_string
)
16025 if (name_string
!= NULL
&& *name_string
!= 0)
16027 if (demangle_name_func
)
16028 name_string
= (*demangle_name_func
) (name_string
);
16030 add_AT_string (die
, DW_AT_name
, name_string
);
16034 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16035 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16036 of TYPE accordingly.
16038 ??? This is a temporary measure until after we're able to generate
16039 regular DWARF for the complex Ada type system. */
16042 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16043 dw_die_ref context_die
)
16046 dw_die_ref dtype_die
;
16048 if (!lang_hooks
.types
.descriptive_type
)
16051 dtype
= lang_hooks
.types
.descriptive_type (type
);
16055 dtype_die
= lookup_type_die (dtype
);
16058 gen_type_die (dtype
, context_die
);
16059 dtype_die
= lookup_type_die (dtype
);
16060 gcc_assert (dtype_die
);
16063 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16066 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16068 static const char *
16069 comp_dir_string (void)
16073 static const char *cached_wd
= NULL
;
16075 if (cached_wd
!= NULL
)
16078 wd
= get_src_pwd ();
16082 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16086 wdlen
= strlen (wd
);
16087 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
16089 wd1
[wdlen
] = DIR_SEPARATOR
;
16090 wd1
[wdlen
+ 1] = 0;
16094 cached_wd
= remap_debug_filename (wd
);
16098 /* Generate a DW_AT_comp_dir attribute for DIE. */
16101 add_comp_dir_attribute (dw_die_ref die
)
16103 const char * wd
= comp_dir_string ();
16105 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16108 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16112 lower_bound_default (void)
16114 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16119 case DW_LANG_C_plus_plus
:
16121 case DW_LANG_ObjC_plus_plus
:
16124 case DW_LANG_Fortran77
:
16125 case DW_LANG_Fortran90
:
16126 case DW_LANG_Fortran95
:
16130 case DW_LANG_Python
:
16131 return dwarf_version
>= 4 ? 0 : -1;
16132 case DW_LANG_Ada95
:
16133 case DW_LANG_Ada83
:
16134 case DW_LANG_Cobol74
:
16135 case DW_LANG_Cobol85
:
16136 case DW_LANG_Pascal83
:
16137 case DW_LANG_Modula2
:
16139 return dwarf_version
>= 4 ? 1 : -1;
16145 /* Given a tree node describing an array bound (either lower or upper) output
16146 a representation for that bound. */
16149 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16151 switch (TREE_CODE (bound
))
16156 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16159 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16162 /* Use the default if possible. */
16163 if (bound_attr
== DW_AT_lower_bound
16164 && host_integerp (bound
, 0)
16165 && (dflt
= lower_bound_default ()) != -1
16166 && tree_low_cst (bound
, 0) == dflt
)
16169 /* Otherwise represent the bound as an unsigned value with the
16170 precision of its type. The precision and signedness of the
16171 type will be necessary to re-interpret it unambiguously. */
16172 else if (prec
< HOST_BITS_PER_WIDE_INT
)
16174 unsigned HOST_WIDE_INT mask
16175 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
16176 add_AT_unsigned (subrange_die
, bound_attr
,
16177 TREE_INT_CST_LOW (bound
) & mask
);
16179 else if (prec
== HOST_BITS_PER_WIDE_INT
16180 || TREE_INT_CST_HIGH (bound
) == 0)
16181 add_AT_unsigned (subrange_die
, bound_attr
,
16182 TREE_INT_CST_LOW (bound
));
16184 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
16185 TREE_INT_CST_LOW (bound
));
16190 case VIEW_CONVERT_EXPR
:
16191 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16201 dw_die_ref decl_die
= lookup_decl_die (bound
);
16203 /* ??? Can this happen, or should the variable have been bound
16204 first? Probably it can, since I imagine that we try to create
16205 the types of parameters in the order in which they exist in
16206 the list, and won't have created a forward reference to a
16207 later parameter. */
16208 if (decl_die
!= NULL
)
16210 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16218 /* Otherwise try to create a stack operation procedure to
16219 evaluate the value of the array bound. */
16221 dw_die_ref ctx
, decl_die
;
16222 dw_loc_list_ref list
;
16224 list
= loc_list_from_tree (bound
, 2);
16225 if (list
== NULL
|| single_element_loc_list_p (list
))
16227 /* If DW_AT_*bound is not a reference nor constant, it is
16228 a DWARF expression rather than location description.
16229 For that loc_list_from_tree (bound, 0) is needed.
16230 If that fails to give a single element list,
16231 fall back to outputting this as a reference anyway. */
16232 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16233 if (list2
&& single_element_loc_list_p (list2
))
16235 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16242 if (current_function_decl
== 0)
16243 ctx
= comp_unit_die ();
16245 ctx
= lookup_decl_die (current_function_decl
);
16247 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16248 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16249 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16250 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16251 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16257 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16258 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16259 Note that the block of subscript information for an array type also
16260 includes information about the element type of the given array type. */
16263 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16265 unsigned dimension_number
;
16267 dw_die_ref subrange_die
;
16269 for (dimension_number
= 0;
16270 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16271 type
= TREE_TYPE (type
), dimension_number
++)
16273 tree domain
= TYPE_DOMAIN (type
);
16275 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16278 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16279 and (in GNU C only) variable bounds. Handle all three forms
16281 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16284 /* We have an array type with specified bounds. */
16285 lower
= TYPE_MIN_VALUE (domain
);
16286 upper
= TYPE_MAX_VALUE (domain
);
16288 /* Define the index type. */
16289 if (TREE_TYPE (domain
))
16291 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16292 TREE_TYPE field. We can't emit debug info for this
16293 because it is an unnamed integral type. */
16294 if (TREE_CODE (domain
) == INTEGER_TYPE
16295 && TYPE_NAME (domain
) == NULL_TREE
16296 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16297 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16300 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16304 /* ??? If upper is NULL, the array has unspecified length,
16305 but it does have a lower bound. This happens with Fortran
16307 Since the debugger is definitely going to need to know N
16308 to produce useful results, go ahead and output the lower
16309 bound solo, and hope the debugger can cope. */
16311 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16313 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16316 /* Otherwise we have an array type with an unspecified length. The
16317 DWARF-2 spec does not say how to handle this; let's just leave out the
16323 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16325 dw_die_ref decl_die
;
16328 switch (TREE_CODE (tree_node
))
16333 case ENUMERAL_TYPE
:
16336 case QUAL_UNION_TYPE
:
16337 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16338 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16340 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16343 size
= int_size_in_bytes (tree_node
);
16346 /* For a data member of a struct or union, the DW_AT_byte_size is
16347 generally given as the number of bytes normally allocated for an
16348 object of the *declared* type of the member itself. This is true
16349 even for bit-fields. */
16350 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16353 gcc_unreachable ();
16356 /* Note that `size' might be -1 when we get to this point. If it is, that
16357 indicates that the byte size of the entity in question is variable. We
16358 have no good way of expressing this fact in Dwarf at the present time,
16359 so just let the -1 pass on through. */
16360 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16363 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16364 which specifies the distance in bits from the highest order bit of the
16365 "containing object" for the bit-field to the highest order bit of the
16368 For any given bit-field, the "containing object" is a hypothetical object
16369 (of some integral or enum type) within which the given bit-field lives. The
16370 type of this hypothetical "containing object" is always the same as the
16371 declared type of the individual bit-field itself. The determination of the
16372 exact location of the "containing object" for a bit-field is rather
16373 complicated. It's handled by the `field_byte_offset' function (above).
16375 Note that it is the size (in bytes) of the hypothetical "containing object"
16376 which will be given in the DW_AT_byte_size attribute for this bit-field.
16377 (See `byte_size_attribute' above). */
16380 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16382 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16383 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16384 HOST_WIDE_INT bitpos_int
;
16385 HOST_WIDE_INT highest_order_object_bit_offset
;
16386 HOST_WIDE_INT highest_order_field_bit_offset
;
16387 HOST_WIDE_INT bit_offset
;
16389 /* Must be a field and a bit field. */
16390 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16392 /* We can't yet handle bit-fields whose offsets are variable, so if we
16393 encounter such things, just return without generating any attribute
16394 whatsoever. Likewise for variable or too large size. */
16395 if (! host_integerp (bit_position (decl
), 0)
16396 || ! host_integerp (DECL_SIZE (decl
), 1))
16399 bitpos_int
= int_bit_position (decl
);
16401 /* Note that the bit offset is always the distance (in bits) from the
16402 highest-order bit of the "containing object" to the highest-order bit of
16403 the bit-field itself. Since the "high-order end" of any object or field
16404 is different on big-endian and little-endian machines, the computation
16405 below must take account of these differences. */
16406 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16407 highest_order_field_bit_offset
= bitpos_int
;
16409 if (! BYTES_BIG_ENDIAN
)
16411 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16412 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16416 = (! BYTES_BIG_ENDIAN
16417 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16418 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16420 if (bit_offset
< 0)
16421 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16423 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16426 /* For a FIELD_DECL node which represents a bit field, output an attribute
16427 which specifies the length in bits of the given field. */
16430 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16432 /* Must be a field and a bit field. */
16433 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16434 && DECL_BIT_FIELD_TYPE (decl
));
16436 if (host_integerp (DECL_SIZE (decl
), 1))
16437 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16440 /* If the compiled language is ANSI C, then add a 'prototyped'
16441 attribute, if arg types are given for the parameters of a function. */
16444 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16446 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16447 && prototype_p (func_type
))
16448 add_AT_flag (die
, DW_AT_prototyped
, 1);
16451 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16452 by looking in either the type declaration or object declaration
16455 static inline dw_die_ref
16456 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16458 dw_die_ref origin_die
= NULL
;
16460 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16462 /* We may have gotten separated from the block for the inlined
16463 function, if we're in an exception handler or some such; make
16464 sure that the abstract function has been written out.
16466 Doing this for nested functions is wrong, however; functions are
16467 distinct units, and our context might not even be inline. */
16471 fn
= TYPE_STUB_DECL (fn
);
16473 fn
= decl_function_context (fn
);
16475 dwarf2out_abstract_function (fn
);
16478 if (DECL_P (origin
))
16479 origin_die
= lookup_decl_die (origin
);
16480 else if (TYPE_P (origin
))
16481 origin_die
= lookup_type_die (origin
);
16483 /* XXX: Functions that are never lowered don't always have correct block
16484 trees (in the case of java, they simply have no block tree, in some other
16485 languages). For these functions, there is nothing we can really do to
16486 output correct debug info for inlined functions in all cases. Rather
16487 than die, we'll just produce deficient debug info now, in that we will
16488 have variables without a proper abstract origin. In the future, when all
16489 functions are lowered, we should re-add a gcc_assert (origin_die)
16493 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16497 /* We do not currently support the pure_virtual attribute. */
16500 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16502 if (DECL_VINDEX (func_decl
))
16504 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16506 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16507 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16508 new_loc_descr (DW_OP_constu
,
16509 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16512 /* GNU extension: Record what type this method came from originally. */
16513 if (debug_info_level
> DINFO_LEVEL_TERSE
16514 && DECL_CONTEXT (func_decl
))
16515 add_AT_die_ref (die
, DW_AT_containing_type
,
16516 lookup_type_die (DECL_CONTEXT (func_decl
)));
16520 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16521 given decl. This used to be a vendor extension until after DWARF 4
16522 standardized it. */
16525 add_linkage_attr (dw_die_ref die
, tree decl
)
16527 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16529 /* Mimic what assemble_name_raw does with a leading '*'. */
16530 if (name
[0] == '*')
16533 if (dwarf_version
>= 4)
16534 add_AT_string (die
, DW_AT_linkage_name
, name
);
16536 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16539 /* Add source coordinate attributes for the given decl. */
16542 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16544 expanded_location s
;
16546 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16548 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16549 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16550 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16553 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16556 add_linkage_name (dw_die_ref die
, tree decl
)
16558 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16559 && TREE_PUBLIC (decl
)
16560 && !DECL_ABSTRACT (decl
)
16561 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16562 && die
->die_tag
!= DW_TAG_member
)
16564 /* Defer until we have an assembler name set. */
16565 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16567 limbo_die_node
*asm_name
;
16569 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16570 asm_name
->die
= die
;
16571 asm_name
->created_for
= decl
;
16572 asm_name
->next
= deferred_asm_name
;
16573 deferred_asm_name
= asm_name
;
16575 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16576 add_linkage_attr (die
, decl
);
16580 /* Add a DW_AT_name attribute and source coordinate attribute for the
16581 given decl, but only if it actually has a name. */
16584 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16588 decl_name
= DECL_NAME (decl
);
16589 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16591 const char *name
= dwarf2_name (decl
, 0);
16593 add_name_attribute (die
, name
);
16594 if (! DECL_ARTIFICIAL (decl
))
16595 add_src_coords_attributes (die
, decl
);
16597 add_linkage_name (die
, decl
);
16600 #ifdef VMS_DEBUGGING_INFO
16601 /* Get the function's name, as described by its RTL. This may be different
16602 from the DECL_NAME name used in the source file. */
16603 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16605 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16606 XEXP (DECL_RTL (decl
), 0), false);
16607 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16609 #endif /* VMS_DEBUGGING_INFO */
16612 #ifdef VMS_DEBUGGING_INFO
16613 /* Output the debug main pointer die for VMS */
16616 dwarf2out_vms_debug_main_pointer (void)
16618 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16621 /* Allocate the VMS debug main subprogram die. */
16622 die
= ggc_alloc_cleared_die_node ();
16623 die
->die_tag
= DW_TAG_subprogram
;
16624 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16625 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16626 current_function_funcdef_no
);
16627 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16629 /* Make it the first child of comp_unit_die (). */
16630 die
->die_parent
= comp_unit_die ();
16631 if (comp_unit_die ()->die_child
)
16633 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16634 comp_unit_die ()->die_child
->die_sib
= die
;
16638 die
->die_sib
= die
;
16639 comp_unit_die ()->die_child
= die
;
16642 #endif /* VMS_DEBUGGING_INFO */
16644 /* Push a new declaration scope. */
16647 push_decl_scope (tree scope
)
16649 vec_safe_push (decl_scope_table
, scope
);
16652 /* Pop a declaration scope. */
16655 pop_decl_scope (void)
16657 decl_scope_table
->pop ();
16660 /* walk_tree helper function for uses_local_type, below. */
16663 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16666 *walk_subtrees
= 0;
16669 tree name
= TYPE_NAME (*tp
);
16670 if (name
&& DECL_P (name
) && decl_function_context (name
))
16676 /* If TYPE involves a function-local type (including a local typedef to a
16677 non-local type), returns that type; otherwise returns NULL_TREE. */
16680 uses_local_type (tree type
)
16682 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16686 /* Return the DIE for the scope that immediately contains this type.
16687 Non-named types that do not involve a function-local type get global
16688 scope. Named types nested in namespaces or other types get their
16689 containing scope. All other types (i.e. function-local named types) get
16690 the current active scope. */
16693 scope_die_for (tree t
, dw_die_ref context_die
)
16695 dw_die_ref scope_die
= NULL
;
16696 tree containing_scope
;
16698 /* Non-types always go in the current scope. */
16699 gcc_assert (TYPE_P (t
));
16701 /* Use the scope of the typedef, rather than the scope of the type
16703 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16704 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16706 containing_scope
= TYPE_CONTEXT (t
);
16708 /* Use the containing namespace if there is one. */
16709 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16711 if (context_die
== lookup_decl_die (containing_scope
))
16713 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16714 context_die
= get_context_die (containing_scope
);
16716 containing_scope
= NULL_TREE
;
16719 /* Ignore function type "scopes" from the C frontend. They mean that
16720 a tagged type is local to a parmlist of a function declarator, but
16721 that isn't useful to DWARF. */
16722 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16723 containing_scope
= NULL_TREE
;
16725 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16727 /* If T uses a local type keep it local as well, to avoid references
16728 to function-local DIEs from outside the function. */
16729 if (current_function_decl
&& uses_local_type (t
))
16730 scope_die
= context_die
;
16732 scope_die
= comp_unit_die ();
16734 else if (TYPE_P (containing_scope
))
16736 /* For types, we can just look up the appropriate DIE. */
16737 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16738 scope_die
= get_context_die (containing_scope
);
16741 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16742 if (scope_die
== NULL
)
16743 scope_die
= comp_unit_die ();
16747 scope_die
= context_die
;
16752 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16755 local_scope_p (dw_die_ref context_die
)
16757 for (; context_die
; context_die
= context_die
->die_parent
)
16758 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16759 || context_die
->die_tag
== DW_TAG_subprogram
)
16765 /* Returns nonzero if CONTEXT_DIE is a class. */
16768 class_scope_p (dw_die_ref context_die
)
16770 return (context_die
16771 && (context_die
->die_tag
== DW_TAG_structure_type
16772 || context_die
->die_tag
== DW_TAG_class_type
16773 || context_die
->die_tag
== DW_TAG_interface_type
16774 || context_die
->die_tag
== DW_TAG_union_type
));
16777 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16778 whether or not to treat a DIE in this context as a declaration. */
16781 class_or_namespace_scope_p (dw_die_ref context_die
)
16783 return (class_scope_p (context_die
)
16784 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16787 /* Many forms of DIEs require a "type description" attribute. This
16788 routine locates the proper "type descriptor" die for the type given
16789 by 'type', and adds a DW_AT_type attribute below the given die. */
16792 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16793 int decl_volatile
, dw_die_ref context_die
)
16795 enum tree_code code
= TREE_CODE (type
);
16796 dw_die_ref type_die
= NULL
;
16798 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16799 or fixed-point type, use the inner type. This is because we have no
16800 support for unnamed types in base_type_die. This can happen if this is
16801 an Ada subrange type. Correct solution is emit a subrange type die. */
16802 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16803 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16804 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16806 if (code
== ERROR_MARK
16807 /* Handle a special case. For functions whose return type is void, we
16808 generate *no* type attribute. (Note that no object may have type
16809 `void', so this only applies to function return types). */
16810 || code
== VOID_TYPE
)
16813 type_die
= modified_type_die (type
,
16814 decl_const
|| TYPE_READONLY (type
),
16815 decl_volatile
|| TYPE_VOLATILE (type
),
16818 if (type_die
!= NULL
)
16819 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16822 /* Given an object die, add the calling convention attribute for the
16823 function call type. */
16825 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16827 enum dwarf_calling_convention value
= DW_CC_normal
;
16829 value
= ((enum dwarf_calling_convention
)
16830 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16833 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16835 /* DWARF 2 doesn't provide a way to identify a program's source-level
16836 entry point. DW_AT_calling_convention attributes are only meant
16837 to describe functions' calling conventions. However, lacking a
16838 better way to signal the Fortran main program, we used this for
16839 a long time, following existing custom. Now, DWARF 4 has
16840 DW_AT_main_subprogram, which we add below, but some tools still
16841 rely on the old way, which we thus keep. */
16842 value
= DW_CC_program
;
16844 if (dwarf_version
>= 4 || !dwarf_strict
)
16845 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16848 /* Only add the attribute if the backend requests it, and
16849 is not DW_CC_normal. */
16850 if (value
&& (value
!= DW_CC_normal
))
16851 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16854 /* Given a tree pointer to a struct, class, union, or enum type node, return
16855 a pointer to the (string) tag name for the given type, or zero if the type
16856 was declared without a tag. */
16858 static const char *
16859 type_tag (const_tree type
)
16861 const char *name
= 0;
16863 if (TYPE_NAME (type
) != 0)
16867 /* Find the IDENTIFIER_NODE for the type name. */
16868 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16869 && !TYPE_NAMELESS (type
))
16870 t
= TYPE_NAME (type
);
16872 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16873 a TYPE_DECL node, regardless of whether or not a `typedef' was
16875 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16876 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16878 /* We want to be extra verbose. Don't call dwarf_name if
16879 DECL_NAME isn't set. The default hook for decl_printable_name
16880 doesn't like that, and in this context it's correct to return
16881 0, instead of "<anonymous>" or the like. */
16882 if (DECL_NAME (TYPE_NAME (type
))
16883 && !DECL_NAMELESS (TYPE_NAME (type
)))
16884 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16887 /* Now get the name as a string, or invent one. */
16888 if (!name
&& t
!= 0)
16889 name
= IDENTIFIER_POINTER (t
);
16892 return (name
== 0 || *name
== '\0') ? 0 : name
;
16895 /* Return the type associated with a data member, make a special check
16896 for bit field types. */
16899 member_declared_type (const_tree member
)
16901 return (DECL_BIT_FIELD_TYPE (member
)
16902 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16905 /* Get the decl's label, as described by its RTL. This may be different
16906 from the DECL_NAME name used in the source file. */
16909 static const char *
16910 decl_start_label (tree decl
)
16913 const char *fnname
;
16915 x
= DECL_RTL (decl
);
16916 gcc_assert (MEM_P (x
));
16919 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16921 fnname
= XSTR (x
, 0);
16926 /* These routines generate the internal representation of the DIE's for
16927 the compilation unit. Debugging information is collected by walking
16928 the declaration trees passed in from dwarf2out_decl(). */
16931 gen_array_type_die (tree type
, dw_die_ref context_die
)
16933 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16934 dw_die_ref array_die
;
16936 /* GNU compilers represent multidimensional array types as sequences of one
16937 dimensional array types whose element types are themselves array types.
16938 We sometimes squish that down to a single array_type DIE with multiple
16939 subscripts in the Dwarf debugging info. The draft Dwarf specification
16940 say that we are allowed to do this kind of compression in C, because
16941 there is no difference between an array of arrays and a multidimensional
16942 array. We don't do this for Ada to remain as close as possible to the
16943 actual representation, which is especially important against the language
16944 flexibilty wrt arrays of variable size. */
16946 bool collapse_nested_arrays
= !is_ada ();
16949 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16950 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16951 if (TYPE_STRING_FLAG (type
)
16952 && TREE_CODE (type
) == ARRAY_TYPE
16954 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16956 HOST_WIDE_INT size
;
16958 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16959 add_name_attribute (array_die
, type_tag (type
));
16960 equate_type_number_to_die (type
, array_die
);
16961 size
= int_size_in_bytes (type
);
16963 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16964 else if (TYPE_DOMAIN (type
) != NULL_TREE
16965 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16966 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16968 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16969 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16971 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16972 if (loc
&& size
> 0)
16974 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16975 if (size
!= DWARF2_ADDR_SIZE
)
16976 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16982 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16983 add_name_attribute (array_die
, type_tag (type
));
16984 equate_type_number_to_die (type
, array_die
);
16986 if (TREE_CODE (type
) == VECTOR_TYPE
)
16987 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16989 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16991 && TREE_CODE (type
) == ARRAY_TYPE
16992 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16993 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16994 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16997 /* We default the array ordering. SDB will probably do
16998 the right things even if DW_AT_ordering is not present. It's not even
16999 an issue until we start to get into multidimensional arrays anyway. If
17000 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17001 then we'll have to put the DW_AT_ordering attribute back in. (But if
17002 and when we find out that we need to put these in, we will only do so
17003 for multidimensional arrays. */
17004 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17007 if (TREE_CODE (type
) == VECTOR_TYPE
)
17009 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17010 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17011 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
17012 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17013 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
17016 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17018 /* Add representation of the type of the elements of this array type and
17019 emit the corresponding DIE if we haven't done it already. */
17020 element_type
= TREE_TYPE (type
);
17021 if (collapse_nested_arrays
)
17022 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17024 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17026 element_type
= TREE_TYPE (element_type
);
17029 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
17031 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17032 if (TYPE_ARTIFICIAL (type
))
17033 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17035 if (get_AT (array_die
, DW_AT_name
))
17036 add_pubtype (type
, array_die
);
17039 static dw_loc_descr_ref
17040 descr_info_loc (tree val
, tree base_decl
)
17042 HOST_WIDE_INT size
;
17043 dw_loc_descr_ref loc
, loc2
;
17044 enum dwarf_location_atom op
;
17046 if (val
== base_decl
)
17047 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
17049 switch (TREE_CODE (val
))
17052 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17054 return loc_descriptor_from_tree (val
, 0);
17056 if (host_integerp (val
, 0))
17057 return int_loc_descriptor (tree_low_cst (val
, 0));
17060 size
= int_size_in_bytes (TREE_TYPE (val
));
17063 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17066 if (size
== DWARF2_ADDR_SIZE
)
17067 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
17069 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
17071 case POINTER_PLUS_EXPR
:
17073 if (host_integerp (TREE_OPERAND (val
, 1), 1)
17074 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
17077 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17080 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
17086 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17089 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
17092 add_loc_descr (&loc
, loc2
);
17093 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17115 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17116 tree val
, tree base_decl
)
17118 dw_loc_descr_ref loc
;
17120 if (host_integerp (val
, 0))
17122 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
17126 loc
= descr_info_loc (val
, base_decl
);
17130 add_AT_loc (die
, attr
, loc
);
17133 /* This routine generates DIE for array with hidden descriptor, details
17134 are filled into *info by a langhook. */
17137 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17138 dw_die_ref context_die
)
17140 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17141 dw_die_ref array_die
;
17144 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17145 add_name_attribute (array_die
, type_tag (type
));
17146 equate_type_number_to_die (type
, array_die
);
17148 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17150 && info
->ndimensions
>= 2)
17151 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17153 if (info
->data_location
)
17154 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17156 if (info
->associated
)
17157 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17159 if (info
->allocated
)
17160 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17163 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17165 dw_die_ref subrange_die
17166 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17168 if (info
->dimen
[dim
].lower_bound
)
17170 /* If it is the default value, omit it. */
17173 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
17174 && (dflt
= lower_bound_default ()) != -1
17175 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
17178 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17179 info
->dimen
[dim
].lower_bound
,
17182 if (info
->dimen
[dim
].upper_bound
)
17183 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17184 info
->dimen
[dim
].upper_bound
,
17186 if (info
->dimen
[dim
].stride
)
17187 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17188 info
->dimen
[dim
].stride
,
17192 gen_type_die (info
->element_type
, context_die
);
17193 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17195 if (get_AT (array_die
, DW_AT_name
))
17196 add_pubtype (type
, array_die
);
17201 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17203 tree origin
= decl_ultimate_origin (decl
);
17204 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17206 if (origin
!= NULL
)
17207 add_abstract_origin_attribute (decl_die
, origin
);
17210 add_name_and_src_coords_attributes (decl_die
, decl
);
17211 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17212 0, 0, context_die
);
17215 if (DECL_ABSTRACT (decl
))
17216 equate_decl_number_to_die (decl
, decl_die
);
17218 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17222 /* Walk through the list of incomplete types again, trying once more to
17223 emit full debugging info for them. */
17226 retry_incomplete_types (void)
17230 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17231 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17232 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17235 /* Determine what tag to use for a record type. */
17237 static enum dwarf_tag
17238 record_type_tag (tree type
)
17240 if (! lang_hooks
.types
.classify_record
)
17241 return DW_TAG_structure_type
;
17243 switch (lang_hooks
.types
.classify_record (type
))
17245 case RECORD_IS_STRUCT
:
17246 return DW_TAG_structure_type
;
17248 case RECORD_IS_CLASS
:
17249 return DW_TAG_class_type
;
17251 case RECORD_IS_INTERFACE
:
17252 if (dwarf_version
>= 3 || !dwarf_strict
)
17253 return DW_TAG_interface_type
;
17254 return DW_TAG_structure_type
;
17257 gcc_unreachable ();
17261 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17262 include all of the information about the enumeration values also. Each
17263 enumerated type name/value is listed as a child of the enumerated type
17267 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17269 dw_die_ref type_die
= lookup_type_die (type
);
17271 if (type_die
== NULL
)
17273 type_die
= new_die (DW_TAG_enumeration_type
,
17274 scope_die_for (type
, context_die
), type
);
17275 equate_type_number_to_die (type
, type_die
);
17276 add_name_attribute (type_die
, type_tag (type
));
17277 if (dwarf_version
>= 4 || !dwarf_strict
)
17279 if (ENUM_IS_SCOPED (type
))
17280 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17281 if (ENUM_IS_OPAQUE (type
))
17282 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17285 else if (! TYPE_SIZE (type
))
17288 remove_AT (type_die
, DW_AT_declaration
);
17290 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17291 given enum type is incomplete, do not generate the DW_AT_byte_size
17292 attribute or the DW_AT_element_list attribute. */
17293 if (TYPE_SIZE (type
))
17297 TREE_ASM_WRITTEN (type
) = 1;
17298 add_byte_size_attribute (type_die
, type
);
17299 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17301 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17302 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17305 /* If the first reference to this type was as the return type of an
17306 inline function, then it may not have a parent. Fix this now. */
17307 if (type_die
->die_parent
== NULL
)
17308 add_child_die (scope_die_for (type
, context_die
), type_die
);
17310 for (link
= TYPE_VALUES (type
);
17311 link
!= NULL
; link
= TREE_CHAIN (link
))
17313 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17314 tree value
= TREE_VALUE (link
);
17316 add_name_attribute (enum_die
,
17317 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17319 if (TREE_CODE (value
) == CONST_DECL
)
17320 value
= DECL_INITIAL (value
);
17322 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
)))
17323 && (simple_type_size_in_bits (TREE_TYPE (value
))
17324 <= HOST_BITS_PER_WIDE_INT
|| host_integerp (value
, 0)))
17325 /* DWARF2 does not provide a way of indicating whether or
17326 not enumeration constants are signed or unsigned. GDB
17327 always assumes the values are signed, so we output all
17328 values as if they were signed. That means that
17329 enumeration constants with very large unsigned values
17330 will appear to have negative values in the debugger.
17332 TODO: the above comment is wrong, DWARF2 does provide
17333 DW_FORM_sdata/DW_FORM_udata to represent signed/unsigned data.
17334 This should be re-worked to use correct signed/unsigned
17335 int/double tags for all cases, instead of always treating as
17337 add_AT_int (enum_die
, DW_AT_const_value
, TREE_INT_CST_LOW (value
));
17339 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17341 add_AT_double (enum_die
, DW_AT_const_value
,
17342 TREE_INT_CST_HIGH (value
), TREE_INT_CST_LOW (value
));
17345 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17346 if (TYPE_ARTIFICIAL (type
))
17347 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17350 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17352 add_pubtype (type
, type_die
);
17357 /* Generate a DIE to represent either a real live formal parameter decl or to
17358 represent just the type of some formal parameter position in some function
17361 Note that this routine is a bit unusual because its argument may be a
17362 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17363 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17364 node. If it's the former then this function is being called to output a
17365 DIE to represent a formal parameter object (or some inlining thereof). If
17366 it's the latter, then this function is only being called to output a
17367 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17368 argument type of some subprogram type.
17369 If EMIT_NAME_P is true, name and source coordinate attributes
17373 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17374 dw_die_ref context_die
)
17376 tree node_or_origin
= node
? node
: origin
;
17377 tree ultimate_origin
;
17378 dw_die_ref parm_die
17379 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17381 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17383 case tcc_declaration
:
17384 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17385 if (node
|| ultimate_origin
)
17386 origin
= ultimate_origin
;
17387 if (origin
!= NULL
)
17388 add_abstract_origin_attribute (parm_die
, origin
);
17389 else if (emit_name_p
)
17390 add_name_and_src_coords_attributes (parm_die
, node
);
17392 || (! DECL_ABSTRACT (node_or_origin
)
17393 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17394 decl_function_context
17395 (node_or_origin
))))
17397 tree type
= TREE_TYPE (node_or_origin
);
17398 if (decl_by_reference_p (node_or_origin
))
17399 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17402 add_type_attribute (parm_die
, type
,
17403 TREE_READONLY (node_or_origin
),
17404 TREE_THIS_VOLATILE (node_or_origin
),
17407 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17408 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17410 if (node
&& node
!= origin
)
17411 equate_decl_number_to_die (node
, parm_die
);
17412 if (! DECL_ABSTRACT (node_or_origin
))
17413 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17414 node
== NULL
, DW_AT_location
);
17419 /* We were called with some kind of a ..._TYPE node. */
17420 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17424 gcc_unreachable ();
17430 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17431 children DW_TAG_formal_parameter DIEs representing the arguments of the
17434 PARM_PACK must be a function parameter pack.
17435 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17436 must point to the subsequent arguments of the function PACK_ARG belongs to.
17437 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17438 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17439 following the last one for which a DIE was generated. */
17442 gen_formal_parameter_pack_die (tree parm_pack
,
17444 dw_die_ref subr_die
,
17448 dw_die_ref parm_pack_die
;
17450 gcc_assert (parm_pack
17451 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17454 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17455 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17457 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17459 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17462 gen_formal_parameter_die (arg
, NULL
,
17463 false /* Don't emit name attribute. */,
17468 return parm_pack_die
;
17471 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17472 at the end of an (ANSI prototyped) formal parameters list. */
17475 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17477 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17480 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17481 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17482 parameters as specified in some function type specification (except for
17483 those which appear as part of a function *definition*). */
17486 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17489 tree formal_type
= NULL
;
17490 tree first_parm_type
;
17493 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17495 arg
= DECL_ARGUMENTS (function_or_method_type
);
17496 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17501 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17503 /* Make our first pass over the list of formal parameter types and output a
17504 DW_TAG_formal_parameter DIE for each one. */
17505 for (link
= first_parm_type
; link
; )
17507 dw_die_ref parm_die
;
17509 formal_type
= TREE_VALUE (link
);
17510 if (formal_type
== void_type_node
)
17513 /* Output a (nameless) DIE to represent the formal parameter itself. */
17514 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17515 true /* Emit name attribute. */,
17517 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17518 && link
== first_parm_type
)
17520 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17521 if (dwarf_version
>= 3 || !dwarf_strict
)
17522 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17524 else if (arg
&& DECL_ARTIFICIAL (arg
))
17525 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17527 link
= TREE_CHAIN (link
);
17529 arg
= DECL_CHAIN (arg
);
17532 /* If this function type has an ellipsis, add a
17533 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17534 if (formal_type
!= void_type_node
)
17535 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17537 /* Make our second (and final) pass over the list of formal parameter types
17538 and output DIEs to represent those types (as necessary). */
17539 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17540 link
&& TREE_VALUE (link
);
17541 link
= TREE_CHAIN (link
))
17542 gen_type_die (TREE_VALUE (link
), context_die
);
17545 /* We want to generate the DIE for TYPE so that we can generate the
17546 die for MEMBER, which has been defined; we will need to refer back
17547 to the member declaration nested within TYPE. If we're trying to
17548 generate minimal debug info for TYPE, processing TYPE won't do the
17549 trick; we need to attach the member declaration by hand. */
17552 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17554 gen_type_die (type
, context_die
);
17556 /* If we're trying to avoid duplicate debug info, we may not have
17557 emitted the member decl for this function. Emit it now. */
17558 if (TYPE_STUB_DECL (type
)
17559 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17560 && ! lookup_decl_die (member
))
17562 dw_die_ref type_die
;
17563 gcc_assert (!decl_ultimate_origin (member
));
17565 push_decl_scope (type
);
17566 type_die
= lookup_type_die_strip_naming_typedef (type
);
17567 if (TREE_CODE (member
) == FUNCTION_DECL
)
17568 gen_subprogram_die (member
, type_die
);
17569 else if (TREE_CODE (member
) == FIELD_DECL
)
17571 /* Ignore the nameless fields that are used to skip bits but handle
17572 C++ anonymous unions and structs. */
17573 if (DECL_NAME (member
) != NULL_TREE
17574 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17575 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17577 gen_type_die (member_declared_type (member
), type_die
);
17578 gen_field_die (member
, type_die
);
17582 gen_variable_die (member
, NULL_TREE
, type_die
);
17588 /* Forward declare these functions, because they are mutually recursive
17589 with their set_block_* pairing functions. */
17590 static void set_decl_origin_self (tree
);
17591 static void set_decl_abstract_flags (tree
, int);
17593 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17594 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17595 that it points to the node itself, thus indicating that the node is its
17596 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17597 the given node is NULL, recursively descend the decl/block tree which
17598 it is the root of, and for each other ..._DECL or BLOCK node contained
17599 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17600 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17601 values to point to themselves. */
17604 set_block_origin_self (tree stmt
)
17606 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17608 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17613 for (local_decl
= BLOCK_VARS (stmt
);
17614 local_decl
!= NULL_TREE
;
17615 local_decl
= DECL_CHAIN (local_decl
))
17616 if (! DECL_EXTERNAL (local_decl
))
17617 set_decl_origin_self (local_decl
); /* Potential recursion. */
17623 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17624 subblock
!= NULL_TREE
;
17625 subblock
= BLOCK_CHAIN (subblock
))
17626 set_block_origin_self (subblock
); /* Recurse. */
17631 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17632 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17633 node to so that it points to the node itself, thus indicating that the
17634 node represents its own (abstract) origin. Additionally, if the
17635 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17636 the decl/block tree of which the given node is the root of, and for
17637 each other ..._DECL or BLOCK node contained therein whose
17638 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17639 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17640 point to themselves. */
17643 set_decl_origin_self (tree decl
)
17645 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17647 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17648 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17652 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17653 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17654 if (DECL_INITIAL (decl
) != NULL_TREE
17655 && DECL_INITIAL (decl
) != error_mark_node
)
17656 set_block_origin_self (DECL_INITIAL (decl
));
17661 /* Given a pointer to some BLOCK node, and a boolean value to set the
17662 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17663 the given block, and for all local decls and all local sub-blocks
17664 (recursively) which are contained therein. */
17667 set_block_abstract_flags (tree stmt
, int setting
)
17673 BLOCK_ABSTRACT (stmt
) = setting
;
17675 for (local_decl
= BLOCK_VARS (stmt
);
17676 local_decl
!= NULL_TREE
;
17677 local_decl
= DECL_CHAIN (local_decl
))
17678 if (! DECL_EXTERNAL (local_decl
))
17679 set_decl_abstract_flags (local_decl
, setting
);
17681 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17683 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17684 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17685 || TREE_CODE (local_decl
) == PARM_DECL
)
17686 set_decl_abstract_flags (local_decl
, setting
);
17689 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17690 subblock
!= NULL_TREE
;
17691 subblock
= BLOCK_CHAIN (subblock
))
17692 set_block_abstract_flags (subblock
, setting
);
17695 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17696 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17697 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17698 set the abstract flags for all of the parameters, local vars, local
17699 blocks and sub-blocks (recursively) to the same setting. */
17702 set_decl_abstract_flags (tree decl
, int setting
)
17704 DECL_ABSTRACT (decl
) = setting
;
17705 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17709 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17710 DECL_ABSTRACT (arg
) = setting
;
17711 if (DECL_INITIAL (decl
) != NULL_TREE
17712 && DECL_INITIAL (decl
) != error_mark_node
)
17713 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17717 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17718 may later generate inlined and/or out-of-line instances of. */
17721 dwarf2out_abstract_function (tree decl
)
17723 dw_die_ref old_die
;
17727 htab_t old_decl_loc_table
;
17728 htab_t old_cached_dw_loc_list_table
;
17729 int old_call_site_count
, old_tail_call_site_count
;
17730 struct call_arg_loc_node
*old_call_arg_locations
;
17732 /* Make sure we have the actual abstract inline, not a clone. */
17733 decl
= DECL_ORIGIN (decl
);
17735 old_die
= lookup_decl_die (decl
);
17736 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17737 /* We've already generated the abstract instance. */
17740 /* We can be called while recursively when seeing block defining inlined subroutine
17741 DIE. Be sure to not clobber the outer location table nor use it or we would
17742 get locations in abstract instantces. */
17743 old_decl_loc_table
= decl_loc_table
;
17744 decl_loc_table
= NULL
;
17745 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17746 cached_dw_loc_list_table
= NULL
;
17747 old_call_arg_locations
= call_arg_locations
;
17748 call_arg_locations
= NULL
;
17749 old_call_site_count
= call_site_count
;
17750 call_site_count
= -1;
17751 old_tail_call_site_count
= tail_call_site_count
;
17752 tail_call_site_count
= -1;
17754 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17755 we don't get confused by DECL_ABSTRACT. */
17756 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17758 context
= decl_class_context (decl
);
17760 gen_type_die_for_member
17761 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17764 /* Pretend we've just finished compiling this function. */
17765 save_fn
= current_function_decl
;
17766 current_function_decl
= decl
;
17768 was_abstract
= DECL_ABSTRACT (decl
);
17769 set_decl_abstract_flags (decl
, 1);
17770 dwarf2out_decl (decl
);
17771 if (! was_abstract
)
17772 set_decl_abstract_flags (decl
, 0);
17774 current_function_decl
= save_fn
;
17775 decl_loc_table
= old_decl_loc_table
;
17776 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17777 call_arg_locations
= old_call_arg_locations
;
17778 call_site_count
= old_call_site_count
;
17779 tail_call_site_count
= old_tail_call_site_count
;
17782 /* Helper function of premark_used_types() which gets called through
17785 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17786 marked as unused by prune_unused_types. */
17789 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17794 type
= (tree
) *slot
;
17795 die
= lookup_type_die (type
);
17797 die
->die_perennial_p
= 1;
17801 /* Helper function of premark_types_used_by_global_vars which gets called
17802 through htab_traverse.
17804 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17805 marked as unused by prune_unused_types. The DIE of the type is marked
17806 only if the global variable using the type will actually be emitted. */
17809 premark_types_used_by_global_vars_helper (void **slot
,
17810 void *data ATTRIBUTE_UNUSED
)
17812 struct types_used_by_vars_entry
*entry
;
17815 entry
= (struct types_used_by_vars_entry
*) *slot
;
17816 gcc_assert (entry
->type
!= NULL
17817 && entry
->var_decl
!= NULL
);
17818 die
= lookup_type_die (entry
->type
);
17821 /* Ask cgraph if the global variable really is to be emitted.
17822 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17823 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17824 if (node
&& node
->symbol
.definition
)
17826 die
->die_perennial_p
= 1;
17827 /* Keep the parent DIEs as well. */
17828 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17829 die
->die_perennial_p
= 1;
17835 /* Mark all members of used_types_hash as perennial. */
17838 premark_used_types (struct function
*fun
)
17840 if (fun
&& fun
->used_types_hash
)
17841 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17844 /* Mark all members of types_used_by_vars_entry as perennial. */
17847 premark_types_used_by_global_vars (void)
17849 if (types_used_by_vars_hash
)
17850 htab_traverse (types_used_by_vars_hash
,
17851 premark_types_used_by_global_vars_helper
, NULL
);
17854 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17855 for CA_LOC call arg loc node. */
17858 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17859 struct call_arg_loc_node
*ca_loc
)
17861 dw_die_ref stmt_die
= NULL
, die
;
17862 tree block
= ca_loc
->block
;
17865 && block
!= DECL_INITIAL (decl
)
17866 && TREE_CODE (block
) == BLOCK
)
17868 if (block_map
.length () > BLOCK_NUMBER (block
))
17869 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17872 block
= BLOCK_SUPERCONTEXT (block
);
17874 if (stmt_die
== NULL
)
17875 stmt_die
= subr_die
;
17876 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17877 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17878 if (ca_loc
->tail_call_p
)
17879 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17880 if (ca_loc
->symbol_ref
)
17882 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17884 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17886 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17891 /* Generate a DIE to represent a declared function (either file-scope or
17895 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17897 tree origin
= decl_ultimate_origin (decl
);
17898 dw_die_ref subr_die
;
17900 dw_die_ref old_die
= lookup_decl_die (decl
);
17901 int declaration
= (current_function_decl
!= decl
17902 || class_or_namespace_scope_p (context_die
));
17904 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17906 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17907 started to generate the abstract instance of an inline, decided to output
17908 its containing class, and proceeded to emit the declaration of the inline
17909 from the member list for the class. If so, DECLARATION takes priority;
17910 we'll get back to the abstract instance when done with the class. */
17912 /* The class-scope declaration DIE must be the primary DIE. */
17913 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17916 gcc_assert (!old_die
);
17919 /* Now that the C++ front end lazily declares artificial member fns, we
17920 might need to retrofit the declaration into its class. */
17921 if (!declaration
&& !origin
&& !old_die
17922 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17923 && !class_or_namespace_scope_p (context_die
)
17924 && debug_info_level
> DINFO_LEVEL_TERSE
)
17925 old_die
= force_decl_die (decl
);
17927 if (origin
!= NULL
)
17929 gcc_assert (!declaration
|| local_scope_p (context_die
));
17931 /* Fixup die_parent for the abstract instance of a nested
17932 inline function. */
17933 if (old_die
&& old_die
->die_parent
== NULL
)
17934 add_child_die (context_die
, old_die
);
17936 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17937 add_abstract_origin_attribute (subr_die
, origin
);
17938 /* This is where the actual code for a cloned function is.
17939 Let's emit linkage name attribute for it. This helps
17940 debuggers to e.g, set breakpoints into
17941 constructors/destructors when the user asks "break
17943 add_linkage_name (subr_die
, decl
);
17947 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17948 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17950 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17951 /* We can have a normal definition following an inline one in the
17952 case of redefinition of GNU C extern inlines.
17953 It seems reasonable to use AT_specification in this case. */
17954 && !get_AT (old_die
, DW_AT_inline
))
17956 /* Detect and ignore this case, where we are trying to output
17957 something we have already output. */
17961 /* If the definition comes from the same place as the declaration,
17962 maybe use the old DIE. We always want the DIE for this function
17963 that has the *_pc attributes to be under comp_unit_die so the
17964 debugger can find it. We also need to do this for abstract
17965 instances of inlines, since the spec requires the out-of-line copy
17966 to have the same parent. For local class methods, this doesn't
17967 apply; we just use the old DIE. */
17968 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17969 && (DECL_ARTIFICIAL (decl
)
17970 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17971 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17972 == (unsigned) s
.line
))))
17974 subr_die
= old_die
;
17976 /* Clear out the declaration attribute and the formal parameters.
17977 Do not remove all children, because it is possible that this
17978 declaration die was forced using force_decl_die(). In such
17979 cases die that forced declaration die (e.g. TAG_imported_module)
17980 is one of the children that we do not want to remove. */
17981 remove_AT (subr_die
, DW_AT_declaration
);
17982 remove_AT (subr_die
, DW_AT_object_pointer
);
17983 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17987 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17988 add_AT_specification (subr_die
, old_die
);
17989 add_pubname (decl
, subr_die
);
17990 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17991 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17992 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17993 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17998 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18000 if (TREE_PUBLIC (decl
))
18001 add_AT_flag (subr_die
, DW_AT_external
, 1);
18003 add_name_and_src_coords_attributes (subr_die
, decl
);
18004 add_pubname (decl
, subr_die
);
18005 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18007 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18008 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18009 0, 0, context_die
);
18012 add_pure_or_virtual_attribute (subr_die
, decl
);
18013 if (DECL_ARTIFICIAL (decl
))
18014 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18016 add_accessibility_attribute (subr_die
, decl
);
18021 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18023 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18025 /* If this is an explicit function declaration then generate
18026 a DW_AT_explicit attribute. */
18027 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18028 && (dwarf_version
>= 3 || !dwarf_strict
))
18029 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18031 /* The first time we see a member function, it is in the context of
18032 the class to which it belongs. We make sure of this by emitting
18033 the class first. The next time is the definition, which is
18034 handled above. The two may come from the same source text.
18036 Note that force_decl_die() forces function declaration die. It is
18037 later reused to represent definition. */
18038 equate_decl_number_to_die (decl
, subr_die
);
18041 else if (DECL_ABSTRACT (decl
))
18043 if (DECL_DECLARED_INLINE_P (decl
))
18045 if (cgraph_function_possibly_inlined_p (decl
))
18046 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18048 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18052 if (cgraph_function_possibly_inlined_p (decl
))
18053 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18055 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18058 if (DECL_DECLARED_INLINE_P (decl
)
18059 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18060 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18062 equate_decl_number_to_die (decl
, subr_die
);
18064 else if (!DECL_EXTERNAL (decl
))
18066 HOST_WIDE_INT cfa_fb_offset
;
18067 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18069 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18070 equate_decl_number_to_die (decl
, subr_die
);
18072 gcc_checking_assert (fun
);
18073 if (!flag_reorder_blocks_and_partition
)
18075 dw_fde_ref fde
= fun
->fde
;
18076 if (fde
->dw_fde_begin
)
18078 /* We have already generated the labels. */
18079 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18080 fde
->dw_fde_end
, false);
18084 /* Create start/end labels and add the range. */
18085 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18086 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18087 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18088 current_function_funcdef_no
);
18089 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18090 current_function_funcdef_no
);
18091 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18095 #if VMS_DEBUGGING_INFO
18096 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18097 Section 2.3 Prologue and Epilogue Attributes:
18098 When a breakpoint is set on entry to a function, it is generally
18099 desirable for execution to be suspended, not on the very first
18100 instruction of the function, but rather at a point after the
18101 function's frame has been set up, after any language defined local
18102 declaration processing has been completed, and before execution of
18103 the first statement of the function begins. Debuggers generally
18104 cannot properly determine where this point is. Similarly for a
18105 breakpoint set on exit from a function. The prologue and epilogue
18106 attributes allow a compiler to communicate the location(s) to use. */
18109 if (fde
->dw_fde_vms_end_prologue
)
18110 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18111 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18113 if (fde
->dw_fde_vms_begin_epilogue
)
18114 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18115 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18122 /* Generate pubnames entries for the split function code ranges. */
18123 dw_fde_ref fde
= fun
->fde
;
18125 if (fde
->dw_fde_second_begin
)
18127 if (dwarf_version
>= 3 || !dwarf_strict
)
18129 /* We should use ranges for non-contiguous code section
18130 addresses. Use the actual code range for the initial
18131 section, since the HOT/COLD labels might precede an
18132 alignment offset. */
18133 bool range_list_added
= false;
18134 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18135 fde
->dw_fde_end
, &range_list_added
,
18137 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18138 fde
->dw_fde_second_end
,
18139 &range_list_added
, false);
18140 if (range_list_added
)
18145 /* There is no real support in DW2 for this .. so we make
18146 a work-around. First, emit the pub name for the segment
18147 containing the function label. Then make and emit a
18148 simplified subprogram DIE for the second segment with the
18149 name pre-fixed by __hot/cold_sect_of_. We use the same
18150 linkage name for the second die so that gdb will find both
18151 sections when given "b foo". */
18152 const char *name
= NULL
;
18153 tree decl_name
= DECL_NAME (decl
);
18154 dw_die_ref seg_die
;
18156 /* Do the 'primary' section. */
18157 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18158 fde
->dw_fde_end
, false);
18160 /* Build a minimal DIE for the secondary section. */
18161 seg_die
= new_die (DW_TAG_subprogram
,
18162 subr_die
->die_parent
, decl
);
18164 if (TREE_PUBLIC (decl
))
18165 add_AT_flag (seg_die
, DW_AT_external
, 1);
18167 if (decl_name
!= NULL
18168 && IDENTIFIER_POINTER (decl_name
) != NULL
)
18170 name
= dwarf2_name (decl
, 1);
18171 if (! DECL_ARTIFICIAL (decl
))
18172 add_src_coords_attributes (seg_die
, decl
);
18174 add_linkage_name (seg_die
, decl
);
18176 gcc_assert (name
!= NULL
);
18177 add_pure_or_virtual_attribute (seg_die
, decl
);
18178 if (DECL_ARTIFICIAL (decl
))
18179 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
18181 name
= concat ("__second_sect_of_", name
, NULL
);
18182 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
18183 fde
->dw_fde_second_end
, false);
18184 add_name_attribute (seg_die
, name
);
18185 if (want_pubnames ())
18186 add_pubname_string (name
, seg_die
);
18190 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
18194 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18196 /* We define the "frame base" as the function's CFA. This is more
18197 convenient for several reasons: (1) It's stable across the prologue
18198 and epilogue, which makes it better than just a frame pointer,
18199 (2) With dwarf3, there exists a one-byte encoding that allows us
18200 to reference the .debug_frame data by proxy, but failing that,
18201 (3) We can at least reuse the code inspection and interpretation
18202 code that determines the CFA position at various points in the
18204 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18206 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18207 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18211 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18212 if (list
->dw_loc_next
)
18213 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18215 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18218 /* Compute a displacement from the "steady-state frame pointer" to
18219 the CFA. The former is what all stack slots and argument slots
18220 will reference in the rtl; the latter is what we've told the
18221 debugger about. We'll need to adjust all frame_base references
18222 by this displacement. */
18223 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18225 if (fun
->static_chain_decl
)
18226 add_AT_location_description (subr_die
, DW_AT_static_link
,
18227 loc_list_from_tree (fun
->static_chain_decl
, 2));
18230 /* Generate child dies for template paramaters. */
18231 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18232 gen_generic_params_dies (decl
);
18234 /* Now output descriptions of the arguments for this function. This gets
18235 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18236 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18237 `...' at the end of the formal parameter list. In order to find out if
18238 there was a trailing ellipsis or not, we must instead look at the type
18239 associated with the FUNCTION_DECL. This will be a node of type
18240 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18241 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18242 an ellipsis at the end. */
18244 /* In the case where we are describing a mere function declaration, all we
18245 need to do here (and all we *can* do here) is to describe the *types* of
18246 its formal parameters. */
18247 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18249 else if (declaration
)
18250 gen_formal_types_die (decl
, subr_die
);
18253 /* Generate DIEs to represent all known formal parameters. */
18254 tree parm
= DECL_ARGUMENTS (decl
);
18255 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18256 tree generic_decl_parm
= generic_decl
18257 ? DECL_ARGUMENTS (generic_decl
)
18260 /* Now we want to walk the list of parameters of the function and
18261 emit their relevant DIEs.
18263 We consider the case of DECL being an instance of a generic function
18264 as well as it being a normal function.
18266 If DECL is an instance of a generic function we walk the
18267 parameters of the generic function declaration _and_ the parameters of
18268 DECL itself. This is useful because we want to emit specific DIEs for
18269 function parameter packs and those are declared as part of the
18270 generic function declaration. In that particular case,
18271 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18272 That DIE has children DIEs representing the set of arguments
18273 of the pack. Note that the set of pack arguments can be empty.
18274 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18277 Otherwise, we just consider the parameters of DECL. */
18278 while (generic_decl_parm
|| parm
)
18280 if (generic_decl_parm
18281 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18282 gen_formal_parameter_pack_die (generic_decl_parm
,
18287 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18289 if (parm
== DECL_ARGUMENTS (decl
)
18290 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18292 && (dwarf_version
>= 3 || !dwarf_strict
))
18293 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18295 parm
= DECL_CHAIN (parm
);
18298 if (generic_decl_parm
)
18299 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18302 /* Decide whether we need an unspecified_parameters DIE at the end.
18303 There are 2 more cases to do this for: 1) the ansi ... declaration -
18304 this is detectable when the end of the arg list is not a
18305 void_type_node 2) an unprototyped function declaration (not a
18306 definition). This just means that we have no info about the
18307 parameters at all. */
18308 if (prototype_p (TREE_TYPE (decl
)))
18310 /* This is the prototyped case, check for.... */
18311 if (stdarg_p (TREE_TYPE (decl
)))
18312 gen_unspecified_parameters_die (decl
, subr_die
);
18314 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18315 gen_unspecified_parameters_die (decl
, subr_die
);
18318 /* Output Dwarf info for all of the stuff within the body of the function
18319 (if it has one - it may be just a declaration). */
18320 outer_scope
= DECL_INITIAL (decl
);
18322 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18323 a function. This BLOCK actually represents the outermost binding contour
18324 for the function, i.e. the contour in which the function's formal
18325 parameters and labels get declared. Curiously, it appears that the front
18326 end doesn't actually put the PARM_DECL nodes for the current function onto
18327 the BLOCK_VARS list for this outer scope, but are strung off of the
18328 DECL_ARGUMENTS list for the function instead.
18330 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18331 the LABEL_DECL nodes for the function however, and we output DWARF info
18332 for those in decls_for_scope. Just within the `outer_scope' there will be
18333 a BLOCK node representing the function's outermost pair of curly braces,
18334 and any blocks used for the base and member initializers of a C++
18335 constructor function. */
18336 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18338 int call_site_note_count
= 0;
18339 int tail_call_site_note_count
= 0;
18341 /* Emit a DW_TAG_variable DIE for a named return value. */
18342 if (DECL_NAME (DECL_RESULT (decl
)))
18343 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18345 current_function_has_inlines
= 0;
18346 decls_for_scope (outer_scope
, subr_die
, 0);
18348 if (call_arg_locations
&& !dwarf_strict
)
18350 struct call_arg_loc_node
*ca_loc
;
18351 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18353 dw_die_ref die
= NULL
;
18354 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18357 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18358 arg
; arg
= next_arg
)
18360 dw_loc_descr_ref reg
, val
;
18361 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18362 dw_die_ref cdie
, tdie
= NULL
;
18364 next_arg
= XEXP (arg
, 1);
18365 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18367 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18368 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18369 && REGNO (XEXP (XEXP (arg
, 0), 0))
18370 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18371 next_arg
= XEXP (next_arg
, 1);
18372 if (mode
== VOIDmode
)
18374 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18375 if (mode
== VOIDmode
)
18376 mode
= GET_MODE (XEXP (arg
, 0));
18378 if (mode
== VOIDmode
|| mode
== BLKmode
)
18380 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18382 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18383 tloc
= XEXP (XEXP (arg
, 0), 1);
18386 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18387 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18389 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18390 tlocc
= XEXP (XEXP (arg
, 0), 1);
18394 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18395 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18396 VAR_INIT_STATUS_INITIALIZED
);
18397 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18399 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18400 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18401 get_address_mode (mem
),
18403 VAR_INIT_STATUS_INITIALIZED
);
18405 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18406 == DEBUG_PARAMETER_REF
)
18409 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18410 tdie
= lookup_decl_die (tdecl
);
18417 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18418 != DEBUG_PARAMETER_REF
)
18420 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18422 VAR_INIT_STATUS_INITIALIZED
);
18426 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18427 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18430 add_AT_loc (cdie
, DW_AT_location
, reg
);
18431 else if (tdie
!= NULL
)
18432 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18433 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18434 if (next_arg
!= XEXP (arg
, 1))
18436 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18437 if (mode
== VOIDmode
)
18438 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18439 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18442 VAR_INIT_STATUS_INITIALIZED
);
18444 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18448 && (ca_loc
->symbol_ref
|| tloc
))
18449 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18450 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18452 dw_loc_descr_ref tval
= NULL
;
18454 if (tloc
!= NULL_RTX
)
18455 tval
= mem_loc_descriptor (tloc
,
18456 GET_MODE (tloc
) == VOIDmode
18457 ? Pmode
: GET_MODE (tloc
),
18459 VAR_INIT_STATUS_INITIALIZED
);
18461 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18462 else if (tlocc
!= NULL_RTX
)
18464 tval
= mem_loc_descriptor (tlocc
,
18465 GET_MODE (tlocc
) == VOIDmode
18466 ? Pmode
: GET_MODE (tlocc
),
18468 VAR_INIT_STATUS_INITIALIZED
);
18470 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18476 call_site_note_count
++;
18477 if (ca_loc
->tail_call_p
)
18478 tail_call_site_note_count
++;
18482 call_arg_locations
= NULL
;
18483 call_arg_loc_last
= NULL
;
18484 if (tail_call_site_count
>= 0
18485 && tail_call_site_count
== tail_call_site_note_count
18488 if (call_site_count
>= 0
18489 && call_site_count
== call_site_note_count
)
18490 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18492 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18494 call_site_count
= -1;
18495 tail_call_site_count
= -1;
18497 /* Add the calling convention attribute if requested. */
18498 add_calling_convention_attribute (subr_die
, decl
);
18502 /* Returns a hash value for X (which really is a die_struct). */
18505 common_block_die_table_hash (const void *x
)
18507 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18508 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18511 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18512 as decl_id and die_parent of die_struct Y. */
18515 common_block_die_table_eq (const void *x
, const void *y
)
18517 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18518 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18519 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18522 /* Generate a DIE to represent a declared data object.
18523 Either DECL or ORIGIN must be non-null. */
18526 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18528 HOST_WIDE_INT off
= 0;
18530 tree decl_or_origin
= decl
? decl
: origin
;
18531 tree ultimate_origin
;
18532 dw_die_ref var_die
;
18533 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18534 dw_die_ref origin_die
;
18535 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18536 || class_or_namespace_scope_p (context_die
));
18537 bool specialization_p
= false;
18539 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18540 if (decl
|| ultimate_origin
)
18541 origin
= ultimate_origin
;
18542 com_decl
= fortran_common (decl_or_origin
, &off
);
18544 /* Symbol in common gets emitted as a child of the common block, in the form
18545 of a data member. */
18548 dw_die_ref com_die
;
18549 dw_loc_list_ref loc
;
18550 die_node com_die_arg
;
18552 var_die
= lookup_decl_die (decl_or_origin
);
18555 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18557 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18562 /* Optimize the common case. */
18563 if (single_element_loc_list_p (loc
)
18564 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18565 && loc
->expr
->dw_loc_next
== NULL
18566 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18569 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18570 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18571 = plus_constant (GET_MODE (x
), x
, off
);
18574 loc_list_plus_const (loc
, off
);
18576 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18577 remove_AT (var_die
, DW_AT_declaration
);
18583 if (common_block_die_table
== NULL
)
18584 common_block_die_table
18585 = htab_create_ggc (10, common_block_die_table_hash
,
18586 common_block_die_table_eq
, NULL
);
18588 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18589 com_die_arg
.die_parent
= context_die
;
18590 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18591 loc
= loc_list_from_tree (com_decl
, 2);
18592 if (com_die
== NULL
)
18595 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18598 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18599 add_name_and_src_coords_attributes (com_die
, com_decl
);
18602 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18603 /* Avoid sharing the same loc descriptor between
18604 DW_TAG_common_block and DW_TAG_variable. */
18605 loc
= loc_list_from_tree (com_decl
, 2);
18607 else if (DECL_EXTERNAL (decl
))
18608 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18609 if (want_pubnames ())
18610 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18611 com_die
->decl_id
= DECL_UID (com_decl
);
18612 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18613 *slot
= (void *) com_die
;
18615 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18617 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18618 loc
= loc_list_from_tree (com_decl
, 2);
18619 remove_AT (com_die
, DW_AT_declaration
);
18621 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18622 add_name_and_src_coords_attributes (var_die
, decl
);
18623 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18624 TREE_THIS_VOLATILE (decl
), context_die
);
18625 add_AT_flag (var_die
, DW_AT_external
, 1);
18630 /* Optimize the common case. */
18631 if (single_element_loc_list_p (loc
)
18632 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18633 && loc
->expr
->dw_loc_next
== NULL
18634 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18636 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18637 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18638 = plus_constant (GET_MODE (x
), x
, off
);
18641 loc_list_plus_const (loc
, off
);
18643 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18645 else if (DECL_EXTERNAL (decl
))
18646 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18647 equate_decl_number_to_die (decl
, var_die
);
18651 /* If the compiler emitted a definition for the DECL declaration
18652 and if we already emitted a DIE for it, don't emit a second
18653 DIE for it again. Allow re-declarations of DECLs that are
18654 inside functions, though. */
18655 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18658 /* For static data members, the declaration in the class is supposed
18659 to have DW_TAG_member tag; the specification should still be
18660 DW_TAG_variable referencing the DW_TAG_member DIE. */
18661 if (declaration
&& class_scope_p (context_die
))
18662 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18664 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18667 if (origin
!= NULL
)
18668 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18670 /* Loop unrolling can create multiple blocks that refer to the same
18671 static variable, so we must test for the DW_AT_declaration flag.
18673 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18674 copy decls and set the DECL_ABSTRACT flag on them instead of
18677 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18679 ??? The declare_in_namespace support causes us to get two DIEs for one
18680 variable, both of which are declarations. We want to avoid considering
18681 one to be a specification, so we must test that this DIE is not a
18683 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18684 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18686 /* This is a definition of a C++ class level static. */
18687 add_AT_specification (var_die
, old_die
);
18688 specialization_p
= true;
18689 if (DECL_NAME (decl
))
18691 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18692 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18694 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18695 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18697 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18698 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18700 if (old_die
->die_tag
== DW_TAG_member
)
18701 add_linkage_name (var_die
, decl
);
18705 add_name_and_src_coords_attributes (var_die
, decl
);
18707 if ((origin
== NULL
&& !specialization_p
)
18709 && !DECL_ABSTRACT (decl_or_origin
)
18710 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18711 decl_function_context
18712 (decl_or_origin
))))
18714 tree type
= TREE_TYPE (decl_or_origin
);
18716 if (decl_by_reference_p (decl_or_origin
))
18717 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18719 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18720 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18723 if (origin
== NULL
&& !specialization_p
)
18725 if (TREE_PUBLIC (decl
))
18726 add_AT_flag (var_die
, DW_AT_external
, 1);
18728 if (DECL_ARTIFICIAL (decl
))
18729 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18731 add_accessibility_attribute (var_die
, decl
);
18735 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18737 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18738 equate_decl_number_to_die (decl
, var_die
);
18741 && (! DECL_ABSTRACT (decl_or_origin
)
18742 /* Local static vars are shared between all clones/inlines,
18743 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18745 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18746 && TREE_STATIC (decl_or_origin
)
18747 && DECL_RTL_SET_P (decl_or_origin
)))
18748 /* When abstract origin already has DW_AT_location attribute, no need
18749 to add it again. */
18750 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18752 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18753 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18754 defer_location (decl_or_origin
, var_die
);
18756 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18757 decl
== NULL
, DW_AT_location
);
18758 add_pubname (decl_or_origin
, var_die
);
18761 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18764 /* Generate a DIE to represent a named constant. */
18767 gen_const_die (tree decl
, dw_die_ref context_die
)
18769 dw_die_ref const_die
;
18770 tree type
= TREE_TYPE (decl
);
18772 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18773 add_name_and_src_coords_attributes (const_die
, decl
);
18774 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18775 if (TREE_PUBLIC (decl
))
18776 add_AT_flag (const_die
, DW_AT_external
, 1);
18777 if (DECL_ARTIFICIAL (decl
))
18778 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18779 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18782 /* Generate a DIE to represent a label identifier. */
18785 gen_label_die (tree decl
, dw_die_ref context_die
)
18787 tree origin
= decl_ultimate_origin (decl
);
18788 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18790 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18792 if (origin
!= NULL
)
18793 add_abstract_origin_attribute (lbl_die
, origin
);
18795 add_name_and_src_coords_attributes (lbl_die
, decl
);
18797 if (DECL_ABSTRACT (decl
))
18798 equate_decl_number_to_die (decl
, lbl_die
);
18801 insn
= DECL_RTL_IF_SET (decl
);
18803 /* Deleted labels are programmer specified labels which have been
18804 eliminated because of various optimizations. We still emit them
18805 here so that it is possible to put breakpoints on them. */
18809 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18811 /* When optimization is enabled (via -O) some parts of the compiler
18812 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18813 represent source-level labels which were explicitly declared by
18814 the user. This really shouldn't be happening though, so catch
18815 it if it ever does happen. */
18816 gcc_assert (!INSN_DELETED_P (insn
));
18818 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18819 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18823 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18824 && CODE_LABEL_NUMBER (insn
) != -1)
18826 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18827 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18832 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18833 attributes to the DIE for a block STMT, to describe where the inlined
18834 function was called from. This is similar to add_src_coords_attributes. */
18837 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18839 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18841 if (dwarf_version
>= 3 || !dwarf_strict
)
18843 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18844 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18849 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18850 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18853 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18855 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18857 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18858 && (dwarf_version
>= 3 || !dwarf_strict
))
18860 tree chain
, superblock
= NULL_TREE
;
18862 dw_attr_ref attr
= NULL
;
18864 if (inlined_function_outer_scope_p (stmt
))
18866 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18867 BLOCK_NUMBER (stmt
));
18868 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18871 /* Optimize duplicate .debug_ranges lists or even tails of
18872 lists. If this BLOCK has same ranges as its supercontext,
18873 lookup DW_AT_ranges attribute in the supercontext (and
18874 recursively so), verify that the ranges_table contains the
18875 right values and use it instead of adding a new .debug_range. */
18876 for (chain
= stmt
, pdie
= die
;
18877 BLOCK_SAME_RANGE (chain
);
18878 chain
= BLOCK_SUPERCONTEXT (chain
))
18880 dw_attr_ref new_attr
;
18882 pdie
= pdie
->die_parent
;
18885 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18887 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18888 if (new_attr
== NULL
18889 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18892 superblock
= BLOCK_SUPERCONTEXT (chain
);
18895 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18896 / 2 / DWARF2_ADDR_SIZE
].num
18897 == BLOCK_NUMBER (superblock
))
18898 && BLOCK_FRAGMENT_CHAIN (superblock
))
18900 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18901 / 2 / DWARF2_ADDR_SIZE
;
18902 unsigned long supercnt
= 0, thiscnt
= 0;
18903 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18904 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18907 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18908 == BLOCK_NUMBER (chain
));
18910 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18911 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18912 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18914 gcc_assert (supercnt
>= thiscnt
);
18915 add_AT_range_list (die
, DW_AT_ranges
,
18916 ((off
+ supercnt
- thiscnt
)
18917 * 2 * DWARF2_ADDR_SIZE
),
18922 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18924 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18927 add_ranges (chain
);
18928 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18935 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18936 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18937 BLOCK_NUMBER (stmt
));
18938 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18939 BLOCK_NUMBER (stmt
));
18940 add_AT_low_high_pc (die
, label
, label_high
, false);
18944 /* Generate a DIE for a lexical block. */
18947 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18949 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18951 if (call_arg_locations
)
18953 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18954 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18955 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18958 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18959 add_high_low_attributes (stmt
, stmt_die
);
18961 decls_for_scope (stmt
, stmt_die
, depth
);
18964 /* Generate a DIE for an inlined subprogram. */
18967 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18971 /* The instance of function that is effectively being inlined shall not
18973 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18975 decl
= block_ultimate_origin (stmt
);
18977 /* Emit info for the abstract instance first, if we haven't yet. We
18978 must emit this even if the block is abstract, otherwise when we
18979 emit the block below (or elsewhere), we may end up trying to emit
18980 a die whose origin die hasn't been emitted, and crashing. */
18981 dwarf2out_abstract_function (decl
);
18983 if (! BLOCK_ABSTRACT (stmt
))
18985 dw_die_ref subr_die
18986 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18988 if (call_arg_locations
)
18990 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18991 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18992 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18994 add_abstract_origin_attribute (subr_die
, decl
);
18995 if (TREE_ASM_WRITTEN (stmt
))
18996 add_high_low_attributes (stmt
, subr_die
);
18997 add_call_src_coords_attributes (stmt
, subr_die
);
18999 decls_for_scope (stmt
, subr_die
, depth
);
19000 current_function_has_inlines
= 1;
19004 /* Generate a DIE for a field in a record, or structure. */
19007 gen_field_die (tree decl
, dw_die_ref context_die
)
19009 dw_die_ref decl_die
;
19011 if (TREE_TYPE (decl
) == error_mark_node
)
19014 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19015 add_name_and_src_coords_attributes (decl_die
, decl
);
19016 add_type_attribute (decl_die
, member_declared_type (decl
),
19017 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
19020 if (DECL_BIT_FIELD_TYPE (decl
))
19022 add_byte_size_attribute (decl_die
, decl
);
19023 add_bit_size_attribute (decl_die
, decl
);
19024 add_bit_offset_attribute (decl_die
, decl
);
19027 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19028 add_data_member_location_attribute (decl_die
, decl
);
19030 if (DECL_ARTIFICIAL (decl
))
19031 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19033 add_accessibility_attribute (decl_die
, decl
);
19035 /* Equate decl number to die, so that we can look up this decl later on. */
19036 equate_decl_number_to_die (decl
, decl_die
);
19040 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19041 Use modified_type_die instead.
19042 We keep this code here just in case these types of DIEs may be needed to
19043 represent certain things in other languages (e.g. Pascal) someday. */
19046 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19049 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19051 equate_type_number_to_die (type
, ptr_die
);
19052 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19053 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19056 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19057 Use modified_type_die instead.
19058 We keep this code here just in case these types of DIEs may be needed to
19059 represent certain things in other languages (e.g. Pascal) someday. */
19062 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19064 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19066 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19067 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19069 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19071 equate_type_number_to_die (type
, ref_die
);
19072 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
19073 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19077 /* Generate a DIE for a pointer to a member type. */
19080 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
19083 = new_die (DW_TAG_ptr_to_member_type
,
19084 scope_die_for (type
, context_die
), type
);
19086 equate_type_number_to_die (type
, ptr_die
);
19087 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
19088 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
19089 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19092 typedef const char *dchar_p
; /* For DEF_VEC_P. */
19094 static char *producer_string
;
19096 /* Return a heap allocated producer string including command line options
19097 if -grecord-gcc-switches. */
19100 gen_producer_string (void)
19103 vec
<dchar_p
> switches
= vNULL
;
19104 const char *language_string
= lang_hooks
.name
;
19105 char *producer
, *tail
;
19107 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
19108 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
19110 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
19111 switch (save_decoded_options
[j
].opt_index
)
19118 case OPT_auxbase_strip
:
19127 case OPT_SPECIAL_unknown
:
19128 case OPT_SPECIAL_ignore
:
19129 case OPT_SPECIAL_program_name
:
19130 case OPT_SPECIAL_input_file
:
19131 case OPT_grecord_gcc_switches
:
19132 case OPT_gno_record_gcc_switches
:
19133 case OPT__output_pch_
:
19134 case OPT_fdiagnostics_show_location_
:
19135 case OPT_fdiagnostics_show_option
:
19136 case OPT_fdiagnostics_show_caret
:
19137 case OPT_fdiagnostics_color_
:
19138 case OPT_fverbose_asm
:
19140 case OPT__sysroot_
:
19142 case OPT_nostdinc__
:
19143 /* Ignore these. */
19146 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
19147 & CL_NO_DWARF_RECORD
)
19149 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
19151 switch (save_decoded_options
[j
].canonical_option
[0][1])
19158 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
19165 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
19166 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
19170 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
19172 sprintf (tail
, "%s %s", language_string
, version_string
);
19175 FOR_EACH_VEC_ELT (switches
, j
, p
)
19179 memcpy (tail
+ 1, p
, len
);
19184 switches
.release ();
19188 /* Generate the DIE for the compilation unit. */
19191 gen_compile_unit_die (const char *filename
)
19194 const char *language_string
= lang_hooks
.name
;
19197 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19201 add_name_attribute (die
, filename
);
19202 /* Don't add cwd for <built-in>. */
19203 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19204 add_comp_dir_attribute (die
);
19207 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19209 /* If our producer is LTO try to figure out a common language to use
19210 from the global list of translation units. */
19211 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19215 const char *common_lang
= NULL
;
19217 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19219 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19222 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19223 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19225 else if (strncmp (common_lang
, "GNU C", 5) == 0
19226 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19227 /* Mixing C and C++ is ok, use C++ in that case. */
19228 common_lang
= "GNU C++";
19231 /* Fall back to C. */
19232 common_lang
= NULL
;
19238 language_string
= common_lang
;
19241 language
= DW_LANG_C89
;
19242 if (strcmp (language_string
, "GNU C++") == 0)
19243 language
= DW_LANG_C_plus_plus
;
19244 else if (strcmp (language_string
, "GNU F77") == 0)
19245 language
= DW_LANG_Fortran77
;
19246 else if (strcmp (language_string
, "GNU Pascal") == 0)
19247 language
= DW_LANG_Pascal83
;
19248 else if (dwarf_version
>= 3 || !dwarf_strict
)
19250 if (strcmp (language_string
, "GNU Ada") == 0)
19251 language
= DW_LANG_Ada95
;
19252 else if (strcmp (language_string
, "GNU Fortran") == 0)
19253 language
= DW_LANG_Fortran95
;
19254 else if (strcmp (language_string
, "GNU Java") == 0)
19255 language
= DW_LANG_Java
;
19256 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19257 language
= DW_LANG_ObjC
;
19258 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19259 language
= DW_LANG_ObjC_plus_plus
;
19260 else if (dwarf_version
>= 5 || !dwarf_strict
)
19262 if (strcmp (language_string
, "GNU Go") == 0)
19263 language
= DW_LANG_Go
;
19266 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19267 else if (strcmp (language_string
, "GNU Fortran") == 0)
19268 language
= DW_LANG_Fortran90
;
19270 add_AT_unsigned (die
, DW_AT_language
, language
);
19274 case DW_LANG_Fortran77
:
19275 case DW_LANG_Fortran90
:
19276 case DW_LANG_Fortran95
:
19277 /* Fortran has case insensitive identifiers and the front-end
19278 lowercases everything. */
19279 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19282 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19288 /* Generate the DIE for a base class. */
19291 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19293 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19295 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19296 add_data_member_location_attribute (die
, binfo
);
19298 if (BINFO_VIRTUAL_P (binfo
))
19299 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19301 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19302 children, otherwise the default is DW_ACCESS_public. In DWARF2
19303 the default has always been DW_ACCESS_private. */
19304 if (access
== access_public_node
)
19306 if (dwarf_version
== 2
19307 || context_die
->die_tag
== DW_TAG_class_type
)
19308 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19310 else if (access
== access_protected_node
)
19311 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19312 else if (dwarf_version
> 2
19313 && context_die
->die_tag
!= DW_TAG_class_type
)
19314 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19317 /* Generate a DIE for a class member. */
19320 gen_member_die (tree type
, dw_die_ref context_die
)
19323 tree binfo
= TYPE_BINFO (type
);
19326 /* If this is not an incomplete type, output descriptions of each of its
19327 members. Note that as we output the DIEs necessary to represent the
19328 members of this record or union type, we will also be trying to output
19329 DIEs to represent the *types* of those members. However the `type'
19330 function (above) will specifically avoid generating type DIEs for member
19331 types *within* the list of member DIEs for this (containing) type except
19332 for those types (of members) which are explicitly marked as also being
19333 members of this (containing) type themselves. The g++ front- end can
19334 force any given type to be treated as a member of some other (containing)
19335 type by setting the TYPE_CONTEXT of the given (member) type to point to
19336 the TREE node representing the appropriate (containing) type. */
19338 /* First output info about the base classes. */
19341 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19345 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19346 gen_inheritance_die (base
,
19347 (accesses
? (*accesses
)[i
] : access_public_node
),
19351 /* Now output info about the data members and type members. */
19352 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19354 /* If we thought we were generating minimal debug info for TYPE
19355 and then changed our minds, some of the member declarations
19356 may have already been defined. Don't define them again, but
19357 do put them in the right order. */
19359 child
= lookup_decl_die (member
);
19361 splice_child_die (context_die
, child
);
19363 gen_decl_die (member
, NULL
, context_die
);
19366 /* Now output info about the function members (if any). */
19367 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19369 /* Don't include clones in the member list. */
19370 if (DECL_ABSTRACT_ORIGIN (member
))
19373 child
= lookup_decl_die (member
);
19375 splice_child_die (context_die
, child
);
19377 gen_decl_die (member
, NULL
, context_die
);
19381 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19382 is set, we pretend that the type was never defined, so we only get the
19383 member DIEs needed by later specification DIEs. */
19386 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19387 enum debug_info_usage usage
)
19389 dw_die_ref type_die
= lookup_type_die (type
);
19390 dw_die_ref scope_die
= 0;
19392 int complete
= (TYPE_SIZE (type
)
19393 && (! TYPE_STUB_DECL (type
)
19394 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19395 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19396 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19398 if (type_die
&& ! complete
)
19401 if (TYPE_CONTEXT (type
) != NULL_TREE
19402 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19403 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19406 scope_die
= scope_die_for (type
, context_die
);
19408 /* Generate child dies for template paramaters. */
19409 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19410 schedule_generic_params_dies_gen (type
);
19412 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19413 /* First occurrence of type or toplevel definition of nested class. */
19415 dw_die_ref old_die
= type_die
;
19417 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19418 ? record_type_tag (type
) : DW_TAG_union_type
,
19420 equate_type_number_to_die (type
, type_die
);
19422 add_AT_specification (type_die
, old_die
);
19424 add_name_attribute (type_die
, type_tag (type
));
19427 remove_AT (type_die
, DW_AT_declaration
);
19429 /* If this type has been completed, then give it a byte_size attribute and
19430 then give a list of members. */
19431 if (complete
&& !ns_decl
)
19433 /* Prevent infinite recursion in cases where the type of some member of
19434 this type is expressed in terms of this type itself. */
19435 TREE_ASM_WRITTEN (type
) = 1;
19436 add_byte_size_attribute (type_die
, type
);
19437 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19439 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19440 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19443 /* If the first reference to this type was as the return type of an
19444 inline function, then it may not have a parent. Fix this now. */
19445 if (type_die
->die_parent
== NULL
)
19446 add_child_die (scope_die
, type_die
);
19448 push_decl_scope (type
);
19449 gen_member_die (type
, type_die
);
19452 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19453 if (TYPE_ARTIFICIAL (type
))
19454 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19456 /* GNU extension: Record what type our vtable lives in. */
19457 if (TYPE_VFIELD (type
))
19459 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19461 gen_type_die (vtype
, context_die
);
19462 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19463 lookup_type_die (vtype
));
19468 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19470 /* We don't need to do this for function-local types. */
19471 if (TYPE_STUB_DECL (type
)
19472 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19473 vec_safe_push (incomplete_types
, type
);
19476 if (get_AT (type_die
, DW_AT_name
))
19477 add_pubtype (type
, type_die
);
19480 /* Generate a DIE for a subroutine _type_. */
19483 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19485 tree return_type
= TREE_TYPE (type
);
19486 dw_die_ref subr_die
19487 = new_die (DW_TAG_subroutine_type
,
19488 scope_die_for (type
, context_die
), type
);
19490 equate_type_number_to_die (type
, subr_die
);
19491 add_prototyped_attribute (subr_die
, type
);
19492 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19493 gen_formal_types_die (type
, subr_die
);
19495 if (get_AT (subr_die
, DW_AT_name
))
19496 add_pubtype (type
, subr_die
);
19499 /* Generate a DIE for a type definition. */
19502 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19504 dw_die_ref type_die
;
19507 if (TREE_ASM_WRITTEN (decl
))
19510 TREE_ASM_WRITTEN (decl
) = 1;
19511 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19512 origin
= decl_ultimate_origin (decl
);
19513 if (origin
!= NULL
)
19514 add_abstract_origin_attribute (type_die
, origin
);
19519 add_name_and_src_coords_attributes (type_die
, decl
);
19520 if (DECL_ORIGINAL_TYPE (decl
))
19522 type
= DECL_ORIGINAL_TYPE (decl
);
19524 gcc_assert (type
!= TREE_TYPE (decl
));
19525 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19529 type
= TREE_TYPE (decl
);
19531 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19533 /* Here, we are in the case of decl being a typedef naming
19534 an anonymous type, e.g:
19535 typedef struct {...} foo;
19536 In that case TREE_TYPE (decl) is not a typedef variant
19537 type and TYPE_NAME of the anonymous type is set to the
19538 TYPE_DECL of the typedef. This construct is emitted by
19541 TYPE is the anonymous struct named by the typedef
19542 DECL. As we need the DW_AT_type attribute of the
19543 DW_TAG_typedef to point to the DIE of TYPE, let's
19544 generate that DIE right away. add_type_attribute
19545 called below will then pick (via lookup_type_die) that
19546 anonymous struct DIE. */
19547 if (!TREE_ASM_WRITTEN (type
))
19548 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19550 /* This is a GNU Extension. We are adding a
19551 DW_AT_linkage_name attribute to the DIE of the
19552 anonymous struct TYPE. The value of that attribute
19553 is the name of the typedef decl naming the anonymous
19554 struct. This greatly eases the work of consumers of
19555 this debug info. */
19556 add_linkage_attr (lookup_type_die (type
), decl
);
19560 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19561 TREE_THIS_VOLATILE (decl
), context_die
);
19563 if (is_naming_typedef_decl (decl
))
19564 /* We want that all subsequent calls to lookup_type_die with
19565 TYPE in argument yield the DW_TAG_typedef we have just
19567 equate_type_number_to_die (type
, type_die
);
19569 add_accessibility_attribute (type_die
, decl
);
19572 if (DECL_ABSTRACT (decl
))
19573 equate_decl_number_to_die (decl
, type_die
);
19575 if (get_AT (type_die
, DW_AT_name
))
19576 add_pubtype (decl
, type_die
);
19579 /* Generate a DIE for a struct, class, enum or union type. */
19582 gen_tagged_type_die (tree type
,
19583 dw_die_ref context_die
,
19584 enum debug_info_usage usage
)
19588 if (type
== NULL_TREE
19589 || !is_tagged_type (type
))
19592 /* If this is a nested type whose containing class hasn't been written
19593 out yet, writing it out will cover this one, too. This does not apply
19594 to instantiations of member class templates; they need to be added to
19595 the containing class as they are generated. FIXME: This hurts the
19596 idea of combining type decls from multiple TUs, since we can't predict
19597 what set of template instantiations we'll get. */
19598 if (TYPE_CONTEXT (type
)
19599 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19600 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19602 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19604 if (TREE_ASM_WRITTEN (type
))
19607 /* If that failed, attach ourselves to the stub. */
19608 push_decl_scope (TYPE_CONTEXT (type
));
19609 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19612 else if (TYPE_CONTEXT (type
) != NULL_TREE
19613 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19615 /* If this type is local to a function that hasn't been written
19616 out yet, use a NULL context for now; it will be fixed up in
19617 decls_for_scope. */
19618 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19619 /* A declaration DIE doesn't count; nested types need to go in the
19621 if (context_die
&& is_declaration_die (context_die
))
19622 context_die
= NULL
;
19627 context_die
= declare_in_namespace (type
, context_die
);
19631 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19633 /* This might have been written out by the call to
19634 declare_in_namespace. */
19635 if (!TREE_ASM_WRITTEN (type
))
19636 gen_enumeration_type_die (type
, context_die
);
19639 gen_struct_or_union_type_die (type
, context_die
, usage
);
19644 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19645 it up if it is ever completed. gen_*_type_die will set it for us
19646 when appropriate. */
19649 /* Generate a type description DIE. */
19652 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19653 enum debug_info_usage usage
)
19655 struct array_descr_info info
;
19657 if (type
== NULL_TREE
|| type
== error_mark_node
)
19660 if (TYPE_NAME (type
) != NULL_TREE
19661 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19662 && is_redundant_typedef (TYPE_NAME (type
))
19663 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19664 /* The DECL of this type is a typedef we don't want to emit debug
19665 info for but we want debug info for its underlying typedef.
19666 This can happen for e.g, the injected-class-name of a C++
19668 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19670 /* If TYPE is a typedef type variant, let's generate debug info
19671 for the parent typedef which TYPE is a type of. */
19672 if (typedef_variant_p (type
))
19674 if (TREE_ASM_WRITTEN (type
))
19677 /* Prevent broken recursion; we can't hand off to the same type. */
19678 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19680 /* Give typedefs the right scope. */
19681 context_die
= scope_die_for (type
, context_die
);
19683 TREE_ASM_WRITTEN (type
) = 1;
19685 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19689 /* If type is an anonymous tagged type named by a typedef, let's
19690 generate debug info for the typedef. */
19691 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19693 /* Use the DIE of the containing namespace as the parent DIE of
19694 the type description DIE we want to generate. */
19695 if (DECL_CONTEXT (TYPE_NAME (type
))
19696 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19697 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19699 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19703 /* If this is an array type with hidden descriptor, handle it first. */
19704 if (!TREE_ASM_WRITTEN (type
)
19705 && lang_hooks
.types
.get_array_descr_info
19706 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19707 && (dwarf_version
>= 3 || !dwarf_strict
))
19709 gen_descr_array_type_die (type
, &info
, context_die
);
19710 TREE_ASM_WRITTEN (type
) = 1;
19714 /* We are going to output a DIE to represent the unqualified version
19715 of this type (i.e. without any const or volatile qualifiers) so
19716 get the main variant (i.e. the unqualified version) of this type
19717 now. (Vectors are special because the debugging info is in the
19718 cloned type itself). */
19719 if (TREE_CODE (type
) != VECTOR_TYPE
)
19720 type
= type_main_variant (type
);
19722 if (TREE_ASM_WRITTEN (type
))
19725 switch (TREE_CODE (type
))
19731 case REFERENCE_TYPE
:
19732 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19733 ensures that the gen_type_die recursion will terminate even if the
19734 type is recursive. Recursive types are possible in Ada. */
19735 /* ??? We could perhaps do this for all types before the switch
19737 TREE_ASM_WRITTEN (type
) = 1;
19739 /* For these types, all that is required is that we output a DIE (or a
19740 set of DIEs) to represent the "basis" type. */
19741 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19742 DINFO_USAGE_IND_USE
);
19746 /* This code is used for C++ pointer-to-data-member types.
19747 Output a description of the relevant class type. */
19748 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19749 DINFO_USAGE_IND_USE
);
19751 /* Output a description of the type of the object pointed to. */
19752 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19753 DINFO_USAGE_IND_USE
);
19755 /* Now output a DIE to represent this pointer-to-data-member type
19757 gen_ptr_to_mbr_type_die (type
, context_die
);
19760 case FUNCTION_TYPE
:
19761 /* Force out return type (in case it wasn't forced out already). */
19762 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19763 DINFO_USAGE_DIR_USE
);
19764 gen_subroutine_type_die (type
, context_die
);
19768 /* Force out return type (in case it wasn't forced out already). */
19769 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19770 DINFO_USAGE_DIR_USE
);
19771 gen_subroutine_type_die (type
, context_die
);
19775 gen_array_type_die (type
, context_die
);
19779 gen_array_type_die (type
, context_die
);
19782 case ENUMERAL_TYPE
:
19785 case QUAL_UNION_TYPE
:
19786 gen_tagged_type_die (type
, context_die
, usage
);
19792 case FIXED_POINT_TYPE
:
19795 /* No DIEs needed for fundamental types. */
19800 /* Just use DW_TAG_unspecified_type. */
19802 dw_die_ref type_die
= lookup_type_die (type
);
19803 if (type_die
== NULL
)
19805 tree name
= TYPE_NAME (type
);
19806 if (TREE_CODE (name
) == TYPE_DECL
)
19807 name
= DECL_NAME (name
);
19808 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19809 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19810 equate_type_number_to_die (type
, type_die
);
19816 gcc_unreachable ();
19819 TREE_ASM_WRITTEN (type
) = 1;
19823 gen_type_die (tree type
, dw_die_ref context_die
)
19825 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19828 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19829 things which are local to the given block. */
19832 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19834 int must_output_die
= 0;
19837 /* Ignore blocks that are NULL. */
19838 if (stmt
== NULL_TREE
)
19841 inlined_func
= inlined_function_outer_scope_p (stmt
);
19843 /* If the block is one fragment of a non-contiguous block, do not
19844 process the variables, since they will have been done by the
19845 origin block. Do process subblocks. */
19846 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19850 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19851 gen_block_die (sub
, context_die
, depth
+ 1);
19856 /* Determine if we need to output any Dwarf DIEs at all to represent this
19859 /* The outer scopes for inlinings *must* always be represented. We
19860 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19861 must_output_die
= 1;
19864 /* Determine if this block directly contains any "significant"
19865 local declarations which we will need to output DIEs for. */
19866 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19867 /* We are not in terse mode so *any* local declaration counts
19868 as being a "significant" one. */
19869 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19870 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19871 && (TREE_USED (stmt
)
19872 || TREE_ASM_WRITTEN (stmt
)
19873 || BLOCK_ABSTRACT (stmt
)));
19874 else if ((TREE_USED (stmt
)
19875 || TREE_ASM_WRITTEN (stmt
)
19876 || BLOCK_ABSTRACT (stmt
))
19877 && !dwarf2out_ignore_block (stmt
))
19878 must_output_die
= 1;
19881 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19882 DIE for any block which contains no significant local declarations at
19883 all. Rather, in such cases we just call `decls_for_scope' so that any
19884 needed Dwarf info for any sub-blocks will get properly generated. Note
19885 that in terse mode, our definition of what constitutes a "significant"
19886 local declaration gets restricted to include only inlined function
19887 instances and local (nested) function definitions. */
19888 if (must_output_die
)
19892 /* If STMT block is abstract, that means we have been called
19893 indirectly from dwarf2out_abstract_function.
19894 That function rightfully marks the descendent blocks (of
19895 the abstract function it is dealing with) as being abstract,
19896 precisely to prevent us from emitting any
19897 DW_TAG_inlined_subroutine DIE as a descendent
19898 of an abstract function instance. So in that case, we should
19899 not call gen_inlined_subroutine_die.
19901 Later though, when cgraph asks dwarf2out to emit info
19902 for the concrete instance of the function decl into which
19903 the concrete instance of STMT got inlined, the later will lead
19904 to the generation of a DW_TAG_inlined_subroutine DIE. */
19905 if (! BLOCK_ABSTRACT (stmt
))
19906 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19909 gen_lexical_block_die (stmt
, context_die
, depth
);
19912 decls_for_scope (stmt
, context_die
, depth
);
19915 /* Process variable DECL (or variable with origin ORIGIN) within
19916 block STMT and add it to CONTEXT_DIE. */
19918 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19921 tree decl_or_origin
= decl
? decl
: origin
;
19923 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19924 die
= lookup_decl_die (decl_or_origin
);
19925 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19926 && TYPE_DECL_IS_STUB (decl_or_origin
))
19927 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19931 if (die
!= NULL
&& die
->die_parent
== NULL
)
19932 add_child_die (context_die
, die
);
19933 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19934 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19935 stmt
, context_die
);
19937 gen_decl_die (decl
, origin
, context_die
);
19940 /* Generate all of the decls declared within a given scope and (recursively)
19941 all of its sub-blocks. */
19944 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19950 /* Ignore NULL blocks. */
19951 if (stmt
== NULL_TREE
)
19954 /* Output the DIEs to represent all of the data objects and typedefs
19955 declared directly within this block but not within any nested
19956 sub-blocks. Also, nested function and tag DIEs have been
19957 generated with a parent of NULL; fix that up now. */
19958 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19959 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19960 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19961 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19964 /* If we're at -g1, we're not interested in subblocks. */
19965 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19968 /* Output the DIEs to represent all sub-blocks (and the items declared
19969 therein) of this block. */
19970 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19972 subblocks
= BLOCK_CHAIN (subblocks
))
19973 gen_block_die (subblocks
, context_die
, depth
+ 1);
19976 /* Is this a typedef we can avoid emitting? */
19979 is_redundant_typedef (const_tree decl
)
19981 if (TYPE_DECL_IS_STUB (decl
))
19984 if (DECL_ARTIFICIAL (decl
)
19985 && DECL_CONTEXT (decl
)
19986 && is_tagged_type (DECL_CONTEXT (decl
))
19987 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19988 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19989 /* Also ignore the artificial member typedef for the class name. */
19995 /* Return TRUE if TYPE is a typedef that names a type for linkage
19996 purposes. This kind of typedefs is produced by the C++ FE for
19999 typedef struct {...} foo;
20001 In that case, there is no typedef variant type produced for foo.
20002 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20006 is_naming_typedef_decl (const_tree decl
)
20008 if (decl
== NULL_TREE
20009 || TREE_CODE (decl
) != TYPE_DECL
20010 || !is_tagged_type (TREE_TYPE (decl
))
20011 || DECL_IS_BUILTIN (decl
)
20012 || is_redundant_typedef (decl
)
20013 /* It looks like Ada produces TYPE_DECLs that are very similar
20014 to C++ naming typedefs but that have different
20015 semantics. Let's be specific to c++ for now. */
20019 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20020 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20021 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20022 != TYPE_NAME (TREE_TYPE (decl
))));
20025 /* Returns the DIE for a context. */
20027 static inline dw_die_ref
20028 get_context_die (tree context
)
20032 /* Find die that represents this context. */
20033 if (TYPE_P (context
))
20035 context
= TYPE_MAIN_VARIANT (context
);
20036 return strip_naming_typedef (context
, force_type_die (context
));
20039 return force_decl_die (context
);
20041 return comp_unit_die ();
20044 /* Returns the DIE for decl. A DIE will always be returned. */
20047 force_decl_die (tree decl
)
20049 dw_die_ref decl_die
;
20050 unsigned saved_external_flag
;
20051 tree save_fn
= NULL_TREE
;
20052 decl_die
= lookup_decl_die (decl
);
20055 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20057 decl_die
= lookup_decl_die (decl
);
20061 switch (TREE_CODE (decl
))
20063 case FUNCTION_DECL
:
20064 /* Clear current_function_decl, so that gen_subprogram_die thinks
20065 that this is a declaration. At this point, we just want to force
20066 declaration die. */
20067 save_fn
= current_function_decl
;
20068 current_function_decl
= NULL_TREE
;
20069 gen_subprogram_die (decl
, context_die
);
20070 current_function_decl
= save_fn
;
20074 /* Set external flag to force declaration die. Restore it after
20075 gen_decl_die() call. */
20076 saved_external_flag
= DECL_EXTERNAL (decl
);
20077 DECL_EXTERNAL (decl
) = 1;
20078 gen_decl_die (decl
, NULL
, context_die
);
20079 DECL_EXTERNAL (decl
) = saved_external_flag
;
20082 case NAMESPACE_DECL
:
20083 if (dwarf_version
>= 3 || !dwarf_strict
)
20084 dwarf2out_decl (decl
);
20086 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20087 decl_die
= comp_unit_die ();
20090 case TRANSLATION_UNIT_DECL
:
20091 decl_die
= comp_unit_die ();
20095 gcc_unreachable ();
20098 /* We should be able to find the DIE now. */
20100 decl_die
= lookup_decl_die (decl
);
20101 gcc_assert (decl_die
);
20107 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20108 always returned. */
20111 force_type_die (tree type
)
20113 dw_die_ref type_die
;
20115 type_die
= lookup_type_die (type
);
20118 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20120 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20121 TYPE_VOLATILE (type
), context_die
);
20122 gcc_assert (type_die
);
20127 /* Force out any required namespaces to be able to output DECL,
20128 and return the new context_die for it, if it's changed. */
20131 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20133 tree context
= (DECL_P (thing
)
20134 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20135 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20136 /* Force out the namespace. */
20137 context_die
= force_decl_die (context
);
20139 return context_die
;
20142 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20143 type) within its namespace, if appropriate.
20145 For compatibility with older debuggers, namespace DIEs only contain
20146 declarations; all definitions are emitted at CU scope. */
20149 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20151 dw_die_ref ns_context
;
20153 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20154 return context_die
;
20156 /* If this decl is from an inlined function, then don't try to emit it in its
20157 namespace, as we will get confused. It would have already been emitted
20158 when the abstract instance of the inline function was emitted anyways. */
20159 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20160 return context_die
;
20162 ns_context
= setup_namespace_context (thing
, context_die
);
20164 if (ns_context
!= context_die
)
20168 if (DECL_P (thing
))
20169 gen_decl_die (thing
, NULL
, ns_context
);
20171 gen_type_die (thing
, ns_context
);
20173 return context_die
;
20176 /* Generate a DIE for a namespace or namespace alias. */
20179 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20181 dw_die_ref namespace_die
;
20183 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20184 they are an alias of. */
20185 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20187 /* Output a real namespace or module. */
20188 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20189 namespace_die
= new_die (is_fortran ()
20190 ? DW_TAG_module
: DW_TAG_namespace
,
20191 context_die
, decl
);
20192 /* For Fortran modules defined in different CU don't add src coords. */
20193 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20195 const char *name
= dwarf2_name (decl
, 0);
20197 add_name_attribute (namespace_die
, name
);
20200 add_name_and_src_coords_attributes (namespace_die
, decl
);
20201 if (DECL_EXTERNAL (decl
))
20202 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20203 equate_decl_number_to_die (decl
, namespace_die
);
20207 /* Output a namespace alias. */
20209 /* Force out the namespace we are an alias of, if necessary. */
20210 dw_die_ref origin_die
20211 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20213 if (DECL_FILE_SCOPE_P (decl
)
20214 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20215 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20216 /* Now create the namespace alias DIE. */
20217 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20218 add_name_and_src_coords_attributes (namespace_die
, decl
);
20219 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20220 equate_decl_number_to_die (decl
, namespace_die
);
20222 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20223 if (want_pubnames ())
20224 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20227 /* Generate Dwarf debug information for a decl described by DECL.
20228 The return value is currently only meaningful for PARM_DECLs,
20229 for all other decls it returns NULL. */
20232 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20234 tree decl_or_origin
= decl
? decl
: origin
;
20235 tree class_origin
= NULL
, ultimate_origin
;
20237 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20240 switch (TREE_CODE (decl_or_origin
))
20246 if (!is_fortran () && !is_ada ())
20248 /* The individual enumerators of an enum type get output when we output
20249 the Dwarf representation of the relevant enum type itself. */
20253 /* Emit its type. */
20254 gen_type_die (TREE_TYPE (decl
), context_die
);
20256 /* And its containing namespace. */
20257 context_die
= declare_in_namespace (decl
, context_die
);
20259 gen_const_die (decl
, context_die
);
20262 case FUNCTION_DECL
:
20263 /* Don't output any DIEs to represent mere function declarations,
20264 unless they are class members or explicit block externs. */
20265 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20266 && DECL_FILE_SCOPE_P (decl_or_origin
)
20267 && (current_function_decl
== NULL_TREE
20268 || DECL_ARTIFICIAL (decl_or_origin
)))
20273 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20274 on local redeclarations of global functions. That seems broken. */
20275 if (current_function_decl
!= decl
)
20276 /* This is only a declaration. */;
20279 /* If we're emitting a clone, emit info for the abstract instance. */
20280 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20281 dwarf2out_abstract_function (origin
20282 ? DECL_ORIGIN (origin
)
20283 : DECL_ABSTRACT_ORIGIN (decl
));
20285 /* If we're emitting an out-of-line copy of an inline function,
20286 emit info for the abstract instance and set up to refer to it. */
20287 else if (cgraph_function_possibly_inlined_p (decl
)
20288 && ! DECL_ABSTRACT (decl
)
20289 && ! class_or_namespace_scope_p (context_die
)
20290 /* dwarf2out_abstract_function won't emit a die if this is just
20291 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20292 that case, because that works only if we have a die. */
20293 && DECL_INITIAL (decl
) != NULL_TREE
)
20295 dwarf2out_abstract_function (decl
);
20296 set_decl_origin_self (decl
);
20299 /* Otherwise we're emitting the primary DIE for this decl. */
20300 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20302 /* Before we describe the FUNCTION_DECL itself, make sure that we
20303 have its containing type. */
20305 origin
= decl_class_context (decl
);
20306 if (origin
!= NULL_TREE
)
20307 gen_type_die (origin
, context_die
);
20309 /* And its return type. */
20310 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20312 /* And its virtual context. */
20313 if (DECL_VINDEX (decl
) != NULL_TREE
)
20314 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20316 /* Make sure we have a member DIE for decl. */
20317 if (origin
!= NULL_TREE
)
20318 gen_type_die_for_member (origin
, decl
, context_die
);
20320 /* And its containing namespace. */
20321 context_die
= declare_in_namespace (decl
, context_die
);
20324 /* Now output a DIE to represent the function itself. */
20326 gen_subprogram_die (decl
, context_die
);
20330 /* If we are in terse mode, don't generate any DIEs to represent any
20331 actual typedefs. */
20332 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20335 /* In the special case of a TYPE_DECL node representing the declaration
20336 of some type tag, if the given TYPE_DECL is marked as having been
20337 instantiated from some other (original) TYPE_DECL node (e.g. one which
20338 was generated within the original definition of an inline function) we
20339 used to generate a special (abbreviated) DW_TAG_structure_type,
20340 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20341 should be actually referencing those DIEs, as variable DIEs with that
20342 type would be emitted already in the abstract origin, so it was always
20343 removed during unused type prunning. Don't add anything in this
20345 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20348 if (is_redundant_typedef (decl
))
20349 gen_type_die (TREE_TYPE (decl
), context_die
);
20351 /* Output a DIE to represent the typedef itself. */
20352 gen_typedef_die (decl
, context_die
);
20356 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20357 gen_label_die (decl
, context_die
);
20362 /* If we are in terse mode, don't generate any DIEs to represent any
20363 variable declarations or definitions. */
20364 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20367 /* Output any DIEs that are needed to specify the type of this data
20369 if (decl_by_reference_p (decl_or_origin
))
20370 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20372 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20374 /* And its containing type. */
20375 class_origin
= decl_class_context (decl_or_origin
);
20376 if (class_origin
!= NULL_TREE
)
20377 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20379 /* And its containing namespace. */
20380 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20382 /* Now output the DIE to represent the data object itself. This gets
20383 complicated because of the possibility that the VAR_DECL really
20384 represents an inlined instance of a formal parameter for an inline
20386 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20387 if (ultimate_origin
!= NULL_TREE
20388 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20389 gen_formal_parameter_die (decl
, origin
,
20390 true /* Emit name attribute. */,
20393 gen_variable_die (decl
, origin
, context_die
);
20397 /* Ignore the nameless fields that are used to skip bits but handle C++
20398 anonymous unions and structs. */
20399 if (DECL_NAME (decl
) != NULL_TREE
20400 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20401 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20403 gen_type_die (member_declared_type (decl
), context_die
);
20404 gen_field_die (decl
, context_die
);
20409 if (DECL_BY_REFERENCE (decl_or_origin
))
20410 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20412 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20413 return gen_formal_parameter_die (decl
, origin
,
20414 true /* Emit name attribute. */,
20417 case NAMESPACE_DECL
:
20418 case IMPORTED_DECL
:
20419 if (dwarf_version
>= 3 || !dwarf_strict
)
20420 gen_namespace_die (decl
, context_die
);
20424 /* Probably some frontend-internal decl. Assume we don't care. */
20425 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20432 /* Output debug information for global decl DECL. Called from toplev.c after
20433 compilation proper has finished. */
20436 dwarf2out_global_decl (tree decl
)
20438 /* Output DWARF2 information for file-scope tentative data object
20439 declarations, file-scope (extern) function declarations (which
20440 had no corresponding body) and file-scope tagged type declarations
20441 and definitions which have not yet been forced out. */
20442 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20443 dwarf2out_decl (decl
);
20446 /* Output debug information for type decl DECL. Called from toplev.c
20447 and from language front ends (to record built-in types). */
20449 dwarf2out_type_decl (tree decl
, int local
)
20452 dwarf2out_decl (decl
);
20455 /* Output debug information for imported module or decl DECL.
20456 NAME is non-NULL name in the lexical block if the decl has been renamed.
20457 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20458 that DECL belongs to.
20459 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20461 dwarf2out_imported_module_or_decl_1 (tree decl
,
20463 tree lexical_block
,
20464 dw_die_ref lexical_block_die
)
20466 expanded_location xloc
;
20467 dw_die_ref imported_die
= NULL
;
20468 dw_die_ref at_import_die
;
20470 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20472 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20473 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20477 xloc
= expand_location (input_location
);
20479 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20481 at_import_die
= force_type_die (TREE_TYPE (decl
));
20482 /* For namespace N { typedef void T; } using N::T; base_type_die
20483 returns NULL, but DW_TAG_imported_declaration requires
20484 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20485 if (!at_import_die
)
20487 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20488 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20489 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20490 gcc_assert (at_import_die
);
20495 at_import_die
= lookup_decl_die (decl
);
20496 if (!at_import_die
)
20498 /* If we're trying to avoid duplicate debug info, we may not have
20499 emitted the member decl for this field. Emit it now. */
20500 if (TREE_CODE (decl
) == FIELD_DECL
)
20502 tree type
= DECL_CONTEXT (decl
);
20504 if (TYPE_CONTEXT (type
)
20505 && TYPE_P (TYPE_CONTEXT (type
))
20506 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20507 DINFO_USAGE_DIR_USE
))
20509 gen_type_die_for_member (type
, decl
,
20510 get_context_die (TYPE_CONTEXT (type
)));
20512 at_import_die
= force_decl_die (decl
);
20516 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20518 if (dwarf_version
>= 3 || !dwarf_strict
)
20519 imported_die
= new_die (DW_TAG_imported_module
,
20526 imported_die
= new_die (DW_TAG_imported_declaration
,
20530 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20531 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20533 add_AT_string (imported_die
, DW_AT_name
,
20534 IDENTIFIER_POINTER (name
));
20535 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20538 /* Output debug information for imported module or decl DECL.
20539 NAME is non-NULL name in context if the decl has been renamed.
20540 CHILD is true if decl is one of the renamed decls as part of
20541 importing whole module. */
20544 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20547 /* dw_die_ref at_import_die; */
20548 dw_die_ref scope_die
;
20550 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20555 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20556 We need decl DIE for reference and scope die. First, get DIE for the decl
20559 /* Get the scope die for decl context. Use comp_unit_die for global module
20560 or decl. If die is not found for non globals, force new die. */
20562 && TYPE_P (context
)
20563 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20566 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20569 scope_die
= get_context_die (context
);
20573 gcc_assert (scope_die
->die_child
);
20574 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20575 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20576 scope_die
= scope_die
->die_child
;
20579 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20580 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20584 /* Write the debugging output for DECL. */
20587 dwarf2out_decl (tree decl
)
20589 dw_die_ref context_die
= comp_unit_die ();
20591 switch (TREE_CODE (decl
))
20596 case FUNCTION_DECL
:
20597 /* What we would really like to do here is to filter out all mere
20598 file-scope declarations of file-scope functions which are never
20599 referenced later within this translation unit (and keep all of ones
20600 that *are* referenced later on) but we aren't clairvoyant, so we have
20601 no idea which functions will be referenced in the future (i.e. later
20602 on within the current translation unit). So here we just ignore all
20603 file-scope function declarations which are not also definitions. If
20604 and when the debugger needs to know something about these functions,
20605 it will have to hunt around and find the DWARF information associated
20606 with the definition of the function.
20608 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20609 nodes represent definitions and which ones represent mere
20610 declarations. We have to check DECL_INITIAL instead. That's because
20611 the C front-end supports some weird semantics for "extern inline"
20612 function definitions. These can get inlined within the current
20613 translation unit (and thus, we need to generate Dwarf info for their
20614 abstract instances so that the Dwarf info for the concrete inlined
20615 instances can have something to refer to) but the compiler never
20616 generates any out-of-lines instances of such things (despite the fact
20617 that they *are* definitions).
20619 The important point is that the C front-end marks these "extern
20620 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20621 them anyway. Note that the C++ front-end also plays some similar games
20622 for inline function definitions appearing within include files which
20623 also contain `#pragma interface' pragmas.
20625 If we are called from dwarf2out_abstract_function output a DIE
20626 anyway. We can end up here this way with early inlining and LTO
20627 where the inlined function is output in a different LTRANS unit
20629 if (DECL_INITIAL (decl
) == NULL_TREE
20630 && ! DECL_ABSTRACT (decl
))
20633 /* If we're a nested function, initially use a parent of NULL; if we're
20634 a plain function, this will be fixed up in decls_for_scope. If
20635 we're a method, it will be ignored, since we already have a DIE. */
20636 if (decl_function_context (decl
)
20637 /* But if we're in terse mode, we don't care about scope. */
20638 && debug_info_level
> DINFO_LEVEL_TERSE
)
20639 context_die
= NULL
;
20643 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20644 declaration and if the declaration was never even referenced from
20645 within this entire compilation unit. We suppress these DIEs in
20646 order to save space in the .debug section (by eliminating entries
20647 which are probably useless). Note that we must not suppress
20648 block-local extern declarations (whether used or not) because that
20649 would screw-up the debugger's name lookup mechanism and cause it to
20650 miss things which really ought to be in scope at a given point. */
20651 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20654 /* For local statics lookup proper context die. */
20655 if (TREE_STATIC (decl
)
20656 && DECL_CONTEXT (decl
)
20657 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20658 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20660 /* If we are in terse mode, don't generate any DIEs to represent any
20661 variable declarations or definitions. */
20662 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20667 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20669 if (!is_fortran () && !is_ada ())
20671 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20672 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20675 case NAMESPACE_DECL
:
20676 case IMPORTED_DECL
:
20677 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20679 if (lookup_decl_die (decl
) != NULL
)
20684 /* Don't emit stubs for types unless they are needed by other DIEs. */
20685 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20688 /* Don't bother trying to generate any DIEs to represent any of the
20689 normal built-in types for the language we are compiling. */
20690 if (DECL_IS_BUILTIN (decl
))
20693 /* If we are in terse mode, don't generate any DIEs for types. */
20694 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20697 /* If we're a function-scope tag, initially use a parent of NULL;
20698 this will be fixed up in decls_for_scope. */
20699 if (decl_function_context (decl
))
20700 context_die
= NULL
;
20708 gen_decl_die (decl
, NULL
, context_die
);
20711 /* Write the debugging output for DECL. */
20714 dwarf2out_function_decl (tree decl
)
20716 dwarf2out_decl (decl
);
20717 call_arg_locations
= NULL
;
20718 call_arg_loc_last
= NULL
;
20719 call_site_count
= -1;
20720 tail_call_site_count
= -1;
20721 block_map
.release ();
20722 htab_empty (decl_loc_table
);
20723 htab_empty (cached_dw_loc_list_table
);
20726 /* Output a marker (i.e. a label) for the beginning of the generated code for
20727 a lexical block. */
20730 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20731 unsigned int blocknum
)
20733 switch_to_section (current_function_section ());
20734 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20737 /* Output a marker (i.e. a label) for the end of the generated code for a
20741 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20743 switch_to_section (current_function_section ());
20744 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20747 /* Returns nonzero if it is appropriate not to emit any debugging
20748 information for BLOCK, because it doesn't contain any instructions.
20750 Don't allow this for blocks with nested functions or local classes
20751 as we would end up with orphans, and in the presence of scheduling
20752 we may end up calling them anyway. */
20755 dwarf2out_ignore_block (const_tree block
)
20760 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20761 if (TREE_CODE (decl
) == FUNCTION_DECL
20762 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20764 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20766 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20767 if (TREE_CODE (decl
) == FUNCTION_DECL
20768 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20775 /* Hash table routines for file_hash. */
20778 file_table_eq (const void *p1_p
, const void *p2_p
)
20780 const struct dwarf_file_data
*const p1
=
20781 (const struct dwarf_file_data
*) p1_p
;
20782 const char *const p2
= (const char *) p2_p
;
20783 return filename_cmp (p1
->filename
, p2
) == 0;
20787 file_table_hash (const void *p_p
)
20789 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20790 return htab_hash_string (p
->filename
);
20793 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20794 dwarf2out.c) and return its "index". The index of each (known) filename is
20795 just a unique number which is associated with only that one filename. We
20796 need such numbers for the sake of generating labels (in the .debug_sfnames
20797 section) and references to those files numbers (in the .debug_srcinfo
20798 and.debug_macinfo sections). If the filename given as an argument is not
20799 found in our current list, add it to the list and assign it the next
20800 available unique index number. In order to speed up searches, we remember
20801 the index of the filename was looked up last. This handles the majority of
20804 static struct dwarf_file_data
*
20805 lookup_filename (const char *file_name
)
20808 struct dwarf_file_data
* created
;
20810 /* Check to see if the file name that was searched on the previous
20811 call matches this file name. If so, return the index. */
20812 if (file_table_last_lookup
20813 && (file_name
== file_table_last_lookup
->filename
20814 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20815 return file_table_last_lookup
;
20817 /* Didn't match the previous lookup, search the table. */
20818 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20819 htab_hash_string (file_name
), INSERT
);
20821 return (struct dwarf_file_data
*) *slot
;
20823 created
= ggc_alloc_dwarf_file_data ();
20824 created
->filename
= file_name
;
20825 created
->emitted_number
= 0;
20830 /* If the assembler will construct the file table, then translate the compiler
20831 internal file table number into the assembler file table number, and emit
20832 a .file directive if we haven't already emitted one yet. The file table
20833 numbers are different because we prune debug info for unused variables and
20834 types, which may include filenames. */
20837 maybe_emit_file (struct dwarf_file_data
* fd
)
20839 if (! fd
->emitted_number
)
20841 if (last_emitted_file
)
20842 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20844 fd
->emitted_number
= 1;
20845 last_emitted_file
= fd
;
20847 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20849 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20850 output_quoted_string (asm_out_file
,
20851 remap_debug_filename (fd
->filename
));
20852 fputc ('\n', asm_out_file
);
20856 return fd
->emitted_number
;
20859 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20860 That generation should happen after function debug info has been
20861 generated. The value of the attribute is the constant value of ARG. */
20864 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20866 die_arg_entry entry
;
20871 if (!tmpl_value_parm_die_table
)
20872 vec_alloc (tmpl_value_parm_die_table
, 32);
20876 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20879 /* Return TRUE if T is an instance of generic type, FALSE
20883 generic_type_p (tree t
)
20885 if (t
== NULL_TREE
|| !TYPE_P (t
))
20887 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20890 /* Schedule the generation of the generic parameter dies for the
20891 instance of generic type T. The proper generation itself is later
20892 done by gen_scheduled_generic_parms_dies. */
20895 schedule_generic_params_dies_gen (tree t
)
20897 if (!generic_type_p (t
))
20900 if (!generic_type_instances
)
20901 vec_alloc (generic_type_instances
, 256);
20903 vec_safe_push (generic_type_instances
, t
);
20906 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20907 by append_entry_to_tmpl_value_parm_die_table. This function must
20908 be called after function DIEs have been generated. */
20911 gen_remaining_tmpl_value_param_die_attribute (void)
20913 if (tmpl_value_parm_die_table
)
20918 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20919 tree_add_const_value_attribute (e
->die
, e
->arg
);
20923 /* Generate generic parameters DIEs for instances of generic types
20924 that have been previously scheduled by
20925 schedule_generic_params_dies_gen. This function must be called
20926 after all the types of the CU have been laid out. */
20929 gen_scheduled_generic_parms_dies (void)
20934 if (!generic_type_instances
)
20937 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20938 if (COMPLETE_TYPE_P (t
))
20939 gen_generic_params_dies (t
);
20943 /* Replace DW_AT_name for the decl with name. */
20946 dwarf2out_set_name (tree decl
, tree name
)
20952 die
= TYPE_SYMTAB_DIE (decl
);
20956 dname
= dwarf2_name (name
, 0);
20960 attr
= get_AT (die
, DW_AT_name
);
20963 struct indirect_string_node
*node
;
20965 node
= find_AT_string (dname
);
20966 /* replace the string. */
20967 attr
->dw_attr_val
.v
.val_str
= node
;
20971 add_name_attribute (die
, dname
);
20974 /* True if before or during processing of the first function being emitted. */
20975 static bool in_first_function_p
= true;
20976 /* True if loc_note during dwarf2out_var_location call might still be
20977 before first real instruction at address equal to .Ltext0. */
20978 static bool maybe_at_text_label_p
= true;
20979 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
20980 static unsigned int first_loclabel_num_not_at_text_label
;
20982 /* Called by the final INSN scan whenever we see a var location. We
20983 use it to drop labels in the right places, and throw the location in
20984 our lookup table. */
20987 dwarf2out_var_location (rtx loc_note
)
20989 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20990 struct var_loc_node
*newloc
;
20991 rtx next_real
, next_note
;
20992 static const char *last_label
;
20993 static const char *last_postcall_label
;
20994 static bool last_in_cold_section_p
;
20995 static rtx expected_next_loc_note
;
20999 if (!NOTE_P (loc_note
))
21001 if (CALL_P (loc_note
))
21004 if (SIBLING_CALL_P (loc_note
))
21005 tail_call_site_count
++;
21010 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
21011 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21014 /* Optimize processing a large consecutive sequence of location
21015 notes so we don't spend too much time in next_real_insn. If the
21016 next insn is another location note, remember the next_real_insn
21017 calculation for next time. */
21018 next_real
= cached_next_real_insn
;
21021 if (expected_next_loc_note
!= loc_note
)
21022 next_real
= NULL_RTX
;
21025 next_note
= NEXT_INSN (loc_note
);
21027 || INSN_DELETED_P (next_note
)
21028 || ! NOTE_P (next_note
)
21029 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
21030 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
21031 next_note
= NULL_RTX
;
21034 next_real
= next_real_insn (loc_note
);
21038 expected_next_loc_note
= next_note
;
21039 cached_next_real_insn
= next_real
;
21042 cached_next_real_insn
= NULL_RTX
;
21044 /* If there are no instructions which would be affected by this note,
21045 don't do anything. */
21047 && next_real
== NULL_RTX
21048 && !NOTE_DURING_CALL_P (loc_note
))
21051 if (next_real
== NULL_RTX
)
21052 next_real
= get_last_insn ();
21054 /* If there were any real insns between note we processed last time
21055 and this note (or if it is the first note), clear
21056 last_{,postcall_}label so that they are not reused this time. */
21057 if (last_var_location_insn
== NULL_RTX
21058 || last_var_location_insn
!= next_real
21059 || last_in_cold_section_p
!= in_cold_section_p
)
21062 last_postcall_label
= NULL
;
21067 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21068 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21069 NOTE_DURING_CALL_P (loc_note
)
21070 ? last_postcall_label
: last_label
);
21071 if (newloc
== NULL
)
21080 /* If there were no real insns between note we processed last time
21081 and this note, use the label we emitted last time. Otherwise
21082 create a new label and emit it. */
21083 if (last_label
== NULL
)
21085 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21086 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21088 last_label
= ggc_strdup (loclabel
);
21089 /* See if loclabel might be equal to .Ltext0. If yes,
21090 bump first_loclabel_num_not_at_text_label. */
21091 if (!have_multiple_function_sections
21092 && in_first_function_p
21093 && maybe_at_text_label_p
)
21095 static rtx last_start
;
21097 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
21098 if (insn
== last_start
)
21100 else if (!NONDEBUG_INSN_P (insn
))
21104 rtx body
= PATTERN (insn
);
21105 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
21107 /* Inline asm could occupy zero bytes. */
21108 else if (GET_CODE (body
) == ASM_INPUT
21109 || asm_noperands (body
) >= 0)
21111 #ifdef HAVE_attr_length
21112 else if (get_attr_min_length (insn
) == 0)
21117 /* Assume insn has non-zero length. */
21118 maybe_at_text_label_p
= false;
21122 if (maybe_at_text_label_p
)
21124 last_start
= loc_note
;
21125 first_loclabel_num_not_at_text_label
= loclabel_num
;
21132 struct call_arg_loc_node
*ca_loc
21133 = ggc_alloc_cleared_call_arg_loc_node ();
21134 rtx prev
= prev_real_insn (loc_note
), x
;
21135 ca_loc
->call_arg_loc_note
= loc_note
;
21136 ca_loc
->next
= NULL
;
21137 ca_loc
->label
= last_label
;
21140 || (NONJUMP_INSN_P (prev
)
21141 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21142 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21143 if (!CALL_P (prev
))
21144 prev
= XVECEXP (PATTERN (prev
), 0, 0);
21145 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
21146 x
= get_call_rtx_from (PATTERN (prev
));
21149 x
= XEXP (XEXP (x
, 0), 0);
21150 if (GET_CODE (x
) == SYMBOL_REF
21151 && SYMBOL_REF_DECL (x
)
21152 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21153 ca_loc
->symbol_ref
= x
;
21155 ca_loc
->block
= insn_scope (prev
);
21156 if (call_arg_locations
)
21157 call_arg_loc_last
->next
= ca_loc
;
21159 call_arg_locations
= ca_loc
;
21160 call_arg_loc_last
= ca_loc
;
21162 else if (!NOTE_DURING_CALL_P (loc_note
))
21163 newloc
->label
= last_label
;
21166 if (!last_postcall_label
)
21168 sprintf (loclabel
, "%s-1", last_label
);
21169 last_postcall_label
= ggc_strdup (loclabel
);
21171 newloc
->label
= last_postcall_label
;
21174 last_var_location_insn
= next_real
;
21175 last_in_cold_section_p
= in_cold_section_p
;
21178 /* Note in one location list that text section has changed. */
21181 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
21183 var_loc_list
*list
= (var_loc_list
*) *slot
;
21185 list
->last_before_switch
21186 = list
->last
->next
? list
->last
->next
: list
->last
;
21190 /* Note in all location lists that text section has changed. */
21193 var_location_switch_text_section (void)
21195 if (decl_loc_table
== NULL
)
21198 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
21201 /* Create a new line number table. */
21203 static dw_line_info_table
*
21204 new_line_info_table (void)
21206 dw_line_info_table
*table
;
21208 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
21209 table
->file_num
= 1;
21210 table
->line_num
= 1;
21211 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21216 /* Lookup the "current" table into which we emit line info, so
21217 that we don't have to do it for every source line. */
21220 set_cur_line_info_table (section
*sec
)
21222 dw_line_info_table
*table
;
21224 if (sec
== text_section
)
21225 table
= text_section_line_info
;
21226 else if (sec
== cold_text_section
)
21228 table
= cold_text_section_line_info
;
21231 cold_text_section_line_info
= table
= new_line_info_table ();
21232 table
->end_label
= cold_end_label
;
21237 const char *end_label
;
21239 if (flag_reorder_blocks_and_partition
)
21241 if (in_cold_section_p
)
21242 end_label
= crtl
->subsections
.cold_section_end_label
;
21244 end_label
= crtl
->subsections
.hot_section_end_label
;
21248 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21249 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21250 current_function_funcdef_no
);
21251 end_label
= ggc_strdup (label
);
21254 table
= new_line_info_table ();
21255 table
->end_label
= end_label
;
21257 vec_safe_push (separate_line_info
, table
);
21260 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21261 table
->is_stmt
= (cur_line_info_table
21262 ? cur_line_info_table
->is_stmt
21263 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21264 cur_line_info_table
= table
;
21268 /* We need to reset the locations at the beginning of each
21269 function. We can't do this in the end_function hook, because the
21270 declarations that use the locations won't have been output when
21271 that hook is called. Also compute have_multiple_function_sections here. */
21274 dwarf2out_begin_function (tree fun
)
21276 section
*sec
= function_section (fun
);
21278 if (sec
!= text_section
)
21279 have_multiple_function_sections
= true;
21281 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21283 gcc_assert (current_function_decl
== fun
);
21284 cold_text_section
= unlikely_text_section ();
21285 switch_to_section (cold_text_section
);
21286 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21287 switch_to_section (sec
);
21290 dwarf2out_note_section_used ();
21291 call_site_count
= 0;
21292 tail_call_site_count
= 0;
21294 set_cur_line_info_table (sec
);
21297 /* Helper function of dwarf2out_end_function, called only after emitting
21298 the very first function into assembly. Check if some .debug_loc range
21299 might end with a .LVL* label that could be equal to .Ltext0.
21300 In that case we must force using absolute addresses in .debug_loc ranges,
21301 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21302 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21304 Set have_multiple_function_sections to true in that case and
21305 terminate htab traversal. */
21308 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21310 var_loc_list
*entry
;
21311 struct var_loc_node
*node
;
21313 entry
= (var_loc_list
*) *slot
;
21314 node
= entry
->first
;
21315 if (node
&& node
->next
&& node
->next
->label
)
21318 const char *label
= node
->next
->label
;
21319 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21321 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21323 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21324 if (strcmp (label
, loclabel
) == 0)
21326 have_multiple_function_sections
= true;
21334 /* Hook called after emitting a function into assembly.
21335 This does something only for the very first function emitted. */
21338 dwarf2out_end_function (unsigned int)
21340 if (in_first_function_p
21341 && !have_multiple_function_sections
21342 && first_loclabel_num_not_at_text_label
21344 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21346 in_first_function_p
= false;
21347 maybe_at_text_label_p
= false;
21350 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21353 push_dw_line_info_entry (dw_line_info_table
*table
,
21354 enum dw_line_info_opcode opcode
, unsigned int val
)
21356 dw_line_info_entry e
;
21359 vec_safe_push (table
->entries
, e
);
21362 /* Output a label to mark the beginning of a source code line entry
21363 and record information relating to this source line, in
21364 'line_info_table' for later output of the .debug_line section. */
21365 /* ??? The discriminator parameter ought to be unsigned. */
21368 dwarf2out_source_line (unsigned int line
, const char *filename
,
21369 int discriminator
, bool is_stmt
)
21371 unsigned int file_num
;
21372 dw_line_info_table
*table
;
21374 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
21377 /* The discriminator column was added in dwarf4. Simplify the below
21378 by simply removing it if we're not supposed to output it. */
21379 if (dwarf_version
< 4 && dwarf_strict
)
21382 table
= cur_line_info_table
;
21383 file_num
= maybe_emit_file (lookup_filename (filename
));
21385 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21386 the debugger has used the second (possibly duplicate) line number
21387 at the beginning of the function to mark the end of the prologue.
21388 We could eliminate any other duplicates within the function. For
21389 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21390 that second line number entry. */
21391 /* Recall that this end-of-prologue indication is *not* the same thing
21392 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21393 to which the hook corresponds, follows the last insn that was
21394 emitted by gen_prologue. What we need is to precede the first insn
21395 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21396 insn that corresponds to something the user wrote. These may be
21397 very different locations once scheduling is enabled. */
21399 if (0 && file_num
== table
->file_num
21400 && line
== table
->line_num
21401 && discriminator
== table
->discrim_num
21402 && is_stmt
== table
->is_stmt
)
21405 switch_to_section (current_function_section ());
21407 /* If requested, emit something human-readable. */
21408 if (flag_debug_asm
)
21409 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21411 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21413 /* Emit the .loc directive understood by GNU as. */
21414 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21415 file_num, line, is_stmt, discriminator */
21416 fputs ("\t.loc ", asm_out_file
);
21417 fprint_ul (asm_out_file
, file_num
);
21418 putc (' ', asm_out_file
);
21419 fprint_ul (asm_out_file
, line
);
21420 putc (' ', asm_out_file
);
21421 putc ('0', asm_out_file
);
21423 if (is_stmt
!= table
->is_stmt
)
21425 fputs (" is_stmt ", asm_out_file
);
21426 putc (is_stmt
? '1' : '0', asm_out_file
);
21428 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21430 gcc_assert (discriminator
> 0);
21431 fputs (" discriminator ", asm_out_file
);
21432 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21434 putc ('\n', asm_out_file
);
21438 unsigned int label_num
= ++line_info_label_num
;
21440 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21442 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21443 if (file_num
!= table
->file_num
)
21444 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21445 if (discriminator
!= table
->discrim_num
)
21446 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21447 if (is_stmt
!= table
->is_stmt
)
21448 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21449 push_dw_line_info_entry (table
, LI_set_line
, line
);
21452 table
->file_num
= file_num
;
21453 table
->line_num
= line
;
21454 table
->discrim_num
= discriminator
;
21455 table
->is_stmt
= is_stmt
;
21456 table
->in_use
= true;
21459 /* Record the beginning of a new source file. */
21462 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21464 if (flag_eliminate_dwarf2_dups
)
21466 /* Record the beginning of the file for break_out_includes. */
21467 dw_die_ref bincl_die
;
21469 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21470 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21473 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21476 e
.code
= DW_MACINFO_start_file
;
21478 e
.info
= ggc_strdup (filename
);
21479 vec_safe_push (macinfo_table
, e
);
21483 /* Record the end of a source file. */
21486 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21488 if (flag_eliminate_dwarf2_dups
)
21489 /* Record the end of the file for break_out_includes. */
21490 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21492 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21495 e
.code
= DW_MACINFO_end_file
;
21498 vec_safe_push (macinfo_table
, e
);
21502 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21503 the tail part of the directive line, i.e. the part which is past the
21504 initial whitespace, #, whitespace, directive-name, whitespace part. */
21507 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21508 const char *buffer ATTRIBUTE_UNUSED
)
21510 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21513 /* Insert a dummy first entry to be able to optimize the whole
21514 predefined macro block using DW_MACRO_GNU_transparent_include. */
21515 if (macinfo_table
->is_empty () && lineno
<= 1)
21520 vec_safe_push (macinfo_table
, e
);
21522 e
.code
= DW_MACINFO_define
;
21524 e
.info
= ggc_strdup (buffer
);
21525 vec_safe_push (macinfo_table
, e
);
21529 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21530 the tail part of the directive line, i.e. the part which is past the
21531 initial whitespace, #, whitespace, directive-name, whitespace part. */
21534 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21535 const char *buffer ATTRIBUTE_UNUSED
)
21537 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21540 /* Insert a dummy first entry to be able to optimize the whole
21541 predefined macro block using DW_MACRO_GNU_transparent_include. */
21542 if (macinfo_table
->is_empty () && lineno
<= 1)
21547 vec_safe_push (macinfo_table
, e
);
21549 e
.code
= DW_MACINFO_undef
;
21551 e
.info
= ggc_strdup (buffer
);
21552 vec_safe_push (macinfo_table
, e
);
21556 /* Helpers to manipulate hash table of CUs. */
21558 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
21560 typedef macinfo_entry value_type
;
21561 typedef macinfo_entry compare_type
;
21562 static inline hashval_t
hash (const value_type
*);
21563 static inline bool equal (const value_type
*, const compare_type
*);
21567 macinfo_entry_hasher::hash (const value_type
*entry
)
21569 return htab_hash_string (entry
->info
);
21573 macinfo_entry_hasher::equal (const value_type
*entry1
,
21574 const compare_type
*entry2
)
21576 return !strcmp (entry1
->info
, entry2
->info
);
21579 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
21581 /* Output a single .debug_macinfo entry. */
21584 output_macinfo_op (macinfo_entry
*ref
)
21588 struct indirect_string_node
*node
;
21589 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21590 struct dwarf_file_data
*fd
;
21594 case DW_MACINFO_start_file
:
21595 fd
= lookup_filename (ref
->info
);
21596 file_num
= maybe_emit_file (fd
);
21597 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21598 dw2_asm_output_data_uleb128 (ref
->lineno
,
21599 "Included from line number %lu",
21600 (unsigned long) ref
->lineno
);
21601 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21603 case DW_MACINFO_end_file
:
21604 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21606 case DW_MACINFO_define
:
21607 case DW_MACINFO_undef
:
21608 len
= strlen (ref
->info
) + 1;
21610 && len
> DWARF_OFFSET_SIZE
21611 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21612 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21614 ref
->code
= ref
->code
== DW_MACINFO_define
21615 ? DW_MACRO_GNU_define_indirect
21616 : DW_MACRO_GNU_undef_indirect
;
21617 output_macinfo_op (ref
);
21620 dw2_asm_output_data (1, ref
->code
,
21621 ref
->code
== DW_MACINFO_define
21622 ? "Define macro" : "Undefine macro");
21623 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21624 (unsigned long) ref
->lineno
);
21625 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21627 case DW_MACRO_GNU_define_indirect
:
21628 case DW_MACRO_GNU_undef_indirect
:
21629 node
= find_AT_string (ref
->info
);
21631 && ((node
->form
== DW_FORM_strp
)
21632 || (node
->form
== DW_FORM_GNU_str_index
)));
21633 dw2_asm_output_data (1, ref
->code
,
21634 ref
->code
== DW_MACRO_GNU_define_indirect
21635 ? "Define macro indirect"
21636 : "Undefine macro indirect");
21637 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21638 (unsigned long) ref
->lineno
);
21639 if (node
->form
== DW_FORM_strp
)
21640 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21641 debug_str_section
, "The macro: \"%s\"",
21644 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21647 case DW_MACRO_GNU_transparent_include
:
21648 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21649 ASM_GENERATE_INTERNAL_LABEL (label
,
21650 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21651 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21654 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21655 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21660 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21661 other compilation unit .debug_macinfo sections. IDX is the first
21662 index of a define/undef, return the number of ops that should be
21663 emitted in a comdat .debug_macinfo section and emit
21664 a DW_MACRO_GNU_transparent_include entry referencing it.
21665 If the define/undef entry should be emitted normally, return 0. */
21668 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21669 macinfo_hash_type
*macinfo_htab
)
21671 macinfo_entry
*first
, *second
, *cur
, *inc
;
21672 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21673 unsigned char checksum
[16];
21674 struct md5_ctx ctx
;
21675 char *grp_name
, *tail
;
21677 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21678 macinfo_entry
**slot
;
21680 first
= &(*macinfo_table
)[idx
];
21681 second
= &(*macinfo_table
)[idx
+ 1];
21683 /* Optimize only if there are at least two consecutive define/undef ops,
21684 and either all of them are before first DW_MACINFO_start_file
21685 with lineno {0,1} (i.e. predefined macro block), or all of them are
21686 in some included header file. */
21687 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21689 if (vec_safe_is_empty (files
))
21691 if (first
->lineno
> 1 || second
->lineno
> 1)
21694 else if (first
->lineno
== 0)
21697 /* Find the last define/undef entry that can be grouped together
21698 with first and at the same time compute md5 checksum of their
21699 codes, linenumbers and strings. */
21700 md5_init_ctx (&ctx
);
21701 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21702 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21704 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21708 unsigned char code
= cur
->code
;
21709 md5_process_bytes (&code
, 1, &ctx
);
21710 checksum_uleb128 (cur
->lineno
, &ctx
);
21711 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21713 md5_finish_ctx (&ctx
, checksum
);
21716 /* From the containing include filename (if any) pick up just
21717 usable characters from its basename. */
21718 if (vec_safe_is_empty (files
))
21721 base
= lbasename (files
->last ().info
);
21722 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21723 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21724 encoded_filename_len
++;
21725 /* Count . at the end. */
21726 if (encoded_filename_len
)
21727 encoded_filename_len
++;
21729 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21730 linebuf_len
= strlen (linebuf
);
21732 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21733 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21735 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21736 tail
= grp_name
+ 4;
21737 if (encoded_filename_len
)
21739 for (i
= 0; base
[i
]; i
++)
21740 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21744 memcpy (tail
, linebuf
, linebuf_len
);
21745 tail
+= linebuf_len
;
21747 for (i
= 0; i
< 16; i
++)
21748 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21750 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21751 in the empty vector entry before the first define/undef. */
21752 inc
= &(*macinfo_table
)[idx
- 1];
21753 inc
->code
= DW_MACRO_GNU_transparent_include
;
21755 inc
->info
= ggc_strdup (grp_name
);
21756 if (!macinfo_htab
->is_created ())
21757 macinfo_htab
->create (10);
21758 /* Avoid emitting duplicates. */
21759 slot
= macinfo_htab
->find_slot (inc
, INSERT
);
21764 /* If such an entry has been used before, just emit
21765 a DW_MACRO_GNU_transparent_include op. */
21767 output_macinfo_op (inc
);
21768 /* And clear all macinfo_entry in the range to avoid emitting them
21769 in the second pass. */
21770 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21779 inc
->lineno
= macinfo_htab
->elements ();
21780 output_macinfo_op (inc
);
21785 /* Save any strings needed by the macinfo table in the debug str
21786 table. All strings must be collected into the table by the time
21787 index_string is called. */
21790 save_macinfo_strings (void)
21794 macinfo_entry
*ref
;
21796 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21800 /* Match the logic in output_macinfo_op to decide on
21801 indirect strings. */
21802 case DW_MACINFO_define
:
21803 case DW_MACINFO_undef
:
21804 len
= strlen (ref
->info
) + 1;
21806 && len
> DWARF_OFFSET_SIZE
21807 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21808 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21809 set_indirect_string (find_AT_string (ref
->info
));
21811 case DW_MACRO_GNU_define_indirect
:
21812 case DW_MACRO_GNU_undef_indirect
:
21813 set_indirect_string (find_AT_string (ref
->info
));
21821 /* Output macinfo section(s). */
21824 output_macinfo (void)
21827 unsigned long length
= vec_safe_length (macinfo_table
);
21828 macinfo_entry
*ref
;
21829 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21830 macinfo_hash_type macinfo_htab
;
21835 /* output_macinfo* uses these interchangeably. */
21836 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21837 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21838 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21839 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21841 /* For .debug_macro emit the section header. */
21844 dw2_asm_output_data (2, 4, "DWARF macro version number");
21845 if (DWARF_OFFSET_SIZE
== 8)
21846 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21848 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21849 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21850 (!dwarf_split_debug_info
? debug_line_section_label
21851 : debug_skeleton_line_section_label
),
21852 debug_line_section
, NULL
);
21855 /* In the first loop, it emits the primary .debug_macinfo section
21856 and after each emitted op the macinfo_entry is cleared.
21857 If a longer range of define/undef ops can be optimized using
21858 DW_MACRO_GNU_transparent_include, the
21859 DW_MACRO_GNU_transparent_include op is emitted and kept in
21860 the vector before the first define/undef in the range and the
21861 whole range of define/undef ops is not emitted and kept. */
21862 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21866 case DW_MACINFO_start_file
:
21867 vec_safe_push (files
, *ref
);
21869 case DW_MACINFO_end_file
:
21870 if (!vec_safe_is_empty (files
))
21873 case DW_MACINFO_define
:
21874 case DW_MACINFO_undef
:
21876 && HAVE_COMDAT_GROUP
21877 && vec_safe_length (files
) != 1
21880 && (*macinfo_table
)[i
- 1].code
== 0)
21882 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21891 /* A dummy entry may be inserted at the beginning to be able
21892 to optimize the whole block of predefined macros. */
21898 output_macinfo_op (ref
);
21903 if (!macinfo_htab
.is_created ())
21906 macinfo_htab
.dispose ();
21908 /* If any DW_MACRO_GNU_transparent_include were used, on those
21909 DW_MACRO_GNU_transparent_include entries terminate the
21910 current chain and switch to a new comdat .debug_macinfo
21911 section and emit the define/undef entries within it. */
21912 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21917 case DW_MACRO_GNU_transparent_include
:
21919 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21920 tree comdat_key
= get_identifier (ref
->info
);
21921 /* Terminate the previous .debug_macinfo section. */
21922 dw2_asm_output_data (1, 0, "End compilation unit");
21923 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21925 | SECTION_LINKONCE
,
21927 ASM_GENERATE_INTERNAL_LABEL (label
,
21928 DEBUG_MACRO_SECTION_LABEL
,
21930 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21933 dw2_asm_output_data (2, 4, "DWARF macro version number");
21934 if (DWARF_OFFSET_SIZE
== 8)
21935 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21937 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21940 case DW_MACINFO_define
:
21941 case DW_MACINFO_undef
:
21942 output_macinfo_op (ref
);
21947 gcc_unreachable ();
21951 /* Set up for Dwarf output at the start of compilation. */
21954 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21956 /* Allocate the file_table. */
21957 file_table
= htab_create_ggc (50, file_table_hash
,
21958 file_table_eq
, NULL
);
21960 /* Allocate the decl_die_table. */
21961 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21962 decl_die_table_eq
, NULL
);
21964 /* Allocate the decl_loc_table. */
21965 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21966 decl_loc_table_eq
, NULL
);
21968 /* Allocate the cached_dw_loc_list_table. */
21969 cached_dw_loc_list_table
21970 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21971 cached_dw_loc_list_table_eq
, NULL
);
21973 /* Allocate the initial hunk of the decl_scope_table. */
21974 vec_alloc (decl_scope_table
, 256);
21976 /* Allocate the initial hunk of the abbrev_die_table. */
21977 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21978 (ABBREV_DIE_TABLE_INCREMENT
);
21979 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21980 /* Zero-th entry is allocated, but unused. */
21981 abbrev_die_table_in_use
= 1;
21983 /* Allocate the pubtypes and pubnames vectors. */
21984 vec_alloc (pubname_table
, 32);
21985 vec_alloc (pubtype_table
, 32);
21987 vec_alloc (incomplete_types
, 64);
21989 vec_alloc (used_rtx_array
, 32);
21991 if (!dwarf_split_debug_info
)
21993 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21994 SECTION_DEBUG
, NULL
);
21995 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21996 SECTION_DEBUG
, NULL
);
21997 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21998 SECTION_DEBUG
, NULL
);
22002 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
22003 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22004 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
22005 SECTION_DEBUG
| SECTION_EXCLUDE
,
22007 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
22008 SECTION_DEBUG
, NULL
);
22009 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
22010 SECTION_DEBUG
, NULL
);
22011 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22012 SECTION_DEBUG
, NULL
);
22013 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
22014 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
22016 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
22017 the main .o, but the skeleton_line goes into the split off dwo. */
22018 debug_skeleton_line_section
22019 = get_section (DEBUG_DWO_LINE_SECTION
,
22020 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22021 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
22022 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
22023 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
22024 SECTION_DEBUG
| SECTION_EXCLUDE
,
22026 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
22027 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
22028 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
22029 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22030 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
22031 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
22033 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
22034 SECTION_DEBUG
, NULL
);
22035 debug_macinfo_section
= get_section (dwarf_strict
22036 ? DEBUG_MACINFO_SECTION
22037 : DEBUG_MACRO_SECTION
,
22038 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
22039 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
22040 SECTION_DEBUG
, NULL
);
22041 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
22042 SECTION_DEBUG
, NULL
);
22043 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
22044 SECTION_DEBUG
, NULL
);
22045 debug_str_section
= get_section (DEBUG_STR_SECTION
,
22046 DEBUG_STR_SECTION_FLAGS
, NULL
);
22047 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
22048 SECTION_DEBUG
, NULL
);
22049 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
22050 SECTION_DEBUG
, NULL
);
22052 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
22053 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
22054 DEBUG_ABBREV_SECTION_LABEL
, 0);
22055 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
22056 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
22057 COLD_TEXT_SECTION_LABEL
, 0);
22058 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
22060 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
22061 DEBUG_INFO_SECTION_LABEL
, 0);
22062 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
22063 DEBUG_LINE_SECTION_LABEL
, 0);
22064 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
22065 DEBUG_RANGES_SECTION_LABEL
, 0);
22066 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
22067 DEBUG_ADDR_SECTION_LABEL
, 0);
22068 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
22070 ? DEBUG_MACINFO_SECTION_LABEL
22071 : DEBUG_MACRO_SECTION_LABEL
, 0);
22072 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
22074 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22075 vec_alloc (macinfo_table
, 64);
22077 switch_to_section (text_section
);
22078 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
22080 /* Make sure the line number table for .text always exists. */
22081 text_section_line_info
= new_line_info_table ();
22082 text_section_line_info
->end_label
= text_end_label
;
22085 /* Called before compile () starts outputtting functions, variables
22086 and toplevel asms into assembly. */
22089 dwarf2out_assembly_start (void)
22091 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22092 && dwarf2out_do_cfi_asm ()
22093 && (!(flag_unwind_tables
|| flag_exceptions
)
22094 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
22095 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
22098 /* A helper function for dwarf2out_finish called through
22099 htab_traverse. Assign a string its index. All strings must be
22100 collected into the table by the time index_string is called,
22101 because the indexing code relies on htab_traverse to traverse nodes
22102 in the same order for each run. */
22105 index_string (void **h
, void *v
)
22107 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22108 unsigned int *index
= (unsigned int *) v
;
22110 find_string_form (node
);
22111 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22113 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
22114 node
->index
= *index
;
22120 /* A helper function for output_indirect_strings called through
22121 htab_traverse. Output the offset to a string and update the
22125 output_index_string_offset (void **h
, void *v
)
22127 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22128 unsigned int *offset
= (unsigned int *) v
;
22130 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22132 /* Assert that this node has been assigned an index. */
22133 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
22134 && node
->index
!= NOT_INDEXED
);
22135 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
22136 "indexed string 0x%x: %s", node
->index
, node
->str
);
22137 *offset
+= strlen (node
->str
) + 1;
22142 /* A helper function for dwarf2out_finish called through
22143 htab_traverse. Output the indexed string. */
22146 output_index_string (void **h
, void *v
)
22148 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22149 unsigned int *cur_idx
= (unsigned int *) v
;
22151 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22153 /* Assert that the strings are output in the same order as their
22154 indexes were assigned. */
22155 gcc_assert (*cur_idx
== node
->index
);
22156 assemble_string (node
->str
, strlen (node
->str
) + 1);
22162 /* A helper function for dwarf2out_finish called through
22163 htab_traverse. Emit one queued .debug_str string. */
22166 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22168 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22170 node
->form
= find_string_form (node
);
22171 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22173 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22174 assemble_string (node
->str
, strlen (node
->str
) + 1);
22180 /* Output the indexed string table. */
22183 output_indirect_strings (void)
22185 switch_to_section (debug_str_section
);
22186 if (!dwarf_split_debug_info
)
22187 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22190 unsigned int offset
= 0;
22191 unsigned int cur_idx
= 0;
22193 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
22195 switch_to_section (debug_str_offsets_section
);
22196 htab_traverse_noresize (debug_str_hash
,
22197 output_index_string_offset
,
22199 switch_to_section (debug_str_dwo_section
);
22200 htab_traverse_noresize (debug_str_hash
,
22201 output_index_string
,
22206 /* Callback for htab_traverse to assign an index to an entry in the
22207 table, and to write that entry to the .debug_addr section. */
22210 output_addr_table_entry (void **slot
, void *data
)
22212 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22213 unsigned int *cur_index
= (unsigned int *)data
;
22215 if (entry
->refcount
== 0)
22217 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22218 || entry
->index
== NOT_INDEXED
);
22222 gcc_assert (entry
->index
== *cur_index
);
22225 switch (entry
->kind
)
22228 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22229 "0x%x", entry
->index
);
22231 case ate_kind_rtx_dtprel
:
22232 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22233 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22236 fputc ('\n', asm_out_file
);
22238 case ate_kind_label
:
22239 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22240 "0x%x", entry
->index
);
22243 gcc_unreachable ();
22248 /* Produce the .debug_addr section. */
22251 output_addr_table (void)
22253 unsigned int index
= 0;
22254 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22257 switch_to_section (debug_addr_section
);
22258 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22261 #if ENABLE_ASSERT_CHECKING
22262 /* Verify that all marks are clear. */
22265 verify_marks_clear (dw_die_ref die
)
22269 gcc_assert (! die
->die_mark
);
22270 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22272 #endif /* ENABLE_ASSERT_CHECKING */
22274 /* Clear the marks for a die and its children.
22275 Be cool if the mark isn't set. */
22278 prune_unmark_dies (dw_die_ref die
)
22284 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22287 /* Given DIE that we're marking as used, find any other dies
22288 it references as attributes and mark them as used. */
22291 prune_unused_types_walk_attribs (dw_die_ref die
)
22296 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22298 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22300 /* A reference to another DIE.
22301 Make sure that it will get emitted.
22302 If it was broken out into a comdat group, don't follow it. */
22303 if (! AT_ref (a
)->comdat_type_p
22304 || a
->dw_attr
== DW_AT_specification
)
22305 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22307 /* Set the string's refcount to 0 so that prune_unused_types_mark
22308 accounts properly for it. */
22309 if (AT_class (a
) == dw_val_class_str
)
22310 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22314 /* Mark the generic parameters and arguments children DIEs of DIE. */
22317 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22321 if (die
== NULL
|| die
->die_child
== NULL
)
22323 c
= die
->die_child
;
22326 if (is_template_parameter (c
))
22327 prune_unused_types_mark (c
, 1);
22329 } while (c
&& c
!= die
->die_child
);
22332 /* Mark DIE as being used. If DOKIDS is true, then walk down
22333 to DIE's children. */
22336 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22340 if (die
->die_mark
== 0)
22342 /* We haven't done this node yet. Mark it as used. */
22344 /* If this is the DIE of a generic type instantiation,
22345 mark the children DIEs that describe its generic parms and
22347 prune_unused_types_mark_generic_parms_dies (die
);
22349 /* We also have to mark its parents as used.
22350 (But we don't want to mark our parent's kids due to this,
22351 unless it is a class.) */
22352 if (die
->die_parent
)
22353 prune_unused_types_mark (die
->die_parent
,
22354 class_scope_p (die
->die_parent
));
22356 /* Mark any referenced nodes. */
22357 prune_unused_types_walk_attribs (die
);
22359 /* If this node is a specification,
22360 also mark the definition, if it exists. */
22361 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22362 prune_unused_types_mark (die
->die_definition
, 1);
22365 if (dokids
&& die
->die_mark
!= 2)
22367 /* We need to walk the children, but haven't done so yet.
22368 Remember that we've walked the kids. */
22371 /* If this is an array type, we need to make sure our
22372 kids get marked, even if they're types. If we're
22373 breaking out types into comdat sections, do this
22374 for all type definitions. */
22375 if (die
->die_tag
== DW_TAG_array_type
22376 || (use_debug_types
22377 && is_type_die (die
) && ! is_declaration_die (die
)))
22378 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22380 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22384 /* For local classes, look if any static member functions were emitted
22385 and if so, mark them. */
22388 prune_unused_types_walk_local_classes (dw_die_ref die
)
22392 if (die
->die_mark
== 2)
22395 switch (die
->die_tag
)
22397 case DW_TAG_structure_type
:
22398 case DW_TAG_union_type
:
22399 case DW_TAG_class_type
:
22402 case DW_TAG_subprogram
:
22403 if (!get_AT_flag (die
, DW_AT_declaration
)
22404 || die
->die_definition
!= NULL
)
22405 prune_unused_types_mark (die
, 1);
22412 /* Mark children. */
22413 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22416 /* Walk the tree DIE and mark types that we actually use. */
22419 prune_unused_types_walk (dw_die_ref die
)
22423 /* Don't do anything if this node is already marked and
22424 children have been marked as well. */
22425 if (die
->die_mark
== 2)
22428 switch (die
->die_tag
)
22430 case DW_TAG_structure_type
:
22431 case DW_TAG_union_type
:
22432 case DW_TAG_class_type
:
22433 if (die
->die_perennial_p
)
22436 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22437 if (c
->die_tag
== DW_TAG_subprogram
)
22440 /* Finding used static member functions inside of classes
22441 is needed just for local classes, because for other classes
22442 static member function DIEs with DW_AT_specification
22443 are emitted outside of the DW_TAG_*_type. If we ever change
22444 it, we'd need to call this even for non-local classes. */
22446 prune_unused_types_walk_local_classes (die
);
22448 /* It's a type node --- don't mark it. */
22451 case DW_TAG_const_type
:
22452 case DW_TAG_packed_type
:
22453 case DW_TAG_pointer_type
:
22454 case DW_TAG_reference_type
:
22455 case DW_TAG_rvalue_reference_type
:
22456 case DW_TAG_volatile_type
:
22457 case DW_TAG_typedef
:
22458 case DW_TAG_array_type
:
22459 case DW_TAG_interface_type
:
22460 case DW_TAG_friend
:
22461 case DW_TAG_variant_part
:
22462 case DW_TAG_enumeration_type
:
22463 case DW_TAG_subroutine_type
:
22464 case DW_TAG_string_type
:
22465 case DW_TAG_set_type
:
22466 case DW_TAG_subrange_type
:
22467 case DW_TAG_ptr_to_member_type
:
22468 case DW_TAG_file_type
:
22469 if (die
->die_perennial_p
)
22472 /* It's a type node --- don't mark it. */
22476 /* Mark everything else. */
22480 if (die
->die_mark
== 0)
22484 /* Now, mark any dies referenced from here. */
22485 prune_unused_types_walk_attribs (die
);
22490 /* Mark children. */
22491 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22494 /* Increment the string counts on strings referred to from DIE's
22498 prune_unused_types_update_strings (dw_die_ref die
)
22503 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22504 if (AT_class (a
) == dw_val_class_str
)
22506 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22508 /* Avoid unnecessarily putting strings that are used less than
22509 twice in the hash table. */
22511 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22514 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22515 htab_hash_string (s
->str
),
22517 gcc_assert (*slot
== NULL
);
22523 /* Remove from the tree DIE any dies that aren't marked. */
22526 prune_unused_types_prune (dw_die_ref die
)
22530 gcc_assert (die
->die_mark
);
22531 prune_unused_types_update_strings (die
);
22533 if (! die
->die_child
)
22536 c
= die
->die_child
;
22538 dw_die_ref prev
= c
;
22539 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22540 if (c
== die
->die_child
)
22542 /* No marked children between 'prev' and the end of the list. */
22544 /* No marked children at all. */
22545 die
->die_child
= NULL
;
22548 prev
->die_sib
= c
->die_sib
;
22549 die
->die_child
= prev
;
22554 if (c
!= prev
->die_sib
)
22556 prune_unused_types_prune (c
);
22557 } while (c
!= die
->die_child
);
22560 /* Remove dies representing declarations that we never use. */
22563 prune_unused_types (void)
22566 limbo_die_node
*node
;
22567 comdat_type_node
*ctnode
;
22569 dw_die_ref base_type
;
22571 #if ENABLE_ASSERT_CHECKING
22572 /* All the marks should already be clear. */
22573 verify_marks_clear (comp_unit_die ());
22574 for (node
= limbo_die_list
; node
; node
= node
->next
)
22575 verify_marks_clear (node
->die
);
22576 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22577 verify_marks_clear (ctnode
->root_die
);
22578 #endif /* ENABLE_ASSERT_CHECKING */
22580 /* Mark types that are used in global variables. */
22581 premark_types_used_by_global_vars ();
22583 /* Set the mark on nodes that are actually used. */
22584 prune_unused_types_walk (comp_unit_die ());
22585 for (node
= limbo_die_list
; node
; node
= node
->next
)
22586 prune_unused_types_walk (node
->die
);
22587 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22589 prune_unused_types_walk (ctnode
->root_die
);
22590 prune_unused_types_mark (ctnode
->type_die
, 1);
22593 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22594 are unusual in that they are pubnames that are the children of pubtypes.
22595 They should only be marked via their parent DW_TAG_enumeration_type die,
22596 not as roots in themselves. */
22597 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22598 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22599 prune_unused_types_mark (pub
->die
, 1);
22600 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22601 prune_unused_types_mark (base_type
, 1);
22603 if (debug_str_hash
)
22604 htab_empty (debug_str_hash
);
22605 if (skeleton_debug_str_hash
)
22606 htab_empty (skeleton_debug_str_hash
);
22607 prune_unused_types_prune (comp_unit_die ());
22608 for (node
= limbo_die_list
; node
; node
= node
->next
)
22609 prune_unused_types_prune (node
->die
);
22610 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22611 prune_unused_types_prune (ctnode
->root_die
);
22613 /* Leave the marks clear. */
22614 prune_unmark_dies (comp_unit_die ());
22615 for (node
= limbo_die_list
; node
; node
= node
->next
)
22616 prune_unmark_dies (node
->die
);
22617 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22618 prune_unmark_dies (ctnode
->root_die
);
22621 /* Set the parameter to true if there are any relative pathnames in
22624 file_table_relative_p (void ** slot
, void *param
)
22626 bool *p
= (bool *) param
;
22627 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22628 if (!IS_ABSOLUTE_PATH (d
->filename
))
22636 /* Helpers to manipulate hash table of comdat type units. */
22638 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
22640 typedef comdat_type_node value_type
;
22641 typedef comdat_type_node compare_type
;
22642 static inline hashval_t
hash (const value_type
*);
22643 static inline bool equal (const value_type
*, const compare_type
*);
22647 comdat_type_hasher::hash (const value_type
*type_node
)
22650 memcpy (&h
, type_node
->signature
, sizeof (h
));
22655 comdat_type_hasher::equal (const value_type
*type_node_1
,
22656 const compare_type
*type_node_2
)
22658 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22659 DWARF_TYPE_SIGNATURE_SIZE
));
22662 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22663 to the location it would have been added, should we know its
22664 DECL_ASSEMBLER_NAME when we added other attributes. This will
22665 probably improve compactness of debug info, removing equivalent
22666 abbrevs, and hide any differences caused by deferring the
22667 computation of the assembler name, triggered by e.g. PCH. */
22670 move_linkage_attr (dw_die_ref die
)
22672 unsigned ix
= vec_safe_length (die
->die_attr
);
22673 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22675 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22676 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22680 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22682 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22686 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22688 die
->die_attr
->pop ();
22689 die
->die_attr
->quick_insert (ix
, linkage
);
22693 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22694 referenced from typed stack ops and count how often they are used. */
22697 mark_base_types (dw_loc_descr_ref loc
)
22699 dw_die_ref base_type
= NULL
;
22701 for (; loc
; loc
= loc
->dw_loc_next
)
22703 switch (loc
->dw_loc_opc
)
22705 case DW_OP_GNU_regval_type
:
22706 case DW_OP_GNU_deref_type
:
22707 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22709 case DW_OP_GNU_convert
:
22710 case DW_OP_GNU_reinterpret
:
22711 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22714 case DW_OP_GNU_const_type
:
22715 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22717 case DW_OP_GNU_entry_value
:
22718 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22723 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22724 if (base_type
->die_mark
)
22725 base_type
->die_mark
++;
22728 base_types
.safe_push (base_type
);
22729 base_type
->die_mark
= 1;
22734 /* Comparison function for sorting marked base types. */
22737 base_type_cmp (const void *x
, const void *y
)
22739 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22740 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22741 unsigned int byte_size1
, byte_size2
;
22742 unsigned int encoding1
, encoding2
;
22743 if (dx
->die_mark
> dy
->die_mark
)
22745 if (dx
->die_mark
< dy
->die_mark
)
22747 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22748 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22749 if (byte_size1
< byte_size2
)
22751 if (byte_size1
> byte_size2
)
22753 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22754 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22755 if (encoding1
< encoding2
)
22757 if (encoding1
> encoding2
)
22762 /* Move base types marked by mark_base_types as early as possible
22763 in the CU, sorted by decreasing usage count both to make the
22764 uleb128 references as small as possible and to make sure they
22765 will have die_offset already computed by calc_die_sizes when
22766 sizes of typed stack loc ops is computed. */
22769 move_marked_base_types (void)
22772 dw_die_ref base_type
, die
, c
;
22774 if (base_types
.is_empty ())
22777 /* Sort by decreasing usage count, they will be added again in that
22779 base_types
.qsort (base_type_cmp
);
22780 die
= comp_unit_die ();
22781 c
= die
->die_child
;
22784 dw_die_ref prev
= c
;
22786 while (c
->die_mark
)
22788 remove_child_with_prev (c
, prev
);
22789 /* As base types got marked, there must be at least
22790 one node other than DW_TAG_base_type. */
22791 gcc_assert (c
!= c
->die_sib
);
22795 while (c
!= die
->die_child
);
22796 gcc_assert (die
->die_child
);
22797 c
= die
->die_child
;
22798 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22800 base_type
->die_mark
= 0;
22801 base_type
->die_sib
= c
->die_sib
;
22802 c
->die_sib
= base_type
;
22807 /* Helper function for resolve_addr, attempt to resolve
22808 one CONST_STRING, return non-zero if not successful. Similarly verify that
22809 SYMBOL_REFs refer to variables emitted in the current CU. */
22812 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22816 if (GET_CODE (rtl
) == CONST_STRING
)
22818 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22819 tree t
= build_string (len
, XSTR (rtl
, 0));
22820 tree tlen
= size_int (len
- 1);
22822 = build_array_type (char_type_node
, build_index_type (tlen
));
22823 rtl
= lookup_constant_def (t
);
22824 if (!rtl
|| !MEM_P (rtl
))
22826 rtl
= XEXP (rtl
, 0);
22827 if (GET_CODE (rtl
) == SYMBOL_REF
22828 && SYMBOL_REF_DECL (rtl
)
22829 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22831 vec_safe_push (used_rtx_array
, rtl
);
22836 if (GET_CODE (rtl
) == SYMBOL_REF
22837 && SYMBOL_REF_DECL (rtl
))
22839 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22841 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22844 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22848 if (GET_CODE (rtl
) == CONST
22849 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22855 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
22856 if possible, and create DW_TAG_dwarf_procedure that can be referenced
22857 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
22860 string_cst_pool_decl (tree t
)
22862 rtx rtl
= output_constant_def (t
, 1);
22863 unsigned char *array
;
22864 dw_loc_descr_ref l
;
22869 if (!rtl
|| !MEM_P (rtl
))
22871 rtl
= XEXP (rtl
, 0);
22872 if (GET_CODE (rtl
) != SYMBOL_REF
22873 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
22876 decl
= SYMBOL_REF_DECL (rtl
);
22877 if (!lookup_decl_die (decl
))
22879 len
= TREE_STRING_LENGTH (t
);
22880 vec_safe_push (used_rtx_array
, rtl
);
22881 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
22882 array
= (unsigned char *) ggc_alloc_atomic (len
);
22883 memcpy (array
, TREE_STRING_POINTER (t
), len
);
22884 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
22885 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
22886 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
22887 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
22888 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
22889 add_AT_loc (ref
, DW_AT_location
, l
);
22890 equate_decl_number_to_die (decl
, ref
);
22895 /* Helper function of resolve_addr_in_expr. LOC is
22896 a DW_OP_addr followed by DW_OP_stack_value, either at the start
22897 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
22898 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
22899 with DW_OP_GNU_implicit_pointer if possible
22900 and return true, if unsuccessful, return false. */
22903 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
22905 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
22906 HOST_WIDE_INT offset
= 0;
22907 dw_die_ref ref
= NULL
;
22910 if (GET_CODE (rtl
) == CONST
22911 && GET_CODE (XEXP (rtl
, 0)) == PLUS
22912 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
22914 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
22915 rtl
= XEXP (XEXP (rtl
, 0), 0);
22917 if (GET_CODE (rtl
) == CONST_STRING
)
22919 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22920 tree t
= build_string (len
, XSTR (rtl
, 0));
22921 tree tlen
= size_int (len
- 1);
22924 = build_array_type (char_type_node
, build_index_type (tlen
));
22925 rtl
= string_cst_pool_decl (t
);
22929 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
22931 decl
= SYMBOL_REF_DECL (rtl
);
22932 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
22934 ref
= lookup_decl_die (decl
);
22935 if (ref
&& (get_AT (ref
, DW_AT_location
)
22936 || get_AT (ref
, DW_AT_const_value
)))
22938 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
22939 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22940 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
22941 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22942 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22943 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22944 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
22952 /* Helper function for resolve_addr, handle one location
22953 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22954 the location list couldn't be resolved. */
22957 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22959 dw_loc_descr_ref keep
= NULL
;
22960 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
22961 switch (loc
->dw_loc_opc
)
22964 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22967 || prev
->dw_loc_opc
== DW_OP_piece
22968 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
22969 && loc
->dw_loc_next
22970 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
22972 && optimize_one_addr_into_implicit_ptr (loc
))
22977 case DW_OP_GNU_addr_index
:
22978 case DW_OP_GNU_const_index
:
22979 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22980 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22981 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22985 case DW_OP_const4u
:
22986 case DW_OP_const8u
:
22988 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22991 case DW_OP_plus_uconst
:
22992 if (size_of_loc_descr (loc
)
22993 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22995 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22997 dw_loc_descr_ref repl
22998 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22999 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
23000 add_loc_descr (&repl
, loc
->dw_loc_next
);
23004 case DW_OP_implicit_value
:
23005 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
23006 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
23009 case DW_OP_GNU_implicit_pointer
:
23010 case DW_OP_GNU_parameter_ref
:
23011 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
23014 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
23017 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23018 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23019 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23022 case DW_OP_GNU_const_type
:
23023 case DW_OP_GNU_regval_type
:
23024 case DW_OP_GNU_deref_type
:
23025 case DW_OP_GNU_convert
:
23026 case DW_OP_GNU_reinterpret
:
23027 while (loc
->dw_loc_next
23028 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
23030 dw_die_ref base1
, base2
;
23031 unsigned enc1
, enc2
, size1
, size2
;
23032 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23033 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23034 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23035 else if (loc
->dw_loc_oprnd1
.val_class
23036 == dw_val_class_unsigned_const
)
23039 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23040 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
23041 == dw_val_class_unsigned_const
)
23043 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23044 gcc_assert (base1
->die_tag
== DW_TAG_base_type
23045 && base2
->die_tag
== DW_TAG_base_type
);
23046 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
23047 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
23048 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
23049 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
23051 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
23052 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
23056 /* Optimize away next DW_OP_GNU_convert after
23057 adjusting LOC's base type die reference. */
23058 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23059 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23060 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
23062 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
23063 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23066 /* Don't change integer DW_OP_GNU_convert after e.g. floating
23067 point typed stack entry. */
23068 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
23069 keep
= loc
->dw_loc_next
;
23079 /* Helper function of resolve_addr. DIE had DW_AT_location of
23080 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
23081 and DW_OP_addr couldn't be resolved. resolve_addr has already
23082 removed the DW_AT_location attribute. This function attempts to
23083 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
23084 to it or DW_AT_const_value attribute, if possible. */
23087 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
23089 if (TREE_CODE (decl
) != VAR_DECL
23090 || lookup_decl_die (decl
) != die
23091 || DECL_EXTERNAL (decl
)
23092 || !TREE_STATIC (decl
)
23093 || DECL_INITIAL (decl
) == NULL_TREE
23094 || DECL_P (DECL_INITIAL (decl
))
23095 || get_AT (die
, DW_AT_const_value
))
23098 tree init
= DECL_INITIAL (decl
);
23099 HOST_WIDE_INT offset
= 0;
23100 /* For variables that have been optimized away and thus
23101 don't have a memory location, see if we can emit
23102 DW_AT_const_value instead. */
23103 if (tree_add_const_value_attribute (die
, init
))
23107 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
23108 and ADDR_EXPR refers to a decl that has DW_AT_location or
23109 DW_AT_const_value (but isn't addressable, otherwise
23110 resolving the original DW_OP_addr wouldn't fail), see if
23111 we can add DW_OP_GNU_implicit_pointer. */
23113 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
23114 && host_integerp (TREE_OPERAND (init
, 1), 0))
23116 offset
= tree_low_cst (TREE_OPERAND (init
, 1), 0);
23117 init
= TREE_OPERAND (init
, 0);
23120 if (TREE_CODE (init
) != ADDR_EXPR
)
23122 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
23123 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
23124 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
23125 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
23126 && TREE_OPERAND (init
, 0) != decl
))
23129 dw_loc_descr_ref l
;
23131 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
23133 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
23136 decl
= SYMBOL_REF_DECL (rtl
);
23139 decl
= TREE_OPERAND (init
, 0);
23140 ref
= lookup_decl_die (decl
);
23142 || (!get_AT (ref
, DW_AT_location
)
23143 && !get_AT (ref
, DW_AT_const_value
)))
23145 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
23146 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23147 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23148 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23149 add_AT_loc (die
, DW_AT_location
, l
);
23153 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23154 an address in .rodata section if the string literal is emitted there,
23155 or remove the containing location list or replace DW_AT_const_value
23156 with DW_AT_location and empty location expression, if it isn't found
23157 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23158 to something that has been emitted in the current CU. */
23161 resolve_addr (dw_die_ref die
)
23165 dw_loc_list_ref
*curr
, *start
, loc
;
23168 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23169 switch (AT_class (a
))
23171 case dw_val_class_loc_list
:
23172 start
= curr
= AT_loc_list_ptr (a
);
23175 /* The same list can be referenced more than once. See if we have
23176 already recorded the result from a previous pass. */
23178 *curr
= loc
->dw_loc_next
;
23179 else if (!loc
->resolved_addr
)
23181 /* As things stand, we do not expect or allow one die to
23182 reference a suffix of another die's location list chain.
23183 References must be identical or completely separate.
23184 There is therefore no need to cache the result of this
23185 pass on any list other than the first; doing so
23186 would lead to unnecessary writes. */
23189 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23190 if (!resolve_addr_in_expr ((*curr
)->expr
))
23192 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23193 dw_loc_descr_ref l
= (*curr
)->expr
;
23195 if (next
&& (*curr
)->ll_symbol
)
23197 gcc_assert (!next
->ll_symbol
);
23198 next
->ll_symbol
= (*curr
)->ll_symbol
;
23200 if (dwarf_split_debug_info
)
23201 remove_loc_list_addr_table_entries (l
);
23206 mark_base_types ((*curr
)->expr
);
23207 curr
= &(*curr
)->dw_loc_next
;
23211 loc
->resolved_addr
= 1;
23215 loc
->dw_loc_next
= *start
;
23220 remove_AT (die
, a
->dw_attr
);
23224 case dw_val_class_loc
:
23226 dw_loc_descr_ref l
= AT_loc (a
);
23227 /* For -gdwarf-2 don't attempt to optimize
23228 DW_AT_data_member_location containing
23229 DW_OP_plus_uconst - older consumers might
23230 rely on it being that op instead of a more complex,
23231 but shorter, location description. */
23232 if ((dwarf_version
> 2
23233 || a
->dw_attr
!= DW_AT_data_member_location
23235 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23236 || l
->dw_loc_next
!= NULL
)
23237 && !resolve_addr_in_expr (l
))
23239 if (dwarf_split_debug_info
)
23240 remove_loc_list_addr_table_entries (l
);
23242 && l
->dw_loc_next
== NULL
23243 && l
->dw_loc_opc
== DW_OP_addr
23244 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
23245 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
23246 && a
->dw_attr
== DW_AT_location
)
23248 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
23249 remove_AT (die
, a
->dw_attr
);
23251 optimize_location_into_implicit_ptr (die
, decl
);
23254 remove_AT (die
, a
->dw_attr
);
23258 mark_base_types (l
);
23261 case dw_val_class_addr
:
23262 if (a
->dw_attr
== DW_AT_const_value
23263 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23265 if (AT_index (a
) != NOT_INDEXED
)
23266 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23267 remove_AT (die
, a
->dw_attr
);
23270 if (die
->die_tag
== DW_TAG_GNU_call_site
23271 && a
->dw_attr
== DW_AT_abstract_origin
)
23273 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23274 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23276 && DECL_EXTERNAL (tdecl
)
23277 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23279 force_decl_die (tdecl
);
23280 tdie
= lookup_decl_die (tdecl
);
23284 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23285 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23286 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23290 if (AT_index (a
) != NOT_INDEXED
)
23291 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23292 remove_AT (die
, a
->dw_attr
);
23301 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23304 /* Helper routines for optimize_location_lists.
23305 This pass tries to share identical local lists in .debug_loc
23308 /* Iteratively hash operands of LOC opcode. */
23311 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23313 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23314 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23316 switch (loc
->dw_loc_opc
)
23318 case DW_OP_const4u
:
23319 case DW_OP_const8u
:
23323 case DW_OP_const1u
:
23324 case DW_OP_const1s
:
23325 case DW_OP_const2u
:
23326 case DW_OP_const2s
:
23327 case DW_OP_const4s
:
23328 case DW_OP_const8s
:
23332 case DW_OP_plus_uconst
:
23368 case DW_OP_deref_size
:
23369 case DW_OP_xderef_size
:
23370 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23377 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23378 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23379 hash
= iterative_hash_object (offset
, hash
);
23382 case DW_OP_implicit_value
:
23383 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23384 switch (val2
->val_class
)
23386 case dw_val_class_const
:
23387 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23389 case dw_val_class_vec
:
23391 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23392 unsigned int len
= val2
->v
.val_vec
.length
;
23394 hash
= iterative_hash_object (elt_size
, hash
);
23395 hash
= iterative_hash_object (len
, hash
);
23396 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23397 len
* elt_size
, hash
);
23400 case dw_val_class_const_double
:
23401 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23402 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23404 case dw_val_class_addr
:
23405 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23408 gcc_unreachable ();
23412 case DW_OP_bit_piece
:
23413 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23414 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23420 unsigned char dtprel
= 0xd1;
23421 hash
= iterative_hash_object (dtprel
, hash
);
23423 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23425 case DW_OP_GNU_addr_index
:
23426 case DW_OP_GNU_const_index
:
23430 unsigned char dtprel
= 0xd1;
23431 hash
= iterative_hash_object (dtprel
, hash
);
23433 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23436 case DW_OP_GNU_implicit_pointer
:
23437 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23439 case DW_OP_GNU_entry_value
:
23440 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23442 case DW_OP_GNU_regval_type
:
23443 case DW_OP_GNU_deref_type
:
23445 unsigned int byte_size
23446 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23447 unsigned int encoding
23448 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23449 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23450 hash
= iterative_hash_object (byte_size
, hash
);
23451 hash
= iterative_hash_object (encoding
, hash
);
23454 case DW_OP_GNU_convert
:
23455 case DW_OP_GNU_reinterpret
:
23456 if (val1
->val_class
== dw_val_class_unsigned_const
)
23458 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23462 case DW_OP_GNU_const_type
:
23464 unsigned int byte_size
23465 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23466 unsigned int encoding
23467 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23468 hash
= iterative_hash_object (byte_size
, hash
);
23469 hash
= iterative_hash_object (encoding
, hash
);
23470 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23472 hash
= iterative_hash_object (val2
->val_class
, hash
);
23473 switch (val2
->val_class
)
23475 case dw_val_class_const
:
23476 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23478 case dw_val_class_vec
:
23480 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23481 unsigned int len
= val2
->v
.val_vec
.length
;
23483 hash
= iterative_hash_object (elt_size
, hash
);
23484 hash
= iterative_hash_object (len
, hash
);
23485 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23486 len
* elt_size
, hash
);
23489 case dw_val_class_const_double
:
23490 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23491 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23494 gcc_unreachable ();
23500 /* Other codes have no operands. */
23506 /* Iteratively hash the whole DWARF location expression LOC. */
23508 static inline hashval_t
23509 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23511 dw_loc_descr_ref l
;
23512 bool sizes_computed
= false;
23513 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23514 size_of_locs (loc
);
23516 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23518 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23519 hash
= iterative_hash_object (opc
, hash
);
23520 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23522 size_of_locs (loc
);
23523 sizes_computed
= true;
23525 hash
= hash_loc_operands (l
, hash
);
23530 /* Compute hash of the whole location list LIST_HEAD. */
23533 hash_loc_list (dw_loc_list_ref list_head
)
23535 dw_loc_list_ref curr
= list_head
;
23536 hashval_t hash
= 0;
23538 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23540 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23541 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23543 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23545 hash
= hash_locs (curr
->expr
, hash
);
23547 list_head
->hash
= hash
;
23550 /* Return true if X and Y opcodes have the same operands. */
23553 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23555 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23556 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23557 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23558 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23560 switch (x
->dw_loc_opc
)
23562 case DW_OP_const4u
:
23563 case DW_OP_const8u
:
23567 case DW_OP_const1u
:
23568 case DW_OP_const1s
:
23569 case DW_OP_const2u
:
23570 case DW_OP_const2s
:
23571 case DW_OP_const4s
:
23572 case DW_OP_const8s
:
23576 case DW_OP_plus_uconst
:
23612 case DW_OP_deref_size
:
23613 case DW_OP_xderef_size
:
23614 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23617 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23618 can cause irrelevant differences in dw_loc_addr. */
23619 gcc_assert (valx1
->val_class
== dw_val_class_loc
23620 && valy1
->val_class
== dw_val_class_loc
23621 && (dwarf_split_debug_info
23622 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23623 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23624 case DW_OP_implicit_value
:
23625 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23626 || valx2
->val_class
!= valy2
->val_class
)
23628 switch (valx2
->val_class
)
23630 case dw_val_class_const
:
23631 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23632 case dw_val_class_vec
:
23633 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23634 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23635 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23636 valx2
->v
.val_vec
.elt_size
23637 * valx2
->v
.val_vec
.length
) == 0;
23638 case dw_val_class_const_double
:
23639 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23640 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23641 case dw_val_class_addr
:
23642 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23644 gcc_unreachable ();
23647 case DW_OP_bit_piece
:
23648 return valx1
->v
.val_int
== valy1
->v
.val_int
23649 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23652 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23653 case DW_OP_GNU_addr_index
:
23654 case DW_OP_GNU_const_index
:
23656 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23657 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23658 return rtx_equal_p (ax1
, ay1
);
23660 case DW_OP_GNU_implicit_pointer
:
23661 return valx1
->val_class
== dw_val_class_die_ref
23662 && valx1
->val_class
== valy1
->val_class
23663 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23664 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23665 case DW_OP_GNU_entry_value
:
23666 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23667 case DW_OP_GNU_const_type
:
23668 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23669 || valx2
->val_class
!= valy2
->val_class
)
23671 switch (valx2
->val_class
)
23673 case dw_val_class_const
:
23674 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23675 case dw_val_class_vec
:
23676 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23677 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23678 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23679 valx2
->v
.val_vec
.elt_size
23680 * valx2
->v
.val_vec
.length
) == 0;
23681 case dw_val_class_const_double
:
23682 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23683 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23685 gcc_unreachable ();
23687 case DW_OP_GNU_regval_type
:
23688 case DW_OP_GNU_deref_type
:
23689 return valx1
->v
.val_int
== valy1
->v
.val_int
23690 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23691 case DW_OP_GNU_convert
:
23692 case DW_OP_GNU_reinterpret
:
23693 if (valx1
->val_class
!= valy1
->val_class
)
23695 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23696 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23697 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23698 case DW_OP_GNU_parameter_ref
:
23699 return valx1
->val_class
== dw_val_class_die_ref
23700 && valx1
->val_class
== valy1
->val_class
23701 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23703 /* Other codes have no operands. */
23708 /* Return true if DWARF location expressions X and Y are the same. */
23711 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23713 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23714 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23715 || x
->dtprel
!= y
->dtprel
23716 || !compare_loc_operands (x
, y
))
23718 return x
== NULL
&& y
== NULL
;
23721 /* Hashtable helpers. */
23723 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
23725 typedef dw_loc_list_struct value_type
;
23726 typedef dw_loc_list_struct compare_type
;
23727 static inline hashval_t
hash (const value_type
*);
23728 static inline bool equal (const value_type
*, const compare_type
*);
23731 /* Return precomputed hash of location list X. */
23734 loc_list_hasher::hash (const value_type
*x
)
23739 /* Return true if location lists A and B are the same. */
23742 loc_list_hasher::equal (const value_type
*a
, const compare_type
*b
)
23746 if (a
->hash
!= b
->hash
)
23748 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23749 if (strcmp (a
->begin
, b
->begin
) != 0
23750 || strcmp (a
->end
, b
->end
) != 0
23751 || (a
->section
== NULL
) != (b
->section
== NULL
)
23752 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23753 || !compare_locs (a
->expr
, b
->expr
))
23755 return a
== NULL
&& b
== NULL
;
23758 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
23761 /* Recursively optimize location lists referenced from DIE
23762 children and share them whenever possible. */
23765 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type htab
)
23770 dw_loc_list_struct
**slot
;
23772 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23773 if (AT_class (a
) == dw_val_class_loc_list
)
23775 dw_loc_list_ref list
= AT_loc_list (a
);
23776 /* TODO: perform some optimizations here, before hashing
23777 it and storing into the hash table. */
23778 hash_loc_list (list
);
23779 slot
= htab
.find_slot_with_hash (list
, list
->hash
, INSERT
);
23783 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
23786 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23790 /* Recursively assign each location list a unique index into the debug_addr
23794 index_location_lists (dw_die_ref die
)
23800 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23801 if (AT_class (a
) == dw_val_class_loc_list
)
23803 dw_loc_list_ref list
= AT_loc_list (a
);
23804 dw_loc_list_ref curr
;
23805 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23807 /* Don't index an entry that has already been indexed
23808 or won't be output. */
23809 if (curr
->begin_entry
!= NULL
23810 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23814 = add_addr_table_entry (xstrdup (curr
->begin
),
23819 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23822 /* Optimize location lists referenced from DIE
23823 children and share them whenever possible. */
23826 optimize_location_lists (dw_die_ref die
)
23828 loc_list_hash_type htab
;
23830 optimize_location_lists_1 (die
, htab
);
23834 /* Output stuff that dwarf requires at the end of every file,
23835 and generate the DWARF-2 debugging info. */
23838 dwarf2out_finish (const char *filename
)
23840 limbo_die_node
*node
, *next_node
;
23841 comdat_type_node
*ctnode
;
23842 hash_table
<comdat_type_hasher
> comdat_type_table
;
23844 dw_die_ref main_comp_unit_die
;
23846 /* PCH might result in DW_AT_producer string being restored from the
23847 header compilation, so always fill it with empty string initially
23848 and overwrite only here. */
23849 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23850 producer_string
= gen_producer_string ();
23851 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23852 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23854 gen_scheduled_generic_parms_dies ();
23855 gen_remaining_tmpl_value_param_die_attribute ();
23857 /* Add the name for the main input file now. We delayed this from
23858 dwarf2out_init to avoid complications with PCH. */
23859 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23860 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23861 add_comp_dir_attribute (comp_unit_die ());
23862 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23865 htab_traverse (file_table
, file_table_relative_p
, &p
);
23867 add_comp_dir_attribute (comp_unit_die ());
23870 if (deferred_locations_list
)
23871 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23873 add_location_or_const_value_attribute (
23874 (*deferred_locations_list
)[i
].die
,
23875 (*deferred_locations_list
)[i
].variable
,
23880 /* Traverse the limbo die list, and add parent/child links. The only
23881 dies without parents that should be here are concrete instances of
23882 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23883 For concrete instances, we can get the parent die from the abstract
23885 for (node
= limbo_die_list
; node
; node
= next_node
)
23887 dw_die_ref die
= node
->die
;
23888 next_node
= node
->next
;
23890 if (die
->die_parent
== NULL
)
23892 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23894 if (origin
&& origin
->die_parent
)
23895 add_child_die (origin
->die_parent
, die
);
23896 else if (is_cu_die (die
))
23898 else if (seen_error ())
23899 /* It's OK to be confused by errors in the input. */
23900 add_child_die (comp_unit_die (), die
);
23903 /* In certain situations, the lexical block containing a
23904 nested function can be optimized away, which results
23905 in the nested function die being orphaned. Likewise
23906 with the return type of that nested function. Force
23907 this to be a child of the containing function.
23909 It may happen that even the containing function got fully
23910 inlined and optimized out. In that case we are lost and
23911 assign the empty child. This should not be big issue as
23912 the function is likely unreachable too. */
23913 gcc_assert (node
->created_for
);
23915 if (DECL_P (node
->created_for
))
23916 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23917 else if (TYPE_P (node
->created_for
))
23918 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23920 origin
= comp_unit_die ();
23922 add_child_die (origin
, die
);
23927 limbo_die_list
= NULL
;
23929 #if ENABLE_ASSERT_CHECKING
23931 dw_die_ref die
= comp_unit_die (), c
;
23932 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23935 resolve_addr (comp_unit_die ());
23936 move_marked_base_types ();
23938 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23940 tree decl
= node
->created_for
;
23941 /* When generating LTO bytecode we can not generate new assembler
23942 names at this point and all important decls got theirs via
23944 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23945 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23947 add_linkage_attr (node
->die
, decl
);
23948 move_linkage_attr (node
->die
);
23952 deferred_asm_name
= NULL
;
23954 /* Walk through the list of incomplete types again, trying once more to
23955 emit full debugging info for them. */
23956 retry_incomplete_types ();
23958 if (flag_eliminate_unused_debug_types
)
23959 prune_unused_types ();
23961 /* Generate separate COMDAT sections for type DIEs. */
23962 if (use_debug_types
)
23964 break_out_comdat_types (comp_unit_die ());
23966 /* Each new type_unit DIE was added to the limbo die list when created.
23967 Since these have all been added to comdat_type_list, clear the
23969 limbo_die_list
= NULL
;
23971 /* For each new comdat type unit, copy declarations for incomplete
23972 types to make the new unit self-contained (i.e., no direct
23973 references to the main compile unit). */
23974 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23975 copy_decls_for_unworthy_types (ctnode
->root_die
);
23976 copy_decls_for_unworthy_types (comp_unit_die ());
23978 /* In the process of copying declarations from one unit to another,
23979 we may have left some declarations behind that are no longer
23980 referenced. Prune them. */
23981 prune_unused_types ();
23984 /* Generate separate CUs for each of the include files we've seen.
23985 They will go into limbo_die_list. */
23986 if (flag_eliminate_dwarf2_dups
)
23987 break_out_includes (comp_unit_die ());
23989 /* Traverse the DIE's and add add sibling attributes to those DIE's
23990 that have children. */
23991 add_sibling_attributes (comp_unit_die ());
23992 for (node
= limbo_die_list
; node
; node
= node
->next
)
23993 add_sibling_attributes (node
->die
);
23994 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23995 add_sibling_attributes (ctnode
->root_die
);
23997 /* When splitting DWARF info, we put some attributes in the
23998 skeleton compile_unit DIE that remains in the .o, while
23999 most attributes go in the DWO compile_unit_die. */
24000 if (dwarf_split_debug_info
)
24001 main_comp_unit_die
= gen_compile_unit_die (NULL
);
24003 main_comp_unit_die
= comp_unit_die ();
24005 /* Output a terminator label for the .text section. */
24006 switch_to_section (text_section
);
24007 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
24008 if (cold_text_section
)
24010 switch_to_section (cold_text_section
);
24011 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
24014 /* We can only use the low/high_pc attributes if all of the code was
24016 if (!have_multiple_function_sections
24017 || (dwarf_version
< 3 && dwarf_strict
))
24019 /* Don't add if the CU has no associated code. */
24020 if (text_section_used
)
24021 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
24022 text_end_label
, true);
24028 bool range_list_added
= false;
24030 if (text_section_used
)
24031 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
24032 text_end_label
, &range_list_added
, true);
24033 if (cold_text_section_used
)
24034 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
24035 cold_end_label
, &range_list_added
, true);
24037 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
24039 if (DECL_IGNORED_P (fde
->decl
))
24041 if (!fde
->in_std_section
)
24042 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
24043 fde
->dw_fde_end
, &range_list_added
,
24045 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
24046 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
24047 fde
->dw_fde_second_end
, &range_list_added
,
24051 if (range_list_added
)
24053 /* We need to give .debug_loc and .debug_ranges an appropriate
24054 "base address". Use zero so that these addresses become
24055 absolute. Historically, we've emitted the unexpected
24056 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
24057 Emit both to give time for other tools to adapt. */
24058 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
24059 if (! dwarf_strict
&& dwarf_version
< 4)
24060 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
24066 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
24067 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
24068 debug_line_section_label
);
24071 add_AT_macptr (comp_unit_die (),
24072 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
24073 macinfo_section_label
);
24075 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
24077 /* optimize_location_lists calculates the size of the lists,
24078 so index them first, and assign indices to the entries.
24079 Although optimize_location_lists will remove entries from
24080 the table, it only does so for duplicates, and therefore
24081 only reduces ref_counts to 1. */
24082 unsigned int index
= 0;
24083 index_location_lists (comp_unit_die ());
24084 htab_traverse_noresize (addr_index_table
,
24085 index_addr_table_entry
, &index
);
24087 if (have_location_lists
)
24088 optimize_location_lists (comp_unit_die ());
24090 save_macinfo_strings ();
24092 if (dwarf_split_debug_info
)
24094 unsigned int index
= 0;
24096 /* Add attributes common to skeleton compile_units and
24097 type_units. Because these attributes include strings, it
24098 must be done before freezing the string table. Top-level
24099 skeleton die attrs are added when the skeleton type unit is
24100 created, so ensure it is created by this point. */
24101 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
24102 (void) get_skeleton_type_unit ();
24103 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
24106 /* Output all of the compilation units. We put the main one last so that
24107 the offsets are available to output_pubnames. */
24108 for (node
= limbo_die_list
; node
; node
= node
->next
)
24109 output_comp_unit (node
->die
, 0);
24111 comdat_type_table
.create (100);
24112 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24114 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
24116 /* Don't output duplicate types. */
24117 if (*slot
!= HTAB_EMPTY_ENTRY
)
24120 /* Add a pointer to the line table for the main compilation unit
24121 so that the debugger can make sense of DW_AT_decl_file
24123 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
24124 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
24125 (!dwarf_split_debug_info
24126 ? debug_line_section_label
24127 : debug_skeleton_line_section_label
));
24129 output_comdat_type_unit (ctnode
);
24132 comdat_type_table
.dispose ();
24134 /* The AT_pubnames attribute needs to go in all skeleton dies, including
24135 both the main_cu and all skeleton TUs. Making this call unconditional
24136 would end up either adding a second copy of the AT_pubnames attribute, or
24137 requiring a special case in add_top_level_skeleton_die_attrs. */
24138 if (!dwarf_split_debug_info
)
24139 add_AT_pubnames (comp_unit_die ());
24141 if (dwarf_split_debug_info
)
24144 unsigned char checksum
[16];
24145 struct md5_ctx ctx
;
24147 /* Compute a checksum of the comp_unit to use as the dwo_id. */
24148 md5_init_ctx (&ctx
);
24150 die_checksum (comp_unit_die (), &ctx
, &mark
);
24151 unmark_all_dies (comp_unit_die ());
24152 md5_finish_ctx (&ctx
, checksum
);
24154 /* Use the first 8 bytes of the checksum as the dwo_id,
24155 and add it to both comp-unit DIEs. */
24156 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
24157 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
24159 /* Add the base offset of the ranges table to the skeleton
24161 if (ranges_table_in_use
)
24162 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
24163 ranges_section_label
);
24165 switch_to_section (debug_addr_section
);
24166 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
24167 output_addr_table ();
24170 /* Output the main compilation unit if non-empty or if .debug_macinfo
24171 or .debug_macro will be emitted. */
24172 output_comp_unit (comp_unit_die (), have_macinfo
);
24174 if (dwarf_split_debug_info
&& info_section_emitted
)
24175 output_skeleton_debug_sections (main_comp_unit_die
);
24177 /* Output the abbreviation table. */
24178 if (abbrev_die_table_in_use
!= 1)
24180 switch_to_section (debug_abbrev_section
);
24181 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
24182 output_abbrev_section ();
24185 /* Output location list section if necessary. */
24186 if (have_location_lists
)
24188 /* Output the location lists info. */
24189 switch_to_section (debug_loc_section
);
24190 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
24191 output_location_lists (comp_unit_die ());
24194 output_pubtables ();
24196 /* Output the address range information if a CU (.debug_info section)
24197 was emitted. We output an empty table even if we had no functions
24198 to put in it. This because the consumer has no way to tell the
24199 difference between an empty table that we omitted and failure to
24200 generate a table that would have contained data. */
24201 if (info_section_emitted
)
24203 unsigned long aranges_length
= size_of_aranges ();
24205 switch_to_section (debug_aranges_section
);
24206 output_aranges (aranges_length
);
24209 /* Output ranges section if necessary. */
24210 if (ranges_table_in_use
)
24212 switch_to_section (debug_ranges_section
);
24213 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24217 /* Have to end the macro section. */
24220 switch_to_section (debug_macinfo_section
);
24221 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24223 dw2_asm_output_data (1, 0, "End compilation unit");
24226 /* Output the source line correspondence table. We must do this
24227 even if there is no line information. Otherwise, on an empty
24228 translation unit, we will generate a present, but empty,
24229 .debug_info section. IRIX 6.5 `nm' will then complain when
24230 examining the file. This is done late so that any filenames
24231 used by the debug_info section are marked as 'used'. */
24232 switch_to_section (debug_line_section
);
24233 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24234 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24235 output_line_info (false);
24237 if (dwarf_split_debug_info
&& info_section_emitted
)
24239 switch_to_section (debug_skeleton_line_section
);
24240 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24241 output_line_info (true);
24244 /* If we emitted any indirect strings, output the string table too. */
24245 if (debug_str_hash
|| skeleton_debug_str_hash
)
24246 output_indirect_strings ();
24249 #include "gt-dwarf2out.h"