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 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
97 static rtx last_var_location_insn
;
98 static rtx cached_next_real_insn
;
100 #ifdef VMS_DEBUGGING_INFO
101 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
103 /* Define this macro to be a nonzero value if the directory specifications
104 which are output in the debug info should end with a separator. */
105 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
106 /* Define this macro to evaluate to a nonzero value if GCC should refrain
107 from generating indirect strings in DWARF2 debug information, for instance
108 if your target is stuck with an old version of GDB that is unable to
109 process them properly or uses VMS Debug. */
110 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
112 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
113 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
116 /* ??? Poison these here until it can be done generically. They've been
117 totally replaced in this file; make sure it stays that way. */
118 #undef DWARF2_UNWIND_INFO
119 #undef DWARF2_FRAME_INFO
120 #if (GCC_VERSION >= 3000)
121 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
124 /* The size of the target's pointer type. */
126 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
129 /* Array of RTXes referenced by the debugging information, which therefore
130 must be kept around forever. */
131 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
133 /* A pointer to the base of a list of incomplete types which might be
134 completed at some later time. incomplete_types_list needs to be a
135 vec<tree, va_gc> *because we want to tell the garbage collector about
137 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
139 /* A pointer to the base of a table of references to declaration
140 scopes. This table is a display which tracks the nesting
141 of declaration scopes at the current scope and containing
142 scopes. This table is used to find the proper place to
143 define type declaration DIE's. */
144 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
146 /* Pointers to various DWARF2 sections. */
147 static GTY(()) section
*debug_info_section
;
148 static GTY(()) section
*debug_skeleton_info_section
;
149 static GTY(()) section
*debug_abbrev_section
;
150 static GTY(()) section
*debug_skeleton_abbrev_section
;
151 static GTY(()) section
*debug_aranges_section
;
152 static GTY(()) section
*debug_addr_section
;
153 static GTY(()) section
*debug_macinfo_section
;
154 static GTY(()) section
*debug_line_section
;
155 static GTY(()) section
*debug_skeleton_line_section
;
156 static GTY(()) section
*debug_loc_section
;
157 static GTY(()) section
*debug_pubnames_section
;
158 static GTY(()) section
*debug_pubtypes_section
;
159 static GTY(()) section
*debug_str_section
;
160 static GTY(()) section
*debug_str_dwo_section
;
161 static GTY(()) section
*debug_str_offsets_section
;
162 static GTY(()) section
*debug_ranges_section
;
163 static GTY(()) section
*debug_frame_section
;
165 /* Maximum size (in bytes) of an artificially generated label. */
166 #define MAX_ARTIFICIAL_LABEL_BYTES 30
168 /* According to the (draft) DWARF 3 specification, the initial length
169 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
170 bytes are 0xffffffff, followed by the length stored in the next 8
173 However, the SGI/MIPS ABI uses an initial length which is equal to
174 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
176 #ifndef DWARF_INITIAL_LENGTH_SIZE
177 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
180 /* Round SIZE up to the nearest BOUNDARY. */
181 #define DWARF_ROUND(SIZE,BOUNDARY) \
182 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
184 /* CIE identifier. */
185 #if HOST_BITS_PER_WIDE_INT >= 64
186 #define DWARF_CIE_ID \
187 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
189 #define DWARF_CIE_ID DW_CIE_ID
193 /* A vector for a table that contains frame description
194 information for each routine. */
195 #define NOT_INDEXED (-1U)
196 #define NO_INDEX_ASSIGNED (-2U)
198 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
200 struct GTY(()) indirect_string_node
{
202 unsigned int refcount
;
203 enum dwarf_form form
;
208 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
210 /* With split_debug_info, both the comp_dir and dwo_name go in the
211 main object file, rather than the dwo, similar to the force_direct
212 parameter elsewhere but with additional complications:
214 1) The string is needed in both the main object file and the dwo.
215 That is, the comp_dir and dwo_name will appear in both places.
217 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
218 DW_FORM_GNU_str_index.
220 3) GCC chooses the form to use late, depending on the size and
223 Rather than forcing the all debug string handling functions and
224 callers to deal with these complications, simply use a separate,
225 special-cased string table for any attribute that should go in the
226 main object file. This limits the complexity to just the places
229 static GTY ((param_is (struct indirect_string_node
)))
230 htab_t skeleton_debug_str_hash
;
232 static GTY(()) int dw2_string_counter
;
234 /* True if the compilation unit places functions in more than one section. */
235 static GTY(()) bool have_multiple_function_sections
= false;
237 /* Whether the default text and cold text sections have been used at all. */
239 static GTY(()) bool text_section_used
= false;
240 static GTY(()) bool cold_text_section_used
= false;
242 /* The default cold text section. */
243 static GTY(()) section
*cold_text_section
;
245 /* Forward declarations for functions defined in this file. */
247 static char *stripattributes (const char *);
248 static void output_call_frame_info (int);
249 static void dwarf2out_note_section_used (void);
251 /* Personality decl of current unit. Used only when assembler does not support
253 static GTY(()) rtx current_unit_personality
;
255 /* Data and reference forms for relocatable data. */
256 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
257 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
259 #ifndef DEBUG_FRAME_SECTION
260 #define DEBUG_FRAME_SECTION ".debug_frame"
263 #ifndef FUNC_BEGIN_LABEL
264 #define FUNC_BEGIN_LABEL "LFB"
267 #ifndef FUNC_END_LABEL
268 #define FUNC_END_LABEL "LFE"
271 #ifndef PROLOGUE_END_LABEL
272 #define PROLOGUE_END_LABEL "LPE"
275 #ifndef EPILOGUE_BEGIN_LABEL
276 #define EPILOGUE_BEGIN_LABEL "LEB"
279 #ifndef FRAME_BEGIN_LABEL
280 #define FRAME_BEGIN_LABEL "Lframe"
282 #define CIE_AFTER_SIZE_LABEL "LSCIE"
283 #define CIE_END_LABEL "LECIE"
284 #define FDE_LABEL "LSFDE"
285 #define FDE_AFTER_SIZE_LABEL "LASFDE"
286 #define FDE_END_LABEL "LEFDE"
287 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
288 #define LINE_NUMBER_END_LABEL "LELT"
289 #define LN_PROLOG_AS_LABEL "LASLTP"
290 #define LN_PROLOG_END_LABEL "LELTP"
291 #define DIE_LABEL_PREFIX "DW"
293 /* Match the base name of a file to the base name of a compilation unit. */
296 matches_main_base (const char *path
)
298 /* Cache the last query. */
299 static const char *last_path
= NULL
;
300 static int last_match
= 0;
301 if (path
!= last_path
)
304 int length
= base_of_path (path
, &base
);
306 last_match
= (length
== main_input_baselength
307 && memcmp (base
, main_input_basename
, length
) == 0);
312 #ifdef DEBUG_DEBUG_STRUCT
315 dump_struct_debug (tree type
, enum debug_info_usage usage
,
316 enum debug_struct_file criterion
, int generic
,
317 int matches
, int result
)
319 /* Find the type name. */
320 tree type_decl
= TYPE_STUB_DECL (type
);
322 const char *name
= 0;
323 if (TREE_CODE (t
) == TYPE_DECL
)
326 name
= IDENTIFIER_POINTER (t
);
328 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
330 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
331 matches
? "bas" : "hdr",
332 generic
? "gen" : "ord",
333 usage
== DINFO_USAGE_DFN
? ";" :
334 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
336 (void*) type_decl
, name
);
339 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
340 dump_struct_debug (type, usage, criterion, generic, matches, result)
344 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
350 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
352 enum debug_struct_file criterion
;
354 bool generic
= lang_hooks
.types
.generic_p (type
);
357 criterion
= debug_struct_generic
[usage
];
359 criterion
= debug_struct_ordinary
[usage
];
361 if (criterion
== DINFO_STRUCT_FILE_NONE
)
362 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
363 if (criterion
== DINFO_STRUCT_FILE_ANY
)
364 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
366 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
368 if (type_decl
!= NULL
)
370 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
371 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
373 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
374 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
377 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
380 /* Return a pointer to a copy of the section string name S with all
381 attributes stripped off, and an asterisk prepended (for assemble_name). */
384 stripattributes (const char *s
)
386 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
391 while (*s
&& *s
!= ',')
398 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
399 switch to the data section instead, and write out a synthetic start label
400 for collect2 the first time around. */
403 switch_to_eh_frame_section (bool back
)
407 #ifdef EH_FRAME_SECTION_NAME
408 if (eh_frame_section
== 0)
412 if (EH_TABLES_CAN_BE_READ_ONLY
)
418 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
420 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
422 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
425 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
426 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
427 && (per_encoding
& 0x70) != DW_EH_PE_absptr
428 && (per_encoding
& 0x70) != DW_EH_PE_aligned
429 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
430 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
431 ? 0 : SECTION_WRITE
);
434 flags
= SECTION_WRITE
;
435 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
437 #endif /* EH_FRAME_SECTION_NAME */
439 if (eh_frame_section
)
440 switch_to_section (eh_frame_section
);
443 /* We have no special eh_frame section. Put the information in
444 the data section and emit special labels to guide collect2. */
445 switch_to_section (data_section
);
449 label
= get_file_function_name ("F");
450 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
451 targetm
.asm_out
.globalize_label (asm_out_file
,
452 IDENTIFIER_POINTER (label
));
453 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
458 /* Switch [BACK] to the eh or debug frame table section, depending on
462 switch_to_frame_table_section (int for_eh
, bool back
)
465 switch_to_eh_frame_section (back
);
468 if (!debug_frame_section
)
469 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
470 SECTION_DEBUG
, NULL
);
471 switch_to_section (debug_frame_section
);
475 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
477 enum dw_cfi_oprnd_type
478 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
483 case DW_CFA_GNU_window_save
:
484 case DW_CFA_remember_state
:
485 case DW_CFA_restore_state
:
486 return dw_cfi_oprnd_unused
;
489 case DW_CFA_advance_loc1
:
490 case DW_CFA_advance_loc2
:
491 case DW_CFA_advance_loc4
:
492 case DW_CFA_MIPS_advance_loc8
:
493 return dw_cfi_oprnd_addr
;
496 case DW_CFA_offset_extended
:
498 case DW_CFA_offset_extended_sf
:
499 case DW_CFA_def_cfa_sf
:
501 case DW_CFA_restore_extended
:
502 case DW_CFA_undefined
:
503 case DW_CFA_same_value
:
504 case DW_CFA_def_cfa_register
:
505 case DW_CFA_register
:
506 case DW_CFA_expression
:
507 return dw_cfi_oprnd_reg_num
;
509 case DW_CFA_def_cfa_offset
:
510 case DW_CFA_GNU_args_size
:
511 case DW_CFA_def_cfa_offset_sf
:
512 return dw_cfi_oprnd_offset
;
514 case DW_CFA_def_cfa_expression
:
515 return dw_cfi_oprnd_loc
;
522 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
524 enum dw_cfi_oprnd_type
525 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
530 case DW_CFA_def_cfa_sf
:
532 case DW_CFA_offset_extended_sf
:
533 case DW_CFA_offset_extended
:
534 return dw_cfi_oprnd_offset
;
536 case DW_CFA_register
:
537 return dw_cfi_oprnd_reg_num
;
539 case DW_CFA_expression
:
540 return dw_cfi_oprnd_loc
;
543 return dw_cfi_oprnd_unused
;
547 /* Output one FDE. */
550 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
551 char *section_start_label
, int fde_encoding
, char *augmentation
,
552 bool any_lsda_needed
, int lsda_encoding
)
554 const char *begin
, *end
;
555 static unsigned int j
;
558 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
560 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
562 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
563 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
564 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
565 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
566 " indicating 64-bit DWARF extension");
567 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
569 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
572 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
574 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
575 debug_frame_section
, "FDE CIE offset");
577 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
578 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
582 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
583 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
584 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
585 "FDE initial location");
586 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
587 end
, begin
, "FDE address range");
591 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
592 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
599 int size
= size_of_encoded_value (lsda_encoding
);
601 if (lsda_encoding
== DW_EH_PE_aligned
)
603 int offset
= ( 4 /* Length */
605 + 2 * size_of_encoded_value (fde_encoding
)
606 + 1 /* Augmentation size */ );
607 int pad
= -offset
& (PTR_SIZE
- 1);
610 gcc_assert (size_of_uleb128 (size
) == 1);
613 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
615 if (fde
->uses_eh_lsda
)
617 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
618 fde
->funcdef_number
);
619 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
620 gen_rtx_SYMBOL_REF (Pmode
, l1
),
622 "Language Specific Data Area");
626 if (lsda_encoding
== DW_EH_PE_aligned
)
627 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
628 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
629 "Language Specific Data Area (none)");
633 dw2_asm_output_data_uleb128 (0, "Augmentation size");
636 /* Loop through the Call Frame Instructions associated with this FDE. */
637 fde
->dw_fde_current_label
= begin
;
639 size_t from
, until
, i
;
642 until
= vec_safe_length (fde
->dw_fde_cfi
);
644 if (fde
->dw_fde_second_begin
== NULL
)
647 until
= fde
->dw_fde_switch_cfi_index
;
649 from
= fde
->dw_fde_switch_cfi_index
;
651 for (i
= from
; i
< until
; i
++)
652 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
655 /* If we are to emit a ref/link from function bodies to their frame tables,
656 do it now. This is typically performed to make sure that tables
657 associated with functions are dragged with them and not discarded in
658 garbage collecting links. We need to do this on a per function basis to
659 cope with -ffunction-sections. */
661 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
662 /* Switch to the function section, emit the ref to the tables, and
663 switch *back* into the table section. */
664 switch_to_section (function_section (fde
->decl
));
665 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
666 switch_to_frame_table_section (for_eh
, true);
669 /* Pad the FDE out to an address sized boundary. */
670 ASM_OUTPUT_ALIGN (asm_out_file
,
671 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
672 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
677 /* Return true if frame description entry FDE is needed for EH. */
680 fde_needed_for_eh_p (dw_fde_ref fde
)
682 if (flag_asynchronous_unwind_tables
)
685 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
688 if (fde
->uses_eh_lsda
)
691 /* If exceptions are enabled, we have collected nothrow info. */
692 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
698 /* Output the call frame information used to record information
699 that relates to calculating the frame pointer, and records the
700 location of saved registers. */
703 output_call_frame_info (int for_eh
)
708 char l1
[20], l2
[20], section_start_label
[20];
709 bool any_lsda_needed
= false;
710 char augmentation
[6];
711 int augmentation_size
;
712 int fde_encoding
= DW_EH_PE_absptr
;
713 int per_encoding
= DW_EH_PE_absptr
;
714 int lsda_encoding
= DW_EH_PE_absptr
;
716 rtx personality
= NULL
;
719 /* Don't emit a CIE if there won't be any FDEs. */
723 /* Nothing to do if the assembler's doing it all. */
724 if (dwarf2out_do_cfi_asm ())
727 /* If we don't have any functions we'll want to unwind out of, don't emit
728 any EH unwind information. If we make FDEs linkonce, we may have to
729 emit an empty label for an FDE that wouldn't otherwise be emitted. We
730 want to avoid having an FDE kept around when the function it refers to
731 is discarded. Example where this matters: a primary function template
732 in C++ requires EH information, an explicit specialization doesn't. */
735 bool any_eh_needed
= false;
737 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
739 if (fde
->uses_eh_lsda
)
740 any_eh_needed
= any_lsda_needed
= true;
741 else if (fde_needed_for_eh_p (fde
))
742 any_eh_needed
= true;
743 else if (TARGET_USES_WEAK_UNWIND_INFO
)
744 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
751 /* We're going to be generating comments, so turn on app. */
755 /* Switch to the proper frame section, first time. */
756 switch_to_frame_table_section (for_eh
, false);
758 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
759 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
761 /* Output the CIE. */
762 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
763 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
764 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
765 dw2_asm_output_data (4, 0xffffffff,
766 "Initial length escape value indicating 64-bit DWARF extension");
767 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
768 "Length of Common Information Entry");
769 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
771 /* Now that the CIE pointer is PC-relative for EH,
772 use 0 to identify the CIE. */
773 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
774 (for_eh
? 0 : DWARF_CIE_ID
),
775 "CIE Identifier Tag");
777 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
778 use CIE version 1, unless that would produce incorrect results
779 due to overflowing the return register column. */
780 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
782 if (return_reg
>= 256 || dwarf_version
> 2)
784 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
787 augmentation_size
= 0;
789 personality
= current_unit_personality
;
795 z Indicates that a uleb128 is present to size the
796 augmentation section.
797 L Indicates the encoding (and thus presence) of
798 an LSDA pointer in the FDE augmentation.
799 R Indicates a non-default pointer encoding for
801 P Indicates the presence of an encoding + language
802 personality routine in the CIE augmentation. */
804 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
805 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
806 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
808 p
= augmentation
+ 1;
812 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
813 assemble_external_libcall (personality
);
818 augmentation_size
+= 1;
820 if (fde_encoding
!= DW_EH_PE_absptr
)
823 augmentation_size
+= 1;
825 if (p
> augmentation
+ 1)
827 augmentation
[0] = 'z';
831 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
832 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
834 int offset
= ( 4 /* Length */
836 + 1 /* CIE version */
837 + strlen (augmentation
) + 1 /* Augmentation */
838 + size_of_uleb128 (1) /* Code alignment */
839 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
841 + 1 /* Augmentation size */
842 + 1 /* Personality encoding */ );
843 int pad
= -offset
& (PTR_SIZE
- 1);
845 augmentation_size
+= pad
;
847 /* Augmentations should be small, so there's scarce need to
848 iterate for a solution. Die if we exceed one uleb128 byte. */
849 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
853 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
854 if (dw_cie_version
>= 4)
856 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
857 dw2_asm_output_data (1, 0, "CIE Segment Size");
859 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
860 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
861 "CIE Data Alignment Factor");
863 if (dw_cie_version
== 1)
864 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
866 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
870 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
873 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
874 eh_data_format_name (per_encoding
));
875 dw2_asm_output_encoded_addr_rtx (per_encoding
,
881 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
882 eh_data_format_name (lsda_encoding
));
884 if (fde_encoding
!= DW_EH_PE_absptr
)
885 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
886 eh_data_format_name (fde_encoding
));
889 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
890 output_cfi (cfi
, NULL
, for_eh
);
892 /* Pad the CIE out to an address sized boundary. */
893 ASM_OUTPUT_ALIGN (asm_out_file
,
894 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
895 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
897 /* Loop through all of the FDE's. */
898 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
902 /* Don't emit EH unwind info for leaf functions that don't need it. */
903 if (for_eh
&& !fde_needed_for_eh_p (fde
))
906 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
907 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
908 augmentation
, any_lsda_needed
, lsda_encoding
);
911 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
912 dw2_asm_output_data (4, 0, "End of Table");
914 /* Turn off app to make assembly quicker. */
919 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
922 dwarf2out_do_cfi_startproc (bool second
)
926 rtx personality
= get_personality_function (current_function_decl
);
928 fprintf (asm_out_file
, "\t.cfi_startproc\n");
932 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
935 /* ??? The GAS support isn't entirely consistent. We have to
936 handle indirect support ourselves, but PC-relative is done
937 in the assembler. Further, the assembler can't handle any
938 of the weirder relocation types. */
939 if (enc
& DW_EH_PE_indirect
)
940 ref
= dw2_force_const_mem (ref
, true);
942 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
943 output_addr_const (asm_out_file
, ref
);
944 fputc ('\n', asm_out_file
);
947 if (crtl
->uses_eh_lsda
)
951 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
952 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
953 current_function_funcdef_no
);
954 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
955 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
957 if (enc
& DW_EH_PE_indirect
)
958 ref
= dw2_force_const_mem (ref
, true);
960 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
961 output_addr_const (asm_out_file
, ref
);
962 fputc ('\n', asm_out_file
);
966 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
967 this allocation may be done before pass_final. */
970 dwarf2out_alloc_current_fde (void)
974 fde
= ggc_alloc_cleared_dw_fde_node ();
975 fde
->decl
= current_function_decl
;
976 fde
->funcdef_number
= current_function_funcdef_no
;
977 fde
->fde_index
= vec_safe_length (fde_vec
);
978 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
979 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
980 fde
->nothrow
= crtl
->nothrow
;
981 fde
->drap_reg
= INVALID_REGNUM
;
982 fde
->vdrap_reg
= INVALID_REGNUM
;
984 /* Record the FDE associated with this function. */
986 vec_safe_push (fde_vec
, fde
);
991 /* Output a marker (i.e. a label) for the beginning of a function, before
995 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
996 const char *file ATTRIBUTE_UNUSED
)
998 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1004 current_function_func_begin_label
= NULL
;
1006 do_frame
= dwarf2out_do_frame ();
1008 /* ??? current_function_func_begin_label is also used by except.c for
1009 call-site information. We must emit this label if it might be used. */
1011 && (!flag_exceptions
1012 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1015 fnsec
= function_section (current_function_decl
);
1016 switch_to_section (fnsec
);
1017 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1018 current_function_funcdef_no
);
1019 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1020 current_function_funcdef_no
);
1021 dup_label
= xstrdup (label
);
1022 current_function_func_begin_label
= dup_label
;
1024 /* We can elide the fde allocation if we're not emitting debug info. */
1028 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1029 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1030 would include pass_dwarf2_frame. If we've not created the FDE yet,
1034 fde
= dwarf2out_alloc_current_fde ();
1036 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1037 fde
->dw_fde_begin
= dup_label
;
1038 fde
->dw_fde_current_label
= dup_label
;
1039 fde
->in_std_section
= (fnsec
== text_section
1040 || (cold_text_section
&& fnsec
== cold_text_section
));
1042 /* We only want to output line number information for the genuine dwarf2
1043 prologue case, not the eh frame case. */
1044 #ifdef DWARF2_DEBUGGING_INFO
1046 dwarf2out_source_line (line
, file
, 0, true);
1049 if (dwarf2out_do_cfi_asm ())
1050 dwarf2out_do_cfi_startproc (false);
1053 rtx personality
= get_personality_function (current_function_decl
);
1054 if (!current_unit_personality
)
1055 current_unit_personality
= personality
;
1057 /* We cannot keep a current personality per function as without CFI
1058 asm, at the point where we emit the CFI data, there is no current
1059 function anymore. */
1060 if (personality
&& current_unit_personality
!= personality
)
1061 sorry ("multiple EH personalities are supported only with assemblers "
1062 "supporting .cfi_personality directive");
1066 /* Output a marker (i.e. a label) for the end of the generated code
1067 for a function prologue. This gets called *after* the prologue code has
1071 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1072 const char *file ATTRIBUTE_UNUSED
)
1074 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1076 /* Output a label to mark the endpoint of the code generated for this
1078 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1079 current_function_funcdef_no
);
1080 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1081 current_function_funcdef_no
);
1082 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1085 /* Output a marker (i.e. a label) for the beginning of the generated code
1086 for a function epilogue. This gets called *before* the prologue code has
1090 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1091 const char *file ATTRIBUTE_UNUSED
)
1093 dw_fde_ref fde
= cfun
->fde
;
1094 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1096 if (fde
->dw_fde_vms_begin_epilogue
)
1099 /* Output a label to mark the endpoint of the code generated for this
1101 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1102 current_function_funcdef_no
);
1103 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1104 current_function_funcdef_no
);
1105 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1108 /* Output a marker (i.e. a label) for the absolute end of the generated code
1109 for a function definition. This gets called *after* the epilogue code has
1113 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1114 const char *file ATTRIBUTE_UNUSED
)
1117 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1119 last_var_location_insn
= NULL_RTX
;
1120 cached_next_real_insn
= NULL_RTX
;
1122 if (dwarf2out_do_cfi_asm ())
1123 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1125 /* Output a label to mark the endpoint of the code generated for this
1127 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1128 current_function_funcdef_no
);
1129 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1131 gcc_assert (fde
!= NULL
);
1132 if (fde
->dw_fde_second_begin
== NULL
)
1133 fde
->dw_fde_end
= xstrdup (label
);
1137 dwarf2out_frame_finish (void)
1139 /* Output call frame information. */
1140 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1141 output_call_frame_info (0);
1143 /* Output another copy for the unwinder. */
1144 if ((flag_unwind_tables
|| flag_exceptions
)
1145 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1146 output_call_frame_info (1);
1149 /* Note that the current function section is being used for code. */
1152 dwarf2out_note_section_used (void)
1154 section
*sec
= current_function_section ();
1155 if (sec
== text_section
)
1156 text_section_used
= true;
1157 else if (sec
== cold_text_section
)
1158 cold_text_section_used
= true;
1161 static void var_location_switch_text_section (void);
1162 static void set_cur_line_info_table (section
*);
1165 dwarf2out_switch_text_section (void)
1168 dw_fde_ref fde
= cfun
->fde
;
1170 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1172 if (!in_cold_section_p
)
1174 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1175 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1176 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1180 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1181 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1182 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1184 have_multiple_function_sections
= true;
1186 /* There is no need to mark used sections when not debugging. */
1187 if (cold_text_section
!= NULL
)
1188 dwarf2out_note_section_used ();
1190 if (dwarf2out_do_cfi_asm ())
1191 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1193 /* Now do the real section switch. */
1194 sect
= current_function_section ();
1195 switch_to_section (sect
);
1197 fde
->second_in_std_section
1198 = (sect
== text_section
1199 || (cold_text_section
&& sect
== cold_text_section
));
1201 if (dwarf2out_do_cfi_asm ())
1202 dwarf2out_do_cfi_startproc (true);
1204 var_location_switch_text_section ();
1206 if (cold_text_section
!= NULL
)
1207 set_cur_line_info_table (sect
);
1210 /* And now, the subset of the debugging information support code necessary
1211 for emitting location expressions. */
1213 /* Data about a single source file. */
1214 struct GTY(()) dwarf_file_data
{
1215 const char * filename
;
1219 typedef struct GTY(()) deferred_locations_struct
1223 } deferred_locations
;
1226 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1229 /* Describe an entry into the .debug_addr section. */
1233 ate_kind_rtx_dtprel
,
1237 typedef struct GTY(()) addr_table_entry_struct
{
1239 unsigned int refcount
;
1241 union addr_table_entry_struct_union
1243 rtx
GTY ((tag ("0"))) rtl
;
1244 char * GTY ((tag ("1"))) label
;
1246 GTY ((desc ("%1.kind"))) addr
;
1250 /* Location lists are ranges + location descriptions for that range,
1251 so you can track variables that are in different places over
1252 their entire life. */
1253 typedef struct GTY(()) dw_loc_list_struct
{
1254 dw_loc_list_ref dw_loc_next
;
1255 const char *begin
; /* Label and addr_entry for start of range */
1256 addr_table_entry
*begin_entry
;
1257 const char *end
; /* Label for end of range */
1258 char *ll_symbol
; /* Label for beginning of location list.
1259 Only on head of list */
1260 const char *section
; /* Section this loclist is relative to */
1261 dw_loc_descr_ref expr
;
1263 /* True if all addresses in this and subsequent lists are known to be
1266 /* True if this list has been replaced by dw_loc_next. */
1269 /* True if the range should be emitted even if begin and end
1274 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1276 /* Convert a DWARF stack opcode into its string name. */
1279 dwarf_stack_op_name (unsigned int op
)
1281 const char *name
= get_DW_OP_name (op
);
1286 return "OP_<unknown>";
1289 /* Return a pointer to a newly allocated location description. Location
1290 descriptions are simple expression terms that can be strung
1291 together to form more complicated location (address) descriptions. */
1293 static inline dw_loc_descr_ref
1294 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1295 unsigned HOST_WIDE_INT oprnd2
)
1297 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1299 descr
->dw_loc_opc
= op
;
1300 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1301 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1302 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1303 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1304 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1305 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1310 /* Return a pointer to a newly allocated location description for
1313 static inline dw_loc_descr_ref
1314 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1317 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1320 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1323 /* Add a location description term to a location description expression. */
1326 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1328 dw_loc_descr_ref
*d
;
1330 /* Find the end of the chain. */
1331 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1337 /* Compare two location operands for exact equality. */
1340 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1342 if (a
->val_class
!= b
->val_class
)
1344 switch (a
->val_class
)
1346 case dw_val_class_none
:
1348 case dw_val_class_addr
:
1349 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1351 case dw_val_class_offset
:
1352 case dw_val_class_unsigned_const
:
1353 case dw_val_class_const
:
1354 case dw_val_class_range_list
:
1355 case dw_val_class_lineptr
:
1356 case dw_val_class_macptr
:
1357 /* These are all HOST_WIDE_INT, signed or unsigned. */
1358 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1360 case dw_val_class_loc
:
1361 return a
->v
.val_loc
== b
->v
.val_loc
;
1362 case dw_val_class_loc_list
:
1363 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1364 case dw_val_class_die_ref
:
1365 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1366 case dw_val_class_fde_ref
:
1367 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1368 case dw_val_class_lbl_id
:
1369 case dw_val_class_high_pc
:
1370 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1371 case dw_val_class_str
:
1372 return a
->v
.val_str
== b
->v
.val_str
;
1373 case dw_val_class_flag
:
1374 return a
->v
.val_flag
== b
->v
.val_flag
;
1375 case dw_val_class_file
:
1376 return a
->v
.val_file
== b
->v
.val_file
;
1377 case dw_val_class_decl_ref
:
1378 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1380 case dw_val_class_const_double
:
1381 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1382 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1384 case dw_val_class_vec
:
1386 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1387 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1389 return (a_len
== b_len
1390 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1393 case dw_val_class_data8
:
1394 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1396 case dw_val_class_vms_delta
:
1397 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1398 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1403 /* Compare two location atoms for exact equality. */
1406 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1408 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1411 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1412 address size, but since we always allocate cleared storage it
1413 should be zero for other types of locations. */
1414 if (a
->dtprel
!= b
->dtprel
)
1417 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1418 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1421 /* Compare two complete location expressions for exact equality. */
1424 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1430 if (a
== NULL
|| b
== NULL
)
1432 if (!loc_descr_equal_p_1 (a
, b
))
1441 /* Add a constant OFFSET to a location expression. */
1444 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1446 dw_loc_descr_ref loc
;
1449 gcc_assert (*list_head
!= NULL
);
1454 /* Find the end of the chain. */
1455 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1459 if (loc
->dw_loc_opc
== DW_OP_fbreg
1460 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1461 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1462 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1463 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1465 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1466 offset. Don't optimize if an signed integer overflow would happen. */
1468 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1469 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1472 else if (offset
> 0)
1473 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1477 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1478 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1482 /* Add a constant OFFSET to a location list. */
1485 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1488 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1489 loc_descr_plus_const (&d
->expr
, offset
);
1492 #define DWARF_REF_SIZE \
1493 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1495 static unsigned long int get_base_type_offset (dw_die_ref
);
1497 /* Return the size of a location descriptor. */
1499 static unsigned long
1500 size_of_loc_descr (dw_loc_descr_ref loc
)
1502 unsigned long size
= 1;
1504 switch (loc
->dw_loc_opc
)
1507 size
+= DWARF2_ADDR_SIZE
;
1509 case DW_OP_GNU_addr_index
:
1510 case DW_OP_GNU_const_index
:
1511 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1512 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1531 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1534 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1539 case DW_OP_plus_uconst
:
1540 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1578 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1581 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1584 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1587 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1588 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1591 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1593 case DW_OP_bit_piece
:
1594 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1595 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1597 case DW_OP_deref_size
:
1598 case DW_OP_xderef_size
:
1607 case DW_OP_call_ref
:
1608 size
+= DWARF_REF_SIZE
;
1610 case DW_OP_implicit_value
:
1611 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1612 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1614 case DW_OP_GNU_implicit_pointer
:
1615 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1617 case DW_OP_GNU_entry_value
:
1619 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1620 size
+= size_of_uleb128 (op_size
) + op_size
;
1623 case DW_OP_GNU_const_type
:
1626 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1627 size
+= size_of_uleb128 (o
) + 1;
1628 switch (loc
->dw_loc_oprnd2
.val_class
)
1630 case dw_val_class_vec
:
1631 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1632 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1634 case dw_val_class_const
:
1635 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1637 case dw_val_class_const_double
:
1638 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1645 case DW_OP_GNU_regval_type
:
1648 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1649 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1650 + size_of_uleb128 (o
);
1653 case DW_OP_GNU_deref_type
:
1656 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1657 size
+= 1 + size_of_uleb128 (o
);
1660 case DW_OP_GNU_convert
:
1661 case DW_OP_GNU_reinterpret
:
1662 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1663 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1667 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1668 size
+= size_of_uleb128 (o
);
1671 case DW_OP_GNU_parameter_ref
:
1681 /* Return the size of a series of location descriptors. */
1684 size_of_locs (dw_loc_descr_ref loc
)
1689 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1690 field, to avoid writing to a PCH file. */
1691 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1693 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1695 size
+= size_of_loc_descr (l
);
1700 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1702 l
->dw_loc_addr
= size
;
1703 size
+= size_of_loc_descr (l
);
1709 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1710 static void get_ref_die_offset_label (char *, dw_die_ref
);
1711 static unsigned long int get_ref_die_offset (dw_die_ref
);
1713 /* Output location description stack opcode's operands (if any).
1714 The for_eh_or_skip parameter controls whether register numbers are
1715 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1716 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1717 info). This should be suppressed for the cases that have not been converted
1718 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1721 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1723 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1724 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1726 switch (loc
->dw_loc_opc
)
1728 #ifdef DWARF2_DEBUGGING_INFO
1731 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1736 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1737 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1739 fputc ('\n', asm_out_file
);
1744 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1749 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1750 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1752 fputc ('\n', asm_out_file
);
1757 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1758 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1765 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1766 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1768 dw2_asm_output_data (2, offset
, NULL
);
1771 case DW_OP_implicit_value
:
1772 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1773 switch (val2
->val_class
)
1775 case dw_val_class_const
:
1776 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1778 case dw_val_class_vec
:
1780 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1781 unsigned int len
= val2
->v
.val_vec
.length
;
1785 if (elt_size
> sizeof (HOST_WIDE_INT
))
1790 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1793 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1794 "fp or vector constant word %u", i
);
1797 case dw_val_class_const_double
:
1799 unsigned HOST_WIDE_INT first
, second
;
1801 if (WORDS_BIG_ENDIAN
)
1803 first
= val2
->v
.val_double
.high
;
1804 second
= val2
->v
.val_double
.low
;
1808 first
= val2
->v
.val_double
.low
;
1809 second
= val2
->v
.val_double
.high
;
1811 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1813 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1817 case dw_val_class_addr
:
1818 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1819 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1834 case DW_OP_implicit_value
:
1835 /* We currently don't make any attempt to make sure these are
1836 aligned properly like we do for the main unwind info, so
1837 don't support emitting things larger than a byte if we're
1838 only doing unwinding. */
1843 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1846 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1849 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1852 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1854 case DW_OP_plus_uconst
:
1855 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1889 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1893 unsigned r
= val1
->v
.val_unsigned
;
1894 if (for_eh_or_skip
>= 0)
1895 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1896 gcc_assert (size_of_uleb128 (r
)
1897 == size_of_uleb128 (val1
->v
.val_unsigned
));
1898 dw2_asm_output_data_uleb128 (r
, NULL
);
1902 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1906 unsigned r
= val1
->v
.val_unsigned
;
1907 if (for_eh_or_skip
>= 0)
1908 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1909 gcc_assert (size_of_uleb128 (r
)
1910 == size_of_uleb128 (val1
->v
.val_unsigned
));
1911 dw2_asm_output_data_uleb128 (r
, NULL
);
1912 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1916 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1918 case DW_OP_bit_piece
:
1919 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1920 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1922 case DW_OP_deref_size
:
1923 case DW_OP_xderef_size
:
1924 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1930 if (targetm
.asm_out
.output_dwarf_dtprel
)
1932 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1935 fputc ('\n', asm_out_file
);
1942 #ifdef DWARF2_DEBUGGING_INFO
1943 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1950 case DW_OP_GNU_addr_index
:
1951 case DW_OP_GNU_const_index
:
1952 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1953 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1954 "(index into .debug_addr)");
1957 case DW_OP_GNU_implicit_pointer
:
1959 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1960 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1961 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1962 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1963 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1964 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1968 case DW_OP_GNU_entry_value
:
1969 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1970 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1973 case DW_OP_GNU_const_type
:
1975 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1977 dw2_asm_output_data_uleb128 (o
, NULL
);
1978 switch (val2
->val_class
)
1980 case dw_val_class_const
:
1981 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1982 dw2_asm_output_data (1, l
, NULL
);
1983 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1985 case dw_val_class_vec
:
1987 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1988 unsigned int len
= val2
->v
.val_vec
.length
;
1993 dw2_asm_output_data (1, l
, NULL
);
1994 if (elt_size
> sizeof (HOST_WIDE_INT
))
1999 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2002 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2003 "fp or vector constant word %u", i
);
2006 case dw_val_class_const_double
:
2008 unsigned HOST_WIDE_INT first
, second
;
2009 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2011 dw2_asm_output_data (1, 2 * l
, NULL
);
2012 if (WORDS_BIG_ENDIAN
)
2014 first
= val2
->v
.val_double
.high
;
2015 second
= val2
->v
.val_double
.low
;
2019 first
= val2
->v
.val_double
.low
;
2020 second
= val2
->v
.val_double
.high
;
2022 dw2_asm_output_data (l
, first
, NULL
);
2023 dw2_asm_output_data (l
, second
, NULL
);
2031 case DW_OP_GNU_regval_type
:
2033 unsigned r
= val1
->v
.val_unsigned
;
2034 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2036 if (for_eh_or_skip
>= 0)
2038 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2039 gcc_assert (size_of_uleb128 (r
)
2040 == size_of_uleb128 (val1
->v
.val_unsigned
));
2042 dw2_asm_output_data_uleb128 (r
, NULL
);
2043 dw2_asm_output_data_uleb128 (o
, NULL
);
2046 case DW_OP_GNU_deref_type
:
2048 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2050 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2051 dw2_asm_output_data_uleb128 (o
, NULL
);
2054 case DW_OP_GNU_convert
:
2055 case DW_OP_GNU_reinterpret
:
2056 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2057 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2060 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2062 dw2_asm_output_data_uleb128 (o
, NULL
);
2066 case DW_OP_GNU_parameter_ref
:
2069 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2070 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2071 dw2_asm_output_data (4, o
, NULL
);
2076 /* Other codes have no operands. */
2081 /* Output a sequence of location operations.
2082 The for_eh_or_skip parameter controls whether register numbers are
2083 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2084 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2085 info). This should be suppressed for the cases that have not been converted
2086 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2089 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2091 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2093 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2094 /* Output the opcode. */
2095 if (for_eh_or_skip
>= 0
2096 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2098 unsigned r
= (opc
- DW_OP_breg0
);
2099 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2100 gcc_assert (r
<= 31);
2101 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2103 else if (for_eh_or_skip
>= 0
2104 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2106 unsigned r
= (opc
- DW_OP_reg0
);
2107 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2108 gcc_assert (r
<= 31);
2109 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2112 dw2_asm_output_data (1, opc
,
2113 "%s", dwarf_stack_op_name (opc
));
2115 /* Output the operand(s) (if any). */
2116 output_loc_operands (loc
, for_eh_or_skip
);
2120 /* Output location description stack opcode's operands (if any).
2121 The output is single bytes on a line, suitable for .cfi_escape. */
2124 output_loc_operands_raw (dw_loc_descr_ref loc
)
2126 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2127 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2129 switch (loc
->dw_loc_opc
)
2132 case DW_OP_GNU_addr_index
:
2133 case DW_OP_GNU_const_index
:
2134 case DW_OP_implicit_value
:
2135 /* We cannot output addresses in .cfi_escape, only bytes. */
2141 case DW_OP_deref_size
:
2142 case DW_OP_xderef_size
:
2143 fputc (',', asm_out_file
);
2144 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2149 fputc (',', asm_out_file
);
2150 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2155 fputc (',', asm_out_file
);
2156 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2161 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2162 fputc (',', asm_out_file
);
2163 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2171 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2172 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2174 fputc (',', asm_out_file
);
2175 dw2_asm_output_data_raw (2, offset
);
2181 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2182 gcc_assert (size_of_uleb128 (r
)
2183 == size_of_uleb128 (val1
->v
.val_unsigned
));
2184 fputc (',', asm_out_file
);
2185 dw2_asm_output_data_uleb128_raw (r
);
2190 case DW_OP_plus_uconst
:
2192 fputc (',', asm_out_file
);
2193 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2196 case DW_OP_bit_piece
:
2197 fputc (',', asm_out_file
);
2198 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2199 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2236 fputc (',', asm_out_file
);
2237 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2242 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2243 gcc_assert (size_of_uleb128 (r
)
2244 == size_of_uleb128 (val1
->v
.val_unsigned
));
2245 fputc (',', asm_out_file
);
2246 dw2_asm_output_data_uleb128_raw (r
);
2247 fputc (',', asm_out_file
);
2248 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2252 case DW_OP_GNU_implicit_pointer
:
2253 case DW_OP_GNU_entry_value
:
2254 case DW_OP_GNU_const_type
:
2255 case DW_OP_GNU_regval_type
:
2256 case DW_OP_GNU_deref_type
:
2257 case DW_OP_GNU_convert
:
2258 case DW_OP_GNU_reinterpret
:
2259 case DW_OP_GNU_parameter_ref
:
2264 /* Other codes have no operands. */
2270 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2274 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2275 /* Output the opcode. */
2276 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2278 unsigned r
= (opc
- DW_OP_breg0
);
2279 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2280 gcc_assert (r
<= 31);
2281 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2283 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2285 unsigned r
= (opc
- DW_OP_reg0
);
2286 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2287 gcc_assert (r
<= 31);
2288 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2290 /* Output the opcode. */
2291 fprintf (asm_out_file
, "%#x", opc
);
2292 output_loc_operands_raw (loc
);
2294 if (!loc
->dw_loc_next
)
2296 loc
= loc
->dw_loc_next
;
2298 fputc (',', asm_out_file
);
2302 /* This function builds a dwarf location descriptor sequence from a
2303 dw_cfa_location, adding the given OFFSET to the result of the
2306 struct dw_loc_descr_struct
*
2307 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2309 struct dw_loc_descr_struct
*head
, *tmp
;
2311 offset
+= cfa
->offset
;
2315 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2316 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2317 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2318 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2319 add_loc_descr (&head
, tmp
);
2322 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2323 add_loc_descr (&head
, tmp
);
2327 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2332 /* This function builds a dwarf location descriptor sequence for
2333 the address at OFFSET from the CFA when stack is aligned to
2336 struct dw_loc_descr_struct
*
2337 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2338 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2340 struct dw_loc_descr_struct
*head
;
2341 unsigned int dwarf_fp
2342 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2344 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2345 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2347 head
= new_reg_loc_descr (dwarf_fp
, 0);
2348 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2349 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2350 loc_descr_plus_const (&head
, offset
);
2353 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2357 /* And now, the support for symbolic debugging information. */
2359 /* .debug_str support. */
2360 static int output_indirect_string (void **, void *);
2362 static void dwarf2out_init (const char *);
2363 static void dwarf2out_finish (const char *);
2364 static void dwarf2out_assembly_start (void);
2365 static void dwarf2out_define (unsigned int, const char *);
2366 static void dwarf2out_undef (unsigned int, const char *);
2367 static void dwarf2out_start_source_file (unsigned, const char *);
2368 static void dwarf2out_end_source_file (unsigned);
2369 static void dwarf2out_function_decl (tree
);
2370 static void dwarf2out_begin_block (unsigned, unsigned);
2371 static void dwarf2out_end_block (unsigned, unsigned);
2372 static bool dwarf2out_ignore_block (const_tree
);
2373 static void dwarf2out_global_decl (tree
);
2374 static void dwarf2out_type_decl (tree
, int);
2375 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2376 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2378 static void dwarf2out_abstract_function (tree
);
2379 static void dwarf2out_var_location (rtx
);
2380 static void dwarf2out_begin_function (tree
);
2381 static void dwarf2out_end_function (unsigned int);
2382 static void dwarf2out_set_name (tree
, tree
);
2384 /* The debug hooks structure. */
2386 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2390 dwarf2out_assembly_start
,
2393 dwarf2out_start_source_file
,
2394 dwarf2out_end_source_file
,
2395 dwarf2out_begin_block
,
2396 dwarf2out_end_block
,
2397 dwarf2out_ignore_block
,
2398 dwarf2out_source_line
,
2399 dwarf2out_begin_prologue
,
2400 #if VMS_DEBUGGING_INFO
2401 dwarf2out_vms_end_prologue
,
2402 dwarf2out_vms_begin_epilogue
,
2404 debug_nothing_int_charstar
,
2405 debug_nothing_int_charstar
,
2407 dwarf2out_end_epilogue
,
2408 dwarf2out_begin_function
,
2409 dwarf2out_end_function
, /* end_function */
2410 dwarf2out_function_decl
, /* function_decl */
2411 dwarf2out_global_decl
,
2412 dwarf2out_type_decl
, /* type_decl */
2413 dwarf2out_imported_module_or_decl
,
2414 debug_nothing_tree
, /* deferred_inline_function */
2415 /* The DWARF 2 backend tries to reduce debugging bloat by not
2416 emitting the abstract description of inline functions until
2417 something tries to reference them. */
2418 dwarf2out_abstract_function
, /* outlining_inline_function */
2419 debug_nothing_rtx
, /* label */
2420 debug_nothing_int
, /* handle_pch */
2421 dwarf2out_var_location
,
2422 dwarf2out_switch_text_section
,
2424 1, /* start_end_main_source_file */
2425 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2428 /* NOTE: In the comments in this file, many references are made to
2429 "Debugging Information Entries". This term is abbreviated as `DIE'
2430 throughout the remainder of this file. */
2432 /* An internal representation of the DWARF output is built, and then
2433 walked to generate the DWARF debugging info. The walk of the internal
2434 representation is done after the entire program has been compiled.
2435 The types below are used to describe the internal representation. */
2437 /* Whether to put type DIEs into their own section .debug_types instead
2438 of making them part of the .debug_info section. Only supported for
2439 Dwarf V4 or higher and the user didn't disable them through
2440 -fno-debug-types-section. It is more efficient to put them in a
2441 separate comdat sections since the linker will then be able to
2442 remove duplicates. But not all tools support .debug_types sections
2445 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2447 /* Various DIE's use offsets relative to the beginning of the
2448 .debug_info section to refer to each other. */
2450 typedef long int dw_offset
;
2452 /* Define typedefs here to avoid circular dependencies. */
2454 typedef struct dw_attr_struct
*dw_attr_ref
;
2455 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2456 typedef struct pubname_struct
*pubname_ref
;
2457 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2458 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2459 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2461 /* The entries in the line_info table more-or-less mirror the opcodes
2462 that are used in the real dwarf line table. Arrays of these entries
2463 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2466 enum dw_line_info_opcode
{
2467 /* Emit DW_LNE_set_address; the operand is the label index. */
2470 /* Emit a row to the matrix with the given line. This may be done
2471 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2475 /* Emit a DW_LNS_set_file. */
2478 /* Emit a DW_LNS_set_column. */
2481 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2484 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2485 LI_set_prologue_end
,
2486 LI_set_epilogue_begin
,
2488 /* Emit a DW_LNE_set_discriminator. */
2489 LI_set_discriminator
2492 typedef struct GTY(()) dw_line_info_struct
{
2493 enum dw_line_info_opcode opcode
;
2495 } dw_line_info_entry
;
2498 typedef struct GTY(()) dw_line_info_table_struct
{
2499 /* The label that marks the end of this section. */
2500 const char *end_label
;
2502 /* The values for the last row of the matrix, as collected in the table.
2503 These are used to minimize the changes to the next row. */
2504 unsigned int file_num
;
2505 unsigned int line_num
;
2506 unsigned int column_num
;
2511 vec
<dw_line_info_entry
, va_gc
> *entries
;
2512 } dw_line_info_table
;
2514 typedef dw_line_info_table
*dw_line_info_table_p
;
2517 /* Each DIE attribute has a field specifying the attribute kind,
2518 a link to the next attribute in the chain, and an attribute value.
2519 Attributes are typically linked below the DIE they modify. */
2521 typedef struct GTY(()) dw_attr_struct
{
2522 enum dwarf_attribute dw_attr
;
2523 dw_val_node dw_attr_val
;
2528 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2529 The children of each node form a circular list linked by
2530 die_sib. die_child points to the node *before* the "first" child node. */
2532 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2533 union die_symbol_or_type_node
2535 const char * GTY ((tag ("0"))) die_symbol
;
2536 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2538 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2539 vec
<dw_attr_node
, va_gc
> *die_attr
;
2540 dw_die_ref die_parent
;
2541 dw_die_ref die_child
;
2543 dw_die_ref die_definition
; /* ref from a specification to its definition */
2544 dw_offset die_offset
;
2545 unsigned long die_abbrev
;
2547 unsigned int decl_id
;
2548 enum dwarf_tag die_tag
;
2549 /* Die is used and must not be pruned as unused. */
2550 BOOL_BITFIELD die_perennial_p
: 1;
2551 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2552 /* Lots of spare bits. */
2556 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2557 #define FOR_EACH_CHILD(die, c, expr) do { \
2558 c = die->die_child; \
2562 } while (c != die->die_child); \
2565 /* The pubname structure */
2567 typedef struct GTY(()) pubname_struct
{
2574 struct GTY(()) dw_ranges_struct
{
2575 /* If this is positive, it's a block number, otherwise it's a
2576 bitwise-negated index into dw_ranges_by_label. */
2580 /* A structure to hold a macinfo entry. */
2582 typedef struct GTY(()) macinfo_struct
{
2584 unsigned HOST_WIDE_INT lineno
;
2590 struct GTY(()) dw_ranges_by_label_struct
{
2595 /* The comdat type node structure. */
2596 typedef struct GTY(()) comdat_type_struct
2598 dw_die_ref root_die
;
2599 dw_die_ref type_die
;
2600 dw_die_ref skeleton_die
;
2601 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2602 struct comdat_type_struct
*next
;
2606 /* The limbo die list structure. */
2607 typedef struct GTY(()) limbo_die_struct
{
2610 struct limbo_die_struct
*next
;
2614 typedef struct skeleton_chain_struct
2618 struct skeleton_chain_struct
*parent
;
2620 skeleton_chain_node
;
2622 /* Define a macro which returns nonzero for a TYPE_DECL which was
2623 implicitly generated for a type.
2625 Note that, unlike the C front-end (which generates a NULL named
2626 TYPE_DECL node for each complete tagged type, each array type,
2627 and each function type node created) the C++ front-end generates
2628 a _named_ TYPE_DECL node for each tagged type node created.
2629 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2630 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2631 front-end, but for each type, tagged or not. */
2633 #define TYPE_DECL_IS_STUB(decl) \
2634 (DECL_NAME (decl) == NULL_TREE \
2635 || (DECL_ARTIFICIAL (decl) \
2636 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2637 /* This is necessary for stub decls that \
2638 appear in nested inline functions. */ \
2639 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2640 && (decl_ultimate_origin (decl) \
2641 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2643 /* Information concerning the compilation unit's programming
2644 language, and compiler version. */
2646 /* Fixed size portion of the DWARF compilation unit header. */
2647 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2648 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2650 /* Fixed size portion of the DWARF comdat type unit header. */
2651 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2652 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2653 + DWARF_OFFSET_SIZE)
2655 /* Fixed size portion of public names info. */
2656 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2658 /* Fixed size portion of the address range info. */
2659 #define DWARF_ARANGES_HEADER_SIZE \
2660 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2661 DWARF2_ADDR_SIZE * 2) \
2662 - DWARF_INITIAL_LENGTH_SIZE)
2664 /* Size of padding portion in the address range info. It must be
2665 aligned to twice the pointer size. */
2666 #define DWARF_ARANGES_PAD_SIZE \
2667 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2668 DWARF2_ADDR_SIZE * 2) \
2669 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2671 /* Use assembler line directives if available. */
2672 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2673 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2674 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2676 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2680 /* Minimum line offset in a special line info. opcode.
2681 This value was chosen to give a reasonable range of values. */
2682 #define DWARF_LINE_BASE -10
2684 /* First special line opcode - leave room for the standard opcodes. */
2685 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2687 /* Range of line offsets in a special line info. opcode. */
2688 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2690 /* Flag that indicates the initial value of the is_stmt_start flag.
2691 In the present implementation, we do not mark any lines as
2692 the beginning of a source statement, because that information
2693 is not made available by the GCC front-end. */
2694 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2696 /* Maximum number of operations per instruction bundle. */
2697 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2698 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2701 /* This location is used by calc_die_sizes() to keep track
2702 the offset of each DIE within the .debug_info section. */
2703 static unsigned long next_die_offset
;
2705 /* Record the root of the DIE's built for the current compilation unit. */
2706 static GTY(()) dw_die_ref single_comp_unit_die
;
2708 /* A list of type DIEs that have been separated into comdat sections. */
2709 static GTY(()) comdat_type_node
*comdat_type_list
;
2711 /* A list of DIEs with a NULL parent waiting to be relocated. */
2712 static GTY(()) limbo_die_node
*limbo_die_list
;
2714 /* A list of DIEs for which we may have to generate
2715 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2716 static GTY(()) limbo_die_node
*deferred_asm_name
;
2718 /* Filenames referenced by this compilation unit. */
2719 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2721 /* A hash table of references to DIE's that describe declarations.
2722 The key is a DECL_UID() which is a unique number identifying each decl. */
2723 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2725 /* A hash table of references to DIE's that describe COMMON blocks.
2726 The key is DECL_UID() ^ die_parent. */
2727 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2729 typedef struct GTY(()) die_arg_entry_struct
{
2735 /* Node of the variable location list. */
2736 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2737 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2738 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2739 in mode of the EXPR_LIST node and first EXPR_LIST operand
2740 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2741 location or NULL for padding. For larger bitsizes,
2742 mode is 0 and first operand is a CONCAT with bitsize
2743 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2744 NULL as second operand. */
2746 const char * GTY (()) label
;
2747 struct var_loc_node
* GTY (()) next
;
2750 /* Variable location list. */
2751 struct GTY (()) var_loc_list_def
{
2752 struct var_loc_node
* GTY (()) first
;
2754 /* Pointer to the last but one or last element of the
2755 chained list. If the list is empty, both first and
2756 last are NULL, if the list contains just one node
2757 or the last node certainly is not redundant, it points
2758 to the last node, otherwise points to the last but one.
2759 Do not mark it for GC because it is marked through the chain. */
2760 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2762 /* Pointer to the last element before section switch,
2763 if NULL, either sections weren't switched or first
2764 is after section switch. */
2765 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2767 /* DECL_UID of the variable decl. */
2768 unsigned int decl_id
;
2770 typedef struct var_loc_list_def var_loc_list
;
2772 /* Call argument location list. */
2773 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2774 rtx
GTY (()) call_arg_loc_note
;
2775 const char * GTY (()) label
;
2776 tree
GTY (()) block
;
2778 rtx
GTY (()) symbol_ref
;
2779 struct call_arg_loc_node
* GTY (()) next
;
2783 /* Table of decl location linked lists. */
2784 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2786 /* Head and tail of call_arg_loc chain. */
2787 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2788 static struct call_arg_loc_node
*call_arg_loc_last
;
2790 /* Number of call sites in the current function. */
2791 static int call_site_count
= -1;
2792 /* Number of tail call sites in the current function. */
2793 static int tail_call_site_count
= -1;
2795 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2797 static vec
<dw_die_ref
> block_map
;
2799 /* A cached location list. */
2800 struct GTY (()) cached_dw_loc_list_def
{
2801 /* The DECL_UID of the decl that this entry describes. */
2802 unsigned int decl_id
;
2804 /* The cached location list. */
2805 dw_loc_list_ref loc_list
;
2807 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2809 /* Table of cached location lists. */
2810 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2812 /* A pointer to the base of a list of references to DIE's that
2813 are uniquely identified by their tag, presence/absence of
2814 children DIE's, and list of attribute/value pairs. */
2815 static GTY((length ("abbrev_die_table_allocated")))
2816 dw_die_ref
*abbrev_die_table
;
2818 /* Number of elements currently allocated for abbrev_die_table. */
2819 static GTY(()) unsigned abbrev_die_table_allocated
;
2821 /* Number of elements in type_die_table currently in use. */
2822 static GTY(()) unsigned abbrev_die_table_in_use
;
2824 /* Size (in elements) of increments by which we may expand the
2825 abbrev_die_table. */
2826 #define ABBREV_DIE_TABLE_INCREMENT 256
2828 /* A global counter for generating labels for line number data. */
2829 static unsigned int line_info_label_num
;
2831 /* The current table to which we should emit line number information
2832 for the current function. This will be set up at the beginning of
2833 assembly for the function. */
2834 static dw_line_info_table
*cur_line_info_table
;
2836 /* The two default tables of line number info. */
2837 static GTY(()) dw_line_info_table
*text_section_line_info
;
2838 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2840 /* The set of all non-default tables of line number info. */
2841 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2843 /* A flag to tell pubnames/types export if there is an info section to
2845 static bool info_section_emitted
;
2847 /* A pointer to the base of a table that contains a list of publicly
2848 accessible names. */
2849 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2851 /* A pointer to the base of a table that contains a list of publicly
2852 accessible types. */
2853 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2855 /* A pointer to the base of a table that contains a list of macro
2856 defines/undefines (and file start/end markers). */
2857 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2859 /* True if .debug_macinfo or .debug_macros section is going to be
2861 #define have_macinfo \
2862 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2863 && !macinfo_table->is_empty ())
2865 /* Array of dies for which we should generate .debug_ranges info. */
2866 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2868 /* Number of elements currently allocated for ranges_table. */
2869 static GTY(()) unsigned ranges_table_allocated
;
2871 /* Number of elements in ranges_table currently in use. */
2872 static GTY(()) unsigned ranges_table_in_use
;
2874 /* Array of pairs of labels referenced in ranges_table. */
2875 static GTY ((length ("ranges_by_label_allocated")))
2876 dw_ranges_by_label_ref ranges_by_label
;
2878 /* Number of elements currently allocated for ranges_by_label. */
2879 static GTY(()) unsigned ranges_by_label_allocated
;
2881 /* Number of elements in ranges_by_label currently in use. */
2882 static GTY(()) unsigned ranges_by_label_in_use
;
2884 /* Size (in elements) of increments by which we may expand the
2886 #define RANGES_TABLE_INCREMENT 64
2888 /* Whether we have location lists that need outputting */
2889 static GTY(()) bool have_location_lists
;
2891 /* Unique label counter. */
2892 static GTY(()) unsigned int loclabel_num
;
2894 /* Unique label counter for point-of-call tables. */
2895 static GTY(()) unsigned int poc_label_num
;
2897 /* Record whether the function being analyzed contains inlined functions. */
2898 static int current_function_has_inlines
;
2900 /* The last file entry emitted by maybe_emit_file(). */
2901 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2903 /* Number of internal labels generated by gen_internal_sym(). */
2904 static GTY(()) int label_num
;
2906 /* Cached result of previous call to lookup_filename. */
2907 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2909 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2911 /* Instances of generic types for which we need to generate debug
2912 info that describe their generic parameters and arguments. That
2913 generation needs to happen once all types are properly laid out so
2914 we do it at the end of compilation. */
2915 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2917 /* Offset from the "steady-state frame pointer" to the frame base,
2918 within the current function. */
2919 static HOST_WIDE_INT frame_pointer_fb_offset
;
2920 static bool frame_pointer_fb_offset_valid
;
2922 static vec
<dw_die_ref
> base_types
;
2924 /* Forward declarations for functions defined in this file. */
2926 static int is_pseudo_reg (const_rtx
);
2927 static tree
type_main_variant (tree
);
2928 static int is_tagged_type (const_tree
);
2929 static const char *dwarf_tag_name (unsigned);
2930 static const char *dwarf_attr_name (unsigned);
2931 static const char *dwarf_form_name (unsigned);
2932 static tree
decl_ultimate_origin (const_tree
);
2933 static tree
decl_class_context (tree
);
2934 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2935 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2936 static inline unsigned int AT_index (dw_attr_ref
);
2937 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2938 static inline unsigned AT_flag (dw_attr_ref
);
2939 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2940 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2941 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2942 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2943 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2944 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2945 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2946 unsigned int, unsigned char *);
2947 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2948 static hashval_t
debug_str_do_hash (const void *);
2949 static int debug_str_eq (const void *, const void *);
2950 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2951 static inline const char *AT_string (dw_attr_ref
);
2952 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2953 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2954 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2955 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2956 static inline int AT_ref_external (dw_attr_ref
);
2957 static inline void set_AT_ref_external (dw_attr_ref
, int);
2958 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2959 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2960 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2961 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2963 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2964 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2965 static void remove_addr_table_entry (addr_table_entry
*);
2966 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
2967 static inline rtx
AT_addr (dw_attr_ref
);
2968 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2969 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2970 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2971 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2972 unsigned HOST_WIDE_INT
);
2973 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2974 unsigned long, bool);
2975 static inline const char *AT_lbl (dw_attr_ref
);
2976 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2977 static const char *get_AT_low_pc (dw_die_ref
);
2978 static const char *get_AT_hi_pc (dw_die_ref
);
2979 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2980 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2981 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2982 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2983 static bool is_cxx (void);
2984 static bool is_fortran (void);
2985 static bool is_ada (void);
2986 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2987 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2988 static void add_child_die (dw_die_ref
, dw_die_ref
);
2989 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2990 static dw_die_ref
lookup_type_die (tree
);
2991 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2992 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
2993 static void equate_type_number_to_die (tree
, dw_die_ref
);
2994 static hashval_t
decl_die_table_hash (const void *);
2995 static int decl_die_table_eq (const void *, const void *);
2996 static dw_die_ref
lookup_decl_die (tree
);
2997 static hashval_t
common_block_die_table_hash (const void *);
2998 static int common_block_die_table_eq (const void *, const void *);
2999 static hashval_t
decl_loc_table_hash (const void *);
3000 static int decl_loc_table_eq (const void *, const void *);
3001 static var_loc_list
*lookup_decl_loc (const_tree
);
3002 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3003 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3004 static void print_spaces (FILE *);
3005 static void print_die (dw_die_ref
, FILE *);
3006 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3007 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3008 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3009 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3010 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3011 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3012 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3013 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3014 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3015 struct md5_ctx
*, int *);
3016 struct checksum_attributes
;
3017 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3018 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3019 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3020 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3021 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3022 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3023 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3024 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3025 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3026 static void compute_section_prefix (dw_die_ref
);
3027 static int is_type_die (dw_die_ref
);
3028 static int is_comdat_die (dw_die_ref
);
3029 static int is_symbol_die (dw_die_ref
);
3030 static inline bool is_template_instantiation (dw_die_ref
);
3031 static void assign_symbol_names (dw_die_ref
);
3032 static void break_out_includes (dw_die_ref
);
3033 static int is_declaration_die (dw_die_ref
);
3034 static int should_move_die_to_comdat (dw_die_ref
);
3035 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3036 static dw_die_ref
clone_die (dw_die_ref
);
3037 static dw_die_ref
clone_tree (dw_die_ref
);
3038 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3039 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3040 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3041 static dw_die_ref
generate_skeleton (dw_die_ref
);
3042 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3045 static void break_out_comdat_types (dw_die_ref
);
3046 static void copy_decls_for_unworthy_types (dw_die_ref
);
3048 static void add_sibling_attributes (dw_die_ref
);
3049 static void output_location_lists (dw_die_ref
);
3050 static int constant_size (unsigned HOST_WIDE_INT
);
3051 static unsigned long size_of_die (dw_die_ref
);
3052 static void calc_die_sizes (dw_die_ref
);
3053 static void calc_base_type_die_sizes (void);
3054 static void mark_dies (dw_die_ref
);
3055 static void unmark_dies (dw_die_ref
);
3056 static void unmark_all_dies (dw_die_ref
);
3057 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3058 static unsigned long size_of_aranges (void);
3059 static enum dwarf_form
value_format (dw_attr_ref
);
3060 static void output_value_format (dw_attr_ref
);
3061 static void output_abbrev_section (void);
3062 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3063 static void output_die_symbol (dw_die_ref
);
3064 static void output_die (dw_die_ref
);
3065 static void output_compilation_unit_header (void);
3066 static void output_comp_unit (dw_die_ref
, int);
3067 static void output_comdat_type_unit (comdat_type_node
*);
3068 static const char *dwarf2_name (tree
, int);
3069 static void add_pubname (tree
, dw_die_ref
);
3070 static void add_enumerator_pubname (const char *, dw_die_ref
);
3071 static void add_pubname_string (const char *, dw_die_ref
);
3072 static void add_pubtype (tree
, dw_die_ref
);
3073 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3074 static void output_aranges (unsigned long);
3075 static unsigned int add_ranges_num (int);
3076 static unsigned int add_ranges (const_tree
);
3077 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3079 static void output_ranges (void);
3080 static dw_line_info_table
*new_line_info_table (void);
3081 static void output_line_info (bool);
3082 static void output_file_names (void);
3083 static dw_die_ref
base_type_die (tree
);
3084 static int is_base_type (tree
);
3085 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3086 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3087 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3088 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3089 static int type_is_enum (const_tree
);
3090 static unsigned int dbx_reg_number (const_rtx
);
3091 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3092 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3093 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3094 enum var_init_status
);
3095 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3096 enum var_init_status
);
3097 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3098 enum var_init_status
);
3099 static int is_based_loc (const_rtx
);
3100 static int resolve_one_addr (rtx
*, void *);
3101 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3102 enum var_init_status
);
3103 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3104 enum var_init_status
);
3105 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3106 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3107 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3108 static tree
field_type (const_tree
);
3109 static unsigned int simple_type_align_in_bits (const_tree
);
3110 static unsigned int simple_decl_align_in_bits (const_tree
);
3111 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3112 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3113 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3115 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3116 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3117 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3118 static void insert_double (double_int
, unsigned char *);
3119 static void insert_float (const_rtx
, unsigned char *);
3120 static rtx
rtl_for_decl_location (tree
);
3121 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3122 enum dwarf_attribute
);
3123 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3124 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3125 static void add_name_attribute (dw_die_ref
, const char *);
3126 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3127 static void add_comp_dir_attribute (dw_die_ref
);
3128 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3129 static void add_subscript_info (dw_die_ref
, tree
, bool);
3130 static void add_byte_size_attribute (dw_die_ref
, tree
);
3131 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3132 static void add_bit_size_attribute (dw_die_ref
, tree
);
3133 static void add_prototyped_attribute (dw_die_ref
, tree
);
3134 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3135 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3136 static void add_src_coords_attributes (dw_die_ref
, tree
);
3137 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3138 static void push_decl_scope (tree
);
3139 static void pop_decl_scope (void);
3140 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3141 static inline int local_scope_p (dw_die_ref
);
3142 static inline int class_scope_p (dw_die_ref
);
3143 static inline int class_or_namespace_scope_p (dw_die_ref
);
3144 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3145 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3146 static const char *type_tag (const_tree
);
3147 static tree
member_declared_type (const_tree
);
3149 static const char *decl_start_label (tree
);
3151 static void gen_array_type_die (tree
, dw_die_ref
);
3152 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3154 static void gen_entry_point_die (tree
, dw_die_ref
);
3156 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3157 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3158 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3159 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3160 static void gen_formal_types_die (tree
, dw_die_ref
);
3161 static void gen_subprogram_die (tree
, dw_die_ref
);
3162 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3163 static void gen_const_die (tree
, dw_die_ref
);
3164 static void gen_label_die (tree
, dw_die_ref
);
3165 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3166 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3167 static void gen_field_die (tree
, dw_die_ref
);
3168 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3169 static dw_die_ref
gen_compile_unit_die (const char *);
3170 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3171 static void gen_member_die (tree
, dw_die_ref
);
3172 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3173 enum debug_info_usage
);
3174 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3175 static void gen_typedef_die (tree
, dw_die_ref
);
3176 static void gen_type_die (tree
, dw_die_ref
);
3177 static void gen_block_die (tree
, dw_die_ref
, int);
3178 static void decls_for_scope (tree
, dw_die_ref
, int);
3179 static inline int is_redundant_typedef (const_tree
);
3180 static bool is_naming_typedef_decl (const_tree
);
3181 static inline dw_die_ref
get_context_die (tree
);
3182 static void gen_namespace_die (tree
, dw_die_ref
);
3183 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3184 static dw_die_ref
force_decl_die (tree
);
3185 static dw_die_ref
force_type_die (tree
);
3186 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3187 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3188 static struct dwarf_file_data
* lookup_filename (const char *);
3189 static void retry_incomplete_types (void);
3190 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3191 static void gen_generic_params_dies (tree
);
3192 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3193 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3194 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3195 static int file_info_cmp (const void *, const void *);
3196 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3197 const char *, const char *);
3198 static void output_loc_list (dw_loc_list_ref
);
3199 static char *gen_internal_sym (const char *);
3200 static bool want_pubnames (void);
3202 static void prune_unmark_dies (dw_die_ref
);
3203 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3204 static void prune_unused_types_mark (dw_die_ref
, int);
3205 static void prune_unused_types_walk (dw_die_ref
);
3206 static void prune_unused_types_walk_attribs (dw_die_ref
);
3207 static void prune_unused_types_prune (dw_die_ref
);
3208 static void prune_unused_types (void);
3209 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3210 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3211 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3212 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3213 const char *, const char *);
3214 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3215 static void gen_remaining_tmpl_value_param_die_attribute (void);
3216 static bool generic_type_p (tree
);
3217 static void schedule_generic_params_dies_gen (tree t
);
3218 static void gen_scheduled_generic_parms_dies (void);
3220 static const char *comp_dir_string (void);
3222 static hashval_t
hash_loc_operands (dw_loc_descr_ref
, hashval_t
);
3224 /* enum for tracking thread-local variables whose address is really an offset
3225 relative to the TLS pointer, which will need link-time relocation, but will
3226 not need relocation by the DWARF consumer. */
3234 /* Return the operator to use for an address of a variable. For dtprel_true, we
3235 use DW_OP_const*. For regular variables, which need both link-time
3236 relocation and consumer-level relocation (e.g., to account for shared objects
3237 loaded at a random address), we use DW_OP_addr*. */
3239 static inline enum dwarf_location_atom
3240 dw_addr_op (enum dtprel_bool dtprel
)
3242 if (dtprel
== dtprel_true
)
3243 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3244 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3246 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3249 /* Return a pointer to a newly allocated address location description. If
3250 dwarf_split_debug_info is true, then record the address with the appropriate
3252 static inline dw_loc_descr_ref
3253 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3255 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3257 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3258 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3259 ref
->dtprel
= dtprel
;
3260 if (dwarf_split_debug_info
)
3261 ref
->dw_loc_oprnd1
.val_entry
3262 = add_addr_table_entry (addr
,
3263 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3265 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3270 /* Section names used to hold DWARF debugging information. */
3272 #ifndef DEBUG_INFO_SECTION
3273 #define DEBUG_INFO_SECTION ".debug_info"
3275 #ifndef DEBUG_DWO_INFO_SECTION
3276 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3278 #ifndef DEBUG_ABBREV_SECTION
3279 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3281 #ifndef DEBUG_DWO_ABBREV_SECTION
3282 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3284 #ifndef DEBUG_ARANGES_SECTION
3285 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3287 #ifndef DEBUG_ADDR_SECTION
3288 #define DEBUG_ADDR_SECTION ".debug_addr"
3290 #ifndef DEBUG_NORM_MACINFO_SECTION
3291 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3293 #ifndef DEBUG_DWO_MACINFO_SECTION
3294 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3296 #ifndef DEBUG_MACINFO_SECTION
3297 #define DEBUG_MACINFO_SECTION \
3298 (!dwarf_split_debug_info \
3299 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3301 #ifndef DEBUG_NORM_MACRO_SECTION
3302 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3304 #ifndef DEBUG_DWO_MACRO_SECTION
3305 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3307 #ifndef DEBUG_MACRO_SECTION
3308 #define DEBUG_MACRO_SECTION \
3309 (!dwarf_split_debug_info \
3310 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3312 #ifndef DEBUG_LINE_SECTION
3313 #define DEBUG_LINE_SECTION ".debug_line"
3315 #ifndef DEBUG_DWO_LINE_SECTION
3316 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3318 #ifndef DEBUG_LOC_SECTION
3319 #define DEBUG_LOC_SECTION ".debug_loc"
3321 #ifndef DEBUG_DWO_LOC_SECTION
3322 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3324 #ifndef DEBUG_PUBNAMES_SECTION
3325 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3327 #ifndef DEBUG_PUBTYPES_SECTION
3328 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3330 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3331 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3332 #ifndef DEBUG_STR_OFFSETS_SECTION
3333 #define DEBUG_STR_OFFSETS_SECTION \
3334 (!dwarf_split_debug_info \
3335 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3337 #ifndef DEBUG_STR_DWO_SECTION
3338 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3340 #ifndef DEBUG_STR_SECTION
3341 #define DEBUG_STR_SECTION ".debug_str"
3343 #ifndef DEBUG_RANGES_SECTION
3344 #define DEBUG_RANGES_SECTION ".debug_ranges"
3347 /* Standard ELF section names for compiled code and data. */
3348 #ifndef TEXT_SECTION_NAME
3349 #define TEXT_SECTION_NAME ".text"
3352 /* Section flags for .debug_macinfo/.debug_macro section. */
3353 #define DEBUG_MACRO_SECTION_FLAGS \
3354 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3356 /* Section flags for .debug_str section. */
3357 #define DEBUG_STR_SECTION_FLAGS \
3358 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3359 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3362 /* Section flags for .debug_str.dwo section. */
3363 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3365 /* Labels we insert at beginning sections we can reference instead of
3366 the section names themselves. */
3368 #ifndef TEXT_SECTION_LABEL
3369 #define TEXT_SECTION_LABEL "Ltext"
3371 #ifndef COLD_TEXT_SECTION_LABEL
3372 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3374 #ifndef DEBUG_LINE_SECTION_LABEL
3375 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3377 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3378 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3380 #ifndef DEBUG_INFO_SECTION_LABEL
3381 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3383 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3384 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3386 #ifndef DEBUG_ABBREV_SECTION_LABEL
3387 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3389 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3390 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3392 #ifndef DEBUG_ADDR_SECTION_LABEL
3393 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3395 #ifndef DEBUG_LOC_SECTION_LABEL
3396 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3398 #ifndef DEBUG_RANGES_SECTION_LABEL
3399 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3401 #ifndef DEBUG_MACINFO_SECTION_LABEL
3402 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3404 #ifndef DEBUG_MACRO_SECTION_LABEL
3405 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3407 #define SKELETON_COMP_DIE_ABBREV 1
3408 #define SKELETON_TYPE_DIE_ABBREV 2
3410 /* Definitions of defaults for formats and names of various special
3411 (artificial) labels which may be generated within this file (when the -g
3412 options is used and DWARF2_DEBUGGING_INFO is in effect.
3413 If necessary, these may be overridden from within the tm.h file, but
3414 typically, overriding these defaults is unnecessary. */
3416 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3417 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3418 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3419 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3420 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3421 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3422 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3423 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3424 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3425 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3426 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3427 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3428 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3429 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3431 #ifndef TEXT_END_LABEL
3432 #define TEXT_END_LABEL "Letext"
3434 #ifndef COLD_END_LABEL
3435 #define COLD_END_LABEL "Letext_cold"
3437 #ifndef BLOCK_BEGIN_LABEL
3438 #define BLOCK_BEGIN_LABEL "LBB"
3440 #ifndef BLOCK_END_LABEL
3441 #define BLOCK_END_LABEL "LBE"
3443 #ifndef LINE_CODE_LABEL
3444 #define LINE_CODE_LABEL "LM"
3448 /* Return the root of the DIE's built for the current compilation unit. */
3450 comp_unit_die (void)
3452 if (!single_comp_unit_die
)
3453 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3454 return single_comp_unit_die
;
3457 /* We allow a language front-end to designate a function that is to be
3458 called to "demangle" any name before it is put into a DIE. */
3460 static const char *(*demangle_name_func
) (const char *);
3463 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3465 demangle_name_func
= func
;
3468 /* Test if rtl node points to a pseudo register. */
3471 is_pseudo_reg (const_rtx rtl
)
3473 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3474 || (GET_CODE (rtl
) == SUBREG
3475 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3478 /* Return a reference to a type, with its const and volatile qualifiers
3482 type_main_variant (tree type
)
3484 type
= TYPE_MAIN_VARIANT (type
);
3486 /* ??? There really should be only one main variant among any group of
3487 variants of a given type (and all of the MAIN_VARIANT values for all
3488 members of the group should point to that one type) but sometimes the C
3489 front-end messes this up for array types, so we work around that bug
3491 if (TREE_CODE (type
) == ARRAY_TYPE
)
3492 while (type
!= TYPE_MAIN_VARIANT (type
))
3493 type
= TYPE_MAIN_VARIANT (type
);
3498 /* Return nonzero if the given type node represents a tagged type. */
3501 is_tagged_type (const_tree type
)
3503 enum tree_code code
= TREE_CODE (type
);
3505 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3506 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3509 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3512 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3514 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3517 /* Return die_offset of a DIE reference to a base type. */
3519 static unsigned long int
3520 get_base_type_offset (dw_die_ref ref
)
3522 if (ref
->die_offset
)
3523 return ref
->die_offset
;
3524 if (comp_unit_die ()->die_abbrev
)
3526 calc_base_type_die_sizes ();
3527 gcc_assert (ref
->die_offset
);
3529 return ref
->die_offset
;
3532 /* Return die_offset of a DIE reference other than base type. */
3534 static unsigned long int
3535 get_ref_die_offset (dw_die_ref ref
)
3537 gcc_assert (ref
->die_offset
);
3538 return ref
->die_offset
;
3541 /* Convert a DIE tag into its string name. */
3544 dwarf_tag_name (unsigned int tag
)
3546 const char *name
= get_DW_TAG_name (tag
);
3551 return "DW_TAG_<unknown>";
3554 /* Convert a DWARF attribute code into its string name. */
3557 dwarf_attr_name (unsigned int attr
)
3563 #if VMS_DEBUGGING_INFO
3564 case DW_AT_HP_prologue
:
3565 return "DW_AT_HP_prologue";
3567 case DW_AT_MIPS_loop_unroll_factor
:
3568 return "DW_AT_MIPS_loop_unroll_factor";
3571 #if VMS_DEBUGGING_INFO
3572 case DW_AT_HP_epilogue
:
3573 return "DW_AT_HP_epilogue";
3575 case DW_AT_MIPS_stride
:
3576 return "DW_AT_MIPS_stride";
3580 name
= get_DW_AT_name (attr
);
3585 return "DW_AT_<unknown>";
3588 /* Convert a DWARF value form code into its string name. */
3591 dwarf_form_name (unsigned int form
)
3593 const char *name
= get_DW_FORM_name (form
);
3598 return "DW_FORM_<unknown>";
3601 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3602 instance of an inlined instance of a decl which is local to an inline
3603 function, so we have to trace all of the way back through the origin chain
3604 to find out what sort of node actually served as the original seed for the
3608 decl_ultimate_origin (const_tree decl
)
3610 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3613 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3614 nodes in the function to point to themselves; ignore that if
3615 we're trying to output the abstract instance of this function. */
3616 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3619 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3620 most distant ancestor, this should never happen. */
3621 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3623 return DECL_ABSTRACT_ORIGIN (decl
);
3626 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3627 of a virtual function may refer to a base class, so we check the 'this'
3631 decl_class_context (tree decl
)
3633 tree context
= NULL_TREE
;
3635 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3636 context
= DECL_CONTEXT (decl
);
3638 context
= TYPE_MAIN_VARIANT
3639 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3641 if (context
&& !TYPE_P (context
))
3642 context
= NULL_TREE
;
3647 /* Add an attribute/value pair to a DIE. */
3650 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3652 /* Maybe this should be an assert? */
3656 vec_safe_reserve (die
->die_attr
, 1);
3657 vec_safe_push (die
->die_attr
, *attr
);
3660 static inline enum dw_val_class
3661 AT_class (dw_attr_ref a
)
3663 return a
->dw_attr_val
.val_class
;
3666 /* Return the index for any attribute that will be referenced with a
3667 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3668 are stored in dw_attr_val.v.val_str for reference counting
3671 static inline unsigned int
3672 AT_index (dw_attr_ref a
)
3674 if (AT_class (a
) == dw_val_class_str
)
3675 return a
->dw_attr_val
.v
.val_str
->index
;
3676 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3677 return a
->dw_attr_val
.val_entry
->index
;
3681 /* Add a flag value attribute to a DIE. */
3684 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3688 attr
.dw_attr
= attr_kind
;
3689 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3690 attr
.dw_attr_val
.val_entry
= NULL
;
3691 attr
.dw_attr_val
.v
.val_flag
= flag
;
3692 add_dwarf_attr (die
, &attr
);
3695 static inline unsigned
3696 AT_flag (dw_attr_ref a
)
3698 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3699 return a
->dw_attr_val
.v
.val_flag
;
3702 /* Add a signed integer attribute value to a DIE. */
3705 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3709 attr
.dw_attr
= attr_kind
;
3710 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3711 attr
.dw_attr_val
.val_entry
= NULL
;
3712 attr
.dw_attr_val
.v
.val_int
= int_val
;
3713 add_dwarf_attr (die
, &attr
);
3716 static inline HOST_WIDE_INT
3717 AT_int (dw_attr_ref a
)
3719 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3720 return a
->dw_attr_val
.v
.val_int
;
3723 /* Add an unsigned integer attribute value to a DIE. */
3726 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3727 unsigned HOST_WIDE_INT unsigned_val
)
3731 attr
.dw_attr
= attr_kind
;
3732 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3733 attr
.dw_attr_val
.val_entry
= NULL
;
3734 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3735 add_dwarf_attr (die
, &attr
);
3738 static inline unsigned HOST_WIDE_INT
3739 AT_unsigned (dw_attr_ref a
)
3741 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3742 return a
->dw_attr_val
.v
.val_unsigned
;
3745 /* Add an unsigned double integer attribute value to a DIE. */
3748 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3749 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3753 attr
.dw_attr
= attr_kind
;
3754 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3755 attr
.dw_attr_val
.val_entry
= NULL
;
3756 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3757 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3758 add_dwarf_attr (die
, &attr
);
3761 /* Add a floating point attribute value to a DIE and return it. */
3764 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3765 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3769 attr
.dw_attr
= attr_kind
;
3770 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3771 attr
.dw_attr_val
.val_entry
= NULL
;
3772 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3773 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3774 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3775 add_dwarf_attr (die
, &attr
);
3778 /* Add an 8-byte data attribute value to a DIE. */
3781 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3782 unsigned char data8
[8])
3786 attr
.dw_attr
= attr_kind
;
3787 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3788 attr
.dw_attr_val
.val_entry
= NULL
;
3789 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3790 add_dwarf_attr (die
, &attr
);
3793 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3794 dwarf_split_debug_info, address attributes in dies destined for the
3795 final executable have force_direct set to avoid using indexed
3799 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3805 lbl_id
= xstrdup (lbl_low
);
3806 attr
.dw_attr
= DW_AT_low_pc
;
3807 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3808 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3809 if (dwarf_split_debug_info
&& !force_direct
)
3810 attr
.dw_attr_val
.val_entry
3811 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3813 attr
.dw_attr_val
.val_entry
= NULL
;
3814 add_dwarf_attr (die
, &attr
);
3816 attr
.dw_attr
= DW_AT_high_pc
;
3817 if (dwarf_version
< 4)
3818 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3820 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3821 lbl_id
= xstrdup (lbl_high
);
3822 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3823 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3824 && dwarf_split_debug_info
&& !force_direct
)
3825 attr
.dw_attr_val
.val_entry
3826 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3828 attr
.dw_attr_val
.val_entry
= NULL
;
3829 add_dwarf_attr (die
, &attr
);
3832 /* Hash and equality functions for debug_str_hash. */
3835 debug_str_do_hash (const void *x
)
3837 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3841 debug_str_eq (const void *x1
, const void *x2
)
3843 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3844 (const char *)x2
) == 0;
3847 /* Add STR to the given string hash table. */
3849 static struct indirect_string_node
*
3850 find_AT_string_in_table (const char *str
, htab_t table
)
3852 struct indirect_string_node
*node
;
3855 slot
= htab_find_slot_with_hash (table
, str
,
3856 htab_hash_string (str
), INSERT
);
3859 node
= ggc_alloc_cleared_indirect_string_node ();
3860 node
->str
= ggc_strdup (str
);
3864 node
= (struct indirect_string_node
*) *slot
;
3870 /* Add STR to the indirect string hash table. */
3872 static struct indirect_string_node
*
3873 find_AT_string (const char *str
)
3875 if (! debug_str_hash
)
3876 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3877 debug_str_eq
, NULL
);
3879 return find_AT_string_in_table (str
, debug_str_hash
);
3882 /* Add a string attribute value to a DIE. */
3885 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3888 struct indirect_string_node
*node
;
3890 node
= find_AT_string (str
);
3892 attr
.dw_attr
= attr_kind
;
3893 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3894 attr
.dw_attr_val
.val_entry
= NULL
;
3895 attr
.dw_attr_val
.v
.val_str
= node
;
3896 add_dwarf_attr (die
, &attr
);
3899 static inline const char *
3900 AT_string (dw_attr_ref a
)
3902 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3903 return a
->dw_attr_val
.v
.val_str
->str
;
3906 /* Call this function directly to bypass AT_string_form's logic to put
3907 the string inline in the die. */
3910 set_indirect_string (struct indirect_string_node
*node
)
3913 /* Already indirect is a no op. */
3914 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3916 gcc_assert (node
->label
);
3919 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3920 ++dw2_string_counter
;
3921 node
->label
= xstrdup (label
);
3923 if (!dwarf_split_debug_info
)
3925 node
->form
= DW_FORM_strp
;
3926 node
->index
= NOT_INDEXED
;
3930 node
->form
= DW_FORM_GNU_str_index
;
3931 node
->index
= NO_INDEX_ASSIGNED
;
3935 /* Find out whether a string should be output inline in DIE
3936 or out-of-line in .debug_str section. */
3938 static enum dwarf_form
3939 find_string_form (struct indirect_string_node
*node
)
3946 len
= strlen (node
->str
) + 1;
3948 /* If the string is shorter or equal to the size of the reference, it is
3949 always better to put it inline. */
3950 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3951 return node
->form
= DW_FORM_string
;
3953 /* If we cannot expect the linker to merge strings in .debug_str
3954 section, only put it into .debug_str if it is worth even in this
3956 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3957 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3958 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3959 return node
->form
= DW_FORM_string
;
3961 set_indirect_string (node
);
3966 /* Find out whether the string referenced from the attribute should be
3967 output inline in DIE or out-of-line in .debug_str section. */
3969 static enum dwarf_form
3970 AT_string_form (dw_attr_ref a
)
3972 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3973 return find_string_form (a
->dw_attr_val
.v
.val_str
);
3976 /* Add a DIE reference attribute value to a DIE. */
3979 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3983 #ifdef ENABLE_CHECKING
3984 gcc_assert (targ_die
!= NULL
);
3986 /* With LTO we can end up trying to reference something we didn't create
3987 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3988 if (targ_die
== NULL
)
3992 attr
.dw_attr
= attr_kind
;
3993 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
3994 attr
.dw_attr_val
.val_entry
= NULL
;
3995 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
3996 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
3997 add_dwarf_attr (die
, &attr
);
4000 /* Change DIE reference REF to point to NEW_DIE instead. */
4003 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4005 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4006 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4007 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4010 /* Add an AT_specification attribute to a DIE, and also make the back
4011 pointer from the specification to the definition. */
4014 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4016 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4017 gcc_assert (!targ_die
->die_definition
);
4018 targ_die
->die_definition
= die
;
4021 static inline dw_die_ref
4022 AT_ref (dw_attr_ref a
)
4024 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4025 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4029 AT_ref_external (dw_attr_ref a
)
4031 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4032 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4038 set_AT_ref_external (dw_attr_ref a
, int i
)
4040 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4041 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4044 /* Add an FDE reference attribute value to a DIE. */
4047 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4051 attr
.dw_attr
= attr_kind
;
4052 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4053 attr
.dw_attr_val
.val_entry
= NULL
;
4054 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4055 add_dwarf_attr (die
, &attr
);
4058 /* Add a location description attribute value to a DIE. */
4061 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4065 attr
.dw_attr
= attr_kind
;
4066 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4067 attr
.dw_attr_val
.val_entry
= NULL
;
4068 attr
.dw_attr_val
.v
.val_loc
= loc
;
4069 add_dwarf_attr (die
, &attr
);
4072 static inline dw_loc_descr_ref
4073 AT_loc (dw_attr_ref a
)
4075 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4076 return a
->dw_attr_val
.v
.val_loc
;
4080 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4084 attr
.dw_attr
= attr_kind
;
4085 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4086 attr
.dw_attr_val
.val_entry
= NULL
;
4087 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4088 add_dwarf_attr (die
, &attr
);
4089 have_location_lists
= true;
4092 static inline dw_loc_list_ref
4093 AT_loc_list (dw_attr_ref a
)
4095 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4096 return a
->dw_attr_val
.v
.val_loc_list
;
4099 static inline dw_loc_list_ref
*
4100 AT_loc_list_ptr (dw_attr_ref a
)
4102 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4103 return &a
->dw_attr_val
.v
.val_loc_list
;
4106 /* Table of entries into the .debug_addr section. */
4108 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4110 /* Hash an address_table_entry. */
4113 addr_table_entry_do_hash (const void *x
)
4115 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4119 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4120 case ate_kind_rtx_dtprel
:
4121 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4122 case ate_kind_label
:
4123 return htab_hash_string (a
->addr
.label
);
4129 /* Determine equality for two address_table_entries. */
4132 addr_table_entry_eq (const void *x1
, const void *x2
)
4134 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4135 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4137 if (a1
->kind
!= a2
->kind
)
4142 case ate_kind_rtx_dtprel
:
4143 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4144 case ate_kind_label
:
4145 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4151 /* Initialize an addr_table_entry. */
4154 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4160 case ate_kind_rtx_dtprel
:
4161 e
->addr
.rtl
= (rtx
) addr
;
4163 case ate_kind_label
:
4164 e
->addr
.label
= (char *) addr
;
4168 e
->index
= NO_INDEX_ASSIGNED
;
4171 /* Add attr to the address table entry to the table. Defer setting an
4172 index until output time. */
4174 static addr_table_entry
*
4175 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4177 addr_table_entry
*node
;
4178 addr_table_entry finder
;
4181 gcc_assert (dwarf_split_debug_info
);
4182 if (! addr_index_table
)
4183 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4184 addr_table_entry_eq
, NULL
);
4185 init_addr_table_entry (&finder
, kind
, addr
);
4186 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4188 if (*slot
== HTAB_EMPTY_ENTRY
)
4190 node
= ggc_alloc_cleared_addr_table_entry ();
4191 init_addr_table_entry (node
, kind
, addr
);
4195 node
= (addr_table_entry
*) *slot
;
4201 /* Remove an entry from the addr table by decrementing its refcount.
4202 Strictly, decrementing the refcount would be enough, but the
4203 assertion that the entry is actually in the table has found
4207 remove_addr_table_entry (addr_table_entry
*entry
)
4209 addr_table_entry
*node
;
4211 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4212 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4213 /* After an index is assigned, the table is frozen. */
4214 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4218 /* Given a location list, remove all addresses it refers to from the
4222 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4224 for (; descr
; descr
= descr
->dw_loc_next
)
4225 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4227 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4228 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4232 /* A helper function for dwarf2out_finish called through
4233 htab_traverse. Assign an addr_table_entry its index. All entries
4234 must be collected into the table when this function is called,
4235 because the indexing code relies on htab_traverse to traverse nodes
4236 in the same order for each run. */
4239 index_addr_table_entry (void **h
, void *v
)
4241 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4242 unsigned int *index
= (unsigned int *) v
;
4244 /* Don't index unreferenced nodes. */
4245 if (node
->refcount
== 0)
4248 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
4249 node
->index
= *index
;
4255 /* Add an address constant attribute value to a DIE. When using
4256 dwarf_split_debug_info, address attributes in dies destined for the
4257 final executable should be direct references--setting the parameter
4258 force_direct ensures this behavior. */
4261 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4266 attr
.dw_attr
= attr_kind
;
4267 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4268 attr
.dw_attr_val
.v
.val_addr
= addr
;
4269 if (dwarf_split_debug_info
&& !force_direct
)
4270 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4272 attr
.dw_attr_val
.val_entry
= NULL
;
4273 add_dwarf_attr (die
, &attr
);
4276 /* Get the RTX from to an address DIE attribute. */
4279 AT_addr (dw_attr_ref a
)
4281 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4282 return a
->dw_attr_val
.v
.val_addr
;
4285 /* Add a file attribute value to a DIE. */
4288 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4289 struct dwarf_file_data
*fd
)
4293 attr
.dw_attr
= attr_kind
;
4294 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4295 attr
.dw_attr_val
.val_entry
= NULL
;
4296 attr
.dw_attr_val
.v
.val_file
= fd
;
4297 add_dwarf_attr (die
, &attr
);
4300 /* Get the dwarf_file_data from a file DIE attribute. */
4302 static inline struct dwarf_file_data
*
4303 AT_file (dw_attr_ref a
)
4305 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4306 return a
->dw_attr_val
.v
.val_file
;
4309 /* Add a vms delta attribute value to a DIE. */
4312 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4313 const char *lbl1
, const char *lbl2
)
4317 attr
.dw_attr
= attr_kind
;
4318 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4319 attr
.dw_attr_val
.val_entry
= NULL
;
4320 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4321 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4322 add_dwarf_attr (die
, &attr
);
4325 /* Add a label identifier attribute value to a DIE. */
4328 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4333 attr
.dw_attr
= attr_kind
;
4334 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4335 attr
.dw_attr_val
.val_entry
= NULL
;
4336 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4337 if (dwarf_split_debug_info
)
4338 attr
.dw_attr_val
.val_entry
4339 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4341 add_dwarf_attr (die
, &attr
);
4344 /* Add a section offset attribute value to a DIE, an offset into the
4345 debug_line section. */
4348 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4353 attr
.dw_attr
= attr_kind
;
4354 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4355 attr
.dw_attr_val
.val_entry
= NULL
;
4356 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4357 add_dwarf_attr (die
, &attr
);
4360 /* Add a section offset attribute value to a DIE, an offset into the
4361 debug_macinfo section. */
4364 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4369 attr
.dw_attr
= attr_kind
;
4370 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4371 attr
.dw_attr_val
.val_entry
= NULL
;
4372 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4373 add_dwarf_attr (die
, &attr
);
4376 /* Add an offset attribute value to a DIE. */
4379 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4380 unsigned HOST_WIDE_INT offset
)
4384 attr
.dw_attr
= attr_kind
;
4385 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4386 attr
.dw_attr_val
.val_entry
= NULL
;
4387 attr
.dw_attr_val
.v
.val_offset
= offset
;
4388 add_dwarf_attr (die
, &attr
);
4391 /* Add a range_list attribute value to a DIE. When using
4392 dwarf_split_debug_info, address attributes in dies destined for the
4393 final executable should be direct references--setting the parameter
4394 force_direct ensures this behavior. */
4396 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4397 #define RELOCATED_OFFSET (NULL)
4400 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4401 long unsigned int offset
, bool force_direct
)
4405 attr
.dw_attr
= attr_kind
;
4406 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4407 /* For the range_list attribute, use val_entry to store whether the
4408 offset should follow split-debug-info or normal semantics. This
4409 value is read in output_range_list_offset. */
4410 if (dwarf_split_debug_info
&& !force_direct
)
4411 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4413 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4414 attr
.dw_attr_val
.v
.val_offset
= offset
;
4415 add_dwarf_attr (die
, &attr
);
4418 /* Return the start label of a delta attribute. */
4420 static inline const char *
4421 AT_vms_delta1 (dw_attr_ref a
)
4423 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4424 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4427 /* Return the end label of a delta attribute. */
4429 static inline const char *
4430 AT_vms_delta2 (dw_attr_ref a
)
4432 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4433 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4436 static inline const char *
4437 AT_lbl (dw_attr_ref a
)
4439 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4440 || AT_class (a
) == dw_val_class_lineptr
4441 || AT_class (a
) == dw_val_class_macptr
4442 || AT_class (a
) == dw_val_class_high_pc
));
4443 return a
->dw_attr_val
.v
.val_lbl_id
;
4446 /* Get the attribute of type attr_kind. */
4449 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4453 dw_die_ref spec
= NULL
;
4458 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4459 if (a
->dw_attr
== attr_kind
)
4461 else if (a
->dw_attr
== DW_AT_specification
4462 || a
->dw_attr
== DW_AT_abstract_origin
)
4466 return get_AT (spec
, attr_kind
);
4471 /* Returns the parent of the declaration of DIE. */
4474 get_die_parent (dw_die_ref die
)
4481 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4482 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4485 return die
->die_parent
;
4488 /* Return the "low pc" attribute value, typically associated with a subprogram
4489 DIE. Return null if the "low pc" attribute is either not present, or if it
4490 cannot be represented as an assembler label identifier. */
4492 static inline const char *
4493 get_AT_low_pc (dw_die_ref die
)
4495 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4497 return a
? AT_lbl (a
) : NULL
;
4500 /* Return the "high pc" attribute value, typically associated with a subprogram
4501 DIE. Return null if the "high pc" attribute is either not present, or if it
4502 cannot be represented as an assembler label identifier. */
4504 static inline const char *
4505 get_AT_hi_pc (dw_die_ref die
)
4507 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4509 return a
? AT_lbl (a
) : NULL
;
4512 /* Return the value of the string attribute designated by ATTR_KIND, or
4513 NULL if it is not present. */
4515 static inline const char *
4516 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4518 dw_attr_ref a
= get_AT (die
, attr_kind
);
4520 return a
? AT_string (a
) : NULL
;
4523 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4524 if it is not present. */
4527 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4529 dw_attr_ref a
= get_AT (die
, attr_kind
);
4531 return a
? AT_flag (a
) : 0;
4534 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4535 if it is not present. */
4537 static inline unsigned
4538 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4540 dw_attr_ref a
= get_AT (die
, attr_kind
);
4542 return a
? AT_unsigned (a
) : 0;
4545 static inline dw_die_ref
4546 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4548 dw_attr_ref a
= get_AT (die
, attr_kind
);
4550 return a
? AT_ref (a
) : NULL
;
4553 static inline struct dwarf_file_data
*
4554 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4556 dw_attr_ref a
= get_AT (die
, attr_kind
);
4558 return a
? AT_file (a
) : NULL
;
4561 /* Return TRUE if the language is C++. */
4566 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4568 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4571 /* Return TRUE if the language is Fortran. */
4576 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4578 return (lang
== DW_LANG_Fortran77
4579 || lang
== DW_LANG_Fortran90
4580 || lang
== DW_LANG_Fortran95
);
4583 /* Return TRUE if the language is Ada. */
4588 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4590 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4593 /* Remove the specified attribute if present. */
4596 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4604 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4605 if (a
->dw_attr
== attr_kind
)
4607 if (AT_class (a
) == dw_val_class_str
)
4608 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4609 a
->dw_attr_val
.v
.val_str
->refcount
--;
4611 /* vec::ordered_remove should help reduce the number of abbrevs
4613 die
->die_attr
->ordered_remove (ix
);
4618 /* Remove CHILD from its parent. PREV must have the property that
4619 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4622 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4624 gcc_assert (child
->die_parent
== prev
->die_parent
);
4625 gcc_assert (prev
->die_sib
== child
);
4628 gcc_assert (child
->die_parent
->die_child
== child
);
4632 prev
->die_sib
= child
->die_sib
;
4633 if (child
->die_parent
->die_child
== child
)
4634 child
->die_parent
->die_child
= prev
;
4637 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4638 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4641 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4643 dw_die_ref parent
= old_child
->die_parent
;
4645 gcc_assert (parent
== prev
->die_parent
);
4646 gcc_assert (prev
->die_sib
== old_child
);
4648 new_child
->die_parent
= parent
;
4649 if (prev
== old_child
)
4651 gcc_assert (parent
->die_child
== old_child
);
4652 new_child
->die_sib
= new_child
;
4656 prev
->die_sib
= new_child
;
4657 new_child
->die_sib
= old_child
->die_sib
;
4659 if (old_child
->die_parent
->die_child
== old_child
)
4660 old_child
->die_parent
->die_child
= new_child
;
4663 /* Move all children from OLD_PARENT to NEW_PARENT. */
4666 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4669 new_parent
->die_child
= old_parent
->die_child
;
4670 old_parent
->die_child
= NULL
;
4671 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4674 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4678 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4684 dw_die_ref prev
= c
;
4686 while (c
->die_tag
== tag
)
4688 remove_child_with_prev (c
, prev
);
4689 /* Might have removed every child. */
4690 if (c
== c
->die_sib
)
4694 } while (c
!= die
->die_child
);
4697 /* Add a CHILD_DIE as the last child of DIE. */
4700 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4702 /* FIXME this should probably be an assert. */
4703 if (! die
|| ! child_die
)
4705 gcc_assert (die
!= child_die
);
4707 child_die
->die_parent
= die
;
4710 child_die
->die_sib
= die
->die_child
->die_sib
;
4711 die
->die_child
->die_sib
= child_die
;
4714 child_die
->die_sib
= child_die
;
4715 die
->die_child
= child_die
;
4718 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4719 is the specification, to the end of PARENT's list of children.
4720 This is done by removing and re-adding it. */
4723 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4727 /* We want the declaration DIE from inside the class, not the
4728 specification DIE at toplevel. */
4729 if (child
->die_parent
!= parent
)
4731 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4737 gcc_assert (child
->die_parent
== parent
4738 || (child
->die_parent
4739 == get_AT_ref (parent
, DW_AT_specification
)));
4741 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4742 if (p
->die_sib
== child
)
4744 remove_child_with_prev (child
, p
);
4748 add_child_die (parent
, child
);
4751 /* Return a pointer to a newly created DIE node. */
4753 static inline dw_die_ref
4754 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4756 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4758 die
->die_tag
= tag_value
;
4760 if (parent_die
!= NULL
)
4761 add_child_die (parent_die
, die
);
4764 limbo_die_node
*limbo_node
;
4766 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4767 limbo_node
->die
= die
;
4768 limbo_node
->created_for
= t
;
4769 limbo_node
->next
= limbo_die_list
;
4770 limbo_die_list
= limbo_node
;
4776 /* Return the DIE associated with the given type specifier. */
4778 static inline dw_die_ref
4779 lookup_type_die (tree type
)
4781 return TYPE_SYMTAB_DIE (type
);
4784 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4785 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4786 anonymous type instead the one of the naming typedef. */
4788 static inline dw_die_ref
4789 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4792 && TREE_CODE (type
) == RECORD_TYPE
4794 && type_die
->die_tag
== DW_TAG_typedef
4795 && is_naming_typedef_decl (TYPE_NAME (type
)))
4796 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4800 /* Like lookup_type_die, but if type is an anonymous type named by a
4801 typedef[1], return the DIE of the anonymous type instead the one of
4802 the naming typedef. This is because in gen_typedef_die, we did
4803 equate the anonymous struct named by the typedef with the DIE of
4804 the naming typedef. So by default, lookup_type_die on an anonymous
4805 struct yields the DIE of the naming typedef.
4807 [1]: Read the comment of is_naming_typedef_decl to learn about what
4808 a naming typedef is. */
4810 static inline dw_die_ref
4811 lookup_type_die_strip_naming_typedef (tree type
)
4813 dw_die_ref die
= lookup_type_die (type
);
4814 return strip_naming_typedef (type
, die
);
4817 /* Equate a DIE to a given type specifier. */
4820 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4822 TYPE_SYMTAB_DIE (type
) = type_die
;
4825 /* Returns a hash value for X (which really is a die_struct). */
4828 decl_die_table_hash (const void *x
)
4830 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4833 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4836 decl_die_table_eq (const void *x
, const void *y
)
4838 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4841 /* Return the DIE associated with a given declaration. */
4843 static inline dw_die_ref
4844 lookup_decl_die (tree decl
)
4846 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4849 /* Returns a hash value for X (which really is a var_loc_list). */
4852 decl_loc_table_hash (const void *x
)
4854 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4857 /* Return nonzero if decl_id of var_loc_list X is the same as
4861 decl_loc_table_eq (const void *x
, const void *y
)
4863 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4866 /* Return the var_loc list associated with a given declaration. */
4868 static inline var_loc_list
*
4869 lookup_decl_loc (const_tree decl
)
4871 if (!decl_loc_table
)
4873 return (var_loc_list
*)
4874 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4877 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4880 cached_dw_loc_list_table_hash (const void *x
)
4882 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4885 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4889 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4891 return (((const cached_dw_loc_list
*) x
)->decl_id
4892 == DECL_UID ((const_tree
) y
));
4895 /* Equate a DIE to a particular declaration. */
4898 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4900 unsigned int decl_id
= DECL_UID (decl
);
4903 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4905 decl_die
->decl_id
= decl_id
;
4908 /* Return how many bits covers PIECE EXPR_LIST. */
4911 decl_piece_bitsize (rtx piece
)
4913 int ret
= (int) GET_MODE (piece
);
4916 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4917 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4918 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4921 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4924 decl_piece_varloc_ptr (rtx piece
)
4926 if ((int) GET_MODE (piece
))
4927 return &XEXP (piece
, 0);
4929 return &XEXP (XEXP (piece
, 0), 1);
4932 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4933 Next is the chain of following piece nodes. */
4936 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4938 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4939 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4941 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4946 /* Return rtx that should be stored into loc field for
4947 LOC_NOTE and BITPOS/BITSIZE. */
4950 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4951 HOST_WIDE_INT bitsize
)
4955 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4957 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4962 /* This function either modifies location piece list *DEST in
4963 place (if SRC and INNER is NULL), or copies location piece list
4964 *SRC to *DEST while modifying it. Location BITPOS is modified
4965 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4966 not copied and if needed some padding around it is added.
4967 When modifying in place, DEST should point to EXPR_LIST where
4968 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4969 to the start of the whole list and INNER points to the EXPR_LIST
4970 where earlier pieces cover PIECE_BITPOS bits. */
4973 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4974 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4975 HOST_WIDE_INT bitsize
, rtx loc_note
)
4978 bool copy
= inner
!= NULL
;
4982 /* First copy all nodes preceding the current bitpos. */
4983 while (src
!= inner
)
4985 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4986 decl_piece_bitsize (*src
), NULL_RTX
);
4987 dest
= &XEXP (*dest
, 1);
4988 src
= &XEXP (*src
, 1);
4991 /* Add padding if needed. */
4992 if (bitpos
!= piece_bitpos
)
4994 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
4995 copy
? NULL_RTX
: *dest
);
4996 dest
= &XEXP (*dest
, 1);
4998 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5001 /* A piece with correct bitpos and bitsize already exist,
5002 just update the location for it and return. */
5003 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5006 /* Add the piece that changed. */
5007 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5008 dest
= &XEXP (*dest
, 1);
5009 /* Skip over pieces that overlap it. */
5010 diff
= bitpos
- piece_bitpos
+ bitsize
;
5013 while (diff
> 0 && *src
)
5016 diff
-= decl_piece_bitsize (piece
);
5018 src
= &XEXP (piece
, 1);
5021 *src
= XEXP (piece
, 1);
5022 free_EXPR_LIST_node (piece
);
5025 /* Add padding if needed. */
5026 if (diff
< 0 && *src
)
5030 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5031 dest
= &XEXP (*dest
, 1);
5035 /* Finally copy all nodes following it. */
5038 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5039 decl_piece_bitsize (*src
), NULL_RTX
);
5040 dest
= &XEXP (*dest
, 1);
5041 src
= &XEXP (*src
, 1);
5045 /* Add a variable location node to the linked list for DECL. */
5047 static struct var_loc_node
*
5048 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5050 unsigned int decl_id
;
5053 struct var_loc_node
*loc
= NULL
;
5054 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5056 if (TREE_CODE (decl
) == VAR_DECL
5057 && DECL_HAS_DEBUG_EXPR_P (decl
))
5059 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5060 if (handled_component_p (realdecl
)
5061 || (TREE_CODE (realdecl
) == MEM_REF
5062 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5064 HOST_WIDE_INT maxsize
;
5067 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5068 if (!DECL_P (innerdecl
)
5069 || DECL_IGNORED_P (innerdecl
)
5070 || TREE_STATIC (innerdecl
)
5072 || bitpos
+ bitsize
> 256
5073 || bitsize
!= maxsize
)
5079 decl_id
= DECL_UID (decl
);
5080 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5083 temp
= ggc_alloc_cleared_var_loc_list ();
5084 temp
->decl_id
= decl_id
;
5088 temp
= (var_loc_list
*) *slot
;
5090 /* For PARM_DECLs try to keep around the original incoming value,
5091 even if that means we'll emit a zero-range .debug_loc entry. */
5093 && temp
->first
== temp
->last
5094 && TREE_CODE (decl
) == PARM_DECL
5095 && NOTE_P (temp
->first
->loc
)
5096 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5097 && DECL_INCOMING_RTL (decl
)
5098 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5099 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5100 == GET_CODE (DECL_INCOMING_RTL (decl
))
5101 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5103 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5104 NOTE_VAR_LOCATION_LOC (loc_note
))
5105 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5106 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5108 loc
= ggc_alloc_cleared_var_loc_node ();
5109 temp
->first
->next
= loc
;
5111 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5113 else if (temp
->last
)
5115 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5116 rtx
*piece_loc
= NULL
, last_loc_note
;
5117 int piece_bitpos
= 0;
5121 gcc_assert (last
->next
== NULL
);
5123 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5125 piece_loc
= &last
->loc
;
5128 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5129 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5131 piece_bitpos
+= cur_bitsize
;
5132 piece_loc
= &XEXP (*piece_loc
, 1);
5136 /* TEMP->LAST here is either pointer to the last but one or
5137 last element in the chained list, LAST is pointer to the
5139 if (label
&& strcmp (last
->label
, label
) == 0)
5141 /* For SRA optimized variables if there weren't any real
5142 insns since last note, just modify the last node. */
5143 if (piece_loc
!= NULL
)
5145 adjust_piece_list (piece_loc
, NULL
, NULL
,
5146 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5149 /* If the last note doesn't cover any instructions, remove it. */
5150 if (temp
->last
!= last
)
5152 temp
->last
->next
= NULL
;
5155 gcc_assert (strcmp (last
->label
, label
) != 0);
5159 gcc_assert (temp
->first
== temp
->last
5160 || (temp
->first
->next
== temp
->last
5161 && TREE_CODE (decl
) == PARM_DECL
));
5162 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5163 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5167 if (bitsize
== -1 && NOTE_P (last
->loc
))
5168 last_loc_note
= last
->loc
;
5169 else if (piece_loc
!= NULL
5170 && *piece_loc
!= NULL_RTX
5171 && piece_bitpos
== bitpos
5172 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5173 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5175 last_loc_note
= NULL_RTX
;
5176 /* If the current location is the same as the end of the list,
5177 and either both or neither of the locations is uninitialized,
5178 we have nothing to do. */
5179 if (last_loc_note
== NULL_RTX
5180 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5181 NOTE_VAR_LOCATION_LOC (loc_note
)))
5182 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5183 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5184 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5185 == VAR_INIT_STATUS_UNINITIALIZED
)
5186 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5187 == VAR_INIT_STATUS_UNINITIALIZED
))))
5189 /* Add LOC to the end of list and update LAST. If the last
5190 element of the list has been removed above, reuse its
5191 memory for the new node, otherwise allocate a new one. */
5195 memset (loc
, '\0', sizeof (*loc
));
5198 loc
= ggc_alloc_cleared_var_loc_node ();
5199 if (bitsize
== -1 || piece_loc
== NULL
)
5200 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5202 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5203 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5205 /* Ensure TEMP->LAST will point either to the new last but one
5206 element of the chain, or to the last element in it. */
5207 if (last
!= temp
->last
)
5215 loc
= ggc_alloc_cleared_var_loc_node ();
5218 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5223 /* Keep track of the number of spaces used to indent the
5224 output of the debugging routines that print the structure of
5225 the DIE internal representation. */
5226 static int print_indent
;
5228 /* Indent the line the number of spaces given by print_indent. */
5231 print_spaces (FILE *outfile
)
5233 fprintf (outfile
, "%*s", print_indent
, "");
5236 /* Print a type signature in hex. */
5239 print_signature (FILE *outfile
, char *sig
)
5243 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5244 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5247 /* Print the information associated with a given DIE, and its children.
5248 This routine is a debugging aid only. */
5251 print_die (dw_die_ref die
, FILE *outfile
)
5257 print_spaces (outfile
);
5258 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5259 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5261 print_spaces (outfile
);
5262 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5263 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5264 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5266 if (die
->comdat_type_p
)
5268 print_spaces (outfile
);
5269 fprintf (outfile
, " signature: ");
5270 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5271 fprintf (outfile
, "\n");
5274 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5276 print_spaces (outfile
);
5277 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5279 switch (AT_class (a
))
5281 case dw_val_class_addr
:
5282 fprintf (outfile
, "address");
5284 case dw_val_class_offset
:
5285 fprintf (outfile
, "offset");
5287 case dw_val_class_loc
:
5288 fprintf (outfile
, "location descriptor");
5290 case dw_val_class_loc_list
:
5291 fprintf (outfile
, "location list -> label:%s",
5292 AT_loc_list (a
)->ll_symbol
);
5294 case dw_val_class_range_list
:
5295 fprintf (outfile
, "range list");
5297 case dw_val_class_const
:
5298 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5300 case dw_val_class_unsigned_const
:
5301 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5303 case dw_val_class_const_double
:
5304 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5305 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5306 a
->dw_attr_val
.v
.val_double
.high
,
5307 a
->dw_attr_val
.v
.val_double
.low
);
5309 case dw_val_class_vec
:
5310 fprintf (outfile
, "floating-point or vector constant");
5312 case dw_val_class_flag
:
5313 fprintf (outfile
, "%u", AT_flag (a
));
5315 case dw_val_class_die_ref
:
5316 if (AT_ref (a
) != NULL
)
5318 if (AT_ref (a
)->comdat_type_p
)
5320 fprintf (outfile
, "die -> signature: ");
5321 print_signature (outfile
,
5322 AT_ref (a
)->die_id
.die_type_node
->signature
);
5324 else if (AT_ref (a
)->die_id
.die_symbol
)
5325 fprintf (outfile
, "die -> label: %s",
5326 AT_ref (a
)->die_id
.die_symbol
);
5328 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5329 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5332 fprintf (outfile
, "die -> <null>");
5334 case dw_val_class_vms_delta
:
5335 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5336 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5338 case dw_val_class_lbl_id
:
5339 case dw_val_class_lineptr
:
5340 case dw_val_class_macptr
:
5341 case dw_val_class_high_pc
:
5342 fprintf (outfile
, "label: %s", AT_lbl (a
));
5344 case dw_val_class_str
:
5345 if (AT_string (a
) != NULL
)
5346 fprintf (outfile
, "\"%s\"", AT_string (a
));
5348 fprintf (outfile
, "<null>");
5350 case dw_val_class_file
:
5351 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5352 AT_file (a
)->emitted_number
);
5354 case dw_val_class_data8
:
5358 for (i
= 0; i
< 8; i
++)
5359 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5366 fprintf (outfile
, "\n");
5369 if (die
->die_child
!= NULL
)
5372 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5375 if (print_indent
== 0)
5376 fprintf (outfile
, "\n");
5379 /* Print the information collected for a given DIE. */
5382 debug_dwarf_die (dw_die_ref die
)
5384 print_die (die
, stderr
);
5388 debug (die_struct
&ref
)
5390 print_die (&ref
, stderr
);
5394 debug (die_struct
*ptr
)
5399 fprintf (stderr
, "<nil>\n");
5403 /* Print all DWARF information collected for the compilation unit.
5404 This routine is a debugging aid only. */
5410 print_die (comp_unit_die (), stderr
);
5413 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5414 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5415 DIE that marks the start of the DIEs for this include file. */
5418 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5420 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5421 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5423 new_unit
->die_sib
= old_unit
;
5427 /* Close an include-file CU and reopen the enclosing one. */
5430 pop_compile_unit (dw_die_ref old_unit
)
5432 dw_die_ref new_unit
= old_unit
->die_sib
;
5434 old_unit
->die_sib
= NULL
;
5438 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5439 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5440 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5442 /* Calculate the checksum of a location expression. */
5445 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5450 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5452 hash
= hash_loc_operands (loc
, hash
);
5456 /* Calculate the checksum of an attribute. */
5459 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5461 dw_loc_descr_ref loc
;
5464 CHECKSUM (at
->dw_attr
);
5466 /* We don't care that this was compiled with a different compiler
5467 snapshot; if the output is the same, that's what matters. */
5468 if (at
->dw_attr
== DW_AT_producer
)
5471 switch (AT_class (at
))
5473 case dw_val_class_const
:
5474 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5476 case dw_val_class_unsigned_const
:
5477 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5479 case dw_val_class_const_double
:
5480 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5482 case dw_val_class_vec
:
5483 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5484 (at
->dw_attr_val
.v
.val_vec
.length
5485 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5487 case dw_val_class_flag
:
5488 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5490 case dw_val_class_str
:
5491 CHECKSUM_STRING (AT_string (at
));
5494 case dw_val_class_addr
:
5496 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5497 CHECKSUM_STRING (XSTR (r
, 0));
5500 case dw_val_class_offset
:
5501 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5504 case dw_val_class_loc
:
5505 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5506 loc_checksum (loc
, ctx
);
5509 case dw_val_class_die_ref
:
5510 die_checksum (AT_ref (at
), ctx
, mark
);
5513 case dw_val_class_fde_ref
:
5514 case dw_val_class_vms_delta
:
5515 case dw_val_class_lbl_id
:
5516 case dw_val_class_lineptr
:
5517 case dw_val_class_macptr
:
5518 case dw_val_class_high_pc
:
5521 case dw_val_class_file
:
5522 CHECKSUM_STRING (AT_file (at
)->filename
);
5525 case dw_val_class_data8
:
5526 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5534 /* Calculate the checksum of a DIE. */
5537 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5543 /* To avoid infinite recursion. */
5546 CHECKSUM (die
->die_mark
);
5549 die
->die_mark
= ++(*mark
);
5551 CHECKSUM (die
->die_tag
);
5553 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5554 attr_checksum (a
, ctx
, mark
);
5556 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5560 #undef CHECKSUM_BLOCK
5561 #undef CHECKSUM_STRING
5563 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5564 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5565 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5566 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5567 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5568 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5569 #define CHECKSUM_ATTR(FOO) \
5570 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5572 /* Calculate the checksum of a number in signed LEB128 format. */
5575 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5582 byte
= (value
& 0x7f);
5584 more
= !((value
== 0 && (byte
& 0x40) == 0)
5585 || (value
== -1 && (byte
& 0x40) != 0));
5594 /* Calculate the checksum of a number in unsigned LEB128 format. */
5597 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5601 unsigned char byte
= (value
& 0x7f);
5604 /* More bytes to follow. */
5612 /* Checksum the context of the DIE. This adds the names of any
5613 surrounding namespaces or structures to the checksum. */
5616 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5620 int tag
= die
->die_tag
;
5622 if (tag
!= DW_TAG_namespace
5623 && tag
!= DW_TAG_structure_type
5624 && tag
!= DW_TAG_class_type
)
5627 name
= get_AT_string (die
, DW_AT_name
);
5629 spec
= get_AT_ref (die
, DW_AT_specification
);
5633 if (die
->die_parent
!= NULL
)
5634 checksum_die_context (die
->die_parent
, ctx
);
5636 CHECKSUM_ULEB128 ('C');
5637 CHECKSUM_ULEB128 (tag
);
5639 CHECKSUM_STRING (name
);
5642 /* Calculate the checksum of a location expression. */
5645 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5647 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5648 were emitted as a DW_FORM_sdata instead of a location expression. */
5649 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5651 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5652 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5656 /* Otherwise, just checksum the raw location expression. */
5661 CHECKSUM_ULEB128 (loc
->dtprel
);
5662 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5663 hash
= hash_loc_operands (loc
, hash
);
5665 loc
= loc
->dw_loc_next
;
5669 /* Calculate the checksum of an attribute. */
5672 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5673 struct md5_ctx
*ctx
, int *mark
)
5675 dw_loc_descr_ref loc
;
5678 if (AT_class (at
) == dw_val_class_die_ref
)
5680 dw_die_ref target_die
= AT_ref (at
);
5682 /* For pointer and reference types, we checksum only the (qualified)
5683 name of the target type (if there is a name). For friend entries,
5684 we checksum only the (qualified) name of the target type or function.
5685 This allows the checksum to remain the same whether the target type
5686 is complete or not. */
5687 if ((at
->dw_attr
== DW_AT_type
5688 && (tag
== DW_TAG_pointer_type
5689 || tag
== DW_TAG_reference_type
5690 || tag
== DW_TAG_rvalue_reference_type
5691 || tag
== DW_TAG_ptr_to_member_type
))
5692 || (at
->dw_attr
== DW_AT_friend
5693 && tag
== DW_TAG_friend
))
5695 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5697 if (name_attr
!= NULL
)
5699 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5703 CHECKSUM_ULEB128 ('N');
5704 CHECKSUM_ULEB128 (at
->dw_attr
);
5705 if (decl
->die_parent
!= NULL
)
5706 checksum_die_context (decl
->die_parent
, ctx
);
5707 CHECKSUM_ULEB128 ('E');
5708 CHECKSUM_STRING (AT_string (name_attr
));
5713 /* For all other references to another DIE, we check to see if the
5714 target DIE has already been visited. If it has, we emit a
5715 backward reference; if not, we descend recursively. */
5716 if (target_die
->die_mark
> 0)
5718 CHECKSUM_ULEB128 ('R');
5719 CHECKSUM_ULEB128 (at
->dw_attr
);
5720 CHECKSUM_ULEB128 (target_die
->die_mark
);
5724 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5728 target_die
->die_mark
= ++(*mark
);
5729 CHECKSUM_ULEB128 ('T');
5730 CHECKSUM_ULEB128 (at
->dw_attr
);
5731 if (decl
->die_parent
!= NULL
)
5732 checksum_die_context (decl
->die_parent
, ctx
);
5733 die_checksum_ordered (target_die
, ctx
, mark
);
5738 CHECKSUM_ULEB128 ('A');
5739 CHECKSUM_ULEB128 (at
->dw_attr
);
5741 switch (AT_class (at
))
5743 case dw_val_class_const
:
5744 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5745 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5748 case dw_val_class_unsigned_const
:
5749 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5750 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5753 case dw_val_class_const_double
:
5754 CHECKSUM_ULEB128 (DW_FORM_block
);
5755 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5756 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5759 case dw_val_class_vec
:
5760 CHECKSUM_ULEB128 (DW_FORM_block
);
5761 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
5762 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
5763 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5764 (at
->dw_attr_val
.v
.val_vec
.length
5765 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5768 case dw_val_class_flag
:
5769 CHECKSUM_ULEB128 (DW_FORM_flag
);
5770 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5773 case dw_val_class_str
:
5774 CHECKSUM_ULEB128 (DW_FORM_string
);
5775 CHECKSUM_STRING (AT_string (at
));
5778 case dw_val_class_addr
:
5780 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5781 CHECKSUM_ULEB128 (DW_FORM_string
);
5782 CHECKSUM_STRING (XSTR (r
, 0));
5785 case dw_val_class_offset
:
5786 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5787 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5790 case dw_val_class_loc
:
5791 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5792 loc_checksum_ordered (loc
, ctx
);
5795 case dw_val_class_fde_ref
:
5796 case dw_val_class_lbl_id
:
5797 case dw_val_class_lineptr
:
5798 case dw_val_class_macptr
:
5799 case dw_val_class_high_pc
:
5802 case dw_val_class_file
:
5803 CHECKSUM_ULEB128 (DW_FORM_string
);
5804 CHECKSUM_STRING (AT_file (at
)->filename
);
5807 case dw_val_class_data8
:
5808 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5816 struct checksum_attributes
5818 dw_attr_ref at_name
;
5819 dw_attr_ref at_type
;
5820 dw_attr_ref at_friend
;
5821 dw_attr_ref at_accessibility
;
5822 dw_attr_ref at_address_class
;
5823 dw_attr_ref at_allocated
;
5824 dw_attr_ref at_artificial
;
5825 dw_attr_ref at_associated
;
5826 dw_attr_ref at_binary_scale
;
5827 dw_attr_ref at_bit_offset
;
5828 dw_attr_ref at_bit_size
;
5829 dw_attr_ref at_bit_stride
;
5830 dw_attr_ref at_byte_size
;
5831 dw_attr_ref at_byte_stride
;
5832 dw_attr_ref at_const_value
;
5833 dw_attr_ref at_containing_type
;
5834 dw_attr_ref at_count
;
5835 dw_attr_ref at_data_location
;
5836 dw_attr_ref at_data_member_location
;
5837 dw_attr_ref at_decimal_scale
;
5838 dw_attr_ref at_decimal_sign
;
5839 dw_attr_ref at_default_value
;
5840 dw_attr_ref at_digit_count
;
5841 dw_attr_ref at_discr
;
5842 dw_attr_ref at_discr_list
;
5843 dw_attr_ref at_discr_value
;
5844 dw_attr_ref at_encoding
;
5845 dw_attr_ref at_endianity
;
5846 dw_attr_ref at_explicit
;
5847 dw_attr_ref at_is_optional
;
5848 dw_attr_ref at_location
;
5849 dw_attr_ref at_lower_bound
;
5850 dw_attr_ref at_mutable
;
5851 dw_attr_ref at_ordering
;
5852 dw_attr_ref at_picture_string
;
5853 dw_attr_ref at_prototyped
;
5854 dw_attr_ref at_small
;
5855 dw_attr_ref at_segment
;
5856 dw_attr_ref at_string_length
;
5857 dw_attr_ref at_threads_scaled
;
5858 dw_attr_ref at_upper_bound
;
5859 dw_attr_ref at_use_location
;
5860 dw_attr_ref at_use_UTF8
;
5861 dw_attr_ref at_variable_parameter
;
5862 dw_attr_ref at_virtuality
;
5863 dw_attr_ref at_visibility
;
5864 dw_attr_ref at_vtable_elem_location
;
5867 /* Collect the attributes that we will want to use for the checksum. */
5870 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5875 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5886 attrs
->at_friend
= a
;
5888 case DW_AT_accessibility
:
5889 attrs
->at_accessibility
= a
;
5891 case DW_AT_address_class
:
5892 attrs
->at_address_class
= a
;
5894 case DW_AT_allocated
:
5895 attrs
->at_allocated
= a
;
5897 case DW_AT_artificial
:
5898 attrs
->at_artificial
= a
;
5900 case DW_AT_associated
:
5901 attrs
->at_associated
= a
;
5903 case DW_AT_binary_scale
:
5904 attrs
->at_binary_scale
= a
;
5906 case DW_AT_bit_offset
:
5907 attrs
->at_bit_offset
= a
;
5909 case DW_AT_bit_size
:
5910 attrs
->at_bit_size
= a
;
5912 case DW_AT_bit_stride
:
5913 attrs
->at_bit_stride
= a
;
5915 case DW_AT_byte_size
:
5916 attrs
->at_byte_size
= a
;
5918 case DW_AT_byte_stride
:
5919 attrs
->at_byte_stride
= a
;
5921 case DW_AT_const_value
:
5922 attrs
->at_const_value
= a
;
5924 case DW_AT_containing_type
:
5925 attrs
->at_containing_type
= a
;
5928 attrs
->at_count
= a
;
5930 case DW_AT_data_location
:
5931 attrs
->at_data_location
= a
;
5933 case DW_AT_data_member_location
:
5934 attrs
->at_data_member_location
= a
;
5936 case DW_AT_decimal_scale
:
5937 attrs
->at_decimal_scale
= a
;
5939 case DW_AT_decimal_sign
:
5940 attrs
->at_decimal_sign
= a
;
5942 case DW_AT_default_value
:
5943 attrs
->at_default_value
= a
;
5945 case DW_AT_digit_count
:
5946 attrs
->at_digit_count
= a
;
5949 attrs
->at_discr
= a
;
5951 case DW_AT_discr_list
:
5952 attrs
->at_discr_list
= a
;
5954 case DW_AT_discr_value
:
5955 attrs
->at_discr_value
= a
;
5957 case DW_AT_encoding
:
5958 attrs
->at_encoding
= a
;
5960 case DW_AT_endianity
:
5961 attrs
->at_endianity
= a
;
5963 case DW_AT_explicit
:
5964 attrs
->at_explicit
= a
;
5966 case DW_AT_is_optional
:
5967 attrs
->at_is_optional
= a
;
5969 case DW_AT_location
:
5970 attrs
->at_location
= a
;
5972 case DW_AT_lower_bound
:
5973 attrs
->at_lower_bound
= a
;
5976 attrs
->at_mutable
= a
;
5978 case DW_AT_ordering
:
5979 attrs
->at_ordering
= a
;
5981 case DW_AT_picture_string
:
5982 attrs
->at_picture_string
= a
;
5984 case DW_AT_prototyped
:
5985 attrs
->at_prototyped
= a
;
5988 attrs
->at_small
= a
;
5991 attrs
->at_segment
= a
;
5993 case DW_AT_string_length
:
5994 attrs
->at_string_length
= a
;
5996 case DW_AT_threads_scaled
:
5997 attrs
->at_threads_scaled
= a
;
5999 case DW_AT_upper_bound
:
6000 attrs
->at_upper_bound
= a
;
6002 case DW_AT_use_location
:
6003 attrs
->at_use_location
= a
;
6005 case DW_AT_use_UTF8
:
6006 attrs
->at_use_UTF8
= a
;
6008 case DW_AT_variable_parameter
:
6009 attrs
->at_variable_parameter
= a
;
6011 case DW_AT_virtuality
:
6012 attrs
->at_virtuality
= a
;
6014 case DW_AT_visibility
:
6015 attrs
->at_visibility
= a
;
6017 case DW_AT_vtable_elem_location
:
6018 attrs
->at_vtable_elem_location
= a
;
6026 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6029 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6033 struct checksum_attributes attrs
;
6035 CHECKSUM_ULEB128 ('D');
6036 CHECKSUM_ULEB128 (die
->die_tag
);
6038 memset (&attrs
, 0, sizeof (attrs
));
6040 decl
= get_AT_ref (die
, DW_AT_specification
);
6042 collect_checksum_attributes (&attrs
, decl
);
6043 collect_checksum_attributes (&attrs
, die
);
6045 CHECKSUM_ATTR (attrs
.at_name
);
6046 CHECKSUM_ATTR (attrs
.at_accessibility
);
6047 CHECKSUM_ATTR (attrs
.at_address_class
);
6048 CHECKSUM_ATTR (attrs
.at_allocated
);
6049 CHECKSUM_ATTR (attrs
.at_artificial
);
6050 CHECKSUM_ATTR (attrs
.at_associated
);
6051 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6052 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6053 CHECKSUM_ATTR (attrs
.at_bit_size
);
6054 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6055 CHECKSUM_ATTR (attrs
.at_byte_size
);
6056 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6057 CHECKSUM_ATTR (attrs
.at_const_value
);
6058 CHECKSUM_ATTR (attrs
.at_containing_type
);
6059 CHECKSUM_ATTR (attrs
.at_count
);
6060 CHECKSUM_ATTR (attrs
.at_data_location
);
6061 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6062 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6063 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6064 CHECKSUM_ATTR (attrs
.at_default_value
);
6065 CHECKSUM_ATTR (attrs
.at_digit_count
);
6066 CHECKSUM_ATTR (attrs
.at_discr
);
6067 CHECKSUM_ATTR (attrs
.at_discr_list
);
6068 CHECKSUM_ATTR (attrs
.at_discr_value
);
6069 CHECKSUM_ATTR (attrs
.at_encoding
);
6070 CHECKSUM_ATTR (attrs
.at_endianity
);
6071 CHECKSUM_ATTR (attrs
.at_explicit
);
6072 CHECKSUM_ATTR (attrs
.at_is_optional
);
6073 CHECKSUM_ATTR (attrs
.at_location
);
6074 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6075 CHECKSUM_ATTR (attrs
.at_mutable
);
6076 CHECKSUM_ATTR (attrs
.at_ordering
);
6077 CHECKSUM_ATTR (attrs
.at_picture_string
);
6078 CHECKSUM_ATTR (attrs
.at_prototyped
);
6079 CHECKSUM_ATTR (attrs
.at_small
);
6080 CHECKSUM_ATTR (attrs
.at_segment
);
6081 CHECKSUM_ATTR (attrs
.at_string_length
);
6082 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6083 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6084 CHECKSUM_ATTR (attrs
.at_use_location
);
6085 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6086 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6087 CHECKSUM_ATTR (attrs
.at_virtuality
);
6088 CHECKSUM_ATTR (attrs
.at_visibility
);
6089 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6090 CHECKSUM_ATTR (attrs
.at_type
);
6091 CHECKSUM_ATTR (attrs
.at_friend
);
6093 /* Checksum the child DIEs. */
6096 dw_attr_ref name_attr
;
6099 name_attr
= get_AT (c
, DW_AT_name
);
6100 if (is_template_instantiation (c
))
6102 /* Ignore instantiations of member type and function templates. */
6104 else if (name_attr
!= NULL
6105 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6107 /* Use a shallow checksum for named nested types and member
6109 CHECKSUM_ULEB128 ('S');
6110 CHECKSUM_ULEB128 (c
->die_tag
);
6111 CHECKSUM_STRING (AT_string (name_attr
));
6115 /* Use a deep checksum for other children. */
6116 /* Mark this DIE so it gets processed when unmarking. */
6117 if (c
->die_mark
== 0)
6119 die_checksum_ordered (c
, ctx
, mark
);
6121 } while (c
!= die
->die_child
);
6123 CHECKSUM_ULEB128 (0);
6126 /* Add a type name and tag to a hash. */
6128 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6130 CHECKSUM_ULEB128 (tag
);
6131 CHECKSUM_STRING (name
);
6135 #undef CHECKSUM_STRING
6136 #undef CHECKSUM_ATTR
6137 #undef CHECKSUM_LEB128
6138 #undef CHECKSUM_ULEB128
6140 /* Generate the type signature for DIE. This is computed by generating an
6141 MD5 checksum over the DIE's tag, its relevant attributes, and its
6142 children. Attributes that are references to other DIEs are processed
6143 by recursion, using the MARK field to prevent infinite recursion.
6144 If the DIE is nested inside a namespace or another type, we also
6145 need to include that context in the signature. The lower 64 bits
6146 of the resulting MD5 checksum comprise the signature. */
6149 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6153 unsigned char checksum
[16];
6158 name
= get_AT_string (die
, DW_AT_name
);
6159 decl
= get_AT_ref (die
, DW_AT_specification
);
6160 parent
= get_die_parent (die
);
6162 /* First, compute a signature for just the type name (and its surrounding
6163 context, if any. This is stored in the type unit DIE for link-time
6164 ODR (one-definition rule) checking. */
6166 if (is_cxx() && name
!= NULL
)
6168 md5_init_ctx (&ctx
);
6170 /* Checksum the names of surrounding namespaces and structures. */
6172 checksum_die_context (parent
, &ctx
);
6174 /* Checksum the current DIE. */
6175 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6176 md5_finish_ctx (&ctx
, checksum
);
6178 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6181 /* Next, compute the complete type signature. */
6183 md5_init_ctx (&ctx
);
6185 die
->die_mark
= mark
;
6187 /* Checksum the names of surrounding namespaces and structures. */
6189 checksum_die_context (parent
, &ctx
);
6191 /* Checksum the DIE and its children. */
6192 die_checksum_ordered (die
, &ctx
, &mark
);
6193 unmark_all_dies (die
);
6194 md5_finish_ctx (&ctx
, checksum
);
6196 /* Store the signature in the type node and link the type DIE and the
6197 type node together. */
6198 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6199 DWARF_TYPE_SIGNATURE_SIZE
);
6200 die
->comdat_type_p
= true;
6201 die
->die_id
.die_type_node
= type_node
;
6202 type_node
->type_die
= die
;
6204 /* If the DIE is a specification, link its declaration to the type node
6208 decl
->comdat_type_p
= true;
6209 decl
->die_id
.die_type_node
= type_node
;
6213 /* Do the location expressions look same? */
6215 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6217 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6218 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6219 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6222 /* Do the values look the same? */
6224 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6226 dw_loc_descr_ref loc1
, loc2
;
6229 if (v1
->val_class
!= v2
->val_class
)
6232 switch (v1
->val_class
)
6234 case dw_val_class_const
:
6235 return v1
->v
.val_int
== v2
->v
.val_int
;
6236 case dw_val_class_unsigned_const
:
6237 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6238 case dw_val_class_const_double
:
6239 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6240 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6241 case dw_val_class_vec
:
6242 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6243 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6245 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6246 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6249 case dw_val_class_flag
:
6250 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6251 case dw_val_class_str
:
6252 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6254 case dw_val_class_addr
:
6255 r1
= v1
->v
.val_addr
;
6256 r2
= v2
->v
.val_addr
;
6257 if (GET_CODE (r1
) != GET_CODE (r2
))
6259 return !rtx_equal_p (r1
, r2
);
6261 case dw_val_class_offset
:
6262 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6264 case dw_val_class_loc
:
6265 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6267 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6268 if (!same_loc_p (loc1
, loc2
, mark
))
6270 return !loc1
&& !loc2
;
6272 case dw_val_class_die_ref
:
6273 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6275 case dw_val_class_fde_ref
:
6276 case dw_val_class_vms_delta
:
6277 case dw_val_class_lbl_id
:
6278 case dw_val_class_lineptr
:
6279 case dw_val_class_macptr
:
6280 case dw_val_class_high_pc
:
6283 case dw_val_class_file
:
6284 return v1
->v
.val_file
== v2
->v
.val_file
;
6286 case dw_val_class_data8
:
6287 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6294 /* Do the attributes look the same? */
6297 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6299 if (at1
->dw_attr
!= at2
->dw_attr
)
6302 /* We don't care that this was compiled with a different compiler
6303 snapshot; if the output is the same, that's what matters. */
6304 if (at1
->dw_attr
== DW_AT_producer
)
6307 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6310 /* Do the dies look the same? */
6313 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6319 /* To avoid infinite recursion. */
6321 return die1
->die_mark
== die2
->die_mark
;
6322 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6324 if (die1
->die_tag
!= die2
->die_tag
)
6327 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6330 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6331 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6334 c1
= die1
->die_child
;
6335 c2
= die2
->die_child
;
6344 if (!same_die_p (c1
, c2
, mark
))
6348 if (c1
== die1
->die_child
)
6350 if (c2
== die2
->die_child
)
6360 /* Do the dies look the same? Wrapper around same_die_p. */
6363 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6366 int ret
= same_die_p (die1
, die2
, &mark
);
6368 unmark_all_dies (die1
);
6369 unmark_all_dies (die2
);
6374 /* The prefix to attach to symbols on DIEs in the current comdat debug
6376 static const char *comdat_symbol_id
;
6378 /* The index of the current symbol within the current comdat CU. */
6379 static unsigned int comdat_symbol_number
;
6381 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6382 children, and set comdat_symbol_id accordingly. */
6385 compute_section_prefix (dw_die_ref unit_die
)
6387 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6388 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6389 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6392 unsigned char checksum
[16];
6395 /* Compute the checksum of the DIE, then append part of it as hex digits to
6396 the name filename of the unit. */
6398 md5_init_ctx (&ctx
);
6400 die_checksum (unit_die
, &ctx
, &mark
);
6401 unmark_all_dies (unit_die
);
6402 md5_finish_ctx (&ctx
, checksum
);
6404 sprintf (name
, "%s.", base
);
6405 clean_symbol_name (name
);
6407 p
= name
+ strlen (name
);
6408 for (i
= 0; i
< 4; i
++)
6410 sprintf (p
, "%.2x", checksum
[i
]);
6414 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6415 comdat_symbol_number
= 0;
6418 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6421 is_type_die (dw_die_ref die
)
6423 switch (die
->die_tag
)
6425 case DW_TAG_array_type
:
6426 case DW_TAG_class_type
:
6427 case DW_TAG_interface_type
:
6428 case DW_TAG_enumeration_type
:
6429 case DW_TAG_pointer_type
:
6430 case DW_TAG_reference_type
:
6431 case DW_TAG_rvalue_reference_type
:
6432 case DW_TAG_string_type
:
6433 case DW_TAG_structure_type
:
6434 case DW_TAG_subroutine_type
:
6435 case DW_TAG_union_type
:
6436 case DW_TAG_ptr_to_member_type
:
6437 case DW_TAG_set_type
:
6438 case DW_TAG_subrange_type
:
6439 case DW_TAG_base_type
:
6440 case DW_TAG_const_type
:
6441 case DW_TAG_file_type
:
6442 case DW_TAG_packed_type
:
6443 case DW_TAG_volatile_type
:
6444 case DW_TAG_typedef
:
6451 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6452 Basically, we want to choose the bits that are likely to be shared between
6453 compilations (types) and leave out the bits that are specific to individual
6454 compilations (functions). */
6457 is_comdat_die (dw_die_ref c
)
6459 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6460 we do for stabs. The advantage is a greater likelihood of sharing between
6461 objects that don't include headers in the same order (and therefore would
6462 put the base types in a different comdat). jason 8/28/00 */
6464 if (c
->die_tag
== DW_TAG_base_type
)
6467 if (c
->die_tag
== DW_TAG_pointer_type
6468 || c
->die_tag
== DW_TAG_reference_type
6469 || c
->die_tag
== DW_TAG_rvalue_reference_type
6470 || c
->die_tag
== DW_TAG_const_type
6471 || c
->die_tag
== DW_TAG_volatile_type
)
6473 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6475 return t
? is_comdat_die (t
) : 0;
6478 return is_type_die (c
);
6481 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6482 compilation unit. */
6485 is_symbol_die (dw_die_ref c
)
6487 return (is_type_die (c
)
6488 || is_declaration_die (c
)
6489 || c
->die_tag
== DW_TAG_namespace
6490 || c
->die_tag
== DW_TAG_module
);
6493 /* Returns true iff C is a compile-unit DIE. */
6496 is_cu_die (dw_die_ref c
)
6498 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6501 /* Returns true iff C is a unit DIE of some sort. */
6504 is_unit_die (dw_die_ref c
)
6506 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6507 || c
->die_tag
== DW_TAG_partial_unit
6508 || c
->die_tag
== DW_TAG_type_unit
);
6511 /* Returns true iff C is a namespace DIE. */
6514 is_namespace_die (dw_die_ref c
)
6516 return c
&& c
->die_tag
== DW_TAG_namespace
;
6519 /* Returns true iff C is a class or structure DIE. */
6522 is_class_die (dw_die_ref c
)
6524 return c
&& (c
->die_tag
== DW_TAG_class_type
6525 || c
->die_tag
== DW_TAG_structure_type
);
6528 /* Return non-zero if this DIE is a template parameter. */
6531 is_template_parameter (dw_die_ref die
)
6533 switch (die
->die_tag
)
6535 case DW_TAG_template_type_param
:
6536 case DW_TAG_template_value_param
:
6537 case DW_TAG_GNU_template_template_param
:
6538 case DW_TAG_GNU_template_parameter_pack
:
6545 /* Return non-zero if this DIE represents a template instantiation. */
6548 is_template_instantiation (dw_die_ref die
)
6552 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6554 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6559 gen_internal_sym (const char *prefix
)
6563 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6564 return xstrdup (buf
);
6567 /* Assign symbols to all worthy DIEs under DIE. */
6570 assign_symbol_names (dw_die_ref die
)
6574 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6576 if (comdat_symbol_id
)
6578 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6580 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6581 comdat_symbol_id
, comdat_symbol_number
++);
6582 die
->die_id
.die_symbol
= xstrdup (p
);
6585 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6588 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6591 struct cu_hash_table_entry
6594 unsigned min_comdat_num
, max_comdat_num
;
6595 struct cu_hash_table_entry
*next
;
6598 /* Helpers to manipulate hash table of CUs. */
6600 struct cu_hash_table_entry_hasher
6602 typedef cu_hash_table_entry value_type
;
6603 typedef die_struct compare_type
;
6604 static inline hashval_t
hash (const value_type
*);
6605 static inline bool equal (const value_type
*, const compare_type
*);
6606 static inline void remove (value_type
*);
6610 cu_hash_table_entry_hasher::hash (const value_type
*entry
)
6612 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6616 cu_hash_table_entry_hasher::equal (const value_type
*entry1
,
6617 const compare_type
*entry2
)
6619 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6623 cu_hash_table_entry_hasher::remove (value_type
*entry
)
6625 struct cu_hash_table_entry
*next
;
6635 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6637 /* Check whether we have already seen this CU and set up SYM_NUM
6640 check_duplicate_cu (dw_die_ref cu
, cu_hash_type htable
, unsigned int *sym_num
)
6642 struct cu_hash_table_entry dummy
;
6643 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6645 dummy
.max_comdat_num
= 0;
6647 slot
= htable
.find_slot_with_hash (cu
,
6648 htab_hash_string (cu
->die_id
.die_symbol
),
6652 for (; entry
; last
= entry
, entry
= entry
->next
)
6654 if (same_die_p_wrap (cu
, entry
->cu
))
6660 *sym_num
= entry
->min_comdat_num
;
6664 entry
= XCNEW (struct cu_hash_table_entry
);
6666 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6667 entry
->next
= *slot
;
6673 /* Record SYM_NUM to record of CU in HTABLE. */
6675 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type htable
,
6676 unsigned int sym_num
)
6678 struct cu_hash_table_entry
**slot
, *entry
;
6680 slot
= htable
.find_slot_with_hash (cu
,
6681 htab_hash_string (cu
->die_id
.die_symbol
),
6685 entry
->max_comdat_num
= sym_num
;
6688 /* Traverse the DIE (which is always comp_unit_die), and set up
6689 additional compilation units for each of the include files we see
6690 bracketed by BINCL/EINCL. */
6693 break_out_includes (dw_die_ref die
)
6696 dw_die_ref unit
= NULL
;
6697 limbo_die_node
*node
, **pnode
;
6698 cu_hash_type cu_hash_table
;
6702 dw_die_ref prev
= c
;
6704 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6705 || (unit
&& is_comdat_die (c
)))
6707 dw_die_ref next
= c
->die_sib
;
6709 /* This DIE is for a secondary CU; remove it from the main one. */
6710 remove_child_with_prev (c
, prev
);
6712 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6713 unit
= push_new_compile_unit (unit
, c
);
6714 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6715 unit
= pop_compile_unit (unit
);
6717 add_child_die (unit
, c
);
6719 if (c
== die
->die_child
)
6722 } while (c
!= die
->die_child
);
6725 /* We can only use this in debugging, since the frontend doesn't check
6726 to make sure that we leave every include file we enter. */
6730 assign_symbol_names (die
);
6731 cu_hash_table
.create (10);
6732 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6738 compute_section_prefix (node
->die
);
6739 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6740 &comdat_symbol_number
);
6741 assign_symbol_names (node
->die
);
6743 *pnode
= node
->next
;
6746 pnode
= &node
->next
;
6747 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6748 comdat_symbol_number
);
6751 cu_hash_table
.dispose ();
6754 /* Return non-zero if this DIE is a declaration. */
6757 is_declaration_die (dw_die_ref die
)
6762 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6763 if (a
->dw_attr
== DW_AT_declaration
)
6769 /* Return non-zero if this DIE is nested inside a subprogram. */
6772 is_nested_in_subprogram (dw_die_ref die
)
6774 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6778 return local_scope_p (decl
);
6781 /* Return non-zero if this DIE contains a defining declaration of a
6785 contains_subprogram_definition (dw_die_ref die
)
6789 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6791 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6795 /* Return non-zero if this is a type DIE that should be moved to a
6796 COMDAT .debug_types section. */
6799 should_move_die_to_comdat (dw_die_ref die
)
6801 switch (die
->die_tag
)
6803 case DW_TAG_class_type
:
6804 case DW_TAG_structure_type
:
6805 case DW_TAG_enumeration_type
:
6806 case DW_TAG_union_type
:
6807 /* Don't move declarations, inlined instances, or types nested in a
6809 if (is_declaration_die (die
)
6810 || get_AT (die
, DW_AT_abstract_origin
)
6811 || is_nested_in_subprogram (die
))
6813 /* A type definition should never contain a subprogram definition. */
6814 gcc_assert (!contains_subprogram_definition (die
));
6816 case DW_TAG_array_type
:
6817 case DW_TAG_interface_type
:
6818 case DW_TAG_pointer_type
:
6819 case DW_TAG_reference_type
:
6820 case DW_TAG_rvalue_reference_type
:
6821 case DW_TAG_string_type
:
6822 case DW_TAG_subroutine_type
:
6823 case DW_TAG_ptr_to_member_type
:
6824 case DW_TAG_set_type
:
6825 case DW_TAG_subrange_type
:
6826 case DW_TAG_base_type
:
6827 case DW_TAG_const_type
:
6828 case DW_TAG_file_type
:
6829 case DW_TAG_packed_type
:
6830 case DW_TAG_volatile_type
:
6831 case DW_TAG_typedef
:
6837 /* Make a clone of DIE. */
6840 clone_die (dw_die_ref die
)
6846 clone
= ggc_alloc_cleared_die_node ();
6847 clone
->die_tag
= die
->die_tag
;
6849 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6850 add_dwarf_attr (clone
, a
);
6855 /* Make a clone of the tree rooted at DIE. */
6858 clone_tree (dw_die_ref die
)
6861 dw_die_ref clone
= clone_die (die
);
6863 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
6868 /* Make a clone of DIE as a declaration. */
6871 clone_as_declaration (dw_die_ref die
)
6878 /* If the DIE is already a declaration, just clone it. */
6879 if (is_declaration_die (die
))
6880 return clone_die (die
);
6882 /* If the DIE is a specification, just clone its declaration DIE. */
6883 decl
= get_AT_ref (die
, DW_AT_specification
);
6886 clone
= clone_die (decl
);
6887 if (die
->comdat_type_p
)
6888 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6892 clone
= ggc_alloc_cleared_die_node ();
6893 clone
->die_tag
= die
->die_tag
;
6895 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6897 /* We don't want to copy over all attributes.
6898 For example we don't want DW_AT_byte_size because otherwise we will no
6899 longer have a declaration and GDB will treat it as a definition. */
6903 case DW_AT_artificial
:
6904 case DW_AT_containing_type
:
6905 case DW_AT_external
:
6908 case DW_AT_virtuality
:
6909 case DW_AT_linkage_name
:
6910 case DW_AT_MIPS_linkage_name
:
6911 add_dwarf_attr (clone
, a
);
6913 case DW_AT_byte_size
:
6919 if (die
->comdat_type_p
)
6920 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6922 add_AT_flag (clone
, DW_AT_declaration
, 1);
6927 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
6929 struct decl_table_entry
6935 /* Helpers to manipulate hash table of copied declarations. */
6937 /* Hashtable helpers. */
6939 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
6941 typedef decl_table_entry value_type
;
6942 typedef die_struct compare_type
;
6943 static inline hashval_t
hash (const value_type
*);
6944 static inline bool equal (const value_type
*, const compare_type
*);
6948 decl_table_entry_hasher::hash (const value_type
*entry
)
6950 return htab_hash_pointer (entry
->orig
);
6954 decl_table_entry_hasher::equal (const value_type
*entry1
,
6955 const compare_type
*entry2
)
6957 return entry1
->orig
== entry2
;
6960 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
6962 /* Copy DIE and its ancestors, up to, but not including, the compile unit
6963 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
6964 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
6965 to check if the ancestor has already been copied into UNIT. */
6968 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
6970 dw_die_ref parent
= die
->die_parent
;
6971 dw_die_ref new_parent
= unit
;
6973 decl_table_entry
**slot
= NULL
;
6974 struct decl_table_entry
*entry
= NULL
;
6976 if (decl_table
.is_created ())
6978 /* Check if the entry has already been copied to UNIT. */
6979 slot
= decl_table
.find_slot_with_hash (die
, htab_hash_pointer (die
),
6981 if (*slot
!= HTAB_EMPTY_ENTRY
)
6987 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
6988 entry
= XCNEW (struct decl_table_entry
);
6996 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
6999 if (!is_unit_die (parent
))
7000 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7003 copy
= clone_as_declaration (die
);
7004 add_child_die (new_parent
, copy
);
7006 if (decl_table
.is_created ())
7008 /* Record the pointer to the copy. */
7014 /* Copy the declaration context to the new type unit DIE. This includes
7015 any surrounding namespace or type declarations. If the DIE has an
7016 AT_specification attribute, it also includes attributes and children
7017 attached to the specification, and returns a pointer to the original
7018 parent of the declaration DIE. Returns NULL otherwise. */
7021 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7024 dw_die_ref new_decl
;
7025 dw_die_ref orig_parent
= NULL
;
7027 decl
= get_AT_ref (die
, DW_AT_specification
);
7036 /* The original DIE will be changed to a declaration, and must
7037 be moved to be a child of the original declaration DIE. */
7038 orig_parent
= decl
->die_parent
;
7040 /* Copy the type node pointer from the new DIE to the original
7041 declaration DIE so we can forward references later. */
7042 decl
->comdat_type_p
= true;
7043 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7045 remove_AT (die
, DW_AT_specification
);
7047 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7049 if (a
->dw_attr
!= DW_AT_name
7050 && a
->dw_attr
!= DW_AT_declaration
7051 && a
->dw_attr
!= DW_AT_external
)
7052 add_dwarf_attr (die
, a
);
7055 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
7058 if (decl
->die_parent
!= NULL
7059 && !is_unit_die (decl
->die_parent
))
7061 new_decl
= copy_ancestor_tree (unit
, decl
, decl_hash_type ());
7062 if (new_decl
!= NULL
)
7064 remove_AT (new_decl
, DW_AT_signature
);
7065 add_AT_specification (die
, new_decl
);
7072 /* Generate the skeleton ancestor tree for the given NODE, then clone
7073 the DIE and add the clone into the tree. */
7076 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7078 if (node
->new_die
!= NULL
)
7081 node
->new_die
= clone_as_declaration (node
->old_die
);
7083 if (node
->parent
!= NULL
)
7085 generate_skeleton_ancestor_tree (node
->parent
);
7086 add_child_die (node
->parent
->new_die
, node
->new_die
);
7090 /* Generate a skeleton tree of DIEs containing any declarations that are
7091 found in the original tree. We traverse the tree looking for declaration
7092 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7095 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7097 skeleton_chain_node node
;
7100 dw_die_ref prev
= NULL
;
7101 dw_die_ref next
= NULL
;
7103 node
.parent
= parent
;
7105 first
= c
= parent
->old_die
->die_child
;
7109 if (prev
== NULL
|| prev
->die_sib
== c
)
7112 next
= (c
== first
? NULL
: c
->die_sib
);
7114 node
.new_die
= NULL
;
7115 if (is_declaration_die (c
))
7117 if (is_template_instantiation (c
))
7119 /* Instantiated templates do not need to be cloned into the
7120 type unit. Just move the DIE and its children back to
7121 the skeleton tree (in the main CU). */
7122 remove_child_with_prev (c
, prev
);
7123 add_child_die (parent
->new_die
, c
);
7128 /* Clone the existing DIE, move the original to the skeleton
7129 tree (which is in the main CU), and put the clone, with
7130 all the original's children, where the original came from
7131 (which is about to be moved to the type unit). */
7132 dw_die_ref clone
= clone_die (c
);
7133 move_all_children (c
, clone
);
7135 replace_child (c
, clone
, prev
);
7136 generate_skeleton_ancestor_tree (parent
);
7137 add_child_die (parent
->new_die
, c
);
7142 generate_skeleton_bottom_up (&node
);
7143 } while (next
!= NULL
);
7146 /* Wrapper function for generate_skeleton_bottom_up. */
7149 generate_skeleton (dw_die_ref die
)
7151 skeleton_chain_node node
;
7154 node
.new_die
= NULL
;
7157 /* If this type definition is nested inside another type,
7158 and is not an instantiation of a template, always leave
7159 at least a declaration in its place. */
7160 if (die
->die_parent
!= NULL
7161 && is_type_die (die
->die_parent
)
7162 && !is_template_instantiation (die
))
7163 node
.new_die
= clone_as_declaration (die
);
7165 generate_skeleton_bottom_up (&node
);
7166 return node
.new_die
;
7169 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7170 declaration. The original DIE is moved to a new compile unit so that
7171 existing references to it follow it to the new location. If any of the
7172 original DIE's descendants is a declaration, we need to replace the
7173 original DIE with a skeleton tree and move the declarations back into the
7177 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7180 dw_die_ref skeleton
, orig_parent
;
7182 /* Copy the declaration context to the type unit DIE. If the returned
7183 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7185 orig_parent
= copy_declaration_context (unit
, child
);
7187 skeleton
= generate_skeleton (child
);
7188 if (skeleton
== NULL
)
7189 remove_child_with_prev (child
, prev
);
7192 skeleton
->comdat_type_p
= true;
7193 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7195 /* If the original DIE was a specification, we need to put
7196 the skeleton under the parent DIE of the declaration.
7197 This leaves the original declaration in the tree, but
7198 it will be pruned later since there are no longer any
7199 references to it. */
7200 if (orig_parent
!= NULL
)
7202 remove_child_with_prev (child
, prev
);
7203 add_child_die (orig_parent
, skeleton
);
7206 replace_child (child
, skeleton
, prev
);
7212 /* Traverse the DIE and set up additional .debug_types sections for each
7213 type worthy of being placed in a COMDAT section. */
7216 break_out_comdat_types (dw_die_ref die
)
7220 dw_die_ref prev
= NULL
;
7221 dw_die_ref next
= NULL
;
7222 dw_die_ref unit
= NULL
;
7224 first
= c
= die
->die_child
;
7228 if (prev
== NULL
|| prev
->die_sib
== c
)
7231 next
= (c
== first
? NULL
: c
->die_sib
);
7232 if (should_move_die_to_comdat (c
))
7234 dw_die_ref replacement
;
7235 comdat_type_node_ref type_node
;
7237 /* Break out nested types into their own type units. */
7238 break_out_comdat_types (c
);
7240 /* Create a new type unit DIE as the root for the new tree, and
7241 add it to the list of comdat types. */
7242 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7243 add_AT_unsigned (unit
, DW_AT_language
,
7244 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7245 type_node
= ggc_alloc_cleared_comdat_type_node ();
7246 type_node
->root_die
= unit
;
7247 type_node
->next
= comdat_type_list
;
7248 comdat_type_list
= type_node
;
7250 /* Generate the type signature. */
7251 generate_type_signature (c
, type_node
);
7253 /* Copy the declaration context, attributes, and children of the
7254 declaration into the new type unit DIE, then remove this DIE
7255 from the main CU (or replace it with a skeleton if necessary). */
7256 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7257 type_node
->skeleton_die
= replacement
;
7259 /* Add the DIE to the new compunit. */
7260 add_child_die (unit
, c
);
7262 if (replacement
!= NULL
)
7265 else if (c
->die_tag
== DW_TAG_namespace
7266 || c
->die_tag
== DW_TAG_class_type
7267 || c
->die_tag
== DW_TAG_structure_type
7268 || c
->die_tag
== DW_TAG_union_type
)
7270 /* Look for nested types that can be broken out. */
7271 break_out_comdat_types (c
);
7273 } while (next
!= NULL
);
7276 /* Like clone_tree, but additionally enter all the children into
7277 the hash table decl_table. */
7280 clone_tree_hash (dw_die_ref die
, decl_hash_type decl_table
)
7283 dw_die_ref clone
= clone_die (die
);
7284 struct decl_table_entry
*entry
;
7285 decl_table_entry
**slot
= decl_table
.find_slot_with_hash (die
,
7286 htab_hash_pointer (die
), INSERT
);
7287 /* Assert that DIE isn't in the hash table yet. If it would be there
7288 before, the ancestors would be necessarily there as well, therefore
7289 clone_tree_hash wouldn't be called. */
7290 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7291 entry
= XCNEW (struct decl_table_entry
);
7293 entry
->copy
= clone
;
7296 FOR_EACH_CHILD (die
, c
,
7297 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7302 /* Walk the DIE and its children, looking for references to incomplete
7303 or trivial types that are unmarked (i.e., that are not in the current
7307 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
7313 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7315 if (AT_class (a
) == dw_val_class_die_ref
)
7317 dw_die_ref targ
= AT_ref (a
);
7318 decl_table_entry
**slot
;
7319 struct decl_table_entry
*entry
;
7321 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7324 slot
= decl_table
.find_slot_with_hash (targ
, htab_hash_pointer (targ
),
7327 if (*slot
!= HTAB_EMPTY_ENTRY
)
7329 /* TARG has already been copied, so we just need to
7330 modify the reference to point to the copy. */
7332 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7336 dw_die_ref parent
= unit
;
7337 dw_die_ref copy
= clone_die (targ
);
7339 /* Record in DECL_TABLE that TARG has been copied.
7340 Need to do this now, before the recursive call,
7341 because DECL_TABLE may be expanded and SLOT
7342 would no longer be a valid pointer. */
7343 entry
= XCNEW (struct decl_table_entry
);
7348 FOR_EACH_CHILD (targ
, c
,
7349 add_child_die (copy
,
7350 clone_tree_hash (c
, decl_table
)));
7352 /* Make sure the cloned tree is marked as part of the
7356 /* If TARG has surrounding context, copy its ancestor tree
7357 into the new type unit. */
7358 if (targ
->die_parent
!= NULL
7359 && !is_unit_die (targ
->die_parent
))
7360 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7363 add_child_die (parent
, copy
);
7364 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7366 /* Make sure the newly-copied DIE is walked. If it was
7367 installed in a previously-added context, it won't
7368 get visited otherwise. */
7371 /* Find the highest point of the newly-added tree,
7372 mark each node along the way, and walk from there. */
7373 parent
->die_mark
= 1;
7374 while (parent
->die_parent
7375 && parent
->die_parent
->die_mark
== 0)
7377 parent
= parent
->die_parent
;
7378 parent
->die_mark
= 1;
7380 copy_decls_walk (unit
, parent
, decl_table
);
7386 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7389 /* Copy declarations for "unworthy" types into the new comdat section.
7390 Incomplete types, modified types, and certain other types aren't broken
7391 out into comdat sections of their own, so they don't have a signature,
7392 and we need to copy the declaration into the same section so that we
7393 don't have an external reference. */
7396 copy_decls_for_unworthy_types (dw_die_ref unit
)
7398 decl_hash_type decl_table
;
7401 decl_table
.create (10);
7402 copy_decls_walk (unit
, unit
, decl_table
);
7403 decl_table
.dispose ();
7407 /* Traverse the DIE and add a sibling attribute if it may have the
7408 effect of speeding up access to siblings. To save some space,
7409 avoid generating sibling attributes for DIE's without children. */
7412 add_sibling_attributes (dw_die_ref die
)
7416 if (! die
->die_child
)
7419 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7420 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7422 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7425 /* Output all location lists for the DIE and its children. */
7428 output_location_lists (dw_die_ref die
)
7434 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7435 if (AT_class (a
) == dw_val_class_loc_list
)
7436 output_loc_list (AT_loc_list (a
));
7438 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7441 /* We want to limit the number of external references, because they are
7442 larger than local references: a relocation takes multiple words, and
7443 even a sig8 reference is always eight bytes, whereas a local reference
7444 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7445 So if we encounter multiple external references to the same type DIE, we
7446 make a local typedef stub for it and redirect all references there.
7448 This is the element of the hash table for keeping track of these
7458 /* Hashtable helpers. */
7460 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7462 typedef external_ref value_type
;
7463 typedef external_ref compare_type
;
7464 static inline hashval_t
hash (const value_type
*);
7465 static inline bool equal (const value_type
*, const compare_type
*);
7469 external_ref_hasher::hash (const value_type
*r
)
7471 dw_die_ref die
= r
->type
;
7474 /* We can't use the address of the DIE for hashing, because
7475 that will make the order of the stub DIEs non-deterministic. */
7476 if (! die
->comdat_type_p
)
7477 /* We have a symbol; use it to compute a hash. */
7478 h
= htab_hash_string (die
->die_id
.die_symbol
);
7481 /* We have a type signature; use a subset of the bits as the hash.
7482 The 8-byte signature is at least as large as hashval_t. */
7483 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7484 memcpy (&h
, type_node
->signature
, sizeof (h
));
7490 external_ref_hasher::equal (const value_type
*r1
, const compare_type
*r2
)
7492 return r1
->type
== r2
->type
;
7495 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7497 /* Return a pointer to the external_ref for references to DIE. */
7499 static struct external_ref
*
7500 lookup_external_ref (external_ref_hash_type map
, dw_die_ref die
)
7502 struct external_ref ref
, *ref_p
;
7503 external_ref
**slot
;
7506 slot
= map
.find_slot (&ref
, INSERT
);
7507 if (*slot
!= HTAB_EMPTY_ENTRY
)
7510 ref_p
= XCNEW (struct external_ref
);
7516 /* Subroutine of optimize_external_refs, below.
7518 If we see a type skeleton, record it as our stub. If we see external
7519 references, remember how many we've seen. */
7522 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type map
)
7527 struct external_ref
*ref_p
;
7529 if (is_type_die (die
)
7530 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7532 /* This is a local skeleton; use it for local references. */
7533 ref_p
= lookup_external_ref (map
, c
);
7537 /* Scan the DIE references, and remember any that refer to DIEs from
7538 other CUs (i.e. those which are not marked). */
7539 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7540 if (AT_class (a
) == dw_val_class_die_ref
7541 && (c
= AT_ref (a
))->die_mark
== 0
7544 ref_p
= lookup_external_ref (map
, c
);
7548 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7551 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7552 points to an external_ref, DATA is the CU we're processing. If we don't
7553 already have a local stub, and we have multiple refs, build a stub. */
7556 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7558 struct external_ref
*ref_p
= *slot
;
7560 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7562 /* We have multiple references to this type, so build a small stub.
7563 Both of these forms are a bit dodgy from the perspective of the
7564 DWARF standard, since technically they should have names. */
7565 dw_die_ref cu
= data
;
7566 dw_die_ref type
= ref_p
->type
;
7567 dw_die_ref stub
= NULL
;
7569 if (type
->comdat_type_p
)
7571 /* If we refer to this type via sig8, use AT_signature. */
7572 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7573 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7577 /* Otherwise, use a typedef with no name. */
7578 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7579 add_AT_die_ref (stub
, DW_AT_type
, type
);
7588 /* DIE is a unit; look through all the DIE references to see if there are
7589 any external references to types, and if so, create local stubs for
7590 them which will be applied in build_abbrev_table. This is useful because
7591 references to local DIEs are smaller. */
7593 static external_ref_hash_type
7594 optimize_external_refs (dw_die_ref die
)
7596 external_ref_hash_type map
;
7598 optimize_external_refs_1 (die
, map
);
7599 map
.traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7603 /* The format of each DIE (and its attribute value pairs) is encoded in an
7604 abbreviation table. This routine builds the abbreviation table and assigns
7605 a unique abbreviation id for each abbreviation entry. The children of each
7606 die are visited recursively. */
7609 build_abbrev_table (dw_die_ref die
, external_ref_hash_type extern_map
)
7611 unsigned long abbrev_id
;
7612 unsigned int n_alloc
;
7617 /* Scan the DIE references, and replace any that refer to
7618 DIEs from other CUs (i.e. those which are not marked) with
7619 the local stubs we built in optimize_external_refs. */
7620 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7621 if (AT_class (a
) == dw_val_class_die_ref
7622 && (c
= AT_ref (a
))->die_mark
== 0)
7624 struct external_ref
*ref_p
;
7625 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7627 ref_p
= lookup_external_ref (extern_map
, c
);
7628 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7629 change_AT_die_ref (a
, ref_p
->stub
);
7631 /* We aren't changing this reference, so mark it external. */
7632 set_AT_ref_external (a
, 1);
7635 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7637 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7638 dw_attr_ref die_a
, abbrev_a
;
7642 if (abbrev
->die_tag
!= die
->die_tag
)
7644 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7647 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7650 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7652 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7653 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7654 || (value_format (abbrev_a
) != value_format (die_a
)))
7664 if (abbrev_id
>= abbrev_die_table_in_use
)
7666 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7668 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7669 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7672 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7673 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7674 abbrev_die_table_allocated
= n_alloc
;
7677 ++abbrev_die_table_in_use
;
7678 abbrev_die_table
[abbrev_id
] = die
;
7681 die
->die_abbrev
= abbrev_id
;
7682 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7685 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7688 constant_size (unsigned HOST_WIDE_INT value
)
7695 log
= floor_log2 (value
);
7698 log
= 1 << (floor_log2 (log
) + 1);
7703 /* Return the size of a DIE as it is represented in the
7704 .debug_info section. */
7706 static unsigned long
7707 size_of_die (dw_die_ref die
)
7709 unsigned long size
= 0;
7712 enum dwarf_form form
;
7714 size
+= size_of_uleb128 (die
->die_abbrev
);
7715 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7717 switch (AT_class (a
))
7719 case dw_val_class_addr
:
7720 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7722 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7723 size
+= size_of_uleb128 (AT_index (a
));
7726 size
+= DWARF2_ADDR_SIZE
;
7728 case dw_val_class_offset
:
7729 size
+= DWARF_OFFSET_SIZE
;
7731 case dw_val_class_loc
:
7733 unsigned long lsize
= size_of_locs (AT_loc (a
));
7736 if (dwarf_version
>= 4)
7737 size
+= size_of_uleb128 (lsize
);
7739 size
+= constant_size (lsize
);
7743 case dw_val_class_loc_list
:
7744 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7746 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7747 size
+= size_of_uleb128 (AT_index (a
));
7750 size
+= DWARF_OFFSET_SIZE
;
7752 case dw_val_class_range_list
:
7753 size
+= DWARF_OFFSET_SIZE
;
7755 case dw_val_class_const
:
7756 size
+= size_of_sleb128 (AT_int (a
));
7758 case dw_val_class_unsigned_const
:
7760 int csize
= constant_size (AT_unsigned (a
));
7761 if (dwarf_version
== 3
7762 && a
->dw_attr
== DW_AT_data_member_location
7764 size
+= size_of_uleb128 (AT_unsigned (a
));
7769 case dw_val_class_const_double
:
7770 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7771 if (HOST_BITS_PER_WIDE_INT
>= 64)
7774 case dw_val_class_vec
:
7775 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7776 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7777 + a
->dw_attr_val
.v
.val_vec
.length
7778 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7780 case dw_val_class_flag
:
7781 if (dwarf_version
>= 4)
7782 /* Currently all add_AT_flag calls pass in 1 as last argument,
7783 so DW_FORM_flag_present can be used. If that ever changes,
7784 we'll need to use DW_FORM_flag and have some optimization
7785 in build_abbrev_table that will change those to
7786 DW_FORM_flag_present if it is set to 1 in all DIEs using
7787 the same abbrev entry. */
7788 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7792 case dw_val_class_die_ref
:
7793 if (AT_ref_external (a
))
7795 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7796 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7797 is sized by target address length, whereas in DWARF3
7798 it's always sized as an offset. */
7799 if (use_debug_types
)
7800 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7801 else if (dwarf_version
== 2)
7802 size
+= DWARF2_ADDR_SIZE
;
7804 size
+= DWARF_OFFSET_SIZE
;
7807 size
+= DWARF_OFFSET_SIZE
;
7809 case dw_val_class_fde_ref
:
7810 size
+= DWARF_OFFSET_SIZE
;
7812 case dw_val_class_lbl_id
:
7813 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7815 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7816 size
+= size_of_uleb128 (AT_index (a
));
7819 size
+= DWARF2_ADDR_SIZE
;
7821 case dw_val_class_lineptr
:
7822 case dw_val_class_macptr
:
7823 size
+= DWARF_OFFSET_SIZE
;
7825 case dw_val_class_str
:
7826 form
= AT_string_form (a
);
7827 if (form
== DW_FORM_strp
)
7828 size
+= DWARF_OFFSET_SIZE
;
7829 else if (form
== DW_FORM_GNU_str_index
)
7830 size
+= size_of_uleb128 (AT_index (a
));
7832 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7834 case dw_val_class_file
:
7835 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7837 case dw_val_class_data8
:
7840 case dw_val_class_vms_delta
:
7841 size
+= DWARF_OFFSET_SIZE
;
7843 case dw_val_class_high_pc
:
7844 size
+= DWARF2_ADDR_SIZE
;
7854 /* Size the debugging information associated with a given DIE. Visits the
7855 DIE's children recursively. Updates the global variable next_die_offset, on
7856 each time through. Uses the current value of next_die_offset to update the
7857 die_offset field in each DIE. */
7860 calc_die_sizes (dw_die_ref die
)
7864 gcc_assert (die
->die_offset
== 0
7865 || (unsigned long int) die
->die_offset
== next_die_offset
);
7866 die
->die_offset
= next_die_offset
;
7867 next_die_offset
+= size_of_die (die
);
7869 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7871 if (die
->die_child
!= NULL
)
7872 /* Count the null byte used to terminate sibling lists. */
7873 next_die_offset
+= 1;
7876 /* Size just the base type children at the start of the CU.
7877 This is needed because build_abbrev needs to size locs
7878 and sizing of type based stack ops needs to know die_offset
7879 values for the base types. */
7882 calc_base_type_die_sizes (void)
7884 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7886 dw_die_ref base_type
;
7887 #if ENABLE_ASSERT_CHECKING
7888 dw_die_ref prev
= comp_unit_die ()->die_child
;
7891 die_offset
+= size_of_die (comp_unit_die ());
7892 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7894 #if ENABLE_ASSERT_CHECKING
7895 gcc_assert (base_type
->die_offset
== 0
7896 && prev
->die_sib
== base_type
7897 && base_type
->die_child
== NULL
7898 && base_type
->die_abbrev
);
7901 base_type
->die_offset
= die_offset
;
7902 die_offset
+= size_of_die (base_type
);
7906 /* Set the marks for a die and its children. We do this so
7907 that we know whether or not a reference needs to use FORM_ref_addr; only
7908 DIEs in the same CU will be marked. We used to clear out the offset
7909 and use that as the flag, but ran into ordering problems. */
7912 mark_dies (dw_die_ref die
)
7916 gcc_assert (!die
->die_mark
);
7919 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7922 /* Clear the marks for a die and its children. */
7925 unmark_dies (dw_die_ref die
)
7929 if (! use_debug_types
)
7930 gcc_assert (die
->die_mark
);
7933 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7936 /* Clear the marks for a die, its children and referred dies. */
7939 unmark_all_dies (dw_die_ref die
)
7949 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7951 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7952 if (AT_class (a
) == dw_val_class_die_ref
)
7953 unmark_all_dies (AT_ref (a
));
7956 /* Calculate if the entry should appear in the final output file. It may be
7957 from a pruned a type. */
7960 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
7962 if (table
== pubname_table
)
7964 /* Enumerator names are part of the pubname table, but the
7965 parent DW_TAG_enumeration_type die may have been pruned.
7966 Don't output them if that is the case. */
7967 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
7968 (p
->die
->die_parent
== NULL
7969 || !p
->die
->die_parent
->die_perennial_p
))
7972 /* Everything else in the pubname table is included. */
7976 /* The pubtypes table shouldn't include types that have been
7978 return (p
->die
->die_offset
!= 0
7979 || !flag_eliminate_unused_debug_types
);
7982 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7983 generated for the compilation unit. */
7985 static unsigned long
7986 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
7992 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7993 FOR_EACH_VEC_ELT (*names
, i
, p
)
7994 if (include_pubname_in_output (names
, p
))
7995 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7997 size
+= DWARF_OFFSET_SIZE
;
8001 /* Return the size of the information in the .debug_aranges section. */
8003 static unsigned long
8004 size_of_aranges (void)
8008 size
= DWARF_ARANGES_HEADER_SIZE
;
8010 /* Count the address/length pair for this compilation unit. */
8011 if (text_section_used
)
8012 size
+= 2 * DWARF2_ADDR_SIZE
;
8013 if (cold_text_section_used
)
8014 size
+= 2 * DWARF2_ADDR_SIZE
;
8015 if (have_multiple_function_sections
)
8020 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8022 if (DECL_IGNORED_P (fde
->decl
))
8024 if (!fde
->in_std_section
)
8025 size
+= 2 * DWARF2_ADDR_SIZE
;
8026 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8027 size
+= 2 * DWARF2_ADDR_SIZE
;
8031 /* Count the two zero words used to terminated the address range table. */
8032 size
+= 2 * DWARF2_ADDR_SIZE
;
8036 /* Select the encoding of an attribute value. */
8038 static enum dwarf_form
8039 value_format (dw_attr_ref a
)
8041 switch (AT_class (a
))
8043 case dw_val_class_addr
:
8044 /* Only very few attributes allow DW_FORM_addr. */
8049 case DW_AT_entry_pc
:
8050 case DW_AT_trampoline
:
8051 return (AT_index (a
) == NOT_INDEXED
8052 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8056 switch (DWARF2_ADDR_SIZE
)
8059 return DW_FORM_data1
;
8061 return DW_FORM_data2
;
8063 return DW_FORM_data4
;
8065 return DW_FORM_data8
;
8069 case dw_val_class_range_list
:
8070 case dw_val_class_loc_list
:
8071 if (dwarf_version
>= 4)
8072 return DW_FORM_sec_offset
;
8074 case dw_val_class_vms_delta
:
8075 case dw_val_class_offset
:
8076 switch (DWARF_OFFSET_SIZE
)
8079 return DW_FORM_data4
;
8081 return DW_FORM_data8
;
8085 case dw_val_class_loc
:
8086 if (dwarf_version
>= 4)
8087 return DW_FORM_exprloc
;
8088 switch (constant_size (size_of_locs (AT_loc (a
))))
8091 return DW_FORM_block1
;
8093 return DW_FORM_block2
;
8095 return DW_FORM_block4
;
8099 case dw_val_class_const
:
8100 return DW_FORM_sdata
;
8101 case dw_val_class_unsigned_const
:
8102 switch (constant_size (AT_unsigned (a
)))
8105 return DW_FORM_data1
;
8107 return DW_FORM_data2
;
8109 /* In DWARF3 DW_AT_data_member_location with
8110 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8111 constant, so we need to use DW_FORM_udata if we need
8112 a large constant. */
8113 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8114 return DW_FORM_udata
;
8115 return DW_FORM_data4
;
8117 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8118 return DW_FORM_udata
;
8119 return DW_FORM_data8
;
8123 case dw_val_class_const_double
:
8124 switch (HOST_BITS_PER_WIDE_INT
)
8127 return DW_FORM_data2
;
8129 return DW_FORM_data4
;
8131 return DW_FORM_data8
;
8134 return DW_FORM_block1
;
8136 case dw_val_class_vec
:
8137 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8138 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8141 return DW_FORM_block1
;
8143 return DW_FORM_block2
;
8145 return DW_FORM_block4
;
8149 case dw_val_class_flag
:
8150 if (dwarf_version
>= 4)
8152 /* Currently all add_AT_flag calls pass in 1 as last argument,
8153 so DW_FORM_flag_present can be used. If that ever changes,
8154 we'll need to use DW_FORM_flag and have some optimization
8155 in build_abbrev_table that will change those to
8156 DW_FORM_flag_present if it is set to 1 in all DIEs using
8157 the same abbrev entry. */
8158 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8159 return DW_FORM_flag_present
;
8161 return DW_FORM_flag
;
8162 case dw_val_class_die_ref
:
8163 if (AT_ref_external (a
))
8164 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8167 case dw_val_class_fde_ref
:
8168 return DW_FORM_data
;
8169 case dw_val_class_lbl_id
:
8170 return (AT_index (a
) == NOT_INDEXED
8171 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8172 case dw_val_class_lineptr
:
8173 case dw_val_class_macptr
:
8174 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8175 case dw_val_class_str
:
8176 return AT_string_form (a
);
8177 case dw_val_class_file
:
8178 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8181 return DW_FORM_data1
;
8183 return DW_FORM_data2
;
8185 return DW_FORM_data4
;
8190 case dw_val_class_data8
:
8191 return DW_FORM_data8
;
8193 case dw_val_class_high_pc
:
8194 switch (DWARF2_ADDR_SIZE
)
8197 return DW_FORM_data1
;
8199 return DW_FORM_data2
;
8201 return DW_FORM_data4
;
8203 return DW_FORM_data8
;
8213 /* Output the encoding of an attribute value. */
8216 output_value_format (dw_attr_ref a
)
8218 enum dwarf_form form
= value_format (a
);
8220 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8223 /* Given a die and id, produce the appropriate abbreviations. */
8226 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8231 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8232 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8233 dwarf_tag_name (abbrev
->die_tag
));
8235 if (abbrev
->die_child
!= NULL
)
8236 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8238 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8240 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8242 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8243 dwarf_attr_name (a_attr
->dw_attr
));
8244 output_value_format (a_attr
);
8247 dw2_asm_output_data (1, 0, NULL
);
8248 dw2_asm_output_data (1, 0, NULL
);
8252 /* Output the .debug_abbrev section which defines the DIE abbreviation
8256 output_abbrev_section (void)
8258 unsigned long abbrev_id
;
8260 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8261 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8263 /* Terminate the table. */
8264 dw2_asm_output_data (1, 0, NULL
);
8267 /* Output a symbol we can use to refer to this DIE from another CU. */
8270 output_die_symbol (dw_die_ref die
)
8272 const char *sym
= die
->die_id
.die_symbol
;
8274 gcc_assert (!die
->comdat_type_p
);
8279 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8280 /* We make these global, not weak; if the target doesn't support
8281 .linkonce, it doesn't support combining the sections, so debugging
8283 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8285 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8288 /* Return a new location list, given the begin and end range, and the
8291 static inline dw_loc_list_ref
8292 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8293 const char *section
)
8295 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8297 retlist
->begin
= begin
;
8298 retlist
->begin_entry
= NULL
;
8300 retlist
->expr
= expr
;
8301 retlist
->section
= section
;
8306 /* Generate a new internal symbol for this location list node, if it
8307 hasn't got one yet. */
8310 gen_llsym (dw_loc_list_ref list
)
8312 gcc_assert (!list
->ll_symbol
);
8313 list
->ll_symbol
= gen_internal_sym ("LLST");
8316 /* Output the location list given to us. */
8319 output_loc_list (dw_loc_list_ref list_head
)
8321 dw_loc_list_ref curr
= list_head
;
8323 if (list_head
->emitted
)
8325 list_head
->emitted
= true;
8327 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8329 /* Walk the location list, and output each range + expression. */
8330 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8333 /* Don't output an entry that starts and ends at the same address. */
8334 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8336 size
= size_of_locs (curr
->expr
);
8337 /* If the expression is too large, drop it on the floor. We could
8338 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8339 in the expression, but >= 64KB expressions for a single value
8340 in a single range are unlikely very useful. */
8343 if (dwarf_split_debug_info
)
8345 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8346 "Location list start/length entry (%s)",
8347 list_head
->ll_symbol
);
8348 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8349 "Location list range start index (%s)",
8351 /* The length field is 4 bytes. If we ever need to support
8352 an 8-byte length, we can add a new DW_LLE code or fall back
8353 to DW_LLE_GNU_start_end_entry. */
8354 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8355 "Location list range length (%s)",
8356 list_head
->ll_symbol
);
8358 else if (!have_multiple_function_sections
)
8360 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8361 "Location list begin address (%s)",
8362 list_head
->ll_symbol
);
8363 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8364 "Location list end address (%s)",
8365 list_head
->ll_symbol
);
8369 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8370 "Location list begin address (%s)",
8371 list_head
->ll_symbol
);
8372 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8373 "Location list end address (%s)",
8374 list_head
->ll_symbol
);
8377 /* Output the block length for this list of location operations. */
8378 gcc_assert (size
<= 0xffff);
8379 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8381 output_loc_sequence (curr
->expr
, -1);
8384 if (dwarf_split_debug_info
)
8385 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8386 "Location list terminator (%s)",
8387 list_head
->ll_symbol
);
8390 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8391 "Location list terminator begin (%s)",
8392 list_head
->ll_symbol
);
8393 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8394 "Location list terminator end (%s)",
8395 list_head
->ll_symbol
);
8399 /* Output a range_list offset into the debug_range section. Emit a
8400 relocated reference if val_entry is NULL, otherwise, emit an
8401 indirect reference. */
8404 output_range_list_offset (dw_attr_ref a
)
8406 const char *name
= dwarf_attr_name (a
->dw_attr
);
8408 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8410 char *p
= strchr (ranges_section_label
, '\0');
8411 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8412 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8413 debug_ranges_section
, "%s", name
);
8417 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8418 "%s (offset from %s)", name
, ranges_section_label
);
8421 /* Output the offset into the debug_loc section. */
8424 output_loc_list_offset (dw_attr_ref a
)
8426 char *sym
= AT_loc_list (a
)->ll_symbol
;
8429 if (dwarf_split_debug_info
)
8430 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8431 "%s", dwarf_attr_name (a
->dw_attr
));
8433 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8434 "%s", dwarf_attr_name (a
->dw_attr
));
8437 /* Output an attribute's index or value appropriately. */
8440 output_attr_index_or_value (dw_attr_ref a
)
8442 const char *name
= dwarf_attr_name (a
->dw_attr
);
8444 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8446 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8449 switch (AT_class (a
))
8451 case dw_val_class_addr
:
8452 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8454 case dw_val_class_high_pc
:
8455 case dw_val_class_lbl_id
:
8456 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8458 case dw_val_class_loc_list
:
8459 output_loc_list_offset (a
);
8466 /* Output a type signature. */
8469 output_signature (const char *sig
, const char *name
)
8473 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8474 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8477 /* Output the DIE and its attributes. Called recursively to generate
8478 the definitions of each child DIE. */
8481 output_die (dw_die_ref die
)
8488 /* If someone in another CU might refer to us, set up a symbol for
8489 them to point to. */
8490 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8491 output_die_symbol (die
);
8493 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8494 (unsigned long)die
->die_offset
,
8495 dwarf_tag_name (die
->die_tag
));
8497 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8499 const char *name
= dwarf_attr_name (a
->dw_attr
);
8501 switch (AT_class (a
))
8503 case dw_val_class_addr
:
8504 output_attr_index_or_value (a
);
8507 case dw_val_class_offset
:
8508 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8512 case dw_val_class_range_list
:
8513 output_range_list_offset (a
);
8516 case dw_val_class_loc
:
8517 size
= size_of_locs (AT_loc (a
));
8519 /* Output the block length for this list of location operations. */
8520 if (dwarf_version
>= 4)
8521 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8523 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8525 output_loc_sequence (AT_loc (a
), -1);
8528 case dw_val_class_const
:
8529 /* ??? It would be slightly more efficient to use a scheme like is
8530 used for unsigned constants below, but gdb 4.x does not sign
8531 extend. Gdb 5.x does sign extend. */
8532 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8535 case dw_val_class_unsigned_const
:
8537 int csize
= constant_size (AT_unsigned (a
));
8538 if (dwarf_version
== 3
8539 && a
->dw_attr
== DW_AT_data_member_location
8541 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8543 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8547 case dw_val_class_const_double
:
8549 unsigned HOST_WIDE_INT first
, second
;
8551 if (HOST_BITS_PER_WIDE_INT
>= 64)
8552 dw2_asm_output_data (1,
8553 HOST_BITS_PER_DOUBLE_INT
8554 / HOST_BITS_PER_CHAR
,
8557 if (WORDS_BIG_ENDIAN
)
8559 first
= a
->dw_attr_val
.v
.val_double
.high
;
8560 second
= a
->dw_attr_val
.v
.val_double
.low
;
8564 first
= a
->dw_attr_val
.v
.val_double
.low
;
8565 second
= a
->dw_attr_val
.v
.val_double
.high
;
8568 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8570 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8575 case dw_val_class_vec
:
8577 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8578 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8582 dw2_asm_output_data (constant_size (len
* elt_size
),
8583 len
* elt_size
, "%s", name
);
8584 if (elt_size
> sizeof (HOST_WIDE_INT
))
8589 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8592 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8593 "fp or vector constant word %u", i
);
8597 case dw_val_class_flag
:
8598 if (dwarf_version
>= 4)
8600 /* Currently all add_AT_flag calls pass in 1 as last argument,
8601 so DW_FORM_flag_present can be used. If that ever changes,
8602 we'll need to use DW_FORM_flag and have some optimization
8603 in build_abbrev_table that will change those to
8604 DW_FORM_flag_present if it is set to 1 in all DIEs using
8605 the same abbrev entry. */
8606 gcc_assert (AT_flag (a
) == 1);
8608 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8609 ASM_COMMENT_START
, name
);
8612 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8615 case dw_val_class_loc_list
:
8616 output_attr_index_or_value (a
);
8619 case dw_val_class_die_ref
:
8620 if (AT_ref_external (a
))
8622 if (AT_ref (a
)->comdat_type_p
)
8624 comdat_type_node_ref type_node
=
8625 AT_ref (a
)->die_id
.die_type_node
;
8627 gcc_assert (type_node
);
8628 output_signature (type_node
->signature
, name
);
8632 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8636 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8637 length, whereas in DWARF3 it's always sized as an
8639 if (dwarf_version
== 2)
8640 size
= DWARF2_ADDR_SIZE
;
8642 size
= DWARF_OFFSET_SIZE
;
8643 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8649 gcc_assert (AT_ref (a
)->die_offset
);
8650 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8655 case dw_val_class_fde_ref
:
8659 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8660 a
->dw_attr_val
.v
.val_fde_index
* 2);
8661 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8666 case dw_val_class_vms_delta
:
8667 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8668 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8672 case dw_val_class_lbl_id
:
8673 output_attr_index_or_value (a
);
8676 case dw_val_class_lineptr
:
8677 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8678 debug_line_section
, "%s", name
);
8681 case dw_val_class_macptr
:
8682 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8683 debug_macinfo_section
, "%s", name
);
8686 case dw_val_class_str
:
8687 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8688 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8689 a
->dw_attr_val
.v
.val_str
->label
,
8691 "%s: \"%s\"", name
, AT_string (a
));
8692 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8693 dw2_asm_output_data_uleb128 (AT_index (a
),
8694 "%s: \"%s\"", name
, AT_string (a
));
8696 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8699 case dw_val_class_file
:
8701 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8703 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8704 a
->dw_attr_val
.v
.val_file
->filename
);
8708 case dw_val_class_data8
:
8712 for (i
= 0; i
< 8; i
++)
8713 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8714 i
== 0 ? "%s" : NULL
, name
);
8718 case dw_val_class_high_pc
:
8719 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8720 get_AT_low_pc (die
), "DW_AT_high_pc");
8728 FOR_EACH_CHILD (die
, c
, output_die (c
));
8730 /* Add null byte to terminate sibling list. */
8731 if (die
->die_child
!= NULL
)
8732 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8733 (unsigned long) die
->die_offset
);
8736 /* Output the compilation unit that appears at the beginning of the
8737 .debug_info section, and precedes the DIE descriptions. */
8740 output_compilation_unit_header (void)
8742 int ver
= dwarf_version
;
8744 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8745 dw2_asm_output_data (4, 0xffffffff,
8746 "Initial length escape value indicating 64-bit DWARF extension");
8747 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8748 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8749 "Length of Compilation Unit Info");
8750 dw2_asm_output_data (2, ver
, "DWARF version number");
8751 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8752 debug_abbrev_section
,
8753 "Offset Into Abbrev. Section");
8754 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8757 /* Output the compilation unit DIE and its children. */
8760 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8762 const char *secname
, *oldsym
;
8764 external_ref_hash_type extern_map
;
8766 /* Unless we are outputting main CU, we may throw away empty ones. */
8767 if (!output_if_empty
&& die
->die_child
== NULL
)
8770 /* Even if there are no children of this DIE, we must output the information
8771 about the compilation unit. Otherwise, on an empty translation unit, we
8772 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8773 will then complain when examining the file. First mark all the DIEs in
8774 this CU so we know which get local refs. */
8777 extern_map
= optimize_external_refs (die
);
8779 build_abbrev_table (die
, extern_map
);
8781 extern_map
.dispose ();
8783 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8784 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8785 calc_die_sizes (die
);
8787 oldsym
= die
->die_id
.die_symbol
;
8790 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8792 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8794 die
->die_id
.die_symbol
= NULL
;
8795 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8799 switch_to_section (debug_info_section
);
8800 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8801 info_section_emitted
= true;
8804 /* Output debugging information. */
8805 output_compilation_unit_header ();
8808 /* Leave the marks on the main CU, so we can check them in
8813 die
->die_id
.die_symbol
= oldsym
;
8817 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8818 and .debug_pubtypes. This is configured per-target, but can be
8819 overridden by the -gpubnames or -gno-pubnames options. */
8822 want_pubnames (void)
8824 if (debug_generate_pub_sections
!= -1)
8825 return debug_generate_pub_sections
;
8826 return targetm
.want_debug_pub_sections
;
8829 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8832 add_AT_pubnames (dw_die_ref die
)
8834 if (want_pubnames ())
8835 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8838 /* Add a string attribute value to a skeleton DIE. */
8841 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8845 struct indirect_string_node
*node
;
8847 if (! skeleton_debug_str_hash
)
8848 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
8849 debug_str_eq
, NULL
);
8851 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
8852 find_string_form (node
);
8853 if (node
->form
== DW_FORM_GNU_str_index
)
8854 node
->form
= DW_FORM_strp
;
8856 attr
.dw_attr
= attr_kind
;
8857 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
8858 attr
.dw_attr_val
.val_entry
= NULL
;
8859 attr
.dw_attr_val
.v
.val_str
= node
;
8860 add_dwarf_attr (die
, &attr
);
8863 /* Helper function to generate top-level dies for skeleton debug_info and
8867 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8869 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8870 const char *comp_dir
= comp_dir_string ();
8872 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8873 if (comp_dir
!= NULL
)
8874 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
8875 add_AT_pubnames (die
);
8876 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8879 /* Return the single type-unit die for skeleton type units. */
8882 get_skeleton_type_unit (void)
8884 /* For dwarf_split_debug_sections with use_type info, all type units in the
8885 skeleton sections have identical dies (but different headers). This
8886 single die will be output many times. */
8888 static dw_die_ref skeleton_type_unit
= NULL
;
8890 if (skeleton_type_unit
== NULL
)
8892 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8893 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8894 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8896 return skeleton_type_unit
;
8899 /* Output skeleton debug sections that point to the dwo file. */
8902 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8904 /* These attributes will be found in the full debug_info section. */
8905 remove_AT (comp_unit
, DW_AT_producer
);
8906 remove_AT (comp_unit
, DW_AT_language
);
8908 switch_to_section (debug_skeleton_info_section
);
8909 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8911 /* Produce the skeleton compilation-unit header. This one differs enough from
8912 a normal CU header that it's better not to call output_compilation_unit
8914 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8915 dw2_asm_output_data (4, 0xffffffff,
8916 "Initial length escape value indicating 64-bit DWARF extension");
8918 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8919 DWARF_COMPILE_UNIT_HEADER_SIZE
8920 - DWARF_INITIAL_LENGTH_SIZE
8921 + size_of_die (comp_unit
),
8922 "Length of Compilation Unit Info");
8923 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8924 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8925 debug_abbrev_section
,
8926 "Offset Into Abbrev. Section");
8927 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8929 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8930 output_die (comp_unit
);
8932 /* Build the skeleton debug_abbrev section. */
8933 switch_to_section (debug_skeleton_abbrev_section
);
8934 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8936 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8937 if (use_debug_types
)
8938 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8940 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8943 /* Output a comdat type unit DIE and its children. */
8946 output_comdat_type_unit (comdat_type_node
*node
)
8948 const char *secname
;
8951 #if defined (OBJECT_FORMAT_ELF)
8954 external_ref_hash_type extern_map
;
8956 /* First mark all the DIEs in this CU so we know which get local refs. */
8957 mark_dies (node
->root_die
);
8959 extern_map
= optimize_external_refs (node
->root_die
);
8961 build_abbrev_table (node
->root_die
, extern_map
);
8963 extern_map
.dispose ();
8965 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8966 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8967 calc_die_sizes (node
->root_die
);
8969 #if defined (OBJECT_FORMAT_ELF)
8970 if (!dwarf_split_debug_info
)
8971 secname
= ".debug_types";
8973 secname
= ".debug_types.dwo";
8975 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8976 sprintf (tmp
, "wt.");
8977 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8978 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8979 comdat_key
= get_identifier (tmp
);
8980 targetm
.asm_out
.named_section (secname
,
8981 SECTION_DEBUG
| SECTION_LINKONCE
,
8984 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8985 sprintf (tmp
, ".gnu.linkonce.wt.");
8986 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8987 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8989 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8992 /* Output debugging information. */
8993 output_compilation_unit_header ();
8994 output_signature (node
->signature
, "Type Signature");
8995 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8996 "Offset to Type DIE");
8997 output_die (node
->root_die
);
8999 unmark_dies (node
->root_die
);
9001 #if defined (OBJECT_FORMAT_ELF)
9002 if (dwarf_split_debug_info
)
9004 /* Produce the skeleton type-unit header. */
9005 const char *secname
= ".debug_types";
9007 targetm
.asm_out
.named_section (secname
,
9008 SECTION_DEBUG
| SECTION_LINKONCE
,
9010 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9011 dw2_asm_output_data (4, 0xffffffff,
9012 "Initial length escape value indicating 64-bit DWARF extension");
9014 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9015 DWARF_COMPILE_UNIT_HEADER_SIZE
9016 - DWARF_INITIAL_LENGTH_SIZE
9017 + size_of_die (get_skeleton_type_unit ())
9018 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
9019 "Length of Type Unit Info");
9020 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9021 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9022 debug_skeleton_abbrev_section_label
,
9023 debug_abbrev_section
,
9024 "Offset Into Abbrev. Section");
9025 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9026 output_signature (node
->signature
, "Type Signature");
9027 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
9029 output_die (get_skeleton_type_unit ());
9034 /* Return the DWARF2/3 pubname associated with a decl. */
9037 dwarf2_name (tree decl
, int scope
)
9039 if (DECL_NAMELESS (decl
))
9041 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9044 /* Add a new entry to .debug_pubnames if appropriate. */
9047 add_pubname_string (const char *str
, dw_die_ref die
)
9052 e
.name
= xstrdup (str
);
9053 vec_safe_push (pubname_table
, e
);
9057 add_pubname (tree decl
, dw_die_ref die
)
9059 if (!want_pubnames ())
9062 /* Don't add items to the table when we expect that the consumer will have
9063 just read the enclosing die. For example, if the consumer is looking at a
9064 class_member, it will either be inside the class already, or will have just
9065 looked up the class to find the member. Either way, searching the class is
9066 faster than searching the index. */
9067 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9068 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9070 const char *name
= dwarf2_name (decl
, 1);
9073 add_pubname_string (name
, die
);
9077 /* Add an enumerator to the pubnames section. */
9080 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9084 gcc_assert (scope_name
);
9085 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9087 vec_safe_push (pubname_table
, e
);
9090 /* Add a new entry to .debug_pubtypes if appropriate. */
9093 add_pubtype (tree decl
, dw_die_ref die
)
9097 if (!want_pubnames ())
9100 if ((TREE_PUBLIC (decl
)
9101 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9102 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9105 const char *scope_name
= "";
9106 const char *sep
= is_cxx () ? "::" : ".";
9109 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9110 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9112 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9113 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9114 scope_name
= concat (scope_name
, sep
, NULL
);
9120 name
= type_tag (decl
);
9122 name
= lang_hooks
.dwarf_name (decl
, 1);
9124 /* If we don't have a name for the type, there's no point in adding
9126 if (name
!= NULL
&& name
[0] != '\0')
9129 e
.name
= concat (scope_name
, name
, NULL
);
9130 vec_safe_push (pubtype_table
, e
);
9133 /* Although it might be more consistent to add the pubinfo for the
9134 enumerators as their dies are created, they should only be added if the
9135 enum type meets the criteria above. So rather than re-check the parent
9136 enum type whenever an enumerator die is created, just output them all
9137 here. This isn't protected by the name conditional because anonymous
9138 enums don't have names. */
9139 if (die
->die_tag
== DW_TAG_enumeration_type
)
9143 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9148 /* Output the public names table used to speed up access to externally
9149 visible names; or the public types table used to find type definitions. */
9152 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9155 unsigned long pubnames_length
= size_of_pubnames (names
);
9158 if (!want_pubnames () || !info_section_emitted
)
9160 if (names
== pubname_table
)
9161 switch_to_section (debug_pubnames_section
);
9163 switch_to_section (debug_pubtypes_section
);
9164 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9165 dw2_asm_output_data (4, 0xffffffff,
9166 "Initial length escape value indicating 64-bit DWARF extension");
9167 if (names
== pubname_table
)
9168 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9169 "Length of Public Names Info");
9171 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9172 "Length of Public Type Names Info");
9173 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9174 dw2_asm_output_data (2, 2, "DWARF Version");
9175 if (dwarf_split_debug_info
)
9176 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9177 debug_skeleton_info_section
,
9178 "Offset of Compilation Unit Info");
9180 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9182 "Offset of Compilation Unit Info");
9183 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9184 "Compilation Unit Length");
9186 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9188 if (include_pubname_in_output (names
, pub
))
9190 dw_offset die_offset
= pub
->die
->die_offset
;
9192 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9193 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9194 gcc_assert (pub
->die
->die_mark
);
9196 /* If we're putting types in their own .debug_types sections,
9197 the .debug_pubtypes table will still point to the compile
9198 unit (not the type unit), so we want to use the offset of
9199 the skeleton DIE (if there is one). */
9200 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9202 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9204 if (type_node
!= NULL
)
9205 die_offset
= (type_node
->skeleton_die
!= NULL
9206 ? type_node
->skeleton_die
->die_offset
9210 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9212 dw2_asm_output_nstring (pub
->name
, -1, "external name");
9216 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9219 /* Output the information that goes into the .debug_aranges table.
9220 Namely, define the beginning and ending address range of the
9221 text section generated for this compilation unit. */
9224 output_aranges (unsigned long aranges_length
)
9228 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9229 dw2_asm_output_data (4, 0xffffffff,
9230 "Initial length escape value indicating 64-bit DWARF extension");
9231 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9232 "Length of Address Ranges Info");
9233 /* Version number for aranges is still 2, even in DWARF3. */
9234 dw2_asm_output_data (2, 2, "DWARF Version");
9235 if (dwarf_split_debug_info
)
9236 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9237 debug_skeleton_info_section
,
9238 "Offset of Compilation Unit Info");
9240 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9242 "Offset of Compilation Unit Info");
9243 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9244 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9246 /* We need to align to twice the pointer size here. */
9247 if (DWARF_ARANGES_PAD_SIZE
)
9249 /* Pad using a 2 byte words so that padding is correct for any
9251 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9252 2 * DWARF2_ADDR_SIZE
);
9253 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9254 dw2_asm_output_data (2, 0, NULL
);
9257 /* It is necessary not to output these entries if the sections were
9258 not used; if the sections were not used, the length will be 0 and
9259 the address may end up as 0 if the section is discarded by ld
9260 --gc-sections, leaving an invalid (0, 0) entry that can be
9261 confused with the terminator. */
9262 if (text_section_used
)
9264 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9265 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9266 text_section_label
, "Length");
9268 if (cold_text_section_used
)
9270 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9272 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9273 cold_text_section_label
, "Length");
9276 if (have_multiple_function_sections
)
9281 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9283 if (DECL_IGNORED_P (fde
->decl
))
9285 if (!fde
->in_std_section
)
9287 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9289 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9290 fde
->dw_fde_begin
, "Length");
9292 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9294 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9296 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9297 fde
->dw_fde_second_begin
, "Length");
9302 /* Output the terminator words. */
9303 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9304 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9307 /* Add a new entry to .debug_ranges. Return the offset at which it
9311 add_ranges_num (int num
)
9313 unsigned int in_use
= ranges_table_in_use
;
9315 if (in_use
== ranges_table_allocated
)
9317 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9318 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9319 ranges_table_allocated
);
9320 memset (ranges_table
+ ranges_table_in_use
, 0,
9321 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9324 ranges_table
[in_use
].num
= num
;
9325 ranges_table_in_use
= in_use
+ 1;
9327 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9330 /* Add a new entry to .debug_ranges corresponding to a block, or a
9331 range terminator if BLOCK is NULL. */
9334 add_ranges (const_tree block
)
9336 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9339 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9340 When using dwarf_split_debug_info, address attributes in dies destined
9341 for the final executable should be direct references--setting the
9342 parameter force_direct ensures this behavior. */
9345 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9346 bool *added
, bool force_direct
)
9348 unsigned int in_use
= ranges_by_label_in_use
;
9349 unsigned int offset
;
9351 if (in_use
== ranges_by_label_allocated
)
9353 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9354 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9356 ranges_by_label_allocated
);
9357 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9358 RANGES_TABLE_INCREMENT
9359 * sizeof (struct dw_ranges_by_label_struct
));
9362 ranges_by_label
[in_use
].begin
= begin
;
9363 ranges_by_label
[in_use
].end
= end
;
9364 ranges_by_label_in_use
= in_use
+ 1;
9366 offset
= add_ranges_num (-(int)in_use
- 1);
9369 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9375 output_ranges (void)
9378 static const char *const start_fmt
= "Offset %#x";
9379 const char *fmt
= start_fmt
;
9381 for (i
= 0; i
< ranges_table_in_use
; i
++)
9383 int block_num
= ranges_table
[i
].num
;
9387 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9388 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9390 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9391 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9393 /* If all code is in the text section, then the compilation
9394 unit base address defaults to DW_AT_low_pc, which is the
9395 base of the text section. */
9396 if (!have_multiple_function_sections
)
9398 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9400 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9401 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9402 text_section_label
, NULL
);
9405 /* Otherwise, the compilation unit base address is zero,
9406 which allows us to use absolute addresses, and not worry
9407 about whether the target supports cross-section
9411 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9412 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9413 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9419 /* Negative block_num stands for an index into ranges_by_label. */
9420 else if (block_num
< 0)
9422 int lab_idx
= - block_num
- 1;
9424 if (!have_multiple_function_sections
)
9428 /* If we ever use add_ranges_by_labels () for a single
9429 function section, all we have to do is to take out
9431 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9432 ranges_by_label
[lab_idx
].begin
,
9434 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9435 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9436 ranges_by_label
[lab_idx
].end
,
9437 text_section_label
, NULL
);
9442 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9443 ranges_by_label
[lab_idx
].begin
,
9444 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9445 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9446 ranges_by_label
[lab_idx
].end
,
9452 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9453 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9459 /* Data structure containing information about input files. */
9462 const char *path
; /* Complete file name. */
9463 const char *fname
; /* File name part. */
9464 int length
; /* Length of entire string. */
9465 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9466 int dir_idx
; /* Index in directory table. */
9469 /* Data structure containing information about directories with source
9473 const char *path
; /* Path including directory name. */
9474 int length
; /* Path length. */
9475 int prefix
; /* Index of directory entry which is a prefix. */
9476 int count
; /* Number of files in this directory. */
9477 int dir_idx
; /* Index of directory used as base. */
9480 /* Callback function for file_info comparison. We sort by looking at
9481 the directories in the path. */
9484 file_info_cmp (const void *p1
, const void *p2
)
9486 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9487 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9488 const unsigned char *cp1
;
9489 const unsigned char *cp2
;
9491 /* Take care of file names without directories. We need to make sure that
9492 we return consistent values to qsort since some will get confused if
9493 we return the same value when identical operands are passed in opposite
9494 orders. So if neither has a directory, return 0 and otherwise return
9495 1 or -1 depending on which one has the directory. */
9496 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9497 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9499 cp1
= (const unsigned char *) s1
->path
;
9500 cp2
= (const unsigned char *) s2
->path
;
9506 /* Reached the end of the first path? If so, handle like above. */
9507 if ((cp1
== (const unsigned char *) s1
->fname
)
9508 || (cp2
== (const unsigned char *) s2
->fname
))
9509 return ((cp2
== (const unsigned char *) s2
->fname
)
9510 - (cp1
== (const unsigned char *) s1
->fname
));
9512 /* Character of current path component the same? */
9513 else if (*cp1
!= *cp2
)
9518 struct file_name_acquire_data
9520 struct file_info
*files
;
9525 /* Traversal function for the hash table. */
9528 file_name_acquire (void ** slot
, void *data
)
9530 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9531 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9532 struct file_info
*fi
;
9535 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9537 if (! d
->emitted_number
)
9540 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9542 fi
= fnad
->files
+ fnad
->used_files
++;
9544 /* Skip all leading "./". */
9546 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9549 /* Create a new array entry. */
9551 fi
->length
= strlen (f
);
9554 /* Search for the file name part. */
9555 f
= strrchr (f
, DIR_SEPARATOR
);
9556 #if defined (DIR_SEPARATOR_2)
9558 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9562 if (f
== NULL
|| f
< g
)
9568 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9572 /* Output the directory table and the file name table. We try to minimize
9573 the total amount of memory needed. A heuristic is used to avoid large
9574 slowdowns with many input files. */
9577 output_file_names (void)
9579 struct file_name_acquire_data fnad
;
9581 struct file_info
*files
;
9582 struct dir_info
*dirs
;
9590 if (!last_emitted_file
)
9592 dw2_asm_output_data (1, 0, "End directory table");
9593 dw2_asm_output_data (1, 0, "End file name table");
9597 numfiles
= last_emitted_file
->emitted_number
;
9599 /* Allocate the various arrays we need. */
9600 files
= XALLOCAVEC (struct file_info
, numfiles
);
9601 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9604 fnad
.used_files
= 0;
9605 fnad
.max_files
= numfiles
;
9606 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9607 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9609 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9611 /* Find all the different directories used. */
9612 dirs
[0].path
= files
[0].path
;
9613 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9614 dirs
[0].prefix
= -1;
9616 dirs
[0].dir_idx
= 0;
9617 files
[0].dir_idx
= 0;
9620 for (i
= 1; i
< numfiles
; i
++)
9621 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9622 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9623 dirs
[ndirs
- 1].length
) == 0)
9625 /* Same directory as last entry. */
9626 files
[i
].dir_idx
= ndirs
- 1;
9627 ++dirs
[ndirs
- 1].count
;
9633 /* This is a new directory. */
9634 dirs
[ndirs
].path
= files
[i
].path
;
9635 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9636 dirs
[ndirs
].count
= 1;
9637 dirs
[ndirs
].dir_idx
= ndirs
;
9638 files
[i
].dir_idx
= ndirs
;
9640 /* Search for a prefix. */
9641 dirs
[ndirs
].prefix
= -1;
9642 for (j
= 0; j
< ndirs
; j
++)
9643 if (dirs
[j
].length
< dirs
[ndirs
].length
9644 && dirs
[j
].length
> 1
9645 && (dirs
[ndirs
].prefix
== -1
9646 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9647 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9648 dirs
[ndirs
].prefix
= j
;
9653 /* Now to the actual work. We have to find a subset of the directories which
9654 allow expressing the file name using references to the directory table
9655 with the least amount of characters. We do not do an exhaustive search
9656 where we would have to check out every combination of every single
9657 possible prefix. Instead we use a heuristic which provides nearly optimal
9658 results in most cases and never is much off. */
9659 saved
= XALLOCAVEC (int, ndirs
);
9660 savehere
= XALLOCAVEC (int, ndirs
);
9662 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9663 for (i
= 0; i
< ndirs
; i
++)
9668 /* We can always save some space for the current directory. But this
9669 does not mean it will be enough to justify adding the directory. */
9670 savehere
[i
] = dirs
[i
].length
;
9671 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9673 for (j
= i
+ 1; j
< ndirs
; j
++)
9676 if (saved
[j
] < dirs
[i
].length
)
9678 /* Determine whether the dirs[i] path is a prefix of the
9683 while (k
!= -1 && k
!= (int) i
)
9688 /* Yes it is. We can possibly save some memory by
9689 writing the filenames in dirs[j] relative to
9691 savehere
[j
] = dirs
[i
].length
;
9692 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9697 /* Check whether we can save enough to justify adding the dirs[i]
9699 if (total
> dirs
[i
].length
+ 1)
9701 /* It's worthwhile adding. */
9702 for (j
= i
; j
< ndirs
; j
++)
9703 if (savehere
[j
] > 0)
9705 /* Remember how much we saved for this directory so far. */
9706 saved
[j
] = savehere
[j
];
9708 /* Remember the prefix directory. */
9709 dirs
[j
].dir_idx
= i
;
9714 /* Emit the directory name table. */
9715 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9716 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9717 dw2_asm_output_nstring (dirs
[i
].path
,
9719 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9720 "Directory Entry: %#x", i
+ idx_offset
);
9722 dw2_asm_output_data (1, 0, "End directory table");
9724 /* We have to emit them in the order of emitted_number since that's
9725 used in the debug info generation. To do this efficiently we
9726 generate a back-mapping of the indices first. */
9727 backmap
= XALLOCAVEC (int, numfiles
);
9728 for (i
= 0; i
< numfiles
; i
++)
9729 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9731 /* Now write all the file names. */
9732 for (i
= 0; i
< numfiles
; i
++)
9734 int file_idx
= backmap
[i
];
9735 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9737 #ifdef VMS_DEBUGGING_INFO
9738 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9740 /* Setting these fields can lead to debugger miscomparisons,
9741 but VMS Debug requires them to be set correctly. */
9746 int maxfilelen
= strlen (files
[file_idx
].path
)
9747 + dirs
[dir_idx
].length
9748 + MAX_VMS_VERSION_LEN
+ 1;
9749 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9751 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9752 snprintf (filebuf
, maxfilelen
, "%s;%d",
9753 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9755 dw2_asm_output_nstring
9756 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9758 /* Include directory index. */
9759 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9761 /* Modification time. */
9762 dw2_asm_output_data_uleb128
9763 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9767 /* File length in bytes. */
9768 dw2_asm_output_data_uleb128
9769 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9773 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9774 "File Entry: %#x", (unsigned) i
+ 1);
9776 /* Include directory index. */
9777 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9779 /* Modification time. */
9780 dw2_asm_output_data_uleb128 (0, NULL
);
9782 /* File length in bytes. */
9783 dw2_asm_output_data_uleb128 (0, NULL
);
9784 #endif /* VMS_DEBUGGING_INFO */
9787 dw2_asm_output_data (1, 0, "End file name table");
9791 /* Output one line number table into the .debug_line section. */
9794 output_one_line_info_table (dw_line_info_table
*table
)
9796 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9797 unsigned int current_line
= 1;
9798 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9799 dw_line_info_entry
*ent
;
9802 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9804 switch (ent
->opcode
)
9806 case LI_set_address
:
9807 /* ??? Unfortunately, we have little choice here currently, and
9808 must always use the most general form. GCC does not know the
9809 address delta itself, so we can't use DW_LNS_advance_pc. Many
9810 ports do have length attributes which will give an upper bound
9811 on the address range. We could perhaps use length attributes
9812 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9813 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9815 /* This can handle any delta. This takes
9816 4+DWARF2_ADDR_SIZE bytes. */
9817 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9818 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9819 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9820 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9824 if (ent
->val
== current_line
)
9826 /* We still need to start a new row, so output a copy insn. */
9827 dw2_asm_output_data (1, DW_LNS_copy
,
9828 "copy line %u", current_line
);
9832 int line_offset
= ent
->val
- current_line
;
9833 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9835 current_line
= ent
->val
;
9836 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9838 /* This can handle deltas from -10 to 234, using the current
9839 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9840 This takes 1 byte. */
9841 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9842 "line %u", current_line
);
9846 /* This can handle any delta. This takes at least 4 bytes,
9847 depending on the value being encoded. */
9848 dw2_asm_output_data (1, DW_LNS_advance_line
,
9849 "advance to line %u", current_line
);
9850 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9851 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9857 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9858 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9862 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9863 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9866 case LI_negate_stmt
:
9867 current_is_stmt
= !current_is_stmt
;
9868 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9869 "is_stmt %d", current_is_stmt
);
9872 case LI_set_prologue_end
:
9873 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9874 "set prologue end");
9877 case LI_set_epilogue_begin
:
9878 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9879 "set epilogue begin");
9882 case LI_set_discriminator
:
9883 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9884 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9885 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9886 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9891 /* Emit debug info for the address of the end of the table. */
9892 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9893 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9894 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9895 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9897 dw2_asm_output_data (1, 0, "end sequence");
9898 dw2_asm_output_data_uleb128 (1, NULL
);
9899 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9902 /* Output the source line number correspondence information. This
9903 information goes into the .debug_line section. */
9906 output_line_info (bool prologue_only
)
9908 char l1
[20], l2
[20], p1
[20], p2
[20];
9909 int ver
= dwarf_version
;
9910 bool saw_one
= false;
9913 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9914 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9915 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9916 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9918 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9919 dw2_asm_output_data (4, 0xffffffff,
9920 "Initial length escape value indicating 64-bit DWARF extension");
9921 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9922 "Length of Source Line Info");
9923 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9925 dw2_asm_output_data (2, ver
, "DWARF Version");
9926 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9927 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9929 /* Define the architecture-dependent minimum instruction length (in bytes).
9930 In this implementation of DWARF, this field is used for information
9931 purposes only. Since GCC generates assembly language, we have no
9932 a priori knowledge of how many instruction bytes are generated for each
9933 source line, and therefore can use only the DW_LNE_set_address and
9934 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9935 this as '1', which is "correct enough" for all architectures,
9936 and don't let the target override. */
9937 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9940 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9941 "Maximum Operations Per Instruction");
9942 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9943 "Default is_stmt_start flag");
9944 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9945 "Line Base Value (Special Opcodes)");
9946 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9947 "Line Range Value (Special Opcodes)");
9948 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9949 "Special Opcode Base");
9951 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9956 case DW_LNS_advance_pc
:
9957 case DW_LNS_advance_line
:
9958 case DW_LNS_set_file
:
9959 case DW_LNS_set_column
:
9960 case DW_LNS_fixed_advance_pc
:
9961 case DW_LNS_set_isa
:
9969 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9973 /* Write out the information about the files we use. */
9974 output_file_names ();
9975 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9978 /* Output the marker for the end of the line number info. */
9979 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9983 if (separate_line_info
)
9985 dw_line_info_table
*table
;
9988 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
9991 output_one_line_info_table (table
);
9995 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9997 output_one_line_info_table (cold_text_section_line_info
);
10001 /* ??? Some Darwin linkers crash on a .debug_line section with no
10002 sequences. Further, merely a DW_LNE_end_sequence entry is not
10003 sufficient -- the address column must also be initialized.
10004 Make sure to output at least one set_address/end_sequence pair,
10005 choosing .text since that section is always present. */
10006 if (text_section_line_info
->in_use
|| !saw_one
)
10007 output_one_line_info_table (text_section_line_info
);
10009 /* Output the marker for the end of the line number info. */
10010 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10013 /* Given a pointer to a tree node for some base type, return a pointer to
10014 a DIE that describes the given type.
10016 This routine must only be called for GCC type nodes that correspond to
10017 Dwarf base (fundamental) types. */
10020 base_type_die (tree type
)
10022 dw_die_ref base_type_result
;
10023 enum dwarf_type encoding
;
10025 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10028 /* If this is a subtype that should not be emitted as a subrange type,
10029 use the base type. See subrange_type_for_debug_p. */
10030 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10031 type
= TREE_TYPE (type
);
10033 switch (TREE_CODE (type
))
10036 if ((dwarf_version
>= 4 || !dwarf_strict
)
10037 && TYPE_NAME (type
)
10038 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10039 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10040 && DECL_NAME (TYPE_NAME (type
)))
10042 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10043 if (strcmp (name
, "char16_t") == 0
10044 || strcmp (name
, "char32_t") == 0)
10046 encoding
= DW_ATE_UTF
;
10050 if (TYPE_STRING_FLAG (type
))
10052 if (TYPE_UNSIGNED (type
))
10053 encoding
= DW_ATE_unsigned_char
;
10055 encoding
= DW_ATE_signed_char
;
10057 else if (TYPE_UNSIGNED (type
))
10058 encoding
= DW_ATE_unsigned
;
10060 encoding
= DW_ATE_signed
;
10064 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10066 if (dwarf_version
>= 3 || !dwarf_strict
)
10067 encoding
= DW_ATE_decimal_float
;
10069 encoding
= DW_ATE_lo_user
;
10072 encoding
= DW_ATE_float
;
10075 case FIXED_POINT_TYPE
:
10076 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10077 encoding
= DW_ATE_lo_user
;
10078 else if (TYPE_UNSIGNED (type
))
10079 encoding
= DW_ATE_unsigned_fixed
;
10081 encoding
= DW_ATE_signed_fixed
;
10084 /* Dwarf2 doesn't know anything about complex ints, so use
10085 a user defined type for it. */
10087 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10088 encoding
= DW_ATE_complex_float
;
10090 encoding
= DW_ATE_lo_user
;
10094 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10095 encoding
= DW_ATE_boolean
;
10099 /* No other TREE_CODEs are Dwarf fundamental types. */
10100 gcc_unreachable ();
10103 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10105 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10106 int_size_in_bytes (type
));
10107 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10108 add_pubtype (type
, base_type_result
);
10110 return base_type_result
;
10113 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10114 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10117 is_base_type (tree type
)
10119 switch (TREE_CODE (type
))
10125 case FIXED_POINT_TYPE
:
10133 case QUAL_UNION_TYPE
:
10134 case ENUMERAL_TYPE
:
10135 case FUNCTION_TYPE
:
10138 case REFERENCE_TYPE
:
10146 gcc_unreachable ();
10152 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10153 node, return the size in bits for the type if it is a constant, or else
10154 return the alignment for the type if the type's size is not constant, or
10155 else return BITS_PER_WORD if the type actually turns out to be an
10156 ERROR_MARK node. */
10158 static inline unsigned HOST_WIDE_INT
10159 simple_type_size_in_bits (const_tree type
)
10161 if (TREE_CODE (type
) == ERROR_MARK
)
10162 return BITS_PER_WORD
;
10163 else if (TYPE_SIZE (type
) == NULL_TREE
)
10165 else if (host_integerp (TYPE_SIZE (type
), 1))
10166 return tree_low_cst (TYPE_SIZE (type
), 1);
10168 return TYPE_ALIGN (type
);
10171 /* Similarly, but return a double_int instead of UHWI. */
10173 static inline double_int
10174 double_int_type_size_in_bits (const_tree type
)
10176 if (TREE_CODE (type
) == ERROR_MARK
)
10177 return double_int::from_uhwi (BITS_PER_WORD
);
10178 else if (TYPE_SIZE (type
) == NULL_TREE
)
10179 return double_int_zero
;
10180 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10181 return tree_to_double_int (TYPE_SIZE (type
));
10183 return double_int::from_uhwi (TYPE_ALIGN (type
));
10186 /* Given a pointer to a tree node for a subrange type, return a pointer
10187 to a DIE that describes the given type. */
10190 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10192 dw_die_ref subrange_die
;
10193 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10195 if (context_die
== NULL
)
10196 context_die
= comp_unit_die ();
10198 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10200 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10202 /* The size of the subrange type and its base type do not match,
10203 so we need to generate a size attribute for the subrange type. */
10204 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10208 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10210 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10212 return subrange_die
;
10215 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10216 entry that chains various modifiers in front of the given type. */
10219 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10220 dw_die_ref context_die
)
10222 enum tree_code code
= TREE_CODE (type
);
10223 dw_die_ref mod_type_die
;
10224 dw_die_ref sub_die
= NULL
;
10225 tree item_type
= NULL
;
10226 tree qualified_type
;
10227 tree name
, low
, high
;
10228 dw_die_ref mod_scope
;
10230 if (code
== ERROR_MARK
)
10233 /* See if we already have the appropriately qualified variant of
10236 = get_qualified_type (type
,
10237 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10238 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10240 if (qualified_type
== sizetype
10241 && TYPE_NAME (qualified_type
)
10242 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10244 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10246 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10247 && TYPE_PRECISION (t
)
10248 == TYPE_PRECISION (qualified_type
)
10249 && TYPE_UNSIGNED (t
)
10250 == TYPE_UNSIGNED (qualified_type
));
10251 qualified_type
= t
;
10254 /* If we do, then we can just use its DIE, if it exists. */
10255 if (qualified_type
)
10257 mod_type_die
= lookup_type_die (qualified_type
);
10259 return mod_type_die
;
10262 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10264 /* Handle C typedef types. */
10265 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10266 && !DECL_ARTIFICIAL (name
))
10268 tree dtype
= TREE_TYPE (name
);
10270 if (qualified_type
== dtype
)
10272 /* For a named type, use the typedef. */
10273 gen_type_die (qualified_type
, context_die
);
10274 return lookup_type_die (qualified_type
);
10276 else if (is_const_type
< TYPE_READONLY (dtype
)
10277 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10278 || (is_const_type
<= TYPE_READONLY (dtype
)
10279 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10280 && DECL_ORIGINAL_TYPE (name
) != type
))
10281 /* cv-unqualified version of named type. Just use the unnamed
10282 type to which it refers. */
10283 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10284 is_const_type
, is_volatile_type
,
10286 /* Else cv-qualified version of named type; fall through. */
10289 mod_scope
= scope_die_for (type
, context_die
);
10292 /* If both is_const_type and is_volatile_type, prefer the path
10293 which leads to a qualified type. */
10294 && (!is_volatile_type
10295 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10296 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10298 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10299 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10301 else if (is_volatile_type
)
10303 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10304 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10306 else if (code
== POINTER_TYPE
)
10308 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10309 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10310 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10311 item_type
= TREE_TYPE (type
);
10312 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10313 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10314 TYPE_ADDR_SPACE (item_type
));
10316 else if (code
== REFERENCE_TYPE
)
10318 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10319 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10322 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10323 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10324 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10325 item_type
= TREE_TYPE (type
);
10326 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10327 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10328 TYPE_ADDR_SPACE (item_type
));
10330 else if (code
== INTEGER_TYPE
10331 && TREE_TYPE (type
) != NULL_TREE
10332 && subrange_type_for_debug_p (type
, &low
, &high
))
10334 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10335 item_type
= TREE_TYPE (type
);
10337 else if (is_base_type (type
))
10338 mod_type_die
= base_type_die (type
);
10341 gen_type_die (type
, context_die
);
10343 /* We have to get the type_main_variant here (and pass that to the
10344 `lookup_type_die' routine) because the ..._TYPE node we have
10345 might simply be a *copy* of some original type node (where the
10346 copy was created to help us keep track of typedef names) and
10347 that copy might have a different TYPE_UID from the original
10349 if (TREE_CODE (type
) != VECTOR_TYPE
)
10350 return lookup_type_die (type_main_variant (type
));
10352 /* Vectors have the debugging information in the type,
10353 not the main variant. */
10354 return lookup_type_die (type
);
10357 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10358 don't output a DW_TAG_typedef, since there isn't one in the
10359 user's program; just attach a DW_AT_name to the type.
10360 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10361 if the base type already has the same name. */
10363 && ((TREE_CODE (name
) != TYPE_DECL
10364 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10365 || (!is_const_type
&& !is_volatile_type
)))
10366 || (TREE_CODE (name
) == TYPE_DECL
10367 && TREE_TYPE (name
) == qualified_type
10368 && DECL_NAME (name
))))
10370 if (TREE_CODE (name
) == TYPE_DECL
)
10371 /* Could just call add_name_and_src_coords_attributes here,
10372 but since this is a builtin type it doesn't have any
10373 useful source coordinates anyway. */
10374 name
= DECL_NAME (name
);
10375 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10377 /* This probably indicates a bug. */
10378 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10380 name
= TYPE_NAME (type
);
10382 && TREE_CODE (name
) == TYPE_DECL
)
10383 name
= DECL_NAME (name
);
10384 add_name_attribute (mod_type_die
,
10385 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10388 if (qualified_type
)
10389 equate_type_number_to_die (qualified_type
, mod_type_die
);
10392 /* We must do this after the equate_type_number_to_die call, in case
10393 this is a recursive type. This ensures that the modified_type_die
10394 recursion will terminate even if the type is recursive. Recursive
10395 types are possible in Ada. */
10396 sub_die
= modified_type_die (item_type
,
10397 TYPE_READONLY (item_type
),
10398 TYPE_VOLATILE (item_type
),
10401 if (sub_die
!= NULL
)
10402 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10404 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10405 if (TYPE_ARTIFICIAL (type
))
10406 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10408 return mod_type_die
;
10411 /* Generate DIEs for the generic parameters of T.
10412 T must be either a generic type or a generic function.
10413 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10416 gen_generic_params_dies (tree t
)
10420 dw_die_ref die
= NULL
;
10423 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10427 die
= lookup_type_die (t
);
10428 else if (DECL_P (t
))
10429 die
= lookup_decl_die (t
);
10433 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10435 /* T has no generic parameter. It means T is neither a generic type
10436 or function. End of story. */
10439 parms_num
= TREE_VEC_LENGTH (parms
);
10440 args
= lang_hooks
.get_innermost_generic_args (t
);
10441 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10442 non_default
= int_cst_value (TREE_CHAIN (args
));
10444 non_default
= TREE_VEC_LENGTH (args
);
10445 for (i
= 0; i
< parms_num
; i
++)
10447 tree parm
, arg
, arg_pack_elems
;
10448 dw_die_ref parm_die
;
10450 parm
= TREE_VEC_ELT (parms
, i
);
10451 arg
= TREE_VEC_ELT (args
, i
);
10452 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10453 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10455 if (parm
&& TREE_VALUE (parm
) && arg
)
10457 /* If PARM represents a template parameter pack,
10458 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10459 by DW_TAG_template_*_parameter DIEs for the argument
10460 pack elements of ARG. Note that ARG would then be
10461 an argument pack. */
10462 if (arg_pack_elems
)
10463 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10467 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10468 true /* emit name */, die
);
10469 if (i
>= non_default
)
10470 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10475 /* Create and return a DIE for PARM which should be
10476 the representation of a generic type parameter.
10477 For instance, in the C++ front end, PARM would be a template parameter.
10478 ARG is the argument to PARM.
10479 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10481 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10482 as a child node. */
10485 generic_parameter_die (tree parm
, tree arg
,
10487 dw_die_ref parent_die
)
10489 dw_die_ref tmpl_die
= NULL
;
10490 const char *name
= NULL
;
10492 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10495 /* We support non-type generic parameters and arguments,
10496 type generic parameters and arguments, as well as
10497 generic generic parameters (a.k.a. template template parameters in C++)
10499 if (TREE_CODE (parm
) == PARM_DECL
)
10500 /* PARM is a nontype generic parameter */
10501 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10502 else if (TREE_CODE (parm
) == TYPE_DECL
)
10503 /* PARM is a type generic parameter. */
10504 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10505 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10506 /* PARM is a generic generic parameter.
10507 Its DIE is a GNU extension. It shall have a
10508 DW_AT_name attribute to represent the name of the template template
10509 parameter, and a DW_AT_GNU_template_name attribute to represent the
10510 name of the template template argument. */
10511 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10514 gcc_unreachable ();
10520 /* If PARM is a generic parameter pack, it means we are
10521 emitting debug info for a template argument pack element.
10522 In other terms, ARG is a template argument pack element.
10523 In that case, we don't emit any DW_AT_name attribute for
10527 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10529 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10532 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10534 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10535 TMPL_DIE should have a child DW_AT_type attribute that is set
10536 to the type of the argument to PARM, which is ARG.
10537 If PARM is a type generic parameter, TMPL_DIE should have a
10538 child DW_AT_type that is set to ARG. */
10539 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10540 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10541 TREE_THIS_VOLATILE (tmpl_type
),
10546 /* So TMPL_DIE is a DIE representing a
10547 a generic generic template parameter, a.k.a template template
10548 parameter in C++ and arg is a template. */
10550 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10551 to the name of the argument. */
10552 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10554 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10557 if (TREE_CODE (parm
) == PARM_DECL
)
10558 /* So PARM is a non-type generic parameter.
10559 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10560 attribute of TMPL_DIE which value represents the value
10562 We must be careful here:
10563 The value of ARG might reference some function decls.
10564 We might currently be emitting debug info for a generic
10565 type and types are emitted before function decls, we don't
10566 know if the function decls referenced by ARG will actually be
10567 emitted after cgraph computations.
10568 So must defer the generation of the DW_AT_const_value to
10569 after cgraph is ready. */
10570 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10576 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10577 PARM_PACK must be a template parameter pack. The returned DIE
10578 will be child DIE of PARENT_DIE. */
10581 template_parameter_pack_die (tree parm_pack
,
10582 tree parm_pack_args
,
10583 dw_die_ref parent_die
)
10588 gcc_assert (parent_die
&& parm_pack
);
10590 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10591 add_name_and_src_coords_attributes (die
, parm_pack
);
10592 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10593 generic_parameter_die (parm_pack
,
10594 TREE_VEC_ELT (parm_pack_args
, j
),
10595 false /* Don't emit DW_AT_name */,
10600 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10601 an enumerated type. */
10604 type_is_enum (const_tree type
)
10606 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10609 /* Return the DBX register number described by a given RTL node. */
10611 static unsigned int
10612 dbx_reg_number (const_rtx rtl
)
10614 unsigned regno
= REGNO (rtl
);
10616 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10618 #ifdef LEAF_REG_REMAP
10619 if (crtl
->uses_only_leaf_regs
)
10621 int leaf_reg
= LEAF_REG_REMAP (regno
);
10622 if (leaf_reg
!= -1)
10623 regno
= (unsigned) leaf_reg
;
10627 regno
= DBX_REGISTER_NUMBER (regno
);
10628 gcc_assert (regno
!= INVALID_REGNUM
);
10632 /* Optionally add a DW_OP_piece term to a location description expression.
10633 DW_OP_piece is only added if the location description expression already
10634 doesn't end with DW_OP_piece. */
10637 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10639 dw_loc_descr_ref loc
;
10641 if (*list_head
!= NULL
)
10643 /* Find the end of the chain. */
10644 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10647 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10648 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10652 /* Return a location descriptor that designates a machine register or
10653 zero if there is none. */
10655 static dw_loc_descr_ref
10656 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10660 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10663 /* We only use "frame base" when we're sure we're talking about the
10664 post-prologue local stack frame. We do this by *not* running
10665 register elimination until this point, and recognizing the special
10666 argument pointer and soft frame pointer rtx's.
10667 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10668 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10669 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10671 dw_loc_descr_ref result
= NULL
;
10673 if (dwarf_version
>= 4 || !dwarf_strict
)
10675 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10678 add_loc_descr (&result
,
10679 new_loc_descr (DW_OP_stack_value
, 0, 0));
10684 regs
= targetm
.dwarf_register_span (rtl
);
10686 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10687 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10690 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10691 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10693 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10697 /* Return a location descriptor that designates a machine register for
10698 a given hard register number. */
10700 static dw_loc_descr_ref
10701 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10703 dw_loc_descr_ref reg_loc_descr
;
10707 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10709 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10711 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10712 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10714 return reg_loc_descr
;
10717 /* Given an RTL of a register, return a location descriptor that
10718 designates a value that spans more than one register. */
10720 static dw_loc_descr_ref
10721 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10722 enum var_init_status initialized
)
10725 dw_loc_descr_ref loc_result
= NULL
;
10727 /* Simple, contiguous registers. */
10728 if (regs
== NULL_RTX
)
10730 unsigned reg
= REGNO (rtl
);
10733 #ifdef LEAF_REG_REMAP
10734 if (crtl
->uses_only_leaf_regs
)
10736 int leaf_reg
= LEAF_REG_REMAP (reg
);
10737 if (leaf_reg
!= -1)
10738 reg
= (unsigned) leaf_reg
;
10742 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10743 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10745 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10750 dw_loc_descr_ref t
;
10752 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10753 VAR_INIT_STATUS_INITIALIZED
);
10754 add_loc_descr (&loc_result
, t
);
10755 add_loc_descr_op_piece (&loc_result
, size
);
10761 /* Now onto stupid register sets in non contiguous locations. */
10763 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10765 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10768 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10770 dw_loc_descr_ref t
;
10772 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
10773 VAR_INIT_STATUS_INITIALIZED
);
10774 add_loc_descr (&loc_result
, t
);
10775 add_loc_descr_op_piece (&loc_result
, size
);
10778 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10779 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10783 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10785 /* Return a location descriptor that designates a constant i,
10786 as a compound operation from constant (i >> shift), constant shift
10789 static dw_loc_descr_ref
10790 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10792 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10793 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10794 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10798 /* Return a location descriptor that designates a constant. */
10800 static dw_loc_descr_ref
10801 int_loc_descriptor (HOST_WIDE_INT i
)
10803 enum dwarf_location_atom op
;
10805 /* Pick the smallest representation of a constant, rather than just
10806 defaulting to the LEB encoding. */
10809 int clz
= clz_hwi (i
);
10810 int ctz
= ctz_hwi (i
);
10812 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10813 else if (i
<= 0xff)
10814 op
= DW_OP_const1u
;
10815 else if (i
<= 0xffff)
10816 op
= DW_OP_const2u
;
10817 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10818 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10819 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10820 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10821 while DW_OP_const4u is 5 bytes. */
10822 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10823 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10824 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10825 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10826 while DW_OP_const4u is 5 bytes. */
10827 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10828 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10829 op
= DW_OP_const4u
;
10830 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10831 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10832 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10833 while DW_OP_constu of constant >= 0x100000000 takes at least
10835 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10836 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10837 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10838 >= HOST_BITS_PER_WIDE_INT
)
10839 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10840 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10841 while DW_OP_constu takes in this case at least 6 bytes. */
10842 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10843 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10844 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10845 && size_of_uleb128 (i
) > 6)
10846 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10847 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10854 op
= DW_OP_const1s
;
10855 else if (i
>= -0x8000)
10856 op
= DW_OP_const2s
;
10857 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10859 if (size_of_int_loc_descriptor (i
) < 5)
10861 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10862 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10865 op
= DW_OP_const4s
;
10869 if (size_of_int_loc_descriptor (i
)
10870 < (unsigned long) 1 + size_of_sleb128 (i
))
10872 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10873 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10880 return new_loc_descr (op
, i
, 0);
10883 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10884 without actually allocating it. */
10886 static unsigned long
10887 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10889 return size_of_int_loc_descriptor (i
>> shift
)
10890 + size_of_int_loc_descriptor (shift
)
10894 /* Return size_of_locs (int_loc_descriptor (i)) without
10895 actually allocating it. */
10897 static unsigned long
10898 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10907 else if (i
<= 0xff)
10909 else if (i
<= 0xffff)
10913 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10914 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10915 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10917 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10918 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10919 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10921 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10923 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10924 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10925 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10926 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10928 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10929 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10930 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10932 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10933 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10935 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10944 else if (i
>= -0x8000)
10946 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10948 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10950 s
= size_of_int_loc_descriptor (-i
) + 1;
10958 unsigned long r
= 1 + size_of_sleb128 (i
);
10959 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10961 s
= size_of_int_loc_descriptor (-i
) + 1;
10970 /* Return loc description representing "address" of integer value.
10971 This can appear only as toplevel expression. */
10973 static dw_loc_descr_ref
10974 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10977 dw_loc_descr_ref loc_result
= NULL
;
10979 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10982 litsize
= size_of_int_loc_descriptor (i
);
10983 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10984 is more compact. For DW_OP_stack_value we need:
10985 litsize + 1 (DW_OP_stack_value)
10986 and for DW_OP_implicit_value:
10987 1 (DW_OP_implicit_value) + 1 (length) + size. */
10988 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10990 loc_result
= int_loc_descriptor (i
);
10991 add_loc_descr (&loc_result
,
10992 new_loc_descr (DW_OP_stack_value
, 0, 0));
10996 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10998 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10999 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11003 /* Return a location descriptor that designates a base+offset location. */
11005 static dw_loc_descr_ref
11006 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11007 enum var_init_status initialized
)
11009 unsigned int regno
;
11010 dw_loc_descr_ref result
;
11011 dw_fde_ref fde
= cfun
->fde
;
11013 /* We only use "frame base" when we're sure we're talking about the
11014 post-prologue local stack frame. We do this by *not* running
11015 register elimination until this point, and recognizing the special
11016 argument pointer and soft frame pointer rtx's. */
11017 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11019 rtx elim
= (ira_use_lra_p
11020 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11021 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11025 if (GET_CODE (elim
) == PLUS
)
11027 offset
+= INTVAL (XEXP (elim
, 1));
11028 elim
= XEXP (elim
, 0);
11030 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11031 && (elim
== hard_frame_pointer_rtx
11032 || elim
== stack_pointer_rtx
))
11033 || elim
== (frame_pointer_needed
11034 ? hard_frame_pointer_rtx
11035 : stack_pointer_rtx
));
11037 /* If drap register is used to align stack, use frame
11038 pointer + offset to access stack variables. If stack
11039 is aligned without drap, use stack pointer + offset to
11040 access stack variables. */
11041 if (crtl
->stack_realign_tried
11042 && reg
== frame_pointer_rtx
)
11045 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11046 ? HARD_FRAME_POINTER_REGNUM
11048 return new_reg_loc_descr (base_reg
, offset
);
11051 gcc_assert (frame_pointer_fb_offset_valid
);
11052 offset
+= frame_pointer_fb_offset
;
11053 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11057 regno
= REGNO (reg
);
11058 #ifdef LEAF_REG_REMAP
11059 if (crtl
->uses_only_leaf_regs
)
11061 int leaf_reg
= LEAF_REG_REMAP (regno
);
11062 if (leaf_reg
!= -1)
11063 regno
= (unsigned) leaf_reg
;
11066 regno
= DWARF_FRAME_REGNUM (regno
);
11068 if (!optimize
&& fde
11069 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11071 /* Use cfa+offset to represent the location of arguments passed
11072 on the stack when drap is used to align stack.
11073 Only do this when not optimizing, for optimized code var-tracking
11074 is supposed to track where the arguments live and the register
11075 used as vdrap or drap in some spot might be used for something
11076 else in other part of the routine. */
11077 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11081 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11084 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11086 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11087 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11092 /* Return true if this RTL expression describes a base+offset calculation. */
11095 is_based_loc (const_rtx rtl
)
11097 return (GET_CODE (rtl
) == PLUS
11098 && ((REG_P (XEXP (rtl
, 0))
11099 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11100 && CONST_INT_P (XEXP (rtl
, 1)))));
11103 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11106 static dw_loc_descr_ref
11107 tls_mem_loc_descriptor (rtx mem
)
11110 dw_loc_descr_ref loc_result
;
11112 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11115 base
= get_base_address (MEM_EXPR (mem
));
11117 || TREE_CODE (base
) != VAR_DECL
11118 || !DECL_THREAD_LOCAL_P (base
))
11121 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11122 if (loc_result
== NULL
)
11125 if (MEM_OFFSET (mem
))
11126 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11131 /* Output debug info about reason why we failed to expand expression as dwarf
11135 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11137 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11139 fprintf (dump_file
, "Failed to expand as dwarf: ");
11141 print_generic_expr (dump_file
, expr
, dump_flags
);
11144 fprintf (dump_file
, "\n");
11145 print_rtl (dump_file
, rtl
);
11147 fprintf (dump_file
, "\nReason: %s\n", reason
);
11151 /* Helper function for const_ok_for_output, called either directly
11152 or via for_each_rtx. */
11155 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11159 if (GET_CODE (rtl
) == UNSPEC
)
11161 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11162 we can't express it in the debug info. */
11163 #ifdef ENABLE_CHECKING
11164 /* Don't complain about TLS UNSPECs, those are just too hard to
11165 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11166 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11167 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11168 if (XVECLEN (rtl
, 0) == 0
11169 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11170 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11171 inform (current_function_decl
11172 ? DECL_SOURCE_LOCATION (current_function_decl
)
11173 : UNKNOWN_LOCATION
,
11174 #if NUM_UNSPEC_VALUES > 0
11175 "non-delegitimized UNSPEC %s (%d) found in variable location",
11176 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11177 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11180 "non-delegitimized UNSPEC %d found in variable location",
11184 expansion_failed (NULL_TREE
, rtl
,
11185 "UNSPEC hasn't been delegitimized.\n");
11189 if (targetm
.const_not_ok_for_debug_p (rtl
))
11191 expansion_failed (NULL_TREE
, rtl
,
11192 "Expression rejected for debug by the backend.\n");
11196 if (GET_CODE (rtl
) != SYMBOL_REF
)
11199 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11202 get_pool_constant_mark (rtl
, &marked
);
11203 /* If all references to this pool constant were optimized away,
11204 it was not output and thus we can't represent it. */
11207 expansion_failed (NULL_TREE
, rtl
,
11208 "Constant was removed from constant pool.\n");
11213 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11216 /* Avoid references to external symbols in debug info, on several targets
11217 the linker might even refuse to link when linking a shared library,
11218 and in many other cases the relocations for .debug_info/.debug_loc are
11219 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11220 to be defined within the same shared library or executable are fine. */
11221 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11223 tree decl
= SYMBOL_REF_DECL (rtl
);
11225 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11227 expansion_failed (NULL_TREE
, rtl
,
11228 "Symbol not defined in current TU.\n");
11236 /* Return true if constant RTL can be emitted in DW_OP_addr or
11237 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11238 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11241 const_ok_for_output (rtx rtl
)
11243 if (GET_CODE (rtl
) == SYMBOL_REF
)
11244 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11246 if (GET_CODE (rtl
) == CONST
)
11247 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11252 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11253 if possible, NULL otherwise. */
11256 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11258 dw_die_ref type_die
;
11259 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11263 switch (TREE_CODE (type
))
11271 type_die
= lookup_type_die (type
);
11273 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11274 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11279 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11280 type matching MODE, or, if MODE is narrower than or as wide as
11281 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11284 static dw_loc_descr_ref
11285 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11287 enum machine_mode outer_mode
= mode
;
11288 dw_die_ref type_die
;
11289 dw_loc_descr_ref cvt
;
11291 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11293 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11296 type_die
= base_type_for_mode (outer_mode
, 1);
11297 if (type_die
== NULL
)
11299 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11300 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11301 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11302 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11303 add_loc_descr (&op
, cvt
);
11307 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11309 static dw_loc_descr_ref
11310 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11311 dw_loc_descr_ref op1
)
11313 dw_loc_descr_ref ret
= op0
;
11314 add_loc_descr (&ret
, op1
);
11315 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11316 if (STORE_FLAG_VALUE
!= 1)
11318 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11319 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11324 /* Return location descriptor for signed comparison OP RTL. */
11326 static dw_loc_descr_ref
11327 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11328 enum machine_mode mem_mode
)
11330 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11331 dw_loc_descr_ref op0
, op1
;
11334 if (op_mode
== VOIDmode
)
11335 op_mode
= GET_MODE (XEXP (rtl
, 1));
11336 if (op_mode
== VOIDmode
)
11340 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11341 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11344 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11345 VAR_INIT_STATUS_INITIALIZED
);
11346 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11347 VAR_INIT_STATUS_INITIALIZED
);
11349 if (op0
== NULL
|| op1
== NULL
)
11352 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11353 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11354 return compare_loc_descriptor (op
, op0
, op1
);
11356 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11358 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11359 dw_loc_descr_ref cvt
;
11361 if (type_die
== NULL
)
11363 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11364 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11365 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11366 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11367 add_loc_descr (&op0
, cvt
);
11368 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11369 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11370 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11371 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11372 add_loc_descr (&op1
, cvt
);
11373 return compare_loc_descriptor (op
, op0
, op1
);
11376 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11377 /* For eq/ne, if the operands are known to be zero-extended,
11378 there is no need to do the fancy shifting up. */
11379 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11381 dw_loc_descr_ref last0
, last1
;
11382 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11384 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11386 /* deref_size zero extends, and for constants we can check
11387 whether they are zero extended or not. */
11388 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11389 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11390 || (CONST_INT_P (XEXP (rtl
, 0))
11391 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11392 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11393 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11394 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11395 || (CONST_INT_P (XEXP (rtl
, 1))
11396 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11397 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11398 return compare_loc_descriptor (op
, op0
, op1
);
11400 /* EQ/NE comparison against constant in narrower type than
11401 DWARF2_ADDR_SIZE can be performed either as
11402 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11405 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11406 DW_OP_{eq,ne}. Pick whatever is shorter. */
11407 if (CONST_INT_P (XEXP (rtl
, 1))
11408 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11409 && (size_of_int_loc_descriptor (shift
) + 1
11410 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11411 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11412 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11413 & GET_MODE_MASK (op_mode
))))
11415 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11416 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11417 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11418 & GET_MODE_MASK (op_mode
));
11419 return compare_loc_descriptor (op
, op0
, op1
);
11422 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11423 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11424 if (CONST_INT_P (XEXP (rtl
, 1)))
11425 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11428 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11429 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11431 return compare_loc_descriptor (op
, op0
, op1
);
11434 /* Return location descriptor for unsigned comparison OP RTL. */
11436 static dw_loc_descr_ref
11437 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11438 enum machine_mode mem_mode
)
11440 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11441 dw_loc_descr_ref op0
, op1
;
11443 if (op_mode
== VOIDmode
)
11444 op_mode
= GET_MODE (XEXP (rtl
, 1));
11445 if (op_mode
== VOIDmode
)
11447 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11450 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11453 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11454 VAR_INIT_STATUS_INITIALIZED
);
11455 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11456 VAR_INIT_STATUS_INITIALIZED
);
11458 if (op0
== NULL
|| op1
== NULL
)
11461 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11463 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11464 dw_loc_descr_ref last0
, last1
;
11465 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11467 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11469 if (CONST_INT_P (XEXP (rtl
, 0)))
11470 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11471 /* deref_size zero extends, so no need to mask it again. */
11472 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11473 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11475 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11476 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11478 if (CONST_INT_P (XEXP (rtl
, 1)))
11479 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11480 /* deref_size zero extends, so no need to mask it again. */
11481 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11482 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11484 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11485 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11488 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11490 HOST_WIDE_INT bias
= 1;
11491 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11492 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11493 if (CONST_INT_P (XEXP (rtl
, 1)))
11494 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11495 + INTVAL (XEXP (rtl
, 1)));
11497 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11500 return compare_loc_descriptor (op
, op0
, op1
);
11503 /* Return location descriptor for {U,S}{MIN,MAX}. */
11505 static dw_loc_descr_ref
11506 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11507 enum machine_mode mem_mode
)
11509 enum dwarf_location_atom op
;
11510 dw_loc_descr_ref op0
, op1
, ret
;
11511 dw_loc_descr_ref bra_node
, drop_node
;
11514 && (GET_MODE_CLASS (mode
) != MODE_INT
11515 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11518 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11519 VAR_INIT_STATUS_INITIALIZED
);
11520 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11521 VAR_INIT_STATUS_INITIALIZED
);
11523 if (op0
== NULL
|| op1
== NULL
)
11526 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11527 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11528 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11529 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11531 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11533 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11534 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11535 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11536 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11537 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11539 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11541 HOST_WIDE_INT bias
= 1;
11542 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11543 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11544 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11547 else if (GET_MODE_CLASS (mode
) == MODE_INT
11548 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11550 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11551 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11552 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11553 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11554 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11556 else if (GET_MODE_CLASS (mode
) == MODE_INT
11557 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11559 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11560 dw_loc_descr_ref cvt
;
11561 if (type_die
== NULL
)
11563 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11564 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11565 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11566 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11567 add_loc_descr (&op0
, cvt
);
11568 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11569 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11570 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11571 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11572 add_loc_descr (&op1
, cvt
);
11575 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11580 add_loc_descr (&ret
, op1
);
11581 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11582 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11583 add_loc_descr (&ret
, bra_node
);
11584 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11585 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11586 add_loc_descr (&ret
, drop_node
);
11587 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11588 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11589 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11590 && GET_MODE_CLASS (mode
) == MODE_INT
11591 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11592 ret
= convert_descriptor_to_mode (mode
, ret
);
11596 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11597 but after converting arguments to type_die, afterwards
11598 convert back to unsigned. */
11600 static dw_loc_descr_ref
11601 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11602 enum machine_mode mode
, enum machine_mode mem_mode
)
11604 dw_loc_descr_ref cvt
, op0
, op1
;
11606 if (type_die
== NULL
)
11608 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11609 VAR_INIT_STATUS_INITIALIZED
);
11610 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11611 VAR_INIT_STATUS_INITIALIZED
);
11612 if (op0
== NULL
|| op1
== NULL
)
11614 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11615 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11616 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11617 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11618 add_loc_descr (&op0
, cvt
);
11619 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11620 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11621 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11622 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11623 add_loc_descr (&op1
, cvt
);
11624 add_loc_descr (&op0
, op1
);
11625 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11626 return convert_descriptor_to_mode (mode
, op0
);
11629 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11630 const0 is DW_OP_lit0 or corresponding typed constant,
11631 const1 is DW_OP_lit1 or corresponding typed constant
11632 and constMSB is constant with just the MSB bit set
11634 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11635 L1: const0 DW_OP_swap
11636 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11637 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11642 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11643 L1: const0 DW_OP_swap
11644 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11645 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11650 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11651 L1: const1 DW_OP_swap
11652 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11653 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11657 static dw_loc_descr_ref
11658 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11659 enum machine_mode mem_mode
)
11661 dw_loc_descr_ref op0
, ret
, tmp
;
11662 HOST_WIDE_INT valv
;
11663 dw_loc_descr_ref l1jump
, l1label
;
11664 dw_loc_descr_ref l2jump
, l2label
;
11665 dw_loc_descr_ref l3jump
, l3label
;
11666 dw_loc_descr_ref l4jump
, l4label
;
11669 if (GET_MODE_CLASS (mode
) != MODE_INT
11670 || GET_MODE (XEXP (rtl
, 0)) != mode
11671 || (GET_CODE (rtl
) == CLZ
11672 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11675 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11676 VAR_INIT_STATUS_INITIALIZED
);
11680 if (GET_CODE (rtl
) == CLZ
)
11682 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11683 valv
= GET_MODE_BITSIZE (mode
);
11685 else if (GET_CODE (rtl
) == FFS
)
11687 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11688 valv
= GET_MODE_BITSIZE (mode
);
11689 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11690 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11691 add_loc_descr (&ret
, l1jump
);
11692 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11693 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11694 VAR_INIT_STATUS_INITIALIZED
);
11697 add_loc_descr (&ret
, tmp
);
11698 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11699 add_loc_descr (&ret
, l4jump
);
11700 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11701 ? const1_rtx
: const0_rtx
,
11703 VAR_INIT_STATUS_INITIALIZED
);
11704 if (l1label
== NULL
)
11706 add_loc_descr (&ret
, l1label
);
11707 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11708 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11709 add_loc_descr (&ret
, l2label
);
11710 if (GET_CODE (rtl
) != CLZ
)
11712 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11713 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11714 << (GET_MODE_BITSIZE (mode
) - 1));
11716 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11717 << (GET_MODE_BITSIZE (mode
)
11718 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11719 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11720 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11721 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11722 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11724 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11725 VAR_INIT_STATUS_INITIALIZED
);
11728 add_loc_descr (&ret
, tmp
);
11729 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11730 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11731 add_loc_descr (&ret
, l3jump
);
11732 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11733 VAR_INIT_STATUS_INITIALIZED
);
11736 add_loc_descr (&ret
, tmp
);
11737 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11738 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11739 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11740 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11741 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11742 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11743 add_loc_descr (&ret
, l2jump
);
11744 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11745 add_loc_descr (&ret
, l3label
);
11746 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11747 add_loc_descr (&ret
, l4label
);
11748 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11749 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11750 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11751 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11752 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11753 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11754 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11755 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11759 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11760 const1 is DW_OP_lit1 or corresponding typed constant):
11762 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11763 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11767 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11768 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11771 static dw_loc_descr_ref
11772 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11773 enum machine_mode mem_mode
)
11775 dw_loc_descr_ref op0
, ret
, tmp
;
11776 dw_loc_descr_ref l1jump
, l1label
;
11777 dw_loc_descr_ref l2jump
, l2label
;
11779 if (GET_MODE_CLASS (mode
) != MODE_INT
11780 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11783 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11784 VAR_INIT_STATUS_INITIALIZED
);
11788 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11789 VAR_INIT_STATUS_INITIALIZED
);
11792 add_loc_descr (&ret
, tmp
);
11793 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11794 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11795 add_loc_descr (&ret
, l1label
);
11796 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11797 add_loc_descr (&ret
, l2jump
);
11798 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11799 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11800 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11801 VAR_INIT_STATUS_INITIALIZED
);
11804 add_loc_descr (&ret
, tmp
);
11805 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11806 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11807 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11808 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11809 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11810 VAR_INIT_STATUS_INITIALIZED
);
11811 add_loc_descr (&ret
, tmp
);
11812 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11813 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11814 add_loc_descr (&ret
, l1jump
);
11815 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11816 add_loc_descr (&ret
, l2label
);
11817 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11818 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11819 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11820 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11824 /* BSWAP (constS is initial shift count, either 56 or 24):
11826 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11827 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11828 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11829 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11830 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11832 static dw_loc_descr_ref
11833 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11834 enum machine_mode mem_mode
)
11836 dw_loc_descr_ref op0
, ret
, tmp
;
11837 dw_loc_descr_ref l1jump
, l1label
;
11838 dw_loc_descr_ref l2jump
, l2label
;
11840 if (GET_MODE_CLASS (mode
) != MODE_INT
11841 || BITS_PER_UNIT
!= 8
11842 || (GET_MODE_BITSIZE (mode
) != 32
11843 && GET_MODE_BITSIZE (mode
) != 64))
11846 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11847 VAR_INIT_STATUS_INITIALIZED
);
11852 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11854 VAR_INIT_STATUS_INITIALIZED
);
11857 add_loc_descr (&ret
, tmp
);
11858 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11859 VAR_INIT_STATUS_INITIALIZED
);
11862 add_loc_descr (&ret
, tmp
);
11863 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11864 add_loc_descr (&ret
, l1label
);
11865 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11867 VAR_INIT_STATUS_INITIALIZED
);
11868 add_loc_descr (&ret
, tmp
);
11869 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11870 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11871 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11872 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11873 VAR_INIT_STATUS_INITIALIZED
);
11876 add_loc_descr (&ret
, tmp
);
11877 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11878 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11879 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11880 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11881 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11882 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11883 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11884 VAR_INIT_STATUS_INITIALIZED
);
11885 add_loc_descr (&ret
, tmp
);
11886 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11887 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11888 add_loc_descr (&ret
, l2jump
);
11889 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11890 VAR_INIT_STATUS_INITIALIZED
);
11891 add_loc_descr (&ret
, tmp
);
11892 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11893 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11894 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11895 add_loc_descr (&ret
, l1jump
);
11896 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11897 add_loc_descr (&ret
, l2label
);
11898 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11899 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11900 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11901 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11902 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11903 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11907 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11908 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11909 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11910 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11912 ROTATERT is similar:
11913 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11914 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11915 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11917 static dw_loc_descr_ref
11918 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11919 enum machine_mode mem_mode
)
11921 rtx rtlop1
= XEXP (rtl
, 1);
11922 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11925 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11928 if (GET_MODE (rtlop1
) != VOIDmode
11929 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11930 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11931 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11932 VAR_INIT_STATUS_INITIALIZED
);
11933 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11934 VAR_INIT_STATUS_INITIALIZED
);
11935 if (op0
== NULL
|| op1
== NULL
)
11937 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11938 for (i
= 0; i
< 2; i
++)
11940 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11941 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11943 VAR_INIT_STATUS_INITIALIZED
);
11944 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11945 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11947 : HOST_BITS_PER_WIDE_INT
== 64
11948 ? DW_OP_const8u
: DW_OP_constu
,
11949 GET_MODE_MASK (mode
), 0);
11952 if (mask
[i
] == NULL
)
11954 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11957 add_loc_descr (&ret
, op1
);
11958 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11959 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11960 if (GET_CODE (rtl
) == ROTATERT
)
11962 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11963 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11964 GET_MODE_BITSIZE (mode
), 0));
11966 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11967 if (mask
[0] != NULL
)
11968 add_loc_descr (&ret
, mask
[0]);
11969 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11970 if (mask
[1] != NULL
)
11972 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11973 add_loc_descr (&ret
, mask
[1]);
11974 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11976 if (GET_CODE (rtl
) == ROTATE
)
11978 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11979 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11980 GET_MODE_BITSIZE (mode
), 0));
11982 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11983 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11987 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11988 for DEBUG_PARAMETER_REF RTL. */
11990 static dw_loc_descr_ref
11991 parameter_ref_descriptor (rtx rtl
)
11993 dw_loc_descr_ref ret
;
11998 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11999 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12000 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12003 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12004 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12005 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12009 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12010 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12015 /* The following routine converts the RTL for a variable or parameter
12016 (resident in memory) into an equivalent Dwarf representation of a
12017 mechanism for getting the address of that same variable onto the top of a
12018 hypothetical "address evaluation" stack.
12020 When creating memory location descriptors, we are effectively transforming
12021 the RTL for a memory-resident object into its Dwarf postfix expression
12022 equivalent. This routine recursively descends an RTL tree, turning
12023 it into Dwarf postfix code as it goes.
12025 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12027 MEM_MODE is the mode of the memory reference, needed to handle some
12028 autoincrement addressing modes.
12030 Return 0 if we can't represent the location. */
12033 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12034 enum machine_mode mem_mode
,
12035 enum var_init_status initialized
)
12037 dw_loc_descr_ref mem_loc_result
= NULL
;
12038 enum dwarf_location_atom op
;
12039 dw_loc_descr_ref op0
, op1
;
12040 rtx inner
= NULL_RTX
;
12042 if (mode
== VOIDmode
)
12043 mode
= GET_MODE (rtl
);
12045 /* Note that for a dynamically sized array, the location we will generate a
12046 description of here will be the lowest numbered location which is
12047 actually within the array. That's *not* necessarily the same as the
12048 zeroth element of the array. */
12050 rtl
= targetm
.delegitimize_address (rtl
);
12052 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12055 switch (GET_CODE (rtl
))
12060 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12063 /* The case of a subreg may arise when we have a local (register)
12064 variable or a formal (register) parameter which doesn't quite fill
12065 up an entire register. For now, just assume that it is
12066 legitimate to make the Dwarf info refer to the whole register which
12067 contains the given subreg. */
12068 if (!subreg_lowpart_p (rtl
))
12070 inner
= SUBREG_REG (rtl
);
12072 if (inner
== NULL_RTX
)
12073 inner
= XEXP (rtl
, 0);
12074 if (GET_MODE_CLASS (mode
) == MODE_INT
12075 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12076 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12077 #ifdef POINTERS_EXTEND_UNSIGNED
12078 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12081 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12083 mem_loc_result
= mem_loc_descriptor (inner
,
12085 mem_mode
, initialized
);
12090 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12092 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12093 && (GET_MODE_CLASS (mode
) != MODE_INT
12094 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12098 dw_die_ref type_die
;
12099 dw_loc_descr_ref cvt
;
12101 mem_loc_result
= mem_loc_descriptor (inner
,
12103 mem_mode
, initialized
);
12104 if (mem_loc_result
== NULL
)
12106 type_die
= base_type_for_mode (mode
,
12107 GET_MODE_CLASS (mode
) == MODE_INT
);
12108 if (type_die
== NULL
)
12110 mem_loc_result
= NULL
;
12113 if (GET_MODE_SIZE (mode
)
12114 != GET_MODE_SIZE (GET_MODE (inner
)))
12115 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12117 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12118 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12119 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12120 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12121 add_loc_descr (&mem_loc_result
, cvt
);
12126 if (GET_MODE_CLASS (mode
) != MODE_INT
12127 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12128 && rtl
!= arg_pointer_rtx
12129 && rtl
!= frame_pointer_rtx
12130 #ifdef POINTERS_EXTEND_UNSIGNED
12131 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12135 dw_die_ref type_die
;
12136 unsigned int dbx_regnum
;
12140 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12142 type_die
= base_type_for_mode (mode
,
12143 GET_MODE_CLASS (mode
) == MODE_INT
);
12144 if (type_die
== NULL
)
12147 dbx_regnum
= dbx_reg_number (rtl
);
12148 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12150 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12152 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12153 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12154 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12157 /* Whenever a register number forms a part of the description of the
12158 method for calculating the (dynamic) address of a memory resident
12159 object, DWARF rules require the register number be referred to as
12160 a "base register". This distinction is not based in any way upon
12161 what category of register the hardware believes the given register
12162 belongs to. This is strictly DWARF terminology we're dealing with
12163 here. Note that in cases where the location of a memory-resident
12164 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12165 OP_CONST (0)) the actual DWARF location descriptor that we generate
12166 may just be OP_BASEREG (basereg). This may look deceptively like
12167 the object in question was allocated to a register (rather than in
12168 memory) so DWARF consumers need to be aware of the subtle
12169 distinction between OP_REG and OP_BASEREG. */
12170 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12171 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12172 else if (stack_realign_drap
12174 && crtl
->args
.internal_arg_pointer
== rtl
12175 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12177 /* If RTL is internal_arg_pointer, which has been optimized
12178 out, use DRAP instead. */
12179 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12180 VAR_INIT_STATUS_INITIALIZED
);
12186 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12188 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12189 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12192 else if (GET_CODE (rtl
) == ZERO_EXTEND
12193 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12194 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12195 < HOST_BITS_PER_WIDE_INT
12196 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12197 to expand zero extend as two shifts instead of
12199 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12201 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12202 mem_loc_result
= op0
;
12203 add_loc_descr (&mem_loc_result
,
12204 int_loc_descriptor (GET_MODE_MASK (imode
)));
12205 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12207 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12209 int shift
= DWARF2_ADDR_SIZE
12210 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12211 shift
*= BITS_PER_UNIT
;
12212 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12216 mem_loc_result
= op0
;
12217 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12218 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12219 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12220 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12222 else if (!dwarf_strict
)
12224 dw_die_ref type_die1
, type_die2
;
12225 dw_loc_descr_ref cvt
;
12227 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12228 GET_CODE (rtl
) == ZERO_EXTEND
);
12229 if (type_die1
== NULL
)
12231 type_die2
= base_type_for_mode (mode
, 1);
12232 if (type_die2
== NULL
)
12234 mem_loc_result
= op0
;
12235 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12236 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12237 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12238 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12239 add_loc_descr (&mem_loc_result
, cvt
);
12240 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12241 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12242 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12243 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12244 add_loc_descr (&mem_loc_result
, cvt
);
12250 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12251 if (new_rtl
!= rtl
)
12253 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12255 if (mem_loc_result
!= NULL
)
12256 return mem_loc_result
;
12259 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12260 get_address_mode (rtl
), mode
,
12261 VAR_INIT_STATUS_INITIALIZED
);
12262 if (mem_loc_result
== NULL
)
12263 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12264 if (mem_loc_result
!= NULL
)
12266 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12267 || GET_MODE_CLASS (mode
) != MODE_INT
)
12269 dw_die_ref type_die
;
12270 dw_loc_descr_ref deref
;
12275 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12276 if (type_die
== NULL
)
12278 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12279 GET_MODE_SIZE (mode
), 0);
12280 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12281 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12282 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12283 add_loc_descr (&mem_loc_result
, deref
);
12285 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12286 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12288 add_loc_descr (&mem_loc_result
,
12289 new_loc_descr (DW_OP_deref_size
,
12290 GET_MODE_SIZE (mode
), 0));
12295 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12298 /* Some ports can transform a symbol ref into a label ref, because
12299 the symbol ref is too far away and has to be dumped into a constant
12303 if (GET_MODE_CLASS (mode
) != MODE_INT
12304 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12305 #ifdef POINTERS_EXTEND_UNSIGNED
12306 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12310 if (GET_CODE (rtl
) == SYMBOL_REF
12311 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12313 dw_loc_descr_ref temp
;
12315 /* If this is not defined, we have no way to emit the data. */
12316 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12319 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12321 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12322 add_loc_descr (&mem_loc_result
, temp
);
12327 if (!const_ok_for_output (rtl
))
12331 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12332 vec_safe_push (used_rtx_array
, rtl
);
12338 case DEBUG_IMPLICIT_PTR
:
12339 expansion_failed (NULL_TREE
, rtl
,
12340 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12346 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12348 if (GET_MODE_CLASS (mode
) != MODE_INT
12349 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12350 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12351 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12354 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12355 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12357 op0
= one_reg_loc_descriptor (dbx_regnum
,
12358 VAR_INIT_STATUS_INITIALIZED
);
12361 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12362 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12364 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12365 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12366 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12370 gcc_unreachable ();
12373 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12374 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12375 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12378 case DEBUG_PARAMETER_REF
:
12379 mem_loc_result
= parameter_ref_descriptor (rtl
);
12383 /* Extract the PLUS expression nested inside and fall into
12384 PLUS code below. */
12385 rtl
= XEXP (rtl
, 1);
12390 /* Turn these into a PLUS expression and fall into the PLUS code
12392 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12393 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12394 ? GET_MODE_UNIT_SIZE (mem_mode
)
12395 : -GET_MODE_UNIT_SIZE (mem_mode
),
12398 /* ... fall through ... */
12402 if (is_based_loc (rtl
)
12403 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12404 || XEXP (rtl
, 0) == arg_pointer_rtx
12405 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12406 && GET_MODE_CLASS (mode
) == MODE_INT
)
12407 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12408 INTVAL (XEXP (rtl
, 1)),
12409 VAR_INIT_STATUS_INITIALIZED
);
12412 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12413 VAR_INIT_STATUS_INITIALIZED
);
12414 if (mem_loc_result
== 0)
12417 if (CONST_INT_P (XEXP (rtl
, 1))
12418 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12419 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12422 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12423 VAR_INIT_STATUS_INITIALIZED
);
12426 add_loc_descr (&mem_loc_result
, op1
);
12427 add_loc_descr (&mem_loc_result
,
12428 new_loc_descr (DW_OP_plus
, 0, 0));
12433 /* If a pseudo-reg is optimized away, it is possible for it to
12434 be replaced with a MEM containing a multiply or shift. */
12445 && GET_MODE_CLASS (mode
) == MODE_INT
12446 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12448 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12449 base_type_for_mode (mode
, 0),
12473 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12475 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12476 VAR_INIT_STATUS_INITIALIZED
);
12478 rtx rtlop1
= XEXP (rtl
, 1);
12479 if (GET_MODE (rtlop1
) != VOIDmode
12480 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12481 < GET_MODE_BITSIZE (mode
))
12482 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12483 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12484 VAR_INIT_STATUS_INITIALIZED
);
12487 if (op0
== 0 || op1
== 0)
12490 mem_loc_result
= op0
;
12491 add_loc_descr (&mem_loc_result
, op1
);
12492 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12508 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12509 VAR_INIT_STATUS_INITIALIZED
);
12510 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12511 VAR_INIT_STATUS_INITIALIZED
);
12513 if (op0
== 0 || op1
== 0)
12516 mem_loc_result
= op0
;
12517 add_loc_descr (&mem_loc_result
, op1
);
12518 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12522 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12524 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12525 base_type_for_mode (mode
, 0),
12530 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12531 VAR_INIT_STATUS_INITIALIZED
);
12532 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12533 VAR_INIT_STATUS_INITIALIZED
);
12535 if (op0
== 0 || op1
== 0)
12538 mem_loc_result
= op0
;
12539 add_loc_descr (&mem_loc_result
, op1
);
12540 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12541 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12542 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12543 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12544 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12548 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12550 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12555 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12556 base_type_for_mode (mode
, 1),
12574 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12575 VAR_INIT_STATUS_INITIALIZED
);
12580 mem_loc_result
= op0
;
12581 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12585 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12586 #ifdef POINTERS_EXTEND_UNSIGNED
12588 && mem_mode
!= VOIDmode
12589 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12593 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12597 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12598 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12600 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12601 enum machine_mode amode
;
12602 if (type_die
== NULL
)
12604 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12606 if (INTVAL (rtl
) >= 0
12607 && amode
!= BLKmode
12608 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12609 /* const DW_OP_GNU_convert <XXX> vs.
12610 DW_OP_GNU_const_type <XXX, 1, const>. */
12611 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12612 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12614 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12615 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12616 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12617 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12618 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12619 add_loc_descr (&mem_loc_result
, op0
);
12620 return mem_loc_result
;
12622 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12624 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12625 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12626 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12627 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12628 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12631 mem_loc_result
->dw_loc_oprnd2
.val_class
12632 = dw_val_class_const_double
;
12633 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12634 = double_int::from_shwi (INTVAL (rtl
));
12642 dw_die_ref type_die
;
12644 /* Note that a CONST_DOUBLE rtx could represent either an integer
12645 or a floating-point constant. A CONST_DOUBLE is used whenever
12646 the constant requires more than one word in order to be
12647 adequately represented. We output CONST_DOUBLEs as blocks. */
12648 if (mode
== VOIDmode
12649 || (GET_MODE (rtl
) == VOIDmode
12650 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12652 type_die
= base_type_for_mode (mode
,
12653 GET_MODE_CLASS (mode
) == MODE_INT
);
12654 if (type_die
== NULL
)
12656 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12657 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12658 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12659 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12660 if (SCALAR_FLOAT_MODE_P (mode
))
12662 unsigned int length
= GET_MODE_SIZE (mode
);
12663 unsigned char *array
12664 = (unsigned char*) ggc_alloc_atomic (length
);
12666 insert_float (rtl
, array
);
12667 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12668 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12669 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12670 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12674 mem_loc_result
->dw_loc_oprnd2
.val_class
12675 = dw_val_class_const_double
;
12676 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12677 = rtx_to_double_int (rtl
);
12683 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12687 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12691 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12695 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12699 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12703 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12707 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12711 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12715 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12719 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12724 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12729 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12734 if (CONST_INT_P (XEXP (rtl
, 1))
12735 && CONST_INT_P (XEXP (rtl
, 2))
12736 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12737 + (unsigned) INTVAL (XEXP (rtl
, 2))
12738 <= GET_MODE_BITSIZE (mode
))
12739 && GET_MODE_CLASS (mode
) == MODE_INT
12740 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12741 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12744 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12745 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12748 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12752 mem_loc_result
= op0
;
12753 size
= INTVAL (XEXP (rtl
, 1));
12754 shift
= INTVAL (XEXP (rtl
, 2));
12755 if (BITS_BIG_ENDIAN
)
12756 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12758 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12760 add_loc_descr (&mem_loc_result
,
12761 int_loc_descriptor (DWARF2_ADDR_SIZE
12763 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12765 if (size
!= (int) DWARF2_ADDR_SIZE
)
12767 add_loc_descr (&mem_loc_result
,
12768 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12769 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12776 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12777 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12778 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12779 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12780 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12781 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12782 VAR_INIT_STATUS_INITIALIZED
);
12783 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12784 VAR_INIT_STATUS_INITIALIZED
);
12785 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12788 mem_loc_result
= op1
;
12789 add_loc_descr (&mem_loc_result
, op2
);
12790 add_loc_descr (&mem_loc_result
, op0
);
12791 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12792 add_loc_descr (&mem_loc_result
, bra_node
);
12793 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12794 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12795 add_loc_descr (&mem_loc_result
, drop_node
);
12796 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12797 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12802 case FLOAT_TRUNCATE
:
12804 case UNSIGNED_FLOAT
:
12809 dw_die_ref type_die
;
12810 dw_loc_descr_ref cvt
;
12812 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12813 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12816 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12817 && (GET_CODE (rtl
) == FLOAT
12818 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12819 <= DWARF2_ADDR_SIZE
))
12821 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12822 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12823 if (type_die
== NULL
)
12825 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12826 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12827 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12828 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12829 add_loc_descr (&op0
, cvt
);
12831 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12832 if (type_die
== NULL
)
12834 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12835 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12836 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12837 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12838 add_loc_descr (&op0
, cvt
);
12839 if (GET_MODE_CLASS (mode
) == MODE_INT
12840 && (GET_CODE (rtl
) == FIX
12841 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12843 op0
= convert_descriptor_to_mode (mode
, op0
);
12847 mem_loc_result
= op0
;
12854 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12859 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12863 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12868 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12872 /* In theory, we could implement the above. */
12873 /* DWARF cannot represent the unsigned compare operations
12898 case FRACT_CONVERT
:
12899 case UNSIGNED_FRACT_CONVERT
:
12901 case UNSIGNED_SAT_FRACT
:
12907 case VEC_DUPLICATE
:
12911 case STRICT_LOW_PART
:
12916 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12917 can't express it in the debug info. This can happen e.g. with some
12922 resolve_one_addr (&rtl
, NULL
);
12926 #ifdef ENABLE_CHECKING
12927 print_rtl (stderr
, rtl
);
12928 gcc_unreachable ();
12934 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12935 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12937 return mem_loc_result
;
12940 /* Return a descriptor that describes the concatenation of two locations.
12941 This is typically a complex variable. */
12943 static dw_loc_descr_ref
12944 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12946 dw_loc_descr_ref cc_loc_result
= NULL
;
12947 dw_loc_descr_ref x0_ref
12948 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12949 dw_loc_descr_ref x1_ref
12950 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12952 if (x0_ref
== 0 || x1_ref
== 0)
12955 cc_loc_result
= x0_ref
;
12956 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12958 add_loc_descr (&cc_loc_result
, x1_ref
);
12959 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12961 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12962 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12964 return cc_loc_result
;
12967 /* Return a descriptor that describes the concatenation of N
12970 static dw_loc_descr_ref
12971 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12974 dw_loc_descr_ref cc_loc_result
= NULL
;
12975 unsigned int n
= XVECLEN (concatn
, 0);
12977 for (i
= 0; i
< n
; ++i
)
12979 dw_loc_descr_ref ref
;
12980 rtx x
= XVECEXP (concatn
, 0, i
);
12982 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12986 add_loc_descr (&cc_loc_result
, ref
);
12987 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12990 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12991 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12993 return cc_loc_result
;
12996 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12997 for DEBUG_IMPLICIT_PTR RTL. */
12999 static dw_loc_descr_ref
13000 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13002 dw_loc_descr_ref ret
;
13007 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13008 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13009 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13010 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13011 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13012 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13015 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13016 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13017 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13021 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13022 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13027 /* Output a proper Dwarf location descriptor for a variable or parameter
13028 which is either allocated in a register or in a memory location. For a
13029 register, we just generate an OP_REG and the register number. For a
13030 memory location we provide a Dwarf postfix expression describing how to
13031 generate the (dynamic) address of the object onto the address stack.
13033 MODE is mode of the decl if this loc_descriptor is going to be used in
13034 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13035 allowed, VOIDmode otherwise.
13037 If we don't know how to describe it, return 0. */
13039 static dw_loc_descr_ref
13040 loc_descriptor (rtx rtl
, enum machine_mode mode
,
13041 enum var_init_status initialized
)
13043 dw_loc_descr_ref loc_result
= NULL
;
13045 switch (GET_CODE (rtl
))
13048 /* The case of a subreg may arise when we have a local (register)
13049 variable or a formal (register) parameter which doesn't quite fill
13050 up an entire register. For now, just assume that it is
13051 legitimate to make the Dwarf info refer to the whole register which
13052 contains the given subreg. */
13053 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13054 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13055 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13061 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13065 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13066 GET_MODE (rtl
), initialized
);
13067 if (loc_result
== NULL
)
13068 loc_result
= tls_mem_loc_descriptor (rtl
);
13069 if (loc_result
== NULL
)
13071 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13072 if (new_rtl
!= rtl
)
13073 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13078 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13083 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13088 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13090 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13091 if (GET_CODE (loc
) == EXPR_LIST
)
13092 loc
= XEXP (loc
, 0);
13093 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13097 rtl
= XEXP (rtl
, 1);
13102 rtvec par_elems
= XVEC (rtl
, 0);
13103 int num_elem
= GET_NUM_ELEM (par_elems
);
13104 enum machine_mode mode
;
13107 /* Create the first one, so we have something to add to. */
13108 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13109 VOIDmode
, initialized
);
13110 if (loc_result
== NULL
)
13112 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13113 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13114 for (i
= 1; i
< num_elem
; i
++)
13116 dw_loc_descr_ref temp
;
13118 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13119 VOIDmode
, initialized
);
13122 add_loc_descr (&loc_result
, temp
);
13123 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13124 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13130 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13131 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13136 if (mode
== VOIDmode
)
13137 mode
= GET_MODE (rtl
);
13139 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13141 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13143 /* Note that a CONST_DOUBLE rtx could represent either an integer
13144 or a floating-point constant. A CONST_DOUBLE is used whenever
13145 the constant requires more than one word in order to be
13146 adequately represented. We output CONST_DOUBLEs as blocks. */
13147 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13148 GET_MODE_SIZE (mode
), 0);
13149 if (SCALAR_FLOAT_MODE_P (mode
))
13151 unsigned int length
= GET_MODE_SIZE (mode
);
13152 unsigned char *array
13153 = (unsigned char*) ggc_alloc_atomic (length
);
13155 insert_float (rtl
, array
);
13156 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13157 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13158 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13159 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13163 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13164 loc_result
->dw_loc_oprnd2
.v
.val_double
13165 = rtx_to_double_int (rtl
);
13171 if (mode
== VOIDmode
)
13172 mode
= GET_MODE (rtl
);
13174 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13176 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13177 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13178 unsigned char *array
= (unsigned char *)
13179 ggc_alloc_atomic (length
* elt_size
);
13183 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13184 switch (GET_MODE_CLASS (mode
))
13186 case MODE_VECTOR_INT
:
13187 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13189 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13190 double_int val
= rtx_to_double_int (elt
);
13192 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13193 insert_int (val
.to_shwi (), elt_size
, p
);
13196 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13197 insert_double (val
, p
);
13202 case MODE_VECTOR_FLOAT
:
13203 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13205 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13206 insert_float (elt
, p
);
13211 gcc_unreachable ();
13214 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13215 length
* elt_size
, 0);
13216 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13217 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13218 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13219 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13224 if (mode
== VOIDmode
13225 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13226 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13227 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13229 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13234 if (!const_ok_for_output (rtl
))
13237 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13238 && (dwarf_version
>= 4 || !dwarf_strict
))
13240 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13241 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13242 vec_safe_push (used_rtx_array
, rtl
);
13246 case DEBUG_IMPLICIT_PTR
:
13247 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13251 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13252 && CONST_INT_P (XEXP (rtl
, 1)))
13255 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13261 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13262 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13263 && dwarf_version
>= 4)
13264 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13266 /* Value expression. */
13267 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13269 add_loc_descr (&loc_result
,
13270 new_loc_descr (DW_OP_stack_value
, 0, 0));
13278 /* We need to figure out what section we should use as the base for the
13279 address ranges where a given location is valid.
13280 1. If this particular DECL has a section associated with it, use that.
13281 2. If this function has a section associated with it, use that.
13282 3. Otherwise, use the text section.
13283 XXX: If you split a variable across multiple sections, we won't notice. */
13285 static const char *
13286 secname_for_decl (const_tree decl
)
13288 const char *secname
;
13290 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13292 tree sectree
= DECL_SECTION_NAME (decl
);
13293 secname
= TREE_STRING_POINTER (sectree
);
13295 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13297 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13298 secname
= TREE_STRING_POINTER (sectree
);
13300 else if (cfun
&& in_cold_section_p
)
13301 secname
= crtl
->subsections
.cold_section_label
;
13303 secname
= text_section_label
;
13308 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13311 decl_by_reference_p (tree decl
)
13313 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13314 || TREE_CODE (decl
) == VAR_DECL
)
13315 && DECL_BY_REFERENCE (decl
));
13318 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13321 static dw_loc_descr_ref
13322 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13323 enum var_init_status initialized
)
13325 int have_address
= 0;
13326 dw_loc_descr_ref descr
;
13327 enum machine_mode mode
;
13329 if (want_address
!= 2)
13331 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13333 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13335 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13336 if (GET_CODE (varloc
) == EXPR_LIST
)
13337 varloc
= XEXP (varloc
, 0);
13338 mode
= GET_MODE (varloc
);
13339 if (MEM_P (varloc
))
13341 rtx addr
= XEXP (varloc
, 0);
13342 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13343 mode
, initialized
);
13348 rtx x
= avoid_constant_pool_reference (varloc
);
13350 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13355 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13362 if (GET_CODE (varloc
) == VAR_LOCATION
)
13363 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13365 mode
= DECL_MODE (loc
);
13366 descr
= loc_descriptor (varloc
, mode
, initialized
);
13373 if (want_address
== 2 && !have_address
13374 && (dwarf_version
>= 4 || !dwarf_strict
))
13376 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13378 expansion_failed (loc
, NULL_RTX
,
13379 "DWARF address size mismatch");
13382 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13385 /* Show if we can't fill the request for an address. */
13386 if (want_address
&& !have_address
)
13388 expansion_failed (loc
, NULL_RTX
,
13389 "Want address and only have value");
13393 /* If we've got an address and don't want one, dereference. */
13394 if (!want_address
&& have_address
)
13396 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13397 enum dwarf_location_atom op
;
13399 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13401 expansion_failed (loc
, NULL_RTX
,
13402 "DWARF address size mismatch");
13405 else if (size
== DWARF2_ADDR_SIZE
)
13408 op
= DW_OP_deref_size
;
13410 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13416 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13417 if it is not possible. */
13419 static dw_loc_descr_ref
13420 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13422 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13423 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13424 else if (dwarf_version
>= 3 || !dwarf_strict
)
13425 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13430 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13431 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13433 static dw_loc_descr_ref
13434 dw_sra_loc_expr (tree decl
, rtx loc
)
13437 unsigned int padsize
= 0;
13438 dw_loc_descr_ref descr
, *descr_tail
;
13439 unsigned HOST_WIDE_INT decl_size
;
13441 enum var_init_status initialized
;
13443 if (DECL_SIZE (decl
) == NULL
13444 || !host_integerp (DECL_SIZE (decl
), 1))
13447 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13449 descr_tail
= &descr
;
13451 for (p
= loc
; p
; p
= XEXP (p
, 1))
13453 unsigned int bitsize
= decl_piece_bitsize (p
);
13454 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13455 dw_loc_descr_ref cur_descr
;
13456 dw_loc_descr_ref
*tail
, last
= NULL
;
13457 unsigned int opsize
= 0;
13459 if (loc_note
== NULL_RTX
13460 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13462 padsize
+= bitsize
;
13465 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13466 varloc
= NOTE_VAR_LOCATION (loc_note
);
13467 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13468 if (cur_descr
== NULL
)
13470 padsize
+= bitsize
;
13474 /* Check that cur_descr either doesn't use
13475 DW_OP_*piece operations, or their sum is equal
13476 to bitsize. Otherwise we can't embed it. */
13477 for (tail
= &cur_descr
; *tail
!= NULL
;
13478 tail
= &(*tail
)->dw_loc_next
)
13479 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13481 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13485 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13487 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13491 if (last
!= NULL
&& opsize
!= bitsize
)
13493 padsize
+= bitsize
;
13497 /* If there is a hole, add DW_OP_*piece after empty DWARF
13498 expression, which means that those bits are optimized out. */
13501 if (padsize
> decl_size
)
13503 decl_size
-= padsize
;
13504 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13505 if (*descr_tail
== NULL
)
13507 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13510 *descr_tail
= cur_descr
;
13512 if (bitsize
> decl_size
)
13514 decl_size
-= bitsize
;
13517 HOST_WIDE_INT offset
= 0;
13518 if (GET_CODE (varloc
) == VAR_LOCATION
13519 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13521 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13522 if (GET_CODE (varloc
) == EXPR_LIST
)
13523 varloc
= XEXP (varloc
, 0);
13527 if (GET_CODE (varloc
) == CONST
13528 || GET_CODE (varloc
) == SIGN_EXTEND
13529 || GET_CODE (varloc
) == ZERO_EXTEND
)
13530 varloc
= XEXP (varloc
, 0);
13531 else if (GET_CODE (varloc
) == SUBREG
)
13532 varloc
= SUBREG_REG (varloc
);
13537 /* DW_OP_bit_size offset should be zero for register
13538 or implicit location descriptions and empty location
13539 descriptions, but for memory addresses needs big endian
13541 if (MEM_P (varloc
))
13543 unsigned HOST_WIDE_INT memsize
13544 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13545 if (memsize
!= bitsize
)
13547 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13548 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13550 if (memsize
< bitsize
)
13552 if (BITS_BIG_ENDIAN
)
13553 offset
= memsize
- bitsize
;
13557 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13558 if (*descr_tail
== NULL
)
13560 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13564 /* If there were any non-empty expressions, add padding till the end of
13566 if (descr
!= NULL
&& decl_size
!= 0)
13568 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13569 if (*descr_tail
== NULL
)
13575 /* Return the dwarf representation of the location list LOC_LIST of
13576 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13579 static dw_loc_list_ref
13580 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13582 const char *endname
, *secname
;
13584 enum var_init_status initialized
;
13585 struct var_loc_node
*node
;
13586 dw_loc_descr_ref descr
;
13587 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13588 dw_loc_list_ref list
= NULL
;
13589 dw_loc_list_ref
*listp
= &list
;
13591 /* Now that we know what section we are using for a base,
13592 actually construct the list of locations.
13593 The first location information is what is passed to the
13594 function that creates the location list, and the remaining
13595 locations just get added on to that list.
13596 Note that we only know the start address for a location
13597 (IE location changes), so to build the range, we use
13598 the range [current location start, next location start].
13599 This means we have to special case the last node, and generate
13600 a range of [last location start, end of function label]. */
13602 secname
= secname_for_decl (decl
);
13604 for (node
= loc_list
->first
; node
; node
= node
->next
)
13605 if (GET_CODE (node
->loc
) == EXPR_LIST
13606 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13608 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13610 /* This requires DW_OP_{,bit_}piece, which is not usable
13611 inside DWARF expressions. */
13612 if (want_address
!= 2)
13614 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13620 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13621 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13622 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13626 bool range_across_switch
= false;
13627 /* If section switch happens in between node->label
13628 and node->next->label (or end of function) and
13629 we can't emit it as a single entry list,
13630 emit two ranges, first one ending at the end
13631 of first partition and second one starting at the
13632 beginning of second partition. */
13633 if (node
== loc_list
->last_before_switch
13634 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13635 && current_function_decl
)
13637 endname
= cfun
->fde
->dw_fde_end
;
13638 range_across_switch
= true;
13640 /* The variable has a location between NODE->LABEL and
13641 NODE->NEXT->LABEL. */
13642 else if (node
->next
)
13643 endname
= node
->next
->label
;
13644 /* If the variable has a location at the last label
13645 it keeps its location until the end of function. */
13646 else if (!current_function_decl
)
13647 endname
= text_end_label
;
13650 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13651 current_function_funcdef_no
);
13652 endname
= ggc_strdup (label_id
);
13655 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13656 if (TREE_CODE (decl
) == PARM_DECL
13657 && node
== loc_list
->first
13658 && NOTE_P (node
->loc
)
13659 && strcmp (node
->label
, endname
) == 0)
13660 (*listp
)->force
= true;
13661 listp
= &(*listp
)->dw_loc_next
;
13663 if (range_across_switch
)
13665 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13666 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13669 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13670 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13671 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13674 gcc_assert (descr
);
13675 /* The variable has a location between NODE->LABEL and
13676 NODE->NEXT->LABEL. */
13678 endname
= node
->next
->label
;
13680 endname
= cfun
->fde
->dw_fde_second_end
;
13681 *listp
= new_loc_list (descr
,
13682 cfun
->fde
->dw_fde_second_begin
,
13684 listp
= &(*listp
)->dw_loc_next
;
13689 /* Try to avoid the overhead of a location list emitting a location
13690 expression instead, but only if we didn't have more than one
13691 location entry in the first place. If some entries were not
13692 representable, we don't want to pretend a single entry that was
13693 applies to the entire scope in which the variable is
13695 if (list
&& loc_list
->first
->next
)
13701 /* Return if the loc_list has only single element and thus can be represented
13702 as location description. */
13705 single_element_loc_list_p (dw_loc_list_ref list
)
13707 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13708 return !list
->ll_symbol
;
13711 /* To each location in list LIST add loc descr REF. */
13714 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13716 dw_loc_descr_ref copy
;
13717 add_loc_descr (&list
->expr
, ref
);
13718 list
= list
->dw_loc_next
;
13721 copy
= ggc_alloc_dw_loc_descr_node ();
13722 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13723 add_loc_descr (&list
->expr
, copy
);
13724 while (copy
->dw_loc_next
)
13726 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13727 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13728 copy
->dw_loc_next
= new_copy
;
13731 list
= list
->dw_loc_next
;
13735 /* Given two lists RET and LIST
13736 produce location list that is result of adding expression in LIST
13737 to expression in RET on each position in program.
13738 Might be destructive on both RET and LIST.
13740 TODO: We handle only simple cases of RET or LIST having at most one
13741 element. General case would inolve sorting the lists in program order
13742 and merging them that will need some additional work.
13743 Adding that will improve quality of debug info especially for SRA-ed
13747 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13756 if (!list
->dw_loc_next
)
13758 add_loc_descr_to_each (*ret
, list
->expr
);
13761 if (!(*ret
)->dw_loc_next
)
13763 add_loc_descr_to_each (list
, (*ret
)->expr
);
13767 expansion_failed (NULL_TREE
, NULL_RTX
,
13768 "Don't know how to merge two non-trivial"
13769 " location lists.\n");
13774 /* LOC is constant expression. Try a luck, look it up in constant
13775 pool and return its loc_descr of its address. */
13777 static dw_loc_descr_ref
13778 cst_pool_loc_descr (tree loc
)
13780 /* Get an RTL for this, if something has been emitted. */
13781 rtx rtl
= lookup_constant_def (loc
);
13783 if (!rtl
|| !MEM_P (rtl
))
13788 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13790 /* TODO: We might get more coverage if we was actually delaying expansion
13791 of all expressions till end of compilation when constant pools are fully
13793 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13795 expansion_failed (loc
, NULL_RTX
,
13796 "CST value in contant pool but not marked.");
13799 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13800 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13803 /* Return dw_loc_list representing address of addr_expr LOC
13804 by looking for inner INDIRECT_REF expression and turning
13805 it into simple arithmetics. */
13807 static dw_loc_list_ref
13808 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13811 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13812 enum machine_mode mode
;
13813 int unsignedp
, volatilep
= 0;
13814 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13816 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13817 &bitsize
, &bitpos
, &offset
, &mode
,
13818 &unsignedp
, &volatilep
, false);
13820 if (bitpos
% BITS_PER_UNIT
)
13822 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13825 if (!INDIRECT_REF_P (obj
))
13827 expansion_failed (obj
,
13828 NULL_RTX
, "no indirect ref in inner refrence");
13831 if (!offset
&& !bitpos
)
13832 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13834 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13835 && (dwarf_version
>= 4 || !dwarf_strict
))
13837 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13842 /* Variable offset. */
13843 list_ret1
= loc_list_from_tree (offset
, 0);
13844 if (list_ret1
== 0)
13846 add_loc_list (&list_ret
, list_ret1
);
13849 add_loc_descr_to_each (list_ret
,
13850 new_loc_descr (DW_OP_plus
, 0, 0));
13852 bytepos
= bitpos
/ BITS_PER_UNIT
;
13854 add_loc_descr_to_each (list_ret
,
13855 new_loc_descr (DW_OP_plus_uconst
,
13857 else if (bytepos
< 0)
13858 loc_list_plus_const (list_ret
, bytepos
);
13859 add_loc_descr_to_each (list_ret
,
13860 new_loc_descr (DW_OP_stack_value
, 0, 0));
13866 /* Generate Dwarf location list representing LOC.
13867 If WANT_ADDRESS is false, expression computing LOC will be computed
13868 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13869 if WANT_ADDRESS is 2, expression computing address useable in location
13870 will be returned (i.e. DW_OP_reg can be used
13871 to refer to register values). */
13873 static dw_loc_list_ref
13874 loc_list_from_tree (tree loc
, int want_address
)
13876 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13877 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13878 int have_address
= 0;
13879 enum dwarf_location_atom op
;
13881 /* ??? Most of the time we do not take proper care for sign/zero
13882 extending the values properly. Hopefully this won't be a real
13885 switch (TREE_CODE (loc
))
13888 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13891 case PLACEHOLDER_EXPR
:
13892 /* This case involves extracting fields from an object to determine the
13893 position of other fields. We don't try to encode this here. The
13894 only user of this is Ada, which encodes the needed information using
13895 the names of types. */
13896 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13900 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13901 /* There are no opcodes for these operations. */
13904 case PREINCREMENT_EXPR
:
13905 case PREDECREMENT_EXPR
:
13906 case POSTINCREMENT_EXPR
:
13907 case POSTDECREMENT_EXPR
:
13908 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13909 /* There are no opcodes for these operations. */
13913 /* If we already want an address, see if there is INDIRECT_REF inside
13914 e.g. for &this->field. */
13917 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13918 (loc
, want_address
== 2);
13921 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13922 && (ret
= cst_pool_loc_descr (loc
)))
13925 /* Otherwise, process the argument and look for the address. */
13926 if (!list_ret
&& !ret
)
13927 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13931 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13937 if (DECL_THREAD_LOCAL_P (loc
))
13940 enum dwarf_location_atom tls_op
;
13941 enum dtprel_bool dtprel
= dtprel_false
;
13943 if (targetm
.have_tls
)
13945 /* If this is not defined, we have no way to emit the
13947 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13950 /* The way DW_OP_GNU_push_tls_address is specified, we
13951 can only look up addresses of objects in the current
13952 module. We used DW_OP_addr as first op, but that's
13953 wrong, because DW_OP_addr is relocated by the debug
13954 info consumer, while DW_OP_GNU_push_tls_address
13955 operand shouldn't be. */
13956 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13958 dtprel
= dtprel_true
;
13959 tls_op
= DW_OP_GNU_push_tls_address
;
13963 if (!targetm
.emutls
.debug_form_tls_address
13964 || !(dwarf_version
>= 3 || !dwarf_strict
))
13966 /* We stuffed the control variable into the DECL_VALUE_EXPR
13967 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13968 no longer appear in gimple code. We used the control
13969 variable in specific so that we could pick it up here. */
13970 loc
= DECL_VALUE_EXPR (loc
);
13971 tls_op
= DW_OP_form_tls_address
;
13974 rtl
= rtl_for_decl_location (loc
);
13975 if (rtl
== NULL_RTX
)
13980 rtl
= XEXP (rtl
, 0);
13981 if (! CONSTANT_P (rtl
))
13984 ret
= new_addr_loc_descr (rtl
, dtprel
);
13985 ret1
= new_loc_descr (tls_op
, 0, 0);
13986 add_loc_descr (&ret
, ret1
);
13995 if (DECL_HAS_VALUE_EXPR_P (loc
))
13996 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14000 case FUNCTION_DECL
:
14003 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14005 if (loc_list
&& loc_list
->first
)
14007 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14008 have_address
= want_address
!= 0;
14011 rtl
= rtl_for_decl_location (loc
);
14012 if (rtl
== NULL_RTX
)
14014 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14017 else if (CONST_INT_P (rtl
))
14019 HOST_WIDE_INT val
= INTVAL (rtl
);
14020 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14021 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14022 ret
= int_loc_descriptor (val
);
14024 else if (GET_CODE (rtl
) == CONST_STRING
)
14026 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14029 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14030 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14033 enum machine_mode mode
, mem_mode
;
14035 /* Certain constructs can only be represented at top-level. */
14036 if (want_address
== 2)
14038 ret
= loc_descriptor (rtl
, VOIDmode
,
14039 VAR_INIT_STATUS_INITIALIZED
);
14044 mode
= GET_MODE (rtl
);
14045 mem_mode
= VOIDmode
;
14049 mode
= get_address_mode (rtl
);
14050 rtl
= XEXP (rtl
, 0);
14053 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14054 VAR_INIT_STATUS_INITIALIZED
);
14057 expansion_failed (loc
, rtl
,
14058 "failed to produce loc descriptor for rtl");
14065 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14069 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14073 case COMPOUND_EXPR
:
14074 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14077 case VIEW_CONVERT_EXPR
:
14080 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14082 case COMPONENT_REF
:
14083 case BIT_FIELD_REF
:
14085 case ARRAY_RANGE_REF
:
14086 case REALPART_EXPR
:
14087 case IMAGPART_EXPR
:
14090 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14091 enum machine_mode mode
;
14092 int unsignedp
, volatilep
= 0;
14094 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14095 &unsignedp
, &volatilep
, false);
14097 gcc_assert (obj
!= loc
);
14099 list_ret
= loc_list_from_tree (obj
,
14101 && !bitpos
&& !offset
? 2 : 1);
14102 /* TODO: We can extract value of the small expression via shifting even
14103 for nonzero bitpos. */
14106 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14108 expansion_failed (loc
, NULL_RTX
,
14109 "bitfield access");
14113 if (offset
!= NULL_TREE
)
14115 /* Variable offset. */
14116 list_ret1
= loc_list_from_tree (offset
, 0);
14117 if (list_ret1
== 0)
14119 add_loc_list (&list_ret
, list_ret1
);
14122 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14125 bytepos
= bitpos
/ BITS_PER_UNIT
;
14127 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14128 else if (bytepos
< 0)
14129 loc_list_plus_const (list_ret
, bytepos
);
14136 if ((want_address
|| !host_integerp (loc
, 0))
14137 && (ret
= cst_pool_loc_descr (loc
)))
14139 else if (want_address
== 2
14140 && host_integerp (loc
, 0)
14141 && (ret
= address_of_int_loc_descriptor
14142 (int_size_in_bytes (TREE_TYPE (loc
)),
14143 tree_low_cst (loc
, 0))))
14145 else if (host_integerp (loc
, 0))
14146 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
14149 expansion_failed (loc
, NULL_RTX
,
14150 "Integer operand is not host integer");
14159 if ((ret
= cst_pool_loc_descr (loc
)))
14162 /* We can construct small constants here using int_loc_descriptor. */
14163 expansion_failed (loc
, NULL_RTX
,
14164 "constructor or constant not in constant pool");
14167 case TRUTH_AND_EXPR
:
14168 case TRUTH_ANDIF_EXPR
:
14173 case TRUTH_XOR_EXPR
:
14178 case TRUTH_OR_EXPR
:
14179 case TRUTH_ORIF_EXPR
:
14184 case FLOOR_DIV_EXPR
:
14185 case CEIL_DIV_EXPR
:
14186 case ROUND_DIV_EXPR
:
14187 case TRUNC_DIV_EXPR
:
14188 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14197 case FLOOR_MOD_EXPR
:
14198 case CEIL_MOD_EXPR
:
14199 case ROUND_MOD_EXPR
:
14200 case TRUNC_MOD_EXPR
:
14201 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14206 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14207 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14208 if (list_ret
== 0 || list_ret1
== 0)
14211 add_loc_list (&list_ret
, list_ret1
);
14214 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14215 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14216 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14217 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14218 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14230 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14233 case POINTER_PLUS_EXPR
:
14235 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14237 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14241 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14249 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14256 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14263 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14270 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14285 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14286 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14287 if (list_ret
== 0 || list_ret1
== 0)
14290 add_loc_list (&list_ret
, list_ret1
);
14293 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14296 case TRUTH_NOT_EXPR
:
14310 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14314 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14320 const enum tree_code code
=
14321 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14323 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14324 build2 (code
, integer_type_node
,
14325 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14326 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14329 /* ... fall through ... */
14333 dw_loc_descr_ref lhs
14334 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14335 dw_loc_list_ref rhs
14336 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14337 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14339 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14340 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14343 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14344 add_loc_descr_to_each (list_ret
, bra_node
);
14346 add_loc_list (&list_ret
, rhs
);
14347 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14348 add_loc_descr_to_each (list_ret
, jump_node
);
14350 add_loc_descr_to_each (list_ret
, lhs
);
14351 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14352 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14354 /* ??? Need a node to point the skip at. Use a nop. */
14355 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14356 add_loc_descr_to_each (list_ret
, tmp
);
14357 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14358 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14362 case FIX_TRUNC_EXPR
:
14366 /* Leave front-end specific codes as simply unknown. This comes
14367 up, for instance, with the C STMT_EXPR. */
14368 if ((unsigned int) TREE_CODE (loc
)
14369 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14371 expansion_failed (loc
, NULL_RTX
,
14372 "language specific tree node");
14376 #ifdef ENABLE_CHECKING
14377 /* Otherwise this is a generic code; we should just lists all of
14378 these explicitly. We forgot one. */
14379 gcc_unreachable ();
14381 /* In a release build, we want to degrade gracefully: better to
14382 generate incomplete debugging information than to crash. */
14387 if (!ret
&& !list_ret
)
14390 if (want_address
== 2 && !have_address
14391 && (dwarf_version
>= 4 || !dwarf_strict
))
14393 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14395 expansion_failed (loc
, NULL_RTX
,
14396 "DWARF address size mismatch");
14400 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14402 add_loc_descr_to_each (list_ret
,
14403 new_loc_descr (DW_OP_stack_value
, 0, 0));
14406 /* Show if we can't fill the request for an address. */
14407 if (want_address
&& !have_address
)
14409 expansion_failed (loc
, NULL_RTX
,
14410 "Want address and only have value");
14414 gcc_assert (!ret
|| !list_ret
);
14416 /* If we've got an address and don't want one, dereference. */
14417 if (!want_address
&& have_address
)
14419 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14421 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14423 expansion_failed (loc
, NULL_RTX
,
14424 "DWARF address size mismatch");
14427 else if (size
== DWARF2_ADDR_SIZE
)
14430 op
= DW_OP_deref_size
;
14433 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14435 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14438 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14443 /* Same as above but return only single location expression. */
14444 static dw_loc_descr_ref
14445 loc_descriptor_from_tree (tree loc
, int want_address
)
14447 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14450 if (ret
->dw_loc_next
)
14452 expansion_failed (loc
, NULL_RTX
,
14453 "Location list where only loc descriptor needed");
14459 /* Given a value, round it up to the lowest multiple of `boundary'
14460 which is not less than the value itself. */
14462 static inline HOST_WIDE_INT
14463 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14465 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14468 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14469 pointer to the declared type for the relevant field variable, or return
14470 `integer_type_node' if the given node turns out to be an
14471 ERROR_MARK node. */
14474 field_type (const_tree decl
)
14478 if (TREE_CODE (decl
) == ERROR_MARK
)
14479 return integer_type_node
;
14481 type
= DECL_BIT_FIELD_TYPE (decl
);
14482 if (type
== NULL_TREE
)
14483 type
= TREE_TYPE (decl
);
14488 /* Given a pointer to a tree node, return the alignment in bits for
14489 it, or else return BITS_PER_WORD if the node actually turns out to
14490 be an ERROR_MARK node. */
14492 static inline unsigned
14493 simple_type_align_in_bits (const_tree type
)
14495 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14498 static inline unsigned
14499 simple_decl_align_in_bits (const_tree decl
)
14501 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14504 /* Return the result of rounding T up to ALIGN. */
14506 static inline double_int
14507 round_up_to_align (double_int t
, unsigned int align
)
14509 double_int alignd
= double_int::from_uhwi (align
);
14511 t
+= double_int_minus_one
;
14512 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14517 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14518 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14519 or return 0 if we are unable to determine what that offset is, either
14520 because the argument turns out to be a pointer to an ERROR_MARK node, or
14521 because the offset is actually variable. (We can't handle the latter case
14524 static HOST_WIDE_INT
14525 field_byte_offset (const_tree decl
)
14527 double_int object_offset_in_bits
;
14528 double_int object_offset_in_bytes
;
14529 double_int bitpos_int
;
14531 if (TREE_CODE (decl
) == ERROR_MARK
)
14534 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14536 /* We cannot yet cope with fields whose positions are variable, so
14537 for now, when we see such things, we simply return 0. Someday, we may
14538 be able to handle such cases, but it will be damn difficult. */
14539 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14542 bitpos_int
= tree_to_double_int (bit_position (decl
));
14544 #ifdef PCC_BITFIELD_TYPE_MATTERS
14545 if (PCC_BITFIELD_TYPE_MATTERS
)
14548 tree field_size_tree
;
14549 double_int deepest_bitpos
;
14550 double_int field_size_in_bits
;
14551 unsigned int type_align_in_bits
;
14552 unsigned int decl_align_in_bits
;
14553 double_int type_size_in_bits
;
14555 type
= field_type (decl
);
14556 type_size_in_bits
= double_int_type_size_in_bits (type
);
14557 type_align_in_bits
= simple_type_align_in_bits (type
);
14559 field_size_tree
= DECL_SIZE (decl
);
14561 /* The size could be unspecified if there was an error, or for
14562 a flexible array member. */
14563 if (!field_size_tree
)
14564 field_size_tree
= bitsize_zero_node
;
14566 /* If the size of the field is not constant, use the type size. */
14567 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14568 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14570 field_size_in_bits
= type_size_in_bits
;
14572 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14574 /* The GCC front-end doesn't make any attempt to keep track of the
14575 starting bit offset (relative to the start of the containing
14576 structure type) of the hypothetical "containing object" for a
14577 bit-field. Thus, when computing the byte offset value for the
14578 start of the "containing object" of a bit-field, we must deduce
14579 this information on our own. This can be rather tricky to do in
14580 some cases. For example, handling the following structure type
14581 definition when compiling for an i386/i486 target (which only
14582 aligns long long's to 32-bit boundaries) can be very tricky:
14584 struct S { int field1; long long field2:31; };
14586 Fortunately, there is a simple rule-of-thumb which can be used
14587 in such cases. When compiling for an i386/i486, GCC will
14588 allocate 8 bytes for the structure shown above. It decides to
14589 do this based upon one simple rule for bit-field allocation.
14590 GCC allocates each "containing object" for each bit-field at
14591 the first (i.e. lowest addressed) legitimate alignment boundary
14592 (based upon the required minimum alignment for the declared
14593 type of the field) which it can possibly use, subject to the
14594 condition that there is still enough available space remaining
14595 in the containing object (when allocated at the selected point)
14596 to fully accommodate all of the bits of the bit-field itself.
14598 This simple rule makes it obvious why GCC allocates 8 bytes for
14599 each object of the structure type shown above. When looking
14600 for a place to allocate the "containing object" for `field2',
14601 the compiler simply tries to allocate a 64-bit "containing
14602 object" at each successive 32-bit boundary (starting at zero)
14603 until it finds a place to allocate that 64- bit field such that
14604 at least 31 contiguous (and previously unallocated) bits remain
14605 within that selected 64 bit field. (As it turns out, for the
14606 example above, the compiler finds it is OK to allocate the
14607 "containing object" 64-bit field at bit-offset zero within the
14610 Here we attempt to work backwards from the limited set of facts
14611 we're given, and we try to deduce from those facts, where GCC
14612 must have believed that the containing object started (within
14613 the structure type). The value we deduce is then used (by the
14614 callers of this routine) to generate DW_AT_location and
14615 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14616 the case of DW_AT_location, regular fields as well). */
14618 /* Figure out the bit-distance from the start of the structure to
14619 the "deepest" bit of the bit-field. */
14620 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14622 /* This is the tricky part. Use some fancy footwork to deduce
14623 where the lowest addressed bit of the containing object must
14625 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14627 /* Round up to type_align by default. This works best for
14629 object_offset_in_bits
14630 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14632 if (object_offset_in_bits
.ugt (bitpos_int
))
14634 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14636 /* Round up to decl_align instead. */
14637 object_offset_in_bits
14638 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14642 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14643 object_offset_in_bits
= bitpos_int
;
14645 object_offset_in_bytes
14646 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14647 true, TRUNC_DIV_EXPR
);
14648 return object_offset_in_bytes
.to_shwi ();
14651 /* The following routines define various Dwarf attributes and any data
14652 associated with them. */
14654 /* Add a location description attribute value to a DIE.
14656 This emits location attributes suitable for whole variables and
14657 whole parameters. Note that the location attributes for struct fields are
14658 generated by the routine `data_member_location_attribute' below. */
14661 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14662 dw_loc_list_ref descr
)
14666 if (single_element_loc_list_p (descr
))
14667 add_AT_loc (die
, attr_kind
, descr
->expr
);
14669 add_AT_loc_list (die
, attr_kind
, descr
);
14672 /* Add DW_AT_accessibility attribute to DIE if needed. */
14675 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14677 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14678 children, otherwise the default is DW_ACCESS_public. In DWARF2
14679 the default has always been DW_ACCESS_public. */
14680 if (TREE_PROTECTED (decl
))
14681 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14682 else if (TREE_PRIVATE (decl
))
14684 if (dwarf_version
== 2
14685 || die
->die_parent
== NULL
14686 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14687 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14689 else if (dwarf_version
> 2
14691 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14692 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14695 /* Attach the specialized form of location attribute used for data members of
14696 struct and union types. In the special case of a FIELD_DECL node which
14697 represents a bit-field, the "offset" part of this special location
14698 descriptor must indicate the distance in bytes from the lowest-addressed
14699 byte of the containing struct or union type to the lowest-addressed byte of
14700 the "containing object" for the bit-field. (See the `field_byte_offset'
14703 For any given bit-field, the "containing object" is a hypothetical object
14704 (of some integral or enum type) within which the given bit-field lives. The
14705 type of this hypothetical "containing object" is always the same as the
14706 declared type of the individual bit-field itself (for GCC anyway... the
14707 DWARF spec doesn't actually mandate this). Note that it is the size (in
14708 bytes) of the hypothetical "containing object" which will be given in the
14709 DW_AT_byte_size attribute for this bit-field. (See the
14710 `byte_size_attribute' function below.) It is also used when calculating the
14711 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14712 function below.) */
14715 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14717 HOST_WIDE_INT offset
;
14718 dw_loc_descr_ref loc_descr
= 0;
14720 if (TREE_CODE (decl
) == TREE_BINFO
)
14722 /* We're working on the TAG_inheritance for a base class. */
14723 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14725 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14726 aren't at a fixed offset from all (sub)objects of the same
14727 type. We need to extract the appropriate offset from our
14728 vtable. The following dwarf expression means
14730 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14732 This is specific to the V3 ABI, of course. */
14734 dw_loc_descr_ref tmp
;
14736 /* Make a copy of the object address. */
14737 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14738 add_loc_descr (&loc_descr
, tmp
);
14740 /* Extract the vtable address. */
14741 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14742 add_loc_descr (&loc_descr
, tmp
);
14744 /* Calculate the address of the offset. */
14745 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14746 gcc_assert (offset
< 0);
14748 tmp
= int_loc_descriptor (-offset
);
14749 add_loc_descr (&loc_descr
, tmp
);
14750 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14751 add_loc_descr (&loc_descr
, tmp
);
14753 /* Extract the offset. */
14754 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14755 add_loc_descr (&loc_descr
, tmp
);
14757 /* Add it to the object address. */
14758 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14759 add_loc_descr (&loc_descr
, tmp
);
14762 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14765 offset
= field_byte_offset (decl
);
14769 if (dwarf_version
> 2)
14771 /* Don't need to output a location expression, just the constant. */
14773 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14775 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14780 enum dwarf_location_atom op
;
14782 /* The DWARF2 standard says that we should assume that the structure
14783 address is already on the stack, so we can specify a structure
14784 field address by using DW_OP_plus_uconst. */
14785 op
= DW_OP_plus_uconst
;
14786 loc_descr
= new_loc_descr (op
, offset
, 0);
14790 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14793 /* Writes integer values to dw_vec_const array. */
14796 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14800 *dest
++ = val
& 0xff;
14806 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14808 static HOST_WIDE_INT
14809 extract_int (const unsigned char *src
, unsigned int size
)
14811 HOST_WIDE_INT val
= 0;
14817 val
|= *--src
& 0xff;
14823 /* Writes double_int values to dw_vec_const array. */
14826 insert_double (double_int val
, unsigned char *dest
)
14828 unsigned char *p0
= dest
;
14829 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14831 if (WORDS_BIG_ENDIAN
)
14837 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14838 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14841 /* Writes floating point values to dw_vec_const array. */
14844 insert_float (const_rtx rtl
, unsigned char *array
)
14846 REAL_VALUE_TYPE rv
;
14850 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14851 real_to_target (val
, &rv
, GET_MODE (rtl
));
14853 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14854 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14856 insert_int (val
[i
], 4, array
);
14861 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14862 does not have a "location" either in memory or in a register. These
14863 things can arise in GNU C when a constant is passed as an actual parameter
14864 to an inlined function. They can also arise in C++ where declared
14865 constants do not necessarily get memory "homes". */
14868 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14870 switch (GET_CODE (rtl
))
14874 HOST_WIDE_INT val
= INTVAL (rtl
);
14877 add_AT_int (die
, DW_AT_const_value
, val
);
14879 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14884 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14885 floating-point constant. A CONST_DOUBLE is used whenever the
14886 constant requires more than one word in order to be adequately
14889 enum machine_mode mode
= GET_MODE (rtl
);
14891 if (SCALAR_FLOAT_MODE_P (mode
))
14893 unsigned int length
= GET_MODE_SIZE (mode
);
14894 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14896 insert_float (rtl
, array
);
14897 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14900 add_AT_double (die
, DW_AT_const_value
,
14901 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14907 enum machine_mode mode
= GET_MODE (rtl
);
14908 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14909 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14910 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14911 (length
* elt_size
);
14915 switch (GET_MODE_CLASS (mode
))
14917 case MODE_VECTOR_INT
:
14918 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14920 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14921 double_int val
= rtx_to_double_int (elt
);
14923 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14924 insert_int (val
.to_shwi (), elt_size
, p
);
14927 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14928 insert_double (val
, p
);
14933 case MODE_VECTOR_FLOAT
:
14934 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14936 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14937 insert_float (elt
, p
);
14942 gcc_unreachable ();
14945 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14950 if (dwarf_version
>= 4 || !dwarf_strict
)
14952 dw_loc_descr_ref loc_result
;
14953 resolve_one_addr (&rtl
, NULL
);
14955 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14956 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14957 add_AT_loc (die
, DW_AT_location
, loc_result
);
14958 vec_safe_push (used_rtx_array
, rtl
);
14964 if (CONSTANT_P (XEXP (rtl
, 0)))
14965 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14968 if (!const_ok_for_output (rtl
))
14971 if (dwarf_version
>= 4 || !dwarf_strict
)
14976 /* In cases where an inlined instance of an inline function is passed
14977 the address of an `auto' variable (which is local to the caller) we
14978 can get a situation where the DECL_RTL of the artificial local
14979 variable (for the inlining) which acts as a stand-in for the
14980 corresponding formal parameter (of the inline function) will look
14981 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14982 exactly a compile-time constant expression, but it isn't the address
14983 of the (artificial) local variable either. Rather, it represents the
14984 *value* which the artificial local variable always has during its
14985 lifetime. We currently have no way to represent such quasi-constant
14986 values in Dwarf, so for now we just punt and generate nothing. */
14994 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14995 && MEM_READONLY_P (rtl
)
14996 && GET_MODE (rtl
) == BLKmode
)
14998 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15004 /* No other kinds of rtx should be possible here. */
15005 gcc_unreachable ();
15010 /* Determine whether the evaluation of EXPR references any variables
15011 or functions which aren't otherwise used (and therefore may not be
15014 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15015 void * data ATTRIBUTE_UNUSED
)
15017 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15018 *walk_subtrees
= 0;
15020 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15021 && ! TREE_ASM_WRITTEN (*tp
))
15023 /* ??? The C++ FE emits debug information for using decls, so
15024 putting gcc_unreachable here falls over. See PR31899. For now
15025 be conservative. */
15026 else if (!cgraph_global_info_ready
15027 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15029 else if (TREE_CODE (*tp
) == VAR_DECL
)
15031 struct varpool_node
*node
= varpool_get_node (*tp
);
15032 if (!node
|| !node
->symbol
.definition
)
15035 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15036 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15038 /* The call graph machinery must have finished analyzing,
15039 optimizing and gimplifying the CU by now.
15040 So if *TP has no call graph node associated
15041 to it, it means *TP will not be emitted. */
15042 if (!cgraph_get_node (*tp
))
15045 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15051 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15052 for use in a later add_const_value_attribute call. */
15055 rtl_for_decl_init (tree init
, tree type
)
15057 rtx rtl
= NULL_RTX
;
15061 /* If a variable is initialized with a string constant without embedded
15062 zeros, build CONST_STRING. */
15063 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15065 tree enttype
= TREE_TYPE (type
);
15066 tree domain
= TYPE_DOMAIN (type
);
15067 enum machine_mode mode
= TYPE_MODE (enttype
);
15069 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15071 && integer_zerop (TYPE_MIN_VALUE (domain
))
15072 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15073 TREE_STRING_LENGTH (init
) - 1) == 0
15074 && ((size_t) TREE_STRING_LENGTH (init
)
15075 == strlen (TREE_STRING_POINTER (init
)) + 1))
15077 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15078 ggc_strdup (TREE_STRING_POINTER (init
)));
15079 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15080 MEM_READONLY_P (rtl
) = 1;
15083 /* Other aggregates, and complex values, could be represented using
15085 else if (AGGREGATE_TYPE_P (type
)
15086 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15087 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15088 || TREE_CODE (type
) == COMPLEX_TYPE
)
15090 /* Vectors only work if their mode is supported by the target.
15091 FIXME: generic vectors ought to work too. */
15092 else if (TREE_CODE (type
) == VECTOR_TYPE
15093 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15095 /* If the initializer is something that we know will expand into an
15096 immediate RTL constant, expand it now. We must be careful not to
15097 reference variables which won't be output. */
15098 else if (initializer_constant_valid_p (init
, type
)
15099 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15101 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15103 if (TREE_CODE (type
) == VECTOR_TYPE
)
15104 switch (TREE_CODE (init
))
15109 if (TREE_CONSTANT (init
))
15111 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15112 bool constant_p
= true;
15114 unsigned HOST_WIDE_INT ix
;
15116 /* Even when ctor is constant, it might contain non-*_CST
15117 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15118 belong into VECTOR_CST nodes. */
15119 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15120 if (!CONSTANT_CLASS_P (value
))
15122 constant_p
= false;
15128 init
= build_vector_from_ctor (type
, elts
);
15138 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15140 /* If expand_expr returns a MEM, it wasn't immediate. */
15141 gcc_assert (!rtl
|| !MEM_P (rtl
));
15147 /* Generate RTL for the variable DECL to represent its location. */
15150 rtl_for_decl_location (tree decl
)
15154 /* Here we have to decide where we are going to say the parameter "lives"
15155 (as far as the debugger is concerned). We only have a couple of
15156 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15158 DECL_RTL normally indicates where the parameter lives during most of the
15159 activation of the function. If optimization is enabled however, this
15160 could be either NULL or else a pseudo-reg. Both of those cases indicate
15161 that the parameter doesn't really live anywhere (as far as the code
15162 generation parts of GCC are concerned) during most of the function's
15163 activation. That will happen (for example) if the parameter is never
15164 referenced within the function.
15166 We could just generate a location descriptor here for all non-NULL
15167 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15168 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15169 where DECL_RTL is NULL or is a pseudo-reg.
15171 Note however that we can only get away with using DECL_INCOMING_RTL as
15172 a backup substitute for DECL_RTL in certain limited cases. In cases
15173 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15174 we can be sure that the parameter was passed using the same type as it is
15175 declared to have within the function, and that its DECL_INCOMING_RTL
15176 points us to a place where a value of that type is passed.
15178 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15179 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15180 because in these cases DECL_INCOMING_RTL points us to a value of some
15181 type which is *different* from the type of the parameter itself. Thus,
15182 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15183 such cases, the debugger would end up (for example) trying to fetch a
15184 `float' from a place which actually contains the first part of a
15185 `double'. That would lead to really incorrect and confusing
15186 output at debug-time.
15188 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15189 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15190 are a couple of exceptions however. On little-endian machines we can
15191 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15192 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15193 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15194 when (on a little-endian machine) a non-prototyped function has a
15195 parameter declared to be of type `short' or `char'. In such cases,
15196 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15197 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15198 passed `int' value. If the debugger then uses that address to fetch
15199 a `short' or a `char' (on a little-endian machine) the result will be
15200 the correct data, so we allow for such exceptional cases below.
15202 Note that our goal here is to describe the place where the given formal
15203 parameter lives during most of the function's activation (i.e. between the
15204 end of the prologue and the start of the epilogue). We'll do that as best
15205 as we can. Note however that if the given formal parameter is modified
15206 sometime during the execution of the function, then a stack backtrace (at
15207 debug-time) will show the function as having been called with the *new*
15208 value rather than the value which was originally passed in. This happens
15209 rarely enough that it is not a major problem, but it *is* a problem, and
15210 I'd like to fix it.
15212 A future version of dwarf2out.c may generate two additional attributes for
15213 any given DW_TAG_formal_parameter DIE which will describe the "passed
15214 type" and the "passed location" for the given formal parameter in addition
15215 to the attributes we now generate to indicate the "declared type" and the
15216 "active location" for each parameter. This additional set of attributes
15217 could be used by debuggers for stack backtraces. Separately, note that
15218 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15219 This happens (for example) for inlined-instances of inline function formal
15220 parameters which are never referenced. This really shouldn't be
15221 happening. All PARM_DECL nodes should get valid non-NULL
15222 DECL_INCOMING_RTL values. FIXME. */
15224 /* Use DECL_RTL as the "location" unless we find something better. */
15225 rtl
= DECL_RTL_IF_SET (decl
);
15227 /* When generating abstract instances, ignore everything except
15228 constants, symbols living in memory, and symbols living in
15229 fixed registers. */
15230 if (! reload_completed
)
15233 && (CONSTANT_P (rtl
)
15235 && CONSTANT_P (XEXP (rtl
, 0)))
15237 && TREE_CODE (decl
) == VAR_DECL
15238 && TREE_STATIC (decl
))))
15240 rtl
= targetm
.delegitimize_address (rtl
);
15245 else if (TREE_CODE (decl
) == PARM_DECL
)
15247 if (rtl
== NULL_RTX
15248 || is_pseudo_reg (rtl
)
15250 && is_pseudo_reg (XEXP (rtl
, 0))
15251 && DECL_INCOMING_RTL (decl
)
15252 && MEM_P (DECL_INCOMING_RTL (decl
))
15253 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15255 tree declared_type
= TREE_TYPE (decl
);
15256 tree passed_type
= DECL_ARG_TYPE (decl
);
15257 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15258 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15260 /* This decl represents a formal parameter which was optimized out.
15261 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15262 all cases where (rtl == NULL_RTX) just below. */
15263 if (dmode
== pmode
)
15264 rtl
= DECL_INCOMING_RTL (decl
);
15265 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15266 && SCALAR_INT_MODE_P (dmode
)
15267 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15268 && DECL_INCOMING_RTL (decl
))
15270 rtx inc
= DECL_INCOMING_RTL (decl
);
15273 else if (MEM_P (inc
))
15275 if (BYTES_BIG_ENDIAN
)
15276 rtl
= adjust_address_nv (inc
, dmode
,
15277 GET_MODE_SIZE (pmode
)
15278 - GET_MODE_SIZE (dmode
));
15285 /* If the parm was passed in registers, but lives on the stack, then
15286 make a big endian correction if the mode of the type of the
15287 parameter is not the same as the mode of the rtl. */
15288 /* ??? This is the same series of checks that are made in dbxout.c before
15289 we reach the big endian correction code there. It isn't clear if all
15290 of these checks are necessary here, but keeping them all is the safe
15292 else if (MEM_P (rtl
)
15293 && XEXP (rtl
, 0) != const0_rtx
15294 && ! CONSTANT_P (XEXP (rtl
, 0))
15295 /* Not passed in memory. */
15296 && !MEM_P (DECL_INCOMING_RTL (decl
))
15297 /* Not passed by invisible reference. */
15298 && (!REG_P (XEXP (rtl
, 0))
15299 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15300 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15301 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15302 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15305 /* Big endian correction check. */
15306 && BYTES_BIG_ENDIAN
15307 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15308 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15311 enum machine_mode addr_mode
= get_address_mode (rtl
);
15312 int offset
= (UNITS_PER_WORD
15313 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15315 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15316 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15319 else if (TREE_CODE (decl
) == VAR_DECL
15322 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15323 && BYTES_BIG_ENDIAN
)
15325 enum machine_mode addr_mode
= get_address_mode (rtl
);
15326 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15327 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15329 /* If a variable is declared "register" yet is smaller than
15330 a register, then if we store the variable to memory, it
15331 looks like we're storing a register-sized value, when in
15332 fact we are not. We need to adjust the offset of the
15333 storage location to reflect the actual value's bytes,
15334 else gdb will not be able to display it. */
15336 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15337 plus_constant (addr_mode
, XEXP (rtl
, 0),
15341 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15342 and will have been substituted directly into all expressions that use it.
15343 C does not have such a concept, but C++ and other languages do. */
15344 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15345 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15348 rtl
= targetm
.delegitimize_address (rtl
);
15350 /* If we don't look past the constant pool, we risk emitting a
15351 reference to a constant pool entry that isn't referenced from
15352 code, and thus is not emitted. */
15354 rtl
= avoid_constant_pool_reference (rtl
);
15356 /* Try harder to get a rtl. If this symbol ends up not being emitted
15357 in the current CU, resolve_addr will remove the expression referencing
15359 if (rtl
== NULL_RTX
15360 && TREE_CODE (decl
) == VAR_DECL
15361 && !DECL_EXTERNAL (decl
)
15362 && TREE_STATIC (decl
)
15363 && DECL_NAME (decl
)
15364 && !DECL_HARD_REGISTER (decl
)
15365 && DECL_MODE (decl
) != VOIDmode
)
15367 rtl
= make_decl_rtl_for_debug (decl
);
15369 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15370 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15377 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15378 returned. If so, the decl for the COMMON block is returned, and the
15379 value is the offset into the common block for the symbol. */
15382 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15384 tree val_expr
, cvar
;
15385 enum machine_mode mode
;
15386 HOST_WIDE_INT bitsize
, bitpos
;
15388 int unsignedp
, volatilep
= 0;
15390 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15391 it does not have a value (the offset into the common area), or if it
15392 is thread local (as opposed to global) then it isn't common, and shouldn't
15393 be handled as such. */
15394 if (TREE_CODE (decl
) != VAR_DECL
15395 || !TREE_STATIC (decl
)
15396 || !DECL_HAS_VALUE_EXPR_P (decl
)
15400 val_expr
= DECL_VALUE_EXPR (decl
);
15401 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15404 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15405 &mode
, &unsignedp
, &volatilep
, true);
15407 if (cvar
== NULL_TREE
15408 || TREE_CODE (cvar
) != VAR_DECL
15409 || DECL_ARTIFICIAL (cvar
)
15410 || !TREE_PUBLIC (cvar
))
15414 if (offset
!= NULL
)
15416 if (!host_integerp (offset
, 0))
15418 *value
= tree_low_cst (offset
, 0);
15421 *value
+= bitpos
/ BITS_PER_UNIT
;
15426 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15427 data attribute for a variable or a parameter. We generate the
15428 DW_AT_const_value attribute only in those cases where the given variable
15429 or parameter does not have a true "location" either in memory or in a
15430 register. This can happen (for example) when a constant is passed as an
15431 actual argument in a call to an inline function. (It's possible that
15432 these things can crop up in other ways also.) Note that one type of
15433 constant value which can be passed into an inlined function is a constant
15434 pointer. This can happen for example if an actual argument in an inlined
15435 function call evaluates to a compile-time constant address.
15437 CACHE_P is true if it is worth caching the location list for DECL,
15438 so that future calls can reuse it rather than regenerate it from scratch.
15439 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15440 since we will need to refer to them each time the function is inlined. */
15443 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15444 enum dwarf_attribute attr
)
15447 dw_loc_list_ref list
;
15448 var_loc_list
*loc_list
;
15449 cached_dw_loc_list
*cache
;
15452 if (TREE_CODE (decl
) == ERROR_MARK
)
15455 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15456 || TREE_CODE (decl
) == RESULT_DECL
);
15458 /* Try to get some constant RTL for this decl, and use that as the value of
15461 rtl
= rtl_for_decl_location (decl
);
15462 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15463 && add_const_value_attribute (die
, rtl
))
15466 /* See if we have single element location list that is equivalent to
15467 a constant value. That way we are better to use add_const_value_attribute
15468 rather than expanding constant value equivalent. */
15469 loc_list
= lookup_decl_loc (decl
);
15472 && loc_list
->first
->next
== NULL
15473 && NOTE_P (loc_list
->first
->loc
)
15474 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15475 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15477 struct var_loc_node
*node
;
15479 node
= loc_list
->first
;
15480 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15481 if (GET_CODE (rtl
) == EXPR_LIST
)
15482 rtl
= XEXP (rtl
, 0);
15483 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15484 && add_const_value_attribute (die
, rtl
))
15487 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15488 list several times. See if we've already cached the contents. */
15490 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15494 cache
= (cached_dw_loc_list
*)
15495 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15497 list
= cache
->loc_list
;
15501 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15502 /* It is usually worth caching this result if the decl is from
15503 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15504 if (cache_p
&& list
&& list
->dw_loc_next
)
15506 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15507 DECL_UID (decl
), INSERT
);
15508 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15509 cache
->decl_id
= DECL_UID (decl
);
15510 cache
->loc_list
= list
;
15516 add_AT_location_description (die
, attr
, list
);
15519 /* None of that worked, so it must not really have a location;
15520 try adding a constant value attribute from the DECL_INITIAL. */
15521 return tree_add_const_value_attribute_for_decl (die
, decl
);
15524 /* Add VARIABLE and DIE into deferred locations list. */
15527 defer_location (tree variable
, dw_die_ref die
)
15529 deferred_locations entry
;
15530 entry
.variable
= variable
;
15532 vec_safe_push (deferred_locations_list
, entry
);
15535 /* Helper function for tree_add_const_value_attribute. Natively encode
15536 initializer INIT into an array. Return true if successful. */
15539 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15543 if (init
== NULL_TREE
)
15547 switch (TREE_CODE (init
))
15550 type
= TREE_TYPE (init
);
15551 if (TREE_CODE (type
) == ARRAY_TYPE
)
15553 tree enttype
= TREE_TYPE (type
);
15554 enum machine_mode mode
= TYPE_MODE (enttype
);
15556 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15558 if (int_size_in_bytes (type
) != size
)
15560 if (size
> TREE_STRING_LENGTH (init
))
15562 memcpy (array
, TREE_STRING_POINTER (init
),
15563 TREE_STRING_LENGTH (init
));
15564 memset (array
+ TREE_STRING_LENGTH (init
),
15565 '\0', size
- TREE_STRING_LENGTH (init
));
15568 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15573 type
= TREE_TYPE (init
);
15574 if (int_size_in_bytes (type
) != size
)
15576 if (TREE_CODE (type
) == ARRAY_TYPE
)
15578 HOST_WIDE_INT min_index
;
15579 unsigned HOST_WIDE_INT cnt
;
15580 int curpos
= 0, fieldsize
;
15581 constructor_elt
*ce
;
15583 if (TYPE_DOMAIN (type
) == NULL_TREE
15584 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15587 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15588 if (fieldsize
<= 0)
15591 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15592 memset (array
, '\0', size
);
15593 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15595 tree val
= ce
->value
;
15596 tree index
= ce
->index
;
15598 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15599 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15602 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15607 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15610 curpos
= pos
+ fieldsize
;
15611 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15613 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15614 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15615 while (count
-- > 0)
15618 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15619 curpos
+= fieldsize
;
15622 gcc_assert (curpos
<= size
);
15626 else if (TREE_CODE (type
) == RECORD_TYPE
15627 || TREE_CODE (type
) == UNION_TYPE
)
15629 tree field
= NULL_TREE
;
15630 unsigned HOST_WIDE_INT cnt
;
15631 constructor_elt
*ce
;
15633 if (int_size_in_bytes (type
) != size
)
15636 if (TREE_CODE (type
) == RECORD_TYPE
)
15637 field
= TYPE_FIELDS (type
);
15639 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15641 tree val
= ce
->value
;
15642 int pos
, fieldsize
;
15644 if (ce
->index
!= 0)
15650 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15653 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15654 && TYPE_DOMAIN (TREE_TYPE (field
))
15655 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15657 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15658 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15660 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15661 pos
= int_byte_position (field
);
15662 gcc_assert (pos
+ fieldsize
<= size
);
15664 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15670 case VIEW_CONVERT_EXPR
:
15671 case NON_LVALUE_EXPR
:
15672 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15674 return native_encode_expr (init
, array
, size
) == size
;
15678 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15679 attribute is the const value T. */
15682 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15685 tree type
= TREE_TYPE (t
);
15688 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15692 gcc_assert (!DECL_P (init
));
15694 rtl
= rtl_for_decl_init (init
, type
);
15696 return add_const_value_attribute (die
, rtl
);
15697 /* If the host and target are sane, try harder. */
15698 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15699 && initializer_constant_valid_p (init
, type
))
15701 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15702 if (size
> 0 && (int) size
== size
)
15704 unsigned char *array
= (unsigned char *)
15705 ggc_alloc_cleared_atomic (size
);
15707 if (native_encode_initializer (init
, array
, size
))
15709 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15718 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15719 attribute is the const value of T, where T is an integral constant
15720 variable with static storage duration
15721 (so it can't be a PARM_DECL or a RESULT_DECL). */
15724 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15728 || (TREE_CODE (decl
) != VAR_DECL
15729 && TREE_CODE (decl
) != CONST_DECL
)
15730 || (TREE_CODE (decl
) == VAR_DECL
15731 && !TREE_STATIC (decl
)))
15734 if (TREE_READONLY (decl
)
15735 && ! TREE_THIS_VOLATILE (decl
)
15736 && DECL_INITIAL (decl
))
15741 /* Don't add DW_AT_const_value if abstract origin already has one. */
15742 if (get_AT (var_die
, DW_AT_const_value
))
15745 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15748 /* Convert the CFI instructions for the current function into a
15749 location list. This is used for DW_AT_frame_base when we targeting
15750 a dwarf2 consumer that does not support the dwarf3
15751 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15754 static dw_loc_list_ref
15755 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15759 dw_loc_list_ref list
, *list_tail
;
15761 dw_cfa_location last_cfa
, next_cfa
;
15762 const char *start_label
, *last_label
, *section
;
15763 dw_cfa_location remember
;
15766 gcc_assert (fde
!= NULL
);
15768 section
= secname_for_decl (current_function_decl
);
15772 memset (&next_cfa
, 0, sizeof (next_cfa
));
15773 next_cfa
.reg
= INVALID_REGNUM
;
15774 remember
= next_cfa
;
15776 start_label
= fde
->dw_fde_begin
;
15778 /* ??? Bald assumption that the CIE opcode list does not contain
15779 advance opcodes. */
15780 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15781 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15783 last_cfa
= next_cfa
;
15784 last_label
= start_label
;
15786 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15788 /* If the first partition contained no CFI adjustments, the
15789 CIE opcodes apply to the whole first partition. */
15790 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15791 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15792 list_tail
=&(*list_tail
)->dw_loc_next
;
15793 start_label
= last_label
= fde
->dw_fde_second_begin
;
15796 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15798 switch (cfi
->dw_cfi_opc
)
15800 case DW_CFA_set_loc
:
15801 case DW_CFA_advance_loc1
:
15802 case DW_CFA_advance_loc2
:
15803 case DW_CFA_advance_loc4
:
15804 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15806 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15807 start_label
, last_label
, section
);
15809 list_tail
= &(*list_tail
)->dw_loc_next
;
15810 last_cfa
= next_cfa
;
15811 start_label
= last_label
;
15813 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15816 case DW_CFA_advance_loc
:
15817 /* The encoding is complex enough that we should never emit this. */
15818 gcc_unreachable ();
15821 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15824 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15826 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15828 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15829 start_label
, last_label
, section
);
15831 list_tail
= &(*list_tail
)->dw_loc_next
;
15832 last_cfa
= next_cfa
;
15833 start_label
= last_label
;
15835 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15836 start_label
, fde
->dw_fde_end
, section
);
15837 list_tail
= &(*list_tail
)->dw_loc_next
;
15838 start_label
= last_label
= fde
->dw_fde_second_begin
;
15842 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15844 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15845 start_label
, last_label
, section
);
15846 list_tail
= &(*list_tail
)->dw_loc_next
;
15847 start_label
= last_label
;
15850 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15852 fde
->dw_fde_second_begin
15853 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15856 if (list
&& list
->dw_loc_next
)
15862 /* Compute a displacement from the "steady-state frame pointer" to the
15863 frame base (often the same as the CFA), and store it in
15864 frame_pointer_fb_offset. OFFSET is added to the displacement
15865 before the latter is negated. */
15868 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15872 #ifdef FRAME_POINTER_CFA_OFFSET
15873 reg
= frame_pointer_rtx
;
15874 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15876 reg
= arg_pointer_rtx
;
15877 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15880 elim
= (ira_use_lra_p
15881 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15882 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15883 if (GET_CODE (elim
) == PLUS
)
15885 offset
+= INTVAL (XEXP (elim
, 1));
15886 elim
= XEXP (elim
, 0);
15889 frame_pointer_fb_offset
= -offset
;
15891 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15892 in which to eliminate. This is because it's stack pointer isn't
15893 directly accessible as a register within the ISA. To work around
15894 this, assume that while we cannot provide a proper value for
15895 frame_pointer_fb_offset, we won't need one either. */
15896 frame_pointer_fb_offset_valid
15897 = ((SUPPORTS_STACK_ALIGNMENT
15898 && (elim
== hard_frame_pointer_rtx
15899 || elim
== stack_pointer_rtx
))
15900 || elim
== (frame_pointer_needed
15901 ? hard_frame_pointer_rtx
15902 : stack_pointer_rtx
));
15905 /* Generate a DW_AT_name attribute given some string value to be included as
15906 the value of the attribute. */
15909 add_name_attribute (dw_die_ref die
, const char *name_string
)
15911 if (name_string
!= NULL
&& *name_string
!= 0)
15913 if (demangle_name_func
)
15914 name_string
= (*demangle_name_func
) (name_string
);
15916 add_AT_string (die
, DW_AT_name
, name_string
);
15920 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15921 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15922 of TYPE accordingly.
15924 ??? This is a temporary measure until after we're able to generate
15925 regular DWARF for the complex Ada type system. */
15928 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15929 dw_die_ref context_die
)
15932 dw_die_ref dtype_die
;
15934 if (!lang_hooks
.types
.descriptive_type
)
15937 dtype
= lang_hooks
.types
.descriptive_type (type
);
15941 dtype_die
= lookup_type_die (dtype
);
15944 gen_type_die (dtype
, context_die
);
15945 dtype_die
= lookup_type_die (dtype
);
15946 gcc_assert (dtype_die
);
15949 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15952 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
15954 static const char *
15955 comp_dir_string (void)
15959 static const char *cached_wd
= NULL
;
15961 if (cached_wd
!= NULL
)
15964 wd
= get_src_pwd ();
15968 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15972 wdlen
= strlen (wd
);
15973 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15975 wd1
[wdlen
] = DIR_SEPARATOR
;
15976 wd1
[wdlen
+ 1] = 0;
15980 cached_wd
= remap_debug_filename (wd
);
15984 /* Generate a DW_AT_comp_dir attribute for DIE. */
15987 add_comp_dir_attribute (dw_die_ref die
)
15989 const char * wd
= comp_dir_string ();
15991 add_AT_string (die
, DW_AT_comp_dir
, wd
);
15994 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15998 lower_bound_default (void)
16000 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16005 case DW_LANG_C_plus_plus
:
16007 case DW_LANG_ObjC_plus_plus
:
16010 case DW_LANG_Fortran77
:
16011 case DW_LANG_Fortran90
:
16012 case DW_LANG_Fortran95
:
16016 case DW_LANG_Python
:
16017 return dwarf_version
>= 4 ? 0 : -1;
16018 case DW_LANG_Ada95
:
16019 case DW_LANG_Ada83
:
16020 case DW_LANG_Cobol74
:
16021 case DW_LANG_Cobol85
:
16022 case DW_LANG_Pascal83
:
16023 case DW_LANG_Modula2
:
16025 return dwarf_version
>= 4 ? 1 : -1;
16031 /* Given a tree node describing an array bound (either lower or upper) output
16032 a representation for that bound. */
16035 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16037 switch (TREE_CODE (bound
))
16042 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16045 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16048 /* Use the default if possible. */
16049 if (bound_attr
== DW_AT_lower_bound
16050 && host_integerp (bound
, 0)
16051 && (dflt
= lower_bound_default ()) != -1
16052 && tree_low_cst (bound
, 0) == dflt
)
16055 /* Otherwise represent the bound as an unsigned value with the
16056 precision of its type. The precision and signedness of the
16057 type will be necessary to re-interpret it unambiguously. */
16058 else if (prec
< HOST_BITS_PER_WIDE_INT
)
16060 unsigned HOST_WIDE_INT mask
16061 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
16062 add_AT_unsigned (subrange_die
, bound_attr
,
16063 TREE_INT_CST_LOW (bound
) & mask
);
16065 else if (prec
== HOST_BITS_PER_WIDE_INT
16066 || TREE_INT_CST_HIGH (bound
) == 0)
16067 add_AT_unsigned (subrange_die
, bound_attr
,
16068 TREE_INT_CST_LOW (bound
));
16070 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
16071 TREE_INT_CST_LOW (bound
));
16076 case VIEW_CONVERT_EXPR
:
16077 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16087 dw_die_ref decl_die
= lookup_decl_die (bound
);
16089 /* ??? Can this happen, or should the variable have been bound
16090 first? Probably it can, since I imagine that we try to create
16091 the types of parameters in the order in which they exist in
16092 the list, and won't have created a forward reference to a
16093 later parameter. */
16094 if (decl_die
!= NULL
)
16096 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16104 /* Otherwise try to create a stack operation procedure to
16105 evaluate the value of the array bound. */
16107 dw_die_ref ctx
, decl_die
;
16108 dw_loc_list_ref list
;
16110 list
= loc_list_from_tree (bound
, 2);
16111 if (list
== NULL
|| single_element_loc_list_p (list
))
16113 /* If DW_AT_*bound is not a reference nor constant, it is
16114 a DWARF expression rather than location description.
16115 For that loc_list_from_tree (bound, 0) is needed.
16116 If that fails to give a single element list,
16117 fall back to outputting this as a reference anyway. */
16118 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16119 if (list2
&& single_element_loc_list_p (list2
))
16121 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16128 if (current_function_decl
== 0)
16129 ctx
= comp_unit_die ();
16131 ctx
= lookup_decl_die (current_function_decl
);
16133 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16134 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16135 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16136 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16137 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16143 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16144 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16145 Note that the block of subscript information for an array type also
16146 includes information about the element type of the given array type. */
16149 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16151 unsigned dimension_number
;
16153 dw_die_ref subrange_die
;
16155 for (dimension_number
= 0;
16156 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16157 type
= TREE_TYPE (type
), dimension_number
++)
16159 tree domain
= TYPE_DOMAIN (type
);
16161 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16164 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16165 and (in GNU C only) variable bounds. Handle all three forms
16167 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16170 /* We have an array type with specified bounds. */
16171 lower
= TYPE_MIN_VALUE (domain
);
16172 upper
= TYPE_MAX_VALUE (domain
);
16174 /* Define the index type. */
16175 if (TREE_TYPE (domain
))
16177 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16178 TREE_TYPE field. We can't emit debug info for this
16179 because it is an unnamed integral type. */
16180 if (TREE_CODE (domain
) == INTEGER_TYPE
16181 && TYPE_NAME (domain
) == NULL_TREE
16182 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16183 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16186 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16190 /* ??? If upper is NULL, the array has unspecified length,
16191 but it does have a lower bound. This happens with Fortran
16193 Since the debugger is definitely going to need to know N
16194 to produce useful results, go ahead and output the lower
16195 bound solo, and hope the debugger can cope. */
16197 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16199 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16202 /* Otherwise we have an array type with an unspecified length. The
16203 DWARF-2 spec does not say how to handle this; let's just leave out the
16209 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16211 dw_die_ref decl_die
;
16214 switch (TREE_CODE (tree_node
))
16219 case ENUMERAL_TYPE
:
16222 case QUAL_UNION_TYPE
:
16223 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16224 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16226 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16229 size
= int_size_in_bytes (tree_node
);
16232 /* For a data member of a struct or union, the DW_AT_byte_size is
16233 generally given as the number of bytes normally allocated for an
16234 object of the *declared* type of the member itself. This is true
16235 even for bit-fields. */
16236 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16239 gcc_unreachable ();
16242 /* Note that `size' might be -1 when we get to this point. If it is, that
16243 indicates that the byte size of the entity in question is variable. We
16244 have no good way of expressing this fact in Dwarf at the present time,
16245 so just let the -1 pass on through. */
16246 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16249 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16250 which specifies the distance in bits from the highest order bit of the
16251 "containing object" for the bit-field to the highest order bit of the
16254 For any given bit-field, the "containing object" is a hypothetical object
16255 (of some integral or enum type) within which the given bit-field lives. The
16256 type of this hypothetical "containing object" is always the same as the
16257 declared type of the individual bit-field itself. The determination of the
16258 exact location of the "containing object" for a bit-field is rather
16259 complicated. It's handled by the `field_byte_offset' function (above).
16261 Note that it is the size (in bytes) of the hypothetical "containing object"
16262 which will be given in the DW_AT_byte_size attribute for this bit-field.
16263 (See `byte_size_attribute' above). */
16266 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16268 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16269 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16270 HOST_WIDE_INT bitpos_int
;
16271 HOST_WIDE_INT highest_order_object_bit_offset
;
16272 HOST_WIDE_INT highest_order_field_bit_offset
;
16273 HOST_WIDE_INT bit_offset
;
16275 /* Must be a field and a bit field. */
16276 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16278 /* We can't yet handle bit-fields whose offsets are variable, so if we
16279 encounter such things, just return without generating any attribute
16280 whatsoever. Likewise for variable or too large size. */
16281 if (! host_integerp (bit_position (decl
), 0)
16282 || ! host_integerp (DECL_SIZE (decl
), 1))
16285 bitpos_int
= int_bit_position (decl
);
16287 /* Note that the bit offset is always the distance (in bits) from the
16288 highest-order bit of the "containing object" to the highest-order bit of
16289 the bit-field itself. Since the "high-order end" of any object or field
16290 is different on big-endian and little-endian machines, the computation
16291 below must take account of these differences. */
16292 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16293 highest_order_field_bit_offset
= bitpos_int
;
16295 if (! BYTES_BIG_ENDIAN
)
16297 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16298 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16302 = (! BYTES_BIG_ENDIAN
16303 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16304 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16306 if (bit_offset
< 0)
16307 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16309 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16312 /* For a FIELD_DECL node which represents a bit field, output an attribute
16313 which specifies the length in bits of the given field. */
16316 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16318 /* Must be a field and a bit field. */
16319 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16320 && DECL_BIT_FIELD_TYPE (decl
));
16322 if (host_integerp (DECL_SIZE (decl
), 1))
16323 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16326 /* If the compiled language is ANSI C, then add a 'prototyped'
16327 attribute, if arg types are given for the parameters of a function. */
16330 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16332 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16333 && prototype_p (func_type
))
16334 add_AT_flag (die
, DW_AT_prototyped
, 1);
16337 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16338 by looking in either the type declaration or object declaration
16341 static inline dw_die_ref
16342 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16344 dw_die_ref origin_die
= NULL
;
16346 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16348 /* We may have gotten separated from the block for the inlined
16349 function, if we're in an exception handler or some such; make
16350 sure that the abstract function has been written out.
16352 Doing this for nested functions is wrong, however; functions are
16353 distinct units, and our context might not even be inline. */
16357 fn
= TYPE_STUB_DECL (fn
);
16359 fn
= decl_function_context (fn
);
16361 dwarf2out_abstract_function (fn
);
16364 if (DECL_P (origin
))
16365 origin_die
= lookup_decl_die (origin
);
16366 else if (TYPE_P (origin
))
16367 origin_die
= lookup_type_die (origin
);
16369 /* XXX: Functions that are never lowered don't always have correct block
16370 trees (in the case of java, they simply have no block tree, in some other
16371 languages). For these functions, there is nothing we can really do to
16372 output correct debug info for inlined functions in all cases. Rather
16373 than die, we'll just produce deficient debug info now, in that we will
16374 have variables without a proper abstract origin. In the future, when all
16375 functions are lowered, we should re-add a gcc_assert (origin_die)
16379 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16383 /* We do not currently support the pure_virtual attribute. */
16386 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16388 if (DECL_VINDEX (func_decl
))
16390 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16392 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16393 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16394 new_loc_descr (DW_OP_constu
,
16395 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16398 /* GNU extension: Record what type this method came from originally. */
16399 if (debug_info_level
> DINFO_LEVEL_TERSE
16400 && DECL_CONTEXT (func_decl
))
16401 add_AT_die_ref (die
, DW_AT_containing_type
,
16402 lookup_type_die (DECL_CONTEXT (func_decl
)));
16406 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16407 given decl. This used to be a vendor extension until after DWARF 4
16408 standardized it. */
16411 add_linkage_attr (dw_die_ref die
, tree decl
)
16413 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16415 /* Mimic what assemble_name_raw does with a leading '*'. */
16416 if (name
[0] == '*')
16419 if (dwarf_version
>= 4)
16420 add_AT_string (die
, DW_AT_linkage_name
, name
);
16422 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16425 /* Add source coordinate attributes for the given decl. */
16428 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16430 expanded_location s
;
16432 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16434 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16435 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16436 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16439 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16442 add_linkage_name (dw_die_ref die
, tree decl
)
16444 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16445 && TREE_PUBLIC (decl
)
16446 && !DECL_ABSTRACT (decl
)
16447 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16448 && die
->die_tag
!= DW_TAG_member
)
16450 /* Defer until we have an assembler name set. */
16451 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16453 limbo_die_node
*asm_name
;
16455 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16456 asm_name
->die
= die
;
16457 asm_name
->created_for
= decl
;
16458 asm_name
->next
= deferred_asm_name
;
16459 deferred_asm_name
= asm_name
;
16461 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16462 add_linkage_attr (die
, decl
);
16466 /* Add a DW_AT_name attribute and source coordinate attribute for the
16467 given decl, but only if it actually has a name. */
16470 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16474 decl_name
= DECL_NAME (decl
);
16475 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16477 const char *name
= dwarf2_name (decl
, 0);
16479 add_name_attribute (die
, name
);
16480 if (! DECL_ARTIFICIAL (decl
))
16481 add_src_coords_attributes (die
, decl
);
16483 add_linkage_name (die
, decl
);
16486 #ifdef VMS_DEBUGGING_INFO
16487 /* Get the function's name, as described by its RTL. This may be different
16488 from the DECL_NAME name used in the source file. */
16489 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16491 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16492 XEXP (DECL_RTL (decl
), 0), false);
16493 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16495 #endif /* VMS_DEBUGGING_INFO */
16498 #ifdef VMS_DEBUGGING_INFO
16499 /* Output the debug main pointer die for VMS */
16502 dwarf2out_vms_debug_main_pointer (void)
16504 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16507 /* Allocate the VMS debug main subprogram die. */
16508 die
= ggc_alloc_cleared_die_node ();
16509 die
->die_tag
= DW_TAG_subprogram
;
16510 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16511 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16512 current_function_funcdef_no
);
16513 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16515 /* Make it the first child of comp_unit_die (). */
16516 die
->die_parent
= comp_unit_die ();
16517 if (comp_unit_die ()->die_child
)
16519 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16520 comp_unit_die ()->die_child
->die_sib
= die
;
16524 die
->die_sib
= die
;
16525 comp_unit_die ()->die_child
= die
;
16528 #endif /* VMS_DEBUGGING_INFO */
16530 /* Push a new declaration scope. */
16533 push_decl_scope (tree scope
)
16535 vec_safe_push (decl_scope_table
, scope
);
16538 /* Pop a declaration scope. */
16541 pop_decl_scope (void)
16543 decl_scope_table
->pop ();
16546 /* walk_tree helper function for uses_local_type, below. */
16549 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16552 *walk_subtrees
= 0;
16555 tree name
= TYPE_NAME (*tp
);
16556 if (name
&& DECL_P (name
) && decl_function_context (name
))
16562 /* If TYPE involves a function-local type (including a local typedef to a
16563 non-local type), returns that type; otherwise returns NULL_TREE. */
16566 uses_local_type (tree type
)
16568 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16572 /* Return the DIE for the scope that immediately contains this type.
16573 Non-named types that do not involve a function-local type get global
16574 scope. Named types nested in namespaces or other types get their
16575 containing scope. All other types (i.e. function-local named types) get
16576 the current active scope. */
16579 scope_die_for (tree t
, dw_die_ref context_die
)
16581 dw_die_ref scope_die
= NULL
;
16582 tree containing_scope
;
16584 /* Non-types always go in the current scope. */
16585 gcc_assert (TYPE_P (t
));
16587 /* Use the scope of the typedef, rather than the scope of the type
16589 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16590 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16592 containing_scope
= TYPE_CONTEXT (t
);
16594 /* Use the containing namespace if there is one. */
16595 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16597 if (context_die
== lookup_decl_die (containing_scope
))
16599 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16600 context_die
= get_context_die (containing_scope
);
16602 containing_scope
= NULL_TREE
;
16605 /* Ignore function type "scopes" from the C frontend. They mean that
16606 a tagged type is local to a parmlist of a function declarator, but
16607 that isn't useful to DWARF. */
16608 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16609 containing_scope
= NULL_TREE
;
16611 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16613 /* If T uses a local type keep it local as well, to avoid references
16614 to function-local DIEs from outside the function. */
16615 if (current_function_decl
&& uses_local_type (t
))
16616 scope_die
= context_die
;
16618 scope_die
= comp_unit_die ();
16620 else if (TYPE_P (containing_scope
))
16622 /* For types, we can just look up the appropriate DIE. */
16623 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16624 scope_die
= get_context_die (containing_scope
);
16627 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16628 if (scope_die
== NULL
)
16629 scope_die
= comp_unit_die ();
16633 scope_die
= context_die
;
16638 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16641 local_scope_p (dw_die_ref context_die
)
16643 for (; context_die
; context_die
= context_die
->die_parent
)
16644 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16645 || context_die
->die_tag
== DW_TAG_subprogram
)
16651 /* Returns nonzero if CONTEXT_DIE is a class. */
16654 class_scope_p (dw_die_ref context_die
)
16656 return (context_die
16657 && (context_die
->die_tag
== DW_TAG_structure_type
16658 || context_die
->die_tag
== DW_TAG_class_type
16659 || context_die
->die_tag
== DW_TAG_interface_type
16660 || context_die
->die_tag
== DW_TAG_union_type
));
16663 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16664 whether or not to treat a DIE in this context as a declaration. */
16667 class_or_namespace_scope_p (dw_die_ref context_die
)
16669 return (class_scope_p (context_die
)
16670 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16673 /* Many forms of DIEs require a "type description" attribute. This
16674 routine locates the proper "type descriptor" die for the type given
16675 by 'type', and adds a DW_AT_type attribute below the given die. */
16678 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16679 int decl_volatile
, dw_die_ref context_die
)
16681 enum tree_code code
= TREE_CODE (type
);
16682 dw_die_ref type_die
= NULL
;
16684 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16685 or fixed-point type, use the inner type. This is because we have no
16686 support for unnamed types in base_type_die. This can happen if this is
16687 an Ada subrange type. Correct solution is emit a subrange type die. */
16688 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16689 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16690 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16692 if (code
== ERROR_MARK
16693 /* Handle a special case. For functions whose return type is void, we
16694 generate *no* type attribute. (Note that no object may have type
16695 `void', so this only applies to function return types). */
16696 || code
== VOID_TYPE
)
16699 type_die
= modified_type_die (type
,
16700 decl_const
|| TYPE_READONLY (type
),
16701 decl_volatile
|| TYPE_VOLATILE (type
),
16704 if (type_die
!= NULL
)
16705 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16708 /* Given an object die, add the calling convention attribute for the
16709 function call type. */
16711 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16713 enum dwarf_calling_convention value
= DW_CC_normal
;
16715 value
= ((enum dwarf_calling_convention
)
16716 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16719 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16721 /* DWARF 2 doesn't provide a way to identify a program's source-level
16722 entry point. DW_AT_calling_convention attributes are only meant
16723 to describe functions' calling conventions. However, lacking a
16724 better way to signal the Fortran main program, we used this for
16725 a long time, following existing custom. Now, DWARF 4 has
16726 DW_AT_main_subprogram, which we add below, but some tools still
16727 rely on the old way, which we thus keep. */
16728 value
= DW_CC_program
;
16730 if (dwarf_version
>= 4 || !dwarf_strict
)
16731 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16734 /* Only add the attribute if the backend requests it, and
16735 is not DW_CC_normal. */
16736 if (value
&& (value
!= DW_CC_normal
))
16737 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16740 /* Given a tree pointer to a struct, class, union, or enum type node, return
16741 a pointer to the (string) tag name for the given type, or zero if the type
16742 was declared without a tag. */
16744 static const char *
16745 type_tag (const_tree type
)
16747 const char *name
= 0;
16749 if (TYPE_NAME (type
) != 0)
16753 /* Find the IDENTIFIER_NODE for the type name. */
16754 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16755 && !TYPE_NAMELESS (type
))
16756 t
= TYPE_NAME (type
);
16758 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16759 a TYPE_DECL node, regardless of whether or not a `typedef' was
16761 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16762 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16764 /* We want to be extra verbose. Don't call dwarf_name if
16765 DECL_NAME isn't set. The default hook for decl_printable_name
16766 doesn't like that, and in this context it's correct to return
16767 0, instead of "<anonymous>" or the like. */
16768 if (DECL_NAME (TYPE_NAME (type
))
16769 && !DECL_NAMELESS (TYPE_NAME (type
)))
16770 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16773 /* Now get the name as a string, or invent one. */
16774 if (!name
&& t
!= 0)
16775 name
= IDENTIFIER_POINTER (t
);
16778 return (name
== 0 || *name
== '\0') ? 0 : name
;
16781 /* Return the type associated with a data member, make a special check
16782 for bit field types. */
16785 member_declared_type (const_tree member
)
16787 return (DECL_BIT_FIELD_TYPE (member
)
16788 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16791 /* Get the decl's label, as described by its RTL. This may be different
16792 from the DECL_NAME name used in the source file. */
16795 static const char *
16796 decl_start_label (tree decl
)
16799 const char *fnname
;
16801 x
= DECL_RTL (decl
);
16802 gcc_assert (MEM_P (x
));
16805 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16807 fnname
= XSTR (x
, 0);
16812 /* These routines generate the internal representation of the DIE's for
16813 the compilation unit. Debugging information is collected by walking
16814 the declaration trees passed in from dwarf2out_decl(). */
16817 gen_array_type_die (tree type
, dw_die_ref context_die
)
16819 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16820 dw_die_ref array_die
;
16822 /* GNU compilers represent multidimensional array types as sequences of one
16823 dimensional array types whose element types are themselves array types.
16824 We sometimes squish that down to a single array_type DIE with multiple
16825 subscripts in the Dwarf debugging info. The draft Dwarf specification
16826 say that we are allowed to do this kind of compression in C, because
16827 there is no difference between an array of arrays and a multidimensional
16828 array. We don't do this for Ada to remain as close as possible to the
16829 actual representation, which is especially important against the language
16830 flexibilty wrt arrays of variable size. */
16832 bool collapse_nested_arrays
= !is_ada ();
16835 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16836 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16837 if (TYPE_STRING_FLAG (type
)
16838 && TREE_CODE (type
) == ARRAY_TYPE
16840 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16842 HOST_WIDE_INT size
;
16844 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16845 add_name_attribute (array_die
, type_tag (type
));
16846 equate_type_number_to_die (type
, array_die
);
16847 size
= int_size_in_bytes (type
);
16849 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16850 else if (TYPE_DOMAIN (type
) != NULL_TREE
16851 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16852 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16854 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16855 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16857 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16858 if (loc
&& size
> 0)
16860 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16861 if (size
!= DWARF2_ADDR_SIZE
)
16862 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16868 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16869 add_name_attribute (array_die
, type_tag (type
));
16870 equate_type_number_to_die (type
, array_die
);
16872 if (TREE_CODE (type
) == VECTOR_TYPE
)
16873 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16875 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16877 && TREE_CODE (type
) == ARRAY_TYPE
16878 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16879 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16880 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16883 /* We default the array ordering. SDB will probably do
16884 the right things even if DW_AT_ordering is not present. It's not even
16885 an issue until we start to get into multidimensional arrays anyway. If
16886 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16887 then we'll have to put the DW_AT_ordering attribute back in. (But if
16888 and when we find out that we need to put these in, we will only do so
16889 for multidimensional arrays. */
16890 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16893 if (TREE_CODE (type
) == VECTOR_TYPE
)
16895 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16896 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16897 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16898 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16899 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16902 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16904 /* Add representation of the type of the elements of this array type and
16905 emit the corresponding DIE if we haven't done it already. */
16906 element_type
= TREE_TYPE (type
);
16907 if (collapse_nested_arrays
)
16908 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16910 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16912 element_type
= TREE_TYPE (element_type
);
16915 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16917 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16918 if (TYPE_ARTIFICIAL (type
))
16919 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16921 if (get_AT (array_die
, DW_AT_name
))
16922 add_pubtype (type
, array_die
);
16925 static dw_loc_descr_ref
16926 descr_info_loc (tree val
, tree base_decl
)
16928 HOST_WIDE_INT size
;
16929 dw_loc_descr_ref loc
, loc2
;
16930 enum dwarf_location_atom op
;
16932 if (val
== base_decl
)
16933 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16935 switch (TREE_CODE (val
))
16938 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16940 return loc_descriptor_from_tree (val
, 0);
16942 if (host_integerp (val
, 0))
16943 return int_loc_descriptor (tree_low_cst (val
, 0));
16946 size
= int_size_in_bytes (TREE_TYPE (val
));
16949 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16952 if (size
== DWARF2_ADDR_SIZE
)
16953 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16955 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16957 case POINTER_PLUS_EXPR
:
16959 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16960 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16963 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16966 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16972 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16975 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16978 add_loc_descr (&loc
, loc2
);
16979 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17001 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17002 tree val
, tree base_decl
)
17004 dw_loc_descr_ref loc
;
17006 if (host_integerp (val
, 0))
17008 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
17012 loc
= descr_info_loc (val
, base_decl
);
17016 add_AT_loc (die
, attr
, loc
);
17019 /* This routine generates DIE for array with hidden descriptor, details
17020 are filled into *info by a langhook. */
17023 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17024 dw_die_ref context_die
)
17026 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17027 dw_die_ref array_die
;
17030 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17031 add_name_attribute (array_die
, type_tag (type
));
17032 equate_type_number_to_die (type
, array_die
);
17034 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17036 && info
->ndimensions
>= 2)
17037 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17039 if (info
->data_location
)
17040 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17042 if (info
->associated
)
17043 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17045 if (info
->allocated
)
17046 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17049 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17051 dw_die_ref subrange_die
17052 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17054 if (info
->dimen
[dim
].lower_bound
)
17056 /* If it is the default value, omit it. */
17059 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
17060 && (dflt
= lower_bound_default ()) != -1
17061 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
17064 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17065 info
->dimen
[dim
].lower_bound
,
17068 if (info
->dimen
[dim
].upper_bound
)
17069 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17070 info
->dimen
[dim
].upper_bound
,
17072 if (info
->dimen
[dim
].stride
)
17073 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17074 info
->dimen
[dim
].stride
,
17078 gen_type_die (info
->element_type
, context_die
);
17079 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17081 if (get_AT (array_die
, DW_AT_name
))
17082 add_pubtype (type
, array_die
);
17087 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17089 tree origin
= decl_ultimate_origin (decl
);
17090 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17092 if (origin
!= NULL
)
17093 add_abstract_origin_attribute (decl_die
, origin
);
17096 add_name_and_src_coords_attributes (decl_die
, decl
);
17097 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17098 0, 0, context_die
);
17101 if (DECL_ABSTRACT (decl
))
17102 equate_decl_number_to_die (decl
, decl_die
);
17104 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17108 /* Walk through the list of incomplete types again, trying once more to
17109 emit full debugging info for them. */
17112 retry_incomplete_types (void)
17116 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17117 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17118 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17121 /* Determine what tag to use for a record type. */
17123 static enum dwarf_tag
17124 record_type_tag (tree type
)
17126 if (! lang_hooks
.types
.classify_record
)
17127 return DW_TAG_structure_type
;
17129 switch (lang_hooks
.types
.classify_record (type
))
17131 case RECORD_IS_STRUCT
:
17132 return DW_TAG_structure_type
;
17134 case RECORD_IS_CLASS
:
17135 return DW_TAG_class_type
;
17137 case RECORD_IS_INTERFACE
:
17138 if (dwarf_version
>= 3 || !dwarf_strict
)
17139 return DW_TAG_interface_type
;
17140 return DW_TAG_structure_type
;
17143 gcc_unreachable ();
17147 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17148 include all of the information about the enumeration values also. Each
17149 enumerated type name/value is listed as a child of the enumerated type
17153 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17155 dw_die_ref type_die
= lookup_type_die (type
);
17157 if (type_die
== NULL
)
17159 type_die
= new_die (DW_TAG_enumeration_type
,
17160 scope_die_for (type
, context_die
), type
);
17161 equate_type_number_to_die (type
, type_die
);
17162 add_name_attribute (type_die
, type_tag (type
));
17163 if (dwarf_version
>= 4 || !dwarf_strict
)
17165 if (ENUM_IS_SCOPED (type
))
17166 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17167 if (ENUM_IS_OPAQUE (type
))
17168 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17171 else if (! TYPE_SIZE (type
))
17174 remove_AT (type_die
, DW_AT_declaration
);
17176 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17177 given enum type is incomplete, do not generate the DW_AT_byte_size
17178 attribute or the DW_AT_element_list attribute. */
17179 if (TYPE_SIZE (type
))
17183 TREE_ASM_WRITTEN (type
) = 1;
17184 add_byte_size_attribute (type_die
, type
);
17185 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17187 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17188 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17191 /* If the first reference to this type was as the return type of an
17192 inline function, then it may not have a parent. Fix this now. */
17193 if (type_die
->die_parent
== NULL
)
17194 add_child_die (scope_die_for (type
, context_die
), type_die
);
17196 for (link
= TYPE_VALUES (type
);
17197 link
!= NULL
; link
= TREE_CHAIN (link
))
17199 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17200 tree value
= TREE_VALUE (link
);
17202 add_name_attribute (enum_die
,
17203 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17205 if (TREE_CODE (value
) == CONST_DECL
)
17206 value
= DECL_INITIAL (value
);
17208 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
)))
17209 && (simple_type_size_in_bits (TREE_TYPE (value
))
17210 <= HOST_BITS_PER_WIDE_INT
|| host_integerp (value
, 0)))
17211 /* DWARF2 does not provide a way of indicating whether or
17212 not enumeration constants are signed or unsigned. GDB
17213 always assumes the values are signed, so we output all
17214 values as if they were signed. That means that
17215 enumeration constants with very large unsigned values
17216 will appear to have negative values in the debugger.
17218 TODO: the above comment is wrong, DWARF2 does provide
17219 DW_FORM_sdata/DW_FORM_udata to represent signed/unsigned data.
17220 This should be re-worked to use correct signed/unsigned
17221 int/double tags for all cases, instead of always treating as
17223 add_AT_int (enum_die
, DW_AT_const_value
, TREE_INT_CST_LOW (value
));
17225 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17227 add_AT_double (enum_die
, DW_AT_const_value
,
17228 TREE_INT_CST_HIGH (value
), TREE_INT_CST_LOW (value
));
17231 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17232 if (TYPE_ARTIFICIAL (type
))
17233 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17236 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17238 add_pubtype (type
, type_die
);
17243 /* Generate a DIE to represent either a real live formal parameter decl or to
17244 represent just the type of some formal parameter position in some function
17247 Note that this routine is a bit unusual because its argument may be a
17248 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17249 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17250 node. If it's the former then this function is being called to output a
17251 DIE to represent a formal parameter object (or some inlining thereof). If
17252 it's the latter, then this function is only being called to output a
17253 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17254 argument type of some subprogram type.
17255 If EMIT_NAME_P is true, name and source coordinate attributes
17259 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17260 dw_die_ref context_die
)
17262 tree node_or_origin
= node
? node
: origin
;
17263 tree ultimate_origin
;
17264 dw_die_ref parm_die
17265 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17267 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17269 case tcc_declaration
:
17270 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17271 if (node
|| ultimate_origin
)
17272 origin
= ultimate_origin
;
17273 if (origin
!= NULL
)
17274 add_abstract_origin_attribute (parm_die
, origin
);
17275 else if (emit_name_p
)
17276 add_name_and_src_coords_attributes (parm_die
, node
);
17278 || (! DECL_ABSTRACT (node_or_origin
)
17279 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17280 decl_function_context
17281 (node_or_origin
))))
17283 tree type
= TREE_TYPE (node_or_origin
);
17284 if (decl_by_reference_p (node_or_origin
))
17285 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17288 add_type_attribute (parm_die
, type
,
17289 TREE_READONLY (node_or_origin
),
17290 TREE_THIS_VOLATILE (node_or_origin
),
17293 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17294 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17296 if (node
&& node
!= origin
)
17297 equate_decl_number_to_die (node
, parm_die
);
17298 if (! DECL_ABSTRACT (node_or_origin
))
17299 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17300 node
== NULL
, DW_AT_location
);
17305 /* We were called with some kind of a ..._TYPE node. */
17306 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17310 gcc_unreachable ();
17316 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17317 children DW_TAG_formal_parameter DIEs representing the arguments of the
17320 PARM_PACK must be a function parameter pack.
17321 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17322 must point to the subsequent arguments of the function PACK_ARG belongs to.
17323 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17324 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17325 following the last one for which a DIE was generated. */
17328 gen_formal_parameter_pack_die (tree parm_pack
,
17330 dw_die_ref subr_die
,
17334 dw_die_ref parm_pack_die
;
17336 gcc_assert (parm_pack
17337 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17340 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17341 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17343 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17345 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17348 gen_formal_parameter_die (arg
, NULL
,
17349 false /* Don't emit name attribute. */,
17354 return parm_pack_die
;
17357 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17358 at the end of an (ANSI prototyped) formal parameters list. */
17361 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17363 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17366 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17367 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17368 parameters as specified in some function type specification (except for
17369 those which appear as part of a function *definition*). */
17372 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17375 tree formal_type
= NULL
;
17376 tree first_parm_type
;
17379 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17381 arg
= DECL_ARGUMENTS (function_or_method_type
);
17382 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17387 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17389 /* Make our first pass over the list of formal parameter types and output a
17390 DW_TAG_formal_parameter DIE for each one. */
17391 for (link
= first_parm_type
; link
; )
17393 dw_die_ref parm_die
;
17395 formal_type
= TREE_VALUE (link
);
17396 if (formal_type
== void_type_node
)
17399 /* Output a (nameless) DIE to represent the formal parameter itself. */
17400 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17401 true /* Emit name attribute. */,
17403 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17404 && link
== first_parm_type
)
17406 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17407 if (dwarf_version
>= 3 || !dwarf_strict
)
17408 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17410 else if (arg
&& DECL_ARTIFICIAL (arg
))
17411 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17413 link
= TREE_CHAIN (link
);
17415 arg
= DECL_CHAIN (arg
);
17418 /* If this function type has an ellipsis, add a
17419 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17420 if (formal_type
!= void_type_node
)
17421 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17423 /* Make our second (and final) pass over the list of formal parameter types
17424 and output DIEs to represent those types (as necessary). */
17425 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17426 link
&& TREE_VALUE (link
);
17427 link
= TREE_CHAIN (link
))
17428 gen_type_die (TREE_VALUE (link
), context_die
);
17431 /* We want to generate the DIE for TYPE so that we can generate the
17432 die for MEMBER, which has been defined; we will need to refer back
17433 to the member declaration nested within TYPE. If we're trying to
17434 generate minimal debug info for TYPE, processing TYPE won't do the
17435 trick; we need to attach the member declaration by hand. */
17438 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17440 gen_type_die (type
, context_die
);
17442 /* If we're trying to avoid duplicate debug info, we may not have
17443 emitted the member decl for this function. Emit it now. */
17444 if (TYPE_STUB_DECL (type
)
17445 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17446 && ! lookup_decl_die (member
))
17448 dw_die_ref type_die
;
17449 gcc_assert (!decl_ultimate_origin (member
));
17451 push_decl_scope (type
);
17452 type_die
= lookup_type_die_strip_naming_typedef (type
);
17453 if (TREE_CODE (member
) == FUNCTION_DECL
)
17454 gen_subprogram_die (member
, type_die
);
17455 else if (TREE_CODE (member
) == FIELD_DECL
)
17457 /* Ignore the nameless fields that are used to skip bits but handle
17458 C++ anonymous unions and structs. */
17459 if (DECL_NAME (member
) != NULL_TREE
17460 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17461 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17463 gen_type_die (member_declared_type (member
), type_die
);
17464 gen_field_die (member
, type_die
);
17468 gen_variable_die (member
, NULL_TREE
, type_die
);
17474 /* Forward declare these functions, because they are mutually recursive
17475 with their set_block_* pairing functions. */
17476 static void set_decl_origin_self (tree
);
17477 static void set_decl_abstract_flags (tree
, int);
17479 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17480 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17481 that it points to the node itself, thus indicating that the node is its
17482 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17483 the given node is NULL, recursively descend the decl/block tree which
17484 it is the root of, and for each other ..._DECL or BLOCK node contained
17485 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17486 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17487 values to point to themselves. */
17490 set_block_origin_self (tree stmt
)
17492 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17494 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17499 for (local_decl
= BLOCK_VARS (stmt
);
17500 local_decl
!= NULL_TREE
;
17501 local_decl
= DECL_CHAIN (local_decl
))
17502 if (! DECL_EXTERNAL (local_decl
))
17503 set_decl_origin_self (local_decl
); /* Potential recursion. */
17509 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17510 subblock
!= NULL_TREE
;
17511 subblock
= BLOCK_CHAIN (subblock
))
17512 set_block_origin_self (subblock
); /* Recurse. */
17517 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17518 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17519 node to so that it points to the node itself, thus indicating that the
17520 node represents its own (abstract) origin. Additionally, if the
17521 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17522 the decl/block tree of which the given node is the root of, and for
17523 each other ..._DECL or BLOCK node contained therein whose
17524 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17525 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17526 point to themselves. */
17529 set_decl_origin_self (tree decl
)
17531 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17533 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17534 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17538 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17539 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17540 if (DECL_INITIAL (decl
) != NULL_TREE
17541 && DECL_INITIAL (decl
) != error_mark_node
)
17542 set_block_origin_self (DECL_INITIAL (decl
));
17547 /* Given a pointer to some BLOCK node, and a boolean value to set the
17548 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17549 the given block, and for all local decls and all local sub-blocks
17550 (recursively) which are contained therein. */
17553 set_block_abstract_flags (tree stmt
, int setting
)
17559 BLOCK_ABSTRACT (stmt
) = setting
;
17561 for (local_decl
= BLOCK_VARS (stmt
);
17562 local_decl
!= NULL_TREE
;
17563 local_decl
= DECL_CHAIN (local_decl
))
17564 if (! DECL_EXTERNAL (local_decl
))
17565 set_decl_abstract_flags (local_decl
, setting
);
17567 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17569 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17570 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17571 || TREE_CODE (local_decl
) == PARM_DECL
)
17572 set_decl_abstract_flags (local_decl
, setting
);
17575 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17576 subblock
!= NULL_TREE
;
17577 subblock
= BLOCK_CHAIN (subblock
))
17578 set_block_abstract_flags (subblock
, setting
);
17581 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17582 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17583 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17584 set the abstract flags for all of the parameters, local vars, local
17585 blocks and sub-blocks (recursively) to the same setting. */
17588 set_decl_abstract_flags (tree decl
, int setting
)
17590 DECL_ABSTRACT (decl
) = setting
;
17591 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17595 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17596 DECL_ABSTRACT (arg
) = setting
;
17597 if (DECL_INITIAL (decl
) != NULL_TREE
17598 && DECL_INITIAL (decl
) != error_mark_node
)
17599 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17603 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17604 may later generate inlined and/or out-of-line instances of. */
17607 dwarf2out_abstract_function (tree decl
)
17609 dw_die_ref old_die
;
17613 htab_t old_decl_loc_table
;
17614 htab_t old_cached_dw_loc_list_table
;
17615 int old_call_site_count
, old_tail_call_site_count
;
17616 struct call_arg_loc_node
*old_call_arg_locations
;
17618 /* Make sure we have the actual abstract inline, not a clone. */
17619 decl
= DECL_ORIGIN (decl
);
17621 old_die
= lookup_decl_die (decl
);
17622 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17623 /* We've already generated the abstract instance. */
17626 /* We can be called while recursively when seeing block defining inlined subroutine
17627 DIE. Be sure to not clobber the outer location table nor use it or we would
17628 get locations in abstract instantces. */
17629 old_decl_loc_table
= decl_loc_table
;
17630 decl_loc_table
= NULL
;
17631 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17632 cached_dw_loc_list_table
= NULL
;
17633 old_call_arg_locations
= call_arg_locations
;
17634 call_arg_locations
= NULL
;
17635 old_call_site_count
= call_site_count
;
17636 call_site_count
= -1;
17637 old_tail_call_site_count
= tail_call_site_count
;
17638 tail_call_site_count
= -1;
17640 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17641 we don't get confused by DECL_ABSTRACT. */
17642 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17644 context
= decl_class_context (decl
);
17646 gen_type_die_for_member
17647 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17650 /* Pretend we've just finished compiling this function. */
17651 save_fn
= current_function_decl
;
17652 current_function_decl
= decl
;
17654 was_abstract
= DECL_ABSTRACT (decl
);
17655 set_decl_abstract_flags (decl
, 1);
17656 dwarf2out_decl (decl
);
17657 if (! was_abstract
)
17658 set_decl_abstract_flags (decl
, 0);
17660 current_function_decl
= save_fn
;
17661 decl_loc_table
= old_decl_loc_table
;
17662 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17663 call_arg_locations
= old_call_arg_locations
;
17664 call_site_count
= old_call_site_count
;
17665 tail_call_site_count
= old_tail_call_site_count
;
17668 /* Helper function of premark_used_types() which gets called through
17671 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17672 marked as unused by prune_unused_types. */
17675 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17680 type
= (tree
) *slot
;
17681 die
= lookup_type_die (type
);
17683 die
->die_perennial_p
= 1;
17687 /* Helper function of premark_types_used_by_global_vars which gets called
17688 through htab_traverse.
17690 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17691 marked as unused by prune_unused_types. The DIE of the type is marked
17692 only if the global variable using the type will actually be emitted. */
17695 premark_types_used_by_global_vars_helper (void **slot
,
17696 void *data ATTRIBUTE_UNUSED
)
17698 struct types_used_by_vars_entry
*entry
;
17701 entry
= (struct types_used_by_vars_entry
*) *slot
;
17702 gcc_assert (entry
->type
!= NULL
17703 && entry
->var_decl
!= NULL
);
17704 die
= lookup_type_die (entry
->type
);
17707 /* Ask cgraph if the global variable really is to be emitted.
17708 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17709 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17710 if (node
&& node
->symbol
.definition
)
17712 die
->die_perennial_p
= 1;
17713 /* Keep the parent DIEs as well. */
17714 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17715 die
->die_perennial_p
= 1;
17721 /* Mark all members of used_types_hash as perennial. */
17724 premark_used_types (struct function
*fun
)
17726 if (fun
&& fun
->used_types_hash
)
17727 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17730 /* Mark all members of types_used_by_vars_entry as perennial. */
17733 premark_types_used_by_global_vars (void)
17735 if (types_used_by_vars_hash
)
17736 htab_traverse (types_used_by_vars_hash
,
17737 premark_types_used_by_global_vars_helper
, NULL
);
17740 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17741 for CA_LOC call arg loc node. */
17744 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17745 struct call_arg_loc_node
*ca_loc
)
17747 dw_die_ref stmt_die
= NULL
, die
;
17748 tree block
= ca_loc
->block
;
17751 && block
!= DECL_INITIAL (decl
)
17752 && TREE_CODE (block
) == BLOCK
)
17754 if (block_map
.length () > BLOCK_NUMBER (block
))
17755 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17758 block
= BLOCK_SUPERCONTEXT (block
);
17760 if (stmt_die
== NULL
)
17761 stmt_die
= subr_die
;
17762 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17763 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17764 if (ca_loc
->tail_call_p
)
17765 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17766 if (ca_loc
->symbol_ref
)
17768 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17770 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17772 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17777 /* Generate a DIE to represent a declared function (either file-scope or
17781 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17783 tree origin
= decl_ultimate_origin (decl
);
17784 dw_die_ref subr_die
;
17786 dw_die_ref old_die
= lookup_decl_die (decl
);
17787 int declaration
= (current_function_decl
!= decl
17788 || class_or_namespace_scope_p (context_die
));
17790 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17792 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17793 started to generate the abstract instance of an inline, decided to output
17794 its containing class, and proceeded to emit the declaration of the inline
17795 from the member list for the class. If so, DECLARATION takes priority;
17796 we'll get back to the abstract instance when done with the class. */
17798 /* The class-scope declaration DIE must be the primary DIE. */
17799 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17802 gcc_assert (!old_die
);
17805 /* Now that the C++ front end lazily declares artificial member fns, we
17806 might need to retrofit the declaration into its class. */
17807 if (!declaration
&& !origin
&& !old_die
17808 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17809 && !class_or_namespace_scope_p (context_die
)
17810 && debug_info_level
> DINFO_LEVEL_TERSE
)
17811 old_die
= force_decl_die (decl
);
17813 if (origin
!= NULL
)
17815 gcc_assert (!declaration
|| local_scope_p (context_die
));
17817 /* Fixup die_parent for the abstract instance of a nested
17818 inline function. */
17819 if (old_die
&& old_die
->die_parent
== NULL
)
17820 add_child_die (context_die
, old_die
);
17822 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17823 add_abstract_origin_attribute (subr_die
, origin
);
17824 /* This is where the actual code for a cloned function is.
17825 Let's emit linkage name attribute for it. This helps
17826 debuggers to e.g, set breakpoints into
17827 constructors/destructors when the user asks "break
17829 add_linkage_name (subr_die
, decl
);
17833 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17834 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17836 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17837 /* We can have a normal definition following an inline one in the
17838 case of redefinition of GNU C extern inlines.
17839 It seems reasonable to use AT_specification in this case. */
17840 && !get_AT (old_die
, DW_AT_inline
))
17842 /* Detect and ignore this case, where we are trying to output
17843 something we have already output. */
17847 /* If the definition comes from the same place as the declaration,
17848 maybe use the old DIE. We always want the DIE for this function
17849 that has the *_pc attributes to be under comp_unit_die so the
17850 debugger can find it. We also need to do this for abstract
17851 instances of inlines, since the spec requires the out-of-line copy
17852 to have the same parent. For local class methods, this doesn't
17853 apply; we just use the old DIE. */
17854 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17855 && (DECL_ARTIFICIAL (decl
)
17856 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17857 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17858 == (unsigned) s
.line
))))
17860 subr_die
= old_die
;
17862 /* Clear out the declaration attribute and the formal parameters.
17863 Do not remove all children, because it is possible that this
17864 declaration die was forced using force_decl_die(). In such
17865 cases die that forced declaration die (e.g. TAG_imported_module)
17866 is one of the children that we do not want to remove. */
17867 remove_AT (subr_die
, DW_AT_declaration
);
17868 remove_AT (subr_die
, DW_AT_object_pointer
);
17869 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17873 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17874 add_AT_specification (subr_die
, old_die
);
17875 add_pubname (decl
, subr_die
);
17876 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17877 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17878 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17879 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17884 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17886 if (TREE_PUBLIC (decl
))
17887 add_AT_flag (subr_die
, DW_AT_external
, 1);
17889 add_name_and_src_coords_attributes (subr_die
, decl
);
17890 add_pubname (decl
, subr_die
);
17891 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17893 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17894 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17895 0, 0, context_die
);
17898 add_pure_or_virtual_attribute (subr_die
, decl
);
17899 if (DECL_ARTIFICIAL (decl
))
17900 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17902 add_accessibility_attribute (subr_die
, decl
);
17907 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17909 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17911 /* If this is an explicit function declaration then generate
17912 a DW_AT_explicit attribute. */
17913 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17914 && (dwarf_version
>= 3 || !dwarf_strict
))
17915 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17917 /* The first time we see a member function, it is in the context of
17918 the class to which it belongs. We make sure of this by emitting
17919 the class first. The next time is the definition, which is
17920 handled above. The two may come from the same source text.
17922 Note that force_decl_die() forces function declaration die. It is
17923 later reused to represent definition. */
17924 equate_decl_number_to_die (decl
, subr_die
);
17927 else if (DECL_ABSTRACT (decl
))
17929 if (DECL_DECLARED_INLINE_P (decl
))
17931 if (cgraph_function_possibly_inlined_p (decl
))
17932 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17934 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17938 if (cgraph_function_possibly_inlined_p (decl
))
17939 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17941 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17944 if (DECL_DECLARED_INLINE_P (decl
)
17945 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17946 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17948 equate_decl_number_to_die (decl
, subr_die
);
17950 else if (!DECL_EXTERNAL (decl
))
17952 HOST_WIDE_INT cfa_fb_offset
;
17953 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
17955 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17956 equate_decl_number_to_die (decl
, subr_die
);
17958 gcc_checking_assert (fun
);
17959 if (!flag_reorder_blocks_and_partition
)
17961 dw_fde_ref fde
= fun
->fde
;
17962 if (fde
->dw_fde_begin
)
17964 /* We have already generated the labels. */
17965 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17966 fde
->dw_fde_end
, false);
17970 /* Create start/end labels and add the range. */
17971 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
17972 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17973 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
17974 current_function_funcdef_no
);
17975 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
17976 current_function_funcdef_no
);
17977 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
17981 #if VMS_DEBUGGING_INFO
17982 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17983 Section 2.3 Prologue and Epilogue Attributes:
17984 When a breakpoint is set on entry to a function, it is generally
17985 desirable for execution to be suspended, not on the very first
17986 instruction of the function, but rather at a point after the
17987 function's frame has been set up, after any language defined local
17988 declaration processing has been completed, and before execution of
17989 the first statement of the function begins. Debuggers generally
17990 cannot properly determine where this point is. Similarly for a
17991 breakpoint set on exit from a function. The prologue and epilogue
17992 attributes allow a compiler to communicate the location(s) to use. */
17995 if (fde
->dw_fde_vms_end_prologue
)
17996 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17997 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17999 if (fde
->dw_fde_vms_begin_epilogue
)
18000 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18001 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18008 /* Generate pubnames entries for the split function code ranges. */
18009 dw_fde_ref fde
= fun
->fde
;
18011 if (fde
->dw_fde_second_begin
)
18013 if (dwarf_version
>= 3 || !dwarf_strict
)
18015 /* We should use ranges for non-contiguous code section
18016 addresses. Use the actual code range for the initial
18017 section, since the HOT/COLD labels might precede an
18018 alignment offset. */
18019 bool range_list_added
= false;
18020 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18021 fde
->dw_fde_end
, &range_list_added
,
18023 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18024 fde
->dw_fde_second_end
,
18025 &range_list_added
, false);
18026 if (range_list_added
)
18031 /* There is no real support in DW2 for this .. so we make
18032 a work-around. First, emit the pub name for the segment
18033 containing the function label. Then make and emit a
18034 simplified subprogram DIE for the second segment with the
18035 name pre-fixed by __hot/cold_sect_of_. We use the same
18036 linkage name for the second die so that gdb will find both
18037 sections when given "b foo". */
18038 const char *name
= NULL
;
18039 tree decl_name
= DECL_NAME (decl
);
18040 dw_die_ref seg_die
;
18042 /* Do the 'primary' section. */
18043 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18044 fde
->dw_fde_end
, false);
18046 /* Build a minimal DIE for the secondary section. */
18047 seg_die
= new_die (DW_TAG_subprogram
,
18048 subr_die
->die_parent
, decl
);
18050 if (TREE_PUBLIC (decl
))
18051 add_AT_flag (seg_die
, DW_AT_external
, 1);
18053 if (decl_name
!= NULL
18054 && IDENTIFIER_POINTER (decl_name
) != NULL
)
18056 name
= dwarf2_name (decl
, 1);
18057 if (! DECL_ARTIFICIAL (decl
))
18058 add_src_coords_attributes (seg_die
, decl
);
18060 add_linkage_name (seg_die
, decl
);
18062 gcc_assert (name
!= NULL
);
18063 add_pure_or_virtual_attribute (seg_die
, decl
);
18064 if (DECL_ARTIFICIAL (decl
))
18065 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
18067 name
= concat ("__second_sect_of_", name
, NULL
);
18068 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
18069 fde
->dw_fde_second_end
, false);
18070 add_name_attribute (seg_die
, name
);
18071 if (want_pubnames ())
18072 add_pubname_string (name
, seg_die
);
18076 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
18080 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18082 /* We define the "frame base" as the function's CFA. This is more
18083 convenient for several reasons: (1) It's stable across the prologue
18084 and epilogue, which makes it better than just a frame pointer,
18085 (2) With dwarf3, there exists a one-byte encoding that allows us
18086 to reference the .debug_frame data by proxy, but failing that,
18087 (3) We can at least reuse the code inspection and interpretation
18088 code that determines the CFA position at various points in the
18090 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18092 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18093 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18097 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18098 if (list
->dw_loc_next
)
18099 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18101 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18104 /* Compute a displacement from the "steady-state frame pointer" to
18105 the CFA. The former is what all stack slots and argument slots
18106 will reference in the rtl; the latter is what we've told the
18107 debugger about. We'll need to adjust all frame_base references
18108 by this displacement. */
18109 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18111 if (fun
->static_chain_decl
)
18112 add_AT_location_description (subr_die
, DW_AT_static_link
,
18113 loc_list_from_tree (fun
->static_chain_decl
, 2));
18116 /* Generate child dies for template paramaters. */
18117 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18118 gen_generic_params_dies (decl
);
18120 /* Now output descriptions of the arguments for this function. This gets
18121 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18122 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18123 `...' at the end of the formal parameter list. In order to find out if
18124 there was a trailing ellipsis or not, we must instead look at the type
18125 associated with the FUNCTION_DECL. This will be a node of type
18126 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18127 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18128 an ellipsis at the end. */
18130 /* In the case where we are describing a mere function declaration, all we
18131 need to do here (and all we *can* do here) is to describe the *types* of
18132 its formal parameters. */
18133 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18135 else if (declaration
)
18136 gen_formal_types_die (decl
, subr_die
);
18139 /* Generate DIEs to represent all known formal parameters. */
18140 tree parm
= DECL_ARGUMENTS (decl
);
18141 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18142 tree generic_decl_parm
= generic_decl
18143 ? DECL_ARGUMENTS (generic_decl
)
18146 /* Now we want to walk the list of parameters of the function and
18147 emit their relevant DIEs.
18149 We consider the case of DECL being an instance of a generic function
18150 as well as it being a normal function.
18152 If DECL is an instance of a generic function we walk the
18153 parameters of the generic function declaration _and_ the parameters of
18154 DECL itself. This is useful because we want to emit specific DIEs for
18155 function parameter packs and those are declared as part of the
18156 generic function declaration. In that particular case,
18157 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18158 That DIE has children DIEs representing the set of arguments
18159 of the pack. Note that the set of pack arguments can be empty.
18160 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18163 Otherwise, we just consider the parameters of DECL. */
18164 while (generic_decl_parm
|| parm
)
18166 if (generic_decl_parm
18167 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18168 gen_formal_parameter_pack_die (generic_decl_parm
,
18173 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18175 if (parm
== DECL_ARGUMENTS (decl
)
18176 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18178 && (dwarf_version
>= 3 || !dwarf_strict
))
18179 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18181 parm
= DECL_CHAIN (parm
);
18184 if (generic_decl_parm
)
18185 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18188 /* Decide whether we need an unspecified_parameters DIE at the end.
18189 There are 2 more cases to do this for: 1) the ansi ... declaration -
18190 this is detectable when the end of the arg list is not a
18191 void_type_node 2) an unprototyped function declaration (not a
18192 definition). This just means that we have no info about the
18193 parameters at all. */
18194 if (prototype_p (TREE_TYPE (decl
)))
18196 /* This is the prototyped case, check for.... */
18197 if (stdarg_p (TREE_TYPE (decl
)))
18198 gen_unspecified_parameters_die (decl
, subr_die
);
18200 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18201 gen_unspecified_parameters_die (decl
, subr_die
);
18204 /* Output Dwarf info for all of the stuff within the body of the function
18205 (if it has one - it may be just a declaration). */
18206 outer_scope
= DECL_INITIAL (decl
);
18208 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18209 a function. This BLOCK actually represents the outermost binding contour
18210 for the function, i.e. the contour in which the function's formal
18211 parameters and labels get declared. Curiously, it appears that the front
18212 end doesn't actually put the PARM_DECL nodes for the current function onto
18213 the BLOCK_VARS list for this outer scope, but are strung off of the
18214 DECL_ARGUMENTS list for the function instead.
18216 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18217 the LABEL_DECL nodes for the function however, and we output DWARF info
18218 for those in decls_for_scope. Just within the `outer_scope' there will be
18219 a BLOCK node representing the function's outermost pair of curly braces,
18220 and any blocks used for the base and member initializers of a C++
18221 constructor function. */
18222 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18224 int call_site_note_count
= 0;
18225 int tail_call_site_note_count
= 0;
18227 /* Emit a DW_TAG_variable DIE for a named return value. */
18228 if (DECL_NAME (DECL_RESULT (decl
)))
18229 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18231 current_function_has_inlines
= 0;
18232 decls_for_scope (outer_scope
, subr_die
, 0);
18234 if (call_arg_locations
&& !dwarf_strict
)
18236 struct call_arg_loc_node
*ca_loc
;
18237 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18239 dw_die_ref die
= NULL
;
18240 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18243 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18244 arg
; arg
= next_arg
)
18246 dw_loc_descr_ref reg
, val
;
18247 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18248 dw_die_ref cdie
, tdie
= NULL
;
18250 next_arg
= XEXP (arg
, 1);
18251 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18253 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18254 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18255 && REGNO (XEXP (XEXP (arg
, 0), 0))
18256 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18257 next_arg
= XEXP (next_arg
, 1);
18258 if (mode
== VOIDmode
)
18260 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18261 if (mode
== VOIDmode
)
18262 mode
= GET_MODE (XEXP (arg
, 0));
18264 if (mode
== VOIDmode
|| mode
== BLKmode
)
18266 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18268 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18269 tloc
= XEXP (XEXP (arg
, 0), 1);
18272 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18273 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18275 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18276 tlocc
= XEXP (XEXP (arg
, 0), 1);
18280 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18281 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18282 VAR_INIT_STATUS_INITIALIZED
);
18283 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18285 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18286 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18287 get_address_mode (mem
),
18289 VAR_INIT_STATUS_INITIALIZED
);
18291 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18292 == DEBUG_PARAMETER_REF
)
18295 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18296 tdie
= lookup_decl_die (tdecl
);
18303 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18304 != DEBUG_PARAMETER_REF
)
18306 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18308 VAR_INIT_STATUS_INITIALIZED
);
18312 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18313 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18316 add_AT_loc (cdie
, DW_AT_location
, reg
);
18317 else if (tdie
!= NULL
)
18318 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18319 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18320 if (next_arg
!= XEXP (arg
, 1))
18322 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18323 if (mode
== VOIDmode
)
18324 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18325 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18328 VAR_INIT_STATUS_INITIALIZED
);
18330 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18334 && (ca_loc
->symbol_ref
|| tloc
))
18335 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18336 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18338 dw_loc_descr_ref tval
= NULL
;
18340 if (tloc
!= NULL_RTX
)
18341 tval
= mem_loc_descriptor (tloc
,
18342 GET_MODE (tloc
) == VOIDmode
18343 ? Pmode
: GET_MODE (tloc
),
18345 VAR_INIT_STATUS_INITIALIZED
);
18347 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18348 else if (tlocc
!= NULL_RTX
)
18350 tval
= mem_loc_descriptor (tlocc
,
18351 GET_MODE (tlocc
) == VOIDmode
18352 ? Pmode
: GET_MODE (tlocc
),
18354 VAR_INIT_STATUS_INITIALIZED
);
18356 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18362 call_site_note_count
++;
18363 if (ca_loc
->tail_call_p
)
18364 tail_call_site_note_count
++;
18368 call_arg_locations
= NULL
;
18369 call_arg_loc_last
= NULL
;
18370 if (tail_call_site_count
>= 0
18371 && tail_call_site_count
== tail_call_site_note_count
18374 if (call_site_count
>= 0
18375 && call_site_count
== call_site_note_count
)
18376 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18378 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18380 call_site_count
= -1;
18381 tail_call_site_count
= -1;
18383 /* Add the calling convention attribute if requested. */
18384 add_calling_convention_attribute (subr_die
, decl
);
18388 /* Returns a hash value for X (which really is a die_struct). */
18391 common_block_die_table_hash (const void *x
)
18393 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18394 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18397 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18398 as decl_id and die_parent of die_struct Y. */
18401 common_block_die_table_eq (const void *x
, const void *y
)
18403 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18404 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18405 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18408 /* Generate a DIE to represent a declared data object.
18409 Either DECL or ORIGIN must be non-null. */
18412 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18414 HOST_WIDE_INT off
= 0;
18416 tree decl_or_origin
= decl
? decl
: origin
;
18417 tree ultimate_origin
;
18418 dw_die_ref var_die
;
18419 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18420 dw_die_ref origin_die
;
18421 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18422 || class_or_namespace_scope_p (context_die
));
18423 bool specialization_p
= false;
18425 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18426 if (decl
|| ultimate_origin
)
18427 origin
= ultimate_origin
;
18428 com_decl
= fortran_common (decl_or_origin
, &off
);
18430 /* Symbol in common gets emitted as a child of the common block, in the form
18431 of a data member. */
18434 dw_die_ref com_die
;
18435 dw_loc_list_ref loc
;
18436 die_node com_die_arg
;
18438 var_die
= lookup_decl_die (decl_or_origin
);
18441 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18443 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18448 /* Optimize the common case. */
18449 if (single_element_loc_list_p (loc
)
18450 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18451 && loc
->expr
->dw_loc_next
== NULL
18452 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18455 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18456 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18457 = plus_constant (GET_MODE (x
), x
, off
);
18460 loc_list_plus_const (loc
, off
);
18462 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18463 remove_AT (var_die
, DW_AT_declaration
);
18469 if (common_block_die_table
== NULL
)
18470 common_block_die_table
18471 = htab_create_ggc (10, common_block_die_table_hash
,
18472 common_block_die_table_eq
, NULL
);
18474 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18475 com_die_arg
.die_parent
= context_die
;
18476 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18477 loc
= loc_list_from_tree (com_decl
, 2);
18478 if (com_die
== NULL
)
18481 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18484 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18485 add_name_and_src_coords_attributes (com_die
, com_decl
);
18488 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18489 /* Avoid sharing the same loc descriptor between
18490 DW_TAG_common_block and DW_TAG_variable. */
18491 loc
= loc_list_from_tree (com_decl
, 2);
18493 else if (DECL_EXTERNAL (decl
))
18494 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18495 if (want_pubnames ())
18496 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18497 com_die
->decl_id
= DECL_UID (com_decl
);
18498 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18499 *slot
= (void *) com_die
;
18501 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18503 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18504 loc
= loc_list_from_tree (com_decl
, 2);
18505 remove_AT (com_die
, DW_AT_declaration
);
18507 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18508 add_name_and_src_coords_attributes (var_die
, decl
);
18509 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18510 TREE_THIS_VOLATILE (decl
), context_die
);
18511 add_AT_flag (var_die
, DW_AT_external
, 1);
18516 /* Optimize the common case. */
18517 if (single_element_loc_list_p (loc
)
18518 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18519 && loc
->expr
->dw_loc_next
== NULL
18520 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18522 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18523 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18524 = plus_constant (GET_MODE (x
), x
, off
);
18527 loc_list_plus_const (loc
, off
);
18529 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18531 else if (DECL_EXTERNAL (decl
))
18532 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18533 equate_decl_number_to_die (decl
, var_die
);
18537 /* If the compiler emitted a definition for the DECL declaration
18538 and if we already emitted a DIE for it, don't emit a second
18539 DIE for it again. Allow re-declarations of DECLs that are
18540 inside functions, though. */
18541 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18544 /* For static data members, the declaration in the class is supposed
18545 to have DW_TAG_member tag; the specification should still be
18546 DW_TAG_variable referencing the DW_TAG_member DIE. */
18547 if (declaration
&& class_scope_p (context_die
))
18548 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18550 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18553 if (origin
!= NULL
)
18554 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18556 /* Loop unrolling can create multiple blocks that refer to the same
18557 static variable, so we must test for the DW_AT_declaration flag.
18559 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18560 copy decls and set the DECL_ABSTRACT flag on them instead of
18563 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18565 ??? The declare_in_namespace support causes us to get two DIEs for one
18566 variable, both of which are declarations. We want to avoid considering
18567 one to be a specification, so we must test that this DIE is not a
18569 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18570 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18572 /* This is a definition of a C++ class level static. */
18573 add_AT_specification (var_die
, old_die
);
18574 specialization_p
= true;
18575 if (DECL_NAME (decl
))
18577 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18578 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18580 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18581 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18583 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18584 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18586 if (old_die
->die_tag
== DW_TAG_member
)
18587 add_linkage_name (var_die
, decl
);
18591 add_name_and_src_coords_attributes (var_die
, decl
);
18593 if ((origin
== NULL
&& !specialization_p
)
18595 && !DECL_ABSTRACT (decl_or_origin
)
18596 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18597 decl_function_context
18598 (decl_or_origin
))))
18600 tree type
= TREE_TYPE (decl_or_origin
);
18602 if (decl_by_reference_p (decl_or_origin
))
18603 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18605 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18606 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18609 if (origin
== NULL
&& !specialization_p
)
18611 if (TREE_PUBLIC (decl
))
18612 add_AT_flag (var_die
, DW_AT_external
, 1);
18614 if (DECL_ARTIFICIAL (decl
))
18615 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18617 add_accessibility_attribute (var_die
, decl
);
18621 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18623 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18624 equate_decl_number_to_die (decl
, var_die
);
18627 && (! DECL_ABSTRACT (decl_or_origin
)
18628 /* Local static vars are shared between all clones/inlines,
18629 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18631 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18632 && TREE_STATIC (decl_or_origin
)
18633 && DECL_RTL_SET_P (decl_or_origin
)))
18634 /* When abstract origin already has DW_AT_location attribute, no need
18635 to add it again. */
18636 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18638 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18639 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18640 defer_location (decl_or_origin
, var_die
);
18642 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18643 decl
== NULL
, DW_AT_location
);
18644 add_pubname (decl_or_origin
, var_die
);
18647 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18650 /* Generate a DIE to represent a named constant. */
18653 gen_const_die (tree decl
, dw_die_ref context_die
)
18655 dw_die_ref const_die
;
18656 tree type
= TREE_TYPE (decl
);
18658 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18659 add_name_and_src_coords_attributes (const_die
, decl
);
18660 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18661 if (TREE_PUBLIC (decl
))
18662 add_AT_flag (const_die
, DW_AT_external
, 1);
18663 if (DECL_ARTIFICIAL (decl
))
18664 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18665 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18668 /* Generate a DIE to represent a label identifier. */
18671 gen_label_die (tree decl
, dw_die_ref context_die
)
18673 tree origin
= decl_ultimate_origin (decl
);
18674 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18676 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18678 if (origin
!= NULL
)
18679 add_abstract_origin_attribute (lbl_die
, origin
);
18681 add_name_and_src_coords_attributes (lbl_die
, decl
);
18683 if (DECL_ABSTRACT (decl
))
18684 equate_decl_number_to_die (decl
, lbl_die
);
18687 insn
= DECL_RTL_IF_SET (decl
);
18689 /* Deleted labels are programmer specified labels which have been
18690 eliminated because of various optimizations. We still emit them
18691 here so that it is possible to put breakpoints on them. */
18695 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18697 /* When optimization is enabled (via -O) some parts of the compiler
18698 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18699 represent source-level labels which were explicitly declared by
18700 the user. This really shouldn't be happening though, so catch
18701 it if it ever does happen. */
18702 gcc_assert (!INSN_DELETED_P (insn
));
18704 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18705 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18709 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18710 && CODE_LABEL_NUMBER (insn
) != -1)
18712 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18713 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18718 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18719 attributes to the DIE for a block STMT, to describe where the inlined
18720 function was called from. This is similar to add_src_coords_attributes. */
18723 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18725 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18727 if (dwarf_version
>= 3 || !dwarf_strict
)
18729 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18730 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18735 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18736 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18739 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18741 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18743 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18744 && (dwarf_version
>= 3 || !dwarf_strict
))
18746 tree chain
, superblock
= NULL_TREE
;
18748 dw_attr_ref attr
= NULL
;
18750 if (inlined_function_outer_scope_p (stmt
))
18752 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18753 BLOCK_NUMBER (stmt
));
18754 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18757 /* Optimize duplicate .debug_ranges lists or even tails of
18758 lists. If this BLOCK has same ranges as its supercontext,
18759 lookup DW_AT_ranges attribute in the supercontext (and
18760 recursively so), verify that the ranges_table contains the
18761 right values and use it instead of adding a new .debug_range. */
18762 for (chain
= stmt
, pdie
= die
;
18763 BLOCK_SAME_RANGE (chain
);
18764 chain
= BLOCK_SUPERCONTEXT (chain
))
18766 dw_attr_ref new_attr
;
18768 pdie
= pdie
->die_parent
;
18771 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18773 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18774 if (new_attr
== NULL
18775 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18778 superblock
= BLOCK_SUPERCONTEXT (chain
);
18781 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18782 / 2 / DWARF2_ADDR_SIZE
].num
18783 == BLOCK_NUMBER (superblock
))
18784 && BLOCK_FRAGMENT_CHAIN (superblock
))
18786 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18787 / 2 / DWARF2_ADDR_SIZE
;
18788 unsigned long supercnt
= 0, thiscnt
= 0;
18789 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18790 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18793 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18794 == BLOCK_NUMBER (chain
));
18796 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18797 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18798 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18800 gcc_assert (supercnt
>= thiscnt
);
18801 add_AT_range_list (die
, DW_AT_ranges
,
18802 ((off
+ supercnt
- thiscnt
)
18803 * 2 * DWARF2_ADDR_SIZE
),
18808 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18810 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18813 add_ranges (chain
);
18814 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18821 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18822 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18823 BLOCK_NUMBER (stmt
));
18824 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18825 BLOCK_NUMBER (stmt
));
18826 add_AT_low_high_pc (die
, label
, label_high
, false);
18830 /* Generate a DIE for a lexical block. */
18833 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18835 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18837 if (call_arg_locations
)
18839 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18840 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18841 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18844 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18845 add_high_low_attributes (stmt
, stmt_die
);
18847 decls_for_scope (stmt
, stmt_die
, depth
);
18850 /* Generate a DIE for an inlined subprogram. */
18853 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18857 /* The instance of function that is effectively being inlined shall not
18859 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18861 decl
= block_ultimate_origin (stmt
);
18863 /* Emit info for the abstract instance first, if we haven't yet. We
18864 must emit this even if the block is abstract, otherwise when we
18865 emit the block below (or elsewhere), we may end up trying to emit
18866 a die whose origin die hasn't been emitted, and crashing. */
18867 dwarf2out_abstract_function (decl
);
18869 if (! BLOCK_ABSTRACT (stmt
))
18871 dw_die_ref subr_die
18872 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18874 if (call_arg_locations
)
18876 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18877 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18878 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18880 add_abstract_origin_attribute (subr_die
, decl
);
18881 if (TREE_ASM_WRITTEN (stmt
))
18882 add_high_low_attributes (stmt
, subr_die
);
18883 add_call_src_coords_attributes (stmt
, subr_die
);
18885 decls_for_scope (stmt
, subr_die
, depth
);
18886 current_function_has_inlines
= 1;
18890 /* Generate a DIE for a field in a record, or structure. */
18893 gen_field_die (tree decl
, dw_die_ref context_die
)
18895 dw_die_ref decl_die
;
18897 if (TREE_TYPE (decl
) == error_mark_node
)
18900 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18901 add_name_and_src_coords_attributes (decl_die
, decl
);
18902 add_type_attribute (decl_die
, member_declared_type (decl
),
18903 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18906 if (DECL_BIT_FIELD_TYPE (decl
))
18908 add_byte_size_attribute (decl_die
, decl
);
18909 add_bit_size_attribute (decl_die
, decl
);
18910 add_bit_offset_attribute (decl_die
, decl
);
18913 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18914 add_data_member_location_attribute (decl_die
, decl
);
18916 if (DECL_ARTIFICIAL (decl
))
18917 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18919 add_accessibility_attribute (decl_die
, decl
);
18921 /* Equate decl number to die, so that we can look up this decl later on. */
18922 equate_decl_number_to_die (decl
, decl_die
);
18926 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18927 Use modified_type_die instead.
18928 We keep this code here just in case these types of DIEs may be needed to
18929 represent certain things in other languages (e.g. Pascal) someday. */
18932 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18935 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18937 equate_type_number_to_die (type
, ptr_die
);
18938 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18939 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18942 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18943 Use modified_type_die instead.
18944 We keep this code here just in case these types of DIEs may be needed to
18945 represent certain things in other languages (e.g. Pascal) someday. */
18948 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18950 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18952 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18953 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18955 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18957 equate_type_number_to_die (type
, ref_die
);
18958 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18959 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18963 /* Generate a DIE for a pointer to a member type. */
18966 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18969 = new_die (DW_TAG_ptr_to_member_type
,
18970 scope_die_for (type
, context_die
), type
);
18972 equate_type_number_to_die (type
, ptr_die
);
18973 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18974 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18975 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18978 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18980 static char *producer_string
;
18982 /* Return a heap allocated producer string including command line options
18983 if -grecord-gcc-switches. */
18986 gen_producer_string (void)
18989 vec
<dchar_p
> switches
= vNULL
;
18990 const char *language_string
= lang_hooks
.name
;
18991 char *producer
, *tail
;
18993 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18994 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18996 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18997 switch (save_decoded_options
[j
].opt_index
)
19004 case OPT_auxbase_strip
:
19013 case OPT_SPECIAL_unknown
:
19014 case OPT_SPECIAL_ignore
:
19015 case OPT_SPECIAL_program_name
:
19016 case OPT_SPECIAL_input_file
:
19017 case OPT_grecord_gcc_switches
:
19018 case OPT_gno_record_gcc_switches
:
19019 case OPT__output_pch_
:
19020 case OPT_fdiagnostics_show_location_
:
19021 case OPT_fdiagnostics_show_option
:
19022 case OPT_fdiagnostics_show_caret
:
19023 case OPT_fdiagnostics_color_
:
19024 case OPT_fverbose_asm
:
19026 case OPT__sysroot_
:
19028 case OPT_nostdinc__
:
19029 /* Ignore these. */
19032 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
19033 & CL_NO_DWARF_RECORD
)
19035 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
19037 switch (save_decoded_options
[j
].canonical_option
[0][1])
19044 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
19051 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
19052 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
19056 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
19058 sprintf (tail
, "%s %s", language_string
, version_string
);
19061 FOR_EACH_VEC_ELT (switches
, j
, p
)
19065 memcpy (tail
+ 1, p
, len
);
19070 switches
.release ();
19074 /* Generate the DIE for the compilation unit. */
19077 gen_compile_unit_die (const char *filename
)
19080 const char *language_string
= lang_hooks
.name
;
19083 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19087 add_name_attribute (die
, filename
);
19088 /* Don't add cwd for <built-in>. */
19089 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19090 add_comp_dir_attribute (die
);
19093 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19095 /* If our producer is LTO try to figure out a common language to use
19096 from the global list of translation units. */
19097 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19101 const char *common_lang
= NULL
;
19103 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19105 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19108 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19109 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19111 else if (strncmp (common_lang
, "GNU C", 5) == 0
19112 && strncmp(TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19113 /* Mixing C and C++ is ok, use C++ in that case. */
19114 common_lang
= "GNU C++";
19117 /* Fall back to C. */
19118 common_lang
= NULL
;
19124 language_string
= common_lang
;
19127 language
= DW_LANG_C89
;
19128 if (strcmp (language_string
, "GNU C++") == 0)
19129 language
= DW_LANG_C_plus_plus
;
19130 else if (strcmp (language_string
, "GNU F77") == 0)
19131 language
= DW_LANG_Fortran77
;
19132 else if (strcmp (language_string
, "GNU Pascal") == 0)
19133 language
= DW_LANG_Pascal83
;
19134 else if (dwarf_version
>= 3 || !dwarf_strict
)
19136 if (strcmp (language_string
, "GNU Ada") == 0)
19137 language
= DW_LANG_Ada95
;
19138 else if (strcmp (language_string
, "GNU Fortran") == 0)
19139 language
= DW_LANG_Fortran95
;
19140 else if (strcmp (language_string
, "GNU Java") == 0)
19141 language
= DW_LANG_Java
;
19142 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19143 language
= DW_LANG_ObjC
;
19144 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19145 language
= DW_LANG_ObjC_plus_plus
;
19146 else if (dwarf_version
>= 5 || !dwarf_strict
)
19148 if (strcmp (language_string
, "GNU Go") == 0)
19149 language
= DW_LANG_Go
;
19152 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19153 else if (strcmp (language_string
, "GNU Fortran") == 0)
19154 language
= DW_LANG_Fortran90
;
19156 add_AT_unsigned (die
, DW_AT_language
, language
);
19160 case DW_LANG_Fortran77
:
19161 case DW_LANG_Fortran90
:
19162 case DW_LANG_Fortran95
:
19163 /* Fortran has case insensitive identifiers and the front-end
19164 lowercases everything. */
19165 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19168 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19174 /* Generate the DIE for a base class. */
19177 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19179 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19181 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19182 add_data_member_location_attribute (die
, binfo
);
19184 if (BINFO_VIRTUAL_P (binfo
))
19185 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19187 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19188 children, otherwise the default is DW_ACCESS_public. In DWARF2
19189 the default has always been DW_ACCESS_private. */
19190 if (access
== access_public_node
)
19192 if (dwarf_version
== 2
19193 || context_die
->die_tag
== DW_TAG_class_type
)
19194 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19196 else if (access
== access_protected_node
)
19197 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19198 else if (dwarf_version
> 2
19199 && context_die
->die_tag
!= DW_TAG_class_type
)
19200 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19203 /* Generate a DIE for a class member. */
19206 gen_member_die (tree type
, dw_die_ref context_die
)
19209 tree binfo
= TYPE_BINFO (type
);
19212 /* If this is not an incomplete type, output descriptions of each of its
19213 members. Note that as we output the DIEs necessary to represent the
19214 members of this record or union type, we will also be trying to output
19215 DIEs to represent the *types* of those members. However the `type'
19216 function (above) will specifically avoid generating type DIEs for member
19217 types *within* the list of member DIEs for this (containing) type except
19218 for those types (of members) which are explicitly marked as also being
19219 members of this (containing) type themselves. The g++ front- end can
19220 force any given type to be treated as a member of some other (containing)
19221 type by setting the TYPE_CONTEXT of the given (member) type to point to
19222 the TREE node representing the appropriate (containing) type. */
19224 /* First output info about the base classes. */
19227 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19231 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19232 gen_inheritance_die (base
,
19233 (accesses
? (*accesses
)[i
] : access_public_node
),
19237 /* Now output info about the data members and type members. */
19238 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19240 /* If we thought we were generating minimal debug info for TYPE
19241 and then changed our minds, some of the member declarations
19242 may have already been defined. Don't define them again, but
19243 do put them in the right order. */
19245 child
= lookup_decl_die (member
);
19247 splice_child_die (context_die
, child
);
19249 gen_decl_die (member
, NULL
, context_die
);
19252 /* Now output info about the function members (if any). */
19253 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19255 /* Don't include clones in the member list. */
19256 if (DECL_ABSTRACT_ORIGIN (member
))
19259 child
= lookup_decl_die (member
);
19261 splice_child_die (context_die
, child
);
19263 gen_decl_die (member
, NULL
, context_die
);
19267 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19268 is set, we pretend that the type was never defined, so we only get the
19269 member DIEs needed by later specification DIEs. */
19272 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19273 enum debug_info_usage usage
)
19275 dw_die_ref type_die
= lookup_type_die (type
);
19276 dw_die_ref scope_die
= 0;
19278 int complete
= (TYPE_SIZE (type
)
19279 && (! TYPE_STUB_DECL (type
)
19280 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19281 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19282 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19284 if (type_die
&& ! complete
)
19287 if (TYPE_CONTEXT (type
) != NULL_TREE
19288 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19289 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19292 scope_die
= scope_die_for (type
, context_die
);
19294 /* Generate child dies for template paramaters. */
19295 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19296 schedule_generic_params_dies_gen (type
);
19298 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19299 /* First occurrence of type or toplevel definition of nested class. */
19301 dw_die_ref old_die
= type_die
;
19303 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19304 ? record_type_tag (type
) : DW_TAG_union_type
,
19306 equate_type_number_to_die (type
, type_die
);
19308 add_AT_specification (type_die
, old_die
);
19310 add_name_attribute (type_die
, type_tag (type
));
19313 remove_AT (type_die
, DW_AT_declaration
);
19315 /* If this type has been completed, then give it a byte_size attribute and
19316 then give a list of members. */
19317 if (complete
&& !ns_decl
)
19319 /* Prevent infinite recursion in cases where the type of some member of
19320 this type is expressed in terms of this type itself. */
19321 TREE_ASM_WRITTEN (type
) = 1;
19322 add_byte_size_attribute (type_die
, type
);
19323 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19325 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19326 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19329 /* If the first reference to this type was as the return type of an
19330 inline function, then it may not have a parent. Fix this now. */
19331 if (type_die
->die_parent
== NULL
)
19332 add_child_die (scope_die
, type_die
);
19334 push_decl_scope (type
);
19335 gen_member_die (type
, type_die
);
19338 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19339 if (TYPE_ARTIFICIAL (type
))
19340 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19342 /* GNU extension: Record what type our vtable lives in. */
19343 if (TYPE_VFIELD (type
))
19345 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19347 gen_type_die (vtype
, context_die
);
19348 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19349 lookup_type_die (vtype
));
19354 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19356 /* We don't need to do this for function-local types. */
19357 if (TYPE_STUB_DECL (type
)
19358 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19359 vec_safe_push (incomplete_types
, type
);
19362 if (get_AT (type_die
, DW_AT_name
))
19363 add_pubtype (type
, type_die
);
19366 /* Generate a DIE for a subroutine _type_. */
19369 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19371 tree return_type
= TREE_TYPE (type
);
19372 dw_die_ref subr_die
19373 = new_die (DW_TAG_subroutine_type
,
19374 scope_die_for (type
, context_die
), type
);
19376 equate_type_number_to_die (type
, subr_die
);
19377 add_prototyped_attribute (subr_die
, type
);
19378 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19379 gen_formal_types_die (type
, subr_die
);
19381 if (get_AT (subr_die
, DW_AT_name
))
19382 add_pubtype (type
, subr_die
);
19385 /* Generate a DIE for a type definition. */
19388 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19390 dw_die_ref type_die
;
19393 if (TREE_ASM_WRITTEN (decl
))
19396 TREE_ASM_WRITTEN (decl
) = 1;
19397 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19398 origin
= decl_ultimate_origin (decl
);
19399 if (origin
!= NULL
)
19400 add_abstract_origin_attribute (type_die
, origin
);
19405 add_name_and_src_coords_attributes (type_die
, decl
);
19406 if (DECL_ORIGINAL_TYPE (decl
))
19408 type
= DECL_ORIGINAL_TYPE (decl
);
19410 gcc_assert (type
!= TREE_TYPE (decl
));
19411 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19415 type
= TREE_TYPE (decl
);
19417 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19419 /* Here, we are in the case of decl being a typedef naming
19420 an anonymous type, e.g:
19421 typedef struct {...} foo;
19422 In that case TREE_TYPE (decl) is not a typedef variant
19423 type and TYPE_NAME of the anonymous type is set to the
19424 TYPE_DECL of the typedef. This construct is emitted by
19427 TYPE is the anonymous struct named by the typedef
19428 DECL. As we need the DW_AT_type attribute of the
19429 DW_TAG_typedef to point to the DIE of TYPE, let's
19430 generate that DIE right away. add_type_attribute
19431 called below will then pick (via lookup_type_die) that
19432 anonymous struct DIE. */
19433 if (!TREE_ASM_WRITTEN (type
))
19434 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19436 /* This is a GNU Extension. We are adding a
19437 DW_AT_linkage_name attribute to the DIE of the
19438 anonymous struct TYPE. The value of that attribute
19439 is the name of the typedef decl naming the anonymous
19440 struct. This greatly eases the work of consumers of
19441 this debug info. */
19442 add_linkage_attr (lookup_type_die (type
), decl
);
19446 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19447 TREE_THIS_VOLATILE (decl
), context_die
);
19449 if (is_naming_typedef_decl (decl
))
19450 /* We want that all subsequent calls to lookup_type_die with
19451 TYPE in argument yield the DW_TAG_typedef we have just
19453 equate_type_number_to_die (type
, type_die
);
19455 add_accessibility_attribute (type_die
, decl
);
19458 if (DECL_ABSTRACT (decl
))
19459 equate_decl_number_to_die (decl
, type_die
);
19461 if (get_AT (type_die
, DW_AT_name
))
19462 add_pubtype (decl
, type_die
);
19465 /* Generate a DIE for a struct, class, enum or union type. */
19468 gen_tagged_type_die (tree type
,
19469 dw_die_ref context_die
,
19470 enum debug_info_usage usage
)
19474 if (type
== NULL_TREE
19475 || !is_tagged_type (type
))
19478 /* If this is a nested type whose containing class hasn't been written
19479 out yet, writing it out will cover this one, too. This does not apply
19480 to instantiations of member class templates; they need to be added to
19481 the containing class as they are generated. FIXME: This hurts the
19482 idea of combining type decls from multiple TUs, since we can't predict
19483 what set of template instantiations we'll get. */
19484 if (TYPE_CONTEXT (type
)
19485 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19486 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19488 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19490 if (TREE_ASM_WRITTEN (type
))
19493 /* If that failed, attach ourselves to the stub. */
19494 push_decl_scope (TYPE_CONTEXT (type
));
19495 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19498 else if (TYPE_CONTEXT (type
) != NULL_TREE
19499 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19501 /* If this type is local to a function that hasn't been written
19502 out yet, use a NULL context for now; it will be fixed up in
19503 decls_for_scope. */
19504 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19505 /* A declaration DIE doesn't count; nested types need to go in the
19507 if (context_die
&& is_declaration_die (context_die
))
19508 context_die
= NULL
;
19513 context_die
= declare_in_namespace (type
, context_die
);
19517 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19519 /* This might have been written out by the call to
19520 declare_in_namespace. */
19521 if (!TREE_ASM_WRITTEN (type
))
19522 gen_enumeration_type_die (type
, context_die
);
19525 gen_struct_or_union_type_die (type
, context_die
, usage
);
19530 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19531 it up if it is ever completed. gen_*_type_die will set it for us
19532 when appropriate. */
19535 /* Generate a type description DIE. */
19538 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19539 enum debug_info_usage usage
)
19541 struct array_descr_info info
;
19543 if (type
== NULL_TREE
|| type
== error_mark_node
)
19546 if (TYPE_NAME (type
) != NULL_TREE
19547 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19548 && is_redundant_typedef (TYPE_NAME (type
))
19549 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19550 /* The DECL of this type is a typedef we don't want to emit debug
19551 info for but we want debug info for its underlying typedef.
19552 This can happen for e.g, the injected-class-name of a C++
19554 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19556 /* If TYPE is a typedef type variant, let's generate debug info
19557 for the parent typedef which TYPE is a type of. */
19558 if (typedef_variant_p (type
))
19560 if (TREE_ASM_WRITTEN (type
))
19563 /* Prevent broken recursion; we can't hand off to the same type. */
19564 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19566 /* Give typedefs the right scope. */
19567 context_die
= scope_die_for (type
, context_die
);
19569 TREE_ASM_WRITTEN (type
) = 1;
19571 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19575 /* If type is an anonymous tagged type named by a typedef, let's
19576 generate debug info for the typedef. */
19577 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19579 /* Use the DIE of the containing namespace as the parent DIE of
19580 the type description DIE we want to generate. */
19581 if (DECL_CONTEXT (TYPE_NAME (type
))
19582 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19583 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19585 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19589 /* If this is an array type with hidden descriptor, handle it first. */
19590 if (!TREE_ASM_WRITTEN (type
)
19591 && lang_hooks
.types
.get_array_descr_info
19592 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19593 && (dwarf_version
>= 3 || !dwarf_strict
))
19595 gen_descr_array_type_die (type
, &info
, context_die
);
19596 TREE_ASM_WRITTEN (type
) = 1;
19600 /* We are going to output a DIE to represent the unqualified version
19601 of this type (i.e. without any const or volatile qualifiers) so
19602 get the main variant (i.e. the unqualified version) of this type
19603 now. (Vectors are special because the debugging info is in the
19604 cloned type itself). */
19605 if (TREE_CODE (type
) != VECTOR_TYPE
)
19606 type
= type_main_variant (type
);
19608 if (TREE_ASM_WRITTEN (type
))
19611 switch (TREE_CODE (type
))
19617 case REFERENCE_TYPE
:
19618 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19619 ensures that the gen_type_die recursion will terminate even if the
19620 type is recursive. Recursive types are possible in Ada. */
19621 /* ??? We could perhaps do this for all types before the switch
19623 TREE_ASM_WRITTEN (type
) = 1;
19625 /* For these types, all that is required is that we output a DIE (or a
19626 set of DIEs) to represent the "basis" type. */
19627 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19628 DINFO_USAGE_IND_USE
);
19632 /* This code is used for C++ pointer-to-data-member types.
19633 Output a description of the relevant class type. */
19634 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19635 DINFO_USAGE_IND_USE
);
19637 /* Output a description of the type of the object pointed to. */
19638 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19639 DINFO_USAGE_IND_USE
);
19641 /* Now output a DIE to represent this pointer-to-data-member type
19643 gen_ptr_to_mbr_type_die (type
, context_die
);
19646 case FUNCTION_TYPE
:
19647 /* Force out return type (in case it wasn't forced out already). */
19648 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19649 DINFO_USAGE_DIR_USE
);
19650 gen_subroutine_type_die (type
, context_die
);
19654 /* Force out return type (in case it wasn't forced out already). */
19655 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19656 DINFO_USAGE_DIR_USE
);
19657 gen_subroutine_type_die (type
, context_die
);
19661 gen_array_type_die (type
, context_die
);
19665 gen_array_type_die (type
, context_die
);
19668 case ENUMERAL_TYPE
:
19671 case QUAL_UNION_TYPE
:
19672 gen_tagged_type_die (type
, context_die
, usage
);
19678 case FIXED_POINT_TYPE
:
19681 /* No DIEs needed for fundamental types. */
19686 /* Just use DW_TAG_unspecified_type. */
19688 dw_die_ref type_die
= lookup_type_die (type
);
19689 if (type_die
== NULL
)
19691 tree name
= TYPE_NAME (type
);
19692 if (TREE_CODE (name
) == TYPE_DECL
)
19693 name
= DECL_NAME (name
);
19694 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19695 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19696 equate_type_number_to_die (type
, type_die
);
19702 gcc_unreachable ();
19705 TREE_ASM_WRITTEN (type
) = 1;
19709 gen_type_die (tree type
, dw_die_ref context_die
)
19711 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19714 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19715 things which are local to the given block. */
19718 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19720 int must_output_die
= 0;
19723 /* Ignore blocks that are NULL. */
19724 if (stmt
== NULL_TREE
)
19727 inlined_func
= inlined_function_outer_scope_p (stmt
);
19729 /* If the block is one fragment of a non-contiguous block, do not
19730 process the variables, since they will have been done by the
19731 origin block. Do process subblocks. */
19732 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19736 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19737 gen_block_die (sub
, context_die
, depth
+ 1);
19742 /* Determine if we need to output any Dwarf DIEs at all to represent this
19745 /* The outer scopes for inlinings *must* always be represented. We
19746 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19747 must_output_die
= 1;
19750 /* Determine if this block directly contains any "significant"
19751 local declarations which we will need to output DIEs for. */
19752 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19753 /* We are not in terse mode so *any* local declaration counts
19754 as being a "significant" one. */
19755 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19756 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19757 && (TREE_USED (stmt
)
19758 || TREE_ASM_WRITTEN (stmt
)
19759 || BLOCK_ABSTRACT (stmt
)));
19760 else if ((TREE_USED (stmt
)
19761 || TREE_ASM_WRITTEN (stmt
)
19762 || BLOCK_ABSTRACT (stmt
))
19763 && !dwarf2out_ignore_block (stmt
))
19764 must_output_die
= 1;
19767 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19768 DIE for any block which contains no significant local declarations at
19769 all. Rather, in such cases we just call `decls_for_scope' so that any
19770 needed Dwarf info for any sub-blocks will get properly generated. Note
19771 that in terse mode, our definition of what constitutes a "significant"
19772 local declaration gets restricted to include only inlined function
19773 instances and local (nested) function definitions. */
19774 if (must_output_die
)
19778 /* If STMT block is abstract, that means we have been called
19779 indirectly from dwarf2out_abstract_function.
19780 That function rightfully marks the descendent blocks (of
19781 the abstract function it is dealing with) as being abstract,
19782 precisely to prevent us from emitting any
19783 DW_TAG_inlined_subroutine DIE as a descendent
19784 of an abstract function instance. So in that case, we should
19785 not call gen_inlined_subroutine_die.
19787 Later though, when cgraph asks dwarf2out to emit info
19788 for the concrete instance of the function decl into which
19789 the concrete instance of STMT got inlined, the later will lead
19790 to the generation of a DW_TAG_inlined_subroutine DIE. */
19791 if (! BLOCK_ABSTRACT (stmt
))
19792 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19795 gen_lexical_block_die (stmt
, context_die
, depth
);
19798 decls_for_scope (stmt
, context_die
, depth
);
19801 /* Process variable DECL (or variable with origin ORIGIN) within
19802 block STMT and add it to CONTEXT_DIE. */
19804 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19807 tree decl_or_origin
= decl
? decl
: origin
;
19809 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19810 die
= lookup_decl_die (decl_or_origin
);
19811 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19812 && TYPE_DECL_IS_STUB (decl_or_origin
))
19813 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19817 if (die
!= NULL
&& die
->die_parent
== NULL
)
19818 add_child_die (context_die
, die
);
19819 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19820 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19821 stmt
, context_die
);
19823 gen_decl_die (decl
, origin
, context_die
);
19826 /* Generate all of the decls declared within a given scope and (recursively)
19827 all of its sub-blocks. */
19830 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19836 /* Ignore NULL blocks. */
19837 if (stmt
== NULL_TREE
)
19840 /* Output the DIEs to represent all of the data objects and typedefs
19841 declared directly within this block but not within any nested
19842 sub-blocks. Also, nested function and tag DIEs have been
19843 generated with a parent of NULL; fix that up now. */
19844 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19845 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19846 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19847 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19850 /* If we're at -g1, we're not interested in subblocks. */
19851 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19854 /* Output the DIEs to represent all sub-blocks (and the items declared
19855 therein) of this block. */
19856 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19858 subblocks
= BLOCK_CHAIN (subblocks
))
19859 gen_block_die (subblocks
, context_die
, depth
+ 1);
19862 /* Is this a typedef we can avoid emitting? */
19865 is_redundant_typedef (const_tree decl
)
19867 if (TYPE_DECL_IS_STUB (decl
))
19870 if (DECL_ARTIFICIAL (decl
)
19871 && DECL_CONTEXT (decl
)
19872 && is_tagged_type (DECL_CONTEXT (decl
))
19873 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19874 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19875 /* Also ignore the artificial member typedef for the class name. */
19881 /* Return TRUE if TYPE is a typedef that names a type for linkage
19882 purposes. This kind of typedefs is produced by the C++ FE for
19885 typedef struct {...} foo;
19887 In that case, there is no typedef variant type produced for foo.
19888 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19892 is_naming_typedef_decl (const_tree decl
)
19894 if (decl
== NULL_TREE
19895 || TREE_CODE (decl
) != TYPE_DECL
19896 || !is_tagged_type (TREE_TYPE (decl
))
19897 || DECL_IS_BUILTIN (decl
)
19898 || is_redundant_typedef (decl
)
19899 /* It looks like Ada produces TYPE_DECLs that are very similar
19900 to C++ naming typedefs but that have different
19901 semantics. Let's be specific to c++ for now. */
19905 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19906 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19907 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19908 != TYPE_NAME (TREE_TYPE (decl
))));
19911 /* Returns the DIE for a context. */
19913 static inline dw_die_ref
19914 get_context_die (tree context
)
19918 /* Find die that represents this context. */
19919 if (TYPE_P (context
))
19921 context
= TYPE_MAIN_VARIANT (context
);
19922 return strip_naming_typedef (context
, force_type_die (context
));
19925 return force_decl_die (context
);
19927 return comp_unit_die ();
19930 /* Returns the DIE for decl. A DIE will always be returned. */
19933 force_decl_die (tree decl
)
19935 dw_die_ref decl_die
;
19936 unsigned saved_external_flag
;
19937 tree save_fn
= NULL_TREE
;
19938 decl_die
= lookup_decl_die (decl
);
19941 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19943 decl_die
= lookup_decl_die (decl
);
19947 switch (TREE_CODE (decl
))
19949 case FUNCTION_DECL
:
19950 /* Clear current_function_decl, so that gen_subprogram_die thinks
19951 that this is a declaration. At this point, we just want to force
19952 declaration die. */
19953 save_fn
= current_function_decl
;
19954 current_function_decl
= NULL_TREE
;
19955 gen_subprogram_die (decl
, context_die
);
19956 current_function_decl
= save_fn
;
19960 /* Set external flag to force declaration die. Restore it after
19961 gen_decl_die() call. */
19962 saved_external_flag
= DECL_EXTERNAL (decl
);
19963 DECL_EXTERNAL (decl
) = 1;
19964 gen_decl_die (decl
, NULL
, context_die
);
19965 DECL_EXTERNAL (decl
) = saved_external_flag
;
19968 case NAMESPACE_DECL
:
19969 if (dwarf_version
>= 3 || !dwarf_strict
)
19970 dwarf2out_decl (decl
);
19972 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19973 decl_die
= comp_unit_die ();
19976 case TRANSLATION_UNIT_DECL
:
19977 decl_die
= comp_unit_die ();
19981 gcc_unreachable ();
19984 /* We should be able to find the DIE now. */
19986 decl_die
= lookup_decl_die (decl
);
19987 gcc_assert (decl_die
);
19993 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19994 always returned. */
19997 force_type_die (tree type
)
19999 dw_die_ref type_die
;
20001 type_die
= lookup_type_die (type
);
20004 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20006 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20007 TYPE_VOLATILE (type
), context_die
);
20008 gcc_assert (type_die
);
20013 /* Force out any required namespaces to be able to output DECL,
20014 and return the new context_die for it, if it's changed. */
20017 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20019 tree context
= (DECL_P (thing
)
20020 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20021 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20022 /* Force out the namespace. */
20023 context_die
= force_decl_die (context
);
20025 return context_die
;
20028 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20029 type) within its namespace, if appropriate.
20031 For compatibility with older debuggers, namespace DIEs only contain
20032 declarations; all definitions are emitted at CU scope. */
20035 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20037 dw_die_ref ns_context
;
20039 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20040 return context_die
;
20042 /* If this decl is from an inlined function, then don't try to emit it in its
20043 namespace, as we will get confused. It would have already been emitted
20044 when the abstract instance of the inline function was emitted anyways. */
20045 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20046 return context_die
;
20048 ns_context
= setup_namespace_context (thing
, context_die
);
20050 if (ns_context
!= context_die
)
20054 if (DECL_P (thing
))
20055 gen_decl_die (thing
, NULL
, ns_context
);
20057 gen_type_die (thing
, ns_context
);
20059 return context_die
;
20062 /* Generate a DIE for a namespace or namespace alias. */
20065 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20067 dw_die_ref namespace_die
;
20069 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20070 they are an alias of. */
20071 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20073 /* Output a real namespace or module. */
20074 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20075 namespace_die
= new_die (is_fortran ()
20076 ? DW_TAG_module
: DW_TAG_namespace
,
20077 context_die
, decl
);
20078 /* For Fortran modules defined in different CU don't add src coords. */
20079 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20081 const char *name
= dwarf2_name (decl
, 0);
20083 add_name_attribute (namespace_die
, name
);
20086 add_name_and_src_coords_attributes (namespace_die
, decl
);
20087 if (DECL_EXTERNAL (decl
))
20088 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20089 equate_decl_number_to_die (decl
, namespace_die
);
20093 /* Output a namespace alias. */
20095 /* Force out the namespace we are an alias of, if necessary. */
20096 dw_die_ref origin_die
20097 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20099 if (DECL_FILE_SCOPE_P (decl
)
20100 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20101 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20102 /* Now create the namespace alias DIE. */
20103 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20104 add_name_and_src_coords_attributes (namespace_die
, decl
);
20105 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20106 equate_decl_number_to_die (decl
, namespace_die
);
20108 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20109 if (want_pubnames ())
20110 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20113 /* Generate Dwarf debug information for a decl described by DECL.
20114 The return value is currently only meaningful for PARM_DECLs,
20115 for all other decls it returns NULL. */
20118 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20120 tree decl_or_origin
= decl
? decl
: origin
;
20121 tree class_origin
= NULL
, ultimate_origin
;
20123 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20126 switch (TREE_CODE (decl_or_origin
))
20132 if (!is_fortran () && !is_ada ())
20134 /* The individual enumerators of an enum type get output when we output
20135 the Dwarf representation of the relevant enum type itself. */
20139 /* Emit its type. */
20140 gen_type_die (TREE_TYPE (decl
), context_die
);
20142 /* And its containing namespace. */
20143 context_die
= declare_in_namespace (decl
, context_die
);
20145 gen_const_die (decl
, context_die
);
20148 case FUNCTION_DECL
:
20149 /* Don't output any DIEs to represent mere function declarations,
20150 unless they are class members or explicit block externs. */
20151 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20152 && DECL_FILE_SCOPE_P (decl_or_origin
)
20153 && (current_function_decl
== NULL_TREE
20154 || DECL_ARTIFICIAL (decl_or_origin
)))
20159 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20160 on local redeclarations of global functions. That seems broken. */
20161 if (current_function_decl
!= decl
)
20162 /* This is only a declaration. */;
20165 /* If we're emitting a clone, emit info for the abstract instance. */
20166 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20167 dwarf2out_abstract_function (origin
20168 ? DECL_ORIGIN (origin
)
20169 : DECL_ABSTRACT_ORIGIN (decl
));
20171 /* If we're emitting an out-of-line copy of an inline function,
20172 emit info for the abstract instance and set up to refer to it. */
20173 else if (cgraph_function_possibly_inlined_p (decl
)
20174 && ! DECL_ABSTRACT (decl
)
20175 && ! class_or_namespace_scope_p (context_die
)
20176 /* dwarf2out_abstract_function won't emit a die if this is just
20177 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20178 that case, because that works only if we have a die. */
20179 && DECL_INITIAL (decl
) != NULL_TREE
)
20181 dwarf2out_abstract_function (decl
);
20182 set_decl_origin_self (decl
);
20185 /* Otherwise we're emitting the primary DIE for this decl. */
20186 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20188 /* Before we describe the FUNCTION_DECL itself, make sure that we
20189 have its containing type. */
20191 origin
= decl_class_context (decl
);
20192 if (origin
!= NULL_TREE
)
20193 gen_type_die (origin
, context_die
);
20195 /* And its return type. */
20196 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20198 /* And its virtual context. */
20199 if (DECL_VINDEX (decl
) != NULL_TREE
)
20200 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20202 /* Make sure we have a member DIE for decl. */
20203 if (origin
!= NULL_TREE
)
20204 gen_type_die_for_member (origin
, decl
, context_die
);
20206 /* And its containing namespace. */
20207 context_die
= declare_in_namespace (decl
, context_die
);
20210 /* Now output a DIE to represent the function itself. */
20212 gen_subprogram_die (decl
, context_die
);
20216 /* If we are in terse mode, don't generate any DIEs to represent any
20217 actual typedefs. */
20218 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20221 /* In the special case of a TYPE_DECL node representing the declaration
20222 of some type tag, if the given TYPE_DECL is marked as having been
20223 instantiated from some other (original) TYPE_DECL node (e.g. one which
20224 was generated within the original definition of an inline function) we
20225 used to generate a special (abbreviated) DW_TAG_structure_type,
20226 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20227 should be actually referencing those DIEs, as variable DIEs with that
20228 type would be emitted already in the abstract origin, so it was always
20229 removed during unused type prunning. Don't add anything in this
20231 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20234 if (is_redundant_typedef (decl
))
20235 gen_type_die (TREE_TYPE (decl
), context_die
);
20237 /* Output a DIE to represent the typedef itself. */
20238 gen_typedef_die (decl
, context_die
);
20242 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20243 gen_label_die (decl
, context_die
);
20248 /* If we are in terse mode, don't generate any DIEs to represent any
20249 variable declarations or definitions. */
20250 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20253 /* Output any DIEs that are needed to specify the type of this data
20255 if (decl_by_reference_p (decl_or_origin
))
20256 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20258 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20260 /* And its containing type. */
20261 class_origin
= decl_class_context (decl_or_origin
);
20262 if (class_origin
!= NULL_TREE
)
20263 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20265 /* And its containing namespace. */
20266 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20268 /* Now output the DIE to represent the data object itself. This gets
20269 complicated because of the possibility that the VAR_DECL really
20270 represents an inlined instance of a formal parameter for an inline
20272 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20273 if (ultimate_origin
!= NULL_TREE
20274 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20275 gen_formal_parameter_die (decl
, origin
,
20276 true /* Emit name attribute. */,
20279 gen_variable_die (decl
, origin
, context_die
);
20283 /* Ignore the nameless fields that are used to skip bits but handle C++
20284 anonymous unions and structs. */
20285 if (DECL_NAME (decl
) != NULL_TREE
20286 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20287 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20289 gen_type_die (member_declared_type (decl
), context_die
);
20290 gen_field_die (decl
, context_die
);
20295 if (DECL_BY_REFERENCE (decl_or_origin
))
20296 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20298 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20299 return gen_formal_parameter_die (decl
, origin
,
20300 true /* Emit name attribute. */,
20303 case NAMESPACE_DECL
:
20304 case IMPORTED_DECL
:
20305 if (dwarf_version
>= 3 || !dwarf_strict
)
20306 gen_namespace_die (decl
, context_die
);
20310 /* Probably some frontend-internal decl. Assume we don't care. */
20311 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20318 /* Output debug information for global decl DECL. Called from toplev.c after
20319 compilation proper has finished. */
20322 dwarf2out_global_decl (tree decl
)
20324 /* Output DWARF2 information for file-scope tentative data object
20325 declarations, file-scope (extern) function declarations (which
20326 had no corresponding body) and file-scope tagged type declarations
20327 and definitions which have not yet been forced out. */
20328 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20329 dwarf2out_decl (decl
);
20332 /* Output debug information for type decl DECL. Called from toplev.c
20333 and from language front ends (to record built-in types). */
20335 dwarf2out_type_decl (tree decl
, int local
)
20338 dwarf2out_decl (decl
);
20341 /* Output debug information for imported module or decl DECL.
20342 NAME is non-NULL name in the lexical block if the decl has been renamed.
20343 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20344 that DECL belongs to.
20345 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20347 dwarf2out_imported_module_or_decl_1 (tree decl
,
20349 tree lexical_block
,
20350 dw_die_ref lexical_block_die
)
20352 expanded_location xloc
;
20353 dw_die_ref imported_die
= NULL
;
20354 dw_die_ref at_import_die
;
20356 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20358 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20359 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20363 xloc
= expand_location (input_location
);
20365 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20367 at_import_die
= force_type_die (TREE_TYPE (decl
));
20368 /* For namespace N { typedef void T; } using N::T; base_type_die
20369 returns NULL, but DW_TAG_imported_declaration requires
20370 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20371 if (!at_import_die
)
20373 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20374 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20375 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20376 gcc_assert (at_import_die
);
20381 at_import_die
= lookup_decl_die (decl
);
20382 if (!at_import_die
)
20384 /* If we're trying to avoid duplicate debug info, we may not have
20385 emitted the member decl for this field. Emit it now. */
20386 if (TREE_CODE (decl
) == FIELD_DECL
)
20388 tree type
= DECL_CONTEXT (decl
);
20390 if (TYPE_CONTEXT (type
)
20391 && TYPE_P (TYPE_CONTEXT (type
))
20392 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20393 DINFO_USAGE_DIR_USE
))
20395 gen_type_die_for_member (type
, decl
,
20396 get_context_die (TYPE_CONTEXT (type
)));
20398 at_import_die
= force_decl_die (decl
);
20402 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20404 if (dwarf_version
>= 3 || !dwarf_strict
)
20405 imported_die
= new_die (DW_TAG_imported_module
,
20412 imported_die
= new_die (DW_TAG_imported_declaration
,
20416 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20417 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20419 add_AT_string (imported_die
, DW_AT_name
,
20420 IDENTIFIER_POINTER (name
));
20421 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20424 /* Output debug information for imported module or decl DECL.
20425 NAME is non-NULL name in context if the decl has been renamed.
20426 CHILD is true if decl is one of the renamed decls as part of
20427 importing whole module. */
20430 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20433 /* dw_die_ref at_import_die; */
20434 dw_die_ref scope_die
;
20436 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20441 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20442 We need decl DIE for reference and scope die. First, get DIE for the decl
20445 /* Get the scope die for decl context. Use comp_unit_die for global module
20446 or decl. If die is not found for non globals, force new die. */
20448 && TYPE_P (context
)
20449 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20452 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20455 scope_die
= get_context_die (context
);
20459 gcc_assert (scope_die
->die_child
);
20460 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20461 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20462 scope_die
= scope_die
->die_child
;
20465 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20466 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20470 /* Write the debugging output for DECL. */
20473 dwarf2out_decl (tree decl
)
20475 dw_die_ref context_die
= comp_unit_die ();
20477 switch (TREE_CODE (decl
))
20482 case FUNCTION_DECL
:
20483 /* What we would really like to do here is to filter out all mere
20484 file-scope declarations of file-scope functions which are never
20485 referenced later within this translation unit (and keep all of ones
20486 that *are* referenced later on) but we aren't clairvoyant, so we have
20487 no idea which functions will be referenced in the future (i.e. later
20488 on within the current translation unit). So here we just ignore all
20489 file-scope function declarations which are not also definitions. If
20490 and when the debugger needs to know something about these functions,
20491 it will have to hunt around and find the DWARF information associated
20492 with the definition of the function.
20494 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20495 nodes represent definitions and which ones represent mere
20496 declarations. We have to check DECL_INITIAL instead. That's because
20497 the C front-end supports some weird semantics for "extern inline"
20498 function definitions. These can get inlined within the current
20499 translation unit (and thus, we need to generate Dwarf info for their
20500 abstract instances so that the Dwarf info for the concrete inlined
20501 instances can have something to refer to) but the compiler never
20502 generates any out-of-lines instances of such things (despite the fact
20503 that they *are* definitions).
20505 The important point is that the C front-end marks these "extern
20506 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20507 them anyway. Note that the C++ front-end also plays some similar games
20508 for inline function definitions appearing within include files which
20509 also contain `#pragma interface' pragmas.
20511 If we are called from dwarf2out_abstract_function output a DIE
20512 anyway. We can end up here this way with early inlining and LTO
20513 where the inlined function is output in a different LTRANS unit
20515 if (DECL_INITIAL (decl
) == NULL_TREE
20516 && ! DECL_ABSTRACT (decl
))
20519 /* If we're a nested function, initially use a parent of NULL; if we're
20520 a plain function, this will be fixed up in decls_for_scope. If
20521 we're a method, it will be ignored, since we already have a DIE. */
20522 if (decl_function_context (decl
)
20523 /* But if we're in terse mode, we don't care about scope. */
20524 && debug_info_level
> DINFO_LEVEL_TERSE
)
20525 context_die
= NULL
;
20529 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20530 declaration and if the declaration was never even referenced from
20531 within this entire compilation unit. We suppress these DIEs in
20532 order to save space in the .debug section (by eliminating entries
20533 which are probably useless). Note that we must not suppress
20534 block-local extern declarations (whether used or not) because that
20535 would screw-up the debugger's name lookup mechanism and cause it to
20536 miss things which really ought to be in scope at a given point. */
20537 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20540 /* For local statics lookup proper context die. */
20541 if (TREE_STATIC (decl
)
20542 && DECL_CONTEXT (decl
)
20543 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20544 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20546 /* If we are in terse mode, don't generate any DIEs to represent any
20547 variable declarations or definitions. */
20548 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20553 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20555 if (!is_fortran () && !is_ada ())
20557 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20558 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20561 case NAMESPACE_DECL
:
20562 case IMPORTED_DECL
:
20563 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20565 if (lookup_decl_die (decl
) != NULL
)
20570 /* Don't emit stubs for types unless they are needed by other DIEs. */
20571 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20574 /* Don't bother trying to generate any DIEs to represent any of the
20575 normal built-in types for the language we are compiling. */
20576 if (DECL_IS_BUILTIN (decl
))
20579 /* If we are in terse mode, don't generate any DIEs for types. */
20580 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20583 /* If we're a function-scope tag, initially use a parent of NULL;
20584 this will be fixed up in decls_for_scope. */
20585 if (decl_function_context (decl
))
20586 context_die
= NULL
;
20594 gen_decl_die (decl
, NULL
, context_die
);
20597 /* Write the debugging output for DECL. */
20600 dwarf2out_function_decl (tree decl
)
20602 dwarf2out_decl (decl
);
20603 call_arg_locations
= NULL
;
20604 call_arg_loc_last
= NULL
;
20605 call_site_count
= -1;
20606 tail_call_site_count
= -1;
20607 block_map
.release ();
20608 htab_empty (decl_loc_table
);
20609 htab_empty (cached_dw_loc_list_table
);
20612 /* Output a marker (i.e. a label) for the beginning of the generated code for
20613 a lexical block. */
20616 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20617 unsigned int blocknum
)
20619 switch_to_section (current_function_section ());
20620 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20623 /* Output a marker (i.e. a label) for the end of the generated code for a
20627 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20629 switch_to_section (current_function_section ());
20630 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20633 /* Returns nonzero if it is appropriate not to emit any debugging
20634 information for BLOCK, because it doesn't contain any instructions.
20636 Don't allow this for blocks with nested functions or local classes
20637 as we would end up with orphans, and in the presence of scheduling
20638 we may end up calling them anyway. */
20641 dwarf2out_ignore_block (const_tree block
)
20646 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20647 if (TREE_CODE (decl
) == FUNCTION_DECL
20648 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20650 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20652 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20653 if (TREE_CODE (decl
) == FUNCTION_DECL
20654 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20661 /* Hash table routines for file_hash. */
20664 file_table_eq (const void *p1_p
, const void *p2_p
)
20666 const struct dwarf_file_data
*const p1
=
20667 (const struct dwarf_file_data
*) p1_p
;
20668 const char *const p2
= (const char *) p2_p
;
20669 return filename_cmp (p1
->filename
, p2
) == 0;
20673 file_table_hash (const void *p_p
)
20675 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20676 return htab_hash_string (p
->filename
);
20679 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20680 dwarf2out.c) and return its "index". The index of each (known) filename is
20681 just a unique number which is associated with only that one filename. We
20682 need such numbers for the sake of generating labels (in the .debug_sfnames
20683 section) and references to those files numbers (in the .debug_srcinfo
20684 and.debug_macinfo sections). If the filename given as an argument is not
20685 found in our current list, add it to the list and assign it the next
20686 available unique index number. In order to speed up searches, we remember
20687 the index of the filename was looked up last. This handles the majority of
20690 static struct dwarf_file_data
*
20691 lookup_filename (const char *file_name
)
20694 struct dwarf_file_data
* created
;
20696 /* Check to see if the file name that was searched on the previous
20697 call matches this file name. If so, return the index. */
20698 if (file_table_last_lookup
20699 && (file_name
== file_table_last_lookup
->filename
20700 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20701 return file_table_last_lookup
;
20703 /* Didn't match the previous lookup, search the table. */
20704 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20705 htab_hash_string (file_name
), INSERT
);
20707 return (struct dwarf_file_data
*) *slot
;
20709 created
= ggc_alloc_dwarf_file_data ();
20710 created
->filename
= file_name
;
20711 created
->emitted_number
= 0;
20716 /* If the assembler will construct the file table, then translate the compiler
20717 internal file table number into the assembler file table number, and emit
20718 a .file directive if we haven't already emitted one yet. The file table
20719 numbers are different because we prune debug info for unused variables and
20720 types, which may include filenames. */
20723 maybe_emit_file (struct dwarf_file_data
* fd
)
20725 if (! fd
->emitted_number
)
20727 if (last_emitted_file
)
20728 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20730 fd
->emitted_number
= 1;
20731 last_emitted_file
= fd
;
20733 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20735 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20736 output_quoted_string (asm_out_file
,
20737 remap_debug_filename (fd
->filename
));
20738 fputc ('\n', asm_out_file
);
20742 return fd
->emitted_number
;
20745 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20746 That generation should happen after function debug info has been
20747 generated. The value of the attribute is the constant value of ARG. */
20750 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20752 die_arg_entry entry
;
20757 if (!tmpl_value_parm_die_table
)
20758 vec_alloc (tmpl_value_parm_die_table
, 32);
20762 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20765 /* Return TRUE if T is an instance of generic type, FALSE
20769 generic_type_p (tree t
)
20771 if (t
== NULL_TREE
|| !TYPE_P (t
))
20773 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20776 /* Schedule the generation of the generic parameter dies for the
20777 instance of generic type T. The proper generation itself is later
20778 done by gen_scheduled_generic_parms_dies. */
20781 schedule_generic_params_dies_gen (tree t
)
20783 if (!generic_type_p (t
))
20786 if (!generic_type_instances
)
20787 vec_alloc (generic_type_instances
, 256);
20789 vec_safe_push (generic_type_instances
, t
);
20792 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20793 by append_entry_to_tmpl_value_parm_die_table. This function must
20794 be called after function DIEs have been generated. */
20797 gen_remaining_tmpl_value_param_die_attribute (void)
20799 if (tmpl_value_parm_die_table
)
20804 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20805 tree_add_const_value_attribute (e
->die
, e
->arg
);
20809 /* Generate generic parameters DIEs for instances of generic types
20810 that have been previously scheduled by
20811 schedule_generic_params_dies_gen. This function must be called
20812 after all the types of the CU have been laid out. */
20815 gen_scheduled_generic_parms_dies (void)
20820 if (!generic_type_instances
)
20823 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20824 if (COMPLETE_TYPE_P (t
))
20825 gen_generic_params_dies (t
);
20829 /* Replace DW_AT_name for the decl with name. */
20832 dwarf2out_set_name (tree decl
, tree name
)
20838 die
= TYPE_SYMTAB_DIE (decl
);
20842 dname
= dwarf2_name (name
, 0);
20846 attr
= get_AT (die
, DW_AT_name
);
20849 struct indirect_string_node
*node
;
20851 node
= find_AT_string (dname
);
20852 /* replace the string. */
20853 attr
->dw_attr_val
.v
.val_str
= node
;
20857 add_name_attribute (die
, dname
);
20860 /* True if before or during processing of the first function being emitted. */
20861 static bool in_first_function_p
= true;
20862 /* True if loc_note during dwarf2out_var_location call might still be
20863 before first real instruction at address equal to .Ltext0. */
20864 static bool maybe_at_text_label_p
= true;
20865 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
20866 static unsigned int first_loclabel_num_not_at_text_label
;
20868 /* Called by the final INSN scan whenever we see a var location. We
20869 use it to drop labels in the right places, and throw the location in
20870 our lookup table. */
20873 dwarf2out_var_location (rtx loc_note
)
20875 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20876 struct var_loc_node
*newloc
;
20877 rtx next_real
, next_note
;
20878 static const char *last_label
;
20879 static const char *last_postcall_label
;
20880 static bool last_in_cold_section_p
;
20881 static rtx expected_next_loc_note
;
20885 if (!NOTE_P (loc_note
))
20887 if (CALL_P (loc_note
))
20890 if (SIBLING_CALL_P (loc_note
))
20891 tail_call_site_count
++;
20896 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20897 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20900 /* Optimize processing a large consecutive sequence of location
20901 notes so we don't spend too much time in next_real_insn. If the
20902 next insn is another location note, remember the next_real_insn
20903 calculation for next time. */
20904 next_real
= cached_next_real_insn
;
20907 if (expected_next_loc_note
!= loc_note
)
20908 next_real
= NULL_RTX
;
20911 next_note
= NEXT_INSN (loc_note
);
20913 || INSN_DELETED_P (next_note
)
20914 || ! NOTE_P (next_note
)
20915 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20916 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20917 next_note
= NULL_RTX
;
20920 next_real
= next_real_insn (loc_note
);
20924 expected_next_loc_note
= next_note
;
20925 cached_next_real_insn
= next_real
;
20928 cached_next_real_insn
= NULL_RTX
;
20930 /* If there are no instructions which would be affected by this note,
20931 don't do anything. */
20933 && next_real
== NULL_RTX
20934 && !NOTE_DURING_CALL_P (loc_note
))
20937 if (next_real
== NULL_RTX
)
20938 next_real
= get_last_insn ();
20940 /* If there were any real insns between note we processed last time
20941 and this note (or if it is the first note), clear
20942 last_{,postcall_}label so that they are not reused this time. */
20943 if (last_var_location_insn
== NULL_RTX
20944 || last_var_location_insn
!= next_real
20945 || last_in_cold_section_p
!= in_cold_section_p
)
20948 last_postcall_label
= NULL
;
20953 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20954 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20955 NOTE_DURING_CALL_P (loc_note
)
20956 ? last_postcall_label
: last_label
);
20957 if (newloc
== NULL
)
20966 /* If there were no real insns between note we processed last time
20967 and this note, use the label we emitted last time. Otherwise
20968 create a new label and emit it. */
20969 if (last_label
== NULL
)
20971 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20972 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20974 last_label
= ggc_strdup (loclabel
);
20975 /* See if loclabel might be equal to .Ltext0. If yes,
20976 bump first_loclabel_num_not_at_text_label. */
20977 if (!have_multiple_function_sections
20978 && in_first_function_p
20979 && maybe_at_text_label_p
)
20981 static rtx last_start
;
20983 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
20984 if (insn
== last_start
)
20986 else if (!NONDEBUG_INSN_P (insn
))
20990 rtx body
= PATTERN (insn
);
20991 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
20993 /* Inline asm could occupy zero bytes. */
20994 else if (GET_CODE (body
) == ASM_INPUT
20995 || asm_noperands (body
) >= 0)
20997 #ifdef HAVE_attr_length
20998 else if (get_attr_min_length (insn
) == 0)
21003 /* Assume insn has non-zero length. */
21004 maybe_at_text_label_p
= false;
21008 if (maybe_at_text_label_p
)
21010 last_start
= loc_note
;
21011 first_loclabel_num_not_at_text_label
= loclabel_num
;
21018 struct call_arg_loc_node
*ca_loc
21019 = ggc_alloc_cleared_call_arg_loc_node ();
21020 rtx prev
= prev_real_insn (loc_note
), x
;
21021 ca_loc
->call_arg_loc_note
= loc_note
;
21022 ca_loc
->next
= NULL
;
21023 ca_loc
->label
= last_label
;
21026 || (NONJUMP_INSN_P (prev
)
21027 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21028 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21029 if (!CALL_P (prev
))
21030 prev
= XVECEXP (PATTERN (prev
), 0, 0);
21031 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
21032 x
= get_call_rtx_from (PATTERN (prev
));
21035 x
= XEXP (XEXP (x
, 0), 0);
21036 if (GET_CODE (x
) == SYMBOL_REF
21037 && SYMBOL_REF_DECL (x
)
21038 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21039 ca_loc
->symbol_ref
= x
;
21041 ca_loc
->block
= insn_scope (prev
);
21042 if (call_arg_locations
)
21043 call_arg_loc_last
->next
= ca_loc
;
21045 call_arg_locations
= ca_loc
;
21046 call_arg_loc_last
= ca_loc
;
21048 else if (!NOTE_DURING_CALL_P (loc_note
))
21049 newloc
->label
= last_label
;
21052 if (!last_postcall_label
)
21054 sprintf (loclabel
, "%s-1", last_label
);
21055 last_postcall_label
= ggc_strdup (loclabel
);
21057 newloc
->label
= last_postcall_label
;
21060 last_var_location_insn
= next_real
;
21061 last_in_cold_section_p
= in_cold_section_p
;
21064 /* Note in one location list that text section has changed. */
21067 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
21069 var_loc_list
*list
= (var_loc_list
*) *slot
;
21071 list
->last_before_switch
21072 = list
->last
->next
? list
->last
->next
: list
->last
;
21076 /* Note in all location lists that text section has changed. */
21079 var_location_switch_text_section (void)
21081 if (decl_loc_table
== NULL
)
21084 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
21087 /* Create a new line number table. */
21089 static dw_line_info_table
*
21090 new_line_info_table (void)
21092 dw_line_info_table
*table
;
21094 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
21095 table
->file_num
= 1;
21096 table
->line_num
= 1;
21097 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21102 /* Lookup the "current" table into which we emit line info, so
21103 that we don't have to do it for every source line. */
21106 set_cur_line_info_table (section
*sec
)
21108 dw_line_info_table
*table
;
21110 if (sec
== text_section
)
21111 table
= text_section_line_info
;
21112 else if (sec
== cold_text_section
)
21114 table
= cold_text_section_line_info
;
21117 cold_text_section_line_info
= table
= new_line_info_table ();
21118 table
->end_label
= cold_end_label
;
21123 const char *end_label
;
21125 if (flag_reorder_blocks_and_partition
)
21127 if (in_cold_section_p
)
21128 end_label
= crtl
->subsections
.cold_section_end_label
;
21130 end_label
= crtl
->subsections
.hot_section_end_label
;
21134 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21135 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21136 current_function_funcdef_no
);
21137 end_label
= ggc_strdup (label
);
21140 table
= new_line_info_table ();
21141 table
->end_label
= end_label
;
21143 vec_safe_push (separate_line_info
, table
);
21146 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21147 table
->is_stmt
= (cur_line_info_table
21148 ? cur_line_info_table
->is_stmt
21149 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21150 cur_line_info_table
= table
;
21154 /* We need to reset the locations at the beginning of each
21155 function. We can't do this in the end_function hook, because the
21156 declarations that use the locations won't have been output when
21157 that hook is called. Also compute have_multiple_function_sections here. */
21160 dwarf2out_begin_function (tree fun
)
21162 section
*sec
= function_section (fun
);
21164 if (sec
!= text_section
)
21165 have_multiple_function_sections
= true;
21167 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21169 gcc_assert (current_function_decl
== fun
);
21170 cold_text_section
= unlikely_text_section ();
21171 switch_to_section (cold_text_section
);
21172 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21173 switch_to_section (sec
);
21176 dwarf2out_note_section_used ();
21177 call_site_count
= 0;
21178 tail_call_site_count
= 0;
21180 set_cur_line_info_table (sec
);
21183 /* Helper function of dwarf2out_end_function, called only after emitting
21184 the very first function into assembly. Check if some .debug_loc range
21185 might end with a .LVL* label that could be equal to .Ltext0.
21186 In that case we must force using absolute addresses in .debug_loc ranges,
21187 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21188 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21190 Set have_multiple_function_sections to true in that case and
21191 terminate htab traversal. */
21194 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21196 var_loc_list
*entry
;
21197 struct var_loc_node
*node
;
21199 entry
= (var_loc_list
*) *slot
;
21200 node
= entry
->first
;
21201 if (node
&& node
->next
&& node
->next
->label
)
21204 const char *label
= node
->next
->label
;
21205 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21207 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21209 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21210 if (strcmp (label
, loclabel
) == 0)
21212 have_multiple_function_sections
= true;
21220 /* Hook called after emitting a function into assembly.
21221 This does something only for the very first function emitted. */
21224 dwarf2out_end_function (unsigned int)
21226 if (in_first_function_p
21227 && !have_multiple_function_sections
21228 && first_loclabel_num_not_at_text_label
21230 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21232 in_first_function_p
= false;
21233 maybe_at_text_label_p
= false;
21236 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21239 push_dw_line_info_entry (dw_line_info_table
*table
,
21240 enum dw_line_info_opcode opcode
, unsigned int val
)
21242 dw_line_info_entry e
;
21245 vec_safe_push (table
->entries
, e
);
21248 /* Output a label to mark the beginning of a source code line entry
21249 and record information relating to this source line, in
21250 'line_info_table' for later output of the .debug_line section. */
21251 /* ??? The discriminator parameter ought to be unsigned. */
21254 dwarf2out_source_line (unsigned int line
, const char *filename
,
21255 int discriminator
, bool is_stmt
)
21257 unsigned int file_num
;
21258 dw_line_info_table
*table
;
21260 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
21263 /* The discriminator column was added in dwarf4. Simplify the below
21264 by simply removing it if we're not supposed to output it. */
21265 if (dwarf_version
< 4 && dwarf_strict
)
21268 table
= cur_line_info_table
;
21269 file_num
= maybe_emit_file (lookup_filename (filename
));
21271 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21272 the debugger has used the second (possibly duplicate) line number
21273 at the beginning of the function to mark the end of the prologue.
21274 We could eliminate any other duplicates within the function. For
21275 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21276 that second line number entry. */
21277 /* Recall that this end-of-prologue indication is *not* the same thing
21278 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21279 to which the hook corresponds, follows the last insn that was
21280 emitted by gen_prologue. What we need is to precede the first insn
21281 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21282 insn that corresponds to something the user wrote. These may be
21283 very different locations once scheduling is enabled. */
21285 if (0 && file_num
== table
->file_num
21286 && line
== table
->line_num
21287 && discriminator
== table
->discrim_num
21288 && is_stmt
== table
->is_stmt
)
21291 switch_to_section (current_function_section ());
21293 /* If requested, emit something human-readable. */
21294 if (flag_debug_asm
)
21295 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21297 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21299 /* Emit the .loc directive understood by GNU as. */
21300 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21301 file_num, line, is_stmt, discriminator */
21302 fputs ("\t.loc ", asm_out_file
);
21303 fprint_ul (asm_out_file
, file_num
);
21304 putc (' ', asm_out_file
);
21305 fprint_ul (asm_out_file
, line
);
21306 putc (' ', asm_out_file
);
21307 putc ('0', asm_out_file
);
21309 if (is_stmt
!= table
->is_stmt
)
21311 fputs (" is_stmt ", asm_out_file
);
21312 putc (is_stmt
? '1' : '0', asm_out_file
);
21314 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21316 gcc_assert (discriminator
> 0);
21317 fputs (" discriminator ", asm_out_file
);
21318 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21320 putc ('\n', asm_out_file
);
21324 unsigned int label_num
= ++line_info_label_num
;
21326 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21328 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21329 if (file_num
!= table
->file_num
)
21330 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21331 if (discriminator
!= table
->discrim_num
)
21332 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21333 if (is_stmt
!= table
->is_stmt
)
21334 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21335 push_dw_line_info_entry (table
, LI_set_line
, line
);
21338 table
->file_num
= file_num
;
21339 table
->line_num
= line
;
21340 table
->discrim_num
= discriminator
;
21341 table
->is_stmt
= is_stmt
;
21342 table
->in_use
= true;
21345 /* Record the beginning of a new source file. */
21348 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21350 if (flag_eliminate_dwarf2_dups
)
21352 /* Record the beginning of the file for break_out_includes. */
21353 dw_die_ref bincl_die
;
21355 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21356 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21359 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21362 e
.code
= DW_MACINFO_start_file
;
21364 e
.info
= ggc_strdup (filename
);
21365 vec_safe_push (macinfo_table
, e
);
21369 /* Record the end of a source file. */
21372 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21374 if (flag_eliminate_dwarf2_dups
)
21375 /* Record the end of the file for break_out_includes. */
21376 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21378 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21381 e
.code
= DW_MACINFO_end_file
;
21384 vec_safe_push (macinfo_table
, e
);
21388 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21389 the tail part of the directive line, i.e. the part which is past the
21390 initial whitespace, #, whitespace, directive-name, whitespace part. */
21393 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21394 const char *buffer ATTRIBUTE_UNUSED
)
21396 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21399 /* Insert a dummy first entry to be able to optimize the whole
21400 predefined macro block using DW_MACRO_GNU_transparent_include. */
21401 if (macinfo_table
->is_empty () && lineno
<= 1)
21406 vec_safe_push (macinfo_table
, e
);
21408 e
.code
= DW_MACINFO_define
;
21410 e
.info
= ggc_strdup (buffer
);
21411 vec_safe_push (macinfo_table
, e
);
21415 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21416 the tail part of the directive line, i.e. the part which is past the
21417 initial whitespace, #, whitespace, directive-name, whitespace part. */
21420 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21421 const char *buffer ATTRIBUTE_UNUSED
)
21423 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21426 /* Insert a dummy first entry to be able to optimize the whole
21427 predefined macro block using DW_MACRO_GNU_transparent_include. */
21428 if (macinfo_table
->is_empty () && lineno
<= 1)
21433 vec_safe_push (macinfo_table
, e
);
21435 e
.code
= DW_MACINFO_undef
;
21437 e
.info
= ggc_strdup (buffer
);
21438 vec_safe_push (macinfo_table
, e
);
21442 /* Helpers to manipulate hash table of CUs. */
21444 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
21446 typedef macinfo_entry value_type
;
21447 typedef macinfo_entry compare_type
;
21448 static inline hashval_t
hash (const value_type
*);
21449 static inline bool equal (const value_type
*, const compare_type
*);
21453 macinfo_entry_hasher::hash (const value_type
*entry
)
21455 return htab_hash_string (entry
->info
);
21459 macinfo_entry_hasher::equal (const value_type
*entry1
,
21460 const compare_type
*entry2
)
21462 return !strcmp (entry1
->info
, entry2
->info
);
21465 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
21467 /* Output a single .debug_macinfo entry. */
21470 output_macinfo_op (macinfo_entry
*ref
)
21474 struct indirect_string_node
*node
;
21475 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21476 struct dwarf_file_data
*fd
;
21480 case DW_MACINFO_start_file
:
21481 fd
= lookup_filename (ref
->info
);
21482 file_num
= maybe_emit_file (fd
);
21483 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21484 dw2_asm_output_data_uleb128 (ref
->lineno
,
21485 "Included from line number %lu",
21486 (unsigned long) ref
->lineno
);
21487 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21489 case DW_MACINFO_end_file
:
21490 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21492 case DW_MACINFO_define
:
21493 case DW_MACINFO_undef
:
21494 len
= strlen (ref
->info
) + 1;
21496 && len
> DWARF_OFFSET_SIZE
21497 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21498 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21500 ref
->code
= ref
->code
== DW_MACINFO_define
21501 ? DW_MACRO_GNU_define_indirect
21502 : DW_MACRO_GNU_undef_indirect
;
21503 output_macinfo_op (ref
);
21506 dw2_asm_output_data (1, ref
->code
,
21507 ref
->code
== DW_MACINFO_define
21508 ? "Define macro" : "Undefine macro");
21509 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21510 (unsigned long) ref
->lineno
);
21511 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21513 case DW_MACRO_GNU_define_indirect
:
21514 case DW_MACRO_GNU_undef_indirect
:
21515 node
= find_AT_string (ref
->info
);
21517 && ((node
->form
== DW_FORM_strp
)
21518 || (node
->form
== DW_FORM_GNU_str_index
)));
21519 dw2_asm_output_data (1, ref
->code
,
21520 ref
->code
== DW_MACRO_GNU_define_indirect
21521 ? "Define macro indirect"
21522 : "Undefine macro indirect");
21523 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21524 (unsigned long) ref
->lineno
);
21525 if (node
->form
== DW_FORM_strp
)
21526 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21527 debug_str_section
, "The macro: \"%s\"",
21530 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21533 case DW_MACRO_GNU_transparent_include
:
21534 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21535 ASM_GENERATE_INTERNAL_LABEL (label
,
21536 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21537 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21540 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21541 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21546 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21547 other compilation unit .debug_macinfo sections. IDX is the first
21548 index of a define/undef, return the number of ops that should be
21549 emitted in a comdat .debug_macinfo section and emit
21550 a DW_MACRO_GNU_transparent_include entry referencing it.
21551 If the define/undef entry should be emitted normally, return 0. */
21554 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21555 macinfo_hash_type
*macinfo_htab
)
21557 macinfo_entry
*first
, *second
, *cur
, *inc
;
21558 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21559 unsigned char checksum
[16];
21560 struct md5_ctx ctx
;
21561 char *grp_name
, *tail
;
21563 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21564 macinfo_entry
**slot
;
21566 first
= &(*macinfo_table
)[idx
];
21567 second
= &(*macinfo_table
)[idx
+ 1];
21569 /* Optimize only if there are at least two consecutive define/undef ops,
21570 and either all of them are before first DW_MACINFO_start_file
21571 with lineno {0,1} (i.e. predefined macro block), or all of them are
21572 in some included header file. */
21573 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21575 if (vec_safe_is_empty (files
))
21577 if (first
->lineno
> 1 || second
->lineno
> 1)
21580 else if (first
->lineno
== 0)
21583 /* Find the last define/undef entry that can be grouped together
21584 with first and at the same time compute md5 checksum of their
21585 codes, linenumbers and strings. */
21586 md5_init_ctx (&ctx
);
21587 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21588 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21590 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21594 unsigned char code
= cur
->code
;
21595 md5_process_bytes (&code
, 1, &ctx
);
21596 checksum_uleb128 (cur
->lineno
, &ctx
);
21597 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21599 md5_finish_ctx (&ctx
, checksum
);
21602 /* From the containing include filename (if any) pick up just
21603 usable characters from its basename. */
21604 if (vec_safe_is_empty (files
))
21607 base
= lbasename (files
->last ().info
);
21608 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21609 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21610 encoded_filename_len
++;
21611 /* Count . at the end. */
21612 if (encoded_filename_len
)
21613 encoded_filename_len
++;
21615 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21616 linebuf_len
= strlen (linebuf
);
21618 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21619 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21621 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21622 tail
= grp_name
+ 4;
21623 if (encoded_filename_len
)
21625 for (i
= 0; base
[i
]; i
++)
21626 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21630 memcpy (tail
, linebuf
, linebuf_len
);
21631 tail
+= linebuf_len
;
21633 for (i
= 0; i
< 16; i
++)
21634 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21636 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21637 in the empty vector entry before the first define/undef. */
21638 inc
= &(*macinfo_table
)[idx
- 1];
21639 inc
->code
= DW_MACRO_GNU_transparent_include
;
21641 inc
->info
= ggc_strdup (grp_name
);
21642 if (!macinfo_htab
->is_created ())
21643 macinfo_htab
->create (10);
21644 /* Avoid emitting duplicates. */
21645 slot
= macinfo_htab
->find_slot (inc
, INSERT
);
21650 /* If such an entry has been used before, just emit
21651 a DW_MACRO_GNU_transparent_include op. */
21653 output_macinfo_op (inc
);
21654 /* And clear all macinfo_entry in the range to avoid emitting them
21655 in the second pass. */
21656 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21665 inc
->lineno
= macinfo_htab
->elements ();
21666 output_macinfo_op (inc
);
21671 /* Save any strings needed by the macinfo table in the debug str
21672 table. All strings must be collected into the table by the time
21673 index_string is called. */
21676 save_macinfo_strings (void)
21680 macinfo_entry
*ref
;
21682 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21686 /* Match the logic in output_macinfo_op to decide on
21687 indirect strings. */
21688 case DW_MACINFO_define
:
21689 case DW_MACINFO_undef
:
21690 len
= strlen (ref
->info
) + 1;
21692 && len
> DWARF_OFFSET_SIZE
21693 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21694 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21695 set_indirect_string (find_AT_string (ref
->info
));
21697 case DW_MACRO_GNU_define_indirect
:
21698 case DW_MACRO_GNU_undef_indirect
:
21699 set_indirect_string (find_AT_string (ref
->info
));
21707 /* Output macinfo section(s). */
21710 output_macinfo (void)
21713 unsigned long length
= vec_safe_length (macinfo_table
);
21714 macinfo_entry
*ref
;
21715 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21716 macinfo_hash_type macinfo_htab
;
21721 /* output_macinfo* uses these interchangeably. */
21722 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21723 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21724 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21725 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21727 /* For .debug_macro emit the section header. */
21730 dw2_asm_output_data (2, 4, "DWARF macro version number");
21731 if (DWARF_OFFSET_SIZE
== 8)
21732 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21734 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21735 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21736 (!dwarf_split_debug_info
? debug_line_section_label
21737 : debug_skeleton_line_section_label
),
21738 debug_line_section
, NULL
);
21741 /* In the first loop, it emits the primary .debug_macinfo section
21742 and after each emitted op the macinfo_entry is cleared.
21743 If a longer range of define/undef ops can be optimized using
21744 DW_MACRO_GNU_transparent_include, the
21745 DW_MACRO_GNU_transparent_include op is emitted and kept in
21746 the vector before the first define/undef in the range and the
21747 whole range of define/undef ops is not emitted and kept. */
21748 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21752 case DW_MACINFO_start_file
:
21753 vec_safe_push (files
, *ref
);
21755 case DW_MACINFO_end_file
:
21756 if (!vec_safe_is_empty (files
))
21759 case DW_MACINFO_define
:
21760 case DW_MACINFO_undef
:
21762 && HAVE_COMDAT_GROUP
21763 && vec_safe_length (files
) != 1
21766 && (*macinfo_table
)[i
- 1].code
== 0)
21768 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21777 /* A dummy entry may be inserted at the beginning to be able
21778 to optimize the whole block of predefined macros. */
21784 output_macinfo_op (ref
);
21789 if (!macinfo_htab
.is_created ())
21792 macinfo_htab
.dispose ();
21794 /* If any DW_MACRO_GNU_transparent_include were used, on those
21795 DW_MACRO_GNU_transparent_include entries terminate the
21796 current chain and switch to a new comdat .debug_macinfo
21797 section and emit the define/undef entries within it. */
21798 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21803 case DW_MACRO_GNU_transparent_include
:
21805 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21806 tree comdat_key
= get_identifier (ref
->info
);
21807 /* Terminate the previous .debug_macinfo section. */
21808 dw2_asm_output_data (1, 0, "End compilation unit");
21809 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21811 | SECTION_LINKONCE
,
21813 ASM_GENERATE_INTERNAL_LABEL (label
,
21814 DEBUG_MACRO_SECTION_LABEL
,
21816 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21819 dw2_asm_output_data (2, 4, "DWARF macro version number");
21820 if (DWARF_OFFSET_SIZE
== 8)
21821 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21823 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21826 case DW_MACINFO_define
:
21827 case DW_MACINFO_undef
:
21828 output_macinfo_op (ref
);
21833 gcc_unreachable ();
21837 /* Set up for Dwarf output at the start of compilation. */
21840 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21842 /* Allocate the file_table. */
21843 file_table
= htab_create_ggc (50, file_table_hash
,
21844 file_table_eq
, NULL
);
21846 /* Allocate the decl_die_table. */
21847 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21848 decl_die_table_eq
, NULL
);
21850 /* Allocate the decl_loc_table. */
21851 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21852 decl_loc_table_eq
, NULL
);
21854 /* Allocate the cached_dw_loc_list_table. */
21855 cached_dw_loc_list_table
21856 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21857 cached_dw_loc_list_table_eq
, NULL
);
21859 /* Allocate the initial hunk of the decl_scope_table. */
21860 vec_alloc (decl_scope_table
, 256);
21862 /* Allocate the initial hunk of the abbrev_die_table. */
21863 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21864 (ABBREV_DIE_TABLE_INCREMENT
);
21865 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21866 /* Zero-th entry is allocated, but unused. */
21867 abbrev_die_table_in_use
= 1;
21869 /* Allocate the pubtypes and pubnames vectors. */
21870 vec_alloc (pubname_table
, 32);
21871 vec_alloc (pubtype_table
, 32);
21873 vec_alloc (incomplete_types
, 64);
21875 vec_alloc (used_rtx_array
, 32);
21877 if (!dwarf_split_debug_info
)
21879 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21880 SECTION_DEBUG
, NULL
);
21881 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21882 SECTION_DEBUG
, NULL
);
21883 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21884 SECTION_DEBUG
, NULL
);
21888 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
21889 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21890 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
21891 SECTION_DEBUG
| SECTION_EXCLUDE
,
21893 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
21894 SECTION_DEBUG
, NULL
);
21895 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
21896 SECTION_DEBUG
, NULL
);
21897 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21898 SECTION_DEBUG
, NULL
);
21899 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
21900 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
21902 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
21903 the main .o, but the skeleton_line goes into the split off dwo. */
21904 debug_skeleton_line_section
21905 = get_section (DEBUG_DWO_LINE_SECTION
,
21906 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21907 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
21908 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
21909 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
21910 SECTION_DEBUG
| SECTION_EXCLUDE
,
21912 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
21913 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
21914 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
21915 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21916 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
21917 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
21919 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21920 SECTION_DEBUG
, NULL
);
21921 debug_macinfo_section
= get_section (dwarf_strict
21922 ? DEBUG_MACINFO_SECTION
21923 : DEBUG_MACRO_SECTION
,
21924 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
21925 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21926 SECTION_DEBUG
, NULL
);
21927 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21928 SECTION_DEBUG
, NULL
);
21929 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21930 SECTION_DEBUG
, NULL
);
21931 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21932 DEBUG_STR_SECTION_FLAGS
, NULL
);
21933 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21934 SECTION_DEBUG
, NULL
);
21935 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21936 SECTION_DEBUG
, NULL
);
21938 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21939 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21940 DEBUG_ABBREV_SECTION_LABEL
, 0);
21941 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21942 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21943 COLD_TEXT_SECTION_LABEL
, 0);
21944 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21946 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21947 DEBUG_INFO_SECTION_LABEL
, 0);
21948 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21949 DEBUG_LINE_SECTION_LABEL
, 0);
21950 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21951 DEBUG_RANGES_SECTION_LABEL
, 0);
21952 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
21953 DEBUG_ADDR_SECTION_LABEL
, 0);
21954 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21956 ? DEBUG_MACINFO_SECTION_LABEL
21957 : DEBUG_MACRO_SECTION_LABEL
, 0);
21958 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
21960 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21961 vec_alloc (macinfo_table
, 64);
21963 switch_to_section (text_section
);
21964 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21966 /* Make sure the line number table for .text always exists. */
21967 text_section_line_info
= new_line_info_table ();
21968 text_section_line_info
->end_label
= text_end_label
;
21971 /* Called before compile () starts outputtting functions, variables
21972 and toplevel asms into assembly. */
21975 dwarf2out_assembly_start (void)
21977 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21978 && dwarf2out_do_cfi_asm ()
21979 && (!(flag_unwind_tables
|| flag_exceptions
)
21980 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
21981 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21984 /* A helper function for dwarf2out_finish called through
21985 htab_traverse. Assign a string its index. All strings must be
21986 collected into the table by the time index_string is called,
21987 because the indexing code relies on htab_traverse to traverse nodes
21988 in the same order for each run. */
21991 index_string (void **h
, void *v
)
21993 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21994 unsigned int *index
= (unsigned int *) v
;
21996 find_string_form (node
);
21997 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21999 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
22000 node
->index
= *index
;
22006 /* A helper function for output_indirect_strings called through
22007 htab_traverse. Output the offset to a string and update the
22011 output_index_string_offset (void **h
, void *v
)
22013 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22014 unsigned int *offset
= (unsigned int *) v
;
22016 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22018 /* Assert that this node has been assigned an index. */
22019 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
22020 && node
->index
!= NOT_INDEXED
);
22021 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
22022 "indexed string 0x%x: %s", node
->index
, node
->str
);
22023 *offset
+= strlen (node
->str
) + 1;
22028 /* A helper function for dwarf2out_finish called through
22029 htab_traverse. Output the indexed string. */
22032 output_index_string (void **h
, void *v
)
22034 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22035 unsigned int *cur_idx
= (unsigned int *) v
;
22037 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22039 /* Assert that the strings are output in the same order as their
22040 indexes were assigned. */
22041 gcc_assert (*cur_idx
== node
->index
);
22042 assemble_string (node
->str
, strlen (node
->str
) + 1);
22048 /* A helper function for dwarf2out_finish called through
22049 htab_traverse. Emit one queued .debug_str string. */
22052 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22054 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22056 node
->form
= find_string_form (node
);
22057 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22059 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22060 assemble_string (node
->str
, strlen (node
->str
) + 1);
22066 /* Output the indexed string table. */
22069 output_indirect_strings (void)
22071 switch_to_section (debug_str_section
);
22072 if (!dwarf_split_debug_info
)
22073 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22076 unsigned int offset
= 0;
22077 unsigned int cur_idx
= 0;
22079 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
22081 switch_to_section (debug_str_offsets_section
);
22082 htab_traverse_noresize (debug_str_hash
,
22083 output_index_string_offset
,
22085 switch_to_section (debug_str_dwo_section
);
22086 htab_traverse_noresize (debug_str_hash
,
22087 output_index_string
,
22092 /* Callback for htab_traverse to assign an index to an entry in the
22093 table, and to write that entry to the .debug_addr section. */
22096 output_addr_table_entry (void **slot
, void *data
)
22098 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22099 unsigned int *cur_index
= (unsigned int *)data
;
22101 if (entry
->refcount
== 0)
22103 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22104 || entry
->index
== NOT_INDEXED
);
22108 gcc_assert (entry
->index
== *cur_index
);
22111 switch (entry
->kind
)
22114 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22115 "0x%x", entry
->index
);
22117 case ate_kind_rtx_dtprel
:
22118 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22119 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22122 fputc ('\n', asm_out_file
);
22124 case ate_kind_label
:
22125 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22126 "0x%x", entry
->index
);
22129 gcc_unreachable ();
22134 /* Produce the .debug_addr section. */
22137 output_addr_table (void)
22139 unsigned int index
= 0;
22140 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22143 switch_to_section (debug_addr_section
);
22144 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22147 #if ENABLE_ASSERT_CHECKING
22148 /* Verify that all marks are clear. */
22151 verify_marks_clear (dw_die_ref die
)
22155 gcc_assert (! die
->die_mark
);
22156 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22158 #endif /* ENABLE_ASSERT_CHECKING */
22160 /* Clear the marks for a die and its children.
22161 Be cool if the mark isn't set. */
22164 prune_unmark_dies (dw_die_ref die
)
22170 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22173 /* Given DIE that we're marking as used, find any other dies
22174 it references as attributes and mark them as used. */
22177 prune_unused_types_walk_attribs (dw_die_ref die
)
22182 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22184 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22186 /* A reference to another DIE.
22187 Make sure that it will get emitted.
22188 If it was broken out into a comdat group, don't follow it. */
22189 if (! AT_ref (a
)->comdat_type_p
22190 || a
->dw_attr
== DW_AT_specification
)
22191 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22193 /* Set the string's refcount to 0 so that prune_unused_types_mark
22194 accounts properly for it. */
22195 if (AT_class (a
) == dw_val_class_str
)
22196 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22200 /* Mark the generic parameters and arguments children DIEs of DIE. */
22203 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22207 if (die
== NULL
|| die
->die_child
== NULL
)
22209 c
= die
->die_child
;
22212 if (is_template_parameter (c
))
22213 prune_unused_types_mark (c
, 1);
22215 } while (c
&& c
!= die
->die_child
);
22218 /* Mark DIE as being used. If DOKIDS is true, then walk down
22219 to DIE's children. */
22222 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22226 if (die
->die_mark
== 0)
22228 /* We haven't done this node yet. Mark it as used. */
22230 /* If this is the DIE of a generic type instantiation,
22231 mark the children DIEs that describe its generic parms and
22233 prune_unused_types_mark_generic_parms_dies (die
);
22235 /* We also have to mark its parents as used.
22236 (But we don't want to mark our parent's kids due to this,
22237 unless it is a class.) */
22238 if (die
->die_parent
)
22239 prune_unused_types_mark (die
->die_parent
,
22240 class_scope_p (die
->die_parent
));
22242 /* Mark any referenced nodes. */
22243 prune_unused_types_walk_attribs (die
);
22245 /* If this node is a specification,
22246 also mark the definition, if it exists. */
22247 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22248 prune_unused_types_mark (die
->die_definition
, 1);
22251 if (dokids
&& die
->die_mark
!= 2)
22253 /* We need to walk the children, but haven't done so yet.
22254 Remember that we've walked the kids. */
22257 /* If this is an array type, we need to make sure our
22258 kids get marked, even if they're types. If we're
22259 breaking out types into comdat sections, do this
22260 for all type definitions. */
22261 if (die
->die_tag
== DW_TAG_array_type
22262 || (use_debug_types
22263 && is_type_die (die
) && ! is_declaration_die (die
)))
22264 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22266 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22270 /* For local classes, look if any static member functions were emitted
22271 and if so, mark them. */
22274 prune_unused_types_walk_local_classes (dw_die_ref die
)
22278 if (die
->die_mark
== 2)
22281 switch (die
->die_tag
)
22283 case DW_TAG_structure_type
:
22284 case DW_TAG_union_type
:
22285 case DW_TAG_class_type
:
22288 case DW_TAG_subprogram
:
22289 if (!get_AT_flag (die
, DW_AT_declaration
)
22290 || die
->die_definition
!= NULL
)
22291 prune_unused_types_mark (die
, 1);
22298 /* Mark children. */
22299 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22302 /* Walk the tree DIE and mark types that we actually use. */
22305 prune_unused_types_walk (dw_die_ref die
)
22309 /* Don't do anything if this node is already marked and
22310 children have been marked as well. */
22311 if (die
->die_mark
== 2)
22314 switch (die
->die_tag
)
22316 case DW_TAG_structure_type
:
22317 case DW_TAG_union_type
:
22318 case DW_TAG_class_type
:
22319 if (die
->die_perennial_p
)
22322 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22323 if (c
->die_tag
== DW_TAG_subprogram
)
22326 /* Finding used static member functions inside of classes
22327 is needed just for local classes, because for other classes
22328 static member function DIEs with DW_AT_specification
22329 are emitted outside of the DW_TAG_*_type. If we ever change
22330 it, we'd need to call this even for non-local classes. */
22332 prune_unused_types_walk_local_classes (die
);
22334 /* It's a type node --- don't mark it. */
22337 case DW_TAG_const_type
:
22338 case DW_TAG_packed_type
:
22339 case DW_TAG_pointer_type
:
22340 case DW_TAG_reference_type
:
22341 case DW_TAG_rvalue_reference_type
:
22342 case DW_TAG_volatile_type
:
22343 case DW_TAG_typedef
:
22344 case DW_TAG_array_type
:
22345 case DW_TAG_interface_type
:
22346 case DW_TAG_friend
:
22347 case DW_TAG_variant_part
:
22348 case DW_TAG_enumeration_type
:
22349 case DW_TAG_subroutine_type
:
22350 case DW_TAG_string_type
:
22351 case DW_TAG_set_type
:
22352 case DW_TAG_subrange_type
:
22353 case DW_TAG_ptr_to_member_type
:
22354 case DW_TAG_file_type
:
22355 if (die
->die_perennial_p
)
22358 /* It's a type node --- don't mark it. */
22362 /* Mark everything else. */
22366 if (die
->die_mark
== 0)
22370 /* Now, mark any dies referenced from here. */
22371 prune_unused_types_walk_attribs (die
);
22376 /* Mark children. */
22377 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22380 /* Increment the string counts on strings referred to from DIE's
22384 prune_unused_types_update_strings (dw_die_ref die
)
22389 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22390 if (AT_class (a
) == dw_val_class_str
)
22392 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22394 /* Avoid unnecessarily putting strings that are used less than
22395 twice in the hash table. */
22397 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22400 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22401 htab_hash_string (s
->str
),
22403 gcc_assert (*slot
== NULL
);
22409 /* Remove from the tree DIE any dies that aren't marked. */
22412 prune_unused_types_prune (dw_die_ref die
)
22416 gcc_assert (die
->die_mark
);
22417 prune_unused_types_update_strings (die
);
22419 if (! die
->die_child
)
22422 c
= die
->die_child
;
22424 dw_die_ref prev
= c
;
22425 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22426 if (c
== die
->die_child
)
22428 /* No marked children between 'prev' and the end of the list. */
22430 /* No marked children at all. */
22431 die
->die_child
= NULL
;
22434 prev
->die_sib
= c
->die_sib
;
22435 die
->die_child
= prev
;
22440 if (c
!= prev
->die_sib
)
22442 prune_unused_types_prune (c
);
22443 } while (c
!= die
->die_child
);
22446 /* Remove dies representing declarations that we never use. */
22449 prune_unused_types (void)
22452 limbo_die_node
*node
;
22453 comdat_type_node
*ctnode
;
22455 dw_die_ref base_type
;
22457 #if ENABLE_ASSERT_CHECKING
22458 /* All the marks should already be clear. */
22459 verify_marks_clear (comp_unit_die ());
22460 for (node
= limbo_die_list
; node
; node
= node
->next
)
22461 verify_marks_clear (node
->die
);
22462 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22463 verify_marks_clear (ctnode
->root_die
);
22464 #endif /* ENABLE_ASSERT_CHECKING */
22466 /* Mark types that are used in global variables. */
22467 premark_types_used_by_global_vars ();
22469 /* Set the mark on nodes that are actually used. */
22470 prune_unused_types_walk (comp_unit_die ());
22471 for (node
= limbo_die_list
; node
; node
= node
->next
)
22472 prune_unused_types_walk (node
->die
);
22473 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22475 prune_unused_types_walk (ctnode
->root_die
);
22476 prune_unused_types_mark (ctnode
->type_die
, 1);
22479 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22480 are unusual in that they are pubnames that are the children of pubtypes.
22481 They should only be marked via their parent DW_TAG_enumeration_type die,
22482 not as roots in themselves. */
22483 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22484 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22485 prune_unused_types_mark (pub
->die
, 1);
22486 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22487 prune_unused_types_mark (base_type
, 1);
22489 if (debug_str_hash
)
22490 htab_empty (debug_str_hash
);
22491 if (skeleton_debug_str_hash
)
22492 htab_empty (skeleton_debug_str_hash
);
22493 prune_unused_types_prune (comp_unit_die ());
22494 for (node
= limbo_die_list
; node
; node
= node
->next
)
22495 prune_unused_types_prune (node
->die
);
22496 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22497 prune_unused_types_prune (ctnode
->root_die
);
22499 /* Leave the marks clear. */
22500 prune_unmark_dies (comp_unit_die ());
22501 for (node
= limbo_die_list
; node
; node
= node
->next
)
22502 prune_unmark_dies (node
->die
);
22503 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22504 prune_unmark_dies (ctnode
->root_die
);
22507 /* Set the parameter to true if there are any relative pathnames in
22510 file_table_relative_p (void ** slot
, void *param
)
22512 bool *p
= (bool *) param
;
22513 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22514 if (!IS_ABSOLUTE_PATH (d
->filename
))
22522 /* Helpers to manipulate hash table of comdat type units. */
22524 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
22526 typedef comdat_type_node value_type
;
22527 typedef comdat_type_node compare_type
;
22528 static inline hashval_t
hash (const value_type
*);
22529 static inline bool equal (const value_type
*, const compare_type
*);
22533 comdat_type_hasher::hash (const value_type
*type_node
)
22536 memcpy (&h
, type_node
->signature
, sizeof (h
));
22541 comdat_type_hasher::equal (const value_type
*type_node_1
,
22542 const compare_type
*type_node_2
)
22544 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22545 DWARF_TYPE_SIGNATURE_SIZE
));
22548 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22549 to the location it would have been added, should we know its
22550 DECL_ASSEMBLER_NAME when we added other attributes. This will
22551 probably improve compactness of debug info, removing equivalent
22552 abbrevs, and hide any differences caused by deferring the
22553 computation of the assembler name, triggered by e.g. PCH. */
22556 move_linkage_attr (dw_die_ref die
)
22558 unsigned ix
= vec_safe_length (die
->die_attr
);
22559 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22561 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22562 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22566 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22568 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22572 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22574 die
->die_attr
->pop ();
22575 die
->die_attr
->quick_insert (ix
, linkage
);
22579 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22580 referenced from typed stack ops and count how often they are used. */
22583 mark_base_types (dw_loc_descr_ref loc
)
22585 dw_die_ref base_type
= NULL
;
22587 for (; loc
; loc
= loc
->dw_loc_next
)
22589 switch (loc
->dw_loc_opc
)
22591 case DW_OP_GNU_regval_type
:
22592 case DW_OP_GNU_deref_type
:
22593 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22595 case DW_OP_GNU_convert
:
22596 case DW_OP_GNU_reinterpret
:
22597 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22600 case DW_OP_GNU_const_type
:
22601 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22603 case DW_OP_GNU_entry_value
:
22604 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22609 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22610 if (base_type
->die_mark
)
22611 base_type
->die_mark
++;
22614 base_types
.safe_push (base_type
);
22615 base_type
->die_mark
= 1;
22620 /* Comparison function for sorting marked base types. */
22623 base_type_cmp (const void *x
, const void *y
)
22625 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22626 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22627 unsigned int byte_size1
, byte_size2
;
22628 unsigned int encoding1
, encoding2
;
22629 if (dx
->die_mark
> dy
->die_mark
)
22631 if (dx
->die_mark
< dy
->die_mark
)
22633 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22634 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22635 if (byte_size1
< byte_size2
)
22637 if (byte_size1
> byte_size2
)
22639 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22640 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22641 if (encoding1
< encoding2
)
22643 if (encoding1
> encoding2
)
22648 /* Move base types marked by mark_base_types as early as possible
22649 in the CU, sorted by decreasing usage count both to make the
22650 uleb128 references as small as possible and to make sure they
22651 will have die_offset already computed by calc_die_sizes when
22652 sizes of typed stack loc ops is computed. */
22655 move_marked_base_types (void)
22658 dw_die_ref base_type
, die
, c
;
22660 if (base_types
.is_empty ())
22663 /* Sort by decreasing usage count, they will be added again in that
22665 base_types
.qsort (base_type_cmp
);
22666 die
= comp_unit_die ();
22667 c
= die
->die_child
;
22670 dw_die_ref prev
= c
;
22672 while (c
->die_mark
)
22674 remove_child_with_prev (c
, prev
);
22675 /* As base types got marked, there must be at least
22676 one node other than DW_TAG_base_type. */
22677 gcc_assert (c
!= c
->die_sib
);
22681 while (c
!= die
->die_child
);
22682 gcc_assert (die
->die_child
);
22683 c
= die
->die_child
;
22684 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22686 base_type
->die_mark
= 0;
22687 base_type
->die_sib
= c
->die_sib
;
22688 c
->die_sib
= base_type
;
22693 /* Helper function for resolve_addr, attempt to resolve
22694 one CONST_STRING, return non-zero if not successful. Similarly verify that
22695 SYMBOL_REFs refer to variables emitted in the current CU. */
22698 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22702 if (GET_CODE (rtl
) == CONST_STRING
)
22704 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22705 tree t
= build_string (len
, XSTR (rtl
, 0));
22706 tree tlen
= size_int (len
- 1);
22708 = build_array_type (char_type_node
, build_index_type (tlen
));
22709 rtl
= lookup_constant_def (t
);
22710 if (!rtl
|| !MEM_P (rtl
))
22712 rtl
= XEXP (rtl
, 0);
22713 if (GET_CODE (rtl
) == SYMBOL_REF
22714 && SYMBOL_REF_DECL (rtl
)
22715 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22717 vec_safe_push (used_rtx_array
, rtl
);
22722 if (GET_CODE (rtl
) == SYMBOL_REF
22723 && SYMBOL_REF_DECL (rtl
))
22725 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22727 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22730 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22734 if (GET_CODE (rtl
) == CONST
22735 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22741 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
22742 if possible, and create DW_TAG_dwarf_procedure that can be referenced
22743 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
22746 string_cst_pool_decl (tree t
)
22748 rtx rtl
= output_constant_def (t
, 1);
22749 unsigned char *array
;
22750 dw_loc_descr_ref l
;
22755 if (!rtl
|| !MEM_P (rtl
))
22757 rtl
= XEXP (rtl
, 0);
22758 if (GET_CODE (rtl
) != SYMBOL_REF
22759 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
22762 decl
= SYMBOL_REF_DECL (rtl
);
22763 if (!lookup_decl_die (decl
))
22765 len
= TREE_STRING_LENGTH (t
);
22766 vec_safe_push (used_rtx_array
, rtl
);
22767 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
22768 array
= (unsigned char *) ggc_alloc_atomic (len
);
22769 memcpy (array
, TREE_STRING_POINTER (t
), len
);
22770 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
22771 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
22772 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
22773 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
22774 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
22775 add_AT_loc (ref
, DW_AT_location
, l
);
22776 equate_decl_number_to_die (decl
, ref
);
22781 /* Helper function of resolve_addr_in_expr. LOC is
22782 a DW_OP_addr followed by DW_OP_stack_value, either at the start
22783 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
22784 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
22785 with DW_OP_GNU_implicit_pointer if possible
22786 and return true, if unsuccessful, return false. */
22789 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
22791 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
22792 HOST_WIDE_INT offset
= 0;
22793 dw_die_ref ref
= NULL
;
22796 if (GET_CODE (rtl
) == CONST
22797 && GET_CODE (XEXP (rtl
, 0)) == PLUS
22798 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
22800 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
22801 rtl
= XEXP (XEXP (rtl
, 0), 0);
22803 if (GET_CODE (rtl
) == CONST_STRING
)
22805 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22806 tree t
= build_string (len
, XSTR (rtl
, 0));
22807 tree tlen
= size_int (len
- 1);
22810 = build_array_type (char_type_node
, build_index_type (tlen
));
22811 rtl
= string_cst_pool_decl (t
);
22815 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
22817 decl
= SYMBOL_REF_DECL (rtl
);
22818 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
22820 ref
= lookup_decl_die (decl
);
22821 if (ref
&& (get_AT (ref
, DW_AT_location
)
22822 || get_AT (ref
, DW_AT_const_value
)))
22824 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
22825 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22826 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
22827 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22828 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22829 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22830 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
22838 /* Helper function for resolve_addr, handle one location
22839 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22840 the location list couldn't be resolved. */
22843 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22845 dw_loc_descr_ref keep
= NULL
;
22846 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
22847 switch (loc
->dw_loc_opc
)
22850 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22853 || prev
->dw_loc_opc
== DW_OP_piece
22854 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
22855 && loc
->dw_loc_next
22856 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
22858 && optimize_one_addr_into_implicit_ptr (loc
))
22863 case DW_OP_GNU_addr_index
:
22864 case DW_OP_GNU_const_index
:
22865 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22866 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22867 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22871 case DW_OP_const4u
:
22872 case DW_OP_const8u
:
22874 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22877 case DW_OP_plus_uconst
:
22878 if (size_of_loc_descr (loc
)
22879 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22881 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22883 dw_loc_descr_ref repl
22884 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22885 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
22886 add_loc_descr (&repl
, loc
->dw_loc_next
);
22890 case DW_OP_implicit_value
:
22891 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22892 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
22895 case DW_OP_GNU_implicit_pointer
:
22896 case DW_OP_GNU_parameter_ref
:
22897 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22900 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22903 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22904 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22905 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22908 case DW_OP_GNU_const_type
:
22909 case DW_OP_GNU_regval_type
:
22910 case DW_OP_GNU_deref_type
:
22911 case DW_OP_GNU_convert
:
22912 case DW_OP_GNU_reinterpret
:
22913 while (loc
->dw_loc_next
22914 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
22916 dw_die_ref base1
, base2
;
22917 unsigned enc1
, enc2
, size1
, size2
;
22918 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22919 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22920 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22921 else if (loc
->dw_loc_oprnd1
.val_class
22922 == dw_val_class_unsigned_const
)
22925 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22926 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
22927 == dw_val_class_unsigned_const
)
22929 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22930 gcc_assert (base1
->die_tag
== DW_TAG_base_type
22931 && base2
->die_tag
== DW_TAG_base_type
);
22932 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
22933 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
22934 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
22935 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
22937 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
22938 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
22942 /* Optimize away next DW_OP_GNU_convert after
22943 adjusting LOC's base type die reference. */
22944 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22945 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22946 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
22948 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
22949 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22952 /* Don't change integer DW_OP_GNU_convert after e.g. floating
22953 point typed stack entry. */
22954 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
22955 keep
= loc
->dw_loc_next
;
22965 /* Helper function of resolve_addr. DIE had DW_AT_location of
22966 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
22967 and DW_OP_addr couldn't be resolved. resolve_addr has already
22968 removed the DW_AT_location attribute. This function attempts to
22969 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
22970 to it or DW_AT_const_value attribute, if possible. */
22973 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
22975 if (TREE_CODE (decl
) != VAR_DECL
22976 || lookup_decl_die (decl
) != die
22977 || DECL_EXTERNAL (decl
)
22978 || !TREE_STATIC (decl
)
22979 || DECL_INITIAL (decl
) == NULL_TREE
22980 || DECL_P (DECL_INITIAL (decl
))
22981 || get_AT (die
, DW_AT_const_value
))
22984 tree init
= DECL_INITIAL (decl
);
22985 HOST_WIDE_INT offset
= 0;
22986 /* For variables that have been optimized away and thus
22987 don't have a memory location, see if we can emit
22988 DW_AT_const_value instead. */
22989 if (tree_add_const_value_attribute (die
, init
))
22993 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
22994 and ADDR_EXPR refers to a decl that has DW_AT_location or
22995 DW_AT_const_value (but isn't addressable, otherwise
22996 resolving the original DW_OP_addr wouldn't fail), see if
22997 we can add DW_OP_GNU_implicit_pointer. */
22999 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
23000 && host_integerp (TREE_OPERAND (init
, 1), 0))
23002 offset
= tree_low_cst (TREE_OPERAND (init
, 1), 0);
23003 init
= TREE_OPERAND (init
, 0);
23006 if (TREE_CODE (init
) != ADDR_EXPR
)
23008 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
23009 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
23010 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
23011 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
23012 && TREE_OPERAND (init
, 0) != decl
))
23015 dw_loc_descr_ref l
;
23017 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
23019 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
23022 decl
= SYMBOL_REF_DECL (rtl
);
23025 decl
= TREE_OPERAND (init
, 0);
23026 ref
= lookup_decl_die (decl
);
23028 || (!get_AT (ref
, DW_AT_location
)
23029 && !get_AT (ref
, DW_AT_const_value
)))
23031 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
23032 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23033 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23034 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23035 add_AT_loc (die
, DW_AT_location
, l
);
23039 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23040 an address in .rodata section if the string literal is emitted there,
23041 or remove the containing location list or replace DW_AT_const_value
23042 with DW_AT_location and empty location expression, if it isn't found
23043 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23044 to something that has been emitted in the current CU. */
23047 resolve_addr (dw_die_ref die
)
23051 dw_loc_list_ref
*curr
, *start
, loc
;
23054 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23055 switch (AT_class (a
))
23057 case dw_val_class_loc_list
:
23058 start
= curr
= AT_loc_list_ptr (a
);
23061 /* The same list can be referenced more than once. See if we have
23062 already recorded the result from a previous pass. */
23064 *curr
= loc
->dw_loc_next
;
23065 else if (!loc
->resolved_addr
)
23067 /* As things stand, we do not expect or allow one die to
23068 reference a suffix of another die's location list chain.
23069 References must be identical or completely separate.
23070 There is therefore no need to cache the result of this
23071 pass on any list other than the first; doing so
23072 would lead to unnecessary writes. */
23075 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23076 if (!resolve_addr_in_expr ((*curr
)->expr
))
23078 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23079 dw_loc_descr_ref l
= (*curr
)->expr
;
23081 if (next
&& (*curr
)->ll_symbol
)
23083 gcc_assert (!next
->ll_symbol
);
23084 next
->ll_symbol
= (*curr
)->ll_symbol
;
23086 if (dwarf_split_debug_info
)
23087 remove_loc_list_addr_table_entries (l
);
23092 mark_base_types ((*curr
)->expr
);
23093 curr
= &(*curr
)->dw_loc_next
;
23097 loc
->resolved_addr
= 1;
23101 loc
->dw_loc_next
= *start
;
23106 remove_AT (die
, a
->dw_attr
);
23110 case dw_val_class_loc
:
23112 dw_loc_descr_ref l
= AT_loc (a
);
23113 /* For -gdwarf-2 don't attempt to optimize
23114 DW_AT_data_member_location containing
23115 DW_OP_plus_uconst - older consumers might
23116 rely on it being that op instead of a more complex,
23117 but shorter, location description. */
23118 if ((dwarf_version
> 2
23119 || a
->dw_attr
!= DW_AT_data_member_location
23121 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23122 || l
->dw_loc_next
!= NULL
)
23123 && !resolve_addr_in_expr (l
))
23125 if (dwarf_split_debug_info
)
23126 remove_loc_list_addr_table_entries (l
);
23128 && l
->dw_loc_next
== NULL
23129 && l
->dw_loc_opc
== DW_OP_addr
23130 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
23131 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
23132 && a
->dw_attr
== DW_AT_location
)
23134 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
23135 remove_AT (die
, a
->dw_attr
);
23137 optimize_location_into_implicit_ptr (die
, decl
);
23140 remove_AT (die
, a
->dw_attr
);
23144 mark_base_types (l
);
23147 case dw_val_class_addr
:
23148 if (a
->dw_attr
== DW_AT_const_value
23149 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23151 if (AT_index (a
) != NOT_INDEXED
)
23152 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23153 remove_AT (die
, a
->dw_attr
);
23156 if (die
->die_tag
== DW_TAG_GNU_call_site
23157 && a
->dw_attr
== DW_AT_abstract_origin
)
23159 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23160 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23162 && DECL_EXTERNAL (tdecl
)
23163 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23165 force_decl_die (tdecl
);
23166 tdie
= lookup_decl_die (tdecl
);
23170 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23171 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23172 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23176 if (AT_index (a
) != NOT_INDEXED
)
23177 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23178 remove_AT (die
, a
->dw_attr
);
23187 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23190 /* Helper routines for optimize_location_lists.
23191 This pass tries to share identical local lists in .debug_loc
23194 /* Iteratively hash operands of LOC opcode. */
23197 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23199 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23200 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23202 switch (loc
->dw_loc_opc
)
23204 case DW_OP_const4u
:
23205 case DW_OP_const8u
:
23209 case DW_OP_const1u
:
23210 case DW_OP_const1s
:
23211 case DW_OP_const2u
:
23212 case DW_OP_const2s
:
23213 case DW_OP_const4s
:
23214 case DW_OP_const8s
:
23218 case DW_OP_plus_uconst
:
23254 case DW_OP_deref_size
:
23255 case DW_OP_xderef_size
:
23256 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23263 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23264 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23265 hash
= iterative_hash_object (offset
, hash
);
23268 case DW_OP_implicit_value
:
23269 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23270 switch (val2
->val_class
)
23272 case dw_val_class_const
:
23273 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23275 case dw_val_class_vec
:
23277 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23278 unsigned int len
= val2
->v
.val_vec
.length
;
23280 hash
= iterative_hash_object (elt_size
, hash
);
23281 hash
= iterative_hash_object (len
, hash
);
23282 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23283 len
* elt_size
, hash
);
23286 case dw_val_class_const_double
:
23287 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23288 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23290 case dw_val_class_addr
:
23291 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23294 gcc_unreachable ();
23298 case DW_OP_bit_piece
:
23299 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23300 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23306 unsigned char dtprel
= 0xd1;
23307 hash
= iterative_hash_object (dtprel
, hash
);
23309 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23311 case DW_OP_GNU_addr_index
:
23312 case DW_OP_GNU_const_index
:
23316 unsigned char dtprel
= 0xd1;
23317 hash
= iterative_hash_object (dtprel
, hash
);
23319 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23322 case DW_OP_GNU_implicit_pointer
:
23323 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23325 case DW_OP_GNU_entry_value
:
23326 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23328 case DW_OP_GNU_regval_type
:
23329 case DW_OP_GNU_deref_type
:
23331 unsigned int byte_size
23332 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23333 unsigned int encoding
23334 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23335 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23336 hash
= iterative_hash_object (byte_size
, hash
);
23337 hash
= iterative_hash_object (encoding
, hash
);
23340 case DW_OP_GNU_convert
:
23341 case DW_OP_GNU_reinterpret
:
23342 if (val1
->val_class
== dw_val_class_unsigned_const
)
23344 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23348 case DW_OP_GNU_const_type
:
23350 unsigned int byte_size
23351 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23352 unsigned int encoding
23353 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23354 hash
= iterative_hash_object (byte_size
, hash
);
23355 hash
= iterative_hash_object (encoding
, hash
);
23356 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23358 hash
= iterative_hash_object (val2
->val_class
, hash
);
23359 switch (val2
->val_class
)
23361 case dw_val_class_const
:
23362 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23364 case dw_val_class_vec
:
23366 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23367 unsigned int len
= val2
->v
.val_vec
.length
;
23369 hash
= iterative_hash_object (elt_size
, hash
);
23370 hash
= iterative_hash_object (len
, hash
);
23371 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23372 len
* elt_size
, hash
);
23375 case dw_val_class_const_double
:
23376 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23377 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23380 gcc_unreachable ();
23386 /* Other codes have no operands. */
23392 /* Iteratively hash the whole DWARF location expression LOC. */
23394 static inline hashval_t
23395 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23397 dw_loc_descr_ref l
;
23398 bool sizes_computed
= false;
23399 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23400 size_of_locs (loc
);
23402 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23404 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23405 hash
= iterative_hash_object (opc
, hash
);
23406 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23408 size_of_locs (loc
);
23409 sizes_computed
= true;
23411 hash
= hash_loc_operands (l
, hash
);
23416 /* Compute hash of the whole location list LIST_HEAD. */
23419 hash_loc_list (dw_loc_list_ref list_head
)
23421 dw_loc_list_ref curr
= list_head
;
23422 hashval_t hash
= 0;
23424 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23426 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23427 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23429 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23431 hash
= hash_locs (curr
->expr
, hash
);
23433 list_head
->hash
= hash
;
23436 /* Return true if X and Y opcodes have the same operands. */
23439 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23441 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23442 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23443 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23444 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23446 switch (x
->dw_loc_opc
)
23448 case DW_OP_const4u
:
23449 case DW_OP_const8u
:
23453 case DW_OP_const1u
:
23454 case DW_OP_const1s
:
23455 case DW_OP_const2u
:
23456 case DW_OP_const2s
:
23457 case DW_OP_const4s
:
23458 case DW_OP_const8s
:
23462 case DW_OP_plus_uconst
:
23498 case DW_OP_deref_size
:
23499 case DW_OP_xderef_size
:
23500 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23503 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23504 can cause irrelevant differences in dw_loc_addr. */
23505 gcc_assert (valx1
->val_class
== dw_val_class_loc
23506 && valy1
->val_class
== dw_val_class_loc
23507 && (dwarf_split_debug_info
23508 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23509 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23510 case DW_OP_implicit_value
:
23511 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23512 || valx2
->val_class
!= valy2
->val_class
)
23514 switch (valx2
->val_class
)
23516 case dw_val_class_const
:
23517 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23518 case dw_val_class_vec
:
23519 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23520 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23521 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23522 valx2
->v
.val_vec
.elt_size
23523 * valx2
->v
.val_vec
.length
) == 0;
23524 case dw_val_class_const_double
:
23525 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23526 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23527 case dw_val_class_addr
:
23528 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23530 gcc_unreachable ();
23533 case DW_OP_bit_piece
:
23534 return valx1
->v
.val_int
== valy1
->v
.val_int
23535 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23538 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23539 case DW_OP_GNU_addr_index
:
23540 case DW_OP_GNU_const_index
:
23542 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23543 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23544 return rtx_equal_p (ax1
, ay1
);
23546 case DW_OP_GNU_implicit_pointer
:
23547 return valx1
->val_class
== dw_val_class_die_ref
23548 && valx1
->val_class
== valy1
->val_class
23549 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23550 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23551 case DW_OP_GNU_entry_value
:
23552 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23553 case DW_OP_GNU_const_type
:
23554 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23555 || valx2
->val_class
!= valy2
->val_class
)
23557 switch (valx2
->val_class
)
23559 case dw_val_class_const
:
23560 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23561 case dw_val_class_vec
:
23562 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23563 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23564 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23565 valx2
->v
.val_vec
.elt_size
23566 * valx2
->v
.val_vec
.length
) == 0;
23567 case dw_val_class_const_double
:
23568 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23569 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23571 gcc_unreachable ();
23573 case DW_OP_GNU_regval_type
:
23574 case DW_OP_GNU_deref_type
:
23575 return valx1
->v
.val_int
== valy1
->v
.val_int
23576 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23577 case DW_OP_GNU_convert
:
23578 case DW_OP_GNU_reinterpret
:
23579 if (valx1
->val_class
!= valy1
->val_class
)
23581 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23582 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23583 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23584 case DW_OP_GNU_parameter_ref
:
23585 return valx1
->val_class
== dw_val_class_die_ref
23586 && valx1
->val_class
== valy1
->val_class
23587 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23589 /* Other codes have no operands. */
23594 /* Return true if DWARF location expressions X and Y are the same. */
23597 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23599 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23600 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23601 || x
->dtprel
!= y
->dtprel
23602 || !compare_loc_operands (x
, y
))
23604 return x
== NULL
&& y
== NULL
;
23607 /* Hashtable helpers. */
23609 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
23611 typedef dw_loc_list_struct value_type
;
23612 typedef dw_loc_list_struct compare_type
;
23613 static inline hashval_t
hash (const value_type
*);
23614 static inline bool equal (const value_type
*, const compare_type
*);
23617 /* Return precomputed hash of location list X. */
23620 loc_list_hasher::hash (const value_type
*x
)
23625 /* Return true if location lists A and B are the same. */
23628 loc_list_hasher::equal (const value_type
*a
, const compare_type
*b
)
23632 if (a
->hash
!= b
->hash
)
23634 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23635 if (strcmp (a
->begin
, b
->begin
) != 0
23636 || strcmp (a
->end
, b
->end
) != 0
23637 || (a
->section
== NULL
) != (b
->section
== NULL
)
23638 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23639 || !compare_locs (a
->expr
, b
->expr
))
23641 return a
== NULL
&& b
== NULL
;
23644 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
23647 /* Recursively optimize location lists referenced from DIE
23648 children and share them whenever possible. */
23651 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type htab
)
23656 dw_loc_list_struct
**slot
;
23658 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23659 if (AT_class (a
) == dw_val_class_loc_list
)
23661 dw_loc_list_ref list
= AT_loc_list (a
);
23662 /* TODO: perform some optimizations here, before hashing
23663 it and storing into the hash table. */
23664 hash_loc_list (list
);
23665 slot
= htab
.find_slot_with_hash (list
, list
->hash
, INSERT
);
23669 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
23672 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23676 /* Recursively assign each location list a unique index into the debug_addr
23680 index_location_lists (dw_die_ref die
)
23686 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23687 if (AT_class (a
) == dw_val_class_loc_list
)
23689 dw_loc_list_ref list
= AT_loc_list (a
);
23690 dw_loc_list_ref curr
;
23691 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23693 /* Don't index an entry that has already been indexed
23694 or won't be output. */
23695 if (curr
->begin_entry
!= NULL
23696 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23700 = add_addr_table_entry (xstrdup (curr
->begin
),
23705 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23708 /* Optimize location lists referenced from DIE
23709 children and share them whenever possible. */
23712 optimize_location_lists (dw_die_ref die
)
23714 loc_list_hash_type htab
;
23716 optimize_location_lists_1 (die
, htab
);
23720 /* Output stuff that dwarf requires at the end of every file,
23721 and generate the DWARF-2 debugging info. */
23724 dwarf2out_finish (const char *filename
)
23726 limbo_die_node
*node
, *next_node
;
23727 comdat_type_node
*ctnode
;
23728 hash_table
<comdat_type_hasher
> comdat_type_table
;
23730 dw_die_ref main_comp_unit_die
;
23732 /* PCH might result in DW_AT_producer string being restored from the
23733 header compilation, so always fill it with empty string initially
23734 and overwrite only here. */
23735 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23736 producer_string
= gen_producer_string ();
23737 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23738 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23740 gen_scheduled_generic_parms_dies ();
23741 gen_remaining_tmpl_value_param_die_attribute ();
23743 /* Add the name for the main input file now. We delayed this from
23744 dwarf2out_init to avoid complications with PCH. */
23745 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23746 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23747 add_comp_dir_attribute (comp_unit_die ());
23748 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23751 htab_traverse (file_table
, file_table_relative_p
, &p
);
23753 add_comp_dir_attribute (comp_unit_die ());
23756 if (deferred_locations_list
)
23757 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23759 add_location_or_const_value_attribute (
23760 (*deferred_locations_list
)[i
].die
,
23761 (*deferred_locations_list
)[i
].variable
,
23766 /* Traverse the limbo die list, and add parent/child links. The only
23767 dies without parents that should be here are concrete instances of
23768 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23769 For concrete instances, we can get the parent die from the abstract
23771 for (node
= limbo_die_list
; node
; node
= next_node
)
23773 dw_die_ref die
= node
->die
;
23774 next_node
= node
->next
;
23776 if (die
->die_parent
== NULL
)
23778 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23780 if (origin
&& origin
->die_parent
)
23781 add_child_die (origin
->die_parent
, die
);
23782 else if (is_cu_die (die
))
23784 else if (seen_error ())
23785 /* It's OK to be confused by errors in the input. */
23786 add_child_die (comp_unit_die (), die
);
23789 /* In certain situations, the lexical block containing a
23790 nested function can be optimized away, which results
23791 in the nested function die being orphaned. Likewise
23792 with the return type of that nested function. Force
23793 this to be a child of the containing function.
23795 It may happen that even the containing function got fully
23796 inlined and optimized out. In that case we are lost and
23797 assign the empty child. This should not be big issue as
23798 the function is likely unreachable too. */
23799 gcc_assert (node
->created_for
);
23801 if (DECL_P (node
->created_for
))
23802 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23803 else if (TYPE_P (node
->created_for
))
23804 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23806 origin
= comp_unit_die ();
23808 add_child_die (origin
, die
);
23813 limbo_die_list
= NULL
;
23815 #if ENABLE_ASSERT_CHECKING
23817 dw_die_ref die
= comp_unit_die (), c
;
23818 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23821 resolve_addr (comp_unit_die ());
23822 move_marked_base_types ();
23824 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23826 tree decl
= node
->created_for
;
23827 /* When generating LTO bytecode we can not generate new assembler
23828 names at this point and all important decls got theirs via
23830 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23831 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23833 add_linkage_attr (node
->die
, decl
);
23834 move_linkage_attr (node
->die
);
23838 deferred_asm_name
= NULL
;
23840 /* Walk through the list of incomplete types again, trying once more to
23841 emit full debugging info for them. */
23842 retry_incomplete_types ();
23844 if (flag_eliminate_unused_debug_types
)
23845 prune_unused_types ();
23847 /* Generate separate COMDAT sections for type DIEs. */
23848 if (use_debug_types
)
23850 break_out_comdat_types (comp_unit_die ());
23852 /* Each new type_unit DIE was added to the limbo die list when created.
23853 Since these have all been added to comdat_type_list, clear the
23855 limbo_die_list
= NULL
;
23857 /* For each new comdat type unit, copy declarations for incomplete
23858 types to make the new unit self-contained (i.e., no direct
23859 references to the main compile unit). */
23860 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23861 copy_decls_for_unworthy_types (ctnode
->root_die
);
23862 copy_decls_for_unworthy_types (comp_unit_die ());
23864 /* In the process of copying declarations from one unit to another,
23865 we may have left some declarations behind that are no longer
23866 referenced. Prune them. */
23867 prune_unused_types ();
23870 /* Generate separate CUs for each of the include files we've seen.
23871 They will go into limbo_die_list. */
23872 if (flag_eliminate_dwarf2_dups
)
23873 break_out_includes (comp_unit_die ());
23875 /* Traverse the DIE's and add add sibling attributes to those DIE's
23876 that have children. */
23877 add_sibling_attributes (comp_unit_die ());
23878 for (node
= limbo_die_list
; node
; node
= node
->next
)
23879 add_sibling_attributes (node
->die
);
23880 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23881 add_sibling_attributes (ctnode
->root_die
);
23883 /* When splitting DWARF info, we put some attributes in the
23884 skeleton compile_unit DIE that remains in the .o, while
23885 most attributes go in the DWO compile_unit_die. */
23886 if (dwarf_split_debug_info
)
23887 main_comp_unit_die
= gen_compile_unit_die (NULL
);
23889 main_comp_unit_die
= comp_unit_die ();
23891 /* Output a terminator label for the .text section. */
23892 switch_to_section (text_section
);
23893 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23894 if (cold_text_section
)
23896 switch_to_section (cold_text_section
);
23897 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23900 /* We can only use the low/high_pc attributes if all of the code was
23902 if (!have_multiple_function_sections
23903 || (dwarf_version
< 3 && dwarf_strict
))
23905 /* Don't add if the CU has no associated code. */
23906 if (text_section_used
)
23907 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
23908 text_end_label
, true);
23914 bool range_list_added
= false;
23916 if (text_section_used
)
23917 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
23918 text_end_label
, &range_list_added
, true);
23919 if (cold_text_section_used
)
23920 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
23921 cold_end_label
, &range_list_added
, true);
23923 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
23925 if (DECL_IGNORED_P (fde
->decl
))
23927 if (!fde
->in_std_section
)
23928 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
23929 fde
->dw_fde_end
, &range_list_added
,
23931 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23932 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
23933 fde
->dw_fde_second_end
, &range_list_added
,
23937 if (range_list_added
)
23939 /* We need to give .debug_loc and .debug_ranges an appropriate
23940 "base address". Use zero so that these addresses become
23941 absolute. Historically, we've emitted the unexpected
23942 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23943 Emit both to give time for other tools to adapt. */
23944 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
23945 if (! dwarf_strict
&& dwarf_version
< 4)
23946 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
23952 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23953 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
23954 debug_line_section_label
);
23957 add_AT_macptr (comp_unit_die (),
23958 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
23959 macinfo_section_label
);
23961 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
23963 /* optimize_location_lists calculates the size of the lists,
23964 so index them first, and assign indices to the entries.
23965 Although optimize_location_lists will remove entries from
23966 the table, it only does so for duplicates, and therefore
23967 only reduces ref_counts to 1. */
23968 unsigned int index
= 0;
23969 index_location_lists (comp_unit_die ());
23970 htab_traverse_noresize (addr_index_table
,
23971 index_addr_table_entry
, &index
);
23973 if (have_location_lists
)
23974 optimize_location_lists (comp_unit_die ());
23976 save_macinfo_strings ();
23978 if (dwarf_split_debug_info
)
23980 unsigned int index
= 0;
23982 /* Add attributes common to skeleton compile_units and
23983 type_units. Because these attributes include strings, it
23984 must be done before freezing the string table. Top-level
23985 skeleton die attrs are added when the skeleton type unit is
23986 created, so ensure it is created by this point. */
23987 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
23988 (void) get_skeleton_type_unit ();
23989 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
23992 /* Output all of the compilation units. We put the main one last so that
23993 the offsets are available to output_pubnames. */
23994 for (node
= limbo_die_list
; node
; node
= node
->next
)
23995 output_comp_unit (node
->die
, 0);
23997 comdat_type_table
.create (100);
23998 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24000 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
24002 /* Don't output duplicate types. */
24003 if (*slot
!= HTAB_EMPTY_ENTRY
)
24006 /* Add a pointer to the line table for the main compilation unit
24007 so that the debugger can make sense of DW_AT_decl_file
24009 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
24010 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
24011 (!dwarf_split_debug_info
24012 ? debug_line_section_label
24013 : debug_skeleton_line_section_label
));
24015 output_comdat_type_unit (ctnode
);
24018 comdat_type_table
.dispose ();
24020 /* The AT_pubnames attribute needs to go in all skeleton dies, including
24021 both the main_cu and all skeleton TUs. Making this call unconditional
24022 would end up either adding a second copy of the AT_pubnames attribute, or
24023 requiring a special case in add_top_level_skeleton_die_attrs. */
24024 if (!dwarf_split_debug_info
)
24025 add_AT_pubnames (comp_unit_die ());
24027 if (dwarf_split_debug_info
)
24030 unsigned char checksum
[16];
24031 struct md5_ctx ctx
;
24033 /* Compute a checksum of the comp_unit to use as the dwo_id. */
24034 md5_init_ctx (&ctx
);
24036 die_checksum (comp_unit_die (), &ctx
, &mark
);
24037 unmark_all_dies (comp_unit_die ());
24038 md5_finish_ctx (&ctx
, checksum
);
24040 /* Use the first 8 bytes of the checksum as the dwo_id,
24041 and add it to both comp-unit DIEs. */
24042 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
24043 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
24045 /* Add the base offset of the ranges table to the skeleton
24047 if (ranges_table_in_use
)
24048 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
24049 ranges_section_label
);
24051 switch_to_section (debug_addr_section
);
24052 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
24053 output_addr_table ();
24056 /* Output the main compilation unit if non-empty or if .debug_macinfo
24057 or .debug_macro will be emitted. */
24058 output_comp_unit (comp_unit_die (), have_macinfo
);
24060 if (dwarf_split_debug_info
&& info_section_emitted
)
24061 output_skeleton_debug_sections (main_comp_unit_die
);
24063 /* Output the abbreviation table. */
24064 if (abbrev_die_table_in_use
!= 1)
24066 switch_to_section (debug_abbrev_section
);
24067 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
24068 output_abbrev_section ();
24071 /* Output location list section if necessary. */
24072 if (have_location_lists
)
24074 /* Output the location lists info. */
24075 switch_to_section (debug_loc_section
);
24076 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
24077 output_location_lists (comp_unit_die ());
24080 /* Output public names and types tables if necessary. */
24081 output_pubnames (pubname_table
);
24082 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
24083 It shouldn't hurt to emit it always, since pure DWARF2 consumers
24084 simply won't look for the section. */
24085 output_pubnames (pubtype_table
);
24087 /* Output the address range information if a CU (.debug_info section)
24088 was emitted. We output an empty table even if we had no functions
24089 to put in it. This because the consumer has no way to tell the
24090 difference between an empty table that we omitted and failure to
24091 generate a table that would have contained data. */
24092 if (info_section_emitted
)
24094 unsigned long aranges_length
= size_of_aranges ();
24096 switch_to_section (debug_aranges_section
);
24097 output_aranges (aranges_length
);
24100 /* Output ranges section if necessary. */
24101 if (ranges_table_in_use
)
24103 switch_to_section (debug_ranges_section
);
24104 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24108 /* Have to end the macro section. */
24111 switch_to_section (debug_macinfo_section
);
24112 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24114 dw2_asm_output_data (1, 0, "End compilation unit");
24117 /* Output the source line correspondence table. We must do this
24118 even if there is no line information. Otherwise, on an empty
24119 translation unit, we will generate a present, but empty,
24120 .debug_info section. IRIX 6.5 `nm' will then complain when
24121 examining the file. This is done late so that any filenames
24122 used by the debug_info section are marked as 'used'. */
24123 switch_to_section (debug_line_section
);
24124 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24125 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24126 output_line_info (false);
24128 if (dwarf_split_debug_info
&& info_section_emitted
)
24130 switch_to_section (debug_skeleton_line_section
);
24131 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24132 output_line_info (true);
24135 /* If we emitted any indirect strings, output the string table too. */
24136 if (debug_str_hash
|| skeleton_debug_str_hash
)
24137 output_indirect_strings ();
24140 #include "gt-dwarf2out.h"