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_set_name (tree
, tree
);
2356 /* The debug hooks structure. */
2358 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2362 dwarf2out_assembly_start
,
2365 dwarf2out_start_source_file
,
2366 dwarf2out_end_source_file
,
2367 dwarf2out_begin_block
,
2368 dwarf2out_end_block
,
2369 dwarf2out_ignore_block
,
2370 dwarf2out_source_line
,
2371 dwarf2out_begin_prologue
,
2372 #if VMS_DEBUGGING_INFO
2373 dwarf2out_vms_end_prologue
,
2374 dwarf2out_vms_begin_epilogue
,
2376 debug_nothing_int_charstar
,
2377 debug_nothing_int_charstar
,
2379 dwarf2out_end_epilogue
,
2380 dwarf2out_begin_function
,
2381 debug_nothing_int
, /* end_function */
2382 dwarf2out_function_decl
, /* function_decl */
2383 dwarf2out_global_decl
,
2384 dwarf2out_type_decl
, /* type_decl */
2385 dwarf2out_imported_module_or_decl
,
2386 debug_nothing_tree
, /* deferred_inline_function */
2387 /* The DWARF 2 backend tries to reduce debugging bloat by not
2388 emitting the abstract description of inline functions until
2389 something tries to reference them. */
2390 dwarf2out_abstract_function
, /* outlining_inline_function */
2391 debug_nothing_rtx
, /* label */
2392 debug_nothing_int
, /* handle_pch */
2393 dwarf2out_var_location
,
2394 dwarf2out_switch_text_section
,
2396 1, /* start_end_main_source_file */
2397 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2400 /* NOTE: In the comments in this file, many references are made to
2401 "Debugging Information Entries". This term is abbreviated as `DIE'
2402 throughout the remainder of this file. */
2404 /* An internal representation of the DWARF output is built, and then
2405 walked to generate the DWARF debugging info. The walk of the internal
2406 representation is done after the entire program has been compiled.
2407 The types below are used to describe the internal representation. */
2409 /* Whether to put type DIEs into their own section .debug_types instead
2410 of making them part of the .debug_info section. Only supported for
2411 Dwarf V4 or higher and the user didn't disable them through
2412 -fno-debug-types-section. It is more efficient to put them in a
2413 separate comdat sections since the linker will then be able to
2414 remove duplicates. But not all tools support .debug_types sections
2417 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2419 /* Various DIE's use offsets relative to the beginning of the
2420 .debug_info section to refer to each other. */
2422 typedef long int dw_offset
;
2424 /* Define typedefs here to avoid circular dependencies. */
2426 typedef struct dw_attr_struct
*dw_attr_ref
;
2427 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2428 typedef struct pubname_struct
*pubname_ref
;
2429 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2430 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2431 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2433 /* The entries in the line_info table more-or-less mirror the opcodes
2434 that are used in the real dwarf line table. Arrays of these entries
2435 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2438 enum dw_line_info_opcode
{
2439 /* Emit DW_LNE_set_address; the operand is the label index. */
2442 /* Emit a row to the matrix with the given line. This may be done
2443 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2447 /* Emit a DW_LNS_set_file. */
2450 /* Emit a DW_LNS_set_column. */
2453 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2456 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2457 LI_set_prologue_end
,
2458 LI_set_epilogue_begin
,
2460 /* Emit a DW_LNE_set_discriminator. */
2461 LI_set_discriminator
2464 typedef struct GTY(()) dw_line_info_struct
{
2465 enum dw_line_info_opcode opcode
;
2467 } dw_line_info_entry
;
2470 typedef struct GTY(()) dw_line_info_table_struct
{
2471 /* The label that marks the end of this section. */
2472 const char *end_label
;
2474 /* The values for the last row of the matrix, as collected in the table.
2475 These are used to minimize the changes to the next row. */
2476 unsigned int file_num
;
2477 unsigned int line_num
;
2478 unsigned int column_num
;
2483 vec
<dw_line_info_entry
, va_gc
> *entries
;
2484 } dw_line_info_table
;
2486 typedef dw_line_info_table
*dw_line_info_table_p
;
2489 /* Each DIE attribute has a field specifying the attribute kind,
2490 a link to the next attribute in the chain, and an attribute value.
2491 Attributes are typically linked below the DIE they modify. */
2493 typedef struct GTY(()) dw_attr_struct
{
2494 enum dwarf_attribute dw_attr
;
2495 dw_val_node dw_attr_val
;
2500 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2501 The children of each node form a circular list linked by
2502 die_sib. die_child points to the node *before* the "first" child node. */
2504 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2505 union die_symbol_or_type_node
2507 const char * GTY ((tag ("0"))) die_symbol
;
2508 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2510 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2511 vec
<dw_attr_node
, va_gc
> *die_attr
;
2512 dw_die_ref die_parent
;
2513 dw_die_ref die_child
;
2515 dw_die_ref die_definition
; /* ref from a specification to its definition */
2516 dw_offset die_offset
;
2517 unsigned long die_abbrev
;
2519 unsigned int decl_id
;
2520 enum dwarf_tag die_tag
;
2521 /* Die is used and must not be pruned as unused. */
2522 BOOL_BITFIELD die_perennial_p
: 1;
2523 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2524 /* Lots of spare bits. */
2528 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2529 #define FOR_EACH_CHILD(die, c, expr) do { \
2530 c = die->die_child; \
2534 } while (c != die->die_child); \
2537 /* The pubname structure */
2539 typedef struct GTY(()) pubname_struct
{
2546 struct GTY(()) dw_ranges_struct
{
2547 /* If this is positive, it's a block number, otherwise it's a
2548 bitwise-negated index into dw_ranges_by_label. */
2552 /* A structure to hold a macinfo entry. */
2554 typedef struct GTY(()) macinfo_struct
{
2556 unsigned HOST_WIDE_INT lineno
;
2562 struct GTY(()) dw_ranges_by_label_struct
{
2567 /* The comdat type node structure. */
2568 typedef struct GTY(()) comdat_type_struct
2570 dw_die_ref root_die
;
2571 dw_die_ref type_die
;
2572 dw_die_ref skeleton_die
;
2573 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2574 struct comdat_type_struct
*next
;
2578 /* The limbo die list structure. */
2579 typedef struct GTY(()) limbo_die_struct
{
2582 struct limbo_die_struct
*next
;
2586 typedef struct skeleton_chain_struct
2590 struct skeleton_chain_struct
*parent
;
2592 skeleton_chain_node
;
2594 /* Define a macro which returns nonzero for a TYPE_DECL which was
2595 implicitly generated for a type.
2597 Note that, unlike the C front-end (which generates a NULL named
2598 TYPE_DECL node for each complete tagged type, each array type,
2599 and each function type node created) the C++ front-end generates
2600 a _named_ TYPE_DECL node for each tagged type node created.
2601 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2602 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2603 front-end, but for each type, tagged or not. */
2605 #define TYPE_DECL_IS_STUB(decl) \
2606 (DECL_NAME (decl) == NULL_TREE \
2607 || (DECL_ARTIFICIAL (decl) \
2608 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2609 /* This is necessary for stub decls that \
2610 appear in nested inline functions. */ \
2611 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2612 && (decl_ultimate_origin (decl) \
2613 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2615 /* Information concerning the compilation unit's programming
2616 language, and compiler version. */
2618 /* Fixed size portion of the DWARF compilation unit header. */
2619 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2620 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2622 /* Fixed size portion of the DWARF comdat type unit header. */
2623 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2624 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2625 + DWARF_OFFSET_SIZE)
2627 /* Fixed size portion of public names info. */
2628 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2630 /* Fixed size portion of the address range info. */
2631 #define DWARF_ARANGES_HEADER_SIZE \
2632 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2633 DWARF2_ADDR_SIZE * 2) \
2634 - DWARF_INITIAL_LENGTH_SIZE)
2636 /* Size of padding portion in the address range info. It must be
2637 aligned to twice the pointer size. */
2638 #define DWARF_ARANGES_PAD_SIZE \
2639 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2640 DWARF2_ADDR_SIZE * 2) \
2641 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2643 /* Use assembler line directives if available. */
2644 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2645 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2646 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2648 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2652 /* Minimum line offset in a special line info. opcode.
2653 This value was chosen to give a reasonable range of values. */
2654 #define DWARF_LINE_BASE -10
2656 /* First special line opcode - leave room for the standard opcodes. */
2657 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2659 /* Range of line offsets in a special line info. opcode. */
2660 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2662 /* Flag that indicates the initial value of the is_stmt_start flag.
2663 In the present implementation, we do not mark any lines as
2664 the beginning of a source statement, because that information
2665 is not made available by the GCC front-end. */
2666 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2668 /* Maximum number of operations per instruction bundle. */
2669 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2670 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2673 /* This location is used by calc_die_sizes() to keep track
2674 the offset of each DIE within the .debug_info section. */
2675 static unsigned long next_die_offset
;
2677 /* Record the root of the DIE's built for the current compilation unit. */
2678 static GTY(()) dw_die_ref single_comp_unit_die
;
2680 /* A list of type DIEs that have been separated into comdat sections. */
2681 static GTY(()) comdat_type_node
*comdat_type_list
;
2683 /* A list of DIEs with a NULL parent waiting to be relocated. */
2684 static GTY(()) limbo_die_node
*limbo_die_list
;
2686 /* A list of DIEs for which we may have to generate
2687 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2688 static GTY(()) limbo_die_node
*deferred_asm_name
;
2690 /* Filenames referenced by this compilation unit. */
2691 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2693 /* A hash table of references to DIE's that describe declarations.
2694 The key is a DECL_UID() which is a unique number identifying each decl. */
2695 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2697 /* A hash table of references to DIE's that describe COMMON blocks.
2698 The key is DECL_UID() ^ die_parent. */
2699 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2701 typedef struct GTY(()) die_arg_entry_struct
{
2707 /* Node of the variable location list. */
2708 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2709 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2710 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2711 in mode of the EXPR_LIST node and first EXPR_LIST operand
2712 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2713 location or NULL for padding. For larger bitsizes,
2714 mode is 0 and first operand is a CONCAT with bitsize
2715 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2716 NULL as second operand. */
2718 const char * GTY (()) label
;
2719 struct var_loc_node
* GTY (()) next
;
2722 /* Variable location list. */
2723 struct GTY (()) var_loc_list_def
{
2724 struct var_loc_node
* GTY (()) first
;
2726 /* Pointer to the last but one or last element of the
2727 chained list. If the list is empty, both first and
2728 last are NULL, if the list contains just one node
2729 or the last node certainly is not redundant, it points
2730 to the last node, otherwise points to the last but one.
2731 Do not mark it for GC because it is marked through the chain. */
2732 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2734 /* Pointer to the last element before section switch,
2735 if NULL, either sections weren't switched or first
2736 is after section switch. */
2737 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2739 /* DECL_UID of the variable decl. */
2740 unsigned int decl_id
;
2742 typedef struct var_loc_list_def var_loc_list
;
2744 /* Call argument location list. */
2745 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2746 rtx
GTY (()) call_arg_loc_note
;
2747 const char * GTY (()) label
;
2748 tree
GTY (()) block
;
2750 rtx
GTY (()) symbol_ref
;
2751 struct call_arg_loc_node
* GTY (()) next
;
2755 /* Table of decl location linked lists. */
2756 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2758 /* Head and tail of call_arg_loc chain. */
2759 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2760 static struct call_arg_loc_node
*call_arg_loc_last
;
2762 /* Number of call sites in the current function. */
2763 static int call_site_count
= -1;
2764 /* Number of tail call sites in the current function. */
2765 static int tail_call_site_count
= -1;
2767 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2769 static vec
<dw_die_ref
> block_map
;
2771 /* A cached location list. */
2772 struct GTY (()) cached_dw_loc_list_def
{
2773 /* The DECL_UID of the decl that this entry describes. */
2774 unsigned int decl_id
;
2776 /* The cached location list. */
2777 dw_loc_list_ref loc_list
;
2779 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2781 /* Table of cached location lists. */
2782 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2784 /* A pointer to the base of a list of references to DIE's that
2785 are uniquely identified by their tag, presence/absence of
2786 children DIE's, and list of attribute/value pairs. */
2787 static GTY((length ("abbrev_die_table_allocated")))
2788 dw_die_ref
*abbrev_die_table
;
2790 /* Number of elements currently allocated for abbrev_die_table. */
2791 static GTY(()) unsigned abbrev_die_table_allocated
;
2793 /* Number of elements in type_die_table currently in use. */
2794 static GTY(()) unsigned abbrev_die_table_in_use
;
2796 /* Size (in elements) of increments by which we may expand the
2797 abbrev_die_table. */
2798 #define ABBREV_DIE_TABLE_INCREMENT 256
2800 /* A global counter for generating labels for line number data. */
2801 static unsigned int line_info_label_num
;
2803 /* The current table to which we should emit line number information
2804 for the current function. This will be set up at the beginning of
2805 assembly for the function. */
2806 static dw_line_info_table
*cur_line_info_table
;
2808 /* The two default tables of line number info. */
2809 static GTY(()) dw_line_info_table
*text_section_line_info
;
2810 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2812 /* The set of all non-default tables of line number info. */
2813 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2815 /* A flag to tell pubnames/types export if there is an info section to
2817 static bool info_section_emitted
;
2819 /* A pointer to the base of a table that contains a list of publicly
2820 accessible names. */
2821 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2823 /* A pointer to the base of a table that contains a list of publicly
2824 accessible types. */
2825 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2827 /* A pointer to the base of a table that contains a list of macro
2828 defines/undefines (and file start/end markers). */
2829 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2831 /* True if .debug_macinfo or .debug_macros section is going to be
2833 #define have_macinfo \
2834 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2835 && !macinfo_table->is_empty ())
2837 /* Array of dies for which we should generate .debug_ranges info. */
2838 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2840 /* Number of elements currently allocated for ranges_table. */
2841 static GTY(()) unsigned ranges_table_allocated
;
2843 /* Number of elements in ranges_table currently in use. */
2844 static GTY(()) unsigned ranges_table_in_use
;
2846 /* Array of pairs of labels referenced in ranges_table. */
2847 static GTY ((length ("ranges_by_label_allocated")))
2848 dw_ranges_by_label_ref ranges_by_label
;
2850 /* Number of elements currently allocated for ranges_by_label. */
2851 static GTY(()) unsigned ranges_by_label_allocated
;
2853 /* Number of elements in ranges_by_label currently in use. */
2854 static GTY(()) unsigned ranges_by_label_in_use
;
2856 /* Size (in elements) of increments by which we may expand the
2858 #define RANGES_TABLE_INCREMENT 64
2860 /* Whether we have location lists that need outputting */
2861 static GTY(()) bool have_location_lists
;
2863 /* Unique label counter. */
2864 static GTY(()) unsigned int loclabel_num
;
2866 /* Unique label counter for point-of-call tables. */
2867 static GTY(()) unsigned int poc_label_num
;
2869 /* Record whether the function being analyzed contains inlined functions. */
2870 static int current_function_has_inlines
;
2872 /* The last file entry emitted by maybe_emit_file(). */
2873 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2875 /* Number of internal labels generated by gen_internal_sym(). */
2876 static GTY(()) int label_num
;
2878 /* Cached result of previous call to lookup_filename. */
2879 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2881 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2883 /* Instances of generic types for which we need to generate debug
2884 info that describe their generic parameters and arguments. That
2885 generation needs to happen once all types are properly laid out so
2886 we do it at the end of compilation. */
2887 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2889 /* Offset from the "steady-state frame pointer" to the frame base,
2890 within the current function. */
2891 static HOST_WIDE_INT frame_pointer_fb_offset
;
2892 static bool frame_pointer_fb_offset_valid
;
2894 static vec
<dw_die_ref
> base_types
;
2896 /* Forward declarations for functions defined in this file. */
2898 static int is_pseudo_reg (const_rtx
);
2899 static int is_tagged_type (const_tree
);
2900 static const char *dwarf_tag_name (unsigned);
2901 static const char *dwarf_attr_name (unsigned);
2902 static const char *dwarf_form_name (unsigned);
2903 static tree
decl_ultimate_origin (const_tree
);
2904 static tree
decl_class_context (tree
);
2905 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2906 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2907 static inline unsigned int AT_index (dw_attr_ref
);
2908 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2909 static inline unsigned AT_flag (dw_attr_ref
);
2910 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2911 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2912 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2913 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2914 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2915 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2916 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2917 unsigned int, unsigned char *);
2918 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2919 static hashval_t
debug_str_do_hash (const void *);
2920 static int debug_str_eq (const void *, const void *);
2921 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2922 static inline const char *AT_string (dw_attr_ref
);
2923 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2924 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2925 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2926 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2927 static inline int AT_ref_external (dw_attr_ref
);
2928 static inline void set_AT_ref_external (dw_attr_ref
, int);
2929 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2930 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2931 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2932 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2934 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2935 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2936 static void remove_addr_table_entry (addr_table_entry
*);
2937 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
2938 static inline rtx
AT_addr (dw_attr_ref
);
2939 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2940 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2941 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2942 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2943 unsigned HOST_WIDE_INT
);
2944 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2945 unsigned long, bool);
2946 static inline const char *AT_lbl (dw_attr_ref
);
2947 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2948 static const char *get_AT_low_pc (dw_die_ref
);
2949 static const char *get_AT_hi_pc (dw_die_ref
);
2950 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2951 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2952 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2953 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2954 static bool is_cxx (void);
2955 static bool is_fortran (void);
2956 static bool is_ada (void);
2957 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2958 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2959 static void add_child_die (dw_die_ref
, dw_die_ref
);
2960 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2961 static dw_die_ref
lookup_type_die (tree
);
2962 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2963 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
2964 static void equate_type_number_to_die (tree
, dw_die_ref
);
2965 static hashval_t
decl_die_table_hash (const void *);
2966 static int decl_die_table_eq (const void *, const void *);
2967 static dw_die_ref
lookup_decl_die (tree
);
2968 static hashval_t
common_block_die_table_hash (const void *);
2969 static int common_block_die_table_eq (const void *, const void *);
2970 static hashval_t
decl_loc_table_hash (const void *);
2971 static int decl_loc_table_eq (const void *, const void *);
2972 static var_loc_list
*lookup_decl_loc (const_tree
);
2973 static void equate_decl_number_to_die (tree
, dw_die_ref
);
2974 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
2975 static void print_spaces (FILE *);
2976 static void print_die (dw_die_ref
, FILE *);
2977 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
2978 static dw_die_ref
pop_compile_unit (dw_die_ref
);
2979 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
2980 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
2981 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
2982 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
2983 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
2984 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
2985 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
2986 struct md5_ctx
*, int *);
2987 struct checksum_attributes
;
2988 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
2989 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
2990 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
2991 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
2992 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
2993 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
2994 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
2995 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
2996 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
2997 static void compute_section_prefix (dw_die_ref
);
2998 static int is_type_die (dw_die_ref
);
2999 static int is_comdat_die (dw_die_ref
);
3000 static int is_symbol_die (dw_die_ref
);
3001 static void assign_symbol_names (dw_die_ref
);
3002 static void break_out_includes (dw_die_ref
);
3003 static int is_declaration_die (dw_die_ref
);
3004 static int should_move_die_to_comdat (dw_die_ref
);
3005 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3006 static dw_die_ref
clone_die (dw_die_ref
);
3007 static dw_die_ref
clone_tree (dw_die_ref
);
3008 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3009 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3010 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3011 static dw_die_ref
generate_skeleton (dw_die_ref
);
3012 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3015 static void break_out_comdat_types (dw_die_ref
);
3016 static dw_die_ref
copy_ancestor_tree (dw_die_ref
, dw_die_ref
, htab_t
);
3017 static void copy_decls_walk (dw_die_ref
, dw_die_ref
, htab_t
);
3018 static void copy_decls_for_unworthy_types (dw_die_ref
);
3020 static hashval_t
htab_cu_hash (const void *);
3021 static int htab_cu_eq (const void *, const void *);
3022 static void htab_cu_del (void *);
3023 static int check_duplicate_cu (dw_die_ref
, htab_t
, unsigned *);
3024 static void record_comdat_symbol_number (dw_die_ref
, htab_t
, unsigned);
3025 static void add_sibling_attributes (dw_die_ref
);
3026 static void build_abbrev_table (dw_die_ref
, htab_t
);
3027 static void output_location_lists (dw_die_ref
);
3028 static int constant_size (unsigned HOST_WIDE_INT
);
3029 static unsigned long size_of_die (dw_die_ref
);
3030 static void calc_die_sizes (dw_die_ref
);
3031 static void calc_base_type_die_sizes (void);
3032 static void mark_dies (dw_die_ref
);
3033 static void unmark_dies (dw_die_ref
);
3034 static void unmark_all_dies (dw_die_ref
);
3035 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3036 static unsigned long size_of_aranges (void);
3037 static enum dwarf_form
value_format (dw_attr_ref
);
3038 static void output_value_format (dw_attr_ref
);
3039 static void output_abbrev_section (void);
3040 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3041 static void output_die_symbol (dw_die_ref
);
3042 static void output_die (dw_die_ref
);
3043 static void output_compilation_unit_header (void);
3044 static void output_comp_unit (dw_die_ref
, int);
3045 static void output_comdat_type_unit (comdat_type_node
*);
3046 static const char *dwarf2_name (tree
, int);
3047 static void add_pubname (tree
, dw_die_ref
);
3048 static void add_enumerator_pubname (const char *, dw_die_ref
);
3049 static void add_pubname_string (const char *, dw_die_ref
);
3050 static void add_pubtype (tree
, dw_die_ref
);
3051 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3052 static void output_aranges (unsigned long);
3053 static unsigned int add_ranges_num (int);
3054 static unsigned int add_ranges (const_tree
);
3055 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3057 static void output_ranges (void);
3058 static dw_line_info_table
*new_line_info_table (void);
3059 static void output_line_info (bool);
3060 static void output_file_names (void);
3061 static dw_die_ref
base_type_die (tree
);
3062 static int is_base_type (tree
);
3063 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3064 static dw_die_ref
modified_type_die (tree
, int, dw_die_ref
);
3065 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3066 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3067 static int type_is_enum (const_tree
);
3068 static unsigned int dbx_reg_number (const_rtx
);
3069 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3070 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3071 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3072 enum var_init_status
);
3073 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3074 enum var_init_status
);
3075 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3076 enum var_init_status
);
3077 static int is_based_loc (const_rtx
);
3078 static int resolve_one_addr (rtx
*, void *);
3079 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3080 enum var_init_status
);
3081 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3082 enum var_init_status
);
3083 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3084 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3085 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3086 static tree
field_type (const_tree
);
3087 static unsigned int simple_type_align_in_bits (const_tree
);
3088 static unsigned int simple_decl_align_in_bits (const_tree
);
3089 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3090 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3091 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3093 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3094 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3095 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3096 static void insert_double (double_int
, unsigned char *);
3097 static void insert_float (const_rtx
, unsigned char *);
3098 static rtx
rtl_for_decl_location (tree
);
3099 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3100 enum dwarf_attribute
);
3101 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3102 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3103 static void add_name_attribute (dw_die_ref
, const char *);
3104 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3105 static void add_comp_dir_attribute (dw_die_ref
);
3106 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3107 static void add_subscript_info (dw_die_ref
, tree
, bool);
3108 static void add_byte_size_attribute (dw_die_ref
, tree
);
3109 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3110 static void add_bit_size_attribute (dw_die_ref
, tree
);
3111 static void add_prototyped_attribute (dw_die_ref
, tree
);
3112 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3113 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3114 static void add_src_coords_attributes (dw_die_ref
, tree
);
3115 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3116 static void push_decl_scope (tree
);
3117 static void pop_decl_scope (void);
3118 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3119 static inline int local_scope_p (dw_die_ref
);
3120 static inline int class_scope_p (dw_die_ref
);
3121 static inline int class_or_namespace_scope_p (dw_die_ref
);
3122 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3123 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3124 static const char *type_tag (const_tree
);
3125 static tree
member_declared_type (const_tree
);
3127 static const char *decl_start_label (tree
);
3129 static void gen_array_type_die (tree
, dw_die_ref
);
3130 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3132 static void gen_entry_point_die (tree
, dw_die_ref
);
3134 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3135 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3136 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3137 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3138 static void gen_formal_types_die (tree
, dw_die_ref
);
3139 static void gen_subprogram_die (tree
, dw_die_ref
);
3140 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3141 static void gen_const_die (tree
, dw_die_ref
);
3142 static void gen_label_die (tree
, dw_die_ref
);
3143 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3144 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3145 static void gen_field_die (tree
, dw_die_ref
);
3146 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3147 static dw_die_ref
gen_compile_unit_die (const char *);
3148 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3149 static void gen_member_die (tree
, dw_die_ref
);
3150 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3151 enum debug_info_usage
);
3152 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3153 static void gen_typedef_die (tree
, dw_die_ref
);
3154 static void gen_type_die (tree
, dw_die_ref
);
3155 static void gen_block_die (tree
, dw_die_ref
, int);
3156 static void decls_for_scope (tree
, dw_die_ref
, int);
3157 static inline int is_redundant_typedef (const_tree
);
3158 static bool is_naming_typedef_decl (const_tree
);
3159 static inline dw_die_ref
get_context_die (tree
);
3160 static void gen_namespace_die (tree
, dw_die_ref
);
3161 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3162 static dw_die_ref
force_decl_die (tree
);
3163 static dw_die_ref
force_type_die (tree
);
3164 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3165 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3166 static struct dwarf_file_data
* lookup_filename (const char *);
3167 static void retry_incomplete_types (void);
3168 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3169 static void gen_generic_params_dies (tree
);
3170 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3171 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3172 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3173 static int file_info_cmp (const void *, const void *);
3174 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3175 const char *, const char *);
3176 static void output_loc_list (dw_loc_list_ref
);
3177 static char *gen_internal_sym (const char *);
3178 static bool want_pubnames (void);
3180 static void prune_unmark_dies (dw_die_ref
);
3181 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3182 static void prune_unused_types_mark (dw_die_ref
, int);
3183 static void prune_unused_types_walk (dw_die_ref
);
3184 static void prune_unused_types_walk_attribs (dw_die_ref
);
3185 static void prune_unused_types_prune (dw_die_ref
);
3186 static void prune_unused_types (void);
3187 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3188 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3189 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3190 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3191 const char *, const char *);
3192 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3193 static void gen_remaining_tmpl_value_param_die_attribute (void);
3194 static bool generic_type_p (tree
);
3195 static void schedule_generic_params_dies_gen (tree t
);
3196 static void gen_scheduled_generic_parms_dies (void);
3198 /* enum for tracking thread-local variables whose address is really an offset
3199 relative to the TLS pointer, which will need link-time relocation, but will
3200 not need relocation by the DWARF consumer. */
3208 /* Return the operator to use for an address of a variable. For dtprel_true, we
3209 use DW_OP_const*. For regular variables, which need both link-time
3210 relocation and consumer-level relocation (e.g., to account for shared objects
3211 loaded at a random address), we use DW_OP_addr*. */
3213 static inline enum dwarf_location_atom
3214 dw_addr_op (enum dtprel_bool dtprel
)
3216 if (dtprel
== dtprel_true
)
3217 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3218 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3220 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3223 /* Return a pointer to a newly allocated address location description. If
3224 dwarf_split_debug_info is true, then record the address with the appropriate
3226 static inline dw_loc_descr_ref
3227 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3229 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3231 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3232 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3233 ref
->dtprel
= dtprel
;
3234 if (dwarf_split_debug_info
)
3235 ref
->dw_loc_oprnd1
.val_entry
3236 = add_addr_table_entry (addr
,
3237 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3239 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3244 /* Section names used to hold DWARF debugging information. */
3246 #ifndef DEBUG_INFO_SECTION
3247 #define DEBUG_INFO_SECTION ".debug_info"
3249 #ifndef DEBUG_DWO_INFO_SECTION
3250 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3252 #ifndef DEBUG_ABBREV_SECTION
3253 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3255 #ifndef DEBUG_DWO_ABBREV_SECTION
3256 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3258 #ifndef DEBUG_ARANGES_SECTION
3259 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3261 #ifndef DEBUG_ADDR_SECTION
3262 #define DEBUG_ADDR_SECTION ".debug_addr"
3264 #ifndef DEBUG_NORM_MACINFO_SECTION
3265 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3267 #ifndef DEBUG_DWO_MACINFO_SECTION
3268 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3270 #ifndef DEBUG_MACINFO_SECTION
3271 #define DEBUG_MACINFO_SECTION \
3272 (!dwarf_split_debug_info \
3273 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3275 #ifndef DEBUG_NORM_MACRO_SECTION
3276 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3278 #ifndef DEBUG_DWO_MACRO_SECTION
3279 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3281 #ifndef DEBUG_MACRO_SECTION
3282 #define DEBUG_MACRO_SECTION \
3283 (!dwarf_split_debug_info \
3284 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3286 #ifndef DEBUG_LINE_SECTION
3287 #define DEBUG_LINE_SECTION ".debug_line"
3289 #ifndef DEBUG_DWO_LINE_SECTION
3290 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3292 #ifndef DEBUG_LOC_SECTION
3293 #define DEBUG_LOC_SECTION ".debug_loc"
3295 #ifndef DEBUG_DWO_LOC_SECTION
3296 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3298 #ifndef DEBUG_PUBNAMES_SECTION
3299 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3301 #ifndef DEBUG_PUBTYPES_SECTION
3302 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3304 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3305 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3306 #ifndef DEBUG_STR_OFFSETS_SECTION
3307 #define DEBUG_STR_OFFSETS_SECTION \
3308 (!dwarf_split_debug_info \
3309 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3311 #define DEBUG_DWO_STR_SECTION ".debug_str.dwo"
3312 #define DEBUG_NORM_STR_SECTION ".debug_str"
3313 #ifndef DEBUG_STR_SECTION
3314 #define DEBUG_STR_SECTION \
3315 (!dwarf_split_debug_info ? (DEBUG_NORM_STR_SECTION) : (DEBUG_DWO_STR_SECTION))
3317 #ifndef DEBUG_RANGES_SECTION
3318 #define DEBUG_RANGES_SECTION ".debug_ranges"
3321 /* Standard ELF section names for compiled code and data. */
3322 #ifndef TEXT_SECTION_NAME
3323 #define TEXT_SECTION_NAME ".text"
3326 /* Section flags for .debug_macinfo/.debug_macro section. */
3327 #define DEBUG_MACRO_SECTION_FLAGS \
3328 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3330 /* Section flags for .debug_str section. */
3331 #define DEBUG_STR_SECTION_FLAGS \
3332 (dwarf_split_debug_info \
3333 ? SECTION_DEBUG | SECTION_EXCLUDE \
3334 : (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3335 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3338 /* Labels we insert at beginning sections we can reference instead of
3339 the section names themselves. */
3341 #ifndef TEXT_SECTION_LABEL
3342 #define TEXT_SECTION_LABEL "Ltext"
3344 #ifndef COLD_TEXT_SECTION_LABEL
3345 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3347 #ifndef DEBUG_LINE_SECTION_LABEL
3348 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3350 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3351 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3353 #ifndef DEBUG_INFO_SECTION_LABEL
3354 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3356 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3357 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3359 #ifndef DEBUG_ABBREV_SECTION_LABEL
3360 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3362 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3363 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3365 #ifndef DEBUG_ADDR_SECTION_LABEL
3366 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3368 #ifndef DEBUG_LOC_SECTION_LABEL
3369 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3371 #ifndef DEBUG_RANGES_SECTION_LABEL
3372 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3374 #ifndef DEBUG_MACINFO_SECTION_LABEL
3375 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3377 #ifndef DEBUG_MACRO_SECTION_LABEL
3378 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3380 #define SKELETON_COMP_DIE_ABBREV 1
3381 #define SKELETON_TYPE_DIE_ABBREV 2
3383 /* Definitions of defaults for formats and names of various special
3384 (artificial) labels which may be generated within this file (when the -g
3385 options is used and DWARF2_DEBUGGING_INFO is in effect.
3386 If necessary, these may be overridden from within the tm.h file, but
3387 typically, overriding these defaults is unnecessary. */
3389 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3390 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3391 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3392 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3393 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3394 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3395 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3396 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3397 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3398 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3399 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3400 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3401 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3402 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3404 #ifndef TEXT_END_LABEL
3405 #define TEXT_END_LABEL "Letext"
3407 #ifndef COLD_END_LABEL
3408 #define COLD_END_LABEL "Letext_cold"
3410 #ifndef BLOCK_BEGIN_LABEL
3411 #define BLOCK_BEGIN_LABEL "LBB"
3413 #ifndef BLOCK_END_LABEL
3414 #define BLOCK_END_LABEL "LBE"
3416 #ifndef LINE_CODE_LABEL
3417 #define LINE_CODE_LABEL "LM"
3421 /* Return the root of the DIE's built for the current compilation unit. */
3423 comp_unit_die (void)
3425 if (!single_comp_unit_die
)
3426 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3427 return single_comp_unit_die
;
3430 /* We allow a language front-end to designate a function that is to be
3431 called to "demangle" any name before it is put into a DIE. */
3433 static const char *(*demangle_name_func
) (const char *);
3436 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3438 demangle_name_func
= func
;
3441 /* Test if rtl node points to a pseudo register. */
3444 is_pseudo_reg (const_rtx rtl
)
3446 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3447 || (GET_CODE (rtl
) == SUBREG
3448 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3451 /* Return a reference to a type, with its const and volatile qualifiers
3455 type_main_variant (tree type
)
3457 type
= TYPE_MAIN_VARIANT (type
);
3459 /* ??? There really should be only one main variant among any group of
3460 variants of a given type (and all of the MAIN_VARIANT values for all
3461 members of the group should point to that one type) but sometimes the C
3462 front-end messes this up for array types, so we work around that bug
3464 if (TREE_CODE (type
) == ARRAY_TYPE
)
3465 while (type
!= TYPE_MAIN_VARIANT (type
))
3466 type
= TYPE_MAIN_VARIANT (type
);
3471 /* Return nonzero if the given type node represents a tagged type. */
3474 is_tagged_type (const_tree type
)
3476 enum tree_code code
= TREE_CODE (type
);
3478 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3479 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3482 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3485 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3487 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3490 /* Return die_offset of a DIE reference to a base type. */
3492 static unsigned long int
3493 get_base_type_offset (dw_die_ref ref
)
3495 if (ref
->die_offset
)
3496 return ref
->die_offset
;
3497 if (comp_unit_die ()->die_abbrev
)
3499 calc_base_type_die_sizes ();
3500 gcc_assert (ref
->die_offset
);
3502 return ref
->die_offset
;
3505 /* Return die_offset of a DIE reference other than base type. */
3507 static unsigned long int
3508 get_ref_die_offset (dw_die_ref ref
)
3510 gcc_assert (ref
->die_offset
);
3511 return ref
->die_offset
;
3514 /* Convert a DIE tag into its string name. */
3517 dwarf_tag_name (unsigned int tag
)
3519 const char *name
= get_DW_TAG_name (tag
);
3524 return "DW_TAG_<unknown>";
3527 /* Convert a DWARF attribute code into its string name. */
3530 dwarf_attr_name (unsigned int attr
)
3536 #if VMS_DEBUGGING_INFO
3537 case DW_AT_HP_prologue
:
3538 return "DW_AT_HP_prologue";
3540 case DW_AT_MIPS_loop_unroll_factor
:
3541 return "DW_AT_MIPS_loop_unroll_factor";
3544 #if VMS_DEBUGGING_INFO
3545 case DW_AT_HP_epilogue
:
3546 return "DW_AT_HP_epilogue";
3548 case DW_AT_MIPS_stride
:
3549 return "DW_AT_MIPS_stride";
3553 name
= get_DW_AT_name (attr
);
3558 return "DW_AT_<unknown>";
3561 /* Convert a DWARF value form code into its string name. */
3564 dwarf_form_name (unsigned int form
)
3566 const char *name
= get_DW_FORM_name (form
);
3571 return "DW_FORM_<unknown>";
3574 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3575 instance of an inlined instance of a decl which is local to an inline
3576 function, so we have to trace all of the way back through the origin chain
3577 to find out what sort of node actually served as the original seed for the
3581 decl_ultimate_origin (const_tree decl
)
3583 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3586 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3587 nodes in the function to point to themselves; ignore that if
3588 we're trying to output the abstract instance of this function. */
3589 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3592 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3593 most distant ancestor, this should never happen. */
3594 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3596 return DECL_ABSTRACT_ORIGIN (decl
);
3599 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3600 of a virtual function may refer to a base class, so we check the 'this'
3604 decl_class_context (tree decl
)
3606 tree context
= NULL_TREE
;
3608 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3609 context
= DECL_CONTEXT (decl
);
3611 context
= TYPE_MAIN_VARIANT
3612 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3614 if (context
&& !TYPE_P (context
))
3615 context
= NULL_TREE
;
3620 /* Add an attribute/value pair to a DIE. */
3623 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3625 /* Maybe this should be an assert? */
3629 vec_safe_reserve (die
->die_attr
, 1);
3630 vec_safe_push (die
->die_attr
, *attr
);
3633 static inline enum dw_val_class
3634 AT_class (dw_attr_ref a
)
3636 return a
->dw_attr_val
.val_class
;
3639 /* Return the index for any attribute that will be referenced with a
3640 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3641 are stored in dw_attr_val.v.val_str for reference counting
3644 static inline unsigned int
3645 AT_index (dw_attr_ref a
)
3647 if (AT_class (a
) == dw_val_class_str
)
3648 return a
->dw_attr_val
.v
.val_str
->index
;
3649 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3650 return a
->dw_attr_val
.val_entry
->index
;
3654 /* Add a flag value attribute to a DIE. */
3657 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3661 attr
.dw_attr
= attr_kind
;
3662 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3663 attr
.dw_attr_val
.val_entry
= NULL
;
3664 attr
.dw_attr_val
.v
.val_flag
= flag
;
3665 add_dwarf_attr (die
, &attr
);
3668 static inline unsigned
3669 AT_flag (dw_attr_ref a
)
3671 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3672 return a
->dw_attr_val
.v
.val_flag
;
3675 /* Add a signed integer attribute value to a DIE. */
3678 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3682 attr
.dw_attr
= attr_kind
;
3683 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3684 attr
.dw_attr_val
.val_entry
= NULL
;
3685 attr
.dw_attr_val
.v
.val_int
= int_val
;
3686 add_dwarf_attr (die
, &attr
);
3689 static inline HOST_WIDE_INT
3690 AT_int (dw_attr_ref a
)
3692 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3693 return a
->dw_attr_val
.v
.val_int
;
3696 /* Add an unsigned integer attribute value to a DIE. */
3699 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3700 unsigned HOST_WIDE_INT unsigned_val
)
3704 attr
.dw_attr
= attr_kind
;
3705 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3706 attr
.dw_attr_val
.val_entry
= NULL
;
3707 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3708 add_dwarf_attr (die
, &attr
);
3711 static inline unsigned HOST_WIDE_INT
3712 AT_unsigned (dw_attr_ref a
)
3714 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3715 return a
->dw_attr_val
.v
.val_unsigned
;
3718 /* Add an unsigned double integer attribute value to a DIE. */
3721 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3722 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3726 attr
.dw_attr
= attr_kind
;
3727 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3728 attr
.dw_attr_val
.val_entry
= NULL
;
3729 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3730 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3731 add_dwarf_attr (die
, &attr
);
3734 /* Add a floating point attribute value to a DIE and return it. */
3737 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3738 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3742 attr
.dw_attr
= attr_kind
;
3743 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3744 attr
.dw_attr_val
.val_entry
= NULL
;
3745 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3746 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3747 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3748 add_dwarf_attr (die
, &attr
);
3751 /* Add an 8-byte data attribute value to a DIE. */
3754 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3755 unsigned char data8
[8])
3759 attr
.dw_attr
= attr_kind
;
3760 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3761 attr
.dw_attr_val
.val_entry
= NULL
;
3762 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3763 add_dwarf_attr (die
, &attr
);
3766 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3767 dwarf_split_debug_info, address attributes in dies destined for the
3768 final executable have force_direct set to avoid using indexed
3772 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3778 lbl_id
= xstrdup (lbl_low
);
3779 attr
.dw_attr
= DW_AT_low_pc
;
3780 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3781 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3782 if (dwarf_split_debug_info
&& !force_direct
)
3783 attr
.dw_attr_val
.val_entry
3784 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3786 attr
.dw_attr_val
.val_entry
= NULL
;
3787 add_dwarf_attr (die
, &attr
);
3789 attr
.dw_attr
= DW_AT_high_pc
;
3790 if (dwarf_version
< 4)
3791 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3793 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3794 lbl_id
= xstrdup (lbl_high
);
3795 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3796 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3797 && dwarf_split_debug_info
&& !force_direct
)
3798 attr
.dw_attr_val
.val_entry
3799 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3801 attr
.dw_attr_val
.val_entry
= NULL
;
3802 add_dwarf_attr (die
, &attr
);
3805 /* Hash and equality functions for debug_str_hash. */
3808 debug_str_do_hash (const void *x
)
3810 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3814 debug_str_eq (const void *x1
, const void *x2
)
3816 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3817 (const char *)x2
) == 0;
3820 /* Add STR to the indirect string hash table. */
3822 static struct indirect_string_node
*
3823 find_AT_string (const char *str
)
3825 struct indirect_string_node
*node
;
3828 if (! debug_str_hash
)
3829 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3830 debug_str_eq
, NULL
);
3832 slot
= htab_find_slot_with_hash (debug_str_hash
, str
,
3833 htab_hash_string (str
), INSERT
);
3836 node
= ggc_alloc_cleared_indirect_string_node ();
3837 node
->str
= ggc_strdup (str
);
3841 node
= (struct indirect_string_node
*) *slot
;
3847 /* Add a string attribute value to a DIE. */
3850 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3853 struct indirect_string_node
*node
;
3855 node
= find_AT_string (str
);
3857 attr
.dw_attr
= attr_kind
;
3858 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3859 attr
.dw_attr_val
.val_entry
= NULL
;
3860 attr
.dw_attr_val
.v
.val_str
= node
;
3861 add_dwarf_attr (die
, &attr
);
3864 static inline const char *
3865 AT_string (dw_attr_ref a
)
3867 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3868 return a
->dw_attr_val
.v
.val_str
->str
;
3871 /* Call this function directly to bypass AT_string_form's logic to put
3872 the string inline in the die. */
3875 set_indirect_string (struct indirect_string_node
*node
)
3878 /* Already indirect is a no op. */
3879 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3881 gcc_assert (node
->label
);
3884 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3885 ++dw2_string_counter
;
3886 node
->label
= xstrdup (label
);
3888 if (!dwarf_split_debug_info
)
3890 node
->form
= DW_FORM_strp
;
3891 node
->index
= NOT_INDEXED
;
3895 node
->form
= DW_FORM_GNU_str_index
;
3896 node
->index
= NO_INDEX_ASSIGNED
;
3900 /* Find out whether a string should be output inline in DIE
3901 or out-of-line in .debug_str section. */
3903 static enum dwarf_form
3904 find_string_form (struct indirect_string_node
*node
)
3911 len
= strlen (node
->str
) + 1;
3913 /* If the string is shorter or equal to the size of the reference, it is
3914 always better to put it inline. */
3915 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3916 return node
->form
= DW_FORM_string
;
3918 /* If we cannot expect the linker to merge strings in .debug_str
3919 section, only put it into .debug_str if it is worth even in this
3921 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3922 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3923 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3924 return node
->form
= DW_FORM_string
;
3926 set_indirect_string (node
);
3931 /* Find out whether the string referenced from the attribute should be
3932 output inline in DIE or out-of-line in .debug_str section. */
3934 static enum dwarf_form
3935 AT_string_form (dw_attr_ref a
)
3937 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3938 return find_string_form (a
->dw_attr_val
.v
.val_str
);
3941 /* Add a DIE reference attribute value to a DIE. */
3944 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3948 #ifdef ENABLE_CHECKING
3949 gcc_assert (targ_die
!= NULL
);
3951 /* With LTO we can end up trying to reference something we didn't create
3952 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3953 if (targ_die
== NULL
)
3957 attr
.dw_attr
= attr_kind
;
3958 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
3959 attr
.dw_attr_val
.val_entry
= NULL
;
3960 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
3961 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
3962 add_dwarf_attr (die
, &attr
);
3965 /* Change DIE reference REF to point to NEW_DIE instead. */
3968 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
3970 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
3971 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
3972 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
3975 /* Add an AT_specification attribute to a DIE, and also make the back
3976 pointer from the specification to the definition. */
3979 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
3981 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
3982 gcc_assert (!targ_die
->die_definition
);
3983 targ_die
->die_definition
= die
;
3986 static inline dw_die_ref
3987 AT_ref (dw_attr_ref a
)
3989 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
3990 return a
->dw_attr_val
.v
.val_die_ref
.die
;
3994 AT_ref_external (dw_attr_ref a
)
3996 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
3997 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4003 set_AT_ref_external (dw_attr_ref a
, int i
)
4005 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4006 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4009 /* Add an FDE reference attribute value to a DIE. */
4012 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4016 attr
.dw_attr
= attr_kind
;
4017 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4018 attr
.dw_attr_val
.val_entry
= NULL
;
4019 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4020 add_dwarf_attr (die
, &attr
);
4023 /* Add a location description attribute value to a DIE. */
4026 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4030 attr
.dw_attr
= attr_kind
;
4031 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4032 attr
.dw_attr_val
.val_entry
= NULL
;
4033 attr
.dw_attr_val
.v
.val_loc
= loc
;
4034 add_dwarf_attr (die
, &attr
);
4037 static inline dw_loc_descr_ref
4038 AT_loc (dw_attr_ref a
)
4040 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4041 return a
->dw_attr_val
.v
.val_loc
;
4045 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4049 attr
.dw_attr
= attr_kind
;
4050 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4051 attr
.dw_attr_val
.val_entry
= NULL
;
4052 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4053 add_dwarf_attr (die
, &attr
);
4054 have_location_lists
= true;
4057 static inline dw_loc_list_ref
4058 AT_loc_list (dw_attr_ref a
)
4060 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4061 return a
->dw_attr_val
.v
.val_loc_list
;
4064 static inline dw_loc_list_ref
*
4065 AT_loc_list_ptr (dw_attr_ref a
)
4067 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4068 return &a
->dw_attr_val
.v
.val_loc_list
;
4071 /* Table of entries into the .debug_addr section. */
4073 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4075 /* Hash an address_table_entry. */
4078 addr_table_entry_do_hash (const void *x
)
4080 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4084 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4085 case ate_kind_rtx_dtprel
:
4086 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4087 case ate_kind_label
:
4088 return htab_hash_string (a
->addr
.label
);
4094 /* Determine equality for two address_table_entries. */
4097 addr_table_entry_eq (const void *x1
, const void *x2
)
4099 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4100 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4102 if (a1
->kind
!= a2
->kind
)
4107 case ate_kind_rtx_dtprel
:
4108 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4109 case ate_kind_label
:
4110 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4116 /* Initialize an addr_table_entry. */
4119 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4125 case ate_kind_rtx_dtprel
:
4126 e
->addr
.rtl
= (rtx
) addr
;
4128 case ate_kind_label
:
4129 e
->addr
.label
= (char *) addr
;
4133 e
->index
= NO_INDEX_ASSIGNED
;
4136 /* Add attr to the address table entry to the table. Defer setting an
4137 index until output time. */
4139 static addr_table_entry
*
4140 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4142 addr_table_entry
*node
;
4143 addr_table_entry finder
;
4146 gcc_assert (dwarf_split_debug_info
);
4147 if (! addr_index_table
)
4148 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4149 addr_table_entry_eq
, NULL
);
4150 init_addr_table_entry (&finder
, kind
, addr
);
4151 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4153 if (*slot
== HTAB_EMPTY_ENTRY
)
4155 node
= ggc_alloc_cleared_addr_table_entry ();
4156 init_addr_table_entry (node
, kind
, addr
);
4160 node
= (addr_table_entry
*) *slot
;
4166 /* Remove an entry from the addr table by decrementing its refcount.
4167 Strictly, decrementing the refcount would be enough, but the
4168 assertion that the entry is actually in the table has found
4172 remove_addr_table_entry (addr_table_entry
*entry
)
4174 addr_table_entry
*node
;
4176 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4177 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4178 /* After an index is assigned, the table is frozen. */
4179 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4183 /* Given a location list, remove all addresses it refers to from the
4187 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4189 for (; descr
; descr
= descr
->dw_loc_next
)
4190 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4192 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4193 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4197 /* A helper function for dwarf2out_finish called through
4198 htab_traverse. Assign an addr_table_entry its index. All entries
4199 must be collected into the table when this function is called,
4200 because the indexing code relies on htab_traverse to traverse nodes
4201 in the same order for each run. */
4204 index_addr_table_entry (void **h
, void *v
)
4206 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4207 unsigned int *index
= (unsigned int *) v
;
4209 /* Don't index unreferenced nodes. */
4210 if (node
->refcount
== 0)
4213 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
4214 node
->index
= *index
;
4220 /* Add an address constant attribute value to a DIE. When using
4221 dwarf_split_debug_info, address attributes in dies destined for the
4222 final executable should be direct references--setting the parameter
4223 force_direct ensures this behavior. */
4226 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4231 attr
.dw_attr
= attr_kind
;
4232 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4233 attr
.dw_attr_val
.v
.val_addr
= addr
;
4234 if (dwarf_split_debug_info
&& !force_direct
)
4235 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4237 attr
.dw_attr_val
.val_entry
= NULL
;
4238 add_dwarf_attr (die
, &attr
);
4241 /* Get the RTX from to an address DIE attribute. */
4244 AT_addr (dw_attr_ref a
)
4246 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4247 return a
->dw_attr_val
.v
.val_addr
;
4250 /* Add a file attribute value to a DIE. */
4253 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4254 struct dwarf_file_data
*fd
)
4258 attr
.dw_attr
= attr_kind
;
4259 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4260 attr
.dw_attr_val
.val_entry
= NULL
;
4261 attr
.dw_attr_val
.v
.val_file
= fd
;
4262 add_dwarf_attr (die
, &attr
);
4265 /* Get the dwarf_file_data from a file DIE attribute. */
4267 static inline struct dwarf_file_data
*
4268 AT_file (dw_attr_ref a
)
4270 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4271 return a
->dw_attr_val
.v
.val_file
;
4274 /* Add a vms delta attribute value to a DIE. */
4277 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4278 const char *lbl1
, const char *lbl2
)
4282 attr
.dw_attr
= attr_kind
;
4283 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4284 attr
.dw_attr_val
.val_entry
= NULL
;
4285 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4286 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4287 add_dwarf_attr (die
, &attr
);
4290 /* Add a label identifier attribute value to a DIE. */
4293 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4298 attr
.dw_attr
= attr_kind
;
4299 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4300 attr
.dw_attr_val
.val_entry
= NULL
;
4301 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4302 if (dwarf_split_debug_info
)
4303 attr
.dw_attr_val
.val_entry
4304 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4306 add_dwarf_attr (die
, &attr
);
4309 /* Add a section offset attribute value to a DIE, an offset into the
4310 debug_line section. */
4313 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4318 attr
.dw_attr
= attr_kind
;
4319 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4320 attr
.dw_attr_val
.val_entry
= NULL
;
4321 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4322 add_dwarf_attr (die
, &attr
);
4325 /* Add a section offset attribute value to a DIE, an offset into the
4326 debug_macinfo section. */
4329 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4334 attr
.dw_attr
= attr_kind
;
4335 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4336 attr
.dw_attr_val
.val_entry
= NULL
;
4337 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4338 add_dwarf_attr (die
, &attr
);
4341 /* Add an offset attribute value to a DIE. */
4344 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4345 unsigned HOST_WIDE_INT offset
)
4349 attr
.dw_attr
= attr_kind
;
4350 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4351 attr
.dw_attr_val
.val_entry
= NULL
;
4352 attr
.dw_attr_val
.v
.val_offset
= offset
;
4353 add_dwarf_attr (die
, &attr
);
4356 /* Add a range_list attribute value to a DIE. When using
4357 dwarf_split_debug_info, address attributes in dies destined for the
4358 final executable should be direct references--setting the parameter
4359 force_direct ensures this behavior. */
4361 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4362 #define RELOCATED_OFFSET (NULL)
4365 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4366 long unsigned int offset
, bool force_direct
)
4370 attr
.dw_attr
= attr_kind
;
4371 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4372 /* For the range_list attribute, use val_entry to store whether the
4373 offset should follow split-debug-info or normal semantics. This
4374 value is read in output_range_list_offset. */
4375 if (dwarf_split_debug_info
&& !force_direct
)
4376 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4378 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4379 attr
.dw_attr_val
.v
.val_offset
= offset
;
4380 add_dwarf_attr (die
, &attr
);
4383 /* Return the start label of a delta attribute. */
4385 static inline const char *
4386 AT_vms_delta1 (dw_attr_ref a
)
4388 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4389 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4392 /* Return the end label of a delta attribute. */
4394 static inline const char *
4395 AT_vms_delta2 (dw_attr_ref a
)
4397 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4398 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4401 static inline const char *
4402 AT_lbl (dw_attr_ref a
)
4404 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4405 || AT_class (a
) == dw_val_class_lineptr
4406 || AT_class (a
) == dw_val_class_macptr
4407 || AT_class (a
) == dw_val_class_high_pc
));
4408 return a
->dw_attr_val
.v
.val_lbl_id
;
4411 /* Get the attribute of type attr_kind. */
4414 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4418 dw_die_ref spec
= NULL
;
4423 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4424 if (a
->dw_attr
== attr_kind
)
4426 else if (a
->dw_attr
== DW_AT_specification
4427 || a
->dw_attr
== DW_AT_abstract_origin
)
4431 return get_AT (spec
, attr_kind
);
4436 /* Returns the parent of the declaration of DIE. */
4439 get_die_parent (dw_die_ref die
)
4446 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4447 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4450 return die
->die_parent
;
4453 /* Return the "low pc" attribute value, typically associated with a subprogram
4454 DIE. Return null if the "low pc" attribute is either not present, or if it
4455 cannot be represented as an assembler label identifier. */
4457 static inline const char *
4458 get_AT_low_pc (dw_die_ref die
)
4460 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4462 return a
? AT_lbl (a
) : NULL
;
4465 /* Return the "high pc" attribute value, typically associated with a subprogram
4466 DIE. Return null if the "high pc" attribute is either not present, or if it
4467 cannot be represented as an assembler label identifier. */
4469 static inline const char *
4470 get_AT_hi_pc (dw_die_ref die
)
4472 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4474 return a
? AT_lbl (a
) : NULL
;
4477 /* Return the value of the string attribute designated by ATTR_KIND, or
4478 NULL if it is not present. */
4480 static inline const char *
4481 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4483 dw_attr_ref a
= get_AT (die
, attr_kind
);
4485 return a
? AT_string (a
) : NULL
;
4488 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4489 if it is not present. */
4492 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4494 dw_attr_ref a
= get_AT (die
, attr_kind
);
4496 return a
? AT_flag (a
) : 0;
4499 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4500 if it is not present. */
4502 static inline unsigned
4503 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4505 dw_attr_ref a
= get_AT (die
, attr_kind
);
4507 return a
? AT_unsigned (a
) : 0;
4510 static inline dw_die_ref
4511 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4513 dw_attr_ref a
= get_AT (die
, attr_kind
);
4515 return a
? AT_ref (a
) : NULL
;
4518 static inline struct dwarf_file_data
*
4519 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4521 dw_attr_ref a
= get_AT (die
, attr_kind
);
4523 return a
? AT_file (a
) : NULL
;
4526 /* Return TRUE if the language is C++. */
4531 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4533 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4536 /* Return TRUE if the language is Fortran. */
4541 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4543 return (lang
== DW_LANG_Fortran77
4544 || lang
== DW_LANG_Fortran90
4545 || lang
== DW_LANG_Fortran95
);
4548 /* Return TRUE if the language is Ada. */
4553 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4555 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4558 /* Remove the specified attribute if present. */
4561 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4569 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4570 if (a
->dw_attr
== attr_kind
)
4572 if (AT_class (a
) == dw_val_class_str
)
4573 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4574 a
->dw_attr_val
.v
.val_str
->refcount
--;
4576 /* vec::ordered_remove should help reduce the number of abbrevs
4578 die
->die_attr
->ordered_remove (ix
);
4583 /* Remove CHILD from its parent. PREV must have the property that
4584 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4587 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4589 gcc_assert (child
->die_parent
== prev
->die_parent
);
4590 gcc_assert (prev
->die_sib
== child
);
4593 gcc_assert (child
->die_parent
->die_child
== child
);
4597 prev
->die_sib
= child
->die_sib
;
4598 if (child
->die_parent
->die_child
== child
)
4599 child
->die_parent
->die_child
= prev
;
4602 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4603 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4606 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4608 dw_die_ref parent
= old_child
->die_parent
;
4610 gcc_assert (parent
== prev
->die_parent
);
4611 gcc_assert (prev
->die_sib
== old_child
);
4613 new_child
->die_parent
= parent
;
4614 if (prev
== old_child
)
4616 gcc_assert (parent
->die_child
== old_child
);
4617 new_child
->die_sib
= new_child
;
4621 prev
->die_sib
= new_child
;
4622 new_child
->die_sib
= old_child
->die_sib
;
4624 if (old_child
->die_parent
->die_child
== old_child
)
4625 old_child
->die_parent
->die_child
= new_child
;
4628 /* Move all children from OLD_PARENT to NEW_PARENT. */
4631 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4634 new_parent
->die_child
= old_parent
->die_child
;
4635 old_parent
->die_child
= NULL
;
4636 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4639 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4643 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4649 dw_die_ref prev
= c
;
4651 while (c
->die_tag
== tag
)
4653 remove_child_with_prev (c
, prev
);
4654 /* Might have removed every child. */
4655 if (c
== c
->die_sib
)
4659 } while (c
!= die
->die_child
);
4662 /* Add a CHILD_DIE as the last child of DIE. */
4665 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4667 /* FIXME this should probably be an assert. */
4668 if (! die
|| ! child_die
)
4670 gcc_assert (die
!= child_die
);
4672 child_die
->die_parent
= die
;
4675 child_die
->die_sib
= die
->die_child
->die_sib
;
4676 die
->die_child
->die_sib
= child_die
;
4679 child_die
->die_sib
= child_die
;
4680 die
->die_child
= child_die
;
4683 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4684 is the specification, to the end of PARENT's list of children.
4685 This is done by removing and re-adding it. */
4688 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4692 /* We want the declaration DIE from inside the class, not the
4693 specification DIE at toplevel. */
4694 if (child
->die_parent
!= parent
)
4696 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4702 gcc_assert (child
->die_parent
== parent
4703 || (child
->die_parent
4704 == get_AT_ref (parent
, DW_AT_specification
)));
4706 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4707 if (p
->die_sib
== child
)
4709 remove_child_with_prev (child
, p
);
4713 add_child_die (parent
, child
);
4716 /* Return a pointer to a newly created DIE node. */
4718 static inline dw_die_ref
4719 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4721 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4723 die
->die_tag
= tag_value
;
4725 if (parent_die
!= NULL
)
4726 add_child_die (parent_die
, die
);
4729 limbo_die_node
*limbo_node
;
4731 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4732 limbo_node
->die
= die
;
4733 limbo_node
->created_for
= t
;
4734 limbo_node
->next
= limbo_die_list
;
4735 limbo_die_list
= limbo_node
;
4741 /* Return the DIE associated with the given type specifier. */
4743 static inline dw_die_ref
4744 lookup_type_die (tree type
)
4746 return TYPE_SYMTAB_DIE (type
);
4749 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4750 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4751 anonymous type instead the one of the naming typedef. */
4753 static inline dw_die_ref
4754 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4757 && TREE_CODE (type
) == RECORD_TYPE
4759 && type_die
->die_tag
== DW_TAG_typedef
4760 && is_naming_typedef_decl (TYPE_NAME (type
)))
4761 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4765 /* Like lookup_type_die, but if type is an anonymous type named by a
4766 typedef[1], return the DIE of the anonymous type instead the one of
4767 the naming typedef. This is because in gen_typedef_die, we did
4768 equate the anonymous struct named by the typedef with the DIE of
4769 the naming typedef. So by default, lookup_type_die on an anonymous
4770 struct yields the DIE of the naming typedef.
4772 [1]: Read the comment of is_naming_typedef_decl to learn about what
4773 a naming typedef is. */
4775 static inline dw_die_ref
4776 lookup_type_die_strip_naming_typedef (tree type
)
4778 dw_die_ref die
= lookup_type_die (type
);
4779 return strip_naming_typedef (type
, die
);
4782 /* Equate a DIE to a given type specifier. */
4785 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4787 TYPE_SYMTAB_DIE (type
) = type_die
;
4790 /* Returns a hash value for X (which really is a die_struct). */
4793 decl_die_table_hash (const void *x
)
4795 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4798 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4801 decl_die_table_eq (const void *x
, const void *y
)
4803 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4806 /* Return the DIE associated with a given declaration. */
4808 static inline dw_die_ref
4809 lookup_decl_die (tree decl
)
4811 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4814 /* Returns a hash value for X (which really is a var_loc_list). */
4817 decl_loc_table_hash (const void *x
)
4819 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4822 /* Return nonzero if decl_id of var_loc_list X is the same as
4826 decl_loc_table_eq (const void *x
, const void *y
)
4828 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4831 /* Return the var_loc list associated with a given declaration. */
4833 static inline var_loc_list
*
4834 lookup_decl_loc (const_tree decl
)
4836 if (!decl_loc_table
)
4838 return (var_loc_list
*)
4839 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4842 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4845 cached_dw_loc_list_table_hash (const void *x
)
4847 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4850 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4854 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4856 return (((const cached_dw_loc_list
*) x
)->decl_id
4857 == DECL_UID ((const_tree
) y
));
4860 /* Equate a DIE to a particular declaration. */
4863 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4865 unsigned int decl_id
= DECL_UID (decl
);
4868 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4870 decl_die
->decl_id
= decl_id
;
4873 /* Return how many bits covers PIECE EXPR_LIST. */
4876 decl_piece_bitsize (rtx piece
)
4878 int ret
= (int) GET_MODE (piece
);
4881 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4882 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4883 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4886 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4889 decl_piece_varloc_ptr (rtx piece
)
4891 if ((int) GET_MODE (piece
))
4892 return &XEXP (piece
, 0);
4894 return &XEXP (XEXP (piece
, 0), 1);
4897 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4898 Next is the chain of following piece nodes. */
4901 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4903 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4904 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4906 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4911 /* Return rtx that should be stored into loc field for
4912 LOC_NOTE and BITPOS/BITSIZE. */
4915 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4916 HOST_WIDE_INT bitsize
)
4920 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4922 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4927 /* This function either modifies location piece list *DEST in
4928 place (if SRC and INNER is NULL), or copies location piece list
4929 *SRC to *DEST while modifying it. Location BITPOS is modified
4930 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4931 not copied and if needed some padding around it is added.
4932 When modifying in place, DEST should point to EXPR_LIST where
4933 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4934 to the start of the whole list and INNER points to the EXPR_LIST
4935 where earlier pieces cover PIECE_BITPOS bits. */
4938 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4939 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4940 HOST_WIDE_INT bitsize
, rtx loc_note
)
4943 bool copy
= inner
!= NULL
;
4947 /* First copy all nodes preceding the current bitpos. */
4948 while (src
!= inner
)
4950 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4951 decl_piece_bitsize (*src
), NULL_RTX
);
4952 dest
= &XEXP (*dest
, 1);
4953 src
= &XEXP (*src
, 1);
4956 /* Add padding if needed. */
4957 if (bitpos
!= piece_bitpos
)
4959 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
4960 copy
? NULL_RTX
: *dest
);
4961 dest
= &XEXP (*dest
, 1);
4963 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
4966 /* A piece with correct bitpos and bitsize already exist,
4967 just update the location for it and return. */
4968 *decl_piece_varloc_ptr (*dest
) = loc_note
;
4971 /* Add the piece that changed. */
4972 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
4973 dest
= &XEXP (*dest
, 1);
4974 /* Skip over pieces that overlap it. */
4975 diff
= bitpos
- piece_bitpos
+ bitsize
;
4978 while (diff
> 0 && *src
)
4981 diff
-= decl_piece_bitsize (piece
);
4983 src
= &XEXP (piece
, 1);
4986 *src
= XEXP (piece
, 1);
4987 free_EXPR_LIST_node (piece
);
4990 /* Add padding if needed. */
4991 if (diff
< 0 && *src
)
4995 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
4996 dest
= &XEXP (*dest
, 1);
5000 /* Finally copy all nodes following it. */
5003 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5004 decl_piece_bitsize (*src
), NULL_RTX
);
5005 dest
= &XEXP (*dest
, 1);
5006 src
= &XEXP (*src
, 1);
5010 /* Add a variable location node to the linked list for DECL. */
5012 static struct var_loc_node
*
5013 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5015 unsigned int decl_id
;
5018 struct var_loc_node
*loc
= NULL
;
5019 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5021 if (DECL_DEBUG_EXPR_IS_FROM (decl
))
5023 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5025 && (handled_component_p (realdecl
)
5026 || (TREE_CODE (realdecl
) == MEM_REF
5027 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
)))
5029 HOST_WIDE_INT maxsize
;
5032 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5033 if (!DECL_P (innerdecl
)
5034 || DECL_IGNORED_P (innerdecl
)
5035 || TREE_STATIC (innerdecl
)
5037 || bitpos
+ bitsize
> 256
5038 || bitsize
!= maxsize
)
5044 decl_id
= DECL_UID (decl
);
5045 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5048 temp
= ggc_alloc_cleared_var_loc_list ();
5049 temp
->decl_id
= decl_id
;
5053 temp
= (var_loc_list
*) *slot
;
5055 /* For PARM_DECLs try to keep around the original incoming value,
5056 even if that means we'll emit a zero-range .debug_loc entry. */
5058 && temp
->first
== temp
->last
5059 && TREE_CODE (decl
) == PARM_DECL
5060 && GET_CODE (temp
->first
->loc
) == NOTE
5061 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5062 && DECL_INCOMING_RTL (decl
)
5063 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5064 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5065 == GET_CODE (DECL_INCOMING_RTL (decl
))
5066 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5068 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5069 NOTE_VAR_LOCATION_LOC (loc_note
))
5070 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5071 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5073 loc
= ggc_alloc_cleared_var_loc_node ();
5074 temp
->first
->next
= loc
;
5076 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5078 else if (temp
->last
)
5080 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5081 rtx
*piece_loc
= NULL
, last_loc_note
;
5082 int piece_bitpos
= 0;
5086 gcc_assert (last
->next
== NULL
);
5088 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5090 piece_loc
= &last
->loc
;
5093 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5094 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5096 piece_bitpos
+= cur_bitsize
;
5097 piece_loc
= &XEXP (*piece_loc
, 1);
5101 /* TEMP->LAST here is either pointer to the last but one or
5102 last element in the chained list, LAST is pointer to the
5104 if (label
&& strcmp (last
->label
, label
) == 0)
5106 /* For SRA optimized variables if there weren't any real
5107 insns since last note, just modify the last node. */
5108 if (piece_loc
!= NULL
)
5110 adjust_piece_list (piece_loc
, NULL
, NULL
,
5111 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5114 /* If the last note doesn't cover any instructions, remove it. */
5115 if (temp
->last
!= last
)
5117 temp
->last
->next
= NULL
;
5120 gcc_assert (strcmp (last
->label
, label
) != 0);
5124 gcc_assert (temp
->first
== temp
->last
5125 || (temp
->first
->next
== temp
->last
5126 && TREE_CODE (decl
) == PARM_DECL
));
5127 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5128 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5132 if (bitsize
== -1 && NOTE_P (last
->loc
))
5133 last_loc_note
= last
->loc
;
5134 else if (piece_loc
!= NULL
5135 && *piece_loc
!= NULL_RTX
5136 && piece_bitpos
== bitpos
5137 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5138 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5140 last_loc_note
= NULL_RTX
;
5141 /* If the current location is the same as the end of the list,
5142 and either both or neither of the locations is uninitialized,
5143 we have nothing to do. */
5144 if (last_loc_note
== NULL_RTX
5145 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5146 NOTE_VAR_LOCATION_LOC (loc_note
)))
5147 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5148 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5149 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5150 == VAR_INIT_STATUS_UNINITIALIZED
)
5151 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5152 == VAR_INIT_STATUS_UNINITIALIZED
))))
5154 /* Add LOC to the end of list and update LAST. If the last
5155 element of the list has been removed above, reuse its
5156 memory for the new node, otherwise allocate a new one. */
5160 memset (loc
, '\0', sizeof (*loc
));
5163 loc
= ggc_alloc_cleared_var_loc_node ();
5164 if (bitsize
== -1 || piece_loc
== NULL
)
5165 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5167 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5168 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5170 /* Ensure TEMP->LAST will point either to the new last but one
5171 element of the chain, or to the last element in it. */
5172 if (last
!= temp
->last
)
5180 loc
= ggc_alloc_cleared_var_loc_node ();
5183 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5188 /* Keep track of the number of spaces used to indent the
5189 output of the debugging routines that print the structure of
5190 the DIE internal representation. */
5191 static int print_indent
;
5193 /* Indent the line the number of spaces given by print_indent. */
5196 print_spaces (FILE *outfile
)
5198 fprintf (outfile
, "%*s", print_indent
, "");
5201 /* Print a type signature in hex. */
5204 print_signature (FILE *outfile
, char *sig
)
5208 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5209 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5212 /* Print the information associated with a given DIE, and its children.
5213 This routine is a debugging aid only. */
5216 print_die (dw_die_ref die
, FILE *outfile
)
5222 print_spaces (outfile
);
5223 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5224 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5226 print_spaces (outfile
);
5227 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5228 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5229 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5231 if (die
->comdat_type_p
)
5233 print_spaces (outfile
);
5234 fprintf (outfile
, " signature: ");
5235 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5236 fprintf (outfile
, "\n");
5239 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5241 print_spaces (outfile
);
5242 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5244 switch (AT_class (a
))
5246 case dw_val_class_addr
:
5247 fprintf (outfile
, "address");
5249 case dw_val_class_offset
:
5250 fprintf (outfile
, "offset");
5252 case dw_val_class_loc
:
5253 fprintf (outfile
, "location descriptor");
5255 case dw_val_class_loc_list
:
5256 fprintf (outfile
, "location list -> label:%s",
5257 AT_loc_list (a
)->ll_symbol
);
5259 case dw_val_class_range_list
:
5260 fprintf (outfile
, "range list");
5262 case dw_val_class_const
:
5263 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5265 case dw_val_class_unsigned_const
:
5266 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5268 case dw_val_class_const_double
:
5269 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5270 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5271 a
->dw_attr_val
.v
.val_double
.high
,
5272 a
->dw_attr_val
.v
.val_double
.low
);
5274 case dw_val_class_vec
:
5275 fprintf (outfile
, "floating-point or vector constant");
5277 case dw_val_class_flag
:
5278 fprintf (outfile
, "%u", AT_flag (a
));
5280 case dw_val_class_die_ref
:
5281 if (AT_ref (a
) != NULL
)
5283 if (AT_ref (a
)->comdat_type_p
)
5285 fprintf (outfile
, "die -> signature: ");
5286 print_signature (outfile
,
5287 AT_ref (a
)->die_id
.die_type_node
->signature
);
5289 else if (AT_ref (a
)->die_id
.die_symbol
)
5290 fprintf (outfile
, "die -> label: %s",
5291 AT_ref (a
)->die_id
.die_symbol
);
5293 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5294 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5297 fprintf (outfile
, "die -> <null>");
5299 case dw_val_class_vms_delta
:
5300 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5301 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5303 case dw_val_class_lbl_id
:
5304 case dw_val_class_lineptr
:
5305 case dw_val_class_macptr
:
5306 case dw_val_class_high_pc
:
5307 fprintf (outfile
, "label: %s", AT_lbl (a
));
5309 case dw_val_class_str
:
5310 if (AT_string (a
) != NULL
)
5311 fprintf (outfile
, "\"%s\"", AT_string (a
));
5313 fprintf (outfile
, "<null>");
5315 case dw_val_class_file
:
5316 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5317 AT_file (a
)->emitted_number
);
5319 case dw_val_class_data8
:
5323 for (i
= 0; i
< 8; i
++)
5324 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5331 fprintf (outfile
, "\n");
5334 if (die
->die_child
!= NULL
)
5337 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5340 if (print_indent
== 0)
5341 fprintf (outfile
, "\n");
5344 /* Print the information collected for a given DIE. */
5347 debug_dwarf_die (dw_die_ref die
)
5349 print_die (die
, stderr
);
5352 /* Print all DWARF information collected for the compilation unit.
5353 This routine is a debugging aid only. */
5359 print_die (comp_unit_die (), stderr
);
5362 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5363 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5364 DIE that marks the start of the DIEs for this include file. */
5367 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5369 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5370 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5372 new_unit
->die_sib
= old_unit
;
5376 /* Close an include-file CU and reopen the enclosing one. */
5379 pop_compile_unit (dw_die_ref old_unit
)
5381 dw_die_ref new_unit
= old_unit
->die_sib
;
5383 old_unit
->die_sib
= NULL
;
5387 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5388 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5390 /* Calculate the checksum of a location expression. */
5393 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5397 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5399 CHECKSUM (loc
->dw_loc_oprnd1
);
5400 CHECKSUM (loc
->dw_loc_oprnd2
);
5403 /* Calculate the checksum of an attribute. */
5406 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5408 dw_loc_descr_ref loc
;
5411 CHECKSUM (at
->dw_attr
);
5413 /* We don't care that this was compiled with a different compiler
5414 snapshot; if the output is the same, that's what matters. */
5415 if (at
->dw_attr
== DW_AT_producer
)
5418 switch (AT_class (at
))
5420 case dw_val_class_const
:
5421 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5423 case dw_val_class_unsigned_const
:
5424 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5426 case dw_val_class_const_double
:
5427 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5429 case dw_val_class_vec
:
5430 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5432 case dw_val_class_flag
:
5433 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5435 case dw_val_class_str
:
5436 CHECKSUM_STRING (AT_string (at
));
5439 case dw_val_class_addr
:
5441 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5442 CHECKSUM_STRING (XSTR (r
, 0));
5445 case dw_val_class_offset
:
5446 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5449 case dw_val_class_loc
:
5450 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5451 loc_checksum (loc
, ctx
);
5454 case dw_val_class_die_ref
:
5455 die_checksum (AT_ref (at
), ctx
, mark
);
5458 case dw_val_class_fde_ref
:
5459 case dw_val_class_vms_delta
:
5460 case dw_val_class_lbl_id
:
5461 case dw_val_class_lineptr
:
5462 case dw_val_class_macptr
:
5463 case dw_val_class_high_pc
:
5466 case dw_val_class_file
:
5467 CHECKSUM_STRING (AT_file (at
)->filename
);
5470 case dw_val_class_data8
:
5471 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5479 /* Calculate the checksum of a DIE. */
5482 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5488 /* To avoid infinite recursion. */
5491 CHECKSUM (die
->die_mark
);
5494 die
->die_mark
= ++(*mark
);
5496 CHECKSUM (die
->die_tag
);
5498 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5499 attr_checksum (a
, ctx
, mark
);
5501 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5505 #undef CHECKSUM_STRING
5507 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5508 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5509 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5510 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5511 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5512 #define CHECKSUM_ATTR(FOO) \
5513 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5515 /* Calculate the checksum of a number in signed LEB128 format. */
5518 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5525 byte
= (value
& 0x7f);
5527 more
= !((value
== 0 && (byte
& 0x40) == 0)
5528 || (value
== -1 && (byte
& 0x40) != 0));
5537 /* Calculate the checksum of a number in unsigned LEB128 format. */
5540 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5544 unsigned char byte
= (value
& 0x7f);
5547 /* More bytes to follow. */
5555 /* Checksum the context of the DIE. This adds the names of any
5556 surrounding namespaces or structures to the checksum. */
5559 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5563 int tag
= die
->die_tag
;
5565 if (tag
!= DW_TAG_namespace
5566 && tag
!= DW_TAG_structure_type
5567 && tag
!= DW_TAG_class_type
)
5570 name
= get_AT_string (die
, DW_AT_name
);
5572 spec
= get_AT_ref (die
, DW_AT_specification
);
5576 if (die
->die_parent
!= NULL
)
5577 checksum_die_context (die
->die_parent
, ctx
);
5579 CHECKSUM_ULEB128 ('C');
5580 CHECKSUM_ULEB128 (tag
);
5582 CHECKSUM_STRING (name
);
5585 /* Calculate the checksum of a location expression. */
5588 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5590 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5591 were emitted as a DW_FORM_sdata instead of a location expression. */
5592 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5594 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5595 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5599 /* Otherwise, just checksum the raw location expression. */
5602 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5603 CHECKSUM (loc
->dw_loc_oprnd1
);
5604 CHECKSUM (loc
->dw_loc_oprnd2
);
5605 loc
= loc
->dw_loc_next
;
5609 /* Calculate the checksum of an attribute. */
5612 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5613 struct md5_ctx
*ctx
, int *mark
)
5615 dw_loc_descr_ref loc
;
5618 if (AT_class (at
) == dw_val_class_die_ref
)
5620 dw_die_ref target_die
= AT_ref (at
);
5622 /* For pointer and reference types, we checksum only the (qualified)
5623 name of the target type (if there is a name). For friend entries,
5624 we checksum only the (qualified) name of the target type or function.
5625 This allows the checksum to remain the same whether the target type
5626 is complete or not. */
5627 if ((at
->dw_attr
== DW_AT_type
5628 && (tag
== DW_TAG_pointer_type
5629 || tag
== DW_TAG_reference_type
5630 || tag
== DW_TAG_rvalue_reference_type
5631 || tag
== DW_TAG_ptr_to_member_type
))
5632 || (at
->dw_attr
== DW_AT_friend
5633 && tag
== DW_TAG_friend
))
5635 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5637 if (name_attr
!= NULL
)
5639 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5643 CHECKSUM_ULEB128 ('N');
5644 CHECKSUM_ULEB128 (at
->dw_attr
);
5645 if (decl
->die_parent
!= NULL
)
5646 checksum_die_context (decl
->die_parent
, ctx
);
5647 CHECKSUM_ULEB128 ('E');
5648 CHECKSUM_STRING (AT_string (name_attr
));
5653 /* For all other references to another DIE, we check to see if the
5654 target DIE has already been visited. If it has, we emit a
5655 backward reference; if not, we descend recursively. */
5656 if (target_die
->die_mark
> 0)
5658 CHECKSUM_ULEB128 ('R');
5659 CHECKSUM_ULEB128 (at
->dw_attr
);
5660 CHECKSUM_ULEB128 (target_die
->die_mark
);
5664 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5668 target_die
->die_mark
= ++(*mark
);
5669 CHECKSUM_ULEB128 ('T');
5670 CHECKSUM_ULEB128 (at
->dw_attr
);
5671 if (decl
->die_parent
!= NULL
)
5672 checksum_die_context (decl
->die_parent
, ctx
);
5673 die_checksum_ordered (target_die
, ctx
, mark
);
5678 CHECKSUM_ULEB128 ('A');
5679 CHECKSUM_ULEB128 (at
->dw_attr
);
5681 switch (AT_class (at
))
5683 case dw_val_class_const
:
5684 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5685 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5688 case dw_val_class_unsigned_const
:
5689 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5690 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5693 case dw_val_class_const_double
:
5694 CHECKSUM_ULEB128 (DW_FORM_block
);
5695 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5696 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5699 case dw_val_class_vec
:
5700 CHECKSUM_ULEB128 (DW_FORM_block
);
5701 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
5702 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5705 case dw_val_class_flag
:
5706 CHECKSUM_ULEB128 (DW_FORM_flag
);
5707 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5710 case dw_val_class_str
:
5711 CHECKSUM_ULEB128 (DW_FORM_string
);
5712 CHECKSUM_STRING (AT_string (at
));
5715 case dw_val_class_addr
:
5717 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5718 CHECKSUM_ULEB128 (DW_FORM_string
);
5719 CHECKSUM_STRING (XSTR (r
, 0));
5722 case dw_val_class_offset
:
5723 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5724 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5727 case dw_val_class_loc
:
5728 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5729 loc_checksum_ordered (loc
, ctx
);
5732 case dw_val_class_fde_ref
:
5733 case dw_val_class_lbl_id
:
5734 case dw_val_class_lineptr
:
5735 case dw_val_class_macptr
:
5736 case dw_val_class_high_pc
:
5739 case dw_val_class_file
:
5740 CHECKSUM_ULEB128 (DW_FORM_string
);
5741 CHECKSUM_STRING (AT_file (at
)->filename
);
5744 case dw_val_class_data8
:
5745 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5753 struct checksum_attributes
5755 dw_attr_ref at_name
;
5756 dw_attr_ref at_type
;
5757 dw_attr_ref at_friend
;
5758 dw_attr_ref at_accessibility
;
5759 dw_attr_ref at_address_class
;
5760 dw_attr_ref at_allocated
;
5761 dw_attr_ref at_artificial
;
5762 dw_attr_ref at_associated
;
5763 dw_attr_ref at_binary_scale
;
5764 dw_attr_ref at_bit_offset
;
5765 dw_attr_ref at_bit_size
;
5766 dw_attr_ref at_bit_stride
;
5767 dw_attr_ref at_byte_size
;
5768 dw_attr_ref at_byte_stride
;
5769 dw_attr_ref at_const_value
;
5770 dw_attr_ref at_containing_type
;
5771 dw_attr_ref at_count
;
5772 dw_attr_ref at_data_location
;
5773 dw_attr_ref at_data_member_location
;
5774 dw_attr_ref at_decimal_scale
;
5775 dw_attr_ref at_decimal_sign
;
5776 dw_attr_ref at_default_value
;
5777 dw_attr_ref at_digit_count
;
5778 dw_attr_ref at_discr
;
5779 dw_attr_ref at_discr_list
;
5780 dw_attr_ref at_discr_value
;
5781 dw_attr_ref at_encoding
;
5782 dw_attr_ref at_endianity
;
5783 dw_attr_ref at_explicit
;
5784 dw_attr_ref at_is_optional
;
5785 dw_attr_ref at_location
;
5786 dw_attr_ref at_lower_bound
;
5787 dw_attr_ref at_mutable
;
5788 dw_attr_ref at_ordering
;
5789 dw_attr_ref at_picture_string
;
5790 dw_attr_ref at_prototyped
;
5791 dw_attr_ref at_small
;
5792 dw_attr_ref at_segment
;
5793 dw_attr_ref at_string_length
;
5794 dw_attr_ref at_threads_scaled
;
5795 dw_attr_ref at_upper_bound
;
5796 dw_attr_ref at_use_location
;
5797 dw_attr_ref at_use_UTF8
;
5798 dw_attr_ref at_variable_parameter
;
5799 dw_attr_ref at_virtuality
;
5800 dw_attr_ref at_visibility
;
5801 dw_attr_ref at_vtable_elem_location
;
5804 /* Collect the attributes that we will want to use for the checksum. */
5807 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5812 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5823 attrs
->at_friend
= a
;
5825 case DW_AT_accessibility
:
5826 attrs
->at_accessibility
= a
;
5828 case DW_AT_address_class
:
5829 attrs
->at_address_class
= a
;
5831 case DW_AT_allocated
:
5832 attrs
->at_allocated
= a
;
5834 case DW_AT_artificial
:
5835 attrs
->at_artificial
= a
;
5837 case DW_AT_associated
:
5838 attrs
->at_associated
= a
;
5840 case DW_AT_binary_scale
:
5841 attrs
->at_binary_scale
= a
;
5843 case DW_AT_bit_offset
:
5844 attrs
->at_bit_offset
= a
;
5846 case DW_AT_bit_size
:
5847 attrs
->at_bit_size
= a
;
5849 case DW_AT_bit_stride
:
5850 attrs
->at_bit_stride
= a
;
5852 case DW_AT_byte_size
:
5853 attrs
->at_byte_size
= a
;
5855 case DW_AT_byte_stride
:
5856 attrs
->at_byte_stride
= a
;
5858 case DW_AT_const_value
:
5859 attrs
->at_const_value
= a
;
5861 case DW_AT_containing_type
:
5862 attrs
->at_containing_type
= a
;
5865 attrs
->at_count
= a
;
5867 case DW_AT_data_location
:
5868 attrs
->at_data_location
= a
;
5870 case DW_AT_data_member_location
:
5871 attrs
->at_data_member_location
= a
;
5873 case DW_AT_decimal_scale
:
5874 attrs
->at_decimal_scale
= a
;
5876 case DW_AT_decimal_sign
:
5877 attrs
->at_decimal_sign
= a
;
5879 case DW_AT_default_value
:
5880 attrs
->at_default_value
= a
;
5882 case DW_AT_digit_count
:
5883 attrs
->at_digit_count
= a
;
5886 attrs
->at_discr
= a
;
5888 case DW_AT_discr_list
:
5889 attrs
->at_discr_list
= a
;
5891 case DW_AT_discr_value
:
5892 attrs
->at_discr_value
= a
;
5894 case DW_AT_encoding
:
5895 attrs
->at_encoding
= a
;
5897 case DW_AT_endianity
:
5898 attrs
->at_endianity
= a
;
5900 case DW_AT_explicit
:
5901 attrs
->at_explicit
= a
;
5903 case DW_AT_is_optional
:
5904 attrs
->at_is_optional
= a
;
5906 case DW_AT_location
:
5907 attrs
->at_location
= a
;
5909 case DW_AT_lower_bound
:
5910 attrs
->at_lower_bound
= a
;
5913 attrs
->at_mutable
= a
;
5915 case DW_AT_ordering
:
5916 attrs
->at_ordering
= a
;
5918 case DW_AT_picture_string
:
5919 attrs
->at_picture_string
= a
;
5921 case DW_AT_prototyped
:
5922 attrs
->at_prototyped
= a
;
5925 attrs
->at_small
= a
;
5928 attrs
->at_segment
= a
;
5930 case DW_AT_string_length
:
5931 attrs
->at_string_length
= a
;
5933 case DW_AT_threads_scaled
:
5934 attrs
->at_threads_scaled
= a
;
5936 case DW_AT_upper_bound
:
5937 attrs
->at_upper_bound
= a
;
5939 case DW_AT_use_location
:
5940 attrs
->at_use_location
= a
;
5942 case DW_AT_use_UTF8
:
5943 attrs
->at_use_UTF8
= a
;
5945 case DW_AT_variable_parameter
:
5946 attrs
->at_variable_parameter
= a
;
5948 case DW_AT_virtuality
:
5949 attrs
->at_virtuality
= a
;
5951 case DW_AT_visibility
:
5952 attrs
->at_visibility
= a
;
5954 case DW_AT_vtable_elem_location
:
5955 attrs
->at_vtable_elem_location
= a
;
5963 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
5966 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5970 struct checksum_attributes attrs
;
5972 CHECKSUM_ULEB128 ('D');
5973 CHECKSUM_ULEB128 (die
->die_tag
);
5975 memset (&attrs
, 0, sizeof (attrs
));
5977 decl
= get_AT_ref (die
, DW_AT_specification
);
5979 collect_checksum_attributes (&attrs
, decl
);
5980 collect_checksum_attributes (&attrs
, die
);
5982 CHECKSUM_ATTR (attrs
.at_name
);
5983 CHECKSUM_ATTR (attrs
.at_accessibility
);
5984 CHECKSUM_ATTR (attrs
.at_address_class
);
5985 CHECKSUM_ATTR (attrs
.at_allocated
);
5986 CHECKSUM_ATTR (attrs
.at_artificial
);
5987 CHECKSUM_ATTR (attrs
.at_associated
);
5988 CHECKSUM_ATTR (attrs
.at_binary_scale
);
5989 CHECKSUM_ATTR (attrs
.at_bit_offset
);
5990 CHECKSUM_ATTR (attrs
.at_bit_size
);
5991 CHECKSUM_ATTR (attrs
.at_bit_stride
);
5992 CHECKSUM_ATTR (attrs
.at_byte_size
);
5993 CHECKSUM_ATTR (attrs
.at_byte_stride
);
5994 CHECKSUM_ATTR (attrs
.at_const_value
);
5995 CHECKSUM_ATTR (attrs
.at_containing_type
);
5996 CHECKSUM_ATTR (attrs
.at_count
);
5997 CHECKSUM_ATTR (attrs
.at_data_location
);
5998 CHECKSUM_ATTR (attrs
.at_data_member_location
);
5999 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6000 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6001 CHECKSUM_ATTR (attrs
.at_default_value
);
6002 CHECKSUM_ATTR (attrs
.at_digit_count
);
6003 CHECKSUM_ATTR (attrs
.at_discr
);
6004 CHECKSUM_ATTR (attrs
.at_discr_list
);
6005 CHECKSUM_ATTR (attrs
.at_discr_value
);
6006 CHECKSUM_ATTR (attrs
.at_encoding
);
6007 CHECKSUM_ATTR (attrs
.at_endianity
);
6008 CHECKSUM_ATTR (attrs
.at_explicit
);
6009 CHECKSUM_ATTR (attrs
.at_is_optional
);
6010 CHECKSUM_ATTR (attrs
.at_location
);
6011 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6012 CHECKSUM_ATTR (attrs
.at_mutable
);
6013 CHECKSUM_ATTR (attrs
.at_ordering
);
6014 CHECKSUM_ATTR (attrs
.at_picture_string
);
6015 CHECKSUM_ATTR (attrs
.at_prototyped
);
6016 CHECKSUM_ATTR (attrs
.at_small
);
6017 CHECKSUM_ATTR (attrs
.at_segment
);
6018 CHECKSUM_ATTR (attrs
.at_string_length
);
6019 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6020 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6021 CHECKSUM_ATTR (attrs
.at_use_location
);
6022 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6023 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6024 CHECKSUM_ATTR (attrs
.at_virtuality
);
6025 CHECKSUM_ATTR (attrs
.at_visibility
);
6026 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6027 CHECKSUM_ATTR (attrs
.at_type
);
6028 CHECKSUM_ATTR (attrs
.at_friend
);
6030 /* Checksum the child DIEs, except for nested types and member functions. */
6033 dw_attr_ref name_attr
;
6036 name_attr
= get_AT (c
, DW_AT_name
);
6037 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
6038 && name_attr
!= NULL
)
6040 CHECKSUM_ULEB128 ('S');
6041 CHECKSUM_ULEB128 (c
->die_tag
);
6042 CHECKSUM_STRING (AT_string (name_attr
));
6046 /* Mark this DIE so it gets processed when unmarking. */
6047 if (c
->die_mark
== 0)
6049 die_checksum_ordered (c
, ctx
, mark
);
6051 } while (c
!= die
->die_child
);
6053 CHECKSUM_ULEB128 (0);
6057 #undef CHECKSUM_STRING
6058 #undef CHECKSUM_ATTR
6059 #undef CHECKSUM_LEB128
6060 #undef CHECKSUM_ULEB128
6062 /* Generate the type signature for DIE. This is computed by generating an
6063 MD5 checksum over the DIE's tag, its relevant attributes, and its
6064 children. Attributes that are references to other DIEs are processed
6065 by recursion, using the MARK field to prevent infinite recursion.
6066 If the DIE is nested inside a namespace or another type, we also
6067 need to include that context in the signature. The lower 64 bits
6068 of the resulting MD5 checksum comprise the signature. */
6071 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6075 unsigned char checksum
[16];
6080 name
= get_AT_string (die
, DW_AT_name
);
6081 decl
= get_AT_ref (die
, DW_AT_specification
);
6082 parent
= get_die_parent (die
);
6084 /* First, compute a signature for just the type name (and its surrounding
6085 context, if any. This is stored in the type unit DIE for link-time
6086 ODR (one-definition rule) checking. */
6088 if (is_cxx() && name
!= NULL
)
6090 md5_init_ctx (&ctx
);
6092 /* Checksum the names of surrounding namespaces and structures. */
6094 checksum_die_context (parent
, &ctx
);
6096 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
6097 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
6098 md5_finish_ctx (&ctx
, checksum
);
6100 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6103 /* Next, compute the complete type signature. */
6105 md5_init_ctx (&ctx
);
6107 die
->die_mark
= mark
;
6109 /* Checksum the names of surrounding namespaces and structures. */
6111 checksum_die_context (parent
, &ctx
);
6113 /* Checksum the DIE and its children. */
6114 die_checksum_ordered (die
, &ctx
, &mark
);
6115 unmark_all_dies (die
);
6116 md5_finish_ctx (&ctx
, checksum
);
6118 /* Store the signature in the type node and link the type DIE and the
6119 type node together. */
6120 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6121 DWARF_TYPE_SIGNATURE_SIZE
);
6122 die
->comdat_type_p
= true;
6123 die
->die_id
.die_type_node
= type_node
;
6124 type_node
->type_die
= die
;
6126 /* If the DIE is a specification, link its declaration to the type node
6130 decl
->comdat_type_p
= true;
6131 decl
->die_id
.die_type_node
= type_node
;
6135 /* Do the location expressions look same? */
6137 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6139 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6140 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6141 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6144 /* Do the values look the same? */
6146 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6148 dw_loc_descr_ref loc1
, loc2
;
6151 if (v1
->val_class
!= v2
->val_class
)
6154 switch (v1
->val_class
)
6156 case dw_val_class_const
:
6157 return v1
->v
.val_int
== v2
->v
.val_int
;
6158 case dw_val_class_unsigned_const
:
6159 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6160 case dw_val_class_const_double
:
6161 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6162 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6163 case dw_val_class_vec
:
6164 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6165 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6167 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6168 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6171 case dw_val_class_flag
:
6172 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6173 case dw_val_class_str
:
6174 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6176 case dw_val_class_addr
:
6177 r1
= v1
->v
.val_addr
;
6178 r2
= v2
->v
.val_addr
;
6179 if (GET_CODE (r1
) != GET_CODE (r2
))
6181 return !rtx_equal_p (r1
, r2
);
6183 case dw_val_class_offset
:
6184 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6186 case dw_val_class_loc
:
6187 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6189 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6190 if (!same_loc_p (loc1
, loc2
, mark
))
6192 return !loc1
&& !loc2
;
6194 case dw_val_class_die_ref
:
6195 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6197 case dw_val_class_fde_ref
:
6198 case dw_val_class_vms_delta
:
6199 case dw_val_class_lbl_id
:
6200 case dw_val_class_lineptr
:
6201 case dw_val_class_macptr
:
6202 case dw_val_class_high_pc
:
6205 case dw_val_class_file
:
6206 return v1
->v
.val_file
== v2
->v
.val_file
;
6208 case dw_val_class_data8
:
6209 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6216 /* Do the attributes look the same? */
6219 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6221 if (at1
->dw_attr
!= at2
->dw_attr
)
6224 /* We don't care that this was compiled with a different compiler
6225 snapshot; if the output is the same, that's what matters. */
6226 if (at1
->dw_attr
== DW_AT_producer
)
6229 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6232 /* Do the dies look the same? */
6235 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6241 /* To avoid infinite recursion. */
6243 return die1
->die_mark
== die2
->die_mark
;
6244 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6246 if (die1
->die_tag
!= die2
->die_tag
)
6249 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6252 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6253 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6256 c1
= die1
->die_child
;
6257 c2
= die2
->die_child
;
6266 if (!same_die_p (c1
, c2
, mark
))
6270 if (c1
== die1
->die_child
)
6272 if (c2
== die2
->die_child
)
6282 /* Do the dies look the same? Wrapper around same_die_p. */
6285 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6288 int ret
= same_die_p (die1
, die2
, &mark
);
6290 unmark_all_dies (die1
);
6291 unmark_all_dies (die2
);
6296 /* The prefix to attach to symbols on DIEs in the current comdat debug
6298 static const char *comdat_symbol_id
;
6300 /* The index of the current symbol within the current comdat CU. */
6301 static unsigned int comdat_symbol_number
;
6303 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6304 children, and set comdat_symbol_id accordingly. */
6307 compute_section_prefix (dw_die_ref unit_die
)
6309 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6310 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6311 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6314 unsigned char checksum
[16];
6317 /* Compute the checksum of the DIE, then append part of it as hex digits to
6318 the name filename of the unit. */
6320 md5_init_ctx (&ctx
);
6322 die_checksum (unit_die
, &ctx
, &mark
);
6323 unmark_all_dies (unit_die
);
6324 md5_finish_ctx (&ctx
, checksum
);
6326 sprintf (name
, "%s.", base
);
6327 clean_symbol_name (name
);
6329 p
= name
+ strlen (name
);
6330 for (i
= 0; i
< 4; i
++)
6332 sprintf (p
, "%.2x", checksum
[i
]);
6336 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6337 comdat_symbol_number
= 0;
6340 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6343 is_type_die (dw_die_ref die
)
6345 switch (die
->die_tag
)
6347 case DW_TAG_array_type
:
6348 case DW_TAG_class_type
:
6349 case DW_TAG_interface_type
:
6350 case DW_TAG_enumeration_type
:
6351 case DW_TAG_pointer_type
:
6352 case DW_TAG_reference_type
:
6353 case DW_TAG_rvalue_reference_type
:
6354 case DW_TAG_string_type
:
6355 case DW_TAG_structure_type
:
6356 case DW_TAG_subroutine_type
:
6357 case DW_TAG_union_type
:
6358 case DW_TAG_ptr_to_member_type
:
6359 case DW_TAG_set_type
:
6360 case DW_TAG_subrange_type
:
6361 case DW_TAG_base_type
:
6362 case DW_TAG_const_type
:
6363 case DW_TAG_file_type
:
6364 case DW_TAG_packed_type
:
6365 case DW_TAG_volatile_type
:
6366 case DW_TAG_typedef
:
6373 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6374 Basically, we want to choose the bits that are likely to be shared between
6375 compilations (types) and leave out the bits that are specific to individual
6376 compilations (functions). */
6379 is_comdat_die (dw_die_ref c
)
6381 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6382 we do for stabs. The advantage is a greater likelihood of sharing between
6383 objects that don't include headers in the same order (and therefore would
6384 put the base types in a different comdat). jason 8/28/00 */
6386 if (c
->die_tag
== DW_TAG_base_type
)
6389 if (c
->die_tag
== DW_TAG_pointer_type
6390 || c
->die_tag
== DW_TAG_reference_type
6391 || c
->die_tag
== DW_TAG_rvalue_reference_type
6392 || c
->die_tag
== DW_TAG_const_type
6393 || c
->die_tag
== DW_TAG_volatile_type
)
6395 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6397 return t
? is_comdat_die (t
) : 0;
6400 return is_type_die (c
);
6403 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6404 compilation unit. */
6407 is_symbol_die (dw_die_ref c
)
6409 return (is_type_die (c
)
6410 || is_declaration_die (c
)
6411 || c
->die_tag
== DW_TAG_namespace
6412 || c
->die_tag
== DW_TAG_module
);
6415 /* Returns true iff C is a compile-unit DIE. */
6418 is_cu_die (dw_die_ref c
)
6420 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6423 /* Returns true iff C is a unit DIE of some sort. */
6426 is_unit_die (dw_die_ref c
)
6428 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6429 || c
->die_tag
== DW_TAG_partial_unit
6430 || c
->die_tag
== DW_TAG_type_unit
);
6433 /* Returns true iff C is a namespace DIE. */
6436 is_namespace_die (dw_die_ref c
)
6438 return c
&& c
->die_tag
== DW_TAG_namespace
;
6441 /* Returns true iff C is a class or structure DIE. */
6444 is_class_die (dw_die_ref c
)
6446 return c
&& (c
->die_tag
== DW_TAG_class_type
6447 || c
->die_tag
== DW_TAG_structure_type
);
6451 gen_internal_sym (const char *prefix
)
6455 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6456 return xstrdup (buf
);
6459 /* Assign symbols to all worthy DIEs under DIE. */
6462 assign_symbol_names (dw_die_ref die
)
6466 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6468 if (comdat_symbol_id
)
6470 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6472 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6473 comdat_symbol_id
, comdat_symbol_number
++);
6474 die
->die_id
.die_symbol
= xstrdup (p
);
6477 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6480 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6483 struct cu_hash_table_entry
6486 unsigned min_comdat_num
, max_comdat_num
;
6487 struct cu_hash_table_entry
*next
;
6490 /* Routines to manipulate hash table of CUs. */
6492 htab_cu_hash (const void *of
)
6494 const struct cu_hash_table_entry
*const entry
=
6495 (const struct cu_hash_table_entry
*) of
;
6497 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6501 htab_cu_eq (const void *of1
, const void *of2
)
6503 const struct cu_hash_table_entry
*const entry1
=
6504 (const struct cu_hash_table_entry
*) of1
;
6505 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
6507 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6511 htab_cu_del (void *what
)
6513 struct cu_hash_table_entry
*next
,
6514 *entry
= (struct cu_hash_table_entry
*) what
;
6524 /* Check whether we have already seen this CU and set up SYM_NUM
6527 check_duplicate_cu (dw_die_ref cu
, htab_t htable
, unsigned int *sym_num
)
6529 struct cu_hash_table_entry dummy
;
6530 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6532 dummy
.max_comdat_num
= 0;
6534 slot
= (struct cu_hash_table_entry
**)
6535 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6539 for (; entry
; last
= entry
, entry
= entry
->next
)
6541 if (same_die_p_wrap (cu
, entry
->cu
))
6547 *sym_num
= entry
->min_comdat_num
;
6551 entry
= XCNEW (struct cu_hash_table_entry
);
6553 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6554 entry
->next
= *slot
;
6560 /* Record SYM_NUM to record of CU in HTABLE. */
6562 record_comdat_symbol_number (dw_die_ref cu
, htab_t htable
, unsigned int sym_num
)
6564 struct cu_hash_table_entry
**slot
, *entry
;
6566 slot
= (struct cu_hash_table_entry
**)
6567 htab_find_slot_with_hash (htable
, cu
, htab_hash_string (cu
->die_id
.die_symbol
),
6571 entry
->max_comdat_num
= sym_num
;
6574 /* Traverse the DIE (which is always comp_unit_die), and set up
6575 additional compilation units for each of the include files we see
6576 bracketed by BINCL/EINCL. */
6579 break_out_includes (dw_die_ref die
)
6582 dw_die_ref unit
= NULL
;
6583 limbo_die_node
*node
, **pnode
;
6584 htab_t cu_hash_table
;
6588 dw_die_ref prev
= c
;
6590 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6591 || (unit
&& is_comdat_die (c
)))
6593 dw_die_ref next
= c
->die_sib
;
6595 /* This DIE is for a secondary CU; remove it from the main one. */
6596 remove_child_with_prev (c
, prev
);
6598 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6599 unit
= push_new_compile_unit (unit
, c
);
6600 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6601 unit
= pop_compile_unit (unit
);
6603 add_child_die (unit
, c
);
6605 if (c
== die
->die_child
)
6608 } while (c
!= die
->die_child
);
6611 /* We can only use this in debugging, since the frontend doesn't check
6612 to make sure that we leave every include file we enter. */
6616 assign_symbol_names (die
);
6617 cu_hash_table
= htab_create (10, htab_cu_hash
, htab_cu_eq
, htab_cu_del
);
6618 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6624 compute_section_prefix (node
->die
);
6625 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6626 &comdat_symbol_number
);
6627 assign_symbol_names (node
->die
);
6629 *pnode
= node
->next
;
6632 pnode
= &node
->next
;
6633 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6634 comdat_symbol_number
);
6637 htab_delete (cu_hash_table
);
6640 /* Return non-zero if this DIE is a declaration. */
6643 is_declaration_die (dw_die_ref die
)
6648 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6649 if (a
->dw_attr
== DW_AT_declaration
)
6655 /* Return non-zero if this DIE is nested inside a subprogram. */
6658 is_nested_in_subprogram (dw_die_ref die
)
6660 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6664 return local_scope_p (decl
);
6667 /* Return non-zero if this DIE contains a defining declaration of a
6671 contains_subprogram_definition (dw_die_ref die
)
6675 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6677 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6681 /* Return non-zero if this is a type DIE that should be moved to a
6682 COMDAT .debug_types section. */
6685 should_move_die_to_comdat (dw_die_ref die
)
6687 switch (die
->die_tag
)
6689 case DW_TAG_class_type
:
6690 case DW_TAG_structure_type
:
6691 case DW_TAG_enumeration_type
:
6692 case DW_TAG_union_type
:
6693 /* Don't move declarations, inlined instances, or types nested in a
6695 if (is_declaration_die (die
)
6696 || get_AT (die
, DW_AT_abstract_origin
)
6697 || is_nested_in_subprogram (die
))
6699 /* A type definition should never contain a subprogram definition. */
6700 gcc_assert (!contains_subprogram_definition (die
));
6702 case DW_TAG_array_type
:
6703 case DW_TAG_interface_type
:
6704 case DW_TAG_pointer_type
:
6705 case DW_TAG_reference_type
:
6706 case DW_TAG_rvalue_reference_type
:
6707 case DW_TAG_string_type
:
6708 case DW_TAG_subroutine_type
:
6709 case DW_TAG_ptr_to_member_type
:
6710 case DW_TAG_set_type
:
6711 case DW_TAG_subrange_type
:
6712 case DW_TAG_base_type
:
6713 case DW_TAG_const_type
:
6714 case DW_TAG_file_type
:
6715 case DW_TAG_packed_type
:
6716 case DW_TAG_volatile_type
:
6717 case DW_TAG_typedef
:
6723 /* Make a clone of DIE. */
6726 clone_die (dw_die_ref die
)
6732 clone
= ggc_alloc_cleared_die_node ();
6733 clone
->die_tag
= die
->die_tag
;
6735 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6736 add_dwarf_attr (clone
, a
);
6741 /* Make a clone of the tree rooted at DIE. */
6744 clone_tree (dw_die_ref die
)
6747 dw_die_ref clone
= clone_die (die
);
6749 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
6754 /* Make a clone of DIE as a declaration. */
6757 clone_as_declaration (dw_die_ref die
)
6764 /* If the DIE is already a declaration, just clone it. */
6765 if (is_declaration_die (die
))
6766 return clone_die (die
);
6768 /* If the DIE is a specification, just clone its declaration DIE. */
6769 decl
= get_AT_ref (die
, DW_AT_specification
);
6772 clone
= clone_die (decl
);
6773 if (die
->comdat_type_p
)
6774 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6778 clone
= ggc_alloc_cleared_die_node ();
6779 clone
->die_tag
= die
->die_tag
;
6781 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6783 /* We don't want to copy over all attributes.
6784 For example we don't want DW_AT_byte_size because otherwise we will no
6785 longer have a declaration and GDB will treat it as a definition. */
6789 case DW_AT_artificial
:
6790 case DW_AT_containing_type
:
6791 case DW_AT_external
:
6794 case DW_AT_virtuality
:
6795 case DW_AT_linkage_name
:
6796 case DW_AT_MIPS_linkage_name
:
6797 add_dwarf_attr (clone
, a
);
6799 case DW_AT_byte_size
:
6805 if (die
->comdat_type_p
)
6806 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6808 add_AT_flag (clone
, DW_AT_declaration
, 1);
6812 /* Copy the declaration context to the new type unit DIE. This includes
6813 any surrounding namespace or type declarations. If the DIE has an
6814 AT_specification attribute, it also includes attributes and children
6815 attached to the specification, and returns a pointer to the original
6816 parent of the declaration DIE. Returns NULL otherwise. */
6819 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
6822 dw_die_ref new_decl
;
6823 dw_die_ref orig_parent
= NULL
;
6825 decl
= get_AT_ref (die
, DW_AT_specification
);
6834 /* The original DIE will be changed to a declaration, and must
6835 be moved to be a child of the original declaration DIE. */
6836 orig_parent
= decl
->die_parent
;
6838 /* Copy the type node pointer from the new DIE to the original
6839 declaration DIE so we can forward references later. */
6840 decl
->comdat_type_p
= true;
6841 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
6843 remove_AT (die
, DW_AT_specification
);
6845 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
6847 if (a
->dw_attr
!= DW_AT_name
6848 && a
->dw_attr
!= DW_AT_declaration
6849 && a
->dw_attr
!= DW_AT_external
)
6850 add_dwarf_attr (die
, a
);
6853 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
6856 if (decl
->die_parent
!= NULL
6857 && !is_unit_die (decl
->die_parent
))
6859 new_decl
= copy_ancestor_tree (unit
, decl
, NULL
);
6860 if (new_decl
!= NULL
)
6862 remove_AT (new_decl
, DW_AT_signature
);
6863 add_AT_specification (die
, new_decl
);
6870 /* Generate the skeleton ancestor tree for the given NODE, then clone
6871 the DIE and add the clone into the tree. */
6874 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
6876 if (node
->new_die
!= NULL
)
6879 node
->new_die
= clone_as_declaration (node
->old_die
);
6881 if (node
->parent
!= NULL
)
6883 generate_skeleton_ancestor_tree (node
->parent
);
6884 add_child_die (node
->parent
->new_die
, node
->new_die
);
6888 /* Generate a skeleton tree of DIEs containing any declarations that are
6889 found in the original tree. We traverse the tree looking for declaration
6890 DIEs, and construct the skeleton from the bottom up whenever we find one. */
6893 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
6895 skeleton_chain_node node
;
6898 dw_die_ref prev
= NULL
;
6899 dw_die_ref next
= NULL
;
6901 node
.parent
= parent
;
6903 first
= c
= parent
->old_die
->die_child
;
6907 if (prev
== NULL
|| prev
->die_sib
== c
)
6910 next
= (c
== first
? NULL
: c
->die_sib
);
6912 node
.new_die
= NULL
;
6913 if (is_declaration_die (c
))
6915 /* Clone the existing DIE, move the original to the skeleton
6916 tree (which is in the main CU), and put the clone, with
6917 all the original's children, where the original came from. */
6918 dw_die_ref clone
= clone_die (c
);
6919 move_all_children (c
, clone
);
6921 replace_child (c
, clone
, prev
);
6922 generate_skeleton_ancestor_tree (parent
);
6923 add_child_die (parent
->new_die
, c
);
6927 generate_skeleton_bottom_up (&node
);
6928 } while (next
!= NULL
);
6931 /* Wrapper function for generate_skeleton_bottom_up. */
6934 generate_skeleton (dw_die_ref die
)
6936 skeleton_chain_node node
;
6939 node
.new_die
= NULL
;
6942 /* If this type definition is nested inside another type,
6943 always leave at least a declaration in its place. */
6944 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
6945 node
.new_die
= clone_as_declaration (die
);
6947 generate_skeleton_bottom_up (&node
);
6948 return node
.new_die
;
6951 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
6952 declaration. The original DIE is moved to a new compile unit so that
6953 existing references to it follow it to the new location. If any of the
6954 original DIE's descendants is a declaration, we need to replace the
6955 original DIE with a skeleton tree and move the declarations back into the
6959 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
6962 dw_die_ref skeleton
, orig_parent
;
6964 /* Copy the declaration context to the type unit DIE. If the returned
6965 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
6967 orig_parent
= copy_declaration_context (unit
, child
);
6969 skeleton
= generate_skeleton (child
);
6970 if (skeleton
== NULL
)
6971 remove_child_with_prev (child
, prev
);
6974 skeleton
->comdat_type_p
= true;
6975 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
6977 /* If the original DIE was a specification, we need to put
6978 the skeleton under the parent DIE of the declaration.
6979 This leaves the original declaration in the tree, but
6980 it will be pruned later since there are no longer any
6981 references to it. */
6982 if (orig_parent
!= NULL
)
6984 remove_child_with_prev (child
, prev
);
6985 add_child_die (orig_parent
, skeleton
);
6988 replace_child (child
, skeleton
, prev
);
6994 /* Traverse the DIE and set up additional .debug_types sections for each
6995 type worthy of being placed in a COMDAT section. */
6998 break_out_comdat_types (dw_die_ref die
)
7002 dw_die_ref prev
= NULL
;
7003 dw_die_ref next
= NULL
;
7004 dw_die_ref unit
= NULL
;
7006 first
= c
= die
->die_child
;
7010 if (prev
== NULL
|| prev
->die_sib
== c
)
7013 next
= (c
== first
? NULL
: c
->die_sib
);
7014 if (should_move_die_to_comdat (c
))
7016 dw_die_ref replacement
;
7017 comdat_type_node_ref type_node
;
7019 /* Create a new type unit DIE as the root for the new tree, and
7020 add it to the list of comdat types. */
7021 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7022 add_AT_unsigned (unit
, DW_AT_language
,
7023 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7024 type_node
= ggc_alloc_cleared_comdat_type_node ();
7025 type_node
->root_die
= unit
;
7026 type_node
->next
= comdat_type_list
;
7027 comdat_type_list
= type_node
;
7029 /* Generate the type signature. */
7030 generate_type_signature (c
, type_node
);
7032 /* Copy the declaration context, attributes, and children of the
7033 declaration into the new type unit DIE, then remove this DIE
7034 from the main CU (or replace it with a skeleton if necessary). */
7035 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7036 type_node
->skeleton_die
= replacement
;
7038 /* Break out nested types into their own type units. */
7039 break_out_comdat_types (c
);
7041 /* Add the DIE to the new compunit. */
7042 add_child_die (unit
, c
);
7044 if (replacement
!= NULL
)
7047 else if (c
->die_tag
== DW_TAG_namespace
7048 || c
->die_tag
== DW_TAG_class_type
7049 || c
->die_tag
== DW_TAG_structure_type
7050 || c
->die_tag
== DW_TAG_union_type
)
7052 /* Look for nested types that can be broken out. */
7053 break_out_comdat_types (c
);
7055 } while (next
!= NULL
);
7058 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7060 struct decl_table_entry
7066 /* Routines to manipulate hash table of copied declarations. */
7069 htab_decl_hash (const void *of
)
7071 const struct decl_table_entry
*const entry
=
7072 (const struct decl_table_entry
*) of
;
7074 return htab_hash_pointer (entry
->orig
);
7078 htab_decl_eq (const void *of1
, const void *of2
)
7080 const struct decl_table_entry
*const entry1
=
7081 (const struct decl_table_entry
*) of1
;
7082 const struct die_struct
*const entry2
= (const struct die_struct
*) of2
;
7084 return entry1
->orig
== entry2
;
7088 htab_decl_del (void *what
)
7090 struct decl_table_entry
*entry
= (struct decl_table_entry
*) what
;
7095 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7096 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7097 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7098 to check if the ancestor has already been copied into UNIT. */
7101 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7103 dw_die_ref parent
= die
->die_parent
;
7104 dw_die_ref new_parent
= unit
;
7107 struct decl_table_entry
*entry
= NULL
;
7111 /* Check if the entry has already been copied to UNIT. */
7112 slot
= htab_find_slot_with_hash (decl_table
, die
,
7113 htab_hash_pointer (die
), INSERT
);
7114 if (*slot
!= HTAB_EMPTY_ENTRY
)
7116 entry
= (struct decl_table_entry
*) *slot
;
7120 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7121 entry
= XCNEW (struct decl_table_entry
);
7129 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7132 if (!is_unit_die (parent
))
7133 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7136 copy
= clone_as_declaration (die
);
7137 add_child_die (new_parent
, copy
);
7139 if (decl_table
!= NULL
)
7141 /* Record the pointer to the copy. */
7148 /* Like clone_tree, but additionally enter all the children into
7149 the hash table decl_table. */
7152 clone_tree_hash (dw_die_ref die
, htab_t decl_table
)
7155 dw_die_ref clone
= clone_die (die
);
7156 struct decl_table_entry
*entry
;
7157 void **slot
= htab_find_slot_with_hash (decl_table
, die
,
7158 htab_hash_pointer (die
), INSERT
);
7159 /* Assert that DIE isn't in the hash table yet. If it would be there
7160 before, the ancestors would be necessarily there as well, therefore
7161 clone_tree_hash wouldn't be called. */
7162 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7163 entry
= XCNEW (struct decl_table_entry
);
7165 entry
->copy
= clone
;
7168 FOR_EACH_CHILD (die
, c
,
7169 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7174 /* Walk the DIE and its children, looking for references to incomplete
7175 or trivial types that are unmarked (i.e., that are not in the current
7179 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, htab_t decl_table
)
7185 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7187 if (AT_class (a
) == dw_val_class_die_ref
)
7189 dw_die_ref targ
= AT_ref (a
);
7191 struct decl_table_entry
*entry
;
7193 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7196 slot
= htab_find_slot_with_hash (decl_table
, targ
,
7197 htab_hash_pointer (targ
), INSERT
);
7199 if (*slot
!= HTAB_EMPTY_ENTRY
)
7201 /* TARG has already been copied, so we just need to
7202 modify the reference to point to the copy. */
7203 entry
= (struct decl_table_entry
*) *slot
;
7204 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7208 dw_die_ref parent
= unit
;
7209 dw_die_ref copy
= clone_die (targ
);
7211 /* Record in DECL_TABLE that TARG has been copied.
7212 Need to do this now, before the recursive call,
7213 because DECL_TABLE may be expanded and SLOT
7214 would no longer be a valid pointer. */
7215 entry
= XCNEW (struct decl_table_entry
);
7220 FOR_EACH_CHILD (targ
, c
,
7221 add_child_die (copy
,
7222 clone_tree_hash (c
, decl_table
)));
7224 /* Make sure the cloned tree is marked as part of the
7228 /* If TARG has surrounding context, copy its ancestor tree
7229 into the new type unit. */
7230 if (targ
->die_parent
!= NULL
7231 && !is_unit_die (targ
->die_parent
))
7232 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7235 add_child_die (parent
, copy
);
7236 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7238 /* Make sure the newly-copied DIE is walked. If it was
7239 installed in a previously-added context, it won't
7240 get visited otherwise. */
7243 /* Find the highest point of the newly-added tree,
7244 mark each node along the way, and walk from there. */
7245 parent
->die_mark
= 1;
7246 while (parent
->die_parent
7247 && parent
->die_parent
->die_mark
== 0)
7249 parent
= parent
->die_parent
;
7250 parent
->die_mark
= 1;
7252 copy_decls_walk (unit
, parent
, decl_table
);
7258 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7261 /* Copy declarations for "unworthy" types into the new comdat section.
7262 Incomplete types, modified types, and certain other types aren't broken
7263 out into comdat sections of their own, so they don't have a signature,
7264 and we need to copy the declaration into the same section so that we
7265 don't have an external reference. */
7268 copy_decls_for_unworthy_types (dw_die_ref unit
)
7273 decl_table
= htab_create (10, htab_decl_hash
, htab_decl_eq
, htab_decl_del
);
7274 copy_decls_walk (unit
, unit
, decl_table
);
7275 htab_delete (decl_table
);
7279 /* Traverse the DIE and add a sibling attribute if it may have the
7280 effect of speeding up access to siblings. To save some space,
7281 avoid generating sibling attributes for DIE's without children. */
7284 add_sibling_attributes (dw_die_ref die
)
7288 if (! die
->die_child
)
7291 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7292 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7294 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7297 /* Output all location lists for the DIE and its children. */
7300 output_location_lists (dw_die_ref die
)
7306 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7307 if (AT_class (a
) == dw_val_class_loc_list
)
7308 output_loc_list (AT_loc_list (a
));
7310 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7313 /* We want to limit the number of external references, because they are
7314 larger than local references: a relocation takes multiple words, and
7315 even a sig8 reference is always eight bytes, whereas a local reference
7316 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7317 So if we encounter multiple external references to the same type DIE, we
7318 make a local typedef stub for it and redirect all references there.
7320 This is the element of the hash table for keeping track of these
7330 /* Hash an external_ref. */
7333 hash_external_ref (const void *p
)
7335 const struct external_ref
*r
= (const struct external_ref
*)p
;
7336 return htab_hash_pointer (r
->type
);
7339 /* Compare external_refs. */
7342 external_ref_eq (const void *p1
, const void *p2
)
7344 const struct external_ref
*r1
= (const struct external_ref
*)p1
;
7345 const struct external_ref
*r2
= (const struct external_ref
*)p2
;
7346 return r1
->type
== r2
->type
;
7349 /* Return a pointer to the external_ref for references to DIE. */
7351 static struct external_ref
*
7352 lookup_external_ref (htab_t map
, dw_die_ref die
)
7354 struct external_ref ref
, *ref_p
;
7358 slot
= htab_find_slot (map
, &ref
, INSERT
);
7359 if (*slot
!= HTAB_EMPTY_ENTRY
)
7360 return (struct external_ref
*) *slot
;
7362 ref_p
= XCNEW (struct external_ref
);
7368 /* Subroutine of optimize_external_refs, below.
7370 If we see a type skeleton, record it as our stub. If we see external
7371 references, remember how many we've seen. */
7374 optimize_external_refs_1 (dw_die_ref die
, htab_t map
)
7379 struct external_ref
*ref_p
;
7381 if (is_type_die (die
)
7382 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7384 /* This is a local skeleton; use it for local references. */
7385 ref_p
= lookup_external_ref (map
, c
);
7389 /* Scan the DIE references, and remember any that refer to DIEs from
7390 other CUs (i.e. those which are not marked). */
7391 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7392 if (AT_class (a
) == dw_val_class_die_ref
7393 && (c
= AT_ref (a
))->die_mark
== 0
7396 ref_p
= lookup_external_ref (map
, c
);
7400 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7403 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7404 points to an external_ref, DATA is the CU we're processing. If we don't
7405 already have a local stub, and we have multiple refs, build a stub. */
7408 build_local_stub (void **slot
, void *data
)
7410 struct external_ref
*ref_p
= (struct external_ref
*)*slot
;
7412 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7414 /* We have multiple references to this type, so build a small stub.
7415 Both of these forms are a bit dodgy from the perspective of the
7416 DWARF standard, since technically they should have names. */
7417 dw_die_ref cu
= (dw_die_ref
) data
;
7418 dw_die_ref type
= ref_p
->type
;
7419 dw_die_ref stub
= NULL
;
7421 if (type
->comdat_type_p
)
7423 /* If we refer to this type via sig8, use AT_signature. */
7424 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7425 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7429 /* Otherwise, use a typedef with no name. */
7430 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7431 add_AT_die_ref (stub
, DW_AT_type
, type
);
7440 /* DIE is a unit; look through all the DIE references to see if there are
7441 any external references to types, and if so, create local stubs for
7442 them which will be applied in build_abbrev_table. This is useful because
7443 references to local DIEs are smaller. */
7446 optimize_external_refs (dw_die_ref die
)
7448 htab_t map
= htab_create (10, hash_external_ref
, external_ref_eq
, free
);
7449 optimize_external_refs_1 (die
, map
);
7450 htab_traverse (map
, build_local_stub
, die
);
7454 /* The format of each DIE (and its attribute value pairs) is encoded in an
7455 abbreviation table. This routine builds the abbreviation table and assigns
7456 a unique abbreviation id for each abbreviation entry. The children of each
7457 die are visited recursively. */
7460 build_abbrev_table (dw_die_ref die
, htab_t extern_map
)
7462 unsigned long abbrev_id
;
7463 unsigned int n_alloc
;
7468 /* Scan the DIE references, and replace any that refer to
7469 DIEs from other CUs (i.e. those which are not marked) with
7470 the local stubs we built in optimize_external_refs. */
7471 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7472 if (AT_class (a
) == dw_val_class_die_ref
7473 && (c
= AT_ref (a
))->die_mark
== 0)
7475 struct external_ref
*ref_p
;
7476 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7478 ref_p
= lookup_external_ref (extern_map
, c
);
7479 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7480 change_AT_die_ref (a
, ref_p
->stub
);
7482 /* We aren't changing this reference, so mark it external. */
7483 set_AT_ref_external (a
, 1);
7486 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7488 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7489 dw_attr_ref die_a
, abbrev_a
;
7493 if (abbrev
->die_tag
!= die
->die_tag
)
7495 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7498 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7501 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7503 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7504 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7505 || (value_format (abbrev_a
) != value_format (die_a
)))
7515 if (abbrev_id
>= abbrev_die_table_in_use
)
7517 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7519 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7520 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7523 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7524 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7525 abbrev_die_table_allocated
= n_alloc
;
7528 ++abbrev_die_table_in_use
;
7529 abbrev_die_table
[abbrev_id
] = die
;
7532 die
->die_abbrev
= abbrev_id
;
7533 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7536 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7539 constant_size (unsigned HOST_WIDE_INT value
)
7546 log
= floor_log2 (value
);
7549 log
= 1 << (floor_log2 (log
) + 1);
7554 /* Return the size of a DIE as it is represented in the
7555 .debug_info section. */
7557 static unsigned long
7558 size_of_die (dw_die_ref die
)
7560 unsigned long size
= 0;
7563 enum dwarf_form form
;
7565 size
+= size_of_uleb128 (die
->die_abbrev
);
7566 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7568 switch (AT_class (a
))
7570 case dw_val_class_addr
:
7571 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7573 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7574 size
+= size_of_uleb128 (AT_index (a
));
7577 size
+= DWARF2_ADDR_SIZE
;
7579 case dw_val_class_offset
:
7580 size
+= DWARF_OFFSET_SIZE
;
7582 case dw_val_class_loc
:
7584 unsigned long lsize
= size_of_locs (AT_loc (a
));
7587 if (dwarf_version
>= 4)
7588 size
+= size_of_uleb128 (lsize
);
7590 size
+= constant_size (lsize
);
7594 case dw_val_class_loc_list
:
7595 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7597 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7598 size
+= size_of_uleb128 (AT_index (a
));
7601 size
+= DWARF_OFFSET_SIZE
;
7603 case dw_val_class_range_list
:
7604 size
+= DWARF_OFFSET_SIZE
;
7606 case dw_val_class_const
:
7607 size
+= size_of_sleb128 (AT_int (a
));
7609 case dw_val_class_unsigned_const
:
7611 int csize
= constant_size (AT_unsigned (a
));
7612 if (dwarf_version
== 3
7613 && a
->dw_attr
== DW_AT_data_member_location
7615 size
+= size_of_uleb128 (AT_unsigned (a
));
7620 case dw_val_class_const_double
:
7621 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7622 if (HOST_BITS_PER_WIDE_INT
>= 64)
7625 case dw_val_class_vec
:
7626 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7627 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7628 + a
->dw_attr_val
.v
.val_vec
.length
7629 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7631 case dw_val_class_flag
:
7632 if (dwarf_version
>= 4)
7633 /* Currently all add_AT_flag calls pass in 1 as last argument,
7634 so DW_FORM_flag_present can be used. If that ever changes,
7635 we'll need to use DW_FORM_flag and have some optimization
7636 in build_abbrev_table that will change those to
7637 DW_FORM_flag_present if it is set to 1 in all DIEs using
7638 the same abbrev entry. */
7639 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7643 case dw_val_class_die_ref
:
7644 if (AT_ref_external (a
))
7646 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7647 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7648 is sized by target address length, whereas in DWARF3
7649 it's always sized as an offset. */
7650 if (use_debug_types
)
7651 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7652 else if (dwarf_version
== 2)
7653 size
+= DWARF2_ADDR_SIZE
;
7655 size
+= DWARF_OFFSET_SIZE
;
7658 size
+= DWARF_OFFSET_SIZE
;
7660 case dw_val_class_fde_ref
:
7661 size
+= DWARF_OFFSET_SIZE
;
7663 case dw_val_class_lbl_id
:
7664 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7666 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7667 size
+= size_of_uleb128 (AT_index (a
));
7670 size
+= DWARF2_ADDR_SIZE
;
7672 case dw_val_class_lineptr
:
7673 case dw_val_class_macptr
:
7674 size
+= DWARF_OFFSET_SIZE
;
7676 case dw_val_class_str
:
7677 form
= AT_string_form (a
);
7678 if (form
== DW_FORM_strp
)
7679 size
+= DWARF_OFFSET_SIZE
;
7680 else if (form
== DW_FORM_GNU_str_index
)
7681 size
+= size_of_uleb128 (AT_index (a
));
7683 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7685 case dw_val_class_file
:
7686 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7688 case dw_val_class_data8
:
7691 case dw_val_class_vms_delta
:
7692 size
+= DWARF_OFFSET_SIZE
;
7694 case dw_val_class_high_pc
:
7695 size
+= DWARF2_ADDR_SIZE
;
7705 /* Size the debugging information associated with a given DIE. Visits the
7706 DIE's children recursively. Updates the global variable next_die_offset, on
7707 each time through. Uses the current value of next_die_offset to update the
7708 die_offset field in each DIE. */
7711 calc_die_sizes (dw_die_ref die
)
7715 gcc_assert (die
->die_offset
== 0
7716 || (unsigned long int) die
->die_offset
== next_die_offset
);
7717 die
->die_offset
= next_die_offset
;
7718 next_die_offset
+= size_of_die (die
);
7720 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7722 if (die
->die_child
!= NULL
)
7723 /* Count the null byte used to terminate sibling lists. */
7724 next_die_offset
+= 1;
7727 /* Size just the base type children at the start of the CU.
7728 This is needed because build_abbrev needs to size locs
7729 and sizing of type based stack ops needs to know die_offset
7730 values for the base types. */
7733 calc_base_type_die_sizes (void)
7735 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7737 dw_die_ref base_type
;
7738 #if ENABLE_ASSERT_CHECKING
7739 dw_die_ref prev
= comp_unit_die ()->die_child
;
7742 die_offset
+= size_of_die (comp_unit_die ());
7743 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7745 #if ENABLE_ASSERT_CHECKING
7746 gcc_assert (base_type
->die_offset
== 0
7747 && prev
->die_sib
== base_type
7748 && base_type
->die_child
== NULL
7749 && base_type
->die_abbrev
);
7752 base_type
->die_offset
= die_offset
;
7753 die_offset
+= size_of_die (base_type
);
7757 /* Set the marks for a die and its children. We do this so
7758 that we know whether or not a reference needs to use FORM_ref_addr; only
7759 DIEs in the same CU will be marked. We used to clear out the offset
7760 and use that as the flag, but ran into ordering problems. */
7763 mark_dies (dw_die_ref die
)
7767 gcc_assert (!die
->die_mark
);
7770 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7773 /* Clear the marks for a die and its children. */
7776 unmark_dies (dw_die_ref die
)
7780 if (! use_debug_types
)
7781 gcc_assert (die
->die_mark
);
7784 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7787 /* Clear the marks for a die, its children and referred dies. */
7790 unmark_all_dies (dw_die_ref die
)
7800 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7802 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7803 if (AT_class (a
) == dw_val_class_die_ref
)
7804 unmark_all_dies (AT_ref (a
));
7807 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7808 generated for the compilation unit. */
7810 static unsigned long
7811 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
7817 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7818 FOR_EACH_VEC_ELT (*names
, i
, p
)
7819 if (names
!= pubtype_table
7820 || p
->die
->die_offset
!= 0
7821 || !flag_eliminate_unused_debug_types
)
7822 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7824 size
+= DWARF_OFFSET_SIZE
;
7828 /* Return the size of the information in the .debug_aranges section. */
7830 static unsigned long
7831 size_of_aranges (void)
7835 size
= DWARF_ARANGES_HEADER_SIZE
;
7837 /* Count the address/length pair for this compilation unit. */
7838 if (text_section_used
)
7839 size
+= 2 * DWARF2_ADDR_SIZE
;
7840 if (cold_text_section_used
)
7841 size
+= 2 * DWARF2_ADDR_SIZE
;
7842 if (have_multiple_function_sections
)
7847 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
7849 if (!fde
->in_std_section
)
7850 size
+= 2 * DWARF2_ADDR_SIZE
;
7851 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
7852 size
+= 2 * DWARF2_ADDR_SIZE
;
7856 /* Count the two zero words used to terminated the address range table. */
7857 size
+= 2 * DWARF2_ADDR_SIZE
;
7861 /* Select the encoding of an attribute value. */
7863 static enum dwarf_form
7864 value_format (dw_attr_ref a
)
7866 switch (AT_class (a
))
7868 case dw_val_class_addr
:
7869 /* Only very few attributes allow DW_FORM_addr. */
7874 case DW_AT_entry_pc
:
7875 case DW_AT_trampoline
:
7876 return (AT_index (a
) == NOT_INDEXED
7877 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
7881 switch (DWARF2_ADDR_SIZE
)
7884 return DW_FORM_data1
;
7886 return DW_FORM_data2
;
7888 return DW_FORM_data4
;
7890 return DW_FORM_data8
;
7894 case dw_val_class_range_list
:
7895 case dw_val_class_loc_list
:
7896 if (dwarf_version
>= 4)
7897 return DW_FORM_sec_offset
;
7899 case dw_val_class_vms_delta
:
7900 case dw_val_class_offset
:
7901 switch (DWARF_OFFSET_SIZE
)
7904 return DW_FORM_data4
;
7906 return DW_FORM_data8
;
7910 case dw_val_class_loc
:
7911 if (dwarf_version
>= 4)
7912 return DW_FORM_exprloc
;
7913 switch (constant_size (size_of_locs (AT_loc (a
))))
7916 return DW_FORM_block1
;
7918 return DW_FORM_block2
;
7920 return DW_FORM_block4
;
7924 case dw_val_class_const
:
7925 return DW_FORM_sdata
;
7926 case dw_val_class_unsigned_const
:
7927 switch (constant_size (AT_unsigned (a
)))
7930 return DW_FORM_data1
;
7932 return DW_FORM_data2
;
7934 /* In DWARF3 DW_AT_data_member_location with
7935 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
7936 constant, so we need to use DW_FORM_udata if we need
7937 a large constant. */
7938 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7939 return DW_FORM_udata
;
7940 return DW_FORM_data4
;
7942 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7943 return DW_FORM_udata
;
7944 return DW_FORM_data8
;
7948 case dw_val_class_const_double
:
7949 switch (HOST_BITS_PER_WIDE_INT
)
7952 return DW_FORM_data2
;
7954 return DW_FORM_data4
;
7956 return DW_FORM_data8
;
7959 return DW_FORM_block1
;
7961 case dw_val_class_vec
:
7962 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
7963 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
7966 return DW_FORM_block1
;
7968 return DW_FORM_block2
;
7970 return DW_FORM_block4
;
7974 case dw_val_class_flag
:
7975 if (dwarf_version
>= 4)
7977 /* Currently all add_AT_flag calls pass in 1 as last argument,
7978 so DW_FORM_flag_present can be used. If that ever changes,
7979 we'll need to use DW_FORM_flag and have some optimization
7980 in build_abbrev_table that will change those to
7981 DW_FORM_flag_present if it is set to 1 in all DIEs using
7982 the same abbrev entry. */
7983 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7984 return DW_FORM_flag_present
;
7986 return DW_FORM_flag
;
7987 case dw_val_class_die_ref
:
7988 if (AT_ref_external (a
))
7989 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
7992 case dw_val_class_fde_ref
:
7993 return DW_FORM_data
;
7994 case dw_val_class_lbl_id
:
7995 return (AT_index (a
) == NOT_INDEXED
7996 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
7997 case dw_val_class_lineptr
:
7998 case dw_val_class_macptr
:
7999 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8000 case dw_val_class_str
:
8001 return AT_string_form (a
);
8002 case dw_val_class_file
:
8003 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8006 return DW_FORM_data1
;
8008 return DW_FORM_data2
;
8010 return DW_FORM_data4
;
8015 case dw_val_class_data8
:
8016 return DW_FORM_data8
;
8018 case dw_val_class_high_pc
:
8019 switch (DWARF2_ADDR_SIZE
)
8022 return DW_FORM_data1
;
8024 return DW_FORM_data2
;
8026 return DW_FORM_data4
;
8028 return DW_FORM_data8
;
8038 /* Output the encoding of an attribute value. */
8041 output_value_format (dw_attr_ref a
)
8043 enum dwarf_form form
= value_format (a
);
8045 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8048 /* Given a die and id, produce the appropriate abbreviations. */
8051 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8056 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8057 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8058 dwarf_tag_name (abbrev
->die_tag
));
8060 if (abbrev
->die_child
!= NULL
)
8061 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8063 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8065 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8067 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8068 dwarf_attr_name (a_attr
->dw_attr
));
8069 output_value_format (a_attr
);
8072 dw2_asm_output_data (1, 0, NULL
);
8073 dw2_asm_output_data (1, 0, NULL
);
8077 /* Output the .debug_abbrev section which defines the DIE abbreviation
8081 output_abbrev_section (void)
8083 unsigned long abbrev_id
;
8085 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8086 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8088 /* Terminate the table. */
8089 dw2_asm_output_data (1, 0, NULL
);
8092 /* Output a symbol we can use to refer to this DIE from another CU. */
8095 output_die_symbol (dw_die_ref die
)
8097 const char *sym
= die
->die_id
.die_symbol
;
8099 gcc_assert (!die
->comdat_type_p
);
8104 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8105 /* We make these global, not weak; if the target doesn't support
8106 .linkonce, it doesn't support combining the sections, so debugging
8108 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8110 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8113 /* Return a new location list, given the begin and end range, and the
8116 static inline dw_loc_list_ref
8117 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8118 const char *section
)
8120 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8122 retlist
->begin
= begin
;
8123 retlist
->begin_entry
= NULL
;
8125 retlist
->expr
= expr
;
8126 retlist
->section
= section
;
8131 /* Generate a new internal symbol for this location list node, if it
8132 hasn't got one yet. */
8135 gen_llsym (dw_loc_list_ref list
)
8137 gcc_assert (!list
->ll_symbol
);
8138 list
->ll_symbol
= gen_internal_sym ("LLST");
8141 /* Output the location list given to us. */
8144 output_loc_list (dw_loc_list_ref list_head
)
8146 dw_loc_list_ref curr
= list_head
;
8148 if (list_head
->emitted
)
8150 list_head
->emitted
= true;
8152 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8154 /* Walk the location list, and output each range + expression. */
8155 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8158 /* Don't output an entry that starts and ends at the same address. */
8159 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8161 size
= size_of_locs (curr
->expr
);
8162 /* If the expression is too large, drop it on the floor. We could
8163 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8164 in the expression, but >= 64KB expressions for a single value
8165 in a single range are unlikely very useful. */
8168 if (dwarf_split_debug_info
)
8170 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8171 "Location list start/length entry (%s)",
8172 list_head
->ll_symbol
);
8173 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8174 "Location list range start index (%s)",
8176 /* The length field is 4 bytes. If we ever need to support
8177 an 8-byte length, we can add a new DW_LLE code or fall back
8178 to DW_LLE_GNU_start_end_entry. */
8179 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8180 "Location list range length (%s)",
8181 list_head
->ll_symbol
);
8183 else if (!have_multiple_function_sections
)
8185 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8186 "Location list begin address (%s)",
8187 list_head
->ll_symbol
);
8188 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8189 "Location list end address (%s)",
8190 list_head
->ll_symbol
);
8194 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8195 "Location list begin address (%s)",
8196 list_head
->ll_symbol
);
8197 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8198 "Location list end address (%s)",
8199 list_head
->ll_symbol
);
8202 /* Output the block length for this list of location operations. */
8203 gcc_assert (size
<= 0xffff);
8204 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8206 output_loc_sequence (curr
->expr
, -1);
8209 if (dwarf_split_debug_info
)
8210 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8211 "Location list terminator (%s)",
8212 list_head
->ll_symbol
);
8215 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8216 "Location list terminator begin (%s)",
8217 list_head
->ll_symbol
);
8218 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8219 "Location list terminator end (%s)",
8220 list_head
->ll_symbol
);
8224 /* Output a range_list offset into the debug_range section. Emit a
8225 relocated reference if val_entry is NULL, otherwise, emit an
8226 indirect reference. */
8229 output_range_list_offset (dw_attr_ref a
)
8231 const char *name
= dwarf_attr_name (a
->dw_attr
);
8233 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8235 char *p
= strchr (ranges_section_label
, '\0');
8236 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8237 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8238 debug_ranges_section
, "%s", name
);
8242 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8243 "%s (offset from %s)", name
, ranges_section_label
);
8246 /* Output the offset into the debug_loc section. */
8249 output_loc_list_offset (dw_attr_ref a
)
8251 char *sym
= AT_loc_list (a
)->ll_symbol
;
8254 if (dwarf_split_debug_info
)
8255 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8256 "%s", dwarf_attr_name (a
->dw_attr
));
8258 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8259 "%s", dwarf_attr_name (a
->dw_attr
));
8262 /* Output an attribute's index or value appropriately. */
8265 output_attr_index_or_value (dw_attr_ref a
)
8267 const char *name
= dwarf_attr_name (a
->dw_attr
);
8269 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8271 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8274 switch (AT_class (a
))
8276 case dw_val_class_addr
:
8277 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8279 case dw_val_class_high_pc
:
8280 case dw_val_class_lbl_id
:
8281 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8283 case dw_val_class_loc_list
:
8284 output_loc_list_offset (a
);
8291 /* Output a type signature. */
8294 output_signature (const char *sig
, const char *name
)
8298 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8299 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8302 /* Output the DIE and its attributes. Called recursively to generate
8303 the definitions of each child DIE. */
8306 output_die (dw_die_ref die
)
8313 /* If someone in another CU might refer to us, set up a symbol for
8314 them to point to. */
8315 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8316 output_die_symbol (die
);
8318 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8319 (unsigned long)die
->die_offset
,
8320 dwarf_tag_name (die
->die_tag
));
8322 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8324 const char *name
= dwarf_attr_name (a
->dw_attr
);
8326 switch (AT_class (a
))
8328 case dw_val_class_addr
:
8329 output_attr_index_or_value (a
);
8332 case dw_val_class_offset
:
8333 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8337 case dw_val_class_range_list
:
8338 output_range_list_offset (a
);
8341 case dw_val_class_loc
:
8342 size
= size_of_locs (AT_loc (a
));
8344 /* Output the block length for this list of location operations. */
8345 if (dwarf_version
>= 4)
8346 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8348 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8350 output_loc_sequence (AT_loc (a
), -1);
8353 case dw_val_class_const
:
8354 /* ??? It would be slightly more efficient to use a scheme like is
8355 used for unsigned constants below, but gdb 4.x does not sign
8356 extend. Gdb 5.x does sign extend. */
8357 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8360 case dw_val_class_unsigned_const
:
8362 int csize
= constant_size (AT_unsigned (a
));
8363 if (dwarf_version
== 3
8364 && a
->dw_attr
== DW_AT_data_member_location
8366 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8368 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8372 case dw_val_class_const_double
:
8374 unsigned HOST_WIDE_INT first
, second
;
8376 if (HOST_BITS_PER_WIDE_INT
>= 64)
8377 dw2_asm_output_data (1,
8378 HOST_BITS_PER_DOUBLE_INT
8379 / HOST_BITS_PER_CHAR
,
8382 if (WORDS_BIG_ENDIAN
)
8384 first
= a
->dw_attr_val
.v
.val_double
.high
;
8385 second
= a
->dw_attr_val
.v
.val_double
.low
;
8389 first
= a
->dw_attr_val
.v
.val_double
.low
;
8390 second
= a
->dw_attr_val
.v
.val_double
.high
;
8393 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8395 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8400 case dw_val_class_vec
:
8402 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8403 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8407 dw2_asm_output_data (constant_size (len
* elt_size
),
8408 len
* elt_size
, "%s", name
);
8409 if (elt_size
> sizeof (HOST_WIDE_INT
))
8414 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8417 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8418 "fp or vector constant word %u", i
);
8422 case dw_val_class_flag
:
8423 if (dwarf_version
>= 4)
8425 /* Currently all add_AT_flag calls pass in 1 as last argument,
8426 so DW_FORM_flag_present can be used. If that ever changes,
8427 we'll need to use DW_FORM_flag and have some optimization
8428 in build_abbrev_table that will change those to
8429 DW_FORM_flag_present if it is set to 1 in all DIEs using
8430 the same abbrev entry. */
8431 gcc_assert (AT_flag (a
) == 1);
8433 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8434 ASM_COMMENT_START
, name
);
8437 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8440 case dw_val_class_loc_list
:
8441 output_attr_index_or_value (a
);
8444 case dw_val_class_die_ref
:
8445 if (AT_ref_external (a
))
8447 if (AT_ref (a
)->comdat_type_p
)
8449 comdat_type_node_ref type_node
=
8450 AT_ref (a
)->die_id
.die_type_node
;
8452 gcc_assert (type_node
);
8453 output_signature (type_node
->signature
, name
);
8457 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8461 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8462 length, whereas in DWARF3 it's always sized as an
8464 if (dwarf_version
== 2)
8465 size
= DWARF2_ADDR_SIZE
;
8467 size
= DWARF_OFFSET_SIZE
;
8468 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8474 gcc_assert (AT_ref (a
)->die_offset
);
8475 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8480 case dw_val_class_fde_ref
:
8484 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8485 a
->dw_attr_val
.v
.val_fde_index
* 2);
8486 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8491 case dw_val_class_vms_delta
:
8492 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8493 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8497 case dw_val_class_lbl_id
:
8498 output_attr_index_or_value (a
);
8501 case dw_val_class_lineptr
:
8502 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8503 debug_line_section
, "%s", name
);
8506 case dw_val_class_macptr
:
8507 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8508 debug_macinfo_section
, "%s", name
);
8511 case dw_val_class_str
:
8512 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8513 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8514 a
->dw_attr_val
.v
.val_str
->label
,
8516 "%s: \"%s\"", name
, AT_string (a
));
8517 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8518 dw2_asm_output_data_uleb128 (AT_index (a
),
8519 "%s: \"%s\"", name
, AT_string (a
));
8521 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8524 case dw_val_class_file
:
8526 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8528 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8529 a
->dw_attr_val
.v
.val_file
->filename
);
8533 case dw_val_class_data8
:
8537 for (i
= 0; i
< 8; i
++)
8538 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8539 i
== 0 ? "%s" : NULL
, name
);
8543 case dw_val_class_high_pc
:
8544 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8545 get_AT_low_pc (die
), "DW_AT_high_pc");
8553 FOR_EACH_CHILD (die
, c
, output_die (c
));
8555 /* Add null byte to terminate sibling list. */
8556 if (die
->die_child
!= NULL
)
8557 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8558 (unsigned long) die
->die_offset
);
8561 /* Output the compilation unit that appears at the beginning of the
8562 .debug_info section, and precedes the DIE descriptions. */
8565 output_compilation_unit_header (void)
8567 int ver
= dwarf_version
;
8569 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8570 dw2_asm_output_data (4, 0xffffffff,
8571 "Initial length escape value indicating 64-bit DWARF extension");
8572 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8573 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8574 "Length of Compilation Unit Info");
8575 dw2_asm_output_data (2, ver
, "DWARF version number");
8576 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8577 debug_abbrev_section
,
8578 "Offset Into Abbrev. Section");
8579 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8582 /* Output the compilation unit DIE and its children. */
8585 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8587 const char *secname
, *oldsym
;
8591 /* Unless we are outputting main CU, we may throw away empty ones. */
8592 if (!output_if_empty
&& die
->die_child
== NULL
)
8595 /* Even if there are no children of this DIE, we must output the information
8596 about the compilation unit. Otherwise, on an empty translation unit, we
8597 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8598 will then complain when examining the file. First mark all the DIEs in
8599 this CU so we know which get local refs. */
8602 extern_map
= optimize_external_refs (die
);
8604 build_abbrev_table (die
, extern_map
);
8606 htab_delete (extern_map
);
8608 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8609 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8610 calc_die_sizes (die
);
8612 oldsym
= die
->die_id
.die_symbol
;
8615 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8617 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8619 die
->die_id
.die_symbol
= NULL
;
8620 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8624 switch_to_section (debug_info_section
);
8625 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8626 info_section_emitted
= true;
8629 /* Output debugging information. */
8630 output_compilation_unit_header ();
8633 /* Leave the marks on the main CU, so we can check them in
8638 die
->die_id
.die_symbol
= oldsym
;
8642 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8643 and .debug_pubtypes. This is configured per-target, but can be
8644 overridden by the -gpubnames or -gno-pubnames options. */
8647 want_pubnames (void)
8649 return (debug_generate_pub_sections
!= -1
8650 ? debug_generate_pub_sections
8651 : targetm
.want_debug_pub_sections
);
8654 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8657 add_AT_pubnames (dw_die_ref die
)
8659 if (want_pubnames ())
8660 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8663 /* Helper function to generate top-level dies for skeleton debug_info and
8667 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8669 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8672 add_comp_dir_attribute (die
);
8673 add_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8674 /* The specification suggests that these attributes be inline to avoid
8675 having a .debug_str section. We know that they exist in the die because
8676 we just added them. */
8677 attr
= get_AT (die
, DW_AT_GNU_dwo_name
);
8678 attr
->dw_attr_val
.v
.val_str
->form
= DW_FORM_string
;
8679 attr
= get_AT (die
, DW_AT_comp_dir
);
8680 attr
->dw_attr_val
.v
.val_str
->form
= DW_FORM_string
;
8682 add_AT_pubnames (die
);
8683 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8686 /* Return the single type-unit die for skeleton type units. */
8689 get_skeleton_type_unit (void)
8691 /* For dwarf_split_debug_sections with use_type info, all type units in the
8692 skeleton sections have identical dies (but different headers). This
8693 single die will be output many times. */
8695 static dw_die_ref skeleton_type_unit
= NULL
;
8697 if (skeleton_type_unit
== NULL
)
8699 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8700 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8701 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8703 return skeleton_type_unit
;
8706 /* Output skeleton debug sections that point to the dwo file. */
8709 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8711 /* These attributes will be found in the full debug_info section. */
8712 remove_AT (comp_unit
, DW_AT_producer
);
8713 remove_AT (comp_unit
, DW_AT_language
);
8715 /* Add attributes common to skeleton compile_units and type_units. */
8716 add_top_level_skeleton_die_attrs (comp_unit
);
8718 switch_to_section (debug_skeleton_info_section
);
8719 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8721 /* Produce the skeleton compilation-unit header. This one differs enough from
8722 a normal CU header that it's better not to call output_compilation_unit
8724 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8725 dw2_asm_output_data (4, 0xffffffff,
8726 "Initial length escape value indicating 64-bit DWARF extension");
8728 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8729 DWARF_COMPILE_UNIT_HEADER_SIZE
8730 - DWARF_INITIAL_LENGTH_SIZE
8731 + size_of_die (comp_unit
),
8732 "Length of Compilation Unit Info");
8733 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8734 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8735 debug_abbrev_section
,
8736 "Offset Into Abbrev. Section");
8737 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8739 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8740 output_die (comp_unit
);
8742 /* Build the skeleton debug_abbrev section. */
8743 switch_to_section (debug_skeleton_abbrev_section
);
8744 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8746 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8747 if (use_debug_types
)
8748 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8750 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8753 /* Output a comdat type unit DIE and its children. */
8756 output_comdat_type_unit (comdat_type_node
*node
)
8758 const char *secname
;
8761 #if defined (OBJECT_FORMAT_ELF)
8766 /* First mark all the DIEs in this CU so we know which get local refs. */
8767 mark_dies (node
->root_die
);
8769 extern_map
= optimize_external_refs (node
->root_die
);
8771 build_abbrev_table (node
->root_die
, extern_map
);
8773 htab_delete (extern_map
);
8775 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8776 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8777 calc_die_sizes (node
->root_die
);
8779 #if defined (OBJECT_FORMAT_ELF)
8780 if (!dwarf_split_debug_info
)
8781 secname
= ".debug_types";
8783 secname
= ".debug_types.dwo";
8785 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8786 sprintf (tmp
, "wt.");
8787 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8788 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8789 comdat_key
= get_identifier (tmp
);
8790 targetm
.asm_out
.named_section (secname
,
8791 SECTION_DEBUG
| SECTION_LINKONCE
,
8794 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8795 sprintf (tmp
, ".gnu.linkonce.wt.");
8796 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8797 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8799 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8802 /* Output debugging information. */
8803 output_compilation_unit_header ();
8804 output_signature (node
->signature
, "Type Signature");
8805 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8806 "Offset to Type DIE");
8807 output_die (node
->root_die
);
8809 unmark_dies (node
->root_die
);
8811 #if defined (OBJECT_FORMAT_ELF)
8812 if (dwarf_split_debug_info
)
8814 /* Produce the skeleton type-unit header. */
8815 const char *secname
= ".debug_types";
8817 targetm
.asm_out
.named_section (secname
,
8818 SECTION_DEBUG
| SECTION_LINKONCE
,
8820 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8821 dw2_asm_output_data (4, 0xffffffff,
8822 "Initial length escape value indicating 64-bit DWARF extension");
8824 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8825 DWARF_COMPILE_UNIT_HEADER_SIZE
8826 - DWARF_INITIAL_LENGTH_SIZE
8827 + size_of_die (get_skeleton_type_unit ())
8828 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
8829 "Length of Type Unit Info");
8830 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8831 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8832 debug_skeleton_abbrev_section_label
,
8833 debug_abbrev_section
,
8834 "Offset Into Abbrev. Section");
8835 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8836 output_signature (node
->signature
, "Type Signature");
8837 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
8839 output_die (get_skeleton_type_unit ());
8844 /* Return the DWARF2/3 pubname associated with a decl. */
8847 dwarf2_name (tree decl
, int scope
)
8849 if (DECL_NAMELESS (decl
))
8851 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8854 /* Add a new entry to .debug_pubnames if appropriate. */
8857 add_pubname_string (const char *str
, dw_die_ref die
)
8862 e
.name
= xstrdup (str
);
8863 vec_safe_push (pubname_table
, e
);
8867 add_pubname (tree decl
, dw_die_ref die
)
8869 if (!want_pubnames ())
8872 /* Don't add items to the table when we expect that the consumer will have
8873 just read the enclosing die. For example, if the consumer is looking at a
8874 class_member, it will either be inside the class already, or will have just
8875 looked up the class to find the member. Either way, searching the class is
8876 faster than searching the index. */
8877 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
8878 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8880 const char *name
= dwarf2_name (decl
, 1);
8883 add_pubname_string (name
, die
);
8887 /* Add an enumerator to the pubnames section. */
8890 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
8894 gcc_assert (scope_name
);
8895 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
8897 vec_safe_push (pubname_table
, e
);
8900 /* Add a new entry to .debug_pubtypes if appropriate. */
8903 add_pubtype (tree decl
, dw_die_ref die
)
8907 if (!want_pubnames ())
8910 if ((TREE_PUBLIC (decl
)
8911 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8912 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8915 const char *scope_name
= "";
8916 const char *sep
= is_cxx () ? "::" : ".";
8919 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
8920 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
8922 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
8923 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
8924 scope_name
= concat (scope_name
, sep
, NULL
);
8930 name
= type_tag (decl
);
8932 name
= lang_hooks
.dwarf_name (decl
, 1);
8934 /* If we don't have a name for the type, there's no point in adding
8936 if (name
!= NULL
&& name
[0] != '\0')
8939 e
.name
= concat (scope_name
, name
, NULL
);
8940 vec_safe_push (pubtype_table
, e
);
8943 /* Although it might be more consistent to add the pubinfo for the
8944 enumerators as their dies are created, they should only be added if the
8945 enum type meets the criteria above. So rather than re-check the parent
8946 enum type whenever an enumerator die is created, just output them all
8947 here. This isn't protected by the name conditional because anonymous
8948 enums don't have names. */
8949 if (die
->die_tag
== DW_TAG_enumeration_type
)
8953 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
8958 /* Output the public names table used to speed up access to externally
8959 visible names; or the public types table used to find type definitions. */
8962 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8965 unsigned long pubnames_length
= size_of_pubnames (names
);
8968 if (!want_pubnames () || !info_section_emitted
)
8970 if (names
== pubname_table
)
8971 switch_to_section (debug_pubnames_section
);
8973 switch_to_section (debug_pubtypes_section
);
8974 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8975 dw2_asm_output_data (4, 0xffffffff,
8976 "Initial length escape value indicating 64-bit DWARF extension");
8977 if (names
== pubname_table
)
8978 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8979 "Length of Public Names Info");
8981 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
8982 "Length of Public Type Names Info");
8983 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
8984 dw2_asm_output_data (2, 2, "DWARF Version");
8985 if (dwarf_split_debug_info
)
8986 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
8987 debug_skeleton_info_section
,
8988 "Offset of Compilation Unit Info");
8990 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
8992 "Offset of Compilation Unit Info");
8993 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
8994 "Compilation Unit Length");
8996 FOR_EACH_VEC_ELT (*names
, i
, pub
)
8998 /* Enumerator names are part of the pubname table, but the parent
8999 DW_TAG_enumeration_type die may have been pruned. Don't output
9000 them if that is the case. */
9001 if (pub
->die
->die_tag
== DW_TAG_enumerator
&& !pub
->die
->die_mark
)
9004 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9005 if (names
== pubname_table
)
9006 gcc_assert (pub
->die
->die_mark
);
9008 if (names
!= pubtype_table
9009 || pub
->die
->die_offset
!= 0
9010 || !flag_eliminate_unused_debug_types
)
9012 dw_offset die_offset
= pub
->die
->die_offset
;
9014 /* If we're putting types in their own .debug_types sections,
9015 the .debug_pubtypes table will still point to the compile
9016 unit (not the type unit), so we want to use the offset of
9017 the skeleton DIE (if there is one). */
9018 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9020 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9022 if (type_node
!= NULL
)
9023 die_offset
= (type_node
->skeleton_die
!= NULL
9024 ? type_node
->skeleton_die
->die_offset
9028 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9030 dw2_asm_output_nstring (pub
->name
, -1, "external name");
9034 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9037 /* Output the information that goes into the .debug_aranges table.
9038 Namely, define the beginning and ending address range of the
9039 text section generated for this compilation unit. */
9042 output_aranges (unsigned long aranges_length
)
9046 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9047 dw2_asm_output_data (4, 0xffffffff,
9048 "Initial length escape value indicating 64-bit DWARF extension");
9049 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9050 "Length of Address Ranges Info");
9051 /* Version number for aranges is still 2, even in DWARF3. */
9052 dw2_asm_output_data (2, 2, "DWARF Version");
9053 if (dwarf_split_debug_info
)
9054 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9055 debug_skeleton_info_section
,
9056 "Offset of Compilation Unit Info");
9058 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9060 "Offset of Compilation Unit Info");
9061 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9062 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9064 /* We need to align to twice the pointer size here. */
9065 if (DWARF_ARANGES_PAD_SIZE
)
9067 /* Pad using a 2 byte words so that padding is correct for any
9069 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9070 2 * DWARF2_ADDR_SIZE
);
9071 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9072 dw2_asm_output_data (2, 0, NULL
);
9075 /* It is necessary not to output these entries if the sections were
9076 not used; if the sections were not used, the length will be 0 and
9077 the address may end up as 0 if the section is discarded by ld
9078 --gc-sections, leaving an invalid (0, 0) entry that can be
9079 confused with the terminator. */
9080 if (text_section_used
)
9082 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9083 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9084 text_section_label
, "Length");
9086 if (cold_text_section_used
)
9088 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9090 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9091 cold_text_section_label
, "Length");
9094 if (have_multiple_function_sections
)
9099 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9101 if (DECL_IGNORED_P (fde
->decl
))
9103 if (!fde
->in_std_section
)
9105 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9107 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9108 fde
->dw_fde_begin
, "Length");
9110 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9112 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9114 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9115 fde
->dw_fde_second_begin
, "Length");
9120 /* Output the terminator words. */
9121 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9122 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9125 /* Add a new entry to .debug_ranges. Return the offset at which it
9129 add_ranges_num (int num
)
9131 unsigned int in_use
= ranges_table_in_use
;
9133 if (in_use
== ranges_table_allocated
)
9135 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9136 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9137 ranges_table_allocated
);
9138 memset (ranges_table
+ ranges_table_in_use
, 0,
9139 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9142 ranges_table
[in_use
].num
= num
;
9143 ranges_table_in_use
= in_use
+ 1;
9145 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9148 /* Add a new entry to .debug_ranges corresponding to a block, or a
9149 range terminator if BLOCK is NULL. */
9152 add_ranges (const_tree block
)
9154 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9157 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9158 When using dwarf_split_debug_info, address attributes in dies destined
9159 for the final executable should be direct references--setting the
9160 parameter force_direct ensures this behavior. */
9163 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9164 bool *added
, bool force_direct
)
9166 unsigned int in_use
= ranges_by_label_in_use
;
9167 unsigned int offset
;
9169 if (in_use
== ranges_by_label_allocated
)
9171 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9172 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9174 ranges_by_label_allocated
);
9175 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9176 RANGES_TABLE_INCREMENT
9177 * sizeof (struct dw_ranges_by_label_struct
));
9180 ranges_by_label
[in_use
].begin
= begin
;
9181 ranges_by_label
[in_use
].end
= end
;
9182 ranges_by_label_in_use
= in_use
+ 1;
9184 offset
= add_ranges_num (-(int)in_use
- 1);
9187 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9193 output_ranges (void)
9196 static const char *const start_fmt
= "Offset %#x";
9197 const char *fmt
= start_fmt
;
9199 for (i
= 0; i
< ranges_table_in_use
; i
++)
9201 int block_num
= ranges_table
[i
].num
;
9205 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9206 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9208 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9209 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9211 /* If all code is in the text section, then the compilation
9212 unit base address defaults to DW_AT_low_pc, which is the
9213 base of the text section. */
9214 if (!have_multiple_function_sections
)
9216 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9218 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9219 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9220 text_section_label
, NULL
);
9223 /* Otherwise, the compilation unit base address is zero,
9224 which allows us to use absolute addresses, and not worry
9225 about whether the target supports cross-section
9229 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9230 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9231 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9237 /* Negative block_num stands for an index into ranges_by_label. */
9238 else if (block_num
< 0)
9240 int lab_idx
= - block_num
- 1;
9242 if (!have_multiple_function_sections
)
9246 /* If we ever use add_ranges_by_labels () for a single
9247 function section, all we have to do is to take out
9249 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9250 ranges_by_label
[lab_idx
].begin
,
9252 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9253 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9254 ranges_by_label
[lab_idx
].end
,
9255 text_section_label
, NULL
);
9260 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9261 ranges_by_label
[lab_idx
].begin
,
9262 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9263 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9264 ranges_by_label
[lab_idx
].end
,
9270 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9271 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9277 /* Data structure containing information about input files. */
9280 const char *path
; /* Complete file name. */
9281 const char *fname
; /* File name part. */
9282 int length
; /* Length of entire string. */
9283 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9284 int dir_idx
; /* Index in directory table. */
9287 /* Data structure containing information about directories with source
9291 const char *path
; /* Path including directory name. */
9292 int length
; /* Path length. */
9293 int prefix
; /* Index of directory entry which is a prefix. */
9294 int count
; /* Number of files in this directory. */
9295 int dir_idx
; /* Index of directory used as base. */
9298 /* Callback function for file_info comparison. We sort by looking at
9299 the directories in the path. */
9302 file_info_cmp (const void *p1
, const void *p2
)
9304 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9305 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9306 const unsigned char *cp1
;
9307 const unsigned char *cp2
;
9309 /* Take care of file names without directories. We need to make sure that
9310 we return consistent values to qsort since some will get confused if
9311 we return the same value when identical operands are passed in opposite
9312 orders. So if neither has a directory, return 0 and otherwise return
9313 1 or -1 depending on which one has the directory. */
9314 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9315 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9317 cp1
= (const unsigned char *) s1
->path
;
9318 cp2
= (const unsigned char *) s2
->path
;
9324 /* Reached the end of the first path? If so, handle like above. */
9325 if ((cp1
== (const unsigned char *) s1
->fname
)
9326 || (cp2
== (const unsigned char *) s2
->fname
))
9327 return ((cp2
== (const unsigned char *) s2
->fname
)
9328 - (cp1
== (const unsigned char *) s1
->fname
));
9330 /* Character of current path component the same? */
9331 else if (*cp1
!= *cp2
)
9336 struct file_name_acquire_data
9338 struct file_info
*files
;
9343 /* Traversal function for the hash table. */
9346 file_name_acquire (void ** slot
, void *data
)
9348 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9349 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9350 struct file_info
*fi
;
9353 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9355 if (! d
->emitted_number
)
9358 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9360 fi
= fnad
->files
+ fnad
->used_files
++;
9362 /* Skip all leading "./". */
9364 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9367 /* Create a new array entry. */
9369 fi
->length
= strlen (f
);
9372 /* Search for the file name part. */
9373 f
= strrchr (f
, DIR_SEPARATOR
);
9374 #if defined (DIR_SEPARATOR_2)
9376 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9380 if (f
== NULL
|| f
< g
)
9386 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9390 /* Output the directory table and the file name table. We try to minimize
9391 the total amount of memory needed. A heuristic is used to avoid large
9392 slowdowns with many input files. */
9395 output_file_names (void)
9397 struct file_name_acquire_data fnad
;
9399 struct file_info
*files
;
9400 struct dir_info
*dirs
;
9408 if (!last_emitted_file
)
9410 dw2_asm_output_data (1, 0, "End directory table");
9411 dw2_asm_output_data (1, 0, "End file name table");
9415 numfiles
= last_emitted_file
->emitted_number
;
9417 /* Allocate the various arrays we need. */
9418 files
= XALLOCAVEC (struct file_info
, numfiles
);
9419 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9422 fnad
.used_files
= 0;
9423 fnad
.max_files
= numfiles
;
9424 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9425 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9427 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9429 /* Find all the different directories used. */
9430 dirs
[0].path
= files
[0].path
;
9431 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9432 dirs
[0].prefix
= -1;
9434 dirs
[0].dir_idx
= 0;
9435 files
[0].dir_idx
= 0;
9438 for (i
= 1; i
< numfiles
; i
++)
9439 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9440 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9441 dirs
[ndirs
- 1].length
) == 0)
9443 /* Same directory as last entry. */
9444 files
[i
].dir_idx
= ndirs
- 1;
9445 ++dirs
[ndirs
- 1].count
;
9451 /* This is a new directory. */
9452 dirs
[ndirs
].path
= files
[i
].path
;
9453 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9454 dirs
[ndirs
].count
= 1;
9455 dirs
[ndirs
].dir_idx
= ndirs
;
9456 files
[i
].dir_idx
= ndirs
;
9458 /* Search for a prefix. */
9459 dirs
[ndirs
].prefix
= -1;
9460 for (j
= 0; j
< ndirs
; j
++)
9461 if (dirs
[j
].length
< dirs
[ndirs
].length
9462 && dirs
[j
].length
> 1
9463 && (dirs
[ndirs
].prefix
== -1
9464 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9465 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9466 dirs
[ndirs
].prefix
= j
;
9471 /* Now to the actual work. We have to find a subset of the directories which
9472 allow expressing the file name using references to the directory table
9473 with the least amount of characters. We do not do an exhaustive search
9474 where we would have to check out every combination of every single
9475 possible prefix. Instead we use a heuristic which provides nearly optimal
9476 results in most cases and never is much off. */
9477 saved
= XALLOCAVEC (int, ndirs
);
9478 savehere
= XALLOCAVEC (int, ndirs
);
9480 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9481 for (i
= 0; i
< ndirs
; i
++)
9486 /* We can always save some space for the current directory. But this
9487 does not mean it will be enough to justify adding the directory. */
9488 savehere
[i
] = dirs
[i
].length
;
9489 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9491 for (j
= i
+ 1; j
< ndirs
; j
++)
9494 if (saved
[j
] < dirs
[i
].length
)
9496 /* Determine whether the dirs[i] path is a prefix of the
9501 while (k
!= -1 && k
!= (int) i
)
9506 /* Yes it is. We can possibly save some memory by
9507 writing the filenames in dirs[j] relative to
9509 savehere
[j
] = dirs
[i
].length
;
9510 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9515 /* Check whether we can save enough to justify adding the dirs[i]
9517 if (total
> dirs
[i
].length
+ 1)
9519 /* It's worthwhile adding. */
9520 for (j
= i
; j
< ndirs
; j
++)
9521 if (savehere
[j
] > 0)
9523 /* Remember how much we saved for this directory so far. */
9524 saved
[j
] = savehere
[j
];
9526 /* Remember the prefix directory. */
9527 dirs
[j
].dir_idx
= i
;
9532 /* Emit the directory name table. */
9533 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9534 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9535 dw2_asm_output_nstring (dirs
[i
].path
,
9537 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9538 "Directory Entry: %#x", i
+ idx_offset
);
9540 dw2_asm_output_data (1, 0, "End directory table");
9542 /* We have to emit them in the order of emitted_number since that's
9543 used in the debug info generation. To do this efficiently we
9544 generate a back-mapping of the indices first. */
9545 backmap
= XALLOCAVEC (int, numfiles
);
9546 for (i
= 0; i
< numfiles
; i
++)
9547 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9549 /* Now write all the file names. */
9550 for (i
= 0; i
< numfiles
; i
++)
9552 int file_idx
= backmap
[i
];
9553 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9555 #ifdef VMS_DEBUGGING_INFO
9556 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9558 /* Setting these fields can lead to debugger miscomparisons,
9559 but VMS Debug requires them to be set correctly. */
9564 int maxfilelen
= strlen (files
[file_idx
].path
)
9565 + dirs
[dir_idx
].length
9566 + MAX_VMS_VERSION_LEN
+ 1;
9567 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9569 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9570 snprintf (filebuf
, maxfilelen
, "%s;%d",
9571 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9573 dw2_asm_output_nstring
9574 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9576 /* Include directory index. */
9577 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9579 /* Modification time. */
9580 dw2_asm_output_data_uleb128
9581 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9585 /* File length in bytes. */
9586 dw2_asm_output_data_uleb128
9587 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9591 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9592 "File Entry: %#x", (unsigned) i
+ 1);
9594 /* Include directory index. */
9595 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9597 /* Modification time. */
9598 dw2_asm_output_data_uleb128 (0, NULL
);
9600 /* File length in bytes. */
9601 dw2_asm_output_data_uleb128 (0, NULL
);
9602 #endif /* VMS_DEBUGGING_INFO */
9605 dw2_asm_output_data (1, 0, "End file name table");
9609 /* Output one line number table into the .debug_line section. */
9612 output_one_line_info_table (dw_line_info_table
*table
)
9614 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9615 unsigned int current_line
= 1;
9616 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9617 dw_line_info_entry
*ent
;
9620 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9622 switch (ent
->opcode
)
9624 case LI_set_address
:
9625 /* ??? Unfortunately, we have little choice here currently, and
9626 must always use the most general form. GCC does not know the
9627 address delta itself, so we can't use DW_LNS_advance_pc. Many
9628 ports do have length attributes which will give an upper bound
9629 on the address range. We could perhaps use length attributes
9630 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9631 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9633 /* This can handle any delta. This takes
9634 4+DWARF2_ADDR_SIZE bytes. */
9635 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9636 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9637 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9638 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9642 if (ent
->val
== current_line
)
9644 /* We still need to start a new row, so output a copy insn. */
9645 dw2_asm_output_data (1, DW_LNS_copy
,
9646 "copy line %u", current_line
);
9650 int line_offset
= ent
->val
- current_line
;
9651 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9653 current_line
= ent
->val
;
9654 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9656 /* This can handle deltas from -10 to 234, using the current
9657 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9658 This takes 1 byte. */
9659 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9660 "line %u", current_line
);
9664 /* This can handle any delta. This takes at least 4 bytes,
9665 depending on the value being encoded. */
9666 dw2_asm_output_data (1, DW_LNS_advance_line
,
9667 "advance to line %u", current_line
);
9668 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9669 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9675 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9676 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9680 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9681 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9684 case LI_negate_stmt
:
9685 current_is_stmt
= !current_is_stmt
;
9686 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9687 "is_stmt %d", current_is_stmt
);
9690 case LI_set_prologue_end
:
9691 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9692 "set prologue end");
9695 case LI_set_epilogue_begin
:
9696 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9697 "set epilogue begin");
9700 case LI_set_discriminator
:
9701 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9702 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9703 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9704 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9709 /* Emit debug info for the address of the end of the table. */
9710 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9711 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9712 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9713 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9715 dw2_asm_output_data (1, 0, "end sequence");
9716 dw2_asm_output_data_uleb128 (1, NULL
);
9717 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9720 /* Output the source line number correspondence information. This
9721 information goes into the .debug_line section. */
9724 output_line_info (bool prologue_only
)
9726 char l1
[20], l2
[20], p1
[20], p2
[20];
9727 int ver
= dwarf_version
;
9728 bool saw_one
= false;
9731 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9732 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9733 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9734 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9736 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9737 dw2_asm_output_data (4, 0xffffffff,
9738 "Initial length escape value indicating 64-bit DWARF extension");
9739 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9740 "Length of Source Line Info");
9741 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9743 dw2_asm_output_data (2, ver
, "DWARF Version");
9744 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9745 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9747 /* Define the architecture-dependent minimum instruction length (in bytes).
9748 In this implementation of DWARF, this field is used for information
9749 purposes only. Since GCC generates assembly language, we have no
9750 a priori knowledge of how many instruction bytes are generated for each
9751 source line, and therefore can use only the DW_LNE_set_address and
9752 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9753 this as '1', which is "correct enough" for all architectures,
9754 and don't let the target override. */
9755 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9758 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9759 "Maximum Operations Per Instruction");
9760 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9761 "Default is_stmt_start flag");
9762 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9763 "Line Base Value (Special Opcodes)");
9764 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9765 "Line Range Value (Special Opcodes)");
9766 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9767 "Special Opcode Base");
9769 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9774 case DW_LNS_advance_pc
:
9775 case DW_LNS_advance_line
:
9776 case DW_LNS_set_file
:
9777 case DW_LNS_set_column
:
9778 case DW_LNS_fixed_advance_pc
:
9779 case DW_LNS_set_isa
:
9787 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9791 /* Write out the information about the files we use. */
9792 output_file_names ();
9793 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9796 /* Output the marker for the end of the line number info. */
9797 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9801 if (separate_line_info
)
9803 dw_line_info_table
*table
;
9806 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
9809 output_one_line_info_table (table
);
9813 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9815 output_one_line_info_table (cold_text_section_line_info
);
9819 /* ??? Some Darwin linkers crash on a .debug_line section with no
9820 sequences. Further, merely a DW_LNE_end_sequence entry is not
9821 sufficient -- the address column must also be initialized.
9822 Make sure to output at least one set_address/end_sequence pair,
9823 choosing .text since that section is always present. */
9824 if (text_section_line_info
->in_use
|| !saw_one
)
9825 output_one_line_info_table (text_section_line_info
);
9827 /* Output the marker for the end of the line number info. */
9828 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9831 /* Given a pointer to a tree node for some base type, return a pointer to
9832 a DIE that describes the given type.
9834 This routine must only be called for GCC type nodes that correspond to
9835 Dwarf base (fundamental) types. */
9838 base_type_die (tree type
)
9840 dw_die_ref base_type_result
;
9841 enum dwarf_type encoding
;
9843 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9846 /* If this is a subtype that should not be emitted as a subrange type,
9847 use the base type. See subrange_type_for_debug_p. */
9848 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9849 type
= TREE_TYPE (type
);
9851 switch (TREE_CODE (type
))
9854 if ((dwarf_version
>= 4 || !dwarf_strict
)
9856 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9857 && DECL_IS_BUILTIN (TYPE_NAME (type
))
9858 && DECL_NAME (TYPE_NAME (type
)))
9860 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
9861 if (strcmp (name
, "char16_t") == 0
9862 || strcmp (name
, "char32_t") == 0)
9864 encoding
= DW_ATE_UTF
;
9868 if (TYPE_STRING_FLAG (type
))
9870 if (TYPE_UNSIGNED (type
))
9871 encoding
= DW_ATE_unsigned_char
;
9873 encoding
= DW_ATE_signed_char
;
9875 else if (TYPE_UNSIGNED (type
))
9876 encoding
= DW_ATE_unsigned
;
9878 encoding
= DW_ATE_signed
;
9882 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9884 if (dwarf_version
>= 3 || !dwarf_strict
)
9885 encoding
= DW_ATE_decimal_float
;
9887 encoding
= DW_ATE_lo_user
;
9890 encoding
= DW_ATE_float
;
9893 case FIXED_POINT_TYPE
:
9894 if (!(dwarf_version
>= 3 || !dwarf_strict
))
9895 encoding
= DW_ATE_lo_user
;
9896 else if (TYPE_UNSIGNED (type
))
9897 encoding
= DW_ATE_unsigned_fixed
;
9899 encoding
= DW_ATE_signed_fixed
;
9902 /* Dwarf2 doesn't know anything about complex ints, so use
9903 a user defined type for it. */
9905 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9906 encoding
= DW_ATE_complex_float
;
9908 encoding
= DW_ATE_lo_user
;
9912 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9913 encoding
= DW_ATE_boolean
;
9917 /* No other TREE_CODEs are Dwarf fundamental types. */
9921 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
9923 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9924 int_size_in_bytes (type
));
9925 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9926 add_pubtype (type
, base_type_result
);
9928 return base_type_result
;
9931 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
9932 given input type is a Dwarf "fundamental" type. Otherwise return null. */
9935 is_base_type (tree type
)
9937 switch (TREE_CODE (type
))
9943 case FIXED_POINT_TYPE
:
9951 case QUAL_UNION_TYPE
:
9956 case REFERENCE_TYPE
:
9970 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
9971 node, return the size in bits for the type if it is a constant, or else
9972 return the alignment for the type if the type's size is not constant, or
9973 else return BITS_PER_WORD if the type actually turns out to be an
9976 static inline unsigned HOST_WIDE_INT
9977 simple_type_size_in_bits (const_tree type
)
9979 if (TREE_CODE (type
) == ERROR_MARK
)
9980 return BITS_PER_WORD
;
9981 else if (TYPE_SIZE (type
) == NULL_TREE
)
9983 else if (host_integerp (TYPE_SIZE (type
), 1))
9984 return tree_low_cst (TYPE_SIZE (type
), 1);
9986 return TYPE_ALIGN (type
);
9989 /* Similarly, but return a double_int instead of UHWI. */
9991 static inline double_int
9992 double_int_type_size_in_bits (const_tree type
)
9994 if (TREE_CODE (type
) == ERROR_MARK
)
9995 return double_int::from_uhwi (BITS_PER_WORD
);
9996 else if (TYPE_SIZE (type
) == NULL_TREE
)
9997 return double_int_zero
;
9998 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
9999 return tree_to_double_int (TYPE_SIZE (type
));
10001 return double_int::from_uhwi (TYPE_ALIGN (type
));
10004 /* Given a pointer to a tree node for a subrange type, return a pointer
10005 to a DIE that describes the given type. */
10008 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10010 dw_die_ref subrange_die
;
10011 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10013 if (context_die
== NULL
)
10014 context_die
= comp_unit_die ();
10016 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10018 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10020 /* The size of the subrange type and its base type do not match,
10021 so we need to generate a size attribute for the subrange type. */
10022 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10026 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10028 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10030 return subrange_die
;
10033 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10034 entry that chains various modifiers in front of the given type. */
10037 modified_type_die (tree type
, int type_quals
,
10038 dw_die_ref context_die
)
10040 const int is_const_type
= ((type_quals
& TYPE_QUAL_CONST
) != 0);
10041 const int is_volatile_type
= ((type_quals
& TYPE_QUAL_VOLATILE
) != 0);
10042 enum tree_code code
= TREE_CODE (type
);
10043 dw_die_ref mod_type_die
;
10044 dw_die_ref sub_die
= NULL
;
10045 tree item_type
= NULL
;
10046 tree qualified_type
;
10047 tree name
, low
, high
;
10048 dw_die_ref mod_scope
;
10050 if (code
== ERROR_MARK
)
10053 /* See if we already have the appropriately qualified variant of
10056 = get_qualified_type (type
, type_quals
);
10058 if (qualified_type
== sizetype
10059 && TYPE_NAME (qualified_type
)
10060 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10062 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10064 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10065 && TYPE_PRECISION (t
)
10066 == TYPE_PRECISION (qualified_type
)
10067 && TYPE_UNSIGNED (t
)
10068 == TYPE_UNSIGNED (qualified_type
));
10069 qualified_type
= t
;
10072 /* If we do, then we can just use its DIE, if it exists. */
10073 if (qualified_type
)
10075 mod_type_die
= lookup_type_die (qualified_type
);
10077 return mod_type_die
;
10080 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10082 /* Handle C typedef types. */
10083 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10084 && !DECL_ARTIFICIAL (name
))
10086 tree dtype
= TREE_TYPE (name
);
10088 if (qualified_type
== dtype
)
10090 /* For a named type, use the typedef. */
10091 gen_type_die (qualified_type
, context_die
);
10092 return lookup_type_die (qualified_type
);
10094 else if (type_quals
== TYPE_QUALS (dtype
))
10095 /* cv-unqualified version of named type. Just use the unnamed
10096 type to which it refers. */
10097 return modified_type_die (DECL_ORIGINAL_TYPE (name
), type_quals
, context_die
);
10098 /* Else cv-qualified version of named type; fall through. */
10101 mod_scope
= scope_die_for (type
, context_die
);
10103 if ((type_quals
& TYPE_QUAL_CONST
)
10104 /* If both is_const_type and is_volatile_type, prefer the path
10105 which leads to a qualified type. */
10106 && (!is_volatile_type
10107 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10108 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10110 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10111 sub_die
= modified_type_die (type
, type_quals
& ~TYPE_QUAL_CONST
, context_die
);
10113 else if (type_quals
& TYPE_QUAL_VOLATILE
)
10115 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10116 sub_die
= modified_type_die (type
, type_quals
& ~TYPE_QUAL_VOLATILE
, context_die
);
10118 else if (use_upc_dwarf2_extensions
10119 && (type_quals
& TYPE_QUAL_SHARED
))
10121 HOST_WIDE_INT block_factor
= 1;
10123 /* Inside the compiler,
10124 "shared int x;" TYPE_BLOCK_FACTOR is null.
10125 "shared [] int *p;" TYPE_BLOCK_FACTOR is zero.
10126 "shared [10] int x[50];" TYPE_BLOCK_FACTOR is 10 * bitsize(int)
10127 The DWARF2 encoding is as follows:
10128 "shared int x;" DW_AT_count: 1
10129 "shared [] int *p;" <no DW_AT_count attribute>
10130 "shared [10] int x[50];" DW_AT_count: 10
10131 The logic below handles thse various contingencies. */
10133 mod_type_die
= new_die (DW_TAG_upc_shared_type
,
10134 comp_unit_die (), type
);
10136 if (TYPE_HAS_BLOCK_FACTOR (type
))
10137 block_factor
= TREE_INT_CST_LOW (TYPE_BLOCK_FACTOR (type
));
10139 if (block_factor
!= 0)
10140 add_AT_unsigned (mod_type_die
, DW_AT_count
, block_factor
);
10142 sub_die
= modified_type_die (type
,
10143 type_quals
& ~TYPE_QUAL_SHARED
,
10146 else if (use_upc_dwarf2_extensions
&& type_quals
& TYPE_QUAL_STRICT
)
10148 mod_type_die
= new_die (DW_TAG_upc_strict_type
,
10149 comp_unit_die (), type
);
10150 sub_die
= modified_type_die (type
,
10151 type_quals
& ~TYPE_QUAL_STRICT
,
10154 else if (use_upc_dwarf2_extensions
&& type_quals
& TYPE_QUAL_RELAXED
)
10156 mod_type_die
= new_die (DW_TAG_upc_relaxed_type
,
10157 comp_unit_die (), type
);
10158 sub_die
= modified_type_die (type
,
10159 type_quals
& ~TYPE_QUAL_RELAXED
,
10162 else if (code
== POINTER_TYPE
)
10164 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10165 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10166 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10167 item_type
= TREE_TYPE (type
);
10168 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10169 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10170 TYPE_ADDR_SPACE (item_type
));
10172 else if (code
== REFERENCE_TYPE
)
10174 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10175 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10178 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10179 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10180 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10181 item_type
= TREE_TYPE (type
);
10182 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10183 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10184 TYPE_ADDR_SPACE (item_type
));
10186 else if (code
== INTEGER_TYPE
10187 && TREE_TYPE (type
) != NULL_TREE
10188 && subrange_type_for_debug_p (type
, &low
, &high
))
10190 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10191 item_type
= TREE_TYPE (type
);
10193 else if (is_base_type (type
))
10194 mod_type_die
= base_type_die (type
);
10197 gen_type_die (type
, context_die
);
10199 /* We have to get the type_main_variant here (and pass that to the
10200 `lookup_type_die' routine) because the ..._TYPE node we have
10201 might simply be a *copy* of some original type node (where the
10202 copy was created to help us keep track of typedef names) and
10203 that copy might have a different TYPE_UID from the original
10205 if (TREE_CODE (type
) != VECTOR_TYPE
)
10206 return lookup_type_die (type_main_variant (type
));
10208 /* Vectors have the debugging information in the type,
10209 not the main variant. */
10210 return lookup_type_die (type
);
10213 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10214 don't output a DW_TAG_typedef, since there isn't one in the
10215 user's program; just attach a DW_AT_name to the type.
10216 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10217 if the base type already has the same name. */
10219 && ((TREE_CODE (name
) != TYPE_DECL
10220 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10221 || (!is_const_type
&& !is_volatile_type
)))
10222 || (TREE_CODE (name
) == TYPE_DECL
10223 && TREE_TYPE (name
) == qualified_type
10224 && DECL_NAME (name
))))
10226 if (TREE_CODE (name
) == TYPE_DECL
)
10227 /* Could just call add_name_and_src_coords_attributes here,
10228 but since this is a builtin type it doesn't have any
10229 useful source coordinates anyway. */
10230 name
= DECL_NAME (name
);
10231 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10233 /* This probably indicates a bug. */
10234 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10236 name
= TYPE_NAME (type
);
10238 && TREE_CODE (name
) == TYPE_DECL
)
10239 name
= DECL_NAME (name
);
10240 add_name_attribute (mod_type_die
,
10241 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10244 if (qualified_type
)
10245 equate_type_number_to_die (qualified_type
, mod_type_die
);
10248 /* We must do this after the equate_type_number_to_die call, in case
10249 this is a recursive type. This ensures that the modified_type_die
10250 recursion will terminate even if the type is recursive. Recursive
10251 types are possible in Ada. */
10252 sub_die
= modified_type_die (item_type
, TYPE_QUALS (item_type
), context_die
);
10254 if (sub_die
!= NULL
)
10255 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10257 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10258 if (TYPE_ARTIFICIAL (type
))
10259 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10261 return mod_type_die
;
10264 /* Generate DIEs for the generic parameters of T.
10265 T must be either a generic type or a generic function.
10266 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10269 gen_generic_params_dies (tree t
)
10273 dw_die_ref die
= NULL
;
10275 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10279 die
= lookup_type_die (t
);
10280 else if (DECL_P (t
))
10281 die
= lookup_decl_die (t
);
10285 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10287 /* T has no generic parameter. It means T is neither a generic type
10288 or function. End of story. */
10291 parms_num
= TREE_VEC_LENGTH (parms
);
10292 args
= lang_hooks
.get_innermost_generic_args (t
);
10293 for (i
= 0; i
< parms_num
; i
++)
10295 tree parm
, arg
, arg_pack_elems
;
10297 parm
= TREE_VEC_ELT (parms
, i
);
10298 arg
= TREE_VEC_ELT (args
, i
);
10299 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10300 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10302 if (parm
&& TREE_VALUE (parm
) && arg
)
10304 /* If PARM represents a template parameter pack,
10305 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10306 by DW_TAG_template_*_parameter DIEs for the argument
10307 pack elements of ARG. Note that ARG would then be
10308 an argument pack. */
10309 if (arg_pack_elems
)
10310 template_parameter_pack_die (TREE_VALUE (parm
),
10314 generic_parameter_die (TREE_VALUE (parm
), arg
,
10315 true /* Emit DW_AT_name */, die
);
10320 /* Create and return a DIE for PARM which should be
10321 the representation of a generic type parameter.
10322 For instance, in the C++ front end, PARM would be a template parameter.
10323 ARG is the argument to PARM.
10324 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10326 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10327 as a child node. */
10330 generic_parameter_die (tree parm
, tree arg
,
10332 dw_die_ref parent_die
)
10334 dw_die_ref tmpl_die
= NULL
;
10335 const char *name
= NULL
;
10337 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10340 /* We support non-type generic parameters and arguments,
10341 type generic parameters and arguments, as well as
10342 generic generic parameters (a.k.a. template template parameters in C++)
10344 if (TREE_CODE (parm
) == PARM_DECL
)
10345 /* PARM is a nontype generic parameter */
10346 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10347 else if (TREE_CODE (parm
) == TYPE_DECL
)
10348 /* PARM is a type generic parameter. */
10349 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10350 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10351 /* PARM is a generic generic parameter.
10352 Its DIE is a GNU extension. It shall have a
10353 DW_AT_name attribute to represent the name of the template template
10354 parameter, and a DW_AT_GNU_template_name attribute to represent the
10355 name of the template template argument. */
10356 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10359 gcc_unreachable ();
10365 /* If PARM is a generic parameter pack, it means we are
10366 emitting debug info for a template argument pack element.
10367 In other terms, ARG is a template argument pack element.
10368 In that case, we don't emit any DW_AT_name attribute for
10372 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10374 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10377 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10379 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10380 TMPL_DIE should have a child DW_AT_type attribute that is set
10381 to the type of the argument to PARM, which is ARG.
10382 If PARM is a type generic parameter, TMPL_DIE should have a
10383 child DW_AT_type that is set to ARG. */
10384 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10385 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10386 TREE_THIS_VOLATILE (tmpl_type
),
10391 /* So TMPL_DIE is a DIE representing a
10392 a generic generic template parameter, a.k.a template template
10393 parameter in C++ and arg is a template. */
10395 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10396 to the name of the argument. */
10397 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10399 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10402 if (TREE_CODE (parm
) == PARM_DECL
)
10403 /* So PARM is a non-type generic parameter.
10404 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10405 attribute of TMPL_DIE which value represents the value
10407 We must be careful here:
10408 The value of ARG might reference some function decls.
10409 We might currently be emitting debug info for a generic
10410 type and types are emitted before function decls, we don't
10411 know if the function decls referenced by ARG will actually be
10412 emitted after cgraph computations.
10413 So must defer the generation of the DW_AT_const_value to
10414 after cgraph is ready. */
10415 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10421 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10422 PARM_PACK must be a template parameter pack. The returned DIE
10423 will be child DIE of PARENT_DIE. */
10426 template_parameter_pack_die (tree parm_pack
,
10427 tree parm_pack_args
,
10428 dw_die_ref parent_die
)
10433 gcc_assert (parent_die
&& parm_pack
);
10435 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10436 add_name_and_src_coords_attributes (die
, parm_pack
);
10437 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10438 generic_parameter_die (parm_pack
,
10439 TREE_VEC_ELT (parm_pack_args
, j
),
10440 false /* Don't emit DW_AT_name */,
10445 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10446 an enumerated type. */
10449 type_is_enum (const_tree type
)
10451 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10454 /* Return the DBX register number described by a given RTL node. */
10456 static unsigned int
10457 dbx_reg_number (const_rtx rtl
)
10459 unsigned regno
= REGNO (rtl
);
10461 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10463 #ifdef LEAF_REG_REMAP
10464 if (crtl
->uses_only_leaf_regs
)
10466 int leaf_reg
= LEAF_REG_REMAP (regno
);
10467 if (leaf_reg
!= -1)
10468 regno
= (unsigned) leaf_reg
;
10472 regno
= DBX_REGISTER_NUMBER (regno
);
10473 gcc_assert (regno
!= INVALID_REGNUM
);
10477 /* Optionally add a DW_OP_piece term to a location description expression.
10478 DW_OP_piece is only added if the location description expression already
10479 doesn't end with DW_OP_piece. */
10482 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10484 dw_loc_descr_ref loc
;
10486 if (*list_head
!= NULL
)
10488 /* Find the end of the chain. */
10489 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10492 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10493 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10497 /* Return a location descriptor that designates a machine register or
10498 zero if there is none. */
10500 static dw_loc_descr_ref
10501 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10505 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10508 /* We only use "frame base" when we're sure we're talking about the
10509 post-prologue local stack frame. We do this by *not* running
10510 register elimination until this point, and recognizing the special
10511 argument pointer and soft frame pointer rtx's.
10512 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10513 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10514 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10516 dw_loc_descr_ref result
= NULL
;
10518 if (dwarf_version
>= 4 || !dwarf_strict
)
10520 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10523 add_loc_descr (&result
,
10524 new_loc_descr (DW_OP_stack_value
, 0, 0));
10529 regs
= targetm
.dwarf_register_span (rtl
);
10531 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10532 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10535 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10536 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10538 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10542 /* Return a location descriptor that designates a machine register for
10543 a given hard register number. */
10545 static dw_loc_descr_ref
10546 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10548 dw_loc_descr_ref reg_loc_descr
;
10552 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10554 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10556 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10557 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10559 return reg_loc_descr
;
10562 /* Given an RTL of a register, return a location descriptor that
10563 designates a value that spans more than one register. */
10565 static dw_loc_descr_ref
10566 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10567 enum var_init_status initialized
)
10569 int nregs
, size
, i
;
10571 dw_loc_descr_ref loc_result
= NULL
;
10574 #ifdef LEAF_REG_REMAP
10575 if (crtl
->uses_only_leaf_regs
)
10577 int leaf_reg
= LEAF_REG_REMAP (reg
);
10578 if (leaf_reg
!= -1)
10579 reg
= (unsigned) leaf_reg
;
10582 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10583 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10585 /* Simple, contiguous registers. */
10586 if (regs
== NULL_RTX
)
10588 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10593 dw_loc_descr_ref t
;
10595 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10596 VAR_INIT_STATUS_INITIALIZED
);
10597 add_loc_descr (&loc_result
, t
);
10598 add_loc_descr_op_piece (&loc_result
, size
);
10604 /* Now onto stupid register sets in non contiguous locations. */
10606 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10608 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10611 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10613 dw_loc_descr_ref t
;
10615 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
10616 VAR_INIT_STATUS_INITIALIZED
);
10617 add_loc_descr (&loc_result
, t
);
10618 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10619 add_loc_descr_op_piece (&loc_result
, size
);
10622 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10623 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10627 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10629 /* Return a location descriptor that designates a constant i,
10630 as a compound operation from constant (i >> shift), constant shift
10633 static dw_loc_descr_ref
10634 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10636 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10637 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10638 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10642 /* Return a location descriptor that designates a constant. */
10644 static dw_loc_descr_ref
10645 int_loc_descriptor (HOST_WIDE_INT i
)
10647 enum dwarf_location_atom op
;
10649 /* Pick the smallest representation of a constant, rather than just
10650 defaulting to the LEB encoding. */
10653 int clz
= clz_hwi (i
);
10654 int ctz
= ctz_hwi (i
);
10656 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10657 else if (i
<= 0xff)
10658 op
= DW_OP_const1u
;
10659 else if (i
<= 0xffff)
10660 op
= DW_OP_const2u
;
10661 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10662 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10663 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10664 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10665 while DW_OP_const4u is 5 bytes. */
10666 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10667 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10668 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10669 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10670 while DW_OP_const4u is 5 bytes. */
10671 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10672 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10673 op
= DW_OP_const4u
;
10674 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10675 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10676 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10677 while DW_OP_constu of constant >= 0x100000000 takes at least
10679 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10680 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10681 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10682 >= HOST_BITS_PER_WIDE_INT
)
10683 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10684 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10685 while DW_OP_constu takes in this case at least 6 bytes. */
10686 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10687 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10688 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10689 && size_of_uleb128 (i
) > 6)
10690 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10691 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10698 op
= DW_OP_const1s
;
10699 else if (i
>= -0x8000)
10700 op
= DW_OP_const2s
;
10701 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10703 if (size_of_int_loc_descriptor (i
) < 5)
10705 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10706 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10709 op
= DW_OP_const4s
;
10713 if (size_of_int_loc_descriptor (i
)
10714 < (unsigned long) 1 + size_of_sleb128 (i
))
10716 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10717 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10724 return new_loc_descr (op
, i
, 0);
10727 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10728 without actually allocating it. */
10730 static unsigned long
10731 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10733 return size_of_int_loc_descriptor (i
>> shift
)
10734 + size_of_int_loc_descriptor (shift
)
10738 /* Return size_of_locs (int_loc_descriptor (i)) without
10739 actually allocating it. */
10741 static unsigned long
10742 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10751 else if (i
<= 0xff)
10753 else if (i
<= 0xffff)
10757 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10758 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10759 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10761 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10762 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10763 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10765 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10767 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10768 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10769 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10770 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10772 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10773 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10774 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10776 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10777 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10779 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10788 else if (i
>= -0x8000)
10790 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10792 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10794 s
= size_of_int_loc_descriptor (-i
) + 1;
10802 unsigned long r
= 1 + size_of_sleb128 (i
);
10803 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10805 s
= size_of_int_loc_descriptor (-i
) + 1;
10814 /* Return loc description representing "address" of integer value.
10815 This can appear only as toplevel expression. */
10817 static dw_loc_descr_ref
10818 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10821 dw_loc_descr_ref loc_result
= NULL
;
10823 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10826 litsize
= size_of_int_loc_descriptor (i
);
10827 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10828 is more compact. For DW_OP_stack_value we need:
10829 litsize + 1 (DW_OP_stack_value)
10830 and for DW_OP_implicit_value:
10831 1 (DW_OP_implicit_value) + 1 (length) + size. */
10832 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10834 loc_result
= int_loc_descriptor (i
);
10835 add_loc_descr (&loc_result
,
10836 new_loc_descr (DW_OP_stack_value
, 0, 0));
10840 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10842 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10843 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10847 /* Return a location descriptor that designates a base+offset location. */
10849 static dw_loc_descr_ref
10850 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10851 enum var_init_status initialized
)
10853 unsigned int regno
;
10854 dw_loc_descr_ref result
;
10855 dw_fde_ref fde
= cfun
->fde
;
10857 /* We only use "frame base" when we're sure we're talking about the
10858 post-prologue local stack frame. We do this by *not* running
10859 register elimination until this point, and recognizing the special
10860 argument pointer and soft frame pointer rtx's. */
10861 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10863 rtx elim
= (ira_use_lra_p
10864 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
10865 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
10869 if (GET_CODE (elim
) == PLUS
)
10871 offset
+= INTVAL (XEXP (elim
, 1));
10872 elim
= XEXP (elim
, 0);
10874 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10875 && (elim
== hard_frame_pointer_rtx
10876 || elim
== stack_pointer_rtx
))
10877 || elim
== (frame_pointer_needed
10878 ? hard_frame_pointer_rtx
10879 : stack_pointer_rtx
));
10881 /* If drap register is used to align stack, use frame
10882 pointer + offset to access stack variables. If stack
10883 is aligned without drap, use stack pointer + offset to
10884 access stack variables. */
10885 if (crtl
->stack_realign_tried
10886 && reg
== frame_pointer_rtx
)
10889 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10890 ? HARD_FRAME_POINTER_REGNUM
10892 return new_reg_loc_descr (base_reg
, offset
);
10895 gcc_assert (frame_pointer_fb_offset_valid
);
10896 offset
+= frame_pointer_fb_offset
;
10897 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10901 regno
= DWARF_FRAME_REGNUM (REGNO (reg
));
10903 if (!optimize
&& fde
10904 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
10906 /* Use cfa+offset to represent the location of arguments passed
10907 on the stack when drap is used to align stack.
10908 Only do this when not optimizing, for optimized code var-tracking
10909 is supposed to track where the arguments live and the register
10910 used as vdrap or drap in some spot might be used for something
10911 else in other part of the routine. */
10912 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10916 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10919 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10921 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10922 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10927 /* Return true if this RTL expression describes a base+offset calculation. */
10930 is_based_loc (const_rtx rtl
)
10932 return (GET_CODE (rtl
) == PLUS
10933 && ((REG_P (XEXP (rtl
, 0))
10934 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
10935 && CONST_INT_P (XEXP (rtl
, 1)))));
10938 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10941 static dw_loc_descr_ref
10942 tls_mem_loc_descriptor (rtx mem
)
10945 dw_loc_descr_ref loc_result
;
10947 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
10950 base
= get_base_address (MEM_EXPR (mem
));
10952 || TREE_CODE (base
) != VAR_DECL
10953 || !DECL_THREAD_LOCAL_P (base
))
10956 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
10957 if (loc_result
== NULL
)
10960 if (MEM_OFFSET (mem
))
10961 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
10966 /* Output debug info about reason why we failed to expand expression as dwarf
10970 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
10972 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
10974 fprintf (dump_file
, "Failed to expand as dwarf: ");
10976 print_generic_expr (dump_file
, expr
, dump_flags
);
10979 fprintf (dump_file
, "\n");
10980 print_rtl (dump_file
, rtl
);
10982 fprintf (dump_file
, "\nReason: %s\n", reason
);
10986 /* Helper function for const_ok_for_output, called either directly
10987 or via for_each_rtx. */
10990 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
10994 if (GET_CODE (rtl
) == UNSPEC
)
10996 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
10997 we can't express it in the debug info. */
10998 #ifdef ENABLE_CHECKING
10999 /* Don't complain about TLS UNSPECs, those are just too hard to
11000 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11001 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11002 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11003 if (XVECLEN (rtl
, 0) == 0
11004 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11005 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11006 inform (current_function_decl
11007 ? DECL_SOURCE_LOCATION (current_function_decl
)
11008 : UNKNOWN_LOCATION
,
11009 #if NUM_UNSPEC_VALUES > 0
11010 "non-delegitimized UNSPEC %s (%d) found in variable location",
11011 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11012 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11015 "non-delegitimized UNSPEC %d found in variable location",
11019 expansion_failed (NULL_TREE
, rtl
,
11020 "UNSPEC hasn't been delegitimized.\n");
11024 if (targetm
.const_not_ok_for_debug_p (rtl
))
11026 expansion_failed (NULL_TREE
, rtl
,
11027 "Expression rejected for debug by the backend.\n");
11031 if (GET_CODE (rtl
) != SYMBOL_REF
)
11034 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11037 get_pool_constant_mark (rtl
, &marked
);
11038 /* If all references to this pool constant were optimized away,
11039 it was not output and thus we can't represent it. */
11042 expansion_failed (NULL_TREE
, rtl
,
11043 "Constant was removed from constant pool.\n");
11048 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11051 /* Avoid references to external symbols in debug info, on several targets
11052 the linker might even refuse to link when linking a shared library,
11053 and in many other cases the relocations for .debug_info/.debug_loc are
11054 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11055 to be defined within the same shared library or executable are fine. */
11056 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11058 tree decl
= SYMBOL_REF_DECL (rtl
);
11060 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11062 expansion_failed (NULL_TREE
, rtl
,
11063 "Symbol not defined in current TU.\n");
11071 /* Return true if constant RTL can be emitted in DW_OP_addr or
11072 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11073 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11076 const_ok_for_output (rtx rtl
)
11078 if (GET_CODE (rtl
) == SYMBOL_REF
)
11079 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11081 if (GET_CODE (rtl
) == CONST
)
11082 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11087 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11088 if possible, NULL otherwise. */
11091 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11093 dw_die_ref type_die
;
11094 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11098 switch (TREE_CODE (type
))
11106 type_die
= lookup_type_die (type
);
11108 type_die
= modified_type_die (type
, TYPE_UNQUALIFIED
, comp_unit_die ());
11109 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11114 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11115 type matching MODE, or, if MODE is narrower than or as wide as
11116 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11119 static dw_loc_descr_ref
11120 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11122 enum machine_mode outer_mode
= mode
;
11123 dw_die_ref type_die
;
11124 dw_loc_descr_ref cvt
;
11126 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11128 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11131 type_die
= base_type_for_mode (outer_mode
, 1);
11132 if (type_die
== NULL
)
11134 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11135 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11136 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11137 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11138 add_loc_descr (&op
, cvt
);
11142 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11144 static dw_loc_descr_ref
11145 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11146 dw_loc_descr_ref op1
)
11148 dw_loc_descr_ref ret
= op0
;
11149 add_loc_descr (&ret
, op1
);
11150 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11151 if (STORE_FLAG_VALUE
!= 1)
11153 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11154 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11159 /* Return location descriptor for signed comparison OP RTL. */
11161 static dw_loc_descr_ref
11162 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11163 enum machine_mode mem_mode
)
11165 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11166 dw_loc_descr_ref op0
, op1
;
11169 if (op_mode
== VOIDmode
)
11170 op_mode
= GET_MODE (XEXP (rtl
, 1));
11171 if (op_mode
== VOIDmode
)
11175 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11176 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11179 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11180 VAR_INIT_STATUS_INITIALIZED
);
11181 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11182 VAR_INIT_STATUS_INITIALIZED
);
11184 if (op0
== NULL
|| op1
== NULL
)
11187 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11188 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11189 return compare_loc_descriptor (op
, op0
, op1
);
11191 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11193 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11194 dw_loc_descr_ref cvt
;
11196 if (type_die
== NULL
)
11198 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11199 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11200 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11201 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11202 add_loc_descr (&op0
, cvt
);
11203 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11204 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11205 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11206 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11207 add_loc_descr (&op1
, cvt
);
11208 return compare_loc_descriptor (op
, op0
, op1
);
11211 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11212 /* For eq/ne, if the operands are known to be zero-extended,
11213 there is no need to do the fancy shifting up. */
11214 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11216 dw_loc_descr_ref last0
, last1
;
11217 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11219 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11221 /* deref_size zero extends, and for constants we can check
11222 whether they are zero extended or not. */
11223 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11224 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11225 || (CONST_INT_P (XEXP (rtl
, 0))
11226 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11227 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11228 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11229 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11230 || (CONST_INT_P (XEXP (rtl
, 1))
11231 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11232 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11233 return compare_loc_descriptor (op
, op0
, op1
);
11235 /* EQ/NE comparison against constant in narrower type than
11236 DWARF2_ADDR_SIZE can be performed either as
11237 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11240 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11241 DW_OP_{eq,ne}. Pick whatever is shorter. */
11242 if (CONST_INT_P (XEXP (rtl
, 1))
11243 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11244 && (size_of_int_loc_descriptor (shift
) + 1
11245 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11246 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11247 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11248 & GET_MODE_MASK (op_mode
))))
11250 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11251 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11252 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11253 & GET_MODE_MASK (op_mode
));
11254 return compare_loc_descriptor (op
, op0
, op1
);
11257 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11258 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11259 if (CONST_INT_P (XEXP (rtl
, 1)))
11260 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11263 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11264 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11266 return compare_loc_descriptor (op
, op0
, op1
);
11269 /* Return location descriptor for unsigned comparison OP RTL. */
11271 static dw_loc_descr_ref
11272 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11273 enum machine_mode mem_mode
)
11275 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11276 dw_loc_descr_ref op0
, op1
;
11278 if (op_mode
== VOIDmode
)
11279 op_mode
= GET_MODE (XEXP (rtl
, 1));
11280 if (op_mode
== VOIDmode
)
11282 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11285 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11288 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11289 VAR_INIT_STATUS_INITIALIZED
);
11290 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11291 VAR_INIT_STATUS_INITIALIZED
);
11293 if (op0
== NULL
|| op1
== NULL
)
11296 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11298 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11299 dw_loc_descr_ref last0
, last1
;
11300 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11302 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11304 if (CONST_INT_P (XEXP (rtl
, 0)))
11305 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11306 /* deref_size zero extends, so no need to mask it again. */
11307 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11308 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11310 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11311 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11313 if (CONST_INT_P (XEXP (rtl
, 1)))
11314 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11315 /* deref_size zero extends, so no need to mask it again. */
11316 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11317 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11319 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11320 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11323 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11325 HOST_WIDE_INT bias
= 1;
11326 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11327 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11328 if (CONST_INT_P (XEXP (rtl
, 1)))
11329 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11330 + INTVAL (XEXP (rtl
, 1)));
11332 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11335 return compare_loc_descriptor (op
, op0
, op1
);
11338 /* Return location descriptor for {U,S}{MIN,MAX}. */
11340 static dw_loc_descr_ref
11341 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11342 enum machine_mode mem_mode
)
11344 enum dwarf_location_atom op
;
11345 dw_loc_descr_ref op0
, op1
, ret
;
11346 dw_loc_descr_ref bra_node
, drop_node
;
11349 && (GET_MODE_CLASS (mode
) != MODE_INT
11350 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11353 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11354 VAR_INIT_STATUS_INITIALIZED
);
11355 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11356 VAR_INIT_STATUS_INITIALIZED
);
11358 if (op0
== NULL
|| op1
== NULL
)
11361 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11362 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11363 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11364 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11366 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11368 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11369 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11370 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11371 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11372 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11374 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11376 HOST_WIDE_INT bias
= 1;
11377 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11378 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11379 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11382 else if (GET_MODE_CLASS (mode
) == MODE_INT
11383 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11385 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11386 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11387 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11388 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11389 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11391 else if (GET_MODE_CLASS (mode
) == MODE_INT
11392 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11394 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11395 dw_loc_descr_ref cvt
;
11396 if (type_die
== NULL
)
11398 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11399 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11400 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11401 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11402 add_loc_descr (&op0
, cvt
);
11403 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11404 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11405 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11406 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11407 add_loc_descr (&op1
, cvt
);
11410 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11415 add_loc_descr (&ret
, op1
);
11416 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11417 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11418 add_loc_descr (&ret
, bra_node
);
11419 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11420 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11421 add_loc_descr (&ret
, drop_node
);
11422 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11423 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11424 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11425 && GET_MODE_CLASS (mode
) == MODE_INT
11426 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11427 ret
= convert_descriptor_to_mode (mode
, ret
);
11431 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11432 but after converting arguments to type_die, afterwards
11433 convert back to unsigned. */
11435 static dw_loc_descr_ref
11436 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11437 enum machine_mode mode
, enum machine_mode mem_mode
)
11439 dw_loc_descr_ref cvt
, op0
, op1
;
11441 if (type_die
== NULL
)
11443 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11444 VAR_INIT_STATUS_INITIALIZED
);
11445 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11446 VAR_INIT_STATUS_INITIALIZED
);
11447 if (op0
== NULL
|| op1
== NULL
)
11449 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11450 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11451 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11452 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11453 add_loc_descr (&op0
, cvt
);
11454 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11455 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11456 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11457 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11458 add_loc_descr (&op1
, cvt
);
11459 add_loc_descr (&op0
, op1
);
11460 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11461 return convert_descriptor_to_mode (mode
, op0
);
11464 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11465 const0 is DW_OP_lit0 or corresponding typed constant,
11466 const1 is DW_OP_lit1 or corresponding typed constant
11467 and constMSB is constant with just the MSB bit set
11469 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11470 L1: const0 DW_OP_swap
11471 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11472 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11477 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11478 L1: const0 DW_OP_swap
11479 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11480 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11485 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11486 L1: const1 DW_OP_swap
11487 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11488 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11492 static dw_loc_descr_ref
11493 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11494 enum machine_mode mem_mode
)
11496 dw_loc_descr_ref op0
, ret
, tmp
;
11497 HOST_WIDE_INT valv
;
11498 dw_loc_descr_ref l1jump
, l1label
;
11499 dw_loc_descr_ref l2jump
, l2label
;
11500 dw_loc_descr_ref l3jump
, l3label
;
11501 dw_loc_descr_ref l4jump
, l4label
;
11504 if (GET_MODE_CLASS (mode
) != MODE_INT
11505 || GET_MODE (XEXP (rtl
, 0)) != mode
11506 || (GET_CODE (rtl
) == CLZ
11507 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11510 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11511 VAR_INIT_STATUS_INITIALIZED
);
11515 if (GET_CODE (rtl
) == CLZ
)
11517 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11518 valv
= GET_MODE_BITSIZE (mode
);
11520 else if (GET_CODE (rtl
) == FFS
)
11522 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11523 valv
= GET_MODE_BITSIZE (mode
);
11524 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11525 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11526 add_loc_descr (&ret
, l1jump
);
11527 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11528 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11529 VAR_INIT_STATUS_INITIALIZED
);
11532 add_loc_descr (&ret
, tmp
);
11533 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11534 add_loc_descr (&ret
, l4jump
);
11535 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11536 ? const1_rtx
: const0_rtx
,
11538 VAR_INIT_STATUS_INITIALIZED
);
11539 if (l1label
== NULL
)
11541 add_loc_descr (&ret
, l1label
);
11542 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11543 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11544 add_loc_descr (&ret
, l2label
);
11545 if (GET_CODE (rtl
) != CLZ
)
11547 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11548 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11549 << (GET_MODE_BITSIZE (mode
) - 1));
11551 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11552 << (GET_MODE_BITSIZE (mode
)
11553 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11554 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11555 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11556 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11557 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11559 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11560 VAR_INIT_STATUS_INITIALIZED
);
11563 add_loc_descr (&ret
, tmp
);
11564 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11565 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11566 add_loc_descr (&ret
, l3jump
);
11567 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11568 VAR_INIT_STATUS_INITIALIZED
);
11571 add_loc_descr (&ret
, tmp
);
11572 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11573 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11574 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11575 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11576 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11577 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11578 add_loc_descr (&ret
, l2jump
);
11579 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11580 add_loc_descr (&ret
, l3label
);
11581 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11582 add_loc_descr (&ret
, l4label
);
11583 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11584 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11585 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11586 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11587 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11588 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11589 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11590 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11594 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11595 const1 is DW_OP_lit1 or corresponding typed constant):
11597 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11598 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11602 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11603 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11606 static dw_loc_descr_ref
11607 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11608 enum machine_mode mem_mode
)
11610 dw_loc_descr_ref op0
, ret
, tmp
;
11611 dw_loc_descr_ref l1jump
, l1label
;
11612 dw_loc_descr_ref l2jump
, l2label
;
11614 if (GET_MODE_CLASS (mode
) != MODE_INT
11615 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11618 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11619 VAR_INIT_STATUS_INITIALIZED
);
11623 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11624 VAR_INIT_STATUS_INITIALIZED
);
11627 add_loc_descr (&ret
, tmp
);
11628 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11629 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11630 add_loc_descr (&ret
, l1label
);
11631 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11632 add_loc_descr (&ret
, l2jump
);
11633 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11634 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11635 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11636 VAR_INIT_STATUS_INITIALIZED
);
11639 add_loc_descr (&ret
, tmp
);
11640 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11641 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11642 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11643 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11644 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11645 VAR_INIT_STATUS_INITIALIZED
);
11646 add_loc_descr (&ret
, tmp
);
11647 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11648 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11649 add_loc_descr (&ret
, l1jump
);
11650 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11651 add_loc_descr (&ret
, l2label
);
11652 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11653 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11654 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11655 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11659 /* BSWAP (constS is initial shift count, either 56 or 24):
11661 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11662 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11663 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11664 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11665 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11667 static dw_loc_descr_ref
11668 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11669 enum machine_mode mem_mode
)
11671 dw_loc_descr_ref op0
, ret
, tmp
;
11672 dw_loc_descr_ref l1jump
, l1label
;
11673 dw_loc_descr_ref l2jump
, l2label
;
11675 if (GET_MODE_CLASS (mode
) != MODE_INT
11676 || BITS_PER_UNIT
!= 8
11677 || (GET_MODE_BITSIZE (mode
) != 32
11678 && GET_MODE_BITSIZE (mode
) != 64))
11681 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11682 VAR_INIT_STATUS_INITIALIZED
);
11687 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11689 VAR_INIT_STATUS_INITIALIZED
);
11692 add_loc_descr (&ret
, tmp
);
11693 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11694 VAR_INIT_STATUS_INITIALIZED
);
11697 add_loc_descr (&ret
, tmp
);
11698 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11699 add_loc_descr (&ret
, l1label
);
11700 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11702 VAR_INIT_STATUS_INITIALIZED
);
11703 add_loc_descr (&ret
, tmp
);
11704 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11705 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11706 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11707 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11708 VAR_INIT_STATUS_INITIALIZED
);
11711 add_loc_descr (&ret
, tmp
);
11712 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11713 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11714 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11715 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11716 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11717 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11718 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11719 VAR_INIT_STATUS_INITIALIZED
);
11720 add_loc_descr (&ret
, tmp
);
11721 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11722 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11723 add_loc_descr (&ret
, l2jump
);
11724 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11725 VAR_INIT_STATUS_INITIALIZED
);
11726 add_loc_descr (&ret
, tmp
);
11727 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11728 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11729 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11730 add_loc_descr (&ret
, l1jump
);
11731 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11732 add_loc_descr (&ret
, l2label
);
11733 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11734 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11735 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11736 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11737 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11738 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11742 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11743 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11744 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11745 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11747 ROTATERT is similar:
11748 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11749 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11750 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11752 static dw_loc_descr_ref
11753 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11754 enum machine_mode mem_mode
)
11756 rtx rtlop1
= XEXP (rtl
, 1);
11757 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11760 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11763 if (GET_MODE (rtlop1
) != VOIDmode
11764 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11765 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11766 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11767 VAR_INIT_STATUS_INITIALIZED
);
11768 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11769 VAR_INIT_STATUS_INITIALIZED
);
11770 if (op0
== NULL
|| op1
== NULL
)
11772 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11773 for (i
= 0; i
< 2; i
++)
11775 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11776 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11778 VAR_INIT_STATUS_INITIALIZED
);
11779 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11780 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11782 : HOST_BITS_PER_WIDE_INT
== 64
11783 ? DW_OP_const8u
: DW_OP_constu
,
11784 GET_MODE_MASK (mode
), 0);
11787 if (mask
[i
] == NULL
)
11789 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11792 add_loc_descr (&ret
, op1
);
11793 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11794 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11795 if (GET_CODE (rtl
) == ROTATERT
)
11797 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11798 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11799 GET_MODE_BITSIZE (mode
), 0));
11801 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11802 if (mask
[0] != NULL
)
11803 add_loc_descr (&ret
, mask
[0]);
11804 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11805 if (mask
[1] != NULL
)
11807 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11808 add_loc_descr (&ret
, mask
[1]);
11809 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11811 if (GET_CODE (rtl
) == ROTATE
)
11813 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11814 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11815 GET_MODE_BITSIZE (mode
), 0));
11817 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11818 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11822 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11823 for DEBUG_PARAMETER_REF RTL. */
11825 static dw_loc_descr_ref
11826 parameter_ref_descriptor (rtx rtl
)
11828 dw_loc_descr_ref ret
;
11833 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11834 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11835 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11838 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11839 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11840 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11844 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11845 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11850 /* The following routine converts the RTL for a variable or parameter
11851 (resident in memory) into an equivalent Dwarf representation of a
11852 mechanism for getting the address of that same variable onto the top of a
11853 hypothetical "address evaluation" stack.
11855 When creating memory location descriptors, we are effectively transforming
11856 the RTL for a memory-resident object into its Dwarf postfix expression
11857 equivalent. This routine recursively descends an RTL tree, turning
11858 it into Dwarf postfix code as it goes.
11860 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11862 MEM_MODE is the mode of the memory reference, needed to handle some
11863 autoincrement addressing modes.
11865 Return 0 if we can't represent the location. */
11868 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11869 enum machine_mode mem_mode
,
11870 enum var_init_status initialized
)
11872 dw_loc_descr_ref mem_loc_result
= NULL
;
11873 enum dwarf_location_atom op
;
11874 dw_loc_descr_ref op0
, op1
;
11875 rtx inner
= NULL_RTX
;
11877 if (mode
== VOIDmode
)
11878 mode
= GET_MODE (rtl
);
11880 /* Note that for a dynamically sized array, the location we will generate a
11881 description of here will be the lowest numbered location which is
11882 actually within the array. That's *not* necessarily the same as the
11883 zeroth element of the array. */
11885 rtl
= targetm
.delegitimize_address (rtl
);
11887 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11890 switch (GET_CODE (rtl
))
11895 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11898 /* The case of a subreg may arise when we have a local (register)
11899 variable or a formal (register) parameter which doesn't quite fill
11900 up an entire register. For now, just assume that it is
11901 legitimate to make the Dwarf info refer to the whole register which
11902 contains the given subreg. */
11903 if (!subreg_lowpart_p (rtl
))
11905 inner
= SUBREG_REG (rtl
);
11907 if (inner
== NULL_RTX
)
11908 inner
= XEXP (rtl
, 0);
11909 if (GET_MODE_CLASS (mode
) == MODE_INT
11910 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
11911 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11912 #ifdef POINTERS_EXTEND_UNSIGNED
11913 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
11916 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
11918 mem_loc_result
= mem_loc_descriptor (inner
,
11920 mem_mode
, initialized
);
11925 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
11927 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
11928 && (GET_MODE_CLASS (mode
) != MODE_INT
11929 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
11933 dw_die_ref type_die
;
11934 dw_loc_descr_ref cvt
;
11936 mem_loc_result
= mem_loc_descriptor (inner
,
11938 mem_mode
, initialized
);
11939 if (mem_loc_result
== NULL
)
11941 type_die
= base_type_for_mode (mode
,
11942 GET_MODE_CLASS (mode
) == MODE_INT
);
11943 if (type_die
== NULL
)
11945 mem_loc_result
= NULL
;
11948 if (GET_MODE_SIZE (mode
)
11949 != GET_MODE_SIZE (GET_MODE (inner
)))
11950 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11952 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
11953 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11954 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11955 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11956 add_loc_descr (&mem_loc_result
, cvt
);
11961 if (GET_MODE_CLASS (mode
) != MODE_INT
11962 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
11963 && rtl
!= arg_pointer_rtx
11964 && rtl
!= frame_pointer_rtx
11965 #ifdef POINTERS_EXTEND_UNSIGNED
11966 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
11970 dw_die_ref type_die
;
11971 unsigned int dbx_regnum
;
11975 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
11977 type_die
= base_type_for_mode (mode
,
11978 GET_MODE_CLASS (mode
) == MODE_INT
);
11979 if (type_die
== NULL
)
11982 dbx_regnum
= dbx_reg_number (rtl
);
11983 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
11985 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
11987 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
11988 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
11989 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
11992 /* Whenever a register number forms a part of the description of the
11993 method for calculating the (dynamic) address of a memory resident
11994 object, DWARF rules require the register number be referred to as
11995 a "base register". This distinction is not based in any way upon
11996 what category of register the hardware believes the given register
11997 belongs to. This is strictly DWARF terminology we're dealing with
11998 here. Note that in cases where the location of a memory-resident
11999 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12000 OP_CONST (0)) the actual DWARF location descriptor that we generate
12001 may just be OP_BASEREG (basereg). This may look deceptively like
12002 the object in question was allocated to a register (rather than in
12003 memory) so DWARF consumers need to be aware of the subtle
12004 distinction between OP_REG and OP_BASEREG. */
12005 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12006 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12007 else if (stack_realign_drap
12009 && crtl
->args
.internal_arg_pointer
== rtl
12010 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12012 /* If RTL is internal_arg_pointer, which has been optimized
12013 out, use DRAP instead. */
12014 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12015 VAR_INIT_STATUS_INITIALIZED
);
12021 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12023 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12024 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12027 else if (GET_CODE (rtl
) == ZERO_EXTEND
12028 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12029 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12030 < HOST_BITS_PER_WIDE_INT
12031 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12032 to expand zero extend as two shifts instead of
12034 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12036 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12037 mem_loc_result
= op0
;
12038 add_loc_descr (&mem_loc_result
,
12039 int_loc_descriptor (GET_MODE_MASK (imode
)));
12040 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12042 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12044 int shift
= DWARF2_ADDR_SIZE
12045 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12046 shift
*= BITS_PER_UNIT
;
12047 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12051 mem_loc_result
= op0
;
12052 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12053 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12054 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12055 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12057 else if (!dwarf_strict
)
12059 dw_die_ref type_die1
, type_die2
;
12060 dw_loc_descr_ref cvt
;
12062 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12063 GET_CODE (rtl
) == ZERO_EXTEND
);
12064 if (type_die1
== NULL
)
12066 type_die2
= base_type_for_mode (mode
, 1);
12067 if (type_die2
== NULL
)
12069 mem_loc_result
= op0
;
12070 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12071 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12072 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12073 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12074 add_loc_descr (&mem_loc_result
, cvt
);
12075 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12076 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12077 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12078 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12079 add_loc_descr (&mem_loc_result
, cvt
);
12085 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12086 if (new_rtl
!= rtl
)
12088 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12090 if (mem_loc_result
!= NULL
)
12091 return mem_loc_result
;
12094 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12095 get_address_mode (rtl
), mode
,
12096 VAR_INIT_STATUS_INITIALIZED
);
12097 if (mem_loc_result
== NULL
)
12098 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12099 if (mem_loc_result
!= NULL
)
12101 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12102 || GET_MODE_CLASS (mode
) != MODE_INT
)
12104 dw_die_ref type_die
;
12105 dw_loc_descr_ref deref
;
12110 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12111 if (type_die
== NULL
)
12113 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12114 GET_MODE_SIZE (mode
), 0);
12115 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12116 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12117 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12118 add_loc_descr (&mem_loc_result
, deref
);
12120 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12121 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12123 add_loc_descr (&mem_loc_result
,
12124 new_loc_descr (DW_OP_deref_size
,
12125 GET_MODE_SIZE (mode
), 0));
12130 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12133 /* Some ports can transform a symbol ref into a label ref, because
12134 the symbol ref is too far away and has to be dumped into a constant
12138 if (GET_MODE_CLASS (mode
) != MODE_INT
12139 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12140 #ifdef POINTERS_EXTEND_UNSIGNED
12141 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12145 if (GET_CODE (rtl
) == SYMBOL_REF
12146 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12148 dw_loc_descr_ref temp
;
12150 /* If this is not defined, we have no way to emit the data. */
12151 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12154 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12156 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12157 add_loc_descr (&mem_loc_result
, temp
);
12162 if (!const_ok_for_output (rtl
))
12166 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12167 vec_safe_push (used_rtx_array
, rtl
);
12173 case DEBUG_IMPLICIT_PTR
:
12174 expansion_failed (NULL_TREE
, rtl
,
12175 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12181 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12183 if (GET_MODE_CLASS (mode
) != MODE_INT
12184 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12185 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12186 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12189 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12190 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12192 op0
= one_reg_loc_descriptor (dbx_regnum
,
12193 VAR_INIT_STATUS_INITIALIZED
);
12196 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12197 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12199 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12200 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12201 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12205 gcc_unreachable ();
12208 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12209 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12210 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12213 case DEBUG_PARAMETER_REF
:
12214 mem_loc_result
= parameter_ref_descriptor (rtl
);
12218 /* Extract the PLUS expression nested inside and fall into
12219 PLUS code below. */
12220 rtl
= XEXP (rtl
, 1);
12225 /* Turn these into a PLUS expression and fall into the PLUS code
12227 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12228 GEN_INT (GET_CODE (rtl
) == PRE_INC
12229 ? GET_MODE_UNIT_SIZE (mem_mode
)
12230 : -GET_MODE_UNIT_SIZE (mem_mode
)));
12232 /* ... fall through ... */
12236 if (is_based_loc (rtl
)
12237 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12238 || XEXP (rtl
, 0) == arg_pointer_rtx
12239 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12240 && GET_MODE_CLASS (mode
) == MODE_INT
)
12241 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12242 INTVAL (XEXP (rtl
, 1)),
12243 VAR_INIT_STATUS_INITIALIZED
);
12246 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12247 VAR_INIT_STATUS_INITIALIZED
);
12248 if (mem_loc_result
== 0)
12251 if (CONST_INT_P (XEXP (rtl
, 1))
12252 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12253 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12256 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12257 VAR_INIT_STATUS_INITIALIZED
);
12260 add_loc_descr (&mem_loc_result
, op1
);
12261 add_loc_descr (&mem_loc_result
,
12262 new_loc_descr (DW_OP_plus
, 0, 0));
12267 /* If a pseudo-reg is optimized away, it is possible for it to
12268 be replaced with a MEM containing a multiply or shift. */
12279 && GET_MODE_CLASS (mode
) == MODE_INT
12280 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12282 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12283 base_type_for_mode (mode
, 0),
12307 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12309 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12310 VAR_INIT_STATUS_INITIALIZED
);
12312 rtx rtlop1
= XEXP (rtl
, 1);
12313 if (GET_MODE (rtlop1
) != VOIDmode
12314 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12315 < GET_MODE_BITSIZE (mode
))
12316 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12317 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12318 VAR_INIT_STATUS_INITIALIZED
);
12321 if (op0
== 0 || op1
== 0)
12324 mem_loc_result
= op0
;
12325 add_loc_descr (&mem_loc_result
, op1
);
12326 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12342 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12343 VAR_INIT_STATUS_INITIALIZED
);
12344 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12345 VAR_INIT_STATUS_INITIALIZED
);
12347 if (op0
== 0 || op1
== 0)
12350 mem_loc_result
= op0
;
12351 add_loc_descr (&mem_loc_result
, op1
);
12352 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12356 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12358 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12359 base_type_for_mode (mode
, 0),
12364 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12365 VAR_INIT_STATUS_INITIALIZED
);
12366 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12367 VAR_INIT_STATUS_INITIALIZED
);
12369 if (op0
== 0 || op1
== 0)
12372 mem_loc_result
= op0
;
12373 add_loc_descr (&mem_loc_result
, op1
);
12374 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12375 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12376 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12377 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12378 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12382 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12384 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12389 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12390 base_type_for_mode (mode
, 1),
12408 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12409 VAR_INIT_STATUS_INITIALIZED
);
12414 mem_loc_result
= op0
;
12415 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12419 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12420 #ifdef POINTERS_EXTEND_UNSIGNED
12422 && mem_mode
!= VOIDmode
12423 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12427 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12431 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12432 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12434 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12435 enum machine_mode amode
;
12436 if (type_die
== NULL
)
12438 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12440 if (INTVAL (rtl
) >= 0
12441 && amode
!= BLKmode
12442 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12443 /* const DW_OP_GNU_convert <XXX> vs.
12444 DW_OP_GNU_const_type <XXX, 1, const>. */
12445 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12446 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12448 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12449 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12450 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12451 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12452 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12453 add_loc_descr (&mem_loc_result
, op0
);
12454 return mem_loc_result
;
12456 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12458 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12459 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12460 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12461 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12462 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12465 mem_loc_result
->dw_loc_oprnd2
.val_class
12466 = dw_val_class_const_double
;
12467 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12468 = double_int::from_shwi (INTVAL (rtl
));
12476 dw_die_ref type_die
;
12478 /* Note that a CONST_DOUBLE rtx could represent either an integer
12479 or a floating-point constant. A CONST_DOUBLE is used whenever
12480 the constant requires more than one word in order to be
12481 adequately represented. We output CONST_DOUBLEs as blocks. */
12482 if (mode
== VOIDmode
12483 || (GET_MODE (rtl
) == VOIDmode
12484 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12486 type_die
= base_type_for_mode (mode
,
12487 GET_MODE_CLASS (mode
) == MODE_INT
);
12488 if (type_die
== NULL
)
12490 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12491 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12492 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12493 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12494 if (SCALAR_FLOAT_MODE_P (mode
))
12496 unsigned int length
= GET_MODE_SIZE (mode
);
12497 unsigned char *array
12498 = (unsigned char*) ggc_alloc_atomic (length
);
12500 insert_float (rtl
, array
);
12501 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12502 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12503 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12504 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12508 mem_loc_result
->dw_loc_oprnd2
.val_class
12509 = dw_val_class_const_double
;
12510 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12511 = rtx_to_double_int (rtl
);
12517 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12521 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12525 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12529 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12533 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12537 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12541 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12545 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12549 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12553 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12558 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12563 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12568 if (CONST_INT_P (XEXP (rtl
, 1))
12569 && CONST_INT_P (XEXP (rtl
, 2))
12570 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12571 + (unsigned) INTVAL (XEXP (rtl
, 2))
12572 <= GET_MODE_BITSIZE (mode
))
12573 && GET_MODE_CLASS (mode
) == MODE_INT
12574 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12575 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12578 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12579 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12582 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12586 mem_loc_result
= op0
;
12587 size
= INTVAL (XEXP (rtl
, 1));
12588 shift
= INTVAL (XEXP (rtl
, 2));
12589 if (BITS_BIG_ENDIAN
)
12590 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12592 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12594 add_loc_descr (&mem_loc_result
,
12595 int_loc_descriptor (DWARF2_ADDR_SIZE
12597 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12599 if (size
!= (int) DWARF2_ADDR_SIZE
)
12601 add_loc_descr (&mem_loc_result
,
12602 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12603 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12610 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12611 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12612 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12613 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12614 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12615 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12616 VAR_INIT_STATUS_INITIALIZED
);
12617 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12618 VAR_INIT_STATUS_INITIALIZED
);
12619 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12622 mem_loc_result
= op1
;
12623 add_loc_descr (&mem_loc_result
, op2
);
12624 add_loc_descr (&mem_loc_result
, op0
);
12625 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12626 add_loc_descr (&mem_loc_result
, bra_node
);
12627 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12628 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12629 add_loc_descr (&mem_loc_result
, drop_node
);
12630 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12631 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12636 case FLOAT_TRUNCATE
:
12638 case UNSIGNED_FLOAT
:
12643 dw_die_ref type_die
;
12644 dw_loc_descr_ref cvt
;
12646 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12647 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12650 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12651 && (GET_CODE (rtl
) == FLOAT
12652 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12653 <= DWARF2_ADDR_SIZE
))
12655 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12656 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12657 if (type_die
== NULL
)
12659 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12660 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12661 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12662 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12663 add_loc_descr (&op0
, cvt
);
12665 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12666 if (type_die
== NULL
)
12668 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12669 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12670 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12671 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12672 add_loc_descr (&op0
, cvt
);
12673 if (GET_MODE_CLASS (mode
) == MODE_INT
12674 && (GET_CODE (rtl
) == FIX
12675 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12677 op0
= convert_descriptor_to_mode (mode
, op0
);
12681 mem_loc_result
= op0
;
12688 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12693 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12697 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12702 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12706 /* In theory, we could implement the above. */
12707 /* DWARF cannot represent the unsigned compare operations
12732 case FRACT_CONVERT
:
12733 case UNSIGNED_FRACT_CONVERT
:
12735 case UNSIGNED_SAT_FRACT
:
12741 case VEC_DUPLICATE
:
12745 case STRICT_LOW_PART
:
12750 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12751 can't express it in the debug info. This can happen e.g. with some
12756 resolve_one_addr (&rtl
, NULL
);
12760 #ifdef ENABLE_CHECKING
12761 print_rtl (stderr
, rtl
);
12762 gcc_unreachable ();
12768 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12769 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12771 return mem_loc_result
;
12774 /* Return a descriptor that describes the concatenation of two locations.
12775 This is typically a complex variable. */
12777 static dw_loc_descr_ref
12778 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12780 dw_loc_descr_ref cc_loc_result
= NULL
;
12781 dw_loc_descr_ref x0_ref
12782 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12783 dw_loc_descr_ref x1_ref
12784 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12786 if (x0_ref
== 0 || x1_ref
== 0)
12789 cc_loc_result
= x0_ref
;
12790 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12792 add_loc_descr (&cc_loc_result
, x1_ref
);
12793 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12795 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12796 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12798 return cc_loc_result
;
12801 /* Return a descriptor that describes the concatenation of N
12804 static dw_loc_descr_ref
12805 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12808 dw_loc_descr_ref cc_loc_result
= NULL
;
12809 unsigned int n
= XVECLEN (concatn
, 0);
12811 for (i
= 0; i
< n
; ++i
)
12813 dw_loc_descr_ref ref
;
12814 rtx x
= XVECEXP (concatn
, 0, i
);
12816 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12820 add_loc_descr (&cc_loc_result
, ref
);
12821 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12824 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12825 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12827 return cc_loc_result
;
12830 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12831 for DEBUG_IMPLICIT_PTR RTL. */
12833 static dw_loc_descr_ref
12834 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12836 dw_loc_descr_ref ret
;
12841 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12842 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12843 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12844 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12845 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12846 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12849 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12850 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12851 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12855 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12856 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12861 /* Output a proper Dwarf location descriptor for a variable or parameter
12862 which is either allocated in a register or in a memory location. For a
12863 register, we just generate an OP_REG and the register number. For a
12864 memory location we provide a Dwarf postfix expression describing how to
12865 generate the (dynamic) address of the object onto the address stack.
12867 MODE is mode of the decl if this loc_descriptor is going to be used in
12868 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12869 allowed, VOIDmode otherwise.
12871 If we don't know how to describe it, return 0. */
12873 static dw_loc_descr_ref
12874 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12875 enum var_init_status initialized
)
12877 dw_loc_descr_ref loc_result
= NULL
;
12879 switch (GET_CODE (rtl
))
12882 /* The case of a subreg may arise when we have a local (register)
12883 variable or a formal (register) parameter which doesn't quite fill
12884 up an entire register. For now, just assume that it is
12885 legitimate to make the Dwarf info refer to the whole register which
12886 contains the given subreg. */
12887 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12888 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12889 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12895 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12899 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12900 GET_MODE (rtl
), initialized
);
12901 if (loc_result
== NULL
)
12902 loc_result
= tls_mem_loc_descriptor (rtl
);
12903 if (loc_result
== NULL
)
12905 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12906 if (new_rtl
!= rtl
)
12907 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
12912 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
12917 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
12922 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
12924 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
12925 if (GET_CODE (loc
) == EXPR_LIST
)
12926 loc
= XEXP (loc
, 0);
12927 loc_result
= loc_descriptor (loc
, mode
, initialized
);
12931 rtl
= XEXP (rtl
, 1);
12936 rtvec par_elems
= XVEC (rtl
, 0);
12937 int num_elem
= GET_NUM_ELEM (par_elems
);
12938 enum machine_mode mode
;
12941 /* Create the first one, so we have something to add to. */
12942 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
12943 VOIDmode
, initialized
);
12944 if (loc_result
== NULL
)
12946 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
12947 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12948 for (i
= 1; i
< num_elem
; i
++)
12950 dw_loc_descr_ref temp
;
12952 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
12953 VOIDmode
, initialized
);
12956 add_loc_descr (&loc_result
, temp
);
12957 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
12958 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
12964 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
12965 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
12970 if (mode
== VOIDmode
)
12971 mode
= GET_MODE (rtl
);
12973 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
12975 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
12977 /* Note that a CONST_DOUBLE rtx could represent either an integer
12978 or a floating-point constant. A CONST_DOUBLE is used whenever
12979 the constant requires more than one word in order to be
12980 adequately represented. We output CONST_DOUBLEs as blocks. */
12981 loc_result
= new_loc_descr (DW_OP_implicit_value
,
12982 GET_MODE_SIZE (mode
), 0);
12983 if (SCALAR_FLOAT_MODE_P (mode
))
12985 unsigned int length
= GET_MODE_SIZE (mode
);
12986 unsigned char *array
12987 = (unsigned char*) ggc_alloc_atomic (length
);
12989 insert_float (rtl
, array
);
12990 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12991 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12992 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12993 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12997 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
12998 loc_result
->dw_loc_oprnd2
.v
.val_double
12999 = rtx_to_double_int (rtl
);
13005 if (mode
== VOIDmode
)
13006 mode
= GET_MODE (rtl
);
13008 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13010 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13011 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13012 unsigned char *array
= (unsigned char *)
13013 ggc_alloc_atomic (length
* elt_size
);
13017 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13018 switch (GET_MODE_CLASS (mode
))
13020 case MODE_VECTOR_INT
:
13021 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13023 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13024 double_int val
= rtx_to_double_int (elt
);
13026 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13027 insert_int (val
.to_shwi (), elt_size
, p
);
13030 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13031 insert_double (val
, p
);
13036 case MODE_VECTOR_FLOAT
:
13037 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13039 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13040 insert_float (elt
, p
);
13045 gcc_unreachable ();
13048 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13049 length
* elt_size
, 0);
13050 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13051 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13052 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13053 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13058 if (mode
== VOIDmode
13059 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13060 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13061 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13063 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13068 if (!const_ok_for_output (rtl
))
13071 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13072 && (dwarf_version
>= 4 || !dwarf_strict
))
13074 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13075 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13076 vec_safe_push (used_rtx_array
, rtl
);
13080 case DEBUG_IMPLICIT_PTR
:
13081 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13085 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13086 && CONST_INT_P (XEXP (rtl
, 1)))
13089 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13095 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13096 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13097 && dwarf_version
>= 4)
13098 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13100 /* Value expression. */
13101 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13103 add_loc_descr (&loc_result
,
13104 new_loc_descr (DW_OP_stack_value
, 0, 0));
13112 /* We need to figure out what section we should use as the base for the
13113 address ranges where a given location is valid.
13114 1. If this particular DECL has a section associated with it, use that.
13115 2. If this function has a section associated with it, use that.
13116 3. Otherwise, use the text section.
13117 XXX: If you split a variable across multiple sections, we won't notice. */
13119 static const char *
13120 secname_for_decl (const_tree decl
)
13122 const char *secname
;
13124 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13126 tree sectree
= DECL_SECTION_NAME (decl
);
13127 secname
= TREE_STRING_POINTER (sectree
);
13129 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13131 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13132 secname
= TREE_STRING_POINTER (sectree
);
13134 else if (cfun
&& in_cold_section_p
)
13135 secname
= crtl
->subsections
.cold_section_label
;
13137 secname
= text_section_label
;
13142 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13145 decl_by_reference_p (tree decl
)
13147 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13148 || TREE_CODE (decl
) == VAR_DECL
)
13149 && DECL_BY_REFERENCE (decl
));
13152 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13155 static dw_loc_descr_ref
13156 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13157 enum var_init_status initialized
)
13159 int have_address
= 0;
13160 dw_loc_descr_ref descr
;
13161 enum machine_mode mode
;
13163 if (want_address
!= 2)
13165 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13167 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13169 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13170 if (GET_CODE (varloc
) == EXPR_LIST
)
13171 varloc
= XEXP (varloc
, 0);
13172 mode
= GET_MODE (varloc
);
13173 if (MEM_P (varloc
))
13175 rtx addr
= XEXP (varloc
, 0);
13176 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13177 mode
, initialized
);
13182 rtx x
= avoid_constant_pool_reference (varloc
);
13184 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13189 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13196 if (GET_CODE (varloc
) == VAR_LOCATION
)
13197 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13199 mode
= DECL_MODE (loc
);
13200 descr
= loc_descriptor (varloc
, mode
, initialized
);
13207 if (want_address
== 2 && !have_address
13208 && (dwarf_version
>= 4 || !dwarf_strict
))
13210 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13212 expansion_failed (loc
, NULL_RTX
,
13213 "DWARF address size mismatch");
13216 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13219 /* Show if we can't fill the request for an address. */
13220 if (want_address
&& !have_address
)
13222 expansion_failed (loc
, NULL_RTX
,
13223 "Want address and only have value");
13227 /* If we've got an address and don't want one, dereference. */
13228 if (!want_address
&& have_address
)
13230 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13231 enum dwarf_location_atom op
;
13233 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13235 expansion_failed (loc
, NULL_RTX
,
13236 "DWARF address size mismatch");
13239 else if (size
== DWARF2_ADDR_SIZE
)
13242 op
= DW_OP_deref_size
;
13244 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13250 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13251 if it is not possible. */
13253 static dw_loc_descr_ref
13254 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13256 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13257 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13258 else if (dwarf_version
>= 3 || !dwarf_strict
)
13259 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13264 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13265 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13267 static dw_loc_descr_ref
13268 dw_sra_loc_expr (tree decl
, rtx loc
)
13271 unsigned int padsize
= 0;
13272 dw_loc_descr_ref descr
, *descr_tail
;
13273 unsigned HOST_WIDE_INT decl_size
;
13275 enum var_init_status initialized
;
13277 if (DECL_SIZE (decl
) == NULL
13278 || !host_integerp (DECL_SIZE (decl
), 1))
13281 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13283 descr_tail
= &descr
;
13285 for (p
= loc
; p
; p
= XEXP (p
, 1))
13287 unsigned int bitsize
= decl_piece_bitsize (p
);
13288 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13289 dw_loc_descr_ref cur_descr
;
13290 dw_loc_descr_ref
*tail
, last
= NULL
;
13291 unsigned int opsize
= 0;
13293 if (loc_note
== NULL_RTX
13294 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13296 padsize
+= bitsize
;
13299 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13300 varloc
= NOTE_VAR_LOCATION (loc_note
);
13301 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13302 if (cur_descr
== NULL
)
13304 padsize
+= bitsize
;
13308 /* Check that cur_descr either doesn't use
13309 DW_OP_*piece operations, or their sum is equal
13310 to bitsize. Otherwise we can't embed it. */
13311 for (tail
= &cur_descr
; *tail
!= NULL
;
13312 tail
= &(*tail
)->dw_loc_next
)
13313 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13315 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13319 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13321 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13325 if (last
!= NULL
&& opsize
!= bitsize
)
13327 padsize
+= bitsize
;
13331 /* If there is a hole, add DW_OP_*piece after empty DWARF
13332 expression, which means that those bits are optimized out. */
13335 if (padsize
> decl_size
)
13337 decl_size
-= padsize
;
13338 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13339 if (*descr_tail
== NULL
)
13341 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13344 *descr_tail
= cur_descr
;
13346 if (bitsize
> decl_size
)
13348 decl_size
-= bitsize
;
13351 HOST_WIDE_INT offset
= 0;
13352 if (GET_CODE (varloc
) == VAR_LOCATION
13353 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13355 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13356 if (GET_CODE (varloc
) == EXPR_LIST
)
13357 varloc
= XEXP (varloc
, 0);
13361 if (GET_CODE (varloc
) == CONST
13362 || GET_CODE (varloc
) == SIGN_EXTEND
13363 || GET_CODE (varloc
) == ZERO_EXTEND
)
13364 varloc
= XEXP (varloc
, 0);
13365 else if (GET_CODE (varloc
) == SUBREG
)
13366 varloc
= SUBREG_REG (varloc
);
13371 /* DW_OP_bit_size offset should be zero for register
13372 or implicit location descriptions and empty location
13373 descriptions, but for memory addresses needs big endian
13375 if (MEM_P (varloc
))
13377 unsigned HOST_WIDE_INT memsize
13378 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13379 if (memsize
!= bitsize
)
13381 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13382 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13384 if (memsize
< bitsize
)
13386 if (BITS_BIG_ENDIAN
)
13387 offset
= memsize
- bitsize
;
13391 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13392 if (*descr_tail
== NULL
)
13394 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13398 /* If there were any non-empty expressions, add padding till the end of
13400 if (descr
!= NULL
&& decl_size
!= 0)
13402 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13403 if (*descr_tail
== NULL
)
13409 /* Return the dwarf representation of the location list LOC_LIST of
13410 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13413 static dw_loc_list_ref
13414 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13416 const char *endname
, *secname
;
13418 enum var_init_status initialized
;
13419 struct var_loc_node
*node
;
13420 dw_loc_descr_ref descr
;
13421 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13422 dw_loc_list_ref list
= NULL
;
13423 dw_loc_list_ref
*listp
= &list
;
13425 /* Now that we know what section we are using for a base,
13426 actually construct the list of locations.
13427 The first location information is what is passed to the
13428 function that creates the location list, and the remaining
13429 locations just get added on to that list.
13430 Note that we only know the start address for a location
13431 (IE location changes), so to build the range, we use
13432 the range [current location start, next location start].
13433 This means we have to special case the last node, and generate
13434 a range of [last location start, end of function label]. */
13436 secname
= secname_for_decl (decl
);
13438 for (node
= loc_list
->first
; node
; node
= node
->next
)
13439 if (GET_CODE (node
->loc
) == EXPR_LIST
13440 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13442 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13444 /* This requires DW_OP_{,bit_}piece, which is not usable
13445 inside DWARF expressions. */
13446 if (want_address
!= 2)
13448 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13454 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13455 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13456 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13460 bool range_across_switch
= false;
13461 /* If section switch happens in between node->label
13462 and node->next->label (or end of function) and
13463 we can't emit it as a single entry list,
13464 emit two ranges, first one ending at the end
13465 of first partition and second one starting at the
13466 beginning of second partition. */
13467 if (node
== loc_list
->last_before_switch
13468 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13469 && current_function_decl
)
13471 endname
= cfun
->fde
->dw_fde_end
;
13472 range_across_switch
= true;
13474 /* The variable has a location between NODE->LABEL and
13475 NODE->NEXT->LABEL. */
13476 else if (node
->next
)
13477 endname
= node
->next
->label
;
13478 /* If the variable has a location at the last label
13479 it keeps its location until the end of function. */
13480 else if (!current_function_decl
)
13481 endname
= text_end_label
;
13484 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13485 current_function_funcdef_no
);
13486 endname
= ggc_strdup (label_id
);
13489 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13490 if (TREE_CODE (decl
) == PARM_DECL
13491 && node
== loc_list
->first
13492 && GET_CODE (node
->loc
) == NOTE
13493 && strcmp (node
->label
, endname
) == 0)
13494 (*listp
)->force
= true;
13495 listp
= &(*listp
)->dw_loc_next
;
13497 if (range_across_switch
)
13499 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13500 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13503 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13504 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13505 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13508 gcc_assert (descr
);
13509 /* The variable has a location between NODE->LABEL and
13510 NODE->NEXT->LABEL. */
13512 endname
= node
->next
->label
;
13514 endname
= cfun
->fde
->dw_fde_second_end
;
13515 *listp
= new_loc_list (descr
,
13516 cfun
->fde
->dw_fde_second_begin
,
13518 listp
= &(*listp
)->dw_loc_next
;
13523 /* Try to avoid the overhead of a location list emitting a location
13524 expression instead, but only if we didn't have more than one
13525 location entry in the first place. If some entries were not
13526 representable, we don't want to pretend a single entry that was
13527 applies to the entire scope in which the variable is
13529 if (list
&& loc_list
->first
->next
)
13535 /* Return if the loc_list has only single element and thus can be represented
13536 as location description. */
13539 single_element_loc_list_p (dw_loc_list_ref list
)
13541 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13542 return !list
->ll_symbol
;
13545 /* To each location in list LIST add loc descr REF. */
13548 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13550 dw_loc_descr_ref copy
;
13551 add_loc_descr (&list
->expr
, ref
);
13552 list
= list
->dw_loc_next
;
13555 copy
= ggc_alloc_dw_loc_descr_node ();
13556 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13557 add_loc_descr (&list
->expr
, copy
);
13558 while (copy
->dw_loc_next
)
13560 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13561 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13562 copy
->dw_loc_next
= new_copy
;
13565 list
= list
->dw_loc_next
;
13569 /* Given two lists RET and LIST
13570 produce location list that is result of adding expression in LIST
13571 to expression in RET on each position in program.
13572 Might be destructive on both RET and LIST.
13574 TODO: We handle only simple cases of RET or LIST having at most one
13575 element. General case would inolve sorting the lists in program order
13576 and merging them that will need some additional work.
13577 Adding that will improve quality of debug info especially for SRA-ed
13581 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13590 if (!list
->dw_loc_next
)
13592 add_loc_descr_to_each (*ret
, list
->expr
);
13595 if (!(*ret
)->dw_loc_next
)
13597 add_loc_descr_to_each (list
, (*ret
)->expr
);
13601 expansion_failed (NULL_TREE
, NULL_RTX
,
13602 "Don't know how to merge two non-trivial"
13603 " location lists.\n");
13608 /* LOC is constant expression. Try a luck, look it up in constant
13609 pool and return its loc_descr of its address. */
13611 static dw_loc_descr_ref
13612 cst_pool_loc_descr (tree loc
)
13614 /* Get an RTL for this, if something has been emitted. */
13615 rtx rtl
= lookup_constant_def (loc
);
13617 if (!rtl
|| !MEM_P (rtl
))
13622 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13624 /* TODO: We might get more coverage if we was actually delaying expansion
13625 of all expressions till end of compilation when constant pools are fully
13627 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13629 expansion_failed (loc
, NULL_RTX
,
13630 "CST value in contant pool but not marked.");
13633 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13634 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13637 /* Return dw_loc_list representing address of addr_expr LOC
13638 by looking for inner INDIRECT_REF expression and turning
13639 it into simple arithmetics. */
13641 static dw_loc_list_ref
13642 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13645 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13646 enum machine_mode mode
;
13647 int unsignedp
, volatilep
= 0;
13648 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13650 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13651 &bitsize
, &bitpos
, &offset
, &mode
,
13652 &unsignedp
, &volatilep
, false);
13654 if (bitpos
% BITS_PER_UNIT
)
13656 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13659 if (!INDIRECT_REF_P (obj
))
13661 expansion_failed (obj
,
13662 NULL_RTX
, "no indirect ref in inner refrence");
13665 if (!offset
&& !bitpos
)
13666 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13668 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13669 && (dwarf_version
>= 4 || !dwarf_strict
))
13671 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13676 /* Variable offset. */
13677 list_ret1
= loc_list_from_tree (offset
, 0);
13678 if (list_ret1
== 0)
13680 add_loc_list (&list_ret
, list_ret1
);
13683 add_loc_descr_to_each (list_ret
,
13684 new_loc_descr (DW_OP_plus
, 0, 0));
13686 bytepos
= bitpos
/ BITS_PER_UNIT
;
13688 add_loc_descr_to_each (list_ret
,
13689 new_loc_descr (DW_OP_plus_uconst
,
13691 else if (bytepos
< 0)
13692 loc_list_plus_const (list_ret
, bytepos
);
13693 add_loc_descr_to_each (list_ret
,
13694 new_loc_descr (DW_OP_stack_value
, 0, 0));
13700 /* Generate Dwarf location list representing LOC.
13701 If WANT_ADDRESS is false, expression computing LOC will be computed
13702 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13703 if WANT_ADDRESS is 2, expression computing address useable in location
13704 will be returned (i.e. DW_OP_reg can be used
13705 to refer to register values). */
13707 static dw_loc_list_ref
13708 loc_list_from_tree (tree loc
, int want_address
)
13710 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13711 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13712 int have_address
= 0;
13713 enum dwarf_location_atom op
;
13715 /* ??? Most of the time we do not take proper care for sign/zero
13716 extending the values properly. Hopefully this won't be a real
13719 switch (TREE_CODE (loc
))
13722 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13725 case PLACEHOLDER_EXPR
:
13726 /* This case involves extracting fields from an object to determine the
13727 position of other fields. We don't try to encode this here. The
13728 only user of this is Ada, which encodes the needed information using
13729 the names of types. */
13730 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13734 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13735 /* There are no opcodes for these operations. */
13738 case PREINCREMENT_EXPR
:
13739 case PREDECREMENT_EXPR
:
13740 case POSTINCREMENT_EXPR
:
13741 case POSTDECREMENT_EXPR
:
13742 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13743 /* There are no opcodes for these operations. */
13747 /* If we already want an address, see if there is INDIRECT_REF inside
13748 e.g. for &this->field. */
13751 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13752 (loc
, want_address
== 2);
13755 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13756 && (ret
= cst_pool_loc_descr (loc
)))
13759 /* Otherwise, process the argument and look for the address. */
13760 if (!list_ret
&& !ret
)
13761 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13765 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13771 if (DECL_THREAD_LOCAL_P (loc
))
13774 enum dwarf_location_atom tls_op
;
13775 enum dtprel_bool dtprel
= dtprel_false
;
13777 if (targetm
.have_tls
)
13779 /* If this is not defined, we have no way to emit the
13781 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13784 /* The way DW_OP_GNU_push_tls_address is specified, we
13785 can only look up addresses of objects in the current
13786 module. We used DW_OP_addr as first op, but that's
13787 wrong, because DW_OP_addr is relocated by the debug
13788 info consumer, while DW_OP_GNU_push_tls_address
13789 operand shouldn't be. */
13790 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13792 dtprel
= dtprel_true
;
13793 tls_op
= DW_OP_GNU_push_tls_address
;
13797 if (!targetm
.emutls
.debug_form_tls_address
13798 || !(dwarf_version
>= 3 || !dwarf_strict
))
13800 /* We stuffed the control variable into the DECL_VALUE_EXPR
13801 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13802 no longer appear in gimple code. We used the control
13803 variable in specific so that we could pick it up here. */
13804 loc
= DECL_VALUE_EXPR (loc
);
13805 tls_op
= DW_OP_form_tls_address
;
13808 rtl
= rtl_for_decl_location (loc
);
13809 if (rtl
== NULL_RTX
)
13814 rtl
= XEXP (rtl
, 0);
13815 if (! CONSTANT_P (rtl
))
13818 ret
= new_addr_loc_descr (rtl
, dtprel
);
13819 ret1
= new_loc_descr (tls_op
, 0, 0);
13820 add_loc_descr (&ret
, ret1
);
13829 if (DECL_HAS_VALUE_EXPR_P (loc
))
13830 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13834 case FUNCTION_DECL
:
13837 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13839 if (loc_list
&& loc_list
->first
)
13841 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13842 have_address
= want_address
!= 0;
13845 rtl
= rtl_for_decl_location (loc
);
13846 if (rtl
== NULL_RTX
)
13848 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13851 else if (CONST_INT_P (rtl
))
13853 HOST_WIDE_INT val
= INTVAL (rtl
);
13854 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13855 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13856 ret
= int_loc_descriptor (val
);
13858 else if (GET_CODE (rtl
) == CONST_STRING
)
13860 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13863 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13864 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
13867 enum machine_mode mode
, mem_mode
;
13869 /* Certain constructs can only be represented at top-level. */
13870 if (want_address
== 2)
13872 ret
= loc_descriptor (rtl
, VOIDmode
,
13873 VAR_INIT_STATUS_INITIALIZED
);
13878 mode
= GET_MODE (rtl
);
13879 mem_mode
= VOIDmode
;
13883 mode
= get_address_mode (rtl
);
13884 rtl
= XEXP (rtl
, 0);
13887 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13888 VAR_INIT_STATUS_INITIALIZED
);
13891 expansion_failed (loc
, rtl
,
13892 "failed to produce loc descriptor for rtl");
13899 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
13903 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13907 case COMPOUND_EXPR
:
13908 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
13911 case VIEW_CONVERT_EXPR
:
13914 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
13916 case COMPONENT_REF
:
13917 case BIT_FIELD_REF
:
13919 case ARRAY_RANGE_REF
:
13920 case REALPART_EXPR
:
13921 case IMAGPART_EXPR
:
13924 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13925 enum machine_mode mode
;
13926 int unsignedp
, volatilep
= 0;
13928 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
13929 &unsignedp
, &volatilep
, false);
13931 gcc_assert (obj
!= loc
);
13933 list_ret
= loc_list_from_tree (obj
,
13935 && !bitpos
&& !offset
? 2 : 1);
13936 /* TODO: We can extract value of the small expression via shifting even
13937 for nonzero bitpos. */
13940 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
13942 expansion_failed (loc
, NULL_RTX
,
13943 "bitfield access");
13947 if (offset
!= NULL_TREE
)
13949 /* Variable offset. */
13950 list_ret1
= loc_list_from_tree (offset
, 0);
13951 if (list_ret1
== 0)
13953 add_loc_list (&list_ret
, list_ret1
);
13956 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
13959 bytepos
= bitpos
/ BITS_PER_UNIT
;
13961 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
13962 else if (bytepos
< 0)
13963 loc_list_plus_const (list_ret
, bytepos
);
13970 if ((want_address
|| !host_integerp (loc
, 0))
13971 && (ret
= cst_pool_loc_descr (loc
)))
13973 else if (want_address
== 2
13974 && host_integerp (loc
, 0)
13975 && (ret
= address_of_int_loc_descriptor
13976 (int_size_in_bytes (TREE_TYPE (loc
)),
13977 tree_low_cst (loc
, 0))))
13979 else if (host_integerp (loc
, 0))
13980 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
13983 expansion_failed (loc
, NULL_RTX
,
13984 "Integer operand is not host integer");
13993 if ((ret
= cst_pool_loc_descr (loc
)))
13996 /* We can construct small constants here using int_loc_descriptor. */
13997 expansion_failed (loc
, NULL_RTX
,
13998 "constructor or constant not in constant pool");
14001 case TRUTH_AND_EXPR
:
14002 case TRUTH_ANDIF_EXPR
:
14007 case TRUTH_XOR_EXPR
:
14012 case TRUTH_OR_EXPR
:
14013 case TRUTH_ORIF_EXPR
:
14018 case FLOOR_DIV_EXPR
:
14019 case CEIL_DIV_EXPR
:
14020 case ROUND_DIV_EXPR
:
14021 case TRUNC_DIV_EXPR
:
14022 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14031 case FLOOR_MOD_EXPR
:
14032 case CEIL_MOD_EXPR
:
14033 case ROUND_MOD_EXPR
:
14034 case TRUNC_MOD_EXPR
:
14035 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14040 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14041 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14042 if (list_ret
== 0 || list_ret1
== 0)
14045 add_loc_list (&list_ret
, list_ret1
);
14048 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14049 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14050 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14051 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14052 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14064 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14067 case POINTER_PLUS_EXPR
:
14069 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14071 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14075 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14083 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14090 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14097 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14104 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14119 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14120 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14121 if (list_ret
== 0 || list_ret1
== 0)
14124 add_loc_list (&list_ret
, list_ret1
);
14127 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14130 case TRUTH_NOT_EXPR
:
14144 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14148 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14154 const enum tree_code code
=
14155 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14157 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14158 build2 (code
, integer_type_node
,
14159 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14160 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14163 /* ... fall through ... */
14167 dw_loc_descr_ref lhs
14168 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14169 dw_loc_list_ref rhs
14170 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14171 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14173 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14174 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14177 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14178 add_loc_descr_to_each (list_ret
, bra_node
);
14180 add_loc_list (&list_ret
, rhs
);
14181 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14182 add_loc_descr_to_each (list_ret
, jump_node
);
14184 add_loc_descr_to_each (list_ret
, lhs
);
14185 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14186 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14188 /* ??? Need a node to point the skip at. Use a nop. */
14189 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14190 add_loc_descr_to_each (list_ret
, tmp
);
14191 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14192 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14196 case FIX_TRUNC_EXPR
:
14200 /* Leave front-end specific codes as simply unknown. This comes
14201 up, for instance, with the C STMT_EXPR. */
14202 if ((unsigned int) TREE_CODE (loc
)
14203 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14205 expansion_failed (loc
, NULL_RTX
,
14206 "language specific tree node");
14210 #ifdef ENABLE_CHECKING
14211 /* Otherwise this is a generic code; we should just lists all of
14212 these explicitly. We forgot one. */
14213 gcc_unreachable ();
14215 /* In a release build, we want to degrade gracefully: better to
14216 generate incomplete debugging information than to crash. */
14221 if (!ret
&& !list_ret
)
14224 if (want_address
== 2 && !have_address
14225 && (dwarf_version
>= 4 || !dwarf_strict
))
14227 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14229 expansion_failed (loc
, NULL_RTX
,
14230 "DWARF address size mismatch");
14234 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14236 add_loc_descr_to_each (list_ret
,
14237 new_loc_descr (DW_OP_stack_value
, 0, 0));
14240 /* Show if we can't fill the request for an address. */
14241 if (want_address
&& !have_address
)
14243 expansion_failed (loc
, NULL_RTX
,
14244 "Want address and only have value");
14248 gcc_assert (!ret
|| !list_ret
);
14250 /* If we've got an address and don't want one, dereference. */
14251 if (!want_address
&& have_address
)
14253 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14255 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14257 expansion_failed (loc
, NULL_RTX
,
14258 "DWARF address size mismatch");
14261 else if (size
== DWARF2_ADDR_SIZE
)
14264 op
= DW_OP_deref_size
;
14267 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14269 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14272 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14277 /* Same as above but return only single location expression. */
14278 static dw_loc_descr_ref
14279 loc_descriptor_from_tree (tree loc
, int want_address
)
14281 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14284 if (ret
->dw_loc_next
)
14286 expansion_failed (loc
, NULL_RTX
,
14287 "Location list where only loc descriptor needed");
14293 /* Given a value, round it up to the lowest multiple of `boundary'
14294 which is not less than the value itself. */
14296 static inline HOST_WIDE_INT
14297 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14299 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14302 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14303 pointer to the declared type for the relevant field variable, or return
14304 `integer_type_node' if the given node turns out to be an
14305 ERROR_MARK node. */
14308 field_type (const_tree decl
)
14312 if (TREE_CODE (decl
) == ERROR_MARK
)
14313 return integer_type_node
;
14315 type
= DECL_BIT_FIELD_TYPE (decl
);
14316 if (type
== NULL_TREE
)
14317 type
= TREE_TYPE (decl
);
14322 /* Given a pointer to a tree node, return the alignment in bits for
14323 it, or else return BITS_PER_WORD if the node actually turns out to
14324 be an ERROR_MARK node. */
14326 static inline unsigned
14327 simple_type_align_in_bits (const_tree type
)
14329 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14332 static inline unsigned
14333 simple_decl_align_in_bits (const_tree decl
)
14335 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14338 /* Return the result of rounding T up to ALIGN. */
14340 static inline double_int
14341 round_up_to_align (double_int t
, unsigned int align
)
14343 double_int alignd
= double_int::from_uhwi (align
);
14345 t
+= double_int_minus_one
;
14346 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14351 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14352 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14353 or return 0 if we are unable to determine what that offset is, either
14354 because the argument turns out to be a pointer to an ERROR_MARK node, or
14355 because the offset is actually variable. (We can't handle the latter case
14358 static HOST_WIDE_INT
14359 field_byte_offset (const_tree decl
)
14361 double_int object_offset_in_bits
;
14362 double_int object_offset_in_bytes
;
14363 double_int bitpos_int
;
14365 if (TREE_CODE (decl
) == ERROR_MARK
)
14368 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14370 /* We cannot yet cope with fields whose positions are variable, so
14371 for now, when we see such things, we simply return 0. Someday, we may
14372 be able to handle such cases, but it will be damn difficult. */
14373 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14376 bitpos_int
= tree_to_double_int (bit_position (decl
));
14378 #ifdef PCC_BITFIELD_TYPE_MATTERS
14379 if (PCC_BITFIELD_TYPE_MATTERS
)
14382 tree field_size_tree
;
14383 double_int deepest_bitpos
;
14384 double_int field_size_in_bits
;
14385 unsigned int type_align_in_bits
;
14386 unsigned int decl_align_in_bits
;
14387 double_int type_size_in_bits
;
14389 type
= field_type (decl
);
14390 type_size_in_bits
= double_int_type_size_in_bits (type
);
14391 type_align_in_bits
= simple_type_align_in_bits (type
);
14393 field_size_tree
= DECL_SIZE (decl
);
14395 /* The size could be unspecified if there was an error, or for
14396 a flexible array member. */
14397 if (!field_size_tree
)
14398 field_size_tree
= bitsize_zero_node
;
14400 /* If the size of the field is not constant, use the type size. */
14401 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14402 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14404 field_size_in_bits
= type_size_in_bits
;
14406 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14408 /* The GCC front-end doesn't make any attempt to keep track of the
14409 starting bit offset (relative to the start of the containing
14410 structure type) of the hypothetical "containing object" for a
14411 bit-field. Thus, when computing the byte offset value for the
14412 start of the "containing object" of a bit-field, we must deduce
14413 this information on our own. This can be rather tricky to do in
14414 some cases. For example, handling the following structure type
14415 definition when compiling for an i386/i486 target (which only
14416 aligns long long's to 32-bit boundaries) can be very tricky:
14418 struct S { int field1; long long field2:31; };
14420 Fortunately, there is a simple rule-of-thumb which can be used
14421 in such cases. When compiling for an i386/i486, GCC will
14422 allocate 8 bytes for the structure shown above. It decides to
14423 do this based upon one simple rule for bit-field allocation.
14424 GCC allocates each "containing object" for each bit-field at
14425 the first (i.e. lowest addressed) legitimate alignment boundary
14426 (based upon the required minimum alignment for the declared
14427 type of the field) which it can possibly use, subject to the
14428 condition that there is still enough available space remaining
14429 in the containing object (when allocated at the selected point)
14430 to fully accommodate all of the bits of the bit-field itself.
14432 This simple rule makes it obvious why GCC allocates 8 bytes for
14433 each object of the structure type shown above. When looking
14434 for a place to allocate the "containing object" for `field2',
14435 the compiler simply tries to allocate a 64-bit "containing
14436 object" at each successive 32-bit boundary (starting at zero)
14437 until it finds a place to allocate that 64- bit field such that
14438 at least 31 contiguous (and previously unallocated) bits remain
14439 within that selected 64 bit field. (As it turns out, for the
14440 example above, the compiler finds it is OK to allocate the
14441 "containing object" 64-bit field at bit-offset zero within the
14444 Here we attempt to work backwards from the limited set of facts
14445 we're given, and we try to deduce from those facts, where GCC
14446 must have believed that the containing object started (within
14447 the structure type). The value we deduce is then used (by the
14448 callers of this routine) to generate DW_AT_location and
14449 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14450 the case of DW_AT_location, regular fields as well). */
14452 /* Figure out the bit-distance from the start of the structure to
14453 the "deepest" bit of the bit-field. */
14454 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14456 /* This is the tricky part. Use some fancy footwork to deduce
14457 where the lowest addressed bit of the containing object must
14459 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14461 /* Round up to type_align by default. This works best for
14463 object_offset_in_bits
14464 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14466 if (object_offset_in_bits
.ugt (bitpos_int
))
14468 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14470 /* Round up to decl_align instead. */
14471 object_offset_in_bits
14472 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14476 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14477 object_offset_in_bits
= bitpos_int
;
14479 object_offset_in_bytes
14480 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14481 true, TRUNC_DIV_EXPR
);
14482 return object_offset_in_bytes
.to_shwi ();
14485 /* The following routines define various Dwarf attributes and any data
14486 associated with them. */
14488 /* Add a location description attribute value to a DIE.
14490 This emits location attributes suitable for whole variables and
14491 whole parameters. Note that the location attributes for struct fields are
14492 generated by the routine `data_member_location_attribute' below. */
14495 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14496 dw_loc_list_ref descr
)
14500 if (single_element_loc_list_p (descr
))
14501 add_AT_loc (die
, attr_kind
, descr
->expr
);
14503 add_AT_loc_list (die
, attr_kind
, descr
);
14506 /* Add DW_AT_accessibility attribute to DIE if needed. */
14509 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14511 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14512 children, otherwise the default is DW_ACCESS_public. In DWARF2
14513 the default has always been DW_ACCESS_public. */
14514 if (TREE_PROTECTED (decl
))
14515 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14516 else if (TREE_PRIVATE (decl
))
14518 if (dwarf_version
== 2
14519 || die
->die_parent
== NULL
14520 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14521 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14523 else if (dwarf_version
> 2
14525 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14526 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14529 /* Attach the specialized form of location attribute used for data members of
14530 struct and union types. In the special case of a FIELD_DECL node which
14531 represents a bit-field, the "offset" part of this special location
14532 descriptor must indicate the distance in bytes from the lowest-addressed
14533 byte of the containing struct or union type to the lowest-addressed byte of
14534 the "containing object" for the bit-field. (See the `field_byte_offset'
14537 For any given bit-field, the "containing object" is a hypothetical object
14538 (of some integral or enum type) within which the given bit-field lives. The
14539 type of this hypothetical "containing object" is always the same as the
14540 declared type of the individual bit-field itself (for GCC anyway... the
14541 DWARF spec doesn't actually mandate this). Note that it is the size (in
14542 bytes) of the hypothetical "containing object" which will be given in the
14543 DW_AT_byte_size attribute for this bit-field. (See the
14544 `byte_size_attribute' function below.) It is also used when calculating the
14545 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14546 function below.) */
14549 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14551 HOST_WIDE_INT offset
;
14552 dw_loc_descr_ref loc_descr
= 0;
14554 if (TREE_CODE (decl
) == TREE_BINFO
)
14556 /* We're working on the TAG_inheritance for a base class. */
14557 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14559 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14560 aren't at a fixed offset from all (sub)objects of the same
14561 type. We need to extract the appropriate offset from our
14562 vtable. The following dwarf expression means
14564 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14566 This is specific to the V3 ABI, of course. */
14568 dw_loc_descr_ref tmp
;
14570 /* Make a copy of the object address. */
14571 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14572 add_loc_descr (&loc_descr
, tmp
);
14574 /* Extract the vtable address. */
14575 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14576 add_loc_descr (&loc_descr
, tmp
);
14578 /* Calculate the address of the offset. */
14579 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14580 gcc_assert (offset
< 0);
14582 tmp
= int_loc_descriptor (-offset
);
14583 add_loc_descr (&loc_descr
, tmp
);
14584 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14585 add_loc_descr (&loc_descr
, tmp
);
14587 /* Extract the offset. */
14588 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14589 add_loc_descr (&loc_descr
, tmp
);
14591 /* Add it to the object address. */
14592 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14593 add_loc_descr (&loc_descr
, tmp
);
14596 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14599 offset
= field_byte_offset (decl
);
14603 if (dwarf_version
> 2)
14605 /* Don't need to output a location expression, just the constant. */
14607 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14609 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14614 enum dwarf_location_atom op
;
14616 /* The DWARF2 standard says that we should assume that the structure
14617 address is already on the stack, so we can specify a structure
14618 field address by using DW_OP_plus_uconst. */
14619 op
= DW_OP_plus_uconst
;
14620 loc_descr
= new_loc_descr (op
, offset
, 0);
14624 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14627 /* Writes integer values to dw_vec_const array. */
14630 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14634 *dest
++ = val
& 0xff;
14640 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14642 static HOST_WIDE_INT
14643 extract_int (const unsigned char *src
, unsigned int size
)
14645 HOST_WIDE_INT val
= 0;
14651 val
|= *--src
& 0xff;
14657 /* Writes double_int values to dw_vec_const array. */
14660 insert_double (double_int val
, unsigned char *dest
)
14662 unsigned char *p0
= dest
;
14663 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14665 if (WORDS_BIG_ENDIAN
)
14671 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14672 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14675 /* Writes floating point values to dw_vec_const array. */
14678 insert_float (const_rtx rtl
, unsigned char *array
)
14680 REAL_VALUE_TYPE rv
;
14684 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14685 real_to_target (val
, &rv
, GET_MODE (rtl
));
14687 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14688 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14690 insert_int (val
[i
], 4, array
);
14695 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14696 does not have a "location" either in memory or in a register. These
14697 things can arise in GNU C when a constant is passed as an actual parameter
14698 to an inlined function. They can also arise in C++ where declared
14699 constants do not necessarily get memory "homes". */
14702 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14704 switch (GET_CODE (rtl
))
14708 HOST_WIDE_INT val
= INTVAL (rtl
);
14711 add_AT_int (die
, DW_AT_const_value
, val
);
14713 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14718 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14719 floating-point constant. A CONST_DOUBLE is used whenever the
14720 constant requires more than one word in order to be adequately
14723 enum machine_mode mode
= GET_MODE (rtl
);
14725 if (SCALAR_FLOAT_MODE_P (mode
))
14727 unsigned int length
= GET_MODE_SIZE (mode
);
14728 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14730 insert_float (rtl
, array
);
14731 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14734 add_AT_double (die
, DW_AT_const_value
,
14735 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14741 enum machine_mode mode
= GET_MODE (rtl
);
14742 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14743 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14744 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14745 (length
* elt_size
);
14749 switch (GET_MODE_CLASS (mode
))
14751 case MODE_VECTOR_INT
:
14752 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14754 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14755 double_int val
= rtx_to_double_int (elt
);
14757 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14758 insert_int (val
.to_shwi (), elt_size
, p
);
14761 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14762 insert_double (val
, p
);
14767 case MODE_VECTOR_FLOAT
:
14768 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14770 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14771 insert_float (elt
, p
);
14776 gcc_unreachable ();
14779 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14784 if (dwarf_version
>= 4 || !dwarf_strict
)
14786 dw_loc_descr_ref loc_result
;
14787 resolve_one_addr (&rtl
, NULL
);
14789 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14790 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14791 add_AT_loc (die
, DW_AT_location
, loc_result
);
14792 vec_safe_push (used_rtx_array
, rtl
);
14798 if (CONSTANT_P (XEXP (rtl
, 0)))
14799 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14802 if (!const_ok_for_output (rtl
))
14805 if (dwarf_version
>= 4 || !dwarf_strict
)
14810 /* In cases where an inlined instance of an inline function is passed
14811 the address of an `auto' variable (which is local to the caller) we
14812 can get a situation where the DECL_RTL of the artificial local
14813 variable (for the inlining) which acts as a stand-in for the
14814 corresponding formal parameter (of the inline function) will look
14815 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14816 exactly a compile-time constant expression, but it isn't the address
14817 of the (artificial) local variable either. Rather, it represents the
14818 *value* which the artificial local variable always has during its
14819 lifetime. We currently have no way to represent such quasi-constant
14820 values in Dwarf, so for now we just punt and generate nothing. */
14828 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14829 && MEM_READONLY_P (rtl
)
14830 && GET_MODE (rtl
) == BLKmode
)
14832 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14838 /* No other kinds of rtx should be possible here. */
14839 gcc_unreachable ();
14844 /* Determine whether the evaluation of EXPR references any variables
14845 or functions which aren't otherwise used (and therefore may not be
14848 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14849 void * data ATTRIBUTE_UNUSED
)
14851 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14852 *walk_subtrees
= 0;
14854 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14855 && ! TREE_ASM_WRITTEN (*tp
))
14857 /* ??? The C++ FE emits debug information for using decls, so
14858 putting gcc_unreachable here falls over. See PR31899. For now
14859 be conservative. */
14860 else if (!cgraph_global_info_ready
14861 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14863 else if (TREE_CODE (*tp
) == VAR_DECL
)
14865 struct varpool_node
*node
= varpool_get_node (*tp
);
14866 if (!node
|| !node
->analyzed
)
14869 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14870 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14872 /* The call graph machinery must have finished analyzing,
14873 optimizing and gimplifying the CU by now.
14874 So if *TP has no call graph node associated
14875 to it, it means *TP will not be emitted. */
14876 if (!cgraph_get_node (*tp
))
14879 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14885 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14886 for use in a later add_const_value_attribute call. */
14889 rtl_for_decl_init (tree init
, tree type
)
14891 rtx rtl
= NULL_RTX
;
14895 /* If a variable is initialized with a string constant without embedded
14896 zeros, build CONST_STRING. */
14897 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14899 tree enttype
= TREE_TYPE (type
);
14900 tree domain
= TYPE_DOMAIN (type
);
14901 enum machine_mode mode
= TYPE_MODE (enttype
);
14903 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
14905 && integer_zerop (TYPE_MIN_VALUE (domain
))
14906 && compare_tree_int (TYPE_MAX_VALUE (domain
),
14907 TREE_STRING_LENGTH (init
) - 1) == 0
14908 && ((size_t) TREE_STRING_LENGTH (init
)
14909 == strlen (TREE_STRING_POINTER (init
)) + 1))
14911 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
14912 ggc_strdup (TREE_STRING_POINTER (init
)));
14913 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
14914 MEM_READONLY_P (rtl
) = 1;
14917 /* Other aggregates, and complex values, could be represented using
14919 else if (AGGREGATE_TYPE_P (type
)
14920 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
14921 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
14922 || TREE_CODE (type
) == COMPLEX_TYPE
)
14924 /* Vectors only work if their mode is supported by the target.
14925 FIXME: generic vectors ought to work too. */
14926 else if (TREE_CODE (type
) == VECTOR_TYPE
14927 && !VECTOR_MODE_P (TYPE_MODE (type
)))
14929 /* If the initializer is something that we know will expand into an
14930 immediate RTL constant, expand it now. We must be careful not to
14931 reference variables which won't be output. */
14932 else if (initializer_constant_valid_p (init
, type
)
14933 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
14935 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14937 if (TREE_CODE (type
) == VECTOR_TYPE
)
14938 switch (TREE_CODE (init
))
14943 if (TREE_CONSTANT (init
))
14945 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
14946 bool constant_p
= true;
14948 unsigned HOST_WIDE_INT ix
;
14950 /* Even when ctor is constant, it might contain non-*_CST
14951 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
14952 belong into VECTOR_CST nodes. */
14953 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
14954 if (!CONSTANT_CLASS_P (value
))
14956 constant_p
= false;
14962 init
= build_vector_from_ctor (type
, elts
);
14972 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
14974 /* If expand_expr returns a MEM, it wasn't immediate. */
14975 gcc_assert (!rtl
|| !MEM_P (rtl
));
14981 /* Generate RTL for the variable DECL to represent its location. */
14984 rtl_for_decl_location (tree decl
)
14988 /* Here we have to decide where we are going to say the parameter "lives"
14989 (as far as the debugger is concerned). We only have a couple of
14990 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
14992 DECL_RTL normally indicates where the parameter lives during most of the
14993 activation of the function. If optimization is enabled however, this
14994 could be either NULL or else a pseudo-reg. Both of those cases indicate
14995 that the parameter doesn't really live anywhere (as far as the code
14996 generation parts of GCC are concerned) during most of the function's
14997 activation. That will happen (for example) if the parameter is never
14998 referenced within the function.
15000 We could just generate a location descriptor here for all non-NULL
15001 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15002 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15003 where DECL_RTL is NULL or is a pseudo-reg.
15005 Note however that we can only get away with using DECL_INCOMING_RTL as
15006 a backup substitute for DECL_RTL in certain limited cases. In cases
15007 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15008 we can be sure that the parameter was passed using the same type as it is
15009 declared to have within the function, and that its DECL_INCOMING_RTL
15010 points us to a place where a value of that type is passed.
15012 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15013 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15014 because in these cases DECL_INCOMING_RTL points us to a value of some
15015 type which is *different* from the type of the parameter itself. Thus,
15016 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15017 such cases, the debugger would end up (for example) trying to fetch a
15018 `float' from a place which actually contains the first part of a
15019 `double'. That would lead to really incorrect and confusing
15020 output at debug-time.
15022 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15023 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15024 are a couple of exceptions however. On little-endian machines we can
15025 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15026 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15027 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15028 when (on a little-endian machine) a non-prototyped function has a
15029 parameter declared to be of type `short' or `char'. In such cases,
15030 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15031 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15032 passed `int' value. If the debugger then uses that address to fetch
15033 a `short' or a `char' (on a little-endian machine) the result will be
15034 the correct data, so we allow for such exceptional cases below.
15036 Note that our goal here is to describe the place where the given formal
15037 parameter lives during most of the function's activation (i.e. between the
15038 end of the prologue and the start of the epilogue). We'll do that as best
15039 as we can. Note however that if the given formal parameter is modified
15040 sometime during the execution of the function, then a stack backtrace (at
15041 debug-time) will show the function as having been called with the *new*
15042 value rather than the value which was originally passed in. This happens
15043 rarely enough that it is not a major problem, but it *is* a problem, and
15044 I'd like to fix it.
15046 A future version of dwarf2out.c may generate two additional attributes for
15047 any given DW_TAG_formal_parameter DIE which will describe the "passed
15048 type" and the "passed location" for the given formal parameter in addition
15049 to the attributes we now generate to indicate the "declared type" and the
15050 "active location" for each parameter. This additional set of attributes
15051 could be used by debuggers for stack backtraces. Separately, note that
15052 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15053 This happens (for example) for inlined-instances of inline function formal
15054 parameters which are never referenced. This really shouldn't be
15055 happening. All PARM_DECL nodes should get valid non-NULL
15056 DECL_INCOMING_RTL values. FIXME. */
15058 /* Use DECL_RTL as the "location" unless we find something better. */
15059 rtl
= DECL_RTL_IF_SET (decl
);
15061 /* When generating abstract instances, ignore everything except
15062 constants, symbols living in memory, and symbols living in
15063 fixed registers. */
15064 if (! reload_completed
)
15067 && (CONSTANT_P (rtl
)
15069 && CONSTANT_P (XEXP (rtl
, 0)))
15071 && TREE_CODE (decl
) == VAR_DECL
15072 && TREE_STATIC (decl
))))
15074 rtl
= targetm
.delegitimize_address (rtl
);
15079 else if (TREE_CODE (decl
) == PARM_DECL
)
15081 if (rtl
== NULL_RTX
15082 || is_pseudo_reg (rtl
)
15084 && is_pseudo_reg (XEXP (rtl
, 0))
15085 && DECL_INCOMING_RTL (decl
)
15086 && MEM_P (DECL_INCOMING_RTL (decl
))
15087 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15089 tree declared_type
= TREE_TYPE (decl
);
15090 tree passed_type
= DECL_ARG_TYPE (decl
);
15091 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15092 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15094 /* This decl represents a formal parameter which was optimized out.
15095 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15096 all cases where (rtl == NULL_RTX) just below. */
15097 if (dmode
== pmode
)
15098 rtl
= DECL_INCOMING_RTL (decl
);
15099 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15100 && SCALAR_INT_MODE_P (dmode
)
15101 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15102 && DECL_INCOMING_RTL (decl
))
15104 rtx inc
= DECL_INCOMING_RTL (decl
);
15107 else if (MEM_P (inc
))
15109 if (BYTES_BIG_ENDIAN
)
15110 rtl
= adjust_address_nv (inc
, dmode
,
15111 GET_MODE_SIZE (pmode
)
15112 - GET_MODE_SIZE (dmode
));
15119 /* If the parm was passed in registers, but lives on the stack, then
15120 make a big endian correction if the mode of the type of the
15121 parameter is not the same as the mode of the rtl. */
15122 /* ??? This is the same series of checks that are made in dbxout.c before
15123 we reach the big endian correction code there. It isn't clear if all
15124 of these checks are necessary here, but keeping them all is the safe
15126 else if (MEM_P (rtl
)
15127 && XEXP (rtl
, 0) != const0_rtx
15128 && ! CONSTANT_P (XEXP (rtl
, 0))
15129 /* Not passed in memory. */
15130 && !MEM_P (DECL_INCOMING_RTL (decl
))
15131 /* Not passed by invisible reference. */
15132 && (!REG_P (XEXP (rtl
, 0))
15133 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15134 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15135 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15136 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15139 /* Big endian correction check. */
15140 && BYTES_BIG_ENDIAN
15141 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15142 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15145 enum machine_mode addr_mode
= get_address_mode (rtl
);
15146 int offset
= (UNITS_PER_WORD
15147 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15149 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15150 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15153 else if (TREE_CODE (decl
) == VAR_DECL
15156 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15157 && BYTES_BIG_ENDIAN
)
15159 enum machine_mode addr_mode
= get_address_mode (rtl
);
15160 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15161 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15163 /* If a variable is declared "register" yet is smaller than
15164 a register, then if we store the variable to memory, it
15165 looks like we're storing a register-sized value, when in
15166 fact we are not. We need to adjust the offset of the
15167 storage location to reflect the actual value's bytes,
15168 else gdb will not be able to display it. */
15170 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15171 plus_constant (addr_mode
, XEXP (rtl
, 0),
15175 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15176 and will have been substituted directly into all expressions that use it.
15177 C does not have such a concept, but C++ and other languages do. */
15178 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15179 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15182 rtl
= targetm
.delegitimize_address (rtl
);
15184 /* If we don't look past the constant pool, we risk emitting a
15185 reference to a constant pool entry that isn't referenced from
15186 code, and thus is not emitted. */
15188 rtl
= avoid_constant_pool_reference (rtl
);
15190 /* Try harder to get a rtl. If this symbol ends up not being emitted
15191 in the current CU, resolve_addr will remove the expression referencing
15193 if (rtl
== NULL_RTX
15194 && TREE_CODE (decl
) == VAR_DECL
15195 && !DECL_EXTERNAL (decl
)
15196 && TREE_STATIC (decl
)
15197 && DECL_NAME (decl
)
15198 && !DECL_HARD_REGISTER (decl
)
15199 && DECL_MODE (decl
) != VOIDmode
)
15201 rtl
= make_decl_rtl_for_debug (decl
);
15203 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15204 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15211 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15212 returned. If so, the decl for the COMMON block is returned, and the
15213 value is the offset into the common block for the symbol. */
15216 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15218 tree val_expr
, cvar
;
15219 enum machine_mode mode
;
15220 HOST_WIDE_INT bitsize
, bitpos
;
15222 int unsignedp
, volatilep
= 0;
15224 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15225 it does not have a value (the offset into the common area), or if it
15226 is thread local (as opposed to global) then it isn't common, and shouldn't
15227 be handled as such. */
15228 if (TREE_CODE (decl
) != VAR_DECL
15229 || !TREE_STATIC (decl
)
15230 || !DECL_HAS_VALUE_EXPR_P (decl
)
15234 val_expr
= DECL_VALUE_EXPR (decl
);
15235 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15238 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15239 &mode
, &unsignedp
, &volatilep
, true);
15241 if (cvar
== NULL_TREE
15242 || TREE_CODE (cvar
) != VAR_DECL
15243 || DECL_ARTIFICIAL (cvar
)
15244 || !TREE_PUBLIC (cvar
))
15248 if (offset
!= NULL
)
15250 if (!host_integerp (offset
, 0))
15252 *value
= tree_low_cst (offset
, 0);
15255 *value
+= bitpos
/ BITS_PER_UNIT
;
15260 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15261 data attribute for a variable or a parameter. We generate the
15262 DW_AT_const_value attribute only in those cases where the given variable
15263 or parameter does not have a true "location" either in memory or in a
15264 register. This can happen (for example) when a constant is passed as an
15265 actual argument in a call to an inline function. (It's possible that
15266 these things can crop up in other ways also.) Note that one type of
15267 constant value which can be passed into an inlined function is a constant
15268 pointer. This can happen for example if an actual argument in an inlined
15269 function call evaluates to a compile-time constant address.
15271 CACHE_P is true if it is worth caching the location list for DECL,
15272 so that future calls can reuse it rather than regenerate it from scratch.
15273 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15274 since we will need to refer to them each time the function is inlined. */
15277 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15278 enum dwarf_attribute attr
)
15281 dw_loc_list_ref list
;
15282 var_loc_list
*loc_list
;
15283 cached_dw_loc_list
*cache
;
15286 if (TREE_CODE (decl
) == ERROR_MARK
)
15289 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15290 || TREE_CODE (decl
) == RESULT_DECL
);
15292 /* Try to get some constant RTL for this decl, and use that as the value of
15295 rtl
= rtl_for_decl_location (decl
);
15296 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15297 && add_const_value_attribute (die
, rtl
))
15300 /* See if we have single element location list that is equivalent to
15301 a constant value. That way we are better to use add_const_value_attribute
15302 rather than expanding constant value equivalent. */
15303 loc_list
= lookup_decl_loc (decl
);
15306 && loc_list
->first
->next
== NULL
15307 && NOTE_P (loc_list
->first
->loc
)
15308 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15309 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15311 struct var_loc_node
*node
;
15313 node
= loc_list
->first
;
15314 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15315 if (GET_CODE (rtl
) == EXPR_LIST
)
15316 rtl
= XEXP (rtl
, 0);
15317 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15318 && add_const_value_attribute (die
, rtl
))
15321 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15322 list several times. See if we've already cached the contents. */
15324 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15328 cache
= (cached_dw_loc_list
*)
15329 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15331 list
= cache
->loc_list
;
15335 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15336 /* It is usually worth caching this result if the decl is from
15337 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15338 if (cache_p
&& list
&& list
->dw_loc_next
)
15340 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15341 DECL_UID (decl
), INSERT
);
15342 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15343 cache
->decl_id
= DECL_UID (decl
);
15344 cache
->loc_list
= list
;
15350 add_AT_location_description (die
, attr
, list
);
15353 /* None of that worked, so it must not really have a location;
15354 try adding a constant value attribute from the DECL_INITIAL. */
15355 return tree_add_const_value_attribute_for_decl (die
, decl
);
15358 /* Add VARIABLE and DIE into deferred locations list. */
15361 defer_location (tree variable
, dw_die_ref die
)
15363 deferred_locations entry
;
15364 entry
.variable
= variable
;
15366 vec_safe_push (deferred_locations_list
, entry
);
15369 /* Helper function for tree_add_const_value_attribute. Natively encode
15370 initializer INIT into an array. Return true if successful. */
15373 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15377 if (init
== NULL_TREE
)
15381 switch (TREE_CODE (init
))
15384 type
= TREE_TYPE (init
);
15385 if (TREE_CODE (type
) == ARRAY_TYPE
)
15387 tree enttype
= TREE_TYPE (type
);
15388 enum machine_mode mode
= TYPE_MODE (enttype
);
15390 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15392 if (int_size_in_bytes (type
) != size
)
15394 if (size
> TREE_STRING_LENGTH (init
))
15396 memcpy (array
, TREE_STRING_POINTER (init
),
15397 TREE_STRING_LENGTH (init
));
15398 memset (array
+ TREE_STRING_LENGTH (init
),
15399 '\0', size
- TREE_STRING_LENGTH (init
));
15402 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15407 type
= TREE_TYPE (init
);
15408 if (int_size_in_bytes (type
) != size
)
15410 if (TREE_CODE (type
) == ARRAY_TYPE
)
15412 HOST_WIDE_INT min_index
;
15413 unsigned HOST_WIDE_INT cnt
;
15414 int curpos
= 0, fieldsize
;
15415 constructor_elt
*ce
;
15417 if (TYPE_DOMAIN (type
) == NULL_TREE
15418 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15421 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15422 if (fieldsize
<= 0)
15425 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15426 memset (array
, '\0', size
);
15427 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15429 tree val
= ce
->value
;
15430 tree index
= ce
->index
;
15432 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15433 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15436 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15441 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15444 curpos
= pos
+ fieldsize
;
15445 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15447 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15448 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15449 while (count
-- > 0)
15452 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15453 curpos
+= fieldsize
;
15456 gcc_assert (curpos
<= size
);
15460 else if (TREE_CODE (type
) == RECORD_TYPE
15461 || TREE_CODE (type
) == UNION_TYPE
)
15463 tree field
= NULL_TREE
;
15464 unsigned HOST_WIDE_INT cnt
;
15465 constructor_elt
*ce
;
15467 if (int_size_in_bytes (type
) != size
)
15470 if (TREE_CODE (type
) == RECORD_TYPE
)
15471 field
= TYPE_FIELDS (type
);
15473 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15475 tree val
= ce
->value
;
15476 int pos
, fieldsize
;
15478 if (ce
->index
!= 0)
15484 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15487 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15488 && TYPE_DOMAIN (TREE_TYPE (field
))
15489 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15491 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15492 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15494 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15495 pos
= int_byte_position (field
);
15496 gcc_assert (pos
+ fieldsize
<= size
);
15498 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15504 case VIEW_CONVERT_EXPR
:
15505 case NON_LVALUE_EXPR
:
15506 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15508 return native_encode_expr (init
, array
, size
) == size
;
15512 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15513 attribute is the const value T. */
15516 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15519 tree type
= TREE_TYPE (t
);
15522 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15526 gcc_assert (!DECL_P (init
));
15528 rtl
= rtl_for_decl_init (init
, type
);
15530 return add_const_value_attribute (die
, rtl
);
15531 /* If the host and target are sane, try harder. */
15532 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15533 && initializer_constant_valid_p (init
, type
))
15535 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15536 if (size
> 0 && (int) size
== size
)
15538 unsigned char *array
= (unsigned char *)
15539 ggc_alloc_cleared_atomic (size
);
15541 if (native_encode_initializer (init
, array
, size
))
15543 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15551 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15552 attribute is the const value of T, where T is an integral constant
15553 variable with static storage duration
15554 (so it can't be a PARM_DECL or a RESULT_DECL). */
15557 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15561 || (TREE_CODE (decl
) != VAR_DECL
15562 && TREE_CODE (decl
) != CONST_DECL
)
15563 || (TREE_CODE (decl
) == VAR_DECL
15564 && !TREE_STATIC (decl
)))
15567 if (TREE_READONLY (decl
)
15568 && ! TREE_THIS_VOLATILE (decl
)
15569 && DECL_INITIAL (decl
))
15574 /* Don't add DW_AT_const_value if abstract origin already has one. */
15575 if (get_AT (var_die
, DW_AT_const_value
))
15578 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15581 /* Convert the CFI instructions for the current function into a
15582 location list. This is used for DW_AT_frame_base when we targeting
15583 a dwarf2 consumer that does not support the dwarf3
15584 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15587 static dw_loc_list_ref
15588 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15592 dw_loc_list_ref list
, *list_tail
;
15594 dw_cfa_location last_cfa
, next_cfa
;
15595 const char *start_label
, *last_label
, *section
;
15596 dw_cfa_location remember
;
15599 gcc_assert (fde
!= NULL
);
15601 section
= secname_for_decl (current_function_decl
);
15605 memset (&next_cfa
, 0, sizeof (next_cfa
));
15606 next_cfa
.reg
= INVALID_REGNUM
;
15607 remember
= next_cfa
;
15609 start_label
= fde
->dw_fde_begin
;
15611 /* ??? Bald assumption that the CIE opcode list does not contain
15612 advance opcodes. */
15613 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15614 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15616 last_cfa
= next_cfa
;
15617 last_label
= start_label
;
15619 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15621 /* If the first partition contained no CFI adjustments, the
15622 CIE opcodes apply to the whole first partition. */
15623 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15624 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15625 list_tail
=&(*list_tail
)->dw_loc_next
;
15626 start_label
= last_label
= fde
->dw_fde_second_begin
;
15629 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15631 switch (cfi
->dw_cfi_opc
)
15633 case DW_CFA_set_loc
:
15634 case DW_CFA_advance_loc1
:
15635 case DW_CFA_advance_loc2
:
15636 case DW_CFA_advance_loc4
:
15637 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15639 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15640 start_label
, last_label
, section
);
15642 list_tail
= &(*list_tail
)->dw_loc_next
;
15643 last_cfa
= next_cfa
;
15644 start_label
= last_label
;
15646 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15649 case DW_CFA_advance_loc
:
15650 /* The encoding is complex enough that we should never emit this. */
15651 gcc_unreachable ();
15654 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15657 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15659 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15661 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15662 start_label
, last_label
, section
);
15664 list_tail
= &(*list_tail
)->dw_loc_next
;
15665 last_cfa
= next_cfa
;
15666 start_label
= last_label
;
15668 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15669 start_label
, fde
->dw_fde_end
, section
);
15670 list_tail
= &(*list_tail
)->dw_loc_next
;
15671 start_label
= last_label
= fde
->dw_fde_second_begin
;
15675 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15677 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15678 start_label
, last_label
, section
);
15679 list_tail
= &(*list_tail
)->dw_loc_next
;
15680 start_label
= last_label
;
15683 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15685 fde
->dw_fde_second_begin
15686 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15689 if (list
&& list
->dw_loc_next
)
15695 /* Compute a displacement from the "steady-state frame pointer" to the
15696 frame base (often the same as the CFA), and store it in
15697 frame_pointer_fb_offset. OFFSET is added to the displacement
15698 before the latter is negated. */
15701 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15705 #ifdef FRAME_POINTER_CFA_OFFSET
15706 reg
= frame_pointer_rtx
;
15707 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15709 reg
= arg_pointer_rtx
;
15710 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15713 elim
= (ira_use_lra_p
15714 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15715 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15716 if (GET_CODE (elim
) == PLUS
)
15718 offset
+= INTVAL (XEXP (elim
, 1));
15719 elim
= XEXP (elim
, 0);
15722 frame_pointer_fb_offset
= -offset
;
15724 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15725 in which to eliminate. This is because it's stack pointer isn't
15726 directly accessible as a register within the ISA. To work around
15727 this, assume that while we cannot provide a proper value for
15728 frame_pointer_fb_offset, we won't need one either. */
15729 frame_pointer_fb_offset_valid
15730 = ((SUPPORTS_STACK_ALIGNMENT
15731 && (elim
== hard_frame_pointer_rtx
15732 || elim
== stack_pointer_rtx
))
15733 || elim
== (frame_pointer_needed
15734 ? hard_frame_pointer_rtx
15735 : stack_pointer_rtx
));
15738 /* Generate a DW_AT_name attribute given some string value to be included as
15739 the value of the attribute. */
15742 add_name_attribute (dw_die_ref die
, const char *name_string
)
15744 if (name_string
!= NULL
&& *name_string
!= 0)
15746 if (demangle_name_func
)
15747 name_string
= (*demangle_name_func
) (name_string
);
15749 add_AT_string (die
, DW_AT_name
, name_string
);
15753 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15754 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15755 of TYPE accordingly.
15757 ??? This is a temporary measure until after we're able to generate
15758 regular DWARF for the complex Ada type system. */
15761 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15762 dw_die_ref context_die
)
15765 dw_die_ref dtype_die
;
15767 if (!lang_hooks
.types
.descriptive_type
)
15770 dtype
= lang_hooks
.types
.descriptive_type (type
);
15774 dtype_die
= lookup_type_die (dtype
);
15777 gen_type_die (dtype
, context_die
);
15778 dtype_die
= lookup_type_die (dtype
);
15779 gcc_assert (dtype_die
);
15782 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15785 /* Generate a DW_AT_comp_dir attribute for DIE. */
15788 add_comp_dir_attribute (dw_die_ref die
)
15790 const char *wd
= get_src_pwd ();
15796 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15800 wdlen
= strlen (wd
);
15801 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15803 wd1
[wdlen
] = DIR_SEPARATOR
;
15804 wd1
[wdlen
+ 1] = 0;
15808 add_AT_string (die
, DW_AT_comp_dir
, remap_debug_filename (wd
));
15811 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15815 lower_bound_default (void)
15817 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15822 case DW_LANG_C_plus_plus
:
15824 case DW_LANG_ObjC_plus_plus
:
15827 case DW_LANG_Fortran77
:
15828 case DW_LANG_Fortran90
:
15829 case DW_LANG_Fortran95
:
15833 case DW_LANG_Python
:
15834 return dwarf_version
>= 4 ? 0 : -1;
15835 case DW_LANG_Ada95
:
15836 case DW_LANG_Ada83
:
15837 case DW_LANG_Cobol74
:
15838 case DW_LANG_Cobol85
:
15839 case DW_LANG_Pascal83
:
15840 case DW_LANG_Modula2
:
15842 return dwarf_version
>= 4 ? 1 : -1;
15848 /* Given a tree node describing an array bound (either lower or upper) output
15849 a representation for that bound. */
15852 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15854 switch (TREE_CODE (bound
))
15859 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15862 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15865 /* Use the default if possible. */
15866 if (bound_attr
== DW_AT_lower_bound
15867 && host_integerp (bound
, 0)
15868 && (dflt
= lower_bound_default ()) != -1
15869 && tree_low_cst (bound
, 0) == dflt
)
15872 /* Otherwise represent the bound as an unsigned value with the
15873 precision of its type. The precision and signedness of the
15874 type will be necessary to re-interpret it unambiguously. */
15875 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15877 unsigned HOST_WIDE_INT mask
15878 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15879 add_AT_unsigned (subrange_die
, bound_attr
,
15880 TREE_INT_CST_LOW (bound
) & mask
);
15882 else if (prec
== HOST_BITS_PER_WIDE_INT
15883 || TREE_INT_CST_HIGH (bound
) == 0)
15884 add_AT_unsigned (subrange_die
, bound_attr
,
15885 TREE_INT_CST_LOW (bound
));
15887 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
15888 TREE_INT_CST_LOW (bound
));
15893 case VIEW_CONVERT_EXPR
:
15894 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
15904 dw_die_ref decl_die
= lookup_decl_die (bound
);
15906 /* ??? Can this happen, or should the variable have been bound
15907 first? Probably it can, since I imagine that we try to create
15908 the types of parameters in the order in which they exist in
15909 the list, and won't have created a forward reference to a
15910 later parameter. */
15911 if (decl_die
!= NULL
)
15913 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15921 /* Otherwise try to create a stack operation procedure to
15922 evaluate the value of the array bound. */
15924 dw_die_ref ctx
, decl_die
;
15925 dw_loc_list_ref list
;
15927 list
= loc_list_from_tree (bound
, 2);
15928 if (list
== NULL
|| single_element_loc_list_p (list
))
15930 /* If DW_AT_*bound is not a reference nor constant, it is
15931 a DWARF expression rather than location description.
15932 For that loc_list_from_tree (bound, 0) is needed.
15933 If that fails to give a single element list,
15934 fall back to outputting this as a reference anyway. */
15935 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
15936 if (list2
&& single_element_loc_list_p (list2
))
15938 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
15945 if (current_function_decl
== 0)
15946 ctx
= comp_unit_die ();
15948 ctx
= lookup_decl_die (current_function_decl
);
15950 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
15951 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
15952 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
15953 add_AT_location_description (decl_die
, DW_AT_location
, list
);
15954 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15960 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
15961 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
15962 Note that the block of subscript information for an array type also
15963 includes information about the element type of the given array type. */
15966 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
15968 unsigned dimension_number
;
15970 dw_die_ref subrange_die
;
15972 for (dimension_number
= 0;
15973 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
15974 type
= TREE_TYPE (type
), dimension_number
++)
15976 tree domain
= TYPE_DOMAIN (type
);
15978 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
15981 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
15982 and (in GNU C only) variable bounds. Handle all three forms
15984 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
15986 if (use_upc_dwarf2_extensions
&& TYPE_HAS_THREADS_FACTOR (type
))
15988 add_AT_flag (subrange_die
, DW_AT_upc_threads_scaled
, 1);
15993 /* We have an array type with specified bounds. */
15994 lower
= TYPE_MIN_VALUE (domain
);
15995 upper
= TYPE_MAX_VALUE (domain
);
15997 /* Define the index type. */
15998 if (TREE_TYPE (domain
))
16000 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16001 TREE_TYPE field. We can't emit debug info for this
16002 because it is an unnamed integral type. */
16003 if (TREE_CODE (domain
) == INTEGER_TYPE
16004 && TYPE_NAME (domain
) == NULL_TREE
16005 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16006 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16009 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16013 /* ??? If upper is NULL, the array has unspecified length,
16014 but it does have a lower bound. This happens with Fortran
16016 Since the debugger is definitely going to need to know N
16017 to produce useful results, go ahead and output the lower
16018 bound solo, and hope the debugger can cope. */
16020 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16022 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16025 /* Otherwise we have an array type with an unspecified length. The
16026 DWARF-2 spec does not say how to handle this; let's just leave out the
16032 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16034 dw_die_ref decl_die
;
16037 switch (TREE_CODE (tree_node
))
16042 case ENUMERAL_TYPE
:
16045 case QUAL_UNION_TYPE
:
16046 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16047 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16049 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16052 size
= int_size_in_bytes (tree_node
);
16055 /* For a data member of a struct or union, the DW_AT_byte_size is
16056 generally given as the number of bytes normally allocated for an
16057 object of the *declared* type of the member itself. This is true
16058 even for bit-fields. */
16059 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16062 gcc_unreachable ();
16065 /* Note that `size' might be -1 when we get to this point. If it is, that
16066 indicates that the byte size of the entity in question is variable. We
16067 have no good way of expressing this fact in Dwarf at the present time,
16068 so just let the -1 pass on through. */
16069 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16072 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16073 which specifies the distance in bits from the highest order bit of the
16074 "containing object" for the bit-field to the highest order bit of the
16077 For any given bit-field, the "containing object" is a hypothetical object
16078 (of some integral or enum type) within which the given bit-field lives. The
16079 type of this hypothetical "containing object" is always the same as the
16080 declared type of the individual bit-field itself. The determination of the
16081 exact location of the "containing object" for a bit-field is rather
16082 complicated. It's handled by the `field_byte_offset' function (above).
16084 Note that it is the size (in bytes) of the hypothetical "containing object"
16085 which will be given in the DW_AT_byte_size attribute for this bit-field.
16086 (See `byte_size_attribute' above). */
16089 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16091 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16092 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16093 HOST_WIDE_INT bitpos_int
;
16094 HOST_WIDE_INT highest_order_object_bit_offset
;
16095 HOST_WIDE_INT highest_order_field_bit_offset
;
16096 HOST_WIDE_INT bit_offset
;
16098 /* Must be a field and a bit field. */
16099 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16101 /* We can't yet handle bit-fields whose offsets are variable, so if we
16102 encounter such things, just return without generating any attribute
16103 whatsoever. Likewise for variable or too large size. */
16104 if (! host_integerp (bit_position (decl
), 0)
16105 || ! host_integerp (DECL_SIZE (decl
), 1))
16108 bitpos_int
= int_bit_position (decl
);
16110 /* Note that the bit offset is always the distance (in bits) from the
16111 highest-order bit of the "containing object" to the highest-order bit of
16112 the bit-field itself. Since the "high-order end" of any object or field
16113 is different on big-endian and little-endian machines, the computation
16114 below must take account of these differences. */
16115 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16116 highest_order_field_bit_offset
= bitpos_int
;
16118 if (! BYTES_BIG_ENDIAN
)
16120 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16121 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16125 = (! BYTES_BIG_ENDIAN
16126 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16127 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16129 if (bit_offset
< 0)
16130 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16132 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16135 /* For a FIELD_DECL node which represents a bit field, output an attribute
16136 which specifies the length in bits of the given field. */
16139 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16141 /* Must be a field and a bit field. */
16142 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16143 && DECL_BIT_FIELD_TYPE (decl
));
16145 if (host_integerp (DECL_SIZE (decl
), 1))
16146 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16149 /* If the compiled language is ANSI C, then add a 'prototyped'
16150 attribute, if arg types are given for the parameters of a function. */
16153 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16155 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16156 && prototype_p (func_type
))
16157 add_AT_flag (die
, DW_AT_prototyped
, 1);
16160 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16161 by looking in either the type declaration or object declaration
16164 static inline dw_die_ref
16165 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16167 dw_die_ref origin_die
= NULL
;
16169 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16171 /* We may have gotten separated from the block for the inlined
16172 function, if we're in an exception handler or some such; make
16173 sure that the abstract function has been written out.
16175 Doing this for nested functions is wrong, however; functions are
16176 distinct units, and our context might not even be inline. */
16180 fn
= TYPE_STUB_DECL (fn
);
16182 fn
= decl_function_context (fn
);
16184 dwarf2out_abstract_function (fn
);
16187 if (DECL_P (origin
))
16188 origin_die
= lookup_decl_die (origin
);
16189 else if (TYPE_P (origin
))
16190 origin_die
= lookup_type_die (origin
);
16192 /* XXX: Functions that are never lowered don't always have correct block
16193 trees (in the case of java, they simply have no block tree, in some other
16194 languages). For these functions, there is nothing we can really do to
16195 output correct debug info for inlined functions in all cases. Rather
16196 than die, we'll just produce deficient debug info now, in that we will
16197 have variables without a proper abstract origin. In the future, when all
16198 functions are lowered, we should re-add a gcc_assert (origin_die)
16202 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16206 /* We do not currently support the pure_virtual attribute. */
16209 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16211 if (DECL_VINDEX (func_decl
))
16213 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16215 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16216 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16217 new_loc_descr (DW_OP_constu
,
16218 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16221 /* GNU extension: Record what type this method came from originally. */
16222 if (debug_info_level
> DINFO_LEVEL_TERSE
16223 && DECL_CONTEXT (func_decl
))
16224 add_AT_die_ref (die
, DW_AT_containing_type
,
16225 lookup_type_die (DECL_CONTEXT (func_decl
)));
16229 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16230 given decl. This used to be a vendor extension until after DWARF 4
16231 standardized it. */
16234 add_linkage_attr (dw_die_ref die
, tree decl
)
16236 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16238 /* Mimic what assemble_name_raw does with a leading '*'. */
16239 if (name
[0] == '*')
16242 if (dwarf_version
>= 4)
16243 add_AT_string (die
, DW_AT_linkage_name
, name
);
16245 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16248 /* Add source coordinate attributes for the given decl. */
16251 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16253 expanded_location s
;
16255 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16257 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16258 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16259 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16262 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16265 add_linkage_name (dw_die_ref die
, tree decl
)
16267 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16268 && TREE_PUBLIC (decl
)
16269 && !DECL_ABSTRACT (decl
)
16270 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16271 && die
->die_tag
!= DW_TAG_member
)
16273 /* Defer until we have an assembler name set. */
16274 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16276 limbo_die_node
*asm_name
;
16278 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16279 asm_name
->die
= die
;
16280 asm_name
->created_for
= decl
;
16281 asm_name
->next
= deferred_asm_name
;
16282 deferred_asm_name
= asm_name
;
16284 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16285 add_linkage_attr (die
, decl
);
16289 /* Add a DW_AT_name attribute and source coordinate attribute for the
16290 given decl, but only if it actually has a name. */
16293 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16297 decl_name
= DECL_NAME (decl
);
16298 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16300 const char *name
= dwarf2_name (decl
, 0);
16302 add_name_attribute (die
, name
);
16303 if (! DECL_ARTIFICIAL (decl
))
16304 add_src_coords_attributes (die
, decl
);
16306 add_linkage_name (die
, decl
);
16309 #ifdef VMS_DEBUGGING_INFO
16310 /* Get the function's name, as described by its RTL. This may be different
16311 from the DECL_NAME name used in the source file. */
16312 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16314 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16315 XEXP (DECL_RTL (decl
), 0), false);
16316 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16318 #endif /* VMS_DEBUGGING_INFO */
16321 #ifdef VMS_DEBUGGING_INFO
16322 /* Output the debug main pointer die for VMS */
16325 dwarf2out_vms_debug_main_pointer (void)
16327 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16330 /* Allocate the VMS debug main subprogram die. */
16331 die
= ggc_alloc_cleared_die_node ();
16332 die
->die_tag
= DW_TAG_subprogram
;
16333 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16334 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16335 current_function_funcdef_no
);
16336 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16338 /* Make it the first child of comp_unit_die (). */
16339 die
->die_parent
= comp_unit_die ();
16340 if (comp_unit_die ()->die_child
)
16342 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16343 comp_unit_die ()->die_child
->die_sib
= die
;
16347 die
->die_sib
= die
;
16348 comp_unit_die ()->die_child
= die
;
16351 #endif /* VMS_DEBUGGING_INFO */
16353 /* Push a new declaration scope. */
16356 push_decl_scope (tree scope
)
16358 vec_safe_push (decl_scope_table
, scope
);
16361 /* Pop a declaration scope. */
16364 pop_decl_scope (void)
16366 decl_scope_table
->pop ();
16369 /* walk_tree helper function for uses_local_type, below. */
16372 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16375 *walk_subtrees
= 0;
16378 tree name
= TYPE_NAME (*tp
);
16379 if (name
&& DECL_P (name
) && decl_function_context (name
))
16385 /* If TYPE involves a function-local type (including a local typedef to a
16386 non-local type), returns that type; otherwise returns NULL_TREE. */
16389 uses_local_type (tree type
)
16391 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16395 /* Return the DIE for the scope that immediately contains this type.
16396 Non-named types that do not involve a function-local type get global
16397 scope. Named types nested in namespaces or other types get their
16398 containing scope. All other types (i.e. function-local named types) get
16399 the current active scope. */
16402 scope_die_for (tree t
, dw_die_ref context_die
)
16404 dw_die_ref scope_die
= NULL
;
16405 tree containing_scope
;
16407 /* Non-types always go in the current scope. */
16408 gcc_assert (TYPE_P (t
));
16410 /* Use the scope of the typedef, rather than the scope of the type
16412 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16413 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16415 containing_scope
= TYPE_CONTEXT (t
);
16417 /* Use the containing namespace if there is one. */
16418 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16420 if (context_die
== lookup_decl_die (containing_scope
))
16422 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16423 context_die
= get_context_die (containing_scope
);
16425 containing_scope
= NULL_TREE
;
16428 /* Ignore function type "scopes" from the C frontend. They mean that
16429 a tagged type is local to a parmlist of a function declarator, but
16430 that isn't useful to DWARF. */
16431 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16432 containing_scope
= NULL_TREE
;
16434 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16436 /* If T uses a local type keep it local as well, to avoid references
16437 to function-local DIEs from outside the function. */
16438 if (current_function_decl
&& uses_local_type (t
))
16439 scope_die
= context_die
;
16441 scope_die
= comp_unit_die ();
16443 else if (TYPE_P (containing_scope
))
16445 /* For types, we can just look up the appropriate DIE. */
16446 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16447 scope_die
= get_context_die (containing_scope
);
16450 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16451 if (scope_die
== NULL
)
16452 scope_die
= comp_unit_die ();
16456 scope_die
= context_die
;
16461 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16464 local_scope_p (dw_die_ref context_die
)
16466 for (; context_die
; context_die
= context_die
->die_parent
)
16467 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16468 || context_die
->die_tag
== DW_TAG_subprogram
)
16474 /* Returns nonzero if CONTEXT_DIE is a class. */
16477 class_scope_p (dw_die_ref context_die
)
16479 return (context_die
16480 && (context_die
->die_tag
== DW_TAG_structure_type
16481 || context_die
->die_tag
== DW_TAG_class_type
16482 || context_die
->die_tag
== DW_TAG_interface_type
16483 || context_die
->die_tag
== DW_TAG_union_type
));
16486 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16487 whether or not to treat a DIE in this context as a declaration. */
16490 class_or_namespace_scope_p (dw_die_ref context_die
)
16492 return (class_scope_p (context_die
)
16493 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16496 /* Many forms of DIEs require a "type description" attribute. This
16497 routine locates the proper "type descriptor" die for the type given
16498 by 'type', and adds a DW_AT_type attribute below the given die. */
16501 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16502 int decl_volatile
, dw_die_ref context_die
)
16504 enum tree_code code
= TREE_CODE (type
);
16505 dw_die_ref type_die
= NULL
;
16508 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16509 or fixed-point type, use the inner type. This is because we have no
16510 support for unnamed types in base_type_die. This can happen if this is
16511 an Ada subrange type. Correct solution is emit a subrange type die. */
16512 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16513 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16514 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16516 if (code
== ERROR_MARK
16517 /* Handle a special case. For functions whose return type is void, we
16518 generate *no* type attribute. (Note that no object may have type
16519 `void', so this only applies to function return types). */
16520 || code
== VOID_TYPE
)
16523 type_quals
= TYPE_QUALS (type
)
16524 | (decl_const
* TYPE_QUAL_CONST
)
16525 | (decl_volatile
* TYPE_QUAL_VOLATILE
);
16526 type_die
= modified_type_die (type
, type_quals
, context_die
);
16528 if (type_die
!= NULL
)
16529 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16532 /* Given an object die, add the calling convention attribute for the
16533 function call type. */
16535 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16537 enum dwarf_calling_convention value
= DW_CC_normal
;
16539 value
= ((enum dwarf_calling_convention
)
16540 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16543 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16545 /* DWARF 2 doesn't provide a way to identify a program's source-level
16546 entry point. DW_AT_calling_convention attributes are only meant
16547 to describe functions' calling conventions. However, lacking a
16548 better way to signal the Fortran main program, we used this for
16549 a long time, following existing custom. Now, DWARF 4 has
16550 DW_AT_main_subprogram, which we add below, but some tools still
16551 rely on the old way, which we thus keep. */
16552 value
= DW_CC_program
;
16554 if (dwarf_version
>= 4 || !dwarf_strict
)
16555 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16558 /* Only add the attribute if the backend requests it, and
16559 is not DW_CC_normal. */
16560 if (value
&& (value
!= DW_CC_normal
))
16561 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16564 /* Given a tree pointer to a struct, class, union, or enum type node, return
16565 a pointer to the (string) tag name for the given type, or zero if the type
16566 was declared without a tag. */
16568 static const char *
16569 type_tag (const_tree type
)
16571 const char *name
= 0;
16573 if (TYPE_NAME (type
) != 0)
16577 /* Find the IDENTIFIER_NODE for the type name. */
16578 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16579 && !TYPE_NAMELESS (type
))
16580 t
= TYPE_NAME (type
);
16582 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16583 a TYPE_DECL node, regardless of whether or not a `typedef' was
16585 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16586 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16588 /* We want to be extra verbose. Don't call dwarf_name if
16589 DECL_NAME isn't set. The default hook for decl_printable_name
16590 doesn't like that, and in this context it's correct to return
16591 0, instead of "<anonymous>" or the like. */
16592 if (DECL_NAME (TYPE_NAME (type
))
16593 && !DECL_NAMELESS (TYPE_NAME (type
)))
16594 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16597 /* Now get the name as a string, or invent one. */
16598 if (!name
&& t
!= 0)
16599 name
= IDENTIFIER_POINTER (t
);
16602 return (name
== 0 || *name
== '\0') ? 0 : name
;
16605 /* Return the type associated with a data member, make a special check
16606 for bit field types. */
16609 member_declared_type (const_tree member
)
16611 return (DECL_BIT_FIELD_TYPE (member
)
16612 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16615 /* Get the decl's label, as described by its RTL. This may be different
16616 from the DECL_NAME name used in the source file. */
16619 static const char *
16620 decl_start_label (tree decl
)
16623 const char *fnname
;
16625 x
= DECL_RTL (decl
);
16626 gcc_assert (MEM_P (x
));
16629 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16631 fnname
= XSTR (x
, 0);
16636 /* These routines generate the internal representation of the DIE's for
16637 the compilation unit. Debugging information is collected by walking
16638 the declaration trees passed in from dwarf2out_decl(). */
16641 gen_array_type_die (tree type
, dw_die_ref context_die
)
16643 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16644 dw_die_ref array_die
;
16646 /* GNU compilers represent multidimensional array types as sequences of one
16647 dimensional array types whose element types are themselves array types.
16648 We sometimes squish that down to a single array_type DIE with multiple
16649 subscripts in the Dwarf debugging info. The draft Dwarf specification
16650 say that we are allowed to do this kind of compression in C, because
16651 there is no difference between an array of arrays and a multidimensional
16652 array. We don't do this for Ada to remain as close as possible to the
16653 actual representation, which is especially important against the language
16654 flexibilty wrt arrays of variable size. */
16656 bool collapse_nested_arrays
= !is_ada ();
16659 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16660 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16661 if (TYPE_STRING_FLAG (type
)
16662 && TREE_CODE (type
) == ARRAY_TYPE
16664 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16666 HOST_WIDE_INT size
;
16668 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16669 add_name_attribute (array_die
, type_tag (type
));
16670 equate_type_number_to_die (type
, array_die
);
16671 size
= int_size_in_bytes (type
);
16673 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16674 else if (TYPE_DOMAIN (type
) != NULL_TREE
16675 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16676 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16678 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16679 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16681 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16682 if (loc
&& size
> 0)
16684 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16685 if (size
!= DWARF2_ADDR_SIZE
)
16686 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16692 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16693 add_name_attribute (array_die
, type_tag (type
));
16694 equate_type_number_to_die (type
, array_die
);
16696 if (TREE_CODE (type
) == VECTOR_TYPE
)
16697 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16699 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16701 && TREE_CODE (type
) == ARRAY_TYPE
16702 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16703 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16704 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16707 /* We default the array ordering. SDB will probably do
16708 the right things even if DW_AT_ordering is not present. It's not even
16709 an issue until we start to get into multidimensional arrays anyway. If
16710 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16711 then we'll have to put the DW_AT_ordering attribute back in. (But if
16712 and when we find out that we need to put these in, we will only do so
16713 for multidimensional arrays. */
16714 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16717 if (TREE_CODE (type
) == VECTOR_TYPE
)
16719 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16720 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16721 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16722 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16723 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16726 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16728 /* Add representation of the type of the elements of this array type and
16729 emit the corresponding DIE if we haven't done it already. */
16730 element_type
= TREE_TYPE (type
);
16731 if (collapse_nested_arrays
)
16732 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16734 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16736 element_type
= TREE_TYPE (element_type
);
16739 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16741 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16742 if (TYPE_ARTIFICIAL (type
))
16743 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16745 if (get_AT (array_die
, DW_AT_name
))
16746 add_pubtype (type
, array_die
);
16749 static dw_loc_descr_ref
16750 descr_info_loc (tree val
, tree base_decl
)
16752 HOST_WIDE_INT size
;
16753 dw_loc_descr_ref loc
, loc2
;
16754 enum dwarf_location_atom op
;
16756 if (val
== base_decl
)
16757 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16759 switch (TREE_CODE (val
))
16762 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16764 return loc_descriptor_from_tree (val
, 0);
16766 if (host_integerp (val
, 0))
16767 return int_loc_descriptor (tree_low_cst (val
, 0));
16770 size
= int_size_in_bytes (TREE_TYPE (val
));
16773 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16776 if (size
== DWARF2_ADDR_SIZE
)
16777 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16779 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16781 case POINTER_PLUS_EXPR
:
16783 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16784 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16787 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16790 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16796 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16799 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16802 add_loc_descr (&loc
, loc2
);
16803 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16825 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16826 tree val
, tree base_decl
)
16828 dw_loc_descr_ref loc
;
16830 if (host_integerp (val
, 0))
16832 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16836 loc
= descr_info_loc (val
, base_decl
);
16840 add_AT_loc (die
, attr
, loc
);
16843 /* This routine generates DIE for array with hidden descriptor, details
16844 are filled into *info by a langhook. */
16847 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16848 dw_die_ref context_die
)
16850 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16851 dw_die_ref array_die
;
16854 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16855 add_name_attribute (array_die
, type_tag (type
));
16856 equate_type_number_to_die (type
, array_die
);
16858 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16860 && info
->ndimensions
>= 2)
16861 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16863 if (info
->data_location
)
16864 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16866 if (info
->associated
)
16867 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16869 if (info
->allocated
)
16870 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16873 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16875 dw_die_ref subrange_die
16876 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16878 if (info
->dimen
[dim
].lower_bound
)
16880 /* If it is the default value, omit it. */
16883 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16884 && (dflt
= lower_bound_default ()) != -1
16885 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16888 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16889 info
->dimen
[dim
].lower_bound
,
16892 if (info
->dimen
[dim
].upper_bound
)
16893 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
16894 info
->dimen
[dim
].upper_bound
,
16896 if (info
->dimen
[dim
].stride
)
16897 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
16898 info
->dimen
[dim
].stride
,
16902 gen_type_die (info
->element_type
, context_die
);
16903 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
16905 if (get_AT (array_die
, DW_AT_name
))
16906 add_pubtype (type
, array_die
);
16911 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
16913 tree origin
= decl_ultimate_origin (decl
);
16914 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
16916 if (origin
!= NULL
)
16917 add_abstract_origin_attribute (decl_die
, origin
);
16920 add_name_and_src_coords_attributes (decl_die
, decl
);
16921 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
16922 0, 0, context_die
);
16925 if (DECL_ABSTRACT (decl
))
16926 equate_decl_number_to_die (decl
, decl_die
);
16928 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
16932 /* Walk through the list of incomplete types again, trying once more to
16933 emit full debugging info for them. */
16936 retry_incomplete_types (void)
16940 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
16941 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
16942 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
16945 /* Determine what tag to use for a record type. */
16947 static enum dwarf_tag
16948 record_type_tag (tree type
)
16950 if (! lang_hooks
.types
.classify_record
)
16951 return DW_TAG_structure_type
;
16953 switch (lang_hooks
.types
.classify_record (type
))
16955 case RECORD_IS_STRUCT
:
16956 return DW_TAG_structure_type
;
16958 case RECORD_IS_CLASS
:
16959 return DW_TAG_class_type
;
16961 case RECORD_IS_INTERFACE
:
16962 if (dwarf_version
>= 3 || !dwarf_strict
)
16963 return DW_TAG_interface_type
;
16964 return DW_TAG_structure_type
;
16967 gcc_unreachable ();
16971 /* Generate a DIE to represent an enumeration type. Note that these DIEs
16972 include all of the information about the enumeration values also. Each
16973 enumerated type name/value is listed as a child of the enumerated type
16977 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
16979 dw_die_ref type_die
= lookup_type_die (type
);
16981 if (type_die
== NULL
)
16983 type_die
= new_die (DW_TAG_enumeration_type
,
16984 scope_die_for (type
, context_die
), type
);
16985 equate_type_number_to_die (type
, type_die
);
16986 add_name_attribute (type_die
, type_tag (type
));
16987 if (dwarf_version
>= 4 || !dwarf_strict
)
16989 if (ENUM_IS_SCOPED (type
))
16990 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
16991 if (ENUM_IS_OPAQUE (type
))
16992 add_AT_flag (type_die
, DW_AT_declaration
, 1);
16995 else if (! TYPE_SIZE (type
))
16998 remove_AT (type_die
, DW_AT_declaration
);
17000 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17001 given enum type is incomplete, do not generate the DW_AT_byte_size
17002 attribute or the DW_AT_element_list attribute. */
17003 if (TYPE_SIZE (type
))
17007 TREE_ASM_WRITTEN (type
) = 1;
17008 add_byte_size_attribute (type_die
, type
);
17009 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17011 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17012 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17015 /* If the first reference to this type was as the return type of an
17016 inline function, then it may not have a parent. Fix this now. */
17017 if (type_die
->die_parent
== NULL
)
17018 add_child_die (scope_die_for (type
, context_die
), type_die
);
17020 for (link
= TYPE_VALUES (type
);
17021 link
!= NULL
; link
= TREE_CHAIN (link
))
17023 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17024 tree value
= TREE_VALUE (link
);
17026 add_name_attribute (enum_die
,
17027 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17029 if (TREE_CODE (value
) == CONST_DECL
)
17030 value
= DECL_INITIAL (value
);
17032 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
))))
17033 /* DWARF2 does not provide a way of indicating whether or
17034 not enumeration constants are signed or unsigned. GDB
17035 always assumes the values are signed, so we output all
17036 values as if they were signed. That means that
17037 enumeration constants with very large unsigned values
17038 will appear to have negative values in the debugger. */
17039 add_AT_int (enum_die
, DW_AT_const_value
,
17040 tree_low_cst (value
, tree_int_cst_sgn (value
) > 0));
17043 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17044 if (TYPE_ARTIFICIAL (type
))
17045 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17048 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17050 add_pubtype (type
, type_die
);
17055 /* Generate a DIE to represent either a real live formal parameter decl or to
17056 represent just the type of some formal parameter position in some function
17059 Note that this routine is a bit unusual because its argument may be a
17060 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17061 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17062 node. If it's the former then this function is being called to output a
17063 DIE to represent a formal parameter object (or some inlining thereof). If
17064 it's the latter, then this function is only being called to output a
17065 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17066 argument type of some subprogram type.
17067 If EMIT_NAME_P is true, name and source coordinate attributes
17071 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17072 dw_die_ref context_die
)
17074 tree node_or_origin
= node
? node
: origin
;
17075 tree ultimate_origin
;
17076 dw_die_ref parm_die
17077 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17079 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17081 case tcc_declaration
:
17082 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17083 if (node
|| ultimate_origin
)
17084 origin
= ultimate_origin
;
17085 if (origin
!= NULL
)
17086 add_abstract_origin_attribute (parm_die
, origin
);
17087 else if (emit_name_p
)
17088 add_name_and_src_coords_attributes (parm_die
, node
);
17090 || (! DECL_ABSTRACT (node_or_origin
)
17091 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17092 decl_function_context
17093 (node_or_origin
))))
17095 tree type
= TREE_TYPE (node_or_origin
);
17096 if (decl_by_reference_p (node_or_origin
))
17097 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17100 add_type_attribute (parm_die
, type
,
17101 TREE_READONLY (node_or_origin
),
17102 TREE_THIS_VOLATILE (node_or_origin
),
17105 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17106 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17108 if (node
&& node
!= origin
)
17109 equate_decl_number_to_die (node
, parm_die
);
17110 if (! DECL_ABSTRACT (node_or_origin
))
17111 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17112 node
== NULL
, DW_AT_location
);
17117 /* We were called with some kind of a ..._TYPE node. */
17118 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17122 gcc_unreachable ();
17128 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17129 children DW_TAG_formal_parameter DIEs representing the arguments of the
17132 PARM_PACK must be a function parameter pack.
17133 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17134 must point to the subsequent arguments of the function PACK_ARG belongs to.
17135 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17136 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17137 following the last one for which a DIE was generated. */
17140 gen_formal_parameter_pack_die (tree parm_pack
,
17142 dw_die_ref subr_die
,
17146 dw_die_ref parm_pack_die
;
17148 gcc_assert (parm_pack
17149 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17152 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17153 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17155 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17157 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17160 gen_formal_parameter_die (arg
, NULL
,
17161 false /* Don't emit name attribute. */,
17166 return parm_pack_die
;
17169 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17170 at the end of an (ANSI prototyped) formal parameters list. */
17173 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17175 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17178 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17179 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17180 parameters as specified in some function type specification (except for
17181 those which appear as part of a function *definition*). */
17184 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17187 tree formal_type
= NULL
;
17188 tree first_parm_type
;
17191 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17193 arg
= DECL_ARGUMENTS (function_or_method_type
);
17194 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17199 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17201 /* Make our first pass over the list of formal parameter types and output a
17202 DW_TAG_formal_parameter DIE for each one. */
17203 for (link
= first_parm_type
; link
; )
17205 dw_die_ref parm_die
;
17207 formal_type
= TREE_VALUE (link
);
17208 if (formal_type
== void_type_node
)
17211 /* Output a (nameless) DIE to represent the formal parameter itself. */
17212 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17213 true /* Emit name attribute. */,
17215 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17216 && link
== first_parm_type
)
17218 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17219 if (dwarf_version
>= 3 || !dwarf_strict
)
17220 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17222 else if (arg
&& DECL_ARTIFICIAL (arg
))
17223 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17225 link
= TREE_CHAIN (link
);
17227 arg
= DECL_CHAIN (arg
);
17230 /* If this function type has an ellipsis, add a
17231 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17232 if (formal_type
!= void_type_node
)
17233 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17235 /* Make our second (and final) pass over the list of formal parameter types
17236 and output DIEs to represent those types (as necessary). */
17237 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17238 link
&& TREE_VALUE (link
);
17239 link
= TREE_CHAIN (link
))
17240 gen_type_die (TREE_VALUE (link
), context_die
);
17243 /* We want to generate the DIE for TYPE so that we can generate the
17244 die for MEMBER, which has been defined; we will need to refer back
17245 to the member declaration nested within TYPE. If we're trying to
17246 generate minimal debug info for TYPE, processing TYPE won't do the
17247 trick; we need to attach the member declaration by hand. */
17250 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17252 gen_type_die (type
, context_die
);
17254 /* If we're trying to avoid duplicate debug info, we may not have
17255 emitted the member decl for this function. Emit it now. */
17256 if (TYPE_STUB_DECL (type
)
17257 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17258 && ! lookup_decl_die (member
))
17260 dw_die_ref type_die
;
17261 gcc_assert (!decl_ultimate_origin (member
));
17263 push_decl_scope (type
);
17264 type_die
= lookup_type_die_strip_naming_typedef (type
);
17265 if (TREE_CODE (member
) == FUNCTION_DECL
)
17266 gen_subprogram_die (member
, type_die
);
17267 else if (TREE_CODE (member
) == FIELD_DECL
)
17269 /* Ignore the nameless fields that are used to skip bits but handle
17270 C++ anonymous unions and structs. */
17271 if (DECL_NAME (member
) != NULL_TREE
17272 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17273 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17275 gen_type_die (member_declared_type (member
), type_die
);
17276 gen_field_die (member
, type_die
);
17280 gen_variable_die (member
, NULL_TREE
, type_die
);
17286 /* Forward declare these functions, because they are mutually recursive
17287 with their set_block_* pairing functions. */
17288 static void set_decl_origin_self (tree
);
17289 static void set_decl_abstract_flags (tree
, int);
17291 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17292 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17293 that it points to the node itself, thus indicating that the node is its
17294 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17295 the given node is NULL, recursively descend the decl/block tree which
17296 it is the root of, and for each other ..._DECL or BLOCK node contained
17297 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17298 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17299 values to point to themselves. */
17302 set_block_origin_self (tree stmt
)
17304 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17306 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17311 for (local_decl
= BLOCK_VARS (stmt
);
17312 local_decl
!= NULL_TREE
;
17313 local_decl
= DECL_CHAIN (local_decl
))
17314 if (! DECL_EXTERNAL (local_decl
))
17315 set_decl_origin_self (local_decl
); /* Potential recursion. */
17321 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17322 subblock
!= NULL_TREE
;
17323 subblock
= BLOCK_CHAIN (subblock
))
17324 set_block_origin_self (subblock
); /* Recurse. */
17329 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17330 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17331 node to so that it points to the node itself, thus indicating that the
17332 node represents its own (abstract) origin. Additionally, if the
17333 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17334 the decl/block tree of which the given node is the root of, and for
17335 each other ..._DECL or BLOCK node contained therein whose
17336 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17337 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17338 point to themselves. */
17341 set_decl_origin_self (tree decl
)
17343 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17345 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17346 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17350 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17351 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17352 if (DECL_INITIAL (decl
) != NULL_TREE
17353 && DECL_INITIAL (decl
) != error_mark_node
)
17354 set_block_origin_self (DECL_INITIAL (decl
));
17359 /* Given a pointer to some BLOCK node, and a boolean value to set the
17360 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17361 the given block, and for all local decls and all local sub-blocks
17362 (recursively) which are contained therein. */
17365 set_block_abstract_flags (tree stmt
, int setting
)
17371 BLOCK_ABSTRACT (stmt
) = setting
;
17373 for (local_decl
= BLOCK_VARS (stmt
);
17374 local_decl
!= NULL_TREE
;
17375 local_decl
= DECL_CHAIN (local_decl
))
17376 if (! DECL_EXTERNAL (local_decl
))
17377 set_decl_abstract_flags (local_decl
, setting
);
17379 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17381 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17382 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17383 || TREE_CODE (local_decl
) == PARM_DECL
)
17384 set_decl_abstract_flags (local_decl
, setting
);
17387 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17388 subblock
!= NULL_TREE
;
17389 subblock
= BLOCK_CHAIN (subblock
))
17390 set_block_abstract_flags (subblock
, setting
);
17393 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17394 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17395 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17396 set the abstract flags for all of the parameters, local vars, local
17397 blocks and sub-blocks (recursively) to the same setting. */
17400 set_decl_abstract_flags (tree decl
, int setting
)
17402 DECL_ABSTRACT (decl
) = setting
;
17403 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17407 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17408 DECL_ABSTRACT (arg
) = setting
;
17409 if (DECL_INITIAL (decl
) != NULL_TREE
17410 && DECL_INITIAL (decl
) != error_mark_node
)
17411 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17415 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17416 may later generate inlined and/or out-of-line instances of. */
17419 dwarf2out_abstract_function (tree decl
)
17421 dw_die_ref old_die
;
17425 htab_t old_decl_loc_table
;
17426 htab_t old_cached_dw_loc_list_table
;
17427 int old_call_site_count
, old_tail_call_site_count
;
17428 struct call_arg_loc_node
*old_call_arg_locations
;
17430 /* Make sure we have the actual abstract inline, not a clone. */
17431 decl
= DECL_ORIGIN (decl
);
17433 old_die
= lookup_decl_die (decl
);
17434 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17435 /* We've already generated the abstract instance. */
17438 /* We can be called while recursively when seeing block defining inlined subroutine
17439 DIE. Be sure to not clobber the outer location table nor use it or we would
17440 get locations in abstract instantces. */
17441 old_decl_loc_table
= decl_loc_table
;
17442 decl_loc_table
= NULL
;
17443 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17444 cached_dw_loc_list_table
= NULL
;
17445 old_call_arg_locations
= call_arg_locations
;
17446 call_arg_locations
= NULL
;
17447 old_call_site_count
= call_site_count
;
17448 call_site_count
= -1;
17449 old_tail_call_site_count
= tail_call_site_count
;
17450 tail_call_site_count
= -1;
17452 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17453 we don't get confused by DECL_ABSTRACT. */
17454 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17456 context
= decl_class_context (decl
);
17458 gen_type_die_for_member
17459 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17462 /* Pretend we've just finished compiling this function. */
17463 save_fn
= current_function_decl
;
17464 current_function_decl
= decl
;
17466 was_abstract
= DECL_ABSTRACT (decl
);
17467 set_decl_abstract_flags (decl
, 1);
17468 dwarf2out_decl (decl
);
17469 if (! was_abstract
)
17470 set_decl_abstract_flags (decl
, 0);
17472 current_function_decl
= save_fn
;
17473 decl_loc_table
= old_decl_loc_table
;
17474 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17475 call_arg_locations
= old_call_arg_locations
;
17476 call_site_count
= old_call_site_count
;
17477 tail_call_site_count
= old_tail_call_site_count
;
17480 /* Helper function of premark_used_types() which gets called through
17483 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17484 marked as unused by prune_unused_types. */
17487 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17492 type
= (tree
) *slot
;
17493 die
= lookup_type_die (type
);
17495 die
->die_perennial_p
= 1;
17499 /* Helper function of premark_types_used_by_global_vars which gets called
17500 through htab_traverse.
17502 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17503 marked as unused by prune_unused_types. The DIE of the type is marked
17504 only if the global variable using the type will actually be emitted. */
17507 premark_types_used_by_global_vars_helper (void **slot
,
17508 void *data ATTRIBUTE_UNUSED
)
17510 struct types_used_by_vars_entry
*entry
;
17513 entry
= (struct types_used_by_vars_entry
*) *slot
;
17514 gcc_assert (entry
->type
!= NULL
17515 && entry
->var_decl
!= NULL
);
17516 die
= lookup_type_die (entry
->type
);
17519 /* Ask cgraph if the global variable really is to be emitted.
17520 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17521 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17522 if (node
&& node
->analyzed
)
17524 die
->die_perennial_p
= 1;
17525 /* Keep the parent DIEs as well. */
17526 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17527 die
->die_perennial_p
= 1;
17533 /* Mark all members of used_types_hash as perennial. */
17536 premark_used_types (struct function
*fun
)
17538 if (fun
&& fun
->used_types_hash
)
17539 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17542 /* Mark all members of types_used_by_vars_entry as perennial. */
17545 premark_types_used_by_global_vars (void)
17547 if (types_used_by_vars_hash
)
17548 htab_traverse (types_used_by_vars_hash
,
17549 premark_types_used_by_global_vars_helper
, NULL
);
17552 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17553 for CA_LOC call arg loc node. */
17556 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17557 struct call_arg_loc_node
*ca_loc
)
17559 dw_die_ref stmt_die
= NULL
, die
;
17560 tree block
= ca_loc
->block
;
17563 && block
!= DECL_INITIAL (decl
)
17564 && TREE_CODE (block
) == BLOCK
)
17566 if (block_map
.length () > BLOCK_NUMBER (block
))
17567 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17570 block
= BLOCK_SUPERCONTEXT (block
);
17572 if (stmt_die
== NULL
)
17573 stmt_die
= subr_die
;
17574 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17575 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17576 if (ca_loc
->tail_call_p
)
17577 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17578 if (ca_loc
->symbol_ref
)
17580 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17582 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17584 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17589 /* Generate a DIE to represent a declared function (either file-scope or
17593 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17595 tree origin
= decl_ultimate_origin (decl
);
17596 dw_die_ref subr_die
;
17598 dw_die_ref old_die
= lookup_decl_die (decl
);
17599 int declaration
= (current_function_decl
!= decl
17600 || class_or_namespace_scope_p (context_die
));
17602 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17604 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17605 started to generate the abstract instance of an inline, decided to output
17606 its containing class, and proceeded to emit the declaration of the inline
17607 from the member list for the class. If so, DECLARATION takes priority;
17608 we'll get back to the abstract instance when done with the class. */
17610 /* The class-scope declaration DIE must be the primary DIE. */
17611 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17614 gcc_assert (!old_die
);
17617 /* Now that the C++ front end lazily declares artificial member fns, we
17618 might need to retrofit the declaration into its class. */
17619 if (!declaration
&& !origin
&& !old_die
17620 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17621 && !class_or_namespace_scope_p (context_die
)
17622 && debug_info_level
> DINFO_LEVEL_TERSE
)
17623 old_die
= force_decl_die (decl
);
17625 if (origin
!= NULL
)
17627 gcc_assert (!declaration
|| local_scope_p (context_die
));
17629 /* Fixup die_parent for the abstract instance of a nested
17630 inline function. */
17631 if (old_die
&& old_die
->die_parent
== NULL
)
17632 add_child_die (context_die
, old_die
);
17634 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17635 add_abstract_origin_attribute (subr_die
, origin
);
17636 /* This is where the actual code for a cloned function is.
17637 Let's emit linkage name attribute for it. This helps
17638 debuggers to e.g, set breakpoints into
17639 constructors/destructors when the user asks "break
17641 add_linkage_name (subr_die
, decl
);
17645 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17646 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17648 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17649 /* We can have a normal definition following an inline one in the
17650 case of redefinition of GNU C extern inlines.
17651 It seems reasonable to use AT_specification in this case. */
17652 && !get_AT (old_die
, DW_AT_inline
))
17654 /* Detect and ignore this case, where we are trying to output
17655 something we have already output. */
17659 /* If the definition comes from the same place as the declaration,
17660 maybe use the old DIE. We always want the DIE for this function
17661 that has the *_pc attributes to be under comp_unit_die so the
17662 debugger can find it. We also need to do this for abstract
17663 instances of inlines, since the spec requires the out-of-line copy
17664 to have the same parent. For local class methods, this doesn't
17665 apply; we just use the old DIE. */
17666 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17667 && (DECL_ARTIFICIAL (decl
)
17668 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17669 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17670 == (unsigned) s
.line
))))
17672 subr_die
= old_die
;
17674 /* Clear out the declaration attribute and the formal parameters.
17675 Do not remove all children, because it is possible that this
17676 declaration die was forced using force_decl_die(). In such
17677 cases die that forced declaration die (e.g. TAG_imported_module)
17678 is one of the children that we do not want to remove. */
17679 remove_AT (subr_die
, DW_AT_declaration
);
17680 remove_AT (subr_die
, DW_AT_object_pointer
);
17681 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17685 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17686 add_AT_specification (subr_die
, old_die
);
17687 add_pubname (decl
, subr_die
);
17688 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17689 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17690 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17691 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17696 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17698 if (TREE_PUBLIC (decl
))
17699 add_AT_flag (subr_die
, DW_AT_external
, 1);
17701 add_name_and_src_coords_attributes (subr_die
, decl
);
17702 add_pubname (decl
, subr_die
);
17703 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17705 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17706 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17707 0, 0, context_die
);
17710 add_pure_or_virtual_attribute (subr_die
, decl
);
17711 if (DECL_ARTIFICIAL (decl
))
17712 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17714 add_accessibility_attribute (subr_die
, decl
);
17719 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17721 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17723 /* If this is an explicit function declaration then generate
17724 a DW_AT_explicit attribute. */
17725 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17726 && (dwarf_version
>= 3 || !dwarf_strict
))
17727 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17729 /* The first time we see a member function, it is in the context of
17730 the class to which it belongs. We make sure of this by emitting
17731 the class first. The next time is the definition, which is
17732 handled above. The two may come from the same source text.
17734 Note that force_decl_die() forces function declaration die. It is
17735 later reused to represent definition. */
17736 equate_decl_number_to_die (decl
, subr_die
);
17739 else if (DECL_ABSTRACT (decl
))
17741 if (DECL_DECLARED_INLINE_P (decl
))
17743 if (cgraph_function_possibly_inlined_p (decl
))
17744 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17746 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17750 if (cgraph_function_possibly_inlined_p (decl
))
17751 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17753 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17756 if (DECL_DECLARED_INLINE_P (decl
)
17757 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17758 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17760 equate_decl_number_to_die (decl
, subr_die
);
17762 else if (!DECL_EXTERNAL (decl
))
17764 HOST_WIDE_INT cfa_fb_offset
;
17765 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
17767 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17768 equate_decl_number_to_die (decl
, subr_die
);
17770 gcc_checking_assert (fun
);
17771 if (!flag_reorder_blocks_and_partition
)
17773 dw_fde_ref fde
= fun
->fde
;
17774 if (fde
->dw_fde_begin
)
17776 /* We have already generated the labels. */
17777 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17778 fde
->dw_fde_end
, false);
17782 /* Create start/end labels and add the range. */
17783 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
17784 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17785 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
17786 current_function_funcdef_no
);
17787 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
17788 current_function_funcdef_no
);
17789 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
17793 #if VMS_DEBUGGING_INFO
17794 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17795 Section 2.3 Prologue and Epilogue Attributes:
17796 When a breakpoint is set on entry to a function, it is generally
17797 desirable for execution to be suspended, not on the very first
17798 instruction of the function, but rather at a point after the
17799 function's frame has been set up, after any language defined local
17800 declaration processing has been completed, and before execution of
17801 the first statement of the function begins. Debuggers generally
17802 cannot properly determine where this point is. Similarly for a
17803 breakpoint set on exit from a function. The prologue and epilogue
17804 attributes allow a compiler to communicate the location(s) to use. */
17807 if (fde
->dw_fde_vms_end_prologue
)
17808 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17809 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17811 if (fde
->dw_fde_vms_begin_epilogue
)
17812 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17813 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17820 /* Generate pubnames entries for the split function code ranges. */
17821 dw_fde_ref fde
= fun
->fde
;
17823 if (fde
->dw_fde_second_begin
)
17825 if (dwarf_version
>= 3 || !dwarf_strict
)
17827 /* We should use ranges for non-contiguous code section
17828 addresses. Use the actual code range for the initial
17829 section, since the HOT/COLD labels might precede an
17830 alignment offset. */
17831 bool range_list_added
= false;
17832 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17833 fde
->dw_fde_end
, &range_list_added
,
17835 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17836 fde
->dw_fde_second_end
,
17837 &range_list_added
, false);
17838 if (range_list_added
)
17843 /* There is no real support in DW2 for this .. so we make
17844 a work-around. First, emit the pub name for the segment
17845 containing the function label. Then make and emit a
17846 simplified subprogram DIE for the second segment with the
17847 name pre-fixed by __hot/cold_sect_of_. We use the same
17848 linkage name for the second die so that gdb will find both
17849 sections when given "b foo". */
17850 const char *name
= NULL
;
17851 tree decl_name
= DECL_NAME (decl
);
17852 dw_die_ref seg_die
;
17854 /* Do the 'primary' section. */
17855 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17856 fde
->dw_fde_end
, false);
17858 /* Build a minimal DIE for the secondary section. */
17859 seg_die
= new_die (DW_TAG_subprogram
,
17860 subr_die
->die_parent
, decl
);
17862 if (TREE_PUBLIC (decl
))
17863 add_AT_flag (seg_die
, DW_AT_external
, 1);
17865 if (decl_name
!= NULL
17866 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17868 name
= dwarf2_name (decl
, 1);
17869 if (! DECL_ARTIFICIAL (decl
))
17870 add_src_coords_attributes (seg_die
, decl
);
17872 add_linkage_name (seg_die
, decl
);
17874 gcc_assert (name
!= NULL
);
17875 add_pure_or_virtual_attribute (seg_die
, decl
);
17876 if (DECL_ARTIFICIAL (decl
))
17877 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17879 name
= concat ("__second_sect_of_", name
, NULL
);
17880 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
17881 fde
->dw_fde_second_end
, false);
17882 add_name_attribute (seg_die
, name
);
17883 if (want_pubnames ())
17884 add_pubname_string (name
, seg_die
);
17888 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
17892 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17894 /* We define the "frame base" as the function's CFA. This is more
17895 convenient for several reasons: (1) It's stable across the prologue
17896 and epilogue, which makes it better than just a frame pointer,
17897 (2) With dwarf3, there exists a one-byte encoding that allows us
17898 to reference the .debug_frame data by proxy, but failing that,
17899 (3) We can at least reuse the code inspection and interpretation
17900 code that determines the CFA position at various points in the
17902 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
17904 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
17905 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
17909 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
17910 if (list
->dw_loc_next
)
17911 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
17913 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
17916 /* Compute a displacement from the "steady-state frame pointer" to
17917 the CFA. The former is what all stack slots and argument slots
17918 will reference in the rtl; the later is what we've told the
17919 debugger about. We'll need to adjust all frame_base references
17920 by this displacement. */
17921 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
17923 if (fun
->static_chain_decl
)
17924 add_AT_location_description (subr_die
, DW_AT_static_link
,
17925 loc_list_from_tree (fun
->static_chain_decl
, 2));
17928 /* Generate child dies for template paramaters. */
17929 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17930 gen_generic_params_dies (decl
);
17932 /* Now output descriptions of the arguments for this function. This gets
17933 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
17934 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
17935 `...' at the end of the formal parameter list. In order to find out if
17936 there was a trailing ellipsis or not, we must instead look at the type
17937 associated with the FUNCTION_DECL. This will be a node of type
17938 FUNCTION_TYPE. If the chain of type nodes hanging off of this
17939 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
17940 an ellipsis at the end. */
17942 /* In the case where we are describing a mere function declaration, all we
17943 need to do here (and all we *can* do here) is to describe the *types* of
17944 its formal parameters. */
17945 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
17947 else if (declaration
)
17948 gen_formal_types_die (decl
, subr_die
);
17951 /* Generate DIEs to represent all known formal parameters. */
17952 tree parm
= DECL_ARGUMENTS (decl
);
17953 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
17954 tree generic_decl_parm
= generic_decl
17955 ? DECL_ARGUMENTS (generic_decl
)
17958 /* Now we want to walk the list of parameters of the function and
17959 emit their relevant DIEs.
17961 We consider the case of DECL being an instance of a generic function
17962 as well as it being a normal function.
17964 If DECL is an instance of a generic function we walk the
17965 parameters of the generic function declaration _and_ the parameters of
17966 DECL itself. This is useful because we want to emit specific DIEs for
17967 function parameter packs and those are declared as part of the
17968 generic function declaration. In that particular case,
17969 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
17970 That DIE has children DIEs representing the set of arguments
17971 of the pack. Note that the set of pack arguments can be empty.
17972 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
17975 Otherwise, we just consider the parameters of DECL. */
17976 while (generic_decl_parm
|| parm
)
17978 if (generic_decl_parm
17979 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
17980 gen_formal_parameter_pack_die (generic_decl_parm
,
17985 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
17987 if (parm
== DECL_ARGUMENTS (decl
)
17988 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
17990 && (dwarf_version
>= 3 || !dwarf_strict
))
17991 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
17993 parm
= DECL_CHAIN (parm
);
17996 if (generic_decl_parm
)
17997 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18000 /* Decide whether we need an unspecified_parameters DIE at the end.
18001 There are 2 more cases to do this for: 1) the ansi ... declaration -
18002 this is detectable when the end of the arg list is not a
18003 void_type_node 2) an unprototyped function declaration (not a
18004 definition). This just means that we have no info about the
18005 parameters at all. */
18006 if (prototype_p (TREE_TYPE (decl
)))
18008 /* This is the prototyped case, check for.... */
18009 if (stdarg_p (TREE_TYPE (decl
)))
18010 gen_unspecified_parameters_die (decl
, subr_die
);
18012 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18013 gen_unspecified_parameters_die (decl
, subr_die
);
18016 /* Output Dwarf info for all of the stuff within the body of the function
18017 (if it has one - it may be just a declaration). */
18018 outer_scope
= DECL_INITIAL (decl
);
18020 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18021 a function. This BLOCK actually represents the outermost binding contour
18022 for the function, i.e. the contour in which the function's formal
18023 parameters and labels get declared. Curiously, it appears that the front
18024 end doesn't actually put the PARM_DECL nodes for the current function onto
18025 the BLOCK_VARS list for this outer scope, but are strung off of the
18026 DECL_ARGUMENTS list for the function instead.
18028 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18029 the LABEL_DECL nodes for the function however, and we output DWARF info
18030 for those in decls_for_scope. Just within the `outer_scope' there will be
18031 a BLOCK node representing the function's outermost pair of curly braces,
18032 and any blocks used for the base and member initializers of a C++
18033 constructor function. */
18034 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18036 int call_site_note_count
= 0;
18037 int tail_call_site_note_count
= 0;
18039 /* Emit a DW_TAG_variable DIE for a named return value. */
18040 if (DECL_NAME (DECL_RESULT (decl
)))
18041 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18043 current_function_has_inlines
= 0;
18044 decls_for_scope (outer_scope
, subr_die
, 0);
18046 if (call_arg_locations
&& !dwarf_strict
)
18048 struct call_arg_loc_node
*ca_loc
;
18049 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18051 dw_die_ref die
= NULL
;
18052 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18055 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18056 arg
; arg
= next_arg
)
18058 dw_loc_descr_ref reg
, val
;
18059 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18060 dw_die_ref cdie
, tdie
= NULL
;
18062 next_arg
= XEXP (arg
, 1);
18063 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18065 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18066 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18067 && REGNO (XEXP (XEXP (arg
, 0), 0))
18068 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18069 next_arg
= XEXP (next_arg
, 1);
18070 if (mode
== VOIDmode
)
18072 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18073 if (mode
== VOIDmode
)
18074 mode
= GET_MODE (XEXP (arg
, 0));
18076 if (mode
== VOIDmode
|| mode
== BLKmode
)
18078 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18080 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18081 tloc
= XEXP (XEXP (arg
, 0), 1);
18084 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18085 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18087 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18088 tlocc
= XEXP (XEXP (arg
, 0), 1);
18092 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18093 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18094 VAR_INIT_STATUS_INITIALIZED
);
18095 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18097 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18098 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18099 get_address_mode (mem
),
18101 VAR_INIT_STATUS_INITIALIZED
);
18103 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18104 == DEBUG_PARAMETER_REF
)
18107 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18108 tdie
= lookup_decl_die (tdecl
);
18115 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18116 != DEBUG_PARAMETER_REF
)
18118 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18120 VAR_INIT_STATUS_INITIALIZED
);
18124 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18125 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18128 add_AT_loc (cdie
, DW_AT_location
, reg
);
18129 else if (tdie
!= NULL
)
18130 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18131 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18132 if (next_arg
!= XEXP (arg
, 1))
18134 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18135 if (mode
== VOIDmode
)
18136 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18137 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18140 VAR_INIT_STATUS_INITIALIZED
);
18142 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18146 && (ca_loc
->symbol_ref
|| tloc
))
18147 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18148 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18150 dw_loc_descr_ref tval
= NULL
;
18152 if (tloc
!= NULL_RTX
)
18153 tval
= mem_loc_descriptor (tloc
,
18154 GET_MODE (tloc
) == VOIDmode
18155 ? Pmode
: GET_MODE (tloc
),
18157 VAR_INIT_STATUS_INITIALIZED
);
18159 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18160 else if (tlocc
!= NULL_RTX
)
18162 tval
= mem_loc_descriptor (tlocc
,
18163 GET_MODE (tlocc
) == VOIDmode
18164 ? Pmode
: GET_MODE (tlocc
),
18166 VAR_INIT_STATUS_INITIALIZED
);
18168 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18174 call_site_note_count
++;
18175 if (ca_loc
->tail_call_p
)
18176 tail_call_site_note_count
++;
18180 call_arg_locations
= NULL
;
18181 call_arg_loc_last
= NULL
;
18182 if (tail_call_site_count
>= 0
18183 && tail_call_site_count
== tail_call_site_note_count
18186 if (call_site_count
>= 0
18187 && call_site_count
== call_site_note_count
)
18188 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18190 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18192 call_site_count
= -1;
18193 tail_call_site_count
= -1;
18195 /* Add the calling convention attribute if requested. */
18196 add_calling_convention_attribute (subr_die
, decl
);
18200 /* Returns a hash value for X (which really is a die_struct). */
18203 common_block_die_table_hash (const void *x
)
18205 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18206 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18209 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18210 as decl_id and die_parent of die_struct Y. */
18213 common_block_die_table_eq (const void *x
, const void *y
)
18215 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18216 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18217 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18220 /* Generate a DIE to represent a declared data object.
18221 Either DECL or ORIGIN must be non-null. */
18224 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18226 HOST_WIDE_INT off
= 0;
18228 tree decl_or_origin
= decl
? decl
: origin
;
18229 tree ultimate_origin
;
18230 dw_die_ref var_die
;
18231 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18232 dw_die_ref origin_die
;
18233 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18234 || class_or_namespace_scope_p (context_die
));
18235 bool specialization_p
= false;
18237 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18238 if (decl
|| ultimate_origin
)
18239 origin
= ultimate_origin
;
18240 com_decl
= fortran_common (decl_or_origin
, &off
);
18242 /* Symbol in common gets emitted as a child of the common block, in the form
18243 of a data member. */
18246 dw_die_ref com_die
;
18247 dw_loc_list_ref loc
;
18248 die_node com_die_arg
;
18250 var_die
= lookup_decl_die (decl_or_origin
);
18253 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18255 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18260 /* Optimize the common case. */
18261 if (single_element_loc_list_p (loc
)
18262 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18263 && loc
->expr
->dw_loc_next
== NULL
18264 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18267 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18268 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18269 = plus_constant (GET_MODE (x
), x
, off
);
18272 loc_list_plus_const (loc
, off
);
18274 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18275 remove_AT (var_die
, DW_AT_declaration
);
18281 if (common_block_die_table
== NULL
)
18282 common_block_die_table
18283 = htab_create_ggc (10, common_block_die_table_hash
,
18284 common_block_die_table_eq
, NULL
);
18286 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18287 com_die_arg
.die_parent
= context_die
;
18288 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18289 loc
= loc_list_from_tree (com_decl
, 2);
18290 if (com_die
== NULL
)
18293 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18296 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18297 add_name_and_src_coords_attributes (com_die
, com_decl
);
18300 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18301 /* Avoid sharing the same loc descriptor between
18302 DW_TAG_common_block and DW_TAG_variable. */
18303 loc
= loc_list_from_tree (com_decl
, 2);
18305 else if (DECL_EXTERNAL (decl
))
18306 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18307 if (want_pubnames ())
18308 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18309 com_die
->decl_id
= DECL_UID (com_decl
);
18310 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18311 *slot
= (void *) com_die
;
18313 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18315 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18316 loc
= loc_list_from_tree (com_decl
, 2);
18317 remove_AT (com_die
, DW_AT_declaration
);
18319 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18320 add_name_and_src_coords_attributes (var_die
, decl
);
18321 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18322 TREE_THIS_VOLATILE (decl
), context_die
);
18323 add_AT_flag (var_die
, DW_AT_external
, 1);
18328 /* Optimize the common case. */
18329 if (single_element_loc_list_p (loc
)
18330 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18331 && loc
->expr
->dw_loc_next
== NULL
18332 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18334 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18335 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18336 = plus_constant (GET_MODE (x
), x
, off
);
18339 loc_list_plus_const (loc
, off
);
18341 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18343 else if (DECL_EXTERNAL (decl
))
18344 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18345 equate_decl_number_to_die (decl
, var_die
);
18349 /* If the compiler emitted a definition for the DECL declaration
18350 and if we already emitted a DIE for it, don't emit a second
18351 DIE for it again. Allow re-declarations of DECLs that are
18352 inside functions, though. */
18353 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18356 /* For static data members, the declaration in the class is supposed
18357 to have DW_TAG_member tag; the specification should still be
18358 DW_TAG_variable referencing the DW_TAG_member DIE. */
18359 if (declaration
&& class_scope_p (context_die
))
18360 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18362 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18365 if (origin
!= NULL
)
18366 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18368 /* Loop unrolling can create multiple blocks that refer to the same
18369 static variable, so we must test for the DW_AT_declaration flag.
18371 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18372 copy decls and set the DECL_ABSTRACT flag on them instead of
18375 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18377 ??? The declare_in_namespace support causes us to get two DIEs for one
18378 variable, both of which are declarations. We want to avoid considering
18379 one to be a specification, so we must test that this DIE is not a
18381 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18382 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18384 /* This is a definition of a C++ class level static. */
18385 add_AT_specification (var_die
, old_die
);
18386 specialization_p
= true;
18387 if (DECL_NAME (decl
))
18389 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18390 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18392 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18393 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18395 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18396 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18398 if (old_die
->die_tag
== DW_TAG_member
)
18399 add_linkage_name (var_die
, decl
);
18403 add_name_and_src_coords_attributes (var_die
, decl
);
18405 if ((origin
== NULL
&& !specialization_p
)
18407 && !DECL_ABSTRACT (decl_or_origin
)
18408 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18409 decl_function_context
18410 (decl_or_origin
))))
18412 tree type
= TREE_TYPE (decl_or_origin
);
18414 if (decl_by_reference_p (decl_or_origin
))
18415 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18417 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18418 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18421 if (origin
== NULL
&& !specialization_p
)
18423 if (TREE_PUBLIC (decl
))
18424 add_AT_flag (var_die
, DW_AT_external
, 1);
18426 if (DECL_ARTIFICIAL (decl
))
18427 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18429 add_accessibility_attribute (var_die
, decl
);
18433 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18435 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18436 equate_decl_number_to_die (decl
, var_die
);
18439 && (! DECL_ABSTRACT (decl_or_origin
)
18440 /* Local static vars are shared between all clones/inlines,
18441 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18443 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18444 && TREE_STATIC (decl_or_origin
)
18445 && DECL_RTL_SET_P (decl_or_origin
)))
18446 /* When abstract origin already has DW_AT_location attribute, no need
18447 to add it again. */
18448 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18450 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18451 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18452 defer_location (decl_or_origin
, var_die
);
18454 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18455 decl
== NULL
, DW_AT_location
);
18456 add_pubname (decl_or_origin
, var_die
);
18459 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18462 /* Generate a DIE to represent a named constant. */
18465 gen_const_die (tree decl
, dw_die_ref context_die
)
18467 dw_die_ref const_die
;
18468 tree type
= TREE_TYPE (decl
);
18470 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18471 add_name_and_src_coords_attributes (const_die
, decl
);
18472 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18473 if (TREE_PUBLIC (decl
))
18474 add_AT_flag (const_die
, DW_AT_external
, 1);
18475 if (DECL_ARTIFICIAL (decl
))
18476 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18477 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18480 /* Generate a DIE to represent a label identifier. */
18483 gen_label_die (tree decl
, dw_die_ref context_die
)
18485 tree origin
= decl_ultimate_origin (decl
);
18486 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18488 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18490 if (origin
!= NULL
)
18491 add_abstract_origin_attribute (lbl_die
, origin
);
18493 add_name_and_src_coords_attributes (lbl_die
, decl
);
18495 if (DECL_ABSTRACT (decl
))
18496 equate_decl_number_to_die (decl
, lbl_die
);
18499 insn
= DECL_RTL_IF_SET (decl
);
18501 /* Deleted labels are programmer specified labels which have been
18502 eliminated because of various optimizations. We still emit them
18503 here so that it is possible to put breakpoints on them. */
18507 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18509 /* When optimization is enabled (via -O) some parts of the compiler
18510 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18511 represent source-level labels which were explicitly declared by
18512 the user. This really shouldn't be happening though, so catch
18513 it if it ever does happen. */
18514 gcc_assert (!INSN_DELETED_P (insn
));
18516 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18517 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18521 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18522 && CODE_LABEL_NUMBER (insn
) != -1)
18524 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18525 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18530 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18531 attributes to the DIE for a block STMT, to describe where the inlined
18532 function was called from. This is similar to add_src_coords_attributes. */
18535 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18537 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18539 if (dwarf_version
>= 3 || !dwarf_strict
)
18541 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18542 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18547 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18548 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18551 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18553 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18555 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18556 && (dwarf_version
>= 3 || !dwarf_strict
))
18558 tree chain
, superblock
= NULL_TREE
;
18560 dw_attr_ref attr
= NULL
;
18562 if (inlined_function_outer_scope_p (stmt
))
18564 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18565 BLOCK_NUMBER (stmt
));
18566 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18569 /* Optimize duplicate .debug_ranges lists or even tails of
18570 lists. If this BLOCK has same ranges as its supercontext,
18571 lookup DW_AT_ranges attribute in the supercontext (and
18572 recursively so), verify that the ranges_table contains the
18573 right values and use it instead of adding a new .debug_range. */
18574 for (chain
= stmt
, pdie
= die
;
18575 BLOCK_SAME_RANGE (chain
);
18576 chain
= BLOCK_SUPERCONTEXT (chain
))
18578 dw_attr_ref new_attr
;
18580 pdie
= pdie
->die_parent
;
18583 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18585 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18586 if (new_attr
== NULL
18587 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18590 superblock
= BLOCK_SUPERCONTEXT (chain
);
18593 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18594 / 2 / DWARF2_ADDR_SIZE
].num
18595 == BLOCK_NUMBER (superblock
))
18596 && BLOCK_FRAGMENT_CHAIN (superblock
))
18598 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18599 / 2 / DWARF2_ADDR_SIZE
;
18600 unsigned long supercnt
= 0, thiscnt
= 0;
18601 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18602 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18605 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18606 == BLOCK_NUMBER (chain
));
18608 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18609 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18610 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18612 gcc_assert (supercnt
>= thiscnt
);
18613 add_AT_range_list (die
, DW_AT_ranges
,
18614 ((off
+ supercnt
- thiscnt
)
18615 * 2 * DWARF2_ADDR_SIZE
),
18620 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18622 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18625 add_ranges (chain
);
18626 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18633 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18634 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18635 BLOCK_NUMBER (stmt
));
18636 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18637 BLOCK_NUMBER (stmt
));
18638 add_AT_low_high_pc (die
, label
, label_high
, false);
18642 /* Generate a DIE for a lexical block. */
18645 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18647 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18649 if (call_arg_locations
)
18651 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18652 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18653 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18656 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18657 add_high_low_attributes (stmt
, stmt_die
);
18659 decls_for_scope (stmt
, stmt_die
, depth
);
18662 /* Generate a DIE for an inlined subprogram. */
18665 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18669 /* The instance of function that is effectively being inlined shall not
18671 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18673 decl
= block_ultimate_origin (stmt
);
18675 /* Emit info for the abstract instance first, if we haven't yet. We
18676 must emit this even if the block is abstract, otherwise when we
18677 emit the block below (or elsewhere), we may end up trying to emit
18678 a die whose origin die hasn't been emitted, and crashing. */
18679 dwarf2out_abstract_function (decl
);
18681 if (! BLOCK_ABSTRACT (stmt
))
18683 dw_die_ref subr_die
18684 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18686 if (call_arg_locations
)
18688 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18689 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18690 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18692 add_abstract_origin_attribute (subr_die
, decl
);
18693 if (TREE_ASM_WRITTEN (stmt
))
18694 add_high_low_attributes (stmt
, subr_die
);
18695 add_call_src_coords_attributes (stmt
, subr_die
);
18697 decls_for_scope (stmt
, subr_die
, depth
);
18698 current_function_has_inlines
= 1;
18702 /* Generate a DIE for a field in a record, or structure. */
18705 gen_field_die (tree decl
, dw_die_ref context_die
)
18707 dw_die_ref decl_die
;
18709 if (TREE_TYPE (decl
) == error_mark_node
)
18712 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18713 add_name_and_src_coords_attributes (decl_die
, decl
);
18714 add_type_attribute (decl_die
, member_declared_type (decl
), 0, 0, context_die
);
18716 if (DECL_BIT_FIELD_TYPE (decl
))
18718 add_byte_size_attribute (decl_die
, decl
);
18719 add_bit_size_attribute (decl_die
, decl
);
18720 add_bit_offset_attribute (decl_die
, decl
);
18723 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18724 add_data_member_location_attribute (decl_die
, decl
);
18726 if (DECL_ARTIFICIAL (decl
))
18727 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18729 add_accessibility_attribute (decl_die
, decl
);
18731 /* Equate decl number to die, so that we can look up this decl later on. */
18732 equate_decl_number_to_die (decl
, decl_die
);
18736 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18737 Use modified_type_die instead.
18738 We keep this code here just in case these types of DIEs may be needed to
18739 represent certain things in other languages (e.g. Pascal) someday. */
18742 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18745 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18747 equate_type_number_to_die (type
, ptr_die
);
18748 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18749 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18752 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18753 Use modified_type_die instead.
18754 We keep this code here just in case these types of DIEs may be needed to
18755 represent certain things in other languages (e.g. Pascal) someday. */
18758 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18760 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18762 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18763 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18765 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18767 equate_type_number_to_die (type
, ref_die
);
18768 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18769 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18773 /* Generate a DIE for a pointer to a member type. */
18776 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18779 = new_die (DW_TAG_ptr_to_member_type
,
18780 scope_die_for (type
, context_die
), type
);
18782 equate_type_number_to_die (type
, ptr_die
);
18783 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18784 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18785 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18788 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18790 static char *producer_string
;
18792 /* Return a heap allocated producer string including command line options
18793 if -grecord-gcc-switches. */
18796 gen_producer_string (void)
18799 vec
<dchar_p
> switches
= vNULL
;
18800 const char *language_string
= lang_hooks
.name
;
18801 char *producer
, *tail
;
18803 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18804 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18806 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18807 switch (save_decoded_options
[j
].opt_index
)
18814 case OPT_auxbase_strip
:
18823 case OPT_SPECIAL_unknown
:
18824 case OPT_SPECIAL_ignore
:
18825 case OPT_SPECIAL_program_name
:
18826 case OPT_SPECIAL_input_file
:
18827 case OPT_grecord_gcc_switches
:
18828 case OPT_gno_record_gcc_switches
:
18829 case OPT__output_pch_
:
18830 case OPT_fdiagnostics_show_location_
:
18831 case OPT_fdiagnostics_show_option
:
18832 case OPT_fdiagnostics_show_caret
:
18833 case OPT_fverbose_asm
:
18835 case OPT__sysroot_
:
18837 case OPT_nostdinc__
:
18838 /* Ignore these. */
18841 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
18842 & CL_NO_DWARF_RECORD
)
18844 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18846 switch (save_decoded_options
[j
].canonical_option
[0][1])
18853 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18860 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
18861 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18865 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18867 sprintf (tail
, "%s %s", language_string
, version_string
);
18870 FOR_EACH_VEC_ELT (switches
, j
, p
)
18874 memcpy (tail
+ 1, p
, len
);
18879 switches
.release ();
18883 /* Generate the DIE for the compilation unit. */
18886 gen_compile_unit_die (const char *filename
)
18889 const char *language_string
= lang_hooks
.name
;
18892 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18896 add_name_attribute (die
, filename
);
18897 /* Don't add cwd for <built-in>. */
18898 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
18899 add_comp_dir_attribute (die
);
18902 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
18904 /* If our producer is LTO try to figure out a common language to use
18905 from the global list of translation units. */
18906 if (strcmp (language_string
, "GNU GIMPLE") == 0)
18910 const char *common_lang
= NULL
;
18912 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
18914 if (!TRANSLATION_UNIT_LANGUAGE (t
))
18917 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
18918 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
18920 else if (strncmp (common_lang
, "GNU C", 5) == 0
18921 && strncmp(TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
18922 /* Mixing C and C++ is ok, use C++ in that case. */
18923 common_lang
= "GNU C++";
18926 /* Fall back to C. */
18927 common_lang
= NULL
;
18933 language_string
= common_lang
;
18936 language
= DW_LANG_C89
;
18937 if (strcmp (language_string
, "GNU C++") == 0)
18938 language
= DW_LANG_C_plus_plus
;
18939 else if (strcmp (language_string
, "GNU F77") == 0)
18940 language
= DW_LANG_Fortran77
;
18941 else if (strcmp (language_string
, "GNU Pascal") == 0)
18942 language
= DW_LANG_Pascal83
;
18943 else if (use_upc_dwarf2_extensions
18944 && (strcmp (language_string
, "GNU UPC") == 0))
18945 language
= DW_LANG_Upc
;
18946 else if (dwarf_version
>= 3 || !dwarf_strict
)
18948 if (strcmp (language_string
, "GNU Ada") == 0)
18949 language
= DW_LANG_Ada95
;
18950 else if (strcmp (language_string
, "GNU Fortran") == 0)
18951 language
= DW_LANG_Fortran95
;
18952 else if (strcmp (language_string
, "GNU Java") == 0)
18953 language
= DW_LANG_Java
;
18954 else if (strcmp (language_string
, "GNU Objective-C") == 0)
18955 language
= DW_LANG_ObjC
;
18956 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
18957 language
= DW_LANG_ObjC_plus_plus
;
18958 else if (dwarf_version
>= 5 || !dwarf_strict
)
18960 if (strcmp (language_string
, "GNU Go") == 0)
18961 language
= DW_LANG_Go
;
18964 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
18965 else if (strcmp (language_string
, "GNU Fortran") == 0)
18966 language
= DW_LANG_Fortran90
;
18968 add_AT_unsigned (die
, DW_AT_language
, language
);
18972 case DW_LANG_Fortran77
:
18973 case DW_LANG_Fortran90
:
18974 case DW_LANG_Fortran95
:
18975 /* Fortran has case insensitive identifiers and the front-end
18976 lowercases everything. */
18977 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
18980 /* The default DW_ID_case_sensitive doesn't need to be specified. */
18986 /* Generate the DIE for a base class. */
18989 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
18991 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
18993 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
18994 add_data_member_location_attribute (die
, binfo
);
18996 if (BINFO_VIRTUAL_P (binfo
))
18997 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
18999 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19000 children, otherwise the default is DW_ACCESS_public. In DWARF2
19001 the default has always been DW_ACCESS_private. */
19002 if (access
== access_public_node
)
19004 if (dwarf_version
== 2
19005 || context_die
->die_tag
== DW_TAG_class_type
)
19006 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19008 else if (access
== access_protected_node
)
19009 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19010 else if (dwarf_version
> 2
19011 && context_die
->die_tag
!= DW_TAG_class_type
)
19012 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19015 /* Generate a DIE for a class member. */
19018 gen_member_die (tree type
, dw_die_ref context_die
)
19021 tree binfo
= TYPE_BINFO (type
);
19024 /* If this is not an incomplete type, output descriptions of each of its
19025 members. Note that as we output the DIEs necessary to represent the
19026 members of this record or union type, we will also be trying to output
19027 DIEs to represent the *types* of those members. However the `type'
19028 function (above) will specifically avoid generating type DIEs for member
19029 types *within* the list of member DIEs for this (containing) type except
19030 for those types (of members) which are explicitly marked as also being
19031 members of this (containing) type themselves. The g++ front- end can
19032 force any given type to be treated as a member of some other (containing)
19033 type by setting the TYPE_CONTEXT of the given (member) type to point to
19034 the TREE node representing the appropriate (containing) type. */
19036 /* First output info about the base classes. */
19039 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19043 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19044 gen_inheritance_die (base
,
19045 (accesses
? (*accesses
)[i
] : access_public_node
),
19049 /* Now output info about the data members and type members. */
19050 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19052 /* If we thought we were generating minimal debug info for TYPE
19053 and then changed our minds, some of the member declarations
19054 may have already been defined. Don't define them again, but
19055 do put them in the right order. */
19057 child
= lookup_decl_die (member
);
19059 splice_child_die (context_die
, child
);
19061 gen_decl_die (member
, NULL
, context_die
);
19064 /* Now output info about the function members (if any). */
19065 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19067 /* Don't include clones in the member list. */
19068 if (DECL_ABSTRACT_ORIGIN (member
))
19071 child
= lookup_decl_die (member
);
19073 splice_child_die (context_die
, child
);
19075 gen_decl_die (member
, NULL
, context_die
);
19079 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19080 is set, we pretend that the type was never defined, so we only get the
19081 member DIEs needed by later specification DIEs. */
19084 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19085 enum debug_info_usage usage
)
19087 dw_die_ref type_die
= lookup_type_die (type
);
19088 dw_die_ref scope_die
= 0;
19090 int complete
= (TYPE_SIZE (type
)
19091 && (! TYPE_STUB_DECL (type
)
19092 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19093 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19094 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19096 if (type_die
&& ! complete
)
19099 if (TYPE_CONTEXT (type
) != NULL_TREE
19100 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19101 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19104 scope_die
= scope_die_for (type
, context_die
);
19106 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19107 /* First occurrence of type or toplevel definition of nested class. */
19109 dw_die_ref old_die
= type_die
;
19111 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19112 ? record_type_tag (type
) : DW_TAG_union_type
,
19114 equate_type_number_to_die (type
, type_die
);
19116 add_AT_specification (type_die
, old_die
);
19118 add_name_attribute (type_die
, type_tag (type
));
19121 remove_AT (type_die
, DW_AT_declaration
);
19123 /* Generate child dies for template paramaters. */
19124 if (debug_info_level
> DINFO_LEVEL_TERSE
19125 && COMPLETE_TYPE_P (type
))
19126 schedule_generic_params_dies_gen (type
);
19128 /* If this type has been completed, then give it a byte_size attribute and
19129 then give a list of members. */
19130 if (complete
&& !ns_decl
)
19132 /* Prevent infinite recursion in cases where the type of some member of
19133 this type is expressed in terms of this type itself. */
19134 TREE_ASM_WRITTEN (type
) = 1;
19135 add_byte_size_attribute (type_die
, type
);
19136 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19138 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19139 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19142 /* If the first reference to this type was as the return type of an
19143 inline function, then it may not have a parent. Fix this now. */
19144 if (type_die
->die_parent
== NULL
)
19145 add_child_die (scope_die
, type_die
);
19147 push_decl_scope (type
);
19148 gen_member_die (type
, type_die
);
19151 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19152 if (TYPE_ARTIFICIAL (type
))
19153 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19155 /* GNU extension: Record what type our vtable lives in. */
19156 if (TYPE_VFIELD (type
))
19158 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19160 gen_type_die (vtype
, context_die
);
19161 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19162 lookup_type_die (vtype
));
19167 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19169 /* We don't need to do this for function-local types. */
19170 if (TYPE_STUB_DECL (type
)
19171 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19172 vec_safe_push (incomplete_types
, type
);
19175 if (get_AT (type_die
, DW_AT_name
))
19176 add_pubtype (type
, type_die
);
19179 /* Generate a DIE for a subroutine _type_. */
19182 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19184 tree return_type
= TREE_TYPE (type
);
19185 dw_die_ref subr_die
19186 = new_die (DW_TAG_subroutine_type
,
19187 scope_die_for (type
, context_die
), type
);
19189 equate_type_number_to_die (type
, subr_die
);
19190 add_prototyped_attribute (subr_die
, type
);
19191 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19192 gen_formal_types_die (type
, subr_die
);
19194 if (get_AT (subr_die
, DW_AT_name
))
19195 add_pubtype (type
, subr_die
);
19198 /* Generate a DIE for a type definition. */
19201 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19203 dw_die_ref type_die
;
19206 if (TREE_ASM_WRITTEN (decl
))
19209 TREE_ASM_WRITTEN (decl
) = 1;
19210 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19211 origin
= decl_ultimate_origin (decl
);
19212 if (origin
!= NULL
)
19213 add_abstract_origin_attribute (type_die
, origin
);
19218 add_name_and_src_coords_attributes (type_die
, decl
);
19219 if (DECL_ORIGINAL_TYPE (decl
))
19221 type
= DECL_ORIGINAL_TYPE (decl
);
19223 gcc_assert (type
!= TREE_TYPE (decl
));
19224 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19228 type
= TREE_TYPE (decl
);
19230 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19232 /* Here, we are in the case of decl being a typedef naming
19233 an anonymous type, e.g:
19234 typedef struct {...} foo;
19235 In that case TREE_TYPE (decl) is not a typedef variant
19236 type and TYPE_NAME of the anonymous type is set to the
19237 TYPE_DECL of the typedef. This construct is emitted by
19240 TYPE is the anonymous struct named by the typedef
19241 DECL. As we need the DW_AT_type attribute of the
19242 DW_TAG_typedef to point to the DIE of TYPE, let's
19243 generate that DIE right away. add_type_attribute
19244 called below will then pick (via lookup_type_die) that
19245 anonymous struct DIE. */
19246 if (!TREE_ASM_WRITTEN (type
))
19247 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19249 /* This is a GNU Extension. We are adding a
19250 DW_AT_linkage_name attribute to the DIE of the
19251 anonymous struct TYPE. The value of that attribute
19252 is the name of the typedef decl naming the anonymous
19253 struct. This greatly eases the work of consumers of
19254 this debug info. */
19255 add_linkage_attr (lookup_type_die (type
), decl
);
19259 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19260 TREE_THIS_VOLATILE (decl
), context_die
);
19262 if (is_naming_typedef_decl (decl
))
19263 /* We want that all subsequent calls to lookup_type_die with
19264 TYPE in argument yield the DW_TAG_typedef we have just
19266 equate_type_number_to_die (type
, type_die
);
19268 add_accessibility_attribute (type_die
, decl
);
19271 if (DECL_ABSTRACT (decl
))
19272 equate_decl_number_to_die (decl
, type_die
);
19274 if (get_AT (type_die
, DW_AT_name
))
19275 add_pubtype (decl
, type_die
);
19278 /* Generate a DIE for a struct, class, enum or union type. */
19281 gen_tagged_type_die (tree type
,
19282 dw_die_ref context_die
,
19283 enum debug_info_usage usage
)
19287 if (type
== NULL_TREE
19288 || !is_tagged_type (type
))
19291 /* If this is a nested type whose containing class hasn't been written
19292 out yet, writing it out will cover this one, too. This does not apply
19293 to instantiations of member class templates; they need to be added to
19294 the containing class as they are generated. FIXME: This hurts the
19295 idea of combining type decls from multiple TUs, since we can't predict
19296 what set of template instantiations we'll get. */
19297 if (TYPE_CONTEXT (type
)
19298 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19299 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19301 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19303 if (TREE_ASM_WRITTEN (type
))
19306 /* If that failed, attach ourselves to the stub. */
19307 push_decl_scope (TYPE_CONTEXT (type
));
19308 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19311 else if (TYPE_CONTEXT (type
) != NULL_TREE
19312 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19314 /* If this type is local to a function that hasn't been written
19315 out yet, use a NULL context for now; it will be fixed up in
19316 decls_for_scope. */
19317 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19318 /* A declaration DIE doesn't count; nested types need to go in the
19320 if (context_die
&& is_declaration_die (context_die
))
19321 context_die
= NULL
;
19326 context_die
= declare_in_namespace (type
, context_die
);
19330 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19332 /* This might have been written out by the call to
19333 declare_in_namespace. */
19334 if (!TREE_ASM_WRITTEN (type
))
19335 gen_enumeration_type_die (type
, context_die
);
19338 gen_struct_or_union_type_die (type
, context_die
, usage
);
19343 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19344 it up if it is ever completed. gen_*_type_die will set it for us
19345 when appropriate. */
19348 /* Generate a type description DIE. */
19351 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19352 enum debug_info_usage usage
)
19354 struct array_descr_info info
;
19356 if (type
== NULL_TREE
|| type
== error_mark_node
)
19359 if (TYPE_NAME (type
) != NULL_TREE
19360 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19361 && is_redundant_typedef (TYPE_NAME (type
))
19362 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19363 /* The DECL of this type is a typedef we don't want to emit debug
19364 info for but we want debug info for its underlying typedef.
19365 This can happen for e.g, the injected-class-name of a C++
19367 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19369 /* If TYPE is a typedef type variant, let's generate debug info
19370 for the parent typedef which TYPE is a type of. */
19371 if (typedef_variant_p (type
))
19373 if (TREE_ASM_WRITTEN (type
))
19376 /* Prevent broken recursion; we can't hand off to the same type. */
19377 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19379 /* Give typedefs the right scope. */
19380 context_die
= scope_die_for (type
, context_die
);
19382 TREE_ASM_WRITTEN (type
) = 1;
19384 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19388 /* If type is an anonymous tagged type named by a typedef, let's
19389 generate debug info for the typedef. */
19390 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19392 /* Use the DIE of the containing namespace as the parent DIE of
19393 the type description DIE we want to generate. */
19394 if (DECL_CONTEXT (TYPE_NAME (type
))
19395 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19396 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19398 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19402 /* If this is an array type with hidden descriptor, handle it first. */
19403 if (!TREE_ASM_WRITTEN (type
)
19404 && lang_hooks
.types
.get_array_descr_info
19405 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19406 && (dwarf_version
>= 3 || !dwarf_strict
))
19408 gen_descr_array_type_die (type
, &info
, context_die
);
19409 TREE_ASM_WRITTEN (type
) = 1;
19413 /* We are going to output a DIE to represent the unqualified version
19414 of this type (i.e. without any const or volatile qualifiers) so
19415 get the main variant (i.e. the unqualified version) of this type
19416 now. (Vectors are special because the debugging info is in the
19417 cloned type itself). */
19418 if (TREE_CODE (type
) != VECTOR_TYPE
)
19419 type
= type_main_variant (type
);
19421 if (TREE_ASM_WRITTEN (type
))
19424 switch (TREE_CODE (type
))
19430 case REFERENCE_TYPE
:
19431 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19432 ensures that the gen_type_die recursion will terminate even if the
19433 type is recursive. Recursive types are possible in Ada. */
19434 /* ??? We could perhaps do this for all types before the switch
19436 TREE_ASM_WRITTEN (type
) = 1;
19438 /* For these types, all that is required is that we output a DIE (or a
19439 set of DIEs) to represent the "basis" type. */
19440 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19441 DINFO_USAGE_IND_USE
);
19445 /* This code is used for C++ pointer-to-data-member types.
19446 Output a description of the relevant class type. */
19447 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19448 DINFO_USAGE_IND_USE
);
19450 /* Output a description of the type of the object pointed to. */
19451 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19452 DINFO_USAGE_IND_USE
);
19454 /* Now output a DIE to represent this pointer-to-data-member type
19456 gen_ptr_to_mbr_type_die (type
, context_die
);
19459 case FUNCTION_TYPE
:
19460 /* Force out return type (in case it wasn't forced out already). */
19461 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19462 DINFO_USAGE_DIR_USE
);
19463 gen_subroutine_type_die (type
, context_die
);
19467 /* Force out return type (in case it wasn't forced out already). */
19468 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19469 DINFO_USAGE_DIR_USE
);
19470 gen_subroutine_type_die (type
, context_die
);
19474 gen_array_type_die (type
, context_die
);
19478 gen_array_type_die (type
, context_die
);
19481 case ENUMERAL_TYPE
:
19484 case QUAL_UNION_TYPE
:
19485 gen_tagged_type_die (type
, context_die
, usage
);
19491 case FIXED_POINT_TYPE
:
19494 /* No DIEs needed for fundamental types. */
19499 /* Just use DW_TAG_unspecified_type. */
19501 dw_die_ref type_die
= lookup_type_die (type
);
19502 if (type_die
== NULL
)
19504 tree name
= TYPE_NAME (type
);
19505 if (TREE_CODE (name
) == TYPE_DECL
)
19506 name
= DECL_NAME (name
);
19507 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19508 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19509 equate_type_number_to_die (type
, type_die
);
19515 gcc_unreachable ();
19518 TREE_ASM_WRITTEN (type
) = 1;
19522 gen_type_die (tree type
, dw_die_ref context_die
)
19524 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19527 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19528 things which are local to the given block. */
19531 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19533 int must_output_die
= 0;
19536 /* Ignore blocks that are NULL. */
19537 if (stmt
== NULL_TREE
)
19540 inlined_func
= inlined_function_outer_scope_p (stmt
);
19542 /* If the block is one fragment of a non-contiguous block, do not
19543 process the variables, since they will have been done by the
19544 origin block. Do process subblocks. */
19545 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19549 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19550 gen_block_die (sub
, context_die
, depth
+ 1);
19555 /* Determine if we need to output any Dwarf DIEs at all to represent this
19558 /* The outer scopes for inlinings *must* always be represented. We
19559 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19560 must_output_die
= 1;
19563 /* Determine if this block directly contains any "significant"
19564 local declarations which we will need to output DIEs for. */
19565 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19566 /* We are not in terse mode so *any* local declaration counts
19567 as being a "significant" one. */
19568 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19569 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19570 && (TREE_USED (stmt
)
19571 || TREE_ASM_WRITTEN (stmt
)
19572 || BLOCK_ABSTRACT (stmt
)));
19573 else if ((TREE_USED (stmt
)
19574 || TREE_ASM_WRITTEN (stmt
)
19575 || BLOCK_ABSTRACT (stmt
))
19576 && !dwarf2out_ignore_block (stmt
))
19577 must_output_die
= 1;
19580 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19581 DIE for any block which contains no significant local declarations at
19582 all. Rather, in such cases we just call `decls_for_scope' so that any
19583 needed Dwarf info for any sub-blocks will get properly generated. Note
19584 that in terse mode, our definition of what constitutes a "significant"
19585 local declaration gets restricted to include only inlined function
19586 instances and local (nested) function definitions. */
19587 if (must_output_die
)
19591 /* If STMT block is abstract, that means we have been called
19592 indirectly from dwarf2out_abstract_function.
19593 That function rightfully marks the descendent blocks (of
19594 the abstract function it is dealing with) as being abstract,
19595 precisely to prevent us from emitting any
19596 DW_TAG_inlined_subroutine DIE as a descendent
19597 of an abstract function instance. So in that case, we should
19598 not call gen_inlined_subroutine_die.
19600 Later though, when cgraph asks dwarf2out to emit info
19601 for the concrete instance of the function decl into which
19602 the concrete instance of STMT got inlined, the later will lead
19603 to the generation of a DW_TAG_inlined_subroutine DIE. */
19604 if (! BLOCK_ABSTRACT (stmt
))
19605 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19608 gen_lexical_block_die (stmt
, context_die
, depth
);
19611 decls_for_scope (stmt
, context_die
, depth
);
19614 /* Process variable DECL (or variable with origin ORIGIN) within
19615 block STMT and add it to CONTEXT_DIE. */
19617 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19620 tree decl_or_origin
= decl
? decl
: origin
;
19622 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19623 die
= lookup_decl_die (decl_or_origin
);
19624 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19625 && TYPE_DECL_IS_STUB (decl_or_origin
))
19626 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19630 if (die
!= NULL
&& die
->die_parent
== NULL
)
19631 add_child_die (context_die
, die
);
19632 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19633 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19634 stmt
, context_die
);
19636 gen_decl_die (decl
, origin
, context_die
);
19639 /* Generate all of the decls declared within a given scope and (recursively)
19640 all of its sub-blocks. */
19643 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19649 /* Ignore NULL blocks. */
19650 if (stmt
== NULL_TREE
)
19653 /* Output the DIEs to represent all of the data objects and typedefs
19654 declared directly within this block but not within any nested
19655 sub-blocks. Also, nested function and tag DIEs have been
19656 generated with a parent of NULL; fix that up now. */
19657 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19658 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19659 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19660 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19663 /* If we're at -g1, we're not interested in subblocks. */
19664 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19667 /* Output the DIEs to represent all sub-blocks (and the items declared
19668 therein) of this block. */
19669 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19671 subblocks
= BLOCK_CHAIN (subblocks
))
19672 gen_block_die (subblocks
, context_die
, depth
+ 1);
19675 /* Is this a typedef we can avoid emitting? */
19678 is_redundant_typedef (const_tree decl
)
19680 if (TYPE_DECL_IS_STUB (decl
))
19683 if (DECL_ARTIFICIAL (decl
)
19684 && DECL_CONTEXT (decl
)
19685 && is_tagged_type (DECL_CONTEXT (decl
))
19686 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19687 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19688 /* Also ignore the artificial member typedef for the class name. */
19694 /* Return TRUE if TYPE is a typedef that names a type for linkage
19695 purposes. This kind of typedefs is produced by the C++ FE for
19698 typedef struct {...} foo;
19700 In that case, there is no typedef variant type produced for foo.
19701 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19705 is_naming_typedef_decl (const_tree decl
)
19707 if (decl
== NULL_TREE
19708 || TREE_CODE (decl
) != TYPE_DECL
19709 || !is_tagged_type (TREE_TYPE (decl
))
19710 || DECL_IS_BUILTIN (decl
)
19711 || is_redundant_typedef (decl
)
19712 /* It looks like Ada produces TYPE_DECLs that are very similar
19713 to C++ naming typedefs but that have different
19714 semantics. Let's be specific to c++ for now. */
19718 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19719 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19720 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19721 != TYPE_NAME (TREE_TYPE (decl
))));
19724 /* Returns the DIE for a context. */
19726 static inline dw_die_ref
19727 get_context_die (tree context
)
19731 /* Find die that represents this context. */
19732 if (TYPE_P (context
))
19734 context
= TYPE_MAIN_VARIANT (context
);
19735 return strip_naming_typedef (context
, force_type_die (context
));
19738 return force_decl_die (context
);
19740 return comp_unit_die ();
19743 /* Returns the DIE for decl. A DIE will always be returned. */
19746 force_decl_die (tree decl
)
19748 dw_die_ref decl_die
;
19749 unsigned saved_external_flag
;
19750 tree save_fn
= NULL_TREE
;
19751 decl_die
= lookup_decl_die (decl
);
19754 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19756 decl_die
= lookup_decl_die (decl
);
19760 switch (TREE_CODE (decl
))
19762 case FUNCTION_DECL
:
19763 /* Clear current_function_decl, so that gen_subprogram_die thinks
19764 that this is a declaration. At this point, we just want to force
19765 declaration die. */
19766 save_fn
= current_function_decl
;
19767 current_function_decl
= NULL_TREE
;
19768 gen_subprogram_die (decl
, context_die
);
19769 current_function_decl
= save_fn
;
19773 /* Set external flag to force declaration die. Restore it after
19774 gen_decl_die() call. */
19775 saved_external_flag
= DECL_EXTERNAL (decl
);
19776 DECL_EXTERNAL (decl
) = 1;
19777 gen_decl_die (decl
, NULL
, context_die
);
19778 DECL_EXTERNAL (decl
) = saved_external_flag
;
19781 case NAMESPACE_DECL
:
19782 if (dwarf_version
>= 3 || !dwarf_strict
)
19783 dwarf2out_decl (decl
);
19785 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19786 decl_die
= comp_unit_die ();
19789 case TRANSLATION_UNIT_DECL
:
19790 decl_die
= comp_unit_die ();
19794 gcc_unreachable ();
19797 /* We should be able to find the DIE now. */
19799 decl_die
= lookup_decl_die (decl
);
19800 gcc_assert (decl_die
);
19806 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19807 always returned. */
19810 force_type_die (tree type
)
19812 dw_die_ref type_die
;
19814 type_die
= lookup_type_die (type
);
19817 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19819 type_die
= modified_type_die (type
, TYPE_QUALS (type
), context_die
);
19820 gcc_assert (type_die
);
19825 /* Force out any required namespaces to be able to output DECL,
19826 and return the new context_die for it, if it's changed. */
19829 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19831 tree context
= (DECL_P (thing
)
19832 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19833 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19834 /* Force out the namespace. */
19835 context_die
= force_decl_die (context
);
19837 return context_die
;
19840 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19841 type) within its namespace, if appropriate.
19843 For compatibility with older debuggers, namespace DIEs only contain
19844 declarations; all definitions are emitted at CU scope. */
19847 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19849 dw_die_ref ns_context
;
19851 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19852 return context_die
;
19854 /* If this decl is from an inlined function, then don't try to emit it in its
19855 namespace, as we will get confused. It would have already been emitted
19856 when the abstract instance of the inline function was emitted anyways. */
19857 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19858 return context_die
;
19860 ns_context
= setup_namespace_context (thing
, context_die
);
19862 if (ns_context
!= context_die
)
19866 if (DECL_P (thing
))
19867 gen_decl_die (thing
, NULL
, ns_context
);
19869 gen_type_die (thing
, ns_context
);
19871 return context_die
;
19874 /* Generate a DIE for a namespace or namespace alias. */
19877 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19879 dw_die_ref namespace_die
;
19881 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19882 they are an alias of. */
19883 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19885 /* Output a real namespace or module. */
19886 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19887 namespace_die
= new_die (is_fortran ()
19888 ? DW_TAG_module
: DW_TAG_namespace
,
19889 context_die
, decl
);
19890 /* For Fortran modules defined in different CU don't add src coords. */
19891 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19893 const char *name
= dwarf2_name (decl
, 0);
19895 add_name_attribute (namespace_die
, name
);
19898 add_name_and_src_coords_attributes (namespace_die
, decl
);
19899 if (DECL_EXTERNAL (decl
))
19900 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
19901 equate_decl_number_to_die (decl
, namespace_die
);
19905 /* Output a namespace alias. */
19907 /* Force out the namespace we are an alias of, if necessary. */
19908 dw_die_ref origin_die
19909 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
19911 if (DECL_FILE_SCOPE_P (decl
)
19912 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
19913 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19914 /* Now create the namespace alias DIE. */
19915 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
19916 add_name_and_src_coords_attributes (namespace_die
, decl
);
19917 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
19918 equate_decl_number_to_die (decl
, namespace_die
);
19920 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
19921 if (want_pubnames ())
19922 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
19925 /* Generate Dwarf debug information for a decl described by DECL.
19926 The return value is currently only meaningful for PARM_DECLs,
19927 for all other decls it returns NULL. */
19930 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
19932 tree decl_or_origin
= decl
? decl
: origin
;
19933 tree class_origin
= NULL
, ultimate_origin
;
19935 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
19938 switch (TREE_CODE (decl_or_origin
))
19944 if (!is_fortran () && !is_ada ())
19946 /* The individual enumerators of an enum type get output when we output
19947 the Dwarf representation of the relevant enum type itself. */
19951 /* Emit its type. */
19952 gen_type_die (TREE_TYPE (decl
), context_die
);
19954 /* And its containing namespace. */
19955 context_die
= declare_in_namespace (decl
, context_die
);
19957 gen_const_die (decl
, context_die
);
19960 case FUNCTION_DECL
:
19961 /* Don't output any DIEs to represent mere function declarations,
19962 unless they are class members or explicit block externs. */
19963 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
19964 && DECL_FILE_SCOPE_P (decl_or_origin
)
19965 && (current_function_decl
== NULL_TREE
19966 || DECL_ARTIFICIAL (decl_or_origin
)))
19971 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
19972 on local redeclarations of global functions. That seems broken. */
19973 if (current_function_decl
!= decl
)
19974 /* This is only a declaration. */;
19977 /* If we're emitting a clone, emit info for the abstract instance. */
19978 if (origin
|| DECL_ORIGIN (decl
) != decl
)
19979 dwarf2out_abstract_function (origin
19980 ? DECL_ORIGIN (origin
)
19981 : DECL_ABSTRACT_ORIGIN (decl
));
19983 /* If we're emitting an out-of-line copy of an inline function,
19984 emit info for the abstract instance and set up to refer to it. */
19985 else if (cgraph_function_possibly_inlined_p (decl
)
19986 && ! DECL_ABSTRACT (decl
)
19987 && ! class_or_namespace_scope_p (context_die
)
19988 /* dwarf2out_abstract_function won't emit a die if this is just
19989 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
19990 that case, because that works only if we have a die. */
19991 && DECL_INITIAL (decl
) != NULL_TREE
)
19993 dwarf2out_abstract_function (decl
);
19994 set_decl_origin_self (decl
);
19997 /* Otherwise we're emitting the primary DIE for this decl. */
19998 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20000 /* Before we describe the FUNCTION_DECL itself, make sure that we
20001 have its containing type. */
20003 origin
= decl_class_context (decl
);
20004 if (origin
!= NULL_TREE
)
20005 gen_type_die (origin
, context_die
);
20007 /* And its return type. */
20008 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20010 /* And its virtual context. */
20011 if (DECL_VINDEX (decl
) != NULL_TREE
)
20012 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20014 /* Make sure we have a member DIE for decl. */
20015 if (origin
!= NULL_TREE
)
20016 gen_type_die_for_member (origin
, decl
, context_die
);
20018 /* And its containing namespace. */
20019 context_die
= declare_in_namespace (decl
, context_die
);
20022 /* Now output a DIE to represent the function itself. */
20024 gen_subprogram_die (decl
, context_die
);
20028 /* If we are in terse mode, don't generate any DIEs to represent any
20029 actual typedefs. */
20030 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20033 /* In the special case of a TYPE_DECL node representing the declaration
20034 of some type tag, if the given TYPE_DECL is marked as having been
20035 instantiated from some other (original) TYPE_DECL node (e.g. one which
20036 was generated within the original definition of an inline function) we
20037 used to generate a special (abbreviated) DW_TAG_structure_type,
20038 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20039 should be actually referencing those DIEs, as variable DIEs with that
20040 type would be emitted already in the abstract origin, so it was always
20041 removed during unused type prunning. Don't add anything in this
20043 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20046 if (is_redundant_typedef (decl
))
20047 gen_type_die (TREE_TYPE (decl
), context_die
);
20049 /* Output a DIE to represent the typedef itself. */
20050 gen_typedef_die (decl
, context_die
);
20054 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20055 gen_label_die (decl
, context_die
);
20060 /* If we are in terse mode, don't generate any DIEs to represent any
20061 variable declarations or definitions. */
20062 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20065 /* Output any DIEs that are needed to specify the type of this data
20067 if (decl_by_reference_p (decl_or_origin
))
20068 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20070 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20072 /* And its containing type. */
20073 class_origin
= decl_class_context (decl_or_origin
);
20074 if (class_origin
!= NULL_TREE
)
20075 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20077 /* And its containing namespace. */
20078 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20080 /* Now output the DIE to represent the data object itself. This gets
20081 complicated because of the possibility that the VAR_DECL really
20082 represents an inlined instance of a formal parameter for an inline
20084 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20085 if (ultimate_origin
!= NULL_TREE
20086 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20087 gen_formal_parameter_die (decl
, origin
,
20088 true /* Emit name attribute. */,
20091 gen_variable_die (decl
, origin
, context_die
);
20095 /* Ignore the nameless fields that are used to skip bits but handle C++
20096 anonymous unions and structs. */
20097 if (DECL_NAME (decl
) != NULL_TREE
20098 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20099 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20101 gen_type_die (member_declared_type (decl
), context_die
);
20102 gen_field_die (decl
, context_die
);
20107 if (DECL_BY_REFERENCE (decl_or_origin
))
20108 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20110 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20111 return gen_formal_parameter_die (decl
, origin
,
20112 true /* Emit name attribute. */,
20115 case NAMESPACE_DECL
:
20116 case IMPORTED_DECL
:
20117 if (dwarf_version
>= 3 || !dwarf_strict
)
20118 gen_namespace_die (decl
, context_die
);
20122 /* Probably some frontend-internal decl. Assume we don't care. */
20123 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20130 /* Output debug information for global decl DECL. Called from toplev.c after
20131 compilation proper has finished. */
20134 dwarf2out_global_decl (tree decl
)
20136 /* Output DWARF2 information for file-scope tentative data object
20137 declarations, file-scope (extern) function declarations (which
20138 had no corresponding body) and file-scope tagged type declarations
20139 and definitions which have not yet been forced out. */
20140 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20141 dwarf2out_decl (decl
);
20144 /* Output debug information for type decl DECL. Called from toplev.c
20145 and from language front ends (to record built-in types). */
20147 dwarf2out_type_decl (tree decl
, int local
)
20150 dwarf2out_decl (decl
);
20153 /* Output debug information for imported module or decl DECL.
20154 NAME is non-NULL name in the lexical block if the decl has been renamed.
20155 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20156 that DECL belongs to.
20157 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20159 dwarf2out_imported_module_or_decl_1 (tree decl
,
20161 tree lexical_block
,
20162 dw_die_ref lexical_block_die
)
20164 expanded_location xloc
;
20165 dw_die_ref imported_die
= NULL
;
20166 dw_die_ref at_import_die
;
20168 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20170 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20171 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20175 xloc
= expand_location (input_location
);
20177 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20179 at_import_die
= force_type_die (TREE_TYPE (decl
));
20180 /* For namespace N { typedef void T; } using N::T; base_type_die
20181 returns NULL, but DW_TAG_imported_declaration requires
20182 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20183 if (!at_import_die
)
20185 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20186 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20187 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20188 gcc_assert (at_import_die
);
20193 at_import_die
= lookup_decl_die (decl
);
20194 if (!at_import_die
)
20196 /* If we're trying to avoid duplicate debug info, we may not have
20197 emitted the member decl for this field. Emit it now. */
20198 if (TREE_CODE (decl
) == FIELD_DECL
)
20200 tree type
= DECL_CONTEXT (decl
);
20202 if (TYPE_CONTEXT (type
)
20203 && TYPE_P (TYPE_CONTEXT (type
))
20204 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20205 DINFO_USAGE_DIR_USE
))
20207 gen_type_die_for_member (type
, decl
,
20208 get_context_die (TYPE_CONTEXT (type
)));
20210 at_import_die
= force_decl_die (decl
);
20214 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20216 if (dwarf_version
>= 3 || !dwarf_strict
)
20217 imported_die
= new_die (DW_TAG_imported_module
,
20224 imported_die
= new_die (DW_TAG_imported_declaration
,
20228 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20229 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20231 add_AT_string (imported_die
, DW_AT_name
,
20232 IDENTIFIER_POINTER (name
));
20233 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20236 /* Output debug information for imported module or decl DECL.
20237 NAME is non-NULL name in context if the decl has been renamed.
20238 CHILD is true if decl is one of the renamed decls as part of
20239 importing whole module. */
20242 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20245 /* dw_die_ref at_import_die; */
20246 dw_die_ref scope_die
;
20248 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20253 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20254 We need decl DIE for reference and scope die. First, get DIE for the decl
20257 /* Get the scope die for decl context. Use comp_unit_die for global module
20258 or decl. If die is not found for non globals, force new die. */
20260 && TYPE_P (context
)
20261 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20264 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20267 scope_die
= get_context_die (context
);
20271 gcc_assert (scope_die
->die_child
);
20272 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20273 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20274 scope_die
= scope_die
->die_child
;
20277 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20278 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20282 /* Write the debugging output for DECL. */
20285 dwarf2out_decl (tree decl
)
20287 dw_die_ref context_die
= comp_unit_die ();
20289 switch (TREE_CODE (decl
))
20294 case FUNCTION_DECL
:
20295 /* What we would really like to do here is to filter out all mere
20296 file-scope declarations of file-scope functions which are never
20297 referenced later within this translation unit (and keep all of ones
20298 that *are* referenced later on) but we aren't clairvoyant, so we have
20299 no idea which functions will be referenced in the future (i.e. later
20300 on within the current translation unit). So here we just ignore all
20301 file-scope function declarations which are not also definitions. If
20302 and when the debugger needs to know something about these functions,
20303 it will have to hunt around and find the DWARF information associated
20304 with the definition of the function.
20306 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20307 nodes represent definitions and which ones represent mere
20308 declarations. We have to check DECL_INITIAL instead. That's because
20309 the C front-end supports some weird semantics for "extern inline"
20310 function definitions. These can get inlined within the current
20311 translation unit (and thus, we need to generate Dwarf info for their
20312 abstract instances so that the Dwarf info for the concrete inlined
20313 instances can have something to refer to) but the compiler never
20314 generates any out-of-lines instances of such things (despite the fact
20315 that they *are* definitions).
20317 The important point is that the C front-end marks these "extern
20318 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20319 them anyway. Note that the C++ front-end also plays some similar games
20320 for inline function definitions appearing within include files which
20321 also contain `#pragma interface' pragmas.
20323 If we are called from dwarf2out_abstract_function output a DIE
20324 anyway. We can end up here this way with early inlining and LTO
20325 where the inlined function is output in a different LTRANS unit
20327 if (DECL_INITIAL (decl
) == NULL_TREE
20328 && ! DECL_ABSTRACT (decl
))
20331 /* If we're a nested function, initially use a parent of NULL; if we're
20332 a plain function, this will be fixed up in decls_for_scope. If
20333 we're a method, it will be ignored, since we already have a DIE. */
20334 if (decl_function_context (decl
)
20335 /* But if we're in terse mode, we don't care about scope. */
20336 && debug_info_level
> DINFO_LEVEL_TERSE
)
20337 context_die
= NULL
;
20341 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20342 declaration and if the declaration was never even referenced from
20343 within this entire compilation unit. We suppress these DIEs in
20344 order to save space in the .debug section (by eliminating entries
20345 which are probably useless). Note that we must not suppress
20346 block-local extern declarations (whether used or not) because that
20347 would screw-up the debugger's name lookup mechanism and cause it to
20348 miss things which really ought to be in scope at a given point. */
20349 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20352 /* For local statics lookup proper context die. */
20353 if (TREE_STATIC (decl
)
20354 && DECL_CONTEXT (decl
)
20355 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20356 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20358 /* If we are in terse mode, don't generate any DIEs to represent any
20359 variable declarations or definitions. */
20360 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20365 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20367 if (!is_fortran () && !is_ada ())
20369 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20370 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20373 case NAMESPACE_DECL
:
20374 case IMPORTED_DECL
:
20375 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20377 if (lookup_decl_die (decl
) != NULL
)
20382 /* Don't emit stubs for types unless they are needed by other DIEs. */
20383 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20386 /* Don't bother trying to generate any DIEs to represent any of the
20387 normal built-in types for the language we are compiling. */
20388 if (DECL_IS_BUILTIN (decl
))
20391 /* If we are in terse mode, don't generate any DIEs for types. */
20392 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20395 /* If we're a function-scope tag, initially use a parent of NULL;
20396 this will be fixed up in decls_for_scope. */
20397 if (decl_function_context (decl
))
20398 context_die
= NULL
;
20406 gen_decl_die (decl
, NULL
, context_die
);
20409 /* Write the debugging output for DECL. */
20412 dwarf2out_function_decl (tree decl
)
20414 dwarf2out_decl (decl
);
20415 call_arg_locations
= NULL
;
20416 call_arg_loc_last
= NULL
;
20417 call_site_count
= -1;
20418 tail_call_site_count
= -1;
20419 block_map
.release ();
20420 htab_empty (decl_loc_table
);
20421 htab_empty (cached_dw_loc_list_table
);
20424 /* Output a marker (i.e. a label) for the beginning of the generated code for
20425 a lexical block. */
20428 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20429 unsigned int blocknum
)
20431 switch_to_section (current_function_section ());
20432 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20435 /* Output a marker (i.e. a label) for the end of the generated code for a
20439 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20441 switch_to_section (current_function_section ());
20442 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20445 /* Returns nonzero if it is appropriate not to emit any debugging
20446 information for BLOCK, because it doesn't contain any instructions.
20448 Don't allow this for blocks with nested functions or local classes
20449 as we would end up with orphans, and in the presence of scheduling
20450 we may end up calling them anyway. */
20453 dwarf2out_ignore_block (const_tree block
)
20458 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20459 if (TREE_CODE (decl
) == FUNCTION_DECL
20460 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20462 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20464 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20465 if (TREE_CODE (decl
) == FUNCTION_DECL
20466 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20473 /* Hash table routines for file_hash. */
20476 file_table_eq (const void *p1_p
, const void *p2_p
)
20478 const struct dwarf_file_data
*const p1
=
20479 (const struct dwarf_file_data
*) p1_p
;
20480 const char *const p2
= (const char *) p2_p
;
20481 return filename_cmp (p1
->filename
, p2
) == 0;
20485 file_table_hash (const void *p_p
)
20487 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20488 return htab_hash_string (p
->filename
);
20491 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20492 dwarf2out.c) and return its "index". The index of each (known) filename is
20493 just a unique number which is associated with only that one filename. We
20494 need such numbers for the sake of generating labels (in the .debug_sfnames
20495 section) and references to those files numbers (in the .debug_srcinfo
20496 and.debug_macinfo sections). If the filename given as an argument is not
20497 found in our current list, add it to the list and assign it the next
20498 available unique index number. In order to speed up searches, we remember
20499 the index of the filename was looked up last. This handles the majority of
20502 static struct dwarf_file_data
*
20503 lookup_filename (const char *file_name
)
20506 struct dwarf_file_data
* created
;
20508 /* Check to see if the file name that was searched on the previous
20509 call matches this file name. If so, return the index. */
20510 if (file_table_last_lookup
20511 && (file_name
== file_table_last_lookup
->filename
20512 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20513 return file_table_last_lookup
;
20515 /* Didn't match the previous lookup, search the table. */
20516 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20517 htab_hash_string (file_name
), INSERT
);
20519 return (struct dwarf_file_data
*) *slot
;
20521 created
= ggc_alloc_dwarf_file_data ();
20522 created
->filename
= file_name
;
20523 created
->emitted_number
= 0;
20528 /* If the assembler will construct the file table, then translate the compiler
20529 internal file table number into the assembler file table number, and emit
20530 a .file directive if we haven't already emitted one yet. The file table
20531 numbers are different because we prune debug info for unused variables and
20532 types, which may include filenames. */
20535 maybe_emit_file (struct dwarf_file_data
* fd
)
20537 if (! fd
->emitted_number
)
20539 if (last_emitted_file
)
20540 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20542 fd
->emitted_number
= 1;
20543 last_emitted_file
= fd
;
20545 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20547 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20548 output_quoted_string (asm_out_file
,
20549 remap_debug_filename (fd
->filename
));
20550 fputc ('\n', asm_out_file
);
20554 return fd
->emitted_number
;
20557 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20558 That generation should happen after function debug info has been
20559 generated. The value of the attribute is the constant value of ARG. */
20562 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20564 die_arg_entry entry
;
20569 if (!tmpl_value_parm_die_table
)
20570 vec_alloc (tmpl_value_parm_die_table
, 32);
20574 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20577 /* Return TRUE if T is an instance of generic type, FALSE
20581 generic_type_p (tree t
)
20583 if (t
== NULL_TREE
|| !TYPE_P (t
))
20585 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20588 /* Schedule the generation of the generic parameter dies for the
20589 instance of generic type T. The proper generation itself is later
20590 done by gen_scheduled_generic_parms_dies. */
20593 schedule_generic_params_dies_gen (tree t
)
20595 if (!generic_type_p (t
))
20598 if (!generic_type_instances
)
20599 vec_alloc (generic_type_instances
, 256);
20601 vec_safe_push (generic_type_instances
, t
);
20604 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20605 by append_entry_to_tmpl_value_parm_die_table. This function must
20606 be called after function DIEs have been generated. */
20609 gen_remaining_tmpl_value_param_die_attribute (void)
20611 if (tmpl_value_parm_die_table
)
20616 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20617 tree_add_const_value_attribute (e
->die
, e
->arg
);
20621 /* Generate generic parameters DIEs for instances of generic types
20622 that have been previously scheduled by
20623 schedule_generic_params_dies_gen. This function must be called
20624 after all the types of the CU have been laid out. */
20627 gen_scheduled_generic_parms_dies (void)
20632 if (!generic_type_instances
)
20635 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20636 gen_generic_params_dies (t
);
20640 /* Replace DW_AT_name for the decl with name. */
20643 dwarf2out_set_name (tree decl
, tree name
)
20649 die
= TYPE_SYMTAB_DIE (decl
);
20653 dname
= dwarf2_name (name
, 0);
20657 attr
= get_AT (die
, DW_AT_name
);
20660 struct indirect_string_node
*node
;
20662 node
= find_AT_string (dname
);
20663 /* replace the string. */
20664 attr
->dw_attr_val
.v
.val_str
= node
;
20668 add_name_attribute (die
, dname
);
20671 /* Called by the final INSN scan whenever we see a var location. We
20672 use it to drop labels in the right places, and throw the location in
20673 our lookup table. */
20676 dwarf2out_var_location (rtx loc_note
)
20678 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20679 struct var_loc_node
*newloc
;
20680 rtx next_real
, next_note
;
20681 static const char *last_label
;
20682 static const char *last_postcall_label
;
20683 static bool last_in_cold_section_p
;
20684 static rtx expected_next_loc_note
;
20688 if (!NOTE_P (loc_note
))
20690 if (CALL_P (loc_note
))
20693 if (SIBLING_CALL_P (loc_note
))
20694 tail_call_site_count
++;
20699 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20700 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20703 /* Optimize processing a large consecutive sequence of location
20704 notes so we don't spend too much time in next_real_insn. If the
20705 next insn is another location note, remember the next_real_insn
20706 calculation for next time. */
20707 next_real
= cached_next_real_insn
;
20710 if (expected_next_loc_note
!= loc_note
)
20711 next_real
= NULL_RTX
;
20714 next_note
= NEXT_INSN (loc_note
);
20716 || INSN_DELETED_P (next_note
)
20717 || GET_CODE (next_note
) != NOTE
20718 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20719 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20720 next_note
= NULL_RTX
;
20723 next_real
= next_real_insn (loc_note
);
20727 expected_next_loc_note
= next_note
;
20728 cached_next_real_insn
= next_real
;
20731 cached_next_real_insn
= NULL_RTX
;
20733 /* If there are no instructions which would be affected by this note,
20734 don't do anything. */
20736 && next_real
== NULL_RTX
20737 && !NOTE_DURING_CALL_P (loc_note
))
20740 if (next_real
== NULL_RTX
)
20741 next_real
= get_last_insn ();
20743 /* If there were any real insns between note we processed last time
20744 and this note (or if it is the first note), clear
20745 last_{,postcall_}label so that they are not reused this time. */
20746 if (last_var_location_insn
== NULL_RTX
20747 || last_var_location_insn
!= next_real
20748 || last_in_cold_section_p
!= in_cold_section_p
)
20751 last_postcall_label
= NULL
;
20756 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20757 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20758 NOTE_DURING_CALL_P (loc_note
)
20759 ? last_postcall_label
: last_label
);
20760 if (newloc
== NULL
)
20769 /* If there were no real insns between note we processed last time
20770 and this note, use the label we emitted last time. Otherwise
20771 create a new label and emit it. */
20772 if (last_label
== NULL
)
20774 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20775 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20777 last_label
= ggc_strdup (loclabel
);
20782 struct call_arg_loc_node
*ca_loc
20783 = ggc_alloc_cleared_call_arg_loc_node ();
20784 rtx prev
= prev_real_insn (loc_note
), x
;
20785 ca_loc
->call_arg_loc_note
= loc_note
;
20786 ca_loc
->next
= NULL
;
20787 ca_loc
->label
= last_label
;
20790 || (NONJUMP_INSN_P (prev
)
20791 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20792 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20793 if (!CALL_P (prev
))
20794 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20795 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20796 x
= get_call_rtx_from (PATTERN (prev
));
20799 x
= XEXP (XEXP (x
, 0), 0);
20800 if (GET_CODE (x
) == SYMBOL_REF
20801 && SYMBOL_REF_DECL (x
)
20802 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20803 ca_loc
->symbol_ref
= x
;
20805 ca_loc
->block
= insn_scope (prev
);
20806 if (call_arg_locations
)
20807 call_arg_loc_last
->next
= ca_loc
;
20809 call_arg_locations
= ca_loc
;
20810 call_arg_loc_last
= ca_loc
;
20812 else if (!NOTE_DURING_CALL_P (loc_note
))
20813 newloc
->label
= last_label
;
20816 if (!last_postcall_label
)
20818 sprintf (loclabel
, "%s-1", last_label
);
20819 last_postcall_label
= ggc_strdup (loclabel
);
20821 newloc
->label
= last_postcall_label
;
20824 last_var_location_insn
= next_real
;
20825 last_in_cold_section_p
= in_cold_section_p
;
20828 /* Note in one location list that text section has changed. */
20831 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20833 var_loc_list
*list
= (var_loc_list
*) *slot
;
20835 list
->last_before_switch
20836 = list
->last
->next
? list
->last
->next
: list
->last
;
20840 /* Note in all location lists that text section has changed. */
20843 var_location_switch_text_section (void)
20845 if (decl_loc_table
== NULL
)
20848 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20851 /* Create a new line number table. */
20853 static dw_line_info_table
*
20854 new_line_info_table (void)
20856 dw_line_info_table
*table
;
20858 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
20859 table
->file_num
= 1;
20860 table
->line_num
= 1;
20861 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
20866 /* Lookup the "current" table into which we emit line info, so
20867 that we don't have to do it for every source line. */
20870 set_cur_line_info_table (section
*sec
)
20872 dw_line_info_table
*table
;
20874 if (sec
== text_section
)
20875 table
= text_section_line_info
;
20876 else if (sec
== cold_text_section
)
20878 table
= cold_text_section_line_info
;
20881 cold_text_section_line_info
= table
= new_line_info_table ();
20882 table
->end_label
= cold_end_label
;
20887 const char *end_label
;
20889 if (flag_reorder_blocks_and_partition
)
20891 if (in_cold_section_p
)
20892 end_label
= crtl
->subsections
.cold_section_end_label
;
20894 end_label
= crtl
->subsections
.hot_section_end_label
;
20898 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
20899 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
20900 current_function_funcdef_no
);
20901 end_label
= ggc_strdup (label
);
20904 table
= new_line_info_table ();
20905 table
->end_label
= end_label
;
20907 vec_safe_push (separate_line_info
, table
);
20910 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20911 table
->is_stmt
= (cur_line_info_table
20912 ? cur_line_info_table
->is_stmt
20913 : DWARF_LINE_DEFAULT_IS_STMT_START
);
20914 cur_line_info_table
= table
;
20918 /* We need to reset the locations at the beginning of each
20919 function. We can't do this in the end_function hook, because the
20920 declarations that use the locations won't have been output when
20921 that hook is called. Also compute have_multiple_function_sections here. */
20924 dwarf2out_begin_function (tree fun
)
20926 section
*sec
= function_section (fun
);
20928 if (sec
!= text_section
)
20929 have_multiple_function_sections
= true;
20931 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
20933 gcc_assert (current_function_decl
== fun
);
20934 cold_text_section
= unlikely_text_section ();
20935 switch_to_section (cold_text_section
);
20936 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
20937 switch_to_section (sec
);
20940 dwarf2out_note_section_used ();
20941 call_site_count
= 0;
20942 tail_call_site_count
= 0;
20944 set_cur_line_info_table (sec
);
20947 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
20950 push_dw_line_info_entry (dw_line_info_table
*table
,
20951 enum dw_line_info_opcode opcode
, unsigned int val
)
20953 dw_line_info_entry e
;
20956 vec_safe_push (table
->entries
, e
);
20959 /* Output a label to mark the beginning of a source code line entry
20960 and record information relating to this source line, in
20961 'line_info_table' for later output of the .debug_line section. */
20962 /* ??? The discriminator parameter ought to be unsigned. */
20965 dwarf2out_source_line (unsigned int line
, const char *filename
,
20966 int discriminator
, bool is_stmt
)
20968 unsigned int file_num
;
20969 dw_line_info_table
*table
;
20971 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
20974 /* The discriminator column was added in dwarf4. Simplify the below
20975 by simply removing it if we're not supposed to output it. */
20976 if (dwarf_version
< 4 && dwarf_strict
)
20979 table
= cur_line_info_table
;
20980 file_num
= maybe_emit_file (lookup_filename (filename
));
20982 /* ??? TODO: Elide duplicate line number entries. Traditionally,
20983 the debugger has used the second (possibly duplicate) line number
20984 at the beginning of the function to mark the end of the prologue.
20985 We could eliminate any other duplicates within the function. For
20986 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
20987 that second line number entry. */
20988 /* Recall that this end-of-prologue indication is *not* the same thing
20989 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
20990 to which the hook corresponds, follows the last insn that was
20991 emitted by gen_prologue. What we need is to precede the first insn
20992 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
20993 insn that corresponds to something the user wrote. These may be
20994 very different locations once scheduling is enabled. */
20996 if (0 && file_num
== table
->file_num
20997 && line
== table
->line_num
20998 && discriminator
== table
->discrim_num
20999 && is_stmt
== table
->is_stmt
)
21002 switch_to_section (current_function_section ());
21004 /* If requested, emit something human-readable. */
21005 if (flag_debug_asm
)
21006 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21008 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21010 /* Emit the .loc directive understood by GNU as. */
21011 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21012 file_num, line, is_stmt, discriminator */
21013 fputs ("\t.loc ", asm_out_file
);
21014 fprint_ul (asm_out_file
, file_num
);
21015 putc (' ', asm_out_file
);
21016 fprint_ul (asm_out_file
, line
);
21017 putc (' ', asm_out_file
);
21018 putc ('0', asm_out_file
);
21020 if (is_stmt
!= table
->is_stmt
)
21022 fputs (" is_stmt ", asm_out_file
);
21023 putc (is_stmt
? '1' : '0', asm_out_file
);
21025 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21027 gcc_assert (discriminator
> 0);
21028 fputs (" discriminator ", asm_out_file
);
21029 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21031 putc ('\n', asm_out_file
);
21035 unsigned int label_num
= ++line_info_label_num
;
21037 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21039 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21040 if (file_num
!= table
->file_num
)
21041 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21042 if (discriminator
!= table
->discrim_num
)
21043 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21044 if (is_stmt
!= table
->is_stmt
)
21045 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21046 push_dw_line_info_entry (table
, LI_set_line
, line
);
21049 table
->file_num
= file_num
;
21050 table
->line_num
= line
;
21051 table
->discrim_num
= discriminator
;
21052 table
->is_stmt
= is_stmt
;
21053 table
->in_use
= true;
21056 /* Record the beginning of a new source file. */
21059 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21061 if (flag_eliminate_dwarf2_dups
)
21063 /* Record the beginning of the file for break_out_includes. */
21064 dw_die_ref bincl_die
;
21066 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21067 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21070 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21073 e
.code
= DW_MACINFO_start_file
;
21075 e
.info
= ggc_strdup (filename
);
21076 vec_safe_push (macinfo_table
, e
);
21080 /* Record the end of a source file. */
21083 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21085 if (flag_eliminate_dwarf2_dups
)
21086 /* Record the end of the file for break_out_includes. */
21087 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21089 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21092 e
.code
= DW_MACINFO_end_file
;
21095 vec_safe_push (macinfo_table
, e
);
21099 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21100 the tail part of the directive line, i.e. the part which is past the
21101 initial whitespace, #, whitespace, directive-name, whitespace part. */
21104 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21105 const char *buffer ATTRIBUTE_UNUSED
)
21107 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21110 /* Insert a dummy first entry to be able to optimize the whole
21111 predefined macro block using DW_MACRO_GNU_transparent_include. */
21112 if (macinfo_table
->is_empty () && lineno
<= 1)
21117 vec_safe_push (macinfo_table
, e
);
21119 e
.code
= DW_MACINFO_define
;
21121 e
.info
= ggc_strdup (buffer
);
21122 vec_safe_push (macinfo_table
, e
);
21126 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21127 the tail part of the directive line, i.e. the part which is past the
21128 initial whitespace, #, whitespace, directive-name, whitespace part. */
21131 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21132 const char *buffer ATTRIBUTE_UNUSED
)
21134 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21137 /* Insert a dummy first entry to be able to optimize the whole
21138 predefined macro block using DW_MACRO_GNU_transparent_include. */
21139 if (macinfo_table
->is_empty () && lineno
<= 1)
21144 vec_safe_push (macinfo_table
, e
);
21146 e
.code
= DW_MACINFO_undef
;
21148 e
.info
= ggc_strdup (buffer
);
21149 vec_safe_push (macinfo_table
, e
);
21153 /* Routines to manipulate hash table of CUs. */
21156 htab_macinfo_hash (const void *of
)
21158 const macinfo_entry
*const entry
=
21159 (const macinfo_entry
*) of
;
21161 return htab_hash_string (entry
->info
);
21165 htab_macinfo_eq (const void *of1
, const void *of2
)
21167 const macinfo_entry
*const entry1
= (const macinfo_entry
*) of1
;
21168 const macinfo_entry
*const entry2
= (const macinfo_entry
*) of2
;
21170 return !strcmp (entry1
->info
, entry2
->info
);
21173 /* Output a single .debug_macinfo entry. */
21176 output_macinfo_op (macinfo_entry
*ref
)
21180 struct indirect_string_node
*node
;
21181 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21182 struct dwarf_file_data
*fd
;
21186 case DW_MACINFO_start_file
:
21187 fd
= lookup_filename (ref
->info
);
21188 file_num
= maybe_emit_file (fd
);
21189 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21190 dw2_asm_output_data_uleb128 (ref
->lineno
,
21191 "Included from line number %lu",
21192 (unsigned long) ref
->lineno
);
21193 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21195 case DW_MACINFO_end_file
:
21196 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21198 case DW_MACINFO_define
:
21199 case DW_MACINFO_undef
:
21200 len
= strlen (ref
->info
) + 1;
21202 && len
> DWARF_OFFSET_SIZE
21203 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21204 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21206 ref
->code
= ref
->code
== DW_MACINFO_define
21207 ? DW_MACRO_GNU_define_indirect
21208 : DW_MACRO_GNU_undef_indirect
;
21209 output_macinfo_op (ref
);
21212 dw2_asm_output_data (1, ref
->code
,
21213 ref
->code
== DW_MACINFO_define
21214 ? "Define macro" : "Undefine macro");
21215 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21216 (unsigned long) ref
->lineno
);
21217 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21219 case DW_MACRO_GNU_define_indirect
:
21220 case DW_MACRO_GNU_undef_indirect
:
21221 node
= find_AT_string (ref
->info
);
21223 && ((node
->form
== DW_FORM_strp
)
21224 || (node
->form
== DW_FORM_GNU_str_index
)));
21225 dw2_asm_output_data (1, ref
->code
,
21226 ref
->code
== DW_MACRO_GNU_define_indirect
21227 ? "Define macro indirect"
21228 : "Undefine macro indirect");
21229 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21230 (unsigned long) ref
->lineno
);
21231 if (node
->form
== DW_FORM_strp
)
21232 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21233 debug_str_section
, "The macro: \"%s\"",
21236 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21239 case DW_MACRO_GNU_transparent_include
:
21240 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21241 ASM_GENERATE_INTERNAL_LABEL (label
,
21242 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21243 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21246 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21247 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21252 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21253 other compilation unit .debug_macinfo sections. IDX is the first
21254 index of a define/undef, return the number of ops that should be
21255 emitted in a comdat .debug_macinfo section and emit
21256 a DW_MACRO_GNU_transparent_include entry referencing it.
21257 If the define/undef entry should be emitted normally, return 0. */
21260 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21261 htab_t
*macinfo_htab
)
21263 macinfo_entry
*first
, *second
, *cur
, *inc
;
21264 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21265 unsigned char checksum
[16];
21266 struct md5_ctx ctx
;
21267 char *grp_name
, *tail
;
21269 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21272 first
= &(*macinfo_table
)[idx
];
21273 second
= &(*macinfo_table
)[idx
+ 1];
21275 /* Optimize only if there are at least two consecutive define/undef ops,
21276 and either all of them are before first DW_MACINFO_start_file
21277 with lineno {0,1} (i.e. predefined macro block), or all of them are
21278 in some included header file. */
21279 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21281 if (vec_safe_is_empty (files
))
21283 if (first
->lineno
> 1 || second
->lineno
> 1)
21286 else if (first
->lineno
== 0)
21289 /* Find the last define/undef entry that can be grouped together
21290 with first and at the same time compute md5 checksum of their
21291 codes, linenumbers and strings. */
21292 md5_init_ctx (&ctx
);
21293 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21294 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21296 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21300 unsigned char code
= cur
->code
;
21301 md5_process_bytes (&code
, 1, &ctx
);
21302 checksum_uleb128 (cur
->lineno
, &ctx
);
21303 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21305 md5_finish_ctx (&ctx
, checksum
);
21308 /* From the containing include filename (if any) pick up just
21309 usable characters from its basename. */
21310 if (vec_safe_is_empty (files
))
21313 base
= lbasename (files
->last ().info
);
21314 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21315 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21316 encoded_filename_len
++;
21317 /* Count . at the end. */
21318 if (encoded_filename_len
)
21319 encoded_filename_len
++;
21321 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21322 linebuf_len
= strlen (linebuf
);
21324 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21325 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21327 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21328 tail
= grp_name
+ 4;
21329 if (encoded_filename_len
)
21331 for (i
= 0; base
[i
]; i
++)
21332 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21336 memcpy (tail
, linebuf
, linebuf_len
);
21337 tail
+= linebuf_len
;
21339 for (i
= 0; i
< 16; i
++)
21340 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21342 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21343 in the empty vector entry before the first define/undef. */
21344 inc
= &(*macinfo_table
)[idx
- 1];
21345 inc
->code
= DW_MACRO_GNU_transparent_include
;
21347 inc
->info
= ggc_strdup (grp_name
);
21348 if (*macinfo_htab
== NULL
)
21349 *macinfo_htab
= htab_create (10, htab_macinfo_hash
, htab_macinfo_eq
, NULL
);
21350 /* Avoid emitting duplicates. */
21351 slot
= htab_find_slot (*macinfo_htab
, inc
, INSERT
);
21356 /* If such an entry has been used before, just emit
21357 a DW_MACRO_GNU_transparent_include op. */
21358 inc
= (macinfo_entry
*) *slot
;
21359 output_macinfo_op (inc
);
21360 /* And clear all macinfo_entry in the range to avoid emitting them
21361 in the second pass. */
21362 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21371 inc
->lineno
= htab_elements (*macinfo_htab
);
21372 output_macinfo_op (inc
);
21377 /* Save any strings needed by the macinfo table in the debug str
21378 table. All strings must be collected into the table by the time
21379 index_string is called. */
21382 save_macinfo_strings (void)
21386 macinfo_entry
*ref
;
21388 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21392 /* Match the logic in output_macinfo_op to decide on
21393 indirect strings. */
21394 case DW_MACINFO_define
:
21395 case DW_MACINFO_undef
:
21396 len
= strlen (ref
->info
) + 1;
21398 && len
> DWARF_OFFSET_SIZE
21399 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21400 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21401 set_indirect_string (find_AT_string (ref
->info
));
21403 case DW_MACRO_GNU_define_indirect
:
21404 case DW_MACRO_GNU_undef_indirect
:
21405 set_indirect_string (find_AT_string (ref
->info
));
21413 /* Output macinfo section(s). */
21416 output_macinfo (void)
21419 unsigned long length
= vec_safe_length (macinfo_table
);
21420 macinfo_entry
*ref
;
21421 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21422 htab_t macinfo_htab
= NULL
;
21427 /* output_macinfo* uses these interchangeably. */
21428 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21429 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21430 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21431 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21433 /* For .debug_macro emit the section header. */
21436 dw2_asm_output_data (2, 4, "DWARF macro version number");
21437 if (DWARF_OFFSET_SIZE
== 8)
21438 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21440 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21441 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21442 (!dwarf_split_debug_info
? debug_line_section_label
21443 : debug_skeleton_line_section_label
),
21444 debug_line_section
, NULL
);
21447 /* In the first loop, it emits the primary .debug_macinfo section
21448 and after each emitted op the macinfo_entry is cleared.
21449 If a longer range of define/undef ops can be optimized using
21450 DW_MACRO_GNU_transparent_include, the
21451 DW_MACRO_GNU_transparent_include op is emitted and kept in
21452 the vector before the first define/undef in the range and the
21453 whole range of define/undef ops is not emitted and kept. */
21454 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21458 case DW_MACINFO_start_file
:
21459 vec_safe_push (files
, *ref
);
21461 case DW_MACINFO_end_file
:
21462 if (!vec_safe_is_empty (files
))
21465 case DW_MACINFO_define
:
21466 case DW_MACINFO_undef
:
21468 && HAVE_COMDAT_GROUP
21469 && vec_safe_length (files
) != 1
21472 && (*macinfo_table
)[i
- 1].code
== 0)
21474 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21483 /* A dummy entry may be inserted at the beginning to be able
21484 to optimize the whole block of predefined macros. */
21490 output_macinfo_op (ref
);
21495 if (macinfo_htab
== NULL
)
21498 htab_delete (macinfo_htab
);
21500 /* If any DW_MACRO_GNU_transparent_include were used, on those
21501 DW_MACRO_GNU_transparent_include entries terminate the
21502 current chain and switch to a new comdat .debug_macinfo
21503 section and emit the define/undef entries within it. */
21504 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21509 case DW_MACRO_GNU_transparent_include
:
21511 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21512 tree comdat_key
= get_identifier (ref
->info
);
21513 /* Terminate the previous .debug_macinfo section. */
21514 dw2_asm_output_data (1, 0, "End compilation unit");
21515 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21517 | SECTION_LINKONCE
,
21519 ASM_GENERATE_INTERNAL_LABEL (label
,
21520 DEBUG_MACRO_SECTION_LABEL
,
21522 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21525 dw2_asm_output_data (2, 4, "DWARF macro version number");
21526 if (DWARF_OFFSET_SIZE
== 8)
21527 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21529 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21532 case DW_MACINFO_define
:
21533 case DW_MACINFO_undef
:
21534 output_macinfo_op (ref
);
21539 gcc_unreachable ();
21543 /* Set up for Dwarf output at the start of compilation. */
21546 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21548 /* Allocate the file_table. */
21549 file_table
= htab_create_ggc (50, file_table_hash
,
21550 file_table_eq
, NULL
);
21552 /* Allocate the decl_die_table. */
21553 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21554 decl_die_table_eq
, NULL
);
21556 /* Allocate the decl_loc_table. */
21557 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21558 decl_loc_table_eq
, NULL
);
21560 /* Allocate the cached_dw_loc_list_table. */
21561 cached_dw_loc_list_table
21562 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21563 cached_dw_loc_list_table_eq
, NULL
);
21565 /* Allocate the initial hunk of the decl_scope_table. */
21566 vec_alloc (decl_scope_table
, 256);
21568 /* Allocate the initial hunk of the abbrev_die_table. */
21569 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21570 (ABBREV_DIE_TABLE_INCREMENT
);
21571 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21572 /* Zero-th entry is allocated, but unused. */
21573 abbrev_die_table_in_use
= 1;
21575 /* Allocate the pubtypes and pubnames vectors. */
21576 vec_alloc (pubname_table
, 32);
21577 vec_alloc (pubtype_table
, 32);
21579 vec_alloc (incomplete_types
, 64);
21581 vec_alloc (used_rtx_array
, 32);
21583 if (!dwarf_split_debug_info
)
21585 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21586 SECTION_DEBUG
, NULL
);
21587 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21588 SECTION_DEBUG
, NULL
);
21589 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21590 SECTION_DEBUG
, NULL
);
21594 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
21595 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21596 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
21597 SECTION_DEBUG
| SECTION_EXCLUDE
,
21599 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
21600 SECTION_DEBUG
, NULL
);
21601 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
21602 SECTION_DEBUG
, NULL
);
21603 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21604 SECTION_DEBUG
, NULL
);
21605 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
21606 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
21608 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
21609 the main .o, but the skeleton_line goes into the split off dwo. */
21610 debug_skeleton_line_section
21611 = get_section (DEBUG_DWO_LINE_SECTION
,
21612 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21613 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
21614 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
21615 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
21616 SECTION_DEBUG
| SECTION_EXCLUDE
,
21618 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
21619 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
21620 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
21621 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21623 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21624 SECTION_DEBUG
, NULL
);
21625 debug_macinfo_section
= get_section (dwarf_strict
21626 ? DEBUG_MACINFO_SECTION
21627 : DEBUG_MACRO_SECTION
,
21628 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
21629 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21630 SECTION_DEBUG
, NULL
);
21631 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21632 SECTION_DEBUG
, NULL
);
21633 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21634 SECTION_DEBUG
, NULL
);
21635 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21636 DEBUG_STR_SECTION_FLAGS
, NULL
);
21637 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21638 SECTION_DEBUG
, NULL
);
21639 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21640 SECTION_DEBUG
, NULL
);
21642 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21643 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21644 DEBUG_ABBREV_SECTION_LABEL
, 0);
21645 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21646 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21647 COLD_TEXT_SECTION_LABEL
, 0);
21648 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21650 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21651 DEBUG_INFO_SECTION_LABEL
, 0);
21652 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21653 DEBUG_LINE_SECTION_LABEL
, 0);
21654 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21655 DEBUG_RANGES_SECTION_LABEL
, 0);
21656 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
21657 DEBUG_ADDR_SECTION_LABEL
, 0);
21658 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21660 ? DEBUG_MACINFO_SECTION_LABEL
21661 : DEBUG_MACRO_SECTION_LABEL
, 0);
21662 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
21664 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21665 vec_alloc (macinfo_table
, 64);
21667 switch_to_section (text_section
);
21668 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21670 /* Make sure the line number table for .text always exists. */
21671 text_section_line_info
= new_line_info_table ();
21672 text_section_line_info
->end_label
= text_end_label
;
21675 /* Called before compile () starts outputtting functions, variables
21676 and toplevel asms into assembly. */
21679 dwarf2out_assembly_start (void)
21681 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21682 && dwarf2out_do_cfi_asm ()
21683 && (!(flag_unwind_tables
|| flag_exceptions
)
21684 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
21685 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21688 /* A helper function for dwarf2out_finish called through
21689 htab_traverse. Assign a string its index. All strings must be
21690 collected into the table by the time index_string is called,
21691 because the indexing code relies on htab_traverse to traverse nodes
21692 in the same order for each run. */
21695 index_string (void **h
, void *v
)
21697 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21698 unsigned int *index
= (unsigned int *) v
;
21700 find_string_form (node
);
21701 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21703 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
21704 node
->index
= *index
;
21710 /* A helper function for output_indirect_strings called through
21711 htab_traverse. Output the offset to a string and update the
21715 output_index_string_offset (void **h
, void *v
)
21717 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21718 unsigned int *offset
= (unsigned int *) v
;
21720 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21722 /* Assert that this node has been assigned an index. */
21723 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
21724 && node
->index
!= NOT_INDEXED
);
21725 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
21726 "indexed string 0x%x: %s", node
->index
, node
->str
);
21727 *offset
+= strlen (node
->str
) + 1;
21732 /* A helper function for dwarf2out_finish called through
21733 htab_traverse. Output the indexed string. */
21736 output_index_string (void **h
, void *v
)
21738 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21739 unsigned int *cur_idx
= (unsigned int *) v
;
21741 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21743 /* Assert that the strings are output in the same order as their
21744 indexes were assigned. */
21745 gcc_assert (*cur_idx
== node
->index
);
21746 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21747 assemble_string (node
->str
, strlen (node
->str
) + 1);
21753 /* A helper function for dwarf2out_finish called through
21754 htab_traverse. Emit one queued .debug_str string. */
21757 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
21759 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21761 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
21763 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21764 assemble_string (node
->str
, strlen (node
->str
) + 1);
21770 /* Output the indexed string table. */
21773 output_indirect_strings (void)
21775 if (!dwarf_split_debug_info
)
21777 switch_to_section (debug_str_section
);
21778 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
21782 unsigned int offset
= 0;
21783 unsigned int cur_idx
= 0;
21785 switch_to_section (debug_str_offsets_section
);
21786 htab_traverse_noresize (debug_str_hash
,
21787 output_index_string_offset
,
21789 switch_to_section (debug_str_section
);
21790 htab_traverse_noresize (debug_str_hash
,
21791 output_index_string
,
21796 /* Callback for htab_traverse to assign an index to an entry in the
21797 table, and to write that entry to the .debug_addr section. */
21800 output_addr_table_entry (void **slot
, void *data
)
21802 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
21803 unsigned int *cur_index
= (unsigned int *)data
;
21805 if (entry
->refcount
== 0)
21807 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
21808 || entry
->index
== NOT_INDEXED
);
21812 gcc_assert (entry
->index
== *cur_index
);
21815 switch (entry
->kind
)
21818 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
21819 "0x%x", entry
->index
);
21821 case ate_kind_rtx_dtprel
:
21822 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
21823 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
21826 fputc ('\n', asm_out_file
);
21828 case ate_kind_label
:
21829 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
21830 "0x%x", entry
->index
);
21833 gcc_unreachable ();
21838 /* Produce the .debug_addr section. */
21841 output_addr_table (void)
21843 unsigned int index
= 0;
21844 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
21847 switch_to_section (debug_addr_section
);
21848 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
21851 #if ENABLE_ASSERT_CHECKING
21852 /* Verify that all marks are clear. */
21855 verify_marks_clear (dw_die_ref die
)
21859 gcc_assert (! die
->die_mark
);
21860 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
21862 #endif /* ENABLE_ASSERT_CHECKING */
21864 /* Clear the marks for a die and its children.
21865 Be cool if the mark isn't set. */
21868 prune_unmark_dies (dw_die_ref die
)
21874 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
21877 /* Given DIE that we're marking as used, find any other dies
21878 it references as attributes and mark them as used. */
21881 prune_unused_types_walk_attribs (dw_die_ref die
)
21886 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
21888 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
21890 /* A reference to another DIE.
21891 Make sure that it will get emitted.
21892 If it was broken out into a comdat group, don't follow it. */
21893 if (! AT_ref (a
)->comdat_type_p
21894 || a
->dw_attr
== DW_AT_specification
)
21895 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
21897 /* Set the string's refcount to 0 so that prune_unused_types_mark
21898 accounts properly for it. */
21899 if (AT_class (a
) == dw_val_class_str
)
21900 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
21904 /* Mark the generic parameters and arguments children DIEs of DIE. */
21907 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
21911 if (die
== NULL
|| die
->die_child
== NULL
)
21913 c
= die
->die_child
;
21916 switch (c
->die_tag
)
21918 case DW_TAG_template_type_param
:
21919 case DW_TAG_template_value_param
:
21920 case DW_TAG_GNU_template_template_param
:
21921 case DW_TAG_GNU_template_parameter_pack
:
21922 prune_unused_types_mark (c
, 1);
21928 } while (c
&& c
!= die
->die_child
);
21931 /* Mark DIE as being used. If DOKIDS is true, then walk down
21932 to DIE's children. */
21935 prune_unused_types_mark (dw_die_ref die
, int dokids
)
21939 if (die
->die_mark
== 0)
21941 /* We haven't done this node yet. Mark it as used. */
21943 /* If this is the DIE of a generic type instantiation,
21944 mark the children DIEs that describe its generic parms and
21946 prune_unused_types_mark_generic_parms_dies (die
);
21948 /* We also have to mark its parents as used.
21949 (But we don't want to mark our parents' kids due to this.) */
21950 if (die
->die_parent
)
21951 prune_unused_types_mark (die
->die_parent
, 0);
21953 /* Mark any referenced nodes. */
21954 prune_unused_types_walk_attribs (die
);
21956 /* If this node is a specification,
21957 also mark the definition, if it exists. */
21958 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
21959 prune_unused_types_mark (die
->die_definition
, 1);
21962 if (dokids
&& die
->die_mark
!= 2)
21964 /* We need to walk the children, but haven't done so yet.
21965 Remember that we've walked the kids. */
21968 /* If this is an array type, we need to make sure our
21969 kids get marked, even if they're types. If we're
21970 breaking out types into comdat sections, do this
21971 for all type definitions. */
21972 if (die
->die_tag
== DW_TAG_array_type
21973 || (use_debug_types
21974 && is_type_die (die
) && ! is_declaration_die (die
)))
21975 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
21977 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
21981 /* For local classes, look if any static member functions were emitted
21982 and if so, mark them. */
21985 prune_unused_types_walk_local_classes (dw_die_ref die
)
21989 if (die
->die_mark
== 2)
21992 switch (die
->die_tag
)
21994 case DW_TAG_structure_type
:
21995 case DW_TAG_union_type
:
21996 case DW_TAG_class_type
:
21999 case DW_TAG_subprogram
:
22000 if (!get_AT_flag (die
, DW_AT_declaration
)
22001 || die
->die_definition
!= NULL
)
22002 prune_unused_types_mark (die
, 1);
22009 /* Mark children. */
22010 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22013 /* Walk the tree DIE and mark types that we actually use. */
22016 prune_unused_types_walk (dw_die_ref die
)
22020 /* Don't do anything if this node is already marked and
22021 children have been marked as well. */
22022 if (die
->die_mark
== 2)
22025 switch (die
->die_tag
)
22027 case DW_TAG_structure_type
:
22028 case DW_TAG_union_type
:
22029 case DW_TAG_class_type
:
22030 if (die
->die_perennial_p
)
22033 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22034 if (c
->die_tag
== DW_TAG_subprogram
)
22037 /* Finding used static member functions inside of classes
22038 is needed just for local classes, because for other classes
22039 static member function DIEs with DW_AT_specification
22040 are emitted outside of the DW_TAG_*_type. If we ever change
22041 it, we'd need to call this even for non-local classes. */
22043 prune_unused_types_walk_local_classes (die
);
22045 /* It's a type node --- don't mark it. */
22048 case DW_TAG_const_type
:
22049 case DW_TAG_packed_type
:
22050 case DW_TAG_pointer_type
:
22051 case DW_TAG_reference_type
:
22052 case DW_TAG_rvalue_reference_type
:
22053 case DW_TAG_volatile_type
:
22054 case DW_TAG_typedef
:
22055 case DW_TAG_array_type
:
22056 case DW_TAG_interface_type
:
22057 case DW_TAG_friend
:
22058 case DW_TAG_variant_part
:
22059 case DW_TAG_enumeration_type
:
22060 case DW_TAG_subroutine_type
:
22061 case DW_TAG_string_type
:
22062 case DW_TAG_set_type
:
22063 case DW_TAG_subrange_type
:
22064 case DW_TAG_ptr_to_member_type
:
22065 case DW_TAG_file_type
:
22066 if (die
->die_perennial_p
)
22069 /* It's a type node --- don't mark it. */
22073 /* Mark everything else. */
22077 if (die
->die_mark
== 0)
22081 /* Now, mark any dies referenced from here. */
22082 prune_unused_types_walk_attribs (die
);
22087 /* Mark children. */
22088 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22091 /* Increment the string counts on strings referred to from DIE's
22095 prune_unused_types_update_strings (dw_die_ref die
)
22100 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22101 if (AT_class (a
) == dw_val_class_str
)
22103 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22105 /* Avoid unnecessarily putting strings that are used less than
22106 twice in the hash table. */
22108 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22111 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22112 htab_hash_string (s
->str
),
22114 gcc_assert (*slot
== NULL
);
22120 /* Remove from the tree DIE any dies that aren't marked. */
22123 prune_unused_types_prune (dw_die_ref die
)
22128 gcc_assert (die
->die_mark
);
22129 prune_unused_types_update_strings (die
);
22131 if (! die
->die_child
)
22134 c
= die
->die_child
;
22136 dw_die_ref prev
= c
;
22137 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22138 if (c
== die
->die_child
)
22140 /* No marked children between 'prev' and the end of the list. */
22142 /* No marked children at all. */
22143 die
->die_child
= NULL
;
22146 prev
->die_sib
= c
->die_sib
;
22147 die
->die_child
= prev
;
22153 if (c
!= prev
->die_sib
)
22158 prune_unused_types_prune (c
);
22159 } while (c
!= die
->die_child
);
22162 /* If we pruned children, and this is a class, mark it as a
22163 declaration to inform debuggers that this is not a complete
22164 class definition. */
22165 if (pruned
&& die
->die_mark
== 1 && class_scope_p (die
)
22166 && ! is_declaration_die (die
))
22167 add_AT_flag (die
, DW_AT_declaration
, 1);
22170 /* Remove dies representing declarations that we never use. */
22173 prune_unused_types (void)
22176 limbo_die_node
*node
;
22177 comdat_type_node
*ctnode
;
22179 dw_die_ref base_type
;
22181 #if ENABLE_ASSERT_CHECKING
22182 /* All the marks should already be clear. */
22183 verify_marks_clear (comp_unit_die ());
22184 for (node
= limbo_die_list
; node
; node
= node
->next
)
22185 verify_marks_clear (node
->die
);
22186 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22187 verify_marks_clear (ctnode
->root_die
);
22188 #endif /* ENABLE_ASSERT_CHECKING */
22190 /* Mark types that are used in global variables. */
22191 premark_types_used_by_global_vars ();
22193 /* Set the mark on nodes that are actually used. */
22194 prune_unused_types_walk (comp_unit_die ());
22195 for (node
= limbo_die_list
; node
; node
= node
->next
)
22196 prune_unused_types_walk (node
->die
);
22197 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22199 prune_unused_types_walk (ctnode
->root_die
);
22200 prune_unused_types_mark (ctnode
->type_die
, 1);
22203 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22204 are unusual in that they are pubnames that are the children of pubtypes.
22205 They should only be marked via their parent DW_TAG_enumeration_type die,
22206 not as roots in themselves. */
22207 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22208 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22209 prune_unused_types_mark (pub
->die
, 1);
22210 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22211 prune_unused_types_mark (base_type
, 1);
22213 if (debug_str_hash
)
22214 htab_empty (debug_str_hash
);
22215 prune_unused_types_prune (comp_unit_die ());
22216 for (node
= limbo_die_list
; node
; node
= node
->next
)
22217 prune_unused_types_prune (node
->die
);
22218 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22219 prune_unused_types_prune (ctnode
->root_die
);
22221 /* Leave the marks clear. */
22222 prune_unmark_dies (comp_unit_die ());
22223 for (node
= limbo_die_list
; node
; node
= node
->next
)
22224 prune_unmark_dies (node
->die
);
22225 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22226 prune_unmark_dies (ctnode
->root_die
);
22229 /* Set the parameter to true if there are any relative pathnames in
22232 file_table_relative_p (void ** slot
, void *param
)
22234 bool *p
= (bool *) param
;
22235 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22236 if (!IS_ABSOLUTE_PATH (d
->filename
))
22244 /* Routines to manipulate hash table of comdat type units. */
22247 htab_ct_hash (const void *of
)
22250 const comdat_type_node
*const type_node
= (const comdat_type_node
*) of
;
22252 memcpy (&h
, type_node
->signature
, sizeof (h
));
22257 htab_ct_eq (const void *of1
, const void *of2
)
22259 const comdat_type_node
*const type_node_1
= (const comdat_type_node
*) of1
;
22260 const comdat_type_node
*const type_node_2
= (const comdat_type_node
*) of2
;
22262 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22263 DWARF_TYPE_SIGNATURE_SIZE
));
22266 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22267 to the location it would have been added, should we know its
22268 DECL_ASSEMBLER_NAME when we added other attributes. This will
22269 probably improve compactness of debug info, removing equivalent
22270 abbrevs, and hide any differences caused by deferring the
22271 computation of the assembler name, triggered by e.g. PCH. */
22274 move_linkage_attr (dw_die_ref die
)
22276 unsigned ix
= vec_safe_length (die
->die_attr
);
22277 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22279 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22280 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22284 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22286 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22290 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22292 die
->die_attr
->pop ();
22293 die
->die_attr
->quick_insert (ix
, linkage
);
22297 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22298 referenced from typed stack ops and count how often they are used. */
22301 mark_base_types (dw_loc_descr_ref loc
)
22303 dw_die_ref base_type
= NULL
;
22305 for (; loc
; loc
= loc
->dw_loc_next
)
22307 switch (loc
->dw_loc_opc
)
22309 case DW_OP_GNU_regval_type
:
22310 case DW_OP_GNU_deref_type
:
22311 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22313 case DW_OP_GNU_convert
:
22314 case DW_OP_GNU_reinterpret
:
22315 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22318 case DW_OP_GNU_const_type
:
22319 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22321 case DW_OP_GNU_entry_value
:
22322 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22327 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22328 if (base_type
->die_mark
)
22329 base_type
->die_mark
++;
22332 base_types
.safe_push (base_type
);
22333 base_type
->die_mark
= 1;
22338 /* Comparison function for sorting marked base types. */
22341 base_type_cmp (const void *x
, const void *y
)
22343 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22344 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22345 unsigned int byte_size1
, byte_size2
;
22346 unsigned int encoding1
, encoding2
;
22347 if (dx
->die_mark
> dy
->die_mark
)
22349 if (dx
->die_mark
< dy
->die_mark
)
22351 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22352 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22353 if (byte_size1
< byte_size2
)
22355 if (byte_size1
> byte_size2
)
22357 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22358 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22359 if (encoding1
< encoding2
)
22361 if (encoding1
> encoding2
)
22366 /* Move base types marked by mark_base_types as early as possible
22367 in the CU, sorted by decreasing usage count both to make the
22368 uleb128 references as small as possible and to make sure they
22369 will have die_offset already computed by calc_die_sizes when
22370 sizes of typed stack loc ops is computed. */
22373 move_marked_base_types (void)
22376 dw_die_ref base_type
, die
, c
;
22378 if (base_types
.is_empty ())
22381 /* Sort by decreasing usage count, they will be added again in that
22383 base_types
.qsort (base_type_cmp
);
22384 die
= comp_unit_die ();
22385 c
= die
->die_child
;
22388 dw_die_ref prev
= c
;
22390 while (c
->die_mark
)
22392 remove_child_with_prev (c
, prev
);
22393 /* As base types got marked, there must be at least
22394 one node other than DW_TAG_base_type. */
22395 gcc_assert (c
!= c
->die_sib
);
22399 while (c
!= die
->die_child
);
22400 gcc_assert (die
->die_child
);
22401 c
= die
->die_child
;
22402 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22404 base_type
->die_mark
= 0;
22405 base_type
->die_sib
= c
->die_sib
;
22406 c
->die_sib
= base_type
;
22411 /* Helper function for resolve_addr, attempt to resolve
22412 one CONST_STRING, return non-zero if not successful. Similarly verify that
22413 SYMBOL_REFs refer to variables emitted in the current CU. */
22416 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22420 if (GET_CODE (rtl
) == CONST_STRING
)
22422 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22423 tree t
= build_string (len
, XSTR (rtl
, 0));
22424 tree tlen
= size_int (len
- 1);
22426 = build_array_type (char_type_node
, build_index_type (tlen
));
22427 rtl
= lookup_constant_def (t
);
22428 if (!rtl
|| !MEM_P (rtl
))
22430 rtl
= XEXP (rtl
, 0);
22431 vec_safe_push (used_rtx_array
, rtl
);
22436 if (GET_CODE (rtl
) == SYMBOL_REF
22437 && SYMBOL_REF_DECL (rtl
))
22439 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22441 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22444 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22448 if (GET_CODE (rtl
) == CONST
22449 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22455 /* Helper function for resolve_addr, handle one location
22456 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22457 the location list couldn't be resolved. */
22460 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22462 dw_loc_descr_ref keep
= NULL
;
22463 for (; loc
; loc
= loc
->dw_loc_next
)
22464 switch (loc
->dw_loc_opc
)
22467 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22470 case DW_OP_GNU_addr_index
:
22471 case DW_OP_GNU_const_index
:
22473 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22474 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22475 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22480 case DW_OP_const4u
:
22481 case DW_OP_const8u
:
22483 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22486 case DW_OP_plus_uconst
:
22487 if (size_of_loc_descr (loc
)
22488 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22490 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22492 dw_loc_descr_ref repl
22493 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22494 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
22495 add_loc_descr (&repl
, loc
->dw_loc_next
);
22499 case DW_OP_implicit_value
:
22500 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22501 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
22504 case DW_OP_GNU_implicit_pointer
:
22505 case DW_OP_GNU_parameter_ref
:
22506 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22509 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22512 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22513 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22514 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22517 case DW_OP_GNU_const_type
:
22518 case DW_OP_GNU_regval_type
:
22519 case DW_OP_GNU_deref_type
:
22520 case DW_OP_GNU_convert
:
22521 case DW_OP_GNU_reinterpret
:
22522 while (loc
->dw_loc_next
22523 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
22525 dw_die_ref base1
, base2
;
22526 unsigned enc1
, enc2
, size1
, size2
;
22527 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22528 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22529 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22530 else if (loc
->dw_loc_oprnd1
.val_class
22531 == dw_val_class_unsigned_const
)
22534 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22535 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
22536 == dw_val_class_unsigned_const
)
22538 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22539 gcc_assert (base1
->die_tag
== DW_TAG_base_type
22540 && base2
->die_tag
== DW_TAG_base_type
);
22541 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
22542 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
22543 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
22544 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
22546 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
22547 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
22551 /* Optimize away next DW_OP_GNU_convert after
22552 adjusting LOC's base type die reference. */
22553 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22554 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22555 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
22557 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
22558 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22561 /* Don't change integer DW_OP_GNU_convert after e.g. floating
22562 point typed stack entry. */
22563 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
22564 keep
= loc
->dw_loc_next
;
22574 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22575 an address in .rodata section if the string literal is emitted there,
22576 or remove the containing location list or replace DW_AT_const_value
22577 with DW_AT_location and empty location expression, if it isn't found
22578 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22579 to something that has been emitted in the current CU. */
22582 resolve_addr (dw_die_ref die
)
22586 dw_loc_list_ref
*curr
, *start
, loc
;
22589 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22590 switch (AT_class (a
))
22592 case dw_val_class_loc_list
:
22593 start
= curr
= AT_loc_list_ptr (a
);
22596 /* The same list can be referenced more than once. See if we have
22597 already recorded the result from a previous pass. */
22599 *curr
= loc
->dw_loc_next
;
22600 else if (!loc
->resolved_addr
)
22602 /* As things stand, we do not expect or allow one die to
22603 reference a suffix of another die's location list chain.
22604 References must be identical or completely separate.
22605 There is therefore no need to cache the result of this
22606 pass on any list other than the first; doing so
22607 would lead to unnecessary writes. */
22610 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
22611 if (!resolve_addr_in_expr ((*curr
)->expr
))
22613 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
22614 dw_loc_descr_ref l
= (*curr
)->expr
;
22616 if (next
&& (*curr
)->ll_symbol
)
22618 gcc_assert (!next
->ll_symbol
);
22619 next
->ll_symbol
= (*curr
)->ll_symbol
;
22621 if (dwarf_split_debug_info
)
22622 remove_loc_list_addr_table_entries (l
);
22627 mark_base_types ((*curr
)->expr
);
22628 curr
= &(*curr
)->dw_loc_next
;
22632 loc
->resolved_addr
= 1;
22636 if (dwarf_split_debug_info
)
22637 remove_loc_list_addr_table_entries (loc
->expr
);
22638 loc
->dw_loc_next
= *start
;
22643 remove_AT (die
, a
->dw_attr
);
22647 case dw_val_class_loc
:
22649 dw_loc_descr_ref l
= AT_loc (a
);
22650 /* For -gdwarf-2 don't attempt to optimize
22651 DW_AT_data_member_location containing
22652 DW_OP_plus_uconst - older consumers might
22653 rely on it being that op instead of a more complex,
22654 but shorter, location description. */
22655 if ((dwarf_version
> 2
22656 || a
->dw_attr
!= DW_AT_data_member_location
22658 || l
->dw_loc_opc
!= DW_OP_plus_uconst
22659 || l
->dw_loc_next
!= NULL
)
22660 && !resolve_addr_in_expr (l
))
22662 if (dwarf_split_debug_info
)
22663 remove_loc_list_addr_table_entries (l
);
22664 remove_AT (die
, a
->dw_attr
);
22668 mark_base_types (l
);
22671 case dw_val_class_addr
:
22672 if (a
->dw_attr
== DW_AT_const_value
22673 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
22675 if (AT_index (a
) != NOT_INDEXED
)
22676 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
22677 remove_AT (die
, a
->dw_attr
);
22680 if (die
->die_tag
== DW_TAG_GNU_call_site
22681 && a
->dw_attr
== DW_AT_abstract_origin
)
22683 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
22684 dw_die_ref tdie
= lookup_decl_die (tdecl
);
22686 && DECL_EXTERNAL (tdecl
)
22687 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
22689 force_decl_die (tdecl
);
22690 tdie
= lookup_decl_die (tdecl
);
22694 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
22695 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
22696 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
22700 if (AT_index (a
) != NOT_INDEXED
)
22701 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
22702 remove_AT (die
, a
->dw_attr
);
22711 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
22714 /* Helper routines for optimize_location_lists.
22715 This pass tries to share identical local lists in .debug_loc
22718 /* Iteratively hash operands of LOC opcode. */
22720 static inline hashval_t
22721 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
22723 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
22724 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
22726 switch (loc
->dw_loc_opc
)
22728 case DW_OP_const4u
:
22729 case DW_OP_const8u
:
22733 case DW_OP_const1u
:
22734 case DW_OP_const1s
:
22735 case DW_OP_const2u
:
22736 case DW_OP_const2s
:
22737 case DW_OP_const4s
:
22738 case DW_OP_const8s
:
22742 case DW_OP_plus_uconst
:
22778 case DW_OP_deref_size
:
22779 case DW_OP_xderef_size
:
22780 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22787 gcc_assert (val1
->val_class
== dw_val_class_loc
);
22788 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
22789 hash
= iterative_hash_object (offset
, hash
);
22792 case DW_OP_implicit_value
:
22793 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22794 switch (val2
->val_class
)
22796 case dw_val_class_const
:
22797 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22799 case dw_val_class_vec
:
22801 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22802 unsigned int len
= val2
->v
.val_vec
.length
;
22804 hash
= iterative_hash_object (elt_size
, hash
);
22805 hash
= iterative_hash_object (len
, hash
);
22806 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22807 len
* elt_size
, hash
);
22810 case dw_val_class_const_double
:
22811 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22812 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22814 case dw_val_class_addr
:
22815 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
22818 gcc_unreachable ();
22822 case DW_OP_bit_piece
:
22823 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22824 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22830 unsigned char dtprel
= 0xd1;
22831 hash
= iterative_hash_object (dtprel
, hash
);
22833 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
22835 case DW_OP_GNU_addr_index
:
22836 case DW_OP_GNU_const_index
:
22840 unsigned char dtprel
= 0xd1;
22841 hash
= iterative_hash_object (dtprel
, hash
);
22843 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
22846 case DW_OP_GNU_implicit_pointer
:
22847 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22849 case DW_OP_GNU_entry_value
:
22850 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
22852 case DW_OP_GNU_regval_type
:
22853 case DW_OP_GNU_deref_type
:
22855 unsigned int byte_size
22856 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
22857 unsigned int encoding
22858 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
22859 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
22860 hash
= iterative_hash_object (byte_size
, hash
);
22861 hash
= iterative_hash_object (encoding
, hash
);
22864 case DW_OP_GNU_convert
:
22865 case DW_OP_GNU_reinterpret
:
22866 if (val1
->val_class
== dw_val_class_unsigned_const
)
22868 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
22872 case DW_OP_GNU_const_type
:
22874 unsigned int byte_size
22875 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
22876 unsigned int encoding
22877 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
22878 hash
= iterative_hash_object (byte_size
, hash
);
22879 hash
= iterative_hash_object (encoding
, hash
);
22880 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
22882 hash
= iterative_hash_object (val2
->val_class
, hash
);
22883 switch (val2
->val_class
)
22885 case dw_val_class_const
:
22886 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
22888 case dw_val_class_vec
:
22890 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
22891 unsigned int len
= val2
->v
.val_vec
.length
;
22893 hash
= iterative_hash_object (elt_size
, hash
);
22894 hash
= iterative_hash_object (len
, hash
);
22895 hash
= iterative_hash (val2
->v
.val_vec
.array
,
22896 len
* elt_size
, hash
);
22899 case dw_val_class_const_double
:
22900 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
22901 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
22904 gcc_unreachable ();
22910 /* Other codes have no operands. */
22916 /* Iteratively hash the whole DWARF location expression LOC. */
22918 static inline hashval_t
22919 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
22921 dw_loc_descr_ref l
;
22922 bool sizes_computed
= false;
22923 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
22924 size_of_locs (loc
);
22926 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
22928 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
22929 hash
= iterative_hash_object (opc
, hash
);
22930 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
22932 size_of_locs (loc
);
22933 sizes_computed
= true;
22935 hash
= hash_loc_operands (l
, hash
);
22940 /* Compute hash of the whole location list LIST_HEAD. */
22943 hash_loc_list (dw_loc_list_ref list_head
)
22945 dw_loc_list_ref curr
= list_head
;
22946 hashval_t hash
= 0;
22948 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
22950 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
22951 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
22953 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
22955 hash
= hash_locs (curr
->expr
, hash
);
22957 list_head
->hash
= hash
;
22960 /* Return true if X and Y opcodes have the same operands. */
22963 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
22965 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
22966 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
22967 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
22968 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
22970 switch (x
->dw_loc_opc
)
22972 case DW_OP_const4u
:
22973 case DW_OP_const8u
:
22977 case DW_OP_const1u
:
22978 case DW_OP_const1s
:
22979 case DW_OP_const2u
:
22980 case DW_OP_const2s
:
22981 case DW_OP_const4s
:
22982 case DW_OP_const8s
:
22986 case DW_OP_plus_uconst
:
23022 case DW_OP_deref_size
:
23023 case DW_OP_xderef_size
:
23024 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23027 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23028 can cause irrelevant differences in dw_loc_addr. */
23029 gcc_assert (valx1
->val_class
== dw_val_class_loc
23030 && valy1
->val_class
== dw_val_class_loc
23031 && (dwarf_split_debug_info
23032 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23033 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23034 case DW_OP_implicit_value
:
23035 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23036 || valx2
->val_class
!= valy2
->val_class
)
23038 switch (valx2
->val_class
)
23040 case dw_val_class_const
:
23041 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23042 case dw_val_class_vec
:
23043 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23044 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23045 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23046 valx2
->v
.val_vec
.elt_size
23047 * valx2
->v
.val_vec
.length
) == 0;
23048 case dw_val_class_const_double
:
23049 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23050 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23051 case dw_val_class_addr
:
23052 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23054 gcc_unreachable ();
23057 case DW_OP_bit_piece
:
23058 return valx1
->v
.val_int
== valy1
->v
.val_int
23059 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23062 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23063 case DW_OP_GNU_addr_index
:
23064 case DW_OP_GNU_const_index
:
23066 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23067 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23068 return rtx_equal_p (ax1
, ay1
);
23070 case DW_OP_GNU_implicit_pointer
:
23071 return valx1
->val_class
== dw_val_class_die_ref
23072 && valx1
->val_class
== valy1
->val_class
23073 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23074 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23075 case DW_OP_GNU_entry_value
:
23076 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23077 case DW_OP_GNU_const_type
:
23078 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23079 || valx2
->val_class
!= valy2
->val_class
)
23081 switch (valx2
->val_class
)
23083 case dw_val_class_const
:
23084 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23085 case dw_val_class_vec
:
23086 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23087 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23088 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23089 valx2
->v
.val_vec
.elt_size
23090 * valx2
->v
.val_vec
.length
) == 0;
23091 case dw_val_class_const_double
:
23092 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23093 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23095 gcc_unreachable ();
23097 case DW_OP_GNU_regval_type
:
23098 case DW_OP_GNU_deref_type
:
23099 return valx1
->v
.val_int
== valy1
->v
.val_int
23100 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23101 case DW_OP_GNU_convert
:
23102 case DW_OP_GNU_reinterpret
:
23103 if (valx1
->val_class
!= valy1
->val_class
)
23105 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23106 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23107 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23108 case DW_OP_GNU_parameter_ref
:
23109 return valx1
->val_class
== dw_val_class_die_ref
23110 && valx1
->val_class
== valy1
->val_class
23111 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23113 /* Other codes have no operands. */
23118 /* Return true if DWARF location expressions X and Y are the same. */
23121 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23123 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23124 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23125 || x
->dtprel
!= y
->dtprel
23126 || !compare_loc_operands (x
, y
))
23128 return x
== NULL
&& y
== NULL
;
23131 /* Return precomputed hash of location list X. */
23134 loc_list_hash (const void *x
)
23136 return ((const struct dw_loc_list_struct
*) x
)->hash
;
23139 /* Return 1 if location lists X and Y are the same. */
23142 loc_list_eq (const void *x
, const void *y
)
23144 const struct dw_loc_list_struct
*a
= (const struct dw_loc_list_struct
*) x
;
23145 const struct dw_loc_list_struct
*b
= (const struct dw_loc_list_struct
*) y
;
23148 if (a
->hash
!= b
->hash
)
23150 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23151 if (strcmp (a
->begin
, b
->begin
) != 0
23152 || strcmp (a
->end
, b
->end
) != 0
23153 || (a
->section
== NULL
) != (b
->section
== NULL
)
23154 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23155 || !compare_locs (a
->expr
, b
->expr
))
23157 return a
== NULL
&& b
== NULL
;
23160 /* Recursively optimize location lists referenced from DIE
23161 children and share them whenever possible. */
23164 optimize_location_lists_1 (dw_die_ref die
, htab_t htab
)
23171 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23172 if (AT_class (a
) == dw_val_class_loc_list
)
23174 dw_loc_list_ref list
= AT_loc_list (a
);
23175 /* TODO: perform some optimizations here, before hashing
23176 it and storing into the hash table. */
23177 hash_loc_list (list
);
23178 slot
= htab_find_slot_with_hash (htab
, list
, list
->hash
,
23181 *slot
= (void *) list
;
23183 a
->dw_attr_val
.v
.val_loc_list
= (dw_loc_list_ref
) *slot
;
23186 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23190 /* Recursively assign each location list a unique index into the debug_addr
23194 index_location_lists (dw_die_ref die
)
23200 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23201 if (AT_class (a
) == dw_val_class_loc_list
)
23203 dw_loc_list_ref list
= AT_loc_list (a
);
23204 dw_loc_list_ref curr
;
23205 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23207 /* Don't index an entry that has already been indexed
23208 or won't be output. */
23209 if (curr
->begin_entry
!= NULL
23210 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23214 = add_addr_table_entry (xstrdup (curr
->begin
),
23219 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23222 /* Optimize location lists referenced from DIE
23223 children and share them whenever possible. */
23226 optimize_location_lists (dw_die_ref die
)
23228 htab_t htab
= htab_create (500, loc_list_hash
, loc_list_eq
, NULL
);
23229 optimize_location_lists_1 (die
, htab
);
23230 htab_delete (htab
);
23233 /* Output stuff that dwarf requires at the end of every file,
23234 and generate the DWARF-2 debugging info. */
23237 dwarf2out_finish (const char *filename
)
23239 limbo_die_node
*node
, *next_node
;
23240 comdat_type_node
*ctnode
;
23241 htab_t comdat_type_table
;
23243 dw_die_ref main_comp_unit_die
;
23245 /* PCH might result in DW_AT_producer string being restored from the
23246 header compilation, so always fill it with empty string initially
23247 and overwrite only here. */
23248 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23249 producer_string
= gen_producer_string ();
23250 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23251 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23253 gen_scheduled_generic_parms_dies ();
23254 gen_remaining_tmpl_value_param_die_attribute ();
23256 /* Add the name for the main input file now. We delayed this from
23257 dwarf2out_init to avoid complications with PCH. */
23258 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23259 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23260 add_comp_dir_attribute (comp_unit_die ());
23261 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23264 htab_traverse (file_table
, file_table_relative_p
, &p
);
23266 add_comp_dir_attribute (comp_unit_die ());
23269 if (deferred_locations_list
)
23270 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23272 add_location_or_const_value_attribute (
23273 (*deferred_locations_list
)[i
].die
,
23274 (*deferred_locations_list
)[i
].variable
,
23279 /* Traverse the limbo die list, and add parent/child links. The only
23280 dies without parents that should be here are concrete instances of
23281 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23282 For concrete instances, we can get the parent die from the abstract
23284 for (node
= limbo_die_list
; node
; node
= next_node
)
23286 dw_die_ref die
= node
->die
;
23287 next_node
= node
->next
;
23289 if (die
->die_parent
== NULL
)
23291 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23293 if (origin
&& origin
->die_parent
)
23294 add_child_die (origin
->die_parent
, die
);
23295 else if (is_cu_die (die
))
23297 else if (seen_error ())
23298 /* It's OK to be confused by errors in the input. */
23299 add_child_die (comp_unit_die (), die
);
23302 /* In certain situations, the lexical block containing a
23303 nested function can be optimized away, which results
23304 in the nested function die being orphaned. Likewise
23305 with the return type of that nested function. Force
23306 this to be a child of the containing function.
23308 It may happen that even the containing function got fully
23309 inlined and optimized out. In that case we are lost and
23310 assign the empty child. This should not be big issue as
23311 the function is likely unreachable too. */
23312 gcc_assert (node
->created_for
);
23314 if (DECL_P (node
->created_for
))
23315 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23316 else if (TYPE_P (node
->created_for
))
23317 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23319 origin
= comp_unit_die ();
23321 add_child_die (origin
, die
);
23326 limbo_die_list
= NULL
;
23328 #if ENABLE_ASSERT_CHECKING
23330 dw_die_ref die
= comp_unit_die (), c
;
23331 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23334 resolve_addr (comp_unit_die ());
23335 move_marked_base_types ();
23337 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23339 tree decl
= node
->created_for
;
23340 /* When generating LTO bytecode we can not generate new assembler
23341 names at this point and all important decls got theirs via
23343 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23344 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23346 add_linkage_attr (node
->die
, decl
);
23347 move_linkage_attr (node
->die
);
23351 deferred_asm_name
= NULL
;
23353 /* Walk through the list of incomplete types again, trying once more to
23354 emit full debugging info for them. */
23355 retry_incomplete_types ();
23357 if (flag_eliminate_unused_debug_types
)
23358 prune_unused_types ();
23360 /* Generate separate COMDAT sections for type DIEs. */
23361 if (use_debug_types
)
23363 break_out_comdat_types (comp_unit_die ());
23365 /* Each new type_unit DIE was added to the limbo die list when created.
23366 Since these have all been added to comdat_type_list, clear the
23368 limbo_die_list
= NULL
;
23370 /* For each new comdat type unit, copy declarations for incomplete
23371 types to make the new unit self-contained (i.e., no direct
23372 references to the main compile unit). */
23373 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23374 copy_decls_for_unworthy_types (ctnode
->root_die
);
23375 copy_decls_for_unworthy_types (comp_unit_die ());
23377 /* In the process of copying declarations from one unit to another,
23378 we may have left some declarations behind that are no longer
23379 referenced. Prune them. */
23380 prune_unused_types ();
23383 /* Generate separate CUs for each of the include files we've seen.
23384 They will go into limbo_die_list. */
23385 if (flag_eliminate_dwarf2_dups
)
23386 break_out_includes (comp_unit_die ());
23388 /* Traverse the DIE's and add add sibling attributes to those DIE's
23389 that have children. */
23390 add_sibling_attributes (comp_unit_die ());
23391 for (node
= limbo_die_list
; node
; node
= node
->next
)
23392 add_sibling_attributes (node
->die
);
23393 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23394 add_sibling_attributes (ctnode
->root_die
);
23396 /* When splitting DWARF info, we put some attributes in the
23397 skeleton compile_unit DIE that remains in the .o, while
23398 most attributes go in the DWO compile_unit_die. */
23399 if (dwarf_split_debug_info
)
23400 main_comp_unit_die
= gen_compile_unit_die (NULL
);
23402 main_comp_unit_die
= comp_unit_die ();
23404 /* Output a terminator label for the .text section. */
23405 switch_to_section (text_section
);
23406 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23407 if (cold_text_section
)
23409 switch_to_section (cold_text_section
);
23410 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23413 /* We can only use the low/high_pc attributes if all of the code was
23415 if (!have_multiple_function_sections
23416 || (dwarf_version
< 3 && dwarf_strict
))
23418 /* Don't add if the CU has no associated code. */
23419 if (text_section_used
)
23420 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
23421 text_end_label
, true);
23427 bool range_list_added
= false;
23429 if (text_section_used
)
23430 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
23431 text_end_label
, &range_list_added
, true);
23432 if (cold_text_section_used
)
23433 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
23434 cold_end_label
, &range_list_added
, true);
23436 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
23438 if (DECL_IGNORED_P (fde
->decl
))
23440 if (!fde
->in_std_section
)
23441 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
23442 fde
->dw_fde_end
, &range_list_added
,
23444 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23445 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
23446 fde
->dw_fde_second_end
, &range_list_added
,
23450 if (range_list_added
)
23452 /* We need to give .debug_loc and .debug_ranges an appropriate
23453 "base address". Use zero so that these addresses become
23454 absolute. Historically, we've emitted the unexpected
23455 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23456 Emit both to give time for other tools to adapt. */
23457 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
23458 if (! dwarf_strict
&& dwarf_version
< 4)
23459 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
23465 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23466 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
23467 debug_line_section_label
);
23470 add_AT_macptr (comp_unit_die (),
23471 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
23472 macinfo_section_label
);
23474 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
23476 /* optimize_location_lists calculates the size of the lists,
23477 so index them first, and assign indices to the entries.
23478 Although optimize_location_lists will remove entries from
23479 the table, it only does so for duplicates, and therefore
23480 only reduces ref_counts to 1. */
23481 unsigned int index
= 0;
23482 index_location_lists (comp_unit_die ());
23483 htab_traverse_noresize (addr_index_table
,
23484 index_addr_table_entry
, &index
);
23486 if (have_location_lists
)
23487 optimize_location_lists (comp_unit_die ());
23489 save_macinfo_strings ();
23490 if (dwarf_split_debug_info
)
23492 unsigned int index
= 0;
23493 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
23496 /* Output all of the compilation units. We put the main one last so that
23497 the offsets are available to output_pubnames. */
23498 for (node
= limbo_die_list
; node
; node
= node
->next
)
23499 output_comp_unit (node
->die
, 0);
23501 comdat_type_table
= htab_create (100, htab_ct_hash
, htab_ct_eq
, NULL
);
23502 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23504 void **slot
= htab_find_slot (comdat_type_table
, ctnode
, INSERT
);
23506 /* Don't output duplicate types. */
23507 if (*slot
!= HTAB_EMPTY_ENTRY
)
23510 /* Add a pointer to the line table for the main compilation unit
23511 so that the debugger can make sense of DW_AT_decl_file
23513 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23514 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23515 (!dwarf_split_debug_info
23516 ? debug_line_section_label
23517 : debug_skeleton_line_section_label
));
23519 output_comdat_type_unit (ctnode
);
23522 htab_delete (comdat_type_table
);
23524 /* The AT_pubnames attribute needs to go in all skeleton dies, including
23525 both the main_cu and all skeleton TUs. Making this call unconditional
23526 would end up either adding a second copy of the AT_pubnames attribute, or
23527 requiring a special case in add_top_level_skeleton_die_attrs. */
23528 if (!dwarf_split_debug_info
)
23529 add_AT_pubnames (comp_unit_die ());
23531 if (dwarf_split_debug_info
)
23534 unsigned char checksum
[16];
23535 struct md5_ctx ctx
;
23537 /* Compute a checksum of the comp_unit to use as the dwo_id. */
23538 md5_init_ctx (&ctx
);
23540 die_checksum (comp_unit_die (), &ctx
, &mark
);
23541 unmark_all_dies (comp_unit_die ());
23542 md5_finish_ctx (&ctx
, checksum
);
23544 /* Use the first 8 bytes of the checksum as the dwo_id,
23545 and add it to both comp-unit DIEs. */
23546 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
23547 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
23549 /* Add the base offset of the ranges table to the skeleton
23551 if (ranges_table_in_use
)
23552 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
23553 ranges_section_label
);
23555 switch_to_section (debug_addr_section
);
23556 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
23557 output_addr_table ();
23560 /* Output the main compilation unit if non-empty or if .debug_macinfo
23561 or .debug_macro will be emitted. */
23562 output_comp_unit (comp_unit_die (), have_macinfo
);
23564 if (dwarf_split_debug_info
&& info_section_emitted
)
23565 output_skeleton_debug_sections (main_comp_unit_die
);
23567 /* Output the abbreviation table. */
23568 if (abbrev_die_table_in_use
!= 1)
23570 switch_to_section (debug_abbrev_section
);
23571 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
23572 output_abbrev_section ();
23575 /* Output location list section if necessary. */
23576 if (have_location_lists
)
23578 /* Output the location lists info. */
23579 switch_to_section (debug_loc_section
);
23580 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
23581 output_location_lists (comp_unit_die ());
23584 /* Output public names and types tables if necessary. */
23585 output_pubnames (pubname_table
);
23586 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23587 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23588 simply won't look for the section. */
23589 output_pubnames (pubtype_table
);
23591 /* Output the address range information if a CU (.debug_info section)
23592 was emitted. We output an empty table even if we had no functions
23593 to put in it. This because the consumer has no way to tell the
23594 difference between an empty table that we omitted and failure to
23595 generate a table that would have contained data. */
23596 if (info_section_emitted
)
23598 unsigned long aranges_length
= size_of_aranges ();
23600 switch_to_section (debug_aranges_section
);
23601 output_aranges (aranges_length
);
23604 /* Output ranges section if necessary. */
23605 if (ranges_table_in_use
)
23607 switch_to_section (debug_ranges_section
);
23608 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
23612 /* Have to end the macro section. */
23615 switch_to_section (debug_macinfo_section
);
23616 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
23618 dw2_asm_output_data (1, 0, "End compilation unit");
23621 /* Output the source line correspondence table. We must do this
23622 even if there is no line information. Otherwise, on an empty
23623 translation unit, we will generate a present, but empty,
23624 .debug_info section. IRIX 6.5 `nm' will then complain when
23625 examining the file. This is done late so that any filenames
23626 used by the debug_info section are marked as 'used'. */
23627 switch_to_section (debug_line_section
);
23628 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
23629 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
23630 output_line_info (false);
23632 if (dwarf_split_debug_info
&& info_section_emitted
)
23634 switch_to_section (debug_skeleton_line_section
);
23635 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
23636 output_line_info (true);
23639 /* If we emitted any indirect strings, output the string table too. */
23640 if (debug_str_hash
)
23641 output_indirect_strings ();
23644 #include "gt-dwarf2out.h"