1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2013 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 /* TODO: Emit .debug_line header even when there are no functions, since
24 the file numbers are used by .debug_info. Alternately, leave
25 out locations for types and decls.
26 Avoid talking about ctors and op= for PODs.
27 Factor out common prologue sequences into multiple CIEs. */
29 /* The first part of this file deals with the DWARF 2 frame unwind
30 information, which is also used by the GCC efficient exception handling
31 mechanism. The second part, controlled only by an #ifdef
32 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 /* DWARF2 Abbreviation Glossary:
37 CFA = Canonical Frame Address
38 a fixed address on the stack which identifies a call frame.
39 We define it to be the value of SP just before the call insn.
40 The CFA register and offset, which may change during the course
41 of the function, are used to calculate its value at runtime.
43 CFI = Call Frame Instruction
44 an instruction for the DWARF2 abstract machine
46 CIE = Common Information Entry
47 information describing information common to one or more FDEs
49 DIE = Debugging Information Entry
51 FDE = Frame Description Entry
52 information describing the stack call frame, in particular,
53 how to restore registers
55 DW_CFA_... = DWARF2 CFA call frame instruction
56 DW_TAG_... = DWARF2 DIE tag */
60 #include "coretypes.h"
66 #include "hard-reg-set.h"
68 #include "insn-config.h"
75 #include "dwarf2out.h"
76 #include "dwarf2asm.h"
81 #include "diagnostic.h"
82 #include "tree-pretty-print.h"
85 #include "common/common-target.h"
86 #include "langhooks.h"
96 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_offsets_section
;
161 static GTY(()) section
*debug_ranges_section
;
162 static GTY(()) section
*debug_frame_section
;
164 /* Maximum size (in bytes) of an artificially generated label. */
165 #define MAX_ARTIFICIAL_LABEL_BYTES 30
167 /* According to the (draft) DWARF 3 specification, the initial length
168 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
169 bytes are 0xffffffff, followed by the length stored in the next 8
172 However, the SGI/MIPS ABI uses an initial length which is equal to
173 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
175 #ifndef DWARF_INITIAL_LENGTH_SIZE
176 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
179 /* Round SIZE up to the nearest BOUNDARY. */
180 #define DWARF_ROUND(SIZE,BOUNDARY) \
181 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
183 /* CIE identifier. */
184 #if HOST_BITS_PER_WIDE_INT >= 64
185 #define DWARF_CIE_ID \
186 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
188 #define DWARF_CIE_ID DW_CIE_ID
192 /* A vector for a table that contains frame description
193 information for each routine. */
194 #define NOT_INDEXED (-1U)
195 #define NO_INDEX_ASSIGNED (-2U)
197 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
199 struct GTY(()) indirect_string_node
{
201 unsigned int refcount
;
202 enum dwarf_form form
;
207 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
209 static GTY(()) int dw2_string_counter
;
211 /* True if the compilation unit places functions in more than one section. */
212 static GTY(()) bool have_multiple_function_sections
= false;
214 /* Whether the default text and cold text sections have been used at all. */
216 static GTY(()) bool text_section_used
= false;
217 static GTY(()) bool cold_text_section_used
= false;
219 /* The default cold text section. */
220 static GTY(()) section
*cold_text_section
;
222 /* Forward declarations for functions defined in this file. */
224 static char *stripattributes (const char *);
225 static void output_call_frame_info (int);
226 static void dwarf2out_note_section_used (void);
228 /* Personality decl of current unit. Used only when assembler does not support
230 static GTY(()) rtx current_unit_personality
;
232 /* Data and reference forms for relocatable data. */
233 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
234 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
236 #ifndef DEBUG_FRAME_SECTION
237 #define DEBUG_FRAME_SECTION ".debug_frame"
240 #ifndef FUNC_BEGIN_LABEL
241 #define FUNC_BEGIN_LABEL "LFB"
244 #ifndef FUNC_END_LABEL
245 #define FUNC_END_LABEL "LFE"
248 #ifndef PROLOGUE_END_LABEL
249 #define PROLOGUE_END_LABEL "LPE"
252 #ifndef EPILOGUE_BEGIN_LABEL
253 #define EPILOGUE_BEGIN_LABEL "LEB"
256 #ifndef FRAME_BEGIN_LABEL
257 #define FRAME_BEGIN_LABEL "Lframe"
259 #define CIE_AFTER_SIZE_LABEL "LSCIE"
260 #define CIE_END_LABEL "LECIE"
261 #define FDE_LABEL "LSFDE"
262 #define FDE_AFTER_SIZE_LABEL "LASFDE"
263 #define FDE_END_LABEL "LEFDE"
264 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
265 #define LINE_NUMBER_END_LABEL "LELT"
266 #define LN_PROLOG_AS_LABEL "LASLTP"
267 #define LN_PROLOG_END_LABEL "LELTP"
268 #define DIE_LABEL_PREFIX "DW"
270 /* Match the base name of a file to the base name of a compilation unit. */
273 matches_main_base (const char *path
)
275 /* Cache the last query. */
276 static const char *last_path
= NULL
;
277 static int last_match
= 0;
278 if (path
!= last_path
)
281 int length
= base_of_path (path
, &base
);
283 last_match
= (length
== main_input_baselength
284 && memcmp (base
, main_input_basename
, length
) == 0);
289 #ifdef DEBUG_DEBUG_STRUCT
292 dump_struct_debug (tree type
, enum debug_info_usage usage
,
293 enum debug_struct_file criterion
, int generic
,
294 int matches
, int result
)
296 /* Find the type name. */
297 tree type_decl
= TYPE_STUB_DECL (type
);
299 const char *name
= 0;
300 if (TREE_CODE (t
) == TYPE_DECL
)
303 name
= IDENTIFIER_POINTER (t
);
305 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
307 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
308 matches
? "bas" : "hdr",
309 generic
? "gen" : "ord",
310 usage
== DINFO_USAGE_DFN
? ";" :
311 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
313 (void*) type_decl
, name
);
316 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
317 dump_struct_debug (type, usage, criterion, generic, matches, result)
321 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
327 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
329 enum debug_struct_file criterion
;
331 bool generic
= lang_hooks
.types
.generic_p (type
);
334 criterion
= debug_struct_generic
[usage
];
336 criterion
= debug_struct_ordinary
[usage
];
338 if (criterion
== DINFO_STRUCT_FILE_NONE
)
339 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
340 if (criterion
== DINFO_STRUCT_FILE_ANY
)
341 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
343 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
345 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
346 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
348 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
349 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
350 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
353 /* Return a pointer to a copy of the section string name S with all
354 attributes stripped off, and an asterisk prepended (for assemble_name). */
357 stripattributes (const char *s
)
359 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
364 while (*s
&& *s
!= ',')
371 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
372 switch to the data section instead, and write out a synthetic start label
373 for collect2 the first time around. */
376 switch_to_eh_frame_section (bool back
)
380 #ifdef EH_FRAME_SECTION_NAME
381 if (eh_frame_section
== 0)
385 if (EH_TABLES_CAN_BE_READ_ONLY
)
391 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
393 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
395 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
398 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
399 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
400 && (per_encoding
& 0x70) != DW_EH_PE_absptr
401 && (per_encoding
& 0x70) != DW_EH_PE_aligned
402 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
403 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
404 ? 0 : SECTION_WRITE
);
407 flags
= SECTION_WRITE
;
408 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
410 #endif /* EH_FRAME_SECTION_NAME */
412 if (eh_frame_section
)
413 switch_to_section (eh_frame_section
);
416 /* We have no special eh_frame section. Put the information in
417 the data section and emit special labels to guide collect2. */
418 switch_to_section (data_section
);
422 label
= get_file_function_name ("F");
423 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
424 targetm
.asm_out
.globalize_label (asm_out_file
,
425 IDENTIFIER_POINTER (label
));
426 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
431 /* Switch [BACK] to the eh or debug frame table section, depending on
435 switch_to_frame_table_section (int for_eh
, bool back
)
438 switch_to_eh_frame_section (back
);
441 if (!debug_frame_section
)
442 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
443 SECTION_DEBUG
, NULL
);
444 switch_to_section (debug_frame_section
);
448 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
450 enum dw_cfi_oprnd_type
451 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
456 case DW_CFA_GNU_window_save
:
457 case DW_CFA_remember_state
:
458 case DW_CFA_restore_state
:
459 return dw_cfi_oprnd_unused
;
462 case DW_CFA_advance_loc1
:
463 case DW_CFA_advance_loc2
:
464 case DW_CFA_advance_loc4
:
465 case DW_CFA_MIPS_advance_loc8
:
466 return dw_cfi_oprnd_addr
;
469 case DW_CFA_offset_extended
:
471 case DW_CFA_offset_extended_sf
:
472 case DW_CFA_def_cfa_sf
:
474 case DW_CFA_restore_extended
:
475 case DW_CFA_undefined
:
476 case DW_CFA_same_value
:
477 case DW_CFA_def_cfa_register
:
478 case DW_CFA_register
:
479 case DW_CFA_expression
:
480 return dw_cfi_oprnd_reg_num
;
482 case DW_CFA_def_cfa_offset
:
483 case DW_CFA_GNU_args_size
:
484 case DW_CFA_def_cfa_offset_sf
:
485 return dw_cfi_oprnd_offset
;
487 case DW_CFA_def_cfa_expression
:
488 return dw_cfi_oprnd_loc
;
495 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
497 enum dw_cfi_oprnd_type
498 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
503 case DW_CFA_def_cfa_sf
:
505 case DW_CFA_offset_extended_sf
:
506 case DW_CFA_offset_extended
:
507 return dw_cfi_oprnd_offset
;
509 case DW_CFA_register
:
510 return dw_cfi_oprnd_reg_num
;
512 case DW_CFA_expression
:
513 return dw_cfi_oprnd_loc
;
516 return dw_cfi_oprnd_unused
;
520 /* Output one FDE. */
523 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
524 char *section_start_label
, int fde_encoding
, char *augmentation
,
525 bool any_lsda_needed
, int lsda_encoding
)
527 const char *begin
, *end
;
528 static unsigned int j
;
531 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
533 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
535 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
536 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
537 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
538 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
539 " indicating 64-bit DWARF extension");
540 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
542 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
545 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
547 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
548 debug_frame_section
, "FDE CIE offset");
550 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
551 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
555 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
556 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
557 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
558 "FDE initial location");
559 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
560 end
, begin
, "FDE address range");
564 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
565 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
572 int size
= size_of_encoded_value (lsda_encoding
);
574 if (lsda_encoding
== DW_EH_PE_aligned
)
576 int offset
= ( 4 /* Length */
578 + 2 * size_of_encoded_value (fde_encoding
)
579 + 1 /* Augmentation size */ );
580 int pad
= -offset
& (PTR_SIZE
- 1);
583 gcc_assert (size_of_uleb128 (size
) == 1);
586 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
588 if (fde
->uses_eh_lsda
)
590 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
591 fde
->funcdef_number
);
592 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
593 gen_rtx_SYMBOL_REF (Pmode
, l1
),
595 "Language Specific Data Area");
599 if (lsda_encoding
== DW_EH_PE_aligned
)
600 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
601 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
602 "Language Specific Data Area (none)");
606 dw2_asm_output_data_uleb128 (0, "Augmentation size");
609 /* Loop through the Call Frame Instructions associated with this FDE. */
610 fde
->dw_fde_current_label
= begin
;
612 size_t from
, until
, i
;
615 until
= vec_safe_length (fde
->dw_fde_cfi
);
617 if (fde
->dw_fde_second_begin
== NULL
)
620 until
= fde
->dw_fde_switch_cfi_index
;
622 from
= fde
->dw_fde_switch_cfi_index
;
624 for (i
= from
; i
< until
; i
++)
625 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
628 /* If we are to emit a ref/link from function bodies to their frame tables,
629 do it now. This is typically performed to make sure that tables
630 associated with functions are dragged with them and not discarded in
631 garbage collecting links. We need to do this on a per function basis to
632 cope with -ffunction-sections. */
634 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
635 /* Switch to the function section, emit the ref to the tables, and
636 switch *back* into the table section. */
637 switch_to_section (function_section (fde
->decl
));
638 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
639 switch_to_frame_table_section (for_eh
, true);
642 /* Pad the FDE out to an address sized boundary. */
643 ASM_OUTPUT_ALIGN (asm_out_file
,
644 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
645 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
650 /* Return true if frame description entry FDE is needed for EH. */
653 fde_needed_for_eh_p (dw_fde_ref fde
)
655 if (flag_asynchronous_unwind_tables
)
658 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
661 if (fde
->uses_eh_lsda
)
664 /* If exceptions are enabled, we have collected nothrow info. */
665 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
671 /* Output the call frame information used to record information
672 that relates to calculating the frame pointer, and records the
673 location of saved registers. */
676 output_call_frame_info (int for_eh
)
681 char l1
[20], l2
[20], section_start_label
[20];
682 bool any_lsda_needed
= false;
683 char augmentation
[6];
684 int augmentation_size
;
685 int fde_encoding
= DW_EH_PE_absptr
;
686 int per_encoding
= DW_EH_PE_absptr
;
687 int lsda_encoding
= DW_EH_PE_absptr
;
689 rtx personality
= NULL
;
692 /* Don't emit a CIE if there won't be any FDEs. */
696 /* Nothing to do if the assembler's doing it all. */
697 if (dwarf2out_do_cfi_asm ())
700 /* If we don't have any functions we'll want to unwind out of, don't emit
701 any EH unwind information. If we make FDEs linkonce, we may have to
702 emit an empty label for an FDE that wouldn't otherwise be emitted. We
703 want to avoid having an FDE kept around when the function it refers to
704 is discarded. Example where this matters: a primary function template
705 in C++ requires EH information, an explicit specialization doesn't. */
708 bool any_eh_needed
= false;
710 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
712 if (fde
->uses_eh_lsda
)
713 any_eh_needed
= any_lsda_needed
= true;
714 else if (fde_needed_for_eh_p (fde
))
715 any_eh_needed
= true;
716 else if (TARGET_USES_WEAK_UNWIND_INFO
)
717 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
724 /* We're going to be generating comments, so turn on app. */
728 /* Switch to the proper frame section, first time. */
729 switch_to_frame_table_section (for_eh
, false);
731 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
732 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
734 /* Output the CIE. */
735 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
736 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
737 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
738 dw2_asm_output_data (4, 0xffffffff,
739 "Initial length escape value indicating 64-bit DWARF extension");
740 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
741 "Length of Common Information Entry");
742 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
744 /* Now that the CIE pointer is PC-relative for EH,
745 use 0 to identify the CIE. */
746 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
747 (for_eh
? 0 : DWARF_CIE_ID
),
748 "CIE Identifier Tag");
750 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
751 use CIE version 1, unless that would produce incorrect results
752 due to overflowing the return register column. */
753 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
755 if (return_reg
>= 256 || dwarf_version
> 2)
757 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
760 augmentation_size
= 0;
762 personality
= current_unit_personality
;
768 z Indicates that a uleb128 is present to size the
769 augmentation section.
770 L Indicates the encoding (and thus presence) of
771 an LSDA pointer in the FDE augmentation.
772 R Indicates a non-default pointer encoding for
774 P Indicates the presence of an encoding + language
775 personality routine in the CIE augmentation. */
777 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
778 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
779 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
781 p
= augmentation
+ 1;
785 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
786 assemble_external_libcall (personality
);
791 augmentation_size
+= 1;
793 if (fde_encoding
!= DW_EH_PE_absptr
)
796 augmentation_size
+= 1;
798 if (p
> augmentation
+ 1)
800 augmentation
[0] = 'z';
804 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
805 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
807 int offset
= ( 4 /* Length */
809 + 1 /* CIE version */
810 + strlen (augmentation
) + 1 /* Augmentation */
811 + size_of_uleb128 (1) /* Code alignment */
812 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
814 + 1 /* Augmentation size */
815 + 1 /* Personality encoding */ );
816 int pad
= -offset
& (PTR_SIZE
- 1);
818 augmentation_size
+= pad
;
820 /* Augmentations should be small, so there's scarce need to
821 iterate for a solution. Die if we exceed one uleb128 byte. */
822 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
826 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
827 if (dw_cie_version
>= 4)
829 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
830 dw2_asm_output_data (1, 0, "CIE Segment Size");
832 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
833 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
834 "CIE Data Alignment Factor");
836 if (dw_cie_version
== 1)
837 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
839 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
843 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
846 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
847 eh_data_format_name (per_encoding
));
848 dw2_asm_output_encoded_addr_rtx (per_encoding
,
854 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
855 eh_data_format_name (lsda_encoding
));
857 if (fde_encoding
!= DW_EH_PE_absptr
)
858 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
859 eh_data_format_name (fde_encoding
));
862 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
863 output_cfi (cfi
, NULL
, for_eh
);
865 /* Pad the CIE out to an address sized boundary. */
866 ASM_OUTPUT_ALIGN (asm_out_file
,
867 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
868 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
870 /* Loop through all of the FDE's. */
871 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
875 /* Don't emit EH unwind info for leaf functions that don't need it. */
876 if (for_eh
&& !fde_needed_for_eh_p (fde
))
879 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
880 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
881 augmentation
, any_lsda_needed
, lsda_encoding
);
884 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
885 dw2_asm_output_data (4, 0, "End of Table");
887 /* Turn off app to make assembly quicker. */
892 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
895 dwarf2out_do_cfi_startproc (bool second
)
899 rtx personality
= get_personality_function (current_function_decl
);
901 fprintf (asm_out_file
, "\t.cfi_startproc\n");
905 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
908 /* ??? The GAS support isn't entirely consistent. We have to
909 handle indirect support ourselves, but PC-relative is done
910 in the assembler. Further, the assembler can't handle any
911 of the weirder relocation types. */
912 if (enc
& DW_EH_PE_indirect
)
913 ref
= dw2_force_const_mem (ref
, true);
915 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
916 output_addr_const (asm_out_file
, ref
);
917 fputc ('\n', asm_out_file
);
920 if (crtl
->uses_eh_lsda
)
924 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
925 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
926 current_function_funcdef_no
);
927 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
928 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
930 if (enc
& DW_EH_PE_indirect
)
931 ref
= dw2_force_const_mem (ref
, true);
933 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
934 output_addr_const (asm_out_file
, ref
);
935 fputc ('\n', asm_out_file
);
939 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
940 this allocation may be done before pass_final. */
943 dwarf2out_alloc_current_fde (void)
947 fde
= ggc_alloc_cleared_dw_fde_node ();
948 fde
->decl
= current_function_decl
;
949 fde
->funcdef_number
= current_function_funcdef_no
;
950 fde
->fde_index
= vec_safe_length (fde_vec
);
951 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
952 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
953 fde
->nothrow
= crtl
->nothrow
;
954 fde
->drap_reg
= INVALID_REGNUM
;
955 fde
->vdrap_reg
= INVALID_REGNUM
;
957 /* Record the FDE associated with this function. */
959 vec_safe_push (fde_vec
, fde
);
964 /* Output a marker (i.e. a label) for the beginning of a function, before
968 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
969 const char *file ATTRIBUTE_UNUSED
)
971 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
977 current_function_func_begin_label
= NULL
;
979 do_frame
= dwarf2out_do_frame ();
981 /* ??? current_function_func_begin_label is also used by except.c for
982 call-site information. We must emit this label if it might be used. */
985 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
988 fnsec
= function_section (current_function_decl
);
989 switch_to_section (fnsec
);
990 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
991 current_function_funcdef_no
);
992 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
993 current_function_funcdef_no
);
994 dup_label
= xstrdup (label
);
995 current_function_func_begin_label
= dup_label
;
997 /* We can elide the fde allocation if we're not emitting debug info. */
1001 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1002 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1003 would include pass_dwarf2_frame. If we've not created the FDE yet,
1007 fde
= dwarf2out_alloc_current_fde ();
1009 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1010 fde
->dw_fde_begin
= dup_label
;
1011 fde
->dw_fde_current_label
= dup_label
;
1012 fde
->in_std_section
= (fnsec
== text_section
1013 || (cold_text_section
&& fnsec
== cold_text_section
));
1015 /* We only want to output line number information for the genuine dwarf2
1016 prologue case, not the eh frame case. */
1017 #ifdef DWARF2_DEBUGGING_INFO
1019 dwarf2out_source_line (line
, file
, 0, true);
1022 if (dwarf2out_do_cfi_asm ())
1023 dwarf2out_do_cfi_startproc (false);
1026 rtx personality
= get_personality_function (current_function_decl
);
1027 if (!current_unit_personality
)
1028 current_unit_personality
= personality
;
1030 /* We cannot keep a current personality per function as without CFI
1031 asm, at the point where we emit the CFI data, there is no current
1032 function anymore. */
1033 if (personality
&& current_unit_personality
!= personality
)
1034 sorry ("multiple EH personalities are supported only with assemblers "
1035 "supporting .cfi_personality directive");
1039 /* Output a marker (i.e. a label) for the end of the generated code
1040 for a function prologue. This gets called *after* the prologue code has
1044 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1045 const char *file ATTRIBUTE_UNUSED
)
1047 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1049 /* Output a label to mark the endpoint of the code generated for this
1051 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1052 current_function_funcdef_no
);
1053 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1054 current_function_funcdef_no
);
1055 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1058 /* Output a marker (i.e. a label) for the beginning of the generated code
1059 for a function epilogue. This gets called *before* the prologue code has
1063 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1064 const char *file ATTRIBUTE_UNUSED
)
1066 dw_fde_ref fde
= cfun
->fde
;
1067 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1069 if (fde
->dw_fde_vms_begin_epilogue
)
1072 /* Output a label to mark the endpoint of the code generated for this
1074 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1075 current_function_funcdef_no
);
1076 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1077 current_function_funcdef_no
);
1078 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1081 /* Output a marker (i.e. a label) for the absolute end of the generated code
1082 for a function definition. This gets called *after* the epilogue code has
1086 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1087 const char *file ATTRIBUTE_UNUSED
)
1090 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1092 last_var_location_insn
= NULL_RTX
;
1093 cached_next_real_insn
= NULL_RTX
;
1095 if (dwarf2out_do_cfi_asm ())
1096 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1098 /* Output a label to mark the endpoint of the code generated for this
1100 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1101 current_function_funcdef_no
);
1102 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1104 gcc_assert (fde
!= NULL
);
1105 if (fde
->dw_fde_second_begin
== NULL
)
1106 fde
->dw_fde_end
= xstrdup (label
);
1110 dwarf2out_frame_finish (void)
1112 /* Output call frame information. */
1113 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1114 output_call_frame_info (0);
1116 /* Output another copy for the unwinder. */
1117 if ((flag_unwind_tables
|| flag_exceptions
)
1118 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1119 output_call_frame_info (1);
1122 /* Note that the current function section is being used for code. */
1125 dwarf2out_note_section_used (void)
1127 section
*sec
= current_function_section ();
1128 if (sec
== text_section
)
1129 text_section_used
= true;
1130 else if (sec
== cold_text_section
)
1131 cold_text_section_used
= true;
1134 static void var_location_switch_text_section (void);
1135 static void set_cur_line_info_table (section
*);
1138 dwarf2out_switch_text_section (void)
1141 dw_fde_ref fde
= cfun
->fde
;
1143 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1145 if (!in_cold_section_p
)
1147 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1148 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1149 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1153 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1154 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1155 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1157 have_multiple_function_sections
= true;
1159 /* There is no need to mark used sections when not debugging. */
1160 if (cold_text_section
!= NULL
)
1161 dwarf2out_note_section_used ();
1163 if (dwarf2out_do_cfi_asm ())
1164 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1166 /* Now do the real section switch. */
1167 sect
= current_function_section ();
1168 switch_to_section (sect
);
1170 fde
->second_in_std_section
1171 = (sect
== text_section
1172 || (cold_text_section
&& sect
== cold_text_section
));
1174 if (dwarf2out_do_cfi_asm ())
1175 dwarf2out_do_cfi_startproc (true);
1177 var_location_switch_text_section ();
1179 if (cold_text_section
!= NULL
)
1180 set_cur_line_info_table (sect
);
1183 /* And now, the subset of the debugging information support code necessary
1184 for emitting location expressions. */
1186 /* Data about a single source file. */
1187 struct GTY(()) dwarf_file_data
{
1188 const char * filename
;
1192 typedef struct GTY(()) deferred_locations_struct
1196 } deferred_locations
;
1199 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1202 /* Describe an entry into the .debug_addr section. */
1206 ate_kind_rtx_dtprel
,
1210 typedef struct GTY(()) addr_table_entry_struct
{
1212 unsigned int refcount
;
1214 union addr_table_entry_struct_union
1216 rtx
GTY ((tag ("0"))) rtl
;
1217 char * GTY ((tag ("1"))) label
;
1219 GTY ((desc ("%1.kind"))) addr
;
1223 /* Location lists are ranges + location descriptions for that range,
1224 so you can track variables that are in different places over
1225 their entire life. */
1226 typedef struct GTY(()) dw_loc_list_struct
{
1227 dw_loc_list_ref dw_loc_next
;
1228 const char *begin
; /* Label and addr_entry for start of range */
1229 addr_table_entry
*begin_entry
;
1230 const char *end
; /* Label for end of range */
1231 char *ll_symbol
; /* Label for beginning of location list.
1232 Only on head of list */
1233 const char *section
; /* Section this loclist is relative to */
1234 dw_loc_descr_ref expr
;
1236 /* True if all addresses in this and subsequent lists are known to be
1239 /* True if this list has been replaced by dw_loc_next. */
1242 /* True if the range should be emitted even if begin and end
1247 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1249 /* Convert a DWARF stack opcode into its string name. */
1252 dwarf_stack_op_name (unsigned int op
)
1254 const char *name
= get_DW_OP_name (op
);
1259 return "OP_<unknown>";
1262 /* Return a pointer to a newly allocated location description. Location
1263 descriptions are simple expression terms that can be strung
1264 together to form more complicated location (address) descriptions. */
1266 static inline dw_loc_descr_ref
1267 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1268 unsigned HOST_WIDE_INT oprnd2
)
1270 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1272 descr
->dw_loc_opc
= op
;
1273 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1274 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1275 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1276 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1277 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1278 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1283 /* Return a pointer to a newly allocated location description for
1286 static inline dw_loc_descr_ref
1287 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1290 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1293 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1296 /* Add a location description term to a location description expression. */
1299 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1301 dw_loc_descr_ref
*d
;
1303 /* Find the end of the chain. */
1304 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1310 /* Compare two location operands for exact equality. */
1313 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1315 if (a
->val_class
!= b
->val_class
)
1317 switch (a
->val_class
)
1319 case dw_val_class_none
:
1321 case dw_val_class_addr
:
1322 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1324 case dw_val_class_offset
:
1325 case dw_val_class_unsigned_const
:
1326 case dw_val_class_const
:
1327 case dw_val_class_range_list
:
1328 case dw_val_class_lineptr
:
1329 case dw_val_class_macptr
:
1330 /* These are all HOST_WIDE_INT, signed or unsigned. */
1331 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1333 case dw_val_class_loc
:
1334 return a
->v
.val_loc
== b
->v
.val_loc
;
1335 case dw_val_class_loc_list
:
1336 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1337 case dw_val_class_die_ref
:
1338 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1339 case dw_val_class_fde_ref
:
1340 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1341 case dw_val_class_lbl_id
:
1342 case dw_val_class_high_pc
:
1343 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1344 case dw_val_class_str
:
1345 return a
->v
.val_str
== b
->v
.val_str
;
1346 case dw_val_class_flag
:
1347 return a
->v
.val_flag
== b
->v
.val_flag
;
1348 case dw_val_class_file
:
1349 return a
->v
.val_file
== b
->v
.val_file
;
1350 case dw_val_class_decl_ref
:
1351 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1353 case dw_val_class_const_double
:
1354 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1355 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1357 case dw_val_class_vec
:
1359 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1360 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1362 return (a_len
== b_len
1363 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1366 case dw_val_class_data8
:
1367 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1369 case dw_val_class_vms_delta
:
1370 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1371 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1376 /* Compare two location atoms for exact equality. */
1379 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1381 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1384 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1385 address size, but since we always allocate cleared storage it
1386 should be zero for other types of locations. */
1387 if (a
->dtprel
!= b
->dtprel
)
1390 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1391 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1394 /* Compare two complete location expressions for exact equality. */
1397 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1403 if (a
== NULL
|| b
== NULL
)
1405 if (!loc_descr_equal_p_1 (a
, b
))
1414 /* Add a constant OFFSET to a location expression. */
1417 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1419 dw_loc_descr_ref loc
;
1422 gcc_assert (*list_head
!= NULL
);
1427 /* Find the end of the chain. */
1428 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1432 if (loc
->dw_loc_opc
== DW_OP_fbreg
1433 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1434 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1435 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1436 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1438 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1439 offset. Don't optimize if an signed integer overflow would happen. */
1441 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1442 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1445 else if (offset
> 0)
1446 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1450 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1451 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1455 /* Add a constant OFFSET to a location list. */
1458 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1461 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1462 loc_descr_plus_const (&d
->expr
, offset
);
1465 #define DWARF_REF_SIZE \
1466 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1468 static unsigned long int get_base_type_offset (dw_die_ref
);
1470 /* Return the size of a location descriptor. */
1472 static unsigned long
1473 size_of_loc_descr (dw_loc_descr_ref loc
)
1475 unsigned long size
= 1;
1477 switch (loc
->dw_loc_opc
)
1480 size
+= DWARF2_ADDR_SIZE
;
1482 case DW_OP_GNU_addr_index
:
1483 case DW_OP_GNU_const_index
:
1484 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1485 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1504 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1507 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1512 case DW_OP_plus_uconst
:
1513 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1551 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1554 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1557 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1560 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1561 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1564 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1566 case DW_OP_bit_piece
:
1567 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1568 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1570 case DW_OP_deref_size
:
1571 case DW_OP_xderef_size
:
1580 case DW_OP_call_ref
:
1581 size
+= DWARF_REF_SIZE
;
1583 case DW_OP_implicit_value
:
1584 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1585 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1587 case DW_OP_GNU_implicit_pointer
:
1588 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1590 case DW_OP_GNU_entry_value
:
1592 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1593 size
+= size_of_uleb128 (op_size
) + op_size
;
1596 case DW_OP_GNU_const_type
:
1599 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1600 size
+= size_of_uleb128 (o
) + 1;
1601 switch (loc
->dw_loc_oprnd2
.val_class
)
1603 case dw_val_class_vec
:
1604 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1605 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1607 case dw_val_class_const
:
1608 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1610 case dw_val_class_const_double
:
1611 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1618 case DW_OP_GNU_regval_type
:
1621 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1622 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1623 + size_of_uleb128 (o
);
1626 case DW_OP_GNU_deref_type
:
1629 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1630 size
+= 1 + size_of_uleb128 (o
);
1633 case DW_OP_GNU_convert
:
1634 case DW_OP_GNU_reinterpret
:
1635 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1636 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1640 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1641 size
+= size_of_uleb128 (o
);
1644 case DW_OP_GNU_parameter_ref
:
1654 /* Return the size of a series of location descriptors. */
1657 size_of_locs (dw_loc_descr_ref loc
)
1662 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1663 field, to avoid writing to a PCH file. */
1664 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1666 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1668 size
+= size_of_loc_descr (l
);
1673 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1675 l
->dw_loc_addr
= size
;
1676 size
+= size_of_loc_descr (l
);
1682 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1683 static void get_ref_die_offset_label (char *, dw_die_ref
);
1684 static unsigned long int get_ref_die_offset (dw_die_ref
);
1686 /* Output location description stack opcode's operands (if any).
1687 The for_eh_or_skip parameter controls whether register numbers are
1688 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1689 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1690 info). This should be suppressed for the cases that have not been converted
1691 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1694 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1696 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1697 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1699 switch (loc
->dw_loc_opc
)
1701 #ifdef DWARF2_DEBUGGING_INFO
1704 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1709 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1710 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1712 fputc ('\n', asm_out_file
);
1717 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1722 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1723 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1725 fputc ('\n', asm_out_file
);
1730 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1731 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1738 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1739 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1741 dw2_asm_output_data (2, offset
, NULL
);
1744 case DW_OP_implicit_value
:
1745 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1746 switch (val2
->val_class
)
1748 case dw_val_class_const
:
1749 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1751 case dw_val_class_vec
:
1753 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1754 unsigned int len
= val2
->v
.val_vec
.length
;
1758 if (elt_size
> sizeof (HOST_WIDE_INT
))
1763 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1766 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1767 "fp or vector constant word %u", i
);
1770 case dw_val_class_const_double
:
1772 unsigned HOST_WIDE_INT first
, second
;
1774 if (WORDS_BIG_ENDIAN
)
1776 first
= val2
->v
.val_double
.high
;
1777 second
= val2
->v
.val_double
.low
;
1781 first
= val2
->v
.val_double
.low
;
1782 second
= val2
->v
.val_double
.high
;
1784 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1786 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1790 case dw_val_class_addr
:
1791 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1792 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1807 case DW_OP_implicit_value
:
1808 /* We currently don't make any attempt to make sure these are
1809 aligned properly like we do for the main unwind info, so
1810 don't support emitting things larger than a byte if we're
1811 only doing unwinding. */
1816 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1819 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1822 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1825 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1827 case DW_OP_plus_uconst
:
1828 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1862 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1866 unsigned r
= val1
->v
.val_unsigned
;
1867 if (for_eh_or_skip
>= 0)
1868 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1869 gcc_assert (size_of_uleb128 (r
)
1870 == size_of_uleb128 (val1
->v
.val_unsigned
));
1871 dw2_asm_output_data_uleb128 (r
, NULL
);
1875 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1879 unsigned r
= val1
->v
.val_unsigned
;
1880 if (for_eh_or_skip
>= 0)
1881 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1882 gcc_assert (size_of_uleb128 (r
)
1883 == size_of_uleb128 (val1
->v
.val_unsigned
));
1884 dw2_asm_output_data_uleb128 (r
, NULL
);
1885 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1889 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1891 case DW_OP_bit_piece
:
1892 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1893 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1895 case DW_OP_deref_size
:
1896 case DW_OP_xderef_size
:
1897 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1903 if (targetm
.asm_out
.output_dwarf_dtprel
)
1905 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1908 fputc ('\n', asm_out_file
);
1915 #ifdef DWARF2_DEBUGGING_INFO
1916 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1923 case DW_OP_GNU_addr_index
:
1924 case DW_OP_GNU_const_index
:
1925 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1926 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1927 "(index into .debug_addr)");
1930 case DW_OP_GNU_implicit_pointer
:
1932 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1933 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1934 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1935 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1936 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1937 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1941 case DW_OP_GNU_entry_value
:
1942 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1943 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1946 case DW_OP_GNU_const_type
:
1948 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1950 dw2_asm_output_data_uleb128 (o
, NULL
);
1951 switch (val2
->val_class
)
1953 case dw_val_class_const
:
1954 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1955 dw2_asm_output_data (1, l
, NULL
);
1956 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1958 case dw_val_class_vec
:
1960 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1961 unsigned int len
= val2
->v
.val_vec
.length
;
1966 dw2_asm_output_data (1, l
, NULL
);
1967 if (elt_size
> sizeof (HOST_WIDE_INT
))
1972 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1975 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1976 "fp or vector constant word %u", i
);
1979 case dw_val_class_const_double
:
1981 unsigned HOST_WIDE_INT first
, second
;
1982 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1984 dw2_asm_output_data (1, 2 * l
, NULL
);
1985 if (WORDS_BIG_ENDIAN
)
1987 first
= val2
->v
.val_double
.high
;
1988 second
= val2
->v
.val_double
.low
;
1992 first
= val2
->v
.val_double
.low
;
1993 second
= val2
->v
.val_double
.high
;
1995 dw2_asm_output_data (l
, first
, NULL
);
1996 dw2_asm_output_data (l
, second
, NULL
);
2004 case DW_OP_GNU_regval_type
:
2006 unsigned r
= val1
->v
.val_unsigned
;
2007 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2009 if (for_eh_or_skip
>= 0)
2011 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2012 gcc_assert (size_of_uleb128 (r
)
2013 == size_of_uleb128 (val1
->v
.val_unsigned
));
2015 dw2_asm_output_data_uleb128 (r
, NULL
);
2016 dw2_asm_output_data_uleb128 (o
, NULL
);
2019 case DW_OP_GNU_deref_type
:
2021 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2023 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2024 dw2_asm_output_data_uleb128 (o
, NULL
);
2027 case DW_OP_GNU_convert
:
2028 case DW_OP_GNU_reinterpret
:
2029 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2030 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2033 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2035 dw2_asm_output_data_uleb128 (o
, NULL
);
2039 case DW_OP_GNU_parameter_ref
:
2042 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2043 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2044 dw2_asm_output_data (4, o
, NULL
);
2049 /* Other codes have no operands. */
2054 /* Output a sequence of location operations.
2055 The for_eh_or_skip parameter controls whether register numbers are
2056 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2057 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2058 info). This should be suppressed for the cases that have not been converted
2059 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2062 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2064 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2066 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2067 /* Output the opcode. */
2068 if (for_eh_or_skip
>= 0
2069 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2071 unsigned r
= (opc
- DW_OP_breg0
);
2072 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2073 gcc_assert (r
<= 31);
2074 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2076 else if (for_eh_or_skip
>= 0
2077 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2079 unsigned r
= (opc
- DW_OP_reg0
);
2080 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2081 gcc_assert (r
<= 31);
2082 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2085 dw2_asm_output_data (1, opc
,
2086 "%s", dwarf_stack_op_name (opc
));
2088 /* Output the operand(s) (if any). */
2089 output_loc_operands (loc
, for_eh_or_skip
);
2093 /* Output location description stack opcode's operands (if any).
2094 The output is single bytes on a line, suitable for .cfi_escape. */
2097 output_loc_operands_raw (dw_loc_descr_ref loc
)
2099 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2100 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2102 switch (loc
->dw_loc_opc
)
2105 case DW_OP_GNU_addr_index
:
2106 case DW_OP_GNU_const_index
:
2107 case DW_OP_implicit_value
:
2108 /* We cannot output addresses in .cfi_escape, only bytes. */
2114 case DW_OP_deref_size
:
2115 case DW_OP_xderef_size
:
2116 fputc (',', asm_out_file
);
2117 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2122 fputc (',', asm_out_file
);
2123 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2128 fputc (',', asm_out_file
);
2129 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2134 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2135 fputc (',', asm_out_file
);
2136 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2144 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2145 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2147 fputc (',', asm_out_file
);
2148 dw2_asm_output_data_raw (2, offset
);
2154 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2155 gcc_assert (size_of_uleb128 (r
)
2156 == size_of_uleb128 (val1
->v
.val_unsigned
));
2157 fputc (',', asm_out_file
);
2158 dw2_asm_output_data_uleb128_raw (r
);
2163 case DW_OP_plus_uconst
:
2165 fputc (',', asm_out_file
);
2166 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2169 case DW_OP_bit_piece
:
2170 fputc (',', asm_out_file
);
2171 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2172 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2209 fputc (',', asm_out_file
);
2210 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2215 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2216 gcc_assert (size_of_uleb128 (r
)
2217 == size_of_uleb128 (val1
->v
.val_unsigned
));
2218 fputc (',', asm_out_file
);
2219 dw2_asm_output_data_uleb128_raw (r
);
2220 fputc (',', asm_out_file
);
2221 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2225 case DW_OP_GNU_implicit_pointer
:
2226 case DW_OP_GNU_entry_value
:
2227 case DW_OP_GNU_const_type
:
2228 case DW_OP_GNU_regval_type
:
2229 case DW_OP_GNU_deref_type
:
2230 case DW_OP_GNU_convert
:
2231 case DW_OP_GNU_reinterpret
:
2232 case DW_OP_GNU_parameter_ref
:
2237 /* Other codes have no operands. */
2243 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2247 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2248 /* Output the opcode. */
2249 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2251 unsigned r
= (opc
- DW_OP_breg0
);
2252 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2253 gcc_assert (r
<= 31);
2254 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2256 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2258 unsigned r
= (opc
- DW_OP_reg0
);
2259 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2260 gcc_assert (r
<= 31);
2261 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2263 /* Output the opcode. */
2264 fprintf (asm_out_file
, "%#x", opc
);
2265 output_loc_operands_raw (loc
);
2267 if (!loc
->dw_loc_next
)
2269 loc
= loc
->dw_loc_next
;
2271 fputc (',', asm_out_file
);
2275 /* This function builds a dwarf location descriptor sequence from a
2276 dw_cfa_location, adding the given OFFSET to the result of the
2279 struct dw_loc_descr_struct
*
2280 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2282 struct dw_loc_descr_struct
*head
, *tmp
;
2284 offset
+= cfa
->offset
;
2288 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2289 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2290 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2291 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2292 add_loc_descr (&head
, tmp
);
2295 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2296 add_loc_descr (&head
, tmp
);
2300 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2305 /* This function builds a dwarf location descriptor sequence for
2306 the address at OFFSET from the CFA when stack is aligned to
2309 struct dw_loc_descr_struct
*
2310 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2311 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2313 struct dw_loc_descr_struct
*head
;
2314 unsigned int dwarf_fp
2315 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2317 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2318 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2320 head
= new_reg_loc_descr (dwarf_fp
, 0);
2321 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2322 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2323 loc_descr_plus_const (&head
, offset
);
2326 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2330 /* And now, the support for symbolic debugging information. */
2332 /* .debug_str support. */
2333 static int output_indirect_string (void **, void *);
2335 static void dwarf2out_init (const char *);
2336 static void dwarf2out_finish (const char *);
2337 static void dwarf2out_assembly_start (void);
2338 static void dwarf2out_define (unsigned int, const char *);
2339 static void dwarf2out_undef (unsigned int, const char *);
2340 static void dwarf2out_start_source_file (unsigned, const char *);
2341 static void dwarf2out_end_source_file (unsigned);
2342 static void dwarf2out_function_decl (tree
);
2343 static void dwarf2out_begin_block (unsigned, unsigned);
2344 static void dwarf2out_end_block (unsigned, unsigned);
2345 static bool dwarf2out_ignore_block (const_tree
);
2346 static void dwarf2out_global_decl (tree
);
2347 static void dwarf2out_type_decl (tree
, int);
2348 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2349 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2351 static void dwarf2out_abstract_function (tree
);
2352 static void dwarf2out_var_location (rtx
);
2353 static void dwarf2out_begin_function (tree
);
2354 static void dwarf2out_end_function (unsigned int);
2355 static void dwarf2out_set_name (tree
, tree
);
2357 /* The debug hooks structure. */
2359 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2363 dwarf2out_assembly_start
,
2366 dwarf2out_start_source_file
,
2367 dwarf2out_end_source_file
,
2368 dwarf2out_begin_block
,
2369 dwarf2out_end_block
,
2370 dwarf2out_ignore_block
,
2371 dwarf2out_source_line
,
2372 dwarf2out_begin_prologue
,
2373 #if VMS_DEBUGGING_INFO
2374 dwarf2out_vms_end_prologue
,
2375 dwarf2out_vms_begin_epilogue
,
2377 debug_nothing_int_charstar
,
2378 debug_nothing_int_charstar
,
2380 dwarf2out_end_epilogue
,
2381 dwarf2out_begin_function
,
2382 dwarf2out_end_function
, /* end_function */
2383 dwarf2out_function_decl
, /* function_decl */
2384 dwarf2out_global_decl
,
2385 dwarf2out_type_decl
, /* type_decl */
2386 dwarf2out_imported_module_or_decl
,
2387 debug_nothing_tree
, /* deferred_inline_function */
2388 /* The DWARF 2 backend tries to reduce debugging bloat by not
2389 emitting the abstract description of inline functions until
2390 something tries to reference them. */
2391 dwarf2out_abstract_function
, /* outlining_inline_function */
2392 debug_nothing_rtx
, /* label */
2393 debug_nothing_int
, /* handle_pch */
2394 dwarf2out_var_location
,
2395 dwarf2out_switch_text_section
,
2397 1, /* start_end_main_source_file */
2398 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2401 /* NOTE: In the comments in this file, many references are made to
2402 "Debugging Information Entries". This term is abbreviated as `DIE'
2403 throughout the remainder of this file. */
2405 /* An internal representation of the DWARF output is built, and then
2406 walked to generate the DWARF debugging info. The walk of the internal
2407 representation is done after the entire program has been compiled.
2408 The types below are used to describe the internal representation. */
2410 /* Whether to put type DIEs into their own section .debug_types instead
2411 of making them part of the .debug_info section. Only supported for
2412 Dwarf V4 or higher and the user didn't disable them through
2413 -fno-debug-types-section. It is more efficient to put them in a
2414 separate comdat sections since the linker will then be able to
2415 remove duplicates. But not all tools support .debug_types sections
2418 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2420 /* Various DIE's use offsets relative to the beginning of the
2421 .debug_info section to refer to each other. */
2423 typedef long int dw_offset
;
2425 /* Define typedefs here to avoid circular dependencies. */
2427 typedef struct dw_attr_struct
*dw_attr_ref
;
2428 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2429 typedef struct pubname_struct
*pubname_ref
;
2430 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2431 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2432 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2434 /* The entries in the line_info table more-or-less mirror the opcodes
2435 that are used in the real dwarf line table. Arrays of these entries
2436 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2439 enum dw_line_info_opcode
{
2440 /* Emit DW_LNE_set_address; the operand is the label index. */
2443 /* Emit a row to the matrix with the given line. This may be done
2444 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2448 /* Emit a DW_LNS_set_file. */
2451 /* Emit a DW_LNS_set_column. */
2454 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2457 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2458 LI_set_prologue_end
,
2459 LI_set_epilogue_begin
,
2461 /* Emit a DW_LNE_set_discriminator. */
2462 LI_set_discriminator
2465 typedef struct GTY(()) dw_line_info_struct
{
2466 enum dw_line_info_opcode opcode
;
2468 } dw_line_info_entry
;
2471 typedef struct GTY(()) dw_line_info_table_struct
{
2472 /* The label that marks the end of this section. */
2473 const char *end_label
;
2475 /* The values for the last row of the matrix, as collected in the table.
2476 These are used to minimize the changes to the next row. */
2477 unsigned int file_num
;
2478 unsigned int line_num
;
2479 unsigned int column_num
;
2484 vec
<dw_line_info_entry
, va_gc
> *entries
;
2485 } dw_line_info_table
;
2487 typedef dw_line_info_table
*dw_line_info_table_p
;
2490 /* Each DIE attribute has a field specifying the attribute kind,
2491 a link to the next attribute in the chain, and an attribute value.
2492 Attributes are typically linked below the DIE they modify. */
2494 typedef struct GTY(()) dw_attr_struct
{
2495 enum dwarf_attribute dw_attr
;
2496 dw_val_node dw_attr_val
;
2501 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2502 The children of each node form a circular list linked by
2503 die_sib. die_child points to the node *before* the "first" child node. */
2505 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2506 union die_symbol_or_type_node
2508 const char * GTY ((tag ("0"))) die_symbol
;
2509 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2511 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2512 vec
<dw_attr_node
, va_gc
> *die_attr
;
2513 dw_die_ref die_parent
;
2514 dw_die_ref die_child
;
2516 dw_die_ref die_definition
; /* ref from a specification to its definition */
2517 dw_offset die_offset
;
2518 unsigned long die_abbrev
;
2520 unsigned int decl_id
;
2521 enum dwarf_tag die_tag
;
2522 /* Die is used and must not be pruned as unused. */
2523 BOOL_BITFIELD die_perennial_p
: 1;
2524 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2525 /* Lots of spare bits. */
2529 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2530 #define FOR_EACH_CHILD(die, c, expr) do { \
2531 c = die->die_child; \
2535 } while (c != die->die_child); \
2538 /* The pubname structure */
2540 typedef struct GTY(()) pubname_struct
{
2547 struct GTY(()) dw_ranges_struct
{
2548 /* If this is positive, it's a block number, otherwise it's a
2549 bitwise-negated index into dw_ranges_by_label. */
2553 /* A structure to hold a macinfo entry. */
2555 typedef struct GTY(()) macinfo_struct
{
2557 unsigned HOST_WIDE_INT lineno
;
2563 struct GTY(()) dw_ranges_by_label_struct
{
2568 /* The comdat type node structure. */
2569 typedef struct GTY(()) comdat_type_struct
2571 dw_die_ref root_die
;
2572 dw_die_ref type_die
;
2573 dw_die_ref skeleton_die
;
2574 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2575 struct comdat_type_struct
*next
;
2579 /* The limbo die list structure. */
2580 typedef struct GTY(()) limbo_die_struct
{
2583 struct limbo_die_struct
*next
;
2587 typedef struct skeleton_chain_struct
2591 struct skeleton_chain_struct
*parent
;
2593 skeleton_chain_node
;
2595 /* Define a macro which returns nonzero for a TYPE_DECL which was
2596 implicitly generated for a type.
2598 Note that, unlike the C front-end (which generates a NULL named
2599 TYPE_DECL node for each complete tagged type, each array type,
2600 and each function type node created) the C++ front-end generates
2601 a _named_ TYPE_DECL node for each tagged type node created.
2602 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2603 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2604 front-end, but for each type, tagged or not. */
2606 #define TYPE_DECL_IS_STUB(decl) \
2607 (DECL_NAME (decl) == NULL_TREE \
2608 || (DECL_ARTIFICIAL (decl) \
2609 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2610 /* This is necessary for stub decls that \
2611 appear in nested inline functions. */ \
2612 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2613 && (decl_ultimate_origin (decl) \
2614 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2616 /* Information concerning the compilation unit's programming
2617 language, and compiler version. */
2619 /* Fixed size portion of the DWARF compilation unit header. */
2620 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2621 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2623 /* Fixed size portion of the DWARF comdat type unit header. */
2624 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2625 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2626 + DWARF_OFFSET_SIZE)
2628 /* Fixed size portion of public names info. */
2629 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2631 /* Fixed size portion of the address range info. */
2632 #define DWARF_ARANGES_HEADER_SIZE \
2633 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2634 DWARF2_ADDR_SIZE * 2) \
2635 - DWARF_INITIAL_LENGTH_SIZE)
2637 /* Size of padding portion in the address range info. It must be
2638 aligned to twice the pointer size. */
2639 #define DWARF_ARANGES_PAD_SIZE \
2640 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2641 DWARF2_ADDR_SIZE * 2) \
2642 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2644 /* Use assembler line directives if available. */
2645 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2646 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2647 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2649 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2653 /* Minimum line offset in a special line info. opcode.
2654 This value was chosen to give a reasonable range of values. */
2655 #define DWARF_LINE_BASE -10
2657 /* First special line opcode - leave room for the standard opcodes. */
2658 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2660 /* Range of line offsets in a special line info. opcode. */
2661 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2663 /* Flag that indicates the initial value of the is_stmt_start flag.
2664 In the present implementation, we do not mark any lines as
2665 the beginning of a source statement, because that information
2666 is not made available by the GCC front-end. */
2667 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2669 /* Maximum number of operations per instruction bundle. */
2670 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2671 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2674 /* This location is used by calc_die_sizes() to keep track
2675 the offset of each DIE within the .debug_info section. */
2676 static unsigned long next_die_offset
;
2678 /* Record the root of the DIE's built for the current compilation unit. */
2679 static GTY(()) dw_die_ref single_comp_unit_die
;
2681 /* A list of type DIEs that have been separated into comdat sections. */
2682 static GTY(()) comdat_type_node
*comdat_type_list
;
2684 /* A list of DIEs with a NULL parent waiting to be relocated. */
2685 static GTY(()) limbo_die_node
*limbo_die_list
;
2687 /* A list of DIEs for which we may have to generate
2688 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2689 static GTY(()) limbo_die_node
*deferred_asm_name
;
2691 /* Filenames referenced by this compilation unit. */
2692 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2694 /* A hash table of references to DIE's that describe declarations.
2695 The key is a DECL_UID() which is a unique number identifying each decl. */
2696 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2698 /* A hash table of references to DIE's that describe COMMON blocks.
2699 The key is DECL_UID() ^ die_parent. */
2700 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2702 typedef struct GTY(()) die_arg_entry_struct
{
2708 /* Node of the variable location list. */
2709 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2710 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2711 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2712 in mode of the EXPR_LIST node and first EXPR_LIST operand
2713 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2714 location or NULL for padding. For larger bitsizes,
2715 mode is 0 and first operand is a CONCAT with bitsize
2716 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2717 NULL as second operand. */
2719 const char * GTY (()) label
;
2720 struct var_loc_node
* GTY (()) next
;
2723 /* Variable location list. */
2724 struct GTY (()) var_loc_list_def
{
2725 struct var_loc_node
* GTY (()) first
;
2727 /* Pointer to the last but one or last element of the
2728 chained list. If the list is empty, both first and
2729 last are NULL, if the list contains just one node
2730 or the last node certainly is not redundant, it points
2731 to the last node, otherwise points to the last but one.
2732 Do not mark it for GC because it is marked through the chain. */
2733 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2735 /* Pointer to the last element before section switch,
2736 if NULL, either sections weren't switched or first
2737 is after section switch. */
2738 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2740 /* DECL_UID of the variable decl. */
2741 unsigned int decl_id
;
2743 typedef struct var_loc_list_def var_loc_list
;
2745 /* Call argument location list. */
2746 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2747 rtx
GTY (()) call_arg_loc_note
;
2748 const char * GTY (()) label
;
2749 tree
GTY (()) block
;
2751 rtx
GTY (()) symbol_ref
;
2752 struct call_arg_loc_node
* GTY (()) next
;
2756 /* Table of decl location linked lists. */
2757 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2759 /* Head and tail of call_arg_loc chain. */
2760 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2761 static struct call_arg_loc_node
*call_arg_loc_last
;
2763 /* Number of call sites in the current function. */
2764 static int call_site_count
= -1;
2765 /* Number of tail call sites in the current function. */
2766 static int tail_call_site_count
= -1;
2768 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2770 static vec
<dw_die_ref
> block_map
;
2772 /* A cached location list. */
2773 struct GTY (()) cached_dw_loc_list_def
{
2774 /* The DECL_UID of the decl that this entry describes. */
2775 unsigned int decl_id
;
2777 /* The cached location list. */
2778 dw_loc_list_ref loc_list
;
2780 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2782 /* Table of cached location lists. */
2783 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2785 /* A pointer to the base of a list of references to DIE's that
2786 are uniquely identified by their tag, presence/absence of
2787 children DIE's, and list of attribute/value pairs. */
2788 static GTY((length ("abbrev_die_table_allocated")))
2789 dw_die_ref
*abbrev_die_table
;
2791 /* Number of elements currently allocated for abbrev_die_table. */
2792 static GTY(()) unsigned abbrev_die_table_allocated
;
2794 /* Number of elements in type_die_table currently in use. */
2795 static GTY(()) unsigned abbrev_die_table_in_use
;
2797 /* Size (in elements) of increments by which we may expand the
2798 abbrev_die_table. */
2799 #define ABBREV_DIE_TABLE_INCREMENT 256
2801 /* A global counter for generating labels for line number data. */
2802 static unsigned int line_info_label_num
;
2804 /* The current table to which we should emit line number information
2805 for the current function. This will be set up at the beginning of
2806 assembly for the function. */
2807 static dw_line_info_table
*cur_line_info_table
;
2809 /* The two default tables of line number info. */
2810 static GTY(()) dw_line_info_table
*text_section_line_info
;
2811 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2813 /* The set of all non-default tables of line number info. */
2814 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2816 /* A flag to tell pubnames/types export if there is an info section to
2818 static bool info_section_emitted
;
2820 /* A pointer to the base of a table that contains a list of publicly
2821 accessible names. */
2822 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2824 /* A pointer to the base of a table that contains a list of publicly
2825 accessible types. */
2826 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2828 /* A pointer to the base of a table that contains a list of macro
2829 defines/undefines (and file start/end markers). */
2830 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2832 /* True if .debug_macinfo or .debug_macros section is going to be
2834 #define have_macinfo \
2835 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2836 && !macinfo_table->is_empty ())
2838 /* Array of dies for which we should generate .debug_ranges info. */
2839 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2841 /* Number of elements currently allocated for ranges_table. */
2842 static GTY(()) unsigned ranges_table_allocated
;
2844 /* Number of elements in ranges_table currently in use. */
2845 static GTY(()) unsigned ranges_table_in_use
;
2847 /* Array of pairs of labels referenced in ranges_table. */
2848 static GTY ((length ("ranges_by_label_allocated")))
2849 dw_ranges_by_label_ref ranges_by_label
;
2851 /* Number of elements currently allocated for ranges_by_label. */
2852 static GTY(()) unsigned ranges_by_label_allocated
;
2854 /* Number of elements in ranges_by_label currently in use. */
2855 static GTY(()) unsigned ranges_by_label_in_use
;
2857 /* Size (in elements) of increments by which we may expand the
2859 #define RANGES_TABLE_INCREMENT 64
2861 /* Whether we have location lists that need outputting */
2862 static GTY(()) bool have_location_lists
;
2864 /* Unique label counter. */
2865 static GTY(()) unsigned int loclabel_num
;
2867 /* Unique label counter for point-of-call tables. */
2868 static GTY(()) unsigned int poc_label_num
;
2870 /* Record whether the function being analyzed contains inlined functions. */
2871 static int current_function_has_inlines
;
2873 /* The last file entry emitted by maybe_emit_file(). */
2874 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2876 /* Number of internal labels generated by gen_internal_sym(). */
2877 static GTY(()) int label_num
;
2879 /* Cached result of previous call to lookup_filename. */
2880 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2882 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2884 /* Instances of generic types for which we need to generate debug
2885 info that describe their generic parameters and arguments. That
2886 generation needs to happen once all types are properly laid out so
2887 we do it at the end of compilation. */
2888 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2890 /* Offset from the "steady-state frame pointer" to the frame base,
2891 within the current function. */
2892 static HOST_WIDE_INT frame_pointer_fb_offset
;
2893 static bool frame_pointer_fb_offset_valid
;
2895 static vec
<dw_die_ref
> base_types
;
2897 /* Forward declarations for functions defined in this file. */
2899 static int is_pseudo_reg (const_rtx
);
2900 static tree
type_main_variant (tree
);
2901 static int is_tagged_type (const_tree
);
2902 static const char *dwarf_tag_name (unsigned);
2903 static const char *dwarf_attr_name (unsigned);
2904 static const char *dwarf_form_name (unsigned);
2905 static tree
decl_ultimate_origin (const_tree
);
2906 static tree
decl_class_context (tree
);
2907 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2908 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2909 static inline unsigned int AT_index (dw_attr_ref
);
2910 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2911 static inline unsigned AT_flag (dw_attr_ref
);
2912 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2913 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2914 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2915 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2916 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2917 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2918 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2919 unsigned int, unsigned char *);
2920 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2921 static hashval_t
debug_str_do_hash (const void *);
2922 static int debug_str_eq (const void *, const void *);
2923 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2924 static inline const char *AT_string (dw_attr_ref
);
2925 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2926 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2927 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2928 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2929 static inline int AT_ref_external (dw_attr_ref
);
2930 static inline void set_AT_ref_external (dw_attr_ref
, int);
2931 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2932 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2933 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2934 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2936 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2937 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2938 static void remove_addr_table_entry (addr_table_entry
*);
2939 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
2940 static inline rtx
AT_addr (dw_attr_ref
);
2941 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2942 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2943 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2944 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2945 unsigned HOST_WIDE_INT
);
2946 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2947 unsigned long, bool);
2948 static inline const char *AT_lbl (dw_attr_ref
);
2949 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2950 static const char *get_AT_low_pc (dw_die_ref
);
2951 static const char *get_AT_hi_pc (dw_die_ref
);
2952 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2953 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2954 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2955 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2956 static bool is_cxx (void);
2957 static bool is_fortran (void);
2958 static bool is_ada (void);
2959 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2960 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2961 static void add_child_die (dw_die_ref
, dw_die_ref
);
2962 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2963 static dw_die_ref
lookup_type_die (tree
);
2964 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2965 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
2966 static void equate_type_number_to_die (tree
, dw_die_ref
);
2967 static hashval_t
decl_die_table_hash (const void *);
2968 static int decl_die_table_eq (const void *, const void *);
2969 static dw_die_ref
lookup_decl_die (tree
);
2970 static hashval_t
common_block_die_table_hash (const void *);
2971 static int common_block_die_table_eq (const void *, const void *);
2972 static hashval_t
decl_loc_table_hash (const void *);
2973 static int decl_loc_table_eq (const void *, const void *);
2974 static var_loc_list
*lookup_decl_loc (const_tree
);
2975 static void equate_decl_number_to_die (tree
, dw_die_ref
);
2976 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
2977 static void print_spaces (FILE *);
2978 static void print_die (dw_die_ref
, FILE *);
2979 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
2980 static dw_die_ref
pop_compile_unit (dw_die_ref
);
2981 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
2982 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
2983 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
2984 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
2985 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
2986 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
2987 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
2988 struct md5_ctx
*, int *);
2989 struct checksum_attributes
;
2990 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
2991 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
2992 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
2993 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
2994 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
2995 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
2996 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
2997 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
2998 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
2999 static void compute_section_prefix (dw_die_ref
);
3000 static int is_type_die (dw_die_ref
);
3001 static int is_comdat_die (dw_die_ref
);
3002 static int is_symbol_die (dw_die_ref
);
3003 static void assign_symbol_names (dw_die_ref
);
3004 static void break_out_includes (dw_die_ref
);
3005 static int is_declaration_die (dw_die_ref
);
3006 static int should_move_die_to_comdat (dw_die_ref
);
3007 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3008 static dw_die_ref
clone_die (dw_die_ref
);
3009 static dw_die_ref
clone_tree (dw_die_ref
);
3010 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3011 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3012 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3013 static dw_die_ref
generate_skeleton (dw_die_ref
);
3014 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3017 static void break_out_comdat_types (dw_die_ref
);
3018 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
3019 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
3020 static void copy_decls_for_unworthy_types (dw_die_ref
);
3022 static hashval_t
htab_cu_hash (const void *);
3023 static int htab_cu_eq (const void *, const void *);
3024 static void htab_cu_del (void *);
3025 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
3026 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
3027 static void add_sibling_attributes (dw_die_ref
);
3028 static void build_abbrev_table (dw_die_ref
, htab_t
);
3029 static void output_location_lists (dw_die_ref
);
3030 static int constant_size (unsigned HOST_WIDE_INT
);
3031 static unsigned long size_of_die (dw_die_ref
);
3032 static void calc_die_sizes (dw_die_ref
);
3033 static void calc_base_type_die_sizes (void);
3034 static void mark_dies (dw_die_ref
);
3035 static void unmark_dies (dw_die_ref
);
3036 static void unmark_all_dies (dw_die_ref
);
3037 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3038 static unsigned long size_of_aranges (void);
3039 static enum dwarf_form
value_format (dw_attr_ref
);
3040 static void output_value_format (dw_attr_ref
);
3041 static void output_abbrev_section (void);
3042 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3043 static void output_die_symbol (dw_die_ref
);
3044 static void output_die (dw_die_ref
);
3045 static void output_compilation_unit_header (void);
3046 static void output_comp_unit (dw_die_ref
, int);
3047 static void output_comdat_type_unit (comdat_type_node
*);
3048 static const char *dwarf2_name (tree
, int);
3049 static void add_pubname (tree
, dw_die_ref
);
3050 static void add_enumerator_pubname (const char *, dw_die_ref
);
3051 static void add_pubname_string (const char *, dw_die_ref
);
3052 static void add_pubtype (tree
, dw_die_ref
);
3053 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3054 static void output_aranges (unsigned long);
3055 static unsigned int add_ranges_num (int);
3056 static unsigned int add_ranges (const_tree
);
3057 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3059 static void output_ranges (void);
3060 static dw_line_info_table
*new_line_info_table (void);
3061 static void output_line_info (bool);
3062 static void output_file_names (void);
3063 static dw_die_ref
base_type_die (tree
);
3064 static int is_base_type (tree
);
3065 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3066 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3067 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3068 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3069 static int type_is_enum (const_tree
);
3070 static unsigned int dbx_reg_number (const_rtx
);
3071 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3072 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3073 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3074 enum var_init_status
);
3075 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3076 enum var_init_status
);
3077 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3078 enum var_init_status
);
3079 static int is_based_loc (const_rtx
);
3080 static int resolve_one_addr (rtx
*, void *);
3081 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3082 enum var_init_status
);
3083 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3084 enum var_init_status
);
3085 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3086 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3087 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3088 static tree
field_type (const_tree
);
3089 static unsigned int simple_type_align_in_bits (const_tree
);
3090 static unsigned int simple_decl_align_in_bits (const_tree
);
3091 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3092 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3093 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3095 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3096 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3097 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3098 static void insert_double (double_int
, unsigned char *);
3099 static void insert_float (const_rtx
, unsigned char *);
3100 static rtx
rtl_for_decl_location (tree
);
3101 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3102 enum dwarf_attribute
);
3103 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3104 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3105 static void add_name_attribute (dw_die_ref
, const char *);
3106 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3107 static void add_comp_dir_attribute (dw_die_ref
);
3108 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3109 static void add_subscript_info (dw_die_ref
, tree
, bool);
3110 static void add_byte_size_attribute (dw_die_ref
, tree
);
3111 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3112 static void add_bit_size_attribute (dw_die_ref
, tree
);
3113 static void add_prototyped_attribute (dw_die_ref
, tree
);
3114 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3115 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3116 static void add_src_coords_attributes (dw_die_ref
, tree
);
3117 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3118 static void push_decl_scope (tree
);
3119 static void pop_decl_scope (void);
3120 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3121 static inline int local_scope_p (dw_die_ref
);
3122 static inline int class_scope_p (dw_die_ref
);
3123 static inline int class_or_namespace_scope_p (dw_die_ref
);
3124 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3125 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3126 static const char *type_tag (const_tree
);
3127 static tree
member_declared_type (const_tree
);
3129 static const char *decl_start_label (tree
);
3131 static void gen_array_type_die (tree
, dw_die_ref
);
3132 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3134 static void gen_entry_point_die (tree
, dw_die_ref
);
3136 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3137 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3138 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3139 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3140 static void gen_formal_types_die (tree
, dw_die_ref
);
3141 static void gen_subprogram_die (tree
, dw_die_ref
);
3142 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3143 static void gen_const_die (tree
, dw_die_ref
);
3144 static void gen_label_die (tree
, dw_die_ref
);
3145 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3146 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3147 static void gen_field_die (tree
, dw_die_ref
);
3148 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3149 static dw_die_ref
gen_compile_unit_die (const char *);
3150 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3151 static void gen_member_die (tree
, dw_die_ref
);
3152 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3153 enum debug_info_usage
);
3154 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3155 static void gen_typedef_die (tree
, dw_die_ref
);
3156 static void gen_type_die (tree
, dw_die_ref
);
3157 static void gen_block_die (tree
, dw_die_ref
, int);
3158 static void decls_for_scope (tree
, dw_die_ref
, int);
3159 static inline int is_redundant_typedef (const_tree
);
3160 static bool is_naming_typedef_decl (const_tree
);
3161 static inline dw_die_ref
get_context_die (tree
);
3162 static void gen_namespace_die (tree
, dw_die_ref
);
3163 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3164 static dw_die_ref
force_decl_die (tree
);
3165 static dw_die_ref
force_type_die (tree
);
3166 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3167 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3168 static struct dwarf_file_data
* lookup_filename (const char *);
3169 static void retry_incomplete_types (void);
3170 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3171 static void gen_generic_params_dies (tree
);
3172 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3173 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3174 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3175 static int file_info_cmp (const void *, const void *);
3176 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3177 const char *, const char *);
3178 static void output_loc_list (dw_loc_list_ref
);
3179 static char *gen_internal_sym (const char *);
3180 static bool want_pubnames (void);
3182 static void prune_unmark_dies (dw_die_ref
);
3183 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3184 static void prune_unused_types_mark (dw_die_ref
, int);
3185 static void prune_unused_types_walk (dw_die_ref
);
3186 static void prune_unused_types_walk_attribs (dw_die_ref
);
3187 static void prune_unused_types_prune (dw_die_ref
);
3188 static void prune_unused_types (void);
3189 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3190 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3191 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3192 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3193 const char *, const char *);
3194 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3195 static void gen_remaining_tmpl_value_param_die_attribute (void);
3196 static bool generic_type_p (tree
);
3197 static void schedule_generic_params_dies_gen (tree t
);
3198 static void gen_scheduled_generic_parms_dies (void);
3200 /* enum for tracking thread-local variables whose address is really an offset
3201 relative to the TLS pointer, which will need link-time relocation, but will
3202 not need relocation by the DWARF consumer. */
3210 /* Return the operator to use for an address of a variable. For dtprel_true, we
3211 use DW_OP_const*. For regular variables, which need both link-time
3212 relocation and consumer-level relocation (e.g., to account for shared objects
3213 loaded at a random address), we use DW_OP_addr*. */
3215 static inline enum dwarf_location_atom
3216 dw_addr_op (enum dtprel_bool dtprel
)
3218 if (dtprel
== dtprel_true
)
3219 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3220 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3222 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3225 /* Return a pointer to a newly allocated address location description. If
3226 dwarf_split_debug_info is true, then record the address with the appropriate
3228 static inline dw_loc_descr_ref
3229 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3231 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3233 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3234 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3235 ref
->dtprel
= dtprel
;
3236 if (dwarf_split_debug_info
)
3237 ref
->dw_loc_oprnd1
.val_entry
3238 = add_addr_table_entry (addr
,
3239 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3241 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3246 /* Section names used to hold DWARF debugging information. */
3248 #ifndef DEBUG_INFO_SECTION
3249 #define DEBUG_INFO_SECTION ".debug_info"
3251 #ifndef DEBUG_DWO_INFO_SECTION
3252 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3254 #ifndef DEBUG_ABBREV_SECTION
3255 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3257 #ifndef DEBUG_DWO_ABBREV_SECTION
3258 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3260 #ifndef DEBUG_ARANGES_SECTION
3261 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3263 #ifndef DEBUG_ADDR_SECTION
3264 #define DEBUG_ADDR_SECTION ".debug_addr"
3266 #ifndef DEBUG_NORM_MACINFO_SECTION
3267 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3269 #ifndef DEBUG_DWO_MACINFO_SECTION
3270 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3272 #ifndef DEBUG_MACINFO_SECTION
3273 #define DEBUG_MACINFO_SECTION \
3274 (!dwarf_split_debug_info \
3275 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3277 #ifndef DEBUG_NORM_MACRO_SECTION
3278 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3280 #ifndef DEBUG_DWO_MACRO_SECTION
3281 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3283 #ifndef DEBUG_MACRO_SECTION
3284 #define DEBUG_MACRO_SECTION \
3285 (!dwarf_split_debug_info \
3286 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3288 #ifndef DEBUG_LINE_SECTION
3289 #define DEBUG_LINE_SECTION ".debug_line"
3291 #ifndef DEBUG_DWO_LINE_SECTION
3292 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3294 #ifndef DEBUG_LOC_SECTION
3295 #define DEBUG_LOC_SECTION ".debug_loc"
3297 #ifndef DEBUG_DWO_LOC_SECTION
3298 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3300 #ifndef DEBUG_PUBNAMES_SECTION
3301 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3303 #ifndef DEBUG_PUBTYPES_SECTION
3304 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3306 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3307 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3308 #ifndef DEBUG_STR_OFFSETS_SECTION
3309 #define DEBUG_STR_OFFSETS_SECTION \
3310 (!dwarf_split_debug_info \
3311 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3313 #define DEBUG_DWO_STR_SECTION ".debug_str.dwo"
3314 #define DEBUG_NORM_STR_SECTION ".debug_str"
3315 #ifndef DEBUG_STR_SECTION
3316 #define DEBUG_STR_SECTION \
3317 (!dwarf_split_debug_info ? (DEBUG_NORM_STR_SECTION) : (DEBUG_DWO_STR_SECTION))
3319 #ifndef DEBUG_RANGES_SECTION
3320 #define DEBUG_RANGES_SECTION ".debug_ranges"
3323 /* Standard ELF section names for compiled code and data. */
3324 #ifndef TEXT_SECTION_NAME
3325 #define TEXT_SECTION_NAME ".text"
3328 /* Section flags for .debug_macinfo/.debug_macro section. */
3329 #define DEBUG_MACRO_SECTION_FLAGS \
3330 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3332 /* Section flags for .debug_str section. */
3333 #define DEBUG_STR_SECTION_FLAGS \
3334 (dwarf_split_debug_info \
3335 ? SECTION_DEBUG | SECTION_EXCLUDE \
3336 : (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3337 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3340 /* Labels we insert at beginning sections we can reference instead of
3341 the section names themselves. */
3343 #ifndef TEXT_SECTION_LABEL
3344 #define TEXT_SECTION_LABEL "Ltext"
3346 #ifndef COLD_TEXT_SECTION_LABEL
3347 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3349 #ifndef DEBUG_LINE_SECTION_LABEL
3350 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3352 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3353 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3355 #ifndef DEBUG_INFO_SECTION_LABEL
3356 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3358 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3359 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3361 #ifndef DEBUG_ABBREV_SECTION_LABEL
3362 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3364 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3365 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3367 #ifndef DEBUG_ADDR_SECTION_LABEL
3368 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3370 #ifndef DEBUG_LOC_SECTION_LABEL
3371 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3373 #ifndef DEBUG_RANGES_SECTION_LABEL
3374 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3376 #ifndef DEBUG_MACINFO_SECTION_LABEL
3377 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3379 #ifndef DEBUG_MACRO_SECTION_LABEL
3380 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3382 #define SKELETON_COMP_DIE_ABBREV 1
3383 #define SKELETON_TYPE_DIE_ABBREV 2
3385 /* Definitions of defaults for formats and names of various special
3386 (artificial) labels which may be generated within this file (when the -g
3387 options is used and DWARF2_DEBUGGING_INFO is in effect.
3388 If necessary, these may be overridden from within the tm.h file, but
3389 typically, overriding these defaults is unnecessary. */
3391 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3392 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3393 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3394 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3395 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3396 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3397 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3398 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3399 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3400 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3401 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3402 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3403 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3404 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3406 #ifndef TEXT_END_LABEL
3407 #define TEXT_END_LABEL "Letext"
3409 #ifndef COLD_END_LABEL
3410 #define COLD_END_LABEL "Letext_cold"
3412 #ifndef BLOCK_BEGIN_LABEL
3413 #define BLOCK_BEGIN_LABEL "LBB"
3415 #ifndef BLOCK_END_LABEL
3416 #define BLOCK_END_LABEL "LBE"
3418 #ifndef LINE_CODE_LABEL
3419 #define LINE_CODE_LABEL "LM"
3423 /* Return the root of the DIE's built for the current compilation unit. */
3425 comp_unit_die (void)
3427 if (!single_comp_unit_die
)
3428 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3429 return single_comp_unit_die
;
3432 /* We allow a language front-end to designate a function that is to be
3433 called to "demangle" any name before it is put into a DIE. */
3435 static const char *(*demangle_name_func
) (const char *);
3438 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3440 demangle_name_func
= func
;
3443 /* Test if rtl node points to a pseudo register. */
3446 is_pseudo_reg (const_rtx rtl
)
3448 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3449 || (GET_CODE (rtl
) == SUBREG
3450 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3453 /* Return a reference to a type, with its const and volatile qualifiers
3457 type_main_variant (tree type
)
3459 type
= TYPE_MAIN_VARIANT (type
);
3461 /* ??? There really should be only one main variant among any group of
3462 variants of a given type (and all of the MAIN_VARIANT values for all
3463 members of the group should point to that one type) but sometimes the C
3464 front-end messes this up for array types, so we work around that bug
3466 if (TREE_CODE (type
) == ARRAY_TYPE
)
3467 while (type
!= TYPE_MAIN_VARIANT (type
))
3468 type
= TYPE_MAIN_VARIANT (type
);
3473 /* Return nonzero if the given type node represents a tagged type. */
3476 is_tagged_type (const_tree type
)
3478 enum tree_code code
= TREE_CODE (type
);
3480 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3481 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3484 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3487 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3489 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3492 /* Return die_offset of a DIE reference to a base type. */
3494 static unsigned long int
3495 get_base_type_offset (dw_die_ref ref
)
3497 if (ref
->die_offset
)
3498 return ref
->die_offset
;
3499 if (comp_unit_die ()->die_abbrev
)
3501 calc_base_type_die_sizes ();
3502 gcc_assert (ref
->die_offset
);
3504 return ref
->die_offset
;
3507 /* Return die_offset of a DIE reference other than base type. */
3509 static unsigned long int
3510 get_ref_die_offset (dw_die_ref ref
)
3512 gcc_assert (ref
->die_offset
);
3513 return ref
->die_offset
;
3516 /* Convert a DIE tag into its string name. */
3519 dwarf_tag_name (unsigned int tag
)
3521 const char *name
= get_DW_TAG_name (tag
);
3526 return "DW_TAG_<unknown>";
3529 /* Convert a DWARF attribute code into its string name. */
3532 dwarf_attr_name (unsigned int attr
)
3538 #if VMS_DEBUGGING_INFO
3539 case DW_AT_HP_prologue
:
3540 return "DW_AT_HP_prologue";
3542 case DW_AT_MIPS_loop_unroll_factor
:
3543 return "DW_AT_MIPS_loop_unroll_factor";
3546 #if VMS_DEBUGGING_INFO
3547 case DW_AT_HP_epilogue
:
3548 return "DW_AT_HP_epilogue";
3550 case DW_AT_MIPS_stride
:
3551 return "DW_AT_MIPS_stride";
3555 name
= get_DW_AT_name (attr
);
3560 return "DW_AT_<unknown>";
3563 /* Convert a DWARF value form code into its string name. */
3566 dwarf_form_name (unsigned int form
)
3568 const char *name
= get_DW_FORM_name (form
);
3573 return "DW_FORM_<unknown>";
3576 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3577 instance of an inlined instance of a decl which is local to an inline
3578 function, so we have to trace all of the way back through the origin chain
3579 to find out what sort of node actually served as the original seed for the
3583 decl_ultimate_origin (const_tree decl
)
3585 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3588 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3589 nodes in the function to point to themselves; ignore that if
3590 we're trying to output the abstract instance of this function. */
3591 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3594 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3595 most distant ancestor, this should never happen. */
3596 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3598 return DECL_ABSTRACT_ORIGIN (decl
);
3601 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3602 of a virtual function may refer to a base class, so we check the 'this'
3606 decl_class_context (tree decl
)
3608 tree context
= NULL_TREE
;
3610 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3611 context
= DECL_CONTEXT (decl
);
3613 context
= TYPE_MAIN_VARIANT
3614 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3616 if (context
&& !TYPE_P (context
))
3617 context
= NULL_TREE
;
3622 /* Add an attribute/value pair to a DIE. */
3625 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3627 /* Maybe this should be an assert? */
3631 vec_safe_reserve (die
->die_attr
, 1);
3632 vec_safe_push (die
->die_attr
, *attr
);
3635 static inline enum dw_val_class
3636 AT_class (dw_attr_ref a
)
3638 return a
->dw_attr_val
.val_class
;
3641 /* Return the index for any attribute that will be referenced with a
3642 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3643 are stored in dw_attr_val.v.val_str for reference counting
3646 static inline unsigned int
3647 AT_index (dw_attr_ref a
)
3649 if (AT_class (a
) == dw_val_class_str
)
3650 return a
->dw_attr_val
.v
.val_str
->index
;
3651 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3652 return a
->dw_attr_val
.val_entry
->index
;
3656 /* Add a flag value attribute to a DIE. */
3659 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3663 attr
.dw_attr
= attr_kind
;
3664 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3665 attr
.dw_attr_val
.val_entry
= NULL
;
3666 attr
.dw_attr_val
.v
.val_flag
= flag
;
3667 add_dwarf_attr (die
, &attr
);
3670 static inline unsigned
3671 AT_flag (dw_attr_ref a
)
3673 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3674 return a
->dw_attr_val
.v
.val_flag
;
3677 /* Add a signed integer attribute value to a DIE. */
3680 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3684 attr
.dw_attr
= attr_kind
;
3685 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3686 attr
.dw_attr_val
.val_entry
= NULL
;
3687 attr
.dw_attr_val
.v
.val_int
= int_val
;
3688 add_dwarf_attr (die
, &attr
);
3691 static inline HOST_WIDE_INT
3692 AT_int (dw_attr_ref a
)
3694 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3695 return a
->dw_attr_val
.v
.val_int
;
3698 /* Add an unsigned integer attribute value to a DIE. */
3701 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3702 unsigned HOST_WIDE_INT unsigned_val
)
3706 attr
.dw_attr
= attr_kind
;
3707 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3708 attr
.dw_attr_val
.val_entry
= NULL
;
3709 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3710 add_dwarf_attr (die
, &attr
);
3713 static inline unsigned HOST_WIDE_INT
3714 AT_unsigned (dw_attr_ref a
)
3716 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3717 return a
->dw_attr_val
.v
.val_unsigned
;
3720 /* Add an unsigned double integer attribute value to a DIE. */
3723 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3724 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3728 attr
.dw_attr
= attr_kind
;
3729 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3730 attr
.dw_attr_val
.val_entry
= NULL
;
3731 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3732 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3733 add_dwarf_attr (die
, &attr
);
3736 /* Add a floating point attribute value to a DIE and return it. */
3739 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3740 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3744 attr
.dw_attr
= attr_kind
;
3745 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3746 attr
.dw_attr_val
.val_entry
= NULL
;
3747 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3748 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3749 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3750 add_dwarf_attr (die
, &attr
);
3753 /* Add an 8-byte data attribute value to a DIE. */
3756 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3757 unsigned char data8
[8])
3761 attr
.dw_attr
= attr_kind
;
3762 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3763 attr
.dw_attr_val
.val_entry
= NULL
;
3764 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3765 add_dwarf_attr (die
, &attr
);
3768 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3769 dwarf_split_debug_info, address attributes in dies destined for the
3770 final executable have force_direct set to avoid using indexed
3774 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3780 lbl_id
= xstrdup (lbl_low
);
3781 attr
.dw_attr
= DW_AT_low_pc
;
3782 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3783 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3784 if (dwarf_split_debug_info
&& !force_direct
)
3785 attr
.dw_attr_val
.val_entry
3786 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3788 attr
.dw_attr_val
.val_entry
= NULL
;
3789 add_dwarf_attr (die
, &attr
);
3791 attr
.dw_attr
= DW_AT_high_pc
;
3792 if (dwarf_version
< 4)
3793 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3795 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3796 lbl_id
= xstrdup (lbl_high
);
3797 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3798 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3799 && dwarf_split_debug_info
&& !force_direct
)
3800 attr
.dw_attr_val
.val_entry
3801 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3803 attr
.dw_attr_val
.val_entry
= NULL
;
3804 add_dwarf_attr (die
, &attr
);
3807 /* Hash and equality functions for debug_str_hash. */
3810 debug_str_do_hash (const void *x
)
3812 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3816 debug_str_eq (const void *x1
, const void *x2
)
3818 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3819 (const char *)x2
) == 0;
3822 /* Add STR to the indirect string hash table. */
3824 static struct indirect_string_node
*
3825 find_AT_string (const char *str
)
3827 struct indirect_string_node
*node
;
3830 if (! debug_str_hash
)
3831 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3832 debug_str_eq
, NULL
);
3834 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
3835 htab_hash_string (str
), INSERT
);
3838 node
= ggc_alloc_cleared_indirect_string_node ();
3839 node
->str
= ggc_strdup (str
);
3843 node
= (struct indirect_string_node
*) *slot
;
3849 /* Add a string attribute value to a DIE. */
3852 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3855 struct indirect_string_node
*node
;
3857 node
= find_AT_string (str
);
3859 attr
.dw_attr
= attr_kind
;
3860 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3861 attr
.dw_attr_val
.val_entry
= NULL
;
3862 attr
.dw_attr_val
.v
.val_str
= node
;
3863 add_dwarf_attr (die
, &attr
);
3866 static inline const char *
3867 AT_string (dw_attr_ref a
)
3869 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3870 return a
->dw_attr_val
.v
.val_str
->str
;
3873 /* Call this function directly to bypass AT_string_form's logic to put
3874 the string inline in the die. */
3877 set_indirect_string (struct indirect_string_node
*node
)
3880 /* Already indirect is a no op. */
3881 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3883 gcc_assert (node
->label
);
3886 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3887 ++dw2_string_counter
;
3888 node
->label
= xstrdup (label
);
3890 if (!dwarf_split_debug_info
)
3892 node
->form
= DW_FORM_strp
;
3893 node
->index
= NOT_INDEXED
;
3897 node
->form
= DW_FORM_GNU_str_index
;
3898 node
->index
= NO_INDEX_ASSIGNED
;
3902 /* Find out whether a string should be output inline in DIE
3903 or out-of-line in .debug_str section. */
3905 static enum dwarf_form
3906 find_string_form (struct indirect_string_node
*node
)
3913 len
= strlen (node
->str
) + 1;
3915 /* If the string is shorter or equal to the size of the reference, it is
3916 always better to put it inline. */
3917 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3918 return node
->form
= DW_FORM_string
;
3920 /* If we cannot expect the linker to merge strings in .debug_str
3921 section, only put it into .debug_str if it is worth even in this
3923 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3924 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3925 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3926 return node
->form
= DW_FORM_string
;
3928 set_indirect_string (node
);
3933 /* Find out whether the string referenced from the attribute should be
3934 output inline in DIE or out-of-line in .debug_str section. */
3936 static enum dwarf_form
3937 AT_string_form (dw_attr_ref a
)
3939 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3940 return find_string_form (a
->dw_attr_val
.v
.val_str
);
3943 /* Add a DIE reference attribute value to a DIE. */
3946 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3950 #ifdef ENABLE_CHECKING
3951 gcc_assert (targ_die
!= NULL
);
3953 /* With LTO we can end up trying to reference something we didn't create
3954 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3955 if (targ_die
== NULL
)
3959 attr
.dw_attr
= attr_kind
;
3960 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
3961 attr
.dw_attr_val
.val_entry
= NULL
;
3962 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
3963 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
3964 add_dwarf_attr (die
, &attr
);
3967 /* Change DIE reference REF to point to NEW_DIE instead. */
3970 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
3972 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
3973 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
3974 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
3977 /* Add an AT_specification attribute to a DIE, and also make the back
3978 pointer from the specification to the definition. */
3981 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
3983 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
3984 gcc_assert (!targ_die
->die_definition
);
3985 targ_die
->die_definition
= die
;
3988 static inline dw_die_ref
3989 AT_ref (dw_attr_ref a
)
3991 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
3992 return a
->dw_attr_val
.v
.val_die_ref
.die
;
3996 AT_ref_external (dw_attr_ref a
)
3998 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
3999 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4005 set_AT_ref_external (dw_attr_ref a
, int i
)
4007 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4008 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4011 /* Add an FDE reference attribute value to a DIE. */
4014 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4018 attr
.dw_attr
= attr_kind
;
4019 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4020 attr
.dw_attr_val
.val_entry
= NULL
;
4021 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4022 add_dwarf_attr (die
, &attr
);
4025 /* Add a location description attribute value to a DIE. */
4028 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4032 attr
.dw_attr
= attr_kind
;
4033 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4034 attr
.dw_attr_val
.val_entry
= NULL
;
4035 attr
.dw_attr_val
.v
.val_loc
= loc
;
4036 add_dwarf_attr (die
, &attr
);
4039 static inline dw_loc_descr_ref
4040 AT_loc (dw_attr_ref a
)
4042 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4043 return a
->dw_attr_val
.v
.val_loc
;
4047 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4051 attr
.dw_attr
= attr_kind
;
4052 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4053 attr
.dw_attr_val
.val_entry
= NULL
;
4054 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4055 add_dwarf_attr (die
, &attr
);
4056 have_location_lists
= true;
4059 static inline dw_loc_list_ref
4060 AT_loc_list (dw_attr_ref a
)
4062 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4063 return a
->dw_attr_val
.v
.val_loc_list
;
4066 static inline dw_loc_list_ref
*
4067 AT_loc_list_ptr (dw_attr_ref a
)
4069 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4070 return &a
->dw_attr_val
.v
.val_loc_list
;
4073 /* Table of entries into the .debug_addr section. */
4075 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4077 /* Hash an address_table_entry. */
4080 addr_table_entry_do_hash (const void *x
)
4082 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4086 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4087 case ate_kind_rtx_dtprel
:
4088 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4089 case ate_kind_label
:
4090 return htab_hash_string (a
->addr
.label
);
4096 /* Determine equality for two address_table_entries. */
4099 addr_table_entry_eq (const void *x1
, const void *x2
)
4101 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4102 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4104 if (a1
->kind
!= a2
->kind
)
4109 case ate_kind_rtx_dtprel
:
4110 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4111 case ate_kind_label
:
4112 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4118 /* Initialize an addr_table_entry. */
4121 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4127 case ate_kind_rtx_dtprel
:
4128 e
->addr
.rtl
= (rtx
) addr
;
4130 case ate_kind_label
:
4131 e
->addr
.label
= (char *) addr
;
4135 e
->index
= NO_INDEX_ASSIGNED
;
4138 /* Add attr to the address table entry to the table. Defer setting an
4139 index until output time. */
4141 static addr_table_entry
*
4142 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4144 addr_table_entry
*node
;
4145 addr_table_entry finder
;
4148 gcc_assert (dwarf_split_debug_info
);
4149 if (! addr_index_table
)
4150 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4151 addr_table_entry_eq
, NULL
);
4152 init_addr_table_entry (&finder
, kind
, addr
);
4153 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4155 if (*slot
== HTAB_EMPTY_ENTRY
)
4157 node
= ggc_alloc_cleared_addr_table_entry ();
4158 init_addr_table_entry (node
, kind
, addr
);
4162 node
= (addr_table_entry
*) *slot
;
4168 /* Remove an entry from the addr table by decrementing its refcount.
4169 Strictly, decrementing the refcount would be enough, but the
4170 assertion that the entry is actually in the table has found
4174 remove_addr_table_entry (addr_table_entry
*entry
)
4176 addr_table_entry
*node
;
4178 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4179 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4180 /* After an index is assigned, the table is frozen. */
4181 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4185 /* Given a location list, remove all addresses it refers to from the
4189 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4191 for (; descr
; descr
= descr
->dw_loc_next
)
4192 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4194 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4195 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4199 /* A helper function for dwarf2out_finish called through
4200 htab_traverse. Assign an addr_table_entry its index. All entries
4201 must be collected into the table when this function is called,
4202 because the indexing code relies on htab_traverse to traverse nodes
4203 in the same order for each run. */
4206 index_addr_table_entry (void **h
, void *v
)
4208 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4209 unsigned int *index
= (unsigned int *) v
;
4211 /* Don't index unreferenced nodes. */
4212 if (node
->refcount
== 0)
4215 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
4216 node
->index
= *index
;
4222 /* Add an address constant attribute value to a DIE. When using
4223 dwarf_split_debug_info, address attributes in dies destined for the
4224 final executable should be direct references--setting the parameter
4225 force_direct ensures this behavior. */
4228 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4233 attr
.dw_attr
= attr_kind
;
4234 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4235 attr
.dw_attr_val
.v
.val_addr
= addr
;
4236 if (dwarf_split_debug_info
&& !force_direct
)
4237 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4239 attr
.dw_attr_val
.val_entry
= NULL
;
4240 add_dwarf_attr (die
, &attr
);
4243 /* Get the RTX from to an address DIE attribute. */
4246 AT_addr (dw_attr_ref a
)
4248 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4249 return a
->dw_attr_val
.v
.val_addr
;
4252 /* Add a file attribute value to a DIE. */
4255 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4256 struct dwarf_file_data
*fd
)
4260 attr
.dw_attr
= attr_kind
;
4261 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4262 attr
.dw_attr_val
.val_entry
= NULL
;
4263 attr
.dw_attr_val
.v
.val_file
= fd
;
4264 add_dwarf_attr (die
, &attr
);
4267 /* Get the dwarf_file_data from a file DIE attribute. */
4269 static inline struct dwarf_file_data
*
4270 AT_file (dw_attr_ref a
)
4272 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4273 return a
->dw_attr_val
.v
.val_file
;
4276 /* Add a vms delta attribute value to a DIE. */
4279 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4280 const char *lbl1
, const char *lbl2
)
4284 attr
.dw_attr
= attr_kind
;
4285 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4286 attr
.dw_attr_val
.val_entry
= NULL
;
4287 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4288 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4289 add_dwarf_attr (die
, &attr
);
4292 /* Add a label identifier attribute value to a DIE. */
4295 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4300 attr
.dw_attr
= attr_kind
;
4301 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4302 attr
.dw_attr_val
.val_entry
= NULL
;
4303 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4304 if (dwarf_split_debug_info
)
4305 attr
.dw_attr_val
.val_entry
4306 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4308 add_dwarf_attr (die
, &attr
);
4311 /* Add a section offset attribute value to a DIE, an offset into the
4312 debug_line section. */
4315 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4320 attr
.dw_attr
= attr_kind
;
4321 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4322 attr
.dw_attr_val
.val_entry
= NULL
;
4323 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4324 add_dwarf_attr (die
, &attr
);
4327 /* Add a section offset attribute value to a DIE, an offset into the
4328 debug_macinfo section. */
4331 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4336 attr
.dw_attr
= attr_kind
;
4337 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4338 attr
.dw_attr_val
.val_entry
= NULL
;
4339 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4340 add_dwarf_attr (die
, &attr
);
4343 /* Add an offset attribute value to a DIE. */
4346 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4347 unsigned HOST_WIDE_INT offset
)
4351 attr
.dw_attr
= attr_kind
;
4352 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4353 attr
.dw_attr_val
.val_entry
= NULL
;
4354 attr
.dw_attr_val
.v
.val_offset
= offset
;
4355 add_dwarf_attr (die
, &attr
);
4358 /* Add a range_list attribute value to a DIE. When using
4359 dwarf_split_debug_info, address attributes in dies destined for the
4360 final executable should be direct references--setting the parameter
4361 force_direct ensures this behavior. */
4363 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4364 #define RELOCATED_OFFSET (NULL)
4367 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4368 long unsigned int offset
, bool force_direct
)
4372 attr
.dw_attr
= attr_kind
;
4373 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4374 /* For the range_list attribute, use val_entry to store whether the
4375 offset should follow split-debug-info or normal semantics. This
4376 value is read in output_range_list_offset. */
4377 if (dwarf_split_debug_info
&& !force_direct
)
4378 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4380 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4381 attr
.dw_attr_val
.v
.val_offset
= offset
;
4382 add_dwarf_attr (die
, &attr
);
4385 /* Return the start label of a delta attribute. */
4387 static inline const char *
4388 AT_vms_delta1 (dw_attr_ref a
)
4390 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4391 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4394 /* Return the end label of a delta attribute. */
4396 static inline const char *
4397 AT_vms_delta2 (dw_attr_ref a
)
4399 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4400 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4403 static inline const char *
4404 AT_lbl (dw_attr_ref a
)
4406 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4407 || AT_class (a
) == dw_val_class_lineptr
4408 || AT_class (a
) == dw_val_class_macptr
4409 || AT_class (a
) == dw_val_class_high_pc
));
4410 return a
->dw_attr_val
.v
.val_lbl_id
;
4413 /* Get the attribute of type attr_kind. */
4416 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4420 dw_die_ref spec
= NULL
;
4425 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4426 if (a
->dw_attr
== attr_kind
)
4428 else if (a
->dw_attr
== DW_AT_specification
4429 || a
->dw_attr
== DW_AT_abstract_origin
)
4433 return get_AT (spec
, attr_kind
);
4438 /* Returns the parent of the declaration of DIE. */
4441 get_die_parent (dw_die_ref die
)
4448 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4449 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4452 return die
->die_parent
;
4455 /* Return the "low pc" attribute value, typically associated with a subprogram
4456 DIE. Return null if the "low pc" attribute is either not present, or if it
4457 cannot be represented as an assembler label identifier. */
4459 static inline const char *
4460 get_AT_low_pc (dw_die_ref die
)
4462 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4464 return a
? AT_lbl (a
) : NULL
;
4467 /* Return the "high pc" attribute value, typically associated with a subprogram
4468 DIE. Return null if the "high pc" attribute is either not present, or if it
4469 cannot be represented as an assembler label identifier. */
4471 static inline const char *
4472 get_AT_hi_pc (dw_die_ref die
)
4474 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4476 return a
? AT_lbl (a
) : NULL
;
4479 /* Return the value of the string attribute designated by ATTR_KIND, or
4480 NULL if it is not present. */
4482 static inline const char *
4483 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4485 dw_attr_ref a
= get_AT (die
, attr_kind
);
4487 return a
? AT_string (a
) : NULL
;
4490 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4491 if it is not present. */
4494 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4496 dw_attr_ref a
= get_AT (die
, attr_kind
);
4498 return a
? AT_flag (a
) : 0;
4501 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4502 if it is not present. */
4504 static inline unsigned
4505 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4507 dw_attr_ref a
= get_AT (die
, attr_kind
);
4509 return a
? AT_unsigned (a
) : 0;
4512 static inline dw_die_ref
4513 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4515 dw_attr_ref a
= get_AT (die
, attr_kind
);
4517 return a
? AT_ref (a
) : NULL
;
4520 static inline struct dwarf_file_data
*
4521 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4523 dw_attr_ref a
= get_AT (die
, attr_kind
);
4525 return a
? AT_file (a
) : NULL
;
4528 /* Return TRUE if the language is C++. */
4533 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4535 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4538 /* Return TRUE if the language is Fortran. */
4543 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4545 return (lang
== DW_LANG_Fortran77
4546 || lang
== DW_LANG_Fortran90
4547 || lang
== DW_LANG_Fortran95
);
4550 /* Return TRUE if the language is Ada. */
4555 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4557 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4560 /* Remove the specified attribute if present. */
4563 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4571 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4572 if (a
->dw_attr
== attr_kind
)
4574 if (AT_class (a
) == dw_val_class_str
)
4575 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4576 a
->dw_attr_val
.v
.val_str
->refcount
--;
4578 /* vec::ordered_remove should help reduce the number of abbrevs
4580 die
->die_attr
->ordered_remove (ix
);
4585 /* Remove CHILD from its parent. PREV must have the property that
4586 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4589 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4591 gcc_assert (child
->die_parent
== prev
->die_parent
);
4592 gcc_assert (prev
->die_sib
== child
);
4595 gcc_assert (child
->die_parent
->die_child
== child
);
4599 prev
->die_sib
= child
->die_sib
;
4600 if (child
->die_parent
->die_child
== child
)
4601 child
->die_parent
->die_child
= prev
;
4604 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4605 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4608 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4610 dw_die_ref parent
= old_child
->die_parent
;
4612 gcc_assert (parent
== prev
->die_parent
);
4613 gcc_assert (prev
->die_sib
== old_child
);
4615 new_child
->die_parent
= parent
;
4616 if (prev
== old_child
)
4618 gcc_assert (parent
->die_child
== old_child
);
4619 new_child
->die_sib
= new_child
;
4623 prev
->die_sib
= new_child
;
4624 new_child
->die_sib
= old_child
->die_sib
;
4626 if (old_child
->die_parent
->die_child
== old_child
)
4627 old_child
->die_parent
->die_child
= new_child
;
4630 /* Move all children from OLD_PARENT to NEW_PARENT. */
4633 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4636 new_parent
->die_child
= old_parent
->die_child
;
4637 old_parent
->die_child
= NULL
;
4638 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4641 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4645 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4651 dw_die_ref prev
= c
;
4653 while (c
->die_tag
== tag
)
4655 remove_child_with_prev (c
, prev
);
4656 /* Might have removed every child. */
4657 if (c
== c
->die_sib
)
4661 } while (c
!= die
->die_child
);
4664 /* Add a CHILD_DIE as the last child of DIE. */
4667 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4669 /* FIXME this should probably be an assert. */
4670 if (! die
|| ! child_die
)
4672 gcc_assert (die
!= child_die
);
4674 child_die
->die_parent
= die
;
4677 child_die
->die_sib
= die
->die_child
->die_sib
;
4678 die
->die_child
->die_sib
= child_die
;
4681 child_die
->die_sib
= child_die
;
4682 die
->die_child
= child_die
;
4685 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4686 is the specification, to the end of PARENT's list of children.
4687 This is done by removing and re-adding it. */
4690 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4694 /* We want the declaration DIE from inside the class, not the
4695 specification DIE at toplevel. */
4696 if (child
->die_parent
!= parent
)
4698 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4704 gcc_assert (child
->die_parent
== parent
4705 || (child
->die_parent
4706 == get_AT_ref (parent
, DW_AT_specification
)));
4708 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4709 if (p
->die_sib
== child
)
4711 remove_child_with_prev (child
, p
);
4715 add_child_die (parent
, child
);
4718 /* Return a pointer to a newly created DIE node. */
4720 static inline dw_die_ref
4721 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4723 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4725 die
->die_tag
= tag_value
;
4727 if (parent_die
!= NULL
)
4728 add_child_die (parent_die
, die
);
4731 limbo_die_node
*limbo_node
;
4733 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4734 limbo_node
->die
= die
;
4735 limbo_node
->created_for
= t
;
4736 limbo_node
->next
= limbo_die_list
;
4737 limbo_die_list
= limbo_node
;
4743 /* Return the DIE associated with the given type specifier. */
4745 static inline dw_die_ref
4746 lookup_type_die (tree type
)
4748 return TYPE_SYMTAB_DIE (type
);
4751 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4752 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4753 anonymous type instead the one of the naming typedef. */
4755 static inline dw_die_ref
4756 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4759 && TREE_CODE (type
) == RECORD_TYPE
4761 && type_die
->die_tag
== DW_TAG_typedef
4762 && is_naming_typedef_decl (TYPE_NAME (type
)))
4763 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4767 /* Like lookup_type_die, but if type is an anonymous type named by a
4768 typedef[1], return the DIE of the anonymous type instead the one of
4769 the naming typedef. This is because in gen_typedef_die, we did
4770 equate the anonymous struct named by the typedef with the DIE of
4771 the naming typedef. So by default, lookup_type_die on an anonymous
4772 struct yields the DIE of the naming typedef.
4774 [1]: Read the comment of is_naming_typedef_decl to learn about what
4775 a naming typedef is. */
4777 static inline dw_die_ref
4778 lookup_type_die_strip_naming_typedef (tree type
)
4780 dw_die_ref die
= lookup_type_die (type
);
4781 return strip_naming_typedef (type
, die
);
4784 /* Equate a DIE to a given type specifier. */
4787 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4789 TYPE_SYMTAB_DIE (type
) = type_die
;
4792 /* Returns a hash value for X (which really is a die_struct). */
4795 decl_die_table_hash (const void *x
)
4797 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4800 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4803 decl_die_table_eq (const void *x
, const void *y
)
4805 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4808 /* Return the DIE associated with a given declaration. */
4810 static inline dw_die_ref
4811 lookup_decl_die (tree decl
)
4813 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4816 /* Returns a hash value for X (which really is a var_loc_list). */
4819 decl_loc_table_hash (const void *x
)
4821 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4824 /* Return nonzero if decl_id of var_loc_list X is the same as
4828 decl_loc_table_eq (const void *x
, const void *y
)
4830 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4833 /* Return the var_loc list associated with a given declaration. */
4835 static inline var_loc_list
*
4836 lookup_decl_loc (const_tree decl
)
4838 if (!decl_loc_table
)
4840 return (var_loc_list
*)
4841 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4844 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4847 cached_dw_loc_list_table_hash (const void *x
)
4849 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4852 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4856 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4858 return (((const cached_dw_loc_list
*) x
)->decl_id
4859 == DECL_UID ((const_tree
) y
));
4862 /* Equate a DIE to a particular declaration. */
4865 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4867 unsigned int decl_id
= DECL_UID (decl
);
4870 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4872 decl_die
->decl_id
= decl_id
;
4875 /* Return how many bits covers PIECE EXPR_LIST. */
4878 decl_piece_bitsize (rtx piece
)
4880 int ret
= (int) GET_MODE (piece
);
4883 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4884 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4885 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4888 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4891 decl_piece_varloc_ptr (rtx piece
)
4893 if ((int) GET_MODE (piece
))
4894 return &XEXP (piece
, 0);
4896 return &XEXP (XEXP (piece
, 0), 1);
4899 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4900 Next is the chain of following piece nodes. */
4903 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4905 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4906 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4908 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4913 /* Return rtx that should be stored into loc field for
4914 LOC_NOTE and BITPOS/BITSIZE. */
4917 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4918 HOST_WIDE_INT bitsize
)
4922 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4924 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4929 /* This function either modifies location piece list *DEST in
4930 place (if SRC and INNER is NULL), or copies location piece list
4931 *SRC to *DEST while modifying it. Location BITPOS is modified
4932 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4933 not copied and if needed some padding around it is added.
4934 When modifying in place, DEST should point to EXPR_LIST where
4935 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4936 to the start of the whole list and INNER points to the EXPR_LIST
4937 where earlier pieces cover PIECE_BITPOS bits. */
4940 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4941 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4942 HOST_WIDE_INT bitsize
, rtx loc_note
)
4945 bool copy
= inner
!= NULL
;
4949 /* First copy all nodes preceding the current bitpos. */
4950 while (src
!= inner
)
4952 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4953 decl_piece_bitsize (*src
), NULL_RTX
);
4954 dest
= &XEXP (*dest
, 1);
4955 src
= &XEXP (*src
, 1);
4958 /* Add padding if needed. */
4959 if (bitpos
!= piece_bitpos
)
4961 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
4962 copy
? NULL_RTX
: *dest
);
4963 dest
= &XEXP (*dest
, 1);
4965 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
4968 /* A piece with correct bitpos and bitsize already exist,
4969 just update the location for it and return. */
4970 *decl_piece_varloc_ptr (*dest
) = loc_note
;
4973 /* Add the piece that changed. */
4974 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
4975 dest
= &XEXP (*dest
, 1);
4976 /* Skip over pieces that overlap it. */
4977 diff
= bitpos
- piece_bitpos
+ bitsize
;
4980 while (diff
> 0 && *src
)
4983 diff
-= decl_piece_bitsize (piece
);
4985 src
= &XEXP (piece
, 1);
4988 *src
= XEXP (piece
, 1);
4989 free_EXPR_LIST_node (piece
);
4992 /* Add padding if needed. */
4993 if (diff
< 0 && *src
)
4997 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
4998 dest
= &XEXP (*dest
, 1);
5002 /* Finally copy all nodes following it. */
5005 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5006 decl_piece_bitsize (*src
), NULL_RTX
);
5007 dest
= &XEXP (*dest
, 1);
5008 src
= &XEXP (*src
, 1);
5012 /* Add a variable location node to the linked list for DECL. */
5014 static struct var_loc_node
*
5015 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5017 unsigned int decl_id
;
5020 struct var_loc_node
*loc
= NULL
;
5021 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5023 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
5025 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5027 && (handled_component_p (realdecl
)
5028 || (TREE_CODE (realdecl
) == MEM_REF
5029 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
)))
5031 HOST_WIDE_INT maxsize
;
5034 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5035 if (!DECL_P (innerdecl
)
5036 || DECL_IGNORED_P (innerdecl
)
5037 || TREE_STATIC (innerdecl
)
5039 || bitpos
+ bitsize
> 256
5040 || bitsize
!= maxsize
)
5046 decl_id
= DECL_UID (decl
);
5047 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5050 temp
= ggc_alloc_cleared_var_loc_list ();
5051 temp
->decl_id
= decl_id
;
5055 temp
= (var_loc_list
*) *slot
;
5057 /* For PARM_DECLs try to keep around the original incoming value,
5058 even if that means we'll emit a zero-range .debug_loc entry. */
5060 && temp
->first
== temp
->last
5061 && TREE_CODE (decl
) == PARM_DECL
5062 && GET_CODE (temp
->first
->loc
) == NOTE
5063 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5064 && DECL_INCOMING_RTL (decl
)
5065 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5066 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5067 == GET_CODE (DECL_INCOMING_RTL (decl
))
5068 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5070 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5071 NOTE_VAR_LOCATION_LOC (loc_note
))
5072 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5073 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5075 loc
= ggc_alloc_cleared_var_loc_node ();
5076 temp
->first
->next
= loc
;
5078 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5080 else if (temp
->last
)
5082 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5083 rtx
*piece_loc
= NULL
, last_loc_note
;
5084 int piece_bitpos
= 0;
5088 gcc_assert (last
->next
== NULL
);
5090 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5092 piece_loc
= &last
->loc
;
5095 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5096 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5098 piece_bitpos
+= cur_bitsize
;
5099 piece_loc
= &XEXP (*piece_loc
, 1);
5103 /* TEMP->LAST here is either pointer to the last but one or
5104 last element in the chained list, LAST is pointer to the
5106 if (label
&& strcmp (last
->label
, label
) == 0)
5108 /* For SRA optimized variables if there weren't any real
5109 insns since last note, just modify the last node. */
5110 if (piece_loc
!= NULL
)
5112 adjust_piece_list (piece_loc
, NULL
, NULL
,
5113 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5116 /* If the last note doesn't cover any instructions, remove it. */
5117 if (temp
->last
!= last
)
5119 temp
->last
->next
= NULL
;
5122 gcc_assert (strcmp (last
->label
, label
) != 0);
5126 gcc_assert (temp
->first
== temp
->last
5127 || (temp
->first
->next
== temp
->last
5128 && TREE_CODE (decl
) == PARM_DECL
));
5129 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5130 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5134 if (bitsize
== -1 && NOTE_P (last
->loc
))
5135 last_loc_note
= last
->loc
;
5136 else if (piece_loc
!= NULL
5137 && *piece_loc
!= NULL_RTX
5138 && piece_bitpos
== bitpos
5139 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5140 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5142 last_loc_note
= NULL_RTX
;
5143 /* If the current location is the same as the end of the list,
5144 and either both or neither of the locations is uninitialized,
5145 we have nothing to do. */
5146 if (last_loc_note
== NULL_RTX
5147 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5148 NOTE_VAR_LOCATION_LOC (loc_note
)))
5149 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5150 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5151 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5152 == VAR_INIT_STATUS_UNINITIALIZED
)
5153 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5154 == VAR_INIT_STATUS_UNINITIALIZED
))))
5156 /* Add LOC to the end of list and update LAST. If the last
5157 element of the list has been removed above, reuse its
5158 memory for the new node, otherwise allocate a new one. */
5162 memset (loc
, '\0', sizeof (*loc
));
5165 loc
= ggc_alloc_cleared_var_loc_node ();
5166 if (bitsize
== -1 || piece_loc
== NULL
)
5167 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5169 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5170 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5172 /* Ensure TEMP->LAST will point either to the new last but one
5173 element of the chain, or to the last element in it. */
5174 if (last
!= temp
->last
)
5182 loc
= ggc_alloc_cleared_var_loc_node ();
5185 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5190 /* Keep track of the number of spaces used to indent the
5191 output of the debugging routines that print the structure of
5192 the DIE internal representation. */
5193 static int print_indent
;
5195 /* Indent the line the number of spaces given by print_indent. */
5198 print_spaces (FILE *outfile
)
5200 fprintf (outfile
, "%*s", print_indent
, "");
5203 /* Print a type signature in hex. */
5206 print_signature (FILE *outfile
, char *sig
)
5210 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5211 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5214 /* Print the information associated with a given DIE, and its children.
5215 This routine is a debugging aid only. */
5218 print_die (dw_die_ref die
, FILE *outfile
)
5224 print_spaces (outfile
);
5225 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5226 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5228 print_spaces (outfile
);
5229 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5230 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5231 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5233 if (die
->comdat_type_p
)
5235 print_spaces (outfile
);
5236 fprintf (outfile
, " signature: ");
5237 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5238 fprintf (outfile
, "\n");
5241 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5243 print_spaces (outfile
);
5244 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5246 switch (AT_class (a
))
5248 case dw_val_class_addr
:
5249 fprintf (outfile
, "address");
5251 case dw_val_class_offset
:
5252 fprintf (outfile
, "offset");
5254 case dw_val_class_loc
:
5255 fprintf (outfile
, "location descriptor");
5257 case dw_val_class_loc_list
:
5258 fprintf (outfile
, "location list -> label:%s",
5259 AT_loc_list (a
)->ll_symbol
);
5261 case dw_val_class_range_list
:
5262 fprintf (outfile
, "range list");
5264 case dw_val_class_const
:
5265 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5267 case dw_val_class_unsigned_const
:
5268 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5270 case dw_val_class_const_double
:
5271 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5272 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5273 a
->dw_attr_val
.v
.val_double
.high
,
5274 a
->dw_attr_val
.v
.val_double
.low
);
5276 case dw_val_class_vec
:
5277 fprintf (outfile
, "floating-point or vector constant");
5279 case dw_val_class_flag
:
5280 fprintf (outfile
, "%u", AT_flag (a
));
5282 case dw_val_class_die_ref
:
5283 if (AT_ref (a
) != NULL
)
5285 if (AT_ref (a
)->comdat_type_p
)
5287 fprintf (outfile
, "die -> signature: ");
5288 print_signature (outfile
,
5289 AT_ref (a
)->die_id
.die_type_node
->signature
);
5291 else if (AT_ref (a
)->die_id
.die_symbol
)
5292 fprintf (outfile
, "die -> label: %s",
5293 AT_ref (a
)->die_id
.die_symbol
);
5295 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5296 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5299 fprintf (outfile
, "die -> <null>");
5301 case dw_val_class_vms_delta
:
5302 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5303 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5305 case dw_val_class_lbl_id
:
5306 case dw_val_class_lineptr
:
5307 case dw_val_class_macptr
:
5308 case dw_val_class_high_pc
:
5309 fprintf (outfile
, "label: %s", AT_lbl (a
));
5311 case dw_val_class_str
:
5312 if (AT_string (a
) != NULL
)
5313 fprintf (outfile
, "\"%s\"", AT_string (a
));
5315 fprintf (outfile
, "<null>");
5317 case dw_val_class_file
:
5318 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5319 AT_file (a
)->emitted_number
);
5321 case dw_val_class_data8
:
5325 for (i
= 0; i
< 8; i
++)
5326 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5333 fprintf (outfile
, "\n");
5336 if (die
->die_child
!= NULL
)
5339 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5342 if (print_indent
== 0)
5343 fprintf (outfile
, "\n");
5346 /* Print the information collected for a given DIE. */
5349 debug_dwarf_die (dw_die_ref die
)
5351 print_die (die
, stderr
);
5354 /* Print all DWARF information collected for the compilation unit.
5355 This routine is a debugging aid only. */
5361 print_die (comp_unit_die (), stderr
);
5364 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5365 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5366 DIE that marks the start of the DIEs for this include file. */
5369 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5371 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5372 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5374 new_unit
->die_sib
= old_unit
;
5378 /* Close an include-file CU and reopen the enclosing one. */
5381 pop_compile_unit (dw_die_ref old_unit
)
5383 dw_die_ref new_unit
= old_unit
->die_sib
;
5385 old_unit
->die_sib
= NULL
;
5389 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5390 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5392 /* Calculate the checksum of a location expression. */
5395 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5399 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5401 CHECKSUM (loc
->dw_loc_oprnd1
);
5402 CHECKSUM (loc
->dw_loc_oprnd2
);
5405 /* Calculate the checksum of an attribute. */
5408 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5410 dw_loc_descr_ref loc
;
5413 CHECKSUM (at
->dw_attr
);
5415 /* We don't care that this was compiled with a different compiler
5416 snapshot; if the output is the same, that's what matters. */
5417 if (at
->dw_attr
== DW_AT_producer
)
5420 switch (AT_class (at
))
5422 case dw_val_class_const
:
5423 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5425 case dw_val_class_unsigned_const
:
5426 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5428 case dw_val_class_const_double
:
5429 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5431 case dw_val_class_vec
:
5432 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5434 case dw_val_class_flag
:
5435 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5437 case dw_val_class_str
:
5438 CHECKSUM_STRING (AT_string (at
));
5441 case dw_val_class_addr
:
5443 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5444 CHECKSUM_STRING (XSTR (r
, 0));
5447 case dw_val_class_offset
:
5448 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5451 case dw_val_class_loc
:
5452 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5453 loc_checksum (loc
, ctx
);
5456 case dw_val_class_die_ref
:
5457 die_checksum (AT_ref (at
), ctx
, mark
);
5460 case dw_val_class_fde_ref
:
5461 case dw_val_class_vms_delta
:
5462 case dw_val_class_lbl_id
:
5463 case dw_val_class_lineptr
:
5464 case dw_val_class_macptr
:
5465 case dw_val_class_high_pc
:
5468 case dw_val_class_file
:
5469 CHECKSUM_STRING (AT_file (at
)->filename
);
5472 case dw_val_class_data8
:
5473 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5481 /* Calculate the checksum of a DIE. */
5484 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5490 /* To avoid infinite recursion. */
5493 CHECKSUM (die
->die_mark
);
5496 die
->die_mark
= ++(*mark
);
5498 CHECKSUM (die
->die_tag
);
5500 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5501 attr_checksum (a
, ctx
, mark
);
5503 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5507 #undef CHECKSUM_STRING
5509 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5510 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5511 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5512 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5513 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5514 #define CHECKSUM_ATTR(FOO) \
5515 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5517 /* Calculate the checksum of a number in signed LEB128 format. */
5520 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5527 byte
= (value
& 0x7f);
5529 more
= !((value
== 0 && (byte
& 0x40) == 0)
5530 || (value
== -1 && (byte
& 0x40) != 0));
5539 /* Calculate the checksum of a number in unsigned LEB128 format. */
5542 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5546 unsigned char byte
= (value
& 0x7f);
5549 /* More bytes to follow. */
5557 /* Checksum the context of the DIE. This adds the names of any
5558 surrounding namespaces or structures to the checksum. */
5561 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5565 int tag
= die
->die_tag
;
5567 if (tag
!= DW_TAG_namespace
5568 && tag
!= DW_TAG_structure_type
5569 && tag
!= DW_TAG_class_type
)
5572 name
= get_AT_string (die
, DW_AT_name
);
5574 spec
= get_AT_ref (die
, DW_AT_specification
);
5578 if (die
->die_parent
!= NULL
)
5579 checksum_die_context (die
->die_parent
, ctx
);
5581 CHECKSUM_ULEB128 ('C');
5582 CHECKSUM_ULEB128 (tag
);
5584 CHECKSUM_STRING (name
);
5587 /* Calculate the checksum of a location expression. */
5590 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5592 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5593 were emitted as a DW_FORM_sdata instead of a location expression. */
5594 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5596 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5597 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5601 /* Otherwise, just checksum the raw location expression. */
5604 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5605 CHECKSUM (loc
->dw_loc_oprnd1
);
5606 CHECKSUM (loc
->dw_loc_oprnd2
);
5607 loc
= loc
->dw_loc_next
;
5611 /* Calculate the checksum of an attribute. */
5614 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5615 struct md5_ctx
*ctx
, int *mark
)
5617 dw_loc_descr_ref loc
;
5620 if (AT_class (at
) == dw_val_class_die_ref
)
5622 dw_die_ref target_die
= AT_ref (at
);
5624 /* For pointer and reference types, we checksum only the (qualified)
5625 name of the target type (if there is a name). For friend entries,
5626 we checksum only the (qualified) name of the target type or function.
5627 This allows the checksum to remain the same whether the target type
5628 is complete or not. */
5629 if ((at
->dw_attr
== DW_AT_type
5630 && (tag
== DW_TAG_pointer_type
5631 || tag
== DW_TAG_reference_type
5632 || tag
== DW_TAG_rvalue_reference_type
5633 || tag
== DW_TAG_ptr_to_member_type
))
5634 || (at
->dw_attr
== DW_AT_friend
5635 && tag
== DW_TAG_friend
))
5637 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5639 if (name_attr
!= NULL
)
5641 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5645 CHECKSUM_ULEB128 ('N');
5646 CHECKSUM_ULEB128 (at
->dw_attr
);
5647 if (decl
->die_parent
!= NULL
)
5648 checksum_die_context (decl
->die_parent
, ctx
);
5649 CHECKSUM_ULEB128 ('E');
5650 CHECKSUM_STRING (AT_string (name_attr
));
5655 /* For all other references to another DIE, we check to see if the
5656 target DIE has already been visited. If it has, we emit a
5657 backward reference; if not, we descend recursively. */
5658 if (target_die
->die_mark
> 0)
5660 CHECKSUM_ULEB128 ('R');
5661 CHECKSUM_ULEB128 (at
->dw_attr
);
5662 CHECKSUM_ULEB128 (target_die
->die_mark
);
5666 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5670 target_die
->die_mark
= ++(*mark
);
5671 CHECKSUM_ULEB128 ('T');
5672 CHECKSUM_ULEB128 (at
->dw_attr
);
5673 if (decl
->die_parent
!= NULL
)
5674 checksum_die_context (decl
->die_parent
, ctx
);
5675 die_checksum_ordered (target_die
, ctx
, mark
);
5680 CHECKSUM_ULEB128 ('A');
5681 CHECKSUM_ULEB128 (at
->dw_attr
);
5683 switch (AT_class (at
))
5685 case dw_val_class_const
:
5686 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5687 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5690 case dw_val_class_unsigned_const
:
5691 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5692 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5695 case dw_val_class_const_double
:
5696 CHECKSUM_ULEB128 (DW_FORM_block
);
5697 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5698 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5701 case dw_val_class_vec
:
5702 CHECKSUM_ULEB128 (DW_FORM_block
);
5703 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
5704 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5707 case dw_val_class_flag
:
5708 CHECKSUM_ULEB128 (DW_FORM_flag
);
5709 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5712 case dw_val_class_str
:
5713 CHECKSUM_ULEB128 (DW_FORM_string
);
5714 CHECKSUM_STRING (AT_string (at
));
5717 case dw_val_class_addr
:
5719 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5720 CHECKSUM_ULEB128 (DW_FORM_string
);
5721 CHECKSUM_STRING (XSTR (r
, 0));
5724 case dw_val_class_offset
:
5725 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5726 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5729 case dw_val_class_loc
:
5730 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5731 loc_checksum_ordered (loc
, ctx
);
5734 case dw_val_class_fde_ref
:
5735 case dw_val_class_lbl_id
:
5736 case dw_val_class_lineptr
:
5737 case dw_val_class_macptr
:
5738 case dw_val_class_high_pc
:
5741 case dw_val_class_file
:
5742 CHECKSUM_ULEB128 (DW_FORM_string
);
5743 CHECKSUM_STRING (AT_file (at
)->filename
);
5746 case dw_val_class_data8
:
5747 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5755 struct checksum_attributes
5757 dw_attr_ref at_name
;
5758 dw_attr_ref at_type
;
5759 dw_attr_ref at_friend
;
5760 dw_attr_ref at_accessibility
;
5761 dw_attr_ref at_address_class
;
5762 dw_attr_ref at_allocated
;
5763 dw_attr_ref at_artificial
;
5764 dw_attr_ref at_associated
;
5765 dw_attr_ref at_binary_scale
;
5766 dw_attr_ref at_bit_offset
;
5767 dw_attr_ref at_bit_size
;
5768 dw_attr_ref at_bit_stride
;
5769 dw_attr_ref at_byte_size
;
5770 dw_attr_ref at_byte_stride
;
5771 dw_attr_ref at_const_value
;
5772 dw_attr_ref at_containing_type
;
5773 dw_attr_ref at_count
;
5774 dw_attr_ref at_data_location
;
5775 dw_attr_ref at_data_member_location
;
5776 dw_attr_ref at_decimal_scale
;
5777 dw_attr_ref at_decimal_sign
;
5778 dw_attr_ref at_default_value
;
5779 dw_attr_ref at_digit_count
;
5780 dw_attr_ref at_discr
;
5781 dw_attr_ref at_discr_list
;
5782 dw_attr_ref at_discr_value
;
5783 dw_attr_ref at_encoding
;
5784 dw_attr_ref at_endianity
;
5785 dw_attr_ref at_explicit
;
5786 dw_attr_ref at_is_optional
;
5787 dw_attr_ref at_location
;
5788 dw_attr_ref at_lower_bound
;
5789 dw_attr_ref at_mutable
;
5790 dw_attr_ref at_ordering
;
5791 dw_attr_ref at_picture_string
;
5792 dw_attr_ref at_prototyped
;
5793 dw_attr_ref at_small
;
5794 dw_attr_ref at_segment
;
5795 dw_attr_ref at_string_length
;
5796 dw_attr_ref at_threads_scaled
;
5797 dw_attr_ref at_upper_bound
;
5798 dw_attr_ref at_use_location
;
5799 dw_attr_ref at_use_UTF8
;
5800 dw_attr_ref at_variable_parameter
;
5801 dw_attr_ref at_virtuality
;
5802 dw_attr_ref at_visibility
;
5803 dw_attr_ref at_vtable_elem_location
;
5806 /* Collect the attributes that we will want to use for the checksum. */
5809 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5814 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5825 attrs
->at_friend
= a
;
5827 case DW_AT_accessibility
:
5828 attrs
->at_accessibility
= a
;
5830 case DW_AT_address_class
:
5831 attrs
->at_address_class
= a
;
5833 case DW_AT_allocated
:
5834 attrs
->at_allocated
= a
;
5836 case DW_AT_artificial
:
5837 attrs
->at_artificial
= a
;
5839 case DW_AT_associated
:
5840 attrs
->at_associated
= a
;
5842 case DW_AT_binary_scale
:
5843 attrs
->at_binary_scale
= a
;
5845 case DW_AT_bit_offset
:
5846 attrs
->at_bit_offset
= a
;
5848 case DW_AT_bit_size
:
5849 attrs
->at_bit_size
= a
;
5851 case DW_AT_bit_stride
:
5852 attrs
->at_bit_stride
= a
;
5854 case DW_AT_byte_size
:
5855 attrs
->at_byte_size
= a
;
5857 case DW_AT_byte_stride
:
5858 attrs
->at_byte_stride
= a
;
5860 case DW_AT_const_value
:
5861 attrs
->at_const_value
= a
;
5863 case DW_AT_containing_type
:
5864 attrs
->at_containing_type
= a
;
5867 attrs
->at_count
= a
;
5869 case DW_AT_data_location
:
5870 attrs
->at_data_location
= a
;
5872 case DW_AT_data_member_location
:
5873 attrs
->at_data_member_location
= a
;
5875 case DW_AT_decimal_scale
:
5876 attrs
->at_decimal_scale
= a
;
5878 case DW_AT_decimal_sign
:
5879 attrs
->at_decimal_sign
= a
;
5881 case DW_AT_default_value
:
5882 attrs
->at_default_value
= a
;
5884 case DW_AT_digit_count
:
5885 attrs
->at_digit_count
= a
;
5888 attrs
->at_discr
= a
;
5890 case DW_AT_discr_list
:
5891 attrs
->at_discr_list
= a
;
5893 case DW_AT_discr_value
:
5894 attrs
->at_discr_value
= a
;
5896 case DW_AT_encoding
:
5897 attrs
->at_encoding
= a
;
5899 case DW_AT_endianity
:
5900 attrs
->at_endianity
= a
;
5902 case DW_AT_explicit
:
5903 attrs
->at_explicit
= a
;
5905 case DW_AT_is_optional
:
5906 attrs
->at_is_optional
= a
;
5908 case DW_AT_location
:
5909 attrs
->at_location
= a
;
5911 case DW_AT_lower_bound
:
5912 attrs
->at_lower_bound
= a
;
5915 attrs
->at_mutable
= a
;
5917 case DW_AT_ordering
:
5918 attrs
->at_ordering
= a
;
5920 case DW_AT_picture_string
:
5921 attrs
->at_picture_string
= a
;
5923 case DW_AT_prototyped
:
5924 attrs
->at_prototyped
= a
;
5927 attrs
->at_small
= a
;
5930 attrs
->at_segment
= a
;
5932 case DW_AT_string_length
:
5933 attrs
->at_string_length
= a
;
5935 case DW_AT_threads_scaled
:
5936 attrs
->at_threads_scaled
= a
;
5938 case DW_AT_upper_bound
:
5939 attrs
->at_upper_bound
= a
;
5941 case DW_AT_use_location
:
5942 attrs
->at_use_location
= a
;
5944 case DW_AT_use_UTF8
:
5945 attrs
->at_use_UTF8
= a
;
5947 case DW_AT_variable_parameter
:
5948 attrs
->at_variable_parameter
= a
;
5950 case DW_AT_virtuality
:
5951 attrs
->at_virtuality
= a
;
5953 case DW_AT_visibility
:
5954 attrs
->at_visibility
= a
;
5956 case DW_AT_vtable_elem_location
:
5957 attrs
->at_vtable_elem_location
= a
;
5965 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
5968 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5972 struct checksum_attributes attrs
;
5974 CHECKSUM_ULEB128 ('D');
5975 CHECKSUM_ULEB128 (die
->die_tag
);
5977 memset (&attrs
, 0, sizeof (attrs
));
5979 decl
= get_AT_ref (die
, DW_AT_specification
);
5981 collect_checksum_attributes (&attrs
, decl
);
5982 collect_checksum_attributes (&attrs
, die
);
5984 CHECKSUM_ATTR (attrs
.at_name
);
5985 CHECKSUM_ATTR (attrs
.at_accessibility
);
5986 CHECKSUM_ATTR (attrs
.at_address_class
);
5987 CHECKSUM_ATTR (attrs
.at_allocated
);
5988 CHECKSUM_ATTR (attrs
.at_artificial
);
5989 CHECKSUM_ATTR (attrs
.at_associated
);
5990 CHECKSUM_ATTR (attrs
.at_binary_scale
);
5991 CHECKSUM_ATTR (attrs
.at_bit_offset
);
5992 CHECKSUM_ATTR (attrs
.at_bit_size
);
5993 CHECKSUM_ATTR (attrs
.at_bit_stride
);
5994 CHECKSUM_ATTR (attrs
.at_byte_size
);
5995 CHECKSUM_ATTR (attrs
.at_byte_stride
);
5996 CHECKSUM_ATTR (attrs
.at_const_value
);
5997 CHECKSUM_ATTR (attrs
.at_containing_type
);
5998 CHECKSUM_ATTR (attrs
.at_count
);
5999 CHECKSUM_ATTR (attrs
.at_data_location
);
6000 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6001 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6002 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6003 CHECKSUM_ATTR (attrs
.at_default_value
);
6004 CHECKSUM_ATTR (attrs
.at_digit_count
);
6005 CHECKSUM_ATTR (attrs
.at_discr
);
6006 CHECKSUM_ATTR (attrs
.at_discr_list
);
6007 CHECKSUM_ATTR (attrs
.at_discr_value
);
6008 CHECKSUM_ATTR (attrs
.at_encoding
);
6009 CHECKSUM_ATTR (attrs
.at_endianity
);
6010 CHECKSUM_ATTR (attrs
.at_explicit
);
6011 CHECKSUM_ATTR (attrs
.at_is_optional
);
6012 CHECKSUM_ATTR (attrs
.at_location
);
6013 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6014 CHECKSUM_ATTR (attrs
.at_mutable
);
6015 CHECKSUM_ATTR (attrs
.at_ordering
);
6016 CHECKSUM_ATTR (attrs
.at_picture_string
);
6017 CHECKSUM_ATTR (attrs
.at_prototyped
);
6018 CHECKSUM_ATTR (attrs
.at_small
);
6019 CHECKSUM_ATTR (attrs
.at_segment
);
6020 CHECKSUM_ATTR (attrs
.at_string_length
);
6021 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6022 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6023 CHECKSUM_ATTR (attrs
.at_use_location
);
6024 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6025 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6026 CHECKSUM_ATTR (attrs
.at_virtuality
);
6027 CHECKSUM_ATTR (attrs
.at_visibility
);
6028 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6029 CHECKSUM_ATTR (attrs
.at_type
);
6030 CHECKSUM_ATTR (attrs
.at_friend
);
6032 /* Checksum the child DIEs, except for nested types and member functions. */
6035 dw_attr_ref name_attr
;
6038 name_attr
= get_AT (c
, DW_AT_name
);
6039 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
6040 && name_attr
!= NULL
)
6042 CHECKSUM_ULEB128 ('S');
6043 CHECKSUM_ULEB128 (c
->die_tag
);
6044 CHECKSUM_STRING (AT_string (name_attr
));
6048 /* Mark this DIE so it gets processed when unmarking. */
6049 if (c
->die_mark
== 0)
6051 die_checksum_ordered (c
, ctx
, mark
);
6053 } while (c
!= die
->die_child
);
6055 CHECKSUM_ULEB128 (0);
6059 #undef CHECKSUM_STRING
6060 #undef CHECKSUM_ATTR
6061 #undef CHECKSUM_LEB128
6062 #undef CHECKSUM_ULEB128
6064 /* Generate the type signature for DIE. This is computed by generating an
6065 MD5 checksum over the DIE's tag, its relevant attributes, and its
6066 children. Attributes that are references to other DIEs are processed
6067 by recursion, using the MARK field to prevent infinite recursion.
6068 If the DIE is nested inside a namespace or another type, we also
6069 need to include that context in the signature. The lower 64 bits
6070 of the resulting MD5 checksum comprise the signature. */
6073 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6077 unsigned char checksum
[16];
6082 name
= get_AT_string (die
, DW_AT_name
);
6083 decl
= get_AT_ref (die
, DW_AT_specification
);
6084 parent
= get_die_parent (die
);
6086 /* First, compute a signature for just the type name (and its surrounding
6087 context, if any. This is stored in the type unit DIE for link-time
6088 ODR (one-definition rule) checking. */
6090 if (is_cxx() && name
!= NULL
)
6092 md5_init_ctx (&ctx
);
6094 /* Checksum the names of surrounding namespaces and structures. */
6096 checksum_die_context (parent
, &ctx
);
6098 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
6099 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
6100 md5_finish_ctx (&ctx
, checksum
);
6102 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6105 /* Next, compute the complete type signature. */
6107 md5_init_ctx (&ctx
);
6109 die
->die_mark
= mark
;
6111 /* Checksum the names of surrounding namespaces and structures. */
6113 checksum_die_context (parent
, &ctx
);
6115 /* Checksum the DIE and its children. */
6116 die_checksum_ordered (die
, &ctx
, &mark
);
6117 unmark_all_dies (die
);
6118 md5_finish_ctx (&ctx
, checksum
);
6120 /* Store the signature in the type node and link the type DIE and the
6121 type node together. */
6122 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6123 DWARF_TYPE_SIGNATURE_SIZE
);
6124 die
->comdat_type_p
= true;
6125 die
->die_id
.die_type_node
= type_node
;
6126 type_node
->type_die
= die
;
6128 /* If the DIE is a specification, link its declaration to the type node
6132 decl
->comdat_type_p
= true;
6133 decl
->die_id
.die_type_node
= type_node
;
6137 /* Do the location expressions look same? */
6139 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6141 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6142 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6143 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6146 /* Do the values look the same? */
6148 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6150 dw_loc_descr_ref loc1
, loc2
;
6153 if (v1
->val_class
!= v2
->val_class
)
6156 switch (v1
->val_class
)
6158 case dw_val_class_const
:
6159 return v1
->v
.val_int
== v2
->v
.val_int
;
6160 case dw_val_class_unsigned_const
:
6161 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6162 case dw_val_class_const_double
:
6163 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6164 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6165 case dw_val_class_vec
:
6166 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6167 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6169 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6170 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6173 case dw_val_class_flag
:
6174 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6175 case dw_val_class_str
:
6176 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6178 case dw_val_class_addr
:
6179 r1
= v1
->v
.val_addr
;
6180 r2
= v2
->v
.val_addr
;
6181 if (GET_CODE (r1
) != GET_CODE (r2
))
6183 return !rtx_equal_p (r1
, r2
);
6185 case dw_val_class_offset
:
6186 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6188 case dw_val_class_loc
:
6189 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6191 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6192 if (!same_loc_p (loc1
, loc2
, mark
))
6194 return !loc1
&& !loc2
;
6196 case dw_val_class_die_ref
:
6197 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6199 case dw_val_class_fde_ref
:
6200 case dw_val_class_vms_delta
:
6201 case dw_val_class_lbl_id
:
6202 case dw_val_class_lineptr
:
6203 case dw_val_class_macptr
:
6204 case dw_val_class_high_pc
:
6207 case dw_val_class_file
:
6208 return v1
->v
.val_file
== v2
->v
.val_file
;
6210 case dw_val_class_data8
:
6211 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6218 /* Do the attributes look the same? */
6221 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6223 if (at1
->dw_attr
!= at2
->dw_attr
)
6226 /* We don't care that this was compiled with a different compiler
6227 snapshot; if the output is the same, that's what matters. */
6228 if (at1
->dw_attr
== DW_AT_producer
)
6231 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6234 /* Do the dies look the same? */
6237 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6243 /* To avoid infinite recursion. */
6245 return die1
->die_mark
== die2
->die_mark
;
6246 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6248 if (die1
->die_tag
!= die2
->die_tag
)
6251 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6254 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6255 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6258 c1
= die1
->die_child
;
6259 c2
= die2
->die_child
;
6268 if (!same_die_p (c1
, c2
, mark
))
6272 if (c1
== die1
->die_child
)
6274 if (c2
== die2
->die_child
)
6284 /* Do the dies look the same? Wrapper around same_die_p. */
6287 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6290 int ret
= same_die_p (die1
, die2
, &mark
);
6292 unmark_all_dies (die1
);
6293 unmark_all_dies (die2
);
6298 /* The prefix to attach to symbols on DIEs in the current comdat debug
6300 static const char *comdat_symbol_id
;
6302 /* The index of the current symbol within the current comdat CU. */
6303 static unsigned int comdat_symbol_number
;
6305 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6306 children, and set comdat_symbol_id accordingly. */
6309 compute_section_prefix (dw_die_ref unit_die
)
6311 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6312 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6313 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6316 unsigned char checksum
[16];
6319 /* Compute the checksum of the DIE, then append part of it as hex digits to
6320 the name filename of the unit. */
6322 md5_init_ctx (&ctx
);
6324 die_checksum (unit_die
, &ctx
, &mark
);
6325 unmark_all_dies (unit_die
);
6326 md5_finish_ctx (&ctx
, checksum
);
6328 sprintf (name
, "%s.", base
);
6329 clean_symbol_name (name
);
6331 p
= name
+ strlen (name
);
6332 for (i
= 0; i
< 4; i
++)
6334 sprintf (p
, "%.2x", checksum
[i
]);
6338 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6339 comdat_symbol_number
= 0;
6342 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6345 is_type_die (dw_die_ref die
)
6347 switch (die
->die_tag
)
6349 case DW_TAG_array_type
:
6350 case DW_TAG_class_type
:
6351 case DW_TAG_interface_type
:
6352 case DW_TAG_enumeration_type
:
6353 case DW_TAG_pointer_type
:
6354 case DW_TAG_reference_type
:
6355 case DW_TAG_rvalue_reference_type
:
6356 case DW_TAG_string_type
:
6357 case DW_TAG_structure_type
:
6358 case DW_TAG_subroutine_type
:
6359 case DW_TAG_union_type
:
6360 case DW_TAG_ptr_to_member_type
:
6361 case DW_TAG_set_type
:
6362 case DW_TAG_subrange_type
:
6363 case DW_TAG_base_type
:
6364 case DW_TAG_const_type
:
6365 case DW_TAG_file_type
:
6366 case DW_TAG_packed_type
:
6367 case DW_TAG_volatile_type
:
6368 case DW_TAG_typedef
:
6375 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6376 Basically, we want to choose the bits that are likely to be shared between
6377 compilations (types) and leave out the bits that are specific to individual
6378 compilations (functions). */
6381 is_comdat_die (dw_die_ref c
)
6383 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6384 we do for stabs. The advantage is a greater likelihood of sharing between
6385 objects that don't include headers in the same order (and therefore would
6386 put the base types in a different comdat). jason 8/28/00 */
6388 if (c
->die_tag
== DW_TAG_base_type
)
6391 if (c
->die_tag
== DW_TAG_pointer_type
6392 || c
->die_tag
== DW_TAG_reference_type
6393 || c
->die_tag
== DW_TAG_rvalue_reference_type
6394 || c
->die_tag
== DW_TAG_const_type
6395 || c
->die_tag
== DW_TAG_volatile_type
)
6397 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6399 return t
? is_comdat_die (t
) : 0;
6402 return is_type_die (c
);
6405 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6406 compilation unit. */
6409 is_symbol_die (dw_die_ref c
)
6411 return (is_type_die (c
)
6412 || is_declaration_die (c
)
6413 || c
->die_tag
== DW_TAG_namespace
6414 || c
->die_tag
== DW_TAG_module
);
6417 /* Returns true iff C is a compile-unit DIE. */
6420 is_cu_die (dw_die_ref c
)
6422 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6425 /* Returns true iff C is a unit DIE of some sort. */
6428 is_unit_die (dw_die_ref c
)
6430 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6431 || c
->die_tag
== DW_TAG_partial_unit
6432 || c
->die_tag
== DW_TAG_type_unit
);
6435 /* Returns true iff C is a namespace DIE. */
6438 is_namespace_die (dw_die_ref c
)
6440 return c
&& c
->die_tag
== DW_TAG_namespace
;
6443 /* Returns true iff C is a class or structure DIE. */
6446 is_class_die (dw_die_ref c
)
6448 return c
&& (c
->die_tag
== DW_TAG_class_type
6449 || c
->die_tag
== DW_TAG_structure_type
);
6453 gen_internal_sym (const char *prefix
)
6457 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6458 return xstrdup (buf
);
6461 /* Assign symbols to all worthy DIEs under DIE. */
6464 assign_symbol_names (dw_die_ref die
)
6468 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6470 if (comdat_symbol_id
)
6472 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6474 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6475 comdat_symbol_id
, comdat_symbol_number
++);
6476 die
->die_id
.die_symbol
= xstrdup (p
);
6479 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6482 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6485 struct cu_hash_table_entry
6488 unsigned min_comdat_num
, max_comdat_num
;
6489 struct cu_hash_table_entry
*next
;
6492 /* Routines to manipulate hash table of CUs. */
6494 htab_cu_hash (const void *of
)
6496 const struct cu_hash_table_entry
*const entry
=
6497 (const struct cu_hash_table_entry
*) of
;
6499 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6503 htab_cu_eq (const void *of1
, const void *of2
)
6505 const struct cu_hash_table_entry
*const entry1
=
6506 (const struct cu_hash_table_entry
*) of1
;
6507 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6509 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6513 htab_cu_del (void *what
)
6515 struct cu_hash_table_entry
*next
,
6516 *entry
= (struct cu_hash_table_entry
*) what
;
6526 /* Check whether we have already seen this CU and set up SYM_NUM
6529 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6531 struct cu_hash_table_entry dummy
;
6532 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6534 dummy
.max_comdat_num
= 0;
6536 slot
= (struct cu_hash_table_entry
**)
6537 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6541 for (; entry
; last
= entry
, entry
= entry
->next
)
6543 if (same_die_p_wrap (cu
, entry
->cu
))
6549 *sym_num
= entry
->min_comdat_num
;
6553 entry
= XCNEW (struct cu_hash_table_entry
);
6555 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6556 entry
->next
= *slot
;
6562 /* Record SYM_NUM to record of CU in HTABLE. */
6564 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6566 struct cu_hash_table_entry
**slot
, *entry
;
6568 slot
= (struct cu_hash_table_entry
**)
6569 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6573 entry
->max_comdat_num
= sym_num
;
6576 /* Traverse the DIE (which is always comp_unit_die), and set up
6577 additional compilation units for each of the include files we see
6578 bracketed by BINCL/EINCL. */
6581 break_out_includes (dw_die_ref die
)
6584 dw_die_ref unit
= NULL
;
6585 limbo_die_node
*node
, **pnode
;
6586 htab_t cu_hash_table
;
6590 dw_die_ref prev
= c
;
6592 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6593 || (unit
&& is_comdat_die (c
)))
6595 dw_die_ref next
= c
->die_sib
;
6597 /* This DIE is for a secondary CU; remove it from the main one. */
6598 remove_child_with_prev (c
, prev
);
6600 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6601 unit
= push_new_compile_unit (unit
, c
);
6602 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6603 unit
= pop_compile_unit (unit
);
6605 add_child_die (unit
, c
);
6607 if (c
== die
->die_child
)
6610 } while (c
!= die
->die_child
);
6613 /* We can only use this in debugging, since the frontend doesn't check
6614 to make sure that we leave every include file we enter. */
6618 assign_symbol_names (die
);
6619 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6620 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6626 compute_section_prefix (node
->die
);
6627 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6628 &comdat_symbol_number
);
6629 assign_symbol_names (node
->die
);
6631 *pnode
= node
->next
;
6634 pnode
= &node
->next
;
6635 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6636 comdat_symbol_number
);
6639 htab_delete (cu_hash_table
);
6642 /* Return non-zero if this DIE is a declaration. */
6645 is_declaration_die (dw_die_ref die
)
6650 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6651 if (a
->dw_attr
== DW_AT_declaration
)
6657 /* Return non-zero if this DIE is nested inside a subprogram. */
6660 is_nested_in_subprogram (dw_die_ref die
)
6662 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6666 return local_scope_p (decl
);
6669 /* Return non-zero if this DIE contains a defining declaration of a
6673 contains_subprogram_definition (dw_die_ref die
)
6677 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6679 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6683 /* Return non-zero if this is a type DIE that should be moved to a
6684 COMDAT .debug_types section. */
6687 should_move_die_to_comdat (dw_die_ref die
)
6689 switch (die
->die_tag
)
6691 case DW_TAG_class_type
:
6692 case DW_TAG_structure_type
:
6693 case DW_TAG_enumeration_type
:
6694 case DW_TAG_union_type
:
6695 /* Don't move declarations, inlined instances, or types nested in a
6697 if (is_declaration_die (die
)
6698 || get_AT (die
, DW_AT_abstract_origin
)
6699 || is_nested_in_subprogram (die
))
6701 /* A type definition should never contain a subprogram definition. */
6702 gcc_assert (!contains_subprogram_definition (die
));
6704 case DW_TAG_array_type
:
6705 case DW_TAG_interface_type
:
6706 case DW_TAG_pointer_type
:
6707 case DW_TAG_reference_type
:
6708 case DW_TAG_rvalue_reference_type
:
6709 case DW_TAG_string_type
:
6710 case DW_TAG_subroutine_type
:
6711 case DW_TAG_ptr_to_member_type
:
6712 case DW_TAG_set_type
:
6713 case DW_TAG_subrange_type
:
6714 case DW_TAG_base_type
:
6715 case DW_TAG_const_type
:
6716 case DW_TAG_file_type
:
6717 case DW_TAG_packed_type
:
6718 case DW_TAG_volatile_type
:
6719 case DW_TAG_typedef
:
6725 /* Make a clone of DIE. */
6728 clone_die (dw_die_ref die
)
6734 clone
= ggc_alloc_cleared_die_node ();
6735 clone
->die_tag
= die
->die_tag
;
6737 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6738 add_dwarf_attr (clone
, a
);
6743 /* Make a clone of the tree rooted at DIE. */
6746 clone_tree (dw_die_ref die
)
6749 dw_die_ref clone
= clone_die (die
);
6751 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
6756 /* Make a clone of DIE as a declaration. */
6759 clone_as_declaration (dw_die_ref die
)
6766 /* If the DIE is already a declaration, just clone it. */
6767 if (is_declaration_die (die
))
6768 return clone_die (die
);
6770 /* If the DIE is a specification, just clone its declaration DIE. */
6771 decl
= get_AT_ref (die
, DW_AT_specification
);
6774 clone
= clone_die (decl
);
6775 if (die
->comdat_type_p
)
6776 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6780 clone
= ggc_alloc_cleared_die_node ();
6781 clone
->die_tag
= die
->die_tag
;
6783 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6785 /* We don't want to copy over all attributes.
6786 For example we don't want DW_AT_byte_size because otherwise we will no
6787 longer have a declaration and GDB will treat it as a definition. */
6791 case DW_AT_artificial
:
6792 case DW_AT_containing_type
:
6793 case DW_AT_external
:
6796 case DW_AT_virtuality
:
6797 case DW_AT_linkage_name
:
6798 case DW_AT_MIPS_linkage_name
:
6799 add_dwarf_attr (clone
, a
);
6801 case DW_AT_byte_size
:
6807 if (die
->comdat_type_p
)
6808 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6810 add_AT_flag (clone
, DW_AT_declaration
, 1);
6814 /* Copy the declaration context to the new type unit DIE. This includes
6815 any surrounding namespace or type declarations. If the DIE has an
6816 AT_specification attribute, it also includes attributes and children
6817 attached to the specification, and returns a pointer to the original
6818 parent of the declaration DIE. Returns NULL otherwise. */
6821 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
6824 dw_die_ref new_decl
;
6825 dw_die_ref orig_parent
= NULL
;
6827 decl
= get_AT_ref (die
, DW_AT_specification
);
6836 /* The original DIE will be changed to a declaration, and must
6837 be moved to be a child of the original declaration DIE. */
6838 orig_parent
= decl
->die_parent
;
6840 /* Copy the type node pointer from the new DIE to the original
6841 declaration DIE so we can forward references later. */
6842 decl
->comdat_type_p
= true;
6843 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
6845 remove_AT (die
, DW_AT_specification
);
6847 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
6849 if (a
->dw_attr
!= DW_AT_name
6850 && a
->dw_attr
!= DW_AT_declaration
6851 && a
->dw_attr
!= DW_AT_external
)
6852 add_dwarf_attr (die
, a
);
6855 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
6858 if (decl
->die_parent
!= NULL
6859 && !is_unit_die (decl
->die_parent
))
6861 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
6862 if (new_decl
!= NULL
)
6864 remove_AT (new_decl
, DW_AT_signature
);
6865 add_AT_specification (die
, new_decl
);
6872 /* Generate the skeleton ancestor tree for the given NODE, then clone
6873 the DIE and add the clone into the tree. */
6876 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
6878 if (node
->new_die
!= NULL
)
6881 node
->new_die
= clone_as_declaration (node
->old_die
);
6883 if (node
->parent
!= NULL
)
6885 generate_skeleton_ancestor_tree (node
->parent
);
6886 add_child_die (node
->parent
->new_die
, node
->new_die
);
6890 /* Generate a skeleton tree of DIEs containing any declarations that are
6891 found in the original tree. We traverse the tree looking for declaration
6892 DIEs, and construct the skeleton from the bottom up whenever we find one. */
6895 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
6897 skeleton_chain_node node
;
6900 dw_die_ref prev
= NULL
;
6901 dw_die_ref next
= NULL
;
6903 node
.parent
= parent
;
6905 first
= c
= parent
->old_die
->die_child
;
6909 if (prev
== NULL
|| prev
->die_sib
== c
)
6912 next
= (c
== first
? NULL
: c
->die_sib
);
6914 node
.new_die
= NULL
;
6915 if (is_declaration_die (c
))
6917 /* Clone the existing DIE, move the original to the skeleton
6918 tree (which is in the main CU), and put the clone, with
6919 all the original's children, where the original came from. */
6920 dw_die_ref clone
= clone_die (c
);
6921 move_all_children (c
, clone
);
6923 replace_child (c
, clone
, prev
);
6924 generate_skeleton_ancestor_tree (parent
);
6925 add_child_die (parent
->new_die
, c
);
6929 generate_skeleton_bottom_up (&node
);
6930 } while (next
!= NULL
);
6933 /* Wrapper function for generate_skeleton_bottom_up. */
6936 generate_skeleton (dw_die_ref die
)
6938 skeleton_chain_node node
;
6941 node
.new_die
= NULL
;
6944 /* If this type definition is nested inside another type,
6945 always leave at least a declaration in its place. */
6946 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
6947 node
.new_die
= clone_as_declaration (die
);
6949 generate_skeleton_bottom_up (&node
);
6950 return node
.new_die
;
6953 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
6954 declaration. The original DIE is moved to a new compile unit so that
6955 existing references to it follow it to the new location. If any of the
6956 original DIE's descendants is a declaration, we need to replace the
6957 original DIE with a skeleton tree and move the declarations back into the
6961 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
6964 dw_die_ref skeleton
, orig_parent
;
6966 /* Copy the declaration context to the type unit DIE. If the returned
6967 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
6969 orig_parent
= copy_declaration_context (unit
, child
);
6971 skeleton
= generate_skeleton (child
);
6972 if (skeleton
== NULL
)
6973 remove_child_with_prev (child
, prev
);
6976 skeleton
->comdat_type_p
= true;
6977 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
6979 /* If the original DIE was a specification, we need to put
6980 the skeleton under the parent DIE of the declaration.
6981 This leaves the original declaration in the tree, but
6982 it will be pruned later since there are no longer any
6983 references to it. */
6984 if (orig_parent
!= NULL
)
6986 remove_child_with_prev (child
, prev
);
6987 add_child_die (orig_parent
, skeleton
);
6990 replace_child (child
, skeleton
, prev
);
6996 /* Traverse the DIE and set up additional .debug_types sections for each
6997 type worthy of being placed in a COMDAT section. */
7000 break_out_comdat_types (dw_die_ref die
)
7004 dw_die_ref prev
= NULL
;
7005 dw_die_ref next
= NULL
;
7006 dw_die_ref unit
= NULL
;
7008 first
= c
= die
->die_child
;
7012 if (prev
== NULL
|| prev
->die_sib
== c
)
7015 next
= (c
== first
? NULL
: c
->die_sib
);
7016 if (should_move_die_to_comdat (c
))
7018 dw_die_ref replacement
;
7019 comdat_type_node_ref type_node
;
7021 /* Create a new type unit DIE as the root for the new tree, and
7022 add it to the list of comdat types. */
7023 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7024 add_AT_unsigned (unit
, DW_AT_language
,
7025 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7026 type_node
= ggc_alloc_cleared_comdat_type_node ();
7027 type_node
->root_die
= unit
;
7028 type_node
->next
= comdat_type_list
;
7029 comdat_type_list
= type_node
;
7031 /* Generate the type signature. */
7032 generate_type_signature (c
, type_node
);
7034 /* Copy the declaration context, attributes, and children of the
7035 declaration into the new type unit DIE, then remove this DIE
7036 from the main CU (or replace it with a skeleton if necessary). */
7037 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7038 type_node
->skeleton_die
= replacement
;
7040 /* Break out nested types into their own type units. */
7041 break_out_comdat_types (c
);
7043 /* Add the DIE to the new compunit. */
7044 add_child_die (unit
, c
);
7046 if (replacement
!= NULL
)
7049 else if (c
->die_tag
== DW_TAG_namespace
7050 || c
->die_tag
== DW_TAG_class_type
7051 || c
->die_tag
== DW_TAG_structure_type
7052 || c
->die_tag
== DW_TAG_union_type
)
7054 /* Look for nested types that can be broken out. */
7055 break_out_comdat_types (c
);
7057 } while (next
!= NULL
);
7060 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7062 struct decl_table_entry
7068 /* Routines to manipulate hash table of copied declarations. */
7071 htab_decl_hash (const void *of
)
7073 const struct decl_table_entry
*const entry
=
7074 (const struct decl_table_entry
*) of
;
7076 return htab_hash_pointer (entry
->orig
);
7080 htab_decl_eq (const void *of1
, const void *of2
)
7082 const struct decl_table_entry
*const entry1
=
7083 (const struct decl_table_entry
*) of1
;
7084 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
7086 return entry1
->orig
== entry2
;
7090 htab_decl_del (void *what
)
7092 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
7097 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7098 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7099 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7100 to check if the ancestor has already been copied into UNIT. */
7103 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7105 dw_die_ref parent
= die
->die_parent
;
7106 dw_die_ref new_parent
= unit
;
7109 struct decl_table_entry
*entry
= NULL
;
7113 /* Check if the entry has already been copied to UNIT. */
7114 slot
= htab_find_slot_with_hash (decl_table
, die
,
7115 htab_hash_pointer (die
), INSERT
);
7116 if (*slot
!= HTAB_EMPTY_ENTRY
)
7118 entry
= (struct decl_table_entry
*) *slot
;
7122 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7123 entry
= XCNEW (struct decl_table_entry
);
7131 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7134 if (!is_unit_die (parent
))
7135 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7138 copy
= clone_as_declaration (die
);
7139 add_child_die (new_parent
, copy
);
7141 if (decl_table
!= NULL
)
7143 /* Record the pointer to the copy. */
7150 /* Like clone_tree, but additionally enter all the children into
7151 the hash table decl_table. */
7154 clone_tree_hash (dw_die_ref die
, htab_t decl_table
)
7157 dw_die_ref clone
= clone_die (die
);
7158 struct decl_table_entry
*entry
;
7159 void **slot
= htab_find_slot_with_hash (decl_table
, die
,
7160 htab_hash_pointer (die
), INSERT
);
7161 /* Assert that DIE isn't in the hash table yet. If it would be there
7162 before, the ancestors would be necessarily there as well, therefore
7163 clone_tree_hash wouldn't be called. */
7164 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7165 entry
= XCNEW (struct decl_table_entry
);
7167 entry
->copy
= clone
;
7170 FOR_EACH_CHILD (die
, c
,
7171 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7176 /* Walk the DIE and its children, looking for references to incomplete
7177 or trivial types that are unmarked (i.e., that are not in the current
7181 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7187 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7189 if (AT_class (a
) == dw_val_class_die_ref
)
7191 dw_die_ref targ
= AT_ref (a
);
7193 struct decl_table_entry
*entry
;
7195 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7198 slot
= htab_find_slot_with_hash (decl_table
, targ
,
7199 htab_hash_pointer (targ
), INSERT
);
7201 if (*slot
!= HTAB_EMPTY_ENTRY
)
7203 /* TARG has already been copied, so we just need to
7204 modify the reference to point to the copy. */
7205 entry
= (struct decl_table_entry
*) *slot
;
7206 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7210 dw_die_ref parent
= unit
;
7211 dw_die_ref copy
= clone_die (targ
);
7213 /* Record in DECL_TABLE that TARG has been copied.
7214 Need to do this now, before the recursive call,
7215 because DECL_TABLE may be expanded and SLOT
7216 would no longer be a valid pointer. */
7217 entry
= XCNEW (struct decl_table_entry
);
7222 FOR_EACH_CHILD (targ
, c
,
7223 add_child_die (copy
,
7224 clone_tree_hash (c
, decl_table
)));
7226 /* Make sure the cloned tree is marked as part of the
7230 /* If TARG has surrounding context, copy its ancestor tree
7231 into the new type unit. */
7232 if (targ
->die_parent
!= NULL
7233 && !is_unit_die (targ
->die_parent
))
7234 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7237 add_child_die (parent
, copy
);
7238 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7240 /* Make sure the newly-copied DIE is walked. If it was
7241 installed in a previously-added context, it won't
7242 get visited otherwise. */
7245 /* Find the highest point of the newly-added tree,
7246 mark each node along the way, and walk from there. */
7247 parent
->die_mark
= 1;
7248 while (parent
->die_parent
7249 && parent
->die_parent
->die_mark
== 0)
7251 parent
= parent
->die_parent
;
7252 parent
->die_mark
= 1;
7254 copy_decls_walk (unit
, parent
, decl_table
);
7260 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7263 /* Copy declarations for "unworthy" types into the new comdat section.
7264 Incomplete types, modified types, and certain other types aren't broken
7265 out into comdat sections of their own, so they don't have a signature,
7266 and we need to copy the declaration into the same section so that we
7267 don't have an external reference. */
7270 copy_decls_for_unworthy_types (dw_die_ref unit
)
7275 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
7276 copy_decls_walk (unit
, unit
, decl_table
);
7277 htab_delete (decl_table
);
7281 /* Traverse the DIE and add a sibling attribute if it may have the
7282 effect of speeding up access to siblings. To save some space,
7283 avoid generating sibling attributes for DIE's without children. */
7286 add_sibling_attributes (dw_die_ref die
)
7290 if (! die
->die_child
)
7293 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7294 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7296 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7299 /* Output all location lists for the DIE and its children. */
7302 output_location_lists (dw_die_ref die
)
7308 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7309 if (AT_class (a
) == dw_val_class_loc_list
)
7310 output_loc_list (AT_loc_list (a
));
7312 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7315 /* We want to limit the number of external references, because they are
7316 larger than local references: a relocation takes multiple words, and
7317 even a sig8 reference is always eight bytes, whereas a local reference
7318 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7319 So if we encounter multiple external references to the same type DIE, we
7320 make a local typedef stub for it and redirect all references there.
7322 This is the element of the hash table for keeping track of these
7332 /* Hash an external_ref. */
7335 hash_external_ref (const void *p
)
7337 const struct external_ref
*r
= (const struct external_ref
*)p
;
7338 return htab_hash_pointer (r
->type
);
7341 /* Compare external_refs. */
7344 external_ref_eq (const void *p1
, const void *p2
)
7346 const struct external_ref
*r1
= (const struct external_ref
*)p1
;
7347 const struct external_ref
*r2
= (const struct external_ref
*)p2
;
7348 return r1
->type
== r2
->type
;
7351 /* Return a pointer to the external_ref for references to DIE. */
7353 static struct external_ref
*
7354 lookup_external_ref (htab_t map
, dw_die_ref die
)
7356 struct external_ref ref
, *ref_p
;
7360 slot
= htab_find_slot (map
, &ref
, INSERT
);
7361 if (*slot
!= HTAB_EMPTY_ENTRY
)
7362 return (struct external_ref
*) *slot
;
7364 ref_p
= XCNEW (struct external_ref
);
7370 /* Subroutine of optimize_external_refs, below.
7372 If we see a type skeleton, record it as our stub. If we see external
7373 references, remember how many we've seen. */
7376 optimize_external_refs_1 (dw_die_ref die
, htab_t map
)
7381 struct external_ref
*ref_p
;
7383 if (is_type_die (die
)
7384 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7386 /* This is a local skeleton; use it for local references. */
7387 ref_p
= lookup_external_ref (map
, c
);
7391 /* Scan the DIE references, and remember any that refer to DIEs from
7392 other CUs (i.e. those which are not marked). */
7393 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7394 if (AT_class (a
) == dw_val_class_die_ref
7395 && (c
= AT_ref (a
))->die_mark
== 0
7398 ref_p
= lookup_external_ref (map
, c
);
7402 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7405 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7406 points to an external_ref, DATA is the CU we're processing. If we don't
7407 already have a local stub, and we have multiple refs, build a stub. */
7410 build_local_stub (void **slot
, void *data
)
7412 struct external_ref
*ref_p
= (struct external_ref
*)*slot
;
7414 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7416 /* We have multiple references to this type, so build a small stub.
7417 Both of these forms are a bit dodgy from the perspective of the
7418 DWARF standard, since technically they should have names. */
7419 dw_die_ref cu
= (dw_die_ref
) data
;
7420 dw_die_ref type
= ref_p
->type
;
7421 dw_die_ref stub
= NULL
;
7423 if (type
->comdat_type_p
)
7425 /* If we refer to this type via sig8, use AT_signature. */
7426 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7427 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7431 /* Otherwise, use a typedef with no name. */
7432 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7433 add_AT_die_ref (stub
, DW_AT_type
, type
);
7442 /* DIE is a unit; look through all the DIE references to see if there are
7443 any external references to types, and if so, create local stubs for
7444 them which will be applied in build_abbrev_table. This is useful because
7445 references to local DIEs are smaller. */
7448 optimize_external_refs (dw_die_ref die
)
7450 htab_t map
= htab_create (10, hash_external_ref
, external_ref_eq
, free
);
7451 optimize_external_refs_1 (die
, map
);
7452 htab_traverse (map
, build_local_stub
, die
);
7456 /* The format of each DIE (and its attribute value pairs) is encoded in an
7457 abbreviation table. This routine builds the abbreviation table and assigns
7458 a unique abbreviation id for each abbreviation entry. The children of each
7459 die are visited recursively. */
7462 build_abbrev_table (dw_die_ref die
, htab_t extern_map
)
7464 unsigned long abbrev_id
;
7465 unsigned int n_alloc
;
7470 /* Scan the DIE references, and replace any that refer to
7471 DIEs from other CUs (i.e. those which are not marked) with
7472 the local stubs we built in optimize_external_refs. */
7473 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7474 if (AT_class (a
) == dw_val_class_die_ref
7475 && (c
= AT_ref (a
))->die_mark
== 0)
7477 struct external_ref
*ref_p
;
7478 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7480 ref_p
= lookup_external_ref (extern_map
, c
);
7481 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7482 change_AT_die_ref (a
, ref_p
->stub
);
7484 /* We aren't changing this reference, so mark it external. */
7485 set_AT_ref_external (a
, 1);
7488 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7490 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7491 dw_attr_ref die_a
, abbrev_a
;
7495 if (abbrev
->die_tag
!= die
->die_tag
)
7497 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7500 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7503 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7505 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7506 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7507 || (value_format (abbrev_a
) != value_format (die_a
)))
7517 if (abbrev_id
>= abbrev_die_table_in_use
)
7519 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7521 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7522 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7525 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7526 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7527 abbrev_die_table_allocated
= n_alloc
;
7530 ++abbrev_die_table_in_use
;
7531 abbrev_die_table
[abbrev_id
] = die
;
7534 die
->die_abbrev
= abbrev_id
;
7535 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7538 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7541 constant_size (unsigned HOST_WIDE_INT value
)
7548 log
= floor_log2 (value
);
7551 log
= 1 << (floor_log2 (log
) + 1);
7556 /* Return the size of a DIE as it is represented in the
7557 .debug_info section. */
7559 static unsigned long
7560 size_of_die (dw_die_ref die
)
7562 unsigned long size
= 0;
7565 enum dwarf_form form
;
7567 size
+= size_of_uleb128 (die
->die_abbrev
);
7568 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7570 switch (AT_class (a
))
7572 case dw_val_class_addr
:
7573 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7575 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7576 size
+= size_of_uleb128 (AT_index (a
));
7579 size
+= DWARF2_ADDR_SIZE
;
7581 case dw_val_class_offset
:
7582 size
+= DWARF_OFFSET_SIZE
;
7584 case dw_val_class_loc
:
7586 unsigned long lsize
= size_of_locs (AT_loc (a
));
7589 if (dwarf_version
>= 4)
7590 size
+= size_of_uleb128 (lsize
);
7592 size
+= constant_size (lsize
);
7596 case dw_val_class_loc_list
:
7597 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7599 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7600 size
+= size_of_uleb128 (AT_index (a
));
7603 size
+= DWARF_OFFSET_SIZE
;
7605 case dw_val_class_range_list
:
7606 size
+= DWARF_OFFSET_SIZE
;
7608 case dw_val_class_const
:
7609 size
+= size_of_sleb128 (AT_int (a
));
7611 case dw_val_class_unsigned_const
:
7613 int csize
= constant_size (AT_unsigned (a
));
7614 if (dwarf_version
== 3
7615 && a
->dw_attr
== DW_AT_data_member_location
7617 size
+= size_of_uleb128 (AT_unsigned (a
));
7622 case dw_val_class_const_double
:
7623 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7624 if (HOST_BITS_PER_WIDE_INT
>= 64)
7627 case dw_val_class_vec
:
7628 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7629 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7630 + a
->dw_attr_val
.v
.val_vec
.length
7631 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7633 case dw_val_class_flag
:
7634 if (dwarf_version
>= 4)
7635 /* Currently all add_AT_flag calls pass in 1 as last argument,
7636 so DW_FORM_flag_present can be used. If that ever changes,
7637 we'll need to use DW_FORM_flag and have some optimization
7638 in build_abbrev_table that will change those to
7639 DW_FORM_flag_present if it is set to 1 in all DIEs using
7640 the same abbrev entry. */
7641 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7645 case dw_val_class_die_ref
:
7646 if (AT_ref_external (a
))
7648 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7649 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7650 is sized by target address length, whereas in DWARF3
7651 it's always sized as an offset. */
7652 if (use_debug_types
)
7653 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7654 else if (dwarf_version
== 2)
7655 size
+= DWARF2_ADDR_SIZE
;
7657 size
+= DWARF_OFFSET_SIZE
;
7660 size
+= DWARF_OFFSET_SIZE
;
7662 case dw_val_class_fde_ref
:
7663 size
+= DWARF_OFFSET_SIZE
;
7665 case dw_val_class_lbl_id
:
7666 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7668 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7669 size
+= size_of_uleb128 (AT_index (a
));
7672 size
+= DWARF2_ADDR_SIZE
;
7674 case dw_val_class_lineptr
:
7675 case dw_val_class_macptr
:
7676 size
+= DWARF_OFFSET_SIZE
;
7678 case dw_val_class_str
:
7679 form
= AT_string_form (a
);
7680 if (form
== DW_FORM_strp
)
7681 size
+= DWARF_OFFSET_SIZE
;
7682 else if (form
== DW_FORM_GNU_str_index
)
7683 size
+= size_of_uleb128 (AT_index (a
));
7685 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7687 case dw_val_class_file
:
7688 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7690 case dw_val_class_data8
:
7693 case dw_val_class_vms_delta
:
7694 size
+= DWARF_OFFSET_SIZE
;
7696 case dw_val_class_high_pc
:
7697 size
+= DWARF2_ADDR_SIZE
;
7707 /* Size the debugging information associated with a given DIE. Visits the
7708 DIE's children recursively. Updates the global variable next_die_offset, on
7709 each time through. Uses the current value of next_die_offset to update the
7710 die_offset field in each DIE. */
7713 calc_die_sizes (dw_die_ref die
)
7717 gcc_assert (die
->die_offset
== 0
7718 || (unsigned long int) die
->die_offset
== next_die_offset
);
7719 die
->die_offset
= next_die_offset
;
7720 next_die_offset
+= size_of_die (die
);
7722 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7724 if (die
->die_child
!= NULL
)
7725 /* Count the null byte used to terminate sibling lists. */
7726 next_die_offset
+= 1;
7729 /* Size just the base type children at the start of the CU.
7730 This is needed because build_abbrev needs to size locs
7731 and sizing of type based stack ops needs to know die_offset
7732 values for the base types. */
7735 calc_base_type_die_sizes (void)
7737 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7739 dw_die_ref base_type
;
7740 #if ENABLE_ASSERT_CHECKING
7741 dw_die_ref prev
= comp_unit_die ()->die_child
;
7744 die_offset
+= size_of_die (comp_unit_die ());
7745 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7747 #if ENABLE_ASSERT_CHECKING
7748 gcc_assert (base_type
->die_offset
== 0
7749 && prev
->die_sib
== base_type
7750 && base_type
->die_child
== NULL
7751 && base_type
->die_abbrev
);
7754 base_type
->die_offset
= die_offset
;
7755 die_offset
+= size_of_die (base_type
);
7759 /* Set the marks for a die and its children. We do this so
7760 that we know whether or not a reference needs to use FORM_ref_addr; only
7761 DIEs in the same CU will be marked. We used to clear out the offset
7762 and use that as the flag, but ran into ordering problems. */
7765 mark_dies (dw_die_ref die
)
7769 gcc_assert (!die
->die_mark
);
7772 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7775 /* Clear the marks for a die and its children. */
7778 unmark_dies (dw_die_ref die
)
7782 if (! use_debug_types
)
7783 gcc_assert (die
->die_mark
);
7786 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7789 /* Clear the marks for a die, its children and referred dies. */
7792 unmark_all_dies (dw_die_ref die
)
7802 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7804 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7805 if (AT_class (a
) == dw_val_class_die_ref
)
7806 unmark_all_dies (AT_ref (a
));
7809 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7810 generated for the compilation unit. */
7812 static unsigned long
7813 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
7819 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7820 FOR_EACH_VEC_ELT (*names
, i
, p
)
7821 if (names
!= pubtype_table
7822 || p
->die
->die_offset
!= 0
7823 || !flag_eliminate_unused_debug_types
)
7824 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7826 size
+= DWARF_OFFSET_SIZE
;
7830 /* Return the size of the information in the .debug_aranges section. */
7832 static unsigned long
7833 size_of_aranges (void)
7837 size
= DWARF_ARANGES_HEADER_SIZE
;
7839 /* Count the address/length pair for this compilation unit. */
7840 if (text_section_used
)
7841 size
+= 2 * DWARF2_ADDR_SIZE
;
7842 if (cold_text_section_used
)
7843 size
+= 2 * DWARF2_ADDR_SIZE
;
7844 if (have_multiple_function_sections
)
7849 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
7851 if (!fde
->in_std_section
)
7852 size
+= 2 * DWARF2_ADDR_SIZE
;
7853 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
7854 size
+= 2 * DWARF2_ADDR_SIZE
;
7858 /* Count the two zero words used to terminated the address range table. */
7859 size
+= 2 * DWARF2_ADDR_SIZE
;
7863 /* Select the encoding of an attribute value. */
7865 static enum dwarf_form
7866 value_format (dw_attr_ref a
)
7868 switch (AT_class (a
))
7870 case dw_val_class_addr
:
7871 /* Only very few attributes allow DW_FORM_addr. */
7876 case DW_AT_entry_pc
:
7877 case DW_AT_trampoline
:
7878 return (AT_index (a
) == NOT_INDEXED
7879 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
7883 switch (DWARF2_ADDR_SIZE
)
7886 return DW_FORM_data1
;
7888 return DW_FORM_data2
;
7890 return DW_FORM_data4
;
7892 return DW_FORM_data8
;
7896 case dw_val_class_range_list
:
7897 case dw_val_class_loc_list
:
7898 if (dwarf_version
>= 4)
7899 return DW_FORM_sec_offset
;
7901 case dw_val_class_vms_delta
:
7902 case dw_val_class_offset
:
7903 switch (DWARF_OFFSET_SIZE
)
7906 return DW_FORM_data4
;
7908 return DW_FORM_data8
;
7912 case dw_val_class_loc
:
7913 if (dwarf_version
>= 4)
7914 return DW_FORM_exprloc
;
7915 switch (constant_size (size_of_locs (AT_loc (a
))))
7918 return DW_FORM_block1
;
7920 return DW_FORM_block2
;
7922 return DW_FORM_block4
;
7926 case dw_val_class_const
:
7927 return DW_FORM_sdata
;
7928 case dw_val_class_unsigned_const
:
7929 switch (constant_size (AT_unsigned (a
)))
7932 return DW_FORM_data1
;
7934 return DW_FORM_data2
;
7936 /* In DWARF3 DW_AT_data_member_location with
7937 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
7938 constant, so we need to use DW_FORM_udata if we need
7939 a large constant. */
7940 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7941 return DW_FORM_udata
;
7942 return DW_FORM_data4
;
7944 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7945 return DW_FORM_udata
;
7946 return DW_FORM_data8
;
7950 case dw_val_class_const_double
:
7951 switch (HOST_BITS_PER_WIDE_INT
)
7954 return DW_FORM_data2
;
7956 return DW_FORM_data4
;
7958 return DW_FORM_data8
;
7961 return DW_FORM_block1
;
7963 case dw_val_class_vec
:
7964 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
7965 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
7968 return DW_FORM_block1
;
7970 return DW_FORM_block2
;
7972 return DW_FORM_block4
;
7976 case dw_val_class_flag
:
7977 if (dwarf_version
>= 4)
7979 /* Currently all add_AT_flag calls pass in 1 as last argument,
7980 so DW_FORM_flag_present can be used. If that ever changes,
7981 we'll need to use DW_FORM_flag and have some optimization
7982 in build_abbrev_table that will change those to
7983 DW_FORM_flag_present if it is set to 1 in all DIEs using
7984 the same abbrev entry. */
7985 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7986 return DW_FORM_flag_present
;
7988 return DW_FORM_flag
;
7989 case dw_val_class_die_ref
:
7990 if (AT_ref_external (a
))
7991 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
7994 case dw_val_class_fde_ref
:
7995 return DW_FORM_data
;
7996 case dw_val_class_lbl_id
:
7997 return (AT_index (a
) == NOT_INDEXED
7998 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
7999 case dw_val_class_lineptr
:
8000 case dw_val_class_macptr
:
8001 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8002 case dw_val_class_str
:
8003 return AT_string_form (a
);
8004 case dw_val_class_file
:
8005 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8008 return DW_FORM_data1
;
8010 return DW_FORM_data2
;
8012 return DW_FORM_data4
;
8017 case dw_val_class_data8
:
8018 return DW_FORM_data8
;
8020 case dw_val_class_high_pc
:
8021 switch (DWARF2_ADDR_SIZE
)
8024 return DW_FORM_data1
;
8026 return DW_FORM_data2
;
8028 return DW_FORM_data4
;
8030 return DW_FORM_data8
;
8040 /* Output the encoding of an attribute value. */
8043 output_value_format (dw_attr_ref a
)
8045 enum dwarf_form form
= value_format (a
);
8047 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8050 /* Given a die and id, produce the appropriate abbreviations. */
8053 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8058 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8059 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8060 dwarf_tag_name (abbrev
->die_tag
));
8062 if (abbrev
->die_child
!= NULL
)
8063 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8065 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8067 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8069 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8070 dwarf_attr_name (a_attr
->dw_attr
));
8071 output_value_format (a_attr
);
8074 dw2_asm_output_data (1, 0, NULL
);
8075 dw2_asm_output_data (1, 0, NULL
);
8079 /* Output the .debug_abbrev section which defines the DIE abbreviation
8083 output_abbrev_section (void)
8085 unsigned long abbrev_id
;
8087 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8088 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8090 /* Terminate the table. */
8091 dw2_asm_output_data (1, 0, NULL
);
8094 /* Output a symbol we can use to refer to this DIE from another CU. */
8097 output_die_symbol (dw_die_ref die
)
8099 const char *sym
= die
->die_id
.die_symbol
;
8101 gcc_assert (!die
->comdat_type_p
);
8106 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8107 /* We make these global, not weak; if the target doesn't support
8108 .linkonce, it doesn't support combining the sections, so debugging
8110 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8112 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8115 /* Return a new location list, given the begin and end range, and the
8118 static inline dw_loc_list_ref
8119 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8120 const char *section
)
8122 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8124 retlist
->begin
= begin
;
8125 retlist
->begin_entry
= NULL
;
8127 retlist
->expr
= expr
;
8128 retlist
->section
= section
;
8133 /* Generate a new internal symbol for this location list node, if it
8134 hasn't got one yet. */
8137 gen_llsym (dw_loc_list_ref list
)
8139 gcc_assert (!list
->ll_symbol
);
8140 list
->ll_symbol
= gen_internal_sym ("LLST");
8143 /* Output the location list given to us. */
8146 output_loc_list (dw_loc_list_ref list_head
)
8148 dw_loc_list_ref curr
= list_head
;
8150 if (list_head
->emitted
)
8152 list_head
->emitted
= true;
8154 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8156 /* Walk the location list, and output each range + expression. */
8157 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8160 /* Don't output an entry that starts and ends at the same address. */
8161 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8163 size
= size_of_locs (curr
->expr
);
8164 /* If the expression is too large, drop it on the floor. We could
8165 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8166 in the expression, but >= 64KB expressions for a single value
8167 in a single range are unlikely very useful. */
8170 if (dwarf_split_debug_info
)
8172 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8173 "Location list start/length entry (%s)",
8174 list_head
->ll_symbol
);
8175 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8176 "Location list range start index (%s)",
8178 /* The length field is 4 bytes. If we ever need to support
8179 an 8-byte length, we can add a new DW_LLE code or fall back
8180 to DW_LLE_GNU_start_end_entry. */
8181 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8182 "Location list range length (%s)",
8183 list_head
->ll_symbol
);
8185 else if (!have_multiple_function_sections
)
8187 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8188 "Location list begin address (%s)",
8189 list_head
->ll_symbol
);
8190 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8191 "Location list end address (%s)",
8192 list_head
->ll_symbol
);
8196 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8197 "Location list begin address (%s)",
8198 list_head
->ll_symbol
);
8199 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8200 "Location list end address (%s)",
8201 list_head
->ll_symbol
);
8204 /* Output the block length for this list of location operations. */
8205 gcc_assert (size
<= 0xffff);
8206 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8208 output_loc_sequence (curr
->expr
, -1);
8211 if (dwarf_split_debug_info
)
8212 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8213 "Location list terminator (%s)",
8214 list_head
->ll_symbol
);
8217 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8218 "Location list terminator begin (%s)",
8219 list_head
->ll_symbol
);
8220 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8221 "Location list terminator end (%s)",
8222 list_head
->ll_symbol
);
8226 /* Output a range_list offset into the debug_range section. Emit a
8227 relocated reference if val_entry is NULL, otherwise, emit an
8228 indirect reference. */
8231 output_range_list_offset (dw_attr_ref a
)
8233 const char *name
= dwarf_attr_name (a
->dw_attr
);
8235 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8237 char *p
= strchr (ranges_section_label
, '\0');
8238 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8239 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8240 debug_ranges_section
, "%s", name
);
8244 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8245 "%s (offset from %s)", name
, ranges_section_label
);
8248 /* Output the offset into the debug_loc section. */
8251 output_loc_list_offset (dw_attr_ref a
)
8253 char *sym
= AT_loc_list (a
)->ll_symbol
;
8256 if (dwarf_split_debug_info
)
8257 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8258 "%s", dwarf_attr_name (a
->dw_attr
));
8260 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8261 "%s", dwarf_attr_name (a
->dw_attr
));
8264 /* Output an attribute's index or value appropriately. */
8267 output_attr_index_or_value (dw_attr_ref a
)
8269 const char *name
= dwarf_attr_name (a
->dw_attr
);
8271 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8273 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8276 switch (AT_class (a
))
8278 case dw_val_class_addr
:
8279 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8281 case dw_val_class_high_pc
:
8282 case dw_val_class_lbl_id
:
8283 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8285 case dw_val_class_loc_list
:
8286 output_loc_list_offset (a
);
8293 /* Output a type signature. */
8296 output_signature (const char *sig
, const char *name
)
8300 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8301 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8304 /* Output the DIE and its attributes. Called recursively to generate
8305 the definitions of each child DIE. */
8308 output_die (dw_die_ref die
)
8315 /* If someone in another CU might refer to us, set up a symbol for
8316 them to point to. */
8317 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8318 output_die_symbol (die
);
8320 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8321 (unsigned long)die
->die_offset
,
8322 dwarf_tag_name (die
->die_tag
));
8324 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8326 const char *name
= dwarf_attr_name (a
->dw_attr
);
8328 switch (AT_class (a
))
8330 case dw_val_class_addr
:
8331 output_attr_index_or_value (a
);
8334 case dw_val_class_offset
:
8335 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8339 case dw_val_class_range_list
:
8340 output_range_list_offset (a
);
8343 case dw_val_class_loc
:
8344 size
= size_of_locs (AT_loc (a
));
8346 /* Output the block length for this list of location operations. */
8347 if (dwarf_version
>= 4)
8348 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8350 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8352 output_loc_sequence (AT_loc (a
), -1);
8355 case dw_val_class_const
:
8356 /* ??? It would be slightly more efficient to use a scheme like is
8357 used for unsigned constants below, but gdb 4.x does not sign
8358 extend. Gdb 5.x does sign extend. */
8359 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8362 case dw_val_class_unsigned_const
:
8364 int csize
= constant_size (AT_unsigned (a
));
8365 if (dwarf_version
== 3
8366 && a
->dw_attr
== DW_AT_data_member_location
8368 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8370 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8374 case dw_val_class_const_double
:
8376 unsigned HOST_WIDE_INT first
, second
;
8378 if (HOST_BITS_PER_WIDE_INT
>= 64)
8379 dw2_asm_output_data (1,
8380 HOST_BITS_PER_DOUBLE_INT
8381 / HOST_BITS_PER_CHAR
,
8384 if (WORDS_BIG_ENDIAN
)
8386 first
= a
->dw_attr_val
.v
.val_double
.high
;
8387 second
= a
->dw_attr_val
.v
.val_double
.low
;
8391 first
= a
->dw_attr_val
.v
.val_double
.low
;
8392 second
= a
->dw_attr_val
.v
.val_double
.high
;
8395 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8397 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8402 case dw_val_class_vec
:
8404 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8405 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8409 dw2_asm_output_data (constant_size (len
* elt_size
),
8410 len
* elt_size
, "%s", name
);
8411 if (elt_size
> sizeof (HOST_WIDE_INT
))
8416 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8419 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8420 "fp or vector constant word %u", i
);
8424 case dw_val_class_flag
:
8425 if (dwarf_version
>= 4)
8427 /* Currently all add_AT_flag calls pass in 1 as last argument,
8428 so DW_FORM_flag_present can be used. If that ever changes,
8429 we'll need to use DW_FORM_flag and have some optimization
8430 in build_abbrev_table that will change those to
8431 DW_FORM_flag_present if it is set to 1 in all DIEs using
8432 the same abbrev entry. */
8433 gcc_assert (AT_flag (a
) == 1);
8435 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8436 ASM_COMMENT_START
, name
);
8439 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8442 case dw_val_class_loc_list
:
8443 output_attr_index_or_value (a
);
8446 case dw_val_class_die_ref
:
8447 if (AT_ref_external (a
))
8449 if (AT_ref (a
)->comdat_type_p
)
8451 comdat_type_node_ref type_node
=
8452 AT_ref (a
)->die_id
.die_type_node
;
8454 gcc_assert (type_node
);
8455 output_signature (type_node
->signature
, name
);
8459 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8463 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8464 length, whereas in DWARF3 it's always sized as an
8466 if (dwarf_version
== 2)
8467 size
= DWARF2_ADDR_SIZE
;
8469 size
= DWARF_OFFSET_SIZE
;
8470 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8476 gcc_assert (AT_ref (a
)->die_offset
);
8477 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8482 case dw_val_class_fde_ref
:
8486 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8487 a
->dw_attr_val
.v
.val_fde_index
* 2);
8488 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8493 case dw_val_class_vms_delta
:
8494 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8495 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8499 case dw_val_class_lbl_id
:
8500 output_attr_index_or_value (a
);
8503 case dw_val_class_lineptr
:
8504 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8505 debug_line_section
, "%s", name
);
8508 case dw_val_class_macptr
:
8509 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8510 debug_macinfo_section
, "%s", name
);
8513 case dw_val_class_str
:
8514 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8515 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8516 a
->dw_attr_val
.v
.val_str
->label
,
8518 "%s: \"%s\"", name
, AT_string (a
));
8519 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8520 dw2_asm_output_data_uleb128 (AT_index (a
),
8521 "%s: \"%s\"", name
, AT_string (a
));
8523 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8526 case dw_val_class_file
:
8528 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8530 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8531 a
->dw_attr_val
.v
.val_file
->filename
);
8535 case dw_val_class_data8
:
8539 for (i
= 0; i
< 8; i
++)
8540 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8541 i
== 0 ? "%s" : NULL
, name
);
8545 case dw_val_class_high_pc
:
8546 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8547 get_AT_low_pc (die
), "DW_AT_high_pc");
8555 FOR_EACH_CHILD (die
, c
, output_die (c
));
8557 /* Add null byte to terminate sibling list. */
8558 if (die
->die_child
!= NULL
)
8559 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8560 (unsigned long) die
->die_offset
);
8563 /* Output the compilation unit that appears at the beginning of the
8564 .debug_info section, and precedes the DIE descriptions. */
8567 output_compilation_unit_header (void)
8569 int ver
= dwarf_version
;
8571 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8572 dw2_asm_output_data (4, 0xffffffff,
8573 "Initial length escape value indicating 64-bit DWARF extension");
8574 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8575 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8576 "Length of Compilation Unit Info");
8577 dw2_asm_output_data (2, ver
, "DWARF version number");
8578 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8579 debug_abbrev_section
,
8580 "Offset Into Abbrev. Section");
8581 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8584 /* Output the compilation unit DIE and its children. */
8587 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8589 const char *secname
, *oldsym
;
8593 /* Unless we are outputting main CU, we may throw away empty ones. */
8594 if (!output_if_empty
&& die
->die_child
== NULL
)
8597 /* Even if there are no children of this DIE, we must output the information
8598 about the compilation unit. Otherwise, on an empty translation unit, we
8599 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8600 will then complain when examining the file. First mark all the DIEs in
8601 this CU so we know which get local refs. */
8604 extern_map
= optimize_external_refs (die
);
8606 build_abbrev_table (die
, extern_map
);
8608 htab_delete (extern_map
);
8610 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8611 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8612 calc_die_sizes (die
);
8614 oldsym
= die
->die_id
.die_symbol
;
8617 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8619 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8621 die
->die_id
.die_symbol
= NULL
;
8622 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8626 switch_to_section (debug_info_section
);
8627 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8628 info_section_emitted
= true;
8631 /* Output debugging information. */
8632 output_compilation_unit_header ();
8635 /* Leave the marks on the main CU, so we can check them in
8640 die
->die_id
.die_symbol
= oldsym
;
8644 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8645 and .debug_pubtypes. This is configured per-target, but can be
8646 overridden by the -gpubnames or -gno-pubnames options. */
8649 want_pubnames (void)
8651 return (debug_generate_pub_sections
!= -1
8652 ? debug_generate_pub_sections
8653 : targetm
.want_debug_pub_sections
);
8656 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8659 add_AT_pubnames (dw_die_ref die
)
8661 if (want_pubnames ())
8662 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8665 /* Helper function to generate top-level dies for skeleton debug_info and
8669 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8671 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8674 add_comp_dir_attribute (die
);
8675 add_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8676 /* The specification suggests that these attributes be inline to avoid
8677 having a .debug_str section. We know that they exist in the die because
8678 we just added them. */
8679 attr
= get_AT (die
, DW_AT_GNU_dwo_name
);
8680 attr
->dw_attr_val
.v
.val_str
->form
= DW_FORM_string
;
8681 attr
= get_AT (die
, DW_AT_comp_dir
);
8682 attr
->dw_attr_val
.v
.val_str
->form
= DW_FORM_string
;
8684 add_AT_pubnames (die
);
8685 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8688 /* Return the single type-unit die for skeleton type units. */
8691 get_skeleton_type_unit (void)
8693 /* For dwarf_split_debug_sections with use_type info, all type units in the
8694 skeleton sections have identical dies (but different headers). This
8695 single die will be output many times. */
8697 static dw_die_ref skeleton_type_unit
= NULL
;
8699 if (skeleton_type_unit
== NULL
)
8701 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8702 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8703 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8705 return skeleton_type_unit
;
8708 /* Output skeleton debug sections that point to the dwo file. */
8711 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8713 /* These attributes will be found in the full debug_info section. */
8714 remove_AT (comp_unit
, DW_AT_producer
);
8715 remove_AT (comp_unit
, DW_AT_language
);
8717 /* Add attributes common to skeleton compile_units and type_units. */
8718 add_top_level_skeleton_die_attrs (comp_unit
);
8720 switch_to_section (debug_skeleton_info_section
);
8721 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8723 /* Produce the skeleton compilation-unit header. This one differs enough from
8724 a normal CU header that it's better not to call output_compilation_unit
8726 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8727 dw2_asm_output_data (4, 0xffffffff,
8728 "Initial length escape value indicating 64-bit DWARF extension");
8730 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8731 DWARF_COMPILE_UNIT_HEADER_SIZE
8732 - DWARF_INITIAL_LENGTH_SIZE
8733 + size_of_die (comp_unit
),
8734 "Length of Compilation Unit Info");
8735 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8736 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8737 debug_abbrev_section
,
8738 "Offset Into Abbrev. Section");
8739 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8741 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8742 output_die (comp_unit
);
8744 /* Build the skeleton debug_abbrev section. */
8745 switch_to_section (debug_skeleton_abbrev_section
);
8746 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8748 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8749 if (use_debug_types
)
8750 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8752 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8755 /* Output a comdat type unit DIE and its children. */
8758 output_comdat_type_unit (comdat_type_node
*node
)
8760 const char *secname
;
8763 #if defined (OBJECT_FORMAT_ELF)
8768 /* First mark all the DIEs in this CU so we know which get local refs. */
8769 mark_dies (node
->root_die
);
8771 extern_map
= optimize_external_refs (node
->root_die
);
8773 build_abbrev_table (node
->root_die
, extern_map
);
8775 htab_delete (extern_map
);
8777 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8778 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8779 calc_die_sizes (node
->root_die
);
8781 #if defined (OBJECT_FORMAT_ELF)
8782 if (!dwarf_split_debug_info
)
8783 secname
= ".debug_types";
8785 secname
= ".debug_types.dwo";
8787 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8788 sprintf (tmp
, "wt.");
8789 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8790 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8791 comdat_key
= get_identifier (tmp
);
8792 targetm
.asm_out
.named_section (secname
,
8793 SECTION_DEBUG
| SECTION_LINKONCE
,
8796 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8797 sprintf (tmp
, ".gnu.linkonce.wt.");
8798 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8799 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8801 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8804 /* Output debugging information. */
8805 output_compilation_unit_header ();
8806 output_signature (node
->signature
, "Type Signature");
8807 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8808 "Offset to Type DIE");
8809 output_die (node
->root_die
);
8811 unmark_dies (node
->root_die
);
8813 #if defined (OBJECT_FORMAT_ELF)
8814 if (dwarf_split_debug_info
)
8816 /* Produce the skeleton type-unit header. */
8817 const char *secname
= ".debug_types";
8819 targetm
.asm_out
.named_section (secname
,
8820 SECTION_DEBUG
| SECTION_LINKONCE
,
8822 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8823 dw2_asm_output_data (4, 0xffffffff,
8824 "Initial length escape value indicating 64-bit DWARF extension");
8826 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8827 DWARF_COMPILE_UNIT_HEADER_SIZE
8828 - DWARF_INITIAL_LENGTH_SIZE
8829 + size_of_die (get_skeleton_type_unit ())
8830 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
8831 "Length of Type Unit Info");
8832 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8833 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8834 debug_skeleton_abbrev_section_label
,
8835 debug_abbrev_section
,
8836 "Offset Into Abbrev. Section");
8837 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8838 output_signature (node
->signature
, "Type Signature");
8839 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
8841 output_die (get_skeleton_type_unit ());
8846 /* Return the DWARF2/3 pubname associated with a decl. */
8849 dwarf2_name (tree decl
, int scope
)
8851 if (DECL_NAMELESS (decl
))
8853 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8856 /* Add a new entry to .debug_pubnames if appropriate. */
8859 add_pubname_string (const char *str
, dw_die_ref die
)
8864 e
.name
= xstrdup (str
);
8865 vec_safe_push (pubname_table
, e
);
8869 add_pubname (tree decl
, dw_die_ref die
)
8871 if (!want_pubnames ())
8874 /* Don't add items to the table when we expect that the consumer will have
8875 just read the enclosing die. For example, if the consumer is looking at a
8876 class_member, it will either be inside the class already, or will have just
8877 looked up the class to find the member. Either way, searching the class is
8878 faster than searching the index. */
8879 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
8880 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8882 const char *name
= dwarf2_name (decl
, 1);
8885 add_pubname_string (name
, die
);
8889 /* Add an enumerator to the pubnames section. */
8892 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
8896 gcc_assert (scope_name
);
8897 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
8899 vec_safe_push (pubname_table
, e
);
8902 /* Add a new entry to .debug_pubtypes if appropriate. */
8905 add_pubtype (tree decl
, dw_die_ref die
)
8909 if (!want_pubnames ())
8912 if ((TREE_PUBLIC (decl
)
8913 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8914 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8917 const char *scope_name
= "";
8918 const char *sep
= is_cxx () ? "::" : ".";
8921 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
8922 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
8924 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
8925 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
8926 scope_name
= concat (scope_name
, sep
, NULL
);
8932 name
= type_tag (decl
);
8934 name
= lang_hooks
.dwarf_name (decl
, 1);
8936 /* If we don't have a name for the type, there's no point in adding
8938 if (name
!= NULL
&& name
[0] != '\0')
8941 e
.name
= concat (scope_name
, name
, NULL
);
8942 vec_safe_push (pubtype_table
, e
);
8945 /* Although it might be more consistent to add the pubinfo for the
8946 enumerators as their dies are created, they should only be added if the
8947 enum type meets the criteria above. So rather than re-check the parent
8948 enum type whenever an enumerator die is created, just output them all
8949 here. This isn't protected by the name conditional because anonymous
8950 enums don't have names. */
8951 if (die
->die_tag
== DW_TAG_enumeration_type
)
8955 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
8960 /* Output the public names table used to speed up access to externally
8961 visible names; or the public types table used to find type definitions. */
8964 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8967 unsigned long pubnames_length
= size_of_pubnames (names
);
8970 if (!want_pubnames () || !info_section_emitted
)
8972 if (names
== pubname_table
)
8973 switch_to_section (debug_pubnames_section
);
8975 switch_to_section (debug_pubtypes_section
);
8976 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8977 dw2_asm_output_data (4, 0xffffffff,
8978 "Initial length escape value indicating 64-bit DWARF extension");
8979 if (names
== pubname_table
)
8980 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8981 "Length of Public Names Info");
8983 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8984 "Length of Public Type Names Info");
8985 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8986 dw2_asm_output_data (2, 2, "DWARF Version");
8987 if (dwarf_split_debug_info
)
8988 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
8989 debug_skeleton_info_section
,
8990 "Offset of Compilation Unit Info");
8992 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8994 "Offset of Compilation Unit Info");
8995 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
8996 "Compilation Unit Length");
8998 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9000 /* Enumerator names are part of the pubname table, but the parent
9001 DW_TAG_enumeration_type die may have been pruned. Don't output
9002 them if that is the case. */
9003 if (pub
->die
->die_tag
== DW_TAG_enumerator
&& !pub
->die
->die_mark
)
9006 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9007 if (names
== pubname_table
)
9008 gcc_assert (pub
->die
->die_mark
);
9010 if (names
!= pubtype_table
9011 || pub
->die
->die_offset
!= 0
9012 || !flag_eliminate_unused_debug_types
)
9014 dw_offset die_offset
= pub
->die
->die_offset
;
9016 /* If we're putting types in their own .debug_types sections,
9017 the .debug_pubtypes table will still point to the compile
9018 unit (not the type unit), so we want to use the offset of
9019 the skeleton DIE (if there is one). */
9020 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9022 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9024 if (type_node
!= NULL
)
9025 die_offset
= (type_node
->skeleton_die
!= NULL
9026 ? type_node
->skeleton_die
->die_offset
9030 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9032 dw2_asm_output_nstring (pub
->name
, -1, "external name");
9036 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9039 /* Output the information that goes into the .debug_aranges table.
9040 Namely, define the beginning and ending address range of the
9041 text section generated for this compilation unit. */
9044 output_aranges (unsigned long aranges_length
)
9048 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9049 dw2_asm_output_data (4, 0xffffffff,
9050 "Initial length escape value indicating 64-bit DWARF extension");
9051 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9052 "Length of Address Ranges Info");
9053 /* Version number for aranges is still 2, even in DWARF3. */
9054 dw2_asm_output_data (2, 2, "DWARF Version");
9055 if (dwarf_split_debug_info
)
9056 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9057 debug_skeleton_info_section
,
9058 "Offset of Compilation Unit Info");
9060 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9062 "Offset of Compilation Unit Info");
9063 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9064 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9066 /* We need to align to twice the pointer size here. */
9067 if (DWARF_ARANGES_PAD_SIZE
)
9069 /* Pad using a 2 byte words so that padding is correct for any
9071 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9072 2 * DWARF2_ADDR_SIZE
);
9073 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9074 dw2_asm_output_data (2, 0, NULL
);
9077 /* It is necessary not to output these entries if the sections were
9078 not used; if the sections were not used, the length will be 0 and
9079 the address may end up as 0 if the section is discarded by ld
9080 --gc-sections, leaving an invalid (0, 0) entry that can be
9081 confused with the terminator. */
9082 if (text_section_used
)
9084 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9085 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9086 text_section_label
, "Length");
9088 if (cold_text_section_used
)
9090 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9092 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9093 cold_text_section_label
, "Length");
9096 if (have_multiple_function_sections
)
9101 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9103 if (DECL_IGNORED_P (fde
->decl
))
9105 if (!fde
->in_std_section
)
9107 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9109 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9110 fde
->dw_fde_begin
, "Length");
9112 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9114 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9116 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9117 fde
->dw_fde_second_begin
, "Length");
9122 /* Output the terminator words. */
9123 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9124 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9127 /* Add a new entry to .debug_ranges. Return the offset at which it
9131 add_ranges_num (int num
)
9133 unsigned int in_use
= ranges_table_in_use
;
9135 if (in_use
== ranges_table_allocated
)
9137 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9138 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9139 ranges_table_allocated
);
9140 memset (ranges_table
+ ranges_table_in_use
, 0,
9141 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9144 ranges_table
[in_use
].num
= num
;
9145 ranges_table_in_use
= in_use
+ 1;
9147 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9150 /* Add a new entry to .debug_ranges corresponding to a block, or a
9151 range terminator if BLOCK is NULL. */
9154 add_ranges (const_tree block
)
9156 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9159 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9160 When using dwarf_split_debug_info, address attributes in dies destined
9161 for the final executable should be direct references--setting the
9162 parameter force_direct ensures this behavior. */
9165 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9166 bool *added
, bool force_direct
)
9168 unsigned int in_use
= ranges_by_label_in_use
;
9169 unsigned int offset
;
9171 if (in_use
== ranges_by_label_allocated
)
9173 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9174 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9176 ranges_by_label_allocated
);
9177 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9178 RANGES_TABLE_INCREMENT
9179 * sizeof (struct dw_ranges_by_label_struct
));
9182 ranges_by_label
[in_use
].begin
= begin
;
9183 ranges_by_label
[in_use
].end
= end
;
9184 ranges_by_label_in_use
= in_use
+ 1;
9186 offset
= add_ranges_num (-(int)in_use
- 1);
9189 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9195 output_ranges (void)
9198 static const char *const start_fmt
= "Offset %#x";
9199 const char *fmt
= start_fmt
;
9201 for (i
= 0; i
< ranges_table_in_use
; i
++)
9203 int block_num
= ranges_table
[i
].num
;
9207 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9208 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9210 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9211 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9213 /* If all code is in the text section, then the compilation
9214 unit base address defaults to DW_AT_low_pc, which is the
9215 base of the text section. */
9216 if (!have_multiple_function_sections
)
9218 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9220 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9221 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9222 text_section_label
, NULL
);
9225 /* Otherwise, the compilation unit base address is zero,
9226 which allows us to use absolute addresses, and not worry
9227 about whether the target supports cross-section
9231 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9232 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9233 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9239 /* Negative block_num stands for an index into ranges_by_label. */
9240 else if (block_num
< 0)
9242 int lab_idx
= - block_num
- 1;
9244 if (!have_multiple_function_sections
)
9248 /* If we ever use add_ranges_by_labels () for a single
9249 function section, all we have to do is to take out
9251 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9252 ranges_by_label
[lab_idx
].begin
,
9254 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9255 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9256 ranges_by_label
[lab_idx
].end
,
9257 text_section_label
, NULL
);
9262 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9263 ranges_by_label
[lab_idx
].begin
,
9264 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9265 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9266 ranges_by_label
[lab_idx
].end
,
9272 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9273 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9279 /* Data structure containing information about input files. */
9282 const char *path
; /* Complete file name. */
9283 const char *fname
; /* File name part. */
9284 int length
; /* Length of entire string. */
9285 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9286 int dir_idx
; /* Index in directory table. */
9289 /* Data structure containing information about directories with source
9293 const char *path
; /* Path including directory name. */
9294 int length
; /* Path length. */
9295 int prefix
; /* Index of directory entry which is a prefix. */
9296 int count
; /* Number of files in this directory. */
9297 int dir_idx
; /* Index of directory used as base. */
9300 /* Callback function for file_info comparison. We sort by looking at
9301 the directories in the path. */
9304 file_info_cmp (const void *p1
, const void *p2
)
9306 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9307 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9308 const unsigned char *cp1
;
9309 const unsigned char *cp2
;
9311 /* Take care of file names without directories. We need to make sure that
9312 we return consistent values to qsort since some will get confused if
9313 we return the same value when identical operands are passed in opposite
9314 orders. So if neither has a directory, return 0 and otherwise return
9315 1 or -1 depending on which one has the directory. */
9316 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9317 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9319 cp1
= (const unsigned char *) s1
->path
;
9320 cp2
= (const unsigned char *) s2
->path
;
9326 /* Reached the end of the first path? If so, handle like above. */
9327 if ((cp1
== (const unsigned char *) s1
->fname
)
9328 || (cp2
== (const unsigned char *) s2
->fname
))
9329 return ((cp2
== (const unsigned char *) s2
->fname
)
9330 - (cp1
== (const unsigned char *) s1
->fname
));
9332 /* Character of current path component the same? */
9333 else if (*cp1
!= *cp2
)
9338 struct file_name_acquire_data
9340 struct file_info
*files
;
9345 /* Traversal function for the hash table. */
9348 file_name_acquire (void ** slot
, void *data
)
9350 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9351 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9352 struct file_info
*fi
;
9355 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9357 if (! d
->emitted_number
)
9360 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9362 fi
= fnad
->files
+ fnad
->used_files
++;
9364 /* Skip all leading "./". */
9366 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9369 /* Create a new array entry. */
9371 fi
->length
= strlen (f
);
9374 /* Search for the file name part. */
9375 f
= strrchr (f
, DIR_SEPARATOR
);
9376 #if defined (DIR_SEPARATOR_2)
9378 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9382 if (f
== NULL
|| f
< g
)
9388 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9392 /* Output the directory table and the file name table. We try to minimize
9393 the total amount of memory needed. A heuristic is used to avoid large
9394 slowdowns with many input files. */
9397 output_file_names (void)
9399 struct file_name_acquire_data fnad
;
9401 struct file_info
*files
;
9402 struct dir_info
*dirs
;
9410 if (!last_emitted_file
)
9412 dw2_asm_output_data (1, 0, "End directory table");
9413 dw2_asm_output_data (1, 0, "End file name table");
9417 numfiles
= last_emitted_file
->emitted_number
;
9419 /* Allocate the various arrays we need. */
9420 files
= XALLOCAVEC (struct file_info
, numfiles
);
9421 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9424 fnad
.used_files
= 0;
9425 fnad
.max_files
= numfiles
;
9426 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9427 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9429 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9431 /* Find all the different directories used. */
9432 dirs
[0].path
= files
[0].path
;
9433 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9434 dirs
[0].prefix
= -1;
9436 dirs
[0].dir_idx
= 0;
9437 files
[0].dir_idx
= 0;
9440 for (i
= 1; i
< numfiles
; i
++)
9441 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9442 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9443 dirs
[ndirs
- 1].length
) == 0)
9445 /* Same directory as last entry. */
9446 files
[i
].dir_idx
= ndirs
- 1;
9447 ++dirs
[ndirs
- 1].count
;
9453 /* This is a new directory. */
9454 dirs
[ndirs
].path
= files
[i
].path
;
9455 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9456 dirs
[ndirs
].count
= 1;
9457 dirs
[ndirs
].dir_idx
= ndirs
;
9458 files
[i
].dir_idx
= ndirs
;
9460 /* Search for a prefix. */
9461 dirs
[ndirs
].prefix
= -1;
9462 for (j
= 0; j
< ndirs
; j
++)
9463 if (dirs
[j
].length
< dirs
[ndirs
].length
9464 && dirs
[j
].length
> 1
9465 && (dirs
[ndirs
].prefix
== -1
9466 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9467 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9468 dirs
[ndirs
].prefix
= j
;
9473 /* Now to the actual work. We have to find a subset of the directories which
9474 allow expressing the file name using references to the directory table
9475 with the least amount of characters. We do not do an exhaustive search
9476 where we would have to check out every combination of every single
9477 possible prefix. Instead we use a heuristic which provides nearly optimal
9478 results in most cases and never is much off. */
9479 saved
= XALLOCAVEC (int, ndirs
);
9480 savehere
= XALLOCAVEC (int, ndirs
);
9482 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9483 for (i
= 0; i
< ndirs
; i
++)
9488 /* We can always save some space for the current directory. But this
9489 does not mean it will be enough to justify adding the directory. */
9490 savehere
[i
] = dirs
[i
].length
;
9491 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9493 for (j
= i
+ 1; j
< ndirs
; j
++)
9496 if (saved
[j
] < dirs
[i
].length
)
9498 /* Determine whether the dirs[i] path is a prefix of the
9503 while (k
!= -1 && k
!= (int) i
)
9508 /* Yes it is. We can possibly save some memory by
9509 writing the filenames in dirs[j] relative to
9511 savehere
[j
] = dirs
[i
].length
;
9512 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9517 /* Check whether we can save enough to justify adding the dirs[i]
9519 if (total
> dirs
[i
].length
+ 1)
9521 /* It's worthwhile adding. */
9522 for (j
= i
; j
< ndirs
; j
++)
9523 if (savehere
[j
] > 0)
9525 /* Remember how much we saved for this directory so far. */
9526 saved
[j
] = savehere
[j
];
9528 /* Remember the prefix directory. */
9529 dirs
[j
].dir_idx
= i
;
9534 /* Emit the directory name table. */
9535 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9536 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9537 dw2_asm_output_nstring (dirs
[i
].path
,
9539 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9540 "Directory Entry: %#x", i
+ idx_offset
);
9542 dw2_asm_output_data (1, 0, "End directory table");
9544 /* We have to emit them in the order of emitted_number since that's
9545 used in the debug info generation. To do this efficiently we
9546 generate a back-mapping of the indices first. */
9547 backmap
= XALLOCAVEC (int, numfiles
);
9548 for (i
= 0; i
< numfiles
; i
++)
9549 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9551 /* Now write all the file names. */
9552 for (i
= 0; i
< numfiles
; i
++)
9554 int file_idx
= backmap
[i
];
9555 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9557 #ifdef VMS_DEBUGGING_INFO
9558 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9560 /* Setting these fields can lead to debugger miscomparisons,
9561 but VMS Debug requires them to be set correctly. */
9566 int maxfilelen
= strlen (files
[file_idx
].path
)
9567 + dirs
[dir_idx
].length
9568 + MAX_VMS_VERSION_LEN
+ 1;
9569 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9571 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9572 snprintf (filebuf
, maxfilelen
, "%s;%d",
9573 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9575 dw2_asm_output_nstring
9576 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9578 /* Include directory index. */
9579 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9581 /* Modification time. */
9582 dw2_asm_output_data_uleb128
9583 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9587 /* File length in bytes. */
9588 dw2_asm_output_data_uleb128
9589 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9593 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9594 "File Entry: %#x", (unsigned) i
+ 1);
9596 /* Include directory index. */
9597 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9599 /* Modification time. */
9600 dw2_asm_output_data_uleb128 (0, NULL
);
9602 /* File length in bytes. */
9603 dw2_asm_output_data_uleb128 (0, NULL
);
9604 #endif /* VMS_DEBUGGING_INFO */
9607 dw2_asm_output_data (1, 0, "End file name table");
9611 /* Output one line number table into the .debug_line section. */
9614 output_one_line_info_table (dw_line_info_table
*table
)
9616 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9617 unsigned int current_line
= 1;
9618 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9619 dw_line_info_entry
*ent
;
9622 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9624 switch (ent
->opcode
)
9626 case LI_set_address
:
9627 /* ??? Unfortunately, we have little choice here currently, and
9628 must always use the most general form. GCC does not know the
9629 address delta itself, so we can't use DW_LNS_advance_pc. Many
9630 ports do have length attributes which will give an upper bound
9631 on the address range. We could perhaps use length attributes
9632 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9633 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9635 /* This can handle any delta. This takes
9636 4+DWARF2_ADDR_SIZE bytes. */
9637 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9638 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9639 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9640 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9644 if (ent
->val
== current_line
)
9646 /* We still need to start a new row, so output a copy insn. */
9647 dw2_asm_output_data (1, DW_LNS_copy
,
9648 "copy line %u", current_line
);
9652 int line_offset
= ent
->val
- current_line
;
9653 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9655 current_line
= ent
->val
;
9656 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9658 /* This can handle deltas from -10 to 234, using the current
9659 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9660 This takes 1 byte. */
9661 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9662 "line %u", current_line
);
9666 /* This can handle any delta. This takes at least 4 bytes,
9667 depending on the value being encoded. */
9668 dw2_asm_output_data (1, DW_LNS_advance_line
,
9669 "advance to line %u", current_line
);
9670 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9671 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9677 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9678 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9682 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9683 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9686 case LI_negate_stmt
:
9687 current_is_stmt
= !current_is_stmt
;
9688 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9689 "is_stmt %d", current_is_stmt
);
9692 case LI_set_prologue_end
:
9693 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9694 "set prologue end");
9697 case LI_set_epilogue_begin
:
9698 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9699 "set epilogue begin");
9702 case LI_set_discriminator
:
9703 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9704 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9705 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9706 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9711 /* Emit debug info for the address of the end of the table. */
9712 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9713 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9714 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9715 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9717 dw2_asm_output_data (1, 0, "end sequence");
9718 dw2_asm_output_data_uleb128 (1, NULL
);
9719 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9722 /* Output the source line number correspondence information. This
9723 information goes into the .debug_line section. */
9726 output_line_info (bool prologue_only
)
9728 char l1
[20], l2
[20], p1
[20], p2
[20];
9729 int ver
= dwarf_version
;
9730 bool saw_one
= false;
9733 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9734 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9735 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9736 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9738 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9739 dw2_asm_output_data (4, 0xffffffff,
9740 "Initial length escape value indicating 64-bit DWARF extension");
9741 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9742 "Length of Source Line Info");
9743 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9745 dw2_asm_output_data (2, ver
, "DWARF Version");
9746 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9747 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9749 /* Define the architecture-dependent minimum instruction length (in bytes).
9750 In this implementation of DWARF, this field is used for information
9751 purposes only. Since GCC generates assembly language, we have no
9752 a priori knowledge of how many instruction bytes are generated for each
9753 source line, and therefore can use only the DW_LNE_set_address and
9754 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9755 this as '1', which is "correct enough" for all architectures,
9756 and don't let the target override. */
9757 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9760 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9761 "Maximum Operations Per Instruction");
9762 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9763 "Default is_stmt_start flag");
9764 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9765 "Line Base Value (Special Opcodes)");
9766 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9767 "Line Range Value (Special Opcodes)");
9768 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9769 "Special Opcode Base");
9771 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9776 case DW_LNS_advance_pc
:
9777 case DW_LNS_advance_line
:
9778 case DW_LNS_set_file
:
9779 case DW_LNS_set_column
:
9780 case DW_LNS_fixed_advance_pc
:
9781 case DW_LNS_set_isa
:
9789 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9793 /* Write out the information about the files we use. */
9794 output_file_names ();
9795 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9798 /* Output the marker for the end of the line number info. */
9799 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9803 if (separate_line_info
)
9805 dw_line_info_table
*table
;
9808 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
9811 output_one_line_info_table (table
);
9815 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9817 output_one_line_info_table (cold_text_section_line_info
);
9821 /* ??? Some Darwin linkers crash on a .debug_line section with no
9822 sequences. Further, merely a DW_LNE_end_sequence entry is not
9823 sufficient -- the address column must also be initialized.
9824 Make sure to output at least one set_address/end_sequence pair,
9825 choosing .text since that section is always present. */
9826 if (text_section_line_info
->in_use
|| !saw_one
)
9827 output_one_line_info_table (text_section_line_info
);
9829 /* Output the marker for the end of the line number info. */
9830 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9833 /* Given a pointer to a tree node for some base type, return a pointer to
9834 a DIE that describes the given type.
9836 This routine must only be called for GCC type nodes that correspond to
9837 Dwarf base (fundamental) types. */
9840 base_type_die (tree type
)
9842 dw_die_ref base_type_result
;
9843 enum dwarf_type encoding
;
9845 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9848 /* If this is a subtype that should not be emitted as a subrange type,
9849 use the base type. See subrange_type_for_debug_p. */
9850 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9851 type
= TREE_TYPE (type
);
9853 switch (TREE_CODE (type
))
9856 if ((dwarf_version
>= 4 || !dwarf_strict
)
9858 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9859 && DECL_IS_BUILTIN (TYPE_NAME (type
))
9860 && DECL_NAME (TYPE_NAME (type
)))
9862 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
9863 if (strcmp (name
, "char16_t") == 0
9864 || strcmp (name
, "char32_t") == 0)
9866 encoding
= DW_ATE_UTF
;
9870 if (TYPE_STRING_FLAG (type
))
9872 if (TYPE_UNSIGNED (type
))
9873 encoding
= DW_ATE_unsigned_char
;
9875 encoding
= DW_ATE_signed_char
;
9877 else if (TYPE_UNSIGNED (type
))
9878 encoding
= DW_ATE_unsigned
;
9880 encoding
= DW_ATE_signed
;
9884 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9886 if (dwarf_version
>= 3 || !dwarf_strict
)
9887 encoding
= DW_ATE_decimal_float
;
9889 encoding
= DW_ATE_lo_user
;
9892 encoding
= DW_ATE_float
;
9895 case FIXED_POINT_TYPE
:
9896 if (!(dwarf_version
>= 3 || !dwarf_strict
))
9897 encoding
= DW_ATE_lo_user
;
9898 else if (TYPE_UNSIGNED (type
))
9899 encoding
= DW_ATE_unsigned_fixed
;
9901 encoding
= DW_ATE_signed_fixed
;
9904 /* Dwarf2 doesn't know anything about complex ints, so use
9905 a user defined type for it. */
9907 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9908 encoding
= DW_ATE_complex_float
;
9910 encoding
= DW_ATE_lo_user
;
9914 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9915 encoding
= DW_ATE_boolean
;
9919 /* No other TREE_CODEs are Dwarf fundamental types. */
9923 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
9925 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9926 int_size_in_bytes (type
));
9927 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9928 add_pubtype (type
, base_type_result
);
9930 return base_type_result
;
9933 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9934 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9937 is_base_type (tree type
)
9939 switch (TREE_CODE (type
))
9945 case FIXED_POINT_TYPE
:
9953 case QUAL_UNION_TYPE
:
9958 case REFERENCE_TYPE
:
9972 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9973 node, return the size in bits for the type if it is a constant, or else
9974 return the alignment for the type if the type's size is not constant, or
9975 else return BITS_PER_WORD if the type actually turns out to be an
9978 static inline unsigned HOST_WIDE_INT
9979 simple_type_size_in_bits (const_tree type
)
9981 if (TREE_CODE (type
) == ERROR_MARK
)
9982 return BITS_PER_WORD
;
9983 else if (TYPE_SIZE (type
) == NULL_TREE
)
9985 else if (host_integerp (TYPE_SIZE (type
), 1))
9986 return tree_low_cst (TYPE_SIZE (type
), 1);
9988 return TYPE_ALIGN (type
);
9991 /* Similarly, but return a double_int instead of UHWI. */
9993 static inline double_int
9994 double_int_type_size_in_bits (const_tree type
)
9996 if (TREE_CODE (type
) == ERROR_MARK
)
9997 return double_int::from_uhwi (BITS_PER_WORD
);
9998 else if (TYPE_SIZE (type
) == NULL_TREE
)
9999 return double_int_zero
;
10000 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10001 return tree_to_double_int (TYPE_SIZE (type
));
10003 return double_int::from_uhwi (TYPE_ALIGN (type
));
10006 /* Given a pointer to a tree node for a subrange type, return a pointer
10007 to a DIE that describes the given type. */
10010 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10012 dw_die_ref subrange_die
;
10013 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10015 if (context_die
== NULL
)
10016 context_die
= comp_unit_die ();
10018 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10020 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10022 /* The size of the subrange type and its base type do not match,
10023 so we need to generate a size attribute for the subrange type. */
10024 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10028 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10030 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10032 return subrange_die
;
10035 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10036 entry that chains various modifiers in front of the given type. */
10039 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10040 dw_die_ref context_die
)
10042 enum tree_code code
= TREE_CODE (type
);
10043 dw_die_ref mod_type_die
;
10044 dw_die_ref sub_die
= NULL
;
10045 tree item_type
= NULL
;
10046 tree qualified_type
;
10047 tree name
, low
, high
;
10048 dw_die_ref mod_scope
;
10050 if (code
== ERROR_MARK
)
10053 /* See if we already have the appropriately qualified variant of
10056 = get_qualified_type (type
,
10057 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10058 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10060 if (qualified_type
== sizetype
10061 && TYPE_NAME (qualified_type
)
10062 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10064 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10066 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10067 && TYPE_PRECISION (t
)
10068 == TYPE_PRECISION (qualified_type
)
10069 && TYPE_UNSIGNED (t
)
10070 == TYPE_UNSIGNED (qualified_type
));
10071 qualified_type
= t
;
10074 /* If we do, then we can just use its DIE, if it exists. */
10075 if (qualified_type
)
10077 mod_type_die
= lookup_type_die (qualified_type
);
10079 return mod_type_die
;
10082 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10084 /* Handle C typedef types. */
10085 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10086 && !DECL_ARTIFICIAL (name
))
10088 tree dtype
= TREE_TYPE (name
);
10090 if (qualified_type
== dtype
)
10092 /* For a named type, use the typedef. */
10093 gen_type_die (qualified_type
, context_die
);
10094 return lookup_type_die (qualified_type
);
10096 else if (is_const_type
< TYPE_READONLY (dtype
)
10097 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10098 || (is_const_type
<= TYPE_READONLY (dtype
)
10099 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10100 && DECL_ORIGINAL_TYPE (name
) != type
))
10101 /* cv-unqualified version of named type. Just use the unnamed
10102 type to which it refers. */
10103 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10104 is_const_type
, is_volatile_type
,
10106 /* Else cv-qualified version of named type; fall through. */
10109 mod_scope
= scope_die_for (type
, context_die
);
10112 /* If both is_const_type and is_volatile_type, prefer the path
10113 which leads to a qualified type. */
10114 && (!is_volatile_type
10115 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10116 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10118 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10119 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10121 else if (is_volatile_type
)
10123 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10124 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10126 else if (code
== POINTER_TYPE
)
10128 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10129 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10130 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10131 item_type
= TREE_TYPE (type
);
10132 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10133 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10134 TYPE_ADDR_SPACE (item_type
));
10136 else if (code
== REFERENCE_TYPE
)
10138 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10139 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10142 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10143 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10144 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10145 item_type
= TREE_TYPE (type
);
10146 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10147 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10148 TYPE_ADDR_SPACE (item_type
));
10150 else if (code
== INTEGER_TYPE
10151 && TREE_TYPE (type
) != NULL_TREE
10152 && subrange_type_for_debug_p (type
, &low
, &high
))
10154 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10155 item_type
= TREE_TYPE (type
);
10157 else if (is_base_type (type
))
10158 mod_type_die
= base_type_die (type
);
10161 gen_type_die (type
, context_die
);
10163 /* We have to get the type_main_variant here (and pass that to the
10164 `lookup_type_die' routine) because the ..._TYPE node we have
10165 might simply be a *copy* of some original type node (where the
10166 copy was created to help us keep track of typedef names) and
10167 that copy might have a different TYPE_UID from the original
10169 if (TREE_CODE (type
) != VECTOR_TYPE
)
10170 return lookup_type_die (type_main_variant (type
));
10172 /* Vectors have the debugging information in the type,
10173 not the main variant. */
10174 return lookup_type_die (type
);
10177 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10178 don't output a DW_TAG_typedef, since there isn't one in the
10179 user's program; just attach a DW_AT_name to the type.
10180 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10181 if the base type already has the same name. */
10183 && ((TREE_CODE (name
) != TYPE_DECL
10184 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10185 || (!is_const_type
&& !is_volatile_type
)))
10186 || (TREE_CODE (name
) == TYPE_DECL
10187 && TREE_TYPE (name
) == qualified_type
10188 && DECL_NAME (name
))))
10190 if (TREE_CODE (name
) == TYPE_DECL
)
10191 /* Could just call add_name_and_src_coords_attributes here,
10192 but since this is a builtin type it doesn't have any
10193 useful source coordinates anyway. */
10194 name
= DECL_NAME (name
);
10195 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10197 /* This probably indicates a bug. */
10198 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10200 name
= TYPE_NAME (type
);
10202 && TREE_CODE (name
) == TYPE_DECL
)
10203 name
= DECL_NAME (name
);
10204 add_name_attribute (mod_type_die
,
10205 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10208 if (qualified_type
)
10209 equate_type_number_to_die (qualified_type
, mod_type_die
);
10212 /* We must do this after the equate_type_number_to_die call, in case
10213 this is a recursive type. This ensures that the modified_type_die
10214 recursion will terminate even if the type is recursive. Recursive
10215 types are possible in Ada. */
10216 sub_die
= modified_type_die (item_type
,
10217 TYPE_READONLY (item_type
),
10218 TYPE_VOLATILE (item_type
),
10221 if (sub_die
!= NULL
)
10222 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10224 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10225 if (TYPE_ARTIFICIAL (type
))
10226 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10228 return mod_type_die
;
10231 /* Generate DIEs for the generic parameters of T.
10232 T must be either a generic type or a generic function.
10233 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10236 gen_generic_params_dies (tree t
)
10240 dw_die_ref die
= NULL
;
10242 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10246 die
= lookup_type_die (t
);
10247 else if (DECL_P (t
))
10248 die
= lookup_decl_die (t
);
10252 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10254 /* T has no generic parameter. It means T is neither a generic type
10255 or function. End of story. */
10258 parms_num
= TREE_VEC_LENGTH (parms
);
10259 args
= lang_hooks
.get_innermost_generic_args (t
);
10260 for (i
= 0; i
< parms_num
; i
++)
10262 tree parm
, arg
, arg_pack_elems
;
10264 parm
= TREE_VEC_ELT (parms
, i
);
10265 arg
= TREE_VEC_ELT (args
, i
);
10266 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10267 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10269 if (parm
&& TREE_VALUE (parm
) && arg
)
10271 /* If PARM represents a template parameter pack,
10272 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10273 by DW_TAG_template_*_parameter DIEs for the argument
10274 pack elements of ARG. Note that ARG would then be
10275 an argument pack. */
10276 if (arg_pack_elems
)
10277 template_parameter_pack_die (TREE_VALUE (parm
),
10281 generic_parameter_die (TREE_VALUE (parm
), arg
,
10282 true /* Emit DW_AT_name */, die
);
10287 /* Create and return a DIE for PARM which should be
10288 the representation of a generic type parameter.
10289 For instance, in the C++ front end, PARM would be a template parameter.
10290 ARG is the argument to PARM.
10291 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10293 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10294 as a child node. */
10297 generic_parameter_die (tree parm
, tree arg
,
10299 dw_die_ref parent_die
)
10301 dw_die_ref tmpl_die
= NULL
;
10302 const char *name
= NULL
;
10304 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10307 /* We support non-type generic parameters and arguments,
10308 type generic parameters and arguments, as well as
10309 generic generic parameters (a.k.a. template template parameters in C++)
10311 if (TREE_CODE (parm
) == PARM_DECL
)
10312 /* PARM is a nontype generic parameter */
10313 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10314 else if (TREE_CODE (parm
) == TYPE_DECL
)
10315 /* PARM is a type generic parameter. */
10316 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10317 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10318 /* PARM is a generic generic parameter.
10319 Its DIE is a GNU extension. It shall have a
10320 DW_AT_name attribute to represent the name of the template template
10321 parameter, and a DW_AT_GNU_template_name attribute to represent the
10322 name of the template template argument. */
10323 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10326 gcc_unreachable ();
10332 /* If PARM is a generic parameter pack, it means we are
10333 emitting debug info for a template argument pack element.
10334 In other terms, ARG is a template argument pack element.
10335 In that case, we don't emit any DW_AT_name attribute for
10339 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10341 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10344 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10346 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10347 TMPL_DIE should have a child DW_AT_type attribute that is set
10348 to the type of the argument to PARM, which is ARG.
10349 If PARM is a type generic parameter, TMPL_DIE should have a
10350 child DW_AT_type that is set to ARG. */
10351 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10352 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10353 TREE_THIS_VOLATILE (tmpl_type
),
10358 /* So TMPL_DIE is a DIE representing a
10359 a generic generic template parameter, a.k.a template template
10360 parameter in C++ and arg is a template. */
10362 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10363 to the name of the argument. */
10364 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10366 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10369 if (TREE_CODE (parm
) == PARM_DECL
)
10370 /* So PARM is a non-type generic parameter.
10371 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10372 attribute of TMPL_DIE which value represents the value
10374 We must be careful here:
10375 The value of ARG might reference some function decls.
10376 We might currently be emitting debug info for a generic
10377 type and types are emitted before function decls, we don't
10378 know if the function decls referenced by ARG will actually be
10379 emitted after cgraph computations.
10380 So must defer the generation of the DW_AT_const_value to
10381 after cgraph is ready. */
10382 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10388 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10389 PARM_PACK must be a template parameter pack. The returned DIE
10390 will be child DIE of PARENT_DIE. */
10393 template_parameter_pack_die (tree parm_pack
,
10394 tree parm_pack_args
,
10395 dw_die_ref parent_die
)
10400 gcc_assert (parent_die
&& parm_pack
);
10402 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10403 add_name_and_src_coords_attributes (die
, parm_pack
);
10404 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10405 generic_parameter_die (parm_pack
,
10406 TREE_VEC_ELT (parm_pack_args
, j
),
10407 false /* Don't emit DW_AT_name */,
10412 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10413 an enumerated type. */
10416 type_is_enum (const_tree type
)
10418 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10421 /* Return the DBX register number described by a given RTL node. */
10423 static unsigned int
10424 dbx_reg_number (const_rtx rtl
)
10426 unsigned regno
= REGNO (rtl
);
10428 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10430 #ifdef LEAF_REG_REMAP
10431 if (crtl
->uses_only_leaf_regs
)
10433 int leaf_reg
= LEAF_REG_REMAP (regno
);
10434 if (leaf_reg
!= -1)
10435 regno
= (unsigned) leaf_reg
;
10439 regno
= DBX_REGISTER_NUMBER (regno
);
10440 gcc_assert (regno
!= INVALID_REGNUM
);
10444 /* Optionally add a DW_OP_piece term to a location description expression.
10445 DW_OP_piece is only added if the location description expression already
10446 doesn't end with DW_OP_piece. */
10449 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10451 dw_loc_descr_ref loc
;
10453 if (*list_head
!= NULL
)
10455 /* Find the end of the chain. */
10456 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10459 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10460 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10464 /* Return a location descriptor that designates a machine register or
10465 zero if there is none. */
10467 static dw_loc_descr_ref
10468 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10472 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10475 /* We only use "frame base" when we're sure we're talking about the
10476 post-prologue local stack frame. We do this by *not* running
10477 register elimination until this point, and recognizing the special
10478 argument pointer and soft frame pointer rtx's.
10479 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10480 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10481 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10483 dw_loc_descr_ref result
= NULL
;
10485 if (dwarf_version
>= 4 || !dwarf_strict
)
10487 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10490 add_loc_descr (&result
,
10491 new_loc_descr (DW_OP_stack_value
, 0, 0));
10496 regs
= targetm
.dwarf_register_span (rtl
);
10498 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10499 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10502 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10503 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10505 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10509 /* Return a location descriptor that designates a machine register for
10510 a given hard register number. */
10512 static dw_loc_descr_ref
10513 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10515 dw_loc_descr_ref reg_loc_descr
;
10519 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10521 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10523 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10524 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10526 return reg_loc_descr
;
10529 /* Given an RTL of a register, return a location descriptor that
10530 designates a value that spans more than one register. */
10532 static dw_loc_descr_ref
10533 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10534 enum var_init_status initialized
)
10536 int nregs
, size
, i
;
10538 dw_loc_descr_ref loc_result
= NULL
;
10541 #ifdef LEAF_REG_REMAP
10542 if (crtl
->uses_only_leaf_regs
)
10544 int leaf_reg
= LEAF_REG_REMAP (reg
);
10545 if (leaf_reg
!= -1)
10546 reg
= (unsigned) leaf_reg
;
10549 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10550 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10552 /* Simple, contiguous registers. */
10553 if (regs
== NULL_RTX
)
10555 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10560 dw_loc_descr_ref t
;
10562 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10563 VAR_INIT_STATUS_INITIALIZED
);
10564 add_loc_descr (&loc_result
, t
);
10565 add_loc_descr_op_piece (&loc_result
, size
);
10571 /* Now onto stupid register sets in non contiguous locations. */
10573 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10575 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10578 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10580 dw_loc_descr_ref t
;
10582 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
10583 VAR_INIT_STATUS_INITIALIZED
);
10584 add_loc_descr (&loc_result
, t
);
10585 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10586 add_loc_descr_op_piece (&loc_result
, size
);
10589 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10590 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10594 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10596 /* Return a location descriptor that designates a constant i,
10597 as a compound operation from constant (i >> shift), constant shift
10600 static dw_loc_descr_ref
10601 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10603 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10604 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10605 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10609 /* Return a location descriptor that designates a constant. */
10611 static dw_loc_descr_ref
10612 int_loc_descriptor (HOST_WIDE_INT i
)
10614 enum dwarf_location_atom op
;
10616 /* Pick the smallest representation of a constant, rather than just
10617 defaulting to the LEB encoding. */
10620 int clz
= clz_hwi (i
);
10621 int ctz
= ctz_hwi (i
);
10623 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10624 else if (i
<= 0xff)
10625 op
= DW_OP_const1u
;
10626 else if (i
<= 0xffff)
10627 op
= DW_OP_const2u
;
10628 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10629 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10630 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10631 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10632 while DW_OP_const4u is 5 bytes. */
10633 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10634 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10635 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10636 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10637 while DW_OP_const4u is 5 bytes. */
10638 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10639 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10640 op
= DW_OP_const4u
;
10641 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10642 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10643 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10644 while DW_OP_constu of constant >= 0x100000000 takes at least
10646 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10647 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10648 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10649 >= HOST_BITS_PER_WIDE_INT
)
10650 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10651 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10652 while DW_OP_constu takes in this case at least 6 bytes. */
10653 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10654 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10655 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10656 && size_of_uleb128 (i
) > 6)
10657 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10658 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10665 op
= DW_OP_const1s
;
10666 else if (i
>= -0x8000)
10667 op
= DW_OP_const2s
;
10668 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10670 if (size_of_int_loc_descriptor (i
) < 5)
10672 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10673 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10676 op
= DW_OP_const4s
;
10680 if (size_of_int_loc_descriptor (i
)
10681 < (unsigned long) 1 + size_of_sleb128 (i
))
10683 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10684 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10691 return new_loc_descr (op
, i
, 0);
10694 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10695 without actually allocating it. */
10697 static unsigned long
10698 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10700 return size_of_int_loc_descriptor (i
>> shift
)
10701 + size_of_int_loc_descriptor (shift
)
10705 /* Return size_of_locs (int_loc_descriptor (i)) without
10706 actually allocating it. */
10708 static unsigned long
10709 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10718 else if (i
<= 0xff)
10720 else if (i
<= 0xffff)
10724 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10725 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10726 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10728 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10729 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10730 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10732 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10734 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10735 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10736 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10737 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10739 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10740 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10741 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10743 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10744 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10746 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10755 else if (i
>= -0x8000)
10757 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10759 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10761 s
= size_of_int_loc_descriptor (-i
) + 1;
10769 unsigned long r
= 1 + size_of_sleb128 (i
);
10770 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10772 s
= size_of_int_loc_descriptor (-i
) + 1;
10781 /* Return loc description representing "address" of integer value.
10782 This can appear only as toplevel expression. */
10784 static dw_loc_descr_ref
10785 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10788 dw_loc_descr_ref loc_result
= NULL
;
10790 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10793 litsize
= size_of_int_loc_descriptor (i
);
10794 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10795 is more compact. For DW_OP_stack_value we need:
10796 litsize + 1 (DW_OP_stack_value)
10797 and for DW_OP_implicit_value:
10798 1 (DW_OP_implicit_value) + 1 (length) + size. */
10799 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10801 loc_result
= int_loc_descriptor (i
);
10802 add_loc_descr (&loc_result
,
10803 new_loc_descr (DW_OP_stack_value
, 0, 0));
10807 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10809 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10810 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10814 /* Return a location descriptor that designates a base+offset location. */
10816 static dw_loc_descr_ref
10817 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10818 enum var_init_status initialized
)
10820 unsigned int regno
;
10821 dw_loc_descr_ref result
;
10822 dw_fde_ref fde
= cfun
->fde
;
10824 /* We only use "frame base" when we're sure we're talking about the
10825 post-prologue local stack frame. We do this by *not* running
10826 register elimination until this point, and recognizing the special
10827 argument pointer and soft frame pointer rtx's. */
10828 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10830 rtx elim
= (ira_use_lra_p
10831 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
10832 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
10836 if (GET_CODE (elim
) == PLUS
)
10838 offset
+= INTVAL (XEXP (elim
, 1));
10839 elim
= XEXP (elim
, 0);
10841 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10842 && (elim
== hard_frame_pointer_rtx
10843 || elim
== stack_pointer_rtx
))
10844 || elim
== (frame_pointer_needed
10845 ? hard_frame_pointer_rtx
10846 : stack_pointer_rtx
));
10848 /* If drap register is used to align stack, use frame
10849 pointer + offset to access stack variables. If stack
10850 is aligned without drap, use stack pointer + offset to
10851 access stack variables. */
10852 if (crtl
->stack_realign_tried
10853 && reg
== frame_pointer_rtx
)
10856 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10857 ? HARD_FRAME_POINTER_REGNUM
10859 return new_reg_loc_descr (base_reg
, offset
);
10862 gcc_assert (frame_pointer_fb_offset_valid
);
10863 offset
+= frame_pointer_fb_offset
;
10864 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10868 regno
= REGNO (reg
);
10869 #ifdef LEAF_REG_REMAP
10870 if (crtl
->uses_only_leaf_regs
)
10872 int leaf_reg
= LEAF_REG_REMAP (regno
);
10873 if (leaf_reg
!= -1)
10874 regno
= (unsigned) leaf_reg
;
10877 regno
= DWARF_FRAME_REGNUM (regno
);
10879 if (!optimize
&& fde
10880 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
10882 /* Use cfa+offset to represent the location of arguments passed
10883 on the stack when drap is used to align stack.
10884 Only do this when not optimizing, for optimized code var-tracking
10885 is supposed to track where the arguments live and the register
10886 used as vdrap or drap in some spot might be used for something
10887 else in other part of the routine. */
10888 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10892 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10895 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10897 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10898 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10903 /* Return true if this RTL expression describes a base+offset calculation. */
10906 is_based_loc (const_rtx rtl
)
10908 return (GET_CODE (rtl
) == PLUS
10909 && ((REG_P (XEXP (rtl
, 0))
10910 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
10911 && CONST_INT_P (XEXP (rtl
, 1)))));
10914 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10917 static dw_loc_descr_ref
10918 tls_mem_loc_descriptor (rtx mem
)
10921 dw_loc_descr_ref loc_result
;
10923 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
10926 base
= get_base_address (MEM_EXPR (mem
));
10928 || TREE_CODE (base
) != VAR_DECL
10929 || !DECL_THREAD_LOCAL_P (base
))
10932 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
10933 if (loc_result
== NULL
)
10936 if (MEM_OFFSET (mem
))
10937 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
10942 /* Output debug info about reason why we failed to expand expression as dwarf
10946 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
10948 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
10950 fprintf (dump_file
, "Failed to expand as dwarf: ");
10952 print_generic_expr (dump_file
, expr
, dump_flags
);
10955 fprintf (dump_file
, "\n");
10956 print_rtl (dump_file
, rtl
);
10958 fprintf (dump_file
, "\nReason: %s\n", reason
);
10962 /* Helper function for const_ok_for_output, called either directly
10963 or via for_each_rtx. */
10966 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
10970 if (GET_CODE (rtl
) == UNSPEC
)
10972 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10973 we can't express it in the debug info. */
10974 #ifdef ENABLE_CHECKING
10975 /* Don't complain about TLS UNSPECs, those are just too hard to
10976 delegitimize. Note this could be a non-decl SYMBOL_REF such as
10977 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
10978 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
10979 if (XVECLEN (rtl
, 0) == 0
10980 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
10981 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
10982 inform (current_function_decl
10983 ? DECL_SOURCE_LOCATION (current_function_decl
)
10984 : UNKNOWN_LOCATION
,
10985 #if NUM_UNSPEC_VALUES > 0
10986 "non-delegitimized UNSPEC %s (%d) found in variable location",
10987 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
10988 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
10991 "non-delegitimized UNSPEC %d found in variable location",
10995 expansion_failed (NULL_TREE
, rtl
,
10996 "UNSPEC hasn't been delegitimized.\n");
11000 if (targetm
.const_not_ok_for_debug_p (rtl
))
11002 expansion_failed (NULL_TREE
, rtl
,
11003 "Expression rejected for debug by the backend.\n");
11007 if (GET_CODE (rtl
) != SYMBOL_REF
)
11010 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11013 get_pool_constant_mark (rtl
, &marked
);
11014 /* If all references to this pool constant were optimized away,
11015 it was not output and thus we can't represent it. */
11018 expansion_failed (NULL_TREE
, rtl
,
11019 "Constant was removed from constant pool.\n");
11024 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11027 /* Avoid references to external symbols in debug info, on several targets
11028 the linker might even refuse to link when linking a shared library,
11029 and in many other cases the relocations for .debug_info/.debug_loc are
11030 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11031 to be defined within the same shared library or executable are fine. */
11032 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11034 tree decl
= SYMBOL_REF_DECL (rtl
);
11036 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11038 expansion_failed (NULL_TREE
, rtl
,
11039 "Symbol not defined in current TU.\n");
11047 /* Return true if constant RTL can be emitted in DW_OP_addr or
11048 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11049 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11052 const_ok_for_output (rtx rtl
)
11054 if (GET_CODE (rtl
) == SYMBOL_REF
)
11055 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11057 if (GET_CODE (rtl
) == CONST
)
11058 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11063 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11064 if possible, NULL otherwise. */
11067 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11069 dw_die_ref type_die
;
11070 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11074 switch (TREE_CODE (type
))
11082 type_die
= lookup_type_die (type
);
11084 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11085 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11090 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11091 type matching MODE, or, if MODE is narrower than or as wide as
11092 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11095 static dw_loc_descr_ref
11096 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11098 enum machine_mode outer_mode
= mode
;
11099 dw_die_ref type_die
;
11100 dw_loc_descr_ref cvt
;
11102 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11104 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11107 type_die
= base_type_for_mode (outer_mode
, 1);
11108 if (type_die
== NULL
)
11110 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11111 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11112 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11113 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11114 add_loc_descr (&op
, cvt
);
11118 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11120 static dw_loc_descr_ref
11121 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11122 dw_loc_descr_ref op1
)
11124 dw_loc_descr_ref ret
= op0
;
11125 add_loc_descr (&ret
, op1
);
11126 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11127 if (STORE_FLAG_VALUE
!= 1)
11129 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11130 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11135 /* Return location descriptor for signed comparison OP RTL. */
11137 static dw_loc_descr_ref
11138 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11139 enum machine_mode mem_mode
)
11141 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11142 dw_loc_descr_ref op0
, op1
;
11145 if (op_mode
== VOIDmode
)
11146 op_mode
= GET_MODE (XEXP (rtl
, 1));
11147 if (op_mode
== VOIDmode
)
11151 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11152 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11155 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11156 VAR_INIT_STATUS_INITIALIZED
);
11157 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11158 VAR_INIT_STATUS_INITIALIZED
);
11160 if (op0
== NULL
|| op1
== NULL
)
11163 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11164 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11165 return compare_loc_descriptor (op
, op0
, op1
);
11167 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11169 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11170 dw_loc_descr_ref cvt
;
11172 if (type_die
== NULL
)
11174 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11175 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11176 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11177 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11178 add_loc_descr (&op0
, cvt
);
11179 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11180 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11181 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11182 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11183 add_loc_descr (&op1
, cvt
);
11184 return compare_loc_descriptor (op
, op0
, op1
);
11187 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11188 /* For eq/ne, if the operands are known to be zero-extended,
11189 there is no need to do the fancy shifting up. */
11190 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11192 dw_loc_descr_ref last0
, last1
;
11193 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11195 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11197 /* deref_size zero extends, and for constants we can check
11198 whether they are zero extended or not. */
11199 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11200 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11201 || (CONST_INT_P (XEXP (rtl
, 0))
11202 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11203 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11204 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11205 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11206 || (CONST_INT_P (XEXP (rtl
, 1))
11207 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11208 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11209 return compare_loc_descriptor (op
, op0
, op1
);
11211 /* EQ/NE comparison against constant in narrower type than
11212 DWARF2_ADDR_SIZE can be performed either as
11213 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11216 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11217 DW_OP_{eq,ne}. Pick whatever is shorter. */
11218 if (CONST_INT_P (XEXP (rtl
, 1))
11219 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11220 && (size_of_int_loc_descriptor (shift
) + 1
11221 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11222 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11223 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11224 & GET_MODE_MASK (op_mode
))))
11226 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11227 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11228 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11229 & GET_MODE_MASK (op_mode
));
11230 return compare_loc_descriptor (op
, op0
, op1
);
11233 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11234 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11235 if (CONST_INT_P (XEXP (rtl
, 1)))
11236 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11239 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11240 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11242 return compare_loc_descriptor (op
, op0
, op1
);
11245 /* Return location descriptor for unsigned comparison OP RTL. */
11247 static dw_loc_descr_ref
11248 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11249 enum machine_mode mem_mode
)
11251 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11252 dw_loc_descr_ref op0
, op1
;
11254 if (op_mode
== VOIDmode
)
11255 op_mode
= GET_MODE (XEXP (rtl
, 1));
11256 if (op_mode
== VOIDmode
)
11258 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11261 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11264 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11265 VAR_INIT_STATUS_INITIALIZED
);
11266 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11267 VAR_INIT_STATUS_INITIALIZED
);
11269 if (op0
== NULL
|| op1
== NULL
)
11272 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11274 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11275 dw_loc_descr_ref last0
, last1
;
11276 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11278 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11280 if (CONST_INT_P (XEXP (rtl
, 0)))
11281 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11282 /* deref_size zero extends, so no need to mask it again. */
11283 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11284 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11286 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11287 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11289 if (CONST_INT_P (XEXP (rtl
, 1)))
11290 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11291 /* deref_size zero extends, so no need to mask it again. */
11292 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11293 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11295 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11296 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11299 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11301 HOST_WIDE_INT bias
= 1;
11302 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11303 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11304 if (CONST_INT_P (XEXP (rtl
, 1)))
11305 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11306 + INTVAL (XEXP (rtl
, 1)));
11308 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11311 return compare_loc_descriptor (op
, op0
, op1
);
11314 /* Return location descriptor for {U,S}{MIN,MAX}. */
11316 static dw_loc_descr_ref
11317 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11318 enum machine_mode mem_mode
)
11320 enum dwarf_location_atom op
;
11321 dw_loc_descr_ref op0
, op1
, ret
;
11322 dw_loc_descr_ref bra_node
, drop_node
;
11325 && (GET_MODE_CLASS (mode
) != MODE_INT
11326 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11329 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11330 VAR_INIT_STATUS_INITIALIZED
);
11331 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11332 VAR_INIT_STATUS_INITIALIZED
);
11334 if (op0
== NULL
|| op1
== NULL
)
11337 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11338 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11339 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11340 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11342 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11344 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11345 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11346 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11347 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11348 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11350 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11352 HOST_WIDE_INT bias
= 1;
11353 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11354 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11355 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11358 else if (GET_MODE_CLASS (mode
) == MODE_INT
11359 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11361 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11362 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11363 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11364 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11365 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11367 else if (GET_MODE_CLASS (mode
) == MODE_INT
11368 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11370 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11371 dw_loc_descr_ref cvt
;
11372 if (type_die
== NULL
)
11374 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11375 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11376 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11377 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11378 add_loc_descr (&op0
, cvt
);
11379 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11380 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11381 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11382 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11383 add_loc_descr (&op1
, cvt
);
11386 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11391 add_loc_descr (&ret
, op1
);
11392 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11393 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11394 add_loc_descr (&ret
, bra_node
);
11395 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11396 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11397 add_loc_descr (&ret
, drop_node
);
11398 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11399 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11400 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11401 && GET_MODE_CLASS (mode
) == MODE_INT
11402 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11403 ret
= convert_descriptor_to_mode (mode
, ret
);
11407 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11408 but after converting arguments to type_die, afterwards
11409 convert back to unsigned. */
11411 static dw_loc_descr_ref
11412 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11413 enum machine_mode mode
, enum machine_mode mem_mode
)
11415 dw_loc_descr_ref cvt
, op0
, op1
;
11417 if (type_die
== NULL
)
11419 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11420 VAR_INIT_STATUS_INITIALIZED
);
11421 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11422 VAR_INIT_STATUS_INITIALIZED
);
11423 if (op0
== NULL
|| op1
== NULL
)
11425 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11426 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11427 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11428 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11429 add_loc_descr (&op0
, cvt
);
11430 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11431 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11432 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11433 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11434 add_loc_descr (&op1
, cvt
);
11435 add_loc_descr (&op0
, op1
);
11436 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11437 return convert_descriptor_to_mode (mode
, op0
);
11440 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11441 const0 is DW_OP_lit0 or corresponding typed constant,
11442 const1 is DW_OP_lit1 or corresponding typed constant
11443 and constMSB is constant with just the MSB bit set
11445 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11446 L1: const0 DW_OP_swap
11447 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11448 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11453 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11454 L1: const0 DW_OP_swap
11455 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11456 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11461 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11462 L1: const1 DW_OP_swap
11463 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11464 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11468 static dw_loc_descr_ref
11469 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11470 enum machine_mode mem_mode
)
11472 dw_loc_descr_ref op0
, ret
, tmp
;
11473 HOST_WIDE_INT valv
;
11474 dw_loc_descr_ref l1jump
, l1label
;
11475 dw_loc_descr_ref l2jump
, l2label
;
11476 dw_loc_descr_ref l3jump
, l3label
;
11477 dw_loc_descr_ref l4jump
, l4label
;
11480 if (GET_MODE_CLASS (mode
) != MODE_INT
11481 || GET_MODE (XEXP (rtl
, 0)) != mode
11482 || (GET_CODE (rtl
) == CLZ
11483 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11486 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11487 VAR_INIT_STATUS_INITIALIZED
);
11491 if (GET_CODE (rtl
) == CLZ
)
11493 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11494 valv
= GET_MODE_BITSIZE (mode
);
11496 else if (GET_CODE (rtl
) == FFS
)
11498 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11499 valv
= GET_MODE_BITSIZE (mode
);
11500 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11501 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11502 add_loc_descr (&ret
, l1jump
);
11503 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11504 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11505 VAR_INIT_STATUS_INITIALIZED
);
11508 add_loc_descr (&ret
, tmp
);
11509 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11510 add_loc_descr (&ret
, l4jump
);
11511 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11512 ? const1_rtx
: const0_rtx
,
11514 VAR_INIT_STATUS_INITIALIZED
);
11515 if (l1label
== NULL
)
11517 add_loc_descr (&ret
, l1label
);
11518 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11519 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11520 add_loc_descr (&ret
, l2label
);
11521 if (GET_CODE (rtl
) != CLZ
)
11523 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11524 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11525 << (GET_MODE_BITSIZE (mode
) - 1));
11527 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11528 << (GET_MODE_BITSIZE (mode
)
11529 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11530 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11531 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11532 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11533 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11535 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11536 VAR_INIT_STATUS_INITIALIZED
);
11539 add_loc_descr (&ret
, tmp
);
11540 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11541 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11542 add_loc_descr (&ret
, l3jump
);
11543 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11544 VAR_INIT_STATUS_INITIALIZED
);
11547 add_loc_descr (&ret
, tmp
);
11548 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11549 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11550 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11551 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11552 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11553 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11554 add_loc_descr (&ret
, l2jump
);
11555 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11556 add_loc_descr (&ret
, l3label
);
11557 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11558 add_loc_descr (&ret
, l4label
);
11559 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11560 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11561 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11562 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11563 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11564 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11565 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11566 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11570 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11571 const1 is DW_OP_lit1 or corresponding typed constant):
11573 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11574 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11578 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11579 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11582 static dw_loc_descr_ref
11583 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11584 enum machine_mode mem_mode
)
11586 dw_loc_descr_ref op0
, ret
, tmp
;
11587 dw_loc_descr_ref l1jump
, l1label
;
11588 dw_loc_descr_ref l2jump
, l2label
;
11590 if (GET_MODE_CLASS (mode
) != MODE_INT
11591 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11594 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11595 VAR_INIT_STATUS_INITIALIZED
);
11599 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11600 VAR_INIT_STATUS_INITIALIZED
);
11603 add_loc_descr (&ret
, tmp
);
11604 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11605 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11606 add_loc_descr (&ret
, l1label
);
11607 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11608 add_loc_descr (&ret
, l2jump
);
11609 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11610 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11611 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11612 VAR_INIT_STATUS_INITIALIZED
);
11615 add_loc_descr (&ret
, tmp
);
11616 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11617 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11618 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11619 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11620 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11621 VAR_INIT_STATUS_INITIALIZED
);
11622 add_loc_descr (&ret
, tmp
);
11623 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11624 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11625 add_loc_descr (&ret
, l1jump
);
11626 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11627 add_loc_descr (&ret
, l2label
);
11628 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11629 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11630 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11631 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11635 /* BSWAP (constS is initial shift count, either 56 or 24):
11637 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11638 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11639 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11640 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11641 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11643 static dw_loc_descr_ref
11644 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11645 enum machine_mode mem_mode
)
11647 dw_loc_descr_ref op0
, ret
, tmp
;
11648 dw_loc_descr_ref l1jump
, l1label
;
11649 dw_loc_descr_ref l2jump
, l2label
;
11651 if (GET_MODE_CLASS (mode
) != MODE_INT
11652 || BITS_PER_UNIT
!= 8
11653 || (GET_MODE_BITSIZE (mode
) != 32
11654 && GET_MODE_BITSIZE (mode
) != 64))
11657 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11658 VAR_INIT_STATUS_INITIALIZED
);
11663 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11665 VAR_INIT_STATUS_INITIALIZED
);
11668 add_loc_descr (&ret
, tmp
);
11669 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11670 VAR_INIT_STATUS_INITIALIZED
);
11673 add_loc_descr (&ret
, tmp
);
11674 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11675 add_loc_descr (&ret
, l1label
);
11676 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11678 VAR_INIT_STATUS_INITIALIZED
);
11679 add_loc_descr (&ret
, tmp
);
11680 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11681 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11682 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11683 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11684 VAR_INIT_STATUS_INITIALIZED
);
11687 add_loc_descr (&ret
, tmp
);
11688 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11689 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11690 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11691 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11692 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11693 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11694 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11695 VAR_INIT_STATUS_INITIALIZED
);
11696 add_loc_descr (&ret
, tmp
);
11697 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11698 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11699 add_loc_descr (&ret
, l2jump
);
11700 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11701 VAR_INIT_STATUS_INITIALIZED
);
11702 add_loc_descr (&ret
, tmp
);
11703 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11704 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11705 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11706 add_loc_descr (&ret
, l1jump
);
11707 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11708 add_loc_descr (&ret
, l2label
);
11709 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11710 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11711 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11712 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11713 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11714 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11718 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11719 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11720 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11721 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11723 ROTATERT is similar:
11724 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11725 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11726 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11728 static dw_loc_descr_ref
11729 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11730 enum machine_mode mem_mode
)
11732 rtx rtlop1
= XEXP (rtl
, 1);
11733 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11736 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11739 if (GET_MODE (rtlop1
) != VOIDmode
11740 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11741 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11742 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11743 VAR_INIT_STATUS_INITIALIZED
);
11744 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11745 VAR_INIT_STATUS_INITIALIZED
);
11746 if (op0
== NULL
|| op1
== NULL
)
11748 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11749 for (i
= 0; i
< 2; i
++)
11751 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11752 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11754 VAR_INIT_STATUS_INITIALIZED
);
11755 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11756 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11758 : HOST_BITS_PER_WIDE_INT
== 64
11759 ? DW_OP_const8u
: DW_OP_constu
,
11760 GET_MODE_MASK (mode
), 0);
11763 if (mask
[i
] == NULL
)
11765 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11768 add_loc_descr (&ret
, op1
);
11769 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11770 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11771 if (GET_CODE (rtl
) == ROTATERT
)
11773 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11774 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11775 GET_MODE_BITSIZE (mode
), 0));
11777 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11778 if (mask
[0] != NULL
)
11779 add_loc_descr (&ret
, mask
[0]);
11780 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11781 if (mask
[1] != NULL
)
11783 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11784 add_loc_descr (&ret
, mask
[1]);
11785 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11787 if (GET_CODE (rtl
) == ROTATE
)
11789 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11790 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11791 GET_MODE_BITSIZE (mode
), 0));
11793 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11794 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11798 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11799 for DEBUG_PARAMETER_REF RTL. */
11801 static dw_loc_descr_ref
11802 parameter_ref_descriptor (rtx rtl
)
11804 dw_loc_descr_ref ret
;
11809 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11810 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11811 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11814 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11815 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11816 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11820 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11821 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11826 /* The following routine converts the RTL for a variable or parameter
11827 (resident in memory) into an equivalent Dwarf representation of a
11828 mechanism for getting the address of that same variable onto the top of a
11829 hypothetical "address evaluation" stack.
11831 When creating memory location descriptors, we are effectively transforming
11832 the RTL for a memory-resident object into its Dwarf postfix expression
11833 equivalent. This routine recursively descends an RTL tree, turning
11834 it into Dwarf postfix code as it goes.
11836 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11838 MEM_MODE is the mode of the memory reference, needed to handle some
11839 autoincrement addressing modes.
11841 Return 0 if we can't represent the location. */
11844 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11845 enum machine_mode mem_mode
,
11846 enum var_init_status initialized
)
11848 dw_loc_descr_ref mem_loc_result
= NULL
;
11849 enum dwarf_location_atom op
;
11850 dw_loc_descr_ref op0
, op1
;
11851 rtx inner
= NULL_RTX
;
11853 if (mode
== VOIDmode
)
11854 mode
= GET_MODE (rtl
);
11856 /* Note that for a dynamically sized array, the location we will generate a
11857 description of here will be the lowest numbered location which is
11858 actually within the array. That's *not* necessarily the same as the
11859 zeroth element of the array. */
11861 rtl
= targetm
.delegitimize_address (rtl
);
11863 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11866 switch (GET_CODE (rtl
))
11871 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11874 /* The case of a subreg may arise when we have a local (register)
11875 variable or a formal (register) parameter which doesn't quite fill
11876 up an entire register. For now, just assume that it is
11877 legitimate to make the Dwarf info refer to the whole register which
11878 contains the given subreg. */
11879 if (!subreg_lowpart_p (rtl
))
11881 inner
= SUBREG_REG (rtl
);
11883 if (inner
== NULL_RTX
)
11884 inner
= XEXP (rtl
, 0);
11885 if (GET_MODE_CLASS (mode
) == MODE_INT
11886 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
11887 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11888 #ifdef POINTERS_EXTEND_UNSIGNED
11889 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
11892 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
11894 mem_loc_result
= mem_loc_descriptor (inner
,
11896 mem_mode
, initialized
);
11901 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
11903 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
11904 && (GET_MODE_CLASS (mode
) != MODE_INT
11905 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
11909 dw_die_ref type_die
;
11910 dw_loc_descr_ref cvt
;
11912 mem_loc_result
= mem_loc_descriptor (inner
,
11914 mem_mode
, initialized
);
11915 if (mem_loc_result
== NULL
)
11917 type_die
= base_type_for_mode (mode
,
11918 GET_MODE_CLASS (mode
) == MODE_INT
);
11919 if (type_die
== NULL
)
11921 mem_loc_result
= NULL
;
11924 if (GET_MODE_SIZE (mode
)
11925 != GET_MODE_SIZE (GET_MODE (inner
)))
11926 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11928 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
11929 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11930 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11931 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11932 add_loc_descr (&mem_loc_result
, cvt
);
11937 if (GET_MODE_CLASS (mode
) != MODE_INT
11938 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11939 && rtl
!= arg_pointer_rtx
11940 && rtl
!= frame_pointer_rtx
11941 #ifdef POINTERS_EXTEND_UNSIGNED
11942 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11946 dw_die_ref type_die
;
11947 unsigned int dbx_regnum
;
11951 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
11953 type_die
= base_type_for_mode (mode
,
11954 GET_MODE_CLASS (mode
) == MODE_INT
);
11955 if (type_die
== NULL
)
11958 dbx_regnum
= dbx_reg_number (rtl
);
11959 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11961 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
11963 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11964 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11965 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11968 /* Whenever a register number forms a part of the description of the
11969 method for calculating the (dynamic) address of a memory resident
11970 object, DWARF rules require the register number be referred to as
11971 a "base register". This distinction is not based in any way upon
11972 what category of register the hardware believes the given register
11973 belongs to. This is strictly DWARF terminology we're dealing with
11974 here. Note that in cases where the location of a memory-resident
11975 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
11976 OP_CONST (0)) the actual DWARF location descriptor that we generate
11977 may just be OP_BASEREG (basereg). This may look deceptively like
11978 the object in question was allocated to a register (rather than in
11979 memory) so DWARF consumers need to be aware of the subtle
11980 distinction between OP_REG and OP_BASEREG. */
11981 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
11982 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
11983 else if (stack_realign_drap
11985 && crtl
->args
.internal_arg_pointer
== rtl
11986 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
11988 /* If RTL is internal_arg_pointer, which has been optimized
11989 out, use DRAP instead. */
11990 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
11991 VAR_INIT_STATUS_INITIALIZED
);
11997 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11999 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12000 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12003 else if (GET_CODE (rtl
) == ZERO_EXTEND
12004 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12005 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12006 < HOST_BITS_PER_WIDE_INT
12007 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12008 to expand zero extend as two shifts instead of
12010 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12012 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12013 mem_loc_result
= op0
;
12014 add_loc_descr (&mem_loc_result
,
12015 int_loc_descriptor (GET_MODE_MASK (imode
)));
12016 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12018 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12020 int shift
= DWARF2_ADDR_SIZE
12021 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12022 shift
*= BITS_PER_UNIT
;
12023 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12027 mem_loc_result
= op0
;
12028 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12029 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12030 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12031 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12033 else if (!dwarf_strict
)
12035 dw_die_ref type_die1
, type_die2
;
12036 dw_loc_descr_ref cvt
;
12038 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12039 GET_CODE (rtl
) == ZERO_EXTEND
);
12040 if (type_die1
== NULL
)
12042 type_die2
= base_type_for_mode (mode
, 1);
12043 if (type_die2
== NULL
)
12045 mem_loc_result
= op0
;
12046 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12047 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12048 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12049 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12050 add_loc_descr (&mem_loc_result
, cvt
);
12051 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12052 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12053 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12054 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12055 add_loc_descr (&mem_loc_result
, cvt
);
12061 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12062 if (new_rtl
!= rtl
)
12064 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12066 if (mem_loc_result
!= NULL
)
12067 return mem_loc_result
;
12070 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12071 get_address_mode (rtl
), mode
,
12072 VAR_INIT_STATUS_INITIALIZED
);
12073 if (mem_loc_result
== NULL
)
12074 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12075 if (mem_loc_result
!= NULL
)
12077 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12078 || GET_MODE_CLASS (mode
) != MODE_INT
)
12080 dw_die_ref type_die
;
12081 dw_loc_descr_ref deref
;
12086 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12087 if (type_die
== NULL
)
12089 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12090 GET_MODE_SIZE (mode
), 0);
12091 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12092 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12093 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12094 add_loc_descr (&mem_loc_result
, deref
);
12096 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12097 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12099 add_loc_descr (&mem_loc_result
,
12100 new_loc_descr (DW_OP_deref_size
,
12101 GET_MODE_SIZE (mode
), 0));
12106 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12109 /* Some ports can transform a symbol ref into a label ref, because
12110 the symbol ref is too far away and has to be dumped into a constant
12114 if (GET_MODE_CLASS (mode
) != MODE_INT
12115 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12116 #ifdef POINTERS_EXTEND_UNSIGNED
12117 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12121 if (GET_CODE (rtl
) == SYMBOL_REF
12122 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12124 dw_loc_descr_ref temp
;
12126 /* If this is not defined, we have no way to emit the data. */
12127 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12130 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12132 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12133 add_loc_descr (&mem_loc_result
, temp
);
12138 if (!const_ok_for_output (rtl
))
12142 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12143 vec_safe_push (used_rtx_array
, rtl
);
12149 case DEBUG_IMPLICIT_PTR
:
12150 expansion_failed (NULL_TREE
, rtl
,
12151 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12157 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12159 if (GET_MODE_CLASS (mode
) != MODE_INT
12160 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12161 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12162 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12165 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12166 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12168 op0
= one_reg_loc_descriptor (dbx_regnum
,
12169 VAR_INIT_STATUS_INITIALIZED
);
12172 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12173 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12175 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12176 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12177 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12181 gcc_unreachable ();
12184 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12185 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12186 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12189 case DEBUG_PARAMETER_REF
:
12190 mem_loc_result
= parameter_ref_descriptor (rtl
);
12194 /* Extract the PLUS expression nested inside and fall into
12195 PLUS code below. */
12196 rtl
= XEXP (rtl
, 1);
12201 /* Turn these into a PLUS expression and fall into the PLUS code
12203 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12204 GEN_INT (GET_CODE (rtl
) == PRE_INC
12205 ? GET_MODE_UNIT_SIZE (mem_mode
)
12206 : -GET_MODE_UNIT_SIZE (mem_mode
)));
12208 /* ... fall through ... */
12212 if (is_based_loc (rtl
)
12213 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12214 || XEXP (rtl
, 0) == arg_pointer_rtx
12215 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12216 && GET_MODE_CLASS (mode
) == MODE_INT
)
12217 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12218 INTVAL (XEXP (rtl
, 1)),
12219 VAR_INIT_STATUS_INITIALIZED
);
12222 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12223 VAR_INIT_STATUS_INITIALIZED
);
12224 if (mem_loc_result
== 0)
12227 if (CONST_INT_P (XEXP (rtl
, 1))
12228 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12229 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12232 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12233 VAR_INIT_STATUS_INITIALIZED
);
12236 add_loc_descr (&mem_loc_result
, op1
);
12237 add_loc_descr (&mem_loc_result
,
12238 new_loc_descr (DW_OP_plus
, 0, 0));
12243 /* If a pseudo-reg is optimized away, it is possible for it to
12244 be replaced with a MEM containing a multiply or shift. */
12255 && GET_MODE_CLASS (mode
) == MODE_INT
12256 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12258 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12259 base_type_for_mode (mode
, 0),
12283 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12285 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12286 VAR_INIT_STATUS_INITIALIZED
);
12288 rtx rtlop1
= XEXP (rtl
, 1);
12289 if (GET_MODE (rtlop1
) != VOIDmode
12290 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12291 < GET_MODE_BITSIZE (mode
))
12292 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12293 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12294 VAR_INIT_STATUS_INITIALIZED
);
12297 if (op0
== 0 || op1
== 0)
12300 mem_loc_result
= op0
;
12301 add_loc_descr (&mem_loc_result
, op1
);
12302 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12318 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12319 VAR_INIT_STATUS_INITIALIZED
);
12320 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12321 VAR_INIT_STATUS_INITIALIZED
);
12323 if (op0
== 0 || op1
== 0)
12326 mem_loc_result
= op0
;
12327 add_loc_descr (&mem_loc_result
, op1
);
12328 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12332 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12334 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12335 base_type_for_mode (mode
, 0),
12340 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12341 VAR_INIT_STATUS_INITIALIZED
);
12342 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12343 VAR_INIT_STATUS_INITIALIZED
);
12345 if (op0
== 0 || op1
== 0)
12348 mem_loc_result
= op0
;
12349 add_loc_descr (&mem_loc_result
, op1
);
12350 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12351 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12352 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12353 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12354 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12358 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12360 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12365 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12366 base_type_for_mode (mode
, 1),
12384 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12385 VAR_INIT_STATUS_INITIALIZED
);
12390 mem_loc_result
= op0
;
12391 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12395 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12396 #ifdef POINTERS_EXTEND_UNSIGNED
12398 && mem_mode
!= VOIDmode
12399 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12403 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12407 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12408 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12410 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12411 enum machine_mode amode
;
12412 if (type_die
== NULL
)
12414 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12416 if (INTVAL (rtl
) >= 0
12417 && amode
!= BLKmode
12418 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12419 /* const DW_OP_GNU_convert <XXX> vs.
12420 DW_OP_GNU_const_type <XXX, 1, const>. */
12421 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12422 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12424 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12425 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12426 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12427 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12428 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12429 add_loc_descr (&mem_loc_result
, op0
);
12430 return mem_loc_result
;
12432 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12434 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12435 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12436 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12437 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12438 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12441 mem_loc_result
->dw_loc_oprnd2
.val_class
12442 = dw_val_class_const_double
;
12443 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12444 = double_int::from_shwi (INTVAL (rtl
));
12452 dw_die_ref type_die
;
12454 /* Note that a CONST_DOUBLE rtx could represent either an integer
12455 or a floating-point constant. A CONST_DOUBLE is used whenever
12456 the constant requires more than one word in order to be
12457 adequately represented. We output CONST_DOUBLEs as blocks. */
12458 if (mode
== VOIDmode
12459 || (GET_MODE (rtl
) == VOIDmode
12460 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12462 type_die
= base_type_for_mode (mode
,
12463 GET_MODE_CLASS (mode
) == MODE_INT
);
12464 if (type_die
== NULL
)
12466 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12467 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12468 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12469 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12470 if (SCALAR_FLOAT_MODE_P (mode
))
12472 unsigned int length
= GET_MODE_SIZE (mode
);
12473 unsigned char *array
12474 = (unsigned char*) ggc_alloc_atomic (length
);
12476 insert_float (rtl
, array
);
12477 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12478 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12479 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12480 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12484 mem_loc_result
->dw_loc_oprnd2
.val_class
12485 = dw_val_class_const_double
;
12486 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12487 = rtx_to_double_int (rtl
);
12493 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12497 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12501 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12505 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12509 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12513 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12517 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12521 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12525 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12529 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12534 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12539 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12544 if (CONST_INT_P (XEXP (rtl
, 1))
12545 && CONST_INT_P (XEXP (rtl
, 2))
12546 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12547 + (unsigned) INTVAL (XEXP (rtl
, 2))
12548 <= GET_MODE_BITSIZE (mode
))
12549 && GET_MODE_CLASS (mode
) == MODE_INT
12550 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12551 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12554 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12555 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12558 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12562 mem_loc_result
= op0
;
12563 size
= INTVAL (XEXP (rtl
, 1));
12564 shift
= INTVAL (XEXP (rtl
, 2));
12565 if (BITS_BIG_ENDIAN
)
12566 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12568 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12570 add_loc_descr (&mem_loc_result
,
12571 int_loc_descriptor (DWARF2_ADDR_SIZE
12573 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12575 if (size
!= (int) DWARF2_ADDR_SIZE
)
12577 add_loc_descr (&mem_loc_result
,
12578 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12579 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12586 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12587 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12588 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12589 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12590 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12591 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12592 VAR_INIT_STATUS_INITIALIZED
);
12593 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12594 VAR_INIT_STATUS_INITIALIZED
);
12595 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12598 mem_loc_result
= op1
;
12599 add_loc_descr (&mem_loc_result
, op2
);
12600 add_loc_descr (&mem_loc_result
, op0
);
12601 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12602 add_loc_descr (&mem_loc_result
, bra_node
);
12603 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12604 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12605 add_loc_descr (&mem_loc_result
, drop_node
);
12606 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12607 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12612 case FLOAT_TRUNCATE
:
12614 case UNSIGNED_FLOAT
:
12619 dw_die_ref type_die
;
12620 dw_loc_descr_ref cvt
;
12622 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12623 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12626 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12627 && (GET_CODE (rtl
) == FLOAT
12628 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12629 <= DWARF2_ADDR_SIZE
))
12631 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12632 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12633 if (type_die
== NULL
)
12635 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12636 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12637 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12638 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12639 add_loc_descr (&op0
, cvt
);
12641 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12642 if (type_die
== NULL
)
12644 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12645 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12646 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12647 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12648 add_loc_descr (&op0
, cvt
);
12649 if (GET_MODE_CLASS (mode
) == MODE_INT
12650 && (GET_CODE (rtl
) == FIX
12651 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12653 op0
= convert_descriptor_to_mode (mode
, op0
);
12657 mem_loc_result
= op0
;
12664 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12669 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12673 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12678 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12682 /* In theory, we could implement the above. */
12683 /* DWARF cannot represent the unsigned compare operations
12708 case FRACT_CONVERT
:
12709 case UNSIGNED_FRACT_CONVERT
:
12711 case UNSIGNED_SAT_FRACT
:
12717 case VEC_DUPLICATE
:
12721 case STRICT_LOW_PART
:
12726 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12727 can't express it in the debug info. This can happen e.g. with some
12732 resolve_one_addr (&rtl
, NULL
);
12736 #ifdef ENABLE_CHECKING
12737 print_rtl (stderr
, rtl
);
12738 gcc_unreachable ();
12744 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12745 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12747 return mem_loc_result
;
12750 /* Return a descriptor that describes the concatenation of two locations.
12751 This is typically a complex variable. */
12753 static dw_loc_descr_ref
12754 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12756 dw_loc_descr_ref cc_loc_result
= NULL
;
12757 dw_loc_descr_ref x0_ref
12758 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12759 dw_loc_descr_ref x1_ref
12760 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12762 if (x0_ref
== 0 || x1_ref
== 0)
12765 cc_loc_result
= x0_ref
;
12766 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12768 add_loc_descr (&cc_loc_result
, x1_ref
);
12769 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12771 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12772 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12774 return cc_loc_result
;
12777 /* Return a descriptor that describes the concatenation of N
12780 static dw_loc_descr_ref
12781 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12784 dw_loc_descr_ref cc_loc_result
= NULL
;
12785 unsigned int n
= XVECLEN (concatn
, 0);
12787 for (i
= 0; i
< n
; ++i
)
12789 dw_loc_descr_ref ref
;
12790 rtx x
= XVECEXP (concatn
, 0, i
);
12792 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12796 add_loc_descr (&cc_loc_result
, ref
);
12797 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12800 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12801 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12803 return cc_loc_result
;
12806 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12807 for DEBUG_IMPLICIT_PTR RTL. */
12809 static dw_loc_descr_ref
12810 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12812 dw_loc_descr_ref ret
;
12817 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12818 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12819 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12820 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12821 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12822 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12825 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12826 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12827 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12831 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12832 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12837 /* Output a proper Dwarf location descriptor for a variable or parameter
12838 which is either allocated in a register or in a memory location. For a
12839 register, we just generate an OP_REG and the register number. For a
12840 memory location we provide a Dwarf postfix expression describing how to
12841 generate the (dynamic) address of the object onto the address stack.
12843 MODE is mode of the decl if this loc_descriptor is going to be used in
12844 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12845 allowed, VOIDmode otherwise.
12847 If we don't know how to describe it, return 0. */
12849 static dw_loc_descr_ref
12850 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12851 enum var_init_status initialized
)
12853 dw_loc_descr_ref loc_result
= NULL
;
12855 switch (GET_CODE (rtl
))
12858 /* The case of a subreg may arise when we have a local (register)
12859 variable or a formal (register) parameter which doesn't quite fill
12860 up an entire register. For now, just assume that it is
12861 legitimate to make the Dwarf info refer to the whole register which
12862 contains the given subreg. */
12863 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12864 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12865 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12871 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12875 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12876 GET_MODE (rtl
), initialized
);
12877 if (loc_result
== NULL
)
12878 loc_result
= tls_mem_loc_descriptor (rtl
);
12879 if (loc_result
== NULL
)
12881 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12882 if (new_rtl
!= rtl
)
12883 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
12888 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
12893 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
12898 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
12900 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
12901 if (GET_CODE (loc
) == EXPR_LIST
)
12902 loc
= XEXP (loc
, 0);
12903 loc_result
= loc_descriptor (loc
, mode
, initialized
);
12907 rtl
= XEXP (rtl
, 1);
12912 rtvec par_elems
= XVEC (rtl
, 0);
12913 int num_elem
= GET_NUM_ELEM (par_elems
);
12914 enum machine_mode mode
;
12917 /* Create the first one, so we have something to add to. */
12918 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
12919 VOIDmode
, initialized
);
12920 if (loc_result
== NULL
)
12922 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
12923 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12924 for (i
= 1; i
< num_elem
; i
++)
12926 dw_loc_descr_ref temp
;
12928 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
12929 VOIDmode
, initialized
);
12932 add_loc_descr (&loc_result
, temp
);
12933 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
12934 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12940 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
12941 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
12946 if (mode
== VOIDmode
)
12947 mode
= GET_MODE (rtl
);
12949 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12951 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12953 /* Note that a CONST_DOUBLE rtx could represent either an integer
12954 or a floating-point constant. A CONST_DOUBLE is used whenever
12955 the constant requires more than one word in order to be
12956 adequately represented. We output CONST_DOUBLEs as blocks. */
12957 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12958 GET_MODE_SIZE (mode
), 0);
12959 if (SCALAR_FLOAT_MODE_P (mode
))
12961 unsigned int length
= GET_MODE_SIZE (mode
);
12962 unsigned char *array
12963 = (unsigned char*) ggc_alloc_atomic (length
);
12965 insert_float (rtl
, array
);
12966 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12967 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12968 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12969 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12973 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
12974 loc_result
->dw_loc_oprnd2
.v
.val_double
12975 = rtx_to_double_int (rtl
);
12981 if (mode
== VOIDmode
)
12982 mode
= GET_MODE (rtl
);
12984 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12986 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
12987 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
12988 unsigned char *array
= (unsigned char *)
12989 ggc_alloc_atomic (length
* elt_size
);
12993 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12994 switch (GET_MODE_CLASS (mode
))
12996 case MODE_VECTOR_INT
:
12997 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
12999 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13000 double_int val
= rtx_to_double_int (elt
);
13002 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13003 insert_int (val
.to_shwi (), elt_size
, p
);
13006 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13007 insert_double (val
, p
);
13012 case MODE_VECTOR_FLOAT
:
13013 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13015 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13016 insert_float (elt
, p
);
13021 gcc_unreachable ();
13024 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13025 length
* elt_size
, 0);
13026 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13027 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13028 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13029 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13034 if (mode
== VOIDmode
13035 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13036 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13037 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13039 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13044 if (!const_ok_for_output (rtl
))
13047 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13048 && (dwarf_version
>= 4 || !dwarf_strict
))
13050 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13051 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13052 vec_safe_push (used_rtx_array
, rtl
);
13056 case DEBUG_IMPLICIT_PTR
:
13057 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13061 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13062 && CONST_INT_P (XEXP (rtl
, 1)))
13065 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13071 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13072 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13073 && dwarf_version
>= 4)
13074 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13076 /* Value expression. */
13077 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13079 add_loc_descr (&loc_result
,
13080 new_loc_descr (DW_OP_stack_value
, 0, 0));
13088 /* We need to figure out what section we should use as the base for the
13089 address ranges where a given location is valid.
13090 1. If this particular DECL has a section associated with it, use that.
13091 2. If this function has a section associated with it, use that.
13092 3. Otherwise, use the text section.
13093 XXX: If you split a variable across multiple sections, we won't notice. */
13095 static const char *
13096 secname_for_decl (const_tree decl
)
13098 const char *secname
;
13100 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13102 tree sectree
= DECL_SECTION_NAME (decl
);
13103 secname
= TREE_STRING_POINTER (sectree
);
13105 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13107 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13108 secname
= TREE_STRING_POINTER (sectree
);
13110 else if (cfun
&& in_cold_section_p
)
13111 secname
= crtl
->subsections
.cold_section_label
;
13113 secname
= text_section_label
;
13118 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13121 decl_by_reference_p (tree decl
)
13123 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13124 || TREE_CODE (decl
) == VAR_DECL
)
13125 && DECL_BY_REFERENCE (decl
));
13128 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13131 static dw_loc_descr_ref
13132 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13133 enum var_init_status initialized
)
13135 int have_address
= 0;
13136 dw_loc_descr_ref descr
;
13137 enum machine_mode mode
;
13139 if (want_address
!= 2)
13141 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13143 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13145 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13146 if (GET_CODE (varloc
) == EXPR_LIST
)
13147 varloc
= XEXP (varloc
, 0);
13148 mode
= GET_MODE (varloc
);
13149 if (MEM_P (varloc
))
13151 rtx addr
= XEXP (varloc
, 0);
13152 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13153 mode
, initialized
);
13158 rtx x
= avoid_constant_pool_reference (varloc
);
13160 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13165 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13172 if (GET_CODE (varloc
) == VAR_LOCATION
)
13173 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13175 mode
= DECL_MODE (loc
);
13176 descr
= loc_descriptor (varloc
, mode
, initialized
);
13183 if (want_address
== 2 && !have_address
13184 && (dwarf_version
>= 4 || !dwarf_strict
))
13186 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13188 expansion_failed (loc
, NULL_RTX
,
13189 "DWARF address size mismatch");
13192 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13195 /* Show if we can't fill the request for an address. */
13196 if (want_address
&& !have_address
)
13198 expansion_failed (loc
, NULL_RTX
,
13199 "Want address and only have value");
13203 /* If we've got an address and don't want one, dereference. */
13204 if (!want_address
&& have_address
)
13206 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13207 enum dwarf_location_atom op
;
13209 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13211 expansion_failed (loc
, NULL_RTX
,
13212 "DWARF address size mismatch");
13215 else if (size
== DWARF2_ADDR_SIZE
)
13218 op
= DW_OP_deref_size
;
13220 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13226 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13227 if it is not possible. */
13229 static dw_loc_descr_ref
13230 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13232 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13233 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13234 else if (dwarf_version
>= 3 || !dwarf_strict
)
13235 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13240 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13241 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13243 static dw_loc_descr_ref
13244 dw_sra_loc_expr (tree decl
, rtx loc
)
13247 unsigned int padsize
= 0;
13248 dw_loc_descr_ref descr
, *descr_tail
;
13249 unsigned HOST_WIDE_INT decl_size
;
13251 enum var_init_status initialized
;
13253 if (DECL_SIZE (decl
) == NULL
13254 || !host_integerp (DECL_SIZE (decl
), 1))
13257 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13259 descr_tail
= &descr
;
13261 for (p
= loc
; p
; p
= XEXP (p
, 1))
13263 unsigned int bitsize
= decl_piece_bitsize (p
);
13264 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13265 dw_loc_descr_ref cur_descr
;
13266 dw_loc_descr_ref
*tail
, last
= NULL
;
13267 unsigned int opsize
= 0;
13269 if (loc_note
== NULL_RTX
13270 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13272 padsize
+= bitsize
;
13275 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13276 varloc
= NOTE_VAR_LOCATION (loc_note
);
13277 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13278 if (cur_descr
== NULL
)
13280 padsize
+= bitsize
;
13284 /* Check that cur_descr either doesn't use
13285 DW_OP_*piece operations, or their sum is equal
13286 to bitsize. Otherwise we can't embed it. */
13287 for (tail
= &cur_descr
; *tail
!= NULL
;
13288 tail
= &(*tail
)->dw_loc_next
)
13289 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13291 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13295 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13297 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13301 if (last
!= NULL
&& opsize
!= bitsize
)
13303 padsize
+= bitsize
;
13307 /* If there is a hole, add DW_OP_*piece after empty DWARF
13308 expression, which means that those bits are optimized out. */
13311 if (padsize
> decl_size
)
13313 decl_size
-= padsize
;
13314 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13315 if (*descr_tail
== NULL
)
13317 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13320 *descr_tail
= cur_descr
;
13322 if (bitsize
> decl_size
)
13324 decl_size
-= bitsize
;
13327 HOST_WIDE_INT offset
= 0;
13328 if (GET_CODE (varloc
) == VAR_LOCATION
13329 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13331 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13332 if (GET_CODE (varloc
) == EXPR_LIST
)
13333 varloc
= XEXP (varloc
, 0);
13337 if (GET_CODE (varloc
) == CONST
13338 || GET_CODE (varloc
) == SIGN_EXTEND
13339 || GET_CODE (varloc
) == ZERO_EXTEND
)
13340 varloc
= XEXP (varloc
, 0);
13341 else if (GET_CODE (varloc
) == SUBREG
)
13342 varloc
= SUBREG_REG (varloc
);
13347 /* DW_OP_bit_size offset should be zero for register
13348 or implicit location descriptions and empty location
13349 descriptions, but for memory addresses needs big endian
13351 if (MEM_P (varloc
))
13353 unsigned HOST_WIDE_INT memsize
13354 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13355 if (memsize
!= bitsize
)
13357 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13358 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13360 if (memsize
< bitsize
)
13362 if (BITS_BIG_ENDIAN
)
13363 offset
= memsize
- bitsize
;
13367 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13368 if (*descr_tail
== NULL
)
13370 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13374 /* If there were any non-empty expressions, add padding till the end of
13376 if (descr
!= NULL
&& decl_size
!= 0)
13378 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13379 if (*descr_tail
== NULL
)
13385 /* Return the dwarf representation of the location list LOC_LIST of
13386 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13389 static dw_loc_list_ref
13390 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13392 const char *endname
, *secname
;
13394 enum var_init_status initialized
;
13395 struct var_loc_node
*node
;
13396 dw_loc_descr_ref descr
;
13397 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13398 dw_loc_list_ref list
= NULL
;
13399 dw_loc_list_ref
*listp
= &list
;
13401 /* Now that we know what section we are using for a base,
13402 actually construct the list of locations.
13403 The first location information is what is passed to the
13404 function that creates the location list, and the remaining
13405 locations just get added on to that list.
13406 Note that we only know the start address for a location
13407 (IE location changes), so to build the range, we use
13408 the range [current location start, next location start].
13409 This means we have to special case the last node, and generate
13410 a range of [last location start, end of function label]. */
13412 secname
= secname_for_decl (decl
);
13414 for (node
= loc_list
->first
; node
; node
= node
->next
)
13415 if (GET_CODE (node
->loc
) == EXPR_LIST
13416 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13418 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13420 /* This requires DW_OP_{,bit_}piece, which is not usable
13421 inside DWARF expressions. */
13422 if (want_address
!= 2)
13424 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13430 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13431 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13432 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13436 bool range_across_switch
= false;
13437 /* If section switch happens in between node->label
13438 and node->next->label (or end of function) and
13439 we can't emit it as a single entry list,
13440 emit two ranges, first one ending at the end
13441 of first partition and second one starting at the
13442 beginning of second partition. */
13443 if (node
== loc_list
->last_before_switch
13444 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13445 && current_function_decl
)
13447 endname
= cfun
->fde
->dw_fde_end
;
13448 range_across_switch
= true;
13450 /* The variable has a location between NODE->LABEL and
13451 NODE->NEXT->LABEL. */
13452 else if (node
->next
)
13453 endname
= node
->next
->label
;
13454 /* If the variable has a location at the last label
13455 it keeps its location until the end of function. */
13456 else if (!current_function_decl
)
13457 endname
= text_end_label
;
13460 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13461 current_function_funcdef_no
);
13462 endname
= ggc_strdup (label_id
);
13465 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13466 if (TREE_CODE (decl
) == PARM_DECL
13467 && node
== loc_list
->first
13468 && GET_CODE (node
->loc
) == NOTE
13469 && strcmp (node
->label
, endname
) == 0)
13470 (*listp
)->force
= true;
13471 listp
= &(*listp
)->dw_loc_next
;
13473 if (range_across_switch
)
13475 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13476 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13479 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13480 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13481 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13484 gcc_assert (descr
);
13485 /* The variable has a location between NODE->LABEL and
13486 NODE->NEXT->LABEL. */
13488 endname
= node
->next
->label
;
13490 endname
= cfun
->fde
->dw_fde_second_end
;
13491 *listp
= new_loc_list (descr
,
13492 cfun
->fde
->dw_fde_second_begin
,
13494 listp
= &(*listp
)->dw_loc_next
;
13499 /* Try to avoid the overhead of a location list emitting a location
13500 expression instead, but only if we didn't have more than one
13501 location entry in the first place. If some entries were not
13502 representable, we don't want to pretend a single entry that was
13503 applies to the entire scope in which the variable is
13505 if (list
&& loc_list
->first
->next
)
13511 /* Return if the loc_list has only single element and thus can be represented
13512 as location description. */
13515 single_element_loc_list_p (dw_loc_list_ref list
)
13517 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13518 return !list
->ll_symbol
;
13521 /* To each location in list LIST add loc descr REF. */
13524 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13526 dw_loc_descr_ref copy
;
13527 add_loc_descr (&list
->expr
, ref
);
13528 list
= list
->dw_loc_next
;
13531 copy
= ggc_alloc_dw_loc_descr_node ();
13532 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13533 add_loc_descr (&list
->expr
, copy
);
13534 while (copy
->dw_loc_next
)
13536 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13537 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13538 copy
->dw_loc_next
= new_copy
;
13541 list
= list
->dw_loc_next
;
13545 /* Given two lists RET and LIST
13546 produce location list that is result of adding expression in LIST
13547 to expression in RET on each position in program.
13548 Might be destructive on both RET and LIST.
13550 TODO: We handle only simple cases of RET or LIST having at most one
13551 element. General case would inolve sorting the lists in program order
13552 and merging them that will need some additional work.
13553 Adding that will improve quality of debug info especially for SRA-ed
13557 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13566 if (!list
->dw_loc_next
)
13568 add_loc_descr_to_each (*ret
, list
->expr
);
13571 if (!(*ret
)->dw_loc_next
)
13573 add_loc_descr_to_each (list
, (*ret
)->expr
);
13577 expansion_failed (NULL_TREE
, NULL_RTX
,
13578 "Don't know how to merge two non-trivial"
13579 " location lists.\n");
13584 /* LOC is constant expression. Try a luck, look it up in constant
13585 pool and return its loc_descr of its address. */
13587 static dw_loc_descr_ref
13588 cst_pool_loc_descr (tree loc
)
13590 /* Get an RTL for this, if something has been emitted. */
13591 rtx rtl
= lookup_constant_def (loc
);
13593 if (!rtl
|| !MEM_P (rtl
))
13598 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13600 /* TODO: We might get more coverage if we was actually delaying expansion
13601 of all expressions till end of compilation when constant pools are fully
13603 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13605 expansion_failed (loc
, NULL_RTX
,
13606 "CST value in contant pool but not marked.");
13609 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13610 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13613 /* Return dw_loc_list representing address of addr_expr LOC
13614 by looking for inner INDIRECT_REF expression and turning
13615 it into simple arithmetics. */
13617 static dw_loc_list_ref
13618 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13621 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13622 enum machine_mode mode
;
13623 int unsignedp
, volatilep
= 0;
13624 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13626 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13627 &bitsize
, &bitpos
, &offset
, &mode
,
13628 &unsignedp
, &volatilep
, false);
13630 if (bitpos
% BITS_PER_UNIT
)
13632 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13635 if (!INDIRECT_REF_P (obj
))
13637 expansion_failed (obj
,
13638 NULL_RTX
, "no indirect ref in inner refrence");
13641 if (!offset
&& !bitpos
)
13642 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13644 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13645 && (dwarf_version
>= 4 || !dwarf_strict
))
13647 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13652 /* Variable offset. */
13653 list_ret1
= loc_list_from_tree (offset
, 0);
13654 if (list_ret1
== 0)
13656 add_loc_list (&list_ret
, list_ret1
);
13659 add_loc_descr_to_each (list_ret
,
13660 new_loc_descr (DW_OP_plus
, 0, 0));
13662 bytepos
= bitpos
/ BITS_PER_UNIT
;
13664 add_loc_descr_to_each (list_ret
,
13665 new_loc_descr (DW_OP_plus_uconst
,
13667 else if (bytepos
< 0)
13668 loc_list_plus_const (list_ret
, bytepos
);
13669 add_loc_descr_to_each (list_ret
,
13670 new_loc_descr (DW_OP_stack_value
, 0, 0));
13676 /* Generate Dwarf location list representing LOC.
13677 If WANT_ADDRESS is false, expression computing LOC will be computed
13678 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13679 if WANT_ADDRESS is 2, expression computing address useable in location
13680 will be returned (i.e. DW_OP_reg can be used
13681 to refer to register values). */
13683 static dw_loc_list_ref
13684 loc_list_from_tree (tree loc
, int want_address
)
13686 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13687 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13688 int have_address
= 0;
13689 enum dwarf_location_atom op
;
13691 /* ??? Most of the time we do not take proper care for sign/zero
13692 extending the values properly. Hopefully this won't be a real
13695 switch (TREE_CODE (loc
))
13698 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13701 case PLACEHOLDER_EXPR
:
13702 /* This case involves extracting fields from an object to determine the
13703 position of other fields. We don't try to encode this here. The
13704 only user of this is Ada, which encodes the needed information using
13705 the names of types. */
13706 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13710 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13711 /* There are no opcodes for these operations. */
13714 case PREINCREMENT_EXPR
:
13715 case PREDECREMENT_EXPR
:
13716 case POSTINCREMENT_EXPR
:
13717 case POSTDECREMENT_EXPR
:
13718 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13719 /* There are no opcodes for these operations. */
13723 /* If we already want an address, see if there is INDIRECT_REF inside
13724 e.g. for &this->field. */
13727 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13728 (loc
, want_address
== 2);
13731 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13732 && (ret
= cst_pool_loc_descr (loc
)))
13735 /* Otherwise, process the argument and look for the address. */
13736 if (!list_ret
&& !ret
)
13737 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13741 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13747 if (DECL_THREAD_LOCAL_P (loc
))
13750 enum dwarf_location_atom tls_op
;
13751 enum dtprel_bool dtprel
= dtprel_false
;
13753 if (targetm
.have_tls
)
13755 /* If this is not defined, we have no way to emit the
13757 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13760 /* The way DW_OP_GNU_push_tls_address is specified, we
13761 can only look up addresses of objects in the current
13762 module. We used DW_OP_addr as first op, but that's
13763 wrong, because DW_OP_addr is relocated by the debug
13764 info consumer, while DW_OP_GNU_push_tls_address
13765 operand shouldn't be. */
13766 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13768 dtprel
= dtprel_true
;
13769 tls_op
= DW_OP_GNU_push_tls_address
;
13773 if (!targetm
.emutls
.debug_form_tls_address
13774 || !(dwarf_version
>= 3 || !dwarf_strict
))
13776 /* We stuffed the control variable into the DECL_VALUE_EXPR
13777 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13778 no longer appear in gimple code. We used the control
13779 variable in specific so that we could pick it up here. */
13780 loc
= DECL_VALUE_EXPR (loc
);
13781 tls_op
= DW_OP_form_tls_address
;
13784 rtl
= rtl_for_decl_location (loc
);
13785 if (rtl
== NULL_RTX
)
13790 rtl
= XEXP (rtl
, 0);
13791 if (! CONSTANT_P (rtl
))
13794 ret
= new_addr_loc_descr (rtl
, dtprel
);
13795 ret1
= new_loc_descr (tls_op
, 0, 0);
13796 add_loc_descr (&ret
, ret1
);
13805 if (DECL_HAS_VALUE_EXPR_P (loc
))
13806 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13810 case FUNCTION_DECL
:
13813 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13815 if (loc_list
&& loc_list
->first
)
13817 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13818 have_address
= want_address
!= 0;
13821 rtl
= rtl_for_decl_location (loc
);
13822 if (rtl
== NULL_RTX
)
13824 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13827 else if (CONST_INT_P (rtl
))
13829 HOST_WIDE_INT val
= INTVAL (rtl
);
13830 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13831 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13832 ret
= int_loc_descriptor (val
);
13834 else if (GET_CODE (rtl
) == CONST_STRING
)
13836 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13839 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13840 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
13843 enum machine_mode mode
, mem_mode
;
13845 /* Certain constructs can only be represented at top-level. */
13846 if (want_address
== 2)
13848 ret
= loc_descriptor (rtl
, VOIDmode
,
13849 VAR_INIT_STATUS_INITIALIZED
);
13854 mode
= GET_MODE (rtl
);
13855 mem_mode
= VOIDmode
;
13859 mode
= get_address_mode (rtl
);
13860 rtl
= XEXP (rtl
, 0);
13863 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13864 VAR_INIT_STATUS_INITIALIZED
);
13867 expansion_failed (loc
, rtl
,
13868 "failed to produce loc descriptor for rtl");
13875 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
13879 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13883 case COMPOUND_EXPR
:
13884 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
13887 case VIEW_CONVERT_EXPR
:
13890 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
13892 case COMPONENT_REF
:
13893 case BIT_FIELD_REF
:
13895 case ARRAY_RANGE_REF
:
13896 case REALPART_EXPR
:
13897 case IMAGPART_EXPR
:
13900 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13901 enum machine_mode mode
;
13902 int unsignedp
, volatilep
= 0;
13904 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
13905 &unsignedp
, &volatilep
, false);
13907 gcc_assert (obj
!= loc
);
13909 list_ret
= loc_list_from_tree (obj
,
13911 && !bitpos
&& !offset
? 2 : 1);
13912 /* TODO: We can extract value of the small expression via shifting even
13913 for nonzero bitpos. */
13916 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
13918 expansion_failed (loc
, NULL_RTX
,
13919 "bitfield access");
13923 if (offset
!= NULL_TREE
)
13925 /* Variable offset. */
13926 list_ret1
= loc_list_from_tree (offset
, 0);
13927 if (list_ret1
== 0)
13929 add_loc_list (&list_ret
, list_ret1
);
13932 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
13935 bytepos
= bitpos
/ BITS_PER_UNIT
;
13937 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
13938 else if (bytepos
< 0)
13939 loc_list_plus_const (list_ret
, bytepos
);
13946 if ((want_address
|| !host_integerp (loc
, 0))
13947 && (ret
= cst_pool_loc_descr (loc
)))
13949 else if (want_address
== 2
13950 && host_integerp (loc
, 0)
13951 && (ret
= address_of_int_loc_descriptor
13952 (int_size_in_bytes (TREE_TYPE (loc
)),
13953 tree_low_cst (loc
, 0))))
13955 else if (host_integerp (loc
, 0))
13956 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
13959 expansion_failed (loc
, NULL_RTX
,
13960 "Integer operand is not host integer");
13969 if ((ret
= cst_pool_loc_descr (loc
)))
13972 /* We can construct small constants here using int_loc_descriptor. */
13973 expansion_failed (loc
, NULL_RTX
,
13974 "constructor or constant not in constant pool");
13977 case TRUTH_AND_EXPR
:
13978 case TRUTH_ANDIF_EXPR
:
13983 case TRUTH_XOR_EXPR
:
13988 case TRUTH_OR_EXPR
:
13989 case TRUTH_ORIF_EXPR
:
13994 case FLOOR_DIV_EXPR
:
13995 case CEIL_DIV_EXPR
:
13996 case ROUND_DIV_EXPR
:
13997 case TRUNC_DIV_EXPR
:
13998 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14007 case FLOOR_MOD_EXPR
:
14008 case CEIL_MOD_EXPR
:
14009 case ROUND_MOD_EXPR
:
14010 case TRUNC_MOD_EXPR
:
14011 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14016 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14017 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14018 if (list_ret
== 0 || list_ret1
== 0)
14021 add_loc_list (&list_ret
, list_ret1
);
14024 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14025 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14026 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14027 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14028 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14040 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14043 case POINTER_PLUS_EXPR
:
14045 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14047 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14051 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14059 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14066 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14073 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14080 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14095 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14096 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14097 if (list_ret
== 0 || list_ret1
== 0)
14100 add_loc_list (&list_ret
, list_ret1
);
14103 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14106 case TRUTH_NOT_EXPR
:
14120 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14124 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14130 const enum tree_code code
=
14131 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14133 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14134 build2 (code
, integer_type_node
,
14135 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14136 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14139 /* ... fall through ... */
14143 dw_loc_descr_ref lhs
14144 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14145 dw_loc_list_ref rhs
14146 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14147 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14149 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14150 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14153 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14154 add_loc_descr_to_each (list_ret
, bra_node
);
14156 add_loc_list (&list_ret
, rhs
);
14157 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14158 add_loc_descr_to_each (list_ret
, jump_node
);
14160 add_loc_descr_to_each (list_ret
, lhs
);
14161 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14162 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14164 /* ??? Need a node to point the skip at. Use a nop. */
14165 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14166 add_loc_descr_to_each (list_ret
, tmp
);
14167 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14168 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14172 case FIX_TRUNC_EXPR
:
14176 /* Leave front-end specific codes as simply unknown. This comes
14177 up, for instance, with the C STMT_EXPR. */
14178 if ((unsigned int) TREE_CODE (loc
)
14179 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14181 expansion_failed (loc
, NULL_RTX
,
14182 "language specific tree node");
14186 #ifdef ENABLE_CHECKING
14187 /* Otherwise this is a generic code; we should just lists all of
14188 these explicitly. We forgot one. */
14189 gcc_unreachable ();
14191 /* In a release build, we want to degrade gracefully: better to
14192 generate incomplete debugging information than to crash. */
14197 if (!ret
&& !list_ret
)
14200 if (want_address
== 2 && !have_address
14201 && (dwarf_version
>= 4 || !dwarf_strict
))
14203 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14205 expansion_failed (loc
, NULL_RTX
,
14206 "DWARF address size mismatch");
14210 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14212 add_loc_descr_to_each (list_ret
,
14213 new_loc_descr (DW_OP_stack_value
, 0, 0));
14216 /* Show if we can't fill the request for an address. */
14217 if (want_address
&& !have_address
)
14219 expansion_failed (loc
, NULL_RTX
,
14220 "Want address and only have value");
14224 gcc_assert (!ret
|| !list_ret
);
14226 /* If we've got an address and don't want one, dereference. */
14227 if (!want_address
&& have_address
)
14229 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14231 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14233 expansion_failed (loc
, NULL_RTX
,
14234 "DWARF address size mismatch");
14237 else if (size
== DWARF2_ADDR_SIZE
)
14240 op
= DW_OP_deref_size
;
14243 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14245 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14248 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14253 /* Same as above but return only single location expression. */
14254 static dw_loc_descr_ref
14255 loc_descriptor_from_tree (tree loc
, int want_address
)
14257 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14260 if (ret
->dw_loc_next
)
14262 expansion_failed (loc
, NULL_RTX
,
14263 "Location list where only loc descriptor needed");
14269 /* Given a value, round it up to the lowest multiple of `boundary'
14270 which is not less than the value itself. */
14272 static inline HOST_WIDE_INT
14273 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14275 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14278 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14279 pointer to the declared type for the relevant field variable, or return
14280 `integer_type_node' if the given node turns out to be an
14281 ERROR_MARK node. */
14284 field_type (const_tree decl
)
14288 if (TREE_CODE (decl
) == ERROR_MARK
)
14289 return integer_type_node
;
14291 type
= DECL_BIT_FIELD_TYPE (decl
);
14292 if (type
== NULL_TREE
)
14293 type
= TREE_TYPE (decl
);
14298 /* Given a pointer to a tree node, return the alignment in bits for
14299 it, or else return BITS_PER_WORD if the node actually turns out to
14300 be an ERROR_MARK node. */
14302 static inline unsigned
14303 simple_type_align_in_bits (const_tree type
)
14305 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14308 static inline unsigned
14309 simple_decl_align_in_bits (const_tree decl
)
14311 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14314 /* Return the result of rounding T up to ALIGN. */
14316 static inline double_int
14317 round_up_to_align (double_int t
, unsigned int align
)
14319 double_int alignd
= double_int::from_uhwi (align
);
14321 t
+= double_int_minus_one
;
14322 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14327 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14328 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14329 or return 0 if we are unable to determine what that offset is, either
14330 because the argument turns out to be a pointer to an ERROR_MARK node, or
14331 because the offset is actually variable. (We can't handle the latter case
14334 static HOST_WIDE_INT
14335 field_byte_offset (const_tree decl
)
14337 double_int object_offset_in_bits
;
14338 double_int object_offset_in_bytes
;
14339 double_int bitpos_int
;
14341 if (TREE_CODE (decl
) == ERROR_MARK
)
14344 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14346 /* We cannot yet cope with fields whose positions are variable, so
14347 for now, when we see such things, we simply return 0. Someday, we may
14348 be able to handle such cases, but it will be damn difficult. */
14349 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14352 bitpos_int
= tree_to_double_int (bit_position (decl
));
14354 #ifdef PCC_BITFIELD_TYPE_MATTERS
14355 if (PCC_BITFIELD_TYPE_MATTERS
)
14358 tree field_size_tree
;
14359 double_int deepest_bitpos
;
14360 double_int field_size_in_bits
;
14361 unsigned int type_align_in_bits
;
14362 unsigned int decl_align_in_bits
;
14363 double_int type_size_in_bits
;
14365 type
= field_type (decl
);
14366 type_size_in_bits
= double_int_type_size_in_bits (type
);
14367 type_align_in_bits
= simple_type_align_in_bits (type
);
14369 field_size_tree
= DECL_SIZE (decl
);
14371 /* The size could be unspecified if there was an error, or for
14372 a flexible array member. */
14373 if (!field_size_tree
)
14374 field_size_tree
= bitsize_zero_node
;
14376 /* If the size of the field is not constant, use the type size. */
14377 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14378 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14380 field_size_in_bits
= type_size_in_bits
;
14382 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14384 /* The GCC front-end doesn't make any attempt to keep track of the
14385 starting bit offset (relative to the start of the containing
14386 structure type) of the hypothetical "containing object" for a
14387 bit-field. Thus, when computing the byte offset value for the
14388 start of the "containing object" of a bit-field, we must deduce
14389 this information on our own. This can be rather tricky to do in
14390 some cases. For example, handling the following structure type
14391 definition when compiling for an i386/i486 target (which only
14392 aligns long long's to 32-bit boundaries) can be very tricky:
14394 struct S { int field1; long long field2:31; };
14396 Fortunately, there is a simple rule-of-thumb which can be used
14397 in such cases. When compiling for an i386/i486, GCC will
14398 allocate 8 bytes for the structure shown above. It decides to
14399 do this based upon one simple rule for bit-field allocation.
14400 GCC allocates each "containing object" for each bit-field at
14401 the first (i.e. lowest addressed) legitimate alignment boundary
14402 (based upon the required minimum alignment for the declared
14403 type of the field) which it can possibly use, subject to the
14404 condition that there is still enough available space remaining
14405 in the containing object (when allocated at the selected point)
14406 to fully accommodate all of the bits of the bit-field itself.
14408 This simple rule makes it obvious why GCC allocates 8 bytes for
14409 each object of the structure type shown above. When looking
14410 for a place to allocate the "containing object" for `field2',
14411 the compiler simply tries to allocate a 64-bit "containing
14412 object" at each successive 32-bit boundary (starting at zero)
14413 until it finds a place to allocate that 64- bit field such that
14414 at least 31 contiguous (and previously unallocated) bits remain
14415 within that selected 64 bit field. (As it turns out, for the
14416 example above, the compiler finds it is OK to allocate the
14417 "containing object" 64-bit field at bit-offset zero within the
14420 Here we attempt to work backwards from the limited set of facts
14421 we're given, and we try to deduce from those facts, where GCC
14422 must have believed that the containing object started (within
14423 the structure type). The value we deduce is then used (by the
14424 callers of this routine) to generate DW_AT_location and
14425 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14426 the case of DW_AT_location, regular fields as well). */
14428 /* Figure out the bit-distance from the start of the structure to
14429 the "deepest" bit of the bit-field. */
14430 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14432 /* This is the tricky part. Use some fancy footwork to deduce
14433 where the lowest addressed bit of the containing object must
14435 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14437 /* Round up to type_align by default. This works best for
14439 object_offset_in_bits
14440 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14442 if (object_offset_in_bits
.ugt (bitpos_int
))
14444 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14446 /* Round up to decl_align instead. */
14447 object_offset_in_bits
14448 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14452 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14453 object_offset_in_bits
= bitpos_int
;
14455 object_offset_in_bytes
14456 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14457 true, TRUNC_DIV_EXPR
);
14458 return object_offset_in_bytes
.to_shwi ();
14461 /* The following routines define various Dwarf attributes and any data
14462 associated with them. */
14464 /* Add a location description attribute value to a DIE.
14466 This emits location attributes suitable for whole variables and
14467 whole parameters. Note that the location attributes for struct fields are
14468 generated by the routine `data_member_location_attribute' below. */
14471 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14472 dw_loc_list_ref descr
)
14476 if (single_element_loc_list_p (descr
))
14477 add_AT_loc (die
, attr_kind
, descr
->expr
);
14479 add_AT_loc_list (die
, attr_kind
, descr
);
14482 /* Add DW_AT_accessibility attribute to DIE if needed. */
14485 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14487 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14488 children, otherwise the default is DW_ACCESS_public. In DWARF2
14489 the default has always been DW_ACCESS_public. */
14490 if (TREE_PROTECTED (decl
))
14491 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14492 else if (TREE_PRIVATE (decl
))
14494 if (dwarf_version
== 2
14495 || die
->die_parent
== NULL
14496 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14497 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14499 else if (dwarf_version
> 2
14501 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14502 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14505 /* Attach the specialized form of location attribute used for data members of
14506 struct and union types. In the special case of a FIELD_DECL node which
14507 represents a bit-field, the "offset" part of this special location
14508 descriptor must indicate the distance in bytes from the lowest-addressed
14509 byte of the containing struct or union type to the lowest-addressed byte of
14510 the "containing object" for the bit-field. (See the `field_byte_offset'
14513 For any given bit-field, the "containing object" is a hypothetical object
14514 (of some integral or enum type) within which the given bit-field lives. The
14515 type of this hypothetical "containing object" is always the same as the
14516 declared type of the individual bit-field itself (for GCC anyway... the
14517 DWARF spec doesn't actually mandate this). Note that it is the size (in
14518 bytes) of the hypothetical "containing object" which will be given in the
14519 DW_AT_byte_size attribute for this bit-field. (See the
14520 `byte_size_attribute' function below.) It is also used when calculating the
14521 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14522 function below.) */
14525 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14527 HOST_WIDE_INT offset
;
14528 dw_loc_descr_ref loc_descr
= 0;
14530 if (TREE_CODE (decl
) == TREE_BINFO
)
14532 /* We're working on the TAG_inheritance for a base class. */
14533 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14535 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14536 aren't at a fixed offset from all (sub)objects of the same
14537 type. We need to extract the appropriate offset from our
14538 vtable. The following dwarf expression means
14540 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14542 This is specific to the V3 ABI, of course. */
14544 dw_loc_descr_ref tmp
;
14546 /* Make a copy of the object address. */
14547 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14548 add_loc_descr (&loc_descr
, tmp
);
14550 /* Extract the vtable address. */
14551 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14552 add_loc_descr (&loc_descr
, tmp
);
14554 /* Calculate the address of the offset. */
14555 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14556 gcc_assert (offset
< 0);
14558 tmp
= int_loc_descriptor (-offset
);
14559 add_loc_descr (&loc_descr
, tmp
);
14560 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14561 add_loc_descr (&loc_descr
, tmp
);
14563 /* Extract the offset. */
14564 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14565 add_loc_descr (&loc_descr
, tmp
);
14567 /* Add it to the object address. */
14568 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14569 add_loc_descr (&loc_descr
, tmp
);
14572 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14575 offset
= field_byte_offset (decl
);
14579 if (dwarf_version
> 2)
14581 /* Don't need to output a location expression, just the constant. */
14583 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14585 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14590 enum dwarf_location_atom op
;
14592 /* The DWARF2 standard says that we should assume that the structure
14593 address is already on the stack, so we can specify a structure
14594 field address by using DW_OP_plus_uconst. */
14595 op
= DW_OP_plus_uconst
;
14596 loc_descr
= new_loc_descr (op
, offset
, 0);
14600 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14603 /* Writes integer values to dw_vec_const array. */
14606 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14610 *dest
++ = val
& 0xff;
14616 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14618 static HOST_WIDE_INT
14619 extract_int (const unsigned char *src
, unsigned int size
)
14621 HOST_WIDE_INT val
= 0;
14627 val
|= *--src
& 0xff;
14633 /* Writes double_int values to dw_vec_const array. */
14636 insert_double (double_int val
, unsigned char *dest
)
14638 unsigned char *p0
= dest
;
14639 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14641 if (WORDS_BIG_ENDIAN
)
14647 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14648 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14651 /* Writes floating point values to dw_vec_const array. */
14654 insert_float (const_rtx rtl
, unsigned char *array
)
14656 REAL_VALUE_TYPE rv
;
14660 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14661 real_to_target (val
, &rv
, GET_MODE (rtl
));
14663 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14664 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14666 insert_int (val
[i
], 4, array
);
14671 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14672 does not have a "location" either in memory or in a register. These
14673 things can arise in GNU C when a constant is passed as an actual parameter
14674 to an inlined function. They can also arise in C++ where declared
14675 constants do not necessarily get memory "homes". */
14678 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14680 switch (GET_CODE (rtl
))
14684 HOST_WIDE_INT val
= INTVAL (rtl
);
14687 add_AT_int (die
, DW_AT_const_value
, val
);
14689 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14694 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14695 floating-point constant. A CONST_DOUBLE is used whenever the
14696 constant requires more than one word in order to be adequately
14699 enum machine_mode mode
= GET_MODE (rtl
);
14701 if (SCALAR_FLOAT_MODE_P (mode
))
14703 unsigned int length
= GET_MODE_SIZE (mode
);
14704 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14706 insert_float (rtl
, array
);
14707 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14710 add_AT_double (die
, DW_AT_const_value
,
14711 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14717 enum machine_mode mode
= GET_MODE (rtl
);
14718 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14719 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14720 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14721 (length
* elt_size
);
14725 switch (GET_MODE_CLASS (mode
))
14727 case MODE_VECTOR_INT
:
14728 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14730 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14731 double_int val
= rtx_to_double_int (elt
);
14733 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14734 insert_int (val
.to_shwi (), elt_size
, p
);
14737 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14738 insert_double (val
, p
);
14743 case MODE_VECTOR_FLOAT
:
14744 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14746 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14747 insert_float (elt
, p
);
14752 gcc_unreachable ();
14755 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14760 if (dwarf_version
>= 4 || !dwarf_strict
)
14762 dw_loc_descr_ref loc_result
;
14763 resolve_one_addr (&rtl
, NULL
);
14765 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14766 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14767 add_AT_loc (die
, DW_AT_location
, loc_result
);
14768 vec_safe_push (used_rtx_array
, rtl
);
14774 if (CONSTANT_P (XEXP (rtl
, 0)))
14775 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14778 if (!const_ok_for_output (rtl
))
14781 if (dwarf_version
>= 4 || !dwarf_strict
)
14786 /* In cases where an inlined instance of an inline function is passed
14787 the address of an `auto' variable (which is local to the caller) we
14788 can get a situation where the DECL_RTL of the artificial local
14789 variable (for the inlining) which acts as a stand-in for the
14790 corresponding formal parameter (of the inline function) will look
14791 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14792 exactly a compile-time constant expression, but it isn't the address
14793 of the (artificial) local variable either. Rather, it represents the
14794 *value* which the artificial local variable always has during its
14795 lifetime. We currently have no way to represent such quasi-constant
14796 values in Dwarf, so for now we just punt and generate nothing. */
14804 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14805 && MEM_READONLY_P (rtl
)
14806 && GET_MODE (rtl
) == BLKmode
)
14808 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14814 /* No other kinds of rtx should be possible here. */
14815 gcc_unreachable ();
14820 /* Determine whether the evaluation of EXPR references any variables
14821 or functions which aren't otherwise used (and therefore may not be
14824 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14825 void * data ATTRIBUTE_UNUSED
)
14827 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14828 *walk_subtrees
= 0;
14830 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14831 && ! TREE_ASM_WRITTEN (*tp
))
14833 /* ??? The C++ FE emits debug information for using decls, so
14834 putting gcc_unreachable here falls over. See PR31899. For now
14835 be conservative. */
14836 else if (!cgraph_global_info_ready
14837 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14839 else if (TREE_CODE (*tp
) == VAR_DECL
)
14841 struct varpool_node
*node
= varpool_get_node (*tp
);
14842 if (!node
|| !node
->analyzed
)
14845 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14846 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14848 /* The call graph machinery must have finished analyzing,
14849 optimizing and gimplifying the CU by now.
14850 So if *TP has no call graph node associated
14851 to it, it means *TP will not be emitted. */
14852 if (!cgraph_get_node (*tp
))
14855 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14861 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14862 for use in a later add_const_value_attribute call. */
14865 rtl_for_decl_init (tree init
, tree type
)
14867 rtx rtl
= NULL_RTX
;
14871 /* If a variable is initialized with a string constant without embedded
14872 zeros, build CONST_STRING. */
14873 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14875 tree enttype
= TREE_TYPE (type
);
14876 tree domain
= TYPE_DOMAIN (type
);
14877 enum machine_mode mode
= TYPE_MODE (enttype
);
14879 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
14881 && integer_zerop (TYPE_MIN_VALUE (domain
))
14882 && compare_tree_int (TYPE_MAX_VALUE (domain
),
14883 TREE_STRING_LENGTH (init
) - 1) == 0
14884 && ((size_t) TREE_STRING_LENGTH (init
)
14885 == strlen (TREE_STRING_POINTER (init
)) + 1))
14887 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
14888 ggc_strdup (TREE_STRING_POINTER (init
)));
14889 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
14890 MEM_READONLY_P (rtl
) = 1;
14893 /* Other aggregates, and complex values, could be represented using
14895 else if (AGGREGATE_TYPE_P (type
)
14896 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
14897 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
14898 || TREE_CODE (type
) == COMPLEX_TYPE
)
14900 /* Vectors only work if their mode is supported by the target.
14901 FIXME: generic vectors ought to work too. */
14902 else if (TREE_CODE (type
) == VECTOR_TYPE
14903 && !VECTOR_MODE_P (TYPE_MODE (type
)))
14905 /* If the initializer is something that we know will expand into an
14906 immediate RTL constant, expand it now. We must be careful not to
14907 reference variables which won't be output. */
14908 else if (initializer_constant_valid_p (init
, type
)
14909 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
14911 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14913 if (TREE_CODE (type
) == VECTOR_TYPE
)
14914 switch (TREE_CODE (init
))
14919 if (TREE_CONSTANT (init
))
14921 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
14922 bool constant_p
= true;
14924 unsigned HOST_WIDE_INT ix
;
14926 /* Even when ctor is constant, it might contain non-*_CST
14927 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14928 belong into VECTOR_CST nodes. */
14929 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
14930 if (!CONSTANT_CLASS_P (value
))
14932 constant_p
= false;
14938 init
= build_vector_from_ctor (type
, elts
);
14948 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
14950 /* If expand_expr returns a MEM, it wasn't immediate. */
14951 gcc_assert (!rtl
|| !MEM_P (rtl
));
14957 /* Generate RTL for the variable DECL to represent its location. */
14960 rtl_for_decl_location (tree decl
)
14964 /* Here we have to decide where we are going to say the parameter "lives"
14965 (as far as the debugger is concerned). We only have a couple of
14966 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14968 DECL_RTL normally indicates where the parameter lives during most of the
14969 activation of the function. If optimization is enabled however, this
14970 could be either NULL or else a pseudo-reg. Both of those cases indicate
14971 that the parameter doesn't really live anywhere (as far as the code
14972 generation parts of GCC are concerned) during most of the function's
14973 activation. That will happen (for example) if the parameter is never
14974 referenced within the function.
14976 We could just generate a location descriptor here for all non-NULL
14977 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
14978 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
14979 where DECL_RTL is NULL or is a pseudo-reg.
14981 Note however that we can only get away with using DECL_INCOMING_RTL as
14982 a backup substitute for DECL_RTL in certain limited cases. In cases
14983 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
14984 we can be sure that the parameter was passed using the same type as it is
14985 declared to have within the function, and that its DECL_INCOMING_RTL
14986 points us to a place where a value of that type is passed.
14988 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
14989 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
14990 because in these cases DECL_INCOMING_RTL points us to a value of some
14991 type which is *different* from the type of the parameter itself. Thus,
14992 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
14993 such cases, the debugger would end up (for example) trying to fetch a
14994 `float' from a place which actually contains the first part of a
14995 `double'. That would lead to really incorrect and confusing
14996 output at debug-time.
14998 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
14999 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15000 are a couple of exceptions however. On little-endian machines we can
15001 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15002 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15003 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15004 when (on a little-endian machine) a non-prototyped function has a
15005 parameter declared to be of type `short' or `char'. In such cases,
15006 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15007 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15008 passed `int' value. If the debugger then uses that address to fetch
15009 a `short' or a `char' (on a little-endian machine) the result will be
15010 the correct data, so we allow for such exceptional cases below.
15012 Note that our goal here is to describe the place where the given formal
15013 parameter lives during most of the function's activation (i.e. between the
15014 end of the prologue and the start of the epilogue). We'll do that as best
15015 as we can. Note however that if the given formal parameter is modified
15016 sometime during the execution of the function, then a stack backtrace (at
15017 debug-time) will show the function as having been called with the *new*
15018 value rather than the value which was originally passed in. This happens
15019 rarely enough that it is not a major problem, but it *is* a problem, and
15020 I'd like to fix it.
15022 A future version of dwarf2out.c may generate two additional attributes for
15023 any given DW_TAG_formal_parameter DIE which will describe the "passed
15024 type" and the "passed location" for the given formal parameter in addition
15025 to the attributes we now generate to indicate the "declared type" and the
15026 "active location" for each parameter. This additional set of attributes
15027 could be used by debuggers for stack backtraces. Separately, note that
15028 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15029 This happens (for example) for inlined-instances of inline function formal
15030 parameters which are never referenced. This really shouldn't be
15031 happening. All PARM_DECL nodes should get valid non-NULL
15032 DECL_INCOMING_RTL values. FIXME. */
15034 /* Use DECL_RTL as the "location" unless we find something better. */
15035 rtl
= DECL_RTL_IF_SET (decl
);
15037 /* When generating abstract instances, ignore everything except
15038 constants, symbols living in memory, and symbols living in
15039 fixed registers. */
15040 if (! reload_completed
)
15043 && (CONSTANT_P (rtl
)
15045 && CONSTANT_P (XEXP (rtl
, 0)))
15047 && TREE_CODE (decl
) == VAR_DECL
15048 && TREE_STATIC (decl
))))
15050 rtl
= targetm
.delegitimize_address (rtl
);
15055 else if (TREE_CODE (decl
) == PARM_DECL
)
15057 if (rtl
== NULL_RTX
15058 || is_pseudo_reg (rtl
)
15060 && is_pseudo_reg (XEXP (rtl
, 0))
15061 && DECL_INCOMING_RTL (decl
)
15062 && MEM_P (DECL_INCOMING_RTL (decl
))
15063 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15065 tree declared_type
= TREE_TYPE (decl
);
15066 tree passed_type
= DECL_ARG_TYPE (decl
);
15067 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15068 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15070 /* This decl represents a formal parameter which was optimized out.
15071 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15072 all cases where (rtl == NULL_RTX) just below. */
15073 if (dmode
== pmode
)
15074 rtl
= DECL_INCOMING_RTL (decl
);
15075 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15076 && SCALAR_INT_MODE_P (dmode
)
15077 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15078 && DECL_INCOMING_RTL (decl
))
15080 rtx inc
= DECL_INCOMING_RTL (decl
);
15083 else if (MEM_P (inc
))
15085 if (BYTES_BIG_ENDIAN
)
15086 rtl
= adjust_address_nv (inc
, dmode
,
15087 GET_MODE_SIZE (pmode
)
15088 - GET_MODE_SIZE (dmode
));
15095 /* If the parm was passed in registers, but lives on the stack, then
15096 make a big endian correction if the mode of the type of the
15097 parameter is not the same as the mode of the rtl. */
15098 /* ??? This is the same series of checks that are made in dbxout.c before
15099 we reach the big endian correction code there. It isn't clear if all
15100 of these checks are necessary here, but keeping them all is the safe
15102 else if (MEM_P (rtl
)
15103 && XEXP (rtl
, 0) != const0_rtx
15104 && ! CONSTANT_P (XEXP (rtl
, 0))
15105 /* Not passed in memory. */
15106 && !MEM_P (DECL_INCOMING_RTL (decl
))
15107 /* Not passed by invisible reference. */
15108 && (!REG_P (XEXP (rtl
, 0))
15109 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15110 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15111 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15112 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15115 /* Big endian correction check. */
15116 && BYTES_BIG_ENDIAN
15117 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15118 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15121 enum machine_mode addr_mode
= get_address_mode (rtl
);
15122 int offset
= (UNITS_PER_WORD
15123 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15125 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15126 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15129 else if (TREE_CODE (decl
) == VAR_DECL
15132 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15133 && BYTES_BIG_ENDIAN
)
15135 enum machine_mode addr_mode
= get_address_mode (rtl
);
15136 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15137 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15139 /* If a variable is declared "register" yet is smaller than
15140 a register, then if we store the variable to memory, it
15141 looks like we're storing a register-sized value, when in
15142 fact we are not. We need to adjust the offset of the
15143 storage location to reflect the actual value's bytes,
15144 else gdb will not be able to display it. */
15146 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15147 plus_constant (addr_mode
, XEXP (rtl
, 0),
15151 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15152 and will have been substituted directly into all expressions that use it.
15153 C does not have such a concept, but C++ and other languages do. */
15154 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15155 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15158 rtl
= targetm
.delegitimize_address (rtl
);
15160 /* If we don't look past the constant pool, we risk emitting a
15161 reference to a constant pool entry that isn't referenced from
15162 code, and thus is not emitted. */
15164 rtl
= avoid_constant_pool_reference (rtl
);
15166 /* Try harder to get a rtl. If this symbol ends up not being emitted
15167 in the current CU, resolve_addr will remove the expression referencing
15169 if (rtl
== NULL_RTX
15170 && TREE_CODE (decl
) == VAR_DECL
15171 && !DECL_EXTERNAL (decl
)
15172 && TREE_STATIC (decl
)
15173 && DECL_NAME (decl
)
15174 && !DECL_HARD_REGISTER (decl
)
15175 && DECL_MODE (decl
) != VOIDmode
)
15177 rtl
= make_decl_rtl_for_debug (decl
);
15179 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15180 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15187 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15188 returned. If so, the decl for the COMMON block is returned, and the
15189 value is the offset into the common block for the symbol. */
15192 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15194 tree val_expr
, cvar
;
15195 enum machine_mode mode
;
15196 HOST_WIDE_INT bitsize
, bitpos
;
15198 int unsignedp
, volatilep
= 0;
15200 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15201 it does not have a value (the offset into the common area), or if it
15202 is thread local (as opposed to global) then it isn't common, and shouldn't
15203 be handled as such. */
15204 if (TREE_CODE (decl
) != VAR_DECL
15205 || !TREE_STATIC (decl
)
15206 || !DECL_HAS_VALUE_EXPR_P (decl
)
15210 val_expr
= DECL_VALUE_EXPR (decl
);
15211 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15214 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15215 &mode
, &unsignedp
, &volatilep
, true);
15217 if (cvar
== NULL_TREE
15218 || TREE_CODE (cvar
) != VAR_DECL
15219 || DECL_ARTIFICIAL (cvar
)
15220 || !TREE_PUBLIC (cvar
))
15224 if (offset
!= NULL
)
15226 if (!host_integerp (offset
, 0))
15228 *value
= tree_low_cst (offset
, 0);
15231 *value
+= bitpos
/ BITS_PER_UNIT
;
15236 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15237 data attribute for a variable or a parameter. We generate the
15238 DW_AT_const_value attribute only in those cases where the given variable
15239 or parameter does not have a true "location" either in memory or in a
15240 register. This can happen (for example) when a constant is passed as an
15241 actual argument in a call to an inline function. (It's possible that
15242 these things can crop up in other ways also.) Note that one type of
15243 constant value which can be passed into an inlined function is a constant
15244 pointer. This can happen for example if an actual argument in an inlined
15245 function call evaluates to a compile-time constant address.
15247 CACHE_P is true if it is worth caching the location list for DECL,
15248 so that future calls can reuse it rather than regenerate it from scratch.
15249 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15250 since we will need to refer to them each time the function is inlined. */
15253 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15254 enum dwarf_attribute attr
)
15257 dw_loc_list_ref list
;
15258 var_loc_list
*loc_list
;
15259 cached_dw_loc_list
*cache
;
15262 if (TREE_CODE (decl
) == ERROR_MARK
)
15265 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15266 || TREE_CODE (decl
) == RESULT_DECL
);
15268 /* Try to get some constant RTL for this decl, and use that as the value of
15271 rtl
= rtl_for_decl_location (decl
);
15272 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15273 && add_const_value_attribute (die
, rtl
))
15276 /* See if we have single element location list that is equivalent to
15277 a constant value. That way we are better to use add_const_value_attribute
15278 rather than expanding constant value equivalent. */
15279 loc_list
= lookup_decl_loc (decl
);
15282 && loc_list
->first
->next
== NULL
15283 && NOTE_P (loc_list
->first
->loc
)
15284 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15285 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15287 struct var_loc_node
*node
;
15289 node
= loc_list
->first
;
15290 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15291 if (GET_CODE (rtl
) == EXPR_LIST
)
15292 rtl
= XEXP (rtl
, 0);
15293 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15294 && add_const_value_attribute (die
, rtl
))
15297 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15298 list several times. See if we've already cached the contents. */
15300 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15304 cache
= (cached_dw_loc_list
*)
15305 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15307 list
= cache
->loc_list
;
15311 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15312 /* It is usually worth caching this result if the decl is from
15313 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15314 if (cache_p
&& list
&& list
->dw_loc_next
)
15316 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15317 DECL_UID (decl
), INSERT
);
15318 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15319 cache
->decl_id
= DECL_UID (decl
);
15320 cache
->loc_list
= list
;
15326 add_AT_location_description (die
, attr
, list
);
15329 /* None of that worked, so it must not really have a location;
15330 try adding a constant value attribute from the DECL_INITIAL. */
15331 return tree_add_const_value_attribute_for_decl (die
, decl
);
15334 /* Add VARIABLE and DIE into deferred locations list. */
15337 defer_location (tree variable
, dw_die_ref die
)
15339 deferred_locations entry
;
15340 entry
.variable
= variable
;
15342 vec_safe_push (deferred_locations_list
, entry
);
15345 /* Helper function for tree_add_const_value_attribute. Natively encode
15346 initializer INIT into an array. Return true if successful. */
15349 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15353 if (init
== NULL_TREE
)
15357 switch (TREE_CODE (init
))
15360 type
= TREE_TYPE (init
);
15361 if (TREE_CODE (type
) == ARRAY_TYPE
)
15363 tree enttype
= TREE_TYPE (type
);
15364 enum machine_mode mode
= TYPE_MODE (enttype
);
15366 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15368 if (int_size_in_bytes (type
) != size
)
15370 if (size
> TREE_STRING_LENGTH (init
))
15372 memcpy (array
, TREE_STRING_POINTER (init
),
15373 TREE_STRING_LENGTH (init
));
15374 memset (array
+ TREE_STRING_LENGTH (init
),
15375 '\0', size
- TREE_STRING_LENGTH (init
));
15378 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15383 type
= TREE_TYPE (init
);
15384 if (int_size_in_bytes (type
) != size
)
15386 if (TREE_CODE (type
) == ARRAY_TYPE
)
15388 HOST_WIDE_INT min_index
;
15389 unsigned HOST_WIDE_INT cnt
;
15390 int curpos
= 0, fieldsize
;
15391 constructor_elt
*ce
;
15393 if (TYPE_DOMAIN (type
) == NULL_TREE
15394 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15397 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15398 if (fieldsize
<= 0)
15401 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15402 memset (array
, '\0', size
);
15403 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15405 tree val
= ce
->value
;
15406 tree index
= ce
->index
;
15408 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15409 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15412 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15417 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15420 curpos
= pos
+ fieldsize
;
15421 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15423 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15424 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15425 while (count
-- > 0)
15428 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15429 curpos
+= fieldsize
;
15432 gcc_assert (curpos
<= size
);
15436 else if (TREE_CODE (type
) == RECORD_TYPE
15437 || TREE_CODE (type
) == UNION_TYPE
)
15439 tree field
= NULL_TREE
;
15440 unsigned HOST_WIDE_INT cnt
;
15441 constructor_elt
*ce
;
15443 if (int_size_in_bytes (type
) != size
)
15446 if (TREE_CODE (type
) == RECORD_TYPE
)
15447 field
= TYPE_FIELDS (type
);
15449 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15451 tree val
= ce
->value
;
15452 int pos
, fieldsize
;
15454 if (ce
->index
!= 0)
15460 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15463 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15464 && TYPE_DOMAIN (TREE_TYPE (field
))
15465 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15467 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15468 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15470 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15471 pos
= int_byte_position (field
);
15472 gcc_assert (pos
+ fieldsize
<= size
);
15474 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15480 case VIEW_CONVERT_EXPR
:
15481 case NON_LVALUE_EXPR
:
15482 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15484 return native_encode_expr (init
, array
, size
) == size
;
15488 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15489 attribute is the const value T. */
15492 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15495 tree type
= TREE_TYPE (t
);
15498 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15502 gcc_assert (!DECL_P (init
));
15504 rtl
= rtl_for_decl_init (init
, type
);
15506 return add_const_value_attribute (die
, rtl
);
15507 /* If the host and target are sane, try harder. */
15508 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15509 && initializer_constant_valid_p (init
, type
))
15511 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15512 if (size
> 0 && (int) size
== size
)
15514 unsigned char *array
= (unsigned char *)
15515 ggc_alloc_cleared_atomic (size
);
15517 if (native_encode_initializer (init
, array
, size
))
15519 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15527 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15528 attribute is the const value of T, where T is an integral constant
15529 variable with static storage duration
15530 (so it can't be a PARM_DECL or a RESULT_DECL). */
15533 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15537 || (TREE_CODE (decl
) != VAR_DECL
15538 && TREE_CODE (decl
) != CONST_DECL
)
15539 || (TREE_CODE (decl
) == VAR_DECL
15540 && !TREE_STATIC (decl
)))
15543 if (TREE_READONLY (decl
)
15544 && ! TREE_THIS_VOLATILE (decl
)
15545 && DECL_INITIAL (decl
))
15550 /* Don't add DW_AT_const_value if abstract origin already has one. */
15551 if (get_AT (var_die
, DW_AT_const_value
))
15554 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15557 /* Convert the CFI instructions for the current function into a
15558 location list. This is used for DW_AT_frame_base when we targeting
15559 a dwarf2 consumer that does not support the dwarf3
15560 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15563 static dw_loc_list_ref
15564 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15568 dw_loc_list_ref list
, *list_tail
;
15570 dw_cfa_location last_cfa
, next_cfa
;
15571 const char *start_label
, *last_label
, *section
;
15572 dw_cfa_location remember
;
15575 gcc_assert (fde
!= NULL
);
15577 section
= secname_for_decl (current_function_decl
);
15581 memset (&next_cfa
, 0, sizeof (next_cfa
));
15582 next_cfa
.reg
= INVALID_REGNUM
;
15583 remember
= next_cfa
;
15585 start_label
= fde
->dw_fde_begin
;
15587 /* ??? Bald assumption that the CIE opcode list does not contain
15588 advance opcodes. */
15589 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15590 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15592 last_cfa
= next_cfa
;
15593 last_label
= start_label
;
15595 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15597 /* If the first partition contained no CFI adjustments, the
15598 CIE opcodes apply to the whole first partition. */
15599 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15600 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15601 list_tail
=&(*list_tail
)->dw_loc_next
;
15602 start_label
= last_label
= fde
->dw_fde_second_begin
;
15605 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15607 switch (cfi
->dw_cfi_opc
)
15609 case DW_CFA_set_loc
:
15610 case DW_CFA_advance_loc1
:
15611 case DW_CFA_advance_loc2
:
15612 case DW_CFA_advance_loc4
:
15613 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15615 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15616 start_label
, last_label
, section
);
15618 list_tail
= &(*list_tail
)->dw_loc_next
;
15619 last_cfa
= next_cfa
;
15620 start_label
= last_label
;
15622 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15625 case DW_CFA_advance_loc
:
15626 /* The encoding is complex enough that we should never emit this. */
15627 gcc_unreachable ();
15630 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15633 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15635 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15637 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15638 start_label
, last_label
, section
);
15640 list_tail
= &(*list_tail
)->dw_loc_next
;
15641 last_cfa
= next_cfa
;
15642 start_label
= last_label
;
15644 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15645 start_label
, fde
->dw_fde_end
, section
);
15646 list_tail
= &(*list_tail
)->dw_loc_next
;
15647 start_label
= last_label
= fde
->dw_fde_second_begin
;
15651 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15653 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15654 start_label
, last_label
, section
);
15655 list_tail
= &(*list_tail
)->dw_loc_next
;
15656 start_label
= last_label
;
15659 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15661 fde
->dw_fde_second_begin
15662 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15665 if (list
&& list
->dw_loc_next
)
15671 /* Compute a displacement from the "steady-state frame pointer" to the
15672 frame base (often the same as the CFA), and store it in
15673 frame_pointer_fb_offset. OFFSET is added to the displacement
15674 before the latter is negated. */
15677 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15681 #ifdef FRAME_POINTER_CFA_OFFSET
15682 reg
= frame_pointer_rtx
;
15683 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15685 reg
= arg_pointer_rtx
;
15686 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15689 elim
= (ira_use_lra_p
15690 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15691 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15692 if (GET_CODE (elim
) == PLUS
)
15694 offset
+= INTVAL (XEXP (elim
, 1));
15695 elim
= XEXP (elim
, 0);
15698 frame_pointer_fb_offset
= -offset
;
15700 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15701 in which to eliminate. This is because it's stack pointer isn't
15702 directly accessible as a register within the ISA. To work around
15703 this, assume that while we cannot provide a proper value for
15704 frame_pointer_fb_offset, we won't need one either. */
15705 frame_pointer_fb_offset_valid
15706 = ((SUPPORTS_STACK_ALIGNMENT
15707 && (elim
== hard_frame_pointer_rtx
15708 || elim
== stack_pointer_rtx
))
15709 || elim
== (frame_pointer_needed
15710 ? hard_frame_pointer_rtx
15711 : stack_pointer_rtx
));
15714 /* Generate a DW_AT_name attribute given some string value to be included as
15715 the value of the attribute. */
15718 add_name_attribute (dw_die_ref die
, const char *name_string
)
15720 if (name_string
!= NULL
&& *name_string
!= 0)
15722 if (demangle_name_func
)
15723 name_string
= (*demangle_name_func
) (name_string
);
15725 add_AT_string (die
, DW_AT_name
, name_string
);
15729 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15730 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15731 of TYPE accordingly.
15733 ??? This is a temporary measure until after we're able to generate
15734 regular DWARF for the complex Ada type system. */
15737 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15738 dw_die_ref context_die
)
15741 dw_die_ref dtype_die
;
15743 if (!lang_hooks
.types
.descriptive_type
)
15746 dtype
= lang_hooks
.types
.descriptive_type (type
);
15750 dtype_die
= lookup_type_die (dtype
);
15753 gen_type_die (dtype
, context_die
);
15754 dtype_die
= lookup_type_die (dtype
);
15755 gcc_assert (dtype_die
);
15758 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15761 /* Generate a DW_AT_comp_dir attribute for DIE. */
15764 add_comp_dir_attribute (dw_die_ref die
)
15766 const char *wd
= get_src_pwd ();
15772 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15776 wdlen
= strlen (wd
);
15777 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15779 wd1
[wdlen
] = DIR_SEPARATOR
;
15780 wd1
[wdlen
+ 1] = 0;
15784 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
15787 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15791 lower_bound_default (void)
15793 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15798 case DW_LANG_C_plus_plus
:
15800 case DW_LANG_ObjC_plus_plus
:
15803 case DW_LANG_Fortran77
:
15804 case DW_LANG_Fortran90
:
15805 case DW_LANG_Fortran95
:
15809 case DW_LANG_Python
:
15810 return dwarf_version
>= 4 ? 0 : -1;
15811 case DW_LANG_Ada95
:
15812 case DW_LANG_Ada83
:
15813 case DW_LANG_Cobol74
:
15814 case DW_LANG_Cobol85
:
15815 case DW_LANG_Pascal83
:
15816 case DW_LANG_Modula2
:
15818 return dwarf_version
>= 4 ? 1 : -1;
15824 /* Given a tree node describing an array bound (either lower or upper) output
15825 a representation for that bound. */
15828 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15830 switch (TREE_CODE (bound
))
15835 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15838 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15841 /* Use the default if possible. */
15842 if (bound_attr
== DW_AT_lower_bound
15843 && host_integerp (bound
, 0)
15844 && (dflt
= lower_bound_default ()) != -1
15845 && tree_low_cst (bound
, 0) == dflt
)
15848 /* Otherwise represent the bound as an unsigned value with the
15849 precision of its type. The precision and signedness of the
15850 type will be necessary to re-interpret it unambiguously. */
15851 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15853 unsigned HOST_WIDE_INT mask
15854 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15855 add_AT_unsigned (subrange_die
, bound_attr
,
15856 TREE_INT_CST_LOW (bound
) & mask
);
15858 else if (prec
== HOST_BITS_PER_WIDE_INT
15859 || TREE_INT_CST_HIGH (bound
) == 0)
15860 add_AT_unsigned (subrange_die
, bound_attr
,
15861 TREE_INT_CST_LOW (bound
));
15863 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
15864 TREE_INT_CST_LOW (bound
));
15869 case VIEW_CONVERT_EXPR
:
15870 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
15880 dw_die_ref decl_die
= lookup_decl_die (bound
);
15882 /* ??? Can this happen, or should the variable have been bound
15883 first? Probably it can, since I imagine that we try to create
15884 the types of parameters in the order in which they exist in
15885 the list, and won't have created a forward reference to a
15886 later parameter. */
15887 if (decl_die
!= NULL
)
15889 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15897 /* Otherwise try to create a stack operation procedure to
15898 evaluate the value of the array bound. */
15900 dw_die_ref ctx
, decl_die
;
15901 dw_loc_list_ref list
;
15903 list
= loc_list_from_tree (bound
, 2);
15904 if (list
== NULL
|| single_element_loc_list_p (list
))
15906 /* If DW_AT_*bound is not a reference nor constant, it is
15907 a DWARF expression rather than location description.
15908 For that loc_list_from_tree (bound, 0) is needed.
15909 If that fails to give a single element list,
15910 fall back to outputting this as a reference anyway. */
15911 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
15912 if (list2
&& single_element_loc_list_p (list2
))
15914 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
15921 if (current_function_decl
== 0)
15922 ctx
= comp_unit_die ();
15924 ctx
= lookup_decl_die (current_function_decl
);
15926 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
15927 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
15928 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
15929 add_AT_location_description (decl_die
, DW_AT_location
, list
);
15930 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15936 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15937 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15938 Note that the block of subscript information for an array type also
15939 includes information about the element type of the given array type. */
15942 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
15944 unsigned dimension_number
;
15946 dw_die_ref subrange_die
;
15948 for (dimension_number
= 0;
15949 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
15950 type
= TREE_TYPE (type
), dimension_number
++)
15952 tree domain
= TYPE_DOMAIN (type
);
15954 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
15957 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15958 and (in GNU C only) variable bounds. Handle all three forms
15960 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
15963 /* We have an array type with specified bounds. */
15964 lower
= TYPE_MIN_VALUE (domain
);
15965 upper
= TYPE_MAX_VALUE (domain
);
15967 /* Define the index type. */
15968 if (TREE_TYPE (domain
))
15970 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15971 TREE_TYPE field. We can't emit debug info for this
15972 because it is an unnamed integral type. */
15973 if (TREE_CODE (domain
) == INTEGER_TYPE
15974 && TYPE_NAME (domain
) == NULL_TREE
15975 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
15976 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
15979 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
15983 /* ??? If upper is NULL, the array has unspecified length,
15984 but it does have a lower bound. This happens with Fortran
15986 Since the debugger is definitely going to need to know N
15987 to produce useful results, go ahead and output the lower
15988 bound solo, and hope the debugger can cope. */
15990 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
15992 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
15995 /* Otherwise we have an array type with an unspecified length. The
15996 DWARF-2 spec does not say how to handle this; let's just leave out the
16002 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16004 dw_die_ref decl_die
;
16007 switch (TREE_CODE (tree_node
))
16012 case ENUMERAL_TYPE
:
16015 case QUAL_UNION_TYPE
:
16016 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16017 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16019 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16022 size
= int_size_in_bytes (tree_node
);
16025 /* For a data member of a struct or union, the DW_AT_byte_size is
16026 generally given as the number of bytes normally allocated for an
16027 object of the *declared* type of the member itself. This is true
16028 even for bit-fields. */
16029 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16032 gcc_unreachable ();
16035 /* Note that `size' might be -1 when we get to this point. If it is, that
16036 indicates that the byte size of the entity in question is variable. We
16037 have no good way of expressing this fact in Dwarf at the present time,
16038 so just let the -1 pass on through. */
16039 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16042 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16043 which specifies the distance in bits from the highest order bit of the
16044 "containing object" for the bit-field to the highest order bit of the
16047 For any given bit-field, the "containing object" is a hypothetical object
16048 (of some integral or enum type) within which the given bit-field lives. The
16049 type of this hypothetical "containing object" is always the same as the
16050 declared type of the individual bit-field itself. The determination of the
16051 exact location of the "containing object" for a bit-field is rather
16052 complicated. It's handled by the `field_byte_offset' function (above).
16054 Note that it is the size (in bytes) of the hypothetical "containing object"
16055 which will be given in the DW_AT_byte_size attribute for this bit-field.
16056 (See `byte_size_attribute' above). */
16059 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16061 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16062 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16063 HOST_WIDE_INT bitpos_int
;
16064 HOST_WIDE_INT highest_order_object_bit_offset
;
16065 HOST_WIDE_INT highest_order_field_bit_offset
;
16066 HOST_WIDE_INT bit_offset
;
16068 /* Must be a field and a bit field. */
16069 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16071 /* We can't yet handle bit-fields whose offsets are variable, so if we
16072 encounter such things, just return without generating any attribute
16073 whatsoever. Likewise for variable or too large size. */
16074 if (! host_integerp (bit_position (decl
), 0)
16075 || ! host_integerp (DECL_SIZE (decl
), 1))
16078 bitpos_int
= int_bit_position (decl
);
16080 /* Note that the bit offset is always the distance (in bits) from the
16081 highest-order bit of the "containing object" to the highest-order bit of
16082 the bit-field itself. Since the "high-order end" of any object or field
16083 is different on big-endian and little-endian machines, the computation
16084 below must take account of these differences. */
16085 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16086 highest_order_field_bit_offset
= bitpos_int
;
16088 if (! BYTES_BIG_ENDIAN
)
16090 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16091 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16095 = (! BYTES_BIG_ENDIAN
16096 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16097 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16099 if (bit_offset
< 0)
16100 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16102 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16105 /* For a FIELD_DECL node which represents a bit field, output an attribute
16106 which specifies the length in bits of the given field. */
16109 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16111 /* Must be a field and a bit field. */
16112 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16113 && DECL_BIT_FIELD_TYPE (decl
));
16115 if (host_integerp (DECL_SIZE (decl
), 1))
16116 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16119 /* If the compiled language is ANSI C, then add a 'prototyped'
16120 attribute, if arg types are given for the parameters of a function. */
16123 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16125 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16126 && prototype_p (func_type
))
16127 add_AT_flag (die
, DW_AT_prototyped
, 1);
16130 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16131 by looking in either the type declaration or object declaration
16134 static inline dw_die_ref
16135 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16137 dw_die_ref origin_die
= NULL
;
16139 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16141 /* We may have gotten separated from the block for the inlined
16142 function, if we're in an exception handler or some such; make
16143 sure that the abstract function has been written out.
16145 Doing this for nested functions is wrong, however; functions are
16146 distinct units, and our context might not even be inline. */
16150 fn
= TYPE_STUB_DECL (fn
);
16152 fn
= decl_function_context (fn
);
16154 dwarf2out_abstract_function (fn
);
16157 if (DECL_P (origin
))
16158 origin_die
= lookup_decl_die (origin
);
16159 else if (TYPE_P (origin
))
16160 origin_die
= lookup_type_die (origin
);
16162 /* XXX: Functions that are never lowered don't always have correct block
16163 trees (in the case of java, they simply have no block tree, in some other
16164 languages). For these functions, there is nothing we can really do to
16165 output correct debug info for inlined functions in all cases. Rather
16166 than die, we'll just produce deficient debug info now, in that we will
16167 have variables without a proper abstract origin. In the future, when all
16168 functions are lowered, we should re-add a gcc_assert (origin_die)
16172 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16176 /* We do not currently support the pure_virtual attribute. */
16179 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16181 if (DECL_VINDEX (func_decl
))
16183 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16185 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16186 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16187 new_loc_descr (DW_OP_constu
,
16188 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16191 /* GNU extension: Record what type this method came from originally. */
16192 if (debug_info_level
> DINFO_LEVEL_TERSE
16193 && DECL_CONTEXT (func_decl
))
16194 add_AT_die_ref (die
, DW_AT_containing_type
,
16195 lookup_type_die (DECL_CONTEXT (func_decl
)));
16199 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16200 given decl. This used to be a vendor extension until after DWARF 4
16201 standardized it. */
16204 add_linkage_attr (dw_die_ref die
, tree decl
)
16206 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16208 /* Mimic what assemble_name_raw does with a leading '*'. */
16209 if (name
[0] == '*')
16212 if (dwarf_version
>= 4)
16213 add_AT_string (die
, DW_AT_linkage_name
, name
);
16215 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16218 /* Add source coordinate attributes for the given decl. */
16221 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16223 expanded_location s
;
16225 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16227 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16228 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16229 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16232 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16235 add_linkage_name (dw_die_ref die
, tree decl
)
16237 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16238 && TREE_PUBLIC (decl
)
16239 && !DECL_ABSTRACT (decl
)
16240 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16241 && die
->die_tag
!= DW_TAG_member
)
16243 /* Defer until we have an assembler name set. */
16244 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16246 limbo_die_node
*asm_name
;
16248 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16249 asm_name
->die
= die
;
16250 asm_name
->created_for
= decl
;
16251 asm_name
->next
= deferred_asm_name
;
16252 deferred_asm_name
= asm_name
;
16254 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16255 add_linkage_attr (die
, decl
);
16259 /* Add a DW_AT_name attribute and source coordinate attribute for the
16260 given decl, but only if it actually has a name. */
16263 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16267 decl_name
= DECL_NAME (decl
);
16268 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16270 const char *name
= dwarf2_name (decl
, 0);
16272 add_name_attribute (die
, name
);
16273 if (! DECL_ARTIFICIAL (decl
))
16274 add_src_coords_attributes (die
, decl
);
16276 add_linkage_name (die
, decl
);
16279 #ifdef VMS_DEBUGGING_INFO
16280 /* Get the function's name, as described by its RTL. This may be different
16281 from the DECL_NAME name used in the source file. */
16282 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16284 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16285 XEXP (DECL_RTL (decl
), 0), false);
16286 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16288 #endif /* VMS_DEBUGGING_INFO */
16291 #ifdef VMS_DEBUGGING_INFO
16292 /* Output the debug main pointer die for VMS */
16295 dwarf2out_vms_debug_main_pointer (void)
16297 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16300 /* Allocate the VMS debug main subprogram die. */
16301 die
= ggc_alloc_cleared_die_node ();
16302 die
->die_tag
= DW_TAG_subprogram
;
16303 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16304 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16305 current_function_funcdef_no
);
16306 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16308 /* Make it the first child of comp_unit_die (). */
16309 die
->die_parent
= comp_unit_die ();
16310 if (comp_unit_die ()->die_child
)
16312 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16313 comp_unit_die ()->die_child
->die_sib
= die
;
16317 die
->die_sib
= die
;
16318 comp_unit_die ()->die_child
= die
;
16321 #endif /* VMS_DEBUGGING_INFO */
16323 /* Push a new declaration scope. */
16326 push_decl_scope (tree scope
)
16328 vec_safe_push (decl_scope_table
, scope
);
16331 /* Pop a declaration scope. */
16334 pop_decl_scope (void)
16336 decl_scope_table
->pop ();
16339 /* walk_tree helper function for uses_local_type, below. */
16342 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16345 *walk_subtrees
= 0;
16348 tree name
= TYPE_NAME (*tp
);
16349 if (name
&& DECL_P (name
) && decl_function_context (name
))
16355 /* If TYPE involves a function-local type (including a local typedef to a
16356 non-local type), returns that type; otherwise returns NULL_TREE. */
16359 uses_local_type (tree type
)
16361 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16365 /* Return the DIE for the scope that immediately contains this type.
16366 Non-named types that do not involve a function-local type get global
16367 scope. Named types nested in namespaces or other types get their
16368 containing scope. All other types (i.e. function-local named types) get
16369 the current active scope. */
16372 scope_die_for (tree t
, dw_die_ref context_die
)
16374 dw_die_ref scope_die
= NULL
;
16375 tree containing_scope
;
16377 /* Non-types always go in the current scope. */
16378 gcc_assert (TYPE_P (t
));
16380 /* Use the scope of the typedef, rather than the scope of the type
16382 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16383 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16385 containing_scope
= TYPE_CONTEXT (t
);
16387 /* Use the containing namespace if there is one. */
16388 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16390 if (context_die
== lookup_decl_die (containing_scope
))
16392 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16393 context_die
= get_context_die (containing_scope
);
16395 containing_scope
= NULL_TREE
;
16398 /* Ignore function type "scopes" from the C frontend. They mean that
16399 a tagged type is local to a parmlist of a function declarator, but
16400 that isn't useful to DWARF. */
16401 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16402 containing_scope
= NULL_TREE
;
16404 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16406 /* If T uses a local type keep it local as well, to avoid references
16407 to function-local DIEs from outside the function. */
16408 if (current_function_decl
&& uses_local_type (t
))
16409 scope_die
= context_die
;
16411 scope_die
= comp_unit_die ();
16413 else if (TYPE_P (containing_scope
))
16415 /* For types, we can just look up the appropriate DIE. */
16416 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16417 scope_die
= get_context_die (containing_scope
);
16420 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16421 if (scope_die
== NULL
)
16422 scope_die
= comp_unit_die ();
16426 scope_die
= context_die
;
16431 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16434 local_scope_p (dw_die_ref context_die
)
16436 for (; context_die
; context_die
= context_die
->die_parent
)
16437 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16438 || context_die
->die_tag
== DW_TAG_subprogram
)
16444 /* Returns nonzero if CONTEXT_DIE is a class. */
16447 class_scope_p (dw_die_ref context_die
)
16449 return (context_die
16450 && (context_die
->die_tag
== DW_TAG_structure_type
16451 || context_die
->die_tag
== DW_TAG_class_type
16452 || context_die
->die_tag
== DW_TAG_interface_type
16453 || context_die
->die_tag
== DW_TAG_union_type
));
16456 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16457 whether or not to treat a DIE in this context as a declaration. */
16460 class_or_namespace_scope_p (dw_die_ref context_die
)
16462 return (class_scope_p (context_die
)
16463 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16466 /* Many forms of DIEs require a "type description" attribute. This
16467 routine locates the proper "type descriptor" die for the type given
16468 by 'type', and adds a DW_AT_type attribute below the given die. */
16471 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16472 int decl_volatile
, dw_die_ref context_die
)
16474 enum tree_code code
= TREE_CODE (type
);
16475 dw_die_ref type_die
= NULL
;
16477 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16478 or fixed-point type, use the inner type. This is because we have no
16479 support for unnamed types in base_type_die. This can happen if this is
16480 an Ada subrange type. Correct solution is emit a subrange type die. */
16481 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16482 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16483 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16485 if (code
== ERROR_MARK
16486 /* Handle a special case. For functions whose return type is void, we
16487 generate *no* type attribute. (Note that no object may have type
16488 `void', so this only applies to function return types). */
16489 || code
== VOID_TYPE
)
16492 type_die
= modified_type_die (type
,
16493 decl_const
|| TYPE_READONLY (type
),
16494 decl_volatile
|| TYPE_VOLATILE (type
),
16497 if (type_die
!= NULL
)
16498 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16501 /* Given an object die, add the calling convention attribute for the
16502 function call type. */
16504 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16506 enum dwarf_calling_convention value
= DW_CC_normal
;
16508 value
= ((enum dwarf_calling_convention
)
16509 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16512 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16514 /* DWARF 2 doesn't provide a way to identify a program's source-level
16515 entry point. DW_AT_calling_convention attributes are only meant
16516 to describe functions' calling conventions. However, lacking a
16517 better way to signal the Fortran main program, we used this for
16518 a long time, following existing custom. Now, DWARF 4 has
16519 DW_AT_main_subprogram, which we add below, but some tools still
16520 rely on the old way, which we thus keep. */
16521 value
= DW_CC_program
;
16523 if (dwarf_version
>= 4 || !dwarf_strict
)
16524 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16527 /* Only add the attribute if the backend requests it, and
16528 is not DW_CC_normal. */
16529 if (value
&& (value
!= DW_CC_normal
))
16530 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16533 /* Given a tree pointer to a struct, class, union, or enum type node, return
16534 a pointer to the (string) tag name for the given type, or zero if the type
16535 was declared without a tag. */
16537 static const char *
16538 type_tag (const_tree type
)
16540 const char *name
= 0;
16542 if (TYPE_NAME (type
) != 0)
16546 /* Find the IDENTIFIER_NODE for the type name. */
16547 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16548 && !TYPE_NAMELESS (type
))
16549 t
= TYPE_NAME (type
);
16551 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16552 a TYPE_DECL node, regardless of whether or not a `typedef' was
16554 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16555 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16557 /* We want to be extra verbose. Don't call dwarf_name if
16558 DECL_NAME isn't set. The default hook for decl_printable_name
16559 doesn't like that, and in this context it's correct to return
16560 0, instead of "<anonymous>" or the like. */
16561 if (DECL_NAME (TYPE_NAME (type
))
16562 && !DECL_NAMELESS (TYPE_NAME (type
)))
16563 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16566 /* Now get the name as a string, or invent one. */
16567 if (!name
&& t
!= 0)
16568 name
= IDENTIFIER_POINTER (t
);
16571 return (name
== 0 || *name
== '\0') ? 0 : name
;
16574 /* Return the type associated with a data member, make a special check
16575 for bit field types. */
16578 member_declared_type (const_tree member
)
16580 return (DECL_BIT_FIELD_TYPE (member
)
16581 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16584 /* Get the decl's label, as described by its RTL. This may be different
16585 from the DECL_NAME name used in the source file. */
16588 static const char *
16589 decl_start_label (tree decl
)
16592 const char *fnname
;
16594 x
= DECL_RTL (decl
);
16595 gcc_assert (MEM_P (x
));
16598 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16600 fnname
= XSTR (x
, 0);
16605 /* These routines generate the internal representation of the DIE's for
16606 the compilation unit. Debugging information is collected by walking
16607 the declaration trees passed in from dwarf2out_decl(). */
16610 gen_array_type_die (tree type
, dw_die_ref context_die
)
16612 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16613 dw_die_ref array_die
;
16615 /* GNU compilers represent multidimensional array types as sequences of one
16616 dimensional array types whose element types are themselves array types.
16617 We sometimes squish that down to a single array_type DIE with multiple
16618 subscripts in the Dwarf debugging info. The draft Dwarf specification
16619 say that we are allowed to do this kind of compression in C, because
16620 there is no difference between an array of arrays and a multidimensional
16621 array. We don't do this for Ada to remain as close as possible to the
16622 actual representation, which is especially important against the language
16623 flexibilty wrt arrays of variable size. */
16625 bool collapse_nested_arrays
= !is_ada ();
16628 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16629 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16630 if (TYPE_STRING_FLAG (type
)
16631 && TREE_CODE (type
) == ARRAY_TYPE
16633 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16635 HOST_WIDE_INT size
;
16637 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16638 add_name_attribute (array_die
, type_tag (type
));
16639 equate_type_number_to_die (type
, array_die
);
16640 size
= int_size_in_bytes (type
);
16642 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16643 else if (TYPE_DOMAIN (type
) != NULL_TREE
16644 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16645 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16647 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16648 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16650 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16651 if (loc
&& size
> 0)
16653 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16654 if (size
!= DWARF2_ADDR_SIZE
)
16655 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16661 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16662 add_name_attribute (array_die
, type_tag (type
));
16663 equate_type_number_to_die (type
, array_die
);
16665 if (TREE_CODE (type
) == VECTOR_TYPE
)
16666 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16668 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16670 && TREE_CODE (type
) == ARRAY_TYPE
16671 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16672 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16673 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16676 /* We default the array ordering. SDB will probably do
16677 the right things even if DW_AT_ordering is not present. It's not even
16678 an issue until we start to get into multidimensional arrays anyway. If
16679 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16680 then we'll have to put the DW_AT_ordering attribute back in. (But if
16681 and when we find out that we need to put these in, we will only do so
16682 for multidimensional arrays. */
16683 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16686 if (TREE_CODE (type
) == VECTOR_TYPE
)
16688 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16689 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16690 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16691 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16692 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16695 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16697 /* Add representation of the type of the elements of this array type and
16698 emit the corresponding DIE if we haven't done it already. */
16699 element_type
= TREE_TYPE (type
);
16700 if (collapse_nested_arrays
)
16701 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16703 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16705 element_type
= TREE_TYPE (element_type
);
16708 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16710 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16711 if (TYPE_ARTIFICIAL (type
))
16712 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16714 if (get_AT (array_die
, DW_AT_name
))
16715 add_pubtype (type
, array_die
);
16718 static dw_loc_descr_ref
16719 descr_info_loc (tree val
, tree base_decl
)
16721 HOST_WIDE_INT size
;
16722 dw_loc_descr_ref loc
, loc2
;
16723 enum dwarf_location_atom op
;
16725 if (val
== base_decl
)
16726 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16728 switch (TREE_CODE (val
))
16731 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16733 return loc_descriptor_from_tree (val
, 0);
16735 if (host_integerp (val
, 0))
16736 return int_loc_descriptor (tree_low_cst (val
, 0));
16739 size
= int_size_in_bytes (TREE_TYPE (val
));
16742 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16745 if (size
== DWARF2_ADDR_SIZE
)
16746 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16748 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16750 case POINTER_PLUS_EXPR
:
16752 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16753 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16756 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16759 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16765 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16768 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16771 add_loc_descr (&loc
, loc2
);
16772 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16794 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16795 tree val
, tree base_decl
)
16797 dw_loc_descr_ref loc
;
16799 if (host_integerp (val
, 0))
16801 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16805 loc
= descr_info_loc (val
, base_decl
);
16809 add_AT_loc (die
, attr
, loc
);
16812 /* This routine generates DIE for array with hidden descriptor, details
16813 are filled into *info by a langhook. */
16816 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16817 dw_die_ref context_die
)
16819 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16820 dw_die_ref array_die
;
16823 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16824 add_name_attribute (array_die
, type_tag (type
));
16825 equate_type_number_to_die (type
, array_die
);
16827 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16829 && info
->ndimensions
>= 2)
16830 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16832 if (info
->data_location
)
16833 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16835 if (info
->associated
)
16836 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16838 if (info
->allocated
)
16839 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16842 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16844 dw_die_ref subrange_die
16845 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16847 if (info
->dimen
[dim
].lower_bound
)
16849 /* If it is the default value, omit it. */
16852 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16853 && (dflt
= lower_bound_default ()) != -1
16854 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16857 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16858 info
->dimen
[dim
].lower_bound
,
16861 if (info
->dimen
[dim
].upper_bound
)
16862 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
16863 info
->dimen
[dim
].upper_bound
,
16865 if (info
->dimen
[dim
].stride
)
16866 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
16867 info
->dimen
[dim
].stride
,
16871 gen_type_die (info
->element_type
, context_die
);
16872 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
16874 if (get_AT (array_die
, DW_AT_name
))
16875 add_pubtype (type
, array_die
);
16880 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
16882 tree origin
= decl_ultimate_origin (decl
);
16883 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
16885 if (origin
!= NULL
)
16886 add_abstract_origin_attribute (decl_die
, origin
);
16889 add_name_and_src_coords_attributes (decl_die
, decl
);
16890 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
16891 0, 0, context_die
);
16894 if (DECL_ABSTRACT (decl
))
16895 equate_decl_number_to_die (decl
, decl_die
);
16897 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
16901 /* Walk through the list of incomplete types again, trying once more to
16902 emit full debugging info for them. */
16905 retry_incomplete_types (void)
16909 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
16910 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
16911 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
16914 /* Determine what tag to use for a record type. */
16916 static enum dwarf_tag
16917 record_type_tag (tree type
)
16919 if (! lang_hooks
.types
.classify_record
)
16920 return DW_TAG_structure_type
;
16922 switch (lang_hooks
.types
.classify_record (type
))
16924 case RECORD_IS_STRUCT
:
16925 return DW_TAG_structure_type
;
16927 case RECORD_IS_CLASS
:
16928 return DW_TAG_class_type
;
16930 case RECORD_IS_INTERFACE
:
16931 if (dwarf_version
>= 3 || !dwarf_strict
)
16932 return DW_TAG_interface_type
;
16933 return DW_TAG_structure_type
;
16936 gcc_unreachable ();
16940 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16941 include all of the information about the enumeration values also. Each
16942 enumerated type name/value is listed as a child of the enumerated type
16946 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
16948 dw_die_ref type_die
= lookup_type_die (type
);
16950 if (type_die
== NULL
)
16952 type_die
= new_die (DW_TAG_enumeration_type
,
16953 scope_die_for (type
, context_die
), type
);
16954 equate_type_number_to_die (type
, type_die
);
16955 add_name_attribute (type_die
, type_tag (type
));
16956 if (dwarf_version
>= 4 || !dwarf_strict
)
16958 if (ENUM_IS_SCOPED (type
))
16959 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
16960 if (ENUM_IS_OPAQUE (type
))
16961 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16964 else if (! TYPE_SIZE (type
))
16967 remove_AT (type_die
, DW_AT_declaration
);
16969 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16970 given enum type is incomplete, do not generate the DW_AT_byte_size
16971 attribute or the DW_AT_element_list attribute. */
16972 if (TYPE_SIZE (type
))
16976 TREE_ASM_WRITTEN (type
) = 1;
16977 add_byte_size_attribute (type_die
, type
);
16978 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
16980 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
16981 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
16984 /* If the first reference to this type was as the return type of an
16985 inline function, then it may not have a parent. Fix this now. */
16986 if (type_die
->die_parent
== NULL
)
16987 add_child_die (scope_die_for (type
, context_die
), type_die
);
16989 for (link
= TYPE_VALUES (type
);
16990 link
!= NULL
; link
= TREE_CHAIN (link
))
16992 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
16993 tree value
= TREE_VALUE (link
);
16995 add_name_attribute (enum_die
,
16996 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
16998 if (TREE_CODE (value
) == CONST_DECL
)
16999 value
= DECL_INITIAL (value
);
17001 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
17002 /* DWARF2 does not provide a way of indicating whether or
17003 not enumeration constants are signed or unsigned. GDB
17004 always assumes the values are signed, so we output all
17005 values as if they were signed. That means that
17006 enumeration constants with very large unsigned values
17007 will appear to have negative values in the debugger. */
17008 add_AT_int (enum_die
, DW_AT_const_value
,
17009 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
17012 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17013 if (TYPE_ARTIFICIAL (type
))
17014 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17017 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17019 add_pubtype (type
, type_die
);
17024 /* Generate a DIE to represent either a real live formal parameter decl or to
17025 represent just the type of some formal parameter position in some function
17028 Note that this routine is a bit unusual because its argument may be a
17029 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17030 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17031 node. If it's the former then this function is being called to output a
17032 DIE to represent a formal parameter object (or some inlining thereof). If
17033 it's the latter, then this function is only being called to output a
17034 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17035 argument type of some subprogram type.
17036 If EMIT_NAME_P is true, name and source coordinate attributes
17040 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17041 dw_die_ref context_die
)
17043 tree node_or_origin
= node
? node
: origin
;
17044 tree ultimate_origin
;
17045 dw_die_ref parm_die
17046 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17048 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17050 case tcc_declaration
:
17051 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17052 if (node
|| ultimate_origin
)
17053 origin
= ultimate_origin
;
17054 if (origin
!= NULL
)
17055 add_abstract_origin_attribute (parm_die
, origin
);
17056 else if (emit_name_p
)
17057 add_name_and_src_coords_attributes (parm_die
, node
);
17059 || (! DECL_ABSTRACT (node_or_origin
)
17060 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17061 decl_function_context
17062 (node_or_origin
))))
17064 tree type
= TREE_TYPE (node_or_origin
);
17065 if (decl_by_reference_p (node_or_origin
))
17066 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17069 add_type_attribute (parm_die
, type
,
17070 TREE_READONLY (node_or_origin
),
17071 TREE_THIS_VOLATILE (node_or_origin
),
17074 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17075 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17077 if (node
&& node
!= origin
)
17078 equate_decl_number_to_die (node
, parm_die
);
17079 if (! DECL_ABSTRACT (node_or_origin
))
17080 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17081 node
== NULL
, DW_AT_location
);
17086 /* We were called with some kind of a ..._TYPE node. */
17087 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17091 gcc_unreachable ();
17097 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17098 children DW_TAG_formal_parameter DIEs representing the arguments of the
17101 PARM_PACK must be a function parameter pack.
17102 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17103 must point to the subsequent arguments of the function PACK_ARG belongs to.
17104 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17105 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17106 following the last one for which a DIE was generated. */
17109 gen_formal_parameter_pack_die (tree parm_pack
,
17111 dw_die_ref subr_die
,
17115 dw_die_ref parm_pack_die
;
17117 gcc_assert (parm_pack
17118 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17121 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17122 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17124 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17126 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17129 gen_formal_parameter_die (arg
, NULL
,
17130 false /* Don't emit name attribute. */,
17135 return parm_pack_die
;
17138 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17139 at the end of an (ANSI prototyped) formal parameters list. */
17142 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17144 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17147 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17148 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17149 parameters as specified in some function type specification (except for
17150 those which appear as part of a function *definition*). */
17153 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17156 tree formal_type
= NULL
;
17157 tree first_parm_type
;
17160 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17162 arg
= DECL_ARGUMENTS (function_or_method_type
);
17163 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17168 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17170 /* Make our first pass over the list of formal parameter types and output a
17171 DW_TAG_formal_parameter DIE for each one. */
17172 for (link
= first_parm_type
; link
; )
17174 dw_die_ref parm_die
;
17176 formal_type
= TREE_VALUE (link
);
17177 if (formal_type
== void_type_node
)
17180 /* Output a (nameless) DIE to represent the formal parameter itself. */
17181 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17182 true /* Emit name attribute. */,
17184 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17185 && link
== first_parm_type
)
17187 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17188 if (dwarf_version
>= 3 || !dwarf_strict
)
17189 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17191 else if (arg
&& DECL_ARTIFICIAL (arg
))
17192 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17194 link
= TREE_CHAIN (link
);
17196 arg
= DECL_CHAIN (arg
);
17199 /* If this function type has an ellipsis, add a
17200 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17201 if (formal_type
!= void_type_node
)
17202 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17204 /* Make our second (and final) pass over the list of formal parameter types
17205 and output DIEs to represent those types (as necessary). */
17206 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17207 link
&& TREE_VALUE (link
);
17208 link
= TREE_CHAIN (link
))
17209 gen_type_die (TREE_VALUE (link
), context_die
);
17212 /* We want to generate the DIE for TYPE so that we can generate the
17213 die for MEMBER, which has been defined; we will need to refer back
17214 to the member declaration nested within TYPE. If we're trying to
17215 generate minimal debug info for TYPE, processing TYPE won't do the
17216 trick; we need to attach the member declaration by hand. */
17219 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17221 gen_type_die (type
, context_die
);
17223 /* If we're trying to avoid duplicate debug info, we may not have
17224 emitted the member decl for this function. Emit it now. */
17225 if (TYPE_STUB_DECL (type
)
17226 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17227 && ! lookup_decl_die (member
))
17229 dw_die_ref type_die
;
17230 gcc_assert (!decl_ultimate_origin (member
));
17232 push_decl_scope (type
);
17233 type_die
= lookup_type_die_strip_naming_typedef (type
);
17234 if (TREE_CODE (member
) == FUNCTION_DECL
)
17235 gen_subprogram_die (member
, type_die
);
17236 else if (TREE_CODE (member
) == FIELD_DECL
)
17238 /* Ignore the nameless fields that are used to skip bits but handle
17239 C++ anonymous unions and structs. */
17240 if (DECL_NAME (member
) != NULL_TREE
17241 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17242 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17244 gen_type_die (member_declared_type (member
), type_die
);
17245 gen_field_die (member
, type_die
);
17249 gen_variable_die (member
, NULL_TREE
, type_die
);
17255 /* Forward declare these functions, because they are mutually recursive
17256 with their set_block_* pairing functions. */
17257 static void set_decl_origin_self (tree
);
17258 static void set_decl_abstract_flags (tree
, int);
17260 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17261 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17262 that it points to the node itself, thus indicating that the node is its
17263 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17264 the given node is NULL, recursively descend the decl/block tree which
17265 it is the root of, and for each other ..._DECL or BLOCK node contained
17266 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17267 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17268 values to point to themselves. */
17271 set_block_origin_self (tree stmt
)
17273 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17275 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17280 for (local_decl
= BLOCK_VARS (stmt
);
17281 local_decl
!= NULL_TREE
;
17282 local_decl
= DECL_CHAIN (local_decl
))
17283 if (! DECL_EXTERNAL (local_decl
))
17284 set_decl_origin_self (local_decl
); /* Potential recursion. */
17290 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17291 subblock
!= NULL_TREE
;
17292 subblock
= BLOCK_CHAIN (subblock
))
17293 set_block_origin_self (subblock
); /* Recurse. */
17298 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17299 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17300 node to so that it points to the node itself, thus indicating that the
17301 node represents its own (abstract) origin. Additionally, if the
17302 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17303 the decl/block tree of which the given node is the root of, and for
17304 each other ..._DECL or BLOCK node contained therein whose
17305 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17306 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17307 point to themselves. */
17310 set_decl_origin_self (tree decl
)
17312 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17314 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17315 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17319 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17320 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17321 if (DECL_INITIAL (decl
) != NULL_TREE
17322 && DECL_INITIAL (decl
) != error_mark_node
)
17323 set_block_origin_self (DECL_INITIAL (decl
));
17328 /* Given a pointer to some BLOCK node, and a boolean value to set the
17329 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17330 the given block, and for all local decls and all local sub-blocks
17331 (recursively) which are contained therein. */
17334 set_block_abstract_flags (tree stmt
, int setting
)
17340 BLOCK_ABSTRACT (stmt
) = setting
;
17342 for (local_decl
= BLOCK_VARS (stmt
);
17343 local_decl
!= NULL_TREE
;
17344 local_decl
= DECL_CHAIN (local_decl
))
17345 if (! DECL_EXTERNAL (local_decl
))
17346 set_decl_abstract_flags (local_decl
, setting
);
17348 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17350 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17351 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17352 || TREE_CODE (local_decl
) == PARM_DECL
)
17353 set_decl_abstract_flags (local_decl
, setting
);
17356 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17357 subblock
!= NULL_TREE
;
17358 subblock
= BLOCK_CHAIN (subblock
))
17359 set_block_abstract_flags (subblock
, setting
);
17362 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17363 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17364 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17365 set the abstract flags for all of the parameters, local vars, local
17366 blocks and sub-blocks (recursively) to the same setting. */
17369 set_decl_abstract_flags (tree decl
, int setting
)
17371 DECL_ABSTRACT (decl
) = setting
;
17372 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17376 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17377 DECL_ABSTRACT (arg
) = setting
;
17378 if (DECL_INITIAL (decl
) != NULL_TREE
17379 && DECL_INITIAL (decl
) != error_mark_node
)
17380 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17384 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17385 may later generate inlined and/or out-of-line instances of. */
17388 dwarf2out_abstract_function (tree decl
)
17390 dw_die_ref old_die
;
17394 htab_t old_decl_loc_table
;
17395 htab_t old_cached_dw_loc_list_table
;
17396 int old_call_site_count
, old_tail_call_site_count
;
17397 struct call_arg_loc_node
*old_call_arg_locations
;
17399 /* Make sure we have the actual abstract inline, not a clone. */
17400 decl
= DECL_ORIGIN (decl
);
17402 old_die
= lookup_decl_die (decl
);
17403 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17404 /* We've already generated the abstract instance. */
17407 /* We can be called while recursively when seeing block defining inlined subroutine
17408 DIE. Be sure to not clobber the outer location table nor use it or we would
17409 get locations in abstract instantces. */
17410 old_decl_loc_table
= decl_loc_table
;
17411 decl_loc_table
= NULL
;
17412 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17413 cached_dw_loc_list_table
= NULL
;
17414 old_call_arg_locations
= call_arg_locations
;
17415 call_arg_locations
= NULL
;
17416 old_call_site_count
= call_site_count
;
17417 call_site_count
= -1;
17418 old_tail_call_site_count
= tail_call_site_count
;
17419 tail_call_site_count
= -1;
17421 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17422 we don't get confused by DECL_ABSTRACT. */
17423 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17425 context
= decl_class_context (decl
);
17427 gen_type_die_for_member
17428 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17431 /* Pretend we've just finished compiling this function. */
17432 save_fn
= current_function_decl
;
17433 current_function_decl
= decl
;
17435 was_abstract
= DECL_ABSTRACT (decl
);
17436 set_decl_abstract_flags (decl
, 1);
17437 dwarf2out_decl (decl
);
17438 if (! was_abstract
)
17439 set_decl_abstract_flags (decl
, 0);
17441 current_function_decl
= save_fn
;
17442 decl_loc_table
= old_decl_loc_table
;
17443 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17444 call_arg_locations
= old_call_arg_locations
;
17445 call_site_count
= old_call_site_count
;
17446 tail_call_site_count
= old_tail_call_site_count
;
17449 /* Helper function of premark_used_types() which gets called through
17452 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17453 marked as unused by prune_unused_types. */
17456 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17461 type
= (tree
) *slot
;
17462 die
= lookup_type_die (type
);
17464 die
->die_perennial_p
= 1;
17468 /* Helper function of premark_types_used_by_global_vars which gets called
17469 through htab_traverse.
17471 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17472 marked as unused by prune_unused_types. The DIE of the type is marked
17473 only if the global variable using the type will actually be emitted. */
17476 premark_types_used_by_global_vars_helper (void **slot
,
17477 void *data ATTRIBUTE_UNUSED
)
17479 struct types_used_by_vars_entry
*entry
;
17482 entry
= (struct types_used_by_vars_entry
*) *slot
;
17483 gcc_assert (entry
->type
!= NULL
17484 && entry
->var_decl
!= NULL
);
17485 die
= lookup_type_die (entry
->type
);
17488 /* Ask cgraph if the global variable really is to be emitted.
17489 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17490 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17491 if (node
&& node
->analyzed
)
17493 die
->die_perennial_p
= 1;
17494 /* Keep the parent DIEs as well. */
17495 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17496 die
->die_perennial_p
= 1;
17502 /* Mark all members of used_types_hash as perennial. */
17505 premark_used_types (struct function
*fun
)
17507 if (fun
&& fun
->used_types_hash
)
17508 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17511 /* Mark all members of types_used_by_vars_entry as perennial. */
17514 premark_types_used_by_global_vars (void)
17516 if (types_used_by_vars_hash
)
17517 htab_traverse (types_used_by_vars_hash
,
17518 premark_types_used_by_global_vars_helper
, NULL
);
17521 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17522 for CA_LOC call arg loc node. */
17525 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17526 struct call_arg_loc_node
*ca_loc
)
17528 dw_die_ref stmt_die
= NULL
, die
;
17529 tree block
= ca_loc
->block
;
17532 && block
!= DECL_INITIAL (decl
)
17533 && TREE_CODE (block
) == BLOCK
)
17535 if (block_map
.length () > BLOCK_NUMBER (block
))
17536 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17539 block
= BLOCK_SUPERCONTEXT (block
);
17541 if (stmt_die
== NULL
)
17542 stmt_die
= subr_die
;
17543 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17544 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17545 if (ca_loc
->tail_call_p
)
17546 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17547 if (ca_loc
->symbol_ref
)
17549 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17551 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17553 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17558 /* Generate a DIE to represent a declared function (either file-scope or
17562 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17564 tree origin
= decl_ultimate_origin (decl
);
17565 dw_die_ref subr_die
;
17567 dw_die_ref old_die
= lookup_decl_die (decl
);
17568 int declaration
= (current_function_decl
!= decl
17569 || class_or_namespace_scope_p (context_die
));
17571 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17573 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17574 started to generate the abstract instance of an inline, decided to output
17575 its containing class, and proceeded to emit the declaration of the inline
17576 from the member list for the class. If so, DECLARATION takes priority;
17577 we'll get back to the abstract instance when done with the class. */
17579 /* The class-scope declaration DIE must be the primary DIE. */
17580 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17583 gcc_assert (!old_die
);
17586 /* Now that the C++ front end lazily declares artificial member fns, we
17587 might need to retrofit the declaration into its class. */
17588 if (!declaration
&& !origin
&& !old_die
17589 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17590 && !class_or_namespace_scope_p (context_die
)
17591 && debug_info_level
> DINFO_LEVEL_TERSE
)
17592 old_die
= force_decl_die (decl
);
17594 if (origin
!= NULL
)
17596 gcc_assert (!declaration
|| local_scope_p (context_die
));
17598 /* Fixup die_parent for the abstract instance of a nested
17599 inline function. */
17600 if (old_die
&& old_die
->die_parent
== NULL
)
17601 add_child_die (context_die
, old_die
);
17603 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17604 add_abstract_origin_attribute (subr_die
, origin
);
17605 /* This is where the actual code for a cloned function is.
17606 Let's emit linkage name attribute for it. This helps
17607 debuggers to e.g, set breakpoints into
17608 constructors/destructors when the user asks "break
17610 add_linkage_name (subr_die
, decl
);
17614 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17615 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17617 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17618 /* We can have a normal definition following an inline one in the
17619 case of redefinition of GNU C extern inlines.
17620 It seems reasonable to use AT_specification in this case. */
17621 && !get_AT (old_die
, DW_AT_inline
))
17623 /* Detect and ignore this case, where we are trying to output
17624 something we have already output. */
17628 /* If the definition comes from the same place as the declaration,
17629 maybe use the old DIE. We always want the DIE for this function
17630 that has the *_pc attributes to be under comp_unit_die so the
17631 debugger can find it. We also need to do this for abstract
17632 instances of inlines, since the spec requires the out-of-line copy
17633 to have the same parent. For local class methods, this doesn't
17634 apply; we just use the old DIE. */
17635 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17636 && (DECL_ARTIFICIAL (decl
)
17637 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17638 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17639 == (unsigned) s
.line
))))
17641 subr_die
= old_die
;
17643 /* Clear out the declaration attribute and the formal parameters.
17644 Do not remove all children, because it is possible that this
17645 declaration die was forced using force_decl_die(). In such
17646 cases die that forced declaration die (e.g. TAG_imported_module)
17647 is one of the children that we do not want to remove. */
17648 remove_AT (subr_die
, DW_AT_declaration
);
17649 remove_AT (subr_die
, DW_AT_object_pointer
);
17650 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17654 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17655 add_AT_specification (subr_die
, old_die
);
17656 add_pubname (decl
, subr_die
);
17657 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17658 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17659 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17660 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17665 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17667 if (TREE_PUBLIC (decl
))
17668 add_AT_flag (subr_die
, DW_AT_external
, 1);
17670 add_name_and_src_coords_attributes (subr_die
, decl
);
17671 add_pubname (decl
, subr_die
);
17672 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17674 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17675 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17676 0, 0, context_die
);
17679 add_pure_or_virtual_attribute (subr_die
, decl
);
17680 if (DECL_ARTIFICIAL (decl
))
17681 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17683 add_accessibility_attribute (subr_die
, decl
);
17688 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17690 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17692 /* If this is an explicit function declaration then generate
17693 a DW_AT_explicit attribute. */
17694 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17695 && (dwarf_version
>= 3 || !dwarf_strict
))
17696 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17698 /* The first time we see a member function, it is in the context of
17699 the class to which it belongs. We make sure of this by emitting
17700 the class first. The next time is the definition, which is
17701 handled above. The two may come from the same source text.
17703 Note that force_decl_die() forces function declaration die. It is
17704 later reused to represent definition. */
17705 equate_decl_number_to_die (decl
, subr_die
);
17708 else if (DECL_ABSTRACT (decl
))
17710 if (DECL_DECLARED_INLINE_P (decl
))
17712 if (cgraph_function_possibly_inlined_p (decl
))
17713 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17715 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17719 if (cgraph_function_possibly_inlined_p (decl
))
17720 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17722 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17725 if (DECL_DECLARED_INLINE_P (decl
)
17726 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17727 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17729 equate_decl_number_to_die (decl
, subr_die
);
17731 else if (!DECL_EXTERNAL (decl
))
17733 HOST_WIDE_INT cfa_fb_offset
;
17734 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
17736 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17737 equate_decl_number_to_die (decl
, subr_die
);
17739 gcc_checking_assert (fun
);
17740 if (!flag_reorder_blocks_and_partition
)
17742 dw_fde_ref fde
= fun
->fde
;
17743 if (fde
->dw_fde_begin
)
17745 /* We have already generated the labels. */
17746 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17747 fde
->dw_fde_end
, false);
17751 /* Create start/end labels and add the range. */
17752 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
17753 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17754 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
17755 current_function_funcdef_no
);
17756 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
17757 current_function_funcdef_no
);
17758 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
17762 #if VMS_DEBUGGING_INFO
17763 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17764 Section 2.3 Prologue and Epilogue Attributes:
17765 When a breakpoint is set on entry to a function, it is generally
17766 desirable for execution to be suspended, not on the very first
17767 instruction of the function, but rather at a point after the
17768 function's frame has been set up, after any language defined local
17769 declaration processing has been completed, and before execution of
17770 the first statement of the function begins. Debuggers generally
17771 cannot properly determine where this point is. Similarly for a
17772 breakpoint set on exit from a function. The prologue and epilogue
17773 attributes allow a compiler to communicate the location(s) to use. */
17776 if (fde
->dw_fde_vms_end_prologue
)
17777 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17778 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17780 if (fde
->dw_fde_vms_begin_epilogue
)
17781 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17782 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17789 /* Generate pubnames entries for the split function code ranges. */
17790 dw_fde_ref fde
= fun
->fde
;
17792 if (fde
->dw_fde_second_begin
)
17794 if (dwarf_version
>= 3 || !dwarf_strict
)
17796 /* We should use ranges for non-contiguous code section
17797 addresses. Use the actual code range for the initial
17798 section, since the HOT/COLD labels might precede an
17799 alignment offset. */
17800 bool range_list_added
= false;
17801 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17802 fde
->dw_fde_end
, &range_list_added
,
17804 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17805 fde
->dw_fde_second_end
,
17806 &range_list_added
, false);
17807 if (range_list_added
)
17812 /* There is no real support in DW2 for this .. so we make
17813 a work-around. First, emit the pub name for the segment
17814 containing the function label. Then make and emit a
17815 simplified subprogram DIE for the second segment with the
17816 name pre-fixed by __hot/cold_sect_of_. We use the same
17817 linkage name for the second die so that gdb will find both
17818 sections when given "b foo". */
17819 const char *name
= NULL
;
17820 tree decl_name
= DECL_NAME (decl
);
17821 dw_die_ref seg_die
;
17823 /* Do the 'primary' section. */
17824 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17825 fde
->dw_fde_end
, false);
17827 /* Build a minimal DIE for the secondary section. */
17828 seg_die
= new_die (DW_TAG_subprogram
,
17829 subr_die
->die_parent
, decl
);
17831 if (TREE_PUBLIC (decl
))
17832 add_AT_flag (seg_die
, DW_AT_external
, 1);
17834 if (decl_name
!= NULL
17835 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17837 name
= dwarf2_name (decl
, 1);
17838 if (! DECL_ARTIFICIAL (decl
))
17839 add_src_coords_attributes (seg_die
, decl
);
17841 add_linkage_name (seg_die
, decl
);
17843 gcc_assert (name
!= NULL
);
17844 add_pure_or_virtual_attribute (seg_die
, decl
);
17845 if (DECL_ARTIFICIAL (decl
))
17846 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17848 name
= concat ("__second_sect_of_", name
, NULL
);
17849 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
17850 fde
->dw_fde_second_end
, false);
17851 add_name_attribute (seg_die
, name
);
17852 if (want_pubnames ())
17853 add_pubname_string (name
, seg_die
);
17857 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
17861 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17863 /* We define the "frame base" as the function's CFA. This is more
17864 convenient for several reasons: (1) It's stable across the prologue
17865 and epilogue, which makes it better than just a frame pointer,
17866 (2) With dwarf3, there exists a one-byte encoding that allows us
17867 to reference the .debug_frame data by proxy, but failing that,
17868 (3) We can at least reuse the code inspection and interpretation
17869 code that determines the CFA position at various points in the
17871 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
17873 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
17874 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
17878 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
17879 if (list
->dw_loc_next
)
17880 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
17882 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
17885 /* Compute a displacement from the "steady-state frame pointer" to
17886 the CFA. The former is what all stack slots and argument slots
17887 will reference in the rtl; the latter is what we've told the
17888 debugger about. We'll need to adjust all frame_base references
17889 by this displacement. */
17890 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
17892 if (fun
->static_chain_decl
)
17893 add_AT_location_description (subr_die
, DW_AT_static_link
,
17894 loc_list_from_tree (fun
->static_chain_decl
, 2));
17897 /* Generate child dies for template paramaters. */
17898 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17899 gen_generic_params_dies (decl
);
17901 /* Now output descriptions of the arguments for this function. This gets
17902 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17903 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17904 `...' at the end of the formal parameter list. In order to find out if
17905 there was a trailing ellipsis or not, we must instead look at the type
17906 associated with the FUNCTION_DECL. This will be a node of type
17907 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17908 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17909 an ellipsis at the end. */
17911 /* In the case where we are describing a mere function declaration, all we
17912 need to do here (and all we *can* do here) is to describe the *types* of
17913 its formal parameters. */
17914 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
17916 else if (declaration
)
17917 gen_formal_types_die (decl
, subr_die
);
17920 /* Generate DIEs to represent all known formal parameters. */
17921 tree parm
= DECL_ARGUMENTS (decl
);
17922 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
17923 tree generic_decl_parm
= generic_decl
17924 ? DECL_ARGUMENTS (generic_decl
)
17927 /* Now we want to walk the list of parameters of the function and
17928 emit their relevant DIEs.
17930 We consider the case of DECL being an instance of a generic function
17931 as well as it being a normal function.
17933 If DECL is an instance of a generic function we walk the
17934 parameters of the generic function declaration _and_ the parameters of
17935 DECL itself. This is useful because we want to emit specific DIEs for
17936 function parameter packs and those are declared as part of the
17937 generic function declaration. In that particular case,
17938 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17939 That DIE has children DIEs representing the set of arguments
17940 of the pack. Note that the set of pack arguments can be empty.
17941 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17944 Otherwise, we just consider the parameters of DECL. */
17945 while (generic_decl_parm
|| parm
)
17947 if (generic_decl_parm
17948 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
17949 gen_formal_parameter_pack_die (generic_decl_parm
,
17954 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
17956 if (parm
== DECL_ARGUMENTS (decl
)
17957 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
17959 && (dwarf_version
>= 3 || !dwarf_strict
))
17960 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
17962 parm
= DECL_CHAIN (parm
);
17965 if (generic_decl_parm
)
17966 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
17969 /* Decide whether we need an unspecified_parameters DIE at the end.
17970 There are 2 more cases to do this for: 1) the ansi ... declaration -
17971 this is detectable when the end of the arg list is not a
17972 void_type_node 2) an unprototyped function declaration (not a
17973 definition). This just means that we have no info about the
17974 parameters at all. */
17975 if (prototype_p (TREE_TYPE (decl
)))
17977 /* This is the prototyped case, check for.... */
17978 if (stdarg_p (TREE_TYPE (decl
)))
17979 gen_unspecified_parameters_die (decl
, subr_die
);
17981 else if (DECL_INITIAL (decl
) == NULL_TREE
)
17982 gen_unspecified_parameters_die (decl
, subr_die
);
17985 /* Output Dwarf info for all of the stuff within the body of the function
17986 (if it has one - it may be just a declaration). */
17987 outer_scope
= DECL_INITIAL (decl
);
17989 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
17990 a function. This BLOCK actually represents the outermost binding contour
17991 for the function, i.e. the contour in which the function's formal
17992 parameters and labels get declared. Curiously, it appears that the front
17993 end doesn't actually put the PARM_DECL nodes for the current function onto
17994 the BLOCK_VARS list for this outer scope, but are strung off of the
17995 DECL_ARGUMENTS list for the function instead.
17997 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
17998 the LABEL_DECL nodes for the function however, and we output DWARF info
17999 for those in decls_for_scope. Just within the `outer_scope' there will be
18000 a BLOCK node representing the function's outermost pair of curly braces,
18001 and any blocks used for the base and member initializers of a C++
18002 constructor function. */
18003 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18005 int call_site_note_count
= 0;
18006 int tail_call_site_note_count
= 0;
18008 /* Emit a DW_TAG_variable DIE for a named return value. */
18009 if (DECL_NAME (DECL_RESULT (decl
)))
18010 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18012 current_function_has_inlines
= 0;
18013 decls_for_scope (outer_scope
, subr_die
, 0);
18015 if (call_arg_locations
&& !dwarf_strict
)
18017 struct call_arg_loc_node
*ca_loc
;
18018 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18020 dw_die_ref die
= NULL
;
18021 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18024 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18025 arg
; arg
= next_arg
)
18027 dw_loc_descr_ref reg
, val
;
18028 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18029 dw_die_ref cdie
, tdie
= NULL
;
18031 next_arg
= XEXP (arg
, 1);
18032 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18034 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18035 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18036 && REGNO (XEXP (XEXP (arg
, 0), 0))
18037 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18038 next_arg
= XEXP (next_arg
, 1);
18039 if (mode
== VOIDmode
)
18041 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18042 if (mode
== VOIDmode
)
18043 mode
= GET_MODE (XEXP (arg
, 0));
18045 if (mode
== VOIDmode
|| mode
== BLKmode
)
18047 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18049 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18050 tloc
= XEXP (XEXP (arg
, 0), 1);
18053 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18054 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18056 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18057 tlocc
= XEXP (XEXP (arg
, 0), 1);
18061 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18062 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18063 VAR_INIT_STATUS_INITIALIZED
);
18064 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18066 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18067 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18068 get_address_mode (mem
),
18070 VAR_INIT_STATUS_INITIALIZED
);
18072 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18073 == DEBUG_PARAMETER_REF
)
18076 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18077 tdie
= lookup_decl_die (tdecl
);
18084 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18085 != DEBUG_PARAMETER_REF
)
18087 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18089 VAR_INIT_STATUS_INITIALIZED
);
18093 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18094 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18097 add_AT_loc (cdie
, DW_AT_location
, reg
);
18098 else if (tdie
!= NULL
)
18099 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18100 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18101 if (next_arg
!= XEXP (arg
, 1))
18103 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18104 if (mode
== VOIDmode
)
18105 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18106 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18109 VAR_INIT_STATUS_INITIALIZED
);
18111 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18115 && (ca_loc
->symbol_ref
|| tloc
))
18116 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18117 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18119 dw_loc_descr_ref tval
= NULL
;
18121 if (tloc
!= NULL_RTX
)
18122 tval
= mem_loc_descriptor (tloc
,
18123 GET_MODE (tloc
) == VOIDmode
18124 ? Pmode
: GET_MODE (tloc
),
18126 VAR_INIT_STATUS_INITIALIZED
);
18128 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18129 else if (tlocc
!= NULL_RTX
)
18131 tval
= mem_loc_descriptor (tlocc
,
18132 GET_MODE (tlocc
) == VOIDmode
18133 ? Pmode
: GET_MODE (tlocc
),
18135 VAR_INIT_STATUS_INITIALIZED
);
18137 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18143 call_site_note_count
++;
18144 if (ca_loc
->tail_call_p
)
18145 tail_call_site_note_count
++;
18149 call_arg_locations
= NULL
;
18150 call_arg_loc_last
= NULL
;
18151 if (tail_call_site_count
>= 0
18152 && tail_call_site_count
== tail_call_site_note_count
18155 if (call_site_count
>= 0
18156 && call_site_count
== call_site_note_count
)
18157 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18159 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18161 call_site_count
= -1;
18162 tail_call_site_count
= -1;
18164 /* Add the calling convention attribute if requested. */
18165 add_calling_convention_attribute (subr_die
, decl
);
18169 /* Returns a hash value for X (which really is a die_struct). */
18172 common_block_die_table_hash (const void *x
)
18174 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18175 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18178 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18179 as decl_id and die_parent of die_struct Y. */
18182 common_block_die_table_eq (const void *x
, const void *y
)
18184 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18185 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18186 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18189 /* Generate a DIE to represent a declared data object.
18190 Either DECL or ORIGIN must be non-null. */
18193 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18195 HOST_WIDE_INT off
= 0;
18197 tree decl_or_origin
= decl
? decl
: origin
;
18198 tree ultimate_origin
;
18199 dw_die_ref var_die
;
18200 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18201 dw_die_ref origin_die
;
18202 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18203 || class_or_namespace_scope_p (context_die
));
18204 bool specialization_p
= false;
18206 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18207 if (decl
|| ultimate_origin
)
18208 origin
= ultimate_origin
;
18209 com_decl
= fortran_common (decl_or_origin
, &off
);
18211 /* Symbol in common gets emitted as a child of the common block, in the form
18212 of a data member. */
18215 dw_die_ref com_die
;
18216 dw_loc_list_ref loc
;
18217 die_node com_die_arg
;
18219 var_die
= lookup_decl_die (decl_or_origin
);
18222 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18224 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18229 /* Optimize the common case. */
18230 if (single_element_loc_list_p (loc
)
18231 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18232 && loc
->expr
->dw_loc_next
== NULL
18233 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18236 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18237 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18238 = plus_constant (GET_MODE (x
), x
, off
);
18241 loc_list_plus_const (loc
, off
);
18243 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18244 remove_AT (var_die
, DW_AT_declaration
);
18250 if (common_block_die_table
== NULL
)
18251 common_block_die_table
18252 = htab_create_ggc (10, common_block_die_table_hash
,
18253 common_block_die_table_eq
, NULL
);
18255 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18256 com_die_arg
.die_parent
= context_die
;
18257 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18258 loc
= loc_list_from_tree (com_decl
, 2);
18259 if (com_die
== NULL
)
18262 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18265 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18266 add_name_and_src_coords_attributes (com_die
, com_decl
);
18269 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18270 /* Avoid sharing the same loc descriptor between
18271 DW_TAG_common_block and DW_TAG_variable. */
18272 loc
= loc_list_from_tree (com_decl
, 2);
18274 else if (DECL_EXTERNAL (decl
))
18275 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18276 if (want_pubnames ())
18277 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18278 com_die
->decl_id
= DECL_UID (com_decl
);
18279 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18280 *slot
= (void *) com_die
;
18282 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18284 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18285 loc
= loc_list_from_tree (com_decl
, 2);
18286 remove_AT (com_die
, DW_AT_declaration
);
18288 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18289 add_name_and_src_coords_attributes (var_die
, decl
);
18290 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18291 TREE_THIS_VOLATILE (decl
), context_die
);
18292 add_AT_flag (var_die
, DW_AT_external
, 1);
18297 /* Optimize the common case. */
18298 if (single_element_loc_list_p (loc
)
18299 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18300 && loc
->expr
->dw_loc_next
== NULL
18301 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18303 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18304 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18305 = plus_constant (GET_MODE (x
), x
, off
);
18308 loc_list_plus_const (loc
, off
);
18310 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18312 else if (DECL_EXTERNAL (decl
))
18313 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18314 equate_decl_number_to_die (decl
, var_die
);
18318 /* If the compiler emitted a definition for the DECL declaration
18319 and if we already emitted a DIE for it, don't emit a second
18320 DIE for it again. Allow re-declarations of DECLs that are
18321 inside functions, though. */
18322 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18325 /* For static data members, the declaration in the class is supposed
18326 to have DW_TAG_member tag; the specification should still be
18327 DW_TAG_variable referencing the DW_TAG_member DIE. */
18328 if (declaration
&& class_scope_p (context_die
))
18329 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18331 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18334 if (origin
!= NULL
)
18335 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18337 /* Loop unrolling can create multiple blocks that refer to the same
18338 static variable, so we must test for the DW_AT_declaration flag.
18340 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18341 copy decls and set the DECL_ABSTRACT flag on them instead of
18344 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18346 ??? The declare_in_namespace support causes us to get two DIEs for one
18347 variable, both of which are declarations. We want to avoid considering
18348 one to be a specification, so we must test that this DIE is not a
18350 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18351 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18353 /* This is a definition of a C++ class level static. */
18354 add_AT_specification (var_die
, old_die
);
18355 specialization_p
= true;
18356 if (DECL_NAME (decl
))
18358 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18359 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18361 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18362 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18364 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18365 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18367 if (old_die
->die_tag
== DW_TAG_member
)
18368 add_linkage_name (var_die
, decl
);
18372 add_name_and_src_coords_attributes (var_die
, decl
);
18374 if ((origin
== NULL
&& !specialization_p
)
18376 && !DECL_ABSTRACT (decl_or_origin
)
18377 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18378 decl_function_context
18379 (decl_or_origin
))))
18381 tree type
= TREE_TYPE (decl_or_origin
);
18383 if (decl_by_reference_p (decl_or_origin
))
18384 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18386 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18387 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18390 if (origin
== NULL
&& !specialization_p
)
18392 if (TREE_PUBLIC (decl
))
18393 add_AT_flag (var_die
, DW_AT_external
, 1);
18395 if (DECL_ARTIFICIAL (decl
))
18396 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18398 add_accessibility_attribute (var_die
, decl
);
18402 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18404 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18405 equate_decl_number_to_die (decl
, var_die
);
18408 && (! DECL_ABSTRACT (decl_or_origin
)
18409 /* Local static vars are shared between all clones/inlines,
18410 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18412 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18413 && TREE_STATIC (decl_or_origin
)
18414 && DECL_RTL_SET_P (decl_or_origin
)))
18415 /* When abstract origin already has DW_AT_location attribute, no need
18416 to add it again. */
18417 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18419 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18420 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18421 defer_location (decl_or_origin
, var_die
);
18423 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18424 decl
== NULL
, DW_AT_location
);
18425 add_pubname (decl_or_origin
, var_die
);
18428 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18431 /* Generate a DIE to represent a named constant. */
18434 gen_const_die (tree decl
, dw_die_ref context_die
)
18436 dw_die_ref const_die
;
18437 tree type
= TREE_TYPE (decl
);
18439 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18440 add_name_and_src_coords_attributes (const_die
, decl
);
18441 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18442 if (TREE_PUBLIC (decl
))
18443 add_AT_flag (const_die
, DW_AT_external
, 1);
18444 if (DECL_ARTIFICIAL (decl
))
18445 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18446 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18449 /* Generate a DIE to represent a label identifier. */
18452 gen_label_die (tree decl
, dw_die_ref context_die
)
18454 tree origin
= decl_ultimate_origin (decl
);
18455 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18457 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18459 if (origin
!= NULL
)
18460 add_abstract_origin_attribute (lbl_die
, origin
);
18462 add_name_and_src_coords_attributes (lbl_die
, decl
);
18464 if (DECL_ABSTRACT (decl
))
18465 equate_decl_number_to_die (decl
, lbl_die
);
18468 insn
= DECL_RTL_IF_SET (decl
);
18470 /* Deleted labels are programmer specified labels which have been
18471 eliminated because of various optimizations. We still emit them
18472 here so that it is possible to put breakpoints on them. */
18476 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18478 /* When optimization is enabled (via -O) some parts of the compiler
18479 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18480 represent source-level labels which were explicitly declared by
18481 the user. This really shouldn't be happening though, so catch
18482 it if it ever does happen. */
18483 gcc_assert (!INSN_DELETED_P (insn
));
18485 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18486 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18490 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18491 && CODE_LABEL_NUMBER (insn
) != -1)
18493 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18494 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18499 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18500 attributes to the DIE for a block STMT, to describe where the inlined
18501 function was called from. This is similar to add_src_coords_attributes. */
18504 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18506 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18508 if (dwarf_version
>= 3 || !dwarf_strict
)
18510 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18511 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18516 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18517 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18520 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18522 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18524 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18525 && (dwarf_version
>= 3 || !dwarf_strict
))
18527 tree chain
, superblock
= NULL_TREE
;
18529 dw_attr_ref attr
= NULL
;
18531 if (inlined_function_outer_scope_p (stmt
))
18533 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18534 BLOCK_NUMBER (stmt
));
18535 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18538 /* Optimize duplicate .debug_ranges lists or even tails of
18539 lists. If this BLOCK has same ranges as its supercontext,
18540 lookup DW_AT_ranges attribute in the supercontext (and
18541 recursively so), verify that the ranges_table contains the
18542 right values and use it instead of adding a new .debug_range. */
18543 for (chain
= stmt
, pdie
= die
;
18544 BLOCK_SAME_RANGE (chain
);
18545 chain
= BLOCK_SUPERCONTEXT (chain
))
18547 dw_attr_ref new_attr
;
18549 pdie
= pdie
->die_parent
;
18552 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18554 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18555 if (new_attr
== NULL
18556 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18559 superblock
= BLOCK_SUPERCONTEXT (chain
);
18562 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18563 / 2 / DWARF2_ADDR_SIZE
].num
18564 == BLOCK_NUMBER (superblock
))
18565 && BLOCK_FRAGMENT_CHAIN (superblock
))
18567 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18568 / 2 / DWARF2_ADDR_SIZE
;
18569 unsigned long supercnt
= 0, thiscnt
= 0;
18570 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18571 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18574 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18575 == BLOCK_NUMBER (chain
));
18577 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18578 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18579 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18581 gcc_assert (supercnt
>= thiscnt
);
18582 add_AT_range_list (die
, DW_AT_ranges
,
18583 ((off
+ supercnt
- thiscnt
)
18584 * 2 * DWARF2_ADDR_SIZE
),
18589 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18591 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18594 add_ranges (chain
);
18595 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18602 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18603 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18604 BLOCK_NUMBER (stmt
));
18605 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18606 BLOCK_NUMBER (stmt
));
18607 add_AT_low_high_pc (die
, label
, label_high
, false);
18611 /* Generate a DIE for a lexical block. */
18614 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18616 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18618 if (call_arg_locations
)
18620 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18621 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18622 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18625 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18626 add_high_low_attributes (stmt
, stmt_die
);
18628 decls_for_scope (stmt
, stmt_die
, depth
);
18631 /* Generate a DIE for an inlined subprogram. */
18634 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18638 /* The instance of function that is effectively being inlined shall not
18640 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18642 decl
= block_ultimate_origin (stmt
);
18644 /* Emit info for the abstract instance first, if we haven't yet. We
18645 must emit this even if the block is abstract, otherwise when we
18646 emit the block below (or elsewhere), we may end up trying to emit
18647 a die whose origin die hasn't been emitted, and crashing. */
18648 dwarf2out_abstract_function (decl
);
18650 if (! BLOCK_ABSTRACT (stmt
))
18652 dw_die_ref subr_die
18653 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18655 if (call_arg_locations
)
18657 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18658 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18659 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18661 add_abstract_origin_attribute (subr_die
, decl
);
18662 if (TREE_ASM_WRITTEN (stmt
))
18663 add_high_low_attributes (stmt
, subr_die
);
18664 add_call_src_coords_attributes (stmt
, subr_die
);
18666 decls_for_scope (stmt
, subr_die
, depth
);
18667 current_function_has_inlines
= 1;
18671 /* Generate a DIE for a field in a record, or structure. */
18674 gen_field_die (tree decl
, dw_die_ref context_die
)
18676 dw_die_ref decl_die
;
18678 if (TREE_TYPE (decl
) == error_mark_node
)
18681 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18682 add_name_and_src_coords_attributes (decl_die
, decl
);
18683 add_type_attribute (decl_die
, member_declared_type (decl
),
18684 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18687 if (DECL_BIT_FIELD_TYPE (decl
))
18689 add_byte_size_attribute (decl_die
, decl
);
18690 add_bit_size_attribute (decl_die
, decl
);
18691 add_bit_offset_attribute (decl_die
, decl
);
18694 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18695 add_data_member_location_attribute (decl_die
, decl
);
18697 if (DECL_ARTIFICIAL (decl
))
18698 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18700 add_accessibility_attribute (decl_die
, decl
);
18702 /* Equate decl number to die, so that we can look up this decl later on. */
18703 equate_decl_number_to_die (decl
, decl_die
);
18707 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18708 Use modified_type_die instead.
18709 We keep this code here just in case these types of DIEs may be needed to
18710 represent certain things in other languages (e.g. Pascal) someday. */
18713 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18716 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18718 equate_type_number_to_die (type
, ptr_die
);
18719 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18720 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18723 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18724 Use modified_type_die instead.
18725 We keep this code here just in case these types of DIEs may be needed to
18726 represent certain things in other languages (e.g. Pascal) someday. */
18729 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18731 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18733 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18734 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18736 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18738 equate_type_number_to_die (type
, ref_die
);
18739 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18740 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18744 /* Generate a DIE for a pointer to a member type. */
18747 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18750 = new_die (DW_TAG_ptr_to_member_type
,
18751 scope_die_for (type
, context_die
), type
);
18753 equate_type_number_to_die (type
, ptr_die
);
18754 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18755 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18756 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18759 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18761 static char *producer_string
;
18763 /* Return a heap allocated producer string including command line options
18764 if -grecord-gcc-switches. */
18767 gen_producer_string (void)
18770 vec
<dchar_p
> switches
= vNULL
;
18771 const char *language_string
= lang_hooks
.name
;
18772 char *producer
, *tail
;
18774 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18775 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18777 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18778 switch (save_decoded_options
[j
].opt_index
)
18785 case OPT_auxbase_strip
:
18794 case OPT_SPECIAL_unknown
:
18795 case OPT_SPECIAL_ignore
:
18796 case OPT_SPECIAL_program_name
:
18797 case OPT_SPECIAL_input_file
:
18798 case OPT_grecord_gcc_switches
:
18799 case OPT_gno_record_gcc_switches
:
18800 case OPT__output_pch_
:
18801 case OPT_fdiagnostics_show_location_
:
18802 case OPT_fdiagnostics_show_option
:
18803 case OPT_fdiagnostics_show_caret
:
18804 case OPT_fverbose_asm
:
18806 case OPT__sysroot_
:
18808 case OPT_nostdinc__
:
18809 /* Ignore these. */
18812 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
18813 & CL_NO_DWARF_RECORD
)
18815 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18817 switch (save_decoded_options
[j
].canonical_option
[0][1])
18824 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18831 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
18832 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18836 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18838 sprintf (tail
, "%s %s", language_string
, version_string
);
18841 FOR_EACH_VEC_ELT (switches
, j
, p
)
18845 memcpy (tail
+ 1, p
, len
);
18850 switches
.release ();
18854 /* Generate the DIE for the compilation unit. */
18857 gen_compile_unit_die (const char *filename
)
18860 const char *language_string
= lang_hooks
.name
;
18863 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18867 add_name_attribute (die
, filename
);
18868 /* Don't add cwd for <built-in>. */
18869 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
18870 add_comp_dir_attribute (die
);
18873 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
18875 /* If our producer is LTO try to figure out a common language to use
18876 from the global list of translation units. */
18877 if (strcmp (language_string
, "GNU GIMPLE") == 0)
18881 const char *common_lang
= NULL
;
18883 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
18885 if (!TRANSLATION_UNIT_LANGUAGE (t
))
18888 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
18889 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
18891 else if (strncmp (common_lang
, "GNU C", 5) == 0
18892 && strncmp(TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
18893 /* Mixing C and C++ is ok, use C++ in that case. */
18894 common_lang
= "GNU C++";
18897 /* Fall back to C. */
18898 common_lang
= NULL
;
18904 language_string
= common_lang
;
18907 language
= DW_LANG_C89
;
18908 if (strcmp (language_string
, "GNU C++") == 0)
18909 language
= DW_LANG_C_plus_plus
;
18910 else if (strcmp (language_string
, "GNU F77") == 0)
18911 language
= DW_LANG_Fortran77
;
18912 else if (strcmp (language_string
, "GNU Pascal") == 0)
18913 language
= DW_LANG_Pascal83
;
18914 else if (dwarf_version
>= 3 || !dwarf_strict
)
18916 if (strcmp (language_string
, "GNU Ada") == 0)
18917 language
= DW_LANG_Ada95
;
18918 else if (strcmp (language_string
, "GNU Fortran") == 0)
18919 language
= DW_LANG_Fortran95
;
18920 else if (strcmp (language_string
, "GNU Java") == 0)
18921 language
= DW_LANG_Java
;
18922 else if (strcmp (language_string
, "GNU Objective-C") == 0)
18923 language
= DW_LANG_ObjC
;
18924 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
18925 language
= DW_LANG_ObjC_plus_plus
;
18926 else if (dwarf_version
>= 5 || !dwarf_strict
)
18928 if (strcmp (language_string
, "GNU Go") == 0)
18929 language
= DW_LANG_Go
;
18932 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
18933 else if (strcmp (language_string
, "GNU Fortran") == 0)
18934 language
= DW_LANG_Fortran90
;
18936 add_AT_unsigned (die
, DW_AT_language
, language
);
18940 case DW_LANG_Fortran77
:
18941 case DW_LANG_Fortran90
:
18942 case DW_LANG_Fortran95
:
18943 /* Fortran has case insensitive identifiers and the front-end
18944 lowercases everything. */
18945 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
18948 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18954 /* Generate the DIE for a base class. */
18957 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
18959 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
18961 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
18962 add_data_member_location_attribute (die
, binfo
);
18964 if (BINFO_VIRTUAL_P (binfo
))
18965 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18967 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18968 children, otherwise the default is DW_ACCESS_public. In DWARF2
18969 the default has always been DW_ACCESS_private. */
18970 if (access
== access_public_node
)
18972 if (dwarf_version
== 2
18973 || context_die
->die_tag
== DW_TAG_class_type
)
18974 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
18976 else if (access
== access_protected_node
)
18977 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
18978 else if (dwarf_version
> 2
18979 && context_die
->die_tag
!= DW_TAG_class_type
)
18980 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
18983 /* Generate a DIE for a class member. */
18986 gen_member_die (tree type
, dw_die_ref context_die
)
18989 tree binfo
= TYPE_BINFO (type
);
18992 /* If this is not an incomplete type, output descriptions of each of its
18993 members. Note that as we output the DIEs necessary to represent the
18994 members of this record or union type, we will also be trying to output
18995 DIEs to represent the *types* of those members. However the `type'
18996 function (above) will specifically avoid generating type DIEs for member
18997 types *within* the list of member DIEs for this (containing) type except
18998 for those types (of members) which are explicitly marked as also being
18999 members of this (containing) type themselves. The g++ front- end can
19000 force any given type to be treated as a member of some other (containing)
19001 type by setting the TYPE_CONTEXT of the given (member) type to point to
19002 the TREE node representing the appropriate (containing) type. */
19004 /* First output info about the base classes. */
19007 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19011 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19012 gen_inheritance_die (base
,
19013 (accesses
? (*accesses
)[i
] : access_public_node
),
19017 /* Now output info about the data members and type members. */
19018 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19020 /* If we thought we were generating minimal debug info for TYPE
19021 and then changed our minds, some of the member declarations
19022 may have already been defined. Don't define them again, but
19023 do put them in the right order. */
19025 child
= lookup_decl_die (member
);
19027 splice_child_die (context_die
, child
);
19029 gen_decl_die (member
, NULL
, context_die
);
19032 /* Now output info about the function members (if any). */
19033 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19035 /* Don't include clones in the member list. */
19036 if (DECL_ABSTRACT_ORIGIN (member
))
19039 child
= lookup_decl_die (member
);
19041 splice_child_die (context_die
, child
);
19043 gen_decl_die (member
, NULL
, context_die
);
19047 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19048 is set, we pretend that the type was never defined, so we only get the
19049 member DIEs needed by later specification DIEs. */
19052 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19053 enum debug_info_usage usage
)
19055 dw_die_ref type_die
= lookup_type_die (type
);
19056 dw_die_ref scope_die
= 0;
19058 int complete
= (TYPE_SIZE (type
)
19059 && (! TYPE_STUB_DECL (type
)
19060 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19061 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19062 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19064 if (type_die
&& ! complete
)
19067 if (TYPE_CONTEXT (type
) != NULL_TREE
19068 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19069 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19072 scope_die
= scope_die_for (type
, context_die
);
19074 /* Generate child dies for template paramaters. */
19075 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19076 schedule_generic_params_dies_gen (type
);
19078 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19079 /* First occurrence of type or toplevel definition of nested class. */
19081 dw_die_ref old_die
= type_die
;
19083 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19084 ? record_type_tag (type
) : DW_TAG_union_type
,
19086 equate_type_number_to_die (type
, type_die
);
19088 add_AT_specification (type_die
, old_die
);
19090 add_name_attribute (type_die
, type_tag (type
));
19093 remove_AT (type_die
, DW_AT_declaration
);
19095 /* If this type has been completed, then give it a byte_size attribute and
19096 then give a list of members. */
19097 if (complete
&& !ns_decl
)
19099 /* Prevent infinite recursion in cases where the type of some member of
19100 this type is expressed in terms of this type itself. */
19101 TREE_ASM_WRITTEN (type
) = 1;
19102 add_byte_size_attribute (type_die
, type
);
19103 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19105 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19106 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19109 /* If the first reference to this type was as the return type of an
19110 inline function, then it may not have a parent. Fix this now. */
19111 if (type_die
->die_parent
== NULL
)
19112 add_child_die (scope_die
, type_die
);
19114 push_decl_scope (type
);
19115 gen_member_die (type
, type_die
);
19118 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19119 if (TYPE_ARTIFICIAL (type
))
19120 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19122 /* GNU extension: Record what type our vtable lives in. */
19123 if (TYPE_VFIELD (type
))
19125 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19127 gen_type_die (vtype
, context_die
);
19128 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19129 lookup_type_die (vtype
));
19134 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19136 /* We don't need to do this for function-local types. */
19137 if (TYPE_STUB_DECL (type
)
19138 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19139 vec_safe_push (incomplete_types
, type
);
19142 if (get_AT (type_die
, DW_AT_name
))
19143 add_pubtype (type
, type_die
);
19146 /* Generate a DIE for a subroutine _type_. */
19149 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19151 tree return_type
= TREE_TYPE (type
);
19152 dw_die_ref subr_die
19153 = new_die (DW_TAG_subroutine_type
,
19154 scope_die_for (type
, context_die
), type
);
19156 equate_type_number_to_die (type
, subr_die
);
19157 add_prototyped_attribute (subr_die
, type
);
19158 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19159 gen_formal_types_die (type
, subr_die
);
19161 if (get_AT (subr_die
, DW_AT_name
))
19162 add_pubtype (type
, subr_die
);
19165 /* Generate a DIE for a type definition. */
19168 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19170 dw_die_ref type_die
;
19173 if (TREE_ASM_WRITTEN (decl
))
19176 TREE_ASM_WRITTEN (decl
) = 1;
19177 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19178 origin
= decl_ultimate_origin (decl
);
19179 if (origin
!= NULL
)
19180 add_abstract_origin_attribute (type_die
, origin
);
19185 add_name_and_src_coords_attributes (type_die
, decl
);
19186 if (DECL_ORIGINAL_TYPE (decl
))
19188 type
= DECL_ORIGINAL_TYPE (decl
);
19190 gcc_assert (type
!= TREE_TYPE (decl
));
19191 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19195 type
= TREE_TYPE (decl
);
19197 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19199 /* Here, we are in the case of decl being a typedef naming
19200 an anonymous type, e.g:
19201 typedef struct {...} foo;
19202 In that case TREE_TYPE (decl) is not a typedef variant
19203 type and TYPE_NAME of the anonymous type is set to the
19204 TYPE_DECL of the typedef. This construct is emitted by
19207 TYPE is the anonymous struct named by the typedef
19208 DECL. As we need the DW_AT_type attribute of the
19209 DW_TAG_typedef to point to the DIE of TYPE, let's
19210 generate that DIE right away. add_type_attribute
19211 called below will then pick (via lookup_type_die) that
19212 anonymous struct DIE. */
19213 if (!TREE_ASM_WRITTEN (type
))
19214 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19216 /* This is a GNU Extension. We are adding a
19217 DW_AT_linkage_name attribute to the DIE of the
19218 anonymous struct TYPE. The value of that attribute
19219 is the name of the typedef decl naming the anonymous
19220 struct. This greatly eases the work of consumers of
19221 this debug info. */
19222 add_linkage_attr (lookup_type_die (type
), decl
);
19226 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19227 TREE_THIS_VOLATILE (decl
), context_die
);
19229 if (is_naming_typedef_decl (decl
))
19230 /* We want that all subsequent calls to lookup_type_die with
19231 TYPE in argument yield the DW_TAG_typedef we have just
19233 equate_type_number_to_die (type
, type_die
);
19235 add_accessibility_attribute (type_die
, decl
);
19238 if (DECL_ABSTRACT (decl
))
19239 equate_decl_number_to_die (decl
, type_die
);
19241 if (get_AT (type_die
, DW_AT_name
))
19242 add_pubtype (decl
, type_die
);
19245 /* Generate a DIE for a struct, class, enum or union type. */
19248 gen_tagged_type_die (tree type
,
19249 dw_die_ref context_die
,
19250 enum debug_info_usage usage
)
19254 if (type
== NULL_TREE
19255 || !is_tagged_type (type
))
19258 /* If this is a nested type whose containing class hasn't been written
19259 out yet, writing it out will cover this one, too. This does not apply
19260 to instantiations of member class templates; they need to be added to
19261 the containing class as they are generated. FIXME: This hurts the
19262 idea of combining type decls from multiple TUs, since we can't predict
19263 what set of template instantiations we'll get. */
19264 if (TYPE_CONTEXT (type
)
19265 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19266 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19268 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19270 if (TREE_ASM_WRITTEN (type
))
19273 /* If that failed, attach ourselves to the stub. */
19274 push_decl_scope (TYPE_CONTEXT (type
));
19275 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19278 else if (TYPE_CONTEXT (type
) != NULL_TREE
19279 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19281 /* If this type is local to a function that hasn't been written
19282 out yet, use a NULL context for now; it will be fixed up in
19283 decls_for_scope. */
19284 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19285 /* A declaration DIE doesn't count; nested types need to go in the
19287 if (context_die
&& is_declaration_die (context_die
))
19288 context_die
= NULL
;
19293 context_die
= declare_in_namespace (type
, context_die
);
19297 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19299 /* This might have been written out by the call to
19300 declare_in_namespace. */
19301 if (!TREE_ASM_WRITTEN (type
))
19302 gen_enumeration_type_die (type
, context_die
);
19305 gen_struct_or_union_type_die (type
, context_die
, usage
);
19310 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19311 it up if it is ever completed. gen_*_type_die will set it for us
19312 when appropriate. */
19315 /* Generate a type description DIE. */
19318 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19319 enum debug_info_usage usage
)
19321 struct array_descr_info info
;
19323 if (type
== NULL_TREE
|| type
== error_mark_node
)
19326 if (TYPE_NAME (type
) != NULL_TREE
19327 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19328 && is_redundant_typedef (TYPE_NAME (type
))
19329 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19330 /* The DECL of this type is a typedef we don't want to emit debug
19331 info for but we want debug info for its underlying typedef.
19332 This can happen for e.g, the injected-class-name of a C++
19334 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19336 /* If TYPE is a typedef type variant, let's generate debug info
19337 for the parent typedef which TYPE is a type of. */
19338 if (typedef_variant_p (type
))
19340 if (TREE_ASM_WRITTEN (type
))
19343 /* Prevent broken recursion; we can't hand off to the same type. */
19344 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19346 /* Give typedefs the right scope. */
19347 context_die
= scope_die_for (type
, context_die
);
19349 TREE_ASM_WRITTEN (type
) = 1;
19351 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19355 /* If type is an anonymous tagged type named by a typedef, let's
19356 generate debug info for the typedef. */
19357 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19359 /* Use the DIE of the containing namespace as the parent DIE of
19360 the type description DIE we want to generate. */
19361 if (DECL_CONTEXT (TYPE_NAME (type
))
19362 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19363 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19365 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19369 /* If this is an array type with hidden descriptor, handle it first. */
19370 if (!TREE_ASM_WRITTEN (type
)
19371 && lang_hooks
.types
.get_array_descr_info
19372 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19373 && (dwarf_version
>= 3 || !dwarf_strict
))
19375 gen_descr_array_type_die (type
, &info
, context_die
);
19376 TREE_ASM_WRITTEN (type
) = 1;
19380 /* We are going to output a DIE to represent the unqualified version
19381 of this type (i.e. without any const or volatile qualifiers) so
19382 get the main variant (i.e. the unqualified version) of this type
19383 now. (Vectors are special because the debugging info is in the
19384 cloned type itself). */
19385 if (TREE_CODE (type
) != VECTOR_TYPE
)
19386 type
= type_main_variant (type
);
19388 if (TREE_ASM_WRITTEN (type
))
19391 switch (TREE_CODE (type
))
19397 case REFERENCE_TYPE
:
19398 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19399 ensures that the gen_type_die recursion will terminate even if the
19400 type is recursive. Recursive types are possible in Ada. */
19401 /* ??? We could perhaps do this for all types before the switch
19403 TREE_ASM_WRITTEN (type
) = 1;
19405 /* For these types, all that is required is that we output a DIE (or a
19406 set of DIEs) to represent the "basis" type. */
19407 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19408 DINFO_USAGE_IND_USE
);
19412 /* This code is used for C++ pointer-to-data-member types.
19413 Output a description of the relevant class type. */
19414 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19415 DINFO_USAGE_IND_USE
);
19417 /* Output a description of the type of the object pointed to. */
19418 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19419 DINFO_USAGE_IND_USE
);
19421 /* Now output a DIE to represent this pointer-to-data-member type
19423 gen_ptr_to_mbr_type_die (type
, context_die
);
19426 case FUNCTION_TYPE
:
19427 /* Force out return type (in case it wasn't forced out already). */
19428 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19429 DINFO_USAGE_DIR_USE
);
19430 gen_subroutine_type_die (type
, context_die
);
19434 /* Force out return type (in case it wasn't forced out already). */
19435 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19436 DINFO_USAGE_DIR_USE
);
19437 gen_subroutine_type_die (type
, context_die
);
19441 gen_array_type_die (type
, context_die
);
19445 gen_array_type_die (type
, context_die
);
19448 case ENUMERAL_TYPE
:
19451 case QUAL_UNION_TYPE
:
19452 gen_tagged_type_die (type
, context_die
, usage
);
19458 case FIXED_POINT_TYPE
:
19461 /* No DIEs needed for fundamental types. */
19466 /* Just use DW_TAG_unspecified_type. */
19468 dw_die_ref type_die
= lookup_type_die (type
);
19469 if (type_die
== NULL
)
19471 tree name
= TYPE_NAME (type
);
19472 if (TREE_CODE (name
) == TYPE_DECL
)
19473 name
= DECL_NAME (name
);
19474 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19475 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19476 equate_type_number_to_die (type
, type_die
);
19482 gcc_unreachable ();
19485 TREE_ASM_WRITTEN (type
) = 1;
19489 gen_type_die (tree type
, dw_die_ref context_die
)
19491 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19494 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19495 things which are local to the given block. */
19498 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19500 int must_output_die
= 0;
19503 /* Ignore blocks that are NULL. */
19504 if (stmt
== NULL_TREE
)
19507 inlined_func
= inlined_function_outer_scope_p (stmt
);
19509 /* If the block is one fragment of a non-contiguous block, do not
19510 process the variables, since they will have been done by the
19511 origin block. Do process subblocks. */
19512 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19516 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19517 gen_block_die (sub
, context_die
, depth
+ 1);
19522 /* Determine if we need to output any Dwarf DIEs at all to represent this
19525 /* The outer scopes for inlinings *must* always be represented. We
19526 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19527 must_output_die
= 1;
19530 /* Determine if this block directly contains any "significant"
19531 local declarations which we will need to output DIEs for. */
19532 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19533 /* We are not in terse mode so *any* local declaration counts
19534 as being a "significant" one. */
19535 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19536 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19537 && (TREE_USED (stmt
)
19538 || TREE_ASM_WRITTEN (stmt
)
19539 || BLOCK_ABSTRACT (stmt
)));
19540 else if ((TREE_USED (stmt
)
19541 || TREE_ASM_WRITTEN (stmt
)
19542 || BLOCK_ABSTRACT (stmt
))
19543 && !dwarf2out_ignore_block (stmt
))
19544 must_output_die
= 1;
19547 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19548 DIE for any block which contains no significant local declarations at
19549 all. Rather, in such cases we just call `decls_for_scope' so that any
19550 needed Dwarf info for any sub-blocks will get properly generated. Note
19551 that in terse mode, our definition of what constitutes a "significant"
19552 local declaration gets restricted to include only inlined function
19553 instances and local (nested) function definitions. */
19554 if (must_output_die
)
19558 /* If STMT block is abstract, that means we have been called
19559 indirectly from dwarf2out_abstract_function.
19560 That function rightfully marks the descendent blocks (of
19561 the abstract function it is dealing with) as being abstract,
19562 precisely to prevent us from emitting any
19563 DW_TAG_inlined_subroutine DIE as a descendent
19564 of an abstract function instance. So in that case, we should
19565 not call gen_inlined_subroutine_die.
19567 Later though, when cgraph asks dwarf2out to emit info
19568 for the concrete instance of the function decl into which
19569 the concrete instance of STMT got inlined, the later will lead
19570 to the generation of a DW_TAG_inlined_subroutine DIE. */
19571 if (! BLOCK_ABSTRACT (stmt
))
19572 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19575 gen_lexical_block_die (stmt
, context_die
, depth
);
19578 decls_for_scope (stmt
, context_die
, depth
);
19581 /* Process variable DECL (or variable with origin ORIGIN) within
19582 block STMT and add it to CONTEXT_DIE. */
19584 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19587 tree decl_or_origin
= decl
? decl
: origin
;
19589 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19590 die
= lookup_decl_die (decl_or_origin
);
19591 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19592 && TYPE_DECL_IS_STUB (decl_or_origin
))
19593 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19597 if (die
!= NULL
&& die
->die_parent
== NULL
)
19598 add_child_die (context_die
, die
);
19599 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19600 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19601 stmt
, context_die
);
19603 gen_decl_die (decl
, origin
, context_die
);
19606 /* Generate all of the decls declared within a given scope and (recursively)
19607 all of its sub-blocks. */
19610 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19616 /* Ignore NULL blocks. */
19617 if (stmt
== NULL_TREE
)
19620 /* Output the DIEs to represent all of the data objects and typedefs
19621 declared directly within this block but not within any nested
19622 sub-blocks. Also, nested function and tag DIEs have been
19623 generated with a parent of NULL; fix that up now. */
19624 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19625 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19626 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19627 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19630 /* If we're at -g1, we're not interested in subblocks. */
19631 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19634 /* Output the DIEs to represent all sub-blocks (and the items declared
19635 therein) of this block. */
19636 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19638 subblocks
= BLOCK_CHAIN (subblocks
))
19639 gen_block_die (subblocks
, context_die
, depth
+ 1);
19642 /* Is this a typedef we can avoid emitting? */
19645 is_redundant_typedef (const_tree decl
)
19647 if (TYPE_DECL_IS_STUB (decl
))
19650 if (DECL_ARTIFICIAL (decl
)
19651 && DECL_CONTEXT (decl
)
19652 && is_tagged_type (DECL_CONTEXT (decl
))
19653 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19654 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19655 /* Also ignore the artificial member typedef for the class name. */
19661 /* Return TRUE if TYPE is a typedef that names a type for linkage
19662 purposes. This kind of typedefs is produced by the C++ FE for
19665 typedef struct {...} foo;
19667 In that case, there is no typedef variant type produced for foo.
19668 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19672 is_naming_typedef_decl (const_tree decl
)
19674 if (decl
== NULL_TREE
19675 || TREE_CODE (decl
) != TYPE_DECL
19676 || !is_tagged_type (TREE_TYPE (decl
))
19677 || DECL_IS_BUILTIN (decl
)
19678 || is_redundant_typedef (decl
)
19679 /* It looks like Ada produces TYPE_DECLs that are very similar
19680 to C++ naming typedefs but that have different
19681 semantics. Let's be specific to c++ for now. */
19685 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19686 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19687 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19688 != TYPE_NAME (TREE_TYPE (decl
))));
19691 /* Returns the DIE for a context. */
19693 static inline dw_die_ref
19694 get_context_die (tree context
)
19698 /* Find die that represents this context. */
19699 if (TYPE_P (context
))
19701 context
= TYPE_MAIN_VARIANT (context
);
19702 return strip_naming_typedef (context
, force_type_die (context
));
19705 return force_decl_die (context
);
19707 return comp_unit_die ();
19710 /* Returns the DIE for decl. A DIE will always be returned. */
19713 force_decl_die (tree decl
)
19715 dw_die_ref decl_die
;
19716 unsigned saved_external_flag
;
19717 tree save_fn
= NULL_TREE
;
19718 decl_die
= lookup_decl_die (decl
);
19721 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19723 decl_die
= lookup_decl_die (decl
);
19727 switch (TREE_CODE (decl
))
19729 case FUNCTION_DECL
:
19730 /* Clear current_function_decl, so that gen_subprogram_die thinks
19731 that this is a declaration. At this point, we just want to force
19732 declaration die. */
19733 save_fn
= current_function_decl
;
19734 current_function_decl
= NULL_TREE
;
19735 gen_subprogram_die (decl
, context_die
);
19736 current_function_decl
= save_fn
;
19740 /* Set external flag to force declaration die. Restore it after
19741 gen_decl_die() call. */
19742 saved_external_flag
= DECL_EXTERNAL (decl
);
19743 DECL_EXTERNAL (decl
) = 1;
19744 gen_decl_die (decl
, NULL
, context_die
);
19745 DECL_EXTERNAL (decl
) = saved_external_flag
;
19748 case NAMESPACE_DECL
:
19749 if (dwarf_version
>= 3 || !dwarf_strict
)
19750 dwarf2out_decl (decl
);
19752 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19753 decl_die
= comp_unit_die ();
19756 case TRANSLATION_UNIT_DECL
:
19757 decl_die
= comp_unit_die ();
19761 gcc_unreachable ();
19764 /* We should be able to find the DIE now. */
19766 decl_die
= lookup_decl_die (decl
);
19767 gcc_assert (decl_die
);
19773 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19774 always returned. */
19777 force_type_die (tree type
)
19779 dw_die_ref type_die
;
19781 type_die
= lookup_type_die (type
);
19784 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19786 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19787 TYPE_VOLATILE (type
), context_die
);
19788 gcc_assert (type_die
);
19793 /* Force out any required namespaces to be able to output DECL,
19794 and return the new context_die for it, if it's changed. */
19797 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19799 tree context
= (DECL_P (thing
)
19800 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19801 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19802 /* Force out the namespace. */
19803 context_die
= force_decl_die (context
);
19805 return context_die
;
19808 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19809 type) within its namespace, if appropriate.
19811 For compatibility with older debuggers, namespace DIEs only contain
19812 declarations; all definitions are emitted at CU scope. */
19815 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19817 dw_die_ref ns_context
;
19819 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19820 return context_die
;
19822 /* If this decl is from an inlined function, then don't try to emit it in its
19823 namespace, as we will get confused. It would have already been emitted
19824 when the abstract instance of the inline function was emitted anyways. */
19825 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19826 return context_die
;
19828 ns_context
= setup_namespace_context (thing
, context_die
);
19830 if (ns_context
!= context_die
)
19834 if (DECL_P (thing
))
19835 gen_decl_die (thing
, NULL
, ns_context
);
19837 gen_type_die (thing
, ns_context
);
19839 return context_die
;
19842 /* Generate a DIE for a namespace or namespace alias. */
19845 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19847 dw_die_ref namespace_die
;
19849 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19850 they are an alias of. */
19851 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19853 /* Output a real namespace or module. */
19854 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19855 namespace_die
= new_die (is_fortran ()
19856 ? DW_TAG_module
: DW_TAG_namespace
,
19857 context_die
, decl
);
19858 /* For Fortran modules defined in different CU don't add src coords. */
19859 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19861 const char *name
= dwarf2_name (decl
, 0);
19863 add_name_attribute (namespace_die
, name
);
19866 add_name_and_src_coords_attributes (namespace_die
, decl
);
19867 if (DECL_EXTERNAL (decl
))
19868 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
19869 equate_decl_number_to_die (decl
, namespace_die
);
19873 /* Output a namespace alias. */
19875 /* Force out the namespace we are an alias of, if necessary. */
19876 dw_die_ref origin_die
19877 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
19879 if (DECL_FILE_SCOPE_P (decl
)
19880 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
19881 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19882 /* Now create the namespace alias DIE. */
19883 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
19884 add_name_and_src_coords_attributes (namespace_die
, decl
);
19885 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
19886 equate_decl_number_to_die (decl
, namespace_die
);
19888 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
19889 if (want_pubnames ())
19890 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
19893 /* Generate Dwarf debug information for a decl described by DECL.
19894 The return value is currently only meaningful for PARM_DECLs,
19895 for all other decls it returns NULL. */
19898 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
19900 tree decl_or_origin
= decl
? decl
: origin
;
19901 tree class_origin
= NULL
, ultimate_origin
;
19903 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
19906 switch (TREE_CODE (decl_or_origin
))
19912 if (!is_fortran () && !is_ada ())
19914 /* The individual enumerators of an enum type get output when we output
19915 the Dwarf representation of the relevant enum type itself. */
19919 /* Emit its type. */
19920 gen_type_die (TREE_TYPE (decl
), context_die
);
19922 /* And its containing namespace. */
19923 context_die
= declare_in_namespace (decl
, context_die
);
19925 gen_const_die (decl
, context_die
);
19928 case FUNCTION_DECL
:
19929 /* Don't output any DIEs to represent mere function declarations,
19930 unless they are class members or explicit block externs. */
19931 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
19932 && DECL_FILE_SCOPE_P (decl_or_origin
)
19933 && (current_function_decl
== NULL_TREE
19934 || DECL_ARTIFICIAL (decl_or_origin
)))
19939 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19940 on local redeclarations of global functions. That seems broken. */
19941 if (current_function_decl
!= decl
)
19942 /* This is only a declaration. */;
19945 /* If we're emitting a clone, emit info for the abstract instance. */
19946 if (origin
|| DECL_ORIGIN (decl
) != decl
)
19947 dwarf2out_abstract_function (origin
19948 ? DECL_ORIGIN (origin
)
19949 : DECL_ABSTRACT_ORIGIN (decl
));
19951 /* If we're emitting an out-of-line copy of an inline function,
19952 emit info for the abstract instance and set up to refer to it. */
19953 else if (cgraph_function_possibly_inlined_p (decl
)
19954 && ! DECL_ABSTRACT (decl
)
19955 && ! class_or_namespace_scope_p (context_die
)
19956 /* dwarf2out_abstract_function won't emit a die if this is just
19957 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19958 that case, because that works only if we have a die. */
19959 && DECL_INITIAL (decl
) != NULL_TREE
)
19961 dwarf2out_abstract_function (decl
);
19962 set_decl_origin_self (decl
);
19965 /* Otherwise we're emitting the primary DIE for this decl. */
19966 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
19968 /* Before we describe the FUNCTION_DECL itself, make sure that we
19969 have its containing type. */
19971 origin
= decl_class_context (decl
);
19972 if (origin
!= NULL_TREE
)
19973 gen_type_die (origin
, context_die
);
19975 /* And its return type. */
19976 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
19978 /* And its virtual context. */
19979 if (DECL_VINDEX (decl
) != NULL_TREE
)
19980 gen_type_die (DECL_CONTEXT (decl
), context_die
);
19982 /* Make sure we have a member DIE for decl. */
19983 if (origin
!= NULL_TREE
)
19984 gen_type_die_for_member (origin
, decl
, context_die
);
19986 /* And its containing namespace. */
19987 context_die
= declare_in_namespace (decl
, context_die
);
19990 /* Now output a DIE to represent the function itself. */
19992 gen_subprogram_die (decl
, context_die
);
19996 /* If we are in terse mode, don't generate any DIEs to represent any
19997 actual typedefs. */
19998 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20001 /* In the special case of a TYPE_DECL node representing the declaration
20002 of some type tag, if the given TYPE_DECL is marked as having been
20003 instantiated from some other (original) TYPE_DECL node (e.g. one which
20004 was generated within the original definition of an inline function) we
20005 used to generate a special (abbreviated) DW_TAG_structure_type,
20006 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20007 should be actually referencing those DIEs, as variable DIEs with that
20008 type would be emitted already in the abstract origin, so it was always
20009 removed during unused type prunning. Don't add anything in this
20011 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20014 if (is_redundant_typedef (decl
))
20015 gen_type_die (TREE_TYPE (decl
), context_die
);
20017 /* Output a DIE to represent the typedef itself. */
20018 gen_typedef_die (decl
, context_die
);
20022 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20023 gen_label_die (decl
, context_die
);
20028 /* If we are in terse mode, don't generate any DIEs to represent any
20029 variable declarations or definitions. */
20030 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20033 /* Output any DIEs that are needed to specify the type of this data
20035 if (decl_by_reference_p (decl_or_origin
))
20036 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20038 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20040 /* And its containing type. */
20041 class_origin
= decl_class_context (decl_or_origin
);
20042 if (class_origin
!= NULL_TREE
)
20043 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20045 /* And its containing namespace. */
20046 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20048 /* Now output the DIE to represent the data object itself. This gets
20049 complicated because of the possibility that the VAR_DECL really
20050 represents an inlined instance of a formal parameter for an inline
20052 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20053 if (ultimate_origin
!= NULL_TREE
20054 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20055 gen_formal_parameter_die (decl
, origin
,
20056 true /* Emit name attribute. */,
20059 gen_variable_die (decl
, origin
, context_die
);
20063 /* Ignore the nameless fields that are used to skip bits but handle C++
20064 anonymous unions and structs. */
20065 if (DECL_NAME (decl
) != NULL_TREE
20066 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20067 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20069 gen_type_die (member_declared_type (decl
), context_die
);
20070 gen_field_die (decl
, context_die
);
20075 if (DECL_BY_REFERENCE (decl_or_origin
))
20076 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20078 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20079 return gen_formal_parameter_die (decl
, origin
,
20080 true /* Emit name attribute. */,
20083 case NAMESPACE_DECL
:
20084 case IMPORTED_DECL
:
20085 if (dwarf_version
>= 3 || !dwarf_strict
)
20086 gen_namespace_die (decl
, context_die
);
20090 /* Probably some frontend-internal decl. Assume we don't care. */
20091 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20098 /* Output debug information for global decl DECL. Called from toplev.c after
20099 compilation proper has finished. */
20102 dwarf2out_global_decl (tree decl
)
20104 /* Output DWARF2 information for file-scope tentative data object
20105 declarations, file-scope (extern) function declarations (which
20106 had no corresponding body) and file-scope tagged type declarations
20107 and definitions which have not yet been forced out. */
20108 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20109 dwarf2out_decl (decl
);
20112 /* Output debug information for type decl DECL. Called from toplev.c
20113 and from language front ends (to record built-in types). */
20115 dwarf2out_type_decl (tree decl
, int local
)
20118 dwarf2out_decl (decl
);
20121 /* Output debug information for imported module or decl DECL.
20122 NAME is non-NULL name in the lexical block if the decl has been renamed.
20123 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20124 that DECL belongs to.
20125 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20127 dwarf2out_imported_module_or_decl_1 (tree decl
,
20129 tree lexical_block
,
20130 dw_die_ref lexical_block_die
)
20132 expanded_location xloc
;
20133 dw_die_ref imported_die
= NULL
;
20134 dw_die_ref at_import_die
;
20136 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20138 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20139 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20143 xloc
= expand_location (input_location
);
20145 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20147 at_import_die
= force_type_die (TREE_TYPE (decl
));
20148 /* For namespace N { typedef void T; } using N::T; base_type_die
20149 returns NULL, but DW_TAG_imported_declaration requires
20150 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20151 if (!at_import_die
)
20153 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20154 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20155 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20156 gcc_assert (at_import_die
);
20161 at_import_die
= lookup_decl_die (decl
);
20162 if (!at_import_die
)
20164 /* If we're trying to avoid duplicate debug info, we may not have
20165 emitted the member decl for this field. Emit it now. */
20166 if (TREE_CODE (decl
) == FIELD_DECL
)
20168 tree type
= DECL_CONTEXT (decl
);
20170 if (TYPE_CONTEXT (type
)
20171 && TYPE_P (TYPE_CONTEXT (type
))
20172 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20173 DINFO_USAGE_DIR_USE
))
20175 gen_type_die_for_member (type
, decl
,
20176 get_context_die (TYPE_CONTEXT (type
)));
20178 at_import_die
= force_decl_die (decl
);
20182 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20184 if (dwarf_version
>= 3 || !dwarf_strict
)
20185 imported_die
= new_die (DW_TAG_imported_module
,
20192 imported_die
= new_die (DW_TAG_imported_declaration
,
20196 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20197 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20199 add_AT_string (imported_die
, DW_AT_name
,
20200 IDENTIFIER_POINTER (name
));
20201 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20204 /* Output debug information for imported module or decl DECL.
20205 NAME is non-NULL name in context if the decl has been renamed.
20206 CHILD is true if decl is one of the renamed decls as part of
20207 importing whole module. */
20210 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20213 /* dw_die_ref at_import_die; */
20214 dw_die_ref scope_die
;
20216 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20221 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20222 We need decl DIE for reference and scope die. First, get DIE for the decl
20225 /* Get the scope die for decl context. Use comp_unit_die for global module
20226 or decl. If die is not found for non globals, force new die. */
20228 && TYPE_P (context
)
20229 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20232 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20235 scope_die
= get_context_die (context
);
20239 gcc_assert (scope_die
->die_child
);
20240 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20241 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20242 scope_die
= scope_die
->die_child
;
20245 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20246 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20250 /* Write the debugging output for DECL. */
20253 dwarf2out_decl (tree decl
)
20255 dw_die_ref context_die
= comp_unit_die ();
20257 switch (TREE_CODE (decl
))
20262 case FUNCTION_DECL
:
20263 /* What we would really like to do here is to filter out all mere
20264 file-scope declarations of file-scope functions which are never
20265 referenced later within this translation unit (and keep all of ones
20266 that *are* referenced later on) but we aren't clairvoyant, so we have
20267 no idea which functions will be referenced in the future (i.e. later
20268 on within the current translation unit). So here we just ignore all
20269 file-scope function declarations which are not also definitions. If
20270 and when the debugger needs to know something about these functions,
20271 it will have to hunt around and find the DWARF information associated
20272 with the definition of the function.
20274 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20275 nodes represent definitions and which ones represent mere
20276 declarations. We have to check DECL_INITIAL instead. That's because
20277 the C front-end supports some weird semantics for "extern inline"
20278 function definitions. These can get inlined within the current
20279 translation unit (and thus, we need to generate Dwarf info for their
20280 abstract instances so that the Dwarf info for the concrete inlined
20281 instances can have something to refer to) but the compiler never
20282 generates any out-of-lines instances of such things (despite the fact
20283 that they *are* definitions).
20285 The important point is that the C front-end marks these "extern
20286 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20287 them anyway. Note that the C++ front-end also plays some similar games
20288 for inline function definitions appearing within include files which
20289 also contain `#pragma interface' pragmas.
20291 If we are called from dwarf2out_abstract_function output a DIE
20292 anyway. We can end up here this way with early inlining and LTO
20293 where the inlined function is output in a different LTRANS unit
20295 if (DECL_INITIAL (decl
) == NULL_TREE
20296 && ! DECL_ABSTRACT (decl
))
20299 /* If we're a nested function, initially use a parent of NULL; if we're
20300 a plain function, this will be fixed up in decls_for_scope. If
20301 we're a method, it will be ignored, since we already have a DIE. */
20302 if (decl_function_context (decl
)
20303 /* But if we're in terse mode, we don't care about scope. */
20304 && debug_info_level
> DINFO_LEVEL_TERSE
)
20305 context_die
= NULL
;
20309 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20310 declaration and if the declaration was never even referenced from
20311 within this entire compilation unit. We suppress these DIEs in
20312 order to save space in the .debug section (by eliminating entries
20313 which are probably useless). Note that we must not suppress
20314 block-local extern declarations (whether used or not) because that
20315 would screw-up the debugger's name lookup mechanism and cause it to
20316 miss things which really ought to be in scope at a given point. */
20317 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20320 /* For local statics lookup proper context die. */
20321 if (TREE_STATIC (decl
)
20322 && DECL_CONTEXT (decl
)
20323 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20324 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20326 /* If we are in terse mode, don't generate any DIEs to represent any
20327 variable declarations or definitions. */
20328 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20333 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20335 if (!is_fortran () && !is_ada ())
20337 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20338 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20341 case NAMESPACE_DECL
:
20342 case IMPORTED_DECL
:
20343 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20345 if (lookup_decl_die (decl
) != NULL
)
20350 /* Don't emit stubs for types unless they are needed by other DIEs. */
20351 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20354 /* Don't bother trying to generate any DIEs to represent any of the
20355 normal built-in types for the language we are compiling. */
20356 if (DECL_IS_BUILTIN (decl
))
20359 /* If we are in terse mode, don't generate any DIEs for types. */
20360 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20363 /* If we're a function-scope tag, initially use a parent of NULL;
20364 this will be fixed up in decls_for_scope. */
20365 if (decl_function_context (decl
))
20366 context_die
= NULL
;
20374 gen_decl_die (decl
, NULL
, context_die
);
20377 /* Write the debugging output for DECL. */
20380 dwarf2out_function_decl (tree decl
)
20382 dwarf2out_decl (decl
);
20383 call_arg_locations
= NULL
;
20384 call_arg_loc_last
= NULL
;
20385 call_site_count
= -1;
20386 tail_call_site_count
= -1;
20387 block_map
.release ();
20388 htab_empty (decl_loc_table
);
20389 htab_empty (cached_dw_loc_list_table
);
20392 /* Output a marker (i.e. a label) for the beginning of the generated code for
20393 a lexical block. */
20396 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20397 unsigned int blocknum
)
20399 switch_to_section (current_function_section ());
20400 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20403 /* Output a marker (i.e. a label) for the end of the generated code for a
20407 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20409 switch_to_section (current_function_section ());
20410 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20413 /* Returns nonzero if it is appropriate not to emit any debugging
20414 information for BLOCK, because it doesn't contain any instructions.
20416 Don't allow this for blocks with nested functions or local classes
20417 as we would end up with orphans, and in the presence of scheduling
20418 we may end up calling them anyway. */
20421 dwarf2out_ignore_block (const_tree block
)
20426 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20427 if (TREE_CODE (decl
) == FUNCTION_DECL
20428 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20430 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20432 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20433 if (TREE_CODE (decl
) == FUNCTION_DECL
20434 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20441 /* Hash table routines for file_hash. */
20444 file_table_eq (const void *p1_p
, const void *p2_p
)
20446 const struct dwarf_file_data
*const p1
=
20447 (const struct dwarf_file_data
*) p1_p
;
20448 const char *const p2
= (const char *) p2_p
;
20449 return filename_cmp (p1
->filename
, p2
) == 0;
20453 file_table_hash (const void *p_p
)
20455 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20456 return htab_hash_string (p
->filename
);
20459 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20460 dwarf2out.c) and return its "index". The index of each (known) filename is
20461 just a unique number which is associated with only that one filename. We
20462 need such numbers for the sake of generating labels (in the .debug_sfnames
20463 section) and references to those files numbers (in the .debug_srcinfo
20464 and.debug_macinfo sections). If the filename given as an argument is not
20465 found in our current list, add it to the list and assign it the next
20466 available unique index number. In order to speed up searches, we remember
20467 the index of the filename was looked up last. This handles the majority of
20470 static struct dwarf_file_data
*
20471 lookup_filename (const char *file_name
)
20474 struct dwarf_file_data
* created
;
20476 /* Check to see if the file name that was searched on the previous
20477 call matches this file name. If so, return the index. */
20478 if (file_table_last_lookup
20479 && (file_name
== file_table_last_lookup
->filename
20480 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20481 return file_table_last_lookup
;
20483 /* Didn't match the previous lookup, search the table. */
20484 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20485 htab_hash_string (file_name
), INSERT
);
20487 return (struct dwarf_file_data
*) *slot
;
20489 created
= ggc_alloc_dwarf_file_data ();
20490 created
->filename
= file_name
;
20491 created
->emitted_number
= 0;
20496 /* If the assembler will construct the file table, then translate the compiler
20497 internal file table number into the assembler file table number, and emit
20498 a .file directive if we haven't already emitted one yet. The file table
20499 numbers are different because we prune debug info for unused variables and
20500 types, which may include filenames. */
20503 maybe_emit_file (struct dwarf_file_data
* fd
)
20505 if (! fd
->emitted_number
)
20507 if (last_emitted_file
)
20508 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20510 fd
->emitted_number
= 1;
20511 last_emitted_file
= fd
;
20513 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20515 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20516 output_quoted_string (asm_out_file
,
20517 remap_debug_filename (fd
->filename
));
20518 fputc ('\n', asm_out_file
);
20522 return fd
->emitted_number
;
20525 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20526 That generation should happen after function debug info has been
20527 generated. The value of the attribute is the constant value of ARG. */
20530 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20532 die_arg_entry entry
;
20537 if (!tmpl_value_parm_die_table
)
20538 vec_alloc (tmpl_value_parm_die_table
, 32);
20542 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20545 /* Return TRUE if T is an instance of generic type, FALSE
20549 generic_type_p (tree t
)
20551 if (t
== NULL_TREE
|| !TYPE_P (t
))
20553 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20556 /* Schedule the generation of the generic parameter dies for the
20557 instance of generic type T. The proper generation itself is later
20558 done by gen_scheduled_generic_parms_dies. */
20561 schedule_generic_params_dies_gen (tree t
)
20563 if (!generic_type_p (t
))
20566 if (!generic_type_instances
)
20567 vec_alloc (generic_type_instances
, 256);
20569 vec_safe_push (generic_type_instances
, t
);
20572 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20573 by append_entry_to_tmpl_value_parm_die_table. This function must
20574 be called after function DIEs have been generated. */
20577 gen_remaining_tmpl_value_param_die_attribute (void)
20579 if (tmpl_value_parm_die_table
)
20584 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20585 tree_add_const_value_attribute (e
->die
, e
->arg
);
20589 /* Generate generic parameters DIEs for instances of generic types
20590 that have been previously scheduled by
20591 schedule_generic_params_dies_gen. This function must be called
20592 after all the types of the CU have been laid out. */
20595 gen_scheduled_generic_parms_dies (void)
20600 if (!generic_type_instances
)
20603 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20604 if (COMPLETE_TYPE_P (t
))
20605 gen_generic_params_dies (t
);
20609 /* Replace DW_AT_name for the decl with name. */
20612 dwarf2out_set_name (tree decl
, tree name
)
20618 die
= TYPE_SYMTAB_DIE (decl
);
20622 dname
= dwarf2_name (name
, 0);
20626 attr
= get_AT (die
, DW_AT_name
);
20629 struct indirect_string_node
*node
;
20631 node
= find_AT_string (dname
);
20632 /* replace the string. */
20633 attr
->dw_attr_val
.v
.val_str
= node
;
20637 add_name_attribute (die
, dname
);
20640 /* True if before or during processing of the first function being emitted. */
20641 static bool in_first_function_p
= true;
20642 /* True if loc_note during dwarf2out_var_location call might still be
20643 before first real instruction at address equal to .Ltext0. */
20644 static bool maybe_at_text_label_p
= true;
20645 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
20646 static unsigned int first_loclabel_num_not_at_text_label
;
20648 /* Called by the final INSN scan whenever we see a var location. We
20649 use it to drop labels in the right places, and throw the location in
20650 our lookup table. */
20653 dwarf2out_var_location (rtx loc_note
)
20655 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20656 struct var_loc_node
*newloc
;
20657 rtx next_real
, next_note
;
20658 static const char *last_label
;
20659 static const char *last_postcall_label
;
20660 static bool last_in_cold_section_p
;
20661 static rtx expected_next_loc_note
;
20665 if (!NOTE_P (loc_note
))
20667 if (CALL_P (loc_note
))
20670 if (SIBLING_CALL_P (loc_note
))
20671 tail_call_site_count
++;
20676 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20677 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20680 /* Optimize processing a large consecutive sequence of location
20681 notes so we don't spend too much time in next_real_insn. If the
20682 next insn is another location note, remember the next_real_insn
20683 calculation for next time. */
20684 next_real
= cached_next_real_insn
;
20687 if (expected_next_loc_note
!= loc_note
)
20688 next_real
= NULL_RTX
;
20691 next_note
= NEXT_INSN (loc_note
);
20693 || INSN_DELETED_P (next_note
)
20694 || GET_CODE (next_note
) != NOTE
20695 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20696 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20697 next_note
= NULL_RTX
;
20700 next_real
= next_real_insn (loc_note
);
20704 expected_next_loc_note
= next_note
;
20705 cached_next_real_insn
= next_real
;
20708 cached_next_real_insn
= NULL_RTX
;
20710 /* If there are no instructions which would be affected by this note,
20711 don't do anything. */
20713 && next_real
== NULL_RTX
20714 && !NOTE_DURING_CALL_P (loc_note
))
20717 if (next_real
== NULL_RTX
)
20718 next_real
= get_last_insn ();
20720 /* If there were any real insns between note we processed last time
20721 and this note (or if it is the first note), clear
20722 last_{,postcall_}label so that they are not reused this time. */
20723 if (last_var_location_insn
== NULL_RTX
20724 || last_var_location_insn
!= next_real
20725 || last_in_cold_section_p
!= in_cold_section_p
)
20728 last_postcall_label
= NULL
;
20733 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20734 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20735 NOTE_DURING_CALL_P (loc_note
)
20736 ? last_postcall_label
: last_label
);
20737 if (newloc
== NULL
)
20746 /* If there were no real insns between note we processed last time
20747 and this note, use the label we emitted last time. Otherwise
20748 create a new label and emit it. */
20749 if (last_label
== NULL
)
20751 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20752 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20754 last_label
= ggc_strdup (loclabel
);
20755 /* See if loclabel might be equal to .Ltext0. If yes,
20756 bump first_loclabel_num_not_at_text_label. */
20757 if (!have_multiple_function_sections
20758 && in_first_function_p
20759 && maybe_at_text_label_p
)
20761 static rtx last_start
;
20763 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
20764 if (insn
== last_start
)
20766 else if (!NONDEBUG_INSN_P (insn
))
20770 rtx body
= PATTERN (insn
);
20771 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
20773 /* Inline asm could occupy zero bytes. */
20774 else if (GET_CODE (body
) == ASM_INPUT
20775 || asm_noperands (body
) >= 0)
20777 #ifdef HAVE_attr_length
20778 else if (get_attr_min_length (insn
) == 0)
20783 /* Assume insn has non-zero length. */
20784 maybe_at_text_label_p
= false;
20788 if (maybe_at_text_label_p
)
20790 last_start
= loc_note
;
20791 first_loclabel_num_not_at_text_label
= loclabel_num
;
20798 struct call_arg_loc_node
*ca_loc
20799 = ggc_alloc_cleared_call_arg_loc_node ();
20800 rtx prev
= prev_real_insn (loc_note
), x
;
20801 ca_loc
->call_arg_loc_note
= loc_note
;
20802 ca_loc
->next
= NULL
;
20803 ca_loc
->label
= last_label
;
20806 || (NONJUMP_INSN_P (prev
)
20807 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20808 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20809 if (!CALL_P (prev
))
20810 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20811 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20812 x
= get_call_rtx_from (PATTERN (prev
));
20815 x
= XEXP (XEXP (x
, 0), 0);
20816 if (GET_CODE (x
) == SYMBOL_REF
20817 && SYMBOL_REF_DECL (x
)
20818 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20819 ca_loc
->symbol_ref
= x
;
20821 ca_loc
->block
= insn_scope (prev
);
20822 if (call_arg_locations
)
20823 call_arg_loc_last
->next
= ca_loc
;
20825 call_arg_locations
= ca_loc
;
20826 call_arg_loc_last
= ca_loc
;
20828 else if (!NOTE_DURING_CALL_P (loc_note
))
20829 newloc
->label
= last_label
;
20832 if (!last_postcall_label
)
20834 sprintf (loclabel
, "%s-1", last_label
);
20835 last_postcall_label
= ggc_strdup (loclabel
);
20837 newloc
->label
= last_postcall_label
;
20840 last_var_location_insn
= next_real
;
20841 last_in_cold_section_p
= in_cold_section_p
;
20844 /* Note in one location list that text section has changed. */
20847 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20849 var_loc_list
*list
= (var_loc_list
*) *slot
;
20851 list
->last_before_switch
20852 = list
->last
->next
? list
->last
->next
: list
->last
;
20856 /* Note in all location lists that text section has changed. */
20859 var_location_switch_text_section (void)
20861 if (decl_loc_table
== NULL
)
20864 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20867 /* Create a new line number table. */
20869 static dw_line_info_table
*
20870 new_line_info_table (void)
20872 dw_line_info_table
*table
;
20874 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
20875 table
->file_num
= 1;
20876 table
->line_num
= 1;
20877 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
20882 /* Lookup the "current" table into which we emit line info, so
20883 that we don't have to do it for every source line. */
20886 set_cur_line_info_table (section
*sec
)
20888 dw_line_info_table
*table
;
20890 if (sec
== text_section
)
20891 table
= text_section_line_info
;
20892 else if (sec
== cold_text_section
)
20894 table
= cold_text_section_line_info
;
20897 cold_text_section_line_info
= table
= new_line_info_table ();
20898 table
->end_label
= cold_end_label
;
20903 const char *end_label
;
20905 if (flag_reorder_blocks_and_partition
)
20907 if (in_cold_section_p
)
20908 end_label
= crtl
->subsections
.cold_section_end_label
;
20910 end_label
= crtl
->subsections
.hot_section_end_label
;
20914 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20915 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
20916 current_function_funcdef_no
);
20917 end_label
= ggc_strdup (label
);
20920 table
= new_line_info_table ();
20921 table
->end_label
= end_label
;
20923 vec_safe_push (separate_line_info
, table
);
20926 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20927 table
->is_stmt
= (cur_line_info_table
20928 ? cur_line_info_table
->is_stmt
20929 : DWARF_LINE_DEFAULT_IS_STMT_START
);
20930 cur_line_info_table
= table
;
20934 /* We need to reset the locations at the beginning of each
20935 function. We can't do this in the end_function hook, because the
20936 declarations that use the locations won't have been output when
20937 that hook is called. Also compute have_multiple_function_sections here. */
20940 dwarf2out_begin_function (tree fun
)
20942 section
*sec
= function_section (fun
);
20944 if (sec
!= text_section
)
20945 have_multiple_function_sections
= true;
20947 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
20949 gcc_assert (current_function_decl
== fun
);
20950 cold_text_section
= unlikely_text_section ();
20951 switch_to_section (cold_text_section
);
20952 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
20953 switch_to_section (sec
);
20956 dwarf2out_note_section_used ();
20957 call_site_count
= 0;
20958 tail_call_site_count
= 0;
20960 set_cur_line_info_table (sec
);
20963 /* Helper function of dwarf2out_end_function, called only after emitting
20964 the very first function into assembly. Check if some .debug_loc range
20965 might end with a .LVL* label that could be equal to .Ltext0.
20966 In that case we must force using absolute addresses in .debug_loc ranges,
20967 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
20968 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
20970 Set have_multiple_function_sections to true in that case and
20971 terminate htab traversal. */
20974 find_empty_loc_ranges_at_text_label (void **slot
, void *)
20976 var_loc_list
*entry
;
20977 struct var_loc_node
*node
;
20979 entry
= (var_loc_list
*) *slot
;
20980 node
= entry
->first
;
20981 if (node
&& node
->next
&& node
->next
->label
)
20984 const char *label
= node
->next
->label
;
20985 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
20987 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
20989 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
20990 if (strcmp (label
, loclabel
) == 0)
20992 have_multiple_function_sections
= true;
21000 /* Hook called after emitting a function into assembly.
21001 This does something only for the very first function emitted. */
21004 dwarf2out_end_function (unsigned int)
21006 if (in_first_function_p
21007 && !have_multiple_function_sections
21008 && first_loclabel_num_not_at_text_label
21010 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21012 in_first_function_p
= false;
21013 maybe_at_text_label_p
= false;
21016 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21019 push_dw_line_info_entry (dw_line_info_table
*table
,
21020 enum dw_line_info_opcode opcode
, unsigned int val
)
21022 dw_line_info_entry e
;
21025 vec_safe_push (table
->entries
, e
);
21028 /* Output a label to mark the beginning of a source code line entry
21029 and record information relating to this source line, in
21030 'line_info_table' for later output of the .debug_line section. */
21031 /* ??? The discriminator parameter ought to be unsigned. */
21034 dwarf2out_source_line (unsigned int line
, const char *filename
,
21035 int discriminator
, bool is_stmt
)
21037 unsigned int file_num
;
21038 dw_line_info_table
*table
;
21040 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
21043 /* The discriminator column was added in dwarf4. Simplify the below
21044 by simply removing it if we're not supposed to output it. */
21045 if (dwarf_version
< 4 && dwarf_strict
)
21048 table
= cur_line_info_table
;
21049 file_num
= maybe_emit_file (lookup_filename (filename
));
21051 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21052 the debugger has used the second (possibly duplicate) line number
21053 at the beginning of the function to mark the end of the prologue.
21054 We could eliminate any other duplicates within the function. For
21055 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21056 that second line number entry. */
21057 /* Recall that this end-of-prologue indication is *not* the same thing
21058 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21059 to which the hook corresponds, follows the last insn that was
21060 emitted by gen_prologue. What we need is to precede the first insn
21061 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21062 insn that corresponds to something the user wrote. These may be
21063 very different locations once scheduling is enabled. */
21065 if (0 && file_num
== table
->file_num
21066 && line
== table
->line_num
21067 && discriminator
== table
->discrim_num
21068 && is_stmt
== table
->is_stmt
)
21071 switch_to_section (current_function_section ());
21073 /* If requested, emit something human-readable. */
21074 if (flag_debug_asm
)
21075 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21077 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21079 /* Emit the .loc directive understood by GNU as. */
21080 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21081 file_num, line, is_stmt, discriminator */
21082 fputs ("\t.loc ", asm_out_file
);
21083 fprint_ul (asm_out_file
, file_num
);
21084 putc (' ', asm_out_file
);
21085 fprint_ul (asm_out_file
, line
);
21086 putc (' ', asm_out_file
);
21087 putc ('0', asm_out_file
);
21089 if (is_stmt
!= table
->is_stmt
)
21091 fputs (" is_stmt ", asm_out_file
);
21092 putc (is_stmt
? '1' : '0', asm_out_file
);
21094 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21096 gcc_assert (discriminator
> 0);
21097 fputs (" discriminator ", asm_out_file
);
21098 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21100 putc ('\n', asm_out_file
);
21104 unsigned int label_num
= ++line_info_label_num
;
21106 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21108 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21109 if (file_num
!= table
->file_num
)
21110 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21111 if (discriminator
!= table
->discrim_num
)
21112 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21113 if (is_stmt
!= table
->is_stmt
)
21114 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21115 push_dw_line_info_entry (table
, LI_set_line
, line
);
21118 table
->file_num
= file_num
;
21119 table
->line_num
= line
;
21120 table
->discrim_num
= discriminator
;
21121 table
->is_stmt
= is_stmt
;
21122 table
->in_use
= true;
21125 /* Record the beginning of a new source file. */
21128 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21130 if (flag_eliminate_dwarf2_dups
)
21132 /* Record the beginning of the file for break_out_includes. */
21133 dw_die_ref bincl_die
;
21135 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21136 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21139 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21142 e
.code
= DW_MACINFO_start_file
;
21144 e
.info
= ggc_strdup (filename
);
21145 vec_safe_push (macinfo_table
, e
);
21149 /* Record the end of a source file. */
21152 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21154 if (flag_eliminate_dwarf2_dups
)
21155 /* Record the end of the file for break_out_includes. */
21156 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21158 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21161 e
.code
= DW_MACINFO_end_file
;
21164 vec_safe_push (macinfo_table
, e
);
21168 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21169 the tail part of the directive line, i.e. the part which is past the
21170 initial whitespace, #, whitespace, directive-name, whitespace part. */
21173 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21174 const char *buffer ATTRIBUTE_UNUSED
)
21176 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21179 /* Insert a dummy first entry to be able to optimize the whole
21180 predefined macro block using DW_MACRO_GNU_transparent_include. */
21181 if (macinfo_table
->is_empty () && lineno
<= 1)
21186 vec_safe_push (macinfo_table
, e
);
21188 e
.code
= DW_MACINFO_define
;
21190 e
.info
= ggc_strdup (buffer
);
21191 vec_safe_push (macinfo_table
, e
);
21195 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21196 the tail part of the directive line, i.e. the part which is past the
21197 initial whitespace, #, whitespace, directive-name, whitespace part. */
21200 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21201 const char *buffer ATTRIBUTE_UNUSED
)
21203 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21206 /* Insert a dummy first entry to be able to optimize the whole
21207 predefined macro block using DW_MACRO_GNU_transparent_include. */
21208 if (macinfo_table
->is_empty () && lineno
<= 1)
21213 vec_safe_push (macinfo_table
, e
);
21215 e
.code
= DW_MACINFO_undef
;
21217 e
.info
= ggc_strdup (buffer
);
21218 vec_safe_push (macinfo_table
, e
);
21222 /* Routines to manipulate hash table of CUs. */
21225 htab_macinfo_hash (const void *of
)
21227 const macinfo_entry
*const entry
=
21228 (const macinfo_entry
*) of
;
21230 return htab_hash_string (entry
->info
);
21234 htab_macinfo_eq (const void *of1
, const void *of2
)
21236 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
21237 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
21239 return !strcmp (entry1
->info
, entry2
->info
);
21242 /* Output a single .debug_macinfo entry. */
21245 output_macinfo_op (macinfo_entry
*ref
)
21249 struct indirect_string_node
*node
;
21250 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21251 struct dwarf_file_data
*fd
;
21255 case DW_MACINFO_start_file
:
21256 fd
= lookup_filename (ref
->info
);
21257 file_num
= maybe_emit_file (fd
);
21258 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21259 dw2_asm_output_data_uleb128 (ref
->lineno
,
21260 "Included from line number %lu",
21261 (unsigned long) ref
->lineno
);
21262 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21264 case DW_MACINFO_end_file
:
21265 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21267 case DW_MACINFO_define
:
21268 case DW_MACINFO_undef
:
21269 len
= strlen (ref
->info
) + 1;
21271 && len
> DWARF_OFFSET_SIZE
21272 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21273 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21275 ref
->code
= ref
->code
== DW_MACINFO_define
21276 ? DW_MACRO_GNU_define_indirect
21277 : DW_MACRO_GNU_undef_indirect
;
21278 output_macinfo_op (ref
);
21281 dw2_asm_output_data (1, ref
->code
,
21282 ref
->code
== DW_MACINFO_define
21283 ? "Define macro" : "Undefine macro");
21284 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21285 (unsigned long) ref
->lineno
);
21286 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21288 case DW_MACRO_GNU_define_indirect
:
21289 case DW_MACRO_GNU_undef_indirect
:
21290 node
= find_AT_string (ref
->info
);
21292 && ((node
->form
== DW_FORM_strp
)
21293 || (node
->form
== DW_FORM_GNU_str_index
)));
21294 dw2_asm_output_data (1, ref
->code
,
21295 ref
->code
== DW_MACRO_GNU_define_indirect
21296 ? "Define macro indirect"
21297 : "Undefine macro indirect");
21298 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21299 (unsigned long) ref
->lineno
);
21300 if (node
->form
== DW_FORM_strp
)
21301 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21302 debug_str_section
, "The macro: \"%s\"",
21305 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21308 case DW_MACRO_GNU_transparent_include
:
21309 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21310 ASM_GENERATE_INTERNAL_LABEL (label
,
21311 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21312 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21315 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21316 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21321 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21322 other compilation unit .debug_macinfo sections. IDX is the first
21323 index of a define/undef, return the number of ops that should be
21324 emitted in a comdat .debug_macinfo section and emit
21325 a DW_MACRO_GNU_transparent_include entry referencing it.
21326 If the define/undef entry should be emitted normally, return 0. */
21329 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21330 htab_t
*macinfo_htab
)
21332 macinfo_entry
*first
, *second
, *cur
, *inc
;
21333 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21334 unsigned char checksum
[16];
21335 struct md5_ctx ctx
;
21336 char *grp_name
, *tail
;
21338 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21341 first
= &(*macinfo_table
)[idx
];
21342 second
= &(*macinfo_table
)[idx
+ 1];
21344 /* Optimize only if there are at least two consecutive define/undef ops,
21345 and either all of them are before first DW_MACINFO_start_file
21346 with lineno {0,1} (i.e. predefined macro block), or all of them are
21347 in some included header file. */
21348 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21350 if (vec_safe_is_empty (files
))
21352 if (first
->lineno
> 1 || second
->lineno
> 1)
21355 else if (first
->lineno
== 0)
21358 /* Find the last define/undef entry that can be grouped together
21359 with first and at the same time compute md5 checksum of their
21360 codes, linenumbers and strings. */
21361 md5_init_ctx (&ctx
);
21362 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21363 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21365 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21369 unsigned char code
= cur
->code
;
21370 md5_process_bytes (&code
, 1, &ctx
);
21371 checksum_uleb128 (cur
->lineno
, &ctx
);
21372 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21374 md5_finish_ctx (&ctx
, checksum
);
21377 /* From the containing include filename (if any) pick up just
21378 usable characters from its basename. */
21379 if (vec_safe_is_empty (files
))
21382 base
= lbasename (files
->last ().info
);
21383 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21384 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21385 encoded_filename_len
++;
21386 /* Count . at the end. */
21387 if (encoded_filename_len
)
21388 encoded_filename_len
++;
21390 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21391 linebuf_len
= strlen (linebuf
);
21393 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21394 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21396 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21397 tail
= grp_name
+ 4;
21398 if (encoded_filename_len
)
21400 for (i
= 0; base
[i
]; i
++)
21401 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21405 memcpy (tail
, linebuf
, linebuf_len
);
21406 tail
+= linebuf_len
;
21408 for (i
= 0; i
< 16; i
++)
21409 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21411 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21412 in the empty vector entry before the first define/undef. */
21413 inc
= &(*macinfo_table
)[idx
- 1];
21414 inc
->code
= DW_MACRO_GNU_transparent_include
;
21416 inc
->info
= ggc_strdup (grp_name
);
21417 if (*macinfo_htab
== NULL
)
21418 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
21419 /* Avoid emitting duplicates. */
21420 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
21425 /* If such an entry has been used before, just emit
21426 a DW_MACRO_GNU_transparent_include op. */
21427 inc
= (macinfo_entry
*) *slot
;
21428 output_macinfo_op (inc
);
21429 /* And clear all macinfo_entry in the range to avoid emitting them
21430 in the second pass. */
21431 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21440 inc
->lineno
= htab_elements (*macinfo_htab
);
21441 output_macinfo_op (inc
);
21446 /* Save any strings needed by the macinfo table in the debug str
21447 table. All strings must be collected into the table by the time
21448 index_string is called. */
21451 save_macinfo_strings (void)
21455 macinfo_entry
*ref
;
21457 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21461 /* Match the logic in output_macinfo_op to decide on
21462 indirect strings. */
21463 case DW_MACINFO_define
:
21464 case DW_MACINFO_undef
:
21465 len
= strlen (ref
->info
) + 1;
21467 && len
> DWARF_OFFSET_SIZE
21468 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21469 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21470 set_indirect_string (find_AT_string (ref
->info
));
21472 case DW_MACRO_GNU_define_indirect
:
21473 case DW_MACRO_GNU_undef_indirect
:
21474 set_indirect_string (find_AT_string (ref
->info
));
21482 /* Output macinfo section(s). */
21485 output_macinfo (void)
21488 unsigned long length
= vec_safe_length (macinfo_table
);
21489 macinfo_entry
*ref
;
21490 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21491 htab_t macinfo_htab
= NULL
;
21496 /* output_macinfo* uses these interchangeably. */
21497 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21498 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21499 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21500 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21502 /* For .debug_macro emit the section header. */
21505 dw2_asm_output_data (2, 4, "DWARF macro version number");
21506 if (DWARF_OFFSET_SIZE
== 8)
21507 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21509 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21510 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21511 (!dwarf_split_debug_info
? debug_line_section_label
21512 : debug_skeleton_line_section_label
),
21513 debug_line_section
, NULL
);
21516 /* In the first loop, it emits the primary .debug_macinfo section
21517 and after each emitted op the macinfo_entry is cleared.
21518 If a longer range of define/undef ops can be optimized using
21519 DW_MACRO_GNU_transparent_include, the
21520 DW_MACRO_GNU_transparent_include op is emitted and kept in
21521 the vector before the first define/undef in the range and the
21522 whole range of define/undef ops is not emitted and kept. */
21523 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21527 case DW_MACINFO_start_file
:
21528 vec_safe_push (files
, *ref
);
21530 case DW_MACINFO_end_file
:
21531 if (!vec_safe_is_empty (files
))
21534 case DW_MACINFO_define
:
21535 case DW_MACINFO_undef
:
21537 && HAVE_COMDAT_GROUP
21538 && vec_safe_length (files
) != 1
21541 && (*macinfo_table
)[i
- 1].code
== 0)
21543 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21552 /* A dummy entry may be inserted at the beginning to be able
21553 to optimize the whole block of predefined macros. */
21559 output_macinfo_op (ref
);
21564 if (macinfo_htab
== NULL
)
21567 htab_delete (macinfo_htab
);
21569 /* If any DW_MACRO_GNU_transparent_include were used, on those
21570 DW_MACRO_GNU_transparent_include entries terminate the
21571 current chain and switch to a new comdat .debug_macinfo
21572 section and emit the define/undef entries within it. */
21573 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21578 case DW_MACRO_GNU_transparent_include
:
21580 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21581 tree comdat_key
= get_identifier (ref
->info
);
21582 /* Terminate the previous .debug_macinfo section. */
21583 dw2_asm_output_data (1, 0, "End compilation unit");
21584 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21586 | SECTION_LINKONCE
,
21588 ASM_GENERATE_INTERNAL_LABEL (label
,
21589 DEBUG_MACRO_SECTION_LABEL
,
21591 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21594 dw2_asm_output_data (2, 4, "DWARF macro version number");
21595 if (DWARF_OFFSET_SIZE
== 8)
21596 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21598 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21601 case DW_MACINFO_define
:
21602 case DW_MACINFO_undef
:
21603 output_macinfo_op (ref
);
21608 gcc_unreachable ();
21612 /* Set up for Dwarf output at the start of compilation. */
21615 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21617 /* Allocate the file_table. */
21618 file_table
= htab_create_ggc (50, file_table_hash
,
21619 file_table_eq
, NULL
);
21621 /* Allocate the decl_die_table. */
21622 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21623 decl_die_table_eq
, NULL
);
21625 /* Allocate the decl_loc_table. */
21626 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21627 decl_loc_table_eq
, NULL
);
21629 /* Allocate the cached_dw_loc_list_table. */
21630 cached_dw_loc_list_table
21631 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21632 cached_dw_loc_list_table_eq
, NULL
);
21634 /* Allocate the initial hunk of the decl_scope_table. */
21635 vec_alloc (decl_scope_table
, 256);
21637 /* Allocate the initial hunk of the abbrev_die_table. */
21638 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21639 (ABBREV_DIE_TABLE_INCREMENT
);
21640 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21641 /* Zero-th entry is allocated, but unused. */
21642 abbrev_die_table_in_use
= 1;
21644 /* Allocate the pubtypes and pubnames vectors. */
21645 vec_alloc (pubname_table
, 32);
21646 vec_alloc (pubtype_table
, 32);
21648 vec_alloc (incomplete_types
, 64);
21650 vec_alloc (used_rtx_array
, 32);
21652 if (!dwarf_split_debug_info
)
21654 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21655 SECTION_DEBUG
, NULL
);
21656 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21657 SECTION_DEBUG
, NULL
);
21658 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21659 SECTION_DEBUG
, NULL
);
21663 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
21664 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21665 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
21666 SECTION_DEBUG
| SECTION_EXCLUDE
,
21668 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
21669 SECTION_DEBUG
, NULL
);
21670 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
21671 SECTION_DEBUG
, NULL
);
21672 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21673 SECTION_DEBUG
, NULL
);
21674 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
21675 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
21677 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
21678 the main .o, but the skeleton_line goes into the split off dwo. */
21679 debug_skeleton_line_section
21680 = get_section (DEBUG_DWO_LINE_SECTION
,
21681 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21682 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
21683 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
21684 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
21685 SECTION_DEBUG
| SECTION_EXCLUDE
,
21687 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
21688 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
21689 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
21690 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21692 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21693 SECTION_DEBUG
, NULL
);
21694 debug_macinfo_section
= get_section (dwarf_strict
21695 ? DEBUG_MACINFO_SECTION
21696 : DEBUG_MACRO_SECTION
,
21697 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
21698 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21699 SECTION_DEBUG
, NULL
);
21700 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21701 SECTION_DEBUG
, NULL
);
21702 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21703 SECTION_DEBUG
, NULL
);
21704 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21705 DEBUG_STR_SECTION_FLAGS
, NULL
);
21706 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21707 SECTION_DEBUG
, NULL
);
21708 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21709 SECTION_DEBUG
, NULL
);
21711 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21712 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21713 DEBUG_ABBREV_SECTION_LABEL
, 0);
21714 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21715 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21716 COLD_TEXT_SECTION_LABEL
, 0);
21717 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21719 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21720 DEBUG_INFO_SECTION_LABEL
, 0);
21721 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21722 DEBUG_LINE_SECTION_LABEL
, 0);
21723 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21724 DEBUG_RANGES_SECTION_LABEL
, 0);
21725 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
21726 DEBUG_ADDR_SECTION_LABEL
, 0);
21727 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21729 ? DEBUG_MACINFO_SECTION_LABEL
21730 : DEBUG_MACRO_SECTION_LABEL
, 0);
21731 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
21733 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21734 vec_alloc (macinfo_table
, 64);
21736 switch_to_section (text_section
);
21737 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21739 /* Make sure the line number table for .text always exists. */
21740 text_section_line_info
= new_line_info_table ();
21741 text_section_line_info
->end_label
= text_end_label
;
21744 /* Called before compile () starts outputtting functions, variables
21745 and toplevel asms into assembly. */
21748 dwarf2out_assembly_start (void)
21750 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21751 && dwarf2out_do_cfi_asm ()
21752 && (!(flag_unwind_tables
|| flag_exceptions
)
21753 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
21754 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21757 /* A helper function for dwarf2out_finish called through
21758 htab_traverse. Assign a string its index. All strings must be
21759 collected into the table by the time index_string is called,
21760 because the indexing code relies on htab_traverse to traverse nodes
21761 in the same order for each run. */
21764 index_string (void **h
, void *v
)
21766 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21767 unsigned int *index
= (unsigned int *) v
;
21769 find_string_form (node
);
21770 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21772 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
21773 node
->index
= *index
;
21779 /* A helper function for output_indirect_strings called through
21780 htab_traverse. Output the offset to a string and update the
21784 output_index_string_offset (void **h
, void *v
)
21786 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21787 unsigned int *offset
= (unsigned int *) v
;
21789 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21791 /* Assert that this node has been assigned an index. */
21792 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
21793 && node
->index
!= NOT_INDEXED
);
21794 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
21795 "indexed string 0x%x: %s", node
->index
, node
->str
);
21796 *offset
+= strlen (node
->str
) + 1;
21801 /* A helper function for dwarf2out_finish called through
21802 htab_traverse. Output the indexed string. */
21805 output_index_string (void **h
, void *v
)
21807 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21808 unsigned int *cur_idx
= (unsigned int *) v
;
21810 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21812 /* Assert that the strings are output in the same order as their
21813 indexes were assigned. */
21814 gcc_assert (*cur_idx
== node
->index
);
21815 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21816 assemble_string (node
->str
, strlen (node
->str
) + 1);
21822 /* A helper function for dwarf2out_finish called through
21823 htab_traverse. Emit one queued .debug_str string. */
21826 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
21828 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21830 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
21832 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21833 assemble_string (node
->str
, strlen (node
->str
) + 1);
21839 /* Output the indexed string table. */
21842 output_indirect_strings (void)
21844 if (!dwarf_split_debug_info
)
21846 switch_to_section (debug_str_section
);
21847 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
21851 unsigned int offset
= 0;
21852 unsigned int cur_idx
= 0;
21854 switch_to_section (debug_str_offsets_section
);
21855 htab_traverse_noresize (debug_str_hash
,
21856 output_index_string_offset
,
21858 switch_to_section (debug_str_section
);
21859 htab_traverse_noresize (debug_str_hash
,
21860 output_index_string
,
21865 /* Callback for htab_traverse to assign an index to an entry in the
21866 table, and to write that entry to the .debug_addr section. */
21869 output_addr_table_entry (void **slot
, void *data
)
21871 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
21872 unsigned int *cur_index
= (unsigned int *)data
;
21874 if (entry
->refcount
== 0)
21876 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
21877 || entry
->index
== NOT_INDEXED
);
21881 gcc_assert (entry
->index
== *cur_index
);
21884 switch (entry
->kind
)
21887 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
21888 "0x%x", entry
->index
);
21890 case ate_kind_rtx_dtprel
:
21891 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
21892 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
21895 fputc ('\n', asm_out_file
);
21897 case ate_kind_label
:
21898 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
21899 "0x%x", entry
->index
);
21902 gcc_unreachable ();
21907 /* Produce the .debug_addr section. */
21910 output_addr_table (void)
21912 unsigned int index
= 0;
21913 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
21916 switch_to_section (debug_addr_section
);
21917 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
21920 #if ENABLE_ASSERT_CHECKING
21921 /* Verify that all marks are clear. */
21924 verify_marks_clear (dw_die_ref die
)
21928 gcc_assert (! die
->die_mark
);
21929 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
21931 #endif /* ENABLE_ASSERT_CHECKING */
21933 /* Clear the marks for a die and its children.
21934 Be cool if the mark isn't set. */
21937 prune_unmark_dies (dw_die_ref die
)
21943 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
21946 /* Given DIE that we're marking as used, find any other dies
21947 it references as attributes and mark them as used. */
21950 prune_unused_types_walk_attribs (dw_die_ref die
)
21955 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
21957 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
21959 /* A reference to another DIE.
21960 Make sure that it will get emitted.
21961 If it was broken out into a comdat group, don't follow it. */
21962 if (! AT_ref (a
)->comdat_type_p
21963 || a
->dw_attr
== DW_AT_specification
)
21964 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
21966 /* Set the string's refcount to 0 so that prune_unused_types_mark
21967 accounts properly for it. */
21968 if (AT_class (a
) == dw_val_class_str
)
21969 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
21973 /* Mark the generic parameters and arguments children DIEs of DIE. */
21976 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
21980 if (die
== NULL
|| die
->die_child
== NULL
)
21982 c
= die
->die_child
;
21985 switch (c
->die_tag
)
21987 case DW_TAG_template_type_param
:
21988 case DW_TAG_template_value_param
:
21989 case DW_TAG_GNU_template_template_param
:
21990 case DW_TAG_GNU_template_parameter_pack
:
21991 prune_unused_types_mark (c
, 1);
21997 } while (c
&& c
!= die
->die_child
);
22000 /* Mark DIE as being used. If DOKIDS is true, then walk down
22001 to DIE's children. */
22004 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22008 if (die
->die_mark
== 0)
22010 /* We haven't done this node yet. Mark it as used. */
22012 /* If this is the DIE of a generic type instantiation,
22013 mark the children DIEs that describe its generic parms and
22015 prune_unused_types_mark_generic_parms_dies (die
);
22017 /* We also have to mark its parents as used.
22018 (But we don't want to mark our parent's kids due to this,
22019 unless it is a class.) */
22020 if (die
->die_parent
)
22021 prune_unused_types_mark (die
->die_parent
,
22022 class_scope_p (die
->die_parent
));
22024 /* Mark any referenced nodes. */
22025 prune_unused_types_walk_attribs (die
);
22027 /* If this node is a specification,
22028 also mark the definition, if it exists. */
22029 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22030 prune_unused_types_mark (die
->die_definition
, 1);
22033 if (dokids
&& die
->die_mark
!= 2)
22035 /* We need to walk the children, but haven't done so yet.
22036 Remember that we've walked the kids. */
22039 /* If this is an array type, we need to make sure our
22040 kids get marked, even if they're types. If we're
22041 breaking out types into comdat sections, do this
22042 for all type definitions. */
22043 if (die
->die_tag
== DW_TAG_array_type
22044 || (use_debug_types
22045 && is_type_die (die
) && ! is_declaration_die (die
)))
22046 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22048 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22052 /* For local classes, look if any static member functions were emitted
22053 and if so, mark them. */
22056 prune_unused_types_walk_local_classes (dw_die_ref die
)
22060 if (die
->die_mark
== 2)
22063 switch (die
->die_tag
)
22065 case DW_TAG_structure_type
:
22066 case DW_TAG_union_type
:
22067 case DW_TAG_class_type
:
22070 case DW_TAG_subprogram
:
22071 if (!get_AT_flag (die
, DW_AT_declaration
)
22072 || die
->die_definition
!= NULL
)
22073 prune_unused_types_mark (die
, 1);
22080 /* Mark children. */
22081 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22084 /* Walk the tree DIE and mark types that we actually use. */
22087 prune_unused_types_walk (dw_die_ref die
)
22091 /* Don't do anything if this node is already marked and
22092 children have been marked as well. */
22093 if (die
->die_mark
== 2)
22096 switch (die
->die_tag
)
22098 case DW_TAG_structure_type
:
22099 case DW_TAG_union_type
:
22100 case DW_TAG_class_type
:
22101 if (die
->die_perennial_p
)
22104 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22105 if (c
->die_tag
== DW_TAG_subprogram
)
22108 /* Finding used static member functions inside of classes
22109 is needed just for local classes, because for other classes
22110 static member function DIEs with DW_AT_specification
22111 are emitted outside of the DW_TAG_*_type. If we ever change
22112 it, we'd need to call this even for non-local classes. */
22114 prune_unused_types_walk_local_classes (die
);
22116 /* It's a type node --- don't mark it. */
22119 case DW_TAG_const_type
:
22120 case DW_TAG_packed_type
:
22121 case DW_TAG_pointer_type
:
22122 case DW_TAG_reference_type
:
22123 case DW_TAG_rvalue_reference_type
:
22124 case DW_TAG_volatile_type
:
22125 case DW_TAG_typedef
:
22126 case DW_TAG_array_type
:
22127 case DW_TAG_interface_type
:
22128 case DW_TAG_friend
:
22129 case DW_TAG_variant_part
:
22130 case DW_TAG_enumeration_type
:
22131 case DW_TAG_subroutine_type
:
22132 case DW_TAG_string_type
:
22133 case DW_TAG_set_type
:
22134 case DW_TAG_subrange_type
:
22135 case DW_TAG_ptr_to_member_type
:
22136 case DW_TAG_file_type
:
22137 if (die
->die_perennial_p
)
22140 /* It's a type node --- don't mark it. */
22144 /* Mark everything else. */
22148 if (die
->die_mark
== 0)
22152 /* Now, mark any dies referenced from here. */
22153 prune_unused_types_walk_attribs (die
);
22158 /* Mark children. */
22159 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22162 /* Increment the string counts on strings referred to from DIE's
22166 prune_unused_types_update_strings (dw_die_ref die
)
22171 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22172 if (AT_class (a
) == dw_val_class_str
)
22174 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22176 /* Avoid unnecessarily putting strings that are used less than
22177 twice in the hash table. */
22179 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22182 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22183 htab_hash_string (s
->str
),
22185 gcc_assert (*slot
== NULL
);
22191 /* Remove from the tree DIE any dies that aren't marked. */
22194 prune_unused_types_prune (dw_die_ref die
)
22198 gcc_assert (die
->die_mark
);
22199 prune_unused_types_update_strings (die
);
22201 if (! die
->die_child
)
22204 c
= die
->die_child
;
22206 dw_die_ref prev
= c
;
22207 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22208 if (c
== die
->die_child
)
22210 /* No marked children between 'prev' and the end of the list. */
22212 /* No marked children at all. */
22213 die
->die_child
= NULL
;
22216 prev
->die_sib
= c
->die_sib
;
22217 die
->die_child
= prev
;
22222 if (c
!= prev
->die_sib
)
22224 prune_unused_types_prune (c
);
22225 } while (c
!= die
->die_child
);
22228 /* Remove dies representing declarations that we never use. */
22231 prune_unused_types (void)
22234 limbo_die_node
*node
;
22235 comdat_type_node
*ctnode
;
22237 dw_die_ref base_type
;
22239 #if ENABLE_ASSERT_CHECKING
22240 /* All the marks should already be clear. */
22241 verify_marks_clear (comp_unit_die ());
22242 for (node
= limbo_die_list
; node
; node
= node
->next
)
22243 verify_marks_clear (node
->die
);
22244 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22245 verify_marks_clear (ctnode
->root_die
);
22246 #endif /* ENABLE_ASSERT_CHECKING */
22248 /* Mark types that are used in global variables. */
22249 premark_types_used_by_global_vars ();
22251 /* Set the mark on nodes that are actually used. */
22252 prune_unused_types_walk (comp_unit_die ());
22253 for (node
= limbo_die_list
; node
; node
= node
->next
)
22254 prune_unused_types_walk (node
->die
);
22255 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22257 prune_unused_types_walk (ctnode
->root_die
);
22258 prune_unused_types_mark (ctnode
->type_die
, 1);
22261 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22262 are unusual in that they are pubnames that are the children of pubtypes.
22263 They should only be marked via their parent DW_TAG_enumeration_type die,
22264 not as roots in themselves. */
22265 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22266 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22267 prune_unused_types_mark (pub
->die
, 1);
22268 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22269 prune_unused_types_mark (base_type
, 1);
22271 if (debug_str_hash
)
22272 htab_empty (debug_str_hash
);
22273 prune_unused_types_prune (comp_unit_die ());
22274 for (node
= limbo_die_list
; node
; node
= node
->next
)
22275 prune_unused_types_prune (node
->die
);
22276 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22277 prune_unused_types_prune (ctnode
->root_die
);
22279 /* Leave the marks clear. */
22280 prune_unmark_dies (comp_unit_die ());
22281 for (node
= limbo_die_list
; node
; node
= node
->next
)
22282 prune_unmark_dies (node
->die
);
22283 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22284 prune_unmark_dies (ctnode
->root_die
);
22287 /* Set the parameter to true if there are any relative pathnames in
22290 file_table_relative_p (void ** slot
, void *param
)
22292 bool *p
= (bool *) param
;
22293 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22294 if (!IS_ABSOLUTE_PATH (d
->filename
))
22302 /* Routines to manipulate hash table of comdat type units. */
22305 htab_ct_hash (const void *of
)
22308 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
22310 memcpy (&h
, type_node
->signature
, sizeof (h
));
22315 htab_ct_eq (const void *of1
, const void *of2
)
22317 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
22318 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
22320 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22321 DWARF_TYPE_SIGNATURE_SIZE
));
22324 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22325 to the location it would have been added, should we know its
22326 DECL_ASSEMBLER_NAME when we added other attributes. This will
22327 probably improve compactness of debug info, removing equivalent
22328 abbrevs, and hide any differences caused by deferring the
22329 computation of the assembler name, triggered by e.g. PCH. */
22332 move_linkage_attr (dw_die_ref die
)
22334 unsigned ix
= vec_safe_length (die
->die_attr
);
22335 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22337 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22338 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22342 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22344 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22348 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22350 die
->die_attr
->pop ();
22351 die
->die_attr
->quick_insert (ix
, linkage
);
22355 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22356 referenced from typed stack ops and count how often they are used. */
22359 mark_base_types (dw_loc_descr_ref loc
)
22361 dw_die_ref base_type
= NULL
;
22363 for (; loc
; loc
= loc
->dw_loc_next
)
22365 switch (loc
->dw_loc_opc
)
22367 case DW_OP_GNU_regval_type
:
22368 case DW_OP_GNU_deref_type
:
22369 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22371 case DW_OP_GNU_convert
:
22372 case DW_OP_GNU_reinterpret
:
22373 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22376 case DW_OP_GNU_const_type
:
22377 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22379 case DW_OP_GNU_entry_value
:
22380 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22385 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22386 if (base_type
->die_mark
)
22387 base_type
->die_mark
++;
22390 base_types
.safe_push (base_type
);
22391 base_type
->die_mark
= 1;
22396 /* Comparison function for sorting marked base types. */
22399 base_type_cmp (const void *x
, const void *y
)
22401 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22402 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22403 unsigned int byte_size1
, byte_size2
;
22404 unsigned int encoding1
, encoding2
;
22405 if (dx
->die_mark
> dy
->die_mark
)
22407 if (dx
->die_mark
< dy
->die_mark
)
22409 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22410 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22411 if (byte_size1
< byte_size2
)
22413 if (byte_size1
> byte_size2
)
22415 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22416 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22417 if (encoding1
< encoding2
)
22419 if (encoding1
> encoding2
)
22424 /* Move base types marked by mark_base_types as early as possible
22425 in the CU, sorted by decreasing usage count both to make the
22426 uleb128 references as small as possible and to make sure they
22427 will have die_offset already computed by calc_die_sizes when
22428 sizes of typed stack loc ops is computed. */
22431 move_marked_base_types (void)
22434 dw_die_ref base_type
, die
, c
;
22436 if (base_types
.is_empty ())
22439 /* Sort by decreasing usage count, they will be added again in that
22441 base_types
.qsort (base_type_cmp
);
22442 die
= comp_unit_die ();
22443 c
= die
->die_child
;
22446 dw_die_ref prev
= c
;
22448 while (c
->die_mark
)
22450 remove_child_with_prev (c
, prev
);
22451 /* As base types got marked, there must be at least
22452 one node other than DW_TAG_base_type. */
22453 gcc_assert (c
!= c
->die_sib
);
22457 while (c
!= die
->die_child
);
22458 gcc_assert (die
->die_child
);
22459 c
= die
->die_child
;
22460 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22462 base_type
->die_mark
= 0;
22463 base_type
->die_sib
= c
->die_sib
;
22464 c
->die_sib
= base_type
;
22469 /* Helper function for resolve_addr, attempt to resolve
22470 one CONST_STRING, return non-zero if not successful. Similarly verify that
22471 SYMBOL_REFs refer to variables emitted in the current CU. */
22474 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22478 if (GET_CODE (rtl
) == CONST_STRING
)
22480 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22481 tree t
= build_string (len
, XSTR (rtl
, 0));
22482 tree tlen
= size_int (len
- 1);
22484 = build_array_type (char_type_node
, build_index_type (tlen
));
22485 rtl
= lookup_constant_def (t
);
22486 if (!rtl
|| !MEM_P (rtl
))
22488 rtl
= XEXP (rtl
, 0);
22489 vec_safe_push (used_rtx_array
, rtl
);
22494 if (GET_CODE (rtl
) == SYMBOL_REF
22495 && SYMBOL_REF_DECL (rtl
))
22497 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22499 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22502 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22506 if (GET_CODE (rtl
) == CONST
22507 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22513 /* Helper function for resolve_addr, handle one location
22514 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22515 the location list couldn't be resolved. */
22518 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22520 dw_loc_descr_ref keep
= NULL
;
22521 for (; loc
; loc
= loc
->dw_loc_next
)
22522 switch (loc
->dw_loc_opc
)
22525 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22528 case DW_OP_GNU_addr_index
:
22529 case DW_OP_GNU_const_index
:
22531 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22532 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22533 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22538 case DW_OP_const4u
:
22539 case DW_OP_const8u
:
22541 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22544 case DW_OP_plus_uconst
:
22545 if (size_of_loc_descr (loc
)
22546 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22548 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22550 dw_loc_descr_ref repl
22551 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22552 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
22553 add_loc_descr (&repl
, loc
->dw_loc_next
);
22557 case DW_OP_implicit_value
:
22558 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22559 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
22562 case DW_OP_GNU_implicit_pointer
:
22563 case DW_OP_GNU_parameter_ref
:
22564 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22567 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22570 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22571 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22572 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22575 case DW_OP_GNU_const_type
:
22576 case DW_OP_GNU_regval_type
:
22577 case DW_OP_GNU_deref_type
:
22578 case DW_OP_GNU_convert
:
22579 case DW_OP_GNU_reinterpret
:
22580 while (loc
->dw_loc_next
22581 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
22583 dw_die_ref base1
, base2
;
22584 unsigned enc1
, enc2
, size1
, size2
;
22585 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22586 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22587 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22588 else if (loc
->dw_loc_oprnd1
.val_class
22589 == dw_val_class_unsigned_const
)
22592 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22593 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
22594 == dw_val_class_unsigned_const
)
22596 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22597 gcc_assert (base1
->die_tag
== DW_TAG_base_type
22598 && base2
->die_tag
== DW_TAG_base_type
);
22599 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
22600 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
22601 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
22602 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
22604 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
22605 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
22609 /* Optimize away next DW_OP_GNU_convert after
22610 adjusting LOC's base type die reference. */
22611 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22612 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22613 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
22615 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
22616 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22619 /* Don't change integer DW_OP_GNU_convert after e.g. floating
22620 point typed stack entry. */
22621 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
22622 keep
= loc
->dw_loc_next
;
22632 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22633 an address in .rodata section if the string literal is emitted there,
22634 or remove the containing location list or replace DW_AT_const_value
22635 with DW_AT_location and empty location expression, if it isn't found
22636 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22637 to something that has been emitted in the current CU. */
22640 resolve_addr (dw_die_ref die
)
22644 dw_loc_list_ref
*curr
, *start
, loc
;
22647 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22648 switch (AT_class (a
))
22650 case dw_val_class_loc_list
:
22651 start
= curr
= AT_loc_list_ptr (a
);
22654 /* The same list can be referenced more than once. See if we have
22655 already recorded the result from a previous pass. */
22657 *curr
= loc
->dw_loc_next
;
22658 else if (!loc
->resolved_addr
)
22660 /* As things stand, we do not expect or allow one die to
22661 reference a suffix of another die's location list chain.
22662 References must be identical or completely separate.
22663 There is therefore no need to cache the result of this
22664 pass on any list other than the first; doing so
22665 would lead to unnecessary writes. */
22668 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
22669 if (!resolve_addr_in_expr ((*curr
)->expr
))
22671 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
22672 dw_loc_descr_ref l
= (*curr
)->expr
;
22674 if (next
&& (*curr
)->ll_symbol
)
22676 gcc_assert (!next
->ll_symbol
);
22677 next
->ll_symbol
= (*curr
)->ll_symbol
;
22679 if (dwarf_split_debug_info
)
22680 remove_loc_list_addr_table_entries (l
);
22685 mark_base_types ((*curr
)->expr
);
22686 curr
= &(*curr
)->dw_loc_next
;
22690 loc
->resolved_addr
= 1;
22694 if (dwarf_split_debug_info
)
22695 remove_loc_list_addr_table_entries (loc
->expr
);
22696 loc
->dw_loc_next
= *start
;
22701 remove_AT (die
, a
->dw_attr
);
22705 case dw_val_class_loc
:
22707 dw_loc_descr_ref l
= AT_loc (a
);
22708 /* For -gdwarf-2 don't attempt to optimize
22709 DW_AT_data_member_location containing
22710 DW_OP_plus_uconst - older consumers might
22711 rely on it being that op instead of a more complex,
22712 but shorter, location description. */
22713 if ((dwarf_version
> 2
22714 || a
->dw_attr
!= DW_AT_data_member_location
22716 || l
->dw_loc_opc
!= DW_OP_plus_uconst
22717 || l
->dw_loc_next
!= NULL
)
22718 && !resolve_addr_in_expr (l
))
22720 if (dwarf_split_debug_info
)
22721 remove_loc_list_addr_table_entries (l
);
22722 remove_AT (die
, a
->dw_attr
);
22726 mark_base_types (l
);
22729 case dw_val_class_addr
:
22730 if (a
->dw_attr
== DW_AT_const_value
22731 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
22733 if (AT_index (a
) != NOT_INDEXED
)
22734 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
22735 remove_AT (die
, a
->dw_attr
);
22738 if (die
->die_tag
== DW_TAG_GNU_call_site
22739 && a
->dw_attr
== DW_AT_abstract_origin
)
22741 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
22742 dw_die_ref tdie
= lookup_decl_die (tdecl
);
22744 && DECL_EXTERNAL (tdecl
)
22745 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
22747 force_decl_die (tdecl
);
22748 tdie
= lookup_decl_die (tdecl
);
22752 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
22753 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
22754 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
22758 if (AT_index (a
) != NOT_INDEXED
)
22759 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
22760 remove_AT (die
, a
->dw_attr
);
22769 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
22772 /* Helper routines for optimize_location_lists.
22773 This pass tries to share identical local lists in .debug_loc
22776 /* Iteratively hash operands of LOC opcode. */
22778 static inline hashval_t
22779 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
22781 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
22782 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
22784 switch (loc
->dw_loc_opc
)
22786 case DW_OP_const4u
:
22787 case DW_OP_const8u
:
22791 case DW_OP_const1u
:
22792 case DW_OP_const1s
:
22793 case DW_OP_const2u
:
22794 case DW_OP_const2s
:
22795 case DW_OP_const4s
:
22796 case DW_OP_const8s
:
22800 case DW_OP_plus_uconst
:
22836 case DW_OP_deref_size
:
22837 case DW_OP_xderef_size
:
22838 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22845 gcc_assert (val1
->val_class
== dw_val_class_loc
);
22846 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
22847 hash
= iterative_hash_object (offset
, hash
);
22850 case DW_OP_implicit_value
:
22851 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22852 switch (val2
->val_class
)
22854 case dw_val_class_const
:
22855 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22857 case dw_val_class_vec
:
22859 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22860 unsigned int len
= val2
->v
.val_vec
.length
;
22862 hash
= iterative_hash_object (elt_size
, hash
);
22863 hash
= iterative_hash_object (len
, hash
);
22864 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22865 len
* elt_size
, hash
);
22868 case dw_val_class_const_double
:
22869 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22870 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22872 case dw_val_class_addr
:
22873 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
22876 gcc_unreachable ();
22880 case DW_OP_bit_piece
:
22881 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22882 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22888 unsigned char dtprel
= 0xd1;
22889 hash
= iterative_hash_object (dtprel
, hash
);
22891 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
22893 case DW_OP_GNU_addr_index
:
22894 case DW_OP_GNU_const_index
:
22898 unsigned char dtprel
= 0xd1;
22899 hash
= iterative_hash_object (dtprel
, hash
);
22901 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
22904 case DW_OP_GNU_implicit_pointer
:
22905 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22907 case DW_OP_GNU_entry_value
:
22908 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
22910 case DW_OP_GNU_regval_type
:
22911 case DW_OP_GNU_deref_type
:
22913 unsigned int byte_size
22914 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
22915 unsigned int encoding
22916 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
22917 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22918 hash
= iterative_hash_object (byte_size
, hash
);
22919 hash
= iterative_hash_object (encoding
, hash
);
22922 case DW_OP_GNU_convert
:
22923 case DW_OP_GNU_reinterpret
:
22924 if (val1
->val_class
== dw_val_class_unsigned_const
)
22926 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22930 case DW_OP_GNU_const_type
:
22932 unsigned int byte_size
22933 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
22934 unsigned int encoding
22935 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
22936 hash
= iterative_hash_object (byte_size
, hash
);
22937 hash
= iterative_hash_object (encoding
, hash
);
22938 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
22940 hash
= iterative_hash_object (val2
->val_class
, hash
);
22941 switch (val2
->val_class
)
22943 case dw_val_class_const
:
22944 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22946 case dw_val_class_vec
:
22948 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22949 unsigned int len
= val2
->v
.val_vec
.length
;
22951 hash
= iterative_hash_object (elt_size
, hash
);
22952 hash
= iterative_hash_object (len
, hash
);
22953 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22954 len
* elt_size
, hash
);
22957 case dw_val_class_const_double
:
22958 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22959 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22962 gcc_unreachable ();
22968 /* Other codes have no operands. */
22974 /* Iteratively hash the whole DWARF location expression LOC. */
22976 static inline hashval_t
22977 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
22979 dw_loc_descr_ref l
;
22980 bool sizes_computed
= false;
22981 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22982 size_of_locs (loc
);
22984 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
22986 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
22987 hash
= iterative_hash_object (opc
, hash
);
22988 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
22990 size_of_locs (loc
);
22991 sizes_computed
= true;
22993 hash
= hash_loc_operands (l
, hash
);
22998 /* Compute hash of the whole location list LIST_HEAD. */
23001 hash_loc_list (dw_loc_list_ref list_head
)
23003 dw_loc_list_ref curr
= list_head
;
23004 hashval_t hash
= 0;
23006 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23008 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23009 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23011 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23013 hash
= hash_locs (curr
->expr
, hash
);
23015 list_head
->hash
= hash
;
23018 /* Return true if X and Y opcodes have the same operands. */
23021 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23023 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23024 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23025 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23026 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23028 switch (x
->dw_loc_opc
)
23030 case DW_OP_const4u
:
23031 case DW_OP_const8u
:
23035 case DW_OP_const1u
:
23036 case DW_OP_const1s
:
23037 case DW_OP_const2u
:
23038 case DW_OP_const2s
:
23039 case DW_OP_const4s
:
23040 case DW_OP_const8s
:
23044 case DW_OP_plus_uconst
:
23080 case DW_OP_deref_size
:
23081 case DW_OP_xderef_size
:
23082 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23085 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23086 can cause irrelevant differences in dw_loc_addr. */
23087 gcc_assert (valx1
->val_class
== dw_val_class_loc
23088 && valy1
->val_class
== dw_val_class_loc
23089 && (dwarf_split_debug_info
23090 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23091 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23092 case DW_OP_implicit_value
:
23093 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23094 || valx2
->val_class
!= valy2
->val_class
)
23096 switch (valx2
->val_class
)
23098 case dw_val_class_const
:
23099 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23100 case dw_val_class_vec
:
23101 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23102 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23103 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23104 valx2
->v
.val_vec
.elt_size
23105 * valx2
->v
.val_vec
.length
) == 0;
23106 case dw_val_class_const_double
:
23107 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23108 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23109 case dw_val_class_addr
:
23110 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23112 gcc_unreachable ();
23115 case DW_OP_bit_piece
:
23116 return valx1
->v
.val_int
== valy1
->v
.val_int
23117 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23120 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23121 case DW_OP_GNU_addr_index
:
23122 case DW_OP_GNU_const_index
:
23124 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23125 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23126 return rtx_equal_p (ax1
, ay1
);
23128 case DW_OP_GNU_implicit_pointer
:
23129 return valx1
->val_class
== dw_val_class_die_ref
23130 && valx1
->val_class
== valy1
->val_class
23131 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23132 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23133 case DW_OP_GNU_entry_value
:
23134 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23135 case DW_OP_GNU_const_type
:
23136 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23137 || valx2
->val_class
!= valy2
->val_class
)
23139 switch (valx2
->val_class
)
23141 case dw_val_class_const
:
23142 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23143 case dw_val_class_vec
:
23144 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23145 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23146 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23147 valx2
->v
.val_vec
.elt_size
23148 * valx2
->v
.val_vec
.length
) == 0;
23149 case dw_val_class_const_double
:
23150 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23151 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23153 gcc_unreachable ();
23155 case DW_OP_GNU_regval_type
:
23156 case DW_OP_GNU_deref_type
:
23157 return valx1
->v
.val_int
== valy1
->v
.val_int
23158 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23159 case DW_OP_GNU_convert
:
23160 case DW_OP_GNU_reinterpret
:
23161 if (valx1
->val_class
!= valy1
->val_class
)
23163 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23164 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23165 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23166 case DW_OP_GNU_parameter_ref
:
23167 return valx1
->val_class
== dw_val_class_die_ref
23168 && valx1
->val_class
== valy1
->val_class
23169 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23171 /* Other codes have no operands. */
23176 /* Return true if DWARF location expressions X and Y are the same. */
23179 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23181 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23182 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23183 || x
->dtprel
!= y
->dtprel
23184 || !compare_loc_operands (x
, y
))
23186 return x
== NULL
&& y
== NULL
;
23189 /* Return precomputed hash of location list X. */
23192 loc_list_hash (const void *x
)
23194 return ((const struct dw_loc_list_struct
*) x
)->hash
;
23197 /* Return 1 if location lists X and Y are the same. */
23200 loc_list_eq (const void *x
, const void *y
)
23202 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
23203 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
23206 if (a
->hash
!= b
->hash
)
23208 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23209 if (strcmp (a
->begin
, b
->begin
) != 0
23210 || strcmp (a
->end
, b
->end
) != 0
23211 || (a
->section
== NULL
) != (b
->section
== NULL
)
23212 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23213 || !compare_locs (a
->expr
, b
->expr
))
23215 return a
== NULL
&& b
== NULL
;
23218 /* Recursively optimize location lists referenced from DIE
23219 children and share them whenever possible. */
23222 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
23229 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23230 if (AT_class (a
) == dw_val_class_loc_list
)
23232 dw_loc_list_ref list
= AT_loc_list (a
);
23233 /* TODO: perform some optimizations here, before hashing
23234 it and storing into the hash table. */
23235 hash_loc_list (list
);
23236 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
23239 *slot
= (void *) list
;
23241 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
23244 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23248 /* Recursively assign each location list a unique index into the debug_addr
23252 index_location_lists (dw_die_ref die
)
23258 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23259 if (AT_class (a
) == dw_val_class_loc_list
)
23261 dw_loc_list_ref list
= AT_loc_list (a
);
23262 dw_loc_list_ref curr
;
23263 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23265 /* Don't index an entry that has already been indexed
23266 or won't be output. */
23267 if (curr
->begin_entry
!= NULL
23268 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23272 = add_addr_table_entry (xstrdup (curr
->begin
),
23277 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23280 /* Optimize location lists referenced from DIE
23281 children and share them whenever possible. */
23284 optimize_location_lists (dw_die_ref die
)
23286 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
23287 optimize_location_lists_1 (die
, htab
);
23288 htab_delete (htab
);
23291 /* Output stuff that dwarf requires at the end of every file,
23292 and generate the DWARF-2 debugging info. */
23295 dwarf2out_finish (const char *filename
)
23297 limbo_die_node
*node
, *next_node
;
23298 comdat_type_node
*ctnode
;
23299 htab_t comdat_type_table
;
23301 dw_die_ref main_comp_unit_die
;
23303 /* PCH might result in DW_AT_producer string being restored from the
23304 header compilation, so always fill it with empty string initially
23305 and overwrite only here. */
23306 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23307 producer_string
= gen_producer_string ();
23308 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23309 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23311 gen_scheduled_generic_parms_dies ();
23312 gen_remaining_tmpl_value_param_die_attribute ();
23314 /* Add the name for the main input file now. We delayed this from
23315 dwarf2out_init to avoid complications with PCH. */
23316 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23317 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23318 add_comp_dir_attribute (comp_unit_die ());
23319 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23322 htab_traverse (file_table
, file_table_relative_p
, &p
);
23324 add_comp_dir_attribute (comp_unit_die ());
23327 if (deferred_locations_list
)
23328 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23330 add_location_or_const_value_attribute (
23331 (*deferred_locations_list
)[i
].die
,
23332 (*deferred_locations_list
)[i
].variable
,
23337 /* Traverse the limbo die list, and add parent/child links. The only
23338 dies without parents that should be here are concrete instances of
23339 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23340 For concrete instances, we can get the parent die from the abstract
23342 for (node
= limbo_die_list
; node
; node
= next_node
)
23344 dw_die_ref die
= node
->die
;
23345 next_node
= node
->next
;
23347 if (die
->die_parent
== NULL
)
23349 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23351 if (origin
&& origin
->die_parent
)
23352 add_child_die (origin
->die_parent
, die
);
23353 else if (is_cu_die (die
))
23355 else if (seen_error ())
23356 /* It's OK to be confused by errors in the input. */
23357 add_child_die (comp_unit_die (), die
);
23360 /* In certain situations, the lexical block containing a
23361 nested function can be optimized away, which results
23362 in the nested function die being orphaned. Likewise
23363 with the return type of that nested function. Force
23364 this to be a child of the containing function.
23366 It may happen that even the containing function got fully
23367 inlined and optimized out. In that case we are lost and
23368 assign the empty child. This should not be big issue as
23369 the function is likely unreachable too. */
23370 gcc_assert (node
->created_for
);
23372 if (DECL_P (node
->created_for
))
23373 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23374 else if (TYPE_P (node
->created_for
))
23375 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23377 origin
= comp_unit_die ();
23379 add_child_die (origin
, die
);
23384 limbo_die_list
= NULL
;
23386 #if ENABLE_ASSERT_CHECKING
23388 dw_die_ref die
= comp_unit_die (), c
;
23389 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23392 resolve_addr (comp_unit_die ());
23393 move_marked_base_types ();
23395 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23397 tree decl
= node
->created_for
;
23398 /* When generating LTO bytecode we can not generate new assembler
23399 names at this point and all important decls got theirs via
23401 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23402 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23404 add_linkage_attr (node
->die
, decl
);
23405 move_linkage_attr (node
->die
);
23409 deferred_asm_name
= NULL
;
23411 /* Walk through the list of incomplete types again, trying once more to
23412 emit full debugging info for them. */
23413 retry_incomplete_types ();
23415 if (flag_eliminate_unused_debug_types
)
23416 prune_unused_types ();
23418 /* Generate separate COMDAT sections for type DIEs. */
23419 if (use_debug_types
)
23421 break_out_comdat_types (comp_unit_die ());
23423 /* Each new type_unit DIE was added to the limbo die list when created.
23424 Since these have all been added to comdat_type_list, clear the
23426 limbo_die_list
= NULL
;
23428 /* For each new comdat type unit, copy declarations for incomplete
23429 types to make the new unit self-contained (i.e., no direct
23430 references to the main compile unit). */
23431 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23432 copy_decls_for_unworthy_types (ctnode
->root_die
);
23433 copy_decls_for_unworthy_types (comp_unit_die ());
23435 /* In the process of copying declarations from one unit to another,
23436 we may have left some declarations behind that are no longer
23437 referenced. Prune them. */
23438 prune_unused_types ();
23441 /* Generate separate CUs for each of the include files we've seen.
23442 They will go into limbo_die_list. */
23443 if (flag_eliminate_dwarf2_dups
)
23444 break_out_includes (comp_unit_die ());
23446 /* Traverse the DIE's and add add sibling attributes to those DIE's
23447 that have children. */
23448 add_sibling_attributes (comp_unit_die ());
23449 for (node
= limbo_die_list
; node
; node
= node
->next
)
23450 add_sibling_attributes (node
->die
);
23451 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23452 add_sibling_attributes (ctnode
->root_die
);
23454 /* When splitting DWARF info, we put some attributes in the
23455 skeleton compile_unit DIE that remains in the .o, while
23456 most attributes go in the DWO compile_unit_die. */
23457 if (dwarf_split_debug_info
)
23458 main_comp_unit_die
= gen_compile_unit_die (NULL
);
23460 main_comp_unit_die
= comp_unit_die ();
23462 /* Output a terminator label for the .text section. */
23463 switch_to_section (text_section
);
23464 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23465 if (cold_text_section
)
23467 switch_to_section (cold_text_section
);
23468 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23471 /* We can only use the low/high_pc attributes if all of the code was
23473 if (!have_multiple_function_sections
23474 || (dwarf_version
< 3 && dwarf_strict
))
23476 /* Don't add if the CU has no associated code. */
23477 if (text_section_used
)
23478 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
23479 text_end_label
, true);
23485 bool range_list_added
= false;
23487 if (text_section_used
)
23488 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
23489 text_end_label
, &range_list_added
, true);
23490 if (cold_text_section_used
)
23491 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
23492 cold_end_label
, &range_list_added
, true);
23494 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
23496 if (DECL_IGNORED_P (fde
->decl
))
23498 if (!fde
->in_std_section
)
23499 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
23500 fde
->dw_fde_end
, &range_list_added
,
23502 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23503 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
23504 fde
->dw_fde_second_end
, &range_list_added
,
23508 if (range_list_added
)
23510 /* We need to give .debug_loc and .debug_ranges an appropriate
23511 "base address". Use zero so that these addresses become
23512 absolute. Historically, we've emitted the unexpected
23513 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23514 Emit both to give time for other tools to adapt. */
23515 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
23516 if (! dwarf_strict
&& dwarf_version
< 4)
23517 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
23523 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23524 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
23525 debug_line_section_label
);
23528 add_AT_macptr (comp_unit_die (),
23529 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
23530 macinfo_section_label
);
23532 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
23534 /* optimize_location_lists calculates the size of the lists,
23535 so index them first, and assign indices to the entries.
23536 Although optimize_location_lists will remove entries from
23537 the table, it only does so for duplicates, and therefore
23538 only reduces ref_counts to 1. */
23539 unsigned int index
= 0;
23540 index_location_lists (comp_unit_die ());
23541 htab_traverse_noresize (addr_index_table
,
23542 index_addr_table_entry
, &index
);
23544 if (have_location_lists
)
23545 optimize_location_lists (comp_unit_die ());
23547 save_macinfo_strings ();
23548 if (dwarf_split_debug_info
)
23550 unsigned int index
= 0;
23551 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
23554 /* Output all of the compilation units. We put the main one last so that
23555 the offsets are available to output_pubnames. */
23556 for (node
= limbo_die_list
; node
; node
= node
->next
)
23557 output_comp_unit (node
->die
, 0);
23559 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
23560 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23562 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
23564 /* Don't output duplicate types. */
23565 if (*slot
!= HTAB_EMPTY_ENTRY
)
23568 /* Add a pointer to the line table for the main compilation unit
23569 so that the debugger can make sense of DW_AT_decl_file
23571 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23572 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23573 (!dwarf_split_debug_info
23574 ? debug_line_section_label
23575 : debug_skeleton_line_section_label
));
23577 output_comdat_type_unit (ctnode
);
23580 htab_delete (comdat_type_table
);
23582 /* The AT_pubnames attribute needs to go in all skeleton dies, including
23583 both the main_cu and all skeleton TUs. Making this call unconditional
23584 would end up either adding a second copy of the AT_pubnames attribute, or
23585 requiring a special case in add_top_level_skeleton_die_attrs. */
23586 if (!dwarf_split_debug_info
)
23587 add_AT_pubnames (comp_unit_die ());
23589 if (dwarf_split_debug_info
)
23592 unsigned char checksum
[16];
23593 struct md5_ctx ctx
;
23595 /* Compute a checksum of the comp_unit to use as the dwo_id. */
23596 md5_init_ctx (&ctx
);
23598 die_checksum (comp_unit_die (), &ctx
, &mark
);
23599 unmark_all_dies (comp_unit_die ());
23600 md5_finish_ctx (&ctx
, checksum
);
23602 /* Use the first 8 bytes of the checksum as the dwo_id,
23603 and add it to both comp-unit DIEs. */
23604 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
23605 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
23607 /* Add the base offset of the ranges table to the skeleton
23609 if (ranges_table_in_use
)
23610 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
23611 ranges_section_label
);
23613 switch_to_section (debug_addr_section
);
23614 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
23615 output_addr_table ();
23618 /* Output the main compilation unit if non-empty or if .debug_macinfo
23619 or .debug_macro will be emitted. */
23620 output_comp_unit (comp_unit_die (), have_macinfo
);
23622 if (dwarf_split_debug_info
&& info_section_emitted
)
23623 output_skeleton_debug_sections (main_comp_unit_die
);
23625 /* Output the abbreviation table. */
23626 if (abbrev_die_table_in_use
!= 1)
23628 switch_to_section (debug_abbrev_section
);
23629 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
23630 output_abbrev_section ();
23633 /* Output location list section if necessary. */
23634 if (have_location_lists
)
23636 /* Output the location lists info. */
23637 switch_to_section (debug_loc_section
);
23638 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
23639 output_location_lists (comp_unit_die ());
23642 /* Output public names and types tables if necessary. */
23643 output_pubnames (pubname_table
);
23644 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23645 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23646 simply won't look for the section. */
23647 output_pubnames (pubtype_table
);
23649 /* Output the address range information if a CU (.debug_info section)
23650 was emitted. We output an empty table even if we had no functions
23651 to put in it. This because the consumer has no way to tell the
23652 difference between an empty table that we omitted and failure to
23653 generate a table that would have contained data. */
23654 if (info_section_emitted
)
23656 unsigned long aranges_length
= size_of_aranges ();
23658 switch_to_section (debug_aranges_section
);
23659 output_aranges (aranges_length
);
23662 /* Output ranges section if necessary. */
23663 if (ranges_table_in_use
)
23665 switch_to_section (debug_ranges_section
);
23666 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
23670 /* Have to end the macro section. */
23673 switch_to_section (debug_macinfo_section
);
23674 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
23676 dw2_asm_output_data (1, 0, "End compilation unit");
23679 /* Output the source line correspondence table. We must do this
23680 even if there is no line information. Otherwise, on an empty
23681 translation unit, we will generate a present, but empty,
23682 .debug_info section. IRIX 6.5 `nm' will then complain when
23683 examining the file. This is done late so that any filenames
23684 used by the debug_info section are marked as 'used'. */
23685 switch_to_section (debug_line_section
);
23686 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
23687 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
23688 output_line_info (false);
23690 if (dwarf_split_debug_info
&& info_section_emitted
)
23692 switch_to_section (debug_skeleton_line_section
);
23693 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
23694 output_line_info (true);
23697 /* If we emitted any indirect strings, output the string table too. */
23698 if (debug_str_hash
)
23699 output_indirect_strings ();
23702 #include "gt-dwarf2out.h"