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 (TREE_CODE (decl
) == VAR_DECL
5024 && DECL_HAS_DEBUG_EXPR_P (decl
))
5026 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5027 if (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 && NOTE_P (temp
->first
->loc
)
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
);
5355 debug (die_struct
&ref
)
5357 print_die (&ref
, stderr
);
5361 debug (die_struct
*ptr
)
5366 fprintf (stderr
, "<nil>\n");
5370 /* Print all DWARF information collected for the compilation unit.
5371 This routine is a debugging aid only. */
5377 print_die (comp_unit_die (), stderr
);
5380 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5381 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5382 DIE that marks the start of the DIEs for this include file. */
5385 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5387 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5388 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5390 new_unit
->die_sib
= old_unit
;
5394 /* Close an include-file CU and reopen the enclosing one. */
5397 pop_compile_unit (dw_die_ref old_unit
)
5399 dw_die_ref new_unit
= old_unit
->die_sib
;
5401 old_unit
->die_sib
= NULL
;
5405 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5406 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5408 /* Calculate the checksum of a location expression. */
5411 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5415 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5417 CHECKSUM (loc
->dw_loc_oprnd1
);
5418 CHECKSUM (loc
->dw_loc_oprnd2
);
5421 /* Calculate the checksum of an attribute. */
5424 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5426 dw_loc_descr_ref loc
;
5429 CHECKSUM (at
->dw_attr
);
5431 /* We don't care that this was compiled with a different compiler
5432 snapshot; if the output is the same, that's what matters. */
5433 if (at
->dw_attr
== DW_AT_producer
)
5436 switch (AT_class (at
))
5438 case dw_val_class_const
:
5439 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5441 case dw_val_class_unsigned_const
:
5442 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5444 case dw_val_class_const_double
:
5445 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5447 case dw_val_class_vec
:
5448 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5450 case dw_val_class_flag
:
5451 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5453 case dw_val_class_str
:
5454 CHECKSUM_STRING (AT_string (at
));
5457 case dw_val_class_addr
:
5459 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5460 CHECKSUM_STRING (XSTR (r
, 0));
5463 case dw_val_class_offset
:
5464 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5467 case dw_val_class_loc
:
5468 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5469 loc_checksum (loc
, ctx
);
5472 case dw_val_class_die_ref
:
5473 die_checksum (AT_ref (at
), ctx
, mark
);
5476 case dw_val_class_fde_ref
:
5477 case dw_val_class_vms_delta
:
5478 case dw_val_class_lbl_id
:
5479 case dw_val_class_lineptr
:
5480 case dw_val_class_macptr
:
5481 case dw_val_class_high_pc
:
5484 case dw_val_class_file
:
5485 CHECKSUM_STRING (AT_file (at
)->filename
);
5488 case dw_val_class_data8
:
5489 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5497 /* Calculate the checksum of a DIE. */
5500 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5506 /* To avoid infinite recursion. */
5509 CHECKSUM (die
->die_mark
);
5512 die
->die_mark
= ++(*mark
);
5514 CHECKSUM (die
->die_tag
);
5516 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5517 attr_checksum (a
, ctx
, mark
);
5519 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5523 #undef CHECKSUM_STRING
5525 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5526 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5527 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5528 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5529 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5530 #define CHECKSUM_ATTR(FOO) \
5531 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5533 /* Calculate the checksum of a number in signed LEB128 format. */
5536 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5543 byte
= (value
& 0x7f);
5545 more
= !((value
== 0 && (byte
& 0x40) == 0)
5546 || (value
== -1 && (byte
& 0x40) != 0));
5555 /* Calculate the checksum of a number in unsigned LEB128 format. */
5558 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5562 unsigned char byte
= (value
& 0x7f);
5565 /* More bytes to follow. */
5573 /* Checksum the context of the DIE. This adds the names of any
5574 surrounding namespaces or structures to the checksum. */
5577 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5581 int tag
= die
->die_tag
;
5583 if (tag
!= DW_TAG_namespace
5584 && tag
!= DW_TAG_structure_type
5585 && tag
!= DW_TAG_class_type
)
5588 name
= get_AT_string (die
, DW_AT_name
);
5590 spec
= get_AT_ref (die
, DW_AT_specification
);
5594 if (die
->die_parent
!= NULL
)
5595 checksum_die_context (die
->die_parent
, ctx
);
5597 CHECKSUM_ULEB128 ('C');
5598 CHECKSUM_ULEB128 (tag
);
5600 CHECKSUM_STRING (name
);
5603 /* Calculate the checksum of a location expression. */
5606 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5608 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5609 were emitted as a DW_FORM_sdata instead of a location expression. */
5610 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5612 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5613 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5617 /* Otherwise, just checksum the raw location expression. */
5620 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5621 CHECKSUM (loc
->dw_loc_oprnd1
);
5622 CHECKSUM (loc
->dw_loc_oprnd2
);
5623 loc
= loc
->dw_loc_next
;
5627 /* Calculate the checksum of an attribute. */
5630 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5631 struct md5_ctx
*ctx
, int *mark
)
5633 dw_loc_descr_ref loc
;
5636 if (AT_class (at
) == dw_val_class_die_ref
)
5638 dw_die_ref target_die
= AT_ref (at
);
5640 /* For pointer and reference types, we checksum only the (qualified)
5641 name of the target type (if there is a name). For friend entries,
5642 we checksum only the (qualified) name of the target type or function.
5643 This allows the checksum to remain the same whether the target type
5644 is complete or not. */
5645 if ((at
->dw_attr
== DW_AT_type
5646 && (tag
== DW_TAG_pointer_type
5647 || tag
== DW_TAG_reference_type
5648 || tag
== DW_TAG_rvalue_reference_type
5649 || tag
== DW_TAG_ptr_to_member_type
))
5650 || (at
->dw_attr
== DW_AT_friend
5651 && tag
== DW_TAG_friend
))
5653 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5655 if (name_attr
!= NULL
)
5657 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5661 CHECKSUM_ULEB128 ('N');
5662 CHECKSUM_ULEB128 (at
->dw_attr
);
5663 if (decl
->die_parent
!= NULL
)
5664 checksum_die_context (decl
->die_parent
, ctx
);
5665 CHECKSUM_ULEB128 ('E');
5666 CHECKSUM_STRING (AT_string (name_attr
));
5671 /* For all other references to another DIE, we check to see if the
5672 target DIE has already been visited. If it has, we emit a
5673 backward reference; if not, we descend recursively. */
5674 if (target_die
->die_mark
> 0)
5676 CHECKSUM_ULEB128 ('R');
5677 CHECKSUM_ULEB128 (at
->dw_attr
);
5678 CHECKSUM_ULEB128 (target_die
->die_mark
);
5682 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5686 target_die
->die_mark
= ++(*mark
);
5687 CHECKSUM_ULEB128 ('T');
5688 CHECKSUM_ULEB128 (at
->dw_attr
);
5689 if (decl
->die_parent
!= NULL
)
5690 checksum_die_context (decl
->die_parent
, ctx
);
5691 die_checksum_ordered (target_die
, ctx
, mark
);
5696 CHECKSUM_ULEB128 ('A');
5697 CHECKSUM_ULEB128 (at
->dw_attr
);
5699 switch (AT_class (at
))
5701 case dw_val_class_const
:
5702 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5703 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5706 case dw_val_class_unsigned_const
:
5707 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5708 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5711 case dw_val_class_const_double
:
5712 CHECKSUM_ULEB128 (DW_FORM_block
);
5713 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5714 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5717 case dw_val_class_vec
:
5718 CHECKSUM_ULEB128 (DW_FORM_block
);
5719 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
5720 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5723 case dw_val_class_flag
:
5724 CHECKSUM_ULEB128 (DW_FORM_flag
);
5725 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5728 case dw_val_class_str
:
5729 CHECKSUM_ULEB128 (DW_FORM_string
);
5730 CHECKSUM_STRING (AT_string (at
));
5733 case dw_val_class_addr
:
5735 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5736 CHECKSUM_ULEB128 (DW_FORM_string
);
5737 CHECKSUM_STRING (XSTR (r
, 0));
5740 case dw_val_class_offset
:
5741 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5742 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5745 case dw_val_class_loc
:
5746 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5747 loc_checksum_ordered (loc
, ctx
);
5750 case dw_val_class_fde_ref
:
5751 case dw_val_class_lbl_id
:
5752 case dw_val_class_lineptr
:
5753 case dw_val_class_macptr
:
5754 case dw_val_class_high_pc
:
5757 case dw_val_class_file
:
5758 CHECKSUM_ULEB128 (DW_FORM_string
);
5759 CHECKSUM_STRING (AT_file (at
)->filename
);
5762 case dw_val_class_data8
:
5763 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5771 struct checksum_attributes
5773 dw_attr_ref at_name
;
5774 dw_attr_ref at_type
;
5775 dw_attr_ref at_friend
;
5776 dw_attr_ref at_accessibility
;
5777 dw_attr_ref at_address_class
;
5778 dw_attr_ref at_allocated
;
5779 dw_attr_ref at_artificial
;
5780 dw_attr_ref at_associated
;
5781 dw_attr_ref at_binary_scale
;
5782 dw_attr_ref at_bit_offset
;
5783 dw_attr_ref at_bit_size
;
5784 dw_attr_ref at_bit_stride
;
5785 dw_attr_ref at_byte_size
;
5786 dw_attr_ref at_byte_stride
;
5787 dw_attr_ref at_const_value
;
5788 dw_attr_ref at_containing_type
;
5789 dw_attr_ref at_count
;
5790 dw_attr_ref at_data_location
;
5791 dw_attr_ref at_data_member_location
;
5792 dw_attr_ref at_decimal_scale
;
5793 dw_attr_ref at_decimal_sign
;
5794 dw_attr_ref at_default_value
;
5795 dw_attr_ref at_digit_count
;
5796 dw_attr_ref at_discr
;
5797 dw_attr_ref at_discr_list
;
5798 dw_attr_ref at_discr_value
;
5799 dw_attr_ref at_encoding
;
5800 dw_attr_ref at_endianity
;
5801 dw_attr_ref at_explicit
;
5802 dw_attr_ref at_is_optional
;
5803 dw_attr_ref at_location
;
5804 dw_attr_ref at_lower_bound
;
5805 dw_attr_ref at_mutable
;
5806 dw_attr_ref at_ordering
;
5807 dw_attr_ref at_picture_string
;
5808 dw_attr_ref at_prototyped
;
5809 dw_attr_ref at_small
;
5810 dw_attr_ref at_segment
;
5811 dw_attr_ref at_string_length
;
5812 dw_attr_ref at_threads_scaled
;
5813 dw_attr_ref at_upper_bound
;
5814 dw_attr_ref at_use_location
;
5815 dw_attr_ref at_use_UTF8
;
5816 dw_attr_ref at_variable_parameter
;
5817 dw_attr_ref at_virtuality
;
5818 dw_attr_ref at_visibility
;
5819 dw_attr_ref at_vtable_elem_location
;
5822 /* Collect the attributes that we will want to use for the checksum. */
5825 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5830 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5841 attrs
->at_friend
= a
;
5843 case DW_AT_accessibility
:
5844 attrs
->at_accessibility
= a
;
5846 case DW_AT_address_class
:
5847 attrs
->at_address_class
= a
;
5849 case DW_AT_allocated
:
5850 attrs
->at_allocated
= a
;
5852 case DW_AT_artificial
:
5853 attrs
->at_artificial
= a
;
5855 case DW_AT_associated
:
5856 attrs
->at_associated
= a
;
5858 case DW_AT_binary_scale
:
5859 attrs
->at_binary_scale
= a
;
5861 case DW_AT_bit_offset
:
5862 attrs
->at_bit_offset
= a
;
5864 case DW_AT_bit_size
:
5865 attrs
->at_bit_size
= a
;
5867 case DW_AT_bit_stride
:
5868 attrs
->at_bit_stride
= a
;
5870 case DW_AT_byte_size
:
5871 attrs
->at_byte_size
= a
;
5873 case DW_AT_byte_stride
:
5874 attrs
->at_byte_stride
= a
;
5876 case DW_AT_const_value
:
5877 attrs
->at_const_value
= a
;
5879 case DW_AT_containing_type
:
5880 attrs
->at_containing_type
= a
;
5883 attrs
->at_count
= a
;
5885 case DW_AT_data_location
:
5886 attrs
->at_data_location
= a
;
5888 case DW_AT_data_member_location
:
5889 attrs
->at_data_member_location
= a
;
5891 case DW_AT_decimal_scale
:
5892 attrs
->at_decimal_scale
= a
;
5894 case DW_AT_decimal_sign
:
5895 attrs
->at_decimal_sign
= a
;
5897 case DW_AT_default_value
:
5898 attrs
->at_default_value
= a
;
5900 case DW_AT_digit_count
:
5901 attrs
->at_digit_count
= a
;
5904 attrs
->at_discr
= a
;
5906 case DW_AT_discr_list
:
5907 attrs
->at_discr_list
= a
;
5909 case DW_AT_discr_value
:
5910 attrs
->at_discr_value
= a
;
5912 case DW_AT_encoding
:
5913 attrs
->at_encoding
= a
;
5915 case DW_AT_endianity
:
5916 attrs
->at_endianity
= a
;
5918 case DW_AT_explicit
:
5919 attrs
->at_explicit
= a
;
5921 case DW_AT_is_optional
:
5922 attrs
->at_is_optional
= a
;
5924 case DW_AT_location
:
5925 attrs
->at_location
= a
;
5927 case DW_AT_lower_bound
:
5928 attrs
->at_lower_bound
= a
;
5931 attrs
->at_mutable
= a
;
5933 case DW_AT_ordering
:
5934 attrs
->at_ordering
= a
;
5936 case DW_AT_picture_string
:
5937 attrs
->at_picture_string
= a
;
5939 case DW_AT_prototyped
:
5940 attrs
->at_prototyped
= a
;
5943 attrs
->at_small
= a
;
5946 attrs
->at_segment
= a
;
5948 case DW_AT_string_length
:
5949 attrs
->at_string_length
= a
;
5951 case DW_AT_threads_scaled
:
5952 attrs
->at_threads_scaled
= a
;
5954 case DW_AT_upper_bound
:
5955 attrs
->at_upper_bound
= a
;
5957 case DW_AT_use_location
:
5958 attrs
->at_use_location
= a
;
5960 case DW_AT_use_UTF8
:
5961 attrs
->at_use_UTF8
= a
;
5963 case DW_AT_variable_parameter
:
5964 attrs
->at_variable_parameter
= a
;
5966 case DW_AT_virtuality
:
5967 attrs
->at_virtuality
= a
;
5969 case DW_AT_visibility
:
5970 attrs
->at_visibility
= a
;
5972 case DW_AT_vtable_elem_location
:
5973 attrs
->at_vtable_elem_location
= a
;
5981 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
5984 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5988 struct checksum_attributes attrs
;
5990 CHECKSUM_ULEB128 ('D');
5991 CHECKSUM_ULEB128 (die
->die_tag
);
5993 memset (&attrs
, 0, sizeof (attrs
));
5995 decl
= get_AT_ref (die
, DW_AT_specification
);
5997 collect_checksum_attributes (&attrs
, decl
);
5998 collect_checksum_attributes (&attrs
, die
);
6000 CHECKSUM_ATTR (attrs
.at_name
);
6001 CHECKSUM_ATTR (attrs
.at_accessibility
);
6002 CHECKSUM_ATTR (attrs
.at_address_class
);
6003 CHECKSUM_ATTR (attrs
.at_allocated
);
6004 CHECKSUM_ATTR (attrs
.at_artificial
);
6005 CHECKSUM_ATTR (attrs
.at_associated
);
6006 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6007 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6008 CHECKSUM_ATTR (attrs
.at_bit_size
);
6009 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6010 CHECKSUM_ATTR (attrs
.at_byte_size
);
6011 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6012 CHECKSUM_ATTR (attrs
.at_const_value
);
6013 CHECKSUM_ATTR (attrs
.at_containing_type
);
6014 CHECKSUM_ATTR (attrs
.at_count
);
6015 CHECKSUM_ATTR (attrs
.at_data_location
);
6016 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6017 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6018 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6019 CHECKSUM_ATTR (attrs
.at_default_value
);
6020 CHECKSUM_ATTR (attrs
.at_digit_count
);
6021 CHECKSUM_ATTR (attrs
.at_discr
);
6022 CHECKSUM_ATTR (attrs
.at_discr_list
);
6023 CHECKSUM_ATTR (attrs
.at_discr_value
);
6024 CHECKSUM_ATTR (attrs
.at_encoding
);
6025 CHECKSUM_ATTR (attrs
.at_endianity
);
6026 CHECKSUM_ATTR (attrs
.at_explicit
);
6027 CHECKSUM_ATTR (attrs
.at_is_optional
);
6028 CHECKSUM_ATTR (attrs
.at_location
);
6029 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6030 CHECKSUM_ATTR (attrs
.at_mutable
);
6031 CHECKSUM_ATTR (attrs
.at_ordering
);
6032 CHECKSUM_ATTR (attrs
.at_picture_string
);
6033 CHECKSUM_ATTR (attrs
.at_prototyped
);
6034 CHECKSUM_ATTR (attrs
.at_small
);
6035 CHECKSUM_ATTR (attrs
.at_segment
);
6036 CHECKSUM_ATTR (attrs
.at_string_length
);
6037 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6038 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6039 CHECKSUM_ATTR (attrs
.at_use_location
);
6040 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6041 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6042 CHECKSUM_ATTR (attrs
.at_virtuality
);
6043 CHECKSUM_ATTR (attrs
.at_visibility
);
6044 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6045 CHECKSUM_ATTR (attrs
.at_type
);
6046 CHECKSUM_ATTR (attrs
.at_friend
);
6048 /* Checksum the child DIEs, except for nested types and member functions. */
6051 dw_attr_ref name_attr
;
6054 name_attr
= get_AT (c
, DW_AT_name
);
6055 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
6056 && name_attr
!= NULL
)
6058 CHECKSUM_ULEB128 ('S');
6059 CHECKSUM_ULEB128 (c
->die_tag
);
6060 CHECKSUM_STRING (AT_string (name_attr
));
6064 /* Mark this DIE so it gets processed when unmarking. */
6065 if (c
->die_mark
== 0)
6067 die_checksum_ordered (c
, ctx
, mark
);
6069 } while (c
!= die
->die_child
);
6071 CHECKSUM_ULEB128 (0);
6075 #undef CHECKSUM_STRING
6076 #undef CHECKSUM_ATTR
6077 #undef CHECKSUM_LEB128
6078 #undef CHECKSUM_ULEB128
6080 /* Generate the type signature for DIE. This is computed by generating an
6081 MD5 checksum over the DIE's tag, its relevant attributes, and its
6082 children. Attributes that are references to other DIEs are processed
6083 by recursion, using the MARK field to prevent infinite recursion.
6084 If the DIE is nested inside a namespace or another type, we also
6085 need to include that context in the signature. The lower 64 bits
6086 of the resulting MD5 checksum comprise the signature. */
6089 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6093 unsigned char checksum
[16];
6098 name
= get_AT_string (die
, DW_AT_name
);
6099 decl
= get_AT_ref (die
, DW_AT_specification
);
6100 parent
= get_die_parent (die
);
6102 /* First, compute a signature for just the type name (and its surrounding
6103 context, if any. This is stored in the type unit DIE for link-time
6104 ODR (one-definition rule) checking. */
6106 if (is_cxx() && name
!= NULL
)
6108 md5_init_ctx (&ctx
);
6110 /* Checksum the names of surrounding namespaces and structures. */
6112 checksum_die_context (parent
, &ctx
);
6114 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
6115 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
6116 md5_finish_ctx (&ctx
, checksum
);
6118 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6121 /* Next, compute the complete type signature. */
6123 md5_init_ctx (&ctx
);
6125 die
->die_mark
= mark
;
6127 /* Checksum the names of surrounding namespaces and structures. */
6129 checksum_die_context (parent
, &ctx
);
6131 /* Checksum the DIE and its children. */
6132 die_checksum_ordered (die
, &ctx
, &mark
);
6133 unmark_all_dies (die
);
6134 md5_finish_ctx (&ctx
, checksum
);
6136 /* Store the signature in the type node and link the type DIE and the
6137 type node together. */
6138 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6139 DWARF_TYPE_SIGNATURE_SIZE
);
6140 die
->comdat_type_p
= true;
6141 die
->die_id
.die_type_node
= type_node
;
6142 type_node
->type_die
= die
;
6144 /* If the DIE is a specification, link its declaration to the type node
6148 decl
->comdat_type_p
= true;
6149 decl
->die_id
.die_type_node
= type_node
;
6153 /* Do the location expressions look same? */
6155 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6157 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6158 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6159 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6162 /* Do the values look the same? */
6164 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6166 dw_loc_descr_ref loc1
, loc2
;
6169 if (v1
->val_class
!= v2
->val_class
)
6172 switch (v1
->val_class
)
6174 case dw_val_class_const
:
6175 return v1
->v
.val_int
== v2
->v
.val_int
;
6176 case dw_val_class_unsigned_const
:
6177 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6178 case dw_val_class_const_double
:
6179 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6180 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6181 case dw_val_class_vec
:
6182 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6183 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6185 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6186 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6189 case dw_val_class_flag
:
6190 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6191 case dw_val_class_str
:
6192 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6194 case dw_val_class_addr
:
6195 r1
= v1
->v
.val_addr
;
6196 r2
= v2
->v
.val_addr
;
6197 if (GET_CODE (r1
) != GET_CODE (r2
))
6199 return !rtx_equal_p (r1
, r2
);
6201 case dw_val_class_offset
:
6202 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6204 case dw_val_class_loc
:
6205 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6207 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6208 if (!same_loc_p (loc1
, loc2
, mark
))
6210 return !loc1
&& !loc2
;
6212 case dw_val_class_die_ref
:
6213 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6215 case dw_val_class_fde_ref
:
6216 case dw_val_class_vms_delta
:
6217 case dw_val_class_lbl_id
:
6218 case dw_val_class_lineptr
:
6219 case dw_val_class_macptr
:
6220 case dw_val_class_high_pc
:
6223 case dw_val_class_file
:
6224 return v1
->v
.val_file
== v2
->v
.val_file
;
6226 case dw_val_class_data8
:
6227 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6234 /* Do the attributes look the same? */
6237 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6239 if (at1
->dw_attr
!= at2
->dw_attr
)
6242 /* We don't care that this was compiled with a different compiler
6243 snapshot; if the output is the same, that's what matters. */
6244 if (at1
->dw_attr
== DW_AT_producer
)
6247 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6250 /* Do the dies look the same? */
6253 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6259 /* To avoid infinite recursion. */
6261 return die1
->die_mark
== die2
->die_mark
;
6262 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6264 if (die1
->die_tag
!= die2
->die_tag
)
6267 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6270 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6271 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6274 c1
= die1
->die_child
;
6275 c2
= die2
->die_child
;
6284 if (!same_die_p (c1
, c2
, mark
))
6288 if (c1
== die1
->die_child
)
6290 if (c2
== die2
->die_child
)
6300 /* Do the dies look the same? Wrapper around same_die_p. */
6303 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6306 int ret
= same_die_p (die1
, die2
, &mark
);
6308 unmark_all_dies (die1
);
6309 unmark_all_dies (die2
);
6314 /* The prefix to attach to symbols on DIEs in the current comdat debug
6316 static const char *comdat_symbol_id
;
6318 /* The index of the current symbol within the current comdat CU. */
6319 static unsigned int comdat_symbol_number
;
6321 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6322 children, and set comdat_symbol_id accordingly. */
6325 compute_section_prefix (dw_die_ref unit_die
)
6327 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6328 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6329 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6332 unsigned char checksum
[16];
6335 /* Compute the checksum of the DIE, then append part of it as hex digits to
6336 the name filename of the unit. */
6338 md5_init_ctx (&ctx
);
6340 die_checksum (unit_die
, &ctx
, &mark
);
6341 unmark_all_dies (unit_die
);
6342 md5_finish_ctx (&ctx
, checksum
);
6344 sprintf (name
, "%s.", base
);
6345 clean_symbol_name (name
);
6347 p
= name
+ strlen (name
);
6348 for (i
= 0; i
< 4; i
++)
6350 sprintf (p
, "%.2x", checksum
[i
]);
6354 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6355 comdat_symbol_number
= 0;
6358 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6361 is_type_die (dw_die_ref die
)
6363 switch (die
->die_tag
)
6365 case DW_TAG_array_type
:
6366 case DW_TAG_class_type
:
6367 case DW_TAG_interface_type
:
6368 case DW_TAG_enumeration_type
:
6369 case DW_TAG_pointer_type
:
6370 case DW_TAG_reference_type
:
6371 case DW_TAG_rvalue_reference_type
:
6372 case DW_TAG_string_type
:
6373 case DW_TAG_structure_type
:
6374 case DW_TAG_subroutine_type
:
6375 case DW_TAG_union_type
:
6376 case DW_TAG_ptr_to_member_type
:
6377 case DW_TAG_set_type
:
6378 case DW_TAG_subrange_type
:
6379 case DW_TAG_base_type
:
6380 case DW_TAG_const_type
:
6381 case DW_TAG_file_type
:
6382 case DW_TAG_packed_type
:
6383 case DW_TAG_volatile_type
:
6384 case DW_TAG_typedef
:
6391 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6392 Basically, we want to choose the bits that are likely to be shared between
6393 compilations (types) and leave out the bits that are specific to individual
6394 compilations (functions). */
6397 is_comdat_die (dw_die_ref c
)
6399 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6400 we do for stabs. The advantage is a greater likelihood of sharing between
6401 objects that don't include headers in the same order (and therefore would
6402 put the base types in a different comdat). jason 8/28/00 */
6404 if (c
->die_tag
== DW_TAG_base_type
)
6407 if (c
->die_tag
== DW_TAG_pointer_type
6408 || c
->die_tag
== DW_TAG_reference_type
6409 || c
->die_tag
== DW_TAG_rvalue_reference_type
6410 || c
->die_tag
== DW_TAG_const_type
6411 || c
->die_tag
== DW_TAG_volatile_type
)
6413 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6415 return t
? is_comdat_die (t
) : 0;
6418 return is_type_die (c
);
6421 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6422 compilation unit. */
6425 is_symbol_die (dw_die_ref c
)
6427 return (is_type_die (c
)
6428 || is_declaration_die (c
)
6429 || c
->die_tag
== DW_TAG_namespace
6430 || c
->die_tag
== DW_TAG_module
);
6433 /* Returns true iff C is a compile-unit DIE. */
6436 is_cu_die (dw_die_ref c
)
6438 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6441 /* Returns true iff C is a unit DIE of some sort. */
6444 is_unit_die (dw_die_ref c
)
6446 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6447 || c
->die_tag
== DW_TAG_partial_unit
6448 || c
->die_tag
== DW_TAG_type_unit
);
6451 /* Returns true iff C is a namespace DIE. */
6454 is_namespace_die (dw_die_ref c
)
6456 return c
&& c
->die_tag
== DW_TAG_namespace
;
6459 /* Returns true iff C is a class or structure DIE. */
6462 is_class_die (dw_die_ref c
)
6464 return c
&& (c
->die_tag
== DW_TAG_class_type
6465 || c
->die_tag
== DW_TAG_structure_type
);
6469 gen_internal_sym (const char *prefix
)
6473 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6474 return xstrdup (buf
);
6477 /* Assign symbols to all worthy DIEs under DIE. */
6480 assign_symbol_names (dw_die_ref die
)
6484 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6486 if (comdat_symbol_id
)
6488 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6490 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6491 comdat_symbol_id
, comdat_symbol_number
++);
6492 die
->die_id
.die_symbol
= xstrdup (p
);
6495 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6498 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6501 struct cu_hash_table_entry
6504 unsigned min_comdat_num
, max_comdat_num
;
6505 struct cu_hash_table_entry
*next
;
6508 /* Routines to manipulate hash table of CUs. */
6510 htab_cu_hash (const void *of
)
6512 const struct cu_hash_table_entry
*const entry
=
6513 (const struct cu_hash_table_entry
*) of
;
6515 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6519 htab_cu_eq (const void *of1
, const void *of2
)
6521 const struct cu_hash_table_entry
*const entry1
=
6522 (const struct cu_hash_table_entry
*) of1
;
6523 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6525 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6529 htab_cu_del (void *what
)
6531 struct cu_hash_table_entry
*next
,
6532 *entry
= (struct cu_hash_table_entry
*) what
;
6542 /* Check whether we have already seen this CU and set up SYM_NUM
6545 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6547 struct cu_hash_table_entry dummy
;
6548 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6550 dummy
.max_comdat_num
= 0;
6552 slot
= (struct cu_hash_table_entry
**)
6553 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6557 for (; entry
; last
= entry
, entry
= entry
->next
)
6559 if (same_die_p_wrap (cu
, entry
->cu
))
6565 *sym_num
= entry
->min_comdat_num
;
6569 entry
= XCNEW (struct cu_hash_table_entry
);
6571 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6572 entry
->next
= *slot
;
6578 /* Record SYM_NUM to record of CU in HTABLE. */
6580 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6582 struct cu_hash_table_entry
**slot
, *entry
;
6584 slot
= (struct cu_hash_table_entry
**)
6585 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6589 entry
->max_comdat_num
= sym_num
;
6592 /* Traverse the DIE (which is always comp_unit_die), and set up
6593 additional compilation units for each of the include files we see
6594 bracketed by BINCL/EINCL. */
6597 break_out_includes (dw_die_ref die
)
6600 dw_die_ref unit
= NULL
;
6601 limbo_die_node
*node
, **pnode
;
6602 htab_t cu_hash_table
;
6606 dw_die_ref prev
= c
;
6608 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6609 || (unit
&& is_comdat_die (c
)))
6611 dw_die_ref next
= c
->die_sib
;
6613 /* This DIE is for a secondary CU; remove it from the main one. */
6614 remove_child_with_prev (c
, prev
);
6616 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6617 unit
= push_new_compile_unit (unit
, c
);
6618 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6619 unit
= pop_compile_unit (unit
);
6621 add_child_die (unit
, c
);
6623 if (c
== die
->die_child
)
6626 } while (c
!= die
->die_child
);
6629 /* We can only use this in debugging, since the frontend doesn't check
6630 to make sure that we leave every include file we enter. */
6634 assign_symbol_names (die
);
6635 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6636 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6642 compute_section_prefix (node
->die
);
6643 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6644 &comdat_symbol_number
);
6645 assign_symbol_names (node
->die
);
6647 *pnode
= node
->next
;
6650 pnode
= &node
->next
;
6651 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6652 comdat_symbol_number
);
6655 htab_delete (cu_hash_table
);
6658 /* Return non-zero if this DIE is a declaration. */
6661 is_declaration_die (dw_die_ref die
)
6666 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6667 if (a
->dw_attr
== DW_AT_declaration
)
6673 /* Return non-zero if this DIE is nested inside a subprogram. */
6676 is_nested_in_subprogram (dw_die_ref die
)
6678 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6682 return local_scope_p (decl
);
6685 /* Return non-zero if this DIE contains a defining declaration of a
6689 contains_subprogram_definition (dw_die_ref die
)
6693 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6695 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6699 /* Return non-zero if this is a type DIE that should be moved to a
6700 COMDAT .debug_types section. */
6703 should_move_die_to_comdat (dw_die_ref die
)
6705 switch (die
->die_tag
)
6707 case DW_TAG_class_type
:
6708 case DW_TAG_structure_type
:
6709 case DW_TAG_enumeration_type
:
6710 case DW_TAG_union_type
:
6711 /* Don't move declarations, inlined instances, or types nested in a
6713 if (is_declaration_die (die
)
6714 || get_AT (die
, DW_AT_abstract_origin
)
6715 || is_nested_in_subprogram (die
))
6717 /* A type definition should never contain a subprogram definition. */
6718 gcc_assert (!contains_subprogram_definition (die
));
6720 case DW_TAG_array_type
:
6721 case DW_TAG_interface_type
:
6722 case DW_TAG_pointer_type
:
6723 case DW_TAG_reference_type
:
6724 case DW_TAG_rvalue_reference_type
:
6725 case DW_TAG_string_type
:
6726 case DW_TAG_subroutine_type
:
6727 case DW_TAG_ptr_to_member_type
:
6728 case DW_TAG_set_type
:
6729 case DW_TAG_subrange_type
:
6730 case DW_TAG_base_type
:
6731 case DW_TAG_const_type
:
6732 case DW_TAG_file_type
:
6733 case DW_TAG_packed_type
:
6734 case DW_TAG_volatile_type
:
6735 case DW_TAG_typedef
:
6741 /* Make a clone of DIE. */
6744 clone_die (dw_die_ref die
)
6750 clone
= ggc_alloc_cleared_die_node ();
6751 clone
->die_tag
= die
->die_tag
;
6753 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6754 add_dwarf_attr (clone
, a
);
6759 /* Make a clone of the tree rooted at DIE. */
6762 clone_tree (dw_die_ref die
)
6765 dw_die_ref clone
= clone_die (die
);
6767 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
6772 /* Make a clone of DIE as a declaration. */
6775 clone_as_declaration (dw_die_ref die
)
6782 /* If the DIE is already a declaration, just clone it. */
6783 if (is_declaration_die (die
))
6784 return clone_die (die
);
6786 /* If the DIE is a specification, just clone its declaration DIE. */
6787 decl
= get_AT_ref (die
, DW_AT_specification
);
6790 clone
= clone_die (decl
);
6791 if (die
->comdat_type_p
)
6792 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6796 clone
= ggc_alloc_cleared_die_node ();
6797 clone
->die_tag
= die
->die_tag
;
6799 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6801 /* We don't want to copy over all attributes.
6802 For example we don't want DW_AT_byte_size because otherwise we will no
6803 longer have a declaration and GDB will treat it as a definition. */
6807 case DW_AT_artificial
:
6808 case DW_AT_containing_type
:
6809 case DW_AT_external
:
6812 case DW_AT_virtuality
:
6813 case DW_AT_linkage_name
:
6814 case DW_AT_MIPS_linkage_name
:
6815 add_dwarf_attr (clone
, a
);
6817 case DW_AT_byte_size
:
6823 if (die
->comdat_type_p
)
6824 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6826 add_AT_flag (clone
, DW_AT_declaration
, 1);
6830 /* Copy the declaration context to the new type unit DIE. This includes
6831 any surrounding namespace or type declarations. If the DIE has an
6832 AT_specification attribute, it also includes attributes and children
6833 attached to the specification, and returns a pointer to the original
6834 parent of the declaration DIE. Returns NULL otherwise. */
6837 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
6840 dw_die_ref new_decl
;
6841 dw_die_ref orig_parent
= NULL
;
6843 decl
= get_AT_ref (die
, DW_AT_specification
);
6852 /* The original DIE will be changed to a declaration, and must
6853 be moved to be a child of the original declaration DIE. */
6854 orig_parent
= decl
->die_parent
;
6856 /* Copy the type node pointer from the new DIE to the original
6857 declaration DIE so we can forward references later. */
6858 decl
->comdat_type_p
= true;
6859 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
6861 remove_AT (die
, DW_AT_specification
);
6863 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
6865 if (a
->dw_attr
!= DW_AT_name
6866 && a
->dw_attr
!= DW_AT_declaration
6867 && a
->dw_attr
!= DW_AT_external
)
6868 add_dwarf_attr (die
, a
);
6871 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
6874 if (decl
->die_parent
!= NULL
6875 && !is_unit_die (decl
->die_parent
))
6877 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
6878 if (new_decl
!= NULL
)
6880 remove_AT (new_decl
, DW_AT_signature
);
6881 add_AT_specification (die
, new_decl
);
6888 /* Generate the skeleton ancestor tree for the given NODE, then clone
6889 the DIE and add the clone into the tree. */
6892 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
6894 if (node
->new_die
!= NULL
)
6897 node
->new_die
= clone_as_declaration (node
->old_die
);
6899 if (node
->parent
!= NULL
)
6901 generate_skeleton_ancestor_tree (node
->parent
);
6902 add_child_die (node
->parent
->new_die
, node
->new_die
);
6906 /* Generate a skeleton tree of DIEs containing any declarations that are
6907 found in the original tree. We traverse the tree looking for declaration
6908 DIEs, and construct the skeleton from the bottom up whenever we find one. */
6911 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
6913 skeleton_chain_node node
;
6916 dw_die_ref prev
= NULL
;
6917 dw_die_ref next
= NULL
;
6919 node
.parent
= parent
;
6921 first
= c
= parent
->old_die
->die_child
;
6925 if (prev
== NULL
|| prev
->die_sib
== c
)
6928 next
= (c
== first
? NULL
: c
->die_sib
);
6930 node
.new_die
= NULL
;
6931 if (is_declaration_die (c
))
6933 /* Clone the existing DIE, move the original to the skeleton
6934 tree (which is in the main CU), and put the clone, with
6935 all the original's children, where the original came from. */
6936 dw_die_ref clone
= clone_die (c
);
6937 move_all_children (c
, clone
);
6939 replace_child (c
, clone
, prev
);
6940 generate_skeleton_ancestor_tree (parent
);
6941 add_child_die (parent
->new_die
, c
);
6945 generate_skeleton_bottom_up (&node
);
6946 } while (next
!= NULL
);
6949 /* Wrapper function for generate_skeleton_bottom_up. */
6952 generate_skeleton (dw_die_ref die
)
6954 skeleton_chain_node node
;
6957 node
.new_die
= NULL
;
6960 /* If this type definition is nested inside another type,
6961 always leave at least a declaration in its place. */
6962 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
6963 node
.new_die
= clone_as_declaration (die
);
6965 generate_skeleton_bottom_up (&node
);
6966 return node
.new_die
;
6969 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
6970 declaration. The original DIE is moved to a new compile unit so that
6971 existing references to it follow it to the new location. If any of the
6972 original DIE's descendants is a declaration, we need to replace the
6973 original DIE with a skeleton tree and move the declarations back into the
6977 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
6980 dw_die_ref skeleton
, orig_parent
;
6982 /* Copy the declaration context to the type unit DIE. If the returned
6983 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
6985 orig_parent
= copy_declaration_context (unit
, child
);
6987 skeleton
= generate_skeleton (child
);
6988 if (skeleton
== NULL
)
6989 remove_child_with_prev (child
, prev
);
6992 skeleton
->comdat_type_p
= true;
6993 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
6995 /* If the original DIE was a specification, we need to put
6996 the skeleton under the parent DIE of the declaration.
6997 This leaves the original declaration in the tree, but
6998 it will be pruned later since there are no longer any
6999 references to it. */
7000 if (orig_parent
!= NULL
)
7002 remove_child_with_prev (child
, prev
);
7003 add_child_die (orig_parent
, skeleton
);
7006 replace_child (child
, skeleton
, prev
);
7012 /* Traverse the DIE and set up additional .debug_types sections for each
7013 type worthy of being placed in a COMDAT section. */
7016 break_out_comdat_types (dw_die_ref die
)
7020 dw_die_ref prev
= NULL
;
7021 dw_die_ref next
= NULL
;
7022 dw_die_ref unit
= NULL
;
7024 first
= c
= die
->die_child
;
7028 if (prev
== NULL
|| prev
->die_sib
== c
)
7031 next
= (c
== first
? NULL
: c
->die_sib
);
7032 if (should_move_die_to_comdat (c
))
7034 dw_die_ref replacement
;
7035 comdat_type_node_ref type_node
;
7037 /* Create a new type unit DIE as the root for the new tree, and
7038 add it to the list of comdat types. */
7039 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7040 add_AT_unsigned (unit
, DW_AT_language
,
7041 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7042 type_node
= ggc_alloc_cleared_comdat_type_node ();
7043 type_node
->root_die
= unit
;
7044 type_node
->next
= comdat_type_list
;
7045 comdat_type_list
= type_node
;
7047 /* Generate the type signature. */
7048 generate_type_signature (c
, type_node
);
7050 /* Copy the declaration context, attributes, and children of the
7051 declaration into the new type unit DIE, then remove this DIE
7052 from the main CU (or replace it with a skeleton if necessary). */
7053 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7054 type_node
->skeleton_die
= replacement
;
7056 /* Break out nested types into their own type units. */
7057 break_out_comdat_types (c
);
7059 /* Add the DIE to the new compunit. */
7060 add_child_die (unit
, c
);
7062 if (replacement
!= NULL
)
7065 else if (c
->die_tag
== DW_TAG_namespace
7066 || c
->die_tag
== DW_TAG_class_type
7067 || c
->die_tag
== DW_TAG_structure_type
7068 || c
->die_tag
== DW_TAG_union_type
)
7070 /* Look for nested types that can be broken out. */
7071 break_out_comdat_types (c
);
7073 } while (next
!= NULL
);
7076 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7078 struct decl_table_entry
7084 /* Routines to manipulate hash table of copied declarations. */
7087 htab_decl_hash (const void *of
)
7089 const struct decl_table_entry
*const entry
=
7090 (const struct decl_table_entry
*) of
;
7092 return htab_hash_pointer (entry
->orig
);
7096 htab_decl_eq (const void *of1
, const void *of2
)
7098 const struct decl_table_entry
*const entry1
=
7099 (const struct decl_table_entry
*) of1
;
7100 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
7102 return entry1
->orig
== entry2
;
7106 htab_decl_del (void *what
)
7108 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
7113 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7114 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7115 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7116 to check if the ancestor has already been copied into UNIT. */
7119 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7121 dw_die_ref parent
= die
->die_parent
;
7122 dw_die_ref new_parent
= unit
;
7125 struct decl_table_entry
*entry
= NULL
;
7129 /* Check if the entry has already been copied to UNIT. */
7130 slot
= htab_find_slot_with_hash (decl_table
, die
,
7131 htab_hash_pointer (die
), INSERT
);
7132 if (*slot
!= HTAB_EMPTY_ENTRY
)
7134 entry
= (struct decl_table_entry
*) *slot
;
7138 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7139 entry
= XCNEW (struct decl_table_entry
);
7147 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7150 if (!is_unit_die (parent
))
7151 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7154 copy
= clone_as_declaration (die
);
7155 add_child_die (new_parent
, copy
);
7157 if (decl_table
!= NULL
)
7159 /* Record the pointer to the copy. */
7166 /* Like clone_tree, but additionally enter all the children into
7167 the hash table decl_table. */
7170 clone_tree_hash (dw_die_ref die
, htab_t decl_table
)
7173 dw_die_ref clone
= clone_die (die
);
7174 struct decl_table_entry
*entry
;
7175 void **slot
= htab_find_slot_with_hash (decl_table
, die
,
7176 htab_hash_pointer (die
), INSERT
);
7177 /* Assert that DIE isn't in the hash table yet. If it would be there
7178 before, the ancestors would be necessarily there as well, therefore
7179 clone_tree_hash wouldn't be called. */
7180 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7181 entry
= XCNEW (struct decl_table_entry
);
7183 entry
->copy
= clone
;
7186 FOR_EACH_CHILD (die
, c
,
7187 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7192 /* Walk the DIE and its children, looking for references to incomplete
7193 or trivial types that are unmarked (i.e., that are not in the current
7197 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7203 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7205 if (AT_class (a
) == dw_val_class_die_ref
)
7207 dw_die_ref targ
= AT_ref (a
);
7209 struct decl_table_entry
*entry
;
7211 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7214 slot
= htab_find_slot_with_hash (decl_table
, targ
,
7215 htab_hash_pointer (targ
), INSERT
);
7217 if (*slot
!= HTAB_EMPTY_ENTRY
)
7219 /* TARG has already been copied, so we just need to
7220 modify the reference to point to the copy. */
7221 entry
= (struct decl_table_entry
*) *slot
;
7222 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7226 dw_die_ref parent
= unit
;
7227 dw_die_ref copy
= clone_die (targ
);
7229 /* Record in DECL_TABLE that TARG has been copied.
7230 Need to do this now, before the recursive call,
7231 because DECL_TABLE may be expanded and SLOT
7232 would no longer be a valid pointer. */
7233 entry
= XCNEW (struct decl_table_entry
);
7238 FOR_EACH_CHILD (targ
, c
,
7239 add_child_die (copy
,
7240 clone_tree_hash (c
, decl_table
)));
7242 /* Make sure the cloned tree is marked as part of the
7246 /* If TARG has surrounding context, copy its ancestor tree
7247 into the new type unit. */
7248 if (targ
->die_parent
!= NULL
7249 && !is_unit_die (targ
->die_parent
))
7250 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7253 add_child_die (parent
, copy
);
7254 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7256 /* Make sure the newly-copied DIE is walked. If it was
7257 installed in a previously-added context, it won't
7258 get visited otherwise. */
7261 /* Find the highest point of the newly-added tree,
7262 mark each node along the way, and walk from there. */
7263 parent
->die_mark
= 1;
7264 while (parent
->die_parent
7265 && parent
->die_parent
->die_mark
== 0)
7267 parent
= parent
->die_parent
;
7268 parent
->die_mark
= 1;
7270 copy_decls_walk (unit
, parent
, decl_table
);
7276 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7279 /* Copy declarations for "unworthy" types into the new comdat section.
7280 Incomplete types, modified types, and certain other types aren't broken
7281 out into comdat sections of their own, so they don't have a signature,
7282 and we need to copy the declaration into the same section so that we
7283 don't have an external reference. */
7286 copy_decls_for_unworthy_types (dw_die_ref unit
)
7291 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
7292 copy_decls_walk (unit
, unit
, decl_table
);
7293 htab_delete (decl_table
);
7297 /* Traverse the DIE and add a sibling attribute if it may have the
7298 effect of speeding up access to siblings. To save some space,
7299 avoid generating sibling attributes for DIE's without children. */
7302 add_sibling_attributes (dw_die_ref die
)
7306 if (! die
->die_child
)
7309 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7310 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7312 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7315 /* Output all location lists for the DIE and its children. */
7318 output_location_lists (dw_die_ref die
)
7324 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7325 if (AT_class (a
) == dw_val_class_loc_list
)
7326 output_loc_list (AT_loc_list (a
));
7328 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7331 /* We want to limit the number of external references, because they are
7332 larger than local references: a relocation takes multiple words, and
7333 even a sig8 reference is always eight bytes, whereas a local reference
7334 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7335 So if we encounter multiple external references to the same type DIE, we
7336 make a local typedef stub for it and redirect all references there.
7338 This is the element of the hash table for keeping track of these
7348 /* Hash an external_ref. */
7351 hash_external_ref (const void *p
)
7353 const struct external_ref
*r
= (const struct external_ref
*)p
;
7354 return htab_hash_pointer (r
->type
);
7357 /* Compare external_refs. */
7360 external_ref_eq (const void *p1
, const void *p2
)
7362 const struct external_ref
*r1
= (const struct external_ref
*)p1
;
7363 const struct external_ref
*r2
= (const struct external_ref
*)p2
;
7364 return r1
->type
== r2
->type
;
7367 /* Return a pointer to the external_ref for references to DIE. */
7369 static struct external_ref
*
7370 lookup_external_ref (htab_t map
, dw_die_ref die
)
7372 struct external_ref ref
, *ref_p
;
7376 slot
= htab_find_slot (map
, &ref
, INSERT
);
7377 if (*slot
!= HTAB_EMPTY_ENTRY
)
7378 return (struct external_ref
*) *slot
;
7380 ref_p
= XCNEW (struct external_ref
);
7386 /* Subroutine of optimize_external_refs, below.
7388 If we see a type skeleton, record it as our stub. If we see external
7389 references, remember how many we've seen. */
7392 optimize_external_refs_1 (dw_die_ref die
, htab_t map
)
7397 struct external_ref
*ref_p
;
7399 if (is_type_die (die
)
7400 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7402 /* This is a local skeleton; use it for local references. */
7403 ref_p
= lookup_external_ref (map
, c
);
7407 /* Scan the DIE references, and remember any that refer to DIEs from
7408 other CUs (i.e. those which are not marked). */
7409 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7410 if (AT_class (a
) == dw_val_class_die_ref
7411 && (c
= AT_ref (a
))->die_mark
== 0
7414 ref_p
= lookup_external_ref (map
, c
);
7418 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7421 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7422 points to an external_ref, DATA is the CU we're processing. If we don't
7423 already have a local stub, and we have multiple refs, build a stub. */
7426 build_local_stub (void **slot
, void *data
)
7428 struct external_ref
*ref_p
= (struct external_ref
*)*slot
;
7430 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7432 /* We have multiple references to this type, so build a small stub.
7433 Both of these forms are a bit dodgy from the perspective of the
7434 DWARF standard, since technically they should have names. */
7435 dw_die_ref cu
= (dw_die_ref
) data
;
7436 dw_die_ref type
= ref_p
->type
;
7437 dw_die_ref stub
= NULL
;
7439 if (type
->comdat_type_p
)
7441 /* If we refer to this type via sig8, use AT_signature. */
7442 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7443 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7447 /* Otherwise, use a typedef with no name. */
7448 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7449 add_AT_die_ref (stub
, DW_AT_type
, type
);
7458 /* DIE is a unit; look through all the DIE references to see if there are
7459 any external references to types, and if so, create local stubs for
7460 them which will be applied in build_abbrev_table. This is useful because
7461 references to local DIEs are smaller. */
7464 optimize_external_refs (dw_die_ref die
)
7466 htab_t map
= htab_create (10, hash_external_ref
, external_ref_eq
, free
);
7467 optimize_external_refs_1 (die
, map
);
7468 htab_traverse (map
, build_local_stub
, die
);
7472 /* The format of each DIE (and its attribute value pairs) is encoded in an
7473 abbreviation table. This routine builds the abbreviation table and assigns
7474 a unique abbreviation id for each abbreviation entry. The children of each
7475 die are visited recursively. */
7478 build_abbrev_table (dw_die_ref die
, htab_t extern_map
)
7480 unsigned long abbrev_id
;
7481 unsigned int n_alloc
;
7486 /* Scan the DIE references, and replace any that refer to
7487 DIEs from other CUs (i.e. those which are not marked) with
7488 the local stubs we built in optimize_external_refs. */
7489 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7490 if (AT_class (a
) == dw_val_class_die_ref
7491 && (c
= AT_ref (a
))->die_mark
== 0)
7493 struct external_ref
*ref_p
;
7494 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7496 ref_p
= lookup_external_ref (extern_map
, c
);
7497 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7498 change_AT_die_ref (a
, ref_p
->stub
);
7500 /* We aren't changing this reference, so mark it external. */
7501 set_AT_ref_external (a
, 1);
7504 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7506 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7507 dw_attr_ref die_a
, abbrev_a
;
7511 if (abbrev
->die_tag
!= die
->die_tag
)
7513 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7516 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7519 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7521 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7522 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7523 || (value_format (abbrev_a
) != value_format (die_a
)))
7533 if (abbrev_id
>= abbrev_die_table_in_use
)
7535 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7537 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7538 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7541 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7542 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7543 abbrev_die_table_allocated
= n_alloc
;
7546 ++abbrev_die_table_in_use
;
7547 abbrev_die_table
[abbrev_id
] = die
;
7550 die
->die_abbrev
= abbrev_id
;
7551 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7554 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7557 constant_size (unsigned HOST_WIDE_INT value
)
7564 log
= floor_log2 (value
);
7567 log
= 1 << (floor_log2 (log
) + 1);
7572 /* Return the size of a DIE as it is represented in the
7573 .debug_info section. */
7575 static unsigned long
7576 size_of_die (dw_die_ref die
)
7578 unsigned long size
= 0;
7581 enum dwarf_form form
;
7583 size
+= size_of_uleb128 (die
->die_abbrev
);
7584 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7586 switch (AT_class (a
))
7588 case dw_val_class_addr
:
7589 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7591 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7592 size
+= size_of_uleb128 (AT_index (a
));
7595 size
+= DWARF2_ADDR_SIZE
;
7597 case dw_val_class_offset
:
7598 size
+= DWARF_OFFSET_SIZE
;
7600 case dw_val_class_loc
:
7602 unsigned long lsize
= size_of_locs (AT_loc (a
));
7605 if (dwarf_version
>= 4)
7606 size
+= size_of_uleb128 (lsize
);
7608 size
+= constant_size (lsize
);
7612 case dw_val_class_loc_list
:
7613 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7615 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7616 size
+= size_of_uleb128 (AT_index (a
));
7619 size
+= DWARF_OFFSET_SIZE
;
7621 case dw_val_class_range_list
:
7622 size
+= DWARF_OFFSET_SIZE
;
7624 case dw_val_class_const
:
7625 size
+= size_of_sleb128 (AT_int (a
));
7627 case dw_val_class_unsigned_const
:
7629 int csize
= constant_size (AT_unsigned (a
));
7630 if (dwarf_version
== 3
7631 && a
->dw_attr
== DW_AT_data_member_location
7633 size
+= size_of_uleb128 (AT_unsigned (a
));
7638 case dw_val_class_const_double
:
7639 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7640 if (HOST_BITS_PER_WIDE_INT
>= 64)
7643 case dw_val_class_vec
:
7644 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7645 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7646 + a
->dw_attr_val
.v
.val_vec
.length
7647 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7649 case dw_val_class_flag
:
7650 if (dwarf_version
>= 4)
7651 /* Currently all add_AT_flag calls pass in 1 as last argument,
7652 so DW_FORM_flag_present can be used. If that ever changes,
7653 we'll need to use DW_FORM_flag and have some optimization
7654 in build_abbrev_table that will change those to
7655 DW_FORM_flag_present if it is set to 1 in all DIEs using
7656 the same abbrev entry. */
7657 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7661 case dw_val_class_die_ref
:
7662 if (AT_ref_external (a
))
7664 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7665 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7666 is sized by target address length, whereas in DWARF3
7667 it's always sized as an offset. */
7668 if (use_debug_types
)
7669 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7670 else if (dwarf_version
== 2)
7671 size
+= DWARF2_ADDR_SIZE
;
7673 size
+= DWARF_OFFSET_SIZE
;
7676 size
+= DWARF_OFFSET_SIZE
;
7678 case dw_val_class_fde_ref
:
7679 size
+= DWARF_OFFSET_SIZE
;
7681 case dw_val_class_lbl_id
:
7682 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7684 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7685 size
+= size_of_uleb128 (AT_index (a
));
7688 size
+= DWARF2_ADDR_SIZE
;
7690 case dw_val_class_lineptr
:
7691 case dw_val_class_macptr
:
7692 size
+= DWARF_OFFSET_SIZE
;
7694 case dw_val_class_str
:
7695 form
= AT_string_form (a
);
7696 if (form
== DW_FORM_strp
)
7697 size
+= DWARF_OFFSET_SIZE
;
7698 else if (form
== DW_FORM_GNU_str_index
)
7699 size
+= size_of_uleb128 (AT_index (a
));
7701 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7703 case dw_val_class_file
:
7704 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7706 case dw_val_class_data8
:
7709 case dw_val_class_vms_delta
:
7710 size
+= DWARF_OFFSET_SIZE
;
7712 case dw_val_class_high_pc
:
7713 size
+= DWARF2_ADDR_SIZE
;
7723 /* Size the debugging information associated with a given DIE. Visits the
7724 DIE's children recursively. Updates the global variable next_die_offset, on
7725 each time through. Uses the current value of next_die_offset to update the
7726 die_offset field in each DIE. */
7729 calc_die_sizes (dw_die_ref die
)
7733 gcc_assert (die
->die_offset
== 0
7734 || (unsigned long int) die
->die_offset
== next_die_offset
);
7735 die
->die_offset
= next_die_offset
;
7736 next_die_offset
+= size_of_die (die
);
7738 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7740 if (die
->die_child
!= NULL
)
7741 /* Count the null byte used to terminate sibling lists. */
7742 next_die_offset
+= 1;
7745 /* Size just the base type children at the start of the CU.
7746 This is needed because build_abbrev needs to size locs
7747 and sizing of type based stack ops needs to know die_offset
7748 values for the base types. */
7751 calc_base_type_die_sizes (void)
7753 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7755 dw_die_ref base_type
;
7756 #if ENABLE_ASSERT_CHECKING
7757 dw_die_ref prev
= comp_unit_die ()->die_child
;
7760 die_offset
+= size_of_die (comp_unit_die ());
7761 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7763 #if ENABLE_ASSERT_CHECKING
7764 gcc_assert (base_type
->die_offset
== 0
7765 && prev
->die_sib
== base_type
7766 && base_type
->die_child
== NULL
7767 && base_type
->die_abbrev
);
7770 base_type
->die_offset
= die_offset
;
7771 die_offset
+= size_of_die (base_type
);
7775 /* Set the marks for a die and its children. We do this so
7776 that we know whether or not a reference needs to use FORM_ref_addr; only
7777 DIEs in the same CU will be marked. We used to clear out the offset
7778 and use that as the flag, but ran into ordering problems. */
7781 mark_dies (dw_die_ref die
)
7785 gcc_assert (!die
->die_mark
);
7788 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7791 /* Clear the marks for a die and its children. */
7794 unmark_dies (dw_die_ref die
)
7798 if (! use_debug_types
)
7799 gcc_assert (die
->die_mark
);
7802 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7805 /* Clear the marks for a die, its children and referred dies. */
7808 unmark_all_dies (dw_die_ref die
)
7818 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7820 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7821 if (AT_class (a
) == dw_val_class_die_ref
)
7822 unmark_all_dies (AT_ref (a
));
7825 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7826 generated for the compilation unit. */
7828 static unsigned long
7829 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
7835 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7836 FOR_EACH_VEC_ELT (*names
, i
, p
)
7837 if (names
!= pubtype_table
7838 || p
->die
->die_offset
!= 0
7839 || !flag_eliminate_unused_debug_types
)
7840 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7842 size
+= DWARF_OFFSET_SIZE
;
7846 /* Return the size of the information in the .debug_aranges section. */
7848 static unsigned long
7849 size_of_aranges (void)
7853 size
= DWARF_ARANGES_HEADER_SIZE
;
7855 /* Count the address/length pair for this compilation unit. */
7856 if (text_section_used
)
7857 size
+= 2 * DWARF2_ADDR_SIZE
;
7858 if (cold_text_section_used
)
7859 size
+= 2 * DWARF2_ADDR_SIZE
;
7860 if (have_multiple_function_sections
)
7865 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
7867 if (DECL_IGNORED_P (fde
->decl
))
7869 if (!fde
->in_std_section
)
7870 size
+= 2 * DWARF2_ADDR_SIZE
;
7871 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
7872 size
+= 2 * DWARF2_ADDR_SIZE
;
7876 /* Count the two zero words used to terminated the address range table. */
7877 size
+= 2 * DWARF2_ADDR_SIZE
;
7881 /* Select the encoding of an attribute value. */
7883 static enum dwarf_form
7884 value_format (dw_attr_ref a
)
7886 switch (AT_class (a
))
7888 case dw_val_class_addr
:
7889 /* Only very few attributes allow DW_FORM_addr. */
7894 case DW_AT_entry_pc
:
7895 case DW_AT_trampoline
:
7896 return (AT_index (a
) == NOT_INDEXED
7897 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
7901 switch (DWARF2_ADDR_SIZE
)
7904 return DW_FORM_data1
;
7906 return DW_FORM_data2
;
7908 return DW_FORM_data4
;
7910 return DW_FORM_data8
;
7914 case dw_val_class_range_list
:
7915 case dw_val_class_loc_list
:
7916 if (dwarf_version
>= 4)
7917 return DW_FORM_sec_offset
;
7919 case dw_val_class_vms_delta
:
7920 case dw_val_class_offset
:
7921 switch (DWARF_OFFSET_SIZE
)
7924 return DW_FORM_data4
;
7926 return DW_FORM_data8
;
7930 case dw_val_class_loc
:
7931 if (dwarf_version
>= 4)
7932 return DW_FORM_exprloc
;
7933 switch (constant_size (size_of_locs (AT_loc (a
))))
7936 return DW_FORM_block1
;
7938 return DW_FORM_block2
;
7940 return DW_FORM_block4
;
7944 case dw_val_class_const
:
7945 return DW_FORM_sdata
;
7946 case dw_val_class_unsigned_const
:
7947 switch (constant_size (AT_unsigned (a
)))
7950 return DW_FORM_data1
;
7952 return DW_FORM_data2
;
7954 /* In DWARF3 DW_AT_data_member_location with
7955 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
7956 constant, so we need to use DW_FORM_udata if we need
7957 a large constant. */
7958 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7959 return DW_FORM_udata
;
7960 return DW_FORM_data4
;
7962 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7963 return DW_FORM_udata
;
7964 return DW_FORM_data8
;
7968 case dw_val_class_const_double
:
7969 switch (HOST_BITS_PER_WIDE_INT
)
7972 return DW_FORM_data2
;
7974 return DW_FORM_data4
;
7976 return DW_FORM_data8
;
7979 return DW_FORM_block1
;
7981 case dw_val_class_vec
:
7982 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
7983 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
7986 return DW_FORM_block1
;
7988 return DW_FORM_block2
;
7990 return DW_FORM_block4
;
7994 case dw_val_class_flag
:
7995 if (dwarf_version
>= 4)
7997 /* Currently all add_AT_flag calls pass in 1 as last argument,
7998 so DW_FORM_flag_present can be used. If that ever changes,
7999 we'll need to use DW_FORM_flag and have some optimization
8000 in build_abbrev_table that will change those to
8001 DW_FORM_flag_present if it is set to 1 in all DIEs using
8002 the same abbrev entry. */
8003 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8004 return DW_FORM_flag_present
;
8006 return DW_FORM_flag
;
8007 case dw_val_class_die_ref
:
8008 if (AT_ref_external (a
))
8009 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8012 case dw_val_class_fde_ref
:
8013 return DW_FORM_data
;
8014 case dw_val_class_lbl_id
:
8015 return (AT_index (a
) == NOT_INDEXED
8016 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8017 case dw_val_class_lineptr
:
8018 case dw_val_class_macptr
:
8019 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8020 case dw_val_class_str
:
8021 return AT_string_form (a
);
8022 case dw_val_class_file
:
8023 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8026 return DW_FORM_data1
;
8028 return DW_FORM_data2
;
8030 return DW_FORM_data4
;
8035 case dw_val_class_data8
:
8036 return DW_FORM_data8
;
8038 case dw_val_class_high_pc
:
8039 switch (DWARF2_ADDR_SIZE
)
8042 return DW_FORM_data1
;
8044 return DW_FORM_data2
;
8046 return DW_FORM_data4
;
8048 return DW_FORM_data8
;
8058 /* Output the encoding of an attribute value. */
8061 output_value_format (dw_attr_ref a
)
8063 enum dwarf_form form
= value_format (a
);
8065 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8068 /* Given a die and id, produce the appropriate abbreviations. */
8071 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8076 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8077 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8078 dwarf_tag_name (abbrev
->die_tag
));
8080 if (abbrev
->die_child
!= NULL
)
8081 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8083 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8085 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8087 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8088 dwarf_attr_name (a_attr
->dw_attr
));
8089 output_value_format (a_attr
);
8092 dw2_asm_output_data (1, 0, NULL
);
8093 dw2_asm_output_data (1, 0, NULL
);
8097 /* Output the .debug_abbrev section which defines the DIE abbreviation
8101 output_abbrev_section (void)
8103 unsigned long abbrev_id
;
8105 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8106 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8108 /* Terminate the table. */
8109 dw2_asm_output_data (1, 0, NULL
);
8112 /* Output a symbol we can use to refer to this DIE from another CU. */
8115 output_die_symbol (dw_die_ref die
)
8117 const char *sym
= die
->die_id
.die_symbol
;
8119 gcc_assert (!die
->comdat_type_p
);
8124 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8125 /* We make these global, not weak; if the target doesn't support
8126 .linkonce, it doesn't support combining the sections, so debugging
8128 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8130 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8133 /* Return a new location list, given the begin and end range, and the
8136 static inline dw_loc_list_ref
8137 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8138 const char *section
)
8140 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8142 retlist
->begin
= begin
;
8143 retlist
->begin_entry
= NULL
;
8145 retlist
->expr
= expr
;
8146 retlist
->section
= section
;
8151 /* Generate a new internal symbol for this location list node, if it
8152 hasn't got one yet. */
8155 gen_llsym (dw_loc_list_ref list
)
8157 gcc_assert (!list
->ll_symbol
);
8158 list
->ll_symbol
= gen_internal_sym ("LLST");
8161 /* Output the location list given to us. */
8164 output_loc_list (dw_loc_list_ref list_head
)
8166 dw_loc_list_ref curr
= list_head
;
8168 if (list_head
->emitted
)
8170 list_head
->emitted
= true;
8172 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8174 /* Walk the location list, and output each range + expression. */
8175 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8178 /* Don't output an entry that starts and ends at the same address. */
8179 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8181 size
= size_of_locs (curr
->expr
);
8182 /* If the expression is too large, drop it on the floor. We could
8183 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8184 in the expression, but >= 64KB expressions for a single value
8185 in a single range are unlikely very useful. */
8188 if (dwarf_split_debug_info
)
8190 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8191 "Location list start/length entry (%s)",
8192 list_head
->ll_symbol
);
8193 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8194 "Location list range start index (%s)",
8196 /* The length field is 4 bytes. If we ever need to support
8197 an 8-byte length, we can add a new DW_LLE code or fall back
8198 to DW_LLE_GNU_start_end_entry. */
8199 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8200 "Location list range length (%s)",
8201 list_head
->ll_symbol
);
8203 else if (!have_multiple_function_sections
)
8205 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8206 "Location list begin address (%s)",
8207 list_head
->ll_symbol
);
8208 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8209 "Location list end address (%s)",
8210 list_head
->ll_symbol
);
8214 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8215 "Location list begin address (%s)",
8216 list_head
->ll_symbol
);
8217 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8218 "Location list end address (%s)",
8219 list_head
->ll_symbol
);
8222 /* Output the block length for this list of location operations. */
8223 gcc_assert (size
<= 0xffff);
8224 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8226 output_loc_sequence (curr
->expr
, -1);
8229 if (dwarf_split_debug_info
)
8230 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8231 "Location list terminator (%s)",
8232 list_head
->ll_symbol
);
8235 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8236 "Location list terminator begin (%s)",
8237 list_head
->ll_symbol
);
8238 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8239 "Location list terminator end (%s)",
8240 list_head
->ll_symbol
);
8244 /* Output a range_list offset into the debug_range section. Emit a
8245 relocated reference if val_entry is NULL, otherwise, emit an
8246 indirect reference. */
8249 output_range_list_offset (dw_attr_ref a
)
8251 const char *name
= dwarf_attr_name (a
->dw_attr
);
8253 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8255 char *p
= strchr (ranges_section_label
, '\0');
8256 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8257 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8258 debug_ranges_section
, "%s", name
);
8262 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8263 "%s (offset from %s)", name
, ranges_section_label
);
8266 /* Output the offset into the debug_loc section. */
8269 output_loc_list_offset (dw_attr_ref a
)
8271 char *sym
= AT_loc_list (a
)->ll_symbol
;
8274 if (dwarf_split_debug_info
)
8275 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8276 "%s", dwarf_attr_name (a
->dw_attr
));
8278 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8279 "%s", dwarf_attr_name (a
->dw_attr
));
8282 /* Output an attribute's index or value appropriately. */
8285 output_attr_index_or_value (dw_attr_ref a
)
8287 const char *name
= dwarf_attr_name (a
->dw_attr
);
8289 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8291 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8294 switch (AT_class (a
))
8296 case dw_val_class_addr
:
8297 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8299 case dw_val_class_high_pc
:
8300 case dw_val_class_lbl_id
:
8301 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8303 case dw_val_class_loc_list
:
8304 output_loc_list_offset (a
);
8311 /* Output a type signature. */
8314 output_signature (const char *sig
, const char *name
)
8318 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8319 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8322 /* Output the DIE and its attributes. Called recursively to generate
8323 the definitions of each child DIE. */
8326 output_die (dw_die_ref die
)
8333 /* If someone in another CU might refer to us, set up a symbol for
8334 them to point to. */
8335 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8336 output_die_symbol (die
);
8338 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8339 (unsigned long)die
->die_offset
,
8340 dwarf_tag_name (die
->die_tag
));
8342 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8344 const char *name
= dwarf_attr_name (a
->dw_attr
);
8346 switch (AT_class (a
))
8348 case dw_val_class_addr
:
8349 output_attr_index_or_value (a
);
8352 case dw_val_class_offset
:
8353 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8357 case dw_val_class_range_list
:
8358 output_range_list_offset (a
);
8361 case dw_val_class_loc
:
8362 size
= size_of_locs (AT_loc (a
));
8364 /* Output the block length for this list of location operations. */
8365 if (dwarf_version
>= 4)
8366 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8368 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8370 output_loc_sequence (AT_loc (a
), -1);
8373 case dw_val_class_const
:
8374 /* ??? It would be slightly more efficient to use a scheme like is
8375 used for unsigned constants below, but gdb 4.x does not sign
8376 extend. Gdb 5.x does sign extend. */
8377 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8380 case dw_val_class_unsigned_const
:
8382 int csize
= constant_size (AT_unsigned (a
));
8383 if (dwarf_version
== 3
8384 && a
->dw_attr
== DW_AT_data_member_location
8386 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8388 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8392 case dw_val_class_const_double
:
8394 unsigned HOST_WIDE_INT first
, second
;
8396 if (HOST_BITS_PER_WIDE_INT
>= 64)
8397 dw2_asm_output_data (1,
8398 HOST_BITS_PER_DOUBLE_INT
8399 / HOST_BITS_PER_CHAR
,
8402 if (WORDS_BIG_ENDIAN
)
8404 first
= a
->dw_attr_val
.v
.val_double
.high
;
8405 second
= a
->dw_attr_val
.v
.val_double
.low
;
8409 first
= a
->dw_attr_val
.v
.val_double
.low
;
8410 second
= a
->dw_attr_val
.v
.val_double
.high
;
8413 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8415 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8420 case dw_val_class_vec
:
8422 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8423 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8427 dw2_asm_output_data (constant_size (len
* elt_size
),
8428 len
* elt_size
, "%s", name
);
8429 if (elt_size
> sizeof (HOST_WIDE_INT
))
8434 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8437 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8438 "fp or vector constant word %u", i
);
8442 case dw_val_class_flag
:
8443 if (dwarf_version
>= 4)
8445 /* Currently all add_AT_flag calls pass in 1 as last argument,
8446 so DW_FORM_flag_present can be used. If that ever changes,
8447 we'll need to use DW_FORM_flag and have some optimization
8448 in build_abbrev_table that will change those to
8449 DW_FORM_flag_present if it is set to 1 in all DIEs using
8450 the same abbrev entry. */
8451 gcc_assert (AT_flag (a
) == 1);
8453 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8454 ASM_COMMENT_START
, name
);
8457 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8460 case dw_val_class_loc_list
:
8461 output_attr_index_or_value (a
);
8464 case dw_val_class_die_ref
:
8465 if (AT_ref_external (a
))
8467 if (AT_ref (a
)->comdat_type_p
)
8469 comdat_type_node_ref type_node
=
8470 AT_ref (a
)->die_id
.die_type_node
;
8472 gcc_assert (type_node
);
8473 output_signature (type_node
->signature
, name
);
8477 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8481 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8482 length, whereas in DWARF3 it's always sized as an
8484 if (dwarf_version
== 2)
8485 size
= DWARF2_ADDR_SIZE
;
8487 size
= DWARF_OFFSET_SIZE
;
8488 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8494 gcc_assert (AT_ref (a
)->die_offset
);
8495 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8500 case dw_val_class_fde_ref
:
8504 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8505 a
->dw_attr_val
.v
.val_fde_index
* 2);
8506 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8511 case dw_val_class_vms_delta
:
8512 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8513 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8517 case dw_val_class_lbl_id
:
8518 output_attr_index_or_value (a
);
8521 case dw_val_class_lineptr
:
8522 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8523 debug_line_section
, "%s", name
);
8526 case dw_val_class_macptr
:
8527 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8528 debug_macinfo_section
, "%s", name
);
8531 case dw_val_class_str
:
8532 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8533 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8534 a
->dw_attr_val
.v
.val_str
->label
,
8536 "%s: \"%s\"", name
, AT_string (a
));
8537 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8538 dw2_asm_output_data_uleb128 (AT_index (a
),
8539 "%s: \"%s\"", name
, AT_string (a
));
8541 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8544 case dw_val_class_file
:
8546 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8548 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8549 a
->dw_attr_val
.v
.val_file
->filename
);
8553 case dw_val_class_data8
:
8557 for (i
= 0; i
< 8; i
++)
8558 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8559 i
== 0 ? "%s" : NULL
, name
);
8563 case dw_val_class_high_pc
:
8564 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8565 get_AT_low_pc (die
), "DW_AT_high_pc");
8573 FOR_EACH_CHILD (die
, c
, output_die (c
));
8575 /* Add null byte to terminate sibling list. */
8576 if (die
->die_child
!= NULL
)
8577 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8578 (unsigned long) die
->die_offset
);
8581 /* Output the compilation unit that appears at the beginning of the
8582 .debug_info section, and precedes the DIE descriptions. */
8585 output_compilation_unit_header (void)
8587 int ver
= dwarf_version
;
8589 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8590 dw2_asm_output_data (4, 0xffffffff,
8591 "Initial length escape value indicating 64-bit DWARF extension");
8592 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8593 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8594 "Length of Compilation Unit Info");
8595 dw2_asm_output_data (2, ver
, "DWARF version number");
8596 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8597 debug_abbrev_section
,
8598 "Offset Into Abbrev. Section");
8599 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8602 /* Output the compilation unit DIE and its children. */
8605 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8607 const char *secname
, *oldsym
;
8611 /* Unless we are outputting main CU, we may throw away empty ones. */
8612 if (!output_if_empty
&& die
->die_child
== NULL
)
8615 /* Even if there are no children of this DIE, we must output the information
8616 about the compilation unit. Otherwise, on an empty translation unit, we
8617 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8618 will then complain when examining the file. First mark all the DIEs in
8619 this CU so we know which get local refs. */
8622 extern_map
= optimize_external_refs (die
);
8624 build_abbrev_table (die
, extern_map
);
8626 htab_delete (extern_map
);
8628 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8629 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8630 calc_die_sizes (die
);
8632 oldsym
= die
->die_id
.die_symbol
;
8635 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8637 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8639 die
->die_id
.die_symbol
= NULL
;
8640 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8644 switch_to_section (debug_info_section
);
8645 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8646 info_section_emitted
= true;
8649 /* Output debugging information. */
8650 output_compilation_unit_header ();
8653 /* Leave the marks on the main CU, so we can check them in
8658 die
->die_id
.die_symbol
= oldsym
;
8662 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8663 and .debug_pubtypes. This is configured per-target, but can be
8664 overridden by the -gpubnames or -gno-pubnames options. */
8667 want_pubnames (void)
8669 return (debug_generate_pub_sections
!= -1
8670 ? debug_generate_pub_sections
8671 : targetm
.want_debug_pub_sections
);
8674 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8677 add_AT_pubnames (dw_die_ref die
)
8679 if (want_pubnames ())
8680 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8683 /* Helper function to generate top-level dies for skeleton debug_info and
8687 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8689 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8692 add_comp_dir_attribute (die
);
8693 add_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8694 /* The specification suggests that these attributes be inline to avoid
8695 having a .debug_str section. We know that they exist in the die because
8696 we just added them. */
8697 attr
= get_AT (die
, DW_AT_GNU_dwo_name
);
8698 attr
->dw_attr_val
.v
.val_str
->form
= DW_FORM_string
;
8699 attr
= get_AT (die
, DW_AT_comp_dir
);
8700 attr
->dw_attr_val
.v
.val_str
->form
= DW_FORM_string
;
8702 add_AT_pubnames (die
);
8703 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8706 /* Return the single type-unit die for skeleton type units. */
8709 get_skeleton_type_unit (void)
8711 /* For dwarf_split_debug_sections with use_type info, all type units in the
8712 skeleton sections have identical dies (but different headers). This
8713 single die will be output many times. */
8715 static dw_die_ref skeleton_type_unit
= NULL
;
8717 if (skeleton_type_unit
== NULL
)
8719 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8720 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8721 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8723 return skeleton_type_unit
;
8726 /* Output skeleton debug sections that point to the dwo file. */
8729 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8731 /* These attributes will be found in the full debug_info section. */
8732 remove_AT (comp_unit
, DW_AT_producer
);
8733 remove_AT (comp_unit
, DW_AT_language
);
8735 /* Add attributes common to skeleton compile_units and type_units. */
8736 add_top_level_skeleton_die_attrs (comp_unit
);
8738 switch_to_section (debug_skeleton_info_section
);
8739 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8741 /* Produce the skeleton compilation-unit header. This one differs enough from
8742 a normal CU header that it's better not to call output_compilation_unit
8744 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8745 dw2_asm_output_data (4, 0xffffffff,
8746 "Initial length escape value indicating 64-bit DWARF extension");
8748 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8749 DWARF_COMPILE_UNIT_HEADER_SIZE
8750 - DWARF_INITIAL_LENGTH_SIZE
8751 + size_of_die (comp_unit
),
8752 "Length of Compilation Unit Info");
8753 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8754 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8755 debug_abbrev_section
,
8756 "Offset Into Abbrev. Section");
8757 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8759 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8760 output_die (comp_unit
);
8762 /* Build the skeleton debug_abbrev section. */
8763 switch_to_section (debug_skeleton_abbrev_section
);
8764 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8766 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8767 if (use_debug_types
)
8768 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8770 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8773 /* Output a comdat type unit DIE and its children. */
8776 output_comdat_type_unit (comdat_type_node
*node
)
8778 const char *secname
;
8781 #if defined (OBJECT_FORMAT_ELF)
8786 /* First mark all the DIEs in this CU so we know which get local refs. */
8787 mark_dies (node
->root_die
);
8789 extern_map
= optimize_external_refs (node
->root_die
);
8791 build_abbrev_table (node
->root_die
, extern_map
);
8793 htab_delete (extern_map
);
8795 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8796 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8797 calc_die_sizes (node
->root_die
);
8799 #if defined (OBJECT_FORMAT_ELF)
8800 if (!dwarf_split_debug_info
)
8801 secname
= ".debug_types";
8803 secname
= ".debug_types.dwo";
8805 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8806 sprintf (tmp
, "wt.");
8807 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8808 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8809 comdat_key
= get_identifier (tmp
);
8810 targetm
.asm_out
.named_section (secname
,
8811 SECTION_DEBUG
| SECTION_LINKONCE
,
8814 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8815 sprintf (tmp
, ".gnu.linkonce.wt.");
8816 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8817 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8819 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8822 /* Output debugging information. */
8823 output_compilation_unit_header ();
8824 output_signature (node
->signature
, "Type Signature");
8825 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8826 "Offset to Type DIE");
8827 output_die (node
->root_die
);
8829 unmark_dies (node
->root_die
);
8831 #if defined (OBJECT_FORMAT_ELF)
8832 if (dwarf_split_debug_info
)
8834 /* Produce the skeleton type-unit header. */
8835 const char *secname
= ".debug_types";
8837 targetm
.asm_out
.named_section (secname
,
8838 SECTION_DEBUG
| SECTION_LINKONCE
,
8840 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8841 dw2_asm_output_data (4, 0xffffffff,
8842 "Initial length escape value indicating 64-bit DWARF extension");
8844 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8845 DWARF_COMPILE_UNIT_HEADER_SIZE
8846 - DWARF_INITIAL_LENGTH_SIZE
8847 + size_of_die (get_skeleton_type_unit ())
8848 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
8849 "Length of Type Unit Info");
8850 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8851 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8852 debug_skeleton_abbrev_section_label
,
8853 debug_abbrev_section
,
8854 "Offset Into Abbrev. Section");
8855 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8856 output_signature (node
->signature
, "Type Signature");
8857 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
8859 output_die (get_skeleton_type_unit ());
8864 /* Return the DWARF2/3 pubname associated with a decl. */
8867 dwarf2_name (tree decl
, int scope
)
8869 if (DECL_NAMELESS (decl
))
8871 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8874 /* Add a new entry to .debug_pubnames if appropriate. */
8877 add_pubname_string (const char *str
, dw_die_ref die
)
8882 e
.name
= xstrdup (str
);
8883 vec_safe_push (pubname_table
, e
);
8887 add_pubname (tree decl
, dw_die_ref die
)
8889 if (!want_pubnames ())
8892 /* Don't add items to the table when we expect that the consumer will have
8893 just read the enclosing die. For example, if the consumer is looking at a
8894 class_member, it will either be inside the class already, or will have just
8895 looked up the class to find the member. Either way, searching the class is
8896 faster than searching the index. */
8897 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
8898 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8900 const char *name
= dwarf2_name (decl
, 1);
8903 add_pubname_string (name
, die
);
8907 /* Add an enumerator to the pubnames section. */
8910 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
8914 gcc_assert (scope_name
);
8915 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
8917 vec_safe_push (pubname_table
, e
);
8920 /* Add a new entry to .debug_pubtypes if appropriate. */
8923 add_pubtype (tree decl
, dw_die_ref die
)
8927 if (!want_pubnames ())
8930 if ((TREE_PUBLIC (decl
)
8931 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8932 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8935 const char *scope_name
= "";
8936 const char *sep
= is_cxx () ? "::" : ".";
8939 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
8940 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
8942 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
8943 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
8944 scope_name
= concat (scope_name
, sep
, NULL
);
8950 name
= type_tag (decl
);
8952 name
= lang_hooks
.dwarf_name (decl
, 1);
8954 /* If we don't have a name for the type, there's no point in adding
8956 if (name
!= NULL
&& name
[0] != '\0')
8959 e
.name
= concat (scope_name
, name
, NULL
);
8960 vec_safe_push (pubtype_table
, e
);
8963 /* Although it might be more consistent to add the pubinfo for the
8964 enumerators as their dies are created, they should only be added if the
8965 enum type meets the criteria above. So rather than re-check the parent
8966 enum type whenever an enumerator die is created, just output them all
8967 here. This isn't protected by the name conditional because anonymous
8968 enums don't have names. */
8969 if (die
->die_tag
== DW_TAG_enumeration_type
)
8973 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
8978 /* Output the public names table used to speed up access to externally
8979 visible names; or the public types table used to find type definitions. */
8982 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8985 unsigned long pubnames_length
= size_of_pubnames (names
);
8988 if (!want_pubnames () || !info_section_emitted
)
8990 if (names
== pubname_table
)
8991 switch_to_section (debug_pubnames_section
);
8993 switch_to_section (debug_pubtypes_section
);
8994 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8995 dw2_asm_output_data (4, 0xffffffff,
8996 "Initial length escape value indicating 64-bit DWARF extension");
8997 if (names
== pubname_table
)
8998 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8999 "Length of Public Names Info");
9001 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9002 "Length of Public Type Names Info");
9003 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9004 dw2_asm_output_data (2, 2, "DWARF Version");
9005 if (dwarf_split_debug_info
)
9006 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9007 debug_skeleton_info_section
,
9008 "Offset of Compilation Unit Info");
9010 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9012 "Offset of Compilation Unit Info");
9013 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9014 "Compilation Unit Length");
9016 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9018 /* Enumerator names are part of the pubname table, but the parent
9019 DW_TAG_enumeration_type die may have been pruned. Don't output
9020 them if that is the case. */
9021 if (pub
->die
->die_tag
== DW_TAG_enumerator
&& !pub
->die
->die_mark
)
9024 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9025 if (names
== pubname_table
)
9026 gcc_assert (pub
->die
->die_mark
);
9028 if (names
!= pubtype_table
9029 || pub
->die
->die_offset
!= 0
9030 || !flag_eliminate_unused_debug_types
)
9032 dw_offset die_offset
= pub
->die
->die_offset
;
9034 /* If we're putting types in their own .debug_types sections,
9035 the .debug_pubtypes table will still point to the compile
9036 unit (not the type unit), so we want to use the offset of
9037 the skeleton DIE (if there is one). */
9038 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9040 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9042 if (type_node
!= NULL
)
9043 die_offset
= (type_node
->skeleton_die
!= NULL
9044 ? type_node
->skeleton_die
->die_offset
9048 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9050 dw2_asm_output_nstring (pub
->name
, -1, "external name");
9054 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9057 /* Output the information that goes into the .debug_aranges table.
9058 Namely, define the beginning and ending address range of the
9059 text section generated for this compilation unit. */
9062 output_aranges (unsigned long aranges_length
)
9066 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9067 dw2_asm_output_data (4, 0xffffffff,
9068 "Initial length escape value indicating 64-bit DWARF extension");
9069 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9070 "Length of Address Ranges Info");
9071 /* Version number for aranges is still 2, even in DWARF3. */
9072 dw2_asm_output_data (2, 2, "DWARF Version");
9073 if (dwarf_split_debug_info
)
9074 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9075 debug_skeleton_info_section
,
9076 "Offset of Compilation Unit Info");
9078 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9080 "Offset of Compilation Unit Info");
9081 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9082 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9084 /* We need to align to twice the pointer size here. */
9085 if (DWARF_ARANGES_PAD_SIZE
)
9087 /* Pad using a 2 byte words so that padding is correct for any
9089 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9090 2 * DWARF2_ADDR_SIZE
);
9091 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9092 dw2_asm_output_data (2, 0, NULL
);
9095 /* It is necessary not to output these entries if the sections were
9096 not used; if the sections were not used, the length will be 0 and
9097 the address may end up as 0 if the section is discarded by ld
9098 --gc-sections, leaving an invalid (0, 0) entry that can be
9099 confused with the terminator. */
9100 if (text_section_used
)
9102 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9103 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9104 text_section_label
, "Length");
9106 if (cold_text_section_used
)
9108 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9110 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9111 cold_text_section_label
, "Length");
9114 if (have_multiple_function_sections
)
9119 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9121 if (DECL_IGNORED_P (fde
->decl
))
9123 if (!fde
->in_std_section
)
9125 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9127 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9128 fde
->dw_fde_begin
, "Length");
9130 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9132 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9134 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9135 fde
->dw_fde_second_begin
, "Length");
9140 /* Output the terminator words. */
9141 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9142 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9145 /* Add a new entry to .debug_ranges. Return the offset at which it
9149 add_ranges_num (int num
)
9151 unsigned int in_use
= ranges_table_in_use
;
9153 if (in_use
== ranges_table_allocated
)
9155 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9156 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9157 ranges_table_allocated
);
9158 memset (ranges_table
+ ranges_table_in_use
, 0,
9159 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9162 ranges_table
[in_use
].num
= num
;
9163 ranges_table_in_use
= in_use
+ 1;
9165 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9168 /* Add a new entry to .debug_ranges corresponding to a block, or a
9169 range terminator if BLOCK is NULL. */
9172 add_ranges (const_tree block
)
9174 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9177 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9178 When using dwarf_split_debug_info, address attributes in dies destined
9179 for the final executable should be direct references--setting the
9180 parameter force_direct ensures this behavior. */
9183 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9184 bool *added
, bool force_direct
)
9186 unsigned int in_use
= ranges_by_label_in_use
;
9187 unsigned int offset
;
9189 if (in_use
== ranges_by_label_allocated
)
9191 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9192 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9194 ranges_by_label_allocated
);
9195 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9196 RANGES_TABLE_INCREMENT
9197 * sizeof (struct dw_ranges_by_label_struct
));
9200 ranges_by_label
[in_use
].begin
= begin
;
9201 ranges_by_label
[in_use
].end
= end
;
9202 ranges_by_label_in_use
= in_use
+ 1;
9204 offset
= add_ranges_num (-(int)in_use
- 1);
9207 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9213 output_ranges (void)
9216 static const char *const start_fmt
= "Offset %#x";
9217 const char *fmt
= start_fmt
;
9219 for (i
= 0; i
< ranges_table_in_use
; i
++)
9221 int block_num
= ranges_table
[i
].num
;
9225 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9226 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9228 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9229 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9231 /* If all code is in the text section, then the compilation
9232 unit base address defaults to DW_AT_low_pc, which is the
9233 base of the text section. */
9234 if (!have_multiple_function_sections
)
9236 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9238 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9239 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9240 text_section_label
, NULL
);
9243 /* Otherwise, the compilation unit base address is zero,
9244 which allows us to use absolute addresses, and not worry
9245 about whether the target supports cross-section
9249 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9250 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9251 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9257 /* Negative block_num stands for an index into ranges_by_label. */
9258 else if (block_num
< 0)
9260 int lab_idx
= - block_num
- 1;
9262 if (!have_multiple_function_sections
)
9266 /* If we ever use add_ranges_by_labels () for a single
9267 function section, all we have to do is to take out
9269 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9270 ranges_by_label
[lab_idx
].begin
,
9272 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9273 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9274 ranges_by_label
[lab_idx
].end
,
9275 text_section_label
, NULL
);
9280 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9281 ranges_by_label
[lab_idx
].begin
,
9282 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9283 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9284 ranges_by_label
[lab_idx
].end
,
9290 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9291 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9297 /* Data structure containing information about input files. */
9300 const char *path
; /* Complete file name. */
9301 const char *fname
; /* File name part. */
9302 int length
; /* Length of entire string. */
9303 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9304 int dir_idx
; /* Index in directory table. */
9307 /* Data structure containing information about directories with source
9311 const char *path
; /* Path including directory name. */
9312 int length
; /* Path length. */
9313 int prefix
; /* Index of directory entry which is a prefix. */
9314 int count
; /* Number of files in this directory. */
9315 int dir_idx
; /* Index of directory used as base. */
9318 /* Callback function for file_info comparison. We sort by looking at
9319 the directories in the path. */
9322 file_info_cmp (const void *p1
, const void *p2
)
9324 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9325 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9326 const unsigned char *cp1
;
9327 const unsigned char *cp2
;
9329 /* Take care of file names without directories. We need to make sure that
9330 we return consistent values to qsort since some will get confused if
9331 we return the same value when identical operands are passed in opposite
9332 orders. So if neither has a directory, return 0 and otherwise return
9333 1 or -1 depending on which one has the directory. */
9334 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9335 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9337 cp1
= (const unsigned char *) s1
->path
;
9338 cp2
= (const unsigned char *) s2
->path
;
9344 /* Reached the end of the first path? If so, handle like above. */
9345 if ((cp1
== (const unsigned char *) s1
->fname
)
9346 || (cp2
== (const unsigned char *) s2
->fname
))
9347 return ((cp2
== (const unsigned char *) s2
->fname
)
9348 - (cp1
== (const unsigned char *) s1
->fname
));
9350 /* Character of current path component the same? */
9351 else if (*cp1
!= *cp2
)
9356 struct file_name_acquire_data
9358 struct file_info
*files
;
9363 /* Traversal function for the hash table. */
9366 file_name_acquire (void ** slot
, void *data
)
9368 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9369 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9370 struct file_info
*fi
;
9373 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9375 if (! d
->emitted_number
)
9378 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9380 fi
= fnad
->files
+ fnad
->used_files
++;
9382 /* Skip all leading "./". */
9384 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9387 /* Create a new array entry. */
9389 fi
->length
= strlen (f
);
9392 /* Search for the file name part. */
9393 f
= strrchr (f
, DIR_SEPARATOR
);
9394 #if defined (DIR_SEPARATOR_2)
9396 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9400 if (f
== NULL
|| f
< g
)
9406 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9410 /* Output the directory table and the file name table. We try to minimize
9411 the total amount of memory needed. A heuristic is used to avoid large
9412 slowdowns with many input files. */
9415 output_file_names (void)
9417 struct file_name_acquire_data fnad
;
9419 struct file_info
*files
;
9420 struct dir_info
*dirs
;
9428 if (!last_emitted_file
)
9430 dw2_asm_output_data (1, 0, "End directory table");
9431 dw2_asm_output_data (1, 0, "End file name table");
9435 numfiles
= last_emitted_file
->emitted_number
;
9437 /* Allocate the various arrays we need. */
9438 files
= XALLOCAVEC (struct file_info
, numfiles
);
9439 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9442 fnad
.used_files
= 0;
9443 fnad
.max_files
= numfiles
;
9444 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9445 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9447 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9449 /* Find all the different directories used. */
9450 dirs
[0].path
= files
[0].path
;
9451 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9452 dirs
[0].prefix
= -1;
9454 dirs
[0].dir_idx
= 0;
9455 files
[0].dir_idx
= 0;
9458 for (i
= 1; i
< numfiles
; i
++)
9459 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9460 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9461 dirs
[ndirs
- 1].length
) == 0)
9463 /* Same directory as last entry. */
9464 files
[i
].dir_idx
= ndirs
- 1;
9465 ++dirs
[ndirs
- 1].count
;
9471 /* This is a new directory. */
9472 dirs
[ndirs
].path
= files
[i
].path
;
9473 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9474 dirs
[ndirs
].count
= 1;
9475 dirs
[ndirs
].dir_idx
= ndirs
;
9476 files
[i
].dir_idx
= ndirs
;
9478 /* Search for a prefix. */
9479 dirs
[ndirs
].prefix
= -1;
9480 for (j
= 0; j
< ndirs
; j
++)
9481 if (dirs
[j
].length
< dirs
[ndirs
].length
9482 && dirs
[j
].length
> 1
9483 && (dirs
[ndirs
].prefix
== -1
9484 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9485 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9486 dirs
[ndirs
].prefix
= j
;
9491 /* Now to the actual work. We have to find a subset of the directories which
9492 allow expressing the file name using references to the directory table
9493 with the least amount of characters. We do not do an exhaustive search
9494 where we would have to check out every combination of every single
9495 possible prefix. Instead we use a heuristic which provides nearly optimal
9496 results in most cases and never is much off. */
9497 saved
= XALLOCAVEC (int, ndirs
);
9498 savehere
= XALLOCAVEC (int, ndirs
);
9500 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9501 for (i
= 0; i
< ndirs
; i
++)
9506 /* We can always save some space for the current directory. But this
9507 does not mean it will be enough to justify adding the directory. */
9508 savehere
[i
] = dirs
[i
].length
;
9509 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9511 for (j
= i
+ 1; j
< ndirs
; j
++)
9514 if (saved
[j
] < dirs
[i
].length
)
9516 /* Determine whether the dirs[i] path is a prefix of the
9521 while (k
!= -1 && k
!= (int) i
)
9526 /* Yes it is. We can possibly save some memory by
9527 writing the filenames in dirs[j] relative to
9529 savehere
[j
] = dirs
[i
].length
;
9530 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9535 /* Check whether we can save enough to justify adding the dirs[i]
9537 if (total
> dirs
[i
].length
+ 1)
9539 /* It's worthwhile adding. */
9540 for (j
= i
; j
< ndirs
; j
++)
9541 if (savehere
[j
] > 0)
9543 /* Remember how much we saved for this directory so far. */
9544 saved
[j
] = savehere
[j
];
9546 /* Remember the prefix directory. */
9547 dirs
[j
].dir_idx
= i
;
9552 /* Emit the directory name table. */
9553 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9554 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9555 dw2_asm_output_nstring (dirs
[i
].path
,
9557 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9558 "Directory Entry: %#x", i
+ idx_offset
);
9560 dw2_asm_output_data (1, 0, "End directory table");
9562 /* We have to emit them in the order of emitted_number since that's
9563 used in the debug info generation. To do this efficiently we
9564 generate a back-mapping of the indices first. */
9565 backmap
= XALLOCAVEC (int, numfiles
);
9566 for (i
= 0; i
< numfiles
; i
++)
9567 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9569 /* Now write all the file names. */
9570 for (i
= 0; i
< numfiles
; i
++)
9572 int file_idx
= backmap
[i
];
9573 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9575 #ifdef VMS_DEBUGGING_INFO
9576 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9578 /* Setting these fields can lead to debugger miscomparisons,
9579 but VMS Debug requires them to be set correctly. */
9584 int maxfilelen
= strlen (files
[file_idx
].path
)
9585 + dirs
[dir_idx
].length
9586 + MAX_VMS_VERSION_LEN
+ 1;
9587 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9589 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9590 snprintf (filebuf
, maxfilelen
, "%s;%d",
9591 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9593 dw2_asm_output_nstring
9594 (filebuf
, -1, "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
9601 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9605 /* File length in bytes. */
9606 dw2_asm_output_data_uleb128
9607 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9611 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9612 "File Entry: %#x", (unsigned) i
+ 1);
9614 /* Include directory index. */
9615 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9617 /* Modification time. */
9618 dw2_asm_output_data_uleb128 (0, NULL
);
9620 /* File length in bytes. */
9621 dw2_asm_output_data_uleb128 (0, NULL
);
9622 #endif /* VMS_DEBUGGING_INFO */
9625 dw2_asm_output_data (1, 0, "End file name table");
9629 /* Output one line number table into the .debug_line section. */
9632 output_one_line_info_table (dw_line_info_table
*table
)
9634 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9635 unsigned int current_line
= 1;
9636 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9637 dw_line_info_entry
*ent
;
9640 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9642 switch (ent
->opcode
)
9644 case LI_set_address
:
9645 /* ??? Unfortunately, we have little choice here currently, and
9646 must always use the most general form. GCC does not know the
9647 address delta itself, so we can't use DW_LNS_advance_pc. Many
9648 ports do have length attributes which will give an upper bound
9649 on the address range. We could perhaps use length attributes
9650 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9651 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9653 /* This can handle any delta. This takes
9654 4+DWARF2_ADDR_SIZE bytes. */
9655 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9656 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9657 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9658 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9662 if (ent
->val
== current_line
)
9664 /* We still need to start a new row, so output a copy insn. */
9665 dw2_asm_output_data (1, DW_LNS_copy
,
9666 "copy line %u", current_line
);
9670 int line_offset
= ent
->val
- current_line
;
9671 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9673 current_line
= ent
->val
;
9674 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9676 /* This can handle deltas from -10 to 234, using the current
9677 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9678 This takes 1 byte. */
9679 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9680 "line %u", current_line
);
9684 /* This can handle any delta. This takes at least 4 bytes,
9685 depending on the value being encoded. */
9686 dw2_asm_output_data (1, DW_LNS_advance_line
,
9687 "advance to line %u", current_line
);
9688 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9689 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9695 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9696 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9700 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9701 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9704 case LI_negate_stmt
:
9705 current_is_stmt
= !current_is_stmt
;
9706 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9707 "is_stmt %d", current_is_stmt
);
9710 case LI_set_prologue_end
:
9711 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9712 "set prologue end");
9715 case LI_set_epilogue_begin
:
9716 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9717 "set epilogue begin");
9720 case LI_set_discriminator
:
9721 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9722 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9723 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9724 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9729 /* Emit debug info for the address of the end of the table. */
9730 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9731 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9732 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9733 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9735 dw2_asm_output_data (1, 0, "end sequence");
9736 dw2_asm_output_data_uleb128 (1, NULL
);
9737 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9740 /* Output the source line number correspondence information. This
9741 information goes into the .debug_line section. */
9744 output_line_info (bool prologue_only
)
9746 char l1
[20], l2
[20], p1
[20], p2
[20];
9747 int ver
= dwarf_version
;
9748 bool saw_one
= false;
9751 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9752 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9753 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9754 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9756 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9757 dw2_asm_output_data (4, 0xffffffff,
9758 "Initial length escape value indicating 64-bit DWARF extension");
9759 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9760 "Length of Source Line Info");
9761 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9763 dw2_asm_output_data (2, ver
, "DWARF Version");
9764 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9765 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9767 /* Define the architecture-dependent minimum instruction length (in bytes).
9768 In this implementation of DWARF, this field is used for information
9769 purposes only. Since GCC generates assembly language, we have no
9770 a priori knowledge of how many instruction bytes are generated for each
9771 source line, and therefore can use only the DW_LNE_set_address and
9772 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9773 this as '1', which is "correct enough" for all architectures,
9774 and don't let the target override. */
9775 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9778 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9779 "Maximum Operations Per Instruction");
9780 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9781 "Default is_stmt_start flag");
9782 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9783 "Line Base Value (Special Opcodes)");
9784 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9785 "Line Range Value (Special Opcodes)");
9786 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9787 "Special Opcode Base");
9789 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9794 case DW_LNS_advance_pc
:
9795 case DW_LNS_advance_line
:
9796 case DW_LNS_set_file
:
9797 case DW_LNS_set_column
:
9798 case DW_LNS_fixed_advance_pc
:
9799 case DW_LNS_set_isa
:
9807 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9811 /* Write out the information about the files we use. */
9812 output_file_names ();
9813 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9816 /* Output the marker for the end of the line number info. */
9817 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9821 if (separate_line_info
)
9823 dw_line_info_table
*table
;
9826 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
9829 output_one_line_info_table (table
);
9833 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9835 output_one_line_info_table (cold_text_section_line_info
);
9839 /* ??? Some Darwin linkers crash on a .debug_line section with no
9840 sequences. Further, merely a DW_LNE_end_sequence entry is not
9841 sufficient -- the address column must also be initialized.
9842 Make sure to output at least one set_address/end_sequence pair,
9843 choosing .text since that section is always present. */
9844 if (text_section_line_info
->in_use
|| !saw_one
)
9845 output_one_line_info_table (text_section_line_info
);
9847 /* Output the marker for the end of the line number info. */
9848 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9851 /* Given a pointer to a tree node for some base type, return a pointer to
9852 a DIE that describes the given type.
9854 This routine must only be called for GCC type nodes that correspond to
9855 Dwarf base (fundamental) types. */
9858 base_type_die (tree type
)
9860 dw_die_ref base_type_result
;
9861 enum dwarf_type encoding
;
9863 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9866 /* If this is a subtype that should not be emitted as a subrange type,
9867 use the base type. See subrange_type_for_debug_p. */
9868 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9869 type
= TREE_TYPE (type
);
9871 switch (TREE_CODE (type
))
9874 if ((dwarf_version
>= 4 || !dwarf_strict
)
9876 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9877 && DECL_IS_BUILTIN (TYPE_NAME (type
))
9878 && DECL_NAME (TYPE_NAME (type
)))
9880 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
9881 if (strcmp (name
, "char16_t") == 0
9882 || strcmp (name
, "char32_t") == 0)
9884 encoding
= DW_ATE_UTF
;
9888 if (TYPE_STRING_FLAG (type
))
9890 if (TYPE_UNSIGNED (type
))
9891 encoding
= DW_ATE_unsigned_char
;
9893 encoding
= DW_ATE_signed_char
;
9895 else if (TYPE_UNSIGNED (type
))
9896 encoding
= DW_ATE_unsigned
;
9898 encoding
= DW_ATE_signed
;
9902 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9904 if (dwarf_version
>= 3 || !dwarf_strict
)
9905 encoding
= DW_ATE_decimal_float
;
9907 encoding
= DW_ATE_lo_user
;
9910 encoding
= DW_ATE_float
;
9913 case FIXED_POINT_TYPE
:
9914 if (!(dwarf_version
>= 3 || !dwarf_strict
))
9915 encoding
= DW_ATE_lo_user
;
9916 else if (TYPE_UNSIGNED (type
))
9917 encoding
= DW_ATE_unsigned_fixed
;
9919 encoding
= DW_ATE_signed_fixed
;
9922 /* Dwarf2 doesn't know anything about complex ints, so use
9923 a user defined type for it. */
9925 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9926 encoding
= DW_ATE_complex_float
;
9928 encoding
= DW_ATE_lo_user
;
9932 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9933 encoding
= DW_ATE_boolean
;
9937 /* No other TREE_CODEs are Dwarf fundamental types. */
9941 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
9943 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9944 int_size_in_bytes (type
));
9945 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9946 add_pubtype (type
, base_type_result
);
9948 return base_type_result
;
9951 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9952 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9955 is_base_type (tree type
)
9957 switch (TREE_CODE (type
))
9963 case FIXED_POINT_TYPE
:
9971 case QUAL_UNION_TYPE
:
9976 case REFERENCE_TYPE
:
9990 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9991 node, return the size in bits for the type if it is a constant, or else
9992 return the alignment for the type if the type's size is not constant, or
9993 else return BITS_PER_WORD if the type actually turns out to be an
9996 static inline unsigned HOST_WIDE_INT
9997 simple_type_size_in_bits (const_tree type
)
9999 if (TREE_CODE (type
) == ERROR_MARK
)
10000 return BITS_PER_WORD
;
10001 else if (TYPE_SIZE (type
) == NULL_TREE
)
10003 else if (host_integerp (TYPE_SIZE (type
), 1))
10004 return tree_low_cst (TYPE_SIZE (type
), 1);
10006 return TYPE_ALIGN (type
);
10009 /* Similarly, but return a double_int instead of UHWI. */
10011 static inline double_int
10012 double_int_type_size_in_bits (const_tree type
)
10014 if (TREE_CODE (type
) == ERROR_MARK
)
10015 return double_int::from_uhwi (BITS_PER_WORD
);
10016 else if (TYPE_SIZE (type
) == NULL_TREE
)
10017 return double_int_zero
;
10018 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10019 return tree_to_double_int (TYPE_SIZE (type
));
10021 return double_int::from_uhwi (TYPE_ALIGN (type
));
10024 /* Given a pointer to a tree node for a subrange type, return a pointer
10025 to a DIE that describes the given type. */
10028 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10030 dw_die_ref subrange_die
;
10031 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10033 if (context_die
== NULL
)
10034 context_die
= comp_unit_die ();
10036 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10038 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10040 /* The size of the subrange type and its base type do not match,
10041 so we need to generate a size attribute for the subrange type. */
10042 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10046 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10048 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10050 return subrange_die
;
10053 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10054 entry that chains various modifiers in front of the given type. */
10057 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10058 dw_die_ref context_die
)
10060 enum tree_code code
= TREE_CODE (type
);
10061 dw_die_ref mod_type_die
;
10062 dw_die_ref sub_die
= NULL
;
10063 tree item_type
= NULL
;
10064 tree qualified_type
;
10065 tree name
, low
, high
;
10066 dw_die_ref mod_scope
;
10068 if (code
== ERROR_MARK
)
10071 /* See if we already have the appropriately qualified variant of
10074 = get_qualified_type (type
,
10075 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10076 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10078 if (qualified_type
== sizetype
10079 && TYPE_NAME (qualified_type
)
10080 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10082 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10084 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10085 && TYPE_PRECISION (t
)
10086 == TYPE_PRECISION (qualified_type
)
10087 && TYPE_UNSIGNED (t
)
10088 == TYPE_UNSIGNED (qualified_type
));
10089 qualified_type
= t
;
10092 /* If we do, then we can just use its DIE, if it exists. */
10093 if (qualified_type
)
10095 mod_type_die
= lookup_type_die (qualified_type
);
10097 return mod_type_die
;
10100 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10102 /* Handle C typedef types. */
10103 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10104 && !DECL_ARTIFICIAL (name
))
10106 tree dtype
= TREE_TYPE (name
);
10108 if (qualified_type
== dtype
)
10110 /* For a named type, use the typedef. */
10111 gen_type_die (qualified_type
, context_die
);
10112 return lookup_type_die (qualified_type
);
10114 else if (is_const_type
< TYPE_READONLY (dtype
)
10115 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10116 || (is_const_type
<= TYPE_READONLY (dtype
)
10117 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10118 && DECL_ORIGINAL_TYPE (name
) != type
))
10119 /* cv-unqualified version of named type. Just use the unnamed
10120 type to which it refers. */
10121 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10122 is_const_type
, is_volatile_type
,
10124 /* Else cv-qualified version of named type; fall through. */
10127 mod_scope
= scope_die_for (type
, context_die
);
10130 /* If both is_const_type and is_volatile_type, prefer the path
10131 which leads to a qualified type. */
10132 && (!is_volatile_type
10133 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10134 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10136 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10137 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10139 else if (is_volatile_type
)
10141 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10142 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10144 else if (code
== POINTER_TYPE
)
10146 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10147 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10148 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10149 item_type
= TREE_TYPE (type
);
10150 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10151 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10152 TYPE_ADDR_SPACE (item_type
));
10154 else if (code
== REFERENCE_TYPE
)
10156 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10157 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10160 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10161 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10162 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10163 item_type
= TREE_TYPE (type
);
10164 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10165 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10166 TYPE_ADDR_SPACE (item_type
));
10168 else if (code
== INTEGER_TYPE
10169 && TREE_TYPE (type
) != NULL_TREE
10170 && subrange_type_for_debug_p (type
, &low
, &high
))
10172 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10173 item_type
= TREE_TYPE (type
);
10175 else if (is_base_type (type
))
10176 mod_type_die
= base_type_die (type
);
10179 gen_type_die (type
, context_die
);
10181 /* We have to get the type_main_variant here (and pass that to the
10182 `lookup_type_die' routine) because the ..._TYPE node we have
10183 might simply be a *copy* of some original type node (where the
10184 copy was created to help us keep track of typedef names) and
10185 that copy might have a different TYPE_UID from the original
10187 if (TREE_CODE (type
) != VECTOR_TYPE
)
10188 return lookup_type_die (type_main_variant (type
));
10190 /* Vectors have the debugging information in the type,
10191 not the main variant. */
10192 return lookup_type_die (type
);
10195 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10196 don't output a DW_TAG_typedef, since there isn't one in the
10197 user's program; just attach a DW_AT_name to the type.
10198 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10199 if the base type already has the same name. */
10201 && ((TREE_CODE (name
) != TYPE_DECL
10202 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10203 || (!is_const_type
&& !is_volatile_type
)))
10204 || (TREE_CODE (name
) == TYPE_DECL
10205 && TREE_TYPE (name
) == qualified_type
10206 && DECL_NAME (name
))))
10208 if (TREE_CODE (name
) == TYPE_DECL
)
10209 /* Could just call add_name_and_src_coords_attributes here,
10210 but since this is a builtin type it doesn't have any
10211 useful source coordinates anyway. */
10212 name
= DECL_NAME (name
);
10213 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10215 /* This probably indicates a bug. */
10216 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10218 name
= TYPE_NAME (type
);
10220 && TREE_CODE (name
) == TYPE_DECL
)
10221 name
= DECL_NAME (name
);
10222 add_name_attribute (mod_type_die
,
10223 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10226 if (qualified_type
)
10227 equate_type_number_to_die (qualified_type
, mod_type_die
);
10230 /* We must do this after the equate_type_number_to_die call, in case
10231 this is a recursive type. This ensures that the modified_type_die
10232 recursion will terminate even if the type is recursive. Recursive
10233 types are possible in Ada. */
10234 sub_die
= modified_type_die (item_type
,
10235 TYPE_READONLY (item_type
),
10236 TYPE_VOLATILE (item_type
),
10239 if (sub_die
!= NULL
)
10240 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10242 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10243 if (TYPE_ARTIFICIAL (type
))
10244 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10246 return mod_type_die
;
10249 /* Generate DIEs for the generic parameters of T.
10250 T must be either a generic type or a generic function.
10251 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10254 gen_generic_params_dies (tree t
)
10258 dw_die_ref die
= NULL
;
10261 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10265 die
= lookup_type_die (t
);
10266 else if (DECL_P (t
))
10267 die
= lookup_decl_die (t
);
10271 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10273 /* T has no generic parameter. It means T is neither a generic type
10274 or function. End of story. */
10277 parms_num
= TREE_VEC_LENGTH (parms
);
10278 args
= lang_hooks
.get_innermost_generic_args (t
);
10279 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10280 non_default
= int_cst_value (TREE_CHAIN (args
));
10282 non_default
= TREE_VEC_LENGTH (args
);
10283 for (i
= 0; i
< parms_num
; i
++)
10285 tree parm
, arg
, arg_pack_elems
;
10286 dw_die_ref parm_die
;
10288 parm
= TREE_VEC_ELT (parms
, i
);
10289 arg
= TREE_VEC_ELT (args
, i
);
10290 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10291 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10293 if (parm
&& TREE_VALUE (parm
) && arg
)
10295 /* If PARM represents a template parameter pack,
10296 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10297 by DW_TAG_template_*_parameter DIEs for the argument
10298 pack elements of ARG. Note that ARG would then be
10299 an argument pack. */
10300 if (arg_pack_elems
)
10301 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10305 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10306 true /* emit name */, die
);
10307 if (i
>= non_default
)
10308 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10313 /* Create and return a DIE for PARM which should be
10314 the representation of a generic type parameter.
10315 For instance, in the C++ front end, PARM would be a template parameter.
10316 ARG is the argument to PARM.
10317 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10319 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10320 as a child node. */
10323 generic_parameter_die (tree parm
, tree arg
,
10325 dw_die_ref parent_die
)
10327 dw_die_ref tmpl_die
= NULL
;
10328 const char *name
= NULL
;
10330 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10333 /* We support non-type generic parameters and arguments,
10334 type generic parameters and arguments, as well as
10335 generic generic parameters (a.k.a. template template parameters in C++)
10337 if (TREE_CODE (parm
) == PARM_DECL
)
10338 /* PARM is a nontype generic parameter */
10339 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10340 else if (TREE_CODE (parm
) == TYPE_DECL
)
10341 /* PARM is a type generic parameter. */
10342 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10343 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10344 /* PARM is a generic generic parameter.
10345 Its DIE is a GNU extension. It shall have a
10346 DW_AT_name attribute to represent the name of the template template
10347 parameter, and a DW_AT_GNU_template_name attribute to represent the
10348 name of the template template argument. */
10349 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10352 gcc_unreachable ();
10358 /* If PARM is a generic parameter pack, it means we are
10359 emitting debug info for a template argument pack element.
10360 In other terms, ARG is a template argument pack element.
10361 In that case, we don't emit any DW_AT_name attribute for
10365 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10367 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10370 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10372 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10373 TMPL_DIE should have a child DW_AT_type attribute that is set
10374 to the type of the argument to PARM, which is ARG.
10375 If PARM is a type generic parameter, TMPL_DIE should have a
10376 child DW_AT_type that is set to ARG. */
10377 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10378 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10379 TREE_THIS_VOLATILE (tmpl_type
),
10384 /* So TMPL_DIE is a DIE representing a
10385 a generic generic template parameter, a.k.a template template
10386 parameter in C++ and arg is a template. */
10388 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10389 to the name of the argument. */
10390 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10392 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10395 if (TREE_CODE (parm
) == PARM_DECL
)
10396 /* So PARM is a non-type generic parameter.
10397 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10398 attribute of TMPL_DIE which value represents the value
10400 We must be careful here:
10401 The value of ARG might reference some function decls.
10402 We might currently be emitting debug info for a generic
10403 type and types are emitted before function decls, we don't
10404 know if the function decls referenced by ARG will actually be
10405 emitted after cgraph computations.
10406 So must defer the generation of the DW_AT_const_value to
10407 after cgraph is ready. */
10408 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10414 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10415 PARM_PACK must be a template parameter pack. The returned DIE
10416 will be child DIE of PARENT_DIE. */
10419 template_parameter_pack_die (tree parm_pack
,
10420 tree parm_pack_args
,
10421 dw_die_ref parent_die
)
10426 gcc_assert (parent_die
&& parm_pack
);
10428 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10429 add_name_and_src_coords_attributes (die
, parm_pack
);
10430 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10431 generic_parameter_die (parm_pack
,
10432 TREE_VEC_ELT (parm_pack_args
, j
),
10433 false /* Don't emit DW_AT_name */,
10438 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10439 an enumerated type. */
10442 type_is_enum (const_tree type
)
10444 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10447 /* Return the DBX register number described by a given RTL node. */
10449 static unsigned int
10450 dbx_reg_number (const_rtx rtl
)
10452 unsigned regno
= REGNO (rtl
);
10454 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10456 #ifdef LEAF_REG_REMAP
10457 if (crtl
->uses_only_leaf_regs
)
10459 int leaf_reg
= LEAF_REG_REMAP (regno
);
10460 if (leaf_reg
!= -1)
10461 regno
= (unsigned) leaf_reg
;
10465 regno
= DBX_REGISTER_NUMBER (regno
);
10466 gcc_assert (regno
!= INVALID_REGNUM
);
10470 /* Optionally add a DW_OP_piece term to a location description expression.
10471 DW_OP_piece is only added if the location description expression already
10472 doesn't end with DW_OP_piece. */
10475 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10477 dw_loc_descr_ref loc
;
10479 if (*list_head
!= NULL
)
10481 /* Find the end of the chain. */
10482 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10485 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10486 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10490 /* Return a location descriptor that designates a machine register or
10491 zero if there is none. */
10493 static dw_loc_descr_ref
10494 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10498 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10501 /* We only use "frame base" when we're sure we're talking about the
10502 post-prologue local stack frame. We do this by *not* running
10503 register elimination until this point, and recognizing the special
10504 argument pointer and soft frame pointer rtx's.
10505 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10506 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10507 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10509 dw_loc_descr_ref result
= NULL
;
10511 if (dwarf_version
>= 4 || !dwarf_strict
)
10513 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10516 add_loc_descr (&result
,
10517 new_loc_descr (DW_OP_stack_value
, 0, 0));
10522 regs
= targetm
.dwarf_register_span (rtl
);
10524 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10525 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10528 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10529 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10531 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10535 /* Return a location descriptor that designates a machine register for
10536 a given hard register number. */
10538 static dw_loc_descr_ref
10539 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10541 dw_loc_descr_ref reg_loc_descr
;
10545 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10547 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10549 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10550 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10552 return reg_loc_descr
;
10555 /* Given an RTL of a register, return a location descriptor that
10556 designates a value that spans more than one register. */
10558 static dw_loc_descr_ref
10559 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10560 enum var_init_status initialized
)
10562 int nregs
, size
, i
;
10564 dw_loc_descr_ref loc_result
= NULL
;
10567 #ifdef LEAF_REG_REMAP
10568 if (crtl
->uses_only_leaf_regs
)
10570 int leaf_reg
= LEAF_REG_REMAP (reg
);
10571 if (leaf_reg
!= -1)
10572 reg
= (unsigned) leaf_reg
;
10575 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10576 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10578 /* Simple, contiguous registers. */
10579 if (regs
== NULL_RTX
)
10581 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10586 dw_loc_descr_ref t
;
10588 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10589 VAR_INIT_STATUS_INITIALIZED
);
10590 add_loc_descr (&loc_result
, t
);
10591 add_loc_descr_op_piece (&loc_result
, size
);
10597 /* Now onto stupid register sets in non contiguous locations. */
10599 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10601 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10604 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10606 dw_loc_descr_ref t
;
10608 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
10609 VAR_INIT_STATUS_INITIALIZED
);
10610 add_loc_descr (&loc_result
, t
);
10611 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10612 add_loc_descr_op_piece (&loc_result
, size
);
10615 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10616 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10620 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10622 /* Return a location descriptor that designates a constant i,
10623 as a compound operation from constant (i >> shift), constant shift
10626 static dw_loc_descr_ref
10627 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10629 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10630 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10631 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10635 /* Return a location descriptor that designates a constant. */
10637 static dw_loc_descr_ref
10638 int_loc_descriptor (HOST_WIDE_INT i
)
10640 enum dwarf_location_atom op
;
10642 /* Pick the smallest representation of a constant, rather than just
10643 defaulting to the LEB encoding. */
10646 int clz
= clz_hwi (i
);
10647 int ctz
= ctz_hwi (i
);
10649 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10650 else if (i
<= 0xff)
10651 op
= DW_OP_const1u
;
10652 else if (i
<= 0xffff)
10653 op
= DW_OP_const2u
;
10654 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10655 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10656 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10657 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10658 while DW_OP_const4u is 5 bytes. */
10659 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10660 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10661 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10662 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10663 while DW_OP_const4u is 5 bytes. */
10664 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10665 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10666 op
= DW_OP_const4u
;
10667 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10668 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10669 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10670 while DW_OP_constu of constant >= 0x100000000 takes at least
10672 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10673 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10674 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10675 >= HOST_BITS_PER_WIDE_INT
)
10676 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10677 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10678 while DW_OP_constu takes in this case at least 6 bytes. */
10679 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10680 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10681 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10682 && size_of_uleb128 (i
) > 6)
10683 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10684 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10691 op
= DW_OP_const1s
;
10692 else if (i
>= -0x8000)
10693 op
= DW_OP_const2s
;
10694 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10696 if (size_of_int_loc_descriptor (i
) < 5)
10698 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10699 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10702 op
= DW_OP_const4s
;
10706 if (size_of_int_loc_descriptor (i
)
10707 < (unsigned long) 1 + size_of_sleb128 (i
))
10709 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10710 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10717 return new_loc_descr (op
, i
, 0);
10720 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10721 without actually allocating it. */
10723 static unsigned long
10724 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10726 return size_of_int_loc_descriptor (i
>> shift
)
10727 + size_of_int_loc_descriptor (shift
)
10731 /* Return size_of_locs (int_loc_descriptor (i)) without
10732 actually allocating it. */
10734 static unsigned long
10735 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10744 else if (i
<= 0xff)
10746 else if (i
<= 0xffff)
10750 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10751 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10752 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10754 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10755 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10756 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10758 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10760 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10761 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10762 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10763 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10765 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10766 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10767 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10769 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10770 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10772 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10781 else if (i
>= -0x8000)
10783 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10785 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10787 s
= size_of_int_loc_descriptor (-i
) + 1;
10795 unsigned long r
= 1 + size_of_sleb128 (i
);
10796 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10798 s
= size_of_int_loc_descriptor (-i
) + 1;
10807 /* Return loc description representing "address" of integer value.
10808 This can appear only as toplevel expression. */
10810 static dw_loc_descr_ref
10811 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10814 dw_loc_descr_ref loc_result
= NULL
;
10816 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10819 litsize
= size_of_int_loc_descriptor (i
);
10820 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10821 is more compact. For DW_OP_stack_value we need:
10822 litsize + 1 (DW_OP_stack_value)
10823 and for DW_OP_implicit_value:
10824 1 (DW_OP_implicit_value) + 1 (length) + size. */
10825 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10827 loc_result
= int_loc_descriptor (i
);
10828 add_loc_descr (&loc_result
,
10829 new_loc_descr (DW_OP_stack_value
, 0, 0));
10833 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10835 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10836 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10840 /* Return a location descriptor that designates a base+offset location. */
10842 static dw_loc_descr_ref
10843 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10844 enum var_init_status initialized
)
10846 unsigned int regno
;
10847 dw_loc_descr_ref result
;
10848 dw_fde_ref fde
= cfun
->fde
;
10850 /* We only use "frame base" when we're sure we're talking about the
10851 post-prologue local stack frame. We do this by *not* running
10852 register elimination until this point, and recognizing the special
10853 argument pointer and soft frame pointer rtx's. */
10854 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10856 rtx elim
= (ira_use_lra_p
10857 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
10858 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
10862 if (GET_CODE (elim
) == PLUS
)
10864 offset
+= INTVAL (XEXP (elim
, 1));
10865 elim
= XEXP (elim
, 0);
10867 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10868 && (elim
== hard_frame_pointer_rtx
10869 || elim
== stack_pointer_rtx
))
10870 || elim
== (frame_pointer_needed
10871 ? hard_frame_pointer_rtx
10872 : stack_pointer_rtx
));
10874 /* If drap register is used to align stack, use frame
10875 pointer + offset to access stack variables. If stack
10876 is aligned without drap, use stack pointer + offset to
10877 access stack variables. */
10878 if (crtl
->stack_realign_tried
10879 && reg
== frame_pointer_rtx
)
10882 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10883 ? HARD_FRAME_POINTER_REGNUM
10885 return new_reg_loc_descr (base_reg
, offset
);
10888 gcc_assert (frame_pointer_fb_offset_valid
);
10889 offset
+= frame_pointer_fb_offset
;
10890 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10894 regno
= REGNO (reg
);
10895 #ifdef LEAF_REG_REMAP
10896 if (crtl
->uses_only_leaf_regs
)
10898 int leaf_reg
= LEAF_REG_REMAP (regno
);
10899 if (leaf_reg
!= -1)
10900 regno
= (unsigned) leaf_reg
;
10903 regno
= DWARF_FRAME_REGNUM (regno
);
10905 if (!optimize
&& fde
10906 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
10908 /* Use cfa+offset to represent the location of arguments passed
10909 on the stack when drap is used to align stack.
10910 Only do this when not optimizing, for optimized code var-tracking
10911 is supposed to track where the arguments live and the register
10912 used as vdrap or drap in some spot might be used for something
10913 else in other part of the routine. */
10914 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10918 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10921 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10923 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10924 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10929 /* Return true if this RTL expression describes a base+offset calculation. */
10932 is_based_loc (const_rtx rtl
)
10934 return (GET_CODE (rtl
) == PLUS
10935 && ((REG_P (XEXP (rtl
, 0))
10936 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
10937 && CONST_INT_P (XEXP (rtl
, 1)))));
10940 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10943 static dw_loc_descr_ref
10944 tls_mem_loc_descriptor (rtx mem
)
10947 dw_loc_descr_ref loc_result
;
10949 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
10952 base
= get_base_address (MEM_EXPR (mem
));
10954 || TREE_CODE (base
) != VAR_DECL
10955 || !DECL_THREAD_LOCAL_P (base
))
10958 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
10959 if (loc_result
== NULL
)
10962 if (MEM_OFFSET (mem
))
10963 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
10968 /* Output debug info about reason why we failed to expand expression as dwarf
10972 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
10974 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
10976 fprintf (dump_file
, "Failed to expand as dwarf: ");
10978 print_generic_expr (dump_file
, expr
, dump_flags
);
10981 fprintf (dump_file
, "\n");
10982 print_rtl (dump_file
, rtl
);
10984 fprintf (dump_file
, "\nReason: %s\n", reason
);
10988 /* Helper function for const_ok_for_output, called either directly
10989 or via for_each_rtx. */
10992 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
10996 if (GET_CODE (rtl
) == UNSPEC
)
10998 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10999 we can't express it in the debug info. */
11000 #ifdef ENABLE_CHECKING
11001 /* Don't complain about TLS UNSPECs, those are just too hard to
11002 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11003 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11004 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11005 if (XVECLEN (rtl
, 0) == 0
11006 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11007 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11008 inform (current_function_decl
11009 ? DECL_SOURCE_LOCATION (current_function_decl
)
11010 : UNKNOWN_LOCATION
,
11011 #if NUM_UNSPEC_VALUES > 0
11012 "non-delegitimized UNSPEC %s (%d) found in variable location",
11013 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11014 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11017 "non-delegitimized UNSPEC %d found in variable location",
11021 expansion_failed (NULL_TREE
, rtl
,
11022 "UNSPEC hasn't been delegitimized.\n");
11026 if (targetm
.const_not_ok_for_debug_p (rtl
))
11028 expansion_failed (NULL_TREE
, rtl
,
11029 "Expression rejected for debug by the backend.\n");
11033 if (GET_CODE (rtl
) != SYMBOL_REF
)
11036 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11039 get_pool_constant_mark (rtl
, &marked
);
11040 /* If all references to this pool constant were optimized away,
11041 it was not output and thus we can't represent it. */
11044 expansion_failed (NULL_TREE
, rtl
,
11045 "Constant was removed from constant pool.\n");
11050 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11053 /* Avoid references to external symbols in debug info, on several targets
11054 the linker might even refuse to link when linking a shared library,
11055 and in many other cases the relocations for .debug_info/.debug_loc are
11056 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11057 to be defined within the same shared library or executable are fine. */
11058 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11060 tree decl
= SYMBOL_REF_DECL (rtl
);
11062 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11064 expansion_failed (NULL_TREE
, rtl
,
11065 "Symbol not defined in current TU.\n");
11073 /* Return true if constant RTL can be emitted in DW_OP_addr or
11074 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11075 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11078 const_ok_for_output (rtx rtl
)
11080 if (GET_CODE (rtl
) == SYMBOL_REF
)
11081 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11083 if (GET_CODE (rtl
) == CONST
)
11084 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11089 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11090 if possible, NULL otherwise. */
11093 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11095 dw_die_ref type_die
;
11096 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11100 switch (TREE_CODE (type
))
11108 type_die
= lookup_type_die (type
);
11110 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11111 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11116 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11117 type matching MODE, or, if MODE is narrower than or as wide as
11118 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11121 static dw_loc_descr_ref
11122 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11124 enum machine_mode outer_mode
= mode
;
11125 dw_die_ref type_die
;
11126 dw_loc_descr_ref cvt
;
11128 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11130 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11133 type_die
= base_type_for_mode (outer_mode
, 1);
11134 if (type_die
== NULL
)
11136 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11137 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11138 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11139 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11140 add_loc_descr (&op
, cvt
);
11144 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11146 static dw_loc_descr_ref
11147 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11148 dw_loc_descr_ref op1
)
11150 dw_loc_descr_ref ret
= op0
;
11151 add_loc_descr (&ret
, op1
);
11152 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11153 if (STORE_FLAG_VALUE
!= 1)
11155 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11156 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11161 /* Return location descriptor for signed comparison OP RTL. */
11163 static dw_loc_descr_ref
11164 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11165 enum machine_mode mem_mode
)
11167 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11168 dw_loc_descr_ref op0
, op1
;
11171 if (op_mode
== VOIDmode
)
11172 op_mode
= GET_MODE (XEXP (rtl
, 1));
11173 if (op_mode
== VOIDmode
)
11177 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11178 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11181 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11182 VAR_INIT_STATUS_INITIALIZED
);
11183 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11184 VAR_INIT_STATUS_INITIALIZED
);
11186 if (op0
== NULL
|| op1
== NULL
)
11189 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11190 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11191 return compare_loc_descriptor (op
, op0
, op1
);
11193 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11195 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11196 dw_loc_descr_ref cvt
;
11198 if (type_die
== NULL
)
11200 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11201 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11202 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11203 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11204 add_loc_descr (&op0
, cvt
);
11205 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11206 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11207 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11208 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11209 add_loc_descr (&op1
, cvt
);
11210 return compare_loc_descriptor (op
, op0
, op1
);
11213 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11214 /* For eq/ne, if the operands are known to be zero-extended,
11215 there is no need to do the fancy shifting up. */
11216 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11218 dw_loc_descr_ref last0
, last1
;
11219 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11221 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11223 /* deref_size zero extends, and for constants we can check
11224 whether they are zero extended or not. */
11225 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11226 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11227 || (CONST_INT_P (XEXP (rtl
, 0))
11228 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11229 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11230 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11231 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11232 || (CONST_INT_P (XEXP (rtl
, 1))
11233 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11234 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11235 return compare_loc_descriptor (op
, op0
, op1
);
11237 /* EQ/NE comparison against constant in narrower type than
11238 DWARF2_ADDR_SIZE can be performed either as
11239 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11242 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11243 DW_OP_{eq,ne}. Pick whatever is shorter. */
11244 if (CONST_INT_P (XEXP (rtl
, 1))
11245 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11246 && (size_of_int_loc_descriptor (shift
) + 1
11247 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11248 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11249 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11250 & GET_MODE_MASK (op_mode
))))
11252 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11253 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11254 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11255 & GET_MODE_MASK (op_mode
));
11256 return compare_loc_descriptor (op
, op0
, op1
);
11259 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11260 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11261 if (CONST_INT_P (XEXP (rtl
, 1)))
11262 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11265 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11266 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11268 return compare_loc_descriptor (op
, op0
, op1
);
11271 /* Return location descriptor for unsigned comparison OP RTL. */
11273 static dw_loc_descr_ref
11274 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11275 enum machine_mode mem_mode
)
11277 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11278 dw_loc_descr_ref op0
, op1
;
11280 if (op_mode
== VOIDmode
)
11281 op_mode
= GET_MODE (XEXP (rtl
, 1));
11282 if (op_mode
== VOIDmode
)
11284 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11287 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11290 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11291 VAR_INIT_STATUS_INITIALIZED
);
11292 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11293 VAR_INIT_STATUS_INITIALIZED
);
11295 if (op0
== NULL
|| op1
== NULL
)
11298 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11300 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11301 dw_loc_descr_ref last0
, last1
;
11302 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11304 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11306 if (CONST_INT_P (XEXP (rtl
, 0)))
11307 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11308 /* deref_size zero extends, so no need to mask it again. */
11309 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11310 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11312 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11313 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11315 if (CONST_INT_P (XEXP (rtl
, 1)))
11316 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11317 /* deref_size zero extends, so no need to mask it again. */
11318 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11319 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11321 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11322 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11325 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11327 HOST_WIDE_INT bias
= 1;
11328 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11329 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11330 if (CONST_INT_P (XEXP (rtl
, 1)))
11331 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11332 + INTVAL (XEXP (rtl
, 1)));
11334 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11337 return compare_loc_descriptor (op
, op0
, op1
);
11340 /* Return location descriptor for {U,S}{MIN,MAX}. */
11342 static dw_loc_descr_ref
11343 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11344 enum machine_mode mem_mode
)
11346 enum dwarf_location_atom op
;
11347 dw_loc_descr_ref op0
, op1
, ret
;
11348 dw_loc_descr_ref bra_node
, drop_node
;
11351 && (GET_MODE_CLASS (mode
) != MODE_INT
11352 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11355 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11356 VAR_INIT_STATUS_INITIALIZED
);
11357 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11358 VAR_INIT_STATUS_INITIALIZED
);
11360 if (op0
== NULL
|| op1
== NULL
)
11363 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11364 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11365 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11366 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11368 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11370 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11371 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11372 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11373 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11374 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11376 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11378 HOST_WIDE_INT bias
= 1;
11379 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11380 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11381 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11384 else if (GET_MODE_CLASS (mode
) == MODE_INT
11385 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11387 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11388 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11389 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11390 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11391 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11393 else if (GET_MODE_CLASS (mode
) == MODE_INT
11394 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11396 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11397 dw_loc_descr_ref cvt
;
11398 if (type_die
== NULL
)
11400 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11401 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11402 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11403 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11404 add_loc_descr (&op0
, cvt
);
11405 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11406 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11407 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11408 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11409 add_loc_descr (&op1
, cvt
);
11412 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11417 add_loc_descr (&ret
, op1
);
11418 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11419 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11420 add_loc_descr (&ret
, bra_node
);
11421 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11422 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11423 add_loc_descr (&ret
, drop_node
);
11424 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11425 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11426 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11427 && GET_MODE_CLASS (mode
) == MODE_INT
11428 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11429 ret
= convert_descriptor_to_mode (mode
, ret
);
11433 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11434 but after converting arguments to type_die, afterwards
11435 convert back to unsigned. */
11437 static dw_loc_descr_ref
11438 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11439 enum machine_mode mode
, enum machine_mode mem_mode
)
11441 dw_loc_descr_ref cvt
, op0
, op1
;
11443 if (type_die
== NULL
)
11445 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11446 VAR_INIT_STATUS_INITIALIZED
);
11447 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11448 VAR_INIT_STATUS_INITIALIZED
);
11449 if (op0
== NULL
|| op1
== NULL
)
11451 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11452 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11453 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11454 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11455 add_loc_descr (&op0
, cvt
);
11456 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11457 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11458 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11459 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11460 add_loc_descr (&op1
, cvt
);
11461 add_loc_descr (&op0
, op1
);
11462 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11463 return convert_descriptor_to_mode (mode
, op0
);
11466 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11467 const0 is DW_OP_lit0 or corresponding typed constant,
11468 const1 is DW_OP_lit1 or corresponding typed constant
11469 and constMSB is constant with just the MSB bit set
11471 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11472 L1: const0 DW_OP_swap
11473 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11474 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11479 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11480 L1: const0 DW_OP_swap
11481 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11482 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11487 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11488 L1: const1 DW_OP_swap
11489 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11490 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11494 static dw_loc_descr_ref
11495 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11496 enum machine_mode mem_mode
)
11498 dw_loc_descr_ref op0
, ret
, tmp
;
11499 HOST_WIDE_INT valv
;
11500 dw_loc_descr_ref l1jump
, l1label
;
11501 dw_loc_descr_ref l2jump
, l2label
;
11502 dw_loc_descr_ref l3jump
, l3label
;
11503 dw_loc_descr_ref l4jump
, l4label
;
11506 if (GET_MODE_CLASS (mode
) != MODE_INT
11507 || GET_MODE (XEXP (rtl
, 0)) != mode
11508 || (GET_CODE (rtl
) == CLZ
11509 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11512 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11513 VAR_INIT_STATUS_INITIALIZED
);
11517 if (GET_CODE (rtl
) == CLZ
)
11519 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11520 valv
= GET_MODE_BITSIZE (mode
);
11522 else if (GET_CODE (rtl
) == FFS
)
11524 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11525 valv
= GET_MODE_BITSIZE (mode
);
11526 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11527 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11528 add_loc_descr (&ret
, l1jump
);
11529 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11530 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11531 VAR_INIT_STATUS_INITIALIZED
);
11534 add_loc_descr (&ret
, tmp
);
11535 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11536 add_loc_descr (&ret
, l4jump
);
11537 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11538 ? const1_rtx
: const0_rtx
,
11540 VAR_INIT_STATUS_INITIALIZED
);
11541 if (l1label
== NULL
)
11543 add_loc_descr (&ret
, l1label
);
11544 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11545 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11546 add_loc_descr (&ret
, l2label
);
11547 if (GET_CODE (rtl
) != CLZ
)
11549 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11550 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11551 << (GET_MODE_BITSIZE (mode
) - 1));
11553 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11554 << (GET_MODE_BITSIZE (mode
)
11555 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11556 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11557 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11558 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11559 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11561 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11562 VAR_INIT_STATUS_INITIALIZED
);
11565 add_loc_descr (&ret
, tmp
);
11566 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11567 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11568 add_loc_descr (&ret
, l3jump
);
11569 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11570 VAR_INIT_STATUS_INITIALIZED
);
11573 add_loc_descr (&ret
, tmp
);
11574 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11575 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11576 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11577 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11578 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11579 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11580 add_loc_descr (&ret
, l2jump
);
11581 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11582 add_loc_descr (&ret
, l3label
);
11583 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11584 add_loc_descr (&ret
, l4label
);
11585 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11586 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11587 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11588 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11589 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11590 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11591 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11592 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11596 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11597 const1 is DW_OP_lit1 or corresponding typed constant):
11599 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11600 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11604 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11605 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11608 static dw_loc_descr_ref
11609 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11610 enum machine_mode mem_mode
)
11612 dw_loc_descr_ref op0
, ret
, tmp
;
11613 dw_loc_descr_ref l1jump
, l1label
;
11614 dw_loc_descr_ref l2jump
, l2label
;
11616 if (GET_MODE_CLASS (mode
) != MODE_INT
11617 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11620 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11621 VAR_INIT_STATUS_INITIALIZED
);
11625 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11626 VAR_INIT_STATUS_INITIALIZED
);
11629 add_loc_descr (&ret
, tmp
);
11630 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11631 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11632 add_loc_descr (&ret
, l1label
);
11633 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11634 add_loc_descr (&ret
, l2jump
);
11635 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11636 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11637 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11638 VAR_INIT_STATUS_INITIALIZED
);
11641 add_loc_descr (&ret
, tmp
);
11642 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11643 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11644 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11645 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11646 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11647 VAR_INIT_STATUS_INITIALIZED
);
11648 add_loc_descr (&ret
, tmp
);
11649 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11650 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11651 add_loc_descr (&ret
, l1jump
);
11652 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11653 add_loc_descr (&ret
, l2label
);
11654 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11655 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11656 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11657 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11661 /* BSWAP (constS is initial shift count, either 56 or 24):
11663 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11664 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11665 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11666 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11667 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11669 static dw_loc_descr_ref
11670 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11671 enum machine_mode mem_mode
)
11673 dw_loc_descr_ref op0
, ret
, tmp
;
11674 dw_loc_descr_ref l1jump
, l1label
;
11675 dw_loc_descr_ref l2jump
, l2label
;
11677 if (GET_MODE_CLASS (mode
) != MODE_INT
11678 || BITS_PER_UNIT
!= 8
11679 || (GET_MODE_BITSIZE (mode
) != 32
11680 && GET_MODE_BITSIZE (mode
) != 64))
11683 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11684 VAR_INIT_STATUS_INITIALIZED
);
11689 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11691 VAR_INIT_STATUS_INITIALIZED
);
11694 add_loc_descr (&ret
, tmp
);
11695 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11696 VAR_INIT_STATUS_INITIALIZED
);
11699 add_loc_descr (&ret
, tmp
);
11700 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11701 add_loc_descr (&ret
, l1label
);
11702 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11704 VAR_INIT_STATUS_INITIALIZED
);
11705 add_loc_descr (&ret
, tmp
);
11706 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11707 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11708 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11709 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11710 VAR_INIT_STATUS_INITIALIZED
);
11713 add_loc_descr (&ret
, tmp
);
11714 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11715 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11716 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11717 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11718 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11719 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11720 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11721 VAR_INIT_STATUS_INITIALIZED
);
11722 add_loc_descr (&ret
, tmp
);
11723 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11724 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11725 add_loc_descr (&ret
, l2jump
);
11726 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11727 VAR_INIT_STATUS_INITIALIZED
);
11728 add_loc_descr (&ret
, tmp
);
11729 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11730 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11731 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11732 add_loc_descr (&ret
, l1jump
);
11733 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11734 add_loc_descr (&ret
, l2label
);
11735 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11736 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11737 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11738 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11739 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11740 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11744 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11745 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11746 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11747 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11749 ROTATERT is similar:
11750 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11751 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11752 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11754 static dw_loc_descr_ref
11755 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11756 enum machine_mode mem_mode
)
11758 rtx rtlop1
= XEXP (rtl
, 1);
11759 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11762 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11765 if (GET_MODE (rtlop1
) != VOIDmode
11766 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11767 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11768 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11769 VAR_INIT_STATUS_INITIALIZED
);
11770 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11771 VAR_INIT_STATUS_INITIALIZED
);
11772 if (op0
== NULL
|| op1
== NULL
)
11774 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11775 for (i
= 0; i
< 2; i
++)
11777 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11778 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11780 VAR_INIT_STATUS_INITIALIZED
);
11781 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11782 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11784 : HOST_BITS_PER_WIDE_INT
== 64
11785 ? DW_OP_const8u
: DW_OP_constu
,
11786 GET_MODE_MASK (mode
), 0);
11789 if (mask
[i
] == NULL
)
11791 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11794 add_loc_descr (&ret
, op1
);
11795 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11796 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11797 if (GET_CODE (rtl
) == ROTATERT
)
11799 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11800 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11801 GET_MODE_BITSIZE (mode
), 0));
11803 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11804 if (mask
[0] != NULL
)
11805 add_loc_descr (&ret
, mask
[0]);
11806 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11807 if (mask
[1] != NULL
)
11809 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11810 add_loc_descr (&ret
, mask
[1]);
11811 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11813 if (GET_CODE (rtl
) == ROTATE
)
11815 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11816 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11817 GET_MODE_BITSIZE (mode
), 0));
11819 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11820 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11824 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11825 for DEBUG_PARAMETER_REF RTL. */
11827 static dw_loc_descr_ref
11828 parameter_ref_descriptor (rtx rtl
)
11830 dw_loc_descr_ref ret
;
11835 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11836 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11837 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11840 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11841 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11842 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11846 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11847 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11852 /* The following routine converts the RTL for a variable or parameter
11853 (resident in memory) into an equivalent Dwarf representation of a
11854 mechanism for getting the address of that same variable onto the top of a
11855 hypothetical "address evaluation" stack.
11857 When creating memory location descriptors, we are effectively transforming
11858 the RTL for a memory-resident object into its Dwarf postfix expression
11859 equivalent. This routine recursively descends an RTL tree, turning
11860 it into Dwarf postfix code as it goes.
11862 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11864 MEM_MODE is the mode of the memory reference, needed to handle some
11865 autoincrement addressing modes.
11867 Return 0 if we can't represent the location. */
11870 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11871 enum machine_mode mem_mode
,
11872 enum var_init_status initialized
)
11874 dw_loc_descr_ref mem_loc_result
= NULL
;
11875 enum dwarf_location_atom op
;
11876 dw_loc_descr_ref op0
, op1
;
11877 rtx inner
= NULL_RTX
;
11879 if (mode
== VOIDmode
)
11880 mode
= GET_MODE (rtl
);
11882 /* Note that for a dynamically sized array, the location we will generate a
11883 description of here will be the lowest numbered location which is
11884 actually within the array. That's *not* necessarily the same as the
11885 zeroth element of the array. */
11887 rtl
= targetm
.delegitimize_address (rtl
);
11889 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11892 switch (GET_CODE (rtl
))
11897 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11900 /* The case of a subreg may arise when we have a local (register)
11901 variable or a formal (register) parameter which doesn't quite fill
11902 up an entire register. For now, just assume that it is
11903 legitimate to make the Dwarf info refer to the whole register which
11904 contains the given subreg. */
11905 if (!subreg_lowpart_p (rtl
))
11907 inner
= SUBREG_REG (rtl
);
11909 if (inner
== NULL_RTX
)
11910 inner
= XEXP (rtl
, 0);
11911 if (GET_MODE_CLASS (mode
) == MODE_INT
11912 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
11913 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11914 #ifdef POINTERS_EXTEND_UNSIGNED
11915 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
11918 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
11920 mem_loc_result
= mem_loc_descriptor (inner
,
11922 mem_mode
, initialized
);
11927 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
11929 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
11930 && (GET_MODE_CLASS (mode
) != MODE_INT
11931 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
11935 dw_die_ref type_die
;
11936 dw_loc_descr_ref cvt
;
11938 mem_loc_result
= mem_loc_descriptor (inner
,
11940 mem_mode
, initialized
);
11941 if (mem_loc_result
== NULL
)
11943 type_die
= base_type_for_mode (mode
,
11944 GET_MODE_CLASS (mode
) == MODE_INT
);
11945 if (type_die
== NULL
)
11947 mem_loc_result
= NULL
;
11950 if (GET_MODE_SIZE (mode
)
11951 != GET_MODE_SIZE (GET_MODE (inner
)))
11952 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11954 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
11955 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11956 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11957 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11958 add_loc_descr (&mem_loc_result
, cvt
);
11963 if (GET_MODE_CLASS (mode
) != MODE_INT
11964 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11965 && rtl
!= arg_pointer_rtx
11966 && rtl
!= frame_pointer_rtx
11967 #ifdef POINTERS_EXTEND_UNSIGNED
11968 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11972 dw_die_ref type_die
;
11973 unsigned int dbx_regnum
;
11977 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
11979 type_die
= base_type_for_mode (mode
,
11980 GET_MODE_CLASS (mode
) == MODE_INT
);
11981 if (type_die
== NULL
)
11984 dbx_regnum
= dbx_reg_number (rtl
);
11985 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11987 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
11989 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11990 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11991 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11994 /* Whenever a register number forms a part of the description of the
11995 method for calculating the (dynamic) address of a memory resident
11996 object, DWARF rules require the register number be referred to as
11997 a "base register". This distinction is not based in any way upon
11998 what category of register the hardware believes the given register
11999 belongs to. This is strictly DWARF terminology we're dealing with
12000 here. Note that in cases where the location of a memory-resident
12001 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12002 OP_CONST (0)) the actual DWARF location descriptor that we generate
12003 may just be OP_BASEREG (basereg). This may look deceptively like
12004 the object in question was allocated to a register (rather than in
12005 memory) so DWARF consumers need to be aware of the subtle
12006 distinction between OP_REG and OP_BASEREG. */
12007 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12008 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12009 else if (stack_realign_drap
12011 && crtl
->args
.internal_arg_pointer
== rtl
12012 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12014 /* If RTL is internal_arg_pointer, which has been optimized
12015 out, use DRAP instead. */
12016 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12017 VAR_INIT_STATUS_INITIALIZED
);
12023 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12025 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12026 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12029 else if (GET_CODE (rtl
) == ZERO_EXTEND
12030 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12031 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12032 < HOST_BITS_PER_WIDE_INT
12033 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12034 to expand zero extend as two shifts instead of
12036 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12038 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12039 mem_loc_result
= op0
;
12040 add_loc_descr (&mem_loc_result
,
12041 int_loc_descriptor (GET_MODE_MASK (imode
)));
12042 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12044 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12046 int shift
= DWARF2_ADDR_SIZE
12047 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12048 shift
*= BITS_PER_UNIT
;
12049 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12053 mem_loc_result
= op0
;
12054 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12055 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12056 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12057 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12059 else if (!dwarf_strict
)
12061 dw_die_ref type_die1
, type_die2
;
12062 dw_loc_descr_ref cvt
;
12064 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12065 GET_CODE (rtl
) == ZERO_EXTEND
);
12066 if (type_die1
== NULL
)
12068 type_die2
= base_type_for_mode (mode
, 1);
12069 if (type_die2
== NULL
)
12071 mem_loc_result
= op0
;
12072 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12073 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12074 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12075 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12076 add_loc_descr (&mem_loc_result
, cvt
);
12077 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12078 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12079 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12080 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12081 add_loc_descr (&mem_loc_result
, cvt
);
12087 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12088 if (new_rtl
!= rtl
)
12090 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12092 if (mem_loc_result
!= NULL
)
12093 return mem_loc_result
;
12096 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12097 get_address_mode (rtl
), mode
,
12098 VAR_INIT_STATUS_INITIALIZED
);
12099 if (mem_loc_result
== NULL
)
12100 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12101 if (mem_loc_result
!= NULL
)
12103 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12104 || GET_MODE_CLASS (mode
) != MODE_INT
)
12106 dw_die_ref type_die
;
12107 dw_loc_descr_ref deref
;
12112 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12113 if (type_die
== NULL
)
12115 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12116 GET_MODE_SIZE (mode
), 0);
12117 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12118 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12119 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12120 add_loc_descr (&mem_loc_result
, deref
);
12122 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12123 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12125 add_loc_descr (&mem_loc_result
,
12126 new_loc_descr (DW_OP_deref_size
,
12127 GET_MODE_SIZE (mode
), 0));
12132 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12135 /* Some ports can transform a symbol ref into a label ref, because
12136 the symbol ref is too far away and has to be dumped into a constant
12140 if (GET_MODE_CLASS (mode
) != MODE_INT
12141 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12142 #ifdef POINTERS_EXTEND_UNSIGNED
12143 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12147 if (GET_CODE (rtl
) == SYMBOL_REF
12148 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12150 dw_loc_descr_ref temp
;
12152 /* If this is not defined, we have no way to emit the data. */
12153 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12156 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12158 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12159 add_loc_descr (&mem_loc_result
, temp
);
12164 if (!const_ok_for_output (rtl
))
12168 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12169 vec_safe_push (used_rtx_array
, rtl
);
12175 case DEBUG_IMPLICIT_PTR
:
12176 expansion_failed (NULL_TREE
, rtl
,
12177 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12183 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12185 if (GET_MODE_CLASS (mode
) != MODE_INT
12186 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12187 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12188 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12191 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12192 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12194 op0
= one_reg_loc_descriptor (dbx_regnum
,
12195 VAR_INIT_STATUS_INITIALIZED
);
12198 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12199 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12201 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12202 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12203 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12207 gcc_unreachable ();
12210 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12211 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12212 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12215 case DEBUG_PARAMETER_REF
:
12216 mem_loc_result
= parameter_ref_descriptor (rtl
);
12220 /* Extract the PLUS expression nested inside and fall into
12221 PLUS code below. */
12222 rtl
= XEXP (rtl
, 1);
12227 /* Turn these into a PLUS expression and fall into the PLUS code
12229 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12230 GEN_INT (GET_CODE (rtl
) == PRE_INC
12231 ? GET_MODE_UNIT_SIZE (mem_mode
)
12232 : -GET_MODE_UNIT_SIZE (mem_mode
)));
12234 /* ... fall through ... */
12238 if (is_based_loc (rtl
)
12239 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12240 || XEXP (rtl
, 0) == arg_pointer_rtx
12241 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12242 && GET_MODE_CLASS (mode
) == MODE_INT
)
12243 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12244 INTVAL (XEXP (rtl
, 1)),
12245 VAR_INIT_STATUS_INITIALIZED
);
12248 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12249 VAR_INIT_STATUS_INITIALIZED
);
12250 if (mem_loc_result
== 0)
12253 if (CONST_INT_P (XEXP (rtl
, 1))
12254 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12255 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12258 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12259 VAR_INIT_STATUS_INITIALIZED
);
12262 add_loc_descr (&mem_loc_result
, op1
);
12263 add_loc_descr (&mem_loc_result
,
12264 new_loc_descr (DW_OP_plus
, 0, 0));
12269 /* If a pseudo-reg is optimized away, it is possible for it to
12270 be replaced with a MEM containing a multiply or shift. */
12281 && GET_MODE_CLASS (mode
) == MODE_INT
12282 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12284 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12285 base_type_for_mode (mode
, 0),
12309 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12311 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12312 VAR_INIT_STATUS_INITIALIZED
);
12314 rtx rtlop1
= XEXP (rtl
, 1);
12315 if (GET_MODE (rtlop1
) != VOIDmode
12316 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12317 < GET_MODE_BITSIZE (mode
))
12318 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12319 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12320 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));
12344 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12345 VAR_INIT_STATUS_INITIALIZED
);
12346 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12347 VAR_INIT_STATUS_INITIALIZED
);
12349 if (op0
== 0 || op1
== 0)
12352 mem_loc_result
= op0
;
12353 add_loc_descr (&mem_loc_result
, op1
);
12354 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12358 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12360 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12361 base_type_for_mode (mode
, 0),
12366 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12367 VAR_INIT_STATUS_INITIALIZED
);
12368 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12369 VAR_INIT_STATUS_INITIALIZED
);
12371 if (op0
== 0 || op1
== 0)
12374 mem_loc_result
= op0
;
12375 add_loc_descr (&mem_loc_result
, op1
);
12376 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12377 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12378 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12379 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12380 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12384 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12386 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12391 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12392 base_type_for_mode (mode
, 1),
12410 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12411 VAR_INIT_STATUS_INITIALIZED
);
12416 mem_loc_result
= op0
;
12417 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12421 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12422 #ifdef POINTERS_EXTEND_UNSIGNED
12424 && mem_mode
!= VOIDmode
12425 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12429 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12433 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12434 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12436 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12437 enum machine_mode amode
;
12438 if (type_die
== NULL
)
12440 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12442 if (INTVAL (rtl
) >= 0
12443 && amode
!= BLKmode
12444 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12445 /* const DW_OP_GNU_convert <XXX> vs.
12446 DW_OP_GNU_const_type <XXX, 1, const>. */
12447 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12448 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12450 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12451 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12452 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12453 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12454 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12455 add_loc_descr (&mem_loc_result
, op0
);
12456 return mem_loc_result
;
12458 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12460 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12461 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12462 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12463 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12464 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12467 mem_loc_result
->dw_loc_oprnd2
.val_class
12468 = dw_val_class_const_double
;
12469 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12470 = double_int::from_shwi (INTVAL (rtl
));
12478 dw_die_ref type_die
;
12480 /* Note that a CONST_DOUBLE rtx could represent either an integer
12481 or a floating-point constant. A CONST_DOUBLE is used whenever
12482 the constant requires more than one word in order to be
12483 adequately represented. We output CONST_DOUBLEs as blocks. */
12484 if (mode
== VOIDmode
12485 || (GET_MODE (rtl
) == VOIDmode
12486 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12488 type_die
= base_type_for_mode (mode
,
12489 GET_MODE_CLASS (mode
) == MODE_INT
);
12490 if (type_die
== NULL
)
12492 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12493 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12494 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12495 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12496 if (SCALAR_FLOAT_MODE_P (mode
))
12498 unsigned int length
= GET_MODE_SIZE (mode
);
12499 unsigned char *array
12500 = (unsigned char*) ggc_alloc_atomic (length
);
12502 insert_float (rtl
, array
);
12503 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12504 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12505 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12506 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12510 mem_loc_result
->dw_loc_oprnd2
.val_class
12511 = dw_val_class_const_double
;
12512 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12513 = rtx_to_double_int (rtl
);
12519 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12523 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12527 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12531 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12535 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12539 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12543 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12547 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12551 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12555 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12560 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12565 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12570 if (CONST_INT_P (XEXP (rtl
, 1))
12571 && CONST_INT_P (XEXP (rtl
, 2))
12572 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12573 + (unsigned) INTVAL (XEXP (rtl
, 2))
12574 <= GET_MODE_BITSIZE (mode
))
12575 && GET_MODE_CLASS (mode
) == MODE_INT
12576 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12577 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12580 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12581 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12584 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12588 mem_loc_result
= op0
;
12589 size
= INTVAL (XEXP (rtl
, 1));
12590 shift
= INTVAL (XEXP (rtl
, 2));
12591 if (BITS_BIG_ENDIAN
)
12592 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12594 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12596 add_loc_descr (&mem_loc_result
,
12597 int_loc_descriptor (DWARF2_ADDR_SIZE
12599 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12601 if (size
!= (int) DWARF2_ADDR_SIZE
)
12603 add_loc_descr (&mem_loc_result
,
12604 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12605 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12612 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12613 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12614 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12615 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12616 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12617 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12618 VAR_INIT_STATUS_INITIALIZED
);
12619 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12620 VAR_INIT_STATUS_INITIALIZED
);
12621 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12624 mem_loc_result
= op1
;
12625 add_loc_descr (&mem_loc_result
, op2
);
12626 add_loc_descr (&mem_loc_result
, op0
);
12627 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12628 add_loc_descr (&mem_loc_result
, bra_node
);
12629 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12630 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12631 add_loc_descr (&mem_loc_result
, drop_node
);
12632 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12633 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12638 case FLOAT_TRUNCATE
:
12640 case UNSIGNED_FLOAT
:
12645 dw_die_ref type_die
;
12646 dw_loc_descr_ref cvt
;
12648 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12649 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12652 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12653 && (GET_CODE (rtl
) == FLOAT
12654 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12655 <= DWARF2_ADDR_SIZE
))
12657 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12658 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12659 if (type_die
== NULL
)
12661 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12662 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12663 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12664 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12665 add_loc_descr (&op0
, cvt
);
12667 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12668 if (type_die
== NULL
)
12670 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12671 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12672 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12673 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12674 add_loc_descr (&op0
, cvt
);
12675 if (GET_MODE_CLASS (mode
) == MODE_INT
12676 && (GET_CODE (rtl
) == FIX
12677 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12679 op0
= convert_descriptor_to_mode (mode
, op0
);
12683 mem_loc_result
= op0
;
12690 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12695 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12699 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12704 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12708 /* In theory, we could implement the above. */
12709 /* DWARF cannot represent the unsigned compare operations
12734 case FRACT_CONVERT
:
12735 case UNSIGNED_FRACT_CONVERT
:
12737 case UNSIGNED_SAT_FRACT
:
12743 case VEC_DUPLICATE
:
12747 case STRICT_LOW_PART
:
12752 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12753 can't express it in the debug info. This can happen e.g. with some
12758 resolve_one_addr (&rtl
, NULL
);
12762 #ifdef ENABLE_CHECKING
12763 print_rtl (stderr
, rtl
);
12764 gcc_unreachable ();
12770 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12771 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12773 return mem_loc_result
;
12776 /* Return a descriptor that describes the concatenation of two locations.
12777 This is typically a complex variable. */
12779 static dw_loc_descr_ref
12780 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12782 dw_loc_descr_ref cc_loc_result
= NULL
;
12783 dw_loc_descr_ref x0_ref
12784 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12785 dw_loc_descr_ref x1_ref
12786 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12788 if (x0_ref
== 0 || x1_ref
== 0)
12791 cc_loc_result
= x0_ref
;
12792 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12794 add_loc_descr (&cc_loc_result
, x1_ref
);
12795 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12797 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12798 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12800 return cc_loc_result
;
12803 /* Return a descriptor that describes the concatenation of N
12806 static dw_loc_descr_ref
12807 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12810 dw_loc_descr_ref cc_loc_result
= NULL
;
12811 unsigned int n
= XVECLEN (concatn
, 0);
12813 for (i
= 0; i
< n
; ++i
)
12815 dw_loc_descr_ref ref
;
12816 rtx x
= XVECEXP (concatn
, 0, i
);
12818 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12822 add_loc_descr (&cc_loc_result
, ref
);
12823 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12826 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12827 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12829 return cc_loc_result
;
12832 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12833 for DEBUG_IMPLICIT_PTR RTL. */
12835 static dw_loc_descr_ref
12836 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12838 dw_loc_descr_ref ret
;
12843 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12844 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12845 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12846 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12847 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12848 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12851 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12852 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12853 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12857 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12858 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12863 /* Output a proper Dwarf location descriptor for a variable or parameter
12864 which is either allocated in a register or in a memory location. For a
12865 register, we just generate an OP_REG and the register number. For a
12866 memory location we provide a Dwarf postfix expression describing how to
12867 generate the (dynamic) address of the object onto the address stack.
12869 MODE is mode of the decl if this loc_descriptor is going to be used in
12870 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12871 allowed, VOIDmode otherwise.
12873 If we don't know how to describe it, return 0. */
12875 static dw_loc_descr_ref
12876 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12877 enum var_init_status initialized
)
12879 dw_loc_descr_ref loc_result
= NULL
;
12881 switch (GET_CODE (rtl
))
12884 /* The case of a subreg may arise when we have a local (register)
12885 variable or a formal (register) parameter which doesn't quite fill
12886 up an entire register. For now, just assume that it is
12887 legitimate to make the Dwarf info refer to the whole register which
12888 contains the given subreg. */
12889 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12890 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12891 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12897 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12901 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12902 GET_MODE (rtl
), initialized
);
12903 if (loc_result
== NULL
)
12904 loc_result
= tls_mem_loc_descriptor (rtl
);
12905 if (loc_result
== NULL
)
12907 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12908 if (new_rtl
!= rtl
)
12909 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
12914 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
12919 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
12924 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
12926 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
12927 if (GET_CODE (loc
) == EXPR_LIST
)
12928 loc
= XEXP (loc
, 0);
12929 loc_result
= loc_descriptor (loc
, mode
, initialized
);
12933 rtl
= XEXP (rtl
, 1);
12938 rtvec par_elems
= XVEC (rtl
, 0);
12939 int num_elem
= GET_NUM_ELEM (par_elems
);
12940 enum machine_mode mode
;
12943 /* Create the first one, so we have something to add to. */
12944 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
12945 VOIDmode
, initialized
);
12946 if (loc_result
== NULL
)
12948 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
12949 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12950 for (i
= 1; i
< num_elem
; i
++)
12952 dw_loc_descr_ref temp
;
12954 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
12955 VOIDmode
, initialized
);
12958 add_loc_descr (&loc_result
, temp
);
12959 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
12960 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12966 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
12967 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
12972 if (mode
== VOIDmode
)
12973 mode
= GET_MODE (rtl
);
12975 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12977 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12979 /* Note that a CONST_DOUBLE rtx could represent either an integer
12980 or a floating-point constant. A CONST_DOUBLE is used whenever
12981 the constant requires more than one word in order to be
12982 adequately represented. We output CONST_DOUBLEs as blocks. */
12983 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12984 GET_MODE_SIZE (mode
), 0);
12985 if (SCALAR_FLOAT_MODE_P (mode
))
12987 unsigned int length
= GET_MODE_SIZE (mode
);
12988 unsigned char *array
12989 = (unsigned char*) ggc_alloc_atomic (length
);
12991 insert_float (rtl
, array
);
12992 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12993 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12994 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12995 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12999 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13000 loc_result
->dw_loc_oprnd2
.v
.val_double
13001 = rtx_to_double_int (rtl
);
13007 if (mode
== VOIDmode
)
13008 mode
= GET_MODE (rtl
);
13010 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13012 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13013 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13014 unsigned char *array
= (unsigned char *)
13015 ggc_alloc_atomic (length
* elt_size
);
13019 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13020 switch (GET_MODE_CLASS (mode
))
13022 case MODE_VECTOR_INT
:
13023 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13025 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13026 double_int val
= rtx_to_double_int (elt
);
13028 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13029 insert_int (val
.to_shwi (), elt_size
, p
);
13032 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13033 insert_double (val
, p
);
13038 case MODE_VECTOR_FLOAT
:
13039 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13041 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13042 insert_float (elt
, p
);
13047 gcc_unreachable ();
13050 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13051 length
* elt_size
, 0);
13052 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13053 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13054 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13055 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13060 if (mode
== VOIDmode
13061 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13062 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13063 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13065 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13070 if (!const_ok_for_output (rtl
))
13073 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13074 && (dwarf_version
>= 4 || !dwarf_strict
))
13076 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13077 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13078 vec_safe_push (used_rtx_array
, rtl
);
13082 case DEBUG_IMPLICIT_PTR
:
13083 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13087 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13088 && CONST_INT_P (XEXP (rtl
, 1)))
13091 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13097 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13098 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13099 && dwarf_version
>= 4)
13100 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13102 /* Value expression. */
13103 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13105 add_loc_descr (&loc_result
,
13106 new_loc_descr (DW_OP_stack_value
, 0, 0));
13114 /* We need to figure out what section we should use as the base for the
13115 address ranges where a given location is valid.
13116 1. If this particular DECL has a section associated with it, use that.
13117 2. If this function has a section associated with it, use that.
13118 3. Otherwise, use the text section.
13119 XXX: If you split a variable across multiple sections, we won't notice. */
13121 static const char *
13122 secname_for_decl (const_tree decl
)
13124 const char *secname
;
13126 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13128 tree sectree
= DECL_SECTION_NAME (decl
);
13129 secname
= TREE_STRING_POINTER (sectree
);
13131 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13133 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13134 secname
= TREE_STRING_POINTER (sectree
);
13136 else if (cfun
&& in_cold_section_p
)
13137 secname
= crtl
->subsections
.cold_section_label
;
13139 secname
= text_section_label
;
13144 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13147 decl_by_reference_p (tree decl
)
13149 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13150 || TREE_CODE (decl
) == VAR_DECL
)
13151 && DECL_BY_REFERENCE (decl
));
13154 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13157 static dw_loc_descr_ref
13158 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13159 enum var_init_status initialized
)
13161 int have_address
= 0;
13162 dw_loc_descr_ref descr
;
13163 enum machine_mode mode
;
13165 if (want_address
!= 2)
13167 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13169 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13171 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13172 if (GET_CODE (varloc
) == EXPR_LIST
)
13173 varloc
= XEXP (varloc
, 0);
13174 mode
= GET_MODE (varloc
);
13175 if (MEM_P (varloc
))
13177 rtx addr
= XEXP (varloc
, 0);
13178 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13179 mode
, initialized
);
13184 rtx x
= avoid_constant_pool_reference (varloc
);
13186 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13191 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13198 if (GET_CODE (varloc
) == VAR_LOCATION
)
13199 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13201 mode
= DECL_MODE (loc
);
13202 descr
= loc_descriptor (varloc
, mode
, initialized
);
13209 if (want_address
== 2 && !have_address
13210 && (dwarf_version
>= 4 || !dwarf_strict
))
13212 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13214 expansion_failed (loc
, NULL_RTX
,
13215 "DWARF address size mismatch");
13218 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13221 /* Show if we can't fill the request for an address. */
13222 if (want_address
&& !have_address
)
13224 expansion_failed (loc
, NULL_RTX
,
13225 "Want address and only have value");
13229 /* If we've got an address and don't want one, dereference. */
13230 if (!want_address
&& have_address
)
13232 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13233 enum dwarf_location_atom op
;
13235 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13237 expansion_failed (loc
, NULL_RTX
,
13238 "DWARF address size mismatch");
13241 else if (size
== DWARF2_ADDR_SIZE
)
13244 op
= DW_OP_deref_size
;
13246 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13252 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13253 if it is not possible. */
13255 static dw_loc_descr_ref
13256 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13258 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13259 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13260 else if (dwarf_version
>= 3 || !dwarf_strict
)
13261 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13266 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13267 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13269 static dw_loc_descr_ref
13270 dw_sra_loc_expr (tree decl
, rtx loc
)
13273 unsigned int padsize
= 0;
13274 dw_loc_descr_ref descr
, *descr_tail
;
13275 unsigned HOST_WIDE_INT decl_size
;
13277 enum var_init_status initialized
;
13279 if (DECL_SIZE (decl
) == NULL
13280 || !host_integerp (DECL_SIZE (decl
), 1))
13283 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13285 descr_tail
= &descr
;
13287 for (p
= loc
; p
; p
= XEXP (p
, 1))
13289 unsigned int bitsize
= decl_piece_bitsize (p
);
13290 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13291 dw_loc_descr_ref cur_descr
;
13292 dw_loc_descr_ref
*tail
, last
= NULL
;
13293 unsigned int opsize
= 0;
13295 if (loc_note
== NULL_RTX
13296 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13298 padsize
+= bitsize
;
13301 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13302 varloc
= NOTE_VAR_LOCATION (loc_note
);
13303 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13304 if (cur_descr
== NULL
)
13306 padsize
+= bitsize
;
13310 /* Check that cur_descr either doesn't use
13311 DW_OP_*piece operations, or their sum is equal
13312 to bitsize. Otherwise we can't embed it. */
13313 for (tail
= &cur_descr
; *tail
!= NULL
;
13314 tail
= &(*tail
)->dw_loc_next
)
13315 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13317 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13321 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13323 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13327 if (last
!= NULL
&& opsize
!= bitsize
)
13329 padsize
+= bitsize
;
13333 /* If there is a hole, add DW_OP_*piece after empty DWARF
13334 expression, which means that those bits are optimized out. */
13337 if (padsize
> decl_size
)
13339 decl_size
-= padsize
;
13340 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13341 if (*descr_tail
== NULL
)
13343 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13346 *descr_tail
= cur_descr
;
13348 if (bitsize
> decl_size
)
13350 decl_size
-= bitsize
;
13353 HOST_WIDE_INT offset
= 0;
13354 if (GET_CODE (varloc
) == VAR_LOCATION
13355 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13357 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13358 if (GET_CODE (varloc
) == EXPR_LIST
)
13359 varloc
= XEXP (varloc
, 0);
13363 if (GET_CODE (varloc
) == CONST
13364 || GET_CODE (varloc
) == SIGN_EXTEND
13365 || GET_CODE (varloc
) == ZERO_EXTEND
)
13366 varloc
= XEXP (varloc
, 0);
13367 else if (GET_CODE (varloc
) == SUBREG
)
13368 varloc
= SUBREG_REG (varloc
);
13373 /* DW_OP_bit_size offset should be zero for register
13374 or implicit location descriptions and empty location
13375 descriptions, but for memory addresses needs big endian
13377 if (MEM_P (varloc
))
13379 unsigned HOST_WIDE_INT memsize
13380 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13381 if (memsize
!= bitsize
)
13383 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13384 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13386 if (memsize
< bitsize
)
13388 if (BITS_BIG_ENDIAN
)
13389 offset
= memsize
- bitsize
;
13393 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13394 if (*descr_tail
== NULL
)
13396 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13400 /* If there were any non-empty expressions, add padding till the end of
13402 if (descr
!= NULL
&& decl_size
!= 0)
13404 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13405 if (*descr_tail
== NULL
)
13411 /* Return the dwarf representation of the location list LOC_LIST of
13412 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13415 static dw_loc_list_ref
13416 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13418 const char *endname
, *secname
;
13420 enum var_init_status initialized
;
13421 struct var_loc_node
*node
;
13422 dw_loc_descr_ref descr
;
13423 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13424 dw_loc_list_ref list
= NULL
;
13425 dw_loc_list_ref
*listp
= &list
;
13427 /* Now that we know what section we are using for a base,
13428 actually construct the list of locations.
13429 The first location information is what is passed to the
13430 function that creates the location list, and the remaining
13431 locations just get added on to that list.
13432 Note that we only know the start address for a location
13433 (IE location changes), so to build the range, we use
13434 the range [current location start, next location start].
13435 This means we have to special case the last node, and generate
13436 a range of [last location start, end of function label]. */
13438 secname
= secname_for_decl (decl
);
13440 for (node
= loc_list
->first
; node
; node
= node
->next
)
13441 if (GET_CODE (node
->loc
) == EXPR_LIST
13442 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13444 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13446 /* This requires DW_OP_{,bit_}piece, which is not usable
13447 inside DWARF expressions. */
13448 if (want_address
!= 2)
13450 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13456 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13457 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13458 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13462 bool range_across_switch
= false;
13463 /* If section switch happens in between node->label
13464 and node->next->label (or end of function) and
13465 we can't emit it as a single entry list,
13466 emit two ranges, first one ending at the end
13467 of first partition and second one starting at the
13468 beginning of second partition. */
13469 if (node
== loc_list
->last_before_switch
13470 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13471 && current_function_decl
)
13473 endname
= cfun
->fde
->dw_fde_end
;
13474 range_across_switch
= true;
13476 /* The variable has a location between NODE->LABEL and
13477 NODE->NEXT->LABEL. */
13478 else if (node
->next
)
13479 endname
= node
->next
->label
;
13480 /* If the variable has a location at the last label
13481 it keeps its location until the end of function. */
13482 else if (!current_function_decl
)
13483 endname
= text_end_label
;
13486 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13487 current_function_funcdef_no
);
13488 endname
= ggc_strdup (label_id
);
13491 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13492 if (TREE_CODE (decl
) == PARM_DECL
13493 && node
== loc_list
->first
13494 && NOTE_P (node
->loc
)
13495 && strcmp (node
->label
, endname
) == 0)
13496 (*listp
)->force
= true;
13497 listp
= &(*listp
)->dw_loc_next
;
13499 if (range_across_switch
)
13501 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13502 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13505 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13506 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13507 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13510 gcc_assert (descr
);
13511 /* The variable has a location between NODE->LABEL and
13512 NODE->NEXT->LABEL. */
13514 endname
= node
->next
->label
;
13516 endname
= cfun
->fde
->dw_fde_second_end
;
13517 *listp
= new_loc_list (descr
,
13518 cfun
->fde
->dw_fde_second_begin
,
13520 listp
= &(*listp
)->dw_loc_next
;
13525 /* Try to avoid the overhead of a location list emitting a location
13526 expression instead, but only if we didn't have more than one
13527 location entry in the first place. If some entries were not
13528 representable, we don't want to pretend a single entry that was
13529 applies to the entire scope in which the variable is
13531 if (list
&& loc_list
->first
->next
)
13537 /* Return if the loc_list has only single element and thus can be represented
13538 as location description. */
13541 single_element_loc_list_p (dw_loc_list_ref list
)
13543 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13544 return !list
->ll_symbol
;
13547 /* To each location in list LIST add loc descr REF. */
13550 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13552 dw_loc_descr_ref copy
;
13553 add_loc_descr (&list
->expr
, ref
);
13554 list
= list
->dw_loc_next
;
13557 copy
= ggc_alloc_dw_loc_descr_node ();
13558 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13559 add_loc_descr (&list
->expr
, copy
);
13560 while (copy
->dw_loc_next
)
13562 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13563 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13564 copy
->dw_loc_next
= new_copy
;
13567 list
= list
->dw_loc_next
;
13571 /* Given two lists RET and LIST
13572 produce location list that is result of adding expression in LIST
13573 to expression in RET on each position in program.
13574 Might be destructive on both RET and LIST.
13576 TODO: We handle only simple cases of RET or LIST having at most one
13577 element. General case would inolve sorting the lists in program order
13578 and merging them that will need some additional work.
13579 Adding that will improve quality of debug info especially for SRA-ed
13583 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13592 if (!list
->dw_loc_next
)
13594 add_loc_descr_to_each (*ret
, list
->expr
);
13597 if (!(*ret
)->dw_loc_next
)
13599 add_loc_descr_to_each (list
, (*ret
)->expr
);
13603 expansion_failed (NULL_TREE
, NULL_RTX
,
13604 "Don't know how to merge two non-trivial"
13605 " location lists.\n");
13610 /* LOC is constant expression. Try a luck, look it up in constant
13611 pool and return its loc_descr of its address. */
13613 static dw_loc_descr_ref
13614 cst_pool_loc_descr (tree loc
)
13616 /* Get an RTL for this, if something has been emitted. */
13617 rtx rtl
= lookup_constant_def (loc
);
13619 if (!rtl
|| !MEM_P (rtl
))
13624 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13626 /* TODO: We might get more coverage if we was actually delaying expansion
13627 of all expressions till end of compilation when constant pools are fully
13629 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13631 expansion_failed (loc
, NULL_RTX
,
13632 "CST value in contant pool but not marked.");
13635 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13636 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13639 /* Return dw_loc_list representing address of addr_expr LOC
13640 by looking for inner INDIRECT_REF expression and turning
13641 it into simple arithmetics. */
13643 static dw_loc_list_ref
13644 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13647 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13648 enum machine_mode mode
;
13649 int unsignedp
, volatilep
= 0;
13650 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13652 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13653 &bitsize
, &bitpos
, &offset
, &mode
,
13654 &unsignedp
, &volatilep
, false);
13656 if (bitpos
% BITS_PER_UNIT
)
13658 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13661 if (!INDIRECT_REF_P (obj
))
13663 expansion_failed (obj
,
13664 NULL_RTX
, "no indirect ref in inner refrence");
13667 if (!offset
&& !bitpos
)
13668 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13670 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13671 && (dwarf_version
>= 4 || !dwarf_strict
))
13673 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13678 /* Variable offset. */
13679 list_ret1
= loc_list_from_tree (offset
, 0);
13680 if (list_ret1
== 0)
13682 add_loc_list (&list_ret
, list_ret1
);
13685 add_loc_descr_to_each (list_ret
,
13686 new_loc_descr (DW_OP_plus
, 0, 0));
13688 bytepos
= bitpos
/ BITS_PER_UNIT
;
13690 add_loc_descr_to_each (list_ret
,
13691 new_loc_descr (DW_OP_plus_uconst
,
13693 else if (bytepos
< 0)
13694 loc_list_plus_const (list_ret
, bytepos
);
13695 add_loc_descr_to_each (list_ret
,
13696 new_loc_descr (DW_OP_stack_value
, 0, 0));
13702 /* Generate Dwarf location list representing LOC.
13703 If WANT_ADDRESS is false, expression computing LOC will be computed
13704 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13705 if WANT_ADDRESS is 2, expression computing address useable in location
13706 will be returned (i.e. DW_OP_reg can be used
13707 to refer to register values). */
13709 static dw_loc_list_ref
13710 loc_list_from_tree (tree loc
, int want_address
)
13712 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13713 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13714 int have_address
= 0;
13715 enum dwarf_location_atom op
;
13717 /* ??? Most of the time we do not take proper care for sign/zero
13718 extending the values properly. Hopefully this won't be a real
13721 switch (TREE_CODE (loc
))
13724 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13727 case PLACEHOLDER_EXPR
:
13728 /* This case involves extracting fields from an object to determine the
13729 position of other fields. We don't try to encode this here. The
13730 only user of this is Ada, which encodes the needed information using
13731 the names of types. */
13732 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13736 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13737 /* There are no opcodes for these operations. */
13740 case PREINCREMENT_EXPR
:
13741 case PREDECREMENT_EXPR
:
13742 case POSTINCREMENT_EXPR
:
13743 case POSTDECREMENT_EXPR
:
13744 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13745 /* There are no opcodes for these operations. */
13749 /* If we already want an address, see if there is INDIRECT_REF inside
13750 e.g. for &this->field. */
13753 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13754 (loc
, want_address
== 2);
13757 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13758 && (ret
= cst_pool_loc_descr (loc
)))
13761 /* Otherwise, process the argument and look for the address. */
13762 if (!list_ret
&& !ret
)
13763 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13767 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13773 if (DECL_THREAD_LOCAL_P (loc
))
13776 enum dwarf_location_atom tls_op
;
13777 enum dtprel_bool dtprel
= dtprel_false
;
13779 if (targetm
.have_tls
)
13781 /* If this is not defined, we have no way to emit the
13783 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13786 /* The way DW_OP_GNU_push_tls_address is specified, we
13787 can only look up addresses of objects in the current
13788 module. We used DW_OP_addr as first op, but that's
13789 wrong, because DW_OP_addr is relocated by the debug
13790 info consumer, while DW_OP_GNU_push_tls_address
13791 operand shouldn't be. */
13792 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13794 dtprel
= dtprel_true
;
13795 tls_op
= DW_OP_GNU_push_tls_address
;
13799 if (!targetm
.emutls
.debug_form_tls_address
13800 || !(dwarf_version
>= 3 || !dwarf_strict
))
13802 /* We stuffed the control variable into the DECL_VALUE_EXPR
13803 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13804 no longer appear in gimple code. We used the control
13805 variable in specific so that we could pick it up here. */
13806 loc
= DECL_VALUE_EXPR (loc
);
13807 tls_op
= DW_OP_form_tls_address
;
13810 rtl
= rtl_for_decl_location (loc
);
13811 if (rtl
== NULL_RTX
)
13816 rtl
= XEXP (rtl
, 0);
13817 if (! CONSTANT_P (rtl
))
13820 ret
= new_addr_loc_descr (rtl
, dtprel
);
13821 ret1
= new_loc_descr (tls_op
, 0, 0);
13822 add_loc_descr (&ret
, ret1
);
13831 if (DECL_HAS_VALUE_EXPR_P (loc
))
13832 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13836 case FUNCTION_DECL
:
13839 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13841 if (loc_list
&& loc_list
->first
)
13843 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13844 have_address
= want_address
!= 0;
13847 rtl
= rtl_for_decl_location (loc
);
13848 if (rtl
== NULL_RTX
)
13850 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13853 else if (CONST_INT_P (rtl
))
13855 HOST_WIDE_INT val
= INTVAL (rtl
);
13856 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13857 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13858 ret
= int_loc_descriptor (val
);
13860 else if (GET_CODE (rtl
) == CONST_STRING
)
13862 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13865 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13866 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
13869 enum machine_mode mode
, mem_mode
;
13871 /* Certain constructs can only be represented at top-level. */
13872 if (want_address
== 2)
13874 ret
= loc_descriptor (rtl
, VOIDmode
,
13875 VAR_INIT_STATUS_INITIALIZED
);
13880 mode
= GET_MODE (rtl
);
13881 mem_mode
= VOIDmode
;
13885 mode
= get_address_mode (rtl
);
13886 rtl
= XEXP (rtl
, 0);
13889 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13890 VAR_INIT_STATUS_INITIALIZED
);
13893 expansion_failed (loc
, rtl
,
13894 "failed to produce loc descriptor for rtl");
13901 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
13905 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13909 case COMPOUND_EXPR
:
13910 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
13913 case VIEW_CONVERT_EXPR
:
13916 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
13918 case COMPONENT_REF
:
13919 case BIT_FIELD_REF
:
13921 case ARRAY_RANGE_REF
:
13922 case REALPART_EXPR
:
13923 case IMAGPART_EXPR
:
13926 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13927 enum machine_mode mode
;
13928 int unsignedp
, volatilep
= 0;
13930 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
13931 &unsignedp
, &volatilep
, false);
13933 gcc_assert (obj
!= loc
);
13935 list_ret
= loc_list_from_tree (obj
,
13937 && !bitpos
&& !offset
? 2 : 1);
13938 /* TODO: We can extract value of the small expression via shifting even
13939 for nonzero bitpos. */
13942 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
13944 expansion_failed (loc
, NULL_RTX
,
13945 "bitfield access");
13949 if (offset
!= NULL_TREE
)
13951 /* Variable offset. */
13952 list_ret1
= loc_list_from_tree (offset
, 0);
13953 if (list_ret1
== 0)
13955 add_loc_list (&list_ret
, list_ret1
);
13958 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
13961 bytepos
= bitpos
/ BITS_PER_UNIT
;
13963 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
13964 else if (bytepos
< 0)
13965 loc_list_plus_const (list_ret
, bytepos
);
13972 if ((want_address
|| !host_integerp (loc
, 0))
13973 && (ret
= cst_pool_loc_descr (loc
)))
13975 else if (want_address
== 2
13976 && host_integerp (loc
, 0)
13977 && (ret
= address_of_int_loc_descriptor
13978 (int_size_in_bytes (TREE_TYPE (loc
)),
13979 tree_low_cst (loc
, 0))))
13981 else if (host_integerp (loc
, 0))
13982 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
13985 expansion_failed (loc
, NULL_RTX
,
13986 "Integer operand is not host integer");
13995 if ((ret
= cst_pool_loc_descr (loc
)))
13998 /* We can construct small constants here using int_loc_descriptor. */
13999 expansion_failed (loc
, NULL_RTX
,
14000 "constructor or constant not in constant pool");
14003 case TRUTH_AND_EXPR
:
14004 case TRUTH_ANDIF_EXPR
:
14009 case TRUTH_XOR_EXPR
:
14014 case TRUTH_OR_EXPR
:
14015 case TRUTH_ORIF_EXPR
:
14020 case FLOOR_DIV_EXPR
:
14021 case CEIL_DIV_EXPR
:
14022 case ROUND_DIV_EXPR
:
14023 case TRUNC_DIV_EXPR
:
14024 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14033 case FLOOR_MOD_EXPR
:
14034 case CEIL_MOD_EXPR
:
14035 case ROUND_MOD_EXPR
:
14036 case TRUNC_MOD_EXPR
:
14037 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14042 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14043 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14044 if (list_ret
== 0 || list_ret1
== 0)
14047 add_loc_list (&list_ret
, list_ret1
);
14050 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14051 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14052 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14053 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14054 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14066 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14069 case POINTER_PLUS_EXPR
:
14071 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14073 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14077 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14085 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14092 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14099 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14106 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14121 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14122 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14123 if (list_ret
== 0 || list_ret1
== 0)
14126 add_loc_list (&list_ret
, list_ret1
);
14129 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14132 case TRUTH_NOT_EXPR
:
14146 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14150 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14156 const enum tree_code code
=
14157 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14159 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14160 build2 (code
, integer_type_node
,
14161 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14162 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14165 /* ... fall through ... */
14169 dw_loc_descr_ref lhs
14170 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14171 dw_loc_list_ref rhs
14172 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14173 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14175 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14176 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14179 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14180 add_loc_descr_to_each (list_ret
, bra_node
);
14182 add_loc_list (&list_ret
, rhs
);
14183 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14184 add_loc_descr_to_each (list_ret
, jump_node
);
14186 add_loc_descr_to_each (list_ret
, lhs
);
14187 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14188 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14190 /* ??? Need a node to point the skip at. Use a nop. */
14191 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14192 add_loc_descr_to_each (list_ret
, tmp
);
14193 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14194 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14198 case FIX_TRUNC_EXPR
:
14202 /* Leave front-end specific codes as simply unknown. This comes
14203 up, for instance, with the C STMT_EXPR. */
14204 if ((unsigned int) TREE_CODE (loc
)
14205 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14207 expansion_failed (loc
, NULL_RTX
,
14208 "language specific tree node");
14212 #ifdef ENABLE_CHECKING
14213 /* Otherwise this is a generic code; we should just lists all of
14214 these explicitly. We forgot one. */
14215 gcc_unreachable ();
14217 /* In a release build, we want to degrade gracefully: better to
14218 generate incomplete debugging information than to crash. */
14223 if (!ret
&& !list_ret
)
14226 if (want_address
== 2 && !have_address
14227 && (dwarf_version
>= 4 || !dwarf_strict
))
14229 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14231 expansion_failed (loc
, NULL_RTX
,
14232 "DWARF address size mismatch");
14236 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14238 add_loc_descr_to_each (list_ret
,
14239 new_loc_descr (DW_OP_stack_value
, 0, 0));
14242 /* Show if we can't fill the request for an address. */
14243 if (want_address
&& !have_address
)
14245 expansion_failed (loc
, NULL_RTX
,
14246 "Want address and only have value");
14250 gcc_assert (!ret
|| !list_ret
);
14252 /* If we've got an address and don't want one, dereference. */
14253 if (!want_address
&& have_address
)
14255 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14257 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14259 expansion_failed (loc
, NULL_RTX
,
14260 "DWARF address size mismatch");
14263 else if (size
== DWARF2_ADDR_SIZE
)
14266 op
= DW_OP_deref_size
;
14269 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14271 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14274 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14279 /* Same as above but return only single location expression. */
14280 static dw_loc_descr_ref
14281 loc_descriptor_from_tree (tree loc
, int want_address
)
14283 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14286 if (ret
->dw_loc_next
)
14288 expansion_failed (loc
, NULL_RTX
,
14289 "Location list where only loc descriptor needed");
14295 /* Given a value, round it up to the lowest multiple of `boundary'
14296 which is not less than the value itself. */
14298 static inline HOST_WIDE_INT
14299 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14301 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14304 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14305 pointer to the declared type for the relevant field variable, or return
14306 `integer_type_node' if the given node turns out to be an
14307 ERROR_MARK node. */
14310 field_type (const_tree decl
)
14314 if (TREE_CODE (decl
) == ERROR_MARK
)
14315 return integer_type_node
;
14317 type
= DECL_BIT_FIELD_TYPE (decl
);
14318 if (type
== NULL_TREE
)
14319 type
= TREE_TYPE (decl
);
14324 /* Given a pointer to a tree node, return the alignment in bits for
14325 it, or else return BITS_PER_WORD if the node actually turns out to
14326 be an ERROR_MARK node. */
14328 static inline unsigned
14329 simple_type_align_in_bits (const_tree type
)
14331 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14334 static inline unsigned
14335 simple_decl_align_in_bits (const_tree decl
)
14337 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14340 /* Return the result of rounding T up to ALIGN. */
14342 static inline double_int
14343 round_up_to_align (double_int t
, unsigned int align
)
14345 double_int alignd
= double_int::from_uhwi (align
);
14347 t
+= double_int_minus_one
;
14348 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14353 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14354 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14355 or return 0 if we are unable to determine what that offset is, either
14356 because the argument turns out to be a pointer to an ERROR_MARK node, or
14357 because the offset is actually variable. (We can't handle the latter case
14360 static HOST_WIDE_INT
14361 field_byte_offset (const_tree decl
)
14363 double_int object_offset_in_bits
;
14364 double_int object_offset_in_bytes
;
14365 double_int bitpos_int
;
14367 if (TREE_CODE (decl
) == ERROR_MARK
)
14370 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14372 /* We cannot yet cope with fields whose positions are variable, so
14373 for now, when we see such things, we simply return 0. Someday, we may
14374 be able to handle such cases, but it will be damn difficult. */
14375 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14378 bitpos_int
= tree_to_double_int (bit_position (decl
));
14380 #ifdef PCC_BITFIELD_TYPE_MATTERS
14381 if (PCC_BITFIELD_TYPE_MATTERS
)
14384 tree field_size_tree
;
14385 double_int deepest_bitpos
;
14386 double_int field_size_in_bits
;
14387 unsigned int type_align_in_bits
;
14388 unsigned int decl_align_in_bits
;
14389 double_int type_size_in_bits
;
14391 type
= field_type (decl
);
14392 type_size_in_bits
= double_int_type_size_in_bits (type
);
14393 type_align_in_bits
= simple_type_align_in_bits (type
);
14395 field_size_tree
= DECL_SIZE (decl
);
14397 /* The size could be unspecified if there was an error, or for
14398 a flexible array member. */
14399 if (!field_size_tree
)
14400 field_size_tree
= bitsize_zero_node
;
14402 /* If the size of the field is not constant, use the type size. */
14403 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14404 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14406 field_size_in_bits
= type_size_in_bits
;
14408 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14410 /* The GCC front-end doesn't make any attempt to keep track of the
14411 starting bit offset (relative to the start of the containing
14412 structure type) of the hypothetical "containing object" for a
14413 bit-field. Thus, when computing the byte offset value for the
14414 start of the "containing object" of a bit-field, we must deduce
14415 this information on our own. This can be rather tricky to do in
14416 some cases. For example, handling the following structure type
14417 definition when compiling for an i386/i486 target (which only
14418 aligns long long's to 32-bit boundaries) can be very tricky:
14420 struct S { int field1; long long field2:31; };
14422 Fortunately, there is a simple rule-of-thumb which can be used
14423 in such cases. When compiling for an i386/i486, GCC will
14424 allocate 8 bytes for the structure shown above. It decides to
14425 do this based upon one simple rule for bit-field allocation.
14426 GCC allocates each "containing object" for each bit-field at
14427 the first (i.e. lowest addressed) legitimate alignment boundary
14428 (based upon the required minimum alignment for the declared
14429 type of the field) which it can possibly use, subject to the
14430 condition that there is still enough available space remaining
14431 in the containing object (when allocated at the selected point)
14432 to fully accommodate all of the bits of the bit-field itself.
14434 This simple rule makes it obvious why GCC allocates 8 bytes for
14435 each object of the structure type shown above. When looking
14436 for a place to allocate the "containing object" for `field2',
14437 the compiler simply tries to allocate a 64-bit "containing
14438 object" at each successive 32-bit boundary (starting at zero)
14439 until it finds a place to allocate that 64- bit field such that
14440 at least 31 contiguous (and previously unallocated) bits remain
14441 within that selected 64 bit field. (As it turns out, for the
14442 example above, the compiler finds it is OK to allocate the
14443 "containing object" 64-bit field at bit-offset zero within the
14446 Here we attempt to work backwards from the limited set of facts
14447 we're given, and we try to deduce from those facts, where GCC
14448 must have believed that the containing object started (within
14449 the structure type). The value we deduce is then used (by the
14450 callers of this routine) to generate DW_AT_location and
14451 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14452 the case of DW_AT_location, regular fields as well). */
14454 /* Figure out the bit-distance from the start of the structure to
14455 the "deepest" bit of the bit-field. */
14456 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14458 /* This is the tricky part. Use some fancy footwork to deduce
14459 where the lowest addressed bit of the containing object must
14461 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14463 /* Round up to type_align by default. This works best for
14465 object_offset_in_bits
14466 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14468 if (object_offset_in_bits
.ugt (bitpos_int
))
14470 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14472 /* Round up to decl_align instead. */
14473 object_offset_in_bits
14474 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14478 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14479 object_offset_in_bits
= bitpos_int
;
14481 object_offset_in_bytes
14482 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14483 true, TRUNC_DIV_EXPR
);
14484 return object_offset_in_bytes
.to_shwi ();
14487 /* The following routines define various Dwarf attributes and any data
14488 associated with them. */
14490 /* Add a location description attribute value to a DIE.
14492 This emits location attributes suitable for whole variables and
14493 whole parameters. Note that the location attributes for struct fields are
14494 generated by the routine `data_member_location_attribute' below. */
14497 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14498 dw_loc_list_ref descr
)
14502 if (single_element_loc_list_p (descr
))
14503 add_AT_loc (die
, attr_kind
, descr
->expr
);
14505 add_AT_loc_list (die
, attr_kind
, descr
);
14508 /* Add DW_AT_accessibility attribute to DIE if needed. */
14511 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14513 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14514 children, otherwise the default is DW_ACCESS_public. In DWARF2
14515 the default has always been DW_ACCESS_public. */
14516 if (TREE_PROTECTED (decl
))
14517 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14518 else if (TREE_PRIVATE (decl
))
14520 if (dwarf_version
== 2
14521 || die
->die_parent
== NULL
14522 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14523 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14525 else if (dwarf_version
> 2
14527 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14528 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14531 /* Attach the specialized form of location attribute used for data members of
14532 struct and union types. In the special case of a FIELD_DECL node which
14533 represents a bit-field, the "offset" part of this special location
14534 descriptor must indicate the distance in bytes from the lowest-addressed
14535 byte of the containing struct or union type to the lowest-addressed byte of
14536 the "containing object" for the bit-field. (See the `field_byte_offset'
14539 For any given bit-field, the "containing object" is a hypothetical object
14540 (of some integral or enum type) within which the given bit-field lives. The
14541 type of this hypothetical "containing object" is always the same as the
14542 declared type of the individual bit-field itself (for GCC anyway... the
14543 DWARF spec doesn't actually mandate this). Note that it is the size (in
14544 bytes) of the hypothetical "containing object" which will be given in the
14545 DW_AT_byte_size attribute for this bit-field. (See the
14546 `byte_size_attribute' function below.) It is also used when calculating the
14547 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14548 function below.) */
14551 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14553 HOST_WIDE_INT offset
;
14554 dw_loc_descr_ref loc_descr
= 0;
14556 if (TREE_CODE (decl
) == TREE_BINFO
)
14558 /* We're working on the TAG_inheritance for a base class. */
14559 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14561 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14562 aren't at a fixed offset from all (sub)objects of the same
14563 type. We need to extract the appropriate offset from our
14564 vtable. The following dwarf expression means
14566 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14568 This is specific to the V3 ABI, of course. */
14570 dw_loc_descr_ref tmp
;
14572 /* Make a copy of the object address. */
14573 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14574 add_loc_descr (&loc_descr
, tmp
);
14576 /* Extract the vtable address. */
14577 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14578 add_loc_descr (&loc_descr
, tmp
);
14580 /* Calculate the address of the offset. */
14581 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14582 gcc_assert (offset
< 0);
14584 tmp
= int_loc_descriptor (-offset
);
14585 add_loc_descr (&loc_descr
, tmp
);
14586 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14587 add_loc_descr (&loc_descr
, tmp
);
14589 /* Extract the offset. */
14590 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14591 add_loc_descr (&loc_descr
, tmp
);
14593 /* Add it to the object address. */
14594 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14595 add_loc_descr (&loc_descr
, tmp
);
14598 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14601 offset
= field_byte_offset (decl
);
14605 if (dwarf_version
> 2)
14607 /* Don't need to output a location expression, just the constant. */
14609 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14611 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14616 enum dwarf_location_atom op
;
14618 /* The DWARF2 standard says that we should assume that the structure
14619 address is already on the stack, so we can specify a structure
14620 field address by using DW_OP_plus_uconst. */
14621 op
= DW_OP_plus_uconst
;
14622 loc_descr
= new_loc_descr (op
, offset
, 0);
14626 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14629 /* Writes integer values to dw_vec_const array. */
14632 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14636 *dest
++ = val
& 0xff;
14642 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14644 static HOST_WIDE_INT
14645 extract_int (const unsigned char *src
, unsigned int size
)
14647 HOST_WIDE_INT val
= 0;
14653 val
|= *--src
& 0xff;
14659 /* Writes double_int values to dw_vec_const array. */
14662 insert_double (double_int val
, unsigned char *dest
)
14664 unsigned char *p0
= dest
;
14665 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14667 if (WORDS_BIG_ENDIAN
)
14673 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14674 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14677 /* Writes floating point values to dw_vec_const array. */
14680 insert_float (const_rtx rtl
, unsigned char *array
)
14682 REAL_VALUE_TYPE rv
;
14686 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14687 real_to_target (val
, &rv
, GET_MODE (rtl
));
14689 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14690 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14692 insert_int (val
[i
], 4, array
);
14697 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14698 does not have a "location" either in memory or in a register. These
14699 things can arise in GNU C when a constant is passed as an actual parameter
14700 to an inlined function. They can also arise in C++ where declared
14701 constants do not necessarily get memory "homes". */
14704 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14706 switch (GET_CODE (rtl
))
14710 HOST_WIDE_INT val
= INTVAL (rtl
);
14713 add_AT_int (die
, DW_AT_const_value
, val
);
14715 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14720 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14721 floating-point constant. A CONST_DOUBLE is used whenever the
14722 constant requires more than one word in order to be adequately
14725 enum machine_mode mode
= GET_MODE (rtl
);
14727 if (SCALAR_FLOAT_MODE_P (mode
))
14729 unsigned int length
= GET_MODE_SIZE (mode
);
14730 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14732 insert_float (rtl
, array
);
14733 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14736 add_AT_double (die
, DW_AT_const_value
,
14737 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14743 enum machine_mode mode
= GET_MODE (rtl
);
14744 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14745 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14746 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14747 (length
* elt_size
);
14751 switch (GET_MODE_CLASS (mode
))
14753 case MODE_VECTOR_INT
:
14754 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14756 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14757 double_int val
= rtx_to_double_int (elt
);
14759 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14760 insert_int (val
.to_shwi (), elt_size
, p
);
14763 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14764 insert_double (val
, p
);
14769 case MODE_VECTOR_FLOAT
:
14770 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14772 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14773 insert_float (elt
, p
);
14778 gcc_unreachable ();
14781 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14786 if (dwarf_version
>= 4 || !dwarf_strict
)
14788 dw_loc_descr_ref loc_result
;
14789 resolve_one_addr (&rtl
, NULL
);
14791 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14792 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14793 add_AT_loc (die
, DW_AT_location
, loc_result
);
14794 vec_safe_push (used_rtx_array
, rtl
);
14800 if (CONSTANT_P (XEXP (rtl
, 0)))
14801 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14804 if (!const_ok_for_output (rtl
))
14807 if (dwarf_version
>= 4 || !dwarf_strict
)
14812 /* In cases where an inlined instance of an inline function is passed
14813 the address of an `auto' variable (which is local to the caller) we
14814 can get a situation where the DECL_RTL of the artificial local
14815 variable (for the inlining) which acts as a stand-in for the
14816 corresponding formal parameter (of the inline function) will look
14817 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14818 exactly a compile-time constant expression, but it isn't the address
14819 of the (artificial) local variable either. Rather, it represents the
14820 *value* which the artificial local variable always has during its
14821 lifetime. We currently have no way to represent such quasi-constant
14822 values in Dwarf, so for now we just punt and generate nothing. */
14830 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14831 && MEM_READONLY_P (rtl
)
14832 && GET_MODE (rtl
) == BLKmode
)
14834 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14840 /* No other kinds of rtx should be possible here. */
14841 gcc_unreachable ();
14846 /* Determine whether the evaluation of EXPR references any variables
14847 or functions which aren't otherwise used (and therefore may not be
14850 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14851 void * data ATTRIBUTE_UNUSED
)
14853 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14854 *walk_subtrees
= 0;
14856 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14857 && ! TREE_ASM_WRITTEN (*tp
))
14859 /* ??? The C++ FE emits debug information for using decls, so
14860 putting gcc_unreachable here falls over. See PR31899. For now
14861 be conservative. */
14862 else if (!cgraph_global_info_ready
14863 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14865 else if (TREE_CODE (*tp
) == VAR_DECL
)
14867 struct varpool_node
*node
= varpool_get_node (*tp
);
14868 if (!node
|| !node
->analyzed
)
14871 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14872 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14874 /* The call graph machinery must have finished analyzing,
14875 optimizing and gimplifying the CU by now.
14876 So if *TP has no call graph node associated
14877 to it, it means *TP will not be emitted. */
14878 if (!cgraph_get_node (*tp
))
14881 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14887 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14888 for use in a later add_const_value_attribute call. */
14891 rtl_for_decl_init (tree init
, tree type
)
14893 rtx rtl
= NULL_RTX
;
14897 /* If a variable is initialized with a string constant without embedded
14898 zeros, build CONST_STRING. */
14899 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14901 tree enttype
= TREE_TYPE (type
);
14902 tree domain
= TYPE_DOMAIN (type
);
14903 enum machine_mode mode
= TYPE_MODE (enttype
);
14905 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
14907 && integer_zerop (TYPE_MIN_VALUE (domain
))
14908 && compare_tree_int (TYPE_MAX_VALUE (domain
),
14909 TREE_STRING_LENGTH (init
) - 1) == 0
14910 && ((size_t) TREE_STRING_LENGTH (init
)
14911 == strlen (TREE_STRING_POINTER (init
)) + 1))
14913 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
14914 ggc_strdup (TREE_STRING_POINTER (init
)));
14915 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
14916 MEM_READONLY_P (rtl
) = 1;
14919 /* Other aggregates, and complex values, could be represented using
14921 else if (AGGREGATE_TYPE_P (type
)
14922 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
14923 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
14924 || TREE_CODE (type
) == COMPLEX_TYPE
)
14926 /* Vectors only work if their mode is supported by the target.
14927 FIXME: generic vectors ought to work too. */
14928 else if (TREE_CODE (type
) == VECTOR_TYPE
14929 && !VECTOR_MODE_P (TYPE_MODE (type
)))
14931 /* If the initializer is something that we know will expand into an
14932 immediate RTL constant, expand it now. We must be careful not to
14933 reference variables which won't be output. */
14934 else if (initializer_constant_valid_p (init
, type
)
14935 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
14937 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14939 if (TREE_CODE (type
) == VECTOR_TYPE
)
14940 switch (TREE_CODE (init
))
14945 if (TREE_CONSTANT (init
))
14947 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
14948 bool constant_p
= true;
14950 unsigned HOST_WIDE_INT ix
;
14952 /* Even when ctor is constant, it might contain non-*_CST
14953 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14954 belong into VECTOR_CST nodes. */
14955 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
14956 if (!CONSTANT_CLASS_P (value
))
14958 constant_p
= false;
14964 init
= build_vector_from_ctor (type
, elts
);
14974 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
14976 /* If expand_expr returns a MEM, it wasn't immediate. */
14977 gcc_assert (!rtl
|| !MEM_P (rtl
));
14983 /* Generate RTL for the variable DECL to represent its location. */
14986 rtl_for_decl_location (tree decl
)
14990 /* Here we have to decide where we are going to say the parameter "lives"
14991 (as far as the debugger is concerned). We only have a couple of
14992 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14994 DECL_RTL normally indicates where the parameter lives during most of the
14995 activation of the function. If optimization is enabled however, this
14996 could be either NULL or else a pseudo-reg. Both of those cases indicate
14997 that the parameter doesn't really live anywhere (as far as the code
14998 generation parts of GCC are concerned) during most of the function's
14999 activation. That will happen (for example) if the parameter is never
15000 referenced within the function.
15002 We could just generate a location descriptor here for all non-NULL
15003 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15004 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15005 where DECL_RTL is NULL or is a pseudo-reg.
15007 Note however that we can only get away with using DECL_INCOMING_RTL as
15008 a backup substitute for DECL_RTL in certain limited cases. In cases
15009 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15010 we can be sure that the parameter was passed using the same type as it is
15011 declared to have within the function, and that its DECL_INCOMING_RTL
15012 points us to a place where a value of that type is passed.
15014 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15015 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15016 because in these cases DECL_INCOMING_RTL points us to a value of some
15017 type which is *different* from the type of the parameter itself. Thus,
15018 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15019 such cases, the debugger would end up (for example) trying to fetch a
15020 `float' from a place which actually contains the first part of a
15021 `double'. That would lead to really incorrect and confusing
15022 output at debug-time.
15024 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15025 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15026 are a couple of exceptions however. On little-endian machines we can
15027 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15028 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15029 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15030 when (on a little-endian machine) a non-prototyped function has a
15031 parameter declared to be of type `short' or `char'. In such cases,
15032 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15033 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15034 passed `int' value. If the debugger then uses that address to fetch
15035 a `short' or a `char' (on a little-endian machine) the result will be
15036 the correct data, so we allow for such exceptional cases below.
15038 Note that our goal here is to describe the place where the given formal
15039 parameter lives during most of the function's activation (i.e. between the
15040 end of the prologue and the start of the epilogue). We'll do that as best
15041 as we can. Note however that if the given formal parameter is modified
15042 sometime during the execution of the function, then a stack backtrace (at
15043 debug-time) will show the function as having been called with the *new*
15044 value rather than the value which was originally passed in. This happens
15045 rarely enough that it is not a major problem, but it *is* a problem, and
15046 I'd like to fix it.
15048 A future version of dwarf2out.c may generate two additional attributes for
15049 any given DW_TAG_formal_parameter DIE which will describe the "passed
15050 type" and the "passed location" for the given formal parameter in addition
15051 to the attributes we now generate to indicate the "declared type" and the
15052 "active location" for each parameter. This additional set of attributes
15053 could be used by debuggers for stack backtraces. Separately, note that
15054 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15055 This happens (for example) for inlined-instances of inline function formal
15056 parameters which are never referenced. This really shouldn't be
15057 happening. All PARM_DECL nodes should get valid non-NULL
15058 DECL_INCOMING_RTL values. FIXME. */
15060 /* Use DECL_RTL as the "location" unless we find something better. */
15061 rtl
= DECL_RTL_IF_SET (decl
);
15063 /* When generating abstract instances, ignore everything except
15064 constants, symbols living in memory, and symbols living in
15065 fixed registers. */
15066 if (! reload_completed
)
15069 && (CONSTANT_P (rtl
)
15071 && CONSTANT_P (XEXP (rtl
, 0)))
15073 && TREE_CODE (decl
) == VAR_DECL
15074 && TREE_STATIC (decl
))))
15076 rtl
= targetm
.delegitimize_address (rtl
);
15081 else if (TREE_CODE (decl
) == PARM_DECL
)
15083 if (rtl
== NULL_RTX
15084 || is_pseudo_reg (rtl
)
15086 && is_pseudo_reg (XEXP (rtl
, 0))
15087 && DECL_INCOMING_RTL (decl
)
15088 && MEM_P (DECL_INCOMING_RTL (decl
))
15089 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15091 tree declared_type
= TREE_TYPE (decl
);
15092 tree passed_type
= DECL_ARG_TYPE (decl
);
15093 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15094 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15096 /* This decl represents a formal parameter which was optimized out.
15097 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15098 all cases where (rtl == NULL_RTX) just below. */
15099 if (dmode
== pmode
)
15100 rtl
= DECL_INCOMING_RTL (decl
);
15101 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15102 && SCALAR_INT_MODE_P (dmode
)
15103 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15104 && DECL_INCOMING_RTL (decl
))
15106 rtx inc
= DECL_INCOMING_RTL (decl
);
15109 else if (MEM_P (inc
))
15111 if (BYTES_BIG_ENDIAN
)
15112 rtl
= adjust_address_nv (inc
, dmode
,
15113 GET_MODE_SIZE (pmode
)
15114 - GET_MODE_SIZE (dmode
));
15121 /* If the parm was passed in registers, but lives on the stack, then
15122 make a big endian correction if the mode of the type of the
15123 parameter is not the same as the mode of the rtl. */
15124 /* ??? This is the same series of checks that are made in dbxout.c before
15125 we reach the big endian correction code there. It isn't clear if all
15126 of these checks are necessary here, but keeping them all is the safe
15128 else if (MEM_P (rtl
)
15129 && XEXP (rtl
, 0) != const0_rtx
15130 && ! CONSTANT_P (XEXP (rtl
, 0))
15131 /* Not passed in memory. */
15132 && !MEM_P (DECL_INCOMING_RTL (decl
))
15133 /* Not passed by invisible reference. */
15134 && (!REG_P (XEXP (rtl
, 0))
15135 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15136 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15137 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15138 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15141 /* Big endian correction check. */
15142 && BYTES_BIG_ENDIAN
15143 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15144 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15147 enum machine_mode addr_mode
= get_address_mode (rtl
);
15148 int offset
= (UNITS_PER_WORD
15149 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15151 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15152 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15155 else if (TREE_CODE (decl
) == VAR_DECL
15158 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15159 && BYTES_BIG_ENDIAN
)
15161 enum machine_mode addr_mode
= get_address_mode (rtl
);
15162 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15163 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15165 /* If a variable is declared "register" yet is smaller than
15166 a register, then if we store the variable to memory, it
15167 looks like we're storing a register-sized value, when in
15168 fact we are not. We need to adjust the offset of the
15169 storage location to reflect the actual value's bytes,
15170 else gdb will not be able to display it. */
15172 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15173 plus_constant (addr_mode
, XEXP (rtl
, 0),
15177 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15178 and will have been substituted directly into all expressions that use it.
15179 C does not have such a concept, but C++ and other languages do. */
15180 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15181 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15184 rtl
= targetm
.delegitimize_address (rtl
);
15186 /* If we don't look past the constant pool, we risk emitting a
15187 reference to a constant pool entry that isn't referenced from
15188 code, and thus is not emitted. */
15190 rtl
= avoid_constant_pool_reference (rtl
);
15192 /* Try harder to get a rtl. If this symbol ends up not being emitted
15193 in the current CU, resolve_addr will remove the expression referencing
15195 if (rtl
== NULL_RTX
15196 && TREE_CODE (decl
) == VAR_DECL
15197 && !DECL_EXTERNAL (decl
)
15198 && TREE_STATIC (decl
)
15199 && DECL_NAME (decl
)
15200 && !DECL_HARD_REGISTER (decl
)
15201 && DECL_MODE (decl
) != VOIDmode
)
15203 rtl
= make_decl_rtl_for_debug (decl
);
15205 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15206 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15213 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15214 returned. If so, the decl for the COMMON block is returned, and the
15215 value is the offset into the common block for the symbol. */
15218 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15220 tree val_expr
, cvar
;
15221 enum machine_mode mode
;
15222 HOST_WIDE_INT bitsize
, bitpos
;
15224 int unsignedp
, volatilep
= 0;
15226 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15227 it does not have a value (the offset into the common area), or if it
15228 is thread local (as opposed to global) then it isn't common, and shouldn't
15229 be handled as such. */
15230 if (TREE_CODE (decl
) != VAR_DECL
15231 || !TREE_STATIC (decl
)
15232 || !DECL_HAS_VALUE_EXPR_P (decl
)
15236 val_expr
= DECL_VALUE_EXPR (decl
);
15237 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15240 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15241 &mode
, &unsignedp
, &volatilep
, true);
15243 if (cvar
== NULL_TREE
15244 || TREE_CODE (cvar
) != VAR_DECL
15245 || DECL_ARTIFICIAL (cvar
)
15246 || !TREE_PUBLIC (cvar
))
15250 if (offset
!= NULL
)
15252 if (!host_integerp (offset
, 0))
15254 *value
= tree_low_cst (offset
, 0);
15257 *value
+= bitpos
/ BITS_PER_UNIT
;
15262 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15263 data attribute for a variable or a parameter. We generate the
15264 DW_AT_const_value attribute only in those cases where the given variable
15265 or parameter does not have a true "location" either in memory or in a
15266 register. This can happen (for example) when a constant is passed as an
15267 actual argument in a call to an inline function. (It's possible that
15268 these things can crop up in other ways also.) Note that one type of
15269 constant value which can be passed into an inlined function is a constant
15270 pointer. This can happen for example if an actual argument in an inlined
15271 function call evaluates to a compile-time constant address.
15273 CACHE_P is true if it is worth caching the location list for DECL,
15274 so that future calls can reuse it rather than regenerate it from scratch.
15275 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15276 since we will need to refer to them each time the function is inlined. */
15279 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15280 enum dwarf_attribute attr
)
15283 dw_loc_list_ref list
;
15284 var_loc_list
*loc_list
;
15285 cached_dw_loc_list
*cache
;
15288 if (TREE_CODE (decl
) == ERROR_MARK
)
15291 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15292 || TREE_CODE (decl
) == RESULT_DECL
);
15294 /* Try to get some constant RTL for this decl, and use that as the value of
15297 rtl
= rtl_for_decl_location (decl
);
15298 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15299 && add_const_value_attribute (die
, rtl
))
15302 /* See if we have single element location list that is equivalent to
15303 a constant value. That way we are better to use add_const_value_attribute
15304 rather than expanding constant value equivalent. */
15305 loc_list
= lookup_decl_loc (decl
);
15308 && loc_list
->first
->next
== NULL
15309 && NOTE_P (loc_list
->first
->loc
)
15310 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15311 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15313 struct var_loc_node
*node
;
15315 node
= loc_list
->first
;
15316 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15317 if (GET_CODE (rtl
) == EXPR_LIST
)
15318 rtl
= XEXP (rtl
, 0);
15319 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15320 && add_const_value_attribute (die
, rtl
))
15323 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15324 list several times. See if we've already cached the contents. */
15326 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15330 cache
= (cached_dw_loc_list
*)
15331 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15333 list
= cache
->loc_list
;
15337 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15338 /* It is usually worth caching this result if the decl is from
15339 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15340 if (cache_p
&& list
&& list
->dw_loc_next
)
15342 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15343 DECL_UID (decl
), INSERT
);
15344 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15345 cache
->decl_id
= DECL_UID (decl
);
15346 cache
->loc_list
= list
;
15352 add_AT_location_description (die
, attr
, list
);
15355 /* None of that worked, so it must not really have a location;
15356 try adding a constant value attribute from the DECL_INITIAL. */
15357 return tree_add_const_value_attribute_for_decl (die
, decl
);
15360 /* Add VARIABLE and DIE into deferred locations list. */
15363 defer_location (tree variable
, dw_die_ref die
)
15365 deferred_locations entry
;
15366 entry
.variable
= variable
;
15368 vec_safe_push (deferred_locations_list
, entry
);
15371 /* Helper function for tree_add_const_value_attribute. Natively encode
15372 initializer INIT into an array. Return true if successful. */
15375 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15379 if (init
== NULL_TREE
)
15383 switch (TREE_CODE (init
))
15386 type
= TREE_TYPE (init
);
15387 if (TREE_CODE (type
) == ARRAY_TYPE
)
15389 tree enttype
= TREE_TYPE (type
);
15390 enum machine_mode mode
= TYPE_MODE (enttype
);
15392 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15394 if (int_size_in_bytes (type
) != size
)
15396 if (size
> TREE_STRING_LENGTH (init
))
15398 memcpy (array
, TREE_STRING_POINTER (init
),
15399 TREE_STRING_LENGTH (init
));
15400 memset (array
+ TREE_STRING_LENGTH (init
),
15401 '\0', size
- TREE_STRING_LENGTH (init
));
15404 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15409 type
= TREE_TYPE (init
);
15410 if (int_size_in_bytes (type
) != size
)
15412 if (TREE_CODE (type
) == ARRAY_TYPE
)
15414 HOST_WIDE_INT min_index
;
15415 unsigned HOST_WIDE_INT cnt
;
15416 int curpos
= 0, fieldsize
;
15417 constructor_elt
*ce
;
15419 if (TYPE_DOMAIN (type
) == NULL_TREE
15420 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15423 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15424 if (fieldsize
<= 0)
15427 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15428 memset (array
, '\0', size
);
15429 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15431 tree val
= ce
->value
;
15432 tree index
= ce
->index
;
15434 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15435 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15438 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15443 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15446 curpos
= pos
+ fieldsize
;
15447 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15449 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15450 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15451 while (count
-- > 0)
15454 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15455 curpos
+= fieldsize
;
15458 gcc_assert (curpos
<= size
);
15462 else if (TREE_CODE (type
) == RECORD_TYPE
15463 || TREE_CODE (type
) == UNION_TYPE
)
15465 tree field
= NULL_TREE
;
15466 unsigned HOST_WIDE_INT cnt
;
15467 constructor_elt
*ce
;
15469 if (int_size_in_bytes (type
) != size
)
15472 if (TREE_CODE (type
) == RECORD_TYPE
)
15473 field
= TYPE_FIELDS (type
);
15475 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15477 tree val
= ce
->value
;
15478 int pos
, fieldsize
;
15480 if (ce
->index
!= 0)
15486 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15489 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15490 && TYPE_DOMAIN (TREE_TYPE (field
))
15491 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15493 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15494 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15496 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15497 pos
= int_byte_position (field
);
15498 gcc_assert (pos
+ fieldsize
<= size
);
15500 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15506 case VIEW_CONVERT_EXPR
:
15507 case NON_LVALUE_EXPR
:
15508 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15510 return native_encode_expr (init
, array
, size
) == size
;
15514 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15515 attribute is the const value T. */
15518 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15521 tree type
= TREE_TYPE (t
);
15524 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15528 gcc_assert (!DECL_P (init
));
15530 rtl
= rtl_for_decl_init (init
, type
);
15532 return add_const_value_attribute (die
, rtl
);
15533 /* If the host and target are sane, try harder. */
15534 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15535 && initializer_constant_valid_p (init
, type
))
15537 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15538 if (size
> 0 && (int) size
== size
)
15540 unsigned char *array
= (unsigned char *)
15541 ggc_alloc_cleared_atomic (size
);
15543 if (native_encode_initializer (init
, array
, size
))
15545 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15554 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15555 attribute is the const value of T, where T is an integral constant
15556 variable with static storage duration
15557 (so it can't be a PARM_DECL or a RESULT_DECL). */
15560 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15564 || (TREE_CODE (decl
) != VAR_DECL
15565 && TREE_CODE (decl
) != CONST_DECL
)
15566 || (TREE_CODE (decl
) == VAR_DECL
15567 && !TREE_STATIC (decl
)))
15570 if (TREE_READONLY (decl
)
15571 && ! TREE_THIS_VOLATILE (decl
)
15572 && DECL_INITIAL (decl
))
15577 /* Don't add DW_AT_const_value if abstract origin already has one. */
15578 if (get_AT (var_die
, DW_AT_const_value
))
15581 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15584 /* Convert the CFI instructions for the current function into a
15585 location list. This is used for DW_AT_frame_base when we targeting
15586 a dwarf2 consumer that does not support the dwarf3
15587 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15590 static dw_loc_list_ref
15591 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15595 dw_loc_list_ref list
, *list_tail
;
15597 dw_cfa_location last_cfa
, next_cfa
;
15598 const char *start_label
, *last_label
, *section
;
15599 dw_cfa_location remember
;
15602 gcc_assert (fde
!= NULL
);
15604 section
= secname_for_decl (current_function_decl
);
15608 memset (&next_cfa
, 0, sizeof (next_cfa
));
15609 next_cfa
.reg
= INVALID_REGNUM
;
15610 remember
= next_cfa
;
15612 start_label
= fde
->dw_fde_begin
;
15614 /* ??? Bald assumption that the CIE opcode list does not contain
15615 advance opcodes. */
15616 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15617 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15619 last_cfa
= next_cfa
;
15620 last_label
= start_label
;
15622 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15624 /* If the first partition contained no CFI adjustments, the
15625 CIE opcodes apply to the whole first partition. */
15626 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15627 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15628 list_tail
=&(*list_tail
)->dw_loc_next
;
15629 start_label
= last_label
= fde
->dw_fde_second_begin
;
15632 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15634 switch (cfi
->dw_cfi_opc
)
15636 case DW_CFA_set_loc
:
15637 case DW_CFA_advance_loc1
:
15638 case DW_CFA_advance_loc2
:
15639 case DW_CFA_advance_loc4
:
15640 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15642 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15643 start_label
, last_label
, section
);
15645 list_tail
= &(*list_tail
)->dw_loc_next
;
15646 last_cfa
= next_cfa
;
15647 start_label
= last_label
;
15649 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15652 case DW_CFA_advance_loc
:
15653 /* The encoding is complex enough that we should never emit this. */
15654 gcc_unreachable ();
15657 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15660 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15662 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15664 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15665 start_label
, last_label
, section
);
15667 list_tail
= &(*list_tail
)->dw_loc_next
;
15668 last_cfa
= next_cfa
;
15669 start_label
= last_label
;
15671 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15672 start_label
, fde
->dw_fde_end
, section
);
15673 list_tail
= &(*list_tail
)->dw_loc_next
;
15674 start_label
= last_label
= fde
->dw_fde_second_begin
;
15678 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15680 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15681 start_label
, last_label
, section
);
15682 list_tail
= &(*list_tail
)->dw_loc_next
;
15683 start_label
= last_label
;
15686 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15688 fde
->dw_fde_second_begin
15689 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15692 if (list
&& list
->dw_loc_next
)
15698 /* Compute a displacement from the "steady-state frame pointer" to the
15699 frame base (often the same as the CFA), and store it in
15700 frame_pointer_fb_offset. OFFSET is added to the displacement
15701 before the latter is negated. */
15704 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15708 #ifdef FRAME_POINTER_CFA_OFFSET
15709 reg
= frame_pointer_rtx
;
15710 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15712 reg
= arg_pointer_rtx
;
15713 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15716 elim
= (ira_use_lra_p
15717 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15718 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15719 if (GET_CODE (elim
) == PLUS
)
15721 offset
+= INTVAL (XEXP (elim
, 1));
15722 elim
= XEXP (elim
, 0);
15725 frame_pointer_fb_offset
= -offset
;
15727 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15728 in which to eliminate. This is because it's stack pointer isn't
15729 directly accessible as a register within the ISA. To work around
15730 this, assume that while we cannot provide a proper value for
15731 frame_pointer_fb_offset, we won't need one either. */
15732 frame_pointer_fb_offset_valid
15733 = ((SUPPORTS_STACK_ALIGNMENT
15734 && (elim
== hard_frame_pointer_rtx
15735 || elim
== stack_pointer_rtx
))
15736 || elim
== (frame_pointer_needed
15737 ? hard_frame_pointer_rtx
15738 : stack_pointer_rtx
));
15741 /* Generate a DW_AT_name attribute given some string value to be included as
15742 the value of the attribute. */
15745 add_name_attribute (dw_die_ref die
, const char *name_string
)
15747 if (name_string
!= NULL
&& *name_string
!= 0)
15749 if (demangle_name_func
)
15750 name_string
= (*demangle_name_func
) (name_string
);
15752 add_AT_string (die
, DW_AT_name
, name_string
);
15756 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15757 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15758 of TYPE accordingly.
15760 ??? This is a temporary measure until after we're able to generate
15761 regular DWARF for the complex Ada type system. */
15764 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15765 dw_die_ref context_die
)
15768 dw_die_ref dtype_die
;
15770 if (!lang_hooks
.types
.descriptive_type
)
15773 dtype
= lang_hooks
.types
.descriptive_type (type
);
15777 dtype_die
= lookup_type_die (dtype
);
15780 gen_type_die (dtype
, context_die
);
15781 dtype_die
= lookup_type_die (dtype
);
15782 gcc_assert (dtype_die
);
15785 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15788 /* Generate a DW_AT_comp_dir attribute for DIE. */
15791 add_comp_dir_attribute (dw_die_ref die
)
15793 const char *wd
= get_src_pwd ();
15799 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15803 wdlen
= strlen (wd
);
15804 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15806 wd1
[wdlen
] = DIR_SEPARATOR
;
15807 wd1
[wdlen
+ 1] = 0;
15811 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
15814 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15818 lower_bound_default (void)
15820 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15825 case DW_LANG_C_plus_plus
:
15827 case DW_LANG_ObjC_plus_plus
:
15830 case DW_LANG_Fortran77
:
15831 case DW_LANG_Fortran90
:
15832 case DW_LANG_Fortran95
:
15836 case DW_LANG_Python
:
15837 return dwarf_version
>= 4 ? 0 : -1;
15838 case DW_LANG_Ada95
:
15839 case DW_LANG_Ada83
:
15840 case DW_LANG_Cobol74
:
15841 case DW_LANG_Cobol85
:
15842 case DW_LANG_Pascal83
:
15843 case DW_LANG_Modula2
:
15845 return dwarf_version
>= 4 ? 1 : -1;
15851 /* Given a tree node describing an array bound (either lower or upper) output
15852 a representation for that bound. */
15855 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15857 switch (TREE_CODE (bound
))
15862 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15865 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15868 /* Use the default if possible. */
15869 if (bound_attr
== DW_AT_lower_bound
15870 && host_integerp (bound
, 0)
15871 && (dflt
= lower_bound_default ()) != -1
15872 && tree_low_cst (bound
, 0) == dflt
)
15875 /* Otherwise represent the bound as an unsigned value with the
15876 precision of its type. The precision and signedness of the
15877 type will be necessary to re-interpret it unambiguously. */
15878 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15880 unsigned HOST_WIDE_INT mask
15881 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15882 add_AT_unsigned (subrange_die
, bound_attr
,
15883 TREE_INT_CST_LOW (bound
) & mask
);
15885 else if (prec
== HOST_BITS_PER_WIDE_INT
15886 || TREE_INT_CST_HIGH (bound
) == 0)
15887 add_AT_unsigned (subrange_die
, bound_attr
,
15888 TREE_INT_CST_LOW (bound
));
15890 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
15891 TREE_INT_CST_LOW (bound
));
15896 case VIEW_CONVERT_EXPR
:
15897 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
15907 dw_die_ref decl_die
= lookup_decl_die (bound
);
15909 /* ??? Can this happen, or should the variable have been bound
15910 first? Probably it can, since I imagine that we try to create
15911 the types of parameters in the order in which they exist in
15912 the list, and won't have created a forward reference to a
15913 later parameter. */
15914 if (decl_die
!= NULL
)
15916 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15924 /* Otherwise try to create a stack operation procedure to
15925 evaluate the value of the array bound. */
15927 dw_die_ref ctx
, decl_die
;
15928 dw_loc_list_ref list
;
15930 list
= loc_list_from_tree (bound
, 2);
15931 if (list
== NULL
|| single_element_loc_list_p (list
))
15933 /* If DW_AT_*bound is not a reference nor constant, it is
15934 a DWARF expression rather than location description.
15935 For that loc_list_from_tree (bound, 0) is needed.
15936 If that fails to give a single element list,
15937 fall back to outputting this as a reference anyway. */
15938 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
15939 if (list2
&& single_element_loc_list_p (list2
))
15941 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
15948 if (current_function_decl
== 0)
15949 ctx
= comp_unit_die ();
15951 ctx
= lookup_decl_die (current_function_decl
);
15953 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
15954 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
15955 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
15956 add_AT_location_description (decl_die
, DW_AT_location
, list
);
15957 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15963 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15964 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15965 Note that the block of subscript information for an array type also
15966 includes information about the element type of the given array type. */
15969 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
15971 unsigned dimension_number
;
15973 dw_die_ref subrange_die
;
15975 for (dimension_number
= 0;
15976 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
15977 type
= TREE_TYPE (type
), dimension_number
++)
15979 tree domain
= TYPE_DOMAIN (type
);
15981 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
15984 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15985 and (in GNU C only) variable bounds. Handle all three forms
15987 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
15990 /* We have an array type with specified bounds. */
15991 lower
= TYPE_MIN_VALUE (domain
);
15992 upper
= TYPE_MAX_VALUE (domain
);
15994 /* Define the index type. */
15995 if (TREE_TYPE (domain
))
15997 /* ??? This is probably an Ada unnamed subrange type. Ignore the
15998 TREE_TYPE field. We can't emit debug info for this
15999 because it is an unnamed integral type. */
16000 if (TREE_CODE (domain
) == INTEGER_TYPE
16001 && TYPE_NAME (domain
) == NULL_TREE
16002 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16003 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16006 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16010 /* ??? If upper is NULL, the array has unspecified length,
16011 but it does have a lower bound. This happens with Fortran
16013 Since the debugger is definitely going to need to know N
16014 to produce useful results, go ahead and output the lower
16015 bound solo, and hope the debugger can cope. */
16017 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16019 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16022 /* Otherwise we have an array type with an unspecified length. The
16023 DWARF-2 spec does not say how to handle this; let's just leave out the
16029 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16031 dw_die_ref decl_die
;
16034 switch (TREE_CODE (tree_node
))
16039 case ENUMERAL_TYPE
:
16042 case QUAL_UNION_TYPE
:
16043 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16044 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16046 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16049 size
= int_size_in_bytes (tree_node
);
16052 /* For a data member of a struct or union, the DW_AT_byte_size is
16053 generally given as the number of bytes normally allocated for an
16054 object of the *declared* type of the member itself. This is true
16055 even for bit-fields. */
16056 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16059 gcc_unreachable ();
16062 /* Note that `size' might be -1 when we get to this point. If it is, that
16063 indicates that the byte size of the entity in question is variable. We
16064 have no good way of expressing this fact in Dwarf at the present time,
16065 so just let the -1 pass on through. */
16066 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16069 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16070 which specifies the distance in bits from the highest order bit of the
16071 "containing object" for the bit-field to the highest order bit of the
16074 For any given bit-field, the "containing object" is a hypothetical object
16075 (of some integral or enum type) within which the given bit-field lives. The
16076 type of this hypothetical "containing object" is always the same as the
16077 declared type of the individual bit-field itself. The determination of the
16078 exact location of the "containing object" for a bit-field is rather
16079 complicated. It's handled by the `field_byte_offset' function (above).
16081 Note that it is the size (in bytes) of the hypothetical "containing object"
16082 which will be given in the DW_AT_byte_size attribute for this bit-field.
16083 (See `byte_size_attribute' above). */
16086 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16088 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16089 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16090 HOST_WIDE_INT bitpos_int
;
16091 HOST_WIDE_INT highest_order_object_bit_offset
;
16092 HOST_WIDE_INT highest_order_field_bit_offset
;
16093 HOST_WIDE_INT bit_offset
;
16095 /* Must be a field and a bit field. */
16096 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16098 /* We can't yet handle bit-fields whose offsets are variable, so if we
16099 encounter such things, just return without generating any attribute
16100 whatsoever. Likewise for variable or too large size. */
16101 if (! host_integerp (bit_position (decl
), 0)
16102 || ! host_integerp (DECL_SIZE (decl
), 1))
16105 bitpos_int
= int_bit_position (decl
);
16107 /* Note that the bit offset is always the distance (in bits) from the
16108 highest-order bit of the "containing object" to the highest-order bit of
16109 the bit-field itself. Since the "high-order end" of any object or field
16110 is different on big-endian and little-endian machines, the computation
16111 below must take account of these differences. */
16112 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16113 highest_order_field_bit_offset
= bitpos_int
;
16115 if (! BYTES_BIG_ENDIAN
)
16117 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16118 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16122 = (! BYTES_BIG_ENDIAN
16123 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16124 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16126 if (bit_offset
< 0)
16127 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16129 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16132 /* For a FIELD_DECL node which represents a bit field, output an attribute
16133 which specifies the length in bits of the given field. */
16136 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16138 /* Must be a field and a bit field. */
16139 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16140 && DECL_BIT_FIELD_TYPE (decl
));
16142 if (host_integerp (DECL_SIZE (decl
), 1))
16143 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16146 /* If the compiled language is ANSI C, then add a 'prototyped'
16147 attribute, if arg types are given for the parameters of a function. */
16150 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16152 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16153 && prototype_p (func_type
))
16154 add_AT_flag (die
, DW_AT_prototyped
, 1);
16157 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16158 by looking in either the type declaration or object declaration
16161 static inline dw_die_ref
16162 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16164 dw_die_ref origin_die
= NULL
;
16166 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16168 /* We may have gotten separated from the block for the inlined
16169 function, if we're in an exception handler or some such; make
16170 sure that the abstract function has been written out.
16172 Doing this for nested functions is wrong, however; functions are
16173 distinct units, and our context might not even be inline. */
16177 fn
= TYPE_STUB_DECL (fn
);
16179 fn
= decl_function_context (fn
);
16181 dwarf2out_abstract_function (fn
);
16184 if (DECL_P (origin
))
16185 origin_die
= lookup_decl_die (origin
);
16186 else if (TYPE_P (origin
))
16187 origin_die
= lookup_type_die (origin
);
16189 /* XXX: Functions that are never lowered don't always have correct block
16190 trees (in the case of java, they simply have no block tree, in some other
16191 languages). For these functions, there is nothing we can really do to
16192 output correct debug info for inlined functions in all cases. Rather
16193 than die, we'll just produce deficient debug info now, in that we will
16194 have variables without a proper abstract origin. In the future, when all
16195 functions are lowered, we should re-add a gcc_assert (origin_die)
16199 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16203 /* We do not currently support the pure_virtual attribute. */
16206 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16208 if (DECL_VINDEX (func_decl
))
16210 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16212 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16213 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16214 new_loc_descr (DW_OP_constu
,
16215 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16218 /* GNU extension: Record what type this method came from originally. */
16219 if (debug_info_level
> DINFO_LEVEL_TERSE
16220 && DECL_CONTEXT (func_decl
))
16221 add_AT_die_ref (die
, DW_AT_containing_type
,
16222 lookup_type_die (DECL_CONTEXT (func_decl
)));
16226 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16227 given decl. This used to be a vendor extension until after DWARF 4
16228 standardized it. */
16231 add_linkage_attr (dw_die_ref die
, tree decl
)
16233 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16235 /* Mimic what assemble_name_raw does with a leading '*'. */
16236 if (name
[0] == '*')
16239 if (dwarf_version
>= 4)
16240 add_AT_string (die
, DW_AT_linkage_name
, name
);
16242 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16245 /* Add source coordinate attributes for the given decl. */
16248 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16250 expanded_location s
;
16252 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16254 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16255 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16256 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16259 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16262 add_linkage_name (dw_die_ref die
, tree decl
)
16264 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16265 && TREE_PUBLIC (decl
)
16266 && !DECL_ABSTRACT (decl
)
16267 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16268 && die
->die_tag
!= DW_TAG_member
)
16270 /* Defer until we have an assembler name set. */
16271 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16273 limbo_die_node
*asm_name
;
16275 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16276 asm_name
->die
= die
;
16277 asm_name
->created_for
= decl
;
16278 asm_name
->next
= deferred_asm_name
;
16279 deferred_asm_name
= asm_name
;
16281 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16282 add_linkage_attr (die
, decl
);
16286 /* Add a DW_AT_name attribute and source coordinate attribute for the
16287 given decl, but only if it actually has a name. */
16290 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16294 decl_name
= DECL_NAME (decl
);
16295 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16297 const char *name
= dwarf2_name (decl
, 0);
16299 add_name_attribute (die
, name
);
16300 if (! DECL_ARTIFICIAL (decl
))
16301 add_src_coords_attributes (die
, decl
);
16303 add_linkage_name (die
, decl
);
16306 #ifdef VMS_DEBUGGING_INFO
16307 /* Get the function's name, as described by its RTL. This may be different
16308 from the DECL_NAME name used in the source file. */
16309 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16311 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16312 XEXP (DECL_RTL (decl
), 0), false);
16313 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16315 #endif /* VMS_DEBUGGING_INFO */
16318 #ifdef VMS_DEBUGGING_INFO
16319 /* Output the debug main pointer die for VMS */
16322 dwarf2out_vms_debug_main_pointer (void)
16324 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16327 /* Allocate the VMS debug main subprogram die. */
16328 die
= ggc_alloc_cleared_die_node ();
16329 die
->die_tag
= DW_TAG_subprogram
;
16330 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16331 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16332 current_function_funcdef_no
);
16333 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16335 /* Make it the first child of comp_unit_die (). */
16336 die
->die_parent
= comp_unit_die ();
16337 if (comp_unit_die ()->die_child
)
16339 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16340 comp_unit_die ()->die_child
->die_sib
= die
;
16344 die
->die_sib
= die
;
16345 comp_unit_die ()->die_child
= die
;
16348 #endif /* VMS_DEBUGGING_INFO */
16350 /* Push a new declaration scope. */
16353 push_decl_scope (tree scope
)
16355 vec_safe_push (decl_scope_table
, scope
);
16358 /* Pop a declaration scope. */
16361 pop_decl_scope (void)
16363 decl_scope_table
->pop ();
16366 /* walk_tree helper function for uses_local_type, below. */
16369 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16372 *walk_subtrees
= 0;
16375 tree name
= TYPE_NAME (*tp
);
16376 if (name
&& DECL_P (name
) && decl_function_context (name
))
16382 /* If TYPE involves a function-local type (including a local typedef to a
16383 non-local type), returns that type; otherwise returns NULL_TREE. */
16386 uses_local_type (tree type
)
16388 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16392 /* Return the DIE for the scope that immediately contains this type.
16393 Non-named types that do not involve a function-local type get global
16394 scope. Named types nested in namespaces or other types get their
16395 containing scope. All other types (i.e. function-local named types) get
16396 the current active scope. */
16399 scope_die_for (tree t
, dw_die_ref context_die
)
16401 dw_die_ref scope_die
= NULL
;
16402 tree containing_scope
;
16404 /* Non-types always go in the current scope. */
16405 gcc_assert (TYPE_P (t
));
16407 /* Use the scope of the typedef, rather than the scope of the type
16409 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16410 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16412 containing_scope
= TYPE_CONTEXT (t
);
16414 /* Use the containing namespace if there is one. */
16415 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16417 if (context_die
== lookup_decl_die (containing_scope
))
16419 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16420 context_die
= get_context_die (containing_scope
);
16422 containing_scope
= NULL_TREE
;
16425 /* Ignore function type "scopes" from the C frontend. They mean that
16426 a tagged type is local to a parmlist of a function declarator, but
16427 that isn't useful to DWARF. */
16428 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16429 containing_scope
= NULL_TREE
;
16431 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16433 /* If T uses a local type keep it local as well, to avoid references
16434 to function-local DIEs from outside the function. */
16435 if (current_function_decl
&& uses_local_type (t
))
16436 scope_die
= context_die
;
16438 scope_die
= comp_unit_die ();
16440 else if (TYPE_P (containing_scope
))
16442 /* For types, we can just look up the appropriate DIE. */
16443 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16444 scope_die
= get_context_die (containing_scope
);
16447 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16448 if (scope_die
== NULL
)
16449 scope_die
= comp_unit_die ();
16453 scope_die
= context_die
;
16458 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16461 local_scope_p (dw_die_ref context_die
)
16463 for (; context_die
; context_die
= context_die
->die_parent
)
16464 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16465 || context_die
->die_tag
== DW_TAG_subprogram
)
16471 /* Returns nonzero if CONTEXT_DIE is a class. */
16474 class_scope_p (dw_die_ref context_die
)
16476 return (context_die
16477 && (context_die
->die_tag
== DW_TAG_structure_type
16478 || context_die
->die_tag
== DW_TAG_class_type
16479 || context_die
->die_tag
== DW_TAG_interface_type
16480 || context_die
->die_tag
== DW_TAG_union_type
));
16483 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16484 whether or not to treat a DIE in this context as a declaration. */
16487 class_or_namespace_scope_p (dw_die_ref context_die
)
16489 return (class_scope_p (context_die
)
16490 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16493 /* Many forms of DIEs require a "type description" attribute. This
16494 routine locates the proper "type descriptor" die for the type given
16495 by 'type', and adds a DW_AT_type attribute below the given die. */
16498 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16499 int decl_volatile
, dw_die_ref context_die
)
16501 enum tree_code code
= TREE_CODE (type
);
16502 dw_die_ref type_die
= NULL
;
16504 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16505 or fixed-point type, use the inner type. This is because we have no
16506 support for unnamed types in base_type_die. This can happen if this is
16507 an Ada subrange type. Correct solution is emit a subrange type die. */
16508 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16509 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16510 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16512 if (code
== ERROR_MARK
16513 /* Handle a special case. For functions whose return type is void, we
16514 generate *no* type attribute. (Note that no object may have type
16515 `void', so this only applies to function return types). */
16516 || code
== VOID_TYPE
)
16519 type_die
= modified_type_die (type
,
16520 decl_const
|| TYPE_READONLY (type
),
16521 decl_volatile
|| TYPE_VOLATILE (type
),
16524 if (type_die
!= NULL
)
16525 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16528 /* Given an object die, add the calling convention attribute for the
16529 function call type. */
16531 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16533 enum dwarf_calling_convention value
= DW_CC_normal
;
16535 value
= ((enum dwarf_calling_convention
)
16536 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16539 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16541 /* DWARF 2 doesn't provide a way to identify a program's source-level
16542 entry point. DW_AT_calling_convention attributes are only meant
16543 to describe functions' calling conventions. However, lacking a
16544 better way to signal the Fortran main program, we used this for
16545 a long time, following existing custom. Now, DWARF 4 has
16546 DW_AT_main_subprogram, which we add below, but some tools still
16547 rely on the old way, which we thus keep. */
16548 value
= DW_CC_program
;
16550 if (dwarf_version
>= 4 || !dwarf_strict
)
16551 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16554 /* Only add the attribute if the backend requests it, and
16555 is not DW_CC_normal. */
16556 if (value
&& (value
!= DW_CC_normal
))
16557 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16560 /* Given a tree pointer to a struct, class, union, or enum type node, return
16561 a pointer to the (string) tag name for the given type, or zero if the type
16562 was declared without a tag. */
16564 static const char *
16565 type_tag (const_tree type
)
16567 const char *name
= 0;
16569 if (TYPE_NAME (type
) != 0)
16573 /* Find the IDENTIFIER_NODE for the type name. */
16574 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16575 && !TYPE_NAMELESS (type
))
16576 t
= TYPE_NAME (type
);
16578 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16579 a TYPE_DECL node, regardless of whether or not a `typedef' was
16581 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16582 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16584 /* We want to be extra verbose. Don't call dwarf_name if
16585 DECL_NAME isn't set. The default hook for decl_printable_name
16586 doesn't like that, and in this context it's correct to return
16587 0, instead of "<anonymous>" or the like. */
16588 if (DECL_NAME (TYPE_NAME (type
))
16589 && !DECL_NAMELESS (TYPE_NAME (type
)))
16590 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16593 /* Now get the name as a string, or invent one. */
16594 if (!name
&& t
!= 0)
16595 name
= IDENTIFIER_POINTER (t
);
16598 return (name
== 0 || *name
== '\0') ? 0 : name
;
16601 /* Return the type associated with a data member, make a special check
16602 for bit field types. */
16605 member_declared_type (const_tree member
)
16607 return (DECL_BIT_FIELD_TYPE (member
)
16608 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16611 /* Get the decl's label, as described by its RTL. This may be different
16612 from the DECL_NAME name used in the source file. */
16615 static const char *
16616 decl_start_label (tree decl
)
16619 const char *fnname
;
16621 x
= DECL_RTL (decl
);
16622 gcc_assert (MEM_P (x
));
16625 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16627 fnname
= XSTR (x
, 0);
16632 /* These routines generate the internal representation of the DIE's for
16633 the compilation unit. Debugging information is collected by walking
16634 the declaration trees passed in from dwarf2out_decl(). */
16637 gen_array_type_die (tree type
, dw_die_ref context_die
)
16639 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16640 dw_die_ref array_die
;
16642 /* GNU compilers represent multidimensional array types as sequences of one
16643 dimensional array types whose element types are themselves array types.
16644 We sometimes squish that down to a single array_type DIE with multiple
16645 subscripts in the Dwarf debugging info. The draft Dwarf specification
16646 say that we are allowed to do this kind of compression in C, because
16647 there is no difference between an array of arrays and a multidimensional
16648 array. We don't do this for Ada to remain as close as possible to the
16649 actual representation, which is especially important against the language
16650 flexibilty wrt arrays of variable size. */
16652 bool collapse_nested_arrays
= !is_ada ();
16655 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16656 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16657 if (TYPE_STRING_FLAG (type
)
16658 && TREE_CODE (type
) == ARRAY_TYPE
16660 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16662 HOST_WIDE_INT size
;
16664 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16665 add_name_attribute (array_die
, type_tag (type
));
16666 equate_type_number_to_die (type
, array_die
);
16667 size
= int_size_in_bytes (type
);
16669 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16670 else if (TYPE_DOMAIN (type
) != NULL_TREE
16671 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16672 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16674 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16675 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16677 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16678 if (loc
&& size
> 0)
16680 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16681 if (size
!= DWARF2_ADDR_SIZE
)
16682 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16688 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16689 add_name_attribute (array_die
, type_tag (type
));
16690 equate_type_number_to_die (type
, array_die
);
16692 if (TREE_CODE (type
) == VECTOR_TYPE
)
16693 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16695 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16697 && TREE_CODE (type
) == ARRAY_TYPE
16698 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16699 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16700 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16703 /* We default the array ordering. SDB will probably do
16704 the right things even if DW_AT_ordering is not present. It's not even
16705 an issue until we start to get into multidimensional arrays anyway. If
16706 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16707 then we'll have to put the DW_AT_ordering attribute back in. (But if
16708 and when we find out that we need to put these in, we will only do so
16709 for multidimensional arrays. */
16710 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16713 if (TREE_CODE (type
) == VECTOR_TYPE
)
16715 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16716 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16717 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16718 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16719 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16722 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16724 /* Add representation of the type of the elements of this array type and
16725 emit the corresponding DIE if we haven't done it already. */
16726 element_type
= TREE_TYPE (type
);
16727 if (collapse_nested_arrays
)
16728 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16730 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16732 element_type
= TREE_TYPE (element_type
);
16735 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16737 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16738 if (TYPE_ARTIFICIAL (type
))
16739 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16741 if (get_AT (array_die
, DW_AT_name
))
16742 add_pubtype (type
, array_die
);
16745 static dw_loc_descr_ref
16746 descr_info_loc (tree val
, tree base_decl
)
16748 HOST_WIDE_INT size
;
16749 dw_loc_descr_ref loc
, loc2
;
16750 enum dwarf_location_atom op
;
16752 if (val
== base_decl
)
16753 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16755 switch (TREE_CODE (val
))
16758 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16760 return loc_descriptor_from_tree (val
, 0);
16762 if (host_integerp (val
, 0))
16763 return int_loc_descriptor (tree_low_cst (val
, 0));
16766 size
= int_size_in_bytes (TREE_TYPE (val
));
16769 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16772 if (size
== DWARF2_ADDR_SIZE
)
16773 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16775 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16777 case POINTER_PLUS_EXPR
:
16779 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16780 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16783 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16786 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16792 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16795 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16798 add_loc_descr (&loc
, loc2
);
16799 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16821 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16822 tree val
, tree base_decl
)
16824 dw_loc_descr_ref loc
;
16826 if (host_integerp (val
, 0))
16828 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16832 loc
= descr_info_loc (val
, base_decl
);
16836 add_AT_loc (die
, attr
, loc
);
16839 /* This routine generates DIE for array with hidden descriptor, details
16840 are filled into *info by a langhook. */
16843 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16844 dw_die_ref context_die
)
16846 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16847 dw_die_ref array_die
;
16850 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16851 add_name_attribute (array_die
, type_tag (type
));
16852 equate_type_number_to_die (type
, array_die
);
16854 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16856 && info
->ndimensions
>= 2)
16857 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16859 if (info
->data_location
)
16860 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16862 if (info
->associated
)
16863 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16865 if (info
->allocated
)
16866 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16869 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16871 dw_die_ref subrange_die
16872 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16874 if (info
->dimen
[dim
].lower_bound
)
16876 /* If it is the default value, omit it. */
16879 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16880 && (dflt
= lower_bound_default ()) != -1
16881 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16884 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16885 info
->dimen
[dim
].lower_bound
,
16888 if (info
->dimen
[dim
].upper_bound
)
16889 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
16890 info
->dimen
[dim
].upper_bound
,
16892 if (info
->dimen
[dim
].stride
)
16893 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
16894 info
->dimen
[dim
].stride
,
16898 gen_type_die (info
->element_type
, context_die
);
16899 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
16901 if (get_AT (array_die
, DW_AT_name
))
16902 add_pubtype (type
, array_die
);
16907 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
16909 tree origin
= decl_ultimate_origin (decl
);
16910 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
16912 if (origin
!= NULL
)
16913 add_abstract_origin_attribute (decl_die
, origin
);
16916 add_name_and_src_coords_attributes (decl_die
, decl
);
16917 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
16918 0, 0, context_die
);
16921 if (DECL_ABSTRACT (decl
))
16922 equate_decl_number_to_die (decl
, decl_die
);
16924 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
16928 /* Walk through the list of incomplete types again, trying once more to
16929 emit full debugging info for them. */
16932 retry_incomplete_types (void)
16936 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
16937 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
16938 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
16941 /* Determine what tag to use for a record type. */
16943 static enum dwarf_tag
16944 record_type_tag (tree type
)
16946 if (! lang_hooks
.types
.classify_record
)
16947 return DW_TAG_structure_type
;
16949 switch (lang_hooks
.types
.classify_record (type
))
16951 case RECORD_IS_STRUCT
:
16952 return DW_TAG_structure_type
;
16954 case RECORD_IS_CLASS
:
16955 return DW_TAG_class_type
;
16957 case RECORD_IS_INTERFACE
:
16958 if (dwarf_version
>= 3 || !dwarf_strict
)
16959 return DW_TAG_interface_type
;
16960 return DW_TAG_structure_type
;
16963 gcc_unreachable ();
16967 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16968 include all of the information about the enumeration values also. Each
16969 enumerated type name/value is listed as a child of the enumerated type
16973 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
16975 dw_die_ref type_die
= lookup_type_die (type
);
16977 if (type_die
== NULL
)
16979 type_die
= new_die (DW_TAG_enumeration_type
,
16980 scope_die_for (type
, context_die
), type
);
16981 equate_type_number_to_die (type
, type_die
);
16982 add_name_attribute (type_die
, type_tag (type
));
16983 if (dwarf_version
>= 4 || !dwarf_strict
)
16985 if (ENUM_IS_SCOPED (type
))
16986 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
16987 if (ENUM_IS_OPAQUE (type
))
16988 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16991 else if (! TYPE_SIZE (type
))
16994 remove_AT (type_die
, DW_AT_declaration
);
16996 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
16997 given enum type is incomplete, do not generate the DW_AT_byte_size
16998 attribute or the DW_AT_element_list attribute. */
16999 if (TYPE_SIZE (type
))
17003 TREE_ASM_WRITTEN (type
) = 1;
17004 add_byte_size_attribute (type_die
, type
);
17005 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17007 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17008 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17011 /* If the first reference to this type was as the return type of an
17012 inline function, then it may not have a parent. Fix this now. */
17013 if (type_die
->die_parent
== NULL
)
17014 add_child_die (scope_die_for (type
, context_die
), type_die
);
17016 for (link
= TYPE_VALUES (type
);
17017 link
!= NULL
; link
= TREE_CHAIN (link
))
17019 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17020 tree value
= TREE_VALUE (link
);
17022 add_name_attribute (enum_die
,
17023 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17025 if (TREE_CODE (value
) == CONST_DECL
)
17026 value
= DECL_INITIAL (value
);
17028 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
17029 /* DWARF2 does not provide a way of indicating whether or
17030 not enumeration constants are signed or unsigned. GDB
17031 always assumes the values are signed, so we output all
17032 values as if they were signed. That means that
17033 enumeration constants with very large unsigned values
17034 will appear to have negative values in the debugger. */
17035 add_AT_int (enum_die
, DW_AT_const_value
,
17036 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
17039 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17040 if (TYPE_ARTIFICIAL (type
))
17041 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17044 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17046 add_pubtype (type
, type_die
);
17051 /* Generate a DIE to represent either a real live formal parameter decl or to
17052 represent just the type of some formal parameter position in some function
17055 Note that this routine is a bit unusual because its argument may be a
17056 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17057 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17058 node. If it's the former then this function is being called to output a
17059 DIE to represent a formal parameter object (or some inlining thereof). If
17060 it's the latter, then this function is only being called to output a
17061 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17062 argument type of some subprogram type.
17063 If EMIT_NAME_P is true, name and source coordinate attributes
17067 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17068 dw_die_ref context_die
)
17070 tree node_or_origin
= node
? node
: origin
;
17071 tree ultimate_origin
;
17072 dw_die_ref parm_die
17073 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17075 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17077 case tcc_declaration
:
17078 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17079 if (node
|| ultimate_origin
)
17080 origin
= ultimate_origin
;
17081 if (origin
!= NULL
)
17082 add_abstract_origin_attribute (parm_die
, origin
);
17083 else if (emit_name_p
)
17084 add_name_and_src_coords_attributes (parm_die
, node
);
17086 || (! DECL_ABSTRACT (node_or_origin
)
17087 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17088 decl_function_context
17089 (node_or_origin
))))
17091 tree type
= TREE_TYPE (node_or_origin
);
17092 if (decl_by_reference_p (node_or_origin
))
17093 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17096 add_type_attribute (parm_die
, type
,
17097 TREE_READONLY (node_or_origin
),
17098 TREE_THIS_VOLATILE (node_or_origin
),
17101 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17102 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17104 if (node
&& node
!= origin
)
17105 equate_decl_number_to_die (node
, parm_die
);
17106 if (! DECL_ABSTRACT (node_or_origin
))
17107 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17108 node
== NULL
, DW_AT_location
);
17113 /* We were called with some kind of a ..._TYPE node. */
17114 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17118 gcc_unreachable ();
17124 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17125 children DW_TAG_formal_parameter DIEs representing the arguments of the
17128 PARM_PACK must be a function parameter pack.
17129 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17130 must point to the subsequent arguments of the function PACK_ARG belongs to.
17131 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17132 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17133 following the last one for which a DIE was generated. */
17136 gen_formal_parameter_pack_die (tree parm_pack
,
17138 dw_die_ref subr_die
,
17142 dw_die_ref parm_pack_die
;
17144 gcc_assert (parm_pack
17145 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17148 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17149 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17151 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17153 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17156 gen_formal_parameter_die (arg
, NULL
,
17157 false /* Don't emit name attribute. */,
17162 return parm_pack_die
;
17165 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17166 at the end of an (ANSI prototyped) formal parameters list. */
17169 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17171 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17174 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17175 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17176 parameters as specified in some function type specification (except for
17177 those which appear as part of a function *definition*). */
17180 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17183 tree formal_type
= NULL
;
17184 tree first_parm_type
;
17187 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17189 arg
= DECL_ARGUMENTS (function_or_method_type
);
17190 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17195 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17197 /* Make our first pass over the list of formal parameter types and output a
17198 DW_TAG_formal_parameter DIE for each one. */
17199 for (link
= first_parm_type
; link
; )
17201 dw_die_ref parm_die
;
17203 formal_type
= TREE_VALUE (link
);
17204 if (formal_type
== void_type_node
)
17207 /* Output a (nameless) DIE to represent the formal parameter itself. */
17208 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17209 true /* Emit name attribute. */,
17211 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17212 && link
== first_parm_type
)
17214 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17215 if (dwarf_version
>= 3 || !dwarf_strict
)
17216 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17218 else if (arg
&& DECL_ARTIFICIAL (arg
))
17219 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17221 link
= TREE_CHAIN (link
);
17223 arg
= DECL_CHAIN (arg
);
17226 /* If this function type has an ellipsis, add a
17227 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17228 if (formal_type
!= void_type_node
)
17229 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17231 /* Make our second (and final) pass over the list of formal parameter types
17232 and output DIEs to represent those types (as necessary). */
17233 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17234 link
&& TREE_VALUE (link
);
17235 link
= TREE_CHAIN (link
))
17236 gen_type_die (TREE_VALUE (link
), context_die
);
17239 /* We want to generate the DIE for TYPE so that we can generate the
17240 die for MEMBER, which has been defined; we will need to refer back
17241 to the member declaration nested within TYPE. If we're trying to
17242 generate minimal debug info for TYPE, processing TYPE won't do the
17243 trick; we need to attach the member declaration by hand. */
17246 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17248 gen_type_die (type
, context_die
);
17250 /* If we're trying to avoid duplicate debug info, we may not have
17251 emitted the member decl for this function. Emit it now. */
17252 if (TYPE_STUB_DECL (type
)
17253 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17254 && ! lookup_decl_die (member
))
17256 dw_die_ref type_die
;
17257 gcc_assert (!decl_ultimate_origin (member
));
17259 push_decl_scope (type
);
17260 type_die
= lookup_type_die_strip_naming_typedef (type
);
17261 if (TREE_CODE (member
) == FUNCTION_DECL
)
17262 gen_subprogram_die (member
, type_die
);
17263 else if (TREE_CODE (member
) == FIELD_DECL
)
17265 /* Ignore the nameless fields that are used to skip bits but handle
17266 C++ anonymous unions and structs. */
17267 if (DECL_NAME (member
) != NULL_TREE
17268 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17269 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17271 gen_type_die (member_declared_type (member
), type_die
);
17272 gen_field_die (member
, type_die
);
17276 gen_variable_die (member
, NULL_TREE
, type_die
);
17282 /* Forward declare these functions, because they are mutually recursive
17283 with their set_block_* pairing functions. */
17284 static void set_decl_origin_self (tree
);
17285 static void set_decl_abstract_flags (tree
, int);
17287 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17288 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17289 that it points to the node itself, thus indicating that the node is its
17290 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17291 the given node is NULL, recursively descend the decl/block tree which
17292 it is the root of, and for each other ..._DECL or BLOCK node contained
17293 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17294 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17295 values to point to themselves. */
17298 set_block_origin_self (tree stmt
)
17300 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17302 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17307 for (local_decl
= BLOCK_VARS (stmt
);
17308 local_decl
!= NULL_TREE
;
17309 local_decl
= DECL_CHAIN (local_decl
))
17310 if (! DECL_EXTERNAL (local_decl
))
17311 set_decl_origin_self (local_decl
); /* Potential recursion. */
17317 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17318 subblock
!= NULL_TREE
;
17319 subblock
= BLOCK_CHAIN (subblock
))
17320 set_block_origin_self (subblock
); /* Recurse. */
17325 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17326 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17327 node to so that it points to the node itself, thus indicating that the
17328 node represents its own (abstract) origin. Additionally, if the
17329 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17330 the decl/block tree of which the given node is the root of, and for
17331 each other ..._DECL or BLOCK node contained therein whose
17332 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17333 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17334 point to themselves. */
17337 set_decl_origin_self (tree decl
)
17339 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17341 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17342 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17346 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17347 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17348 if (DECL_INITIAL (decl
) != NULL_TREE
17349 && DECL_INITIAL (decl
) != error_mark_node
)
17350 set_block_origin_self (DECL_INITIAL (decl
));
17355 /* Given a pointer to some BLOCK node, and a boolean value to set the
17356 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17357 the given block, and for all local decls and all local sub-blocks
17358 (recursively) which are contained therein. */
17361 set_block_abstract_flags (tree stmt
, int setting
)
17367 BLOCK_ABSTRACT (stmt
) = setting
;
17369 for (local_decl
= BLOCK_VARS (stmt
);
17370 local_decl
!= NULL_TREE
;
17371 local_decl
= DECL_CHAIN (local_decl
))
17372 if (! DECL_EXTERNAL (local_decl
))
17373 set_decl_abstract_flags (local_decl
, setting
);
17375 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17377 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17378 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17379 || TREE_CODE (local_decl
) == PARM_DECL
)
17380 set_decl_abstract_flags (local_decl
, setting
);
17383 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17384 subblock
!= NULL_TREE
;
17385 subblock
= BLOCK_CHAIN (subblock
))
17386 set_block_abstract_flags (subblock
, setting
);
17389 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17390 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17391 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17392 set the abstract flags for all of the parameters, local vars, local
17393 blocks and sub-blocks (recursively) to the same setting. */
17396 set_decl_abstract_flags (tree decl
, int setting
)
17398 DECL_ABSTRACT (decl
) = setting
;
17399 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17403 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17404 DECL_ABSTRACT (arg
) = setting
;
17405 if (DECL_INITIAL (decl
) != NULL_TREE
17406 && DECL_INITIAL (decl
) != error_mark_node
)
17407 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17411 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17412 may later generate inlined and/or out-of-line instances of. */
17415 dwarf2out_abstract_function (tree decl
)
17417 dw_die_ref old_die
;
17421 htab_t old_decl_loc_table
;
17422 htab_t old_cached_dw_loc_list_table
;
17423 int old_call_site_count
, old_tail_call_site_count
;
17424 struct call_arg_loc_node
*old_call_arg_locations
;
17426 /* Make sure we have the actual abstract inline, not a clone. */
17427 decl
= DECL_ORIGIN (decl
);
17429 old_die
= lookup_decl_die (decl
);
17430 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17431 /* We've already generated the abstract instance. */
17434 /* We can be called while recursively when seeing block defining inlined subroutine
17435 DIE. Be sure to not clobber the outer location table nor use it or we would
17436 get locations in abstract instantces. */
17437 old_decl_loc_table
= decl_loc_table
;
17438 decl_loc_table
= NULL
;
17439 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17440 cached_dw_loc_list_table
= NULL
;
17441 old_call_arg_locations
= call_arg_locations
;
17442 call_arg_locations
= NULL
;
17443 old_call_site_count
= call_site_count
;
17444 call_site_count
= -1;
17445 old_tail_call_site_count
= tail_call_site_count
;
17446 tail_call_site_count
= -1;
17448 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17449 we don't get confused by DECL_ABSTRACT. */
17450 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17452 context
= decl_class_context (decl
);
17454 gen_type_die_for_member
17455 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17458 /* Pretend we've just finished compiling this function. */
17459 save_fn
= current_function_decl
;
17460 current_function_decl
= decl
;
17462 was_abstract
= DECL_ABSTRACT (decl
);
17463 set_decl_abstract_flags (decl
, 1);
17464 dwarf2out_decl (decl
);
17465 if (! was_abstract
)
17466 set_decl_abstract_flags (decl
, 0);
17468 current_function_decl
= save_fn
;
17469 decl_loc_table
= old_decl_loc_table
;
17470 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17471 call_arg_locations
= old_call_arg_locations
;
17472 call_site_count
= old_call_site_count
;
17473 tail_call_site_count
= old_tail_call_site_count
;
17476 /* Helper function of premark_used_types() which gets called through
17479 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17480 marked as unused by prune_unused_types. */
17483 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17488 type
= (tree
) *slot
;
17489 die
= lookup_type_die (type
);
17491 die
->die_perennial_p
= 1;
17495 /* Helper function of premark_types_used_by_global_vars which gets called
17496 through htab_traverse.
17498 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17499 marked as unused by prune_unused_types. The DIE of the type is marked
17500 only if the global variable using the type will actually be emitted. */
17503 premark_types_used_by_global_vars_helper (void **slot
,
17504 void *data ATTRIBUTE_UNUSED
)
17506 struct types_used_by_vars_entry
*entry
;
17509 entry
= (struct types_used_by_vars_entry
*) *slot
;
17510 gcc_assert (entry
->type
!= NULL
17511 && entry
->var_decl
!= NULL
);
17512 die
= lookup_type_die (entry
->type
);
17515 /* Ask cgraph if the global variable really is to be emitted.
17516 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17517 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17518 if (node
&& node
->analyzed
)
17520 die
->die_perennial_p
= 1;
17521 /* Keep the parent DIEs as well. */
17522 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17523 die
->die_perennial_p
= 1;
17529 /* Mark all members of used_types_hash as perennial. */
17532 premark_used_types (struct function
*fun
)
17534 if (fun
&& fun
->used_types_hash
)
17535 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17538 /* Mark all members of types_used_by_vars_entry as perennial. */
17541 premark_types_used_by_global_vars (void)
17543 if (types_used_by_vars_hash
)
17544 htab_traverse (types_used_by_vars_hash
,
17545 premark_types_used_by_global_vars_helper
, NULL
);
17548 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17549 for CA_LOC call arg loc node. */
17552 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17553 struct call_arg_loc_node
*ca_loc
)
17555 dw_die_ref stmt_die
= NULL
, die
;
17556 tree block
= ca_loc
->block
;
17559 && block
!= DECL_INITIAL (decl
)
17560 && TREE_CODE (block
) == BLOCK
)
17562 if (block_map
.length () > BLOCK_NUMBER (block
))
17563 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17566 block
= BLOCK_SUPERCONTEXT (block
);
17568 if (stmt_die
== NULL
)
17569 stmt_die
= subr_die
;
17570 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17571 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17572 if (ca_loc
->tail_call_p
)
17573 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17574 if (ca_loc
->symbol_ref
)
17576 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17578 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17580 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17585 /* Generate a DIE to represent a declared function (either file-scope or
17589 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17591 tree origin
= decl_ultimate_origin (decl
);
17592 dw_die_ref subr_die
;
17594 dw_die_ref old_die
= lookup_decl_die (decl
);
17595 int declaration
= (current_function_decl
!= decl
17596 || class_or_namespace_scope_p (context_die
));
17598 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17600 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17601 started to generate the abstract instance of an inline, decided to output
17602 its containing class, and proceeded to emit the declaration of the inline
17603 from the member list for the class. If so, DECLARATION takes priority;
17604 we'll get back to the abstract instance when done with the class. */
17606 /* The class-scope declaration DIE must be the primary DIE. */
17607 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17610 gcc_assert (!old_die
);
17613 /* Now that the C++ front end lazily declares artificial member fns, we
17614 might need to retrofit the declaration into its class. */
17615 if (!declaration
&& !origin
&& !old_die
17616 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17617 && !class_or_namespace_scope_p (context_die
)
17618 && debug_info_level
> DINFO_LEVEL_TERSE
)
17619 old_die
= force_decl_die (decl
);
17621 if (origin
!= NULL
)
17623 gcc_assert (!declaration
|| local_scope_p (context_die
));
17625 /* Fixup die_parent for the abstract instance of a nested
17626 inline function. */
17627 if (old_die
&& old_die
->die_parent
== NULL
)
17628 add_child_die (context_die
, old_die
);
17630 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17631 add_abstract_origin_attribute (subr_die
, origin
);
17632 /* This is where the actual code for a cloned function is.
17633 Let's emit linkage name attribute for it. This helps
17634 debuggers to e.g, set breakpoints into
17635 constructors/destructors when the user asks "break
17637 add_linkage_name (subr_die
, decl
);
17641 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17642 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17644 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17645 /* We can have a normal definition following an inline one in the
17646 case of redefinition of GNU C extern inlines.
17647 It seems reasonable to use AT_specification in this case. */
17648 && !get_AT (old_die
, DW_AT_inline
))
17650 /* Detect and ignore this case, where we are trying to output
17651 something we have already output. */
17655 /* If the definition comes from the same place as the declaration,
17656 maybe use the old DIE. We always want the DIE for this function
17657 that has the *_pc attributes to be under comp_unit_die so the
17658 debugger can find it. We also need to do this for abstract
17659 instances of inlines, since the spec requires the out-of-line copy
17660 to have the same parent. For local class methods, this doesn't
17661 apply; we just use the old DIE. */
17662 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17663 && (DECL_ARTIFICIAL (decl
)
17664 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17665 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17666 == (unsigned) s
.line
))))
17668 subr_die
= old_die
;
17670 /* Clear out the declaration attribute and the formal parameters.
17671 Do not remove all children, because it is possible that this
17672 declaration die was forced using force_decl_die(). In such
17673 cases die that forced declaration die (e.g. TAG_imported_module)
17674 is one of the children that we do not want to remove. */
17675 remove_AT (subr_die
, DW_AT_declaration
);
17676 remove_AT (subr_die
, DW_AT_object_pointer
);
17677 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17681 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17682 add_AT_specification (subr_die
, old_die
);
17683 add_pubname (decl
, subr_die
);
17684 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17685 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17686 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17687 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17692 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17694 if (TREE_PUBLIC (decl
))
17695 add_AT_flag (subr_die
, DW_AT_external
, 1);
17697 add_name_and_src_coords_attributes (subr_die
, decl
);
17698 add_pubname (decl
, subr_die
);
17699 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17701 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17702 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17703 0, 0, context_die
);
17706 add_pure_or_virtual_attribute (subr_die
, decl
);
17707 if (DECL_ARTIFICIAL (decl
))
17708 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17710 add_accessibility_attribute (subr_die
, decl
);
17715 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17717 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17719 /* If this is an explicit function declaration then generate
17720 a DW_AT_explicit attribute. */
17721 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17722 && (dwarf_version
>= 3 || !dwarf_strict
))
17723 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17725 /* The first time we see a member function, it is in the context of
17726 the class to which it belongs. We make sure of this by emitting
17727 the class first. The next time is the definition, which is
17728 handled above. The two may come from the same source text.
17730 Note that force_decl_die() forces function declaration die. It is
17731 later reused to represent definition. */
17732 equate_decl_number_to_die (decl
, subr_die
);
17735 else if (DECL_ABSTRACT (decl
))
17737 if (DECL_DECLARED_INLINE_P (decl
))
17739 if (cgraph_function_possibly_inlined_p (decl
))
17740 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17742 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17746 if (cgraph_function_possibly_inlined_p (decl
))
17747 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17749 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17752 if (DECL_DECLARED_INLINE_P (decl
)
17753 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17754 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17756 equate_decl_number_to_die (decl
, subr_die
);
17758 else if (!DECL_EXTERNAL (decl
))
17760 HOST_WIDE_INT cfa_fb_offset
;
17761 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
17763 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17764 equate_decl_number_to_die (decl
, subr_die
);
17766 gcc_checking_assert (fun
);
17767 if (!flag_reorder_blocks_and_partition
)
17769 dw_fde_ref fde
= fun
->fde
;
17770 if (fde
->dw_fde_begin
)
17772 /* We have already generated the labels. */
17773 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17774 fde
->dw_fde_end
, false);
17778 /* Create start/end labels and add the range. */
17779 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
17780 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17781 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
17782 current_function_funcdef_no
);
17783 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
17784 current_function_funcdef_no
);
17785 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
17789 #if VMS_DEBUGGING_INFO
17790 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17791 Section 2.3 Prologue and Epilogue Attributes:
17792 When a breakpoint is set on entry to a function, it is generally
17793 desirable for execution to be suspended, not on the very first
17794 instruction of the function, but rather at a point after the
17795 function's frame has been set up, after any language defined local
17796 declaration processing has been completed, and before execution of
17797 the first statement of the function begins. Debuggers generally
17798 cannot properly determine where this point is. Similarly for a
17799 breakpoint set on exit from a function. The prologue and epilogue
17800 attributes allow a compiler to communicate the location(s) to use. */
17803 if (fde
->dw_fde_vms_end_prologue
)
17804 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17805 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17807 if (fde
->dw_fde_vms_begin_epilogue
)
17808 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17809 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17816 /* Generate pubnames entries for the split function code ranges. */
17817 dw_fde_ref fde
= fun
->fde
;
17819 if (fde
->dw_fde_second_begin
)
17821 if (dwarf_version
>= 3 || !dwarf_strict
)
17823 /* We should use ranges for non-contiguous code section
17824 addresses. Use the actual code range for the initial
17825 section, since the HOT/COLD labels might precede an
17826 alignment offset. */
17827 bool range_list_added
= false;
17828 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17829 fde
->dw_fde_end
, &range_list_added
,
17831 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17832 fde
->dw_fde_second_end
,
17833 &range_list_added
, false);
17834 if (range_list_added
)
17839 /* There is no real support in DW2 for this .. so we make
17840 a work-around. First, emit the pub name for the segment
17841 containing the function label. Then make and emit a
17842 simplified subprogram DIE for the second segment with the
17843 name pre-fixed by __hot/cold_sect_of_. We use the same
17844 linkage name for the second die so that gdb will find both
17845 sections when given "b foo". */
17846 const char *name
= NULL
;
17847 tree decl_name
= DECL_NAME (decl
);
17848 dw_die_ref seg_die
;
17850 /* Do the 'primary' section. */
17851 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17852 fde
->dw_fde_end
, false);
17854 /* Build a minimal DIE for the secondary section. */
17855 seg_die
= new_die (DW_TAG_subprogram
,
17856 subr_die
->die_parent
, decl
);
17858 if (TREE_PUBLIC (decl
))
17859 add_AT_flag (seg_die
, DW_AT_external
, 1);
17861 if (decl_name
!= NULL
17862 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17864 name
= dwarf2_name (decl
, 1);
17865 if (! DECL_ARTIFICIAL (decl
))
17866 add_src_coords_attributes (seg_die
, decl
);
17868 add_linkage_name (seg_die
, decl
);
17870 gcc_assert (name
!= NULL
);
17871 add_pure_or_virtual_attribute (seg_die
, decl
);
17872 if (DECL_ARTIFICIAL (decl
))
17873 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17875 name
= concat ("__second_sect_of_", name
, NULL
);
17876 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
17877 fde
->dw_fde_second_end
, false);
17878 add_name_attribute (seg_die
, name
);
17879 if (want_pubnames ())
17880 add_pubname_string (name
, seg_die
);
17884 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
17888 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17890 /* We define the "frame base" as the function's CFA. This is more
17891 convenient for several reasons: (1) It's stable across the prologue
17892 and epilogue, which makes it better than just a frame pointer,
17893 (2) With dwarf3, there exists a one-byte encoding that allows us
17894 to reference the .debug_frame data by proxy, but failing that,
17895 (3) We can at least reuse the code inspection and interpretation
17896 code that determines the CFA position at various points in the
17898 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
17900 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
17901 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
17905 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
17906 if (list
->dw_loc_next
)
17907 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
17909 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
17912 /* Compute a displacement from the "steady-state frame pointer" to
17913 the CFA. The former is what all stack slots and argument slots
17914 will reference in the rtl; the latter is what we've told the
17915 debugger about. We'll need to adjust all frame_base references
17916 by this displacement. */
17917 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
17919 if (fun
->static_chain_decl
)
17920 add_AT_location_description (subr_die
, DW_AT_static_link
,
17921 loc_list_from_tree (fun
->static_chain_decl
, 2));
17924 /* Generate child dies for template paramaters. */
17925 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17926 gen_generic_params_dies (decl
);
17928 /* Now output descriptions of the arguments for this function. This gets
17929 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17930 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17931 `...' at the end of the formal parameter list. In order to find out if
17932 there was a trailing ellipsis or not, we must instead look at the type
17933 associated with the FUNCTION_DECL. This will be a node of type
17934 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17935 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17936 an ellipsis at the end. */
17938 /* In the case where we are describing a mere function declaration, all we
17939 need to do here (and all we *can* do here) is to describe the *types* of
17940 its formal parameters. */
17941 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
17943 else if (declaration
)
17944 gen_formal_types_die (decl
, subr_die
);
17947 /* Generate DIEs to represent all known formal parameters. */
17948 tree parm
= DECL_ARGUMENTS (decl
);
17949 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
17950 tree generic_decl_parm
= generic_decl
17951 ? DECL_ARGUMENTS (generic_decl
)
17954 /* Now we want to walk the list of parameters of the function and
17955 emit their relevant DIEs.
17957 We consider the case of DECL being an instance of a generic function
17958 as well as it being a normal function.
17960 If DECL is an instance of a generic function we walk the
17961 parameters of the generic function declaration _and_ the parameters of
17962 DECL itself. This is useful because we want to emit specific DIEs for
17963 function parameter packs and those are declared as part of the
17964 generic function declaration. In that particular case,
17965 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17966 That DIE has children DIEs representing the set of arguments
17967 of the pack. Note that the set of pack arguments can be empty.
17968 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17971 Otherwise, we just consider the parameters of DECL. */
17972 while (generic_decl_parm
|| parm
)
17974 if (generic_decl_parm
17975 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
17976 gen_formal_parameter_pack_die (generic_decl_parm
,
17981 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
17983 if (parm
== DECL_ARGUMENTS (decl
)
17984 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
17986 && (dwarf_version
>= 3 || !dwarf_strict
))
17987 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
17989 parm
= DECL_CHAIN (parm
);
17992 if (generic_decl_parm
)
17993 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
17996 /* Decide whether we need an unspecified_parameters DIE at the end.
17997 There are 2 more cases to do this for: 1) the ansi ... declaration -
17998 this is detectable when the end of the arg list is not a
17999 void_type_node 2) an unprototyped function declaration (not a
18000 definition). This just means that we have no info about the
18001 parameters at all. */
18002 if (prototype_p (TREE_TYPE (decl
)))
18004 /* This is the prototyped case, check for.... */
18005 if (stdarg_p (TREE_TYPE (decl
)))
18006 gen_unspecified_parameters_die (decl
, subr_die
);
18008 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18009 gen_unspecified_parameters_die (decl
, subr_die
);
18012 /* Output Dwarf info for all of the stuff within the body of the function
18013 (if it has one - it may be just a declaration). */
18014 outer_scope
= DECL_INITIAL (decl
);
18016 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18017 a function. This BLOCK actually represents the outermost binding contour
18018 for the function, i.e. the contour in which the function's formal
18019 parameters and labels get declared. Curiously, it appears that the front
18020 end doesn't actually put the PARM_DECL nodes for the current function onto
18021 the BLOCK_VARS list for this outer scope, but are strung off of the
18022 DECL_ARGUMENTS list for the function instead.
18024 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18025 the LABEL_DECL nodes for the function however, and we output DWARF info
18026 for those in decls_for_scope. Just within the `outer_scope' there will be
18027 a BLOCK node representing the function's outermost pair of curly braces,
18028 and any blocks used for the base and member initializers of a C++
18029 constructor function. */
18030 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18032 int call_site_note_count
= 0;
18033 int tail_call_site_note_count
= 0;
18035 /* Emit a DW_TAG_variable DIE for a named return value. */
18036 if (DECL_NAME (DECL_RESULT (decl
)))
18037 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18039 current_function_has_inlines
= 0;
18040 decls_for_scope (outer_scope
, subr_die
, 0);
18042 if (call_arg_locations
&& !dwarf_strict
)
18044 struct call_arg_loc_node
*ca_loc
;
18045 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18047 dw_die_ref die
= NULL
;
18048 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18051 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18052 arg
; arg
= next_arg
)
18054 dw_loc_descr_ref reg
, val
;
18055 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18056 dw_die_ref cdie
, tdie
= NULL
;
18058 next_arg
= XEXP (arg
, 1);
18059 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18061 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18062 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18063 && REGNO (XEXP (XEXP (arg
, 0), 0))
18064 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18065 next_arg
= XEXP (next_arg
, 1);
18066 if (mode
== VOIDmode
)
18068 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18069 if (mode
== VOIDmode
)
18070 mode
= GET_MODE (XEXP (arg
, 0));
18072 if (mode
== VOIDmode
|| mode
== BLKmode
)
18074 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18076 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18077 tloc
= XEXP (XEXP (arg
, 0), 1);
18080 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18081 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18083 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18084 tlocc
= XEXP (XEXP (arg
, 0), 1);
18088 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18089 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18090 VAR_INIT_STATUS_INITIALIZED
);
18091 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18093 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18094 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18095 get_address_mode (mem
),
18097 VAR_INIT_STATUS_INITIALIZED
);
18099 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18100 == DEBUG_PARAMETER_REF
)
18103 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18104 tdie
= lookup_decl_die (tdecl
);
18111 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18112 != DEBUG_PARAMETER_REF
)
18114 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18116 VAR_INIT_STATUS_INITIALIZED
);
18120 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18121 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18124 add_AT_loc (cdie
, DW_AT_location
, reg
);
18125 else if (tdie
!= NULL
)
18126 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18127 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18128 if (next_arg
!= XEXP (arg
, 1))
18130 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18131 if (mode
== VOIDmode
)
18132 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18133 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18136 VAR_INIT_STATUS_INITIALIZED
);
18138 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18142 && (ca_loc
->symbol_ref
|| tloc
))
18143 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18144 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18146 dw_loc_descr_ref tval
= NULL
;
18148 if (tloc
!= NULL_RTX
)
18149 tval
= mem_loc_descriptor (tloc
,
18150 GET_MODE (tloc
) == VOIDmode
18151 ? Pmode
: GET_MODE (tloc
),
18153 VAR_INIT_STATUS_INITIALIZED
);
18155 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18156 else if (tlocc
!= NULL_RTX
)
18158 tval
= mem_loc_descriptor (tlocc
,
18159 GET_MODE (tlocc
) == VOIDmode
18160 ? Pmode
: GET_MODE (tlocc
),
18162 VAR_INIT_STATUS_INITIALIZED
);
18164 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18170 call_site_note_count
++;
18171 if (ca_loc
->tail_call_p
)
18172 tail_call_site_note_count
++;
18176 call_arg_locations
= NULL
;
18177 call_arg_loc_last
= NULL
;
18178 if (tail_call_site_count
>= 0
18179 && tail_call_site_count
== tail_call_site_note_count
18182 if (call_site_count
>= 0
18183 && call_site_count
== call_site_note_count
)
18184 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18186 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18188 call_site_count
= -1;
18189 tail_call_site_count
= -1;
18191 /* Add the calling convention attribute if requested. */
18192 add_calling_convention_attribute (subr_die
, decl
);
18196 /* Returns a hash value for X (which really is a die_struct). */
18199 common_block_die_table_hash (const void *x
)
18201 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18202 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18205 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18206 as decl_id and die_parent of die_struct Y. */
18209 common_block_die_table_eq (const void *x
, const void *y
)
18211 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18212 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18213 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18216 /* Generate a DIE to represent a declared data object.
18217 Either DECL or ORIGIN must be non-null. */
18220 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18222 HOST_WIDE_INT off
= 0;
18224 tree decl_or_origin
= decl
? decl
: origin
;
18225 tree ultimate_origin
;
18226 dw_die_ref var_die
;
18227 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18228 dw_die_ref origin_die
;
18229 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18230 || class_or_namespace_scope_p (context_die
));
18231 bool specialization_p
= false;
18233 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18234 if (decl
|| ultimate_origin
)
18235 origin
= ultimate_origin
;
18236 com_decl
= fortran_common (decl_or_origin
, &off
);
18238 /* Symbol in common gets emitted as a child of the common block, in the form
18239 of a data member. */
18242 dw_die_ref com_die
;
18243 dw_loc_list_ref loc
;
18244 die_node com_die_arg
;
18246 var_die
= lookup_decl_die (decl_or_origin
);
18249 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18251 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18256 /* Optimize the common case. */
18257 if (single_element_loc_list_p (loc
)
18258 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18259 && loc
->expr
->dw_loc_next
== NULL
18260 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18263 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18264 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18265 = plus_constant (GET_MODE (x
), x
, off
);
18268 loc_list_plus_const (loc
, off
);
18270 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18271 remove_AT (var_die
, DW_AT_declaration
);
18277 if (common_block_die_table
== NULL
)
18278 common_block_die_table
18279 = htab_create_ggc (10, common_block_die_table_hash
,
18280 common_block_die_table_eq
, NULL
);
18282 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18283 com_die_arg
.die_parent
= context_die
;
18284 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18285 loc
= loc_list_from_tree (com_decl
, 2);
18286 if (com_die
== NULL
)
18289 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18292 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18293 add_name_and_src_coords_attributes (com_die
, com_decl
);
18296 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18297 /* Avoid sharing the same loc descriptor between
18298 DW_TAG_common_block and DW_TAG_variable. */
18299 loc
= loc_list_from_tree (com_decl
, 2);
18301 else if (DECL_EXTERNAL (decl
))
18302 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18303 if (want_pubnames ())
18304 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18305 com_die
->decl_id
= DECL_UID (com_decl
);
18306 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18307 *slot
= (void *) com_die
;
18309 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18311 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18312 loc
= loc_list_from_tree (com_decl
, 2);
18313 remove_AT (com_die
, DW_AT_declaration
);
18315 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18316 add_name_and_src_coords_attributes (var_die
, decl
);
18317 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18318 TREE_THIS_VOLATILE (decl
), context_die
);
18319 add_AT_flag (var_die
, DW_AT_external
, 1);
18324 /* Optimize the common case. */
18325 if (single_element_loc_list_p (loc
)
18326 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18327 && loc
->expr
->dw_loc_next
== NULL
18328 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18330 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18331 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18332 = plus_constant (GET_MODE (x
), x
, off
);
18335 loc_list_plus_const (loc
, off
);
18337 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18339 else if (DECL_EXTERNAL (decl
))
18340 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18341 equate_decl_number_to_die (decl
, var_die
);
18345 /* If the compiler emitted a definition for the DECL declaration
18346 and if we already emitted a DIE for it, don't emit a second
18347 DIE for it again. Allow re-declarations of DECLs that are
18348 inside functions, though. */
18349 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18352 /* For static data members, the declaration in the class is supposed
18353 to have DW_TAG_member tag; the specification should still be
18354 DW_TAG_variable referencing the DW_TAG_member DIE. */
18355 if (declaration
&& class_scope_p (context_die
))
18356 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18358 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18361 if (origin
!= NULL
)
18362 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18364 /* Loop unrolling can create multiple blocks that refer to the same
18365 static variable, so we must test for the DW_AT_declaration flag.
18367 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18368 copy decls and set the DECL_ABSTRACT flag on them instead of
18371 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18373 ??? The declare_in_namespace support causes us to get two DIEs for one
18374 variable, both of which are declarations. We want to avoid considering
18375 one to be a specification, so we must test that this DIE is not a
18377 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18378 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18380 /* This is a definition of a C++ class level static. */
18381 add_AT_specification (var_die
, old_die
);
18382 specialization_p
= true;
18383 if (DECL_NAME (decl
))
18385 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18386 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18388 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18389 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18391 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18392 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18394 if (old_die
->die_tag
== DW_TAG_member
)
18395 add_linkage_name (var_die
, decl
);
18399 add_name_and_src_coords_attributes (var_die
, decl
);
18401 if ((origin
== NULL
&& !specialization_p
)
18403 && !DECL_ABSTRACT (decl_or_origin
)
18404 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18405 decl_function_context
18406 (decl_or_origin
))))
18408 tree type
= TREE_TYPE (decl_or_origin
);
18410 if (decl_by_reference_p (decl_or_origin
))
18411 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18413 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18414 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18417 if (origin
== NULL
&& !specialization_p
)
18419 if (TREE_PUBLIC (decl
))
18420 add_AT_flag (var_die
, DW_AT_external
, 1);
18422 if (DECL_ARTIFICIAL (decl
))
18423 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18425 add_accessibility_attribute (var_die
, decl
);
18429 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18431 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18432 equate_decl_number_to_die (decl
, var_die
);
18435 && (! DECL_ABSTRACT (decl_or_origin
)
18436 /* Local static vars are shared between all clones/inlines,
18437 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18439 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18440 && TREE_STATIC (decl_or_origin
)
18441 && DECL_RTL_SET_P (decl_or_origin
)))
18442 /* When abstract origin already has DW_AT_location attribute, no need
18443 to add it again. */
18444 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18446 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18447 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18448 defer_location (decl_or_origin
, var_die
);
18450 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18451 decl
== NULL
, DW_AT_location
);
18452 add_pubname (decl_or_origin
, var_die
);
18455 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18458 /* Generate a DIE to represent a named constant. */
18461 gen_const_die (tree decl
, dw_die_ref context_die
)
18463 dw_die_ref const_die
;
18464 tree type
= TREE_TYPE (decl
);
18466 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18467 add_name_and_src_coords_attributes (const_die
, decl
);
18468 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18469 if (TREE_PUBLIC (decl
))
18470 add_AT_flag (const_die
, DW_AT_external
, 1);
18471 if (DECL_ARTIFICIAL (decl
))
18472 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18473 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18476 /* Generate a DIE to represent a label identifier. */
18479 gen_label_die (tree decl
, dw_die_ref context_die
)
18481 tree origin
= decl_ultimate_origin (decl
);
18482 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18484 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18486 if (origin
!= NULL
)
18487 add_abstract_origin_attribute (lbl_die
, origin
);
18489 add_name_and_src_coords_attributes (lbl_die
, decl
);
18491 if (DECL_ABSTRACT (decl
))
18492 equate_decl_number_to_die (decl
, lbl_die
);
18495 insn
= DECL_RTL_IF_SET (decl
);
18497 /* Deleted labels are programmer specified labels which have been
18498 eliminated because of various optimizations. We still emit them
18499 here so that it is possible to put breakpoints on them. */
18503 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18505 /* When optimization is enabled (via -O) some parts of the compiler
18506 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18507 represent source-level labels which were explicitly declared by
18508 the user. This really shouldn't be happening though, so catch
18509 it if it ever does happen. */
18510 gcc_assert (!INSN_DELETED_P (insn
));
18512 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18513 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18517 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18518 && CODE_LABEL_NUMBER (insn
) != -1)
18520 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18521 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18526 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18527 attributes to the DIE for a block STMT, to describe where the inlined
18528 function was called from. This is similar to add_src_coords_attributes. */
18531 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18533 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18535 if (dwarf_version
>= 3 || !dwarf_strict
)
18537 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18538 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18543 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18544 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18547 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18549 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18551 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18552 && (dwarf_version
>= 3 || !dwarf_strict
))
18554 tree chain
, superblock
= NULL_TREE
;
18556 dw_attr_ref attr
= NULL
;
18558 if (inlined_function_outer_scope_p (stmt
))
18560 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18561 BLOCK_NUMBER (stmt
));
18562 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18565 /* Optimize duplicate .debug_ranges lists or even tails of
18566 lists. If this BLOCK has same ranges as its supercontext,
18567 lookup DW_AT_ranges attribute in the supercontext (and
18568 recursively so), verify that the ranges_table contains the
18569 right values and use it instead of adding a new .debug_range. */
18570 for (chain
= stmt
, pdie
= die
;
18571 BLOCK_SAME_RANGE (chain
);
18572 chain
= BLOCK_SUPERCONTEXT (chain
))
18574 dw_attr_ref new_attr
;
18576 pdie
= pdie
->die_parent
;
18579 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18581 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18582 if (new_attr
== NULL
18583 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18586 superblock
= BLOCK_SUPERCONTEXT (chain
);
18589 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18590 / 2 / DWARF2_ADDR_SIZE
].num
18591 == BLOCK_NUMBER (superblock
))
18592 && BLOCK_FRAGMENT_CHAIN (superblock
))
18594 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18595 / 2 / DWARF2_ADDR_SIZE
;
18596 unsigned long supercnt
= 0, thiscnt
= 0;
18597 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18598 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18601 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18602 == BLOCK_NUMBER (chain
));
18604 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18605 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18606 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18608 gcc_assert (supercnt
>= thiscnt
);
18609 add_AT_range_list (die
, DW_AT_ranges
,
18610 ((off
+ supercnt
- thiscnt
)
18611 * 2 * DWARF2_ADDR_SIZE
),
18616 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18618 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18621 add_ranges (chain
);
18622 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18629 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18630 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18631 BLOCK_NUMBER (stmt
));
18632 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18633 BLOCK_NUMBER (stmt
));
18634 add_AT_low_high_pc (die
, label
, label_high
, false);
18638 /* Generate a DIE for a lexical block. */
18641 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18643 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18645 if (call_arg_locations
)
18647 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18648 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18649 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18652 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18653 add_high_low_attributes (stmt
, stmt_die
);
18655 decls_for_scope (stmt
, stmt_die
, depth
);
18658 /* Generate a DIE for an inlined subprogram. */
18661 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18665 /* The instance of function that is effectively being inlined shall not
18667 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18669 decl
= block_ultimate_origin (stmt
);
18671 /* Emit info for the abstract instance first, if we haven't yet. We
18672 must emit this even if the block is abstract, otherwise when we
18673 emit the block below (or elsewhere), we may end up trying to emit
18674 a die whose origin die hasn't been emitted, and crashing. */
18675 dwarf2out_abstract_function (decl
);
18677 if (! BLOCK_ABSTRACT (stmt
))
18679 dw_die_ref subr_die
18680 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18682 if (call_arg_locations
)
18684 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18685 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18686 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18688 add_abstract_origin_attribute (subr_die
, decl
);
18689 if (TREE_ASM_WRITTEN (stmt
))
18690 add_high_low_attributes (stmt
, subr_die
);
18691 add_call_src_coords_attributes (stmt
, subr_die
);
18693 decls_for_scope (stmt
, subr_die
, depth
);
18694 current_function_has_inlines
= 1;
18698 /* Generate a DIE for a field in a record, or structure. */
18701 gen_field_die (tree decl
, dw_die_ref context_die
)
18703 dw_die_ref decl_die
;
18705 if (TREE_TYPE (decl
) == error_mark_node
)
18708 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18709 add_name_and_src_coords_attributes (decl_die
, decl
);
18710 add_type_attribute (decl_die
, member_declared_type (decl
),
18711 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18714 if (DECL_BIT_FIELD_TYPE (decl
))
18716 add_byte_size_attribute (decl_die
, decl
);
18717 add_bit_size_attribute (decl_die
, decl
);
18718 add_bit_offset_attribute (decl_die
, decl
);
18721 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18722 add_data_member_location_attribute (decl_die
, decl
);
18724 if (DECL_ARTIFICIAL (decl
))
18725 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18727 add_accessibility_attribute (decl_die
, decl
);
18729 /* Equate decl number to die, so that we can look up this decl later on. */
18730 equate_decl_number_to_die (decl
, decl_die
);
18734 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18735 Use modified_type_die instead.
18736 We keep this code here just in case these types of DIEs may be needed to
18737 represent certain things in other languages (e.g. Pascal) someday. */
18740 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18743 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18745 equate_type_number_to_die (type
, ptr_die
);
18746 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18747 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18750 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18751 Use modified_type_die instead.
18752 We keep this code here just in case these types of DIEs may be needed to
18753 represent certain things in other languages (e.g. Pascal) someday. */
18756 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18758 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18760 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18761 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18763 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18765 equate_type_number_to_die (type
, ref_die
);
18766 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18767 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18771 /* Generate a DIE for a pointer to a member type. */
18774 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18777 = new_die (DW_TAG_ptr_to_member_type
,
18778 scope_die_for (type
, context_die
), type
);
18780 equate_type_number_to_die (type
, ptr_die
);
18781 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18782 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18783 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18786 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18788 static char *producer_string
;
18790 /* Return a heap allocated producer string including command line options
18791 if -grecord-gcc-switches. */
18794 gen_producer_string (void)
18797 vec
<dchar_p
> switches
= vNULL
;
18798 const char *language_string
= lang_hooks
.name
;
18799 char *producer
, *tail
;
18801 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18802 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18804 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18805 switch (save_decoded_options
[j
].opt_index
)
18812 case OPT_auxbase_strip
:
18821 case OPT_SPECIAL_unknown
:
18822 case OPT_SPECIAL_ignore
:
18823 case OPT_SPECIAL_program_name
:
18824 case OPT_SPECIAL_input_file
:
18825 case OPT_grecord_gcc_switches
:
18826 case OPT_gno_record_gcc_switches
:
18827 case OPT__output_pch_
:
18828 case OPT_fdiagnostics_show_location_
:
18829 case OPT_fdiagnostics_show_option
:
18830 case OPT_fdiagnostics_show_caret
:
18831 case OPT_fverbose_asm
:
18833 case OPT__sysroot_
:
18835 case OPT_nostdinc__
:
18836 /* Ignore these. */
18839 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
18840 & CL_NO_DWARF_RECORD
)
18842 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18844 switch (save_decoded_options
[j
].canonical_option
[0][1])
18851 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18858 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
18859 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18863 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18865 sprintf (tail
, "%s %s", language_string
, version_string
);
18868 FOR_EACH_VEC_ELT (switches
, j
, p
)
18872 memcpy (tail
+ 1, p
, len
);
18877 switches
.release ();
18881 /* Generate the DIE for the compilation unit. */
18884 gen_compile_unit_die (const char *filename
)
18887 const char *language_string
= lang_hooks
.name
;
18890 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18894 add_name_attribute (die
, filename
);
18895 /* Don't add cwd for <built-in>. */
18896 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
18897 add_comp_dir_attribute (die
);
18900 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
18902 /* If our producer is LTO try to figure out a common language to use
18903 from the global list of translation units. */
18904 if (strcmp (language_string
, "GNU GIMPLE") == 0)
18908 const char *common_lang
= NULL
;
18910 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
18912 if (!TRANSLATION_UNIT_LANGUAGE (t
))
18915 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
18916 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
18918 else if (strncmp (common_lang
, "GNU C", 5) == 0
18919 && strncmp(TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
18920 /* Mixing C and C++ is ok, use C++ in that case. */
18921 common_lang
= "GNU C++";
18924 /* Fall back to C. */
18925 common_lang
= NULL
;
18931 language_string
= common_lang
;
18934 language
= DW_LANG_C89
;
18935 if (strcmp (language_string
, "GNU C++") == 0)
18936 language
= DW_LANG_C_plus_plus
;
18937 else if (strcmp (language_string
, "GNU F77") == 0)
18938 language
= DW_LANG_Fortran77
;
18939 else if (strcmp (language_string
, "GNU Pascal") == 0)
18940 language
= DW_LANG_Pascal83
;
18941 else if (dwarf_version
>= 3 || !dwarf_strict
)
18943 if (strcmp (language_string
, "GNU Ada") == 0)
18944 language
= DW_LANG_Ada95
;
18945 else if (strcmp (language_string
, "GNU Fortran") == 0)
18946 language
= DW_LANG_Fortran95
;
18947 else if (strcmp (language_string
, "GNU Java") == 0)
18948 language
= DW_LANG_Java
;
18949 else if (strcmp (language_string
, "GNU Objective-C") == 0)
18950 language
= DW_LANG_ObjC
;
18951 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
18952 language
= DW_LANG_ObjC_plus_plus
;
18953 else if (dwarf_version
>= 5 || !dwarf_strict
)
18955 if (strcmp (language_string
, "GNU Go") == 0)
18956 language
= DW_LANG_Go
;
18959 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
18960 else if (strcmp (language_string
, "GNU Fortran") == 0)
18961 language
= DW_LANG_Fortran90
;
18963 add_AT_unsigned (die
, DW_AT_language
, language
);
18967 case DW_LANG_Fortran77
:
18968 case DW_LANG_Fortran90
:
18969 case DW_LANG_Fortran95
:
18970 /* Fortran has case insensitive identifiers and the front-end
18971 lowercases everything. */
18972 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
18975 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18981 /* Generate the DIE for a base class. */
18984 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
18986 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
18988 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
18989 add_data_member_location_attribute (die
, binfo
);
18991 if (BINFO_VIRTUAL_P (binfo
))
18992 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18994 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
18995 children, otherwise the default is DW_ACCESS_public. In DWARF2
18996 the default has always been DW_ACCESS_private. */
18997 if (access
== access_public_node
)
18999 if (dwarf_version
== 2
19000 || context_die
->die_tag
== DW_TAG_class_type
)
19001 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19003 else if (access
== access_protected_node
)
19004 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19005 else if (dwarf_version
> 2
19006 && context_die
->die_tag
!= DW_TAG_class_type
)
19007 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19010 /* Generate a DIE for a class member. */
19013 gen_member_die (tree type
, dw_die_ref context_die
)
19016 tree binfo
= TYPE_BINFO (type
);
19019 /* If this is not an incomplete type, output descriptions of each of its
19020 members. Note that as we output the DIEs necessary to represent the
19021 members of this record or union type, we will also be trying to output
19022 DIEs to represent the *types* of those members. However the `type'
19023 function (above) will specifically avoid generating type DIEs for member
19024 types *within* the list of member DIEs for this (containing) type except
19025 for those types (of members) which are explicitly marked as also being
19026 members of this (containing) type themselves. The g++ front- end can
19027 force any given type to be treated as a member of some other (containing)
19028 type by setting the TYPE_CONTEXT of the given (member) type to point to
19029 the TREE node representing the appropriate (containing) type. */
19031 /* First output info about the base classes. */
19034 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19038 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19039 gen_inheritance_die (base
,
19040 (accesses
? (*accesses
)[i
] : access_public_node
),
19044 /* Now output info about the data members and type members. */
19045 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19047 /* If we thought we were generating minimal debug info for TYPE
19048 and then changed our minds, some of the member declarations
19049 may have already been defined. Don't define them again, but
19050 do put them in the right order. */
19052 child
= lookup_decl_die (member
);
19054 splice_child_die (context_die
, child
);
19056 gen_decl_die (member
, NULL
, context_die
);
19059 /* Now output info about the function members (if any). */
19060 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19062 /* Don't include clones in the member list. */
19063 if (DECL_ABSTRACT_ORIGIN (member
))
19066 child
= lookup_decl_die (member
);
19068 splice_child_die (context_die
, child
);
19070 gen_decl_die (member
, NULL
, context_die
);
19074 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19075 is set, we pretend that the type was never defined, so we only get the
19076 member DIEs needed by later specification DIEs. */
19079 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19080 enum debug_info_usage usage
)
19082 dw_die_ref type_die
= lookup_type_die (type
);
19083 dw_die_ref scope_die
= 0;
19085 int complete
= (TYPE_SIZE (type
)
19086 && (! TYPE_STUB_DECL (type
)
19087 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19088 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19089 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19091 if (type_die
&& ! complete
)
19094 if (TYPE_CONTEXT (type
) != NULL_TREE
19095 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19096 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19099 scope_die
= scope_die_for (type
, context_die
);
19101 /* Generate child dies for template paramaters. */
19102 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19103 schedule_generic_params_dies_gen (type
);
19105 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19106 /* First occurrence of type or toplevel definition of nested class. */
19108 dw_die_ref old_die
= type_die
;
19110 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19111 ? record_type_tag (type
) : DW_TAG_union_type
,
19113 equate_type_number_to_die (type
, type_die
);
19115 add_AT_specification (type_die
, old_die
);
19117 add_name_attribute (type_die
, type_tag (type
));
19120 remove_AT (type_die
, DW_AT_declaration
);
19122 /* If this type has been completed, then give it a byte_size attribute and
19123 then give a list of members. */
19124 if (complete
&& !ns_decl
)
19126 /* Prevent infinite recursion in cases where the type of some member of
19127 this type is expressed in terms of this type itself. */
19128 TREE_ASM_WRITTEN (type
) = 1;
19129 add_byte_size_attribute (type_die
, type
);
19130 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19132 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19133 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19136 /* If the first reference to this type was as the return type of an
19137 inline function, then it may not have a parent. Fix this now. */
19138 if (type_die
->die_parent
== NULL
)
19139 add_child_die (scope_die
, type_die
);
19141 push_decl_scope (type
);
19142 gen_member_die (type
, type_die
);
19145 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19146 if (TYPE_ARTIFICIAL (type
))
19147 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19149 /* GNU extension: Record what type our vtable lives in. */
19150 if (TYPE_VFIELD (type
))
19152 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19154 gen_type_die (vtype
, context_die
);
19155 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19156 lookup_type_die (vtype
));
19161 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19163 /* We don't need to do this for function-local types. */
19164 if (TYPE_STUB_DECL (type
)
19165 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19166 vec_safe_push (incomplete_types
, type
);
19169 if (get_AT (type_die
, DW_AT_name
))
19170 add_pubtype (type
, type_die
);
19173 /* Generate a DIE for a subroutine _type_. */
19176 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19178 tree return_type
= TREE_TYPE (type
);
19179 dw_die_ref subr_die
19180 = new_die (DW_TAG_subroutine_type
,
19181 scope_die_for (type
, context_die
), type
);
19183 equate_type_number_to_die (type
, subr_die
);
19184 add_prototyped_attribute (subr_die
, type
);
19185 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19186 gen_formal_types_die (type
, subr_die
);
19188 if (get_AT (subr_die
, DW_AT_name
))
19189 add_pubtype (type
, subr_die
);
19192 /* Generate a DIE for a type definition. */
19195 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19197 dw_die_ref type_die
;
19200 if (TREE_ASM_WRITTEN (decl
))
19203 TREE_ASM_WRITTEN (decl
) = 1;
19204 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19205 origin
= decl_ultimate_origin (decl
);
19206 if (origin
!= NULL
)
19207 add_abstract_origin_attribute (type_die
, origin
);
19212 add_name_and_src_coords_attributes (type_die
, decl
);
19213 if (DECL_ORIGINAL_TYPE (decl
))
19215 type
= DECL_ORIGINAL_TYPE (decl
);
19217 gcc_assert (type
!= TREE_TYPE (decl
));
19218 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19222 type
= TREE_TYPE (decl
);
19224 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19226 /* Here, we are in the case of decl being a typedef naming
19227 an anonymous type, e.g:
19228 typedef struct {...} foo;
19229 In that case TREE_TYPE (decl) is not a typedef variant
19230 type and TYPE_NAME of the anonymous type is set to the
19231 TYPE_DECL of the typedef. This construct is emitted by
19234 TYPE is the anonymous struct named by the typedef
19235 DECL. As we need the DW_AT_type attribute of the
19236 DW_TAG_typedef to point to the DIE of TYPE, let's
19237 generate that DIE right away. add_type_attribute
19238 called below will then pick (via lookup_type_die) that
19239 anonymous struct DIE. */
19240 if (!TREE_ASM_WRITTEN (type
))
19241 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19243 /* This is a GNU Extension. We are adding a
19244 DW_AT_linkage_name attribute to the DIE of the
19245 anonymous struct TYPE. The value of that attribute
19246 is the name of the typedef decl naming the anonymous
19247 struct. This greatly eases the work of consumers of
19248 this debug info. */
19249 add_linkage_attr (lookup_type_die (type
), decl
);
19253 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19254 TREE_THIS_VOLATILE (decl
), context_die
);
19256 if (is_naming_typedef_decl (decl
))
19257 /* We want that all subsequent calls to lookup_type_die with
19258 TYPE in argument yield the DW_TAG_typedef we have just
19260 equate_type_number_to_die (type
, type_die
);
19262 add_accessibility_attribute (type_die
, decl
);
19265 if (DECL_ABSTRACT (decl
))
19266 equate_decl_number_to_die (decl
, type_die
);
19268 if (get_AT (type_die
, DW_AT_name
))
19269 add_pubtype (decl
, type_die
);
19272 /* Generate a DIE for a struct, class, enum or union type. */
19275 gen_tagged_type_die (tree type
,
19276 dw_die_ref context_die
,
19277 enum debug_info_usage usage
)
19281 if (type
== NULL_TREE
19282 || !is_tagged_type (type
))
19285 /* If this is a nested type whose containing class hasn't been written
19286 out yet, writing it out will cover this one, too. This does not apply
19287 to instantiations of member class templates; they need to be added to
19288 the containing class as they are generated. FIXME: This hurts the
19289 idea of combining type decls from multiple TUs, since we can't predict
19290 what set of template instantiations we'll get. */
19291 if (TYPE_CONTEXT (type
)
19292 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19293 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19295 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19297 if (TREE_ASM_WRITTEN (type
))
19300 /* If that failed, attach ourselves to the stub. */
19301 push_decl_scope (TYPE_CONTEXT (type
));
19302 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19305 else if (TYPE_CONTEXT (type
) != NULL_TREE
19306 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19308 /* If this type is local to a function that hasn't been written
19309 out yet, use a NULL context for now; it will be fixed up in
19310 decls_for_scope. */
19311 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19312 /* A declaration DIE doesn't count; nested types need to go in the
19314 if (context_die
&& is_declaration_die (context_die
))
19315 context_die
= NULL
;
19320 context_die
= declare_in_namespace (type
, context_die
);
19324 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19326 /* This might have been written out by the call to
19327 declare_in_namespace. */
19328 if (!TREE_ASM_WRITTEN (type
))
19329 gen_enumeration_type_die (type
, context_die
);
19332 gen_struct_or_union_type_die (type
, context_die
, usage
);
19337 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19338 it up if it is ever completed. gen_*_type_die will set it for us
19339 when appropriate. */
19342 /* Generate a type description DIE. */
19345 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19346 enum debug_info_usage usage
)
19348 struct array_descr_info info
;
19350 if (type
== NULL_TREE
|| type
== error_mark_node
)
19353 if (TYPE_NAME (type
) != NULL_TREE
19354 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19355 && is_redundant_typedef (TYPE_NAME (type
))
19356 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19357 /* The DECL of this type is a typedef we don't want to emit debug
19358 info for but we want debug info for its underlying typedef.
19359 This can happen for e.g, the injected-class-name of a C++
19361 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19363 /* If TYPE is a typedef type variant, let's generate debug info
19364 for the parent typedef which TYPE is a type of. */
19365 if (typedef_variant_p (type
))
19367 if (TREE_ASM_WRITTEN (type
))
19370 /* Prevent broken recursion; we can't hand off to the same type. */
19371 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19373 /* Give typedefs the right scope. */
19374 context_die
= scope_die_for (type
, context_die
);
19376 TREE_ASM_WRITTEN (type
) = 1;
19378 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19382 /* If type is an anonymous tagged type named by a typedef, let's
19383 generate debug info for the typedef. */
19384 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19386 /* Use the DIE of the containing namespace as the parent DIE of
19387 the type description DIE we want to generate. */
19388 if (DECL_CONTEXT (TYPE_NAME (type
))
19389 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19390 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19392 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19396 /* If this is an array type with hidden descriptor, handle it first. */
19397 if (!TREE_ASM_WRITTEN (type
)
19398 && lang_hooks
.types
.get_array_descr_info
19399 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19400 && (dwarf_version
>= 3 || !dwarf_strict
))
19402 gen_descr_array_type_die (type
, &info
, context_die
);
19403 TREE_ASM_WRITTEN (type
) = 1;
19407 /* We are going to output a DIE to represent the unqualified version
19408 of this type (i.e. without any const or volatile qualifiers) so
19409 get the main variant (i.e. the unqualified version) of this type
19410 now. (Vectors are special because the debugging info is in the
19411 cloned type itself). */
19412 if (TREE_CODE (type
) != VECTOR_TYPE
)
19413 type
= type_main_variant (type
);
19415 if (TREE_ASM_WRITTEN (type
))
19418 switch (TREE_CODE (type
))
19424 case REFERENCE_TYPE
:
19425 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19426 ensures that the gen_type_die recursion will terminate even if the
19427 type is recursive. Recursive types are possible in Ada. */
19428 /* ??? We could perhaps do this for all types before the switch
19430 TREE_ASM_WRITTEN (type
) = 1;
19432 /* For these types, all that is required is that we output a DIE (or a
19433 set of DIEs) to represent the "basis" type. */
19434 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19435 DINFO_USAGE_IND_USE
);
19439 /* This code is used for C++ pointer-to-data-member types.
19440 Output a description of the relevant class type. */
19441 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19442 DINFO_USAGE_IND_USE
);
19444 /* Output a description of the type of the object pointed to. */
19445 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19446 DINFO_USAGE_IND_USE
);
19448 /* Now output a DIE to represent this pointer-to-data-member type
19450 gen_ptr_to_mbr_type_die (type
, context_die
);
19453 case FUNCTION_TYPE
:
19454 /* Force out return type (in case it wasn't forced out already). */
19455 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19456 DINFO_USAGE_DIR_USE
);
19457 gen_subroutine_type_die (type
, context_die
);
19461 /* Force out return type (in case it wasn't forced out already). */
19462 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19463 DINFO_USAGE_DIR_USE
);
19464 gen_subroutine_type_die (type
, context_die
);
19468 gen_array_type_die (type
, context_die
);
19472 gen_array_type_die (type
, context_die
);
19475 case ENUMERAL_TYPE
:
19478 case QUAL_UNION_TYPE
:
19479 gen_tagged_type_die (type
, context_die
, usage
);
19485 case FIXED_POINT_TYPE
:
19488 /* No DIEs needed for fundamental types. */
19493 /* Just use DW_TAG_unspecified_type. */
19495 dw_die_ref type_die
= lookup_type_die (type
);
19496 if (type_die
== NULL
)
19498 tree name
= TYPE_NAME (type
);
19499 if (TREE_CODE (name
) == TYPE_DECL
)
19500 name
= DECL_NAME (name
);
19501 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19502 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19503 equate_type_number_to_die (type
, type_die
);
19509 gcc_unreachable ();
19512 TREE_ASM_WRITTEN (type
) = 1;
19516 gen_type_die (tree type
, dw_die_ref context_die
)
19518 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19521 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19522 things which are local to the given block. */
19525 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19527 int must_output_die
= 0;
19530 /* Ignore blocks that are NULL. */
19531 if (stmt
== NULL_TREE
)
19534 inlined_func
= inlined_function_outer_scope_p (stmt
);
19536 /* If the block is one fragment of a non-contiguous block, do not
19537 process the variables, since they will have been done by the
19538 origin block. Do process subblocks. */
19539 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19543 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19544 gen_block_die (sub
, context_die
, depth
+ 1);
19549 /* Determine if we need to output any Dwarf DIEs at all to represent this
19552 /* The outer scopes for inlinings *must* always be represented. We
19553 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19554 must_output_die
= 1;
19557 /* Determine if this block directly contains any "significant"
19558 local declarations which we will need to output DIEs for. */
19559 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19560 /* We are not in terse mode so *any* local declaration counts
19561 as being a "significant" one. */
19562 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19563 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19564 && (TREE_USED (stmt
)
19565 || TREE_ASM_WRITTEN (stmt
)
19566 || BLOCK_ABSTRACT (stmt
)));
19567 else if ((TREE_USED (stmt
)
19568 || TREE_ASM_WRITTEN (stmt
)
19569 || BLOCK_ABSTRACT (stmt
))
19570 && !dwarf2out_ignore_block (stmt
))
19571 must_output_die
= 1;
19574 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19575 DIE for any block which contains no significant local declarations at
19576 all. Rather, in such cases we just call `decls_for_scope' so that any
19577 needed Dwarf info for any sub-blocks will get properly generated. Note
19578 that in terse mode, our definition of what constitutes a "significant"
19579 local declaration gets restricted to include only inlined function
19580 instances and local (nested) function definitions. */
19581 if (must_output_die
)
19585 /* If STMT block is abstract, that means we have been called
19586 indirectly from dwarf2out_abstract_function.
19587 That function rightfully marks the descendent blocks (of
19588 the abstract function it is dealing with) as being abstract,
19589 precisely to prevent us from emitting any
19590 DW_TAG_inlined_subroutine DIE as a descendent
19591 of an abstract function instance. So in that case, we should
19592 not call gen_inlined_subroutine_die.
19594 Later though, when cgraph asks dwarf2out to emit info
19595 for the concrete instance of the function decl into which
19596 the concrete instance of STMT got inlined, the later will lead
19597 to the generation of a DW_TAG_inlined_subroutine DIE. */
19598 if (! BLOCK_ABSTRACT (stmt
))
19599 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19602 gen_lexical_block_die (stmt
, context_die
, depth
);
19605 decls_for_scope (stmt
, context_die
, depth
);
19608 /* Process variable DECL (or variable with origin ORIGIN) within
19609 block STMT and add it to CONTEXT_DIE. */
19611 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19614 tree decl_or_origin
= decl
? decl
: origin
;
19616 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19617 die
= lookup_decl_die (decl_or_origin
);
19618 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19619 && TYPE_DECL_IS_STUB (decl_or_origin
))
19620 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19624 if (die
!= NULL
&& die
->die_parent
== NULL
)
19625 add_child_die (context_die
, die
);
19626 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19627 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19628 stmt
, context_die
);
19630 gen_decl_die (decl
, origin
, context_die
);
19633 /* Generate all of the decls declared within a given scope and (recursively)
19634 all of its sub-blocks. */
19637 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19643 /* Ignore NULL blocks. */
19644 if (stmt
== NULL_TREE
)
19647 /* Output the DIEs to represent all of the data objects and typedefs
19648 declared directly within this block but not within any nested
19649 sub-blocks. Also, nested function and tag DIEs have been
19650 generated with a parent of NULL; fix that up now. */
19651 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19652 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19653 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19654 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19657 /* If we're at -g1, we're not interested in subblocks. */
19658 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19661 /* Output the DIEs to represent all sub-blocks (and the items declared
19662 therein) of this block. */
19663 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19665 subblocks
= BLOCK_CHAIN (subblocks
))
19666 gen_block_die (subblocks
, context_die
, depth
+ 1);
19669 /* Is this a typedef we can avoid emitting? */
19672 is_redundant_typedef (const_tree decl
)
19674 if (TYPE_DECL_IS_STUB (decl
))
19677 if (DECL_ARTIFICIAL (decl
)
19678 && DECL_CONTEXT (decl
)
19679 && is_tagged_type (DECL_CONTEXT (decl
))
19680 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19681 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19682 /* Also ignore the artificial member typedef for the class name. */
19688 /* Return TRUE if TYPE is a typedef that names a type for linkage
19689 purposes. This kind of typedefs is produced by the C++ FE for
19692 typedef struct {...} foo;
19694 In that case, there is no typedef variant type produced for foo.
19695 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19699 is_naming_typedef_decl (const_tree decl
)
19701 if (decl
== NULL_TREE
19702 || TREE_CODE (decl
) != TYPE_DECL
19703 || !is_tagged_type (TREE_TYPE (decl
))
19704 || DECL_IS_BUILTIN (decl
)
19705 || is_redundant_typedef (decl
)
19706 /* It looks like Ada produces TYPE_DECLs that are very similar
19707 to C++ naming typedefs but that have different
19708 semantics. Let's be specific to c++ for now. */
19712 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19713 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19714 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19715 != TYPE_NAME (TREE_TYPE (decl
))));
19718 /* Returns the DIE for a context. */
19720 static inline dw_die_ref
19721 get_context_die (tree context
)
19725 /* Find die that represents this context. */
19726 if (TYPE_P (context
))
19728 context
= TYPE_MAIN_VARIANT (context
);
19729 return strip_naming_typedef (context
, force_type_die (context
));
19732 return force_decl_die (context
);
19734 return comp_unit_die ();
19737 /* Returns the DIE for decl. A DIE will always be returned. */
19740 force_decl_die (tree decl
)
19742 dw_die_ref decl_die
;
19743 unsigned saved_external_flag
;
19744 tree save_fn
= NULL_TREE
;
19745 decl_die
= lookup_decl_die (decl
);
19748 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19750 decl_die
= lookup_decl_die (decl
);
19754 switch (TREE_CODE (decl
))
19756 case FUNCTION_DECL
:
19757 /* Clear current_function_decl, so that gen_subprogram_die thinks
19758 that this is a declaration. At this point, we just want to force
19759 declaration die. */
19760 save_fn
= current_function_decl
;
19761 current_function_decl
= NULL_TREE
;
19762 gen_subprogram_die (decl
, context_die
);
19763 current_function_decl
= save_fn
;
19767 /* Set external flag to force declaration die. Restore it after
19768 gen_decl_die() call. */
19769 saved_external_flag
= DECL_EXTERNAL (decl
);
19770 DECL_EXTERNAL (decl
) = 1;
19771 gen_decl_die (decl
, NULL
, context_die
);
19772 DECL_EXTERNAL (decl
) = saved_external_flag
;
19775 case NAMESPACE_DECL
:
19776 if (dwarf_version
>= 3 || !dwarf_strict
)
19777 dwarf2out_decl (decl
);
19779 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19780 decl_die
= comp_unit_die ();
19783 case TRANSLATION_UNIT_DECL
:
19784 decl_die
= comp_unit_die ();
19788 gcc_unreachable ();
19791 /* We should be able to find the DIE now. */
19793 decl_die
= lookup_decl_die (decl
);
19794 gcc_assert (decl_die
);
19800 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19801 always returned. */
19804 force_type_die (tree type
)
19806 dw_die_ref type_die
;
19808 type_die
= lookup_type_die (type
);
19811 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19813 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19814 TYPE_VOLATILE (type
), context_die
);
19815 gcc_assert (type_die
);
19820 /* Force out any required namespaces to be able to output DECL,
19821 and return the new context_die for it, if it's changed. */
19824 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19826 tree context
= (DECL_P (thing
)
19827 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19828 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19829 /* Force out the namespace. */
19830 context_die
= force_decl_die (context
);
19832 return context_die
;
19835 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19836 type) within its namespace, if appropriate.
19838 For compatibility with older debuggers, namespace DIEs only contain
19839 declarations; all definitions are emitted at CU scope. */
19842 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19844 dw_die_ref ns_context
;
19846 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19847 return context_die
;
19849 /* If this decl is from an inlined function, then don't try to emit it in its
19850 namespace, as we will get confused. It would have already been emitted
19851 when the abstract instance of the inline function was emitted anyways. */
19852 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19853 return context_die
;
19855 ns_context
= setup_namespace_context (thing
, context_die
);
19857 if (ns_context
!= context_die
)
19861 if (DECL_P (thing
))
19862 gen_decl_die (thing
, NULL
, ns_context
);
19864 gen_type_die (thing
, ns_context
);
19866 return context_die
;
19869 /* Generate a DIE for a namespace or namespace alias. */
19872 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19874 dw_die_ref namespace_die
;
19876 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19877 they are an alias of. */
19878 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19880 /* Output a real namespace or module. */
19881 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19882 namespace_die
= new_die (is_fortran ()
19883 ? DW_TAG_module
: DW_TAG_namespace
,
19884 context_die
, decl
);
19885 /* For Fortran modules defined in different CU don't add src coords. */
19886 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19888 const char *name
= dwarf2_name (decl
, 0);
19890 add_name_attribute (namespace_die
, name
);
19893 add_name_and_src_coords_attributes (namespace_die
, decl
);
19894 if (DECL_EXTERNAL (decl
))
19895 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
19896 equate_decl_number_to_die (decl
, namespace_die
);
19900 /* Output a namespace alias. */
19902 /* Force out the namespace we are an alias of, if necessary. */
19903 dw_die_ref origin_die
19904 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
19906 if (DECL_FILE_SCOPE_P (decl
)
19907 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
19908 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19909 /* Now create the namespace alias DIE. */
19910 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
19911 add_name_and_src_coords_attributes (namespace_die
, decl
);
19912 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
19913 equate_decl_number_to_die (decl
, namespace_die
);
19915 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
19916 if (want_pubnames ())
19917 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
19920 /* Generate Dwarf debug information for a decl described by DECL.
19921 The return value is currently only meaningful for PARM_DECLs,
19922 for all other decls it returns NULL. */
19925 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
19927 tree decl_or_origin
= decl
? decl
: origin
;
19928 tree class_origin
= NULL
, ultimate_origin
;
19930 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
19933 switch (TREE_CODE (decl_or_origin
))
19939 if (!is_fortran () && !is_ada ())
19941 /* The individual enumerators of an enum type get output when we output
19942 the Dwarf representation of the relevant enum type itself. */
19946 /* Emit its type. */
19947 gen_type_die (TREE_TYPE (decl
), context_die
);
19949 /* And its containing namespace. */
19950 context_die
= declare_in_namespace (decl
, context_die
);
19952 gen_const_die (decl
, context_die
);
19955 case FUNCTION_DECL
:
19956 /* Don't output any DIEs to represent mere function declarations,
19957 unless they are class members or explicit block externs. */
19958 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
19959 && DECL_FILE_SCOPE_P (decl_or_origin
)
19960 && (current_function_decl
== NULL_TREE
19961 || DECL_ARTIFICIAL (decl_or_origin
)))
19966 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19967 on local redeclarations of global functions. That seems broken. */
19968 if (current_function_decl
!= decl
)
19969 /* This is only a declaration. */;
19972 /* If we're emitting a clone, emit info for the abstract instance. */
19973 if (origin
|| DECL_ORIGIN (decl
) != decl
)
19974 dwarf2out_abstract_function (origin
19975 ? DECL_ORIGIN (origin
)
19976 : DECL_ABSTRACT_ORIGIN (decl
));
19978 /* If we're emitting an out-of-line copy of an inline function,
19979 emit info for the abstract instance and set up to refer to it. */
19980 else if (cgraph_function_possibly_inlined_p (decl
)
19981 && ! DECL_ABSTRACT (decl
)
19982 && ! class_or_namespace_scope_p (context_die
)
19983 /* dwarf2out_abstract_function won't emit a die if this is just
19984 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19985 that case, because that works only if we have a die. */
19986 && DECL_INITIAL (decl
) != NULL_TREE
)
19988 dwarf2out_abstract_function (decl
);
19989 set_decl_origin_self (decl
);
19992 /* Otherwise we're emitting the primary DIE for this decl. */
19993 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
19995 /* Before we describe the FUNCTION_DECL itself, make sure that we
19996 have its containing type. */
19998 origin
= decl_class_context (decl
);
19999 if (origin
!= NULL_TREE
)
20000 gen_type_die (origin
, context_die
);
20002 /* And its return type. */
20003 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20005 /* And its virtual context. */
20006 if (DECL_VINDEX (decl
) != NULL_TREE
)
20007 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20009 /* Make sure we have a member DIE for decl. */
20010 if (origin
!= NULL_TREE
)
20011 gen_type_die_for_member (origin
, decl
, context_die
);
20013 /* And its containing namespace. */
20014 context_die
= declare_in_namespace (decl
, context_die
);
20017 /* Now output a DIE to represent the function itself. */
20019 gen_subprogram_die (decl
, context_die
);
20023 /* If we are in terse mode, don't generate any DIEs to represent any
20024 actual typedefs. */
20025 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20028 /* In the special case of a TYPE_DECL node representing the declaration
20029 of some type tag, if the given TYPE_DECL is marked as having been
20030 instantiated from some other (original) TYPE_DECL node (e.g. one which
20031 was generated within the original definition of an inline function) we
20032 used to generate a special (abbreviated) DW_TAG_structure_type,
20033 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20034 should be actually referencing those DIEs, as variable DIEs with that
20035 type would be emitted already in the abstract origin, so it was always
20036 removed during unused type prunning. Don't add anything in this
20038 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20041 if (is_redundant_typedef (decl
))
20042 gen_type_die (TREE_TYPE (decl
), context_die
);
20044 /* Output a DIE to represent the typedef itself. */
20045 gen_typedef_die (decl
, context_die
);
20049 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20050 gen_label_die (decl
, context_die
);
20055 /* If we are in terse mode, don't generate any DIEs to represent any
20056 variable declarations or definitions. */
20057 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20060 /* Output any DIEs that are needed to specify the type of this data
20062 if (decl_by_reference_p (decl_or_origin
))
20063 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20065 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20067 /* And its containing type. */
20068 class_origin
= decl_class_context (decl_or_origin
);
20069 if (class_origin
!= NULL_TREE
)
20070 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20072 /* And its containing namespace. */
20073 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20075 /* Now output the DIE to represent the data object itself. This gets
20076 complicated because of the possibility that the VAR_DECL really
20077 represents an inlined instance of a formal parameter for an inline
20079 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20080 if (ultimate_origin
!= NULL_TREE
20081 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20082 gen_formal_parameter_die (decl
, origin
,
20083 true /* Emit name attribute. */,
20086 gen_variable_die (decl
, origin
, context_die
);
20090 /* Ignore the nameless fields that are used to skip bits but handle C++
20091 anonymous unions and structs. */
20092 if (DECL_NAME (decl
) != NULL_TREE
20093 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20094 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20096 gen_type_die (member_declared_type (decl
), context_die
);
20097 gen_field_die (decl
, context_die
);
20102 if (DECL_BY_REFERENCE (decl_or_origin
))
20103 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20105 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20106 return gen_formal_parameter_die (decl
, origin
,
20107 true /* Emit name attribute. */,
20110 case NAMESPACE_DECL
:
20111 case IMPORTED_DECL
:
20112 if (dwarf_version
>= 3 || !dwarf_strict
)
20113 gen_namespace_die (decl
, context_die
);
20117 /* Probably some frontend-internal decl. Assume we don't care. */
20118 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20125 /* Output debug information for global decl DECL. Called from toplev.c after
20126 compilation proper has finished. */
20129 dwarf2out_global_decl (tree decl
)
20131 /* Output DWARF2 information for file-scope tentative data object
20132 declarations, file-scope (extern) function declarations (which
20133 had no corresponding body) and file-scope tagged type declarations
20134 and definitions which have not yet been forced out. */
20135 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20136 dwarf2out_decl (decl
);
20139 /* Output debug information for type decl DECL. Called from toplev.c
20140 and from language front ends (to record built-in types). */
20142 dwarf2out_type_decl (tree decl
, int local
)
20145 dwarf2out_decl (decl
);
20148 /* Output debug information for imported module or decl DECL.
20149 NAME is non-NULL name in the lexical block if the decl has been renamed.
20150 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20151 that DECL belongs to.
20152 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20154 dwarf2out_imported_module_or_decl_1 (tree decl
,
20156 tree lexical_block
,
20157 dw_die_ref lexical_block_die
)
20159 expanded_location xloc
;
20160 dw_die_ref imported_die
= NULL
;
20161 dw_die_ref at_import_die
;
20163 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20165 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20166 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20170 xloc
= expand_location (input_location
);
20172 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20174 at_import_die
= force_type_die (TREE_TYPE (decl
));
20175 /* For namespace N { typedef void T; } using N::T; base_type_die
20176 returns NULL, but DW_TAG_imported_declaration requires
20177 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20178 if (!at_import_die
)
20180 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20181 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20182 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20183 gcc_assert (at_import_die
);
20188 at_import_die
= lookup_decl_die (decl
);
20189 if (!at_import_die
)
20191 /* If we're trying to avoid duplicate debug info, we may not have
20192 emitted the member decl for this field. Emit it now. */
20193 if (TREE_CODE (decl
) == FIELD_DECL
)
20195 tree type
= DECL_CONTEXT (decl
);
20197 if (TYPE_CONTEXT (type
)
20198 && TYPE_P (TYPE_CONTEXT (type
))
20199 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20200 DINFO_USAGE_DIR_USE
))
20202 gen_type_die_for_member (type
, decl
,
20203 get_context_die (TYPE_CONTEXT (type
)));
20205 at_import_die
= force_decl_die (decl
);
20209 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20211 if (dwarf_version
>= 3 || !dwarf_strict
)
20212 imported_die
= new_die (DW_TAG_imported_module
,
20219 imported_die
= new_die (DW_TAG_imported_declaration
,
20223 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20224 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20226 add_AT_string (imported_die
, DW_AT_name
,
20227 IDENTIFIER_POINTER (name
));
20228 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20231 /* Output debug information for imported module or decl DECL.
20232 NAME is non-NULL name in context if the decl has been renamed.
20233 CHILD is true if decl is one of the renamed decls as part of
20234 importing whole module. */
20237 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20240 /* dw_die_ref at_import_die; */
20241 dw_die_ref scope_die
;
20243 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20248 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20249 We need decl DIE for reference and scope die. First, get DIE for the decl
20252 /* Get the scope die for decl context. Use comp_unit_die for global module
20253 or decl. If die is not found for non globals, force new die. */
20255 && TYPE_P (context
)
20256 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20259 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20262 scope_die
= get_context_die (context
);
20266 gcc_assert (scope_die
->die_child
);
20267 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20268 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20269 scope_die
= scope_die
->die_child
;
20272 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20273 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20277 /* Write the debugging output for DECL. */
20280 dwarf2out_decl (tree decl
)
20282 dw_die_ref context_die
= comp_unit_die ();
20284 switch (TREE_CODE (decl
))
20289 case FUNCTION_DECL
:
20290 /* What we would really like to do here is to filter out all mere
20291 file-scope declarations of file-scope functions which are never
20292 referenced later within this translation unit (and keep all of ones
20293 that *are* referenced later on) but we aren't clairvoyant, so we have
20294 no idea which functions will be referenced in the future (i.e. later
20295 on within the current translation unit). So here we just ignore all
20296 file-scope function declarations which are not also definitions. If
20297 and when the debugger needs to know something about these functions,
20298 it will have to hunt around and find the DWARF information associated
20299 with the definition of the function.
20301 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20302 nodes represent definitions and which ones represent mere
20303 declarations. We have to check DECL_INITIAL instead. That's because
20304 the C front-end supports some weird semantics for "extern inline"
20305 function definitions. These can get inlined within the current
20306 translation unit (and thus, we need to generate Dwarf info for their
20307 abstract instances so that the Dwarf info for the concrete inlined
20308 instances can have something to refer to) but the compiler never
20309 generates any out-of-lines instances of such things (despite the fact
20310 that they *are* definitions).
20312 The important point is that the C front-end marks these "extern
20313 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20314 them anyway. Note that the C++ front-end also plays some similar games
20315 for inline function definitions appearing within include files which
20316 also contain `#pragma interface' pragmas.
20318 If we are called from dwarf2out_abstract_function output a DIE
20319 anyway. We can end up here this way with early inlining and LTO
20320 where the inlined function is output in a different LTRANS unit
20322 if (DECL_INITIAL (decl
) == NULL_TREE
20323 && ! DECL_ABSTRACT (decl
))
20326 /* If we're a nested function, initially use a parent of NULL; if we're
20327 a plain function, this will be fixed up in decls_for_scope. If
20328 we're a method, it will be ignored, since we already have a DIE. */
20329 if (decl_function_context (decl
)
20330 /* But if we're in terse mode, we don't care about scope. */
20331 && debug_info_level
> DINFO_LEVEL_TERSE
)
20332 context_die
= NULL
;
20336 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20337 declaration and if the declaration was never even referenced from
20338 within this entire compilation unit. We suppress these DIEs in
20339 order to save space in the .debug section (by eliminating entries
20340 which are probably useless). Note that we must not suppress
20341 block-local extern declarations (whether used or not) because that
20342 would screw-up the debugger's name lookup mechanism and cause it to
20343 miss things which really ought to be in scope at a given point. */
20344 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20347 /* For local statics lookup proper context die. */
20348 if (TREE_STATIC (decl
)
20349 && DECL_CONTEXT (decl
)
20350 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20351 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20353 /* If we are in terse mode, don't generate any DIEs to represent any
20354 variable declarations or definitions. */
20355 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20360 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20362 if (!is_fortran () && !is_ada ())
20364 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20365 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20368 case NAMESPACE_DECL
:
20369 case IMPORTED_DECL
:
20370 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20372 if (lookup_decl_die (decl
) != NULL
)
20377 /* Don't emit stubs for types unless they are needed by other DIEs. */
20378 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20381 /* Don't bother trying to generate any DIEs to represent any of the
20382 normal built-in types for the language we are compiling. */
20383 if (DECL_IS_BUILTIN (decl
))
20386 /* If we are in terse mode, don't generate any DIEs for types. */
20387 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20390 /* If we're a function-scope tag, initially use a parent of NULL;
20391 this will be fixed up in decls_for_scope. */
20392 if (decl_function_context (decl
))
20393 context_die
= NULL
;
20401 gen_decl_die (decl
, NULL
, context_die
);
20404 /* Write the debugging output for DECL. */
20407 dwarf2out_function_decl (tree decl
)
20409 dwarf2out_decl (decl
);
20410 call_arg_locations
= NULL
;
20411 call_arg_loc_last
= NULL
;
20412 call_site_count
= -1;
20413 tail_call_site_count
= -1;
20414 block_map
.release ();
20415 htab_empty (decl_loc_table
);
20416 htab_empty (cached_dw_loc_list_table
);
20419 /* Output a marker (i.e. a label) for the beginning of the generated code for
20420 a lexical block. */
20423 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20424 unsigned int blocknum
)
20426 switch_to_section (current_function_section ());
20427 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20430 /* Output a marker (i.e. a label) for the end of the generated code for a
20434 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20436 switch_to_section (current_function_section ());
20437 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20440 /* Returns nonzero if it is appropriate not to emit any debugging
20441 information for BLOCK, because it doesn't contain any instructions.
20443 Don't allow this for blocks with nested functions or local classes
20444 as we would end up with orphans, and in the presence of scheduling
20445 we may end up calling them anyway. */
20448 dwarf2out_ignore_block (const_tree block
)
20453 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20454 if (TREE_CODE (decl
) == FUNCTION_DECL
20455 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20457 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20459 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20460 if (TREE_CODE (decl
) == FUNCTION_DECL
20461 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20468 /* Hash table routines for file_hash. */
20471 file_table_eq (const void *p1_p
, const void *p2_p
)
20473 const struct dwarf_file_data
*const p1
=
20474 (const struct dwarf_file_data
*) p1_p
;
20475 const char *const p2
= (const char *) p2_p
;
20476 return filename_cmp (p1
->filename
, p2
) == 0;
20480 file_table_hash (const void *p_p
)
20482 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20483 return htab_hash_string (p
->filename
);
20486 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20487 dwarf2out.c) and return its "index". The index of each (known) filename is
20488 just a unique number which is associated with only that one filename. We
20489 need such numbers for the sake of generating labels (in the .debug_sfnames
20490 section) and references to those files numbers (in the .debug_srcinfo
20491 and.debug_macinfo sections). If the filename given as an argument is not
20492 found in our current list, add it to the list and assign it the next
20493 available unique index number. In order to speed up searches, we remember
20494 the index of the filename was looked up last. This handles the majority of
20497 static struct dwarf_file_data
*
20498 lookup_filename (const char *file_name
)
20501 struct dwarf_file_data
* created
;
20503 /* Check to see if the file name that was searched on the previous
20504 call matches this file name. If so, return the index. */
20505 if (file_table_last_lookup
20506 && (file_name
== file_table_last_lookup
->filename
20507 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20508 return file_table_last_lookup
;
20510 /* Didn't match the previous lookup, search the table. */
20511 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20512 htab_hash_string (file_name
), INSERT
);
20514 return (struct dwarf_file_data
*) *slot
;
20516 created
= ggc_alloc_dwarf_file_data ();
20517 created
->filename
= file_name
;
20518 created
->emitted_number
= 0;
20523 /* If the assembler will construct the file table, then translate the compiler
20524 internal file table number into the assembler file table number, and emit
20525 a .file directive if we haven't already emitted one yet. The file table
20526 numbers are different because we prune debug info for unused variables and
20527 types, which may include filenames. */
20530 maybe_emit_file (struct dwarf_file_data
* fd
)
20532 if (! fd
->emitted_number
)
20534 if (last_emitted_file
)
20535 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20537 fd
->emitted_number
= 1;
20538 last_emitted_file
= fd
;
20540 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20542 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20543 output_quoted_string (asm_out_file
,
20544 remap_debug_filename (fd
->filename
));
20545 fputc ('\n', asm_out_file
);
20549 return fd
->emitted_number
;
20552 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20553 That generation should happen after function debug info has been
20554 generated. The value of the attribute is the constant value of ARG. */
20557 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20559 die_arg_entry entry
;
20564 if (!tmpl_value_parm_die_table
)
20565 vec_alloc (tmpl_value_parm_die_table
, 32);
20569 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20572 /* Return TRUE if T is an instance of generic type, FALSE
20576 generic_type_p (tree t
)
20578 if (t
== NULL_TREE
|| !TYPE_P (t
))
20580 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20583 /* Schedule the generation of the generic parameter dies for the
20584 instance of generic type T. The proper generation itself is later
20585 done by gen_scheduled_generic_parms_dies. */
20588 schedule_generic_params_dies_gen (tree t
)
20590 if (!generic_type_p (t
))
20593 if (!generic_type_instances
)
20594 vec_alloc (generic_type_instances
, 256);
20596 vec_safe_push (generic_type_instances
, t
);
20599 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20600 by append_entry_to_tmpl_value_parm_die_table. This function must
20601 be called after function DIEs have been generated. */
20604 gen_remaining_tmpl_value_param_die_attribute (void)
20606 if (tmpl_value_parm_die_table
)
20611 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20612 tree_add_const_value_attribute (e
->die
, e
->arg
);
20616 /* Generate generic parameters DIEs for instances of generic types
20617 that have been previously scheduled by
20618 schedule_generic_params_dies_gen. This function must be called
20619 after all the types of the CU have been laid out. */
20622 gen_scheduled_generic_parms_dies (void)
20627 if (!generic_type_instances
)
20630 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20631 if (COMPLETE_TYPE_P (t
))
20632 gen_generic_params_dies (t
);
20636 /* Replace DW_AT_name for the decl with name. */
20639 dwarf2out_set_name (tree decl
, tree name
)
20645 die
= TYPE_SYMTAB_DIE (decl
);
20649 dname
= dwarf2_name (name
, 0);
20653 attr
= get_AT (die
, DW_AT_name
);
20656 struct indirect_string_node
*node
;
20658 node
= find_AT_string (dname
);
20659 /* replace the string. */
20660 attr
->dw_attr_val
.v
.val_str
= node
;
20664 add_name_attribute (die
, dname
);
20667 /* True if before or during processing of the first function being emitted. */
20668 static bool in_first_function_p
= true;
20669 /* True if loc_note during dwarf2out_var_location call might still be
20670 before first real instruction at address equal to .Ltext0. */
20671 static bool maybe_at_text_label_p
= true;
20672 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
20673 static unsigned int first_loclabel_num_not_at_text_label
;
20675 /* Called by the final INSN scan whenever we see a var location. We
20676 use it to drop labels in the right places, and throw the location in
20677 our lookup table. */
20680 dwarf2out_var_location (rtx loc_note
)
20682 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20683 struct var_loc_node
*newloc
;
20684 rtx next_real
, next_note
;
20685 static const char *last_label
;
20686 static const char *last_postcall_label
;
20687 static bool last_in_cold_section_p
;
20688 static rtx expected_next_loc_note
;
20692 if (!NOTE_P (loc_note
))
20694 if (CALL_P (loc_note
))
20697 if (SIBLING_CALL_P (loc_note
))
20698 tail_call_site_count
++;
20703 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20704 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20707 /* Optimize processing a large consecutive sequence of location
20708 notes so we don't spend too much time in next_real_insn. If the
20709 next insn is another location note, remember the next_real_insn
20710 calculation for next time. */
20711 next_real
= cached_next_real_insn
;
20714 if (expected_next_loc_note
!= loc_note
)
20715 next_real
= NULL_RTX
;
20718 next_note
= NEXT_INSN (loc_note
);
20720 || INSN_DELETED_P (next_note
)
20721 || ! NOTE_P (next_note
)
20722 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20723 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20724 next_note
= NULL_RTX
;
20727 next_real
= next_real_insn (loc_note
);
20731 expected_next_loc_note
= next_note
;
20732 cached_next_real_insn
= next_real
;
20735 cached_next_real_insn
= NULL_RTX
;
20737 /* If there are no instructions which would be affected by this note,
20738 don't do anything. */
20740 && next_real
== NULL_RTX
20741 && !NOTE_DURING_CALL_P (loc_note
))
20744 if (next_real
== NULL_RTX
)
20745 next_real
= get_last_insn ();
20747 /* If there were any real insns between note we processed last time
20748 and this note (or if it is the first note), clear
20749 last_{,postcall_}label so that they are not reused this time. */
20750 if (last_var_location_insn
== NULL_RTX
20751 || last_var_location_insn
!= next_real
20752 || last_in_cold_section_p
!= in_cold_section_p
)
20755 last_postcall_label
= NULL
;
20760 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20761 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20762 NOTE_DURING_CALL_P (loc_note
)
20763 ? last_postcall_label
: last_label
);
20764 if (newloc
== NULL
)
20773 /* If there were no real insns between note we processed last time
20774 and this note, use the label we emitted last time. Otherwise
20775 create a new label and emit it. */
20776 if (last_label
== NULL
)
20778 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20779 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20781 last_label
= ggc_strdup (loclabel
);
20782 /* See if loclabel might be equal to .Ltext0. If yes,
20783 bump first_loclabel_num_not_at_text_label. */
20784 if (!have_multiple_function_sections
20785 && in_first_function_p
20786 && maybe_at_text_label_p
)
20788 static rtx last_start
;
20790 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
20791 if (insn
== last_start
)
20793 else if (!NONDEBUG_INSN_P (insn
))
20797 rtx body
= PATTERN (insn
);
20798 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
20800 /* Inline asm could occupy zero bytes. */
20801 else if (GET_CODE (body
) == ASM_INPUT
20802 || asm_noperands (body
) >= 0)
20804 #ifdef HAVE_attr_length
20805 else if (get_attr_min_length (insn
) == 0)
20810 /* Assume insn has non-zero length. */
20811 maybe_at_text_label_p
= false;
20815 if (maybe_at_text_label_p
)
20817 last_start
= loc_note
;
20818 first_loclabel_num_not_at_text_label
= loclabel_num
;
20825 struct call_arg_loc_node
*ca_loc
20826 = ggc_alloc_cleared_call_arg_loc_node ();
20827 rtx prev
= prev_real_insn (loc_note
), x
;
20828 ca_loc
->call_arg_loc_note
= loc_note
;
20829 ca_loc
->next
= NULL
;
20830 ca_loc
->label
= last_label
;
20833 || (NONJUMP_INSN_P (prev
)
20834 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20835 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20836 if (!CALL_P (prev
))
20837 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20838 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20839 x
= get_call_rtx_from (PATTERN (prev
));
20842 x
= XEXP (XEXP (x
, 0), 0);
20843 if (GET_CODE (x
) == SYMBOL_REF
20844 && SYMBOL_REF_DECL (x
)
20845 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20846 ca_loc
->symbol_ref
= x
;
20848 ca_loc
->block
= insn_scope (prev
);
20849 if (call_arg_locations
)
20850 call_arg_loc_last
->next
= ca_loc
;
20852 call_arg_locations
= ca_loc
;
20853 call_arg_loc_last
= ca_loc
;
20855 else if (!NOTE_DURING_CALL_P (loc_note
))
20856 newloc
->label
= last_label
;
20859 if (!last_postcall_label
)
20861 sprintf (loclabel
, "%s-1", last_label
);
20862 last_postcall_label
= ggc_strdup (loclabel
);
20864 newloc
->label
= last_postcall_label
;
20867 last_var_location_insn
= next_real
;
20868 last_in_cold_section_p
= in_cold_section_p
;
20871 /* Note in one location list that text section has changed. */
20874 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20876 var_loc_list
*list
= (var_loc_list
*) *slot
;
20878 list
->last_before_switch
20879 = list
->last
->next
? list
->last
->next
: list
->last
;
20883 /* Note in all location lists that text section has changed. */
20886 var_location_switch_text_section (void)
20888 if (decl_loc_table
== NULL
)
20891 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20894 /* Create a new line number table. */
20896 static dw_line_info_table
*
20897 new_line_info_table (void)
20899 dw_line_info_table
*table
;
20901 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
20902 table
->file_num
= 1;
20903 table
->line_num
= 1;
20904 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
20909 /* Lookup the "current" table into which we emit line info, so
20910 that we don't have to do it for every source line. */
20913 set_cur_line_info_table (section
*sec
)
20915 dw_line_info_table
*table
;
20917 if (sec
== text_section
)
20918 table
= text_section_line_info
;
20919 else if (sec
== cold_text_section
)
20921 table
= cold_text_section_line_info
;
20924 cold_text_section_line_info
= table
= new_line_info_table ();
20925 table
->end_label
= cold_end_label
;
20930 const char *end_label
;
20932 if (flag_reorder_blocks_and_partition
)
20934 if (in_cold_section_p
)
20935 end_label
= crtl
->subsections
.cold_section_end_label
;
20937 end_label
= crtl
->subsections
.hot_section_end_label
;
20941 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20942 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
20943 current_function_funcdef_no
);
20944 end_label
= ggc_strdup (label
);
20947 table
= new_line_info_table ();
20948 table
->end_label
= end_label
;
20950 vec_safe_push (separate_line_info
, table
);
20953 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20954 table
->is_stmt
= (cur_line_info_table
20955 ? cur_line_info_table
->is_stmt
20956 : DWARF_LINE_DEFAULT_IS_STMT_START
);
20957 cur_line_info_table
= table
;
20961 /* We need to reset the locations at the beginning of each
20962 function. We can't do this in the end_function hook, because the
20963 declarations that use the locations won't have been output when
20964 that hook is called. Also compute have_multiple_function_sections here. */
20967 dwarf2out_begin_function (tree fun
)
20969 section
*sec
= function_section (fun
);
20971 if (sec
!= text_section
)
20972 have_multiple_function_sections
= true;
20974 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
20976 gcc_assert (current_function_decl
== fun
);
20977 cold_text_section
= unlikely_text_section ();
20978 switch_to_section (cold_text_section
);
20979 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
20980 switch_to_section (sec
);
20983 dwarf2out_note_section_used ();
20984 call_site_count
= 0;
20985 tail_call_site_count
= 0;
20987 set_cur_line_info_table (sec
);
20990 /* Helper function of dwarf2out_end_function, called only after emitting
20991 the very first function into assembly. Check if some .debug_loc range
20992 might end with a .LVL* label that could be equal to .Ltext0.
20993 In that case we must force using absolute addresses in .debug_loc ranges,
20994 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
20995 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
20997 Set have_multiple_function_sections to true in that case and
20998 terminate htab traversal. */
21001 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21003 var_loc_list
*entry
;
21004 struct var_loc_node
*node
;
21006 entry
= (var_loc_list
*) *slot
;
21007 node
= entry
->first
;
21008 if (node
&& node
->next
&& node
->next
->label
)
21011 const char *label
= node
->next
->label
;
21012 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21014 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21016 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21017 if (strcmp (label
, loclabel
) == 0)
21019 have_multiple_function_sections
= true;
21027 /* Hook called after emitting a function into assembly.
21028 This does something only for the very first function emitted. */
21031 dwarf2out_end_function (unsigned int)
21033 if (in_first_function_p
21034 && !have_multiple_function_sections
21035 && first_loclabel_num_not_at_text_label
21037 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21039 in_first_function_p
= false;
21040 maybe_at_text_label_p
= false;
21043 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21046 push_dw_line_info_entry (dw_line_info_table
*table
,
21047 enum dw_line_info_opcode opcode
, unsigned int val
)
21049 dw_line_info_entry e
;
21052 vec_safe_push (table
->entries
, e
);
21055 /* Output a label to mark the beginning of a source code line entry
21056 and record information relating to this source line, in
21057 'line_info_table' for later output of the .debug_line section. */
21058 /* ??? The discriminator parameter ought to be unsigned. */
21061 dwarf2out_source_line (unsigned int line
, const char *filename
,
21062 int discriminator
, bool is_stmt
)
21064 unsigned int file_num
;
21065 dw_line_info_table
*table
;
21067 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
21070 /* The discriminator column was added in dwarf4. Simplify the below
21071 by simply removing it if we're not supposed to output it. */
21072 if (dwarf_version
< 4 && dwarf_strict
)
21075 table
= cur_line_info_table
;
21076 file_num
= maybe_emit_file (lookup_filename (filename
));
21078 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21079 the debugger has used the second (possibly duplicate) line number
21080 at the beginning of the function to mark the end of the prologue.
21081 We could eliminate any other duplicates within the function. For
21082 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21083 that second line number entry. */
21084 /* Recall that this end-of-prologue indication is *not* the same thing
21085 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21086 to which the hook corresponds, follows the last insn that was
21087 emitted by gen_prologue. What we need is to precede the first insn
21088 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21089 insn that corresponds to something the user wrote. These may be
21090 very different locations once scheduling is enabled. */
21092 if (0 && file_num
== table
->file_num
21093 && line
== table
->line_num
21094 && discriminator
== table
->discrim_num
21095 && is_stmt
== table
->is_stmt
)
21098 switch_to_section (current_function_section ());
21100 /* If requested, emit something human-readable. */
21101 if (flag_debug_asm
)
21102 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21104 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21106 /* Emit the .loc directive understood by GNU as. */
21107 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21108 file_num, line, is_stmt, discriminator */
21109 fputs ("\t.loc ", asm_out_file
);
21110 fprint_ul (asm_out_file
, file_num
);
21111 putc (' ', asm_out_file
);
21112 fprint_ul (asm_out_file
, line
);
21113 putc (' ', asm_out_file
);
21114 putc ('0', asm_out_file
);
21116 if (is_stmt
!= table
->is_stmt
)
21118 fputs (" is_stmt ", asm_out_file
);
21119 putc (is_stmt
? '1' : '0', asm_out_file
);
21121 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21123 gcc_assert (discriminator
> 0);
21124 fputs (" discriminator ", asm_out_file
);
21125 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21127 putc ('\n', asm_out_file
);
21131 unsigned int label_num
= ++line_info_label_num
;
21133 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21135 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21136 if (file_num
!= table
->file_num
)
21137 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21138 if (discriminator
!= table
->discrim_num
)
21139 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21140 if (is_stmt
!= table
->is_stmt
)
21141 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21142 push_dw_line_info_entry (table
, LI_set_line
, line
);
21145 table
->file_num
= file_num
;
21146 table
->line_num
= line
;
21147 table
->discrim_num
= discriminator
;
21148 table
->is_stmt
= is_stmt
;
21149 table
->in_use
= true;
21152 /* Record the beginning of a new source file. */
21155 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21157 if (flag_eliminate_dwarf2_dups
)
21159 /* Record the beginning of the file for break_out_includes. */
21160 dw_die_ref bincl_die
;
21162 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21163 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21166 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21169 e
.code
= DW_MACINFO_start_file
;
21171 e
.info
= ggc_strdup (filename
);
21172 vec_safe_push (macinfo_table
, e
);
21176 /* Record the end of a source file. */
21179 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21181 if (flag_eliminate_dwarf2_dups
)
21182 /* Record the end of the file for break_out_includes. */
21183 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21185 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21188 e
.code
= DW_MACINFO_end_file
;
21191 vec_safe_push (macinfo_table
, e
);
21195 /* Called from debug_define 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_define (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_define
;
21217 e
.info
= ggc_strdup (buffer
);
21218 vec_safe_push (macinfo_table
, e
);
21222 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21223 the tail part of the directive line, i.e. the part which is past the
21224 initial whitespace, #, whitespace, directive-name, whitespace part. */
21227 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21228 const char *buffer ATTRIBUTE_UNUSED
)
21230 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21233 /* Insert a dummy first entry to be able to optimize the whole
21234 predefined macro block using DW_MACRO_GNU_transparent_include. */
21235 if (macinfo_table
->is_empty () && lineno
<= 1)
21240 vec_safe_push (macinfo_table
, e
);
21242 e
.code
= DW_MACINFO_undef
;
21244 e
.info
= ggc_strdup (buffer
);
21245 vec_safe_push (macinfo_table
, e
);
21249 /* Routines to manipulate hash table of CUs. */
21252 htab_macinfo_hash (const void *of
)
21254 const macinfo_entry
*const entry
=
21255 (const macinfo_entry
*) of
;
21257 return htab_hash_string (entry
->info
);
21261 htab_macinfo_eq (const void *of1
, const void *of2
)
21263 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
21264 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
21266 return !strcmp (entry1
->info
, entry2
->info
);
21269 /* Output a single .debug_macinfo entry. */
21272 output_macinfo_op (macinfo_entry
*ref
)
21276 struct indirect_string_node
*node
;
21277 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21278 struct dwarf_file_data
*fd
;
21282 case DW_MACINFO_start_file
:
21283 fd
= lookup_filename (ref
->info
);
21284 file_num
= maybe_emit_file (fd
);
21285 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21286 dw2_asm_output_data_uleb128 (ref
->lineno
,
21287 "Included from line number %lu",
21288 (unsigned long) ref
->lineno
);
21289 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21291 case DW_MACINFO_end_file
:
21292 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21294 case DW_MACINFO_define
:
21295 case DW_MACINFO_undef
:
21296 len
= strlen (ref
->info
) + 1;
21298 && len
> DWARF_OFFSET_SIZE
21299 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21300 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21302 ref
->code
= ref
->code
== DW_MACINFO_define
21303 ? DW_MACRO_GNU_define_indirect
21304 : DW_MACRO_GNU_undef_indirect
;
21305 output_macinfo_op (ref
);
21308 dw2_asm_output_data (1, ref
->code
,
21309 ref
->code
== DW_MACINFO_define
21310 ? "Define macro" : "Undefine macro");
21311 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21312 (unsigned long) ref
->lineno
);
21313 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21315 case DW_MACRO_GNU_define_indirect
:
21316 case DW_MACRO_GNU_undef_indirect
:
21317 node
= find_AT_string (ref
->info
);
21319 && ((node
->form
== DW_FORM_strp
)
21320 || (node
->form
== DW_FORM_GNU_str_index
)));
21321 dw2_asm_output_data (1, ref
->code
,
21322 ref
->code
== DW_MACRO_GNU_define_indirect
21323 ? "Define macro indirect"
21324 : "Undefine macro indirect");
21325 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21326 (unsigned long) ref
->lineno
);
21327 if (node
->form
== DW_FORM_strp
)
21328 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21329 debug_str_section
, "The macro: \"%s\"",
21332 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21335 case DW_MACRO_GNU_transparent_include
:
21336 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21337 ASM_GENERATE_INTERNAL_LABEL (label
,
21338 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21339 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21342 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21343 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21348 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21349 other compilation unit .debug_macinfo sections. IDX is the first
21350 index of a define/undef, return the number of ops that should be
21351 emitted in a comdat .debug_macinfo section and emit
21352 a DW_MACRO_GNU_transparent_include entry referencing it.
21353 If the define/undef entry should be emitted normally, return 0. */
21356 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21357 htab_t
*macinfo_htab
)
21359 macinfo_entry
*first
, *second
, *cur
, *inc
;
21360 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21361 unsigned char checksum
[16];
21362 struct md5_ctx ctx
;
21363 char *grp_name
, *tail
;
21365 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21368 first
= &(*macinfo_table
)[idx
];
21369 second
= &(*macinfo_table
)[idx
+ 1];
21371 /* Optimize only if there are at least two consecutive define/undef ops,
21372 and either all of them are before first DW_MACINFO_start_file
21373 with lineno {0,1} (i.e. predefined macro block), or all of them are
21374 in some included header file. */
21375 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21377 if (vec_safe_is_empty (files
))
21379 if (first
->lineno
> 1 || second
->lineno
> 1)
21382 else if (first
->lineno
== 0)
21385 /* Find the last define/undef entry that can be grouped together
21386 with first and at the same time compute md5 checksum of their
21387 codes, linenumbers and strings. */
21388 md5_init_ctx (&ctx
);
21389 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21390 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21392 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21396 unsigned char code
= cur
->code
;
21397 md5_process_bytes (&code
, 1, &ctx
);
21398 checksum_uleb128 (cur
->lineno
, &ctx
);
21399 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21401 md5_finish_ctx (&ctx
, checksum
);
21404 /* From the containing include filename (if any) pick up just
21405 usable characters from its basename. */
21406 if (vec_safe_is_empty (files
))
21409 base
= lbasename (files
->last ().info
);
21410 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21411 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21412 encoded_filename_len
++;
21413 /* Count . at the end. */
21414 if (encoded_filename_len
)
21415 encoded_filename_len
++;
21417 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21418 linebuf_len
= strlen (linebuf
);
21420 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21421 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21423 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21424 tail
= grp_name
+ 4;
21425 if (encoded_filename_len
)
21427 for (i
= 0; base
[i
]; i
++)
21428 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21432 memcpy (tail
, linebuf
, linebuf_len
);
21433 tail
+= linebuf_len
;
21435 for (i
= 0; i
< 16; i
++)
21436 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21438 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21439 in the empty vector entry before the first define/undef. */
21440 inc
= &(*macinfo_table
)[idx
- 1];
21441 inc
->code
= DW_MACRO_GNU_transparent_include
;
21443 inc
->info
= ggc_strdup (grp_name
);
21444 if (*macinfo_htab
== NULL
)
21445 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
21446 /* Avoid emitting duplicates. */
21447 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
21452 /* If such an entry has been used before, just emit
21453 a DW_MACRO_GNU_transparent_include op. */
21454 inc
= (macinfo_entry
*) *slot
;
21455 output_macinfo_op (inc
);
21456 /* And clear all macinfo_entry in the range to avoid emitting them
21457 in the second pass. */
21458 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21467 inc
->lineno
= htab_elements (*macinfo_htab
);
21468 output_macinfo_op (inc
);
21473 /* Save any strings needed by the macinfo table in the debug str
21474 table. All strings must be collected into the table by the time
21475 index_string is called. */
21478 save_macinfo_strings (void)
21482 macinfo_entry
*ref
;
21484 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21488 /* Match the logic in output_macinfo_op to decide on
21489 indirect strings. */
21490 case DW_MACINFO_define
:
21491 case DW_MACINFO_undef
:
21492 len
= strlen (ref
->info
) + 1;
21494 && len
> DWARF_OFFSET_SIZE
21495 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21496 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21497 set_indirect_string (find_AT_string (ref
->info
));
21499 case DW_MACRO_GNU_define_indirect
:
21500 case DW_MACRO_GNU_undef_indirect
:
21501 set_indirect_string (find_AT_string (ref
->info
));
21509 /* Output macinfo section(s). */
21512 output_macinfo (void)
21515 unsigned long length
= vec_safe_length (macinfo_table
);
21516 macinfo_entry
*ref
;
21517 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21518 htab_t macinfo_htab
= NULL
;
21523 /* output_macinfo* uses these interchangeably. */
21524 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21525 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21526 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21527 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21529 /* For .debug_macro emit the section header. */
21532 dw2_asm_output_data (2, 4, "DWARF macro version number");
21533 if (DWARF_OFFSET_SIZE
== 8)
21534 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21536 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21537 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21538 (!dwarf_split_debug_info
? debug_line_section_label
21539 : debug_skeleton_line_section_label
),
21540 debug_line_section
, NULL
);
21543 /* In the first loop, it emits the primary .debug_macinfo section
21544 and after each emitted op the macinfo_entry is cleared.
21545 If a longer range of define/undef ops can be optimized using
21546 DW_MACRO_GNU_transparent_include, the
21547 DW_MACRO_GNU_transparent_include op is emitted and kept in
21548 the vector before the first define/undef in the range and the
21549 whole range of define/undef ops is not emitted and kept. */
21550 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21554 case DW_MACINFO_start_file
:
21555 vec_safe_push (files
, *ref
);
21557 case DW_MACINFO_end_file
:
21558 if (!vec_safe_is_empty (files
))
21561 case DW_MACINFO_define
:
21562 case DW_MACINFO_undef
:
21564 && HAVE_COMDAT_GROUP
21565 && vec_safe_length (files
) != 1
21568 && (*macinfo_table
)[i
- 1].code
== 0)
21570 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21579 /* A dummy entry may be inserted at the beginning to be able
21580 to optimize the whole block of predefined macros. */
21586 output_macinfo_op (ref
);
21591 if (macinfo_htab
== NULL
)
21594 htab_delete (macinfo_htab
);
21596 /* If any DW_MACRO_GNU_transparent_include were used, on those
21597 DW_MACRO_GNU_transparent_include entries terminate the
21598 current chain and switch to a new comdat .debug_macinfo
21599 section and emit the define/undef entries within it. */
21600 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21605 case DW_MACRO_GNU_transparent_include
:
21607 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21608 tree comdat_key
= get_identifier (ref
->info
);
21609 /* Terminate the previous .debug_macinfo section. */
21610 dw2_asm_output_data (1, 0, "End compilation unit");
21611 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21613 | SECTION_LINKONCE
,
21615 ASM_GENERATE_INTERNAL_LABEL (label
,
21616 DEBUG_MACRO_SECTION_LABEL
,
21618 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21621 dw2_asm_output_data (2, 4, "DWARF macro version number");
21622 if (DWARF_OFFSET_SIZE
== 8)
21623 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21625 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21628 case DW_MACINFO_define
:
21629 case DW_MACINFO_undef
:
21630 output_macinfo_op (ref
);
21635 gcc_unreachable ();
21639 /* Set up for Dwarf output at the start of compilation. */
21642 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21644 /* Allocate the file_table. */
21645 file_table
= htab_create_ggc (50, file_table_hash
,
21646 file_table_eq
, NULL
);
21648 /* Allocate the decl_die_table. */
21649 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21650 decl_die_table_eq
, NULL
);
21652 /* Allocate the decl_loc_table. */
21653 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21654 decl_loc_table_eq
, NULL
);
21656 /* Allocate the cached_dw_loc_list_table. */
21657 cached_dw_loc_list_table
21658 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21659 cached_dw_loc_list_table_eq
, NULL
);
21661 /* Allocate the initial hunk of the decl_scope_table. */
21662 vec_alloc (decl_scope_table
, 256);
21664 /* Allocate the initial hunk of the abbrev_die_table. */
21665 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21666 (ABBREV_DIE_TABLE_INCREMENT
);
21667 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21668 /* Zero-th entry is allocated, but unused. */
21669 abbrev_die_table_in_use
= 1;
21671 /* Allocate the pubtypes and pubnames vectors. */
21672 vec_alloc (pubname_table
, 32);
21673 vec_alloc (pubtype_table
, 32);
21675 vec_alloc (incomplete_types
, 64);
21677 vec_alloc (used_rtx_array
, 32);
21679 if (!dwarf_split_debug_info
)
21681 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21682 SECTION_DEBUG
, NULL
);
21683 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21684 SECTION_DEBUG
, NULL
);
21685 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21686 SECTION_DEBUG
, NULL
);
21690 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
21691 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21692 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
21693 SECTION_DEBUG
| SECTION_EXCLUDE
,
21695 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
21696 SECTION_DEBUG
, NULL
);
21697 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
21698 SECTION_DEBUG
, NULL
);
21699 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21700 SECTION_DEBUG
, NULL
);
21701 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
21702 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
21704 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
21705 the main .o, but the skeleton_line goes into the split off dwo. */
21706 debug_skeleton_line_section
21707 = get_section (DEBUG_DWO_LINE_SECTION
,
21708 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21709 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
21710 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
21711 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
21712 SECTION_DEBUG
| SECTION_EXCLUDE
,
21714 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
21715 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
21716 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
21717 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21719 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21720 SECTION_DEBUG
, NULL
);
21721 debug_macinfo_section
= get_section (dwarf_strict
21722 ? DEBUG_MACINFO_SECTION
21723 : DEBUG_MACRO_SECTION
,
21724 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
21725 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21726 SECTION_DEBUG
, NULL
);
21727 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21728 SECTION_DEBUG
, NULL
);
21729 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21730 SECTION_DEBUG
, NULL
);
21731 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21732 DEBUG_STR_SECTION_FLAGS
, NULL
);
21733 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21734 SECTION_DEBUG
, NULL
);
21735 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21736 SECTION_DEBUG
, NULL
);
21738 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21739 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21740 DEBUG_ABBREV_SECTION_LABEL
, 0);
21741 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21742 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21743 COLD_TEXT_SECTION_LABEL
, 0);
21744 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21746 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21747 DEBUG_INFO_SECTION_LABEL
, 0);
21748 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21749 DEBUG_LINE_SECTION_LABEL
, 0);
21750 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21751 DEBUG_RANGES_SECTION_LABEL
, 0);
21752 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
21753 DEBUG_ADDR_SECTION_LABEL
, 0);
21754 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21756 ? DEBUG_MACINFO_SECTION_LABEL
21757 : DEBUG_MACRO_SECTION_LABEL
, 0);
21758 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
21760 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21761 vec_alloc (macinfo_table
, 64);
21763 switch_to_section (text_section
);
21764 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21766 /* Make sure the line number table for .text always exists. */
21767 text_section_line_info
= new_line_info_table ();
21768 text_section_line_info
->end_label
= text_end_label
;
21771 /* Called before compile () starts outputtting functions, variables
21772 and toplevel asms into assembly. */
21775 dwarf2out_assembly_start (void)
21777 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21778 && dwarf2out_do_cfi_asm ()
21779 && (!(flag_unwind_tables
|| flag_exceptions
)
21780 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
21781 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21784 /* A helper function for dwarf2out_finish called through
21785 htab_traverse. Assign a string its index. All strings must be
21786 collected into the table by the time index_string is called,
21787 because the indexing code relies on htab_traverse to traverse nodes
21788 in the same order for each run. */
21791 index_string (void **h
, void *v
)
21793 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21794 unsigned int *index
= (unsigned int *) v
;
21796 find_string_form (node
);
21797 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21799 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
21800 node
->index
= *index
;
21806 /* A helper function for output_indirect_strings called through
21807 htab_traverse. Output the offset to a string and update the
21811 output_index_string_offset (void **h
, void *v
)
21813 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21814 unsigned int *offset
= (unsigned int *) v
;
21816 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21818 /* Assert that this node has been assigned an index. */
21819 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
21820 && node
->index
!= NOT_INDEXED
);
21821 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
21822 "indexed string 0x%x: %s", node
->index
, node
->str
);
21823 *offset
+= strlen (node
->str
) + 1;
21828 /* A helper function for dwarf2out_finish called through
21829 htab_traverse. Output the indexed string. */
21832 output_index_string (void **h
, void *v
)
21834 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21835 unsigned int *cur_idx
= (unsigned int *) v
;
21837 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21839 /* Assert that the strings are output in the same order as their
21840 indexes were assigned. */
21841 gcc_assert (*cur_idx
== node
->index
);
21842 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21843 assemble_string (node
->str
, strlen (node
->str
) + 1);
21849 /* A helper function for dwarf2out_finish called through
21850 htab_traverse. Emit one queued .debug_str string. */
21853 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
21855 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21857 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
21859 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21860 assemble_string (node
->str
, strlen (node
->str
) + 1);
21866 /* Output the indexed string table. */
21869 output_indirect_strings (void)
21871 if (!dwarf_split_debug_info
)
21873 switch_to_section (debug_str_section
);
21874 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
21878 unsigned int offset
= 0;
21879 unsigned int cur_idx
= 0;
21881 switch_to_section (debug_str_offsets_section
);
21882 htab_traverse_noresize (debug_str_hash
,
21883 output_index_string_offset
,
21885 switch_to_section (debug_str_section
);
21886 htab_traverse_noresize (debug_str_hash
,
21887 output_index_string
,
21892 /* Callback for htab_traverse to assign an index to an entry in the
21893 table, and to write that entry to the .debug_addr section. */
21896 output_addr_table_entry (void **slot
, void *data
)
21898 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
21899 unsigned int *cur_index
= (unsigned int *)data
;
21901 if (entry
->refcount
== 0)
21903 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
21904 || entry
->index
== NOT_INDEXED
);
21908 gcc_assert (entry
->index
== *cur_index
);
21911 switch (entry
->kind
)
21914 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
21915 "0x%x", entry
->index
);
21917 case ate_kind_rtx_dtprel
:
21918 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
21919 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
21922 fputc ('\n', asm_out_file
);
21924 case ate_kind_label
:
21925 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
21926 "0x%x", entry
->index
);
21929 gcc_unreachable ();
21934 /* Produce the .debug_addr section. */
21937 output_addr_table (void)
21939 unsigned int index
= 0;
21940 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
21943 switch_to_section (debug_addr_section
);
21944 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
21947 #if ENABLE_ASSERT_CHECKING
21948 /* Verify that all marks are clear. */
21951 verify_marks_clear (dw_die_ref die
)
21955 gcc_assert (! die
->die_mark
);
21956 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
21958 #endif /* ENABLE_ASSERT_CHECKING */
21960 /* Clear the marks for a die and its children.
21961 Be cool if the mark isn't set. */
21964 prune_unmark_dies (dw_die_ref die
)
21970 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
21973 /* Given DIE that we're marking as used, find any other dies
21974 it references as attributes and mark them as used. */
21977 prune_unused_types_walk_attribs (dw_die_ref die
)
21982 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
21984 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
21986 /* A reference to another DIE.
21987 Make sure that it will get emitted.
21988 If it was broken out into a comdat group, don't follow it. */
21989 if (! AT_ref (a
)->comdat_type_p
21990 || a
->dw_attr
== DW_AT_specification
)
21991 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
21993 /* Set the string's refcount to 0 so that prune_unused_types_mark
21994 accounts properly for it. */
21995 if (AT_class (a
) == dw_val_class_str
)
21996 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22000 /* Mark the generic parameters and arguments children DIEs of DIE. */
22003 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22007 if (die
== NULL
|| die
->die_child
== NULL
)
22009 c
= die
->die_child
;
22012 switch (c
->die_tag
)
22014 case DW_TAG_template_type_param
:
22015 case DW_TAG_template_value_param
:
22016 case DW_TAG_GNU_template_template_param
:
22017 case DW_TAG_GNU_template_parameter_pack
:
22018 prune_unused_types_mark (c
, 1);
22024 } while (c
&& c
!= die
->die_child
);
22027 /* Mark DIE as being used. If DOKIDS is true, then walk down
22028 to DIE's children. */
22031 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22035 if (die
->die_mark
== 0)
22037 /* We haven't done this node yet. Mark it as used. */
22039 /* If this is the DIE of a generic type instantiation,
22040 mark the children DIEs that describe its generic parms and
22042 prune_unused_types_mark_generic_parms_dies (die
);
22044 /* We also have to mark its parents as used.
22045 (But we don't want to mark our parent's kids due to this,
22046 unless it is a class.) */
22047 if (die
->die_parent
)
22048 prune_unused_types_mark (die
->die_parent
,
22049 class_scope_p (die
->die_parent
));
22051 /* Mark any referenced nodes. */
22052 prune_unused_types_walk_attribs (die
);
22054 /* If this node is a specification,
22055 also mark the definition, if it exists. */
22056 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22057 prune_unused_types_mark (die
->die_definition
, 1);
22060 if (dokids
&& die
->die_mark
!= 2)
22062 /* We need to walk the children, but haven't done so yet.
22063 Remember that we've walked the kids. */
22066 /* If this is an array type, we need to make sure our
22067 kids get marked, even if they're types. If we're
22068 breaking out types into comdat sections, do this
22069 for all type definitions. */
22070 if (die
->die_tag
== DW_TAG_array_type
22071 || (use_debug_types
22072 && is_type_die (die
) && ! is_declaration_die (die
)))
22073 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22075 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22079 /* For local classes, look if any static member functions were emitted
22080 and if so, mark them. */
22083 prune_unused_types_walk_local_classes (dw_die_ref die
)
22087 if (die
->die_mark
== 2)
22090 switch (die
->die_tag
)
22092 case DW_TAG_structure_type
:
22093 case DW_TAG_union_type
:
22094 case DW_TAG_class_type
:
22097 case DW_TAG_subprogram
:
22098 if (!get_AT_flag (die
, DW_AT_declaration
)
22099 || die
->die_definition
!= NULL
)
22100 prune_unused_types_mark (die
, 1);
22107 /* Mark children. */
22108 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22111 /* Walk the tree DIE and mark types that we actually use. */
22114 prune_unused_types_walk (dw_die_ref die
)
22118 /* Don't do anything if this node is already marked and
22119 children have been marked as well. */
22120 if (die
->die_mark
== 2)
22123 switch (die
->die_tag
)
22125 case DW_TAG_structure_type
:
22126 case DW_TAG_union_type
:
22127 case DW_TAG_class_type
:
22128 if (die
->die_perennial_p
)
22131 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22132 if (c
->die_tag
== DW_TAG_subprogram
)
22135 /* Finding used static member functions inside of classes
22136 is needed just for local classes, because for other classes
22137 static member function DIEs with DW_AT_specification
22138 are emitted outside of the DW_TAG_*_type. If we ever change
22139 it, we'd need to call this even for non-local classes. */
22141 prune_unused_types_walk_local_classes (die
);
22143 /* It's a type node --- don't mark it. */
22146 case DW_TAG_const_type
:
22147 case DW_TAG_packed_type
:
22148 case DW_TAG_pointer_type
:
22149 case DW_TAG_reference_type
:
22150 case DW_TAG_rvalue_reference_type
:
22151 case DW_TAG_volatile_type
:
22152 case DW_TAG_typedef
:
22153 case DW_TAG_array_type
:
22154 case DW_TAG_interface_type
:
22155 case DW_TAG_friend
:
22156 case DW_TAG_variant_part
:
22157 case DW_TAG_enumeration_type
:
22158 case DW_TAG_subroutine_type
:
22159 case DW_TAG_string_type
:
22160 case DW_TAG_set_type
:
22161 case DW_TAG_subrange_type
:
22162 case DW_TAG_ptr_to_member_type
:
22163 case DW_TAG_file_type
:
22164 if (die
->die_perennial_p
)
22167 /* It's a type node --- don't mark it. */
22171 /* Mark everything else. */
22175 if (die
->die_mark
== 0)
22179 /* Now, mark any dies referenced from here. */
22180 prune_unused_types_walk_attribs (die
);
22185 /* Mark children. */
22186 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22189 /* Increment the string counts on strings referred to from DIE's
22193 prune_unused_types_update_strings (dw_die_ref die
)
22198 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22199 if (AT_class (a
) == dw_val_class_str
)
22201 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22203 /* Avoid unnecessarily putting strings that are used less than
22204 twice in the hash table. */
22206 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22209 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22210 htab_hash_string (s
->str
),
22212 gcc_assert (*slot
== NULL
);
22218 /* Remove from the tree DIE any dies that aren't marked. */
22221 prune_unused_types_prune (dw_die_ref die
)
22225 gcc_assert (die
->die_mark
);
22226 prune_unused_types_update_strings (die
);
22228 if (! die
->die_child
)
22231 c
= die
->die_child
;
22233 dw_die_ref prev
= c
;
22234 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22235 if (c
== die
->die_child
)
22237 /* No marked children between 'prev' and the end of the list. */
22239 /* No marked children at all. */
22240 die
->die_child
= NULL
;
22243 prev
->die_sib
= c
->die_sib
;
22244 die
->die_child
= prev
;
22249 if (c
!= prev
->die_sib
)
22251 prune_unused_types_prune (c
);
22252 } while (c
!= die
->die_child
);
22255 /* Remove dies representing declarations that we never use. */
22258 prune_unused_types (void)
22261 limbo_die_node
*node
;
22262 comdat_type_node
*ctnode
;
22264 dw_die_ref base_type
;
22266 #if ENABLE_ASSERT_CHECKING
22267 /* All the marks should already be clear. */
22268 verify_marks_clear (comp_unit_die ());
22269 for (node
= limbo_die_list
; node
; node
= node
->next
)
22270 verify_marks_clear (node
->die
);
22271 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22272 verify_marks_clear (ctnode
->root_die
);
22273 #endif /* ENABLE_ASSERT_CHECKING */
22275 /* Mark types that are used in global variables. */
22276 premark_types_used_by_global_vars ();
22278 /* Set the mark on nodes that are actually used. */
22279 prune_unused_types_walk (comp_unit_die ());
22280 for (node
= limbo_die_list
; node
; node
= node
->next
)
22281 prune_unused_types_walk (node
->die
);
22282 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22284 prune_unused_types_walk (ctnode
->root_die
);
22285 prune_unused_types_mark (ctnode
->type_die
, 1);
22288 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22289 are unusual in that they are pubnames that are the children of pubtypes.
22290 They should only be marked via their parent DW_TAG_enumeration_type die,
22291 not as roots in themselves. */
22292 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22293 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22294 prune_unused_types_mark (pub
->die
, 1);
22295 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22296 prune_unused_types_mark (base_type
, 1);
22298 if (debug_str_hash
)
22299 htab_empty (debug_str_hash
);
22300 prune_unused_types_prune (comp_unit_die ());
22301 for (node
= limbo_die_list
; node
; node
= node
->next
)
22302 prune_unused_types_prune (node
->die
);
22303 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22304 prune_unused_types_prune (ctnode
->root_die
);
22306 /* Leave the marks clear. */
22307 prune_unmark_dies (comp_unit_die ());
22308 for (node
= limbo_die_list
; node
; node
= node
->next
)
22309 prune_unmark_dies (node
->die
);
22310 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22311 prune_unmark_dies (ctnode
->root_die
);
22314 /* Set the parameter to true if there are any relative pathnames in
22317 file_table_relative_p (void ** slot
, void *param
)
22319 bool *p
= (bool *) param
;
22320 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22321 if (!IS_ABSOLUTE_PATH (d
->filename
))
22329 /* Routines to manipulate hash table of comdat type units. */
22332 htab_ct_hash (const void *of
)
22335 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
22337 memcpy (&h
, type_node
->signature
, sizeof (h
));
22342 htab_ct_eq (const void *of1
, const void *of2
)
22344 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
22345 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
22347 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22348 DWARF_TYPE_SIGNATURE_SIZE
));
22351 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22352 to the location it would have been added, should we know its
22353 DECL_ASSEMBLER_NAME when we added other attributes. This will
22354 probably improve compactness of debug info, removing equivalent
22355 abbrevs, and hide any differences caused by deferring the
22356 computation of the assembler name, triggered by e.g. PCH. */
22359 move_linkage_attr (dw_die_ref die
)
22361 unsigned ix
= vec_safe_length (die
->die_attr
);
22362 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22364 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22365 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22369 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22371 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22375 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22377 die
->die_attr
->pop ();
22378 die
->die_attr
->quick_insert (ix
, linkage
);
22382 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22383 referenced from typed stack ops and count how often they are used. */
22386 mark_base_types (dw_loc_descr_ref loc
)
22388 dw_die_ref base_type
= NULL
;
22390 for (; loc
; loc
= loc
->dw_loc_next
)
22392 switch (loc
->dw_loc_opc
)
22394 case DW_OP_GNU_regval_type
:
22395 case DW_OP_GNU_deref_type
:
22396 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22398 case DW_OP_GNU_convert
:
22399 case DW_OP_GNU_reinterpret
:
22400 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22403 case DW_OP_GNU_const_type
:
22404 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22406 case DW_OP_GNU_entry_value
:
22407 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22412 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22413 if (base_type
->die_mark
)
22414 base_type
->die_mark
++;
22417 base_types
.safe_push (base_type
);
22418 base_type
->die_mark
= 1;
22423 /* Comparison function for sorting marked base types. */
22426 base_type_cmp (const void *x
, const void *y
)
22428 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22429 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22430 unsigned int byte_size1
, byte_size2
;
22431 unsigned int encoding1
, encoding2
;
22432 if (dx
->die_mark
> dy
->die_mark
)
22434 if (dx
->die_mark
< dy
->die_mark
)
22436 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22437 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22438 if (byte_size1
< byte_size2
)
22440 if (byte_size1
> byte_size2
)
22442 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22443 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22444 if (encoding1
< encoding2
)
22446 if (encoding1
> encoding2
)
22451 /* Move base types marked by mark_base_types as early as possible
22452 in the CU, sorted by decreasing usage count both to make the
22453 uleb128 references as small as possible and to make sure they
22454 will have die_offset already computed by calc_die_sizes when
22455 sizes of typed stack loc ops is computed. */
22458 move_marked_base_types (void)
22461 dw_die_ref base_type
, die
, c
;
22463 if (base_types
.is_empty ())
22466 /* Sort by decreasing usage count, they will be added again in that
22468 base_types
.qsort (base_type_cmp
);
22469 die
= comp_unit_die ();
22470 c
= die
->die_child
;
22473 dw_die_ref prev
= c
;
22475 while (c
->die_mark
)
22477 remove_child_with_prev (c
, prev
);
22478 /* As base types got marked, there must be at least
22479 one node other than DW_TAG_base_type. */
22480 gcc_assert (c
!= c
->die_sib
);
22484 while (c
!= die
->die_child
);
22485 gcc_assert (die
->die_child
);
22486 c
= die
->die_child
;
22487 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22489 base_type
->die_mark
= 0;
22490 base_type
->die_sib
= c
->die_sib
;
22491 c
->die_sib
= base_type
;
22496 /* Helper function for resolve_addr, attempt to resolve
22497 one CONST_STRING, return non-zero if not successful. Similarly verify that
22498 SYMBOL_REFs refer to variables emitted in the current CU. */
22501 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22505 if (GET_CODE (rtl
) == CONST_STRING
)
22507 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22508 tree t
= build_string (len
, XSTR (rtl
, 0));
22509 tree tlen
= size_int (len
- 1);
22511 = build_array_type (char_type_node
, build_index_type (tlen
));
22512 rtl
= lookup_constant_def (t
);
22513 if (!rtl
|| !MEM_P (rtl
))
22515 rtl
= XEXP (rtl
, 0);
22516 if (GET_CODE (rtl
) == SYMBOL_REF
22517 && SYMBOL_REF_DECL (rtl
)
22518 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22520 vec_safe_push (used_rtx_array
, rtl
);
22525 if (GET_CODE (rtl
) == SYMBOL_REF
22526 && SYMBOL_REF_DECL (rtl
))
22528 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22530 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22533 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22537 if (GET_CODE (rtl
) == CONST
22538 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22544 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
22545 if possible, and create DW_TAG_dwarf_procedure that can be referenced
22546 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
22549 string_cst_pool_decl (tree t
)
22551 rtx rtl
= output_constant_def (t
, 1);
22552 unsigned char *array
;
22553 dw_loc_descr_ref l
;
22558 if (!rtl
|| !MEM_P (rtl
))
22560 rtl
= XEXP (rtl
, 0);
22561 if (GET_CODE (rtl
) != SYMBOL_REF
22562 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
22565 decl
= SYMBOL_REF_DECL (rtl
);
22566 if (!lookup_decl_die (decl
))
22568 len
= TREE_STRING_LENGTH (t
);
22569 vec_safe_push (used_rtx_array
, rtl
);
22570 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
22571 array
= (unsigned char *) ggc_alloc_atomic (len
);
22572 memcpy (array
, TREE_STRING_POINTER (t
), len
);
22573 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
22574 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
22575 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
22576 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
22577 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
22578 add_AT_loc (ref
, DW_AT_location
, l
);
22579 equate_decl_number_to_die (decl
, ref
);
22584 /* Helper function of resolve_addr_in_expr. LOC is
22585 a DW_OP_addr followed by DW_OP_stack_value, either at the start
22586 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
22587 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
22588 with DW_OP_GNU_implicit_pointer if possible
22589 and return true, if unsuccesful, return false. */
22592 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
22594 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
22595 HOST_WIDE_INT offset
= 0;
22596 dw_die_ref ref
= NULL
;
22599 if (GET_CODE (rtl
) == CONST
22600 && GET_CODE (XEXP (rtl
, 0)) == PLUS
22601 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
22603 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
22604 rtl
= XEXP (XEXP (rtl
, 0), 0);
22606 if (GET_CODE (rtl
) == CONST_STRING
)
22608 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22609 tree t
= build_string (len
, XSTR (rtl
, 0));
22610 tree tlen
= size_int (len
- 1);
22613 = build_array_type (char_type_node
, build_index_type (tlen
));
22614 rtl
= string_cst_pool_decl (t
);
22618 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
22620 decl
= SYMBOL_REF_DECL (rtl
);
22621 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
22623 ref
= lookup_decl_die (decl
);
22624 if (ref
&& (get_AT (ref
, DW_AT_location
)
22625 || get_AT (ref
, DW_AT_const_value
)))
22627 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
22628 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22629 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
22630 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22631 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22632 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22633 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
22641 /* Helper function for resolve_addr, handle one location
22642 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22643 the location list couldn't be resolved. */
22646 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22648 dw_loc_descr_ref keep
= NULL
;
22649 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
22650 switch (loc
->dw_loc_opc
)
22653 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22656 || prev
->dw_loc_opc
== DW_OP_piece
22657 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
22658 && loc
->dw_loc_next
22659 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
22661 && optimize_one_addr_into_implicit_ptr (loc
))
22666 case DW_OP_GNU_addr_index
:
22667 case DW_OP_GNU_const_index
:
22668 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22669 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22670 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22674 case DW_OP_const4u
:
22675 case DW_OP_const8u
:
22677 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22680 case DW_OP_plus_uconst
:
22681 if (size_of_loc_descr (loc
)
22682 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22684 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22686 dw_loc_descr_ref repl
22687 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22688 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
22689 add_loc_descr (&repl
, loc
->dw_loc_next
);
22693 case DW_OP_implicit_value
:
22694 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22695 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
22698 case DW_OP_GNU_implicit_pointer
:
22699 case DW_OP_GNU_parameter_ref
:
22700 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22703 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22706 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22707 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22708 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22711 case DW_OP_GNU_const_type
:
22712 case DW_OP_GNU_regval_type
:
22713 case DW_OP_GNU_deref_type
:
22714 case DW_OP_GNU_convert
:
22715 case DW_OP_GNU_reinterpret
:
22716 while (loc
->dw_loc_next
22717 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
22719 dw_die_ref base1
, base2
;
22720 unsigned enc1
, enc2
, size1
, size2
;
22721 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22722 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22723 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22724 else if (loc
->dw_loc_oprnd1
.val_class
22725 == dw_val_class_unsigned_const
)
22728 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22729 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
22730 == dw_val_class_unsigned_const
)
22732 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22733 gcc_assert (base1
->die_tag
== DW_TAG_base_type
22734 && base2
->die_tag
== DW_TAG_base_type
);
22735 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
22736 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
22737 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
22738 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
22740 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
22741 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
22745 /* Optimize away next DW_OP_GNU_convert after
22746 adjusting LOC's base type die reference. */
22747 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22748 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22749 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
22751 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
22752 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22755 /* Don't change integer DW_OP_GNU_convert after e.g. floating
22756 point typed stack entry. */
22757 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
22758 keep
= loc
->dw_loc_next
;
22768 /* Helper function of resolve_addr. DIE had DW_AT_location of
22769 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
22770 and DW_OP_addr couldn't be resolved. resolve_addr has already
22771 removed the DW_AT_location attribute. This function attempts to
22772 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
22773 to it or DW_AT_const_value attribute, if possible. */
22776 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
22778 if (TREE_CODE (decl
) != VAR_DECL
22779 || lookup_decl_die (decl
) != die
22780 || DECL_EXTERNAL (decl
)
22781 || !TREE_STATIC (decl
)
22782 || DECL_INITIAL (decl
) == NULL_TREE
22783 || DECL_P (DECL_INITIAL (decl
))
22784 || get_AT (die
, DW_AT_const_value
))
22787 tree init
= DECL_INITIAL (decl
);
22788 HOST_WIDE_INT offset
= 0;
22789 /* For variables that have been optimized away and thus
22790 don't have a memory location, see if we can emit
22791 DW_AT_const_value instead. */
22792 if (tree_add_const_value_attribute (die
, init
))
22796 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
22797 and ADDR_EXPR refers to a decl that has DW_AT_location or
22798 DW_AT_const_value (but isn't addressable, otherwise
22799 resolving the original DW_OP_addr wouldn't fail), see if
22800 we can add DW_OP_GNU_implicit_pointer. */
22802 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
22803 && host_integerp (TREE_OPERAND (init
, 1), 0))
22805 offset
= tree_low_cst (TREE_OPERAND (init
, 1), 0);
22806 init
= TREE_OPERAND (init
, 0);
22809 if (TREE_CODE (init
) != ADDR_EXPR
)
22811 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
22812 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
22813 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
22814 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
22815 && TREE_OPERAND (init
, 0) != decl
))
22818 dw_loc_descr_ref l
;
22820 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
22822 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
22825 decl
= SYMBOL_REF_DECL (rtl
);
22828 decl
= TREE_OPERAND (init
, 0);
22829 ref
= lookup_decl_die (decl
);
22831 || (!get_AT (ref
, DW_AT_location
)
22832 && !get_AT (ref
, DW_AT_const_value
)))
22834 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
22835 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22836 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22837 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22838 add_AT_loc (die
, DW_AT_location
, l
);
22842 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22843 an address in .rodata section if the string literal is emitted there,
22844 or remove the containing location list or replace DW_AT_const_value
22845 with DW_AT_location and empty location expression, if it isn't found
22846 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22847 to something that has been emitted in the current CU. */
22850 resolve_addr (dw_die_ref die
)
22854 dw_loc_list_ref
*curr
, *start
, loc
;
22857 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22858 switch (AT_class (a
))
22860 case dw_val_class_loc_list
:
22861 start
= curr
= AT_loc_list_ptr (a
);
22864 /* The same list can be referenced more than once. See if we have
22865 already recorded the result from a previous pass. */
22867 *curr
= loc
->dw_loc_next
;
22868 else if (!loc
->resolved_addr
)
22870 /* As things stand, we do not expect or allow one die to
22871 reference a suffix of another die's location list chain.
22872 References must be identical or completely separate.
22873 There is therefore no need to cache the result of this
22874 pass on any list other than the first; doing so
22875 would lead to unnecessary writes. */
22878 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
22879 if (!resolve_addr_in_expr ((*curr
)->expr
))
22881 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
22882 dw_loc_descr_ref l
= (*curr
)->expr
;
22884 if (next
&& (*curr
)->ll_symbol
)
22886 gcc_assert (!next
->ll_symbol
);
22887 next
->ll_symbol
= (*curr
)->ll_symbol
;
22889 if (dwarf_split_debug_info
)
22890 remove_loc_list_addr_table_entries (l
);
22895 mark_base_types ((*curr
)->expr
);
22896 curr
= &(*curr
)->dw_loc_next
;
22900 loc
->resolved_addr
= 1;
22904 loc
->dw_loc_next
= *start
;
22909 remove_AT (die
, a
->dw_attr
);
22913 case dw_val_class_loc
:
22915 dw_loc_descr_ref l
= AT_loc (a
);
22916 /* For -gdwarf-2 don't attempt to optimize
22917 DW_AT_data_member_location containing
22918 DW_OP_plus_uconst - older consumers might
22919 rely on it being that op instead of a more complex,
22920 but shorter, location description. */
22921 if ((dwarf_version
> 2
22922 || a
->dw_attr
!= DW_AT_data_member_location
22924 || l
->dw_loc_opc
!= DW_OP_plus_uconst
22925 || l
->dw_loc_next
!= NULL
)
22926 && !resolve_addr_in_expr (l
))
22928 if (dwarf_split_debug_info
)
22929 remove_loc_list_addr_table_entries (l
);
22931 && l
->dw_loc_next
== NULL
22932 && l
->dw_loc_opc
== DW_OP_addr
22933 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
22934 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
22935 && a
->dw_attr
== DW_AT_location
)
22937 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
22938 remove_AT (die
, a
->dw_attr
);
22940 optimize_location_into_implicit_ptr (die
, decl
);
22943 remove_AT (die
, a
->dw_attr
);
22947 mark_base_types (l
);
22950 case dw_val_class_addr
:
22951 if (a
->dw_attr
== DW_AT_const_value
22952 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
22954 if (AT_index (a
) != NOT_INDEXED
)
22955 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
22956 remove_AT (die
, a
->dw_attr
);
22959 if (die
->die_tag
== DW_TAG_GNU_call_site
22960 && a
->dw_attr
== DW_AT_abstract_origin
)
22962 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
22963 dw_die_ref tdie
= lookup_decl_die (tdecl
);
22965 && DECL_EXTERNAL (tdecl
)
22966 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
22968 force_decl_die (tdecl
);
22969 tdie
= lookup_decl_die (tdecl
);
22973 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
22974 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
22975 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
22979 if (AT_index (a
) != NOT_INDEXED
)
22980 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
22981 remove_AT (die
, a
->dw_attr
);
22990 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
22993 /* Helper routines for optimize_location_lists.
22994 This pass tries to share identical local lists in .debug_loc
22997 /* Iteratively hash operands of LOC opcode. */
22999 static inline hashval_t
23000 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23002 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23003 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23005 switch (loc
->dw_loc_opc
)
23007 case DW_OP_const4u
:
23008 case DW_OP_const8u
:
23012 case DW_OP_const1u
:
23013 case DW_OP_const1s
:
23014 case DW_OP_const2u
:
23015 case DW_OP_const2s
:
23016 case DW_OP_const4s
:
23017 case DW_OP_const8s
:
23021 case DW_OP_plus_uconst
:
23057 case DW_OP_deref_size
:
23058 case DW_OP_xderef_size
:
23059 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23066 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23067 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23068 hash
= iterative_hash_object (offset
, hash
);
23071 case DW_OP_implicit_value
:
23072 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23073 switch (val2
->val_class
)
23075 case dw_val_class_const
:
23076 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23078 case dw_val_class_vec
:
23080 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23081 unsigned int len
= val2
->v
.val_vec
.length
;
23083 hash
= iterative_hash_object (elt_size
, hash
);
23084 hash
= iterative_hash_object (len
, hash
);
23085 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23086 len
* elt_size
, hash
);
23089 case dw_val_class_const_double
:
23090 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23091 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23093 case dw_val_class_addr
:
23094 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23097 gcc_unreachable ();
23101 case DW_OP_bit_piece
:
23102 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23103 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23109 unsigned char dtprel
= 0xd1;
23110 hash
= iterative_hash_object (dtprel
, hash
);
23112 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23114 case DW_OP_GNU_addr_index
:
23115 case DW_OP_GNU_const_index
:
23119 unsigned char dtprel
= 0xd1;
23120 hash
= iterative_hash_object (dtprel
, hash
);
23122 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23125 case DW_OP_GNU_implicit_pointer
:
23126 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23128 case DW_OP_GNU_entry_value
:
23129 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23131 case DW_OP_GNU_regval_type
:
23132 case DW_OP_GNU_deref_type
:
23134 unsigned int byte_size
23135 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23136 unsigned int encoding
23137 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23138 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23139 hash
= iterative_hash_object (byte_size
, hash
);
23140 hash
= iterative_hash_object (encoding
, hash
);
23143 case DW_OP_GNU_convert
:
23144 case DW_OP_GNU_reinterpret
:
23145 if (val1
->val_class
== dw_val_class_unsigned_const
)
23147 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23151 case DW_OP_GNU_const_type
:
23153 unsigned int byte_size
23154 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23155 unsigned int encoding
23156 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23157 hash
= iterative_hash_object (byte_size
, hash
);
23158 hash
= iterative_hash_object (encoding
, hash
);
23159 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23161 hash
= iterative_hash_object (val2
->val_class
, hash
);
23162 switch (val2
->val_class
)
23164 case dw_val_class_const
:
23165 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23167 case dw_val_class_vec
:
23169 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23170 unsigned int len
= val2
->v
.val_vec
.length
;
23172 hash
= iterative_hash_object (elt_size
, hash
);
23173 hash
= iterative_hash_object (len
, hash
);
23174 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23175 len
* elt_size
, hash
);
23178 case dw_val_class_const_double
:
23179 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23180 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23183 gcc_unreachable ();
23189 /* Other codes have no operands. */
23195 /* Iteratively hash the whole DWARF location expression LOC. */
23197 static inline hashval_t
23198 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23200 dw_loc_descr_ref l
;
23201 bool sizes_computed
= false;
23202 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23203 size_of_locs (loc
);
23205 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23207 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23208 hash
= iterative_hash_object (opc
, hash
);
23209 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23211 size_of_locs (loc
);
23212 sizes_computed
= true;
23214 hash
= hash_loc_operands (l
, hash
);
23219 /* Compute hash of the whole location list LIST_HEAD. */
23222 hash_loc_list (dw_loc_list_ref list_head
)
23224 dw_loc_list_ref curr
= list_head
;
23225 hashval_t hash
= 0;
23227 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23229 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23230 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23232 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23234 hash
= hash_locs (curr
->expr
, hash
);
23236 list_head
->hash
= hash
;
23239 /* Return true if X and Y opcodes have the same operands. */
23242 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23244 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23245 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23246 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23247 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23249 switch (x
->dw_loc_opc
)
23251 case DW_OP_const4u
:
23252 case DW_OP_const8u
:
23256 case DW_OP_const1u
:
23257 case DW_OP_const1s
:
23258 case DW_OP_const2u
:
23259 case DW_OP_const2s
:
23260 case DW_OP_const4s
:
23261 case DW_OP_const8s
:
23265 case DW_OP_plus_uconst
:
23301 case DW_OP_deref_size
:
23302 case DW_OP_xderef_size
:
23303 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23306 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23307 can cause irrelevant differences in dw_loc_addr. */
23308 gcc_assert (valx1
->val_class
== dw_val_class_loc
23309 && valy1
->val_class
== dw_val_class_loc
23310 && (dwarf_split_debug_info
23311 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23312 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23313 case DW_OP_implicit_value
:
23314 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23315 || valx2
->val_class
!= valy2
->val_class
)
23317 switch (valx2
->val_class
)
23319 case dw_val_class_const
:
23320 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23321 case dw_val_class_vec
:
23322 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23323 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23324 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23325 valx2
->v
.val_vec
.elt_size
23326 * valx2
->v
.val_vec
.length
) == 0;
23327 case dw_val_class_const_double
:
23328 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23329 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23330 case dw_val_class_addr
:
23331 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23333 gcc_unreachable ();
23336 case DW_OP_bit_piece
:
23337 return valx1
->v
.val_int
== valy1
->v
.val_int
23338 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23341 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23342 case DW_OP_GNU_addr_index
:
23343 case DW_OP_GNU_const_index
:
23345 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23346 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23347 return rtx_equal_p (ax1
, ay1
);
23349 case DW_OP_GNU_implicit_pointer
:
23350 return valx1
->val_class
== dw_val_class_die_ref
23351 && valx1
->val_class
== valy1
->val_class
23352 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23353 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23354 case DW_OP_GNU_entry_value
:
23355 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23356 case DW_OP_GNU_const_type
:
23357 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23358 || valx2
->val_class
!= valy2
->val_class
)
23360 switch (valx2
->val_class
)
23362 case dw_val_class_const
:
23363 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23364 case dw_val_class_vec
:
23365 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23366 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23367 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23368 valx2
->v
.val_vec
.elt_size
23369 * valx2
->v
.val_vec
.length
) == 0;
23370 case dw_val_class_const_double
:
23371 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23372 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23374 gcc_unreachable ();
23376 case DW_OP_GNU_regval_type
:
23377 case DW_OP_GNU_deref_type
:
23378 return valx1
->v
.val_int
== valy1
->v
.val_int
23379 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23380 case DW_OP_GNU_convert
:
23381 case DW_OP_GNU_reinterpret
:
23382 if (valx1
->val_class
!= valy1
->val_class
)
23384 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23385 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23386 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23387 case DW_OP_GNU_parameter_ref
:
23388 return valx1
->val_class
== dw_val_class_die_ref
23389 && valx1
->val_class
== valy1
->val_class
23390 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23392 /* Other codes have no operands. */
23397 /* Return true if DWARF location expressions X and Y are the same. */
23400 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23402 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23403 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23404 || x
->dtprel
!= y
->dtprel
23405 || !compare_loc_operands (x
, y
))
23407 return x
== NULL
&& y
== NULL
;
23410 /* Return precomputed hash of location list X. */
23413 loc_list_hash (const void *x
)
23415 return ((const struct dw_loc_list_struct
*) x
)->hash
;
23418 /* Return 1 if location lists X and Y are the same. */
23421 loc_list_eq (const void *x
, const void *y
)
23423 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
23424 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
23427 if (a
->hash
!= b
->hash
)
23429 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23430 if (strcmp (a
->begin
, b
->begin
) != 0
23431 || strcmp (a
->end
, b
->end
) != 0
23432 || (a
->section
== NULL
) != (b
->section
== NULL
)
23433 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23434 || !compare_locs (a
->expr
, b
->expr
))
23436 return a
== NULL
&& b
== NULL
;
23439 /* Recursively optimize location lists referenced from DIE
23440 children and share them whenever possible. */
23443 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
23450 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23451 if (AT_class (a
) == dw_val_class_loc_list
)
23453 dw_loc_list_ref list
= AT_loc_list (a
);
23454 /* TODO: perform some optimizations here, before hashing
23455 it and storing into the hash table. */
23456 hash_loc_list (list
);
23457 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
23460 *slot
= (void *) list
;
23462 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
23465 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23469 /* Recursively assign each location list a unique index into the debug_addr
23473 index_location_lists (dw_die_ref die
)
23479 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23480 if (AT_class (a
) == dw_val_class_loc_list
)
23482 dw_loc_list_ref list
= AT_loc_list (a
);
23483 dw_loc_list_ref curr
;
23484 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23486 /* Don't index an entry that has already been indexed
23487 or won't be output. */
23488 if (curr
->begin_entry
!= NULL
23489 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23493 = add_addr_table_entry (xstrdup (curr
->begin
),
23498 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23501 /* Optimize location lists referenced from DIE
23502 children and share them whenever possible. */
23505 optimize_location_lists (dw_die_ref die
)
23507 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
23508 optimize_location_lists_1 (die
, htab
);
23509 htab_delete (htab
);
23512 /* Output stuff that dwarf requires at the end of every file,
23513 and generate the DWARF-2 debugging info. */
23516 dwarf2out_finish (const char *filename
)
23518 limbo_die_node
*node
, *next_node
;
23519 comdat_type_node
*ctnode
;
23520 htab_t comdat_type_table
;
23522 dw_die_ref main_comp_unit_die
;
23524 /* PCH might result in DW_AT_producer string being restored from the
23525 header compilation, so always fill it with empty string initially
23526 and overwrite only here. */
23527 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23528 producer_string
= gen_producer_string ();
23529 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23530 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23532 gen_scheduled_generic_parms_dies ();
23533 gen_remaining_tmpl_value_param_die_attribute ();
23535 /* Add the name for the main input file now. We delayed this from
23536 dwarf2out_init to avoid complications with PCH. */
23537 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23538 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23539 add_comp_dir_attribute (comp_unit_die ());
23540 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23543 htab_traverse (file_table
, file_table_relative_p
, &p
);
23545 add_comp_dir_attribute (comp_unit_die ());
23548 if (deferred_locations_list
)
23549 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23551 add_location_or_const_value_attribute (
23552 (*deferred_locations_list
)[i
].die
,
23553 (*deferred_locations_list
)[i
].variable
,
23558 /* Traverse the limbo die list, and add parent/child links. The only
23559 dies without parents that should be here are concrete instances of
23560 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23561 For concrete instances, we can get the parent die from the abstract
23563 for (node
= limbo_die_list
; node
; node
= next_node
)
23565 dw_die_ref die
= node
->die
;
23566 next_node
= node
->next
;
23568 if (die
->die_parent
== NULL
)
23570 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23572 if (origin
&& origin
->die_parent
)
23573 add_child_die (origin
->die_parent
, die
);
23574 else if (is_cu_die (die
))
23576 else if (seen_error ())
23577 /* It's OK to be confused by errors in the input. */
23578 add_child_die (comp_unit_die (), die
);
23581 /* In certain situations, the lexical block containing a
23582 nested function can be optimized away, which results
23583 in the nested function die being orphaned. Likewise
23584 with the return type of that nested function. Force
23585 this to be a child of the containing function.
23587 It may happen that even the containing function got fully
23588 inlined and optimized out. In that case we are lost and
23589 assign the empty child. This should not be big issue as
23590 the function is likely unreachable too. */
23591 gcc_assert (node
->created_for
);
23593 if (DECL_P (node
->created_for
))
23594 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23595 else if (TYPE_P (node
->created_for
))
23596 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23598 origin
= comp_unit_die ();
23600 add_child_die (origin
, die
);
23605 limbo_die_list
= NULL
;
23607 #if ENABLE_ASSERT_CHECKING
23609 dw_die_ref die
= comp_unit_die (), c
;
23610 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23613 resolve_addr (comp_unit_die ());
23614 move_marked_base_types ();
23616 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23618 tree decl
= node
->created_for
;
23619 /* When generating LTO bytecode we can not generate new assembler
23620 names at this point and all important decls got theirs via
23622 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23623 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23625 add_linkage_attr (node
->die
, decl
);
23626 move_linkage_attr (node
->die
);
23630 deferred_asm_name
= NULL
;
23632 /* Walk through the list of incomplete types again, trying once more to
23633 emit full debugging info for them. */
23634 retry_incomplete_types ();
23636 if (flag_eliminate_unused_debug_types
)
23637 prune_unused_types ();
23639 /* Generate separate COMDAT sections for type DIEs. */
23640 if (use_debug_types
)
23642 break_out_comdat_types (comp_unit_die ());
23644 /* Each new type_unit DIE was added to the limbo die list when created.
23645 Since these have all been added to comdat_type_list, clear the
23647 limbo_die_list
= NULL
;
23649 /* For each new comdat type unit, copy declarations for incomplete
23650 types to make the new unit self-contained (i.e., no direct
23651 references to the main compile unit). */
23652 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23653 copy_decls_for_unworthy_types (ctnode
->root_die
);
23654 copy_decls_for_unworthy_types (comp_unit_die ());
23656 /* In the process of copying declarations from one unit to another,
23657 we may have left some declarations behind that are no longer
23658 referenced. Prune them. */
23659 prune_unused_types ();
23662 /* Generate separate CUs for each of the include files we've seen.
23663 They will go into limbo_die_list. */
23664 if (flag_eliminate_dwarf2_dups
)
23665 break_out_includes (comp_unit_die ());
23667 /* Traverse the DIE's and add add sibling attributes to those DIE's
23668 that have children. */
23669 add_sibling_attributes (comp_unit_die ());
23670 for (node
= limbo_die_list
; node
; node
= node
->next
)
23671 add_sibling_attributes (node
->die
);
23672 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23673 add_sibling_attributes (ctnode
->root_die
);
23675 /* When splitting DWARF info, we put some attributes in the
23676 skeleton compile_unit DIE that remains in the .o, while
23677 most attributes go in the DWO compile_unit_die. */
23678 if (dwarf_split_debug_info
)
23679 main_comp_unit_die
= gen_compile_unit_die (NULL
);
23681 main_comp_unit_die
= comp_unit_die ();
23683 /* Output a terminator label for the .text section. */
23684 switch_to_section (text_section
);
23685 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23686 if (cold_text_section
)
23688 switch_to_section (cold_text_section
);
23689 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23692 /* We can only use the low/high_pc attributes if all of the code was
23694 if (!have_multiple_function_sections
23695 || (dwarf_version
< 3 && dwarf_strict
))
23697 /* Don't add if the CU has no associated code. */
23698 if (text_section_used
)
23699 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
23700 text_end_label
, true);
23706 bool range_list_added
= false;
23708 if (text_section_used
)
23709 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
23710 text_end_label
, &range_list_added
, true);
23711 if (cold_text_section_used
)
23712 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
23713 cold_end_label
, &range_list_added
, true);
23715 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
23717 if (DECL_IGNORED_P (fde
->decl
))
23719 if (!fde
->in_std_section
)
23720 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
23721 fde
->dw_fde_end
, &range_list_added
,
23723 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23724 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
23725 fde
->dw_fde_second_end
, &range_list_added
,
23729 if (range_list_added
)
23731 /* We need to give .debug_loc and .debug_ranges an appropriate
23732 "base address". Use zero so that these addresses become
23733 absolute. Historically, we've emitted the unexpected
23734 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23735 Emit both to give time for other tools to adapt. */
23736 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
23737 if (! dwarf_strict
&& dwarf_version
< 4)
23738 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
23744 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23745 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
23746 debug_line_section_label
);
23749 add_AT_macptr (comp_unit_die (),
23750 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
23751 macinfo_section_label
);
23753 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
23755 /* optimize_location_lists calculates the size of the lists,
23756 so index them first, and assign indices to the entries.
23757 Although optimize_location_lists will remove entries from
23758 the table, it only does so for duplicates, and therefore
23759 only reduces ref_counts to 1. */
23760 unsigned int index
= 0;
23761 index_location_lists (comp_unit_die ());
23762 htab_traverse_noresize (addr_index_table
,
23763 index_addr_table_entry
, &index
);
23765 if (have_location_lists
)
23766 optimize_location_lists (comp_unit_die ());
23768 save_macinfo_strings ();
23769 if (dwarf_split_debug_info
)
23771 unsigned int index
= 0;
23772 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
23775 /* Output all of the compilation units. We put the main one last so that
23776 the offsets are available to output_pubnames. */
23777 for (node
= limbo_die_list
; node
; node
= node
->next
)
23778 output_comp_unit (node
->die
, 0);
23780 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
23781 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23783 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
23785 /* Don't output duplicate types. */
23786 if (*slot
!= HTAB_EMPTY_ENTRY
)
23789 /* Add a pointer to the line table for the main compilation unit
23790 so that the debugger can make sense of DW_AT_decl_file
23792 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23793 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23794 (!dwarf_split_debug_info
23795 ? debug_line_section_label
23796 : debug_skeleton_line_section_label
));
23798 output_comdat_type_unit (ctnode
);
23801 htab_delete (comdat_type_table
);
23803 /* The AT_pubnames attribute needs to go in all skeleton dies, including
23804 both the main_cu and all skeleton TUs. Making this call unconditional
23805 would end up either adding a second copy of the AT_pubnames attribute, or
23806 requiring a special case in add_top_level_skeleton_die_attrs. */
23807 if (!dwarf_split_debug_info
)
23808 add_AT_pubnames (comp_unit_die ());
23810 if (dwarf_split_debug_info
)
23813 unsigned char checksum
[16];
23814 struct md5_ctx ctx
;
23816 /* Compute a checksum of the comp_unit to use as the dwo_id. */
23817 md5_init_ctx (&ctx
);
23819 die_checksum (comp_unit_die (), &ctx
, &mark
);
23820 unmark_all_dies (comp_unit_die ());
23821 md5_finish_ctx (&ctx
, checksum
);
23823 /* Use the first 8 bytes of the checksum as the dwo_id,
23824 and add it to both comp-unit DIEs. */
23825 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
23826 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
23828 /* Add the base offset of the ranges table to the skeleton
23830 if (ranges_table_in_use
)
23831 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
23832 ranges_section_label
);
23834 switch_to_section (debug_addr_section
);
23835 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
23836 output_addr_table ();
23839 /* Output the main compilation unit if non-empty or if .debug_macinfo
23840 or .debug_macro will be emitted. */
23841 output_comp_unit (comp_unit_die (), have_macinfo
);
23843 if (dwarf_split_debug_info
&& info_section_emitted
)
23844 output_skeleton_debug_sections (main_comp_unit_die
);
23846 /* Output the abbreviation table. */
23847 if (abbrev_die_table_in_use
!= 1)
23849 switch_to_section (debug_abbrev_section
);
23850 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
23851 output_abbrev_section ();
23854 /* Output location list section if necessary. */
23855 if (have_location_lists
)
23857 /* Output the location lists info. */
23858 switch_to_section (debug_loc_section
);
23859 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
23860 output_location_lists (comp_unit_die ());
23863 /* Output public names and types tables if necessary. */
23864 output_pubnames (pubname_table
);
23865 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23866 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23867 simply won't look for the section. */
23868 output_pubnames (pubtype_table
);
23870 /* Output the address range information if a CU (.debug_info section)
23871 was emitted. We output an empty table even if we had no functions
23872 to put in it. This because the consumer has no way to tell the
23873 difference between an empty table that we omitted and failure to
23874 generate a table that would have contained data. */
23875 if (info_section_emitted
)
23877 unsigned long aranges_length
= size_of_aranges ();
23879 switch_to_section (debug_aranges_section
);
23880 output_aranges (aranges_length
);
23883 /* Output ranges section if necessary. */
23884 if (ranges_table_in_use
)
23886 switch_to_section (debug_ranges_section
);
23887 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
23891 /* Have to end the macro section. */
23894 switch_to_section (debug_macinfo_section
);
23895 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
23897 dw2_asm_output_data (1, 0, "End compilation unit");
23900 /* Output the source line correspondence table. We must do this
23901 even if there is no line information. Otherwise, on an empty
23902 translation unit, we will generate a present, but empty,
23903 .debug_info section. IRIX 6.5 `nm' will then complain when
23904 examining the file. This is done late so that any filenames
23905 used by the debug_info section are marked as 'used'. */
23906 switch_to_section (debug_line_section
);
23907 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
23908 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
23909 output_line_info (false);
23911 if (dwarf_split_debug_info
&& info_section_emitted
)
23913 switch_to_section (debug_skeleton_line_section
);
23914 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
23915 output_line_info (true);
23918 /* If we emitted any indirect strings, output the string table too. */
23919 if (debug_str_hash
)
23920 output_indirect_strings ();
23923 #include "gt-dwarf2out.h"