1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2013 Free Software Foundation, Inc.
3 Contributed by Gary Funck (gary@intrepid.com).
4 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com).
5 Extensively modified by Jason Merrill (jason@cygnus.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
23 /* TODO: Emit .debug_line header even when there are no functions, since
24 the file numbers are used by .debug_info. Alternately, leave
25 out locations for types and decls.
26 Avoid talking about ctors and op= for PODs.
27 Factor out common prologue sequences into multiple CIEs. */
29 /* The first part of this file deals with the DWARF 2 frame unwind
30 information, which is also used by the GCC efficient exception handling
31 mechanism. The second part, controlled only by an #ifdef
32 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging
35 /* DWARF2 Abbreviation Glossary:
37 CFA = Canonical Frame Address
38 a fixed address on the stack which identifies a call frame.
39 We define it to be the value of SP just before the call insn.
40 The CFA register and offset, which may change during the course
41 of the function, are used to calculate its value at runtime.
43 CFI = Call Frame Instruction
44 an instruction for the DWARF2 abstract machine
46 CIE = Common Information Entry
47 information describing information common to one or more FDEs
49 DIE = Debugging Information Entry
51 FDE = Frame Description Entry
52 information describing the stack call frame, in particular,
53 how to restore registers
55 DW_CFA_... = DWARF2 CFA call frame instruction
56 DW_TAG_... = DWARF2 DIE tag */
60 #include "coretypes.h"
66 #include "hard-reg-set.h"
68 #include "insn-config.h"
75 #include "dwarf2out.h"
76 #include "dwarf2asm.h"
81 #include "diagnostic.h"
82 #include "tree-pretty-print.h"
85 #include "common/common-target.h"
86 #include "langhooks.h"
87 #include "hash-table.h"
96 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
97 static rtx last_var_location_insn
;
98 static rtx cached_next_real_insn
;
100 #ifdef VMS_DEBUGGING_INFO
101 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
103 /* Define this macro to be a nonzero value if the directory specifications
104 which are output in the debug info should end with a separator. */
105 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
106 /* Define this macro to evaluate to a nonzero value if GCC should refrain
107 from generating indirect strings in DWARF2 debug information, for instance
108 if your target is stuck with an old version of GDB that is unable to
109 process them properly or uses VMS Debug. */
110 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
112 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
113 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
116 /* ??? Poison these here until it can be done generically. They've been
117 totally replaced in this file; make sure it stays that way. */
118 #undef DWARF2_UNWIND_INFO
119 #undef DWARF2_FRAME_INFO
120 #if (GCC_VERSION >= 3000)
121 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
124 /* The size of the target's pointer type. */
126 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
129 /* Array of RTXes referenced by the debugging information, which therefore
130 must be kept around forever. */
131 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
133 /* A pointer to the base of a list of incomplete types which might be
134 completed at some later time. incomplete_types_list needs to be a
135 vec<tree, va_gc> *because we want to tell the garbage collector about
137 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
139 /* A pointer to the base of a table of references to declaration
140 scopes. This table is a display which tracks the nesting
141 of declaration scopes at the current scope and containing
142 scopes. This table is used to find the proper place to
143 define type declaration DIE's. */
144 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
146 /* Pointers to various DWARF2 sections. */
147 static GTY(()) section
*debug_info_section
;
148 static GTY(()) section
*debug_skeleton_info_section
;
149 static GTY(()) section
*debug_abbrev_section
;
150 static GTY(()) section
*debug_skeleton_abbrev_section
;
151 static GTY(()) section
*debug_aranges_section
;
152 static GTY(()) section
*debug_addr_section
;
153 static GTY(()) section
*debug_macinfo_section
;
154 static GTY(()) section
*debug_line_section
;
155 static GTY(()) section
*debug_skeleton_line_section
;
156 static GTY(()) section
*debug_loc_section
;
157 static GTY(()) section
*debug_pubnames_section
;
158 static GTY(()) section
*debug_pubtypes_section
;
159 static GTY(()) section
*debug_str_section
;
160 static GTY(()) section
*debug_str_dwo_section
;
161 static GTY(()) section
*debug_str_offsets_section
;
162 static GTY(()) section
*debug_ranges_section
;
163 static GTY(()) section
*debug_frame_section
;
165 /* Maximum size (in bytes) of an artificially generated label. */
166 #define MAX_ARTIFICIAL_LABEL_BYTES 30
168 /* According to the (draft) DWARF 3 specification, the initial length
169 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
170 bytes are 0xffffffff, followed by the length stored in the next 8
173 However, the SGI/MIPS ABI uses an initial length which is equal to
174 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
176 #ifndef DWARF_INITIAL_LENGTH_SIZE
177 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
180 /* Round SIZE up to the nearest BOUNDARY. */
181 #define DWARF_ROUND(SIZE,BOUNDARY) \
182 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
184 /* CIE identifier. */
185 #if HOST_BITS_PER_WIDE_INT >= 64
186 #define DWARF_CIE_ID \
187 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
189 #define DWARF_CIE_ID DW_CIE_ID
193 /* A vector for a table that contains frame description
194 information for each routine. */
195 #define NOT_INDEXED (-1U)
196 #define NO_INDEX_ASSIGNED (-2U)
198 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
200 struct GTY(()) indirect_string_node
{
202 unsigned int refcount
;
203 enum dwarf_form form
;
208 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
210 /* With split_debug_info, both the comp_dir and dwo_name go in the
211 main object file, rather than the dwo, similar to the force_direct
212 parameter elsewhere but with additional complications:
214 1) The string is needed in both the main object file and the dwo.
215 That is, the comp_dir and dwo_name will appear in both places.
217 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
218 DW_FORM_GNU_str_index.
220 3) GCC chooses the form to use late, depending on the size and
223 Rather than forcing the all debug string handling functions and
224 callers to deal with these complications, simply use a separate,
225 special-cased string table for any attribute that should go in the
226 main object file. This limits the complexity to just the places
229 static GTY ((param_is (struct indirect_string_node
)))
230 htab_t skeleton_debug_str_hash
;
232 static GTY(()) int dw2_string_counter
;
234 /* True if the compilation unit places functions in more than one section. */
235 static GTY(()) bool have_multiple_function_sections
= false;
237 /* Whether the default text and cold text sections have been used at all. */
239 static GTY(()) bool text_section_used
= false;
240 static GTY(()) bool cold_text_section_used
= false;
242 /* The default cold text section. */
243 static GTY(()) section
*cold_text_section
;
245 /* Forward declarations for functions defined in this file. */
247 static char *stripattributes (const char *);
248 static void output_call_frame_info (int);
249 static void dwarf2out_note_section_used (void);
251 /* Personality decl of current unit. Used only when assembler does not support
253 static GTY(()) rtx current_unit_personality
;
255 /* Data and reference forms for relocatable data. */
256 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
257 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
259 #ifndef DEBUG_FRAME_SECTION
260 #define DEBUG_FRAME_SECTION ".debug_frame"
263 #ifndef FUNC_BEGIN_LABEL
264 #define FUNC_BEGIN_LABEL "LFB"
267 #ifndef FUNC_END_LABEL
268 #define FUNC_END_LABEL "LFE"
271 #ifndef PROLOGUE_END_LABEL
272 #define PROLOGUE_END_LABEL "LPE"
275 #ifndef EPILOGUE_BEGIN_LABEL
276 #define EPILOGUE_BEGIN_LABEL "LEB"
279 #ifndef FRAME_BEGIN_LABEL
280 #define FRAME_BEGIN_LABEL "Lframe"
282 #define CIE_AFTER_SIZE_LABEL "LSCIE"
283 #define CIE_END_LABEL "LECIE"
284 #define FDE_LABEL "LSFDE"
285 #define FDE_AFTER_SIZE_LABEL "LASFDE"
286 #define FDE_END_LABEL "LEFDE"
287 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
288 #define LINE_NUMBER_END_LABEL "LELT"
289 #define LN_PROLOG_AS_LABEL "LASLTP"
290 #define LN_PROLOG_END_LABEL "LELTP"
291 #define DIE_LABEL_PREFIX "DW"
293 /* Match the base name of a file to the base name of a compilation unit. */
296 matches_main_base (const char *path
)
298 /* Cache the last query. */
299 static const char *last_path
= NULL
;
300 static int last_match
= 0;
301 if (path
!= last_path
)
304 int length
= base_of_path (path
, &base
);
306 last_match
= (length
== main_input_baselength
307 && memcmp (base
, main_input_basename
, length
) == 0);
312 #ifdef DEBUG_DEBUG_STRUCT
315 dump_struct_debug (tree type
, enum debug_info_usage usage
,
316 enum debug_struct_file criterion
, int generic
,
317 int matches
, int result
)
319 /* Find the type name. */
320 tree type_decl
= TYPE_STUB_DECL (type
);
322 const char *name
= 0;
323 if (TREE_CODE (t
) == TYPE_DECL
)
326 name
= IDENTIFIER_POINTER (t
);
328 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
330 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
331 matches
? "bas" : "hdr",
332 generic
? "gen" : "ord",
333 usage
== DINFO_USAGE_DFN
? ";" :
334 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
336 (void*) type_decl
, name
);
339 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
340 dump_struct_debug (type, usage, criterion, generic, matches, result)
344 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
350 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
352 enum debug_struct_file criterion
;
354 bool generic
= lang_hooks
.types
.generic_p (type
);
357 criterion
= debug_struct_generic
[usage
];
359 criterion
= debug_struct_ordinary
[usage
];
361 if (criterion
== DINFO_STRUCT_FILE_NONE
)
362 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
363 if (criterion
== DINFO_STRUCT_FILE_ANY
)
364 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
366 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
368 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
369 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
371 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
372 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
373 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
376 /* Return a pointer to a copy of the section string name S with all
377 attributes stripped off, and an asterisk prepended (for assemble_name). */
380 stripattributes (const char *s
)
382 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
387 while (*s
&& *s
!= ',')
394 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
395 switch to the data section instead, and write out a synthetic start label
396 for collect2 the first time around. */
399 switch_to_eh_frame_section (bool back
)
403 #ifdef EH_FRAME_SECTION_NAME
404 if (eh_frame_section
== 0)
408 if (EH_TABLES_CAN_BE_READ_ONLY
)
414 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
416 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
418 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
421 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
422 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
423 && (per_encoding
& 0x70) != DW_EH_PE_absptr
424 && (per_encoding
& 0x70) != DW_EH_PE_aligned
425 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
426 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
427 ? 0 : SECTION_WRITE
);
430 flags
= SECTION_WRITE
;
431 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
433 #endif /* EH_FRAME_SECTION_NAME */
435 if (eh_frame_section
)
436 switch_to_section (eh_frame_section
);
439 /* We have no special eh_frame section. Put the information in
440 the data section and emit special labels to guide collect2. */
441 switch_to_section (data_section
);
445 label
= get_file_function_name ("F");
446 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
447 targetm
.asm_out
.globalize_label (asm_out_file
,
448 IDENTIFIER_POINTER (label
));
449 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
454 /* Switch [BACK] to the eh or debug frame table section, depending on
458 switch_to_frame_table_section (int for_eh
, bool back
)
461 switch_to_eh_frame_section (back
);
464 if (!debug_frame_section
)
465 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
466 SECTION_DEBUG
, NULL
);
467 switch_to_section (debug_frame_section
);
471 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
473 enum dw_cfi_oprnd_type
474 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
479 case DW_CFA_GNU_window_save
:
480 case DW_CFA_remember_state
:
481 case DW_CFA_restore_state
:
482 return dw_cfi_oprnd_unused
;
485 case DW_CFA_advance_loc1
:
486 case DW_CFA_advance_loc2
:
487 case DW_CFA_advance_loc4
:
488 case DW_CFA_MIPS_advance_loc8
:
489 return dw_cfi_oprnd_addr
;
492 case DW_CFA_offset_extended
:
494 case DW_CFA_offset_extended_sf
:
495 case DW_CFA_def_cfa_sf
:
497 case DW_CFA_restore_extended
:
498 case DW_CFA_undefined
:
499 case DW_CFA_same_value
:
500 case DW_CFA_def_cfa_register
:
501 case DW_CFA_register
:
502 case DW_CFA_expression
:
503 return dw_cfi_oprnd_reg_num
;
505 case DW_CFA_def_cfa_offset
:
506 case DW_CFA_GNU_args_size
:
507 case DW_CFA_def_cfa_offset_sf
:
508 return dw_cfi_oprnd_offset
;
510 case DW_CFA_def_cfa_expression
:
511 return dw_cfi_oprnd_loc
;
518 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
520 enum dw_cfi_oprnd_type
521 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
526 case DW_CFA_def_cfa_sf
:
528 case DW_CFA_offset_extended_sf
:
529 case DW_CFA_offset_extended
:
530 return dw_cfi_oprnd_offset
;
532 case DW_CFA_register
:
533 return dw_cfi_oprnd_reg_num
;
535 case DW_CFA_expression
:
536 return dw_cfi_oprnd_loc
;
539 return dw_cfi_oprnd_unused
;
543 /* Output one FDE. */
546 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
547 char *section_start_label
, int fde_encoding
, char *augmentation
,
548 bool any_lsda_needed
, int lsda_encoding
)
550 const char *begin
, *end
;
551 static unsigned int j
;
554 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
556 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
558 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
559 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
560 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
561 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
562 " indicating 64-bit DWARF extension");
563 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
565 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
568 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
570 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
571 debug_frame_section
, "FDE CIE offset");
573 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
574 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
578 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
579 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
580 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
581 "FDE initial location");
582 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
583 end
, begin
, "FDE address range");
587 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
588 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
595 int size
= size_of_encoded_value (lsda_encoding
);
597 if (lsda_encoding
== DW_EH_PE_aligned
)
599 int offset
= ( 4 /* Length */
601 + 2 * size_of_encoded_value (fde_encoding
)
602 + 1 /* Augmentation size */ );
603 int pad
= -offset
& (PTR_SIZE
- 1);
606 gcc_assert (size_of_uleb128 (size
) == 1);
609 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
611 if (fde
->uses_eh_lsda
)
613 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
614 fde
->funcdef_number
);
615 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
616 gen_rtx_SYMBOL_REF (Pmode
, l1
),
618 "Language Specific Data Area");
622 if (lsda_encoding
== DW_EH_PE_aligned
)
623 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
624 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
625 "Language Specific Data Area (none)");
629 dw2_asm_output_data_uleb128 (0, "Augmentation size");
632 /* Loop through the Call Frame Instructions associated with this FDE. */
633 fde
->dw_fde_current_label
= begin
;
635 size_t from
, until
, i
;
638 until
= vec_safe_length (fde
->dw_fde_cfi
);
640 if (fde
->dw_fde_second_begin
== NULL
)
643 until
= fde
->dw_fde_switch_cfi_index
;
645 from
= fde
->dw_fde_switch_cfi_index
;
647 for (i
= from
; i
< until
; i
++)
648 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
651 /* If we are to emit a ref/link from function bodies to their frame tables,
652 do it now. This is typically performed to make sure that tables
653 associated with functions are dragged with them and not discarded in
654 garbage collecting links. We need to do this on a per function basis to
655 cope with -ffunction-sections. */
657 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
658 /* Switch to the function section, emit the ref to the tables, and
659 switch *back* into the table section. */
660 switch_to_section (function_section (fde
->decl
));
661 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
662 switch_to_frame_table_section (for_eh
, true);
665 /* Pad the FDE out to an address sized boundary. */
666 ASM_OUTPUT_ALIGN (asm_out_file
,
667 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
668 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
673 /* Return true if frame description entry FDE is needed for EH. */
676 fde_needed_for_eh_p (dw_fde_ref fde
)
678 if (flag_asynchronous_unwind_tables
)
681 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
684 if (fde
->uses_eh_lsda
)
687 /* If exceptions are enabled, we have collected nothrow info. */
688 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
694 /* Output the call frame information used to record information
695 that relates to calculating the frame pointer, and records the
696 location of saved registers. */
699 output_call_frame_info (int for_eh
)
704 char l1
[20], l2
[20], section_start_label
[20];
705 bool any_lsda_needed
= false;
706 char augmentation
[6];
707 int augmentation_size
;
708 int fde_encoding
= DW_EH_PE_absptr
;
709 int per_encoding
= DW_EH_PE_absptr
;
710 int lsda_encoding
= DW_EH_PE_absptr
;
712 rtx personality
= NULL
;
715 /* Don't emit a CIE if there won't be any FDEs. */
719 /* Nothing to do if the assembler's doing it all. */
720 if (dwarf2out_do_cfi_asm ())
723 /* If we don't have any functions we'll want to unwind out of, don't emit
724 any EH unwind information. If we make FDEs linkonce, we may have to
725 emit an empty label for an FDE that wouldn't otherwise be emitted. We
726 want to avoid having an FDE kept around when the function it refers to
727 is discarded. Example where this matters: a primary function template
728 in C++ requires EH information, an explicit specialization doesn't. */
731 bool any_eh_needed
= false;
733 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
735 if (fde
->uses_eh_lsda
)
736 any_eh_needed
= any_lsda_needed
= true;
737 else if (fde_needed_for_eh_p (fde
))
738 any_eh_needed
= true;
739 else if (TARGET_USES_WEAK_UNWIND_INFO
)
740 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
747 /* We're going to be generating comments, so turn on app. */
751 /* Switch to the proper frame section, first time. */
752 switch_to_frame_table_section (for_eh
, false);
754 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
755 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
757 /* Output the CIE. */
758 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
759 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
760 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
761 dw2_asm_output_data (4, 0xffffffff,
762 "Initial length escape value indicating 64-bit DWARF extension");
763 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
764 "Length of Common Information Entry");
765 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
767 /* Now that the CIE pointer is PC-relative for EH,
768 use 0 to identify the CIE. */
769 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
770 (for_eh
? 0 : DWARF_CIE_ID
),
771 "CIE Identifier Tag");
773 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
774 use CIE version 1, unless that would produce incorrect results
775 due to overflowing the return register column. */
776 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
778 if (return_reg
>= 256 || dwarf_version
> 2)
780 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
783 augmentation_size
= 0;
785 personality
= current_unit_personality
;
791 z Indicates that a uleb128 is present to size the
792 augmentation section.
793 L Indicates the encoding (and thus presence) of
794 an LSDA pointer in the FDE augmentation.
795 R Indicates a non-default pointer encoding for
797 P Indicates the presence of an encoding + language
798 personality routine in the CIE augmentation. */
800 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
801 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
802 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
804 p
= augmentation
+ 1;
808 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
809 assemble_external_libcall (personality
);
814 augmentation_size
+= 1;
816 if (fde_encoding
!= DW_EH_PE_absptr
)
819 augmentation_size
+= 1;
821 if (p
> augmentation
+ 1)
823 augmentation
[0] = 'z';
827 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
828 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
830 int offset
= ( 4 /* Length */
832 + 1 /* CIE version */
833 + strlen (augmentation
) + 1 /* Augmentation */
834 + size_of_uleb128 (1) /* Code alignment */
835 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
837 + 1 /* Augmentation size */
838 + 1 /* Personality encoding */ );
839 int pad
= -offset
& (PTR_SIZE
- 1);
841 augmentation_size
+= pad
;
843 /* Augmentations should be small, so there's scarce need to
844 iterate for a solution. Die if we exceed one uleb128 byte. */
845 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
849 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
850 if (dw_cie_version
>= 4)
852 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
853 dw2_asm_output_data (1, 0, "CIE Segment Size");
855 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
856 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
857 "CIE Data Alignment Factor");
859 if (dw_cie_version
== 1)
860 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
862 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
866 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
869 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
870 eh_data_format_name (per_encoding
));
871 dw2_asm_output_encoded_addr_rtx (per_encoding
,
877 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
878 eh_data_format_name (lsda_encoding
));
880 if (fde_encoding
!= DW_EH_PE_absptr
)
881 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
882 eh_data_format_name (fde_encoding
));
885 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
886 output_cfi (cfi
, NULL
, for_eh
);
888 /* Pad the CIE out to an address sized boundary. */
889 ASM_OUTPUT_ALIGN (asm_out_file
,
890 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
891 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
893 /* Loop through all of the FDE's. */
894 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
898 /* Don't emit EH unwind info for leaf functions that don't need it. */
899 if (for_eh
&& !fde_needed_for_eh_p (fde
))
902 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
903 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
904 augmentation
, any_lsda_needed
, lsda_encoding
);
907 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
908 dw2_asm_output_data (4, 0, "End of Table");
910 /* Turn off app to make assembly quicker. */
915 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
918 dwarf2out_do_cfi_startproc (bool second
)
922 rtx personality
= get_personality_function (current_function_decl
);
924 fprintf (asm_out_file
, "\t.cfi_startproc\n");
928 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
931 /* ??? The GAS support isn't entirely consistent. We have to
932 handle indirect support ourselves, but PC-relative is done
933 in the assembler. Further, the assembler can't handle any
934 of the weirder relocation types. */
935 if (enc
& DW_EH_PE_indirect
)
936 ref
= dw2_force_const_mem (ref
, true);
938 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
939 output_addr_const (asm_out_file
, ref
);
940 fputc ('\n', asm_out_file
);
943 if (crtl
->uses_eh_lsda
)
947 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
948 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
949 current_function_funcdef_no
);
950 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
951 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
953 if (enc
& DW_EH_PE_indirect
)
954 ref
= dw2_force_const_mem (ref
, true);
956 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
957 output_addr_const (asm_out_file
, ref
);
958 fputc ('\n', asm_out_file
);
962 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
963 this allocation may be done before pass_final. */
966 dwarf2out_alloc_current_fde (void)
970 fde
= ggc_alloc_cleared_dw_fde_node ();
971 fde
->decl
= current_function_decl
;
972 fde
->funcdef_number
= current_function_funcdef_no
;
973 fde
->fde_index
= vec_safe_length (fde_vec
);
974 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
975 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
976 fde
->nothrow
= crtl
->nothrow
;
977 fde
->drap_reg
= INVALID_REGNUM
;
978 fde
->vdrap_reg
= INVALID_REGNUM
;
980 /* Record the FDE associated with this function. */
982 vec_safe_push (fde_vec
, fde
);
987 /* Output a marker (i.e. a label) for the beginning of a function, before
991 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
992 const char *file ATTRIBUTE_UNUSED
)
994 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1000 current_function_func_begin_label
= NULL
;
1002 do_frame
= dwarf2out_do_frame ();
1004 /* ??? current_function_func_begin_label is also used by except.c for
1005 call-site information. We must emit this label if it might be used. */
1007 && (!flag_exceptions
1008 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1011 fnsec
= function_section (current_function_decl
);
1012 switch_to_section (fnsec
);
1013 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1014 current_function_funcdef_no
);
1015 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1016 current_function_funcdef_no
);
1017 dup_label
= xstrdup (label
);
1018 current_function_func_begin_label
= dup_label
;
1020 /* We can elide the fde allocation if we're not emitting debug info. */
1024 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1025 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1026 would include pass_dwarf2_frame. If we've not created the FDE yet,
1030 fde
= dwarf2out_alloc_current_fde ();
1032 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1033 fde
->dw_fde_begin
= dup_label
;
1034 fde
->dw_fde_current_label
= dup_label
;
1035 fde
->in_std_section
= (fnsec
== text_section
1036 || (cold_text_section
&& fnsec
== cold_text_section
));
1038 /* We only want to output line number information for the genuine dwarf2
1039 prologue case, not the eh frame case. */
1040 #ifdef DWARF2_DEBUGGING_INFO
1042 dwarf2out_source_line (line
, file
, 0, true);
1045 if (dwarf2out_do_cfi_asm ())
1046 dwarf2out_do_cfi_startproc (false);
1049 rtx personality
= get_personality_function (current_function_decl
);
1050 if (!current_unit_personality
)
1051 current_unit_personality
= personality
;
1053 /* We cannot keep a current personality per function as without CFI
1054 asm, at the point where we emit the CFI data, there is no current
1055 function anymore. */
1056 if (personality
&& current_unit_personality
!= personality
)
1057 sorry ("multiple EH personalities are supported only with assemblers "
1058 "supporting .cfi_personality directive");
1062 /* Output a marker (i.e. a label) for the end of the generated code
1063 for a function prologue. This gets called *after* the prologue code has
1067 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1068 const char *file ATTRIBUTE_UNUSED
)
1070 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1072 /* Output a label to mark the endpoint of the code generated for this
1074 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1075 current_function_funcdef_no
);
1076 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1077 current_function_funcdef_no
);
1078 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1081 /* Output a marker (i.e. a label) for the beginning of the generated code
1082 for a function epilogue. This gets called *before* the prologue code has
1086 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1087 const char *file ATTRIBUTE_UNUSED
)
1089 dw_fde_ref fde
= cfun
->fde
;
1090 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1092 if (fde
->dw_fde_vms_begin_epilogue
)
1095 /* Output a label to mark the endpoint of the code generated for this
1097 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1098 current_function_funcdef_no
);
1099 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1100 current_function_funcdef_no
);
1101 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1104 /* Output a marker (i.e. a label) for the absolute end of the generated code
1105 for a function definition. This gets called *after* the epilogue code has
1109 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1110 const char *file ATTRIBUTE_UNUSED
)
1113 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1115 last_var_location_insn
= NULL_RTX
;
1116 cached_next_real_insn
= NULL_RTX
;
1118 if (dwarf2out_do_cfi_asm ())
1119 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1121 /* Output a label to mark the endpoint of the code generated for this
1123 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1124 current_function_funcdef_no
);
1125 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1127 gcc_assert (fde
!= NULL
);
1128 if (fde
->dw_fde_second_begin
== NULL
)
1129 fde
->dw_fde_end
= xstrdup (label
);
1133 dwarf2out_frame_finish (void)
1135 /* Output call frame information. */
1136 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1137 output_call_frame_info (0);
1139 /* Output another copy for the unwinder. */
1140 if ((flag_unwind_tables
|| flag_exceptions
)
1141 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1142 output_call_frame_info (1);
1145 /* Note that the current function section is being used for code. */
1148 dwarf2out_note_section_used (void)
1150 section
*sec
= current_function_section ();
1151 if (sec
== text_section
)
1152 text_section_used
= true;
1153 else if (sec
== cold_text_section
)
1154 cold_text_section_used
= true;
1157 static void var_location_switch_text_section (void);
1158 static void set_cur_line_info_table (section
*);
1161 dwarf2out_switch_text_section (void)
1164 dw_fde_ref fde
= cfun
->fde
;
1166 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1168 if (!in_cold_section_p
)
1170 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1171 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1172 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1176 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1177 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1178 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1180 have_multiple_function_sections
= true;
1182 /* There is no need to mark used sections when not debugging. */
1183 if (cold_text_section
!= NULL
)
1184 dwarf2out_note_section_used ();
1186 if (dwarf2out_do_cfi_asm ())
1187 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1189 /* Now do the real section switch. */
1190 sect
= current_function_section ();
1191 switch_to_section (sect
);
1193 fde
->second_in_std_section
1194 = (sect
== text_section
1195 || (cold_text_section
&& sect
== cold_text_section
));
1197 if (dwarf2out_do_cfi_asm ())
1198 dwarf2out_do_cfi_startproc (true);
1200 var_location_switch_text_section ();
1202 if (cold_text_section
!= NULL
)
1203 set_cur_line_info_table (sect
);
1206 /* And now, the subset of the debugging information support code necessary
1207 for emitting location expressions. */
1209 /* Data about a single source file. */
1210 struct GTY(()) dwarf_file_data
{
1211 const char * filename
;
1215 typedef struct GTY(()) deferred_locations_struct
1219 } deferred_locations
;
1222 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1225 /* Describe an entry into the .debug_addr section. */
1229 ate_kind_rtx_dtprel
,
1233 typedef struct GTY(()) addr_table_entry_struct
{
1235 unsigned int refcount
;
1237 union addr_table_entry_struct_union
1239 rtx
GTY ((tag ("0"))) rtl
;
1240 char * GTY ((tag ("1"))) label
;
1242 GTY ((desc ("%1.kind"))) addr
;
1246 /* Location lists are ranges + location descriptions for that range,
1247 so you can track variables that are in different places over
1248 their entire life. */
1249 typedef struct GTY(()) dw_loc_list_struct
{
1250 dw_loc_list_ref dw_loc_next
;
1251 const char *begin
; /* Label and addr_entry for start of range */
1252 addr_table_entry
*begin_entry
;
1253 const char *end
; /* Label for end of range */
1254 char *ll_symbol
; /* Label for beginning of location list.
1255 Only on head of list */
1256 const char *section
; /* Section this loclist is relative to */
1257 dw_loc_descr_ref expr
;
1259 /* True if all addresses in this and subsequent lists are known to be
1262 /* True if this list has been replaced by dw_loc_next. */
1265 /* True if the range should be emitted even if begin and end
1270 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1272 /* Convert a DWARF stack opcode into its string name. */
1275 dwarf_stack_op_name (unsigned int op
)
1277 const char *name
= get_DW_OP_name (op
);
1282 return "OP_<unknown>";
1285 /* Return a pointer to a newly allocated location description. Location
1286 descriptions are simple expression terms that can be strung
1287 together to form more complicated location (address) descriptions. */
1289 static inline dw_loc_descr_ref
1290 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1291 unsigned HOST_WIDE_INT oprnd2
)
1293 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1295 descr
->dw_loc_opc
= op
;
1296 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1297 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1298 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1299 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1300 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1301 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1306 /* Return a pointer to a newly allocated location description for
1309 static inline dw_loc_descr_ref
1310 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1313 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1316 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1319 /* Add a location description term to a location description expression. */
1322 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1324 dw_loc_descr_ref
*d
;
1326 /* Find the end of the chain. */
1327 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1333 /* Compare two location operands for exact equality. */
1336 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1338 if (a
->val_class
!= b
->val_class
)
1340 switch (a
->val_class
)
1342 case dw_val_class_none
:
1344 case dw_val_class_addr
:
1345 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1347 case dw_val_class_offset
:
1348 case dw_val_class_unsigned_const
:
1349 case dw_val_class_const
:
1350 case dw_val_class_range_list
:
1351 case dw_val_class_lineptr
:
1352 case dw_val_class_macptr
:
1353 /* These are all HOST_WIDE_INT, signed or unsigned. */
1354 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1356 case dw_val_class_loc
:
1357 return a
->v
.val_loc
== b
->v
.val_loc
;
1358 case dw_val_class_loc_list
:
1359 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1360 case dw_val_class_die_ref
:
1361 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1362 case dw_val_class_fde_ref
:
1363 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1364 case dw_val_class_lbl_id
:
1365 case dw_val_class_high_pc
:
1366 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1367 case dw_val_class_str
:
1368 return a
->v
.val_str
== b
->v
.val_str
;
1369 case dw_val_class_flag
:
1370 return a
->v
.val_flag
== b
->v
.val_flag
;
1371 case dw_val_class_file
:
1372 return a
->v
.val_file
== b
->v
.val_file
;
1373 case dw_val_class_decl_ref
:
1374 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1376 case dw_val_class_const_double
:
1377 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1378 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1380 case dw_val_class_vec
:
1382 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1383 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1385 return (a_len
== b_len
1386 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1389 case dw_val_class_data8
:
1390 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1392 case dw_val_class_vms_delta
:
1393 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1394 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1399 /* Compare two location atoms for exact equality. */
1402 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1404 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1407 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1408 address size, but since we always allocate cleared storage it
1409 should be zero for other types of locations. */
1410 if (a
->dtprel
!= b
->dtprel
)
1413 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1414 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1417 /* Compare two complete location expressions for exact equality. */
1420 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1426 if (a
== NULL
|| b
== NULL
)
1428 if (!loc_descr_equal_p_1 (a
, b
))
1437 /* Add a constant OFFSET to a location expression. */
1440 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1442 dw_loc_descr_ref loc
;
1445 gcc_assert (*list_head
!= NULL
);
1450 /* Find the end of the chain. */
1451 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1455 if (loc
->dw_loc_opc
== DW_OP_fbreg
1456 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1457 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1458 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1459 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1461 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1462 offset. Don't optimize if an signed integer overflow would happen. */
1464 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1465 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1468 else if (offset
> 0)
1469 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1473 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1474 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1478 /* Add a constant OFFSET to a location list. */
1481 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1484 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1485 loc_descr_plus_const (&d
->expr
, offset
);
1488 #define DWARF_REF_SIZE \
1489 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1491 static unsigned long int get_base_type_offset (dw_die_ref
);
1493 /* Return the size of a location descriptor. */
1495 static unsigned long
1496 size_of_loc_descr (dw_loc_descr_ref loc
)
1498 unsigned long size
= 1;
1500 switch (loc
->dw_loc_opc
)
1503 size
+= DWARF2_ADDR_SIZE
;
1505 case DW_OP_GNU_addr_index
:
1506 case DW_OP_GNU_const_index
:
1507 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1508 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1527 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1530 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1535 case DW_OP_plus_uconst
:
1536 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1574 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1577 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1580 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1583 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1584 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1587 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1589 case DW_OP_bit_piece
:
1590 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1591 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1593 case DW_OP_deref_size
:
1594 case DW_OP_xderef_size
:
1603 case DW_OP_call_ref
:
1604 size
+= DWARF_REF_SIZE
;
1606 case DW_OP_implicit_value
:
1607 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1608 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1610 case DW_OP_GNU_implicit_pointer
:
1611 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1613 case DW_OP_GNU_entry_value
:
1615 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1616 size
+= size_of_uleb128 (op_size
) + op_size
;
1619 case DW_OP_GNU_const_type
:
1622 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1623 size
+= size_of_uleb128 (o
) + 1;
1624 switch (loc
->dw_loc_oprnd2
.val_class
)
1626 case dw_val_class_vec
:
1627 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1628 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1630 case dw_val_class_const
:
1631 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1633 case dw_val_class_const_double
:
1634 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1641 case DW_OP_GNU_regval_type
:
1644 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1645 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1646 + size_of_uleb128 (o
);
1649 case DW_OP_GNU_deref_type
:
1652 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1653 size
+= 1 + size_of_uleb128 (o
);
1656 case DW_OP_GNU_convert
:
1657 case DW_OP_GNU_reinterpret
:
1658 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1659 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1663 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1664 size
+= size_of_uleb128 (o
);
1667 case DW_OP_GNU_parameter_ref
:
1677 /* Return the size of a series of location descriptors. */
1680 size_of_locs (dw_loc_descr_ref loc
)
1685 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1686 field, to avoid writing to a PCH file. */
1687 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1689 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1691 size
+= size_of_loc_descr (l
);
1696 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1698 l
->dw_loc_addr
= size
;
1699 size
+= size_of_loc_descr (l
);
1705 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1706 static void get_ref_die_offset_label (char *, dw_die_ref
);
1707 static unsigned long int get_ref_die_offset (dw_die_ref
);
1709 /* Output location description stack opcode's operands (if any).
1710 The for_eh_or_skip parameter controls whether register numbers are
1711 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1712 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1713 info). This should be suppressed for the cases that have not been converted
1714 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1717 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1719 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1720 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1722 switch (loc
->dw_loc_opc
)
1724 #ifdef DWARF2_DEBUGGING_INFO
1727 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1732 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1733 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1735 fputc ('\n', asm_out_file
);
1740 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1745 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1746 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1748 fputc ('\n', asm_out_file
);
1753 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1754 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1761 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1762 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1764 dw2_asm_output_data (2, offset
, NULL
);
1767 case DW_OP_implicit_value
:
1768 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1769 switch (val2
->val_class
)
1771 case dw_val_class_const
:
1772 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1774 case dw_val_class_vec
:
1776 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1777 unsigned int len
= val2
->v
.val_vec
.length
;
1781 if (elt_size
> sizeof (HOST_WIDE_INT
))
1786 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1789 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1790 "fp or vector constant word %u", i
);
1793 case dw_val_class_const_double
:
1795 unsigned HOST_WIDE_INT first
, second
;
1797 if (WORDS_BIG_ENDIAN
)
1799 first
= val2
->v
.val_double
.high
;
1800 second
= val2
->v
.val_double
.low
;
1804 first
= val2
->v
.val_double
.low
;
1805 second
= val2
->v
.val_double
.high
;
1807 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1809 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1813 case dw_val_class_addr
:
1814 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1815 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1830 case DW_OP_implicit_value
:
1831 /* We currently don't make any attempt to make sure these are
1832 aligned properly like we do for the main unwind info, so
1833 don't support emitting things larger than a byte if we're
1834 only doing unwinding. */
1839 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1842 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1845 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1848 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1850 case DW_OP_plus_uconst
:
1851 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1885 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1889 unsigned r
= val1
->v
.val_unsigned
;
1890 if (for_eh_or_skip
>= 0)
1891 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1892 gcc_assert (size_of_uleb128 (r
)
1893 == size_of_uleb128 (val1
->v
.val_unsigned
));
1894 dw2_asm_output_data_uleb128 (r
, NULL
);
1898 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1902 unsigned r
= val1
->v
.val_unsigned
;
1903 if (for_eh_or_skip
>= 0)
1904 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1905 gcc_assert (size_of_uleb128 (r
)
1906 == size_of_uleb128 (val1
->v
.val_unsigned
));
1907 dw2_asm_output_data_uleb128 (r
, NULL
);
1908 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1912 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1914 case DW_OP_bit_piece
:
1915 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1916 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1918 case DW_OP_deref_size
:
1919 case DW_OP_xderef_size
:
1920 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1926 if (targetm
.asm_out
.output_dwarf_dtprel
)
1928 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1931 fputc ('\n', asm_out_file
);
1938 #ifdef DWARF2_DEBUGGING_INFO
1939 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1946 case DW_OP_GNU_addr_index
:
1947 case DW_OP_GNU_const_index
:
1948 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1949 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1950 "(index into .debug_addr)");
1953 case DW_OP_GNU_implicit_pointer
:
1955 char label
[MAX_ARTIFICIAL_LABEL_BYTES
1956 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
1957 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
1958 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
1959 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
1960 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1964 case DW_OP_GNU_entry_value
:
1965 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
1966 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
1969 case DW_OP_GNU_const_type
:
1971 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
1973 dw2_asm_output_data_uleb128 (o
, NULL
);
1974 switch (val2
->val_class
)
1976 case dw_val_class_const
:
1977 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
1978 dw2_asm_output_data (1, l
, NULL
);
1979 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
1981 case dw_val_class_vec
:
1983 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1984 unsigned int len
= val2
->v
.val_vec
.length
;
1989 dw2_asm_output_data (1, l
, NULL
);
1990 if (elt_size
> sizeof (HOST_WIDE_INT
))
1995 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1998 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1999 "fp or vector constant word %u", i
);
2002 case dw_val_class_const_double
:
2004 unsigned HOST_WIDE_INT first
, second
;
2005 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2007 dw2_asm_output_data (1, 2 * l
, NULL
);
2008 if (WORDS_BIG_ENDIAN
)
2010 first
= val2
->v
.val_double
.high
;
2011 second
= val2
->v
.val_double
.low
;
2015 first
= val2
->v
.val_double
.low
;
2016 second
= val2
->v
.val_double
.high
;
2018 dw2_asm_output_data (l
, first
, NULL
);
2019 dw2_asm_output_data (l
, second
, NULL
);
2027 case DW_OP_GNU_regval_type
:
2029 unsigned r
= val1
->v
.val_unsigned
;
2030 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2032 if (for_eh_or_skip
>= 0)
2034 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2035 gcc_assert (size_of_uleb128 (r
)
2036 == size_of_uleb128 (val1
->v
.val_unsigned
));
2038 dw2_asm_output_data_uleb128 (r
, NULL
);
2039 dw2_asm_output_data_uleb128 (o
, NULL
);
2042 case DW_OP_GNU_deref_type
:
2044 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2046 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2047 dw2_asm_output_data_uleb128 (o
, NULL
);
2050 case DW_OP_GNU_convert
:
2051 case DW_OP_GNU_reinterpret
:
2052 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2053 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2056 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2058 dw2_asm_output_data_uleb128 (o
, NULL
);
2062 case DW_OP_GNU_parameter_ref
:
2065 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2066 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2067 dw2_asm_output_data (4, o
, NULL
);
2072 /* Other codes have no operands. */
2077 /* Output a sequence of location operations.
2078 The for_eh_or_skip parameter controls whether register numbers are
2079 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2080 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2081 info). This should be suppressed for the cases that have not been converted
2082 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2085 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2087 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2089 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2090 /* Output the opcode. */
2091 if (for_eh_or_skip
>= 0
2092 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2094 unsigned r
= (opc
- DW_OP_breg0
);
2095 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2096 gcc_assert (r
<= 31);
2097 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2099 else if (for_eh_or_skip
>= 0
2100 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2102 unsigned r
= (opc
- DW_OP_reg0
);
2103 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2104 gcc_assert (r
<= 31);
2105 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2108 dw2_asm_output_data (1, opc
,
2109 "%s", dwarf_stack_op_name (opc
));
2111 /* Output the operand(s) (if any). */
2112 output_loc_operands (loc
, for_eh_or_skip
);
2116 /* Output location description stack opcode's operands (if any).
2117 The output is single bytes on a line, suitable for .cfi_escape. */
2120 output_loc_operands_raw (dw_loc_descr_ref loc
)
2122 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2123 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2125 switch (loc
->dw_loc_opc
)
2128 case DW_OP_GNU_addr_index
:
2129 case DW_OP_GNU_const_index
:
2130 case DW_OP_implicit_value
:
2131 /* We cannot output addresses in .cfi_escape, only bytes. */
2137 case DW_OP_deref_size
:
2138 case DW_OP_xderef_size
:
2139 fputc (',', asm_out_file
);
2140 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2145 fputc (',', asm_out_file
);
2146 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2151 fputc (',', asm_out_file
);
2152 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2157 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2158 fputc (',', asm_out_file
);
2159 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2167 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2168 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2170 fputc (',', asm_out_file
);
2171 dw2_asm_output_data_raw (2, offset
);
2177 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2178 gcc_assert (size_of_uleb128 (r
)
2179 == size_of_uleb128 (val1
->v
.val_unsigned
));
2180 fputc (',', asm_out_file
);
2181 dw2_asm_output_data_uleb128_raw (r
);
2186 case DW_OP_plus_uconst
:
2188 fputc (',', asm_out_file
);
2189 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2192 case DW_OP_bit_piece
:
2193 fputc (',', asm_out_file
);
2194 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2195 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2232 fputc (',', asm_out_file
);
2233 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2238 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2239 gcc_assert (size_of_uleb128 (r
)
2240 == size_of_uleb128 (val1
->v
.val_unsigned
));
2241 fputc (',', asm_out_file
);
2242 dw2_asm_output_data_uleb128_raw (r
);
2243 fputc (',', asm_out_file
);
2244 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2248 case DW_OP_GNU_implicit_pointer
:
2249 case DW_OP_GNU_entry_value
:
2250 case DW_OP_GNU_const_type
:
2251 case DW_OP_GNU_regval_type
:
2252 case DW_OP_GNU_deref_type
:
2253 case DW_OP_GNU_convert
:
2254 case DW_OP_GNU_reinterpret
:
2255 case DW_OP_GNU_parameter_ref
:
2260 /* Other codes have no operands. */
2266 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2270 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2271 /* Output the opcode. */
2272 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2274 unsigned r
= (opc
- DW_OP_breg0
);
2275 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2276 gcc_assert (r
<= 31);
2277 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2279 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2281 unsigned r
= (opc
- DW_OP_reg0
);
2282 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2283 gcc_assert (r
<= 31);
2284 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2286 /* Output the opcode. */
2287 fprintf (asm_out_file
, "%#x", opc
);
2288 output_loc_operands_raw (loc
);
2290 if (!loc
->dw_loc_next
)
2292 loc
= loc
->dw_loc_next
;
2294 fputc (',', asm_out_file
);
2298 /* This function builds a dwarf location descriptor sequence from a
2299 dw_cfa_location, adding the given OFFSET to the result of the
2302 struct dw_loc_descr_struct
*
2303 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2305 struct dw_loc_descr_struct
*head
, *tmp
;
2307 offset
+= cfa
->offset
;
2311 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2312 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2313 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2314 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2315 add_loc_descr (&head
, tmp
);
2318 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2319 add_loc_descr (&head
, tmp
);
2323 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2328 /* This function builds a dwarf location descriptor sequence for
2329 the address at OFFSET from the CFA when stack is aligned to
2332 struct dw_loc_descr_struct
*
2333 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2334 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2336 struct dw_loc_descr_struct
*head
;
2337 unsigned int dwarf_fp
2338 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2340 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2341 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2343 head
= new_reg_loc_descr (dwarf_fp
, 0);
2344 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2345 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2346 loc_descr_plus_const (&head
, offset
);
2349 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2353 /* And now, the support for symbolic debugging information. */
2355 /* .debug_str support. */
2356 static int output_indirect_string (void **, void *);
2358 static void dwarf2out_init (const char *);
2359 static void dwarf2out_finish (const char *);
2360 static void dwarf2out_assembly_start (void);
2361 static void dwarf2out_define (unsigned int, const char *);
2362 static void dwarf2out_undef (unsigned int, const char *);
2363 static void dwarf2out_start_source_file (unsigned, const char *);
2364 static void dwarf2out_end_source_file (unsigned);
2365 static void dwarf2out_function_decl (tree
);
2366 static void dwarf2out_begin_block (unsigned, unsigned);
2367 static void dwarf2out_end_block (unsigned, unsigned);
2368 static bool dwarf2out_ignore_block (const_tree
);
2369 static void dwarf2out_global_decl (tree
);
2370 static void dwarf2out_type_decl (tree
, int);
2371 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2372 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2374 static void dwarf2out_abstract_function (tree
);
2375 static void dwarf2out_var_location (rtx
);
2376 static void dwarf2out_begin_function (tree
);
2377 static void dwarf2out_end_function (unsigned int);
2378 static void dwarf2out_set_name (tree
, tree
);
2380 /* The debug hooks structure. */
2382 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2386 dwarf2out_assembly_start
,
2389 dwarf2out_start_source_file
,
2390 dwarf2out_end_source_file
,
2391 dwarf2out_begin_block
,
2392 dwarf2out_end_block
,
2393 dwarf2out_ignore_block
,
2394 dwarf2out_source_line
,
2395 dwarf2out_begin_prologue
,
2396 #if VMS_DEBUGGING_INFO
2397 dwarf2out_vms_end_prologue
,
2398 dwarf2out_vms_begin_epilogue
,
2400 debug_nothing_int_charstar
,
2401 debug_nothing_int_charstar
,
2403 dwarf2out_end_epilogue
,
2404 dwarf2out_begin_function
,
2405 dwarf2out_end_function
, /* end_function */
2406 dwarf2out_function_decl
, /* function_decl */
2407 dwarf2out_global_decl
,
2408 dwarf2out_type_decl
, /* type_decl */
2409 dwarf2out_imported_module_or_decl
,
2410 debug_nothing_tree
, /* deferred_inline_function */
2411 /* The DWARF 2 backend tries to reduce debugging bloat by not
2412 emitting the abstract description of inline functions until
2413 something tries to reference them. */
2414 dwarf2out_abstract_function
, /* outlining_inline_function */
2415 debug_nothing_rtx
, /* label */
2416 debug_nothing_int
, /* handle_pch */
2417 dwarf2out_var_location
,
2418 dwarf2out_switch_text_section
,
2420 1, /* start_end_main_source_file */
2421 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2424 /* NOTE: In the comments in this file, many references are made to
2425 "Debugging Information Entries". This term is abbreviated as `DIE'
2426 throughout the remainder of this file. */
2428 /* An internal representation of the DWARF output is built, and then
2429 walked to generate the DWARF debugging info. The walk of the internal
2430 representation is done after the entire program has been compiled.
2431 The types below are used to describe the internal representation. */
2433 /* Whether to put type DIEs into their own section .debug_types instead
2434 of making them part of the .debug_info section. Only supported for
2435 Dwarf V4 or higher and the user didn't disable them through
2436 -fno-debug-types-section. It is more efficient to put them in a
2437 separate comdat sections since the linker will then be able to
2438 remove duplicates. But not all tools support .debug_types sections
2441 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2443 /* Various DIE's use offsets relative to the beginning of the
2444 .debug_info section to refer to each other. */
2446 typedef long int dw_offset
;
2448 /* Define typedefs here to avoid circular dependencies. */
2450 typedef struct dw_attr_struct
*dw_attr_ref
;
2451 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2452 typedef struct pubname_struct
*pubname_ref
;
2453 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2454 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2455 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2457 /* The entries in the line_info table more-or-less mirror the opcodes
2458 that are used in the real dwarf line table. Arrays of these entries
2459 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2462 enum dw_line_info_opcode
{
2463 /* Emit DW_LNE_set_address; the operand is the label index. */
2466 /* Emit a row to the matrix with the given line. This may be done
2467 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2471 /* Emit a DW_LNS_set_file. */
2474 /* Emit a DW_LNS_set_column. */
2477 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2480 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2481 LI_set_prologue_end
,
2482 LI_set_epilogue_begin
,
2484 /* Emit a DW_LNE_set_discriminator. */
2485 LI_set_discriminator
2488 typedef struct GTY(()) dw_line_info_struct
{
2489 enum dw_line_info_opcode opcode
;
2491 } dw_line_info_entry
;
2494 typedef struct GTY(()) dw_line_info_table_struct
{
2495 /* The label that marks the end of this section. */
2496 const char *end_label
;
2498 /* The values for the last row of the matrix, as collected in the table.
2499 These are used to minimize the changes to the next row. */
2500 unsigned int file_num
;
2501 unsigned int line_num
;
2502 unsigned int column_num
;
2507 vec
<dw_line_info_entry
, va_gc
> *entries
;
2508 } dw_line_info_table
;
2510 typedef dw_line_info_table
*dw_line_info_table_p
;
2513 /* Each DIE attribute has a field specifying the attribute kind,
2514 a link to the next attribute in the chain, and an attribute value.
2515 Attributes are typically linked below the DIE they modify. */
2517 typedef struct GTY(()) dw_attr_struct
{
2518 enum dwarf_attribute dw_attr
;
2519 dw_val_node dw_attr_val
;
2524 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2525 The children of each node form a circular list linked by
2526 die_sib. die_child points to the node *before* the "first" child node. */
2528 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2529 union die_symbol_or_type_node
2531 const char * GTY ((tag ("0"))) die_symbol
;
2532 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2534 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2535 vec
<dw_attr_node
, va_gc
> *die_attr
;
2536 dw_die_ref die_parent
;
2537 dw_die_ref die_child
;
2539 dw_die_ref die_definition
; /* ref from a specification to its definition */
2540 dw_offset die_offset
;
2541 unsigned long die_abbrev
;
2543 unsigned int decl_id
;
2544 enum dwarf_tag die_tag
;
2545 /* Die is used and must not be pruned as unused. */
2546 BOOL_BITFIELD die_perennial_p
: 1;
2547 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2548 /* Lots of spare bits. */
2552 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2553 #define FOR_EACH_CHILD(die, c, expr) do { \
2554 c = die->die_child; \
2558 } while (c != die->die_child); \
2561 /* The pubname structure */
2563 typedef struct GTY(()) pubname_struct
{
2570 struct GTY(()) dw_ranges_struct
{
2571 /* If this is positive, it's a block number, otherwise it's a
2572 bitwise-negated index into dw_ranges_by_label. */
2576 /* A structure to hold a macinfo entry. */
2578 typedef struct GTY(()) macinfo_struct
{
2580 unsigned HOST_WIDE_INT lineno
;
2586 struct GTY(()) dw_ranges_by_label_struct
{
2591 /* The comdat type node structure. */
2592 typedef struct GTY(()) comdat_type_struct
2594 dw_die_ref root_die
;
2595 dw_die_ref type_die
;
2596 dw_die_ref skeleton_die
;
2597 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2598 struct comdat_type_struct
*next
;
2602 /* The limbo die list structure. */
2603 typedef struct GTY(()) limbo_die_struct
{
2606 struct limbo_die_struct
*next
;
2610 typedef struct skeleton_chain_struct
2614 struct skeleton_chain_struct
*parent
;
2616 skeleton_chain_node
;
2618 /* Define a macro which returns nonzero for a TYPE_DECL which was
2619 implicitly generated for a type.
2621 Note that, unlike the C front-end (which generates a NULL named
2622 TYPE_DECL node for each complete tagged type, each array type,
2623 and each function type node created) the C++ front-end generates
2624 a _named_ TYPE_DECL node for each tagged type node created.
2625 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2626 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2627 front-end, but for each type, tagged or not. */
2629 #define TYPE_DECL_IS_STUB(decl) \
2630 (DECL_NAME (decl) == NULL_TREE \
2631 || (DECL_ARTIFICIAL (decl) \
2632 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2633 /* This is necessary for stub decls that \
2634 appear in nested inline functions. */ \
2635 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2636 && (decl_ultimate_origin (decl) \
2637 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2639 /* Information concerning the compilation unit's programming
2640 language, and compiler version. */
2642 /* Fixed size portion of the DWARF compilation unit header. */
2643 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2644 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2646 /* Fixed size portion of the DWARF comdat type unit header. */
2647 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2648 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2649 + DWARF_OFFSET_SIZE)
2651 /* Fixed size portion of public names info. */
2652 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2654 /* Fixed size portion of the address range info. */
2655 #define DWARF_ARANGES_HEADER_SIZE \
2656 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2657 DWARF2_ADDR_SIZE * 2) \
2658 - DWARF_INITIAL_LENGTH_SIZE)
2660 /* Size of padding portion in the address range info. It must be
2661 aligned to twice the pointer size. */
2662 #define DWARF_ARANGES_PAD_SIZE \
2663 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2664 DWARF2_ADDR_SIZE * 2) \
2665 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2667 /* Use assembler line directives if available. */
2668 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2669 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2670 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2672 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2676 /* Minimum line offset in a special line info. opcode.
2677 This value was chosen to give a reasonable range of values. */
2678 #define DWARF_LINE_BASE -10
2680 /* First special line opcode - leave room for the standard opcodes. */
2681 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2683 /* Range of line offsets in a special line info. opcode. */
2684 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2686 /* Flag that indicates the initial value of the is_stmt_start flag.
2687 In the present implementation, we do not mark any lines as
2688 the beginning of a source statement, because that information
2689 is not made available by the GCC front-end. */
2690 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2692 /* Maximum number of operations per instruction bundle. */
2693 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2694 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2697 /* This location is used by calc_die_sizes() to keep track
2698 the offset of each DIE within the .debug_info section. */
2699 static unsigned long next_die_offset
;
2701 /* Record the root of the DIE's built for the current compilation unit. */
2702 static GTY(()) dw_die_ref single_comp_unit_die
;
2704 /* A list of type DIEs that have been separated into comdat sections. */
2705 static GTY(()) comdat_type_node
*comdat_type_list
;
2707 /* A list of DIEs with a NULL parent waiting to be relocated. */
2708 static GTY(()) limbo_die_node
*limbo_die_list
;
2710 /* A list of DIEs for which we may have to generate
2711 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2712 static GTY(()) limbo_die_node
*deferred_asm_name
;
2714 /* Filenames referenced by this compilation unit. */
2715 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2717 /* A hash table of references to DIE's that describe declarations.
2718 The key is a DECL_UID() which is a unique number identifying each decl. */
2719 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2721 /* A hash table of references to DIE's that describe COMMON blocks.
2722 The key is DECL_UID() ^ die_parent. */
2723 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2725 typedef struct GTY(()) die_arg_entry_struct
{
2731 /* Node of the variable location list. */
2732 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2733 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2734 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2735 in mode of the EXPR_LIST node and first EXPR_LIST operand
2736 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2737 location or NULL for padding. For larger bitsizes,
2738 mode is 0 and first operand is a CONCAT with bitsize
2739 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2740 NULL as second operand. */
2742 const char * GTY (()) label
;
2743 struct var_loc_node
* GTY (()) next
;
2746 /* Variable location list. */
2747 struct GTY (()) var_loc_list_def
{
2748 struct var_loc_node
* GTY (()) first
;
2750 /* Pointer to the last but one or last element of the
2751 chained list. If the list is empty, both first and
2752 last are NULL, if the list contains just one node
2753 or the last node certainly is not redundant, it points
2754 to the last node, otherwise points to the last but one.
2755 Do not mark it for GC because it is marked through the chain. */
2756 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2758 /* Pointer to the last element before section switch,
2759 if NULL, either sections weren't switched or first
2760 is after section switch. */
2761 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2763 /* DECL_UID of the variable decl. */
2764 unsigned int decl_id
;
2766 typedef struct var_loc_list_def var_loc_list
;
2768 /* Call argument location list. */
2769 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2770 rtx
GTY (()) call_arg_loc_note
;
2771 const char * GTY (()) label
;
2772 tree
GTY (()) block
;
2774 rtx
GTY (()) symbol_ref
;
2775 struct call_arg_loc_node
* GTY (()) next
;
2779 /* Table of decl location linked lists. */
2780 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2782 /* Head and tail of call_arg_loc chain. */
2783 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2784 static struct call_arg_loc_node
*call_arg_loc_last
;
2786 /* Number of call sites in the current function. */
2787 static int call_site_count
= -1;
2788 /* Number of tail call sites in the current function. */
2789 static int tail_call_site_count
= -1;
2791 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2793 static vec
<dw_die_ref
> block_map
;
2795 /* A cached location list. */
2796 struct GTY (()) cached_dw_loc_list_def
{
2797 /* The DECL_UID of the decl that this entry describes. */
2798 unsigned int decl_id
;
2800 /* The cached location list. */
2801 dw_loc_list_ref loc_list
;
2803 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2805 /* Table of cached location lists. */
2806 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2808 /* A pointer to the base of a list of references to DIE's that
2809 are uniquely identified by their tag, presence/absence of
2810 children DIE's, and list of attribute/value pairs. */
2811 static GTY((length ("abbrev_die_table_allocated")))
2812 dw_die_ref
*abbrev_die_table
;
2814 /* Number of elements currently allocated for abbrev_die_table. */
2815 static GTY(()) unsigned abbrev_die_table_allocated
;
2817 /* Number of elements in type_die_table currently in use. */
2818 static GTY(()) unsigned abbrev_die_table_in_use
;
2820 /* Size (in elements) of increments by which we may expand the
2821 abbrev_die_table. */
2822 #define ABBREV_DIE_TABLE_INCREMENT 256
2824 /* A global counter for generating labels for line number data. */
2825 static unsigned int line_info_label_num
;
2827 /* The current table to which we should emit line number information
2828 for the current function. This will be set up at the beginning of
2829 assembly for the function. */
2830 static dw_line_info_table
*cur_line_info_table
;
2832 /* The two default tables of line number info. */
2833 static GTY(()) dw_line_info_table
*text_section_line_info
;
2834 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2836 /* The set of all non-default tables of line number info. */
2837 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2839 /* A flag to tell pubnames/types export if there is an info section to
2841 static bool info_section_emitted
;
2843 /* A pointer to the base of a table that contains a list of publicly
2844 accessible names. */
2845 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2847 /* A pointer to the base of a table that contains a list of publicly
2848 accessible types. */
2849 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2851 /* A pointer to the base of a table that contains a list of macro
2852 defines/undefines (and file start/end markers). */
2853 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2855 /* True if .debug_macinfo or .debug_macros section is going to be
2857 #define have_macinfo \
2858 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2859 && !macinfo_table->is_empty ())
2861 /* Array of dies for which we should generate .debug_ranges info. */
2862 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2864 /* Number of elements currently allocated for ranges_table. */
2865 static GTY(()) unsigned ranges_table_allocated
;
2867 /* Number of elements in ranges_table currently in use. */
2868 static GTY(()) unsigned ranges_table_in_use
;
2870 /* Array of pairs of labels referenced in ranges_table. */
2871 static GTY ((length ("ranges_by_label_allocated")))
2872 dw_ranges_by_label_ref ranges_by_label
;
2874 /* Number of elements currently allocated for ranges_by_label. */
2875 static GTY(()) unsigned ranges_by_label_allocated
;
2877 /* Number of elements in ranges_by_label currently in use. */
2878 static GTY(()) unsigned ranges_by_label_in_use
;
2880 /* Size (in elements) of increments by which we may expand the
2882 #define RANGES_TABLE_INCREMENT 64
2884 /* Whether we have location lists that need outputting */
2885 static GTY(()) bool have_location_lists
;
2887 /* Unique label counter. */
2888 static GTY(()) unsigned int loclabel_num
;
2890 /* Unique label counter for point-of-call tables. */
2891 static GTY(()) unsigned int poc_label_num
;
2893 /* Record whether the function being analyzed contains inlined functions. */
2894 static int current_function_has_inlines
;
2896 /* The last file entry emitted by maybe_emit_file(). */
2897 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2899 /* Number of internal labels generated by gen_internal_sym(). */
2900 static GTY(()) int label_num
;
2902 /* Cached result of previous call to lookup_filename. */
2903 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2905 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2907 /* Instances of generic types for which we need to generate debug
2908 info that describe their generic parameters and arguments. That
2909 generation needs to happen once all types are properly laid out so
2910 we do it at the end of compilation. */
2911 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2913 /* Offset from the "steady-state frame pointer" to the frame base,
2914 within the current function. */
2915 static HOST_WIDE_INT frame_pointer_fb_offset
;
2916 static bool frame_pointer_fb_offset_valid
;
2918 static vec
<dw_die_ref
> base_types
;
2920 /* Forward declarations for functions defined in this file. */
2922 static int is_pseudo_reg (const_rtx
);
2923 static tree
type_main_variant (tree
);
2924 static int is_tagged_type (const_tree
);
2925 static const char *dwarf_tag_name (unsigned);
2926 static const char *dwarf_attr_name (unsigned);
2927 static const char *dwarf_form_name (unsigned);
2928 static tree
decl_ultimate_origin (const_tree
);
2929 static tree
decl_class_context (tree
);
2930 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2931 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2932 static inline unsigned int AT_index (dw_attr_ref
);
2933 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2934 static inline unsigned AT_flag (dw_attr_ref
);
2935 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2936 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2937 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2938 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
2939 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
2940 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
2941 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
2942 unsigned int, unsigned char *);
2943 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
2944 static hashval_t
debug_str_do_hash (const void *);
2945 static int debug_str_eq (const void *, const void *);
2946 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
2947 static inline const char *AT_string (dw_attr_ref
);
2948 static enum dwarf_form
AT_string_form (dw_attr_ref
);
2949 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
2950 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
2951 static inline dw_die_ref
AT_ref (dw_attr_ref
);
2952 static inline int AT_ref_external (dw_attr_ref
);
2953 static inline void set_AT_ref_external (dw_attr_ref
, int);
2954 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
2955 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
2956 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
2957 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
2959 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
2960 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
2961 static void remove_addr_table_entry (addr_table_entry
*);
2962 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
2963 static inline rtx
AT_addr (dw_attr_ref
);
2964 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
2965 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2966 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
2967 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
2968 unsigned HOST_WIDE_INT
);
2969 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
2970 unsigned long, bool);
2971 static inline const char *AT_lbl (dw_attr_ref
);
2972 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
2973 static const char *get_AT_low_pc (dw_die_ref
);
2974 static const char *get_AT_hi_pc (dw_die_ref
);
2975 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
2976 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
2977 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
2978 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
2979 static bool is_cxx (void);
2980 static bool is_fortran (void);
2981 static bool is_ada (void);
2982 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
2983 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
2984 static void add_child_die (dw_die_ref
, dw_die_ref
);
2985 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
2986 static dw_die_ref
lookup_type_die (tree
);
2987 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
2988 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
2989 static void equate_type_number_to_die (tree
, dw_die_ref
);
2990 static hashval_t
decl_die_table_hash (const void *);
2991 static int decl_die_table_eq (const void *, const void *);
2992 static dw_die_ref
lookup_decl_die (tree
);
2993 static hashval_t
common_block_die_table_hash (const void *);
2994 static int common_block_die_table_eq (const void *, const void *);
2995 static hashval_t
decl_loc_table_hash (const void *);
2996 static int decl_loc_table_eq (const void *, const void *);
2997 static var_loc_list
*lookup_decl_loc (const_tree
);
2998 static void equate_decl_number_to_die (tree
, dw_die_ref
);
2999 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3000 static void print_spaces (FILE *);
3001 static void print_die (dw_die_ref
, FILE *);
3002 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3003 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3004 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3005 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3006 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3007 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3008 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3009 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3010 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3011 struct md5_ctx
*, int *);
3012 struct checksum_attributes
;
3013 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3014 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3015 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3016 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3017 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3018 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3019 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3020 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3021 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3022 static void compute_section_prefix (dw_die_ref
);
3023 static int is_type_die (dw_die_ref
);
3024 static int is_comdat_die (dw_die_ref
);
3025 static int is_symbol_die (dw_die_ref
);
3026 static void assign_symbol_names (dw_die_ref
);
3027 static void break_out_includes (dw_die_ref
);
3028 static int is_declaration_die (dw_die_ref
);
3029 static int should_move_die_to_comdat (dw_die_ref
);
3030 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3031 static dw_die_ref
clone_die (dw_die_ref
);
3032 static dw_die_ref
clone_tree (dw_die_ref
);
3033 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3034 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3035 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3036 static dw_die_ref
generate_skeleton (dw_die_ref
);
3037 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3040 static void break_out_comdat_types (dw_die_ref
);
3041 static void copy_decls_for_unworthy_types (dw_die_ref
);
3043 static void add_sibling_attributes (dw_die_ref
);
3044 static void output_location_lists (dw_die_ref
);
3045 static int constant_size (unsigned HOST_WIDE_INT
);
3046 static unsigned long size_of_die (dw_die_ref
);
3047 static void calc_die_sizes (dw_die_ref
);
3048 static void calc_base_type_die_sizes (void);
3049 static void mark_dies (dw_die_ref
);
3050 static void unmark_dies (dw_die_ref
);
3051 static void unmark_all_dies (dw_die_ref
);
3052 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3053 static unsigned long size_of_aranges (void);
3054 static enum dwarf_form
value_format (dw_attr_ref
);
3055 static void output_value_format (dw_attr_ref
);
3056 static void output_abbrev_section (void);
3057 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3058 static void output_die_symbol (dw_die_ref
);
3059 static void output_die (dw_die_ref
);
3060 static void output_compilation_unit_header (void);
3061 static void output_comp_unit (dw_die_ref
, int);
3062 static void output_comdat_type_unit (comdat_type_node
*);
3063 static const char *dwarf2_name (tree
, int);
3064 static void add_pubname (tree
, dw_die_ref
);
3065 static void add_enumerator_pubname (const char *, dw_die_ref
);
3066 static void add_pubname_string (const char *, dw_die_ref
);
3067 static void add_pubtype (tree
, dw_die_ref
);
3068 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3069 static void output_aranges (unsigned long);
3070 static unsigned int add_ranges_num (int);
3071 static unsigned int add_ranges (const_tree
);
3072 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3074 static void output_ranges (void);
3075 static dw_line_info_table
*new_line_info_table (void);
3076 static void output_line_info (bool);
3077 static void output_file_names (void);
3078 static dw_die_ref
base_type_die (tree
);
3079 static int is_base_type (tree
);
3080 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3081 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3082 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3083 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3084 static int type_is_enum (const_tree
);
3085 static unsigned int dbx_reg_number (const_rtx
);
3086 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3087 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3088 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3089 enum var_init_status
);
3090 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3091 enum var_init_status
);
3092 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3093 enum var_init_status
);
3094 static int is_based_loc (const_rtx
);
3095 static int resolve_one_addr (rtx
*, void *);
3096 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3097 enum var_init_status
);
3098 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3099 enum var_init_status
);
3100 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3101 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3102 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3103 static tree
field_type (const_tree
);
3104 static unsigned int simple_type_align_in_bits (const_tree
);
3105 static unsigned int simple_decl_align_in_bits (const_tree
);
3106 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3107 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3108 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3110 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3111 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3112 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3113 static void insert_double (double_int
, unsigned char *);
3114 static void insert_float (const_rtx
, unsigned char *);
3115 static rtx
rtl_for_decl_location (tree
);
3116 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3117 enum dwarf_attribute
);
3118 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3119 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3120 static void add_name_attribute (dw_die_ref
, const char *);
3121 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3122 static void add_comp_dir_attribute (dw_die_ref
);
3123 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3124 static void add_subscript_info (dw_die_ref
, tree
, bool);
3125 static void add_byte_size_attribute (dw_die_ref
, tree
);
3126 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3127 static void add_bit_size_attribute (dw_die_ref
, tree
);
3128 static void add_prototyped_attribute (dw_die_ref
, tree
);
3129 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3130 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3131 static void add_src_coords_attributes (dw_die_ref
, tree
);
3132 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3133 static void push_decl_scope (tree
);
3134 static void pop_decl_scope (void);
3135 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3136 static inline int local_scope_p (dw_die_ref
);
3137 static inline int class_scope_p (dw_die_ref
);
3138 static inline int class_or_namespace_scope_p (dw_die_ref
);
3139 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3140 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3141 static const char *type_tag (const_tree
);
3142 static tree
member_declared_type (const_tree
);
3144 static const char *decl_start_label (tree
);
3146 static void gen_array_type_die (tree
, dw_die_ref
);
3147 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3149 static void gen_entry_point_die (tree
, dw_die_ref
);
3151 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3152 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3153 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3154 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3155 static void gen_formal_types_die (tree
, dw_die_ref
);
3156 static void gen_subprogram_die (tree
, dw_die_ref
);
3157 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3158 static void gen_const_die (tree
, dw_die_ref
);
3159 static void gen_label_die (tree
, dw_die_ref
);
3160 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3161 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3162 static void gen_field_die (tree
, dw_die_ref
);
3163 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3164 static dw_die_ref
gen_compile_unit_die (const char *);
3165 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3166 static void gen_member_die (tree
, dw_die_ref
);
3167 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3168 enum debug_info_usage
);
3169 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3170 static void gen_typedef_die (tree
, dw_die_ref
);
3171 static void gen_type_die (tree
, dw_die_ref
);
3172 static void gen_block_die (tree
, dw_die_ref
, int);
3173 static void decls_for_scope (tree
, dw_die_ref
, int);
3174 static inline int is_redundant_typedef (const_tree
);
3175 static bool is_naming_typedef_decl (const_tree
);
3176 static inline dw_die_ref
get_context_die (tree
);
3177 static void gen_namespace_die (tree
, dw_die_ref
);
3178 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3179 static dw_die_ref
force_decl_die (tree
);
3180 static dw_die_ref
force_type_die (tree
);
3181 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3182 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3183 static struct dwarf_file_data
* lookup_filename (const char *);
3184 static void retry_incomplete_types (void);
3185 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3186 static void gen_generic_params_dies (tree
);
3187 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3188 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3189 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3190 static int file_info_cmp (const void *, const void *);
3191 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3192 const char *, const char *);
3193 static void output_loc_list (dw_loc_list_ref
);
3194 static char *gen_internal_sym (const char *);
3195 static bool want_pubnames (void);
3197 static void prune_unmark_dies (dw_die_ref
);
3198 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3199 static void prune_unused_types_mark (dw_die_ref
, int);
3200 static void prune_unused_types_walk (dw_die_ref
);
3201 static void prune_unused_types_walk_attribs (dw_die_ref
);
3202 static void prune_unused_types_prune (dw_die_ref
);
3203 static void prune_unused_types (void);
3204 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3205 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3206 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3207 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3208 const char *, const char *);
3209 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3210 static void gen_remaining_tmpl_value_param_die_attribute (void);
3211 static bool generic_type_p (tree
);
3212 static void schedule_generic_params_dies_gen (tree t
);
3213 static void gen_scheduled_generic_parms_dies (void);
3215 static const char *comp_dir_string (void);
3217 /* enum for tracking thread-local variables whose address is really an offset
3218 relative to the TLS pointer, which will need link-time relocation, but will
3219 not need relocation by the DWARF consumer. */
3227 /* Return the operator to use for an address of a variable. For dtprel_true, we
3228 use DW_OP_const*. For regular variables, which need both link-time
3229 relocation and consumer-level relocation (e.g., to account for shared objects
3230 loaded at a random address), we use DW_OP_addr*. */
3232 static inline enum dwarf_location_atom
3233 dw_addr_op (enum dtprel_bool dtprel
)
3235 if (dtprel
== dtprel_true
)
3236 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3237 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3239 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3242 /* Return a pointer to a newly allocated address location description. If
3243 dwarf_split_debug_info is true, then record the address with the appropriate
3245 static inline dw_loc_descr_ref
3246 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3248 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3250 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3251 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3252 ref
->dtprel
= dtprel
;
3253 if (dwarf_split_debug_info
)
3254 ref
->dw_loc_oprnd1
.val_entry
3255 = add_addr_table_entry (addr
,
3256 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3258 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3263 /* Section names used to hold DWARF debugging information. */
3265 #ifndef DEBUG_INFO_SECTION
3266 #define DEBUG_INFO_SECTION ".debug_info"
3268 #ifndef DEBUG_DWO_INFO_SECTION
3269 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3271 #ifndef DEBUG_ABBREV_SECTION
3272 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3274 #ifndef DEBUG_DWO_ABBREV_SECTION
3275 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3277 #ifndef DEBUG_ARANGES_SECTION
3278 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3280 #ifndef DEBUG_ADDR_SECTION
3281 #define DEBUG_ADDR_SECTION ".debug_addr"
3283 #ifndef DEBUG_NORM_MACINFO_SECTION
3284 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3286 #ifndef DEBUG_DWO_MACINFO_SECTION
3287 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3289 #ifndef DEBUG_MACINFO_SECTION
3290 #define DEBUG_MACINFO_SECTION \
3291 (!dwarf_split_debug_info \
3292 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3294 #ifndef DEBUG_NORM_MACRO_SECTION
3295 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3297 #ifndef DEBUG_DWO_MACRO_SECTION
3298 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3300 #ifndef DEBUG_MACRO_SECTION
3301 #define DEBUG_MACRO_SECTION \
3302 (!dwarf_split_debug_info \
3303 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3305 #ifndef DEBUG_LINE_SECTION
3306 #define DEBUG_LINE_SECTION ".debug_line"
3308 #ifndef DEBUG_DWO_LINE_SECTION
3309 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3311 #ifndef DEBUG_LOC_SECTION
3312 #define DEBUG_LOC_SECTION ".debug_loc"
3314 #ifndef DEBUG_DWO_LOC_SECTION
3315 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3317 #ifndef DEBUG_PUBNAMES_SECTION
3318 #define DEBUG_PUBNAMES_SECTION ".debug_pubnames"
3320 #ifndef DEBUG_PUBTYPES_SECTION
3321 #define DEBUG_PUBTYPES_SECTION ".debug_pubtypes"
3323 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3324 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3325 #ifndef DEBUG_STR_OFFSETS_SECTION
3326 #define DEBUG_STR_OFFSETS_SECTION \
3327 (!dwarf_split_debug_info \
3328 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3330 #ifndef DEBUG_STR_DWO_SECTION
3331 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3333 #ifndef DEBUG_STR_SECTION
3334 #define DEBUG_STR_SECTION ".debug_str"
3336 #ifndef DEBUG_RANGES_SECTION
3337 #define DEBUG_RANGES_SECTION ".debug_ranges"
3340 /* Standard ELF section names for compiled code and data. */
3341 #ifndef TEXT_SECTION_NAME
3342 #define TEXT_SECTION_NAME ".text"
3345 /* Section flags for .debug_macinfo/.debug_macro section. */
3346 #define DEBUG_MACRO_SECTION_FLAGS \
3347 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3349 /* Section flags for .debug_str section. */
3350 #define DEBUG_STR_SECTION_FLAGS \
3351 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3352 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3355 /* Section flags for .debug_str.dwo section. */
3356 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3358 /* Labels we insert at beginning sections we can reference instead of
3359 the section names themselves. */
3361 #ifndef TEXT_SECTION_LABEL
3362 #define TEXT_SECTION_LABEL "Ltext"
3364 #ifndef COLD_TEXT_SECTION_LABEL
3365 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3367 #ifndef DEBUG_LINE_SECTION_LABEL
3368 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3370 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3371 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3373 #ifndef DEBUG_INFO_SECTION_LABEL
3374 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3376 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3377 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3379 #ifndef DEBUG_ABBREV_SECTION_LABEL
3380 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3382 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3383 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3385 #ifndef DEBUG_ADDR_SECTION_LABEL
3386 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3388 #ifndef DEBUG_LOC_SECTION_LABEL
3389 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3391 #ifndef DEBUG_RANGES_SECTION_LABEL
3392 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3394 #ifndef DEBUG_MACINFO_SECTION_LABEL
3395 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3397 #ifndef DEBUG_MACRO_SECTION_LABEL
3398 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3400 #define SKELETON_COMP_DIE_ABBREV 1
3401 #define SKELETON_TYPE_DIE_ABBREV 2
3403 /* Definitions of defaults for formats and names of various special
3404 (artificial) labels which may be generated within this file (when the -g
3405 options is used and DWARF2_DEBUGGING_INFO is in effect.
3406 If necessary, these may be overridden from within the tm.h file, but
3407 typically, overriding these defaults is unnecessary. */
3409 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3410 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3411 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3412 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3413 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3414 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3415 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3416 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3417 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3418 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3419 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3420 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3421 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3422 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3424 #ifndef TEXT_END_LABEL
3425 #define TEXT_END_LABEL "Letext"
3427 #ifndef COLD_END_LABEL
3428 #define COLD_END_LABEL "Letext_cold"
3430 #ifndef BLOCK_BEGIN_LABEL
3431 #define BLOCK_BEGIN_LABEL "LBB"
3433 #ifndef BLOCK_END_LABEL
3434 #define BLOCK_END_LABEL "LBE"
3436 #ifndef LINE_CODE_LABEL
3437 #define LINE_CODE_LABEL "LM"
3441 /* Return the root of the DIE's built for the current compilation unit. */
3443 comp_unit_die (void)
3445 if (!single_comp_unit_die
)
3446 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3447 return single_comp_unit_die
;
3450 /* We allow a language front-end to designate a function that is to be
3451 called to "demangle" any name before it is put into a DIE. */
3453 static const char *(*demangle_name_func
) (const char *);
3456 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3458 demangle_name_func
= func
;
3461 /* Test if rtl node points to a pseudo register. */
3464 is_pseudo_reg (const_rtx rtl
)
3466 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3467 || (GET_CODE (rtl
) == SUBREG
3468 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3471 /* Return a reference to a type, with its const and volatile qualifiers
3475 type_main_variant (tree type
)
3477 type
= TYPE_MAIN_VARIANT (type
);
3479 /* ??? There really should be only one main variant among any group of
3480 variants of a given type (and all of the MAIN_VARIANT values for all
3481 members of the group should point to that one type) but sometimes the C
3482 front-end messes this up for array types, so we work around that bug
3484 if (TREE_CODE (type
) == ARRAY_TYPE
)
3485 while (type
!= TYPE_MAIN_VARIANT (type
))
3486 type
= TYPE_MAIN_VARIANT (type
);
3491 /* Return nonzero if the given type node represents a tagged type. */
3494 is_tagged_type (const_tree type
)
3496 enum tree_code code
= TREE_CODE (type
);
3498 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3499 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3502 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3505 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3507 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3510 /* Return die_offset of a DIE reference to a base type. */
3512 static unsigned long int
3513 get_base_type_offset (dw_die_ref ref
)
3515 if (ref
->die_offset
)
3516 return ref
->die_offset
;
3517 if (comp_unit_die ()->die_abbrev
)
3519 calc_base_type_die_sizes ();
3520 gcc_assert (ref
->die_offset
);
3522 return ref
->die_offset
;
3525 /* Return die_offset of a DIE reference other than base type. */
3527 static unsigned long int
3528 get_ref_die_offset (dw_die_ref ref
)
3530 gcc_assert (ref
->die_offset
);
3531 return ref
->die_offset
;
3534 /* Convert a DIE tag into its string name. */
3537 dwarf_tag_name (unsigned int tag
)
3539 const char *name
= get_DW_TAG_name (tag
);
3544 return "DW_TAG_<unknown>";
3547 /* Convert a DWARF attribute code into its string name. */
3550 dwarf_attr_name (unsigned int attr
)
3556 #if VMS_DEBUGGING_INFO
3557 case DW_AT_HP_prologue
:
3558 return "DW_AT_HP_prologue";
3560 case DW_AT_MIPS_loop_unroll_factor
:
3561 return "DW_AT_MIPS_loop_unroll_factor";
3564 #if VMS_DEBUGGING_INFO
3565 case DW_AT_HP_epilogue
:
3566 return "DW_AT_HP_epilogue";
3568 case DW_AT_MIPS_stride
:
3569 return "DW_AT_MIPS_stride";
3573 name
= get_DW_AT_name (attr
);
3578 return "DW_AT_<unknown>";
3581 /* Convert a DWARF value form code into its string name. */
3584 dwarf_form_name (unsigned int form
)
3586 const char *name
= get_DW_FORM_name (form
);
3591 return "DW_FORM_<unknown>";
3594 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3595 instance of an inlined instance of a decl which is local to an inline
3596 function, so we have to trace all of the way back through the origin chain
3597 to find out what sort of node actually served as the original seed for the
3601 decl_ultimate_origin (const_tree decl
)
3603 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3606 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3607 nodes in the function to point to themselves; ignore that if
3608 we're trying to output the abstract instance of this function. */
3609 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3612 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3613 most distant ancestor, this should never happen. */
3614 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3616 return DECL_ABSTRACT_ORIGIN (decl
);
3619 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3620 of a virtual function may refer to a base class, so we check the 'this'
3624 decl_class_context (tree decl
)
3626 tree context
= NULL_TREE
;
3628 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3629 context
= DECL_CONTEXT (decl
);
3631 context
= TYPE_MAIN_VARIANT
3632 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3634 if (context
&& !TYPE_P (context
))
3635 context
= NULL_TREE
;
3640 /* Add an attribute/value pair to a DIE. */
3643 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3645 /* Maybe this should be an assert? */
3649 vec_safe_reserve (die
->die_attr
, 1);
3650 vec_safe_push (die
->die_attr
, *attr
);
3653 static inline enum dw_val_class
3654 AT_class (dw_attr_ref a
)
3656 return a
->dw_attr_val
.val_class
;
3659 /* Return the index for any attribute that will be referenced with a
3660 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3661 are stored in dw_attr_val.v.val_str for reference counting
3664 static inline unsigned int
3665 AT_index (dw_attr_ref a
)
3667 if (AT_class (a
) == dw_val_class_str
)
3668 return a
->dw_attr_val
.v
.val_str
->index
;
3669 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3670 return a
->dw_attr_val
.val_entry
->index
;
3674 /* Add a flag value attribute to a DIE. */
3677 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3681 attr
.dw_attr
= attr_kind
;
3682 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3683 attr
.dw_attr_val
.val_entry
= NULL
;
3684 attr
.dw_attr_val
.v
.val_flag
= flag
;
3685 add_dwarf_attr (die
, &attr
);
3688 static inline unsigned
3689 AT_flag (dw_attr_ref a
)
3691 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3692 return a
->dw_attr_val
.v
.val_flag
;
3695 /* Add a signed integer attribute value to a DIE. */
3698 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3702 attr
.dw_attr
= attr_kind
;
3703 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3704 attr
.dw_attr_val
.val_entry
= NULL
;
3705 attr
.dw_attr_val
.v
.val_int
= int_val
;
3706 add_dwarf_attr (die
, &attr
);
3709 static inline HOST_WIDE_INT
3710 AT_int (dw_attr_ref a
)
3712 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3713 return a
->dw_attr_val
.v
.val_int
;
3716 /* Add an unsigned integer attribute value to a DIE. */
3719 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3720 unsigned HOST_WIDE_INT unsigned_val
)
3724 attr
.dw_attr
= attr_kind
;
3725 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3726 attr
.dw_attr_val
.val_entry
= NULL
;
3727 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3728 add_dwarf_attr (die
, &attr
);
3731 static inline unsigned HOST_WIDE_INT
3732 AT_unsigned (dw_attr_ref a
)
3734 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3735 return a
->dw_attr_val
.v
.val_unsigned
;
3738 /* Add an unsigned double integer attribute value to a DIE. */
3741 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3742 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3746 attr
.dw_attr
= attr_kind
;
3747 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3748 attr
.dw_attr_val
.val_entry
= NULL
;
3749 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3750 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3751 add_dwarf_attr (die
, &attr
);
3754 /* Add a floating point attribute value to a DIE and return it. */
3757 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3758 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3762 attr
.dw_attr
= attr_kind
;
3763 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3764 attr
.dw_attr_val
.val_entry
= NULL
;
3765 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3766 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3767 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3768 add_dwarf_attr (die
, &attr
);
3771 /* Add an 8-byte data attribute value to a DIE. */
3774 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3775 unsigned char data8
[8])
3779 attr
.dw_attr
= attr_kind
;
3780 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3781 attr
.dw_attr_val
.val_entry
= NULL
;
3782 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3783 add_dwarf_attr (die
, &attr
);
3786 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3787 dwarf_split_debug_info, address attributes in dies destined for the
3788 final executable have force_direct set to avoid using indexed
3792 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3798 lbl_id
= xstrdup (lbl_low
);
3799 attr
.dw_attr
= DW_AT_low_pc
;
3800 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3801 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3802 if (dwarf_split_debug_info
&& !force_direct
)
3803 attr
.dw_attr_val
.val_entry
3804 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3806 attr
.dw_attr_val
.val_entry
= NULL
;
3807 add_dwarf_attr (die
, &attr
);
3809 attr
.dw_attr
= DW_AT_high_pc
;
3810 if (dwarf_version
< 4)
3811 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3813 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3814 lbl_id
= xstrdup (lbl_high
);
3815 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3816 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3817 && dwarf_split_debug_info
&& !force_direct
)
3818 attr
.dw_attr_val
.val_entry
3819 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3821 attr
.dw_attr_val
.val_entry
= NULL
;
3822 add_dwarf_attr (die
, &attr
);
3825 /* Hash and equality functions for debug_str_hash. */
3828 debug_str_do_hash (const void *x
)
3830 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3834 debug_str_eq (const void *x1
, const void *x2
)
3836 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3837 (const char *)x2
) == 0;
3840 /* Add STR to the given string hash table. */
3842 static struct indirect_string_node
*
3843 find_AT_string_in_table (const char *str
, htab_t table
)
3845 struct indirect_string_node
*node
;
3848 slot
= htab_find_slot_with_hash (table
, str
,
3849 htab_hash_string (str
), INSERT
);
3852 node
= ggc_alloc_cleared_indirect_string_node ();
3853 node
->str
= ggc_strdup (str
);
3857 node
= (struct indirect_string_node
*) *slot
;
3863 /* Add STR to the indirect string hash table. */
3865 static struct indirect_string_node
*
3866 find_AT_string (const char *str
)
3868 if (! debug_str_hash
)
3869 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3870 debug_str_eq
, NULL
);
3872 return find_AT_string_in_table (str
, debug_str_hash
);
3875 /* Add a string attribute value to a DIE. */
3878 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3881 struct indirect_string_node
*node
;
3883 node
= find_AT_string (str
);
3885 attr
.dw_attr
= attr_kind
;
3886 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3887 attr
.dw_attr_val
.val_entry
= NULL
;
3888 attr
.dw_attr_val
.v
.val_str
= node
;
3889 add_dwarf_attr (die
, &attr
);
3892 static inline const char *
3893 AT_string (dw_attr_ref a
)
3895 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3896 return a
->dw_attr_val
.v
.val_str
->str
;
3899 /* Call this function directly to bypass AT_string_form's logic to put
3900 the string inline in the die. */
3903 set_indirect_string (struct indirect_string_node
*node
)
3906 /* Already indirect is a no op. */
3907 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3909 gcc_assert (node
->label
);
3912 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3913 ++dw2_string_counter
;
3914 node
->label
= xstrdup (label
);
3916 if (!dwarf_split_debug_info
)
3918 node
->form
= DW_FORM_strp
;
3919 node
->index
= NOT_INDEXED
;
3923 node
->form
= DW_FORM_GNU_str_index
;
3924 node
->index
= NO_INDEX_ASSIGNED
;
3928 /* Find out whether a string should be output inline in DIE
3929 or out-of-line in .debug_str section. */
3931 static enum dwarf_form
3932 find_string_form (struct indirect_string_node
*node
)
3939 len
= strlen (node
->str
) + 1;
3941 /* If the string is shorter or equal to the size of the reference, it is
3942 always better to put it inline. */
3943 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
3944 return node
->form
= DW_FORM_string
;
3946 /* If we cannot expect the linker to merge strings in .debug_str
3947 section, only put it into .debug_str if it is worth even in this
3949 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
3950 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
3951 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
3952 return node
->form
= DW_FORM_string
;
3954 set_indirect_string (node
);
3959 /* Find out whether the string referenced from the attribute should be
3960 output inline in DIE or out-of-line in .debug_str section. */
3962 static enum dwarf_form
3963 AT_string_form (dw_attr_ref a
)
3965 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3966 return find_string_form (a
->dw_attr_val
.v
.val_str
);
3969 /* Add a DIE reference attribute value to a DIE. */
3972 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
3976 #ifdef ENABLE_CHECKING
3977 gcc_assert (targ_die
!= NULL
);
3979 /* With LTO we can end up trying to reference something we didn't create
3980 a DIE for. Avoid crashing later on a NULL referenced DIE. */
3981 if (targ_die
== NULL
)
3985 attr
.dw_attr
= attr_kind
;
3986 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
3987 attr
.dw_attr_val
.val_entry
= NULL
;
3988 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
3989 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
3990 add_dwarf_attr (die
, &attr
);
3993 /* Change DIE reference REF to point to NEW_DIE instead. */
3996 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
3998 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
3999 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4000 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4003 /* Add an AT_specification attribute to a DIE, and also make the back
4004 pointer from the specification to the definition. */
4007 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4009 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4010 gcc_assert (!targ_die
->die_definition
);
4011 targ_die
->die_definition
= die
;
4014 static inline dw_die_ref
4015 AT_ref (dw_attr_ref a
)
4017 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4018 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4022 AT_ref_external (dw_attr_ref a
)
4024 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4025 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4031 set_AT_ref_external (dw_attr_ref a
, int i
)
4033 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4034 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4037 /* Add an FDE reference attribute value to a DIE. */
4040 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4044 attr
.dw_attr
= attr_kind
;
4045 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4046 attr
.dw_attr_val
.val_entry
= NULL
;
4047 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4048 add_dwarf_attr (die
, &attr
);
4051 /* Add a location description attribute value to a DIE. */
4054 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4058 attr
.dw_attr
= attr_kind
;
4059 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4060 attr
.dw_attr_val
.val_entry
= NULL
;
4061 attr
.dw_attr_val
.v
.val_loc
= loc
;
4062 add_dwarf_attr (die
, &attr
);
4065 static inline dw_loc_descr_ref
4066 AT_loc (dw_attr_ref a
)
4068 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4069 return a
->dw_attr_val
.v
.val_loc
;
4073 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4077 attr
.dw_attr
= attr_kind
;
4078 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4079 attr
.dw_attr_val
.val_entry
= NULL
;
4080 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4081 add_dwarf_attr (die
, &attr
);
4082 have_location_lists
= true;
4085 static inline dw_loc_list_ref
4086 AT_loc_list (dw_attr_ref a
)
4088 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4089 return a
->dw_attr_val
.v
.val_loc_list
;
4092 static inline dw_loc_list_ref
*
4093 AT_loc_list_ptr (dw_attr_ref a
)
4095 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4096 return &a
->dw_attr_val
.v
.val_loc_list
;
4099 /* Table of entries into the .debug_addr section. */
4101 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4103 /* Hash an address_table_entry. */
4106 addr_table_entry_do_hash (const void *x
)
4108 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4112 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4113 case ate_kind_rtx_dtprel
:
4114 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4115 case ate_kind_label
:
4116 return htab_hash_string (a
->addr
.label
);
4122 /* Determine equality for two address_table_entries. */
4125 addr_table_entry_eq (const void *x1
, const void *x2
)
4127 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4128 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4130 if (a1
->kind
!= a2
->kind
)
4135 case ate_kind_rtx_dtprel
:
4136 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4137 case ate_kind_label
:
4138 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4144 /* Initialize an addr_table_entry. */
4147 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4153 case ate_kind_rtx_dtprel
:
4154 e
->addr
.rtl
= (rtx
) addr
;
4156 case ate_kind_label
:
4157 e
->addr
.label
= (char *) addr
;
4161 e
->index
= NO_INDEX_ASSIGNED
;
4164 /* Add attr to the address table entry to the table. Defer setting an
4165 index until output time. */
4167 static addr_table_entry
*
4168 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4170 addr_table_entry
*node
;
4171 addr_table_entry finder
;
4174 gcc_assert (dwarf_split_debug_info
);
4175 if (! addr_index_table
)
4176 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4177 addr_table_entry_eq
, NULL
);
4178 init_addr_table_entry (&finder
, kind
, addr
);
4179 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4181 if (*slot
== HTAB_EMPTY_ENTRY
)
4183 node
= ggc_alloc_cleared_addr_table_entry ();
4184 init_addr_table_entry (node
, kind
, addr
);
4188 node
= (addr_table_entry
*) *slot
;
4194 /* Remove an entry from the addr table by decrementing its refcount.
4195 Strictly, decrementing the refcount would be enough, but the
4196 assertion that the entry is actually in the table has found
4200 remove_addr_table_entry (addr_table_entry
*entry
)
4202 addr_table_entry
*node
;
4204 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4205 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4206 /* After an index is assigned, the table is frozen. */
4207 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4211 /* Given a location list, remove all addresses it refers to from the
4215 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4217 for (; descr
; descr
= descr
->dw_loc_next
)
4218 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4220 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4221 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4225 /* A helper function for dwarf2out_finish called through
4226 htab_traverse. Assign an addr_table_entry its index. All entries
4227 must be collected into the table when this function is called,
4228 because the indexing code relies on htab_traverse to traverse nodes
4229 in the same order for each run. */
4232 index_addr_table_entry (void **h
, void *v
)
4234 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4235 unsigned int *index
= (unsigned int *) v
;
4237 /* Don't index unreferenced nodes. */
4238 if (node
->refcount
== 0)
4241 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
4242 node
->index
= *index
;
4248 /* Add an address constant attribute value to a DIE. When using
4249 dwarf_split_debug_info, address attributes in dies destined for the
4250 final executable should be direct references--setting the parameter
4251 force_direct ensures this behavior. */
4254 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4259 attr
.dw_attr
= attr_kind
;
4260 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4261 attr
.dw_attr_val
.v
.val_addr
= addr
;
4262 if (dwarf_split_debug_info
&& !force_direct
)
4263 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4265 attr
.dw_attr_val
.val_entry
= NULL
;
4266 add_dwarf_attr (die
, &attr
);
4269 /* Get the RTX from to an address DIE attribute. */
4272 AT_addr (dw_attr_ref a
)
4274 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4275 return a
->dw_attr_val
.v
.val_addr
;
4278 /* Add a file attribute value to a DIE. */
4281 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4282 struct dwarf_file_data
*fd
)
4286 attr
.dw_attr
= attr_kind
;
4287 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4288 attr
.dw_attr_val
.val_entry
= NULL
;
4289 attr
.dw_attr_val
.v
.val_file
= fd
;
4290 add_dwarf_attr (die
, &attr
);
4293 /* Get the dwarf_file_data from a file DIE attribute. */
4295 static inline struct dwarf_file_data
*
4296 AT_file (dw_attr_ref a
)
4298 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4299 return a
->dw_attr_val
.v
.val_file
;
4302 /* Add a vms delta attribute value to a DIE. */
4305 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4306 const char *lbl1
, const char *lbl2
)
4310 attr
.dw_attr
= attr_kind
;
4311 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4312 attr
.dw_attr_val
.val_entry
= NULL
;
4313 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4314 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4315 add_dwarf_attr (die
, &attr
);
4318 /* Add a label identifier attribute value to a DIE. */
4321 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4326 attr
.dw_attr
= attr_kind
;
4327 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4328 attr
.dw_attr_val
.val_entry
= NULL
;
4329 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4330 if (dwarf_split_debug_info
)
4331 attr
.dw_attr_val
.val_entry
4332 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4334 add_dwarf_attr (die
, &attr
);
4337 /* Add a section offset attribute value to a DIE, an offset into the
4338 debug_line section. */
4341 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4346 attr
.dw_attr
= attr_kind
;
4347 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4348 attr
.dw_attr_val
.val_entry
= NULL
;
4349 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4350 add_dwarf_attr (die
, &attr
);
4353 /* Add a section offset attribute value to a DIE, an offset into the
4354 debug_macinfo section. */
4357 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4362 attr
.dw_attr
= attr_kind
;
4363 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4364 attr
.dw_attr_val
.val_entry
= NULL
;
4365 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4366 add_dwarf_attr (die
, &attr
);
4369 /* Add an offset attribute value to a DIE. */
4372 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4373 unsigned HOST_WIDE_INT offset
)
4377 attr
.dw_attr
= attr_kind
;
4378 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4379 attr
.dw_attr_val
.val_entry
= NULL
;
4380 attr
.dw_attr_val
.v
.val_offset
= offset
;
4381 add_dwarf_attr (die
, &attr
);
4384 /* Add a range_list attribute value to a DIE. When using
4385 dwarf_split_debug_info, address attributes in dies destined for the
4386 final executable should be direct references--setting the parameter
4387 force_direct ensures this behavior. */
4389 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4390 #define RELOCATED_OFFSET (NULL)
4393 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4394 long unsigned int offset
, bool force_direct
)
4398 attr
.dw_attr
= attr_kind
;
4399 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4400 /* For the range_list attribute, use val_entry to store whether the
4401 offset should follow split-debug-info or normal semantics. This
4402 value is read in output_range_list_offset. */
4403 if (dwarf_split_debug_info
&& !force_direct
)
4404 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4406 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4407 attr
.dw_attr_val
.v
.val_offset
= offset
;
4408 add_dwarf_attr (die
, &attr
);
4411 /* Return the start label of a delta attribute. */
4413 static inline const char *
4414 AT_vms_delta1 (dw_attr_ref a
)
4416 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4417 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4420 /* Return the end label of a delta attribute. */
4422 static inline const char *
4423 AT_vms_delta2 (dw_attr_ref a
)
4425 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4426 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4429 static inline const char *
4430 AT_lbl (dw_attr_ref a
)
4432 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4433 || AT_class (a
) == dw_val_class_lineptr
4434 || AT_class (a
) == dw_val_class_macptr
4435 || AT_class (a
) == dw_val_class_high_pc
));
4436 return a
->dw_attr_val
.v
.val_lbl_id
;
4439 /* Get the attribute of type attr_kind. */
4442 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4446 dw_die_ref spec
= NULL
;
4451 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4452 if (a
->dw_attr
== attr_kind
)
4454 else if (a
->dw_attr
== DW_AT_specification
4455 || a
->dw_attr
== DW_AT_abstract_origin
)
4459 return get_AT (spec
, attr_kind
);
4464 /* Returns the parent of the declaration of DIE. */
4467 get_die_parent (dw_die_ref die
)
4474 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4475 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4478 return die
->die_parent
;
4481 /* Return the "low pc" attribute value, typically associated with a subprogram
4482 DIE. Return null if the "low pc" attribute is either not present, or if it
4483 cannot be represented as an assembler label identifier. */
4485 static inline const char *
4486 get_AT_low_pc (dw_die_ref die
)
4488 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4490 return a
? AT_lbl (a
) : NULL
;
4493 /* Return the "high pc" attribute value, typically associated with a subprogram
4494 DIE. Return null if the "high pc" attribute is either not present, or if it
4495 cannot be represented as an assembler label identifier. */
4497 static inline const char *
4498 get_AT_hi_pc (dw_die_ref die
)
4500 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4502 return a
? AT_lbl (a
) : NULL
;
4505 /* Return the value of the string attribute designated by ATTR_KIND, or
4506 NULL if it is not present. */
4508 static inline const char *
4509 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4511 dw_attr_ref a
= get_AT (die
, attr_kind
);
4513 return a
? AT_string (a
) : NULL
;
4516 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4517 if it is not present. */
4520 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4522 dw_attr_ref a
= get_AT (die
, attr_kind
);
4524 return a
? AT_flag (a
) : 0;
4527 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4528 if it is not present. */
4530 static inline unsigned
4531 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4533 dw_attr_ref a
= get_AT (die
, attr_kind
);
4535 return a
? AT_unsigned (a
) : 0;
4538 static inline dw_die_ref
4539 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4541 dw_attr_ref a
= get_AT (die
, attr_kind
);
4543 return a
? AT_ref (a
) : NULL
;
4546 static inline struct dwarf_file_data
*
4547 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4549 dw_attr_ref a
= get_AT (die
, attr_kind
);
4551 return a
? AT_file (a
) : NULL
;
4554 /* Return TRUE if the language is C++. */
4559 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4561 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4564 /* Return TRUE if the language is Fortran. */
4569 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4571 return (lang
== DW_LANG_Fortran77
4572 || lang
== DW_LANG_Fortran90
4573 || lang
== DW_LANG_Fortran95
);
4576 /* Return TRUE if the language is Ada. */
4581 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4583 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4586 /* Remove the specified attribute if present. */
4589 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4597 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4598 if (a
->dw_attr
== attr_kind
)
4600 if (AT_class (a
) == dw_val_class_str
)
4601 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4602 a
->dw_attr_val
.v
.val_str
->refcount
--;
4604 /* vec::ordered_remove should help reduce the number of abbrevs
4606 die
->die_attr
->ordered_remove (ix
);
4611 /* Remove CHILD from its parent. PREV must have the property that
4612 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4615 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4617 gcc_assert (child
->die_parent
== prev
->die_parent
);
4618 gcc_assert (prev
->die_sib
== child
);
4621 gcc_assert (child
->die_parent
->die_child
== child
);
4625 prev
->die_sib
= child
->die_sib
;
4626 if (child
->die_parent
->die_child
== child
)
4627 child
->die_parent
->die_child
= prev
;
4630 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4631 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4634 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4636 dw_die_ref parent
= old_child
->die_parent
;
4638 gcc_assert (parent
== prev
->die_parent
);
4639 gcc_assert (prev
->die_sib
== old_child
);
4641 new_child
->die_parent
= parent
;
4642 if (prev
== old_child
)
4644 gcc_assert (parent
->die_child
== old_child
);
4645 new_child
->die_sib
= new_child
;
4649 prev
->die_sib
= new_child
;
4650 new_child
->die_sib
= old_child
->die_sib
;
4652 if (old_child
->die_parent
->die_child
== old_child
)
4653 old_child
->die_parent
->die_child
= new_child
;
4656 /* Move all children from OLD_PARENT to NEW_PARENT. */
4659 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4662 new_parent
->die_child
= old_parent
->die_child
;
4663 old_parent
->die_child
= NULL
;
4664 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4667 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4671 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4677 dw_die_ref prev
= c
;
4679 while (c
->die_tag
== tag
)
4681 remove_child_with_prev (c
, prev
);
4682 /* Might have removed every child. */
4683 if (c
== c
->die_sib
)
4687 } while (c
!= die
->die_child
);
4690 /* Add a CHILD_DIE as the last child of DIE. */
4693 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4695 /* FIXME this should probably be an assert. */
4696 if (! die
|| ! child_die
)
4698 gcc_assert (die
!= child_die
);
4700 child_die
->die_parent
= die
;
4703 child_die
->die_sib
= die
->die_child
->die_sib
;
4704 die
->die_child
->die_sib
= child_die
;
4707 child_die
->die_sib
= child_die
;
4708 die
->die_child
= child_die
;
4711 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4712 is the specification, to the end of PARENT's list of children.
4713 This is done by removing and re-adding it. */
4716 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4720 /* We want the declaration DIE from inside the class, not the
4721 specification DIE at toplevel. */
4722 if (child
->die_parent
!= parent
)
4724 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4730 gcc_assert (child
->die_parent
== parent
4731 || (child
->die_parent
4732 == get_AT_ref (parent
, DW_AT_specification
)));
4734 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4735 if (p
->die_sib
== child
)
4737 remove_child_with_prev (child
, p
);
4741 add_child_die (parent
, child
);
4744 /* Return a pointer to a newly created DIE node. */
4746 static inline dw_die_ref
4747 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4749 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4751 die
->die_tag
= tag_value
;
4753 if (parent_die
!= NULL
)
4754 add_child_die (parent_die
, die
);
4757 limbo_die_node
*limbo_node
;
4759 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4760 limbo_node
->die
= die
;
4761 limbo_node
->created_for
= t
;
4762 limbo_node
->next
= limbo_die_list
;
4763 limbo_die_list
= limbo_node
;
4769 /* Return the DIE associated with the given type specifier. */
4771 static inline dw_die_ref
4772 lookup_type_die (tree type
)
4774 return TYPE_SYMTAB_DIE (type
);
4777 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4778 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4779 anonymous type instead the one of the naming typedef. */
4781 static inline dw_die_ref
4782 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4785 && TREE_CODE (type
) == RECORD_TYPE
4787 && type_die
->die_tag
== DW_TAG_typedef
4788 && is_naming_typedef_decl (TYPE_NAME (type
)))
4789 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4793 /* Like lookup_type_die, but if type is an anonymous type named by a
4794 typedef[1], return the DIE of the anonymous type instead the one of
4795 the naming typedef. This is because in gen_typedef_die, we did
4796 equate the anonymous struct named by the typedef with the DIE of
4797 the naming typedef. So by default, lookup_type_die on an anonymous
4798 struct yields the DIE of the naming typedef.
4800 [1]: Read the comment of is_naming_typedef_decl to learn about what
4801 a naming typedef is. */
4803 static inline dw_die_ref
4804 lookup_type_die_strip_naming_typedef (tree type
)
4806 dw_die_ref die
= lookup_type_die (type
);
4807 return strip_naming_typedef (type
, die
);
4810 /* Equate a DIE to a given type specifier. */
4813 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4815 TYPE_SYMTAB_DIE (type
) = type_die
;
4818 /* Returns a hash value for X (which really is a die_struct). */
4821 decl_die_table_hash (const void *x
)
4823 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4826 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4829 decl_die_table_eq (const void *x
, const void *y
)
4831 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4834 /* Return the DIE associated with a given declaration. */
4836 static inline dw_die_ref
4837 lookup_decl_die (tree decl
)
4839 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4842 /* Returns a hash value for X (which really is a var_loc_list). */
4845 decl_loc_table_hash (const void *x
)
4847 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4850 /* Return nonzero if decl_id of var_loc_list X is the same as
4854 decl_loc_table_eq (const void *x
, const void *y
)
4856 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4859 /* Return the var_loc list associated with a given declaration. */
4861 static inline var_loc_list
*
4862 lookup_decl_loc (const_tree decl
)
4864 if (!decl_loc_table
)
4866 return (var_loc_list
*)
4867 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4870 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4873 cached_dw_loc_list_table_hash (const void *x
)
4875 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4878 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4882 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4884 return (((const cached_dw_loc_list
*) x
)->decl_id
4885 == DECL_UID ((const_tree
) y
));
4888 /* Equate a DIE to a particular declaration. */
4891 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4893 unsigned int decl_id
= DECL_UID (decl
);
4896 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4898 decl_die
->decl_id
= decl_id
;
4901 /* Return how many bits covers PIECE EXPR_LIST. */
4904 decl_piece_bitsize (rtx piece
)
4906 int ret
= (int) GET_MODE (piece
);
4909 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
4910 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
4911 return INTVAL (XEXP (XEXP (piece
, 0), 0));
4914 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
4917 decl_piece_varloc_ptr (rtx piece
)
4919 if ((int) GET_MODE (piece
))
4920 return &XEXP (piece
, 0);
4922 return &XEXP (XEXP (piece
, 0), 1);
4925 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
4926 Next is the chain of following piece nodes. */
4929 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
4931 if (bitsize
<= (int) MAX_MACHINE_MODE
)
4932 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
4934 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
4939 /* Return rtx that should be stored into loc field for
4940 LOC_NOTE and BITPOS/BITSIZE. */
4943 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
4944 HOST_WIDE_INT bitsize
)
4948 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
4950 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
4955 /* This function either modifies location piece list *DEST in
4956 place (if SRC and INNER is NULL), or copies location piece list
4957 *SRC to *DEST while modifying it. Location BITPOS is modified
4958 to contain LOC_NOTE, any pieces overlapping it are removed resp.
4959 not copied and if needed some padding around it is added.
4960 When modifying in place, DEST should point to EXPR_LIST where
4961 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
4962 to the start of the whole list and INNER points to the EXPR_LIST
4963 where earlier pieces cover PIECE_BITPOS bits. */
4966 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
4967 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
4968 HOST_WIDE_INT bitsize
, rtx loc_note
)
4971 bool copy
= inner
!= NULL
;
4975 /* First copy all nodes preceding the current bitpos. */
4976 while (src
!= inner
)
4978 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
4979 decl_piece_bitsize (*src
), NULL_RTX
);
4980 dest
= &XEXP (*dest
, 1);
4981 src
= &XEXP (*src
, 1);
4984 /* Add padding if needed. */
4985 if (bitpos
!= piece_bitpos
)
4987 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
4988 copy
? NULL_RTX
: *dest
);
4989 dest
= &XEXP (*dest
, 1);
4991 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
4994 /* A piece with correct bitpos and bitsize already exist,
4995 just update the location for it and return. */
4996 *decl_piece_varloc_ptr (*dest
) = loc_note
;
4999 /* Add the piece that changed. */
5000 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5001 dest
= &XEXP (*dest
, 1);
5002 /* Skip over pieces that overlap it. */
5003 diff
= bitpos
- piece_bitpos
+ bitsize
;
5006 while (diff
> 0 && *src
)
5009 diff
-= decl_piece_bitsize (piece
);
5011 src
= &XEXP (piece
, 1);
5014 *src
= XEXP (piece
, 1);
5015 free_EXPR_LIST_node (piece
);
5018 /* Add padding if needed. */
5019 if (diff
< 0 && *src
)
5023 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5024 dest
= &XEXP (*dest
, 1);
5028 /* Finally copy all nodes following it. */
5031 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5032 decl_piece_bitsize (*src
), NULL_RTX
);
5033 dest
= &XEXP (*dest
, 1);
5034 src
= &XEXP (*src
, 1);
5038 /* Add a variable location node to the linked list for DECL. */
5040 static struct var_loc_node
*
5041 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5043 unsigned int decl_id
;
5046 struct var_loc_node
*loc
= NULL
;
5047 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5049 if (TREE_CODE (decl
) == VAR_DECL
5050 && DECL_HAS_DEBUG_EXPR_P (decl
))
5052 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5053 if (handled_component_p (realdecl
)
5054 || (TREE_CODE (realdecl
) == MEM_REF
5055 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5057 HOST_WIDE_INT maxsize
;
5060 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5061 if (!DECL_P (innerdecl
)
5062 || DECL_IGNORED_P (innerdecl
)
5063 || TREE_STATIC (innerdecl
)
5065 || bitpos
+ bitsize
> 256
5066 || bitsize
!= maxsize
)
5072 decl_id
= DECL_UID (decl
);
5073 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5076 temp
= ggc_alloc_cleared_var_loc_list ();
5077 temp
->decl_id
= decl_id
;
5081 temp
= (var_loc_list
*) *slot
;
5083 /* For PARM_DECLs try to keep around the original incoming value,
5084 even if that means we'll emit a zero-range .debug_loc entry. */
5086 && temp
->first
== temp
->last
5087 && TREE_CODE (decl
) == PARM_DECL
5088 && NOTE_P (temp
->first
->loc
)
5089 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5090 && DECL_INCOMING_RTL (decl
)
5091 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5092 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5093 == GET_CODE (DECL_INCOMING_RTL (decl
))
5094 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5096 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5097 NOTE_VAR_LOCATION_LOC (loc_note
))
5098 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5099 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5101 loc
= ggc_alloc_cleared_var_loc_node ();
5102 temp
->first
->next
= loc
;
5104 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5106 else if (temp
->last
)
5108 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5109 rtx
*piece_loc
= NULL
, last_loc_note
;
5110 int piece_bitpos
= 0;
5114 gcc_assert (last
->next
== NULL
);
5116 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5118 piece_loc
= &last
->loc
;
5121 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5122 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5124 piece_bitpos
+= cur_bitsize
;
5125 piece_loc
= &XEXP (*piece_loc
, 1);
5129 /* TEMP->LAST here is either pointer to the last but one or
5130 last element in the chained list, LAST is pointer to the
5132 if (label
&& strcmp (last
->label
, label
) == 0)
5134 /* For SRA optimized variables if there weren't any real
5135 insns since last note, just modify the last node. */
5136 if (piece_loc
!= NULL
)
5138 adjust_piece_list (piece_loc
, NULL
, NULL
,
5139 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5142 /* If the last note doesn't cover any instructions, remove it. */
5143 if (temp
->last
!= last
)
5145 temp
->last
->next
= NULL
;
5148 gcc_assert (strcmp (last
->label
, label
) != 0);
5152 gcc_assert (temp
->first
== temp
->last
5153 || (temp
->first
->next
== temp
->last
5154 && TREE_CODE (decl
) == PARM_DECL
));
5155 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5156 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5160 if (bitsize
== -1 && NOTE_P (last
->loc
))
5161 last_loc_note
= last
->loc
;
5162 else if (piece_loc
!= NULL
5163 && *piece_loc
!= NULL_RTX
5164 && piece_bitpos
== bitpos
5165 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5166 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5168 last_loc_note
= NULL_RTX
;
5169 /* If the current location is the same as the end of the list,
5170 and either both or neither of the locations is uninitialized,
5171 we have nothing to do. */
5172 if (last_loc_note
== NULL_RTX
5173 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5174 NOTE_VAR_LOCATION_LOC (loc_note
)))
5175 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5176 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5177 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5178 == VAR_INIT_STATUS_UNINITIALIZED
)
5179 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5180 == VAR_INIT_STATUS_UNINITIALIZED
))))
5182 /* Add LOC to the end of list and update LAST. If the last
5183 element of the list has been removed above, reuse its
5184 memory for the new node, otherwise allocate a new one. */
5188 memset (loc
, '\0', sizeof (*loc
));
5191 loc
= ggc_alloc_cleared_var_loc_node ();
5192 if (bitsize
== -1 || piece_loc
== NULL
)
5193 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5195 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5196 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5198 /* Ensure TEMP->LAST will point either to the new last but one
5199 element of the chain, or to the last element in it. */
5200 if (last
!= temp
->last
)
5208 loc
= ggc_alloc_cleared_var_loc_node ();
5211 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5216 /* Keep track of the number of spaces used to indent the
5217 output of the debugging routines that print the structure of
5218 the DIE internal representation. */
5219 static int print_indent
;
5221 /* Indent the line the number of spaces given by print_indent. */
5224 print_spaces (FILE *outfile
)
5226 fprintf (outfile
, "%*s", print_indent
, "");
5229 /* Print a type signature in hex. */
5232 print_signature (FILE *outfile
, char *sig
)
5236 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5237 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5240 /* Print the information associated with a given DIE, and its children.
5241 This routine is a debugging aid only. */
5244 print_die (dw_die_ref die
, FILE *outfile
)
5250 print_spaces (outfile
);
5251 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5252 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5254 print_spaces (outfile
);
5255 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5256 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5257 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5259 if (die
->comdat_type_p
)
5261 print_spaces (outfile
);
5262 fprintf (outfile
, " signature: ");
5263 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5264 fprintf (outfile
, "\n");
5267 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5269 print_spaces (outfile
);
5270 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5272 switch (AT_class (a
))
5274 case dw_val_class_addr
:
5275 fprintf (outfile
, "address");
5277 case dw_val_class_offset
:
5278 fprintf (outfile
, "offset");
5280 case dw_val_class_loc
:
5281 fprintf (outfile
, "location descriptor");
5283 case dw_val_class_loc_list
:
5284 fprintf (outfile
, "location list -> label:%s",
5285 AT_loc_list (a
)->ll_symbol
);
5287 case dw_val_class_range_list
:
5288 fprintf (outfile
, "range list");
5290 case dw_val_class_const
:
5291 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5293 case dw_val_class_unsigned_const
:
5294 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5296 case dw_val_class_const_double
:
5297 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5298 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5299 a
->dw_attr_val
.v
.val_double
.high
,
5300 a
->dw_attr_val
.v
.val_double
.low
);
5302 case dw_val_class_vec
:
5303 fprintf (outfile
, "floating-point or vector constant");
5305 case dw_val_class_flag
:
5306 fprintf (outfile
, "%u", AT_flag (a
));
5308 case dw_val_class_die_ref
:
5309 if (AT_ref (a
) != NULL
)
5311 if (AT_ref (a
)->comdat_type_p
)
5313 fprintf (outfile
, "die -> signature: ");
5314 print_signature (outfile
,
5315 AT_ref (a
)->die_id
.die_type_node
->signature
);
5317 else if (AT_ref (a
)->die_id
.die_symbol
)
5318 fprintf (outfile
, "die -> label: %s",
5319 AT_ref (a
)->die_id
.die_symbol
);
5321 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5322 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5325 fprintf (outfile
, "die -> <null>");
5327 case dw_val_class_vms_delta
:
5328 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5329 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5331 case dw_val_class_lbl_id
:
5332 case dw_val_class_lineptr
:
5333 case dw_val_class_macptr
:
5334 case dw_val_class_high_pc
:
5335 fprintf (outfile
, "label: %s", AT_lbl (a
));
5337 case dw_val_class_str
:
5338 if (AT_string (a
) != NULL
)
5339 fprintf (outfile
, "\"%s\"", AT_string (a
));
5341 fprintf (outfile
, "<null>");
5343 case dw_val_class_file
:
5344 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5345 AT_file (a
)->emitted_number
);
5347 case dw_val_class_data8
:
5351 for (i
= 0; i
< 8; i
++)
5352 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5359 fprintf (outfile
, "\n");
5362 if (die
->die_child
!= NULL
)
5365 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5368 if (print_indent
== 0)
5369 fprintf (outfile
, "\n");
5372 /* Print the information collected for a given DIE. */
5375 debug_dwarf_die (dw_die_ref die
)
5377 print_die (die
, stderr
);
5381 debug (die_struct
&ref
)
5383 print_die (&ref
, stderr
);
5387 debug (die_struct
*ptr
)
5392 fprintf (stderr
, "<nil>\n");
5396 /* Print all DWARF information collected for the compilation unit.
5397 This routine is a debugging aid only. */
5403 print_die (comp_unit_die (), stderr
);
5406 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5407 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5408 DIE that marks the start of the DIEs for this include file. */
5411 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5413 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5414 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5416 new_unit
->die_sib
= old_unit
;
5420 /* Close an include-file CU and reopen the enclosing one. */
5423 pop_compile_unit (dw_die_ref old_unit
)
5425 dw_die_ref new_unit
= old_unit
->die_sib
;
5427 old_unit
->die_sib
= NULL
;
5431 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5432 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5434 /* Calculate the checksum of a location expression. */
5437 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5441 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5443 CHECKSUM (loc
->dw_loc_oprnd1
);
5444 CHECKSUM (loc
->dw_loc_oprnd2
);
5447 /* Calculate the checksum of an attribute. */
5450 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5452 dw_loc_descr_ref loc
;
5455 CHECKSUM (at
->dw_attr
);
5457 /* We don't care that this was compiled with a different compiler
5458 snapshot; if the output is the same, that's what matters. */
5459 if (at
->dw_attr
== DW_AT_producer
)
5462 switch (AT_class (at
))
5464 case dw_val_class_const
:
5465 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5467 case dw_val_class_unsigned_const
:
5468 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5470 case dw_val_class_const_double
:
5471 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5473 case dw_val_class_vec
:
5474 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5476 case dw_val_class_flag
:
5477 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5479 case dw_val_class_str
:
5480 CHECKSUM_STRING (AT_string (at
));
5483 case dw_val_class_addr
:
5485 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5486 CHECKSUM_STRING (XSTR (r
, 0));
5489 case dw_val_class_offset
:
5490 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5493 case dw_val_class_loc
:
5494 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5495 loc_checksum (loc
, ctx
);
5498 case dw_val_class_die_ref
:
5499 die_checksum (AT_ref (at
), ctx
, mark
);
5502 case dw_val_class_fde_ref
:
5503 case dw_val_class_vms_delta
:
5504 case dw_val_class_lbl_id
:
5505 case dw_val_class_lineptr
:
5506 case dw_val_class_macptr
:
5507 case dw_val_class_high_pc
:
5510 case dw_val_class_file
:
5511 CHECKSUM_STRING (AT_file (at
)->filename
);
5514 case dw_val_class_data8
:
5515 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5523 /* Calculate the checksum of a DIE. */
5526 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5532 /* To avoid infinite recursion. */
5535 CHECKSUM (die
->die_mark
);
5538 die
->die_mark
= ++(*mark
);
5540 CHECKSUM (die
->die_tag
);
5542 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5543 attr_checksum (a
, ctx
, mark
);
5545 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5549 #undef CHECKSUM_STRING
5551 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5552 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5553 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5554 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5555 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5556 #define CHECKSUM_ATTR(FOO) \
5557 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5559 /* Calculate the checksum of a number in signed LEB128 format. */
5562 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5569 byte
= (value
& 0x7f);
5571 more
= !((value
== 0 && (byte
& 0x40) == 0)
5572 || (value
== -1 && (byte
& 0x40) != 0));
5581 /* Calculate the checksum of a number in unsigned LEB128 format. */
5584 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5588 unsigned char byte
= (value
& 0x7f);
5591 /* More bytes to follow. */
5599 /* Checksum the context of the DIE. This adds the names of any
5600 surrounding namespaces or structures to the checksum. */
5603 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5607 int tag
= die
->die_tag
;
5609 if (tag
!= DW_TAG_namespace
5610 && tag
!= DW_TAG_structure_type
5611 && tag
!= DW_TAG_class_type
)
5614 name
= get_AT_string (die
, DW_AT_name
);
5616 spec
= get_AT_ref (die
, DW_AT_specification
);
5620 if (die
->die_parent
!= NULL
)
5621 checksum_die_context (die
->die_parent
, ctx
);
5623 CHECKSUM_ULEB128 ('C');
5624 CHECKSUM_ULEB128 (tag
);
5626 CHECKSUM_STRING (name
);
5629 /* Calculate the checksum of a location expression. */
5632 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5634 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5635 were emitted as a DW_FORM_sdata instead of a location expression. */
5636 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5638 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5639 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5643 /* Otherwise, just checksum the raw location expression. */
5646 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5647 CHECKSUM (loc
->dw_loc_oprnd1
);
5648 CHECKSUM (loc
->dw_loc_oprnd2
);
5649 loc
= loc
->dw_loc_next
;
5653 /* Calculate the checksum of an attribute. */
5656 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5657 struct md5_ctx
*ctx
, int *mark
)
5659 dw_loc_descr_ref loc
;
5662 if (AT_class (at
) == dw_val_class_die_ref
)
5664 dw_die_ref target_die
= AT_ref (at
);
5666 /* For pointer and reference types, we checksum only the (qualified)
5667 name of the target type (if there is a name). For friend entries,
5668 we checksum only the (qualified) name of the target type or function.
5669 This allows the checksum to remain the same whether the target type
5670 is complete or not. */
5671 if ((at
->dw_attr
== DW_AT_type
5672 && (tag
== DW_TAG_pointer_type
5673 || tag
== DW_TAG_reference_type
5674 || tag
== DW_TAG_rvalue_reference_type
5675 || tag
== DW_TAG_ptr_to_member_type
))
5676 || (at
->dw_attr
== DW_AT_friend
5677 && tag
== DW_TAG_friend
))
5679 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5681 if (name_attr
!= NULL
)
5683 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5687 CHECKSUM_ULEB128 ('N');
5688 CHECKSUM_ULEB128 (at
->dw_attr
);
5689 if (decl
->die_parent
!= NULL
)
5690 checksum_die_context (decl
->die_parent
, ctx
);
5691 CHECKSUM_ULEB128 ('E');
5692 CHECKSUM_STRING (AT_string (name_attr
));
5697 /* For all other references to another DIE, we check to see if the
5698 target DIE has already been visited. If it has, we emit a
5699 backward reference; if not, we descend recursively. */
5700 if (target_die
->die_mark
> 0)
5702 CHECKSUM_ULEB128 ('R');
5703 CHECKSUM_ULEB128 (at
->dw_attr
);
5704 CHECKSUM_ULEB128 (target_die
->die_mark
);
5708 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5712 target_die
->die_mark
= ++(*mark
);
5713 CHECKSUM_ULEB128 ('T');
5714 CHECKSUM_ULEB128 (at
->dw_attr
);
5715 if (decl
->die_parent
!= NULL
)
5716 checksum_die_context (decl
->die_parent
, ctx
);
5717 die_checksum_ordered (target_die
, ctx
, mark
);
5722 CHECKSUM_ULEB128 ('A');
5723 CHECKSUM_ULEB128 (at
->dw_attr
);
5725 switch (AT_class (at
))
5727 case dw_val_class_const
:
5728 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5729 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5732 case dw_val_class_unsigned_const
:
5733 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5734 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5737 case dw_val_class_const_double
:
5738 CHECKSUM_ULEB128 (DW_FORM_block
);
5739 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5740 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5743 case dw_val_class_vec
:
5744 CHECKSUM_ULEB128 (DW_FORM_block
);
5745 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_vec
));
5746 CHECKSUM (at
->dw_attr_val
.v
.val_vec
);
5749 case dw_val_class_flag
:
5750 CHECKSUM_ULEB128 (DW_FORM_flag
);
5751 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5754 case dw_val_class_str
:
5755 CHECKSUM_ULEB128 (DW_FORM_string
);
5756 CHECKSUM_STRING (AT_string (at
));
5759 case dw_val_class_addr
:
5761 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5762 CHECKSUM_ULEB128 (DW_FORM_string
);
5763 CHECKSUM_STRING (XSTR (r
, 0));
5766 case dw_val_class_offset
:
5767 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5768 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5771 case dw_val_class_loc
:
5772 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5773 loc_checksum_ordered (loc
, ctx
);
5776 case dw_val_class_fde_ref
:
5777 case dw_val_class_lbl_id
:
5778 case dw_val_class_lineptr
:
5779 case dw_val_class_macptr
:
5780 case dw_val_class_high_pc
:
5783 case dw_val_class_file
:
5784 CHECKSUM_ULEB128 (DW_FORM_string
);
5785 CHECKSUM_STRING (AT_file (at
)->filename
);
5788 case dw_val_class_data8
:
5789 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5797 struct checksum_attributes
5799 dw_attr_ref at_name
;
5800 dw_attr_ref at_type
;
5801 dw_attr_ref at_friend
;
5802 dw_attr_ref at_accessibility
;
5803 dw_attr_ref at_address_class
;
5804 dw_attr_ref at_allocated
;
5805 dw_attr_ref at_artificial
;
5806 dw_attr_ref at_associated
;
5807 dw_attr_ref at_binary_scale
;
5808 dw_attr_ref at_bit_offset
;
5809 dw_attr_ref at_bit_size
;
5810 dw_attr_ref at_bit_stride
;
5811 dw_attr_ref at_byte_size
;
5812 dw_attr_ref at_byte_stride
;
5813 dw_attr_ref at_const_value
;
5814 dw_attr_ref at_containing_type
;
5815 dw_attr_ref at_count
;
5816 dw_attr_ref at_data_location
;
5817 dw_attr_ref at_data_member_location
;
5818 dw_attr_ref at_decimal_scale
;
5819 dw_attr_ref at_decimal_sign
;
5820 dw_attr_ref at_default_value
;
5821 dw_attr_ref at_digit_count
;
5822 dw_attr_ref at_discr
;
5823 dw_attr_ref at_discr_list
;
5824 dw_attr_ref at_discr_value
;
5825 dw_attr_ref at_encoding
;
5826 dw_attr_ref at_endianity
;
5827 dw_attr_ref at_explicit
;
5828 dw_attr_ref at_is_optional
;
5829 dw_attr_ref at_location
;
5830 dw_attr_ref at_lower_bound
;
5831 dw_attr_ref at_mutable
;
5832 dw_attr_ref at_ordering
;
5833 dw_attr_ref at_picture_string
;
5834 dw_attr_ref at_prototyped
;
5835 dw_attr_ref at_small
;
5836 dw_attr_ref at_segment
;
5837 dw_attr_ref at_string_length
;
5838 dw_attr_ref at_threads_scaled
;
5839 dw_attr_ref at_upper_bound
;
5840 dw_attr_ref at_use_location
;
5841 dw_attr_ref at_use_UTF8
;
5842 dw_attr_ref at_variable_parameter
;
5843 dw_attr_ref at_virtuality
;
5844 dw_attr_ref at_visibility
;
5845 dw_attr_ref at_vtable_elem_location
;
5848 /* Collect the attributes that we will want to use for the checksum. */
5851 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5856 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5867 attrs
->at_friend
= a
;
5869 case DW_AT_accessibility
:
5870 attrs
->at_accessibility
= a
;
5872 case DW_AT_address_class
:
5873 attrs
->at_address_class
= a
;
5875 case DW_AT_allocated
:
5876 attrs
->at_allocated
= a
;
5878 case DW_AT_artificial
:
5879 attrs
->at_artificial
= a
;
5881 case DW_AT_associated
:
5882 attrs
->at_associated
= a
;
5884 case DW_AT_binary_scale
:
5885 attrs
->at_binary_scale
= a
;
5887 case DW_AT_bit_offset
:
5888 attrs
->at_bit_offset
= a
;
5890 case DW_AT_bit_size
:
5891 attrs
->at_bit_size
= a
;
5893 case DW_AT_bit_stride
:
5894 attrs
->at_bit_stride
= a
;
5896 case DW_AT_byte_size
:
5897 attrs
->at_byte_size
= a
;
5899 case DW_AT_byte_stride
:
5900 attrs
->at_byte_stride
= a
;
5902 case DW_AT_const_value
:
5903 attrs
->at_const_value
= a
;
5905 case DW_AT_containing_type
:
5906 attrs
->at_containing_type
= a
;
5909 attrs
->at_count
= a
;
5911 case DW_AT_data_location
:
5912 attrs
->at_data_location
= a
;
5914 case DW_AT_data_member_location
:
5915 attrs
->at_data_member_location
= a
;
5917 case DW_AT_decimal_scale
:
5918 attrs
->at_decimal_scale
= a
;
5920 case DW_AT_decimal_sign
:
5921 attrs
->at_decimal_sign
= a
;
5923 case DW_AT_default_value
:
5924 attrs
->at_default_value
= a
;
5926 case DW_AT_digit_count
:
5927 attrs
->at_digit_count
= a
;
5930 attrs
->at_discr
= a
;
5932 case DW_AT_discr_list
:
5933 attrs
->at_discr_list
= a
;
5935 case DW_AT_discr_value
:
5936 attrs
->at_discr_value
= a
;
5938 case DW_AT_encoding
:
5939 attrs
->at_encoding
= a
;
5941 case DW_AT_endianity
:
5942 attrs
->at_endianity
= a
;
5944 case DW_AT_explicit
:
5945 attrs
->at_explicit
= a
;
5947 case DW_AT_is_optional
:
5948 attrs
->at_is_optional
= a
;
5950 case DW_AT_location
:
5951 attrs
->at_location
= a
;
5953 case DW_AT_lower_bound
:
5954 attrs
->at_lower_bound
= a
;
5957 attrs
->at_mutable
= a
;
5959 case DW_AT_ordering
:
5960 attrs
->at_ordering
= a
;
5962 case DW_AT_picture_string
:
5963 attrs
->at_picture_string
= a
;
5965 case DW_AT_prototyped
:
5966 attrs
->at_prototyped
= a
;
5969 attrs
->at_small
= a
;
5972 attrs
->at_segment
= a
;
5974 case DW_AT_string_length
:
5975 attrs
->at_string_length
= a
;
5977 case DW_AT_threads_scaled
:
5978 attrs
->at_threads_scaled
= a
;
5980 case DW_AT_upper_bound
:
5981 attrs
->at_upper_bound
= a
;
5983 case DW_AT_use_location
:
5984 attrs
->at_use_location
= a
;
5986 case DW_AT_use_UTF8
:
5987 attrs
->at_use_UTF8
= a
;
5989 case DW_AT_variable_parameter
:
5990 attrs
->at_variable_parameter
= a
;
5992 case DW_AT_virtuality
:
5993 attrs
->at_virtuality
= a
;
5995 case DW_AT_visibility
:
5996 attrs
->at_visibility
= a
;
5998 case DW_AT_vtable_elem_location
:
5999 attrs
->at_vtable_elem_location
= a
;
6007 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6010 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6014 struct checksum_attributes attrs
;
6016 CHECKSUM_ULEB128 ('D');
6017 CHECKSUM_ULEB128 (die
->die_tag
);
6019 memset (&attrs
, 0, sizeof (attrs
));
6021 decl
= get_AT_ref (die
, DW_AT_specification
);
6023 collect_checksum_attributes (&attrs
, decl
);
6024 collect_checksum_attributes (&attrs
, die
);
6026 CHECKSUM_ATTR (attrs
.at_name
);
6027 CHECKSUM_ATTR (attrs
.at_accessibility
);
6028 CHECKSUM_ATTR (attrs
.at_address_class
);
6029 CHECKSUM_ATTR (attrs
.at_allocated
);
6030 CHECKSUM_ATTR (attrs
.at_artificial
);
6031 CHECKSUM_ATTR (attrs
.at_associated
);
6032 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6033 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6034 CHECKSUM_ATTR (attrs
.at_bit_size
);
6035 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6036 CHECKSUM_ATTR (attrs
.at_byte_size
);
6037 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6038 CHECKSUM_ATTR (attrs
.at_const_value
);
6039 CHECKSUM_ATTR (attrs
.at_containing_type
);
6040 CHECKSUM_ATTR (attrs
.at_count
);
6041 CHECKSUM_ATTR (attrs
.at_data_location
);
6042 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6043 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6044 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6045 CHECKSUM_ATTR (attrs
.at_default_value
);
6046 CHECKSUM_ATTR (attrs
.at_digit_count
);
6047 CHECKSUM_ATTR (attrs
.at_discr
);
6048 CHECKSUM_ATTR (attrs
.at_discr_list
);
6049 CHECKSUM_ATTR (attrs
.at_discr_value
);
6050 CHECKSUM_ATTR (attrs
.at_encoding
);
6051 CHECKSUM_ATTR (attrs
.at_endianity
);
6052 CHECKSUM_ATTR (attrs
.at_explicit
);
6053 CHECKSUM_ATTR (attrs
.at_is_optional
);
6054 CHECKSUM_ATTR (attrs
.at_location
);
6055 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6056 CHECKSUM_ATTR (attrs
.at_mutable
);
6057 CHECKSUM_ATTR (attrs
.at_ordering
);
6058 CHECKSUM_ATTR (attrs
.at_picture_string
);
6059 CHECKSUM_ATTR (attrs
.at_prototyped
);
6060 CHECKSUM_ATTR (attrs
.at_small
);
6061 CHECKSUM_ATTR (attrs
.at_segment
);
6062 CHECKSUM_ATTR (attrs
.at_string_length
);
6063 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6064 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6065 CHECKSUM_ATTR (attrs
.at_use_location
);
6066 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6067 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6068 CHECKSUM_ATTR (attrs
.at_virtuality
);
6069 CHECKSUM_ATTR (attrs
.at_visibility
);
6070 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6071 CHECKSUM_ATTR (attrs
.at_type
);
6072 CHECKSUM_ATTR (attrs
.at_friend
);
6074 /* Checksum the child DIEs, except for nested types and member functions. */
6077 dw_attr_ref name_attr
;
6080 name_attr
= get_AT (c
, DW_AT_name
);
6081 if ((is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
)
6082 && name_attr
!= NULL
)
6084 CHECKSUM_ULEB128 ('S');
6085 CHECKSUM_ULEB128 (c
->die_tag
);
6086 CHECKSUM_STRING (AT_string (name_attr
));
6090 /* Mark this DIE so it gets processed when unmarking. */
6091 if (c
->die_mark
== 0)
6093 die_checksum_ordered (c
, ctx
, mark
);
6095 } while (c
!= die
->die_child
);
6097 CHECKSUM_ULEB128 (0);
6101 #undef CHECKSUM_STRING
6102 #undef CHECKSUM_ATTR
6103 #undef CHECKSUM_LEB128
6104 #undef CHECKSUM_ULEB128
6106 /* Generate the type signature for DIE. This is computed by generating an
6107 MD5 checksum over the DIE's tag, its relevant attributes, and its
6108 children. Attributes that are references to other DIEs are processed
6109 by recursion, using the MARK field to prevent infinite recursion.
6110 If the DIE is nested inside a namespace or another type, we also
6111 need to include that context in the signature. The lower 64 bits
6112 of the resulting MD5 checksum comprise the signature. */
6115 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6119 unsigned char checksum
[16];
6124 name
= get_AT_string (die
, DW_AT_name
);
6125 decl
= get_AT_ref (die
, DW_AT_specification
);
6126 parent
= get_die_parent (die
);
6128 /* First, compute a signature for just the type name (and its surrounding
6129 context, if any. This is stored in the type unit DIE for link-time
6130 ODR (one-definition rule) checking. */
6132 if (is_cxx() && name
!= NULL
)
6134 md5_init_ctx (&ctx
);
6136 /* Checksum the names of surrounding namespaces and structures. */
6138 checksum_die_context (parent
, &ctx
);
6140 md5_process_bytes (&die
->die_tag
, sizeof (die
->die_tag
), &ctx
);
6141 md5_process_bytes (name
, strlen (name
) + 1, &ctx
);
6142 md5_finish_ctx (&ctx
, checksum
);
6144 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6147 /* Next, compute the complete type signature. */
6149 md5_init_ctx (&ctx
);
6151 die
->die_mark
= mark
;
6153 /* Checksum the names of surrounding namespaces and structures. */
6155 checksum_die_context (parent
, &ctx
);
6157 /* Checksum the DIE and its children. */
6158 die_checksum_ordered (die
, &ctx
, &mark
);
6159 unmark_all_dies (die
);
6160 md5_finish_ctx (&ctx
, checksum
);
6162 /* Store the signature in the type node and link the type DIE and the
6163 type node together. */
6164 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6165 DWARF_TYPE_SIGNATURE_SIZE
);
6166 die
->comdat_type_p
= true;
6167 die
->die_id
.die_type_node
= type_node
;
6168 type_node
->type_die
= die
;
6170 /* If the DIE is a specification, link its declaration to the type node
6174 decl
->comdat_type_p
= true;
6175 decl
->die_id
.die_type_node
= type_node
;
6179 /* Do the location expressions look same? */
6181 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6183 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6184 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6185 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6188 /* Do the values look the same? */
6190 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6192 dw_loc_descr_ref loc1
, loc2
;
6195 if (v1
->val_class
!= v2
->val_class
)
6198 switch (v1
->val_class
)
6200 case dw_val_class_const
:
6201 return v1
->v
.val_int
== v2
->v
.val_int
;
6202 case dw_val_class_unsigned_const
:
6203 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6204 case dw_val_class_const_double
:
6205 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6206 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6207 case dw_val_class_vec
:
6208 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6209 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6211 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6212 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6215 case dw_val_class_flag
:
6216 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6217 case dw_val_class_str
:
6218 return !strcmp(v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6220 case dw_val_class_addr
:
6221 r1
= v1
->v
.val_addr
;
6222 r2
= v2
->v
.val_addr
;
6223 if (GET_CODE (r1
) != GET_CODE (r2
))
6225 return !rtx_equal_p (r1
, r2
);
6227 case dw_val_class_offset
:
6228 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6230 case dw_val_class_loc
:
6231 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6233 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6234 if (!same_loc_p (loc1
, loc2
, mark
))
6236 return !loc1
&& !loc2
;
6238 case dw_val_class_die_ref
:
6239 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6241 case dw_val_class_fde_ref
:
6242 case dw_val_class_vms_delta
:
6243 case dw_val_class_lbl_id
:
6244 case dw_val_class_lineptr
:
6245 case dw_val_class_macptr
:
6246 case dw_val_class_high_pc
:
6249 case dw_val_class_file
:
6250 return v1
->v
.val_file
== v2
->v
.val_file
;
6252 case dw_val_class_data8
:
6253 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6260 /* Do the attributes look the same? */
6263 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6265 if (at1
->dw_attr
!= at2
->dw_attr
)
6268 /* We don't care that this was compiled with a different compiler
6269 snapshot; if the output is the same, that's what matters. */
6270 if (at1
->dw_attr
== DW_AT_producer
)
6273 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6276 /* Do the dies look the same? */
6279 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6285 /* To avoid infinite recursion. */
6287 return die1
->die_mark
== die2
->die_mark
;
6288 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6290 if (die1
->die_tag
!= die2
->die_tag
)
6293 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6296 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6297 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6300 c1
= die1
->die_child
;
6301 c2
= die2
->die_child
;
6310 if (!same_die_p (c1
, c2
, mark
))
6314 if (c1
== die1
->die_child
)
6316 if (c2
== die2
->die_child
)
6326 /* Do the dies look the same? Wrapper around same_die_p. */
6329 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6332 int ret
= same_die_p (die1
, die2
, &mark
);
6334 unmark_all_dies (die1
);
6335 unmark_all_dies (die2
);
6340 /* The prefix to attach to symbols on DIEs in the current comdat debug
6342 static const char *comdat_symbol_id
;
6344 /* The index of the current symbol within the current comdat CU. */
6345 static unsigned int comdat_symbol_number
;
6347 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6348 children, and set comdat_symbol_id accordingly. */
6351 compute_section_prefix (dw_die_ref unit_die
)
6353 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6354 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6355 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6358 unsigned char checksum
[16];
6361 /* Compute the checksum of the DIE, then append part of it as hex digits to
6362 the name filename of the unit. */
6364 md5_init_ctx (&ctx
);
6366 die_checksum (unit_die
, &ctx
, &mark
);
6367 unmark_all_dies (unit_die
);
6368 md5_finish_ctx (&ctx
, checksum
);
6370 sprintf (name
, "%s.", base
);
6371 clean_symbol_name (name
);
6373 p
= name
+ strlen (name
);
6374 for (i
= 0; i
< 4; i
++)
6376 sprintf (p
, "%.2x", checksum
[i
]);
6380 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6381 comdat_symbol_number
= 0;
6384 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6387 is_type_die (dw_die_ref die
)
6389 switch (die
->die_tag
)
6391 case DW_TAG_array_type
:
6392 case DW_TAG_class_type
:
6393 case DW_TAG_interface_type
:
6394 case DW_TAG_enumeration_type
:
6395 case DW_TAG_pointer_type
:
6396 case DW_TAG_reference_type
:
6397 case DW_TAG_rvalue_reference_type
:
6398 case DW_TAG_string_type
:
6399 case DW_TAG_structure_type
:
6400 case DW_TAG_subroutine_type
:
6401 case DW_TAG_union_type
:
6402 case DW_TAG_ptr_to_member_type
:
6403 case DW_TAG_set_type
:
6404 case DW_TAG_subrange_type
:
6405 case DW_TAG_base_type
:
6406 case DW_TAG_const_type
:
6407 case DW_TAG_file_type
:
6408 case DW_TAG_packed_type
:
6409 case DW_TAG_volatile_type
:
6410 case DW_TAG_typedef
:
6417 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6418 Basically, we want to choose the bits that are likely to be shared between
6419 compilations (types) and leave out the bits that are specific to individual
6420 compilations (functions). */
6423 is_comdat_die (dw_die_ref c
)
6425 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6426 we do for stabs. The advantage is a greater likelihood of sharing between
6427 objects that don't include headers in the same order (and therefore would
6428 put the base types in a different comdat). jason 8/28/00 */
6430 if (c
->die_tag
== DW_TAG_base_type
)
6433 if (c
->die_tag
== DW_TAG_pointer_type
6434 || c
->die_tag
== DW_TAG_reference_type
6435 || c
->die_tag
== DW_TAG_rvalue_reference_type
6436 || c
->die_tag
== DW_TAG_const_type
6437 || c
->die_tag
== DW_TAG_volatile_type
)
6439 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6441 return t
? is_comdat_die (t
) : 0;
6444 return is_type_die (c
);
6447 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6448 compilation unit. */
6451 is_symbol_die (dw_die_ref c
)
6453 return (is_type_die (c
)
6454 || is_declaration_die (c
)
6455 || c
->die_tag
== DW_TAG_namespace
6456 || c
->die_tag
== DW_TAG_module
);
6459 /* Returns true iff C is a compile-unit DIE. */
6462 is_cu_die (dw_die_ref c
)
6464 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6467 /* Returns true iff C is a unit DIE of some sort. */
6470 is_unit_die (dw_die_ref c
)
6472 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6473 || c
->die_tag
== DW_TAG_partial_unit
6474 || c
->die_tag
== DW_TAG_type_unit
);
6477 /* Returns true iff C is a namespace DIE. */
6480 is_namespace_die (dw_die_ref c
)
6482 return c
&& c
->die_tag
== DW_TAG_namespace
;
6485 /* Returns true iff C is a class or structure DIE. */
6488 is_class_die (dw_die_ref c
)
6490 return c
&& (c
->die_tag
== DW_TAG_class_type
6491 || c
->die_tag
== DW_TAG_structure_type
);
6495 gen_internal_sym (const char *prefix
)
6499 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6500 return xstrdup (buf
);
6503 /* Assign symbols to all worthy DIEs under DIE. */
6506 assign_symbol_names (dw_die_ref die
)
6510 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6512 if (comdat_symbol_id
)
6514 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6516 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6517 comdat_symbol_id
, comdat_symbol_number
++);
6518 die
->die_id
.die_symbol
= xstrdup (p
);
6521 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6524 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6527 struct cu_hash_table_entry
6530 unsigned min_comdat_num
, max_comdat_num
;
6531 struct cu_hash_table_entry
*next
;
6534 /* Helpers to manipulate hash table of CUs. */
6536 struct cu_hash_table_entry_hasher
6538 typedef cu_hash_table_entry value_type
;
6539 typedef die_struct compare_type
;
6540 static inline hashval_t
hash (const value_type
*);
6541 static inline bool equal (const value_type
*, const compare_type
*);
6542 static inline void remove (value_type
*);
6546 cu_hash_table_entry_hasher::hash (const value_type
*entry
)
6548 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6552 cu_hash_table_entry_hasher::equal (const value_type
*entry1
,
6553 const compare_type
*entry2
)
6555 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6559 cu_hash_table_entry_hasher::remove (value_type
*entry
)
6561 struct cu_hash_table_entry
*next
;
6571 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6573 /* Check whether we have already seen this CU and set up SYM_NUM
6576 check_duplicate_cu (dw_die_ref cu
, cu_hash_type htable
, unsigned int *sym_num
)
6578 struct cu_hash_table_entry dummy
;
6579 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6581 dummy
.max_comdat_num
= 0;
6583 slot
= htable
.find_slot_with_hash (cu
,
6584 htab_hash_string (cu
->die_id
.die_symbol
),
6588 for (; entry
; last
= entry
, entry
= entry
->next
)
6590 if (same_die_p_wrap (cu
, entry
->cu
))
6596 *sym_num
= entry
->min_comdat_num
;
6600 entry
= XCNEW (struct cu_hash_table_entry
);
6602 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6603 entry
->next
= *slot
;
6609 /* Record SYM_NUM to record of CU in HTABLE. */
6611 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type htable
,
6612 unsigned int sym_num
)
6614 struct cu_hash_table_entry
**slot
, *entry
;
6616 slot
= htable
.find_slot_with_hash (cu
,
6617 htab_hash_string (cu
->die_id
.die_symbol
),
6621 entry
->max_comdat_num
= sym_num
;
6624 /* Traverse the DIE (which is always comp_unit_die), and set up
6625 additional compilation units for each of the include files we see
6626 bracketed by BINCL/EINCL. */
6629 break_out_includes (dw_die_ref die
)
6632 dw_die_ref unit
= NULL
;
6633 limbo_die_node
*node
, **pnode
;
6634 cu_hash_type cu_hash_table
;
6638 dw_die_ref prev
= c
;
6640 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6641 || (unit
&& is_comdat_die (c
)))
6643 dw_die_ref next
= c
->die_sib
;
6645 /* This DIE is for a secondary CU; remove it from the main one. */
6646 remove_child_with_prev (c
, prev
);
6648 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6649 unit
= push_new_compile_unit (unit
, c
);
6650 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6651 unit
= pop_compile_unit (unit
);
6653 add_child_die (unit
, c
);
6655 if (c
== die
->die_child
)
6658 } while (c
!= die
->die_child
);
6661 /* We can only use this in debugging, since the frontend doesn't check
6662 to make sure that we leave every include file we enter. */
6666 assign_symbol_names (die
);
6667 cu_hash_table
.create (10);
6668 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6674 compute_section_prefix (node
->die
);
6675 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6676 &comdat_symbol_number
);
6677 assign_symbol_names (node
->die
);
6679 *pnode
= node
->next
;
6682 pnode
= &node
->next
;
6683 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6684 comdat_symbol_number
);
6687 cu_hash_table
.dispose ();
6690 /* Return non-zero if this DIE is a declaration. */
6693 is_declaration_die (dw_die_ref die
)
6698 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6699 if (a
->dw_attr
== DW_AT_declaration
)
6705 /* Return non-zero if this DIE is nested inside a subprogram. */
6708 is_nested_in_subprogram (dw_die_ref die
)
6710 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6714 return local_scope_p (decl
);
6717 /* Return non-zero if this DIE contains a defining declaration of a
6721 contains_subprogram_definition (dw_die_ref die
)
6725 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6727 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition(c
)) return 1);
6731 /* Return non-zero if this is a type DIE that should be moved to a
6732 COMDAT .debug_types section. */
6735 should_move_die_to_comdat (dw_die_ref die
)
6737 switch (die
->die_tag
)
6739 case DW_TAG_class_type
:
6740 case DW_TAG_structure_type
:
6741 case DW_TAG_enumeration_type
:
6742 case DW_TAG_union_type
:
6743 /* Don't move declarations, inlined instances, or types nested in a
6745 if (is_declaration_die (die
)
6746 || get_AT (die
, DW_AT_abstract_origin
)
6747 || is_nested_in_subprogram (die
))
6749 /* A type definition should never contain a subprogram definition. */
6750 gcc_assert (!contains_subprogram_definition (die
));
6752 case DW_TAG_array_type
:
6753 case DW_TAG_interface_type
:
6754 case DW_TAG_pointer_type
:
6755 case DW_TAG_reference_type
:
6756 case DW_TAG_rvalue_reference_type
:
6757 case DW_TAG_string_type
:
6758 case DW_TAG_subroutine_type
:
6759 case DW_TAG_ptr_to_member_type
:
6760 case DW_TAG_set_type
:
6761 case DW_TAG_subrange_type
:
6762 case DW_TAG_base_type
:
6763 case DW_TAG_const_type
:
6764 case DW_TAG_file_type
:
6765 case DW_TAG_packed_type
:
6766 case DW_TAG_volatile_type
:
6767 case DW_TAG_typedef
:
6773 /* Make a clone of DIE. */
6776 clone_die (dw_die_ref die
)
6782 clone
= ggc_alloc_cleared_die_node ();
6783 clone
->die_tag
= die
->die_tag
;
6785 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6786 add_dwarf_attr (clone
, a
);
6791 /* Make a clone of the tree rooted at DIE. */
6794 clone_tree (dw_die_ref die
)
6797 dw_die_ref clone
= clone_die (die
);
6799 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree(c
)));
6804 /* Make a clone of DIE as a declaration. */
6807 clone_as_declaration (dw_die_ref die
)
6814 /* If the DIE is already a declaration, just clone it. */
6815 if (is_declaration_die (die
))
6816 return clone_die (die
);
6818 /* If the DIE is a specification, just clone its declaration DIE. */
6819 decl
= get_AT_ref (die
, DW_AT_specification
);
6822 clone
= clone_die (decl
);
6823 if (die
->comdat_type_p
)
6824 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6828 clone
= ggc_alloc_cleared_die_node ();
6829 clone
->die_tag
= die
->die_tag
;
6831 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6833 /* We don't want to copy over all attributes.
6834 For example we don't want DW_AT_byte_size because otherwise we will no
6835 longer have a declaration and GDB will treat it as a definition. */
6839 case DW_AT_artificial
:
6840 case DW_AT_containing_type
:
6841 case DW_AT_external
:
6844 case DW_AT_virtuality
:
6845 case DW_AT_linkage_name
:
6846 case DW_AT_MIPS_linkage_name
:
6847 add_dwarf_attr (clone
, a
);
6849 case DW_AT_byte_size
:
6855 if (die
->comdat_type_p
)
6856 add_AT_die_ref (clone
, DW_AT_signature
, die
);
6858 add_AT_flag (clone
, DW_AT_declaration
, 1);
6863 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
6865 struct decl_table_entry
6871 /* Helpers to manipulate hash table of copied declarations. */
6873 /* Hashtable helpers. */
6875 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
6877 typedef decl_table_entry value_type
;
6878 typedef die_struct compare_type
;
6879 static inline hashval_t
hash (const value_type
*);
6880 static inline bool equal (const value_type
*, const compare_type
*);
6884 decl_table_entry_hasher::hash (const value_type
*entry
)
6886 return htab_hash_pointer (entry
->orig
);
6890 decl_table_entry_hasher::equal (const value_type
*entry1
,
6891 const compare_type
*entry2
)
6893 return entry1
->orig
== entry2
;
6896 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
6898 /* Copy DIE and its ancestors, up to, but not including, the compile unit
6899 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
6900 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
6901 to check if the ancestor has already been copied into UNIT. */
6904 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
6906 dw_die_ref parent
= die
->die_parent
;
6907 dw_die_ref new_parent
= unit
;
6909 decl_table_entry
**slot
= NULL
;
6910 struct decl_table_entry
*entry
= NULL
;
6912 if (decl_table
.is_created ())
6914 /* Check if the entry has already been copied to UNIT. */
6915 slot
= decl_table
.find_slot_with_hash (die
, htab_hash_pointer (die
),
6917 if (*slot
!= HTAB_EMPTY_ENTRY
)
6923 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
6924 entry
= XCNEW (struct decl_table_entry
);
6932 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
6935 if (!is_unit_die (parent
))
6936 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
6939 copy
= clone_as_declaration (die
);
6940 add_child_die (new_parent
, copy
);
6942 if (decl_table
.is_created ())
6944 /* Record the pointer to the copy. */
6950 /* Copy the declaration context to the new type unit DIE. This includes
6951 any surrounding namespace or type declarations. If the DIE has an
6952 AT_specification attribute, it also includes attributes and children
6953 attached to the specification, and returns a pointer to the original
6954 parent of the declaration DIE. Returns NULL otherwise. */
6957 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
6960 dw_die_ref new_decl
;
6961 dw_die_ref orig_parent
= NULL
;
6963 decl
= get_AT_ref (die
, DW_AT_specification
);
6972 /* The original DIE will be changed to a declaration, and must
6973 be moved to be a child of the original declaration DIE. */
6974 orig_parent
= decl
->die_parent
;
6976 /* Copy the type node pointer from the new DIE to the original
6977 declaration DIE so we can forward references later. */
6978 decl
->comdat_type_p
= true;
6979 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
6981 remove_AT (die
, DW_AT_specification
);
6983 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
6985 if (a
->dw_attr
!= DW_AT_name
6986 && a
->dw_attr
!= DW_AT_declaration
6987 && a
->dw_attr
!= DW_AT_external
)
6988 add_dwarf_attr (die
, a
);
6991 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree(c
)));
6994 if (decl
->die_parent
!= NULL
6995 && !is_unit_die (decl
->die_parent
))
6997 new_decl
= copy_ancestor_tree (unit
, decl
, decl_hash_type ());
6998 if (new_decl
!= NULL
)
7000 remove_AT (new_decl
, DW_AT_signature
);
7001 add_AT_specification (die
, new_decl
);
7008 /* Generate the skeleton ancestor tree for the given NODE, then clone
7009 the DIE and add the clone into the tree. */
7012 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7014 if (node
->new_die
!= NULL
)
7017 node
->new_die
= clone_as_declaration (node
->old_die
);
7019 if (node
->parent
!= NULL
)
7021 generate_skeleton_ancestor_tree (node
->parent
);
7022 add_child_die (node
->parent
->new_die
, node
->new_die
);
7026 /* Generate a skeleton tree of DIEs containing any declarations that are
7027 found in the original tree. We traverse the tree looking for declaration
7028 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7031 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7033 skeleton_chain_node node
;
7036 dw_die_ref prev
= NULL
;
7037 dw_die_ref next
= NULL
;
7039 node
.parent
= parent
;
7041 first
= c
= parent
->old_die
->die_child
;
7045 if (prev
== NULL
|| prev
->die_sib
== c
)
7048 next
= (c
== first
? NULL
: c
->die_sib
);
7050 node
.new_die
= NULL
;
7051 if (is_declaration_die (c
))
7053 /* Clone the existing DIE, move the original to the skeleton
7054 tree (which is in the main CU), and put the clone, with
7055 all the original's children, where the original came from. */
7056 dw_die_ref clone
= clone_die (c
);
7057 move_all_children (c
, clone
);
7059 replace_child (c
, clone
, prev
);
7060 generate_skeleton_ancestor_tree (parent
);
7061 add_child_die (parent
->new_die
, c
);
7065 generate_skeleton_bottom_up (&node
);
7066 } while (next
!= NULL
);
7069 /* Wrapper function for generate_skeleton_bottom_up. */
7072 generate_skeleton (dw_die_ref die
)
7074 skeleton_chain_node node
;
7077 node
.new_die
= NULL
;
7080 /* If this type definition is nested inside another type,
7081 always leave at least a declaration in its place. */
7082 if (die
->die_parent
!= NULL
&& is_type_die (die
->die_parent
))
7083 node
.new_die
= clone_as_declaration (die
);
7085 generate_skeleton_bottom_up (&node
);
7086 return node
.new_die
;
7089 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7090 declaration. The original DIE is moved to a new compile unit so that
7091 existing references to it follow it to the new location. If any of the
7092 original DIE's descendants is a declaration, we need to replace the
7093 original DIE with a skeleton tree and move the declarations back into the
7097 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7100 dw_die_ref skeleton
, orig_parent
;
7102 /* Copy the declaration context to the type unit DIE. If the returned
7103 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7105 orig_parent
= copy_declaration_context (unit
, child
);
7107 skeleton
= generate_skeleton (child
);
7108 if (skeleton
== NULL
)
7109 remove_child_with_prev (child
, prev
);
7112 skeleton
->comdat_type_p
= true;
7113 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7115 /* If the original DIE was a specification, we need to put
7116 the skeleton under the parent DIE of the declaration.
7117 This leaves the original declaration in the tree, but
7118 it will be pruned later since there are no longer any
7119 references to it. */
7120 if (orig_parent
!= NULL
)
7122 remove_child_with_prev (child
, prev
);
7123 add_child_die (orig_parent
, skeleton
);
7126 replace_child (child
, skeleton
, prev
);
7132 /* Traverse the DIE and set up additional .debug_types sections for each
7133 type worthy of being placed in a COMDAT section. */
7136 break_out_comdat_types (dw_die_ref die
)
7140 dw_die_ref prev
= NULL
;
7141 dw_die_ref next
= NULL
;
7142 dw_die_ref unit
= NULL
;
7144 first
= c
= die
->die_child
;
7148 if (prev
== NULL
|| prev
->die_sib
== c
)
7151 next
= (c
== first
? NULL
: c
->die_sib
);
7152 if (should_move_die_to_comdat (c
))
7154 dw_die_ref replacement
;
7155 comdat_type_node_ref type_node
;
7157 /* Create a new type unit DIE as the root for the new tree, and
7158 add it to the list of comdat types. */
7159 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7160 add_AT_unsigned (unit
, DW_AT_language
,
7161 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7162 type_node
= ggc_alloc_cleared_comdat_type_node ();
7163 type_node
->root_die
= unit
;
7164 type_node
->next
= comdat_type_list
;
7165 comdat_type_list
= type_node
;
7167 /* Generate the type signature. */
7168 generate_type_signature (c
, type_node
);
7170 /* Copy the declaration context, attributes, and children of the
7171 declaration into the new type unit DIE, then remove this DIE
7172 from the main CU (or replace it with a skeleton if necessary). */
7173 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7174 type_node
->skeleton_die
= replacement
;
7176 /* Break out nested types into their own type units. */
7177 break_out_comdat_types (c
);
7179 /* Add the DIE to the new compunit. */
7180 add_child_die (unit
, c
);
7182 if (replacement
!= NULL
)
7185 else if (c
->die_tag
== DW_TAG_namespace
7186 || c
->die_tag
== DW_TAG_class_type
7187 || c
->die_tag
== DW_TAG_structure_type
7188 || c
->die_tag
== DW_TAG_union_type
)
7190 /* Look for nested types that can be broken out. */
7191 break_out_comdat_types (c
);
7193 } while (next
!= NULL
);
7196 /* Like clone_tree, but additionally enter all the children into
7197 the hash table decl_table. */
7200 clone_tree_hash (dw_die_ref die
, decl_hash_type decl_table
)
7203 dw_die_ref clone
= clone_die (die
);
7204 struct decl_table_entry
*entry
;
7205 decl_table_entry
**slot
= decl_table
.find_slot_with_hash (die
,
7206 htab_hash_pointer (die
), INSERT
);
7207 /* Assert that DIE isn't in the hash table yet. If it would be there
7208 before, the ancestors would be necessarily there as well, therefore
7209 clone_tree_hash wouldn't be called. */
7210 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7211 entry
= XCNEW (struct decl_table_entry
);
7213 entry
->copy
= clone
;
7216 FOR_EACH_CHILD (die
, c
,
7217 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7222 /* Walk the DIE and its children, looking for references to incomplete
7223 or trivial types that are unmarked (i.e., that are not in the current
7227 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
7233 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7235 if (AT_class (a
) == dw_val_class_die_ref
)
7237 dw_die_ref targ
= AT_ref (a
);
7238 decl_table_entry
**slot
;
7239 struct decl_table_entry
*entry
;
7241 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7244 slot
= decl_table
.find_slot_with_hash (targ
, htab_hash_pointer (targ
),
7247 if (*slot
!= HTAB_EMPTY_ENTRY
)
7249 /* TARG has already been copied, so we just need to
7250 modify the reference to point to the copy. */
7252 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7256 dw_die_ref parent
= unit
;
7257 dw_die_ref copy
= clone_die (targ
);
7259 /* Record in DECL_TABLE that TARG has been copied.
7260 Need to do this now, before the recursive call,
7261 because DECL_TABLE may be expanded and SLOT
7262 would no longer be a valid pointer. */
7263 entry
= XCNEW (struct decl_table_entry
);
7268 FOR_EACH_CHILD (targ
, c
,
7269 add_child_die (copy
,
7270 clone_tree_hash (c
, decl_table
)));
7272 /* Make sure the cloned tree is marked as part of the
7276 /* If TARG has surrounding context, copy its ancestor tree
7277 into the new type unit. */
7278 if (targ
->die_parent
!= NULL
7279 && !is_unit_die (targ
->die_parent
))
7280 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7283 add_child_die (parent
, copy
);
7284 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7286 /* Make sure the newly-copied DIE is walked. If it was
7287 installed in a previously-added context, it won't
7288 get visited otherwise. */
7291 /* Find the highest point of the newly-added tree,
7292 mark each node along the way, and walk from there. */
7293 parent
->die_mark
= 1;
7294 while (parent
->die_parent
7295 && parent
->die_parent
->die_mark
== 0)
7297 parent
= parent
->die_parent
;
7298 parent
->die_mark
= 1;
7300 copy_decls_walk (unit
, parent
, decl_table
);
7306 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7309 /* Copy declarations for "unworthy" types into the new comdat section.
7310 Incomplete types, modified types, and certain other types aren't broken
7311 out into comdat sections of their own, so they don't have a signature,
7312 and we need to copy the declaration into the same section so that we
7313 don't have an external reference. */
7316 copy_decls_for_unworthy_types (dw_die_ref unit
)
7318 decl_hash_type decl_table
;
7321 decl_table
.create (10);
7322 copy_decls_walk (unit
, unit
, decl_table
);
7323 decl_table
.dispose ();
7327 /* Traverse the DIE and add a sibling attribute if it may have the
7328 effect of speeding up access to siblings. To save some space,
7329 avoid generating sibling attributes for DIE's without children. */
7332 add_sibling_attributes (dw_die_ref die
)
7336 if (! die
->die_child
)
7339 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7340 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7342 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7345 /* Output all location lists for the DIE and its children. */
7348 output_location_lists (dw_die_ref die
)
7354 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7355 if (AT_class (a
) == dw_val_class_loc_list
)
7356 output_loc_list (AT_loc_list (a
));
7358 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7361 /* We want to limit the number of external references, because they are
7362 larger than local references: a relocation takes multiple words, and
7363 even a sig8 reference is always eight bytes, whereas a local reference
7364 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7365 So if we encounter multiple external references to the same type DIE, we
7366 make a local typedef stub for it and redirect all references there.
7368 This is the element of the hash table for keeping track of these
7378 /* Hashtable helpers. */
7380 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7382 typedef external_ref value_type
;
7383 typedef external_ref compare_type
;
7384 static inline hashval_t
hash (const value_type
*);
7385 static inline bool equal (const value_type
*, const compare_type
*);
7389 external_ref_hasher::hash (const value_type
*r
)
7391 return htab_hash_pointer (r
->type
);
7395 external_ref_hasher::equal (const value_type
*r1
, const compare_type
*r2
)
7397 return r1
->type
== r2
->type
;
7400 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7402 /* Return a pointer to the external_ref for references to DIE. */
7404 static struct external_ref
*
7405 lookup_external_ref (external_ref_hash_type map
, dw_die_ref die
)
7407 struct external_ref ref
, *ref_p
;
7408 external_ref
**slot
;
7411 slot
= map
.find_slot (&ref
, INSERT
);
7412 if (*slot
!= HTAB_EMPTY_ENTRY
)
7415 ref_p
= XCNEW (struct external_ref
);
7421 /* Subroutine of optimize_external_refs, below.
7423 If we see a type skeleton, record it as our stub. If we see external
7424 references, remember how many we've seen. */
7427 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type map
)
7432 struct external_ref
*ref_p
;
7434 if (is_type_die (die
)
7435 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7437 /* This is a local skeleton; use it for local references. */
7438 ref_p
= lookup_external_ref (map
, c
);
7442 /* Scan the DIE references, and remember any that refer to DIEs from
7443 other CUs (i.e. those which are not marked). */
7444 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7445 if (AT_class (a
) == dw_val_class_die_ref
7446 && (c
= AT_ref (a
))->die_mark
== 0
7449 ref_p
= lookup_external_ref (map
, c
);
7453 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7456 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7457 points to an external_ref, DATA is the CU we're processing. If we don't
7458 already have a local stub, and we have multiple refs, build a stub. */
7461 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7463 struct external_ref
*ref_p
= *slot
;
7465 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7467 /* We have multiple references to this type, so build a small stub.
7468 Both of these forms are a bit dodgy from the perspective of the
7469 DWARF standard, since technically they should have names. */
7470 dw_die_ref cu
= data
;
7471 dw_die_ref type
= ref_p
->type
;
7472 dw_die_ref stub
= NULL
;
7474 if (type
->comdat_type_p
)
7476 /* If we refer to this type via sig8, use AT_signature. */
7477 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7478 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7482 /* Otherwise, use a typedef with no name. */
7483 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7484 add_AT_die_ref (stub
, DW_AT_type
, type
);
7493 /* DIE is a unit; look through all the DIE references to see if there are
7494 any external references to types, and if so, create local stubs for
7495 them which will be applied in build_abbrev_table. This is useful because
7496 references to local DIEs are smaller. */
7498 static external_ref_hash_type
7499 optimize_external_refs (dw_die_ref die
)
7501 external_ref_hash_type map
;
7503 optimize_external_refs_1 (die
, map
);
7504 map
.traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7508 /* The format of each DIE (and its attribute value pairs) is encoded in an
7509 abbreviation table. This routine builds the abbreviation table and assigns
7510 a unique abbreviation id for each abbreviation entry. The children of each
7511 die are visited recursively. */
7514 build_abbrev_table (dw_die_ref die
, external_ref_hash_type extern_map
)
7516 unsigned long abbrev_id
;
7517 unsigned int n_alloc
;
7522 /* Scan the DIE references, and replace any that refer to
7523 DIEs from other CUs (i.e. those which are not marked) with
7524 the local stubs we built in optimize_external_refs. */
7525 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7526 if (AT_class (a
) == dw_val_class_die_ref
7527 && (c
= AT_ref (a
))->die_mark
== 0)
7529 struct external_ref
*ref_p
;
7530 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7532 ref_p
= lookup_external_ref (extern_map
, c
);
7533 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7534 change_AT_die_ref (a
, ref_p
->stub
);
7536 /* We aren't changing this reference, so mark it external. */
7537 set_AT_ref_external (a
, 1);
7540 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7542 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7543 dw_attr_ref die_a
, abbrev_a
;
7547 if (abbrev
->die_tag
!= die
->die_tag
)
7549 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7552 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7555 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7557 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7558 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7559 || (value_format (abbrev_a
) != value_format (die_a
)))
7569 if (abbrev_id
>= abbrev_die_table_in_use
)
7571 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7573 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7574 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7577 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7578 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7579 abbrev_die_table_allocated
= n_alloc
;
7582 ++abbrev_die_table_in_use
;
7583 abbrev_die_table
[abbrev_id
] = die
;
7586 die
->die_abbrev
= abbrev_id
;
7587 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7590 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7593 constant_size (unsigned HOST_WIDE_INT value
)
7600 log
= floor_log2 (value
);
7603 log
= 1 << (floor_log2 (log
) + 1);
7608 /* Return the size of a DIE as it is represented in the
7609 .debug_info section. */
7611 static unsigned long
7612 size_of_die (dw_die_ref die
)
7614 unsigned long size
= 0;
7617 enum dwarf_form form
;
7619 size
+= size_of_uleb128 (die
->die_abbrev
);
7620 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7622 switch (AT_class (a
))
7624 case dw_val_class_addr
:
7625 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7627 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7628 size
+= size_of_uleb128 (AT_index (a
));
7631 size
+= DWARF2_ADDR_SIZE
;
7633 case dw_val_class_offset
:
7634 size
+= DWARF_OFFSET_SIZE
;
7636 case dw_val_class_loc
:
7638 unsigned long lsize
= size_of_locs (AT_loc (a
));
7641 if (dwarf_version
>= 4)
7642 size
+= size_of_uleb128 (lsize
);
7644 size
+= constant_size (lsize
);
7648 case dw_val_class_loc_list
:
7649 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7651 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7652 size
+= size_of_uleb128 (AT_index (a
));
7655 size
+= DWARF_OFFSET_SIZE
;
7657 case dw_val_class_range_list
:
7658 size
+= DWARF_OFFSET_SIZE
;
7660 case dw_val_class_const
:
7661 size
+= size_of_sleb128 (AT_int (a
));
7663 case dw_val_class_unsigned_const
:
7665 int csize
= constant_size (AT_unsigned (a
));
7666 if (dwarf_version
== 3
7667 && a
->dw_attr
== DW_AT_data_member_location
7669 size
+= size_of_uleb128 (AT_unsigned (a
));
7674 case dw_val_class_const_double
:
7675 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7676 if (HOST_BITS_PER_WIDE_INT
>= 64)
7679 case dw_val_class_vec
:
7680 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7681 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7682 + a
->dw_attr_val
.v
.val_vec
.length
7683 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7685 case dw_val_class_flag
:
7686 if (dwarf_version
>= 4)
7687 /* Currently all add_AT_flag calls pass in 1 as last argument,
7688 so DW_FORM_flag_present can be used. If that ever changes,
7689 we'll need to use DW_FORM_flag and have some optimization
7690 in build_abbrev_table that will change those to
7691 DW_FORM_flag_present if it is set to 1 in all DIEs using
7692 the same abbrev entry. */
7693 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7697 case dw_val_class_die_ref
:
7698 if (AT_ref_external (a
))
7700 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7701 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7702 is sized by target address length, whereas in DWARF3
7703 it's always sized as an offset. */
7704 if (use_debug_types
)
7705 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7706 else if (dwarf_version
== 2)
7707 size
+= DWARF2_ADDR_SIZE
;
7709 size
+= DWARF_OFFSET_SIZE
;
7712 size
+= DWARF_OFFSET_SIZE
;
7714 case dw_val_class_fde_ref
:
7715 size
+= DWARF_OFFSET_SIZE
;
7717 case dw_val_class_lbl_id
:
7718 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7720 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7721 size
+= size_of_uleb128 (AT_index (a
));
7724 size
+= DWARF2_ADDR_SIZE
;
7726 case dw_val_class_lineptr
:
7727 case dw_val_class_macptr
:
7728 size
+= DWARF_OFFSET_SIZE
;
7730 case dw_val_class_str
:
7731 form
= AT_string_form (a
);
7732 if (form
== DW_FORM_strp
)
7733 size
+= DWARF_OFFSET_SIZE
;
7734 else if (form
== DW_FORM_GNU_str_index
)
7735 size
+= size_of_uleb128 (AT_index (a
));
7737 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7739 case dw_val_class_file
:
7740 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7742 case dw_val_class_data8
:
7745 case dw_val_class_vms_delta
:
7746 size
+= DWARF_OFFSET_SIZE
;
7748 case dw_val_class_high_pc
:
7749 size
+= DWARF2_ADDR_SIZE
;
7759 /* Size the debugging information associated with a given DIE. Visits the
7760 DIE's children recursively. Updates the global variable next_die_offset, on
7761 each time through. Uses the current value of next_die_offset to update the
7762 die_offset field in each DIE. */
7765 calc_die_sizes (dw_die_ref die
)
7769 gcc_assert (die
->die_offset
== 0
7770 || (unsigned long int) die
->die_offset
== next_die_offset
);
7771 die
->die_offset
= next_die_offset
;
7772 next_die_offset
+= size_of_die (die
);
7774 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7776 if (die
->die_child
!= NULL
)
7777 /* Count the null byte used to terminate sibling lists. */
7778 next_die_offset
+= 1;
7781 /* Size just the base type children at the start of the CU.
7782 This is needed because build_abbrev needs to size locs
7783 and sizing of type based stack ops needs to know die_offset
7784 values for the base types. */
7787 calc_base_type_die_sizes (void)
7789 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
7791 dw_die_ref base_type
;
7792 #if ENABLE_ASSERT_CHECKING
7793 dw_die_ref prev
= comp_unit_die ()->die_child
;
7796 die_offset
+= size_of_die (comp_unit_die ());
7797 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
7799 #if ENABLE_ASSERT_CHECKING
7800 gcc_assert (base_type
->die_offset
== 0
7801 && prev
->die_sib
== base_type
7802 && base_type
->die_child
== NULL
7803 && base_type
->die_abbrev
);
7806 base_type
->die_offset
= die_offset
;
7807 die_offset
+= size_of_die (base_type
);
7811 /* Set the marks for a die and its children. We do this so
7812 that we know whether or not a reference needs to use FORM_ref_addr; only
7813 DIEs in the same CU will be marked. We used to clear out the offset
7814 and use that as the flag, but ran into ordering problems. */
7817 mark_dies (dw_die_ref die
)
7821 gcc_assert (!die
->die_mark
);
7824 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
7827 /* Clear the marks for a die and its children. */
7830 unmark_dies (dw_die_ref die
)
7834 if (! use_debug_types
)
7835 gcc_assert (die
->die_mark
);
7838 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
7841 /* Clear the marks for a die, its children and referred dies. */
7844 unmark_all_dies (dw_die_ref die
)
7854 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
7856 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7857 if (AT_class (a
) == dw_val_class_die_ref
)
7858 unmark_all_dies (AT_ref (a
));
7861 /* Return the size of the .debug_pubnames or .debug_pubtypes table
7862 generated for the compilation unit. */
7864 static unsigned long
7865 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
7871 size
= DWARF_PUBNAMES_HEADER_SIZE
;
7872 FOR_EACH_VEC_ELT (*names
, i
, p
)
7873 if (names
!= pubtype_table
7874 || p
->die
->die_offset
!= 0
7875 || !flag_eliminate_unused_debug_types
)
7876 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1;
7878 size
+= DWARF_OFFSET_SIZE
;
7882 /* Return the size of the information in the .debug_aranges section. */
7884 static unsigned long
7885 size_of_aranges (void)
7889 size
= DWARF_ARANGES_HEADER_SIZE
;
7891 /* Count the address/length pair for this compilation unit. */
7892 if (text_section_used
)
7893 size
+= 2 * DWARF2_ADDR_SIZE
;
7894 if (cold_text_section_used
)
7895 size
+= 2 * DWARF2_ADDR_SIZE
;
7896 if (have_multiple_function_sections
)
7901 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
7903 if (DECL_IGNORED_P (fde
->decl
))
7905 if (!fde
->in_std_section
)
7906 size
+= 2 * DWARF2_ADDR_SIZE
;
7907 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
7908 size
+= 2 * DWARF2_ADDR_SIZE
;
7912 /* Count the two zero words used to terminated the address range table. */
7913 size
+= 2 * DWARF2_ADDR_SIZE
;
7917 /* Select the encoding of an attribute value. */
7919 static enum dwarf_form
7920 value_format (dw_attr_ref a
)
7922 switch (AT_class (a
))
7924 case dw_val_class_addr
:
7925 /* Only very few attributes allow DW_FORM_addr. */
7930 case DW_AT_entry_pc
:
7931 case DW_AT_trampoline
:
7932 return (AT_index (a
) == NOT_INDEXED
7933 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
7937 switch (DWARF2_ADDR_SIZE
)
7940 return DW_FORM_data1
;
7942 return DW_FORM_data2
;
7944 return DW_FORM_data4
;
7946 return DW_FORM_data8
;
7950 case dw_val_class_range_list
:
7951 case dw_val_class_loc_list
:
7952 if (dwarf_version
>= 4)
7953 return DW_FORM_sec_offset
;
7955 case dw_val_class_vms_delta
:
7956 case dw_val_class_offset
:
7957 switch (DWARF_OFFSET_SIZE
)
7960 return DW_FORM_data4
;
7962 return DW_FORM_data8
;
7966 case dw_val_class_loc
:
7967 if (dwarf_version
>= 4)
7968 return DW_FORM_exprloc
;
7969 switch (constant_size (size_of_locs (AT_loc (a
))))
7972 return DW_FORM_block1
;
7974 return DW_FORM_block2
;
7976 return DW_FORM_block4
;
7980 case dw_val_class_const
:
7981 return DW_FORM_sdata
;
7982 case dw_val_class_unsigned_const
:
7983 switch (constant_size (AT_unsigned (a
)))
7986 return DW_FORM_data1
;
7988 return DW_FORM_data2
;
7990 /* In DWARF3 DW_AT_data_member_location with
7991 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
7992 constant, so we need to use DW_FORM_udata if we need
7993 a large constant. */
7994 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7995 return DW_FORM_udata
;
7996 return DW_FORM_data4
;
7998 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
7999 return DW_FORM_udata
;
8000 return DW_FORM_data8
;
8004 case dw_val_class_const_double
:
8005 switch (HOST_BITS_PER_WIDE_INT
)
8008 return DW_FORM_data2
;
8010 return DW_FORM_data4
;
8012 return DW_FORM_data8
;
8015 return DW_FORM_block1
;
8017 case dw_val_class_vec
:
8018 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8019 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8022 return DW_FORM_block1
;
8024 return DW_FORM_block2
;
8026 return DW_FORM_block4
;
8030 case dw_val_class_flag
:
8031 if (dwarf_version
>= 4)
8033 /* Currently all add_AT_flag calls pass in 1 as last argument,
8034 so DW_FORM_flag_present can be used. If that ever changes,
8035 we'll need to use DW_FORM_flag and have some optimization
8036 in build_abbrev_table that will change those to
8037 DW_FORM_flag_present if it is set to 1 in all DIEs using
8038 the same abbrev entry. */
8039 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8040 return DW_FORM_flag_present
;
8042 return DW_FORM_flag
;
8043 case dw_val_class_die_ref
:
8044 if (AT_ref_external (a
))
8045 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8048 case dw_val_class_fde_ref
:
8049 return DW_FORM_data
;
8050 case dw_val_class_lbl_id
:
8051 return (AT_index (a
) == NOT_INDEXED
8052 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8053 case dw_val_class_lineptr
:
8054 case dw_val_class_macptr
:
8055 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8056 case dw_val_class_str
:
8057 return AT_string_form (a
);
8058 case dw_val_class_file
:
8059 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8062 return DW_FORM_data1
;
8064 return DW_FORM_data2
;
8066 return DW_FORM_data4
;
8071 case dw_val_class_data8
:
8072 return DW_FORM_data8
;
8074 case dw_val_class_high_pc
:
8075 switch (DWARF2_ADDR_SIZE
)
8078 return DW_FORM_data1
;
8080 return DW_FORM_data2
;
8082 return DW_FORM_data4
;
8084 return DW_FORM_data8
;
8094 /* Output the encoding of an attribute value. */
8097 output_value_format (dw_attr_ref a
)
8099 enum dwarf_form form
= value_format (a
);
8101 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8104 /* Given a die and id, produce the appropriate abbreviations. */
8107 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8112 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8113 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8114 dwarf_tag_name (abbrev
->die_tag
));
8116 if (abbrev
->die_child
!= NULL
)
8117 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8119 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8121 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8123 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8124 dwarf_attr_name (a_attr
->dw_attr
));
8125 output_value_format (a_attr
);
8128 dw2_asm_output_data (1, 0, NULL
);
8129 dw2_asm_output_data (1, 0, NULL
);
8133 /* Output the .debug_abbrev section which defines the DIE abbreviation
8137 output_abbrev_section (void)
8139 unsigned long abbrev_id
;
8141 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8142 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8144 /* Terminate the table. */
8145 dw2_asm_output_data (1, 0, NULL
);
8148 /* Output a symbol we can use to refer to this DIE from another CU. */
8151 output_die_symbol (dw_die_ref die
)
8153 const char *sym
= die
->die_id
.die_symbol
;
8155 gcc_assert (!die
->comdat_type_p
);
8160 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8161 /* We make these global, not weak; if the target doesn't support
8162 .linkonce, it doesn't support combining the sections, so debugging
8164 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8166 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8169 /* Return a new location list, given the begin and end range, and the
8172 static inline dw_loc_list_ref
8173 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8174 const char *section
)
8176 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8178 retlist
->begin
= begin
;
8179 retlist
->begin_entry
= NULL
;
8181 retlist
->expr
= expr
;
8182 retlist
->section
= section
;
8187 /* Generate a new internal symbol for this location list node, if it
8188 hasn't got one yet. */
8191 gen_llsym (dw_loc_list_ref list
)
8193 gcc_assert (!list
->ll_symbol
);
8194 list
->ll_symbol
= gen_internal_sym ("LLST");
8197 /* Output the location list given to us. */
8200 output_loc_list (dw_loc_list_ref list_head
)
8202 dw_loc_list_ref curr
= list_head
;
8204 if (list_head
->emitted
)
8206 list_head
->emitted
= true;
8208 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8210 /* Walk the location list, and output each range + expression. */
8211 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8214 /* Don't output an entry that starts and ends at the same address. */
8215 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8217 size
= size_of_locs (curr
->expr
);
8218 /* If the expression is too large, drop it on the floor. We could
8219 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8220 in the expression, but >= 64KB expressions for a single value
8221 in a single range are unlikely very useful. */
8224 if (dwarf_split_debug_info
)
8226 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8227 "Location list start/length entry (%s)",
8228 list_head
->ll_symbol
);
8229 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8230 "Location list range start index (%s)",
8232 /* The length field is 4 bytes. If we ever need to support
8233 an 8-byte length, we can add a new DW_LLE code or fall back
8234 to DW_LLE_GNU_start_end_entry. */
8235 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8236 "Location list range length (%s)",
8237 list_head
->ll_symbol
);
8239 else if (!have_multiple_function_sections
)
8241 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8242 "Location list begin address (%s)",
8243 list_head
->ll_symbol
);
8244 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8245 "Location list end address (%s)",
8246 list_head
->ll_symbol
);
8250 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8251 "Location list begin address (%s)",
8252 list_head
->ll_symbol
);
8253 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8254 "Location list end address (%s)",
8255 list_head
->ll_symbol
);
8258 /* Output the block length for this list of location operations. */
8259 gcc_assert (size
<= 0xffff);
8260 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8262 output_loc_sequence (curr
->expr
, -1);
8265 if (dwarf_split_debug_info
)
8266 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8267 "Location list terminator (%s)",
8268 list_head
->ll_symbol
);
8271 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8272 "Location list terminator begin (%s)",
8273 list_head
->ll_symbol
);
8274 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8275 "Location list terminator end (%s)",
8276 list_head
->ll_symbol
);
8280 /* Output a range_list offset into the debug_range section. Emit a
8281 relocated reference if val_entry is NULL, otherwise, emit an
8282 indirect reference. */
8285 output_range_list_offset (dw_attr_ref a
)
8287 const char *name
= dwarf_attr_name (a
->dw_attr
);
8289 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8291 char *p
= strchr (ranges_section_label
, '\0');
8292 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8293 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8294 debug_ranges_section
, "%s", name
);
8298 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8299 "%s (offset from %s)", name
, ranges_section_label
);
8302 /* Output the offset into the debug_loc section. */
8305 output_loc_list_offset (dw_attr_ref a
)
8307 char *sym
= AT_loc_list (a
)->ll_symbol
;
8310 if (dwarf_split_debug_info
)
8311 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8312 "%s", dwarf_attr_name (a
->dw_attr
));
8314 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8315 "%s", dwarf_attr_name (a
->dw_attr
));
8318 /* Output an attribute's index or value appropriately. */
8321 output_attr_index_or_value (dw_attr_ref a
)
8323 const char *name
= dwarf_attr_name (a
->dw_attr
);
8325 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8327 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8330 switch (AT_class (a
))
8332 case dw_val_class_addr
:
8333 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8335 case dw_val_class_high_pc
:
8336 case dw_val_class_lbl_id
:
8337 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8339 case dw_val_class_loc_list
:
8340 output_loc_list_offset (a
);
8347 /* Output a type signature. */
8350 output_signature (const char *sig
, const char *name
)
8354 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8355 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8358 /* Output the DIE and its attributes. Called recursively to generate
8359 the definitions of each child DIE. */
8362 output_die (dw_die_ref die
)
8369 /* If someone in another CU might refer to us, set up a symbol for
8370 them to point to. */
8371 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8372 output_die_symbol (die
);
8374 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8375 (unsigned long)die
->die_offset
,
8376 dwarf_tag_name (die
->die_tag
));
8378 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8380 const char *name
= dwarf_attr_name (a
->dw_attr
);
8382 switch (AT_class (a
))
8384 case dw_val_class_addr
:
8385 output_attr_index_or_value (a
);
8388 case dw_val_class_offset
:
8389 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8393 case dw_val_class_range_list
:
8394 output_range_list_offset (a
);
8397 case dw_val_class_loc
:
8398 size
= size_of_locs (AT_loc (a
));
8400 /* Output the block length for this list of location operations. */
8401 if (dwarf_version
>= 4)
8402 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8404 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8406 output_loc_sequence (AT_loc (a
), -1);
8409 case dw_val_class_const
:
8410 /* ??? It would be slightly more efficient to use a scheme like is
8411 used for unsigned constants below, but gdb 4.x does not sign
8412 extend. Gdb 5.x does sign extend. */
8413 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8416 case dw_val_class_unsigned_const
:
8418 int csize
= constant_size (AT_unsigned (a
));
8419 if (dwarf_version
== 3
8420 && a
->dw_attr
== DW_AT_data_member_location
8422 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8424 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8428 case dw_val_class_const_double
:
8430 unsigned HOST_WIDE_INT first
, second
;
8432 if (HOST_BITS_PER_WIDE_INT
>= 64)
8433 dw2_asm_output_data (1,
8434 HOST_BITS_PER_DOUBLE_INT
8435 / HOST_BITS_PER_CHAR
,
8438 if (WORDS_BIG_ENDIAN
)
8440 first
= a
->dw_attr_val
.v
.val_double
.high
;
8441 second
= a
->dw_attr_val
.v
.val_double
.low
;
8445 first
= a
->dw_attr_val
.v
.val_double
.low
;
8446 second
= a
->dw_attr_val
.v
.val_double
.high
;
8449 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8451 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8456 case dw_val_class_vec
:
8458 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8459 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8463 dw2_asm_output_data (constant_size (len
* elt_size
),
8464 len
* elt_size
, "%s", name
);
8465 if (elt_size
> sizeof (HOST_WIDE_INT
))
8470 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8473 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8474 "fp or vector constant word %u", i
);
8478 case dw_val_class_flag
:
8479 if (dwarf_version
>= 4)
8481 /* Currently all add_AT_flag calls pass in 1 as last argument,
8482 so DW_FORM_flag_present can be used. If that ever changes,
8483 we'll need to use DW_FORM_flag and have some optimization
8484 in build_abbrev_table that will change those to
8485 DW_FORM_flag_present if it is set to 1 in all DIEs using
8486 the same abbrev entry. */
8487 gcc_assert (AT_flag (a
) == 1);
8489 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8490 ASM_COMMENT_START
, name
);
8493 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8496 case dw_val_class_loc_list
:
8497 output_attr_index_or_value (a
);
8500 case dw_val_class_die_ref
:
8501 if (AT_ref_external (a
))
8503 if (AT_ref (a
)->comdat_type_p
)
8505 comdat_type_node_ref type_node
=
8506 AT_ref (a
)->die_id
.die_type_node
;
8508 gcc_assert (type_node
);
8509 output_signature (type_node
->signature
, name
);
8513 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8517 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8518 length, whereas in DWARF3 it's always sized as an
8520 if (dwarf_version
== 2)
8521 size
= DWARF2_ADDR_SIZE
;
8523 size
= DWARF_OFFSET_SIZE
;
8524 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8530 gcc_assert (AT_ref (a
)->die_offset
);
8531 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8536 case dw_val_class_fde_ref
:
8540 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8541 a
->dw_attr_val
.v
.val_fde_index
* 2);
8542 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8547 case dw_val_class_vms_delta
:
8548 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8549 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8553 case dw_val_class_lbl_id
:
8554 output_attr_index_or_value (a
);
8557 case dw_val_class_lineptr
:
8558 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8559 debug_line_section
, "%s", name
);
8562 case dw_val_class_macptr
:
8563 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8564 debug_macinfo_section
, "%s", name
);
8567 case dw_val_class_str
:
8568 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8569 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8570 a
->dw_attr_val
.v
.val_str
->label
,
8572 "%s: \"%s\"", name
, AT_string (a
));
8573 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8574 dw2_asm_output_data_uleb128 (AT_index (a
),
8575 "%s: \"%s\"", name
, AT_string (a
));
8577 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8580 case dw_val_class_file
:
8582 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8584 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8585 a
->dw_attr_val
.v
.val_file
->filename
);
8589 case dw_val_class_data8
:
8593 for (i
= 0; i
< 8; i
++)
8594 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8595 i
== 0 ? "%s" : NULL
, name
);
8599 case dw_val_class_high_pc
:
8600 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8601 get_AT_low_pc (die
), "DW_AT_high_pc");
8609 FOR_EACH_CHILD (die
, c
, output_die (c
));
8611 /* Add null byte to terminate sibling list. */
8612 if (die
->die_child
!= NULL
)
8613 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8614 (unsigned long) die
->die_offset
);
8617 /* Output the compilation unit that appears at the beginning of the
8618 .debug_info section, and precedes the DIE descriptions. */
8621 output_compilation_unit_header (void)
8623 int ver
= dwarf_version
;
8625 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8626 dw2_asm_output_data (4, 0xffffffff,
8627 "Initial length escape value indicating 64-bit DWARF extension");
8628 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8629 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8630 "Length of Compilation Unit Info");
8631 dw2_asm_output_data (2, ver
, "DWARF version number");
8632 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8633 debug_abbrev_section
,
8634 "Offset Into Abbrev. Section");
8635 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8638 /* Output the compilation unit DIE and its children. */
8641 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8643 const char *secname
, *oldsym
;
8645 external_ref_hash_type extern_map
;
8647 /* Unless we are outputting main CU, we may throw away empty ones. */
8648 if (!output_if_empty
&& die
->die_child
== NULL
)
8651 /* Even if there are no children of this DIE, we must output the information
8652 about the compilation unit. Otherwise, on an empty translation unit, we
8653 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8654 will then complain when examining the file. First mark all the DIEs in
8655 this CU so we know which get local refs. */
8658 extern_map
= optimize_external_refs (die
);
8660 build_abbrev_table (die
, extern_map
);
8662 extern_map
.dispose ();
8664 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8665 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8666 calc_die_sizes (die
);
8668 oldsym
= die
->die_id
.die_symbol
;
8671 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8673 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8675 die
->die_id
.die_symbol
= NULL
;
8676 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8680 switch_to_section (debug_info_section
);
8681 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8682 info_section_emitted
= true;
8685 /* Output debugging information. */
8686 output_compilation_unit_header ();
8689 /* Leave the marks on the main CU, so we can check them in
8694 die
->die_id
.die_symbol
= oldsym
;
8698 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8699 and .debug_pubtypes. This is configured per-target, but can be
8700 overridden by the -gpubnames or -gno-pubnames options. */
8703 want_pubnames (void)
8705 return (debug_generate_pub_sections
!= -1
8706 ? debug_generate_pub_sections
8707 : targetm
.want_debug_pub_sections
);
8710 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
8713 add_AT_pubnames (dw_die_ref die
)
8715 if (want_pubnames ())
8716 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
8719 /* Add a string attribute value to a skeleton DIE. */
8722 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
8726 struct indirect_string_node
*node
;
8728 if (! skeleton_debug_str_hash
)
8729 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
8730 debug_str_eq
, NULL
);
8732 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
8733 find_string_form (node
);
8734 if (node
->form
== DW_FORM_GNU_str_index
)
8735 node
->form
= DW_FORM_strp
;
8737 attr
.dw_attr
= attr_kind
;
8738 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
8739 attr
.dw_attr_val
.val_entry
= NULL
;
8740 attr
.dw_attr_val
.v
.val_str
= node
;
8741 add_dwarf_attr (die
, &attr
);
8744 /* Helper function to generate top-level dies for skeleton debug_info and
8748 add_top_level_skeleton_die_attrs (dw_die_ref die
)
8750 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
8751 const char *comp_dir
= comp_dir_string ();
8753 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
8754 if (comp_dir
!= NULL
)
8755 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
8756 add_AT_pubnames (die
);
8757 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
8760 /* Return the single type-unit die for skeleton type units. */
8763 get_skeleton_type_unit (void)
8765 /* For dwarf_split_debug_sections with use_type info, all type units in the
8766 skeleton sections have identical dies (but different headers). This
8767 single die will be output many times. */
8769 static dw_die_ref skeleton_type_unit
= NULL
;
8771 if (skeleton_type_unit
== NULL
)
8773 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
8774 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
8775 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
8777 return skeleton_type_unit
;
8780 /* Output skeleton debug sections that point to the dwo file. */
8783 output_skeleton_debug_sections (dw_die_ref comp_unit
)
8785 /* These attributes will be found in the full debug_info section. */
8786 remove_AT (comp_unit
, DW_AT_producer
);
8787 remove_AT (comp_unit
, DW_AT_language
);
8789 switch_to_section (debug_skeleton_info_section
);
8790 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
8792 /* Produce the skeleton compilation-unit header. This one differs enough from
8793 a normal CU header that it's better not to call output_compilation_unit
8795 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8796 dw2_asm_output_data (4, 0xffffffff,
8797 "Initial length escape value indicating 64-bit DWARF extension");
8799 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8800 DWARF_COMPILE_UNIT_HEADER_SIZE
8801 - DWARF_INITIAL_LENGTH_SIZE
8802 + size_of_die (comp_unit
),
8803 "Length of Compilation Unit Info");
8804 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8805 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
8806 debug_abbrev_section
,
8807 "Offset Into Abbrev. Section");
8808 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8810 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
8811 output_die (comp_unit
);
8813 /* Build the skeleton debug_abbrev section. */
8814 switch_to_section (debug_skeleton_abbrev_section
);
8815 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
8817 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
8818 if (use_debug_types
)
8819 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
8821 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
8824 /* Output a comdat type unit DIE and its children. */
8827 output_comdat_type_unit (comdat_type_node
*node
)
8829 const char *secname
;
8832 #if defined (OBJECT_FORMAT_ELF)
8835 external_ref_hash_type extern_map
;
8837 /* First mark all the DIEs in this CU so we know which get local refs. */
8838 mark_dies (node
->root_die
);
8840 extern_map
= optimize_external_refs (node
->root_die
);
8842 build_abbrev_table (node
->root_die
, extern_map
);
8844 extern_map
.dispose ();
8846 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8847 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
8848 calc_die_sizes (node
->root_die
);
8850 #if defined (OBJECT_FORMAT_ELF)
8851 if (!dwarf_split_debug_info
)
8852 secname
= ".debug_types";
8854 secname
= ".debug_types.dwo";
8856 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8857 sprintf (tmp
, "wt.");
8858 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8859 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8860 comdat_key
= get_identifier (tmp
);
8861 targetm
.asm_out
.named_section (secname
,
8862 SECTION_DEBUG
| SECTION_LINKONCE
,
8865 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
8866 sprintf (tmp
, ".gnu.linkonce.wt.");
8867 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8868 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
8870 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8873 /* Output debugging information. */
8874 output_compilation_unit_header ();
8875 output_signature (node
->signature
, "Type Signature");
8876 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
8877 "Offset to Type DIE");
8878 output_die (node
->root_die
);
8880 unmark_dies (node
->root_die
);
8882 #if defined (OBJECT_FORMAT_ELF)
8883 if (dwarf_split_debug_info
)
8885 /* Produce the skeleton type-unit header. */
8886 const char *secname
= ".debug_types";
8888 targetm
.asm_out
.named_section (secname
,
8889 SECTION_DEBUG
| SECTION_LINKONCE
,
8891 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8892 dw2_asm_output_data (4, 0xffffffff,
8893 "Initial length escape value indicating 64-bit DWARF extension");
8895 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8896 DWARF_COMPILE_UNIT_HEADER_SIZE
8897 - DWARF_INITIAL_LENGTH_SIZE
8898 + size_of_die (get_skeleton_type_unit ())
8899 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
8900 "Length of Type Unit Info");
8901 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
8902 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8903 debug_skeleton_abbrev_section_label
,
8904 debug_abbrev_section
,
8905 "Offset Into Abbrev. Section");
8906 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8907 output_signature (node
->signature
, "Type Signature");
8908 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
8910 output_die (get_skeleton_type_unit ());
8915 /* Return the DWARF2/3 pubname associated with a decl. */
8918 dwarf2_name (tree decl
, int scope
)
8920 if (DECL_NAMELESS (decl
))
8922 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
8925 /* Add a new entry to .debug_pubnames if appropriate. */
8928 add_pubname_string (const char *str
, dw_die_ref die
)
8933 e
.name
= xstrdup (str
);
8934 vec_safe_push (pubname_table
, e
);
8938 add_pubname (tree decl
, dw_die_ref die
)
8940 if (!want_pubnames ())
8943 /* Don't add items to the table when we expect that the consumer will have
8944 just read the enclosing die. For example, if the consumer is looking at a
8945 class_member, it will either be inside the class already, or will have just
8946 looked up the class to find the member. Either way, searching the class is
8947 faster than searching the index. */
8948 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
8949 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8951 const char *name
= dwarf2_name (decl
, 1);
8954 add_pubname_string (name
, die
);
8958 /* Add an enumerator to the pubnames section. */
8961 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
8965 gcc_assert (scope_name
);
8966 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
8968 vec_safe_push (pubname_table
, e
);
8971 /* Add a new entry to .debug_pubtypes if appropriate. */
8974 add_pubtype (tree decl
, dw_die_ref die
)
8978 if (!want_pubnames ())
8981 if ((TREE_PUBLIC (decl
)
8982 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
8983 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
8986 const char *scope_name
= "";
8987 const char *sep
= is_cxx () ? "::" : ".";
8990 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
8991 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
8993 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
8994 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
8995 scope_name
= concat (scope_name
, sep
, NULL
);
9001 name
= type_tag (decl
);
9003 name
= lang_hooks
.dwarf_name (decl
, 1);
9005 /* If we don't have a name for the type, there's no point in adding
9007 if (name
!= NULL
&& name
[0] != '\0')
9010 e
.name
= concat (scope_name
, name
, NULL
);
9011 vec_safe_push (pubtype_table
, e
);
9014 /* Although it might be more consistent to add the pubinfo for the
9015 enumerators as their dies are created, they should only be added if the
9016 enum type meets the criteria above. So rather than re-check the parent
9017 enum type whenever an enumerator die is created, just output them all
9018 here. This isn't protected by the name conditional because anonymous
9019 enums don't have names. */
9020 if (die
->die_tag
== DW_TAG_enumeration_type
)
9024 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9029 /* Output the public names table used to speed up access to externally
9030 visible names; or the public types table used to find type definitions. */
9033 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9036 unsigned long pubnames_length
= size_of_pubnames (names
);
9039 if (!want_pubnames () || !info_section_emitted
)
9041 if (names
== pubname_table
)
9042 switch_to_section (debug_pubnames_section
);
9044 switch_to_section (debug_pubtypes_section
);
9045 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9046 dw2_asm_output_data (4, 0xffffffff,
9047 "Initial length escape value indicating 64-bit DWARF extension");
9048 if (names
== pubname_table
)
9049 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9050 "Length of Public Names Info");
9052 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
,
9053 "Length of Public Type Names Info");
9054 /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */
9055 dw2_asm_output_data (2, 2, "DWARF Version");
9056 if (dwarf_split_debug_info
)
9057 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9058 debug_skeleton_info_section
,
9059 "Offset of Compilation Unit Info");
9061 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9063 "Offset of Compilation Unit Info");
9064 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9065 "Compilation Unit Length");
9067 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9069 /* Enumerator names are part of the pubname table, but the parent
9070 DW_TAG_enumeration_type die may have been pruned. Don't output
9071 them if that is the case. */
9072 if (pub
->die
->die_tag
== DW_TAG_enumerator
&&
9073 (pub
->die
->die_parent
== NULL
9074 || !pub
->die
->die_parent
->die_perennial_p
))
9077 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9078 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9079 gcc_assert (pub
->die
->die_mark
);
9081 if (names
!= pubtype_table
9082 || pub
->die
->die_offset
!= 0
9083 || !flag_eliminate_unused_debug_types
)
9085 dw_offset die_offset
= pub
->die
->die_offset
;
9087 /* If we're putting types in their own .debug_types sections,
9088 the .debug_pubtypes table will still point to the compile
9089 unit (not the type unit), so we want to use the offset of
9090 the skeleton DIE (if there is one). */
9091 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9093 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9095 if (type_node
!= NULL
)
9096 die_offset
= (type_node
->skeleton_die
!= NULL
9097 ? type_node
->skeleton_die
->die_offset
9101 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9103 dw2_asm_output_nstring (pub
->name
, -1, "external name");
9107 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9110 /* Output the information that goes into the .debug_aranges table.
9111 Namely, define the beginning and ending address range of the
9112 text section generated for this compilation unit. */
9115 output_aranges (unsigned long aranges_length
)
9119 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9120 dw2_asm_output_data (4, 0xffffffff,
9121 "Initial length escape value indicating 64-bit DWARF extension");
9122 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9123 "Length of Address Ranges Info");
9124 /* Version number for aranges is still 2, even in DWARF3. */
9125 dw2_asm_output_data (2, 2, "DWARF Version");
9126 if (dwarf_split_debug_info
)
9127 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9128 debug_skeleton_info_section
,
9129 "Offset of Compilation Unit Info");
9131 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9133 "Offset of Compilation Unit Info");
9134 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9135 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9137 /* We need to align to twice the pointer size here. */
9138 if (DWARF_ARANGES_PAD_SIZE
)
9140 /* Pad using a 2 byte words so that padding is correct for any
9142 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9143 2 * DWARF2_ADDR_SIZE
);
9144 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9145 dw2_asm_output_data (2, 0, NULL
);
9148 /* It is necessary not to output these entries if the sections were
9149 not used; if the sections were not used, the length will be 0 and
9150 the address may end up as 0 if the section is discarded by ld
9151 --gc-sections, leaving an invalid (0, 0) entry that can be
9152 confused with the terminator. */
9153 if (text_section_used
)
9155 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9156 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9157 text_section_label
, "Length");
9159 if (cold_text_section_used
)
9161 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9163 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9164 cold_text_section_label
, "Length");
9167 if (have_multiple_function_sections
)
9172 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9174 if (DECL_IGNORED_P (fde
->decl
))
9176 if (!fde
->in_std_section
)
9178 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9180 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9181 fde
->dw_fde_begin
, "Length");
9183 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9185 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9187 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9188 fde
->dw_fde_second_begin
, "Length");
9193 /* Output the terminator words. */
9194 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9195 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9198 /* Add a new entry to .debug_ranges. Return the offset at which it
9202 add_ranges_num (int num
)
9204 unsigned int in_use
= ranges_table_in_use
;
9206 if (in_use
== ranges_table_allocated
)
9208 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9209 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9210 ranges_table_allocated
);
9211 memset (ranges_table
+ ranges_table_in_use
, 0,
9212 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9215 ranges_table
[in_use
].num
= num
;
9216 ranges_table_in_use
= in_use
+ 1;
9218 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9221 /* Add a new entry to .debug_ranges corresponding to a block, or a
9222 range terminator if BLOCK is NULL. */
9225 add_ranges (const_tree block
)
9227 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9230 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9231 When using dwarf_split_debug_info, address attributes in dies destined
9232 for the final executable should be direct references--setting the
9233 parameter force_direct ensures this behavior. */
9236 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9237 bool *added
, bool force_direct
)
9239 unsigned int in_use
= ranges_by_label_in_use
;
9240 unsigned int offset
;
9242 if (in_use
== ranges_by_label_allocated
)
9244 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9245 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9247 ranges_by_label_allocated
);
9248 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9249 RANGES_TABLE_INCREMENT
9250 * sizeof (struct dw_ranges_by_label_struct
));
9253 ranges_by_label
[in_use
].begin
= begin
;
9254 ranges_by_label
[in_use
].end
= end
;
9255 ranges_by_label_in_use
= in_use
+ 1;
9257 offset
= add_ranges_num (-(int)in_use
- 1);
9260 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9266 output_ranges (void)
9269 static const char *const start_fmt
= "Offset %#x";
9270 const char *fmt
= start_fmt
;
9272 for (i
= 0; i
< ranges_table_in_use
; i
++)
9274 int block_num
= ranges_table
[i
].num
;
9278 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9279 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9281 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9282 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9284 /* If all code is in the text section, then the compilation
9285 unit base address defaults to DW_AT_low_pc, which is the
9286 base of the text section. */
9287 if (!have_multiple_function_sections
)
9289 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9291 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9292 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9293 text_section_label
, NULL
);
9296 /* Otherwise, the compilation unit base address is zero,
9297 which allows us to use absolute addresses, and not worry
9298 about whether the target supports cross-section
9302 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9303 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9304 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9310 /* Negative block_num stands for an index into ranges_by_label. */
9311 else if (block_num
< 0)
9313 int lab_idx
= - block_num
- 1;
9315 if (!have_multiple_function_sections
)
9319 /* If we ever use add_ranges_by_labels () for a single
9320 function section, all we have to do is to take out
9322 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9323 ranges_by_label
[lab_idx
].begin
,
9325 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9326 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9327 ranges_by_label
[lab_idx
].end
,
9328 text_section_label
, NULL
);
9333 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9334 ranges_by_label
[lab_idx
].begin
,
9335 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9336 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9337 ranges_by_label
[lab_idx
].end
,
9343 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9344 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9350 /* Data structure containing information about input files. */
9353 const char *path
; /* Complete file name. */
9354 const char *fname
; /* File name part. */
9355 int length
; /* Length of entire string. */
9356 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9357 int dir_idx
; /* Index in directory table. */
9360 /* Data structure containing information about directories with source
9364 const char *path
; /* Path including directory name. */
9365 int length
; /* Path length. */
9366 int prefix
; /* Index of directory entry which is a prefix. */
9367 int count
; /* Number of files in this directory. */
9368 int dir_idx
; /* Index of directory used as base. */
9371 /* Callback function for file_info comparison. We sort by looking at
9372 the directories in the path. */
9375 file_info_cmp (const void *p1
, const void *p2
)
9377 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9378 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9379 const unsigned char *cp1
;
9380 const unsigned char *cp2
;
9382 /* Take care of file names without directories. We need to make sure that
9383 we return consistent values to qsort since some will get confused if
9384 we return the same value when identical operands are passed in opposite
9385 orders. So if neither has a directory, return 0 and otherwise return
9386 1 or -1 depending on which one has the directory. */
9387 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9388 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9390 cp1
= (const unsigned char *) s1
->path
;
9391 cp2
= (const unsigned char *) s2
->path
;
9397 /* Reached the end of the first path? If so, handle like above. */
9398 if ((cp1
== (const unsigned char *) s1
->fname
)
9399 || (cp2
== (const unsigned char *) s2
->fname
))
9400 return ((cp2
== (const unsigned char *) s2
->fname
)
9401 - (cp1
== (const unsigned char *) s1
->fname
));
9403 /* Character of current path component the same? */
9404 else if (*cp1
!= *cp2
)
9409 struct file_name_acquire_data
9411 struct file_info
*files
;
9416 /* Traversal function for the hash table. */
9419 file_name_acquire (void ** slot
, void *data
)
9421 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9422 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9423 struct file_info
*fi
;
9426 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9428 if (! d
->emitted_number
)
9431 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9433 fi
= fnad
->files
+ fnad
->used_files
++;
9435 /* Skip all leading "./". */
9437 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9440 /* Create a new array entry. */
9442 fi
->length
= strlen (f
);
9445 /* Search for the file name part. */
9446 f
= strrchr (f
, DIR_SEPARATOR
);
9447 #if defined (DIR_SEPARATOR_2)
9449 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9453 if (f
== NULL
|| f
< g
)
9459 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9463 /* Output the directory table and the file name table. We try to minimize
9464 the total amount of memory needed. A heuristic is used to avoid large
9465 slowdowns with many input files. */
9468 output_file_names (void)
9470 struct file_name_acquire_data fnad
;
9472 struct file_info
*files
;
9473 struct dir_info
*dirs
;
9481 if (!last_emitted_file
)
9483 dw2_asm_output_data (1, 0, "End directory table");
9484 dw2_asm_output_data (1, 0, "End file name table");
9488 numfiles
= last_emitted_file
->emitted_number
;
9490 /* Allocate the various arrays we need. */
9491 files
= XALLOCAVEC (struct file_info
, numfiles
);
9492 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9495 fnad
.used_files
= 0;
9496 fnad
.max_files
= numfiles
;
9497 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9498 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9500 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9502 /* Find all the different directories used. */
9503 dirs
[0].path
= files
[0].path
;
9504 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9505 dirs
[0].prefix
= -1;
9507 dirs
[0].dir_idx
= 0;
9508 files
[0].dir_idx
= 0;
9511 for (i
= 1; i
< numfiles
; i
++)
9512 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9513 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9514 dirs
[ndirs
- 1].length
) == 0)
9516 /* Same directory as last entry. */
9517 files
[i
].dir_idx
= ndirs
- 1;
9518 ++dirs
[ndirs
- 1].count
;
9524 /* This is a new directory. */
9525 dirs
[ndirs
].path
= files
[i
].path
;
9526 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9527 dirs
[ndirs
].count
= 1;
9528 dirs
[ndirs
].dir_idx
= ndirs
;
9529 files
[i
].dir_idx
= ndirs
;
9531 /* Search for a prefix. */
9532 dirs
[ndirs
].prefix
= -1;
9533 for (j
= 0; j
< ndirs
; j
++)
9534 if (dirs
[j
].length
< dirs
[ndirs
].length
9535 && dirs
[j
].length
> 1
9536 && (dirs
[ndirs
].prefix
== -1
9537 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9538 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9539 dirs
[ndirs
].prefix
= j
;
9544 /* Now to the actual work. We have to find a subset of the directories which
9545 allow expressing the file name using references to the directory table
9546 with the least amount of characters. We do not do an exhaustive search
9547 where we would have to check out every combination of every single
9548 possible prefix. Instead we use a heuristic which provides nearly optimal
9549 results in most cases and never is much off. */
9550 saved
= XALLOCAVEC (int, ndirs
);
9551 savehere
= XALLOCAVEC (int, ndirs
);
9553 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9554 for (i
= 0; i
< ndirs
; i
++)
9559 /* We can always save some space for the current directory. But this
9560 does not mean it will be enough to justify adding the directory. */
9561 savehere
[i
] = dirs
[i
].length
;
9562 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9564 for (j
= i
+ 1; j
< ndirs
; j
++)
9567 if (saved
[j
] < dirs
[i
].length
)
9569 /* Determine whether the dirs[i] path is a prefix of the
9574 while (k
!= -1 && k
!= (int) i
)
9579 /* Yes it is. We can possibly save some memory by
9580 writing the filenames in dirs[j] relative to
9582 savehere
[j
] = dirs
[i
].length
;
9583 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9588 /* Check whether we can save enough to justify adding the dirs[i]
9590 if (total
> dirs
[i
].length
+ 1)
9592 /* It's worthwhile adding. */
9593 for (j
= i
; j
< ndirs
; j
++)
9594 if (savehere
[j
] > 0)
9596 /* Remember how much we saved for this directory so far. */
9597 saved
[j
] = savehere
[j
];
9599 /* Remember the prefix directory. */
9600 dirs
[j
].dir_idx
= i
;
9605 /* Emit the directory name table. */
9606 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9607 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9608 dw2_asm_output_nstring (dirs
[i
].path
,
9610 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9611 "Directory Entry: %#x", i
+ idx_offset
);
9613 dw2_asm_output_data (1, 0, "End directory table");
9615 /* We have to emit them in the order of emitted_number since that's
9616 used in the debug info generation. To do this efficiently we
9617 generate a back-mapping of the indices first. */
9618 backmap
= XALLOCAVEC (int, numfiles
);
9619 for (i
= 0; i
< numfiles
; i
++)
9620 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9622 /* Now write all the file names. */
9623 for (i
= 0; i
< numfiles
; i
++)
9625 int file_idx
= backmap
[i
];
9626 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9628 #ifdef VMS_DEBUGGING_INFO
9629 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9631 /* Setting these fields can lead to debugger miscomparisons,
9632 but VMS Debug requires them to be set correctly. */
9637 int maxfilelen
= strlen (files
[file_idx
].path
)
9638 + dirs
[dir_idx
].length
9639 + MAX_VMS_VERSION_LEN
+ 1;
9640 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9642 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9643 snprintf (filebuf
, maxfilelen
, "%s;%d",
9644 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
9646 dw2_asm_output_nstring
9647 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
9649 /* Include directory index. */
9650 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9652 /* Modification time. */
9653 dw2_asm_output_data_uleb128
9654 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
9658 /* File length in bytes. */
9659 dw2_asm_output_data_uleb128
9660 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
9664 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
9665 "File Entry: %#x", (unsigned) i
+ 1);
9667 /* Include directory index. */
9668 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
9670 /* Modification time. */
9671 dw2_asm_output_data_uleb128 (0, NULL
);
9673 /* File length in bytes. */
9674 dw2_asm_output_data_uleb128 (0, NULL
);
9675 #endif /* VMS_DEBUGGING_INFO */
9678 dw2_asm_output_data (1, 0, "End file name table");
9682 /* Output one line number table into the .debug_line section. */
9685 output_one_line_info_table (dw_line_info_table
*table
)
9687 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
9688 unsigned int current_line
= 1;
9689 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
9690 dw_line_info_entry
*ent
;
9693 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
9695 switch (ent
->opcode
)
9697 case LI_set_address
:
9698 /* ??? Unfortunately, we have little choice here currently, and
9699 must always use the most general form. GCC does not know the
9700 address delta itself, so we can't use DW_LNS_advance_pc. Many
9701 ports do have length attributes which will give an upper bound
9702 on the address range. We could perhaps use length attributes
9703 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
9704 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
9706 /* This can handle any delta. This takes
9707 4+DWARF2_ADDR_SIZE bytes. */
9708 dw2_asm_output_data (1, 0, "set address %s", line_label
);
9709 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9710 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9711 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
9715 if (ent
->val
== current_line
)
9717 /* We still need to start a new row, so output a copy insn. */
9718 dw2_asm_output_data (1, DW_LNS_copy
,
9719 "copy line %u", current_line
);
9723 int line_offset
= ent
->val
- current_line
;
9724 int line_delta
= line_offset
- DWARF_LINE_BASE
;
9726 current_line
= ent
->val
;
9727 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
9729 /* This can handle deltas from -10 to 234, using the current
9730 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
9731 This takes 1 byte. */
9732 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
9733 "line %u", current_line
);
9737 /* This can handle any delta. This takes at least 4 bytes,
9738 depending on the value being encoded. */
9739 dw2_asm_output_data (1, DW_LNS_advance_line
,
9740 "advance to line %u", current_line
);
9741 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
9742 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
9748 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
9749 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9753 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
9754 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
9757 case LI_negate_stmt
:
9758 current_is_stmt
= !current_is_stmt
;
9759 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
9760 "is_stmt %d", current_is_stmt
);
9763 case LI_set_prologue_end
:
9764 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
9765 "set prologue end");
9768 case LI_set_epilogue_begin
:
9769 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
9770 "set epilogue begin");
9773 case LI_set_discriminator
:
9774 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
9775 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
9776 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
9777 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
9782 /* Emit debug info for the address of the end of the table. */
9783 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
9784 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
9785 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
9786 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
9788 dw2_asm_output_data (1, 0, "end sequence");
9789 dw2_asm_output_data_uleb128 (1, NULL
);
9790 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
9793 /* Output the source line number correspondence information. This
9794 information goes into the .debug_line section. */
9797 output_line_info (bool prologue_only
)
9799 char l1
[20], l2
[20], p1
[20], p2
[20];
9800 int ver
= dwarf_version
;
9801 bool saw_one
= false;
9804 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
9805 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
9806 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
9807 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
9809 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9810 dw2_asm_output_data (4, 0xffffffff,
9811 "Initial length escape value indicating 64-bit DWARF extension");
9812 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
9813 "Length of Source Line Info");
9814 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
9816 dw2_asm_output_data (2, ver
, "DWARF Version");
9817 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
9818 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
9820 /* Define the architecture-dependent minimum instruction length (in bytes).
9821 In this implementation of DWARF, this field is used for information
9822 purposes only. Since GCC generates assembly language, we have no
9823 a priori knowledge of how many instruction bytes are generated for each
9824 source line, and therefore can use only the DW_LNE_set_address and
9825 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
9826 this as '1', which is "correct enough" for all architectures,
9827 and don't let the target override. */
9828 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
9831 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
9832 "Maximum Operations Per Instruction");
9833 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
9834 "Default is_stmt_start flag");
9835 dw2_asm_output_data (1, DWARF_LINE_BASE
,
9836 "Line Base Value (Special Opcodes)");
9837 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
9838 "Line Range Value (Special Opcodes)");
9839 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
9840 "Special Opcode Base");
9842 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
9847 case DW_LNS_advance_pc
:
9848 case DW_LNS_advance_line
:
9849 case DW_LNS_set_file
:
9850 case DW_LNS_set_column
:
9851 case DW_LNS_fixed_advance_pc
:
9852 case DW_LNS_set_isa
:
9860 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
9864 /* Write out the information about the files we use. */
9865 output_file_names ();
9866 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
9869 /* Output the marker for the end of the line number info. */
9870 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9874 if (separate_line_info
)
9876 dw_line_info_table
*table
;
9879 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
9882 output_one_line_info_table (table
);
9886 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
9888 output_one_line_info_table (cold_text_section_line_info
);
9892 /* ??? Some Darwin linkers crash on a .debug_line section with no
9893 sequences. Further, merely a DW_LNE_end_sequence entry is not
9894 sufficient -- the address column must also be initialized.
9895 Make sure to output at least one set_address/end_sequence pair,
9896 choosing .text since that section is always present. */
9897 if (text_section_line_info
->in_use
|| !saw_one
)
9898 output_one_line_info_table (text_section_line_info
);
9900 /* Output the marker for the end of the line number info. */
9901 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
9904 /* Given a pointer to a tree node for some base type, return a pointer to
9905 a DIE that describes the given type.
9907 This routine must only be called for GCC type nodes that correspond to
9908 Dwarf base (fundamental) types. */
9911 base_type_die (tree type
)
9913 dw_die_ref base_type_result
;
9914 enum dwarf_type encoding
;
9916 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
9919 /* If this is a subtype that should not be emitted as a subrange type,
9920 use the base type. See subrange_type_for_debug_p. */
9921 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
9922 type
= TREE_TYPE (type
);
9924 switch (TREE_CODE (type
))
9927 if ((dwarf_version
>= 4 || !dwarf_strict
)
9929 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
9930 && DECL_IS_BUILTIN (TYPE_NAME (type
))
9931 && DECL_NAME (TYPE_NAME (type
)))
9933 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
9934 if (strcmp (name
, "char16_t") == 0
9935 || strcmp (name
, "char32_t") == 0)
9937 encoding
= DW_ATE_UTF
;
9941 if (TYPE_STRING_FLAG (type
))
9943 if (TYPE_UNSIGNED (type
))
9944 encoding
= DW_ATE_unsigned_char
;
9946 encoding
= DW_ATE_signed_char
;
9948 else if (TYPE_UNSIGNED (type
))
9949 encoding
= DW_ATE_unsigned
;
9951 encoding
= DW_ATE_signed
;
9955 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
9957 if (dwarf_version
>= 3 || !dwarf_strict
)
9958 encoding
= DW_ATE_decimal_float
;
9960 encoding
= DW_ATE_lo_user
;
9963 encoding
= DW_ATE_float
;
9966 case FIXED_POINT_TYPE
:
9967 if (!(dwarf_version
>= 3 || !dwarf_strict
))
9968 encoding
= DW_ATE_lo_user
;
9969 else if (TYPE_UNSIGNED (type
))
9970 encoding
= DW_ATE_unsigned_fixed
;
9972 encoding
= DW_ATE_signed_fixed
;
9975 /* Dwarf2 doesn't know anything about complex ints, so use
9976 a user defined type for it. */
9978 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
9979 encoding
= DW_ATE_complex_float
;
9981 encoding
= DW_ATE_lo_user
;
9985 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
9986 encoding
= DW_ATE_boolean
;
9990 /* No other TREE_CODEs are Dwarf fundamental types. */
9994 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
9996 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
9997 int_size_in_bytes (type
));
9998 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
9999 add_pubtype (type
, base_type_result
);
10001 return base_type_result
;
10004 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10005 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10008 is_base_type (tree type
)
10010 switch (TREE_CODE (type
))
10016 case FIXED_POINT_TYPE
:
10024 case QUAL_UNION_TYPE
:
10025 case ENUMERAL_TYPE
:
10026 case FUNCTION_TYPE
:
10029 case REFERENCE_TYPE
:
10037 gcc_unreachable ();
10043 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10044 node, return the size in bits for the type if it is a constant, or else
10045 return the alignment for the type if the type's size is not constant, or
10046 else return BITS_PER_WORD if the type actually turns out to be an
10047 ERROR_MARK node. */
10049 static inline unsigned HOST_WIDE_INT
10050 simple_type_size_in_bits (const_tree type
)
10052 if (TREE_CODE (type
) == ERROR_MARK
)
10053 return BITS_PER_WORD
;
10054 else if (TYPE_SIZE (type
) == NULL_TREE
)
10056 else if (host_integerp (TYPE_SIZE (type
), 1))
10057 return tree_low_cst (TYPE_SIZE (type
), 1);
10059 return TYPE_ALIGN (type
);
10062 /* Similarly, but return a double_int instead of UHWI. */
10064 static inline double_int
10065 double_int_type_size_in_bits (const_tree type
)
10067 if (TREE_CODE (type
) == ERROR_MARK
)
10068 return double_int::from_uhwi (BITS_PER_WORD
);
10069 else if (TYPE_SIZE (type
) == NULL_TREE
)
10070 return double_int_zero
;
10071 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10072 return tree_to_double_int (TYPE_SIZE (type
));
10074 return double_int::from_uhwi (TYPE_ALIGN (type
));
10077 /* Given a pointer to a tree node for a subrange type, return a pointer
10078 to a DIE that describes the given type. */
10081 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10083 dw_die_ref subrange_die
;
10084 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10086 if (context_die
== NULL
)
10087 context_die
= comp_unit_die ();
10089 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10091 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10093 /* The size of the subrange type and its base type do not match,
10094 so we need to generate a size attribute for the subrange type. */
10095 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10099 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10101 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10103 return subrange_die
;
10106 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10107 entry that chains various modifiers in front of the given type. */
10110 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10111 dw_die_ref context_die
)
10113 enum tree_code code
= TREE_CODE (type
);
10114 dw_die_ref mod_type_die
;
10115 dw_die_ref sub_die
= NULL
;
10116 tree item_type
= NULL
;
10117 tree qualified_type
;
10118 tree name
, low
, high
;
10119 dw_die_ref mod_scope
;
10121 if (code
== ERROR_MARK
)
10124 /* See if we already have the appropriately qualified variant of
10127 = get_qualified_type (type
,
10128 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10129 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10131 if (qualified_type
== sizetype
10132 && TYPE_NAME (qualified_type
)
10133 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10135 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10137 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10138 && TYPE_PRECISION (t
)
10139 == TYPE_PRECISION (qualified_type
)
10140 && TYPE_UNSIGNED (t
)
10141 == TYPE_UNSIGNED (qualified_type
));
10142 qualified_type
= t
;
10145 /* If we do, then we can just use its DIE, if it exists. */
10146 if (qualified_type
)
10148 mod_type_die
= lookup_type_die (qualified_type
);
10150 return mod_type_die
;
10153 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10155 /* Handle C typedef types. */
10156 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10157 && !DECL_ARTIFICIAL (name
))
10159 tree dtype
= TREE_TYPE (name
);
10161 if (qualified_type
== dtype
)
10163 /* For a named type, use the typedef. */
10164 gen_type_die (qualified_type
, context_die
);
10165 return lookup_type_die (qualified_type
);
10167 else if (is_const_type
< TYPE_READONLY (dtype
)
10168 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10169 || (is_const_type
<= TYPE_READONLY (dtype
)
10170 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10171 && DECL_ORIGINAL_TYPE (name
) != type
))
10172 /* cv-unqualified version of named type. Just use the unnamed
10173 type to which it refers. */
10174 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10175 is_const_type
, is_volatile_type
,
10177 /* Else cv-qualified version of named type; fall through. */
10180 mod_scope
= scope_die_for (type
, context_die
);
10183 /* If both is_const_type and is_volatile_type, prefer the path
10184 which leads to a qualified type. */
10185 && (!is_volatile_type
10186 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10187 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10189 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10190 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10192 else if (is_volatile_type
)
10194 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10195 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10197 else if (code
== POINTER_TYPE
)
10199 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10200 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10201 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10202 item_type
= TREE_TYPE (type
);
10203 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10204 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10205 TYPE_ADDR_SPACE (item_type
));
10207 else if (code
== REFERENCE_TYPE
)
10209 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10210 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10213 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10214 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10215 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10216 item_type
= TREE_TYPE (type
);
10217 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10218 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10219 TYPE_ADDR_SPACE (item_type
));
10221 else if (code
== INTEGER_TYPE
10222 && TREE_TYPE (type
) != NULL_TREE
10223 && subrange_type_for_debug_p (type
, &low
, &high
))
10225 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10226 item_type
= TREE_TYPE (type
);
10228 else if (is_base_type (type
))
10229 mod_type_die
= base_type_die (type
);
10232 gen_type_die (type
, context_die
);
10234 /* We have to get the type_main_variant here (and pass that to the
10235 `lookup_type_die' routine) because the ..._TYPE node we have
10236 might simply be a *copy* of some original type node (where the
10237 copy was created to help us keep track of typedef names) and
10238 that copy might have a different TYPE_UID from the original
10240 if (TREE_CODE (type
) != VECTOR_TYPE
)
10241 return lookup_type_die (type_main_variant (type
));
10243 /* Vectors have the debugging information in the type,
10244 not the main variant. */
10245 return lookup_type_die (type
);
10248 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10249 don't output a DW_TAG_typedef, since there isn't one in the
10250 user's program; just attach a DW_AT_name to the type.
10251 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10252 if the base type already has the same name. */
10254 && ((TREE_CODE (name
) != TYPE_DECL
10255 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10256 || (!is_const_type
&& !is_volatile_type
)))
10257 || (TREE_CODE (name
) == TYPE_DECL
10258 && TREE_TYPE (name
) == qualified_type
10259 && DECL_NAME (name
))))
10261 if (TREE_CODE (name
) == TYPE_DECL
)
10262 /* Could just call add_name_and_src_coords_attributes here,
10263 but since this is a builtin type it doesn't have any
10264 useful source coordinates anyway. */
10265 name
= DECL_NAME (name
);
10266 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10268 /* This probably indicates a bug. */
10269 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10271 name
= TYPE_NAME (type
);
10273 && TREE_CODE (name
) == TYPE_DECL
)
10274 name
= DECL_NAME (name
);
10275 add_name_attribute (mod_type_die
,
10276 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10279 if (qualified_type
)
10280 equate_type_number_to_die (qualified_type
, mod_type_die
);
10283 /* We must do this after the equate_type_number_to_die call, in case
10284 this is a recursive type. This ensures that the modified_type_die
10285 recursion will terminate even if the type is recursive. Recursive
10286 types are possible in Ada. */
10287 sub_die
= modified_type_die (item_type
,
10288 TYPE_READONLY (item_type
),
10289 TYPE_VOLATILE (item_type
),
10292 if (sub_die
!= NULL
)
10293 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10295 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10296 if (TYPE_ARTIFICIAL (type
))
10297 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10299 return mod_type_die
;
10302 /* Generate DIEs for the generic parameters of T.
10303 T must be either a generic type or a generic function.
10304 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10307 gen_generic_params_dies (tree t
)
10311 dw_die_ref die
= NULL
;
10314 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10318 die
= lookup_type_die (t
);
10319 else if (DECL_P (t
))
10320 die
= lookup_decl_die (t
);
10324 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10326 /* T has no generic parameter. It means T is neither a generic type
10327 or function. End of story. */
10330 parms_num
= TREE_VEC_LENGTH (parms
);
10331 args
= lang_hooks
.get_innermost_generic_args (t
);
10332 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10333 non_default
= int_cst_value (TREE_CHAIN (args
));
10335 non_default
= TREE_VEC_LENGTH (args
);
10336 for (i
= 0; i
< parms_num
; i
++)
10338 tree parm
, arg
, arg_pack_elems
;
10339 dw_die_ref parm_die
;
10341 parm
= TREE_VEC_ELT (parms
, i
);
10342 arg
= TREE_VEC_ELT (args
, i
);
10343 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10344 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10346 if (parm
&& TREE_VALUE (parm
) && arg
)
10348 /* If PARM represents a template parameter pack,
10349 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10350 by DW_TAG_template_*_parameter DIEs for the argument
10351 pack elements of ARG. Note that ARG would then be
10352 an argument pack. */
10353 if (arg_pack_elems
)
10354 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10358 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10359 true /* emit name */, die
);
10360 if (i
>= non_default
)
10361 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10366 /* Create and return a DIE for PARM which should be
10367 the representation of a generic type parameter.
10368 For instance, in the C++ front end, PARM would be a template parameter.
10369 ARG is the argument to PARM.
10370 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10372 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10373 as a child node. */
10376 generic_parameter_die (tree parm
, tree arg
,
10378 dw_die_ref parent_die
)
10380 dw_die_ref tmpl_die
= NULL
;
10381 const char *name
= NULL
;
10383 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10386 /* We support non-type generic parameters and arguments,
10387 type generic parameters and arguments, as well as
10388 generic generic parameters (a.k.a. template template parameters in C++)
10390 if (TREE_CODE (parm
) == PARM_DECL
)
10391 /* PARM is a nontype generic parameter */
10392 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10393 else if (TREE_CODE (parm
) == TYPE_DECL
)
10394 /* PARM is a type generic parameter. */
10395 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10396 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10397 /* PARM is a generic generic parameter.
10398 Its DIE is a GNU extension. It shall have a
10399 DW_AT_name attribute to represent the name of the template template
10400 parameter, and a DW_AT_GNU_template_name attribute to represent the
10401 name of the template template argument. */
10402 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10405 gcc_unreachable ();
10411 /* If PARM is a generic parameter pack, it means we are
10412 emitting debug info for a template argument pack element.
10413 In other terms, ARG is a template argument pack element.
10414 In that case, we don't emit any DW_AT_name attribute for
10418 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10420 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10423 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10425 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10426 TMPL_DIE should have a child DW_AT_type attribute that is set
10427 to the type of the argument to PARM, which is ARG.
10428 If PARM is a type generic parameter, TMPL_DIE should have a
10429 child DW_AT_type that is set to ARG. */
10430 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10431 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10432 TREE_THIS_VOLATILE (tmpl_type
),
10437 /* So TMPL_DIE is a DIE representing a
10438 a generic generic template parameter, a.k.a template template
10439 parameter in C++ and arg is a template. */
10441 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10442 to the name of the argument. */
10443 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10445 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10448 if (TREE_CODE (parm
) == PARM_DECL
)
10449 /* So PARM is a non-type generic parameter.
10450 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10451 attribute of TMPL_DIE which value represents the value
10453 We must be careful here:
10454 The value of ARG might reference some function decls.
10455 We might currently be emitting debug info for a generic
10456 type and types are emitted before function decls, we don't
10457 know if the function decls referenced by ARG will actually be
10458 emitted after cgraph computations.
10459 So must defer the generation of the DW_AT_const_value to
10460 after cgraph is ready. */
10461 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10467 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10468 PARM_PACK must be a template parameter pack. The returned DIE
10469 will be child DIE of PARENT_DIE. */
10472 template_parameter_pack_die (tree parm_pack
,
10473 tree parm_pack_args
,
10474 dw_die_ref parent_die
)
10479 gcc_assert (parent_die
&& parm_pack
);
10481 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10482 add_name_and_src_coords_attributes (die
, parm_pack
);
10483 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10484 generic_parameter_die (parm_pack
,
10485 TREE_VEC_ELT (parm_pack_args
, j
),
10486 false /* Don't emit DW_AT_name */,
10491 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10492 an enumerated type. */
10495 type_is_enum (const_tree type
)
10497 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10500 /* Return the DBX register number described by a given RTL node. */
10502 static unsigned int
10503 dbx_reg_number (const_rtx rtl
)
10505 unsigned regno
= REGNO (rtl
);
10507 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10509 #ifdef LEAF_REG_REMAP
10510 if (crtl
->uses_only_leaf_regs
)
10512 int leaf_reg
= LEAF_REG_REMAP (regno
);
10513 if (leaf_reg
!= -1)
10514 regno
= (unsigned) leaf_reg
;
10518 regno
= DBX_REGISTER_NUMBER (regno
);
10519 gcc_assert (regno
!= INVALID_REGNUM
);
10523 /* Optionally add a DW_OP_piece term to a location description expression.
10524 DW_OP_piece is only added if the location description expression already
10525 doesn't end with DW_OP_piece. */
10528 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10530 dw_loc_descr_ref loc
;
10532 if (*list_head
!= NULL
)
10534 /* Find the end of the chain. */
10535 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10538 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10539 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10543 /* Return a location descriptor that designates a machine register or
10544 zero if there is none. */
10546 static dw_loc_descr_ref
10547 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10551 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10554 /* We only use "frame base" when we're sure we're talking about the
10555 post-prologue local stack frame. We do this by *not* running
10556 register elimination until this point, and recognizing the special
10557 argument pointer and soft frame pointer rtx's.
10558 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10559 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10560 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10562 dw_loc_descr_ref result
= NULL
;
10564 if (dwarf_version
>= 4 || !dwarf_strict
)
10566 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10569 add_loc_descr (&result
,
10570 new_loc_descr (DW_OP_stack_value
, 0, 0));
10575 regs
= targetm
.dwarf_register_span (rtl
);
10577 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10578 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10581 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10582 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10584 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10588 /* Return a location descriptor that designates a machine register for
10589 a given hard register number. */
10591 static dw_loc_descr_ref
10592 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10594 dw_loc_descr_ref reg_loc_descr
;
10598 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10600 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10602 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10603 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10605 return reg_loc_descr
;
10608 /* Given an RTL of a register, return a location descriptor that
10609 designates a value that spans more than one register. */
10611 static dw_loc_descr_ref
10612 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10613 enum var_init_status initialized
)
10615 int nregs
, size
, i
;
10617 dw_loc_descr_ref loc_result
= NULL
;
10620 #ifdef LEAF_REG_REMAP
10621 if (crtl
->uses_only_leaf_regs
)
10623 int leaf_reg
= LEAF_REG_REMAP (reg
);
10624 if (leaf_reg
!= -1)
10625 reg
= (unsigned) leaf_reg
;
10628 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
10629 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
10631 /* Simple, contiguous registers. */
10632 if (regs
== NULL_RTX
)
10634 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
10639 dw_loc_descr_ref t
;
10641 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
10642 VAR_INIT_STATUS_INITIALIZED
);
10643 add_loc_descr (&loc_result
, t
);
10644 add_loc_descr_op_piece (&loc_result
, size
);
10650 /* Now onto stupid register sets in non contiguous locations. */
10652 gcc_assert (GET_CODE (regs
) == PARALLEL
);
10654 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10657 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
10659 dw_loc_descr_ref t
;
10661 t
= one_reg_loc_descriptor (REGNO (XVECEXP (regs
, 0, i
)),
10662 VAR_INIT_STATUS_INITIALIZED
);
10663 add_loc_descr (&loc_result
, t
);
10664 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
10665 add_loc_descr_op_piece (&loc_result
, size
);
10668 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10669 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10673 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
10675 /* Return a location descriptor that designates a constant i,
10676 as a compound operation from constant (i >> shift), constant shift
10679 static dw_loc_descr_ref
10680 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10682 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
10683 add_loc_descr (&ret
, int_loc_descriptor (shift
));
10684 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
10688 /* Return a location descriptor that designates a constant. */
10690 static dw_loc_descr_ref
10691 int_loc_descriptor (HOST_WIDE_INT i
)
10693 enum dwarf_location_atom op
;
10695 /* Pick the smallest representation of a constant, rather than just
10696 defaulting to the LEB encoding. */
10699 int clz
= clz_hwi (i
);
10700 int ctz
= ctz_hwi (i
);
10702 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
10703 else if (i
<= 0xff)
10704 op
= DW_OP_const1u
;
10705 else if (i
<= 0xffff)
10706 op
= DW_OP_const2u
;
10707 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10708 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10709 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
10710 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
10711 while DW_OP_const4u is 5 bytes. */
10712 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
10713 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10714 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10715 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
10716 while DW_OP_const4u is 5 bytes. */
10717 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10718 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10719 op
= DW_OP_const4u
;
10720 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10721 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10722 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
10723 while DW_OP_constu of constant >= 0x100000000 takes at least
10725 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
10726 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10727 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
10728 >= HOST_BITS_PER_WIDE_INT
)
10729 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
10730 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
10731 while DW_OP_constu takes in this case at least 6 bytes. */
10732 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
10733 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10734 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10735 && size_of_uleb128 (i
) > 6)
10736 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
10737 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
10744 op
= DW_OP_const1s
;
10745 else if (i
>= -0x8000)
10746 op
= DW_OP_const2s
;
10747 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10749 if (size_of_int_loc_descriptor (i
) < 5)
10751 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10752 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10755 op
= DW_OP_const4s
;
10759 if (size_of_int_loc_descriptor (i
)
10760 < (unsigned long) 1 + size_of_sleb128 (i
))
10762 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
10763 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
10770 return new_loc_descr (op
, i
, 0);
10773 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
10774 without actually allocating it. */
10776 static unsigned long
10777 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
10779 return size_of_int_loc_descriptor (i
>> shift
)
10780 + size_of_int_loc_descriptor (shift
)
10784 /* Return size_of_locs (int_loc_descriptor (i)) without
10785 actually allocating it. */
10787 static unsigned long
10788 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
10797 else if (i
<= 0xff)
10799 else if (i
<= 0xffff)
10803 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
10804 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
10805 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10807 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10808 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
10809 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10811 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
10813 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
10814 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
10815 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
10816 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10818 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
10819 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
10820 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10822 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
10823 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
10825 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
10834 else if (i
>= -0x8000)
10836 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
10838 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10840 s
= size_of_int_loc_descriptor (-i
) + 1;
10848 unsigned long r
= 1 + size_of_sleb128 (i
);
10849 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
10851 s
= size_of_int_loc_descriptor (-i
) + 1;
10860 /* Return loc description representing "address" of integer value.
10861 This can appear only as toplevel expression. */
10863 static dw_loc_descr_ref
10864 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
10867 dw_loc_descr_ref loc_result
= NULL
;
10869 if (!(dwarf_version
>= 4 || !dwarf_strict
))
10872 litsize
= size_of_int_loc_descriptor (i
);
10873 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
10874 is more compact. For DW_OP_stack_value we need:
10875 litsize + 1 (DW_OP_stack_value)
10876 and for DW_OP_implicit_value:
10877 1 (DW_OP_implicit_value) + 1 (length) + size. */
10878 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
10880 loc_result
= int_loc_descriptor (i
);
10881 add_loc_descr (&loc_result
,
10882 new_loc_descr (DW_OP_stack_value
, 0, 0));
10886 loc_result
= new_loc_descr (DW_OP_implicit_value
,
10888 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
10889 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
10893 /* Return a location descriptor that designates a base+offset location. */
10895 static dw_loc_descr_ref
10896 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
10897 enum var_init_status initialized
)
10899 unsigned int regno
;
10900 dw_loc_descr_ref result
;
10901 dw_fde_ref fde
= cfun
->fde
;
10903 /* We only use "frame base" when we're sure we're talking about the
10904 post-prologue local stack frame. We do this by *not* running
10905 register elimination until this point, and recognizing the special
10906 argument pointer and soft frame pointer rtx's. */
10907 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
10909 rtx elim
= (ira_use_lra_p
10910 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
10911 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
10915 if (GET_CODE (elim
) == PLUS
)
10917 offset
+= INTVAL (XEXP (elim
, 1));
10918 elim
= XEXP (elim
, 0);
10920 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
10921 && (elim
== hard_frame_pointer_rtx
10922 || elim
== stack_pointer_rtx
))
10923 || elim
== (frame_pointer_needed
10924 ? hard_frame_pointer_rtx
10925 : stack_pointer_rtx
));
10927 /* If drap register is used to align stack, use frame
10928 pointer + offset to access stack variables. If stack
10929 is aligned without drap, use stack pointer + offset to
10930 access stack variables. */
10931 if (crtl
->stack_realign_tried
10932 && reg
== frame_pointer_rtx
)
10935 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
10936 ? HARD_FRAME_POINTER_REGNUM
10938 return new_reg_loc_descr (base_reg
, offset
);
10941 gcc_assert (frame_pointer_fb_offset_valid
);
10942 offset
+= frame_pointer_fb_offset
;
10943 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10947 regno
= REGNO (reg
);
10948 #ifdef LEAF_REG_REMAP
10949 if (crtl
->uses_only_leaf_regs
)
10951 int leaf_reg
= LEAF_REG_REMAP (regno
);
10952 if (leaf_reg
!= -1)
10953 regno
= (unsigned) leaf_reg
;
10956 regno
= DWARF_FRAME_REGNUM (regno
);
10958 if (!optimize
&& fde
10959 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
10961 /* Use cfa+offset to represent the location of arguments passed
10962 on the stack when drap is used to align stack.
10963 Only do this when not optimizing, for optimized code var-tracking
10964 is supposed to track where the arguments live and the register
10965 used as vdrap or drap in some spot might be used for something
10966 else in other part of the routine. */
10967 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
10971 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
10974 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
10976 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10977 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10982 /* Return true if this RTL expression describes a base+offset calculation. */
10985 is_based_loc (const_rtx rtl
)
10987 return (GET_CODE (rtl
) == PLUS
10988 && ((REG_P (XEXP (rtl
, 0))
10989 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
10990 && CONST_INT_P (XEXP (rtl
, 1)))));
10993 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
10996 static dw_loc_descr_ref
10997 tls_mem_loc_descriptor (rtx mem
)
11000 dw_loc_descr_ref loc_result
;
11002 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11005 base
= get_base_address (MEM_EXPR (mem
));
11007 || TREE_CODE (base
) != VAR_DECL
11008 || !DECL_THREAD_LOCAL_P (base
))
11011 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11012 if (loc_result
== NULL
)
11015 if (MEM_OFFSET (mem
))
11016 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11021 /* Output debug info about reason why we failed to expand expression as dwarf
11025 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11027 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11029 fprintf (dump_file
, "Failed to expand as dwarf: ");
11031 print_generic_expr (dump_file
, expr
, dump_flags
);
11034 fprintf (dump_file
, "\n");
11035 print_rtl (dump_file
, rtl
);
11037 fprintf (dump_file
, "\nReason: %s\n", reason
);
11041 /* Helper function for const_ok_for_output, called either directly
11042 or via for_each_rtx. */
11045 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11049 if (GET_CODE (rtl
) == UNSPEC
)
11051 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11052 we can't express it in the debug info. */
11053 #ifdef ENABLE_CHECKING
11054 /* Don't complain about TLS UNSPECs, those are just too hard to
11055 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11056 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11057 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11058 if (XVECLEN (rtl
, 0) == 0
11059 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11060 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11061 inform (current_function_decl
11062 ? DECL_SOURCE_LOCATION (current_function_decl
)
11063 : UNKNOWN_LOCATION
,
11064 #if NUM_UNSPEC_VALUES > 0
11065 "non-delegitimized UNSPEC %s (%d) found in variable location",
11066 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11067 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11070 "non-delegitimized UNSPEC %d found in variable location",
11074 expansion_failed (NULL_TREE
, rtl
,
11075 "UNSPEC hasn't been delegitimized.\n");
11079 if (targetm
.const_not_ok_for_debug_p (rtl
))
11081 expansion_failed (NULL_TREE
, rtl
,
11082 "Expression rejected for debug by the backend.\n");
11086 if (GET_CODE (rtl
) != SYMBOL_REF
)
11089 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11092 get_pool_constant_mark (rtl
, &marked
);
11093 /* If all references to this pool constant were optimized away,
11094 it was not output and thus we can't represent it. */
11097 expansion_failed (NULL_TREE
, rtl
,
11098 "Constant was removed from constant pool.\n");
11103 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11106 /* Avoid references to external symbols in debug info, on several targets
11107 the linker might even refuse to link when linking a shared library,
11108 and in many other cases the relocations for .debug_info/.debug_loc are
11109 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11110 to be defined within the same shared library or executable are fine. */
11111 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11113 tree decl
= SYMBOL_REF_DECL (rtl
);
11115 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11117 expansion_failed (NULL_TREE
, rtl
,
11118 "Symbol not defined in current TU.\n");
11126 /* Return true if constant RTL can be emitted in DW_OP_addr or
11127 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11128 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11131 const_ok_for_output (rtx rtl
)
11133 if (GET_CODE (rtl
) == SYMBOL_REF
)
11134 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11136 if (GET_CODE (rtl
) == CONST
)
11137 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11142 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11143 if possible, NULL otherwise. */
11146 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11148 dw_die_ref type_die
;
11149 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11153 switch (TREE_CODE (type
))
11161 type_die
= lookup_type_die (type
);
11163 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11164 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11169 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11170 type matching MODE, or, if MODE is narrower than or as wide as
11171 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11174 static dw_loc_descr_ref
11175 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11177 enum machine_mode outer_mode
= mode
;
11178 dw_die_ref type_die
;
11179 dw_loc_descr_ref cvt
;
11181 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11183 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11186 type_die
= base_type_for_mode (outer_mode
, 1);
11187 if (type_die
== NULL
)
11189 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11190 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11191 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11192 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11193 add_loc_descr (&op
, cvt
);
11197 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11199 static dw_loc_descr_ref
11200 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11201 dw_loc_descr_ref op1
)
11203 dw_loc_descr_ref ret
= op0
;
11204 add_loc_descr (&ret
, op1
);
11205 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11206 if (STORE_FLAG_VALUE
!= 1)
11208 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11209 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11214 /* Return location descriptor for signed comparison OP RTL. */
11216 static dw_loc_descr_ref
11217 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11218 enum machine_mode mem_mode
)
11220 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11221 dw_loc_descr_ref op0
, op1
;
11224 if (op_mode
== VOIDmode
)
11225 op_mode
= GET_MODE (XEXP (rtl
, 1));
11226 if (op_mode
== VOIDmode
)
11230 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11231 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11234 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11235 VAR_INIT_STATUS_INITIALIZED
);
11236 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11237 VAR_INIT_STATUS_INITIALIZED
);
11239 if (op0
== NULL
|| op1
== NULL
)
11242 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11243 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11244 return compare_loc_descriptor (op
, op0
, op1
);
11246 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11248 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11249 dw_loc_descr_ref cvt
;
11251 if (type_die
== NULL
)
11253 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11254 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11255 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11256 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11257 add_loc_descr (&op0
, cvt
);
11258 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11259 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11260 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11261 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11262 add_loc_descr (&op1
, cvt
);
11263 return compare_loc_descriptor (op
, op0
, op1
);
11266 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11267 /* For eq/ne, if the operands are known to be zero-extended,
11268 there is no need to do the fancy shifting up. */
11269 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11271 dw_loc_descr_ref last0
, last1
;
11272 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11274 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11276 /* deref_size zero extends, and for constants we can check
11277 whether they are zero extended or not. */
11278 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11279 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11280 || (CONST_INT_P (XEXP (rtl
, 0))
11281 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11282 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11283 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11284 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11285 || (CONST_INT_P (XEXP (rtl
, 1))
11286 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11287 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11288 return compare_loc_descriptor (op
, op0
, op1
);
11290 /* EQ/NE comparison against constant in narrower type than
11291 DWARF2_ADDR_SIZE can be performed either as
11292 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11295 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11296 DW_OP_{eq,ne}. Pick whatever is shorter. */
11297 if (CONST_INT_P (XEXP (rtl
, 1))
11298 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11299 && (size_of_int_loc_descriptor (shift
) + 1
11300 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11301 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11302 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11303 & GET_MODE_MASK (op_mode
))))
11305 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11306 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11307 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11308 & GET_MODE_MASK (op_mode
));
11309 return compare_loc_descriptor (op
, op0
, op1
);
11312 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11313 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11314 if (CONST_INT_P (XEXP (rtl
, 1)))
11315 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11318 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11319 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11321 return compare_loc_descriptor (op
, op0
, op1
);
11324 /* Return location descriptor for unsigned comparison OP RTL. */
11326 static dw_loc_descr_ref
11327 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11328 enum machine_mode mem_mode
)
11330 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11331 dw_loc_descr_ref op0
, op1
;
11333 if (op_mode
== VOIDmode
)
11334 op_mode
= GET_MODE (XEXP (rtl
, 1));
11335 if (op_mode
== VOIDmode
)
11337 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11340 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11343 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11344 VAR_INIT_STATUS_INITIALIZED
);
11345 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11346 VAR_INIT_STATUS_INITIALIZED
);
11348 if (op0
== NULL
|| op1
== NULL
)
11351 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11353 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11354 dw_loc_descr_ref last0
, last1
;
11355 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11357 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11359 if (CONST_INT_P (XEXP (rtl
, 0)))
11360 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11361 /* deref_size zero extends, so no need to mask it again. */
11362 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11363 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11365 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11366 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11368 if (CONST_INT_P (XEXP (rtl
, 1)))
11369 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11370 /* deref_size zero extends, so no need to mask it again. */
11371 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11372 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11374 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11375 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11378 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11380 HOST_WIDE_INT bias
= 1;
11381 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11382 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11383 if (CONST_INT_P (XEXP (rtl
, 1)))
11384 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11385 + INTVAL (XEXP (rtl
, 1)));
11387 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11390 return compare_loc_descriptor (op
, op0
, op1
);
11393 /* Return location descriptor for {U,S}{MIN,MAX}. */
11395 static dw_loc_descr_ref
11396 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11397 enum machine_mode mem_mode
)
11399 enum dwarf_location_atom op
;
11400 dw_loc_descr_ref op0
, op1
, ret
;
11401 dw_loc_descr_ref bra_node
, drop_node
;
11404 && (GET_MODE_CLASS (mode
) != MODE_INT
11405 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11408 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11409 VAR_INIT_STATUS_INITIALIZED
);
11410 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11411 VAR_INIT_STATUS_INITIALIZED
);
11413 if (op0
== NULL
|| op1
== NULL
)
11416 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11417 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11418 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11419 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11421 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11423 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11424 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11425 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11426 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11427 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11429 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11431 HOST_WIDE_INT bias
= 1;
11432 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11433 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11434 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11437 else if (GET_MODE_CLASS (mode
) == MODE_INT
11438 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11440 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11441 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11442 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11443 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11444 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11446 else if (GET_MODE_CLASS (mode
) == MODE_INT
11447 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11449 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11450 dw_loc_descr_ref cvt
;
11451 if (type_die
== NULL
)
11453 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11454 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11455 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11456 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11457 add_loc_descr (&op0
, cvt
);
11458 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11459 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11460 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11461 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11462 add_loc_descr (&op1
, cvt
);
11465 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11470 add_loc_descr (&ret
, op1
);
11471 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11472 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11473 add_loc_descr (&ret
, bra_node
);
11474 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11475 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11476 add_loc_descr (&ret
, drop_node
);
11477 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11478 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11479 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11480 && GET_MODE_CLASS (mode
) == MODE_INT
11481 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11482 ret
= convert_descriptor_to_mode (mode
, ret
);
11486 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11487 but after converting arguments to type_die, afterwards
11488 convert back to unsigned. */
11490 static dw_loc_descr_ref
11491 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11492 enum machine_mode mode
, enum machine_mode mem_mode
)
11494 dw_loc_descr_ref cvt
, op0
, op1
;
11496 if (type_die
== NULL
)
11498 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11499 VAR_INIT_STATUS_INITIALIZED
);
11500 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11501 VAR_INIT_STATUS_INITIALIZED
);
11502 if (op0
== NULL
|| op1
== NULL
)
11504 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11505 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11506 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11507 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11508 add_loc_descr (&op0
, cvt
);
11509 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11510 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11511 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11512 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11513 add_loc_descr (&op1
, cvt
);
11514 add_loc_descr (&op0
, op1
);
11515 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11516 return convert_descriptor_to_mode (mode
, op0
);
11519 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11520 const0 is DW_OP_lit0 or corresponding typed constant,
11521 const1 is DW_OP_lit1 or corresponding typed constant
11522 and constMSB is constant with just the MSB bit set
11524 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11525 L1: const0 DW_OP_swap
11526 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11527 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11532 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11533 L1: const0 DW_OP_swap
11534 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11535 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11540 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11541 L1: const1 DW_OP_swap
11542 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11543 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11547 static dw_loc_descr_ref
11548 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11549 enum machine_mode mem_mode
)
11551 dw_loc_descr_ref op0
, ret
, tmp
;
11552 HOST_WIDE_INT valv
;
11553 dw_loc_descr_ref l1jump
, l1label
;
11554 dw_loc_descr_ref l2jump
, l2label
;
11555 dw_loc_descr_ref l3jump
, l3label
;
11556 dw_loc_descr_ref l4jump
, l4label
;
11559 if (GET_MODE_CLASS (mode
) != MODE_INT
11560 || GET_MODE (XEXP (rtl
, 0)) != mode
11561 || (GET_CODE (rtl
) == CLZ
11562 && GET_MODE_BITSIZE (mode
) > HOST_BITS_PER_DOUBLE_INT
))
11565 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11566 VAR_INIT_STATUS_INITIALIZED
);
11570 if (GET_CODE (rtl
) == CLZ
)
11572 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11573 valv
= GET_MODE_BITSIZE (mode
);
11575 else if (GET_CODE (rtl
) == FFS
)
11577 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11578 valv
= GET_MODE_BITSIZE (mode
);
11579 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11580 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11581 add_loc_descr (&ret
, l1jump
);
11582 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11583 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11584 VAR_INIT_STATUS_INITIALIZED
);
11587 add_loc_descr (&ret
, tmp
);
11588 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11589 add_loc_descr (&ret
, l4jump
);
11590 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11591 ? const1_rtx
: const0_rtx
,
11593 VAR_INIT_STATUS_INITIALIZED
);
11594 if (l1label
== NULL
)
11596 add_loc_descr (&ret
, l1label
);
11597 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11598 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11599 add_loc_descr (&ret
, l2label
);
11600 if (GET_CODE (rtl
) != CLZ
)
11602 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11603 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11604 << (GET_MODE_BITSIZE (mode
) - 1));
11606 msb
= immed_double_const (0, (unsigned HOST_WIDE_INT
) 1
11607 << (GET_MODE_BITSIZE (mode
)
11608 - HOST_BITS_PER_WIDE_INT
- 1), mode
);
11609 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11610 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11611 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11612 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11614 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11615 VAR_INIT_STATUS_INITIALIZED
);
11618 add_loc_descr (&ret
, tmp
);
11619 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11620 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11621 add_loc_descr (&ret
, l3jump
);
11622 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11623 VAR_INIT_STATUS_INITIALIZED
);
11626 add_loc_descr (&ret
, tmp
);
11627 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
11628 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
11629 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11630 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
11631 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11632 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11633 add_loc_descr (&ret
, l2jump
);
11634 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
11635 add_loc_descr (&ret
, l3label
);
11636 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
11637 add_loc_descr (&ret
, l4label
);
11638 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11639 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11640 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11641 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11642 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11643 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
11644 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11645 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
11649 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
11650 const1 is DW_OP_lit1 or corresponding typed constant):
11652 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11653 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11657 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
11658 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
11661 static dw_loc_descr_ref
11662 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11663 enum machine_mode mem_mode
)
11665 dw_loc_descr_ref op0
, ret
, tmp
;
11666 dw_loc_descr_ref l1jump
, l1label
;
11667 dw_loc_descr_ref l2jump
, l2label
;
11669 if (GET_MODE_CLASS (mode
) != MODE_INT
11670 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11673 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11674 VAR_INIT_STATUS_INITIALIZED
);
11678 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11679 VAR_INIT_STATUS_INITIALIZED
);
11682 add_loc_descr (&ret
, tmp
);
11683 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11684 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
11685 add_loc_descr (&ret
, l1label
);
11686 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11687 add_loc_descr (&ret
, l2jump
);
11688 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11689 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11690 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11691 VAR_INIT_STATUS_INITIALIZED
);
11694 add_loc_descr (&ret
, tmp
);
11695 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11696 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
11697 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
11698 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11699 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11700 VAR_INIT_STATUS_INITIALIZED
);
11701 add_loc_descr (&ret
, tmp
);
11702 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11703 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11704 add_loc_descr (&ret
, l1jump
);
11705 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11706 add_loc_descr (&ret
, l2label
);
11707 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11708 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11709 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11710 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11714 /* BSWAP (constS is initial shift count, either 56 or 24):
11716 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
11717 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
11718 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
11719 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
11720 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
11722 static dw_loc_descr_ref
11723 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11724 enum machine_mode mem_mode
)
11726 dw_loc_descr_ref op0
, ret
, tmp
;
11727 dw_loc_descr_ref l1jump
, l1label
;
11728 dw_loc_descr_ref l2jump
, l2label
;
11730 if (GET_MODE_CLASS (mode
) != MODE_INT
11731 || BITS_PER_UNIT
!= 8
11732 || (GET_MODE_BITSIZE (mode
) != 32
11733 && GET_MODE_BITSIZE (mode
) != 64))
11736 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11737 VAR_INIT_STATUS_INITIALIZED
);
11742 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11744 VAR_INIT_STATUS_INITIALIZED
);
11747 add_loc_descr (&ret
, tmp
);
11748 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11749 VAR_INIT_STATUS_INITIALIZED
);
11752 add_loc_descr (&ret
, tmp
);
11753 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
11754 add_loc_descr (&ret
, l1label
);
11755 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
11757 VAR_INIT_STATUS_INITIALIZED
);
11758 add_loc_descr (&ret
, tmp
);
11759 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
11760 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11761 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11762 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
11763 VAR_INIT_STATUS_INITIALIZED
);
11766 add_loc_descr (&ret
, tmp
);
11767 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11768 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
11769 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11770 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11771 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11772 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11773 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
11774 VAR_INIT_STATUS_INITIALIZED
);
11775 add_loc_descr (&ret
, tmp
);
11776 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
11777 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11778 add_loc_descr (&ret
, l2jump
);
11779 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
11780 VAR_INIT_STATUS_INITIALIZED
);
11781 add_loc_descr (&ret
, tmp
);
11782 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
11783 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11784 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11785 add_loc_descr (&ret
, l1jump
);
11786 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
11787 add_loc_descr (&ret
, l2label
);
11788 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11789 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11790 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11791 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
11792 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11793 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
11797 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
11798 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11799 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
11800 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
11802 ROTATERT is similar:
11803 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
11804 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
11805 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
11807 static dw_loc_descr_ref
11808 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11809 enum machine_mode mem_mode
)
11811 rtx rtlop1
= XEXP (rtl
, 1);
11812 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
11815 if (GET_MODE_CLASS (mode
) != MODE_INT
)
11818 if (GET_MODE (rtlop1
) != VOIDmode
11819 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
11820 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
11821 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11822 VAR_INIT_STATUS_INITIALIZED
);
11823 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
11824 VAR_INIT_STATUS_INITIALIZED
);
11825 if (op0
== NULL
|| op1
== NULL
)
11827 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11828 for (i
= 0; i
< 2; i
++)
11830 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
11831 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
11833 VAR_INIT_STATUS_INITIALIZED
);
11834 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
11835 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11837 : HOST_BITS_PER_WIDE_INT
== 64
11838 ? DW_OP_const8u
: DW_OP_constu
,
11839 GET_MODE_MASK (mode
), 0);
11842 if (mask
[i
] == NULL
)
11844 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
11847 add_loc_descr (&ret
, op1
);
11848 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11849 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
11850 if (GET_CODE (rtl
) == ROTATERT
)
11852 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11853 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11854 GET_MODE_BITSIZE (mode
), 0));
11856 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11857 if (mask
[0] != NULL
)
11858 add_loc_descr (&ret
, mask
[0]);
11859 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
11860 if (mask
[1] != NULL
)
11862 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11863 add_loc_descr (&ret
, mask
[1]);
11864 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11866 if (GET_CODE (rtl
) == ROTATE
)
11868 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11869 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
11870 GET_MODE_BITSIZE (mode
), 0));
11872 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
11873 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
11877 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
11878 for DEBUG_PARAMETER_REF RTL. */
11880 static dw_loc_descr_ref
11881 parameter_ref_descriptor (rtx rtl
)
11883 dw_loc_descr_ref ret
;
11888 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
11889 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
11890 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
11893 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11894 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
11895 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11899 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
11900 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
11905 /* The following routine converts the RTL for a variable or parameter
11906 (resident in memory) into an equivalent Dwarf representation of a
11907 mechanism for getting the address of that same variable onto the top of a
11908 hypothetical "address evaluation" stack.
11910 When creating memory location descriptors, we are effectively transforming
11911 the RTL for a memory-resident object into its Dwarf postfix expression
11912 equivalent. This routine recursively descends an RTL tree, turning
11913 it into Dwarf postfix code as it goes.
11915 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
11917 MEM_MODE is the mode of the memory reference, needed to handle some
11918 autoincrement addressing modes.
11920 Return 0 if we can't represent the location. */
11923 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11924 enum machine_mode mem_mode
,
11925 enum var_init_status initialized
)
11927 dw_loc_descr_ref mem_loc_result
= NULL
;
11928 enum dwarf_location_atom op
;
11929 dw_loc_descr_ref op0
, op1
;
11930 rtx inner
= NULL_RTX
;
11932 if (mode
== VOIDmode
)
11933 mode
= GET_MODE (rtl
);
11935 /* Note that for a dynamically sized array, the location we will generate a
11936 description of here will be the lowest numbered location which is
11937 actually within the array. That's *not* necessarily the same as the
11938 zeroth element of the array. */
11940 rtl
= targetm
.delegitimize_address (rtl
);
11942 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
11945 switch (GET_CODE (rtl
))
11950 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
11953 /* The case of a subreg may arise when we have a local (register)
11954 variable or a formal (register) parameter which doesn't quite fill
11955 up an entire register. For now, just assume that it is
11956 legitimate to make the Dwarf info refer to the whole register which
11957 contains the given subreg. */
11958 if (!subreg_lowpart_p (rtl
))
11960 inner
= SUBREG_REG (rtl
);
11962 if (inner
== NULL_RTX
)
11963 inner
= XEXP (rtl
, 0);
11964 if (GET_MODE_CLASS (mode
) == MODE_INT
11965 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
11966 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
11967 #ifdef POINTERS_EXTEND_UNSIGNED
11968 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
11971 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
11973 mem_loc_result
= mem_loc_descriptor (inner
,
11975 mem_mode
, initialized
);
11980 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
11982 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
11983 && (GET_MODE_CLASS (mode
) != MODE_INT
11984 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
11988 dw_die_ref type_die
;
11989 dw_loc_descr_ref cvt
;
11991 mem_loc_result
= mem_loc_descriptor (inner
,
11993 mem_mode
, initialized
);
11994 if (mem_loc_result
== NULL
)
11996 type_die
= base_type_for_mode (mode
,
11997 GET_MODE_CLASS (mode
) == MODE_INT
);
11998 if (type_die
== NULL
)
12000 mem_loc_result
= NULL
;
12003 if (GET_MODE_SIZE (mode
)
12004 != GET_MODE_SIZE (GET_MODE (inner
)))
12005 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12007 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12008 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12009 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12010 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12011 add_loc_descr (&mem_loc_result
, cvt
);
12016 if (GET_MODE_CLASS (mode
) != MODE_INT
12017 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12018 && rtl
!= arg_pointer_rtx
12019 && rtl
!= frame_pointer_rtx
12020 #ifdef POINTERS_EXTEND_UNSIGNED
12021 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12025 dw_die_ref type_die
;
12026 unsigned int dbx_regnum
;
12030 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12032 type_die
= base_type_for_mode (mode
,
12033 GET_MODE_CLASS (mode
) == MODE_INT
);
12034 if (type_die
== NULL
)
12037 dbx_regnum
= dbx_reg_number (rtl
);
12038 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12040 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12042 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12043 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12044 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12047 /* Whenever a register number forms a part of the description of the
12048 method for calculating the (dynamic) address of a memory resident
12049 object, DWARF rules require the register number be referred to as
12050 a "base register". This distinction is not based in any way upon
12051 what category of register the hardware believes the given register
12052 belongs to. This is strictly DWARF terminology we're dealing with
12053 here. Note that in cases where the location of a memory-resident
12054 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12055 OP_CONST (0)) the actual DWARF location descriptor that we generate
12056 may just be OP_BASEREG (basereg). This may look deceptively like
12057 the object in question was allocated to a register (rather than in
12058 memory) so DWARF consumers need to be aware of the subtle
12059 distinction between OP_REG and OP_BASEREG. */
12060 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12061 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12062 else if (stack_realign_drap
12064 && crtl
->args
.internal_arg_pointer
== rtl
12065 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12067 /* If RTL is internal_arg_pointer, which has been optimized
12068 out, use DRAP instead. */
12069 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12070 VAR_INIT_STATUS_INITIALIZED
);
12076 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12078 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12079 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12082 else if (GET_CODE (rtl
) == ZERO_EXTEND
12083 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12084 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12085 < HOST_BITS_PER_WIDE_INT
12086 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12087 to expand zero extend as two shifts instead of
12089 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12091 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12092 mem_loc_result
= op0
;
12093 add_loc_descr (&mem_loc_result
,
12094 int_loc_descriptor (GET_MODE_MASK (imode
)));
12095 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12097 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12099 int shift
= DWARF2_ADDR_SIZE
12100 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12101 shift
*= BITS_PER_UNIT
;
12102 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12106 mem_loc_result
= op0
;
12107 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12108 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12109 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12110 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12112 else if (!dwarf_strict
)
12114 dw_die_ref type_die1
, type_die2
;
12115 dw_loc_descr_ref cvt
;
12117 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12118 GET_CODE (rtl
) == ZERO_EXTEND
);
12119 if (type_die1
== NULL
)
12121 type_die2
= base_type_for_mode (mode
, 1);
12122 if (type_die2
== NULL
)
12124 mem_loc_result
= op0
;
12125 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12126 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12127 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12128 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12129 add_loc_descr (&mem_loc_result
, cvt
);
12130 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12131 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12132 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12133 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12134 add_loc_descr (&mem_loc_result
, cvt
);
12140 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12141 if (new_rtl
!= rtl
)
12143 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12145 if (mem_loc_result
!= NULL
)
12146 return mem_loc_result
;
12149 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12150 get_address_mode (rtl
), mode
,
12151 VAR_INIT_STATUS_INITIALIZED
);
12152 if (mem_loc_result
== NULL
)
12153 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12154 if (mem_loc_result
!= NULL
)
12156 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12157 || GET_MODE_CLASS (mode
) != MODE_INT
)
12159 dw_die_ref type_die
;
12160 dw_loc_descr_ref deref
;
12165 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12166 if (type_die
== NULL
)
12168 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12169 GET_MODE_SIZE (mode
), 0);
12170 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12171 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12172 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12173 add_loc_descr (&mem_loc_result
, deref
);
12175 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12176 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12178 add_loc_descr (&mem_loc_result
,
12179 new_loc_descr (DW_OP_deref_size
,
12180 GET_MODE_SIZE (mode
), 0));
12185 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12188 /* Some ports can transform a symbol ref into a label ref, because
12189 the symbol ref is too far away and has to be dumped into a constant
12193 if (GET_MODE_CLASS (mode
) != MODE_INT
12194 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12195 #ifdef POINTERS_EXTEND_UNSIGNED
12196 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12200 if (GET_CODE (rtl
) == SYMBOL_REF
12201 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12203 dw_loc_descr_ref temp
;
12205 /* If this is not defined, we have no way to emit the data. */
12206 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12209 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12211 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12212 add_loc_descr (&mem_loc_result
, temp
);
12217 if (!const_ok_for_output (rtl
))
12221 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12222 vec_safe_push (used_rtx_array
, rtl
);
12228 case DEBUG_IMPLICIT_PTR
:
12229 expansion_failed (NULL_TREE
, rtl
,
12230 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12236 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12238 if (GET_MODE_CLASS (mode
) != MODE_INT
12239 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12240 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12241 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12244 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12245 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12247 op0
= one_reg_loc_descriptor (dbx_regnum
,
12248 VAR_INIT_STATUS_INITIALIZED
);
12251 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12252 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12254 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12255 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12256 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12260 gcc_unreachable ();
12263 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12264 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12265 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12268 case DEBUG_PARAMETER_REF
:
12269 mem_loc_result
= parameter_ref_descriptor (rtl
);
12273 /* Extract the PLUS expression nested inside and fall into
12274 PLUS code below. */
12275 rtl
= XEXP (rtl
, 1);
12280 /* Turn these into a PLUS expression and fall into the PLUS code
12282 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12283 GEN_INT (GET_CODE (rtl
) == PRE_INC
12284 ? GET_MODE_UNIT_SIZE (mem_mode
)
12285 : -GET_MODE_UNIT_SIZE (mem_mode
)));
12287 /* ... fall through ... */
12291 if (is_based_loc (rtl
)
12292 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12293 || XEXP (rtl
, 0) == arg_pointer_rtx
12294 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12295 && GET_MODE_CLASS (mode
) == MODE_INT
)
12296 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12297 INTVAL (XEXP (rtl
, 1)),
12298 VAR_INIT_STATUS_INITIALIZED
);
12301 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12302 VAR_INIT_STATUS_INITIALIZED
);
12303 if (mem_loc_result
== 0)
12306 if (CONST_INT_P (XEXP (rtl
, 1))
12307 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12308 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12311 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12312 VAR_INIT_STATUS_INITIALIZED
);
12315 add_loc_descr (&mem_loc_result
, op1
);
12316 add_loc_descr (&mem_loc_result
,
12317 new_loc_descr (DW_OP_plus
, 0, 0));
12322 /* If a pseudo-reg is optimized away, it is possible for it to
12323 be replaced with a MEM containing a multiply or shift. */
12334 && GET_MODE_CLASS (mode
) == MODE_INT
12335 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12337 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12338 base_type_for_mode (mode
, 0),
12362 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12364 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12365 VAR_INIT_STATUS_INITIALIZED
);
12367 rtx rtlop1
= XEXP (rtl
, 1);
12368 if (GET_MODE (rtlop1
) != VOIDmode
12369 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12370 < GET_MODE_BITSIZE (mode
))
12371 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12372 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12373 VAR_INIT_STATUS_INITIALIZED
);
12376 if (op0
== 0 || op1
== 0)
12379 mem_loc_result
= op0
;
12380 add_loc_descr (&mem_loc_result
, op1
);
12381 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12397 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12398 VAR_INIT_STATUS_INITIALIZED
);
12399 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12400 VAR_INIT_STATUS_INITIALIZED
);
12402 if (op0
== 0 || op1
== 0)
12405 mem_loc_result
= op0
;
12406 add_loc_descr (&mem_loc_result
, op1
);
12407 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12411 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12413 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12414 base_type_for_mode (mode
, 0),
12419 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12420 VAR_INIT_STATUS_INITIALIZED
);
12421 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12422 VAR_INIT_STATUS_INITIALIZED
);
12424 if (op0
== 0 || op1
== 0)
12427 mem_loc_result
= op0
;
12428 add_loc_descr (&mem_loc_result
, op1
);
12429 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12430 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12431 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12432 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12433 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12437 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12439 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12444 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12445 base_type_for_mode (mode
, 1),
12463 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12464 VAR_INIT_STATUS_INITIALIZED
);
12469 mem_loc_result
= op0
;
12470 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12474 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12475 #ifdef POINTERS_EXTEND_UNSIGNED
12477 && mem_mode
!= VOIDmode
12478 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12482 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12486 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12487 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12489 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12490 enum machine_mode amode
;
12491 if (type_die
== NULL
)
12493 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12495 if (INTVAL (rtl
) >= 0
12496 && amode
!= BLKmode
12497 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12498 /* const DW_OP_GNU_convert <XXX> vs.
12499 DW_OP_GNU_const_type <XXX, 1, const>. */
12500 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12501 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12503 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12504 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12505 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12506 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12507 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12508 add_loc_descr (&mem_loc_result
, op0
);
12509 return mem_loc_result
;
12511 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12513 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12514 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12515 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12516 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12517 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12520 mem_loc_result
->dw_loc_oprnd2
.val_class
12521 = dw_val_class_const_double
;
12522 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12523 = double_int::from_shwi (INTVAL (rtl
));
12531 dw_die_ref type_die
;
12533 /* Note that a CONST_DOUBLE rtx could represent either an integer
12534 or a floating-point constant. A CONST_DOUBLE is used whenever
12535 the constant requires more than one word in order to be
12536 adequately represented. We output CONST_DOUBLEs as blocks. */
12537 if (mode
== VOIDmode
12538 || (GET_MODE (rtl
) == VOIDmode
12539 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12541 type_die
= base_type_for_mode (mode
,
12542 GET_MODE_CLASS (mode
) == MODE_INT
);
12543 if (type_die
== NULL
)
12545 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12546 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12547 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12548 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12549 if (SCALAR_FLOAT_MODE_P (mode
))
12551 unsigned int length
= GET_MODE_SIZE (mode
);
12552 unsigned char *array
12553 = (unsigned char*) ggc_alloc_atomic (length
);
12555 insert_float (rtl
, array
);
12556 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12557 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12558 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12559 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12563 mem_loc_result
->dw_loc_oprnd2
.val_class
12564 = dw_val_class_const_double
;
12565 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12566 = rtx_to_double_int (rtl
);
12572 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12576 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12580 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12584 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12588 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12592 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12596 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12600 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12604 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12608 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12613 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12618 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
12623 if (CONST_INT_P (XEXP (rtl
, 1))
12624 && CONST_INT_P (XEXP (rtl
, 2))
12625 && ((unsigned) INTVAL (XEXP (rtl
, 1))
12626 + (unsigned) INTVAL (XEXP (rtl
, 2))
12627 <= GET_MODE_BITSIZE (mode
))
12628 && GET_MODE_CLASS (mode
) == MODE_INT
12629 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12630 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
12633 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12634 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12637 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
12641 mem_loc_result
= op0
;
12642 size
= INTVAL (XEXP (rtl
, 1));
12643 shift
= INTVAL (XEXP (rtl
, 2));
12644 if (BITS_BIG_ENDIAN
)
12645 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12647 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
12649 add_loc_descr (&mem_loc_result
,
12650 int_loc_descriptor (DWARF2_ADDR_SIZE
12652 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12654 if (size
!= (int) DWARF2_ADDR_SIZE
)
12656 add_loc_descr (&mem_loc_result
,
12657 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
12658 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12665 dw_loc_descr_ref op2
, bra_node
, drop_node
;
12666 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
12667 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
12668 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
12669 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12670 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12671 VAR_INIT_STATUS_INITIALIZED
);
12672 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
12673 VAR_INIT_STATUS_INITIALIZED
);
12674 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
12677 mem_loc_result
= op1
;
12678 add_loc_descr (&mem_loc_result
, op2
);
12679 add_loc_descr (&mem_loc_result
, op0
);
12680 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
12681 add_loc_descr (&mem_loc_result
, bra_node
);
12682 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
12683 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
12684 add_loc_descr (&mem_loc_result
, drop_node
);
12685 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12686 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
12691 case FLOAT_TRUNCATE
:
12693 case UNSIGNED_FLOAT
:
12698 dw_die_ref type_die
;
12699 dw_loc_descr_ref cvt
;
12701 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12702 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12705 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
12706 && (GET_CODE (rtl
) == FLOAT
12707 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
12708 <= DWARF2_ADDR_SIZE
))
12710 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12711 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
12712 if (type_die
== NULL
)
12714 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12715 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12716 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12717 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12718 add_loc_descr (&op0
, cvt
);
12720 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
12721 if (type_die
== NULL
)
12723 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12724 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12725 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12726 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12727 add_loc_descr (&op0
, cvt
);
12728 if (GET_MODE_CLASS (mode
) == MODE_INT
12729 && (GET_CODE (rtl
) == FIX
12730 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
12732 op0
= convert_descriptor_to_mode (mode
, op0
);
12736 mem_loc_result
= op0
;
12743 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
12748 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
12752 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
12757 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
12761 /* In theory, we could implement the above. */
12762 /* DWARF cannot represent the unsigned compare operations
12787 case FRACT_CONVERT
:
12788 case UNSIGNED_FRACT_CONVERT
:
12790 case UNSIGNED_SAT_FRACT
:
12796 case VEC_DUPLICATE
:
12800 case STRICT_LOW_PART
:
12805 /* If delegitimize_address couldn't do anything with the UNSPEC, we
12806 can't express it in the debug info. This can happen e.g. with some
12811 resolve_one_addr (&rtl
, NULL
);
12815 #ifdef ENABLE_CHECKING
12816 print_rtl (stderr
, rtl
);
12817 gcc_unreachable ();
12823 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12824 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12826 return mem_loc_result
;
12829 /* Return a descriptor that describes the concatenation of two locations.
12830 This is typically a complex variable. */
12832 static dw_loc_descr_ref
12833 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
12835 dw_loc_descr_ref cc_loc_result
= NULL
;
12836 dw_loc_descr_ref x0_ref
12837 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12838 dw_loc_descr_ref x1_ref
12839 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12841 if (x0_ref
== 0 || x1_ref
== 0)
12844 cc_loc_result
= x0_ref
;
12845 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
12847 add_loc_descr (&cc_loc_result
, x1_ref
);
12848 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
12850 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12851 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12853 return cc_loc_result
;
12856 /* Return a descriptor that describes the concatenation of N
12859 static dw_loc_descr_ref
12860 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
12863 dw_loc_descr_ref cc_loc_result
= NULL
;
12864 unsigned int n
= XVECLEN (concatn
, 0);
12866 for (i
= 0; i
< n
; ++i
)
12868 dw_loc_descr_ref ref
;
12869 rtx x
= XVECEXP (concatn
, 0, i
);
12871 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12875 add_loc_descr (&cc_loc_result
, ref
);
12876 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
12879 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
12880 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
12882 return cc_loc_result
;
12885 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
12886 for DEBUG_IMPLICIT_PTR RTL. */
12888 static dw_loc_descr_ref
12889 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
12891 dw_loc_descr_ref ret
;
12896 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
12897 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
12898 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
12899 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
12900 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
12901 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12904 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12905 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12906 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12910 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12911 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
12916 /* Output a proper Dwarf location descriptor for a variable or parameter
12917 which is either allocated in a register or in a memory location. For a
12918 register, we just generate an OP_REG and the register number. For a
12919 memory location we provide a Dwarf postfix expression describing how to
12920 generate the (dynamic) address of the object onto the address stack.
12922 MODE is mode of the decl if this loc_descriptor is going to be used in
12923 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
12924 allowed, VOIDmode otherwise.
12926 If we don't know how to describe it, return 0. */
12928 static dw_loc_descr_ref
12929 loc_descriptor (rtx rtl
, enum machine_mode mode
,
12930 enum var_init_status initialized
)
12932 dw_loc_descr_ref loc_result
= NULL
;
12934 switch (GET_CODE (rtl
))
12937 /* The case of a subreg may arise when we have a local (register)
12938 variable or a formal (register) parameter which doesn't quite fill
12939 up an entire register. For now, just assume that it is
12940 legitimate to make the Dwarf info refer to the whole register which
12941 contains the given subreg. */
12942 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
12943 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
12944 GET_MODE (SUBREG_REG (rtl
)), initialized
);
12950 loc_result
= reg_loc_descriptor (rtl
, initialized
);
12954 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
12955 GET_MODE (rtl
), initialized
);
12956 if (loc_result
== NULL
)
12957 loc_result
= tls_mem_loc_descriptor (rtl
);
12958 if (loc_result
== NULL
)
12960 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12961 if (new_rtl
!= rtl
)
12962 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
12967 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
12972 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
12977 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
12979 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
12980 if (GET_CODE (loc
) == EXPR_LIST
)
12981 loc
= XEXP (loc
, 0);
12982 loc_result
= loc_descriptor (loc
, mode
, initialized
);
12986 rtl
= XEXP (rtl
, 1);
12991 rtvec par_elems
= XVEC (rtl
, 0);
12992 int num_elem
= GET_NUM_ELEM (par_elems
);
12993 enum machine_mode mode
;
12996 /* Create the first one, so we have something to add to. */
12997 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
12998 VOIDmode
, initialized
);
12999 if (loc_result
== NULL
)
13001 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13002 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13003 for (i
= 1; i
< num_elem
; i
++)
13005 dw_loc_descr_ref temp
;
13007 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13008 VOIDmode
, initialized
);
13011 add_loc_descr (&loc_result
, temp
);
13012 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13013 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13019 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13020 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13025 if (mode
== VOIDmode
)
13026 mode
= GET_MODE (rtl
);
13028 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13030 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13032 /* Note that a CONST_DOUBLE rtx could represent either an integer
13033 or a floating-point constant. A CONST_DOUBLE is used whenever
13034 the constant requires more than one word in order to be
13035 adequately represented. We output CONST_DOUBLEs as blocks. */
13036 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13037 GET_MODE_SIZE (mode
), 0);
13038 if (SCALAR_FLOAT_MODE_P (mode
))
13040 unsigned int length
= GET_MODE_SIZE (mode
);
13041 unsigned char *array
13042 = (unsigned char*) ggc_alloc_atomic (length
);
13044 insert_float (rtl
, array
);
13045 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13046 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13047 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13048 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13052 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13053 loc_result
->dw_loc_oprnd2
.v
.val_double
13054 = rtx_to_double_int (rtl
);
13060 if (mode
== VOIDmode
)
13061 mode
= GET_MODE (rtl
);
13063 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13065 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13066 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13067 unsigned char *array
= (unsigned char *)
13068 ggc_alloc_atomic (length
* elt_size
);
13072 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13073 switch (GET_MODE_CLASS (mode
))
13075 case MODE_VECTOR_INT
:
13076 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13078 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13079 double_int val
= rtx_to_double_int (elt
);
13081 if (elt_size
<= sizeof (HOST_WIDE_INT
))
13082 insert_int (val
.to_shwi (), elt_size
, p
);
13085 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
13086 insert_double (val
, p
);
13091 case MODE_VECTOR_FLOAT
:
13092 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13094 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13095 insert_float (elt
, p
);
13100 gcc_unreachable ();
13103 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13104 length
* elt_size
, 0);
13105 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13106 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13107 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13108 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13113 if (mode
== VOIDmode
13114 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13115 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13116 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13118 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13123 if (!const_ok_for_output (rtl
))
13126 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13127 && (dwarf_version
>= 4 || !dwarf_strict
))
13129 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13130 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13131 vec_safe_push (used_rtx_array
, rtl
);
13135 case DEBUG_IMPLICIT_PTR
:
13136 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13140 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13141 && CONST_INT_P (XEXP (rtl
, 1)))
13144 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13150 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13151 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13152 && dwarf_version
>= 4)
13153 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13155 /* Value expression. */
13156 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13158 add_loc_descr (&loc_result
,
13159 new_loc_descr (DW_OP_stack_value
, 0, 0));
13167 /* We need to figure out what section we should use as the base for the
13168 address ranges where a given location is valid.
13169 1. If this particular DECL has a section associated with it, use that.
13170 2. If this function has a section associated with it, use that.
13171 3. Otherwise, use the text section.
13172 XXX: If you split a variable across multiple sections, we won't notice. */
13174 static const char *
13175 secname_for_decl (const_tree decl
)
13177 const char *secname
;
13179 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13181 tree sectree
= DECL_SECTION_NAME (decl
);
13182 secname
= TREE_STRING_POINTER (sectree
);
13184 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13186 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13187 secname
= TREE_STRING_POINTER (sectree
);
13189 else if (cfun
&& in_cold_section_p
)
13190 secname
= crtl
->subsections
.cold_section_label
;
13192 secname
= text_section_label
;
13197 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13200 decl_by_reference_p (tree decl
)
13202 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13203 || TREE_CODE (decl
) == VAR_DECL
)
13204 && DECL_BY_REFERENCE (decl
));
13207 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13210 static dw_loc_descr_ref
13211 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13212 enum var_init_status initialized
)
13214 int have_address
= 0;
13215 dw_loc_descr_ref descr
;
13216 enum machine_mode mode
;
13218 if (want_address
!= 2)
13220 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13222 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13224 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13225 if (GET_CODE (varloc
) == EXPR_LIST
)
13226 varloc
= XEXP (varloc
, 0);
13227 mode
= GET_MODE (varloc
);
13228 if (MEM_P (varloc
))
13230 rtx addr
= XEXP (varloc
, 0);
13231 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13232 mode
, initialized
);
13237 rtx x
= avoid_constant_pool_reference (varloc
);
13239 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13244 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13251 if (GET_CODE (varloc
) == VAR_LOCATION
)
13252 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13254 mode
= DECL_MODE (loc
);
13255 descr
= loc_descriptor (varloc
, mode
, initialized
);
13262 if (want_address
== 2 && !have_address
13263 && (dwarf_version
>= 4 || !dwarf_strict
))
13265 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13267 expansion_failed (loc
, NULL_RTX
,
13268 "DWARF address size mismatch");
13271 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13274 /* Show if we can't fill the request for an address. */
13275 if (want_address
&& !have_address
)
13277 expansion_failed (loc
, NULL_RTX
,
13278 "Want address and only have value");
13282 /* If we've got an address and don't want one, dereference. */
13283 if (!want_address
&& have_address
)
13285 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13286 enum dwarf_location_atom op
;
13288 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13290 expansion_failed (loc
, NULL_RTX
,
13291 "DWARF address size mismatch");
13294 else if (size
== DWARF2_ADDR_SIZE
)
13297 op
= DW_OP_deref_size
;
13299 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13305 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13306 if it is not possible. */
13308 static dw_loc_descr_ref
13309 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13311 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13312 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13313 else if (dwarf_version
>= 3 || !dwarf_strict
)
13314 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13319 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13320 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13322 static dw_loc_descr_ref
13323 dw_sra_loc_expr (tree decl
, rtx loc
)
13326 unsigned int padsize
= 0;
13327 dw_loc_descr_ref descr
, *descr_tail
;
13328 unsigned HOST_WIDE_INT decl_size
;
13330 enum var_init_status initialized
;
13332 if (DECL_SIZE (decl
) == NULL
13333 || !host_integerp (DECL_SIZE (decl
), 1))
13336 decl_size
= tree_low_cst (DECL_SIZE (decl
), 1);
13338 descr_tail
= &descr
;
13340 for (p
= loc
; p
; p
= XEXP (p
, 1))
13342 unsigned int bitsize
= decl_piece_bitsize (p
);
13343 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13344 dw_loc_descr_ref cur_descr
;
13345 dw_loc_descr_ref
*tail
, last
= NULL
;
13346 unsigned int opsize
= 0;
13348 if (loc_note
== NULL_RTX
13349 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13351 padsize
+= bitsize
;
13354 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13355 varloc
= NOTE_VAR_LOCATION (loc_note
);
13356 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13357 if (cur_descr
== NULL
)
13359 padsize
+= bitsize
;
13363 /* Check that cur_descr either doesn't use
13364 DW_OP_*piece operations, or their sum is equal
13365 to bitsize. Otherwise we can't embed it. */
13366 for (tail
= &cur_descr
; *tail
!= NULL
;
13367 tail
= &(*tail
)->dw_loc_next
)
13368 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13370 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13374 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13376 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13380 if (last
!= NULL
&& opsize
!= bitsize
)
13382 padsize
+= bitsize
;
13386 /* If there is a hole, add DW_OP_*piece after empty DWARF
13387 expression, which means that those bits are optimized out. */
13390 if (padsize
> decl_size
)
13392 decl_size
-= padsize
;
13393 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13394 if (*descr_tail
== NULL
)
13396 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13399 *descr_tail
= cur_descr
;
13401 if (bitsize
> decl_size
)
13403 decl_size
-= bitsize
;
13406 HOST_WIDE_INT offset
= 0;
13407 if (GET_CODE (varloc
) == VAR_LOCATION
13408 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13410 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13411 if (GET_CODE (varloc
) == EXPR_LIST
)
13412 varloc
= XEXP (varloc
, 0);
13416 if (GET_CODE (varloc
) == CONST
13417 || GET_CODE (varloc
) == SIGN_EXTEND
13418 || GET_CODE (varloc
) == ZERO_EXTEND
)
13419 varloc
= XEXP (varloc
, 0);
13420 else if (GET_CODE (varloc
) == SUBREG
)
13421 varloc
= SUBREG_REG (varloc
);
13426 /* DW_OP_bit_size offset should be zero for register
13427 or implicit location descriptions and empty location
13428 descriptions, but for memory addresses needs big endian
13430 if (MEM_P (varloc
))
13432 unsigned HOST_WIDE_INT memsize
13433 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13434 if (memsize
!= bitsize
)
13436 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13437 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13439 if (memsize
< bitsize
)
13441 if (BITS_BIG_ENDIAN
)
13442 offset
= memsize
- bitsize
;
13446 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13447 if (*descr_tail
== NULL
)
13449 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13453 /* If there were any non-empty expressions, add padding till the end of
13455 if (descr
!= NULL
&& decl_size
!= 0)
13457 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13458 if (*descr_tail
== NULL
)
13464 /* Return the dwarf representation of the location list LOC_LIST of
13465 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13468 static dw_loc_list_ref
13469 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13471 const char *endname
, *secname
;
13473 enum var_init_status initialized
;
13474 struct var_loc_node
*node
;
13475 dw_loc_descr_ref descr
;
13476 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13477 dw_loc_list_ref list
= NULL
;
13478 dw_loc_list_ref
*listp
= &list
;
13480 /* Now that we know what section we are using for a base,
13481 actually construct the list of locations.
13482 The first location information is what is passed to the
13483 function that creates the location list, and the remaining
13484 locations just get added on to that list.
13485 Note that we only know the start address for a location
13486 (IE location changes), so to build the range, we use
13487 the range [current location start, next location start].
13488 This means we have to special case the last node, and generate
13489 a range of [last location start, end of function label]. */
13491 secname
= secname_for_decl (decl
);
13493 for (node
= loc_list
->first
; node
; node
= node
->next
)
13494 if (GET_CODE (node
->loc
) == EXPR_LIST
13495 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13497 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13499 /* This requires DW_OP_{,bit_}piece, which is not usable
13500 inside DWARF expressions. */
13501 if (want_address
!= 2)
13503 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13509 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13510 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13511 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13515 bool range_across_switch
= false;
13516 /* If section switch happens in between node->label
13517 and node->next->label (or end of function) and
13518 we can't emit it as a single entry list,
13519 emit two ranges, first one ending at the end
13520 of first partition and second one starting at the
13521 beginning of second partition. */
13522 if (node
== loc_list
->last_before_switch
13523 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13524 && current_function_decl
)
13526 endname
= cfun
->fde
->dw_fde_end
;
13527 range_across_switch
= true;
13529 /* The variable has a location between NODE->LABEL and
13530 NODE->NEXT->LABEL. */
13531 else if (node
->next
)
13532 endname
= node
->next
->label
;
13533 /* If the variable has a location at the last label
13534 it keeps its location until the end of function. */
13535 else if (!current_function_decl
)
13536 endname
= text_end_label
;
13539 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13540 current_function_funcdef_no
);
13541 endname
= ggc_strdup (label_id
);
13544 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13545 if (TREE_CODE (decl
) == PARM_DECL
13546 && node
== loc_list
->first
13547 && NOTE_P (node
->loc
)
13548 && strcmp (node
->label
, endname
) == 0)
13549 (*listp
)->force
= true;
13550 listp
= &(*listp
)->dw_loc_next
;
13552 if (range_across_switch
)
13554 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13555 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13558 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13559 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13560 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13563 gcc_assert (descr
);
13564 /* The variable has a location between NODE->LABEL and
13565 NODE->NEXT->LABEL. */
13567 endname
= node
->next
->label
;
13569 endname
= cfun
->fde
->dw_fde_second_end
;
13570 *listp
= new_loc_list (descr
,
13571 cfun
->fde
->dw_fde_second_begin
,
13573 listp
= &(*listp
)->dw_loc_next
;
13578 /* Try to avoid the overhead of a location list emitting a location
13579 expression instead, but only if we didn't have more than one
13580 location entry in the first place. If some entries were not
13581 representable, we don't want to pretend a single entry that was
13582 applies to the entire scope in which the variable is
13584 if (list
&& loc_list
->first
->next
)
13590 /* Return if the loc_list has only single element and thus can be represented
13591 as location description. */
13594 single_element_loc_list_p (dw_loc_list_ref list
)
13596 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
13597 return !list
->ll_symbol
;
13600 /* To each location in list LIST add loc descr REF. */
13603 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
13605 dw_loc_descr_ref copy
;
13606 add_loc_descr (&list
->expr
, ref
);
13607 list
= list
->dw_loc_next
;
13610 copy
= ggc_alloc_dw_loc_descr_node ();
13611 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
13612 add_loc_descr (&list
->expr
, copy
);
13613 while (copy
->dw_loc_next
)
13615 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
13616 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
13617 copy
->dw_loc_next
= new_copy
;
13620 list
= list
->dw_loc_next
;
13624 /* Given two lists RET and LIST
13625 produce location list that is result of adding expression in LIST
13626 to expression in RET on each position in program.
13627 Might be destructive on both RET and LIST.
13629 TODO: We handle only simple cases of RET or LIST having at most one
13630 element. General case would inolve sorting the lists in program order
13631 and merging them that will need some additional work.
13632 Adding that will improve quality of debug info especially for SRA-ed
13636 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
13645 if (!list
->dw_loc_next
)
13647 add_loc_descr_to_each (*ret
, list
->expr
);
13650 if (!(*ret
)->dw_loc_next
)
13652 add_loc_descr_to_each (list
, (*ret
)->expr
);
13656 expansion_failed (NULL_TREE
, NULL_RTX
,
13657 "Don't know how to merge two non-trivial"
13658 " location lists.\n");
13663 /* LOC is constant expression. Try a luck, look it up in constant
13664 pool and return its loc_descr of its address. */
13666 static dw_loc_descr_ref
13667 cst_pool_loc_descr (tree loc
)
13669 /* Get an RTL for this, if something has been emitted. */
13670 rtx rtl
= lookup_constant_def (loc
);
13672 if (!rtl
|| !MEM_P (rtl
))
13677 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
13679 /* TODO: We might get more coverage if we was actually delaying expansion
13680 of all expressions till end of compilation when constant pools are fully
13682 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
13684 expansion_failed (loc
, NULL_RTX
,
13685 "CST value in contant pool but not marked.");
13688 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13689 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
13692 /* Return dw_loc_list representing address of addr_expr LOC
13693 by looking for inner INDIRECT_REF expression and turning
13694 it into simple arithmetics. */
13696 static dw_loc_list_ref
13697 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
13700 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13701 enum machine_mode mode
;
13702 int unsignedp
, volatilep
= 0;
13703 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13705 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
13706 &bitsize
, &bitpos
, &offset
, &mode
,
13707 &unsignedp
, &volatilep
, false);
13709 if (bitpos
% BITS_PER_UNIT
)
13711 expansion_failed (loc
, NULL_RTX
, "bitfield access");
13714 if (!INDIRECT_REF_P (obj
))
13716 expansion_failed (obj
,
13717 NULL_RTX
, "no indirect ref in inner refrence");
13720 if (!offset
&& !bitpos
)
13721 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
13723 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
13724 && (dwarf_version
>= 4 || !dwarf_strict
))
13726 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
13731 /* Variable offset. */
13732 list_ret1
= loc_list_from_tree (offset
, 0);
13733 if (list_ret1
== 0)
13735 add_loc_list (&list_ret
, list_ret1
);
13738 add_loc_descr_to_each (list_ret
,
13739 new_loc_descr (DW_OP_plus
, 0, 0));
13741 bytepos
= bitpos
/ BITS_PER_UNIT
;
13743 add_loc_descr_to_each (list_ret
,
13744 new_loc_descr (DW_OP_plus_uconst
,
13746 else if (bytepos
< 0)
13747 loc_list_plus_const (list_ret
, bytepos
);
13748 add_loc_descr_to_each (list_ret
,
13749 new_loc_descr (DW_OP_stack_value
, 0, 0));
13755 /* Generate Dwarf location list representing LOC.
13756 If WANT_ADDRESS is false, expression computing LOC will be computed
13757 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
13758 if WANT_ADDRESS is 2, expression computing address useable in location
13759 will be returned (i.e. DW_OP_reg can be used
13760 to refer to register values). */
13762 static dw_loc_list_ref
13763 loc_list_from_tree (tree loc
, int want_address
)
13765 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
13766 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
13767 int have_address
= 0;
13768 enum dwarf_location_atom op
;
13770 /* ??? Most of the time we do not take proper care for sign/zero
13771 extending the values properly. Hopefully this won't be a real
13774 switch (TREE_CODE (loc
))
13777 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
13780 case PLACEHOLDER_EXPR
:
13781 /* This case involves extracting fields from an object to determine the
13782 position of other fields. We don't try to encode this here. The
13783 only user of this is Ada, which encodes the needed information using
13784 the names of types. */
13785 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
13789 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
13790 /* There are no opcodes for these operations. */
13793 case PREINCREMENT_EXPR
:
13794 case PREDECREMENT_EXPR
:
13795 case POSTINCREMENT_EXPR
:
13796 case POSTDECREMENT_EXPR
:
13797 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
13798 /* There are no opcodes for these operations. */
13802 /* If we already want an address, see if there is INDIRECT_REF inside
13803 e.g. for &this->field. */
13806 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
13807 (loc
, want_address
== 2);
13810 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
13811 && (ret
= cst_pool_loc_descr (loc
)))
13814 /* Otherwise, process the argument and look for the address. */
13815 if (!list_ret
&& !ret
)
13816 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
13820 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
13826 if (DECL_THREAD_LOCAL_P (loc
))
13829 enum dwarf_location_atom tls_op
;
13830 enum dtprel_bool dtprel
= dtprel_false
;
13832 if (targetm
.have_tls
)
13834 /* If this is not defined, we have no way to emit the
13836 if (!targetm
.asm_out
.output_dwarf_dtprel
)
13839 /* The way DW_OP_GNU_push_tls_address is specified, we
13840 can only look up addresses of objects in the current
13841 module. We used DW_OP_addr as first op, but that's
13842 wrong, because DW_OP_addr is relocated by the debug
13843 info consumer, while DW_OP_GNU_push_tls_address
13844 operand shouldn't be. */
13845 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
13847 dtprel
= dtprel_true
;
13848 tls_op
= DW_OP_GNU_push_tls_address
;
13852 if (!targetm
.emutls
.debug_form_tls_address
13853 || !(dwarf_version
>= 3 || !dwarf_strict
))
13855 /* We stuffed the control variable into the DECL_VALUE_EXPR
13856 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
13857 no longer appear in gimple code. We used the control
13858 variable in specific so that we could pick it up here. */
13859 loc
= DECL_VALUE_EXPR (loc
);
13860 tls_op
= DW_OP_form_tls_address
;
13863 rtl
= rtl_for_decl_location (loc
);
13864 if (rtl
== NULL_RTX
)
13869 rtl
= XEXP (rtl
, 0);
13870 if (! CONSTANT_P (rtl
))
13873 ret
= new_addr_loc_descr (rtl
, dtprel
);
13874 ret1
= new_loc_descr (tls_op
, 0, 0);
13875 add_loc_descr (&ret
, ret1
);
13884 if (DECL_HAS_VALUE_EXPR_P (loc
))
13885 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
13889 case FUNCTION_DECL
:
13892 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
13894 if (loc_list
&& loc_list
->first
)
13896 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
13897 have_address
= want_address
!= 0;
13900 rtl
= rtl_for_decl_location (loc
);
13901 if (rtl
== NULL_RTX
)
13903 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
13906 else if (CONST_INT_P (rtl
))
13908 HOST_WIDE_INT val
= INTVAL (rtl
);
13909 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
13910 val
&= GET_MODE_MASK (DECL_MODE (loc
));
13911 ret
= int_loc_descriptor (val
);
13913 else if (GET_CODE (rtl
) == CONST_STRING
)
13915 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
13918 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
13919 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
13922 enum machine_mode mode
, mem_mode
;
13924 /* Certain constructs can only be represented at top-level. */
13925 if (want_address
== 2)
13927 ret
= loc_descriptor (rtl
, VOIDmode
,
13928 VAR_INIT_STATUS_INITIALIZED
);
13933 mode
= GET_MODE (rtl
);
13934 mem_mode
= VOIDmode
;
13938 mode
= get_address_mode (rtl
);
13939 rtl
= XEXP (rtl
, 0);
13942 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
13943 VAR_INIT_STATUS_INITIALIZED
);
13946 expansion_failed (loc
, rtl
,
13947 "failed to produce loc descriptor for rtl");
13954 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
13958 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
13962 case COMPOUND_EXPR
:
13963 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
13966 case VIEW_CONVERT_EXPR
:
13969 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
13971 case COMPONENT_REF
:
13972 case BIT_FIELD_REF
:
13974 case ARRAY_RANGE_REF
:
13975 case REALPART_EXPR
:
13976 case IMAGPART_EXPR
:
13979 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
13980 enum machine_mode mode
;
13981 int unsignedp
, volatilep
= 0;
13983 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
13984 &unsignedp
, &volatilep
, false);
13986 gcc_assert (obj
!= loc
);
13988 list_ret
= loc_list_from_tree (obj
,
13990 && !bitpos
&& !offset
? 2 : 1);
13991 /* TODO: We can extract value of the small expression via shifting even
13992 for nonzero bitpos. */
13995 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
13997 expansion_failed (loc
, NULL_RTX
,
13998 "bitfield access");
14002 if (offset
!= NULL_TREE
)
14004 /* Variable offset. */
14005 list_ret1
= loc_list_from_tree (offset
, 0);
14006 if (list_ret1
== 0)
14008 add_loc_list (&list_ret
, list_ret1
);
14011 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14014 bytepos
= bitpos
/ BITS_PER_UNIT
;
14016 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14017 else if (bytepos
< 0)
14018 loc_list_plus_const (list_ret
, bytepos
);
14025 if ((want_address
|| !host_integerp (loc
, 0))
14026 && (ret
= cst_pool_loc_descr (loc
)))
14028 else if (want_address
== 2
14029 && host_integerp (loc
, 0)
14030 && (ret
= address_of_int_loc_descriptor
14031 (int_size_in_bytes (TREE_TYPE (loc
)),
14032 tree_low_cst (loc
, 0))))
14034 else if (host_integerp (loc
, 0))
14035 ret
= int_loc_descriptor (tree_low_cst (loc
, 0));
14038 expansion_failed (loc
, NULL_RTX
,
14039 "Integer operand is not host integer");
14048 if ((ret
= cst_pool_loc_descr (loc
)))
14051 /* We can construct small constants here using int_loc_descriptor. */
14052 expansion_failed (loc
, NULL_RTX
,
14053 "constructor or constant not in constant pool");
14056 case TRUTH_AND_EXPR
:
14057 case TRUTH_ANDIF_EXPR
:
14062 case TRUTH_XOR_EXPR
:
14067 case TRUTH_OR_EXPR
:
14068 case TRUTH_ORIF_EXPR
:
14073 case FLOOR_DIV_EXPR
:
14074 case CEIL_DIV_EXPR
:
14075 case ROUND_DIV_EXPR
:
14076 case TRUNC_DIV_EXPR
:
14077 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14086 case FLOOR_MOD_EXPR
:
14087 case CEIL_MOD_EXPR
:
14088 case ROUND_MOD_EXPR
:
14089 case TRUNC_MOD_EXPR
:
14090 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14095 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14096 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14097 if (list_ret
== 0 || list_ret1
== 0)
14100 add_loc_list (&list_ret
, list_ret1
);
14103 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14104 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14105 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14106 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14107 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14119 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14122 case POINTER_PLUS_EXPR
:
14124 if (host_integerp (TREE_OPERAND (loc
, 1), 0))
14126 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14130 loc_list_plus_const (list_ret
, tree_low_cst (TREE_OPERAND (loc
, 1), 0));
14138 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14145 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14152 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14159 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14174 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14175 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14176 if (list_ret
== 0 || list_ret1
== 0)
14179 add_loc_list (&list_ret
, list_ret1
);
14182 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14185 case TRUTH_NOT_EXPR
:
14199 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14203 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14209 const enum tree_code code
=
14210 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14212 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14213 build2 (code
, integer_type_node
,
14214 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14215 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14218 /* ... fall through ... */
14222 dw_loc_descr_ref lhs
14223 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14224 dw_loc_list_ref rhs
14225 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14226 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14228 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14229 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14232 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14233 add_loc_descr_to_each (list_ret
, bra_node
);
14235 add_loc_list (&list_ret
, rhs
);
14236 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14237 add_loc_descr_to_each (list_ret
, jump_node
);
14239 add_loc_descr_to_each (list_ret
, lhs
);
14240 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14241 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14243 /* ??? Need a node to point the skip at. Use a nop. */
14244 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14245 add_loc_descr_to_each (list_ret
, tmp
);
14246 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14247 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14251 case FIX_TRUNC_EXPR
:
14255 /* Leave front-end specific codes as simply unknown. This comes
14256 up, for instance, with the C STMT_EXPR. */
14257 if ((unsigned int) TREE_CODE (loc
)
14258 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14260 expansion_failed (loc
, NULL_RTX
,
14261 "language specific tree node");
14265 #ifdef ENABLE_CHECKING
14266 /* Otherwise this is a generic code; we should just lists all of
14267 these explicitly. We forgot one. */
14268 gcc_unreachable ();
14270 /* In a release build, we want to degrade gracefully: better to
14271 generate incomplete debugging information than to crash. */
14276 if (!ret
&& !list_ret
)
14279 if (want_address
== 2 && !have_address
14280 && (dwarf_version
>= 4 || !dwarf_strict
))
14282 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14284 expansion_failed (loc
, NULL_RTX
,
14285 "DWARF address size mismatch");
14289 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14291 add_loc_descr_to_each (list_ret
,
14292 new_loc_descr (DW_OP_stack_value
, 0, 0));
14295 /* Show if we can't fill the request for an address. */
14296 if (want_address
&& !have_address
)
14298 expansion_failed (loc
, NULL_RTX
,
14299 "Want address and only have value");
14303 gcc_assert (!ret
|| !list_ret
);
14305 /* If we've got an address and don't want one, dereference. */
14306 if (!want_address
&& have_address
)
14308 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14310 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14312 expansion_failed (loc
, NULL_RTX
,
14313 "DWARF address size mismatch");
14316 else if (size
== DWARF2_ADDR_SIZE
)
14319 op
= DW_OP_deref_size
;
14322 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14324 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14327 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14332 /* Same as above but return only single location expression. */
14333 static dw_loc_descr_ref
14334 loc_descriptor_from_tree (tree loc
, int want_address
)
14336 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14339 if (ret
->dw_loc_next
)
14341 expansion_failed (loc
, NULL_RTX
,
14342 "Location list where only loc descriptor needed");
14348 /* Given a value, round it up to the lowest multiple of `boundary'
14349 which is not less than the value itself. */
14351 static inline HOST_WIDE_INT
14352 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14354 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14357 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14358 pointer to the declared type for the relevant field variable, or return
14359 `integer_type_node' if the given node turns out to be an
14360 ERROR_MARK node. */
14363 field_type (const_tree decl
)
14367 if (TREE_CODE (decl
) == ERROR_MARK
)
14368 return integer_type_node
;
14370 type
= DECL_BIT_FIELD_TYPE (decl
);
14371 if (type
== NULL_TREE
)
14372 type
= TREE_TYPE (decl
);
14377 /* Given a pointer to a tree node, return the alignment in bits for
14378 it, or else return BITS_PER_WORD if the node actually turns out to
14379 be an ERROR_MARK node. */
14381 static inline unsigned
14382 simple_type_align_in_bits (const_tree type
)
14384 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14387 static inline unsigned
14388 simple_decl_align_in_bits (const_tree decl
)
14390 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14393 /* Return the result of rounding T up to ALIGN. */
14395 static inline double_int
14396 round_up_to_align (double_int t
, unsigned int align
)
14398 double_int alignd
= double_int::from_uhwi (align
);
14400 t
+= double_int_minus_one
;
14401 t
= t
.div (alignd
, true, TRUNC_DIV_EXPR
);
14406 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14407 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14408 or return 0 if we are unable to determine what that offset is, either
14409 because the argument turns out to be a pointer to an ERROR_MARK node, or
14410 because the offset is actually variable. (We can't handle the latter case
14413 static HOST_WIDE_INT
14414 field_byte_offset (const_tree decl
)
14416 double_int object_offset_in_bits
;
14417 double_int object_offset_in_bytes
;
14418 double_int bitpos_int
;
14420 if (TREE_CODE (decl
) == ERROR_MARK
)
14423 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14425 /* We cannot yet cope with fields whose positions are variable, so
14426 for now, when we see such things, we simply return 0. Someday, we may
14427 be able to handle such cases, but it will be damn difficult. */
14428 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14431 bitpos_int
= tree_to_double_int (bit_position (decl
));
14433 #ifdef PCC_BITFIELD_TYPE_MATTERS
14434 if (PCC_BITFIELD_TYPE_MATTERS
)
14437 tree field_size_tree
;
14438 double_int deepest_bitpos
;
14439 double_int field_size_in_bits
;
14440 unsigned int type_align_in_bits
;
14441 unsigned int decl_align_in_bits
;
14442 double_int type_size_in_bits
;
14444 type
= field_type (decl
);
14445 type_size_in_bits
= double_int_type_size_in_bits (type
);
14446 type_align_in_bits
= simple_type_align_in_bits (type
);
14448 field_size_tree
= DECL_SIZE (decl
);
14450 /* The size could be unspecified if there was an error, or for
14451 a flexible array member. */
14452 if (!field_size_tree
)
14453 field_size_tree
= bitsize_zero_node
;
14455 /* If the size of the field is not constant, use the type size. */
14456 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14457 field_size_in_bits
= tree_to_double_int (field_size_tree
);
14459 field_size_in_bits
= type_size_in_bits
;
14461 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14463 /* The GCC front-end doesn't make any attempt to keep track of the
14464 starting bit offset (relative to the start of the containing
14465 structure type) of the hypothetical "containing object" for a
14466 bit-field. Thus, when computing the byte offset value for the
14467 start of the "containing object" of a bit-field, we must deduce
14468 this information on our own. This can be rather tricky to do in
14469 some cases. For example, handling the following structure type
14470 definition when compiling for an i386/i486 target (which only
14471 aligns long long's to 32-bit boundaries) can be very tricky:
14473 struct S { int field1; long long field2:31; };
14475 Fortunately, there is a simple rule-of-thumb which can be used
14476 in such cases. When compiling for an i386/i486, GCC will
14477 allocate 8 bytes for the structure shown above. It decides to
14478 do this based upon one simple rule for bit-field allocation.
14479 GCC allocates each "containing object" for each bit-field at
14480 the first (i.e. lowest addressed) legitimate alignment boundary
14481 (based upon the required minimum alignment for the declared
14482 type of the field) which it can possibly use, subject to the
14483 condition that there is still enough available space remaining
14484 in the containing object (when allocated at the selected point)
14485 to fully accommodate all of the bits of the bit-field itself.
14487 This simple rule makes it obvious why GCC allocates 8 bytes for
14488 each object of the structure type shown above. When looking
14489 for a place to allocate the "containing object" for `field2',
14490 the compiler simply tries to allocate a 64-bit "containing
14491 object" at each successive 32-bit boundary (starting at zero)
14492 until it finds a place to allocate that 64- bit field such that
14493 at least 31 contiguous (and previously unallocated) bits remain
14494 within that selected 64 bit field. (As it turns out, for the
14495 example above, the compiler finds it is OK to allocate the
14496 "containing object" 64-bit field at bit-offset zero within the
14499 Here we attempt to work backwards from the limited set of facts
14500 we're given, and we try to deduce from those facts, where GCC
14501 must have believed that the containing object started (within
14502 the structure type). The value we deduce is then used (by the
14503 callers of this routine) to generate DW_AT_location and
14504 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14505 the case of DW_AT_location, regular fields as well). */
14507 /* Figure out the bit-distance from the start of the structure to
14508 the "deepest" bit of the bit-field. */
14509 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14511 /* This is the tricky part. Use some fancy footwork to deduce
14512 where the lowest addressed bit of the containing object must
14514 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14516 /* Round up to type_align by default. This works best for
14518 object_offset_in_bits
14519 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14521 if (object_offset_in_bits
.ugt (bitpos_int
))
14523 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14525 /* Round up to decl_align instead. */
14526 object_offset_in_bits
14527 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14531 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14532 object_offset_in_bits
= bitpos_int
;
14534 object_offset_in_bytes
14535 = object_offset_in_bits
.div (double_int::from_uhwi (BITS_PER_UNIT
),
14536 true, TRUNC_DIV_EXPR
);
14537 return object_offset_in_bytes
.to_shwi ();
14540 /* The following routines define various Dwarf attributes and any data
14541 associated with them. */
14543 /* Add a location description attribute value to a DIE.
14545 This emits location attributes suitable for whole variables and
14546 whole parameters. Note that the location attributes for struct fields are
14547 generated by the routine `data_member_location_attribute' below. */
14550 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14551 dw_loc_list_ref descr
)
14555 if (single_element_loc_list_p (descr
))
14556 add_AT_loc (die
, attr_kind
, descr
->expr
);
14558 add_AT_loc_list (die
, attr_kind
, descr
);
14561 /* Add DW_AT_accessibility attribute to DIE if needed. */
14564 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14566 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14567 children, otherwise the default is DW_ACCESS_public. In DWARF2
14568 the default has always been DW_ACCESS_public. */
14569 if (TREE_PROTECTED (decl
))
14570 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14571 else if (TREE_PRIVATE (decl
))
14573 if (dwarf_version
== 2
14574 || die
->die_parent
== NULL
14575 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14576 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14578 else if (dwarf_version
> 2
14580 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
14581 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
14584 /* Attach the specialized form of location attribute used for data members of
14585 struct and union types. In the special case of a FIELD_DECL node which
14586 represents a bit-field, the "offset" part of this special location
14587 descriptor must indicate the distance in bytes from the lowest-addressed
14588 byte of the containing struct or union type to the lowest-addressed byte of
14589 the "containing object" for the bit-field. (See the `field_byte_offset'
14592 For any given bit-field, the "containing object" is a hypothetical object
14593 (of some integral or enum type) within which the given bit-field lives. The
14594 type of this hypothetical "containing object" is always the same as the
14595 declared type of the individual bit-field itself (for GCC anyway... the
14596 DWARF spec doesn't actually mandate this). Note that it is the size (in
14597 bytes) of the hypothetical "containing object" which will be given in the
14598 DW_AT_byte_size attribute for this bit-field. (See the
14599 `byte_size_attribute' function below.) It is also used when calculating the
14600 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
14601 function below.) */
14604 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
14606 HOST_WIDE_INT offset
;
14607 dw_loc_descr_ref loc_descr
= 0;
14609 if (TREE_CODE (decl
) == TREE_BINFO
)
14611 /* We're working on the TAG_inheritance for a base class. */
14612 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
14614 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
14615 aren't at a fixed offset from all (sub)objects of the same
14616 type. We need to extract the appropriate offset from our
14617 vtable. The following dwarf expression means
14619 BaseAddr = ObAddr + *((*ObAddr) - Offset)
14621 This is specific to the V3 ABI, of course. */
14623 dw_loc_descr_ref tmp
;
14625 /* Make a copy of the object address. */
14626 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
14627 add_loc_descr (&loc_descr
, tmp
);
14629 /* Extract the vtable address. */
14630 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14631 add_loc_descr (&loc_descr
, tmp
);
14633 /* Calculate the address of the offset. */
14634 offset
= tree_low_cst (BINFO_VPTR_FIELD (decl
), 0);
14635 gcc_assert (offset
< 0);
14637 tmp
= int_loc_descriptor (-offset
);
14638 add_loc_descr (&loc_descr
, tmp
);
14639 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
14640 add_loc_descr (&loc_descr
, tmp
);
14642 /* Extract the offset. */
14643 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
14644 add_loc_descr (&loc_descr
, tmp
);
14646 /* Add it to the object address. */
14647 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
14648 add_loc_descr (&loc_descr
, tmp
);
14651 offset
= tree_low_cst (BINFO_OFFSET (decl
), 0);
14654 offset
= field_byte_offset (decl
);
14658 if (dwarf_version
> 2)
14660 /* Don't need to output a location expression, just the constant. */
14662 add_AT_int (die
, DW_AT_data_member_location
, offset
);
14664 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
14669 enum dwarf_location_atom op
;
14671 /* The DWARF2 standard says that we should assume that the structure
14672 address is already on the stack, so we can specify a structure
14673 field address by using DW_OP_plus_uconst. */
14674 op
= DW_OP_plus_uconst
;
14675 loc_descr
= new_loc_descr (op
, offset
, 0);
14679 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
14682 /* Writes integer values to dw_vec_const array. */
14685 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
14689 *dest
++ = val
& 0xff;
14695 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
14697 static HOST_WIDE_INT
14698 extract_int (const unsigned char *src
, unsigned int size
)
14700 HOST_WIDE_INT val
= 0;
14706 val
|= *--src
& 0xff;
14712 /* Writes double_int values to dw_vec_const array. */
14715 insert_double (double_int val
, unsigned char *dest
)
14717 unsigned char *p0
= dest
;
14718 unsigned char *p1
= dest
+ sizeof (HOST_WIDE_INT
);
14720 if (WORDS_BIG_ENDIAN
)
14726 insert_int ((HOST_WIDE_INT
) val
.low
, sizeof (HOST_WIDE_INT
), p0
);
14727 insert_int ((HOST_WIDE_INT
) val
.high
, sizeof (HOST_WIDE_INT
), p1
);
14730 /* Writes floating point values to dw_vec_const array. */
14733 insert_float (const_rtx rtl
, unsigned char *array
)
14735 REAL_VALUE_TYPE rv
;
14739 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
14740 real_to_target (val
, &rv
, GET_MODE (rtl
));
14742 /* real_to_target puts 32-bit pieces in each long. Pack them. */
14743 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
14745 insert_int (val
[i
], 4, array
);
14750 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
14751 does not have a "location" either in memory or in a register. These
14752 things can arise in GNU C when a constant is passed as an actual parameter
14753 to an inlined function. They can also arise in C++ where declared
14754 constants do not necessarily get memory "homes". */
14757 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
14759 switch (GET_CODE (rtl
))
14763 HOST_WIDE_INT val
= INTVAL (rtl
);
14766 add_AT_int (die
, DW_AT_const_value
, val
);
14768 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
14773 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
14774 floating-point constant. A CONST_DOUBLE is used whenever the
14775 constant requires more than one word in order to be adequately
14778 enum machine_mode mode
= GET_MODE (rtl
);
14780 if (SCALAR_FLOAT_MODE_P (mode
))
14782 unsigned int length
= GET_MODE_SIZE (mode
);
14783 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
14785 insert_float (rtl
, array
);
14786 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
14789 add_AT_double (die
, DW_AT_const_value
,
14790 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
14796 enum machine_mode mode
= GET_MODE (rtl
);
14797 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
14798 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
14799 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
14800 (length
* elt_size
);
14804 switch (GET_MODE_CLASS (mode
))
14806 case MODE_VECTOR_INT
:
14807 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14809 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14810 double_int val
= rtx_to_double_int (elt
);
14812 if (elt_size
<= sizeof (HOST_WIDE_INT
))
14813 insert_int (val
.to_shwi (), elt_size
, p
);
14816 gcc_assert (elt_size
== 2 * sizeof (HOST_WIDE_INT
));
14817 insert_double (val
, p
);
14822 case MODE_VECTOR_FLOAT
:
14823 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
14825 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
14826 insert_float (elt
, p
);
14831 gcc_unreachable ();
14834 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
14839 if (dwarf_version
>= 4 || !dwarf_strict
)
14841 dw_loc_descr_ref loc_result
;
14842 resolve_one_addr (&rtl
, NULL
);
14844 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
14845 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14846 add_AT_loc (die
, DW_AT_location
, loc_result
);
14847 vec_safe_push (used_rtx_array
, rtl
);
14853 if (CONSTANT_P (XEXP (rtl
, 0)))
14854 return add_const_value_attribute (die
, XEXP (rtl
, 0));
14857 if (!const_ok_for_output (rtl
))
14860 if (dwarf_version
>= 4 || !dwarf_strict
)
14865 /* In cases where an inlined instance of an inline function is passed
14866 the address of an `auto' variable (which is local to the caller) we
14867 can get a situation where the DECL_RTL of the artificial local
14868 variable (for the inlining) which acts as a stand-in for the
14869 corresponding formal parameter (of the inline function) will look
14870 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
14871 exactly a compile-time constant expression, but it isn't the address
14872 of the (artificial) local variable either. Rather, it represents the
14873 *value* which the artificial local variable always has during its
14874 lifetime. We currently have no way to represent such quasi-constant
14875 values in Dwarf, so for now we just punt and generate nothing. */
14883 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
14884 && MEM_READONLY_P (rtl
)
14885 && GET_MODE (rtl
) == BLKmode
)
14887 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
14893 /* No other kinds of rtx should be possible here. */
14894 gcc_unreachable ();
14899 /* Determine whether the evaluation of EXPR references any variables
14900 or functions which aren't otherwise used (and therefore may not be
14903 reference_to_unused (tree
* tp
, int * walk_subtrees
,
14904 void * data ATTRIBUTE_UNUSED
)
14906 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
14907 *walk_subtrees
= 0;
14909 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
14910 && ! TREE_ASM_WRITTEN (*tp
))
14912 /* ??? The C++ FE emits debug information for using decls, so
14913 putting gcc_unreachable here falls over. See PR31899. For now
14914 be conservative. */
14915 else if (!cgraph_global_info_ready
14916 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
14918 else if (TREE_CODE (*tp
) == VAR_DECL
)
14920 struct varpool_node
*node
= varpool_get_node (*tp
);
14921 if (!node
|| !node
->analyzed
)
14924 else if (TREE_CODE (*tp
) == FUNCTION_DECL
14925 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
14927 /* The call graph machinery must have finished analyzing,
14928 optimizing and gimplifying the CU by now.
14929 So if *TP has no call graph node associated
14930 to it, it means *TP will not be emitted. */
14931 if (!cgraph_get_node (*tp
))
14934 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
14940 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
14941 for use in a later add_const_value_attribute call. */
14944 rtl_for_decl_init (tree init
, tree type
)
14946 rtx rtl
= NULL_RTX
;
14950 /* If a variable is initialized with a string constant without embedded
14951 zeros, build CONST_STRING. */
14952 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
14954 tree enttype
= TREE_TYPE (type
);
14955 tree domain
= TYPE_DOMAIN (type
);
14956 enum machine_mode mode
= TYPE_MODE (enttype
);
14958 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
14960 && integer_zerop (TYPE_MIN_VALUE (domain
))
14961 && compare_tree_int (TYPE_MAX_VALUE (domain
),
14962 TREE_STRING_LENGTH (init
) - 1) == 0
14963 && ((size_t) TREE_STRING_LENGTH (init
)
14964 == strlen (TREE_STRING_POINTER (init
)) + 1))
14966 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
14967 ggc_strdup (TREE_STRING_POINTER (init
)));
14968 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
14969 MEM_READONLY_P (rtl
) = 1;
14972 /* Other aggregates, and complex values, could be represented using
14974 else if (AGGREGATE_TYPE_P (type
)
14975 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
14976 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
14977 || TREE_CODE (type
) == COMPLEX_TYPE
)
14979 /* Vectors only work if their mode is supported by the target.
14980 FIXME: generic vectors ought to work too. */
14981 else if (TREE_CODE (type
) == VECTOR_TYPE
14982 && !VECTOR_MODE_P (TYPE_MODE (type
)))
14984 /* If the initializer is something that we know will expand into an
14985 immediate RTL constant, expand it now. We must be careful not to
14986 reference variables which won't be output. */
14987 else if (initializer_constant_valid_p (init
, type
)
14988 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
14990 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
14992 if (TREE_CODE (type
) == VECTOR_TYPE
)
14993 switch (TREE_CODE (init
))
14998 if (TREE_CONSTANT (init
))
15000 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15001 bool constant_p
= true;
15003 unsigned HOST_WIDE_INT ix
;
15005 /* Even when ctor is constant, it might contain non-*_CST
15006 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15007 belong into VECTOR_CST nodes. */
15008 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15009 if (!CONSTANT_CLASS_P (value
))
15011 constant_p
= false;
15017 init
= build_vector_from_ctor (type
, elts
);
15027 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15029 /* If expand_expr returns a MEM, it wasn't immediate. */
15030 gcc_assert (!rtl
|| !MEM_P (rtl
));
15036 /* Generate RTL for the variable DECL to represent its location. */
15039 rtl_for_decl_location (tree decl
)
15043 /* Here we have to decide where we are going to say the parameter "lives"
15044 (as far as the debugger is concerned). We only have a couple of
15045 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15047 DECL_RTL normally indicates where the parameter lives during most of the
15048 activation of the function. If optimization is enabled however, this
15049 could be either NULL or else a pseudo-reg. Both of those cases indicate
15050 that the parameter doesn't really live anywhere (as far as the code
15051 generation parts of GCC are concerned) during most of the function's
15052 activation. That will happen (for example) if the parameter is never
15053 referenced within the function.
15055 We could just generate a location descriptor here for all non-NULL
15056 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15057 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15058 where DECL_RTL is NULL or is a pseudo-reg.
15060 Note however that we can only get away with using DECL_INCOMING_RTL as
15061 a backup substitute for DECL_RTL in certain limited cases. In cases
15062 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15063 we can be sure that the parameter was passed using the same type as it is
15064 declared to have within the function, and that its DECL_INCOMING_RTL
15065 points us to a place where a value of that type is passed.
15067 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15068 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15069 because in these cases DECL_INCOMING_RTL points us to a value of some
15070 type which is *different* from the type of the parameter itself. Thus,
15071 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15072 such cases, the debugger would end up (for example) trying to fetch a
15073 `float' from a place which actually contains the first part of a
15074 `double'. That would lead to really incorrect and confusing
15075 output at debug-time.
15077 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15078 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15079 are a couple of exceptions however. On little-endian machines we can
15080 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15081 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15082 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15083 when (on a little-endian machine) a non-prototyped function has a
15084 parameter declared to be of type `short' or `char'. In such cases,
15085 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15086 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15087 passed `int' value. If the debugger then uses that address to fetch
15088 a `short' or a `char' (on a little-endian machine) the result will be
15089 the correct data, so we allow for such exceptional cases below.
15091 Note that our goal here is to describe the place where the given formal
15092 parameter lives during most of the function's activation (i.e. between the
15093 end of the prologue and the start of the epilogue). We'll do that as best
15094 as we can. Note however that if the given formal parameter is modified
15095 sometime during the execution of the function, then a stack backtrace (at
15096 debug-time) will show the function as having been called with the *new*
15097 value rather than the value which was originally passed in. This happens
15098 rarely enough that it is not a major problem, but it *is* a problem, and
15099 I'd like to fix it.
15101 A future version of dwarf2out.c may generate two additional attributes for
15102 any given DW_TAG_formal_parameter DIE which will describe the "passed
15103 type" and the "passed location" for the given formal parameter in addition
15104 to the attributes we now generate to indicate the "declared type" and the
15105 "active location" for each parameter. This additional set of attributes
15106 could be used by debuggers for stack backtraces. Separately, note that
15107 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15108 This happens (for example) for inlined-instances of inline function formal
15109 parameters which are never referenced. This really shouldn't be
15110 happening. All PARM_DECL nodes should get valid non-NULL
15111 DECL_INCOMING_RTL values. FIXME. */
15113 /* Use DECL_RTL as the "location" unless we find something better. */
15114 rtl
= DECL_RTL_IF_SET (decl
);
15116 /* When generating abstract instances, ignore everything except
15117 constants, symbols living in memory, and symbols living in
15118 fixed registers. */
15119 if (! reload_completed
)
15122 && (CONSTANT_P (rtl
)
15124 && CONSTANT_P (XEXP (rtl
, 0)))
15126 && TREE_CODE (decl
) == VAR_DECL
15127 && TREE_STATIC (decl
))))
15129 rtl
= targetm
.delegitimize_address (rtl
);
15134 else if (TREE_CODE (decl
) == PARM_DECL
)
15136 if (rtl
== NULL_RTX
15137 || is_pseudo_reg (rtl
)
15139 && is_pseudo_reg (XEXP (rtl
, 0))
15140 && DECL_INCOMING_RTL (decl
)
15141 && MEM_P (DECL_INCOMING_RTL (decl
))
15142 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15144 tree declared_type
= TREE_TYPE (decl
);
15145 tree passed_type
= DECL_ARG_TYPE (decl
);
15146 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15147 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15149 /* This decl represents a formal parameter which was optimized out.
15150 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15151 all cases where (rtl == NULL_RTX) just below. */
15152 if (dmode
== pmode
)
15153 rtl
= DECL_INCOMING_RTL (decl
);
15154 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15155 && SCALAR_INT_MODE_P (dmode
)
15156 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15157 && DECL_INCOMING_RTL (decl
))
15159 rtx inc
= DECL_INCOMING_RTL (decl
);
15162 else if (MEM_P (inc
))
15164 if (BYTES_BIG_ENDIAN
)
15165 rtl
= adjust_address_nv (inc
, dmode
,
15166 GET_MODE_SIZE (pmode
)
15167 - GET_MODE_SIZE (dmode
));
15174 /* If the parm was passed in registers, but lives on the stack, then
15175 make a big endian correction if the mode of the type of the
15176 parameter is not the same as the mode of the rtl. */
15177 /* ??? This is the same series of checks that are made in dbxout.c before
15178 we reach the big endian correction code there. It isn't clear if all
15179 of these checks are necessary here, but keeping them all is the safe
15181 else if (MEM_P (rtl
)
15182 && XEXP (rtl
, 0) != const0_rtx
15183 && ! CONSTANT_P (XEXP (rtl
, 0))
15184 /* Not passed in memory. */
15185 && !MEM_P (DECL_INCOMING_RTL (decl
))
15186 /* Not passed by invisible reference. */
15187 && (!REG_P (XEXP (rtl
, 0))
15188 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15189 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15190 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15191 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15194 /* Big endian correction check. */
15195 && BYTES_BIG_ENDIAN
15196 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15197 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15200 enum machine_mode addr_mode
= get_address_mode (rtl
);
15201 int offset
= (UNITS_PER_WORD
15202 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15204 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15205 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15208 else if (TREE_CODE (decl
) == VAR_DECL
15211 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15212 && BYTES_BIG_ENDIAN
)
15214 enum machine_mode addr_mode
= get_address_mode (rtl
);
15215 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15216 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15218 /* If a variable is declared "register" yet is smaller than
15219 a register, then if we store the variable to memory, it
15220 looks like we're storing a register-sized value, when in
15221 fact we are not. We need to adjust the offset of the
15222 storage location to reflect the actual value's bytes,
15223 else gdb will not be able to display it. */
15225 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15226 plus_constant (addr_mode
, XEXP (rtl
, 0),
15230 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15231 and will have been substituted directly into all expressions that use it.
15232 C does not have such a concept, but C++ and other languages do. */
15233 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15234 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15237 rtl
= targetm
.delegitimize_address (rtl
);
15239 /* If we don't look past the constant pool, we risk emitting a
15240 reference to a constant pool entry that isn't referenced from
15241 code, and thus is not emitted. */
15243 rtl
= avoid_constant_pool_reference (rtl
);
15245 /* Try harder to get a rtl. If this symbol ends up not being emitted
15246 in the current CU, resolve_addr will remove the expression referencing
15248 if (rtl
== NULL_RTX
15249 && TREE_CODE (decl
) == VAR_DECL
15250 && !DECL_EXTERNAL (decl
)
15251 && TREE_STATIC (decl
)
15252 && DECL_NAME (decl
)
15253 && !DECL_HARD_REGISTER (decl
)
15254 && DECL_MODE (decl
) != VOIDmode
)
15256 rtl
= make_decl_rtl_for_debug (decl
);
15258 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15259 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15266 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15267 returned. If so, the decl for the COMMON block is returned, and the
15268 value is the offset into the common block for the symbol. */
15271 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15273 tree val_expr
, cvar
;
15274 enum machine_mode mode
;
15275 HOST_WIDE_INT bitsize
, bitpos
;
15277 int unsignedp
, volatilep
= 0;
15279 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15280 it does not have a value (the offset into the common area), or if it
15281 is thread local (as opposed to global) then it isn't common, and shouldn't
15282 be handled as such. */
15283 if (TREE_CODE (decl
) != VAR_DECL
15284 || !TREE_STATIC (decl
)
15285 || !DECL_HAS_VALUE_EXPR_P (decl
)
15289 val_expr
= DECL_VALUE_EXPR (decl
);
15290 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15293 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15294 &mode
, &unsignedp
, &volatilep
, true);
15296 if (cvar
== NULL_TREE
15297 || TREE_CODE (cvar
) != VAR_DECL
15298 || DECL_ARTIFICIAL (cvar
)
15299 || !TREE_PUBLIC (cvar
))
15303 if (offset
!= NULL
)
15305 if (!host_integerp (offset
, 0))
15307 *value
= tree_low_cst (offset
, 0);
15310 *value
+= bitpos
/ BITS_PER_UNIT
;
15315 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15316 data attribute for a variable or a parameter. We generate the
15317 DW_AT_const_value attribute only in those cases where the given variable
15318 or parameter does not have a true "location" either in memory or in a
15319 register. This can happen (for example) when a constant is passed as an
15320 actual argument in a call to an inline function. (It's possible that
15321 these things can crop up in other ways also.) Note that one type of
15322 constant value which can be passed into an inlined function is a constant
15323 pointer. This can happen for example if an actual argument in an inlined
15324 function call evaluates to a compile-time constant address.
15326 CACHE_P is true if it is worth caching the location list for DECL,
15327 so that future calls can reuse it rather than regenerate it from scratch.
15328 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15329 since we will need to refer to them each time the function is inlined. */
15332 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15333 enum dwarf_attribute attr
)
15336 dw_loc_list_ref list
;
15337 var_loc_list
*loc_list
;
15338 cached_dw_loc_list
*cache
;
15341 if (TREE_CODE (decl
) == ERROR_MARK
)
15344 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15345 || TREE_CODE (decl
) == RESULT_DECL
);
15347 /* Try to get some constant RTL for this decl, and use that as the value of
15350 rtl
= rtl_for_decl_location (decl
);
15351 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15352 && add_const_value_attribute (die
, rtl
))
15355 /* See if we have single element location list that is equivalent to
15356 a constant value. That way we are better to use add_const_value_attribute
15357 rather than expanding constant value equivalent. */
15358 loc_list
= lookup_decl_loc (decl
);
15361 && loc_list
->first
->next
== NULL
15362 && NOTE_P (loc_list
->first
->loc
)
15363 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15364 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15366 struct var_loc_node
*node
;
15368 node
= loc_list
->first
;
15369 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15370 if (GET_CODE (rtl
) == EXPR_LIST
)
15371 rtl
= XEXP (rtl
, 0);
15372 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15373 && add_const_value_attribute (die
, rtl
))
15376 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15377 list several times. See if we've already cached the contents. */
15379 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15383 cache
= (cached_dw_loc_list
*)
15384 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15386 list
= cache
->loc_list
;
15390 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15391 /* It is usually worth caching this result if the decl is from
15392 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15393 if (cache_p
&& list
&& list
->dw_loc_next
)
15395 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15396 DECL_UID (decl
), INSERT
);
15397 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15398 cache
->decl_id
= DECL_UID (decl
);
15399 cache
->loc_list
= list
;
15405 add_AT_location_description (die
, attr
, list
);
15408 /* None of that worked, so it must not really have a location;
15409 try adding a constant value attribute from the DECL_INITIAL. */
15410 return tree_add_const_value_attribute_for_decl (die
, decl
);
15413 /* Add VARIABLE and DIE into deferred locations list. */
15416 defer_location (tree variable
, dw_die_ref die
)
15418 deferred_locations entry
;
15419 entry
.variable
= variable
;
15421 vec_safe_push (deferred_locations_list
, entry
);
15424 /* Helper function for tree_add_const_value_attribute. Natively encode
15425 initializer INIT into an array. Return true if successful. */
15428 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15432 if (init
== NULL_TREE
)
15436 switch (TREE_CODE (init
))
15439 type
= TREE_TYPE (init
);
15440 if (TREE_CODE (type
) == ARRAY_TYPE
)
15442 tree enttype
= TREE_TYPE (type
);
15443 enum machine_mode mode
= TYPE_MODE (enttype
);
15445 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15447 if (int_size_in_bytes (type
) != size
)
15449 if (size
> TREE_STRING_LENGTH (init
))
15451 memcpy (array
, TREE_STRING_POINTER (init
),
15452 TREE_STRING_LENGTH (init
));
15453 memset (array
+ TREE_STRING_LENGTH (init
),
15454 '\0', size
- TREE_STRING_LENGTH (init
));
15457 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15462 type
= TREE_TYPE (init
);
15463 if (int_size_in_bytes (type
) != size
)
15465 if (TREE_CODE (type
) == ARRAY_TYPE
)
15467 HOST_WIDE_INT min_index
;
15468 unsigned HOST_WIDE_INT cnt
;
15469 int curpos
= 0, fieldsize
;
15470 constructor_elt
*ce
;
15472 if (TYPE_DOMAIN (type
) == NULL_TREE
15473 || !host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0))
15476 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15477 if (fieldsize
<= 0)
15480 min_index
= tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0);
15481 memset (array
, '\0', size
);
15482 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15484 tree val
= ce
->value
;
15485 tree index
= ce
->index
;
15487 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15488 pos
= (tree_low_cst (TREE_OPERAND (index
, 0), 0) - min_index
)
15491 pos
= (tree_low_cst (index
, 0) - min_index
) * fieldsize
;
15496 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15499 curpos
= pos
+ fieldsize
;
15500 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15502 int count
= tree_low_cst (TREE_OPERAND (index
, 1), 0)
15503 - tree_low_cst (TREE_OPERAND (index
, 0), 0);
15504 while (count
-- > 0)
15507 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15508 curpos
+= fieldsize
;
15511 gcc_assert (curpos
<= size
);
15515 else if (TREE_CODE (type
) == RECORD_TYPE
15516 || TREE_CODE (type
) == UNION_TYPE
)
15518 tree field
= NULL_TREE
;
15519 unsigned HOST_WIDE_INT cnt
;
15520 constructor_elt
*ce
;
15522 if (int_size_in_bytes (type
) != size
)
15525 if (TREE_CODE (type
) == RECORD_TYPE
)
15526 field
= TYPE_FIELDS (type
);
15528 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15530 tree val
= ce
->value
;
15531 int pos
, fieldsize
;
15533 if (ce
->index
!= 0)
15539 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15542 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15543 && TYPE_DOMAIN (TREE_TYPE (field
))
15544 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15546 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15547 || !host_integerp (DECL_SIZE_UNIT (field
), 0))
15549 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 0);
15550 pos
= int_byte_position (field
);
15551 gcc_assert (pos
+ fieldsize
<= size
);
15553 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15559 case VIEW_CONVERT_EXPR
:
15560 case NON_LVALUE_EXPR
:
15561 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15563 return native_encode_expr (init
, array
, size
) == size
;
15567 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15568 attribute is the const value T. */
15571 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
15574 tree type
= TREE_TYPE (t
);
15577 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
15581 gcc_assert (!DECL_P (init
));
15583 rtl
= rtl_for_decl_init (init
, type
);
15585 return add_const_value_attribute (die
, rtl
);
15586 /* If the host and target are sane, try harder. */
15587 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
15588 && initializer_constant_valid_p (init
, type
))
15590 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
15591 if (size
> 0 && (int) size
== size
)
15593 unsigned char *array
= (unsigned char *)
15594 ggc_alloc_cleared_atomic (size
);
15596 if (native_encode_initializer (init
, array
, size
))
15598 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
15607 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
15608 attribute is the const value of T, where T is an integral constant
15609 variable with static storage duration
15610 (so it can't be a PARM_DECL or a RESULT_DECL). */
15613 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
15617 || (TREE_CODE (decl
) != VAR_DECL
15618 && TREE_CODE (decl
) != CONST_DECL
)
15619 || (TREE_CODE (decl
) == VAR_DECL
15620 && !TREE_STATIC (decl
)))
15623 if (TREE_READONLY (decl
)
15624 && ! TREE_THIS_VOLATILE (decl
)
15625 && DECL_INITIAL (decl
))
15630 /* Don't add DW_AT_const_value if abstract origin already has one. */
15631 if (get_AT (var_die
, DW_AT_const_value
))
15634 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
15637 /* Convert the CFI instructions for the current function into a
15638 location list. This is used for DW_AT_frame_base when we targeting
15639 a dwarf2 consumer that does not support the dwarf3
15640 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
15643 static dw_loc_list_ref
15644 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
15648 dw_loc_list_ref list
, *list_tail
;
15650 dw_cfa_location last_cfa
, next_cfa
;
15651 const char *start_label
, *last_label
, *section
;
15652 dw_cfa_location remember
;
15655 gcc_assert (fde
!= NULL
);
15657 section
= secname_for_decl (current_function_decl
);
15661 memset (&next_cfa
, 0, sizeof (next_cfa
));
15662 next_cfa
.reg
= INVALID_REGNUM
;
15663 remember
= next_cfa
;
15665 start_label
= fde
->dw_fde_begin
;
15667 /* ??? Bald assumption that the CIE opcode list does not contain
15668 advance opcodes. */
15669 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
15670 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15672 last_cfa
= next_cfa
;
15673 last_label
= start_label
;
15675 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
15677 /* If the first partition contained no CFI adjustments, the
15678 CIE opcodes apply to the whole first partition. */
15679 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15680 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
15681 list_tail
=&(*list_tail
)->dw_loc_next
;
15682 start_label
= last_label
= fde
->dw_fde_second_begin
;
15685 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
15687 switch (cfi
->dw_cfi_opc
)
15689 case DW_CFA_set_loc
:
15690 case DW_CFA_advance_loc1
:
15691 case DW_CFA_advance_loc2
:
15692 case DW_CFA_advance_loc4
:
15693 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15695 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15696 start_label
, last_label
, section
);
15698 list_tail
= &(*list_tail
)->dw_loc_next
;
15699 last_cfa
= next_cfa
;
15700 start_label
= last_label
;
15702 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
15705 case DW_CFA_advance_loc
:
15706 /* The encoding is complex enough that we should never emit this. */
15707 gcc_unreachable ();
15710 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
15713 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
15715 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15717 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15718 start_label
, last_label
, section
);
15720 list_tail
= &(*list_tail
)->dw_loc_next
;
15721 last_cfa
= next_cfa
;
15722 start_label
= last_label
;
15724 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15725 start_label
, fde
->dw_fde_end
, section
);
15726 list_tail
= &(*list_tail
)->dw_loc_next
;
15727 start_label
= last_label
= fde
->dw_fde_second_begin
;
15731 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
15733 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
15734 start_label
, last_label
, section
);
15735 list_tail
= &(*list_tail
)->dw_loc_next
;
15736 start_label
= last_label
;
15739 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
15741 fde
->dw_fde_second_begin
15742 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
15745 if (list
&& list
->dw_loc_next
)
15751 /* Compute a displacement from the "steady-state frame pointer" to the
15752 frame base (often the same as the CFA), and store it in
15753 frame_pointer_fb_offset. OFFSET is added to the displacement
15754 before the latter is negated. */
15757 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
15761 #ifdef FRAME_POINTER_CFA_OFFSET
15762 reg
= frame_pointer_rtx
;
15763 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
15765 reg
= arg_pointer_rtx
;
15766 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
15769 elim
= (ira_use_lra_p
15770 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
15771 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
15772 if (GET_CODE (elim
) == PLUS
)
15774 offset
+= INTVAL (XEXP (elim
, 1));
15775 elim
= XEXP (elim
, 0);
15778 frame_pointer_fb_offset
= -offset
;
15780 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
15781 in which to eliminate. This is because it's stack pointer isn't
15782 directly accessible as a register within the ISA. To work around
15783 this, assume that while we cannot provide a proper value for
15784 frame_pointer_fb_offset, we won't need one either. */
15785 frame_pointer_fb_offset_valid
15786 = ((SUPPORTS_STACK_ALIGNMENT
15787 && (elim
== hard_frame_pointer_rtx
15788 || elim
== stack_pointer_rtx
))
15789 || elim
== (frame_pointer_needed
15790 ? hard_frame_pointer_rtx
15791 : stack_pointer_rtx
));
15794 /* Generate a DW_AT_name attribute given some string value to be included as
15795 the value of the attribute. */
15798 add_name_attribute (dw_die_ref die
, const char *name_string
)
15800 if (name_string
!= NULL
&& *name_string
!= 0)
15802 if (demangle_name_func
)
15803 name_string
= (*demangle_name_func
) (name_string
);
15805 add_AT_string (die
, DW_AT_name
, name_string
);
15809 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
15810 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
15811 of TYPE accordingly.
15813 ??? This is a temporary measure until after we're able to generate
15814 regular DWARF for the complex Ada type system. */
15817 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
15818 dw_die_ref context_die
)
15821 dw_die_ref dtype_die
;
15823 if (!lang_hooks
.types
.descriptive_type
)
15826 dtype
= lang_hooks
.types
.descriptive_type (type
);
15830 dtype_die
= lookup_type_die (dtype
);
15833 gen_type_die (dtype
, context_die
);
15834 dtype_die
= lookup_type_die (dtype
);
15835 gcc_assert (dtype_die
);
15838 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
15841 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
15843 static const char *
15844 comp_dir_string (void)
15848 static const char *cached_wd
= NULL
;
15850 if (cached_wd
!= NULL
)
15853 wd
= get_src_pwd ();
15857 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
15861 wdlen
= strlen (wd
);
15862 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
15864 wd1
[wdlen
] = DIR_SEPARATOR
;
15865 wd1
[wdlen
+ 1] = 0;
15869 cached_wd
= remap_debug_filename (wd
);
15873 /* Generate a DW_AT_comp_dir attribute for DIE. */
15876 add_comp_dir_attribute (dw_die_ref die
)
15878 const char * wd
= comp_dir_string ();
15880 add_AT_string (die
, DW_AT_comp_dir
, wd
);
15883 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
15887 lower_bound_default (void)
15889 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
15894 case DW_LANG_C_plus_plus
:
15896 case DW_LANG_ObjC_plus_plus
:
15899 case DW_LANG_Fortran77
:
15900 case DW_LANG_Fortran90
:
15901 case DW_LANG_Fortran95
:
15905 case DW_LANG_Python
:
15906 return dwarf_version
>= 4 ? 0 : -1;
15907 case DW_LANG_Ada95
:
15908 case DW_LANG_Ada83
:
15909 case DW_LANG_Cobol74
:
15910 case DW_LANG_Cobol85
:
15911 case DW_LANG_Pascal83
:
15912 case DW_LANG_Modula2
:
15914 return dwarf_version
>= 4 ? 1 : -1;
15920 /* Given a tree node describing an array bound (either lower or upper) output
15921 a representation for that bound. */
15924 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
15926 switch (TREE_CODE (bound
))
15931 /* All fixed-bounds are represented by INTEGER_CST nodes. */
15934 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
15937 /* Use the default if possible. */
15938 if (bound_attr
== DW_AT_lower_bound
15939 && host_integerp (bound
, 0)
15940 && (dflt
= lower_bound_default ()) != -1
15941 && tree_low_cst (bound
, 0) == dflt
)
15944 /* Otherwise represent the bound as an unsigned value with the
15945 precision of its type. The precision and signedness of the
15946 type will be necessary to re-interpret it unambiguously. */
15947 else if (prec
< HOST_BITS_PER_WIDE_INT
)
15949 unsigned HOST_WIDE_INT mask
15950 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
15951 add_AT_unsigned (subrange_die
, bound_attr
,
15952 TREE_INT_CST_LOW (bound
) & mask
);
15954 else if (prec
== HOST_BITS_PER_WIDE_INT
15955 || TREE_INT_CST_HIGH (bound
) == 0)
15956 add_AT_unsigned (subrange_die
, bound_attr
,
15957 TREE_INT_CST_LOW (bound
));
15959 add_AT_double (subrange_die
, bound_attr
, TREE_INT_CST_HIGH (bound
),
15960 TREE_INT_CST_LOW (bound
));
15965 case VIEW_CONVERT_EXPR
:
15966 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
15976 dw_die_ref decl_die
= lookup_decl_die (bound
);
15978 /* ??? Can this happen, or should the variable have been bound
15979 first? Probably it can, since I imagine that we try to create
15980 the types of parameters in the order in which they exist in
15981 the list, and won't have created a forward reference to a
15982 later parameter. */
15983 if (decl_die
!= NULL
)
15985 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
15993 /* Otherwise try to create a stack operation procedure to
15994 evaluate the value of the array bound. */
15996 dw_die_ref ctx
, decl_die
;
15997 dw_loc_list_ref list
;
15999 list
= loc_list_from_tree (bound
, 2);
16000 if (list
== NULL
|| single_element_loc_list_p (list
))
16002 /* If DW_AT_*bound is not a reference nor constant, it is
16003 a DWARF expression rather than location description.
16004 For that loc_list_from_tree (bound, 0) is needed.
16005 If that fails to give a single element list,
16006 fall back to outputting this as a reference anyway. */
16007 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16008 if (list2
&& single_element_loc_list_p (list2
))
16010 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16017 if (current_function_decl
== 0)
16018 ctx
= comp_unit_die ();
16020 ctx
= lookup_decl_die (current_function_decl
);
16022 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16023 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16024 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16025 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16026 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16032 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16033 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16034 Note that the block of subscript information for an array type also
16035 includes information about the element type of the given array type. */
16038 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16040 unsigned dimension_number
;
16042 dw_die_ref subrange_die
;
16044 for (dimension_number
= 0;
16045 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16046 type
= TREE_TYPE (type
), dimension_number
++)
16048 tree domain
= TYPE_DOMAIN (type
);
16050 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16053 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16054 and (in GNU C only) variable bounds. Handle all three forms
16056 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16059 /* We have an array type with specified bounds. */
16060 lower
= TYPE_MIN_VALUE (domain
);
16061 upper
= TYPE_MAX_VALUE (domain
);
16063 /* Define the index type. */
16064 if (TREE_TYPE (domain
))
16066 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16067 TREE_TYPE field. We can't emit debug info for this
16068 because it is an unnamed integral type. */
16069 if (TREE_CODE (domain
) == INTEGER_TYPE
16070 && TYPE_NAME (domain
) == NULL_TREE
16071 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16072 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16075 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16079 /* ??? If upper is NULL, the array has unspecified length,
16080 but it does have a lower bound. This happens with Fortran
16082 Since the debugger is definitely going to need to know N
16083 to produce useful results, go ahead and output the lower
16084 bound solo, and hope the debugger can cope. */
16086 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16088 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16091 /* Otherwise we have an array type with an unspecified length. The
16092 DWARF-2 spec does not say how to handle this; let's just leave out the
16098 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16100 dw_die_ref decl_die
;
16103 switch (TREE_CODE (tree_node
))
16108 case ENUMERAL_TYPE
:
16111 case QUAL_UNION_TYPE
:
16112 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16113 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16115 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16118 size
= int_size_in_bytes (tree_node
);
16121 /* For a data member of a struct or union, the DW_AT_byte_size is
16122 generally given as the number of bytes normally allocated for an
16123 object of the *declared* type of the member itself. This is true
16124 even for bit-fields. */
16125 size
= simple_type_size_in_bits (field_type (tree_node
)) / BITS_PER_UNIT
;
16128 gcc_unreachable ();
16131 /* Note that `size' might be -1 when we get to this point. If it is, that
16132 indicates that the byte size of the entity in question is variable. We
16133 have no good way of expressing this fact in Dwarf at the present time,
16134 so just let the -1 pass on through. */
16135 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16138 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16139 which specifies the distance in bits from the highest order bit of the
16140 "containing object" for the bit-field to the highest order bit of the
16143 For any given bit-field, the "containing object" is a hypothetical object
16144 (of some integral or enum type) within which the given bit-field lives. The
16145 type of this hypothetical "containing object" is always the same as the
16146 declared type of the individual bit-field itself. The determination of the
16147 exact location of the "containing object" for a bit-field is rather
16148 complicated. It's handled by the `field_byte_offset' function (above).
16150 Note that it is the size (in bytes) of the hypothetical "containing object"
16151 which will be given in the DW_AT_byte_size attribute for this bit-field.
16152 (See `byte_size_attribute' above). */
16155 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16157 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16158 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16159 HOST_WIDE_INT bitpos_int
;
16160 HOST_WIDE_INT highest_order_object_bit_offset
;
16161 HOST_WIDE_INT highest_order_field_bit_offset
;
16162 HOST_WIDE_INT bit_offset
;
16164 /* Must be a field and a bit field. */
16165 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16167 /* We can't yet handle bit-fields whose offsets are variable, so if we
16168 encounter such things, just return without generating any attribute
16169 whatsoever. Likewise for variable or too large size. */
16170 if (! host_integerp (bit_position (decl
), 0)
16171 || ! host_integerp (DECL_SIZE (decl
), 1))
16174 bitpos_int
= int_bit_position (decl
);
16176 /* Note that the bit offset is always the distance (in bits) from the
16177 highest-order bit of the "containing object" to the highest-order bit of
16178 the bit-field itself. Since the "high-order end" of any object or field
16179 is different on big-endian and little-endian machines, the computation
16180 below must take account of these differences. */
16181 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16182 highest_order_field_bit_offset
= bitpos_int
;
16184 if (! BYTES_BIG_ENDIAN
)
16186 highest_order_field_bit_offset
+= tree_low_cst (DECL_SIZE (decl
), 0);
16187 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16191 = (! BYTES_BIG_ENDIAN
16192 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16193 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16195 if (bit_offset
< 0)
16196 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16198 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16201 /* For a FIELD_DECL node which represents a bit field, output an attribute
16202 which specifies the length in bits of the given field. */
16205 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16207 /* Must be a field and a bit field. */
16208 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16209 && DECL_BIT_FIELD_TYPE (decl
));
16211 if (host_integerp (DECL_SIZE (decl
), 1))
16212 add_AT_unsigned (die
, DW_AT_bit_size
, tree_low_cst (DECL_SIZE (decl
), 1));
16215 /* If the compiled language is ANSI C, then add a 'prototyped'
16216 attribute, if arg types are given for the parameters of a function. */
16219 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16221 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16222 && prototype_p (func_type
))
16223 add_AT_flag (die
, DW_AT_prototyped
, 1);
16226 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16227 by looking in either the type declaration or object declaration
16230 static inline dw_die_ref
16231 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16233 dw_die_ref origin_die
= NULL
;
16235 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16237 /* We may have gotten separated from the block for the inlined
16238 function, if we're in an exception handler or some such; make
16239 sure that the abstract function has been written out.
16241 Doing this for nested functions is wrong, however; functions are
16242 distinct units, and our context might not even be inline. */
16246 fn
= TYPE_STUB_DECL (fn
);
16248 fn
= decl_function_context (fn
);
16250 dwarf2out_abstract_function (fn
);
16253 if (DECL_P (origin
))
16254 origin_die
= lookup_decl_die (origin
);
16255 else if (TYPE_P (origin
))
16256 origin_die
= lookup_type_die (origin
);
16258 /* XXX: Functions that are never lowered don't always have correct block
16259 trees (in the case of java, they simply have no block tree, in some other
16260 languages). For these functions, there is nothing we can really do to
16261 output correct debug info for inlined functions in all cases. Rather
16262 than die, we'll just produce deficient debug info now, in that we will
16263 have variables without a proper abstract origin. In the future, when all
16264 functions are lowered, we should re-add a gcc_assert (origin_die)
16268 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16272 /* We do not currently support the pure_virtual attribute. */
16275 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16277 if (DECL_VINDEX (func_decl
))
16279 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16281 if (host_integerp (DECL_VINDEX (func_decl
), 0))
16282 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16283 new_loc_descr (DW_OP_constu
,
16284 tree_low_cst (DECL_VINDEX (func_decl
), 0),
16287 /* GNU extension: Record what type this method came from originally. */
16288 if (debug_info_level
> DINFO_LEVEL_TERSE
16289 && DECL_CONTEXT (func_decl
))
16290 add_AT_die_ref (die
, DW_AT_containing_type
,
16291 lookup_type_die (DECL_CONTEXT (func_decl
)));
16295 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16296 given decl. This used to be a vendor extension until after DWARF 4
16297 standardized it. */
16300 add_linkage_attr (dw_die_ref die
, tree decl
)
16302 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16304 /* Mimic what assemble_name_raw does with a leading '*'. */
16305 if (name
[0] == '*')
16308 if (dwarf_version
>= 4)
16309 add_AT_string (die
, DW_AT_linkage_name
, name
);
16311 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16314 /* Add source coordinate attributes for the given decl. */
16317 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16319 expanded_location s
;
16321 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16323 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16324 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16325 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16328 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16331 add_linkage_name (dw_die_ref die
, tree decl
)
16333 if ((TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16334 && TREE_PUBLIC (decl
)
16335 && !DECL_ABSTRACT (decl
)
16336 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16337 && die
->die_tag
!= DW_TAG_member
)
16339 /* Defer until we have an assembler name set. */
16340 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16342 limbo_die_node
*asm_name
;
16344 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16345 asm_name
->die
= die
;
16346 asm_name
->created_for
= decl
;
16347 asm_name
->next
= deferred_asm_name
;
16348 deferred_asm_name
= asm_name
;
16350 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16351 add_linkage_attr (die
, decl
);
16355 /* Add a DW_AT_name attribute and source coordinate attribute for the
16356 given decl, but only if it actually has a name. */
16359 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16363 decl_name
= DECL_NAME (decl
);
16364 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16366 const char *name
= dwarf2_name (decl
, 0);
16368 add_name_attribute (die
, name
);
16369 if (! DECL_ARTIFICIAL (decl
))
16370 add_src_coords_attributes (die
, decl
);
16372 add_linkage_name (die
, decl
);
16375 #ifdef VMS_DEBUGGING_INFO
16376 /* Get the function's name, as described by its RTL. This may be different
16377 from the DECL_NAME name used in the source file. */
16378 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16380 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16381 XEXP (DECL_RTL (decl
), 0), false);
16382 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16384 #endif /* VMS_DEBUGGING_INFO */
16387 #ifdef VMS_DEBUGGING_INFO
16388 /* Output the debug main pointer die for VMS */
16391 dwarf2out_vms_debug_main_pointer (void)
16393 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16396 /* Allocate the VMS debug main subprogram die. */
16397 die
= ggc_alloc_cleared_die_node ();
16398 die
->die_tag
= DW_TAG_subprogram
;
16399 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16400 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16401 current_function_funcdef_no
);
16402 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16404 /* Make it the first child of comp_unit_die (). */
16405 die
->die_parent
= comp_unit_die ();
16406 if (comp_unit_die ()->die_child
)
16408 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16409 comp_unit_die ()->die_child
->die_sib
= die
;
16413 die
->die_sib
= die
;
16414 comp_unit_die ()->die_child
= die
;
16417 #endif /* VMS_DEBUGGING_INFO */
16419 /* Push a new declaration scope. */
16422 push_decl_scope (tree scope
)
16424 vec_safe_push (decl_scope_table
, scope
);
16427 /* Pop a declaration scope. */
16430 pop_decl_scope (void)
16432 decl_scope_table
->pop ();
16435 /* walk_tree helper function for uses_local_type, below. */
16438 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16441 *walk_subtrees
= 0;
16444 tree name
= TYPE_NAME (*tp
);
16445 if (name
&& DECL_P (name
) && decl_function_context (name
))
16451 /* If TYPE involves a function-local type (including a local typedef to a
16452 non-local type), returns that type; otherwise returns NULL_TREE. */
16455 uses_local_type (tree type
)
16457 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16461 /* Return the DIE for the scope that immediately contains this type.
16462 Non-named types that do not involve a function-local type get global
16463 scope. Named types nested in namespaces or other types get their
16464 containing scope. All other types (i.e. function-local named types) get
16465 the current active scope. */
16468 scope_die_for (tree t
, dw_die_ref context_die
)
16470 dw_die_ref scope_die
= NULL
;
16471 tree containing_scope
;
16473 /* Non-types always go in the current scope. */
16474 gcc_assert (TYPE_P (t
));
16476 /* Use the scope of the typedef, rather than the scope of the type
16478 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16479 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16481 containing_scope
= TYPE_CONTEXT (t
);
16483 /* Use the containing namespace if there is one. */
16484 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16486 if (context_die
== lookup_decl_die (containing_scope
))
16488 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16489 context_die
= get_context_die (containing_scope
);
16491 containing_scope
= NULL_TREE
;
16494 /* Ignore function type "scopes" from the C frontend. They mean that
16495 a tagged type is local to a parmlist of a function declarator, but
16496 that isn't useful to DWARF. */
16497 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16498 containing_scope
= NULL_TREE
;
16500 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16502 /* If T uses a local type keep it local as well, to avoid references
16503 to function-local DIEs from outside the function. */
16504 if (current_function_decl
&& uses_local_type (t
))
16505 scope_die
= context_die
;
16507 scope_die
= comp_unit_die ();
16509 else if (TYPE_P (containing_scope
))
16511 /* For types, we can just look up the appropriate DIE. */
16512 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16513 scope_die
= get_context_die (containing_scope
);
16516 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16517 if (scope_die
== NULL
)
16518 scope_die
= comp_unit_die ();
16522 scope_die
= context_die
;
16527 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16530 local_scope_p (dw_die_ref context_die
)
16532 for (; context_die
; context_die
= context_die
->die_parent
)
16533 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16534 || context_die
->die_tag
== DW_TAG_subprogram
)
16540 /* Returns nonzero if CONTEXT_DIE is a class. */
16543 class_scope_p (dw_die_ref context_die
)
16545 return (context_die
16546 && (context_die
->die_tag
== DW_TAG_structure_type
16547 || context_die
->die_tag
== DW_TAG_class_type
16548 || context_die
->die_tag
== DW_TAG_interface_type
16549 || context_die
->die_tag
== DW_TAG_union_type
));
16552 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16553 whether or not to treat a DIE in this context as a declaration. */
16556 class_or_namespace_scope_p (dw_die_ref context_die
)
16558 return (class_scope_p (context_die
)
16559 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16562 /* Many forms of DIEs require a "type description" attribute. This
16563 routine locates the proper "type descriptor" die for the type given
16564 by 'type', and adds a DW_AT_type attribute below the given die. */
16567 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
16568 int decl_volatile
, dw_die_ref context_die
)
16570 enum tree_code code
= TREE_CODE (type
);
16571 dw_die_ref type_die
= NULL
;
16573 /* ??? If this type is an unnamed subrange type of an integral, floating-point
16574 or fixed-point type, use the inner type. This is because we have no
16575 support for unnamed types in base_type_die. This can happen if this is
16576 an Ada subrange type. Correct solution is emit a subrange type die. */
16577 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
16578 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
16579 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
16581 if (code
== ERROR_MARK
16582 /* Handle a special case. For functions whose return type is void, we
16583 generate *no* type attribute. (Note that no object may have type
16584 `void', so this only applies to function return types). */
16585 || code
== VOID_TYPE
)
16588 type_die
= modified_type_die (type
,
16589 decl_const
|| TYPE_READONLY (type
),
16590 decl_volatile
|| TYPE_VOLATILE (type
),
16593 if (type_die
!= NULL
)
16594 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
16597 /* Given an object die, add the calling convention attribute for the
16598 function call type. */
16600 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
16602 enum dwarf_calling_convention value
= DW_CC_normal
;
16604 value
= ((enum dwarf_calling_convention
)
16605 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
16608 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
16610 /* DWARF 2 doesn't provide a way to identify a program's source-level
16611 entry point. DW_AT_calling_convention attributes are only meant
16612 to describe functions' calling conventions. However, lacking a
16613 better way to signal the Fortran main program, we used this for
16614 a long time, following existing custom. Now, DWARF 4 has
16615 DW_AT_main_subprogram, which we add below, but some tools still
16616 rely on the old way, which we thus keep. */
16617 value
= DW_CC_program
;
16619 if (dwarf_version
>= 4 || !dwarf_strict
)
16620 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
16623 /* Only add the attribute if the backend requests it, and
16624 is not DW_CC_normal. */
16625 if (value
&& (value
!= DW_CC_normal
))
16626 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
16629 /* Given a tree pointer to a struct, class, union, or enum type node, return
16630 a pointer to the (string) tag name for the given type, or zero if the type
16631 was declared without a tag. */
16633 static const char *
16634 type_tag (const_tree type
)
16636 const char *name
= 0;
16638 if (TYPE_NAME (type
) != 0)
16642 /* Find the IDENTIFIER_NODE for the type name. */
16643 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
16644 && !TYPE_NAMELESS (type
))
16645 t
= TYPE_NAME (type
);
16647 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
16648 a TYPE_DECL node, regardless of whether or not a `typedef' was
16650 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
16651 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
16653 /* We want to be extra verbose. Don't call dwarf_name if
16654 DECL_NAME isn't set. The default hook for decl_printable_name
16655 doesn't like that, and in this context it's correct to return
16656 0, instead of "<anonymous>" or the like. */
16657 if (DECL_NAME (TYPE_NAME (type
))
16658 && !DECL_NAMELESS (TYPE_NAME (type
)))
16659 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
16662 /* Now get the name as a string, or invent one. */
16663 if (!name
&& t
!= 0)
16664 name
= IDENTIFIER_POINTER (t
);
16667 return (name
== 0 || *name
== '\0') ? 0 : name
;
16670 /* Return the type associated with a data member, make a special check
16671 for bit field types. */
16674 member_declared_type (const_tree member
)
16676 return (DECL_BIT_FIELD_TYPE (member
)
16677 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
16680 /* Get the decl's label, as described by its RTL. This may be different
16681 from the DECL_NAME name used in the source file. */
16684 static const char *
16685 decl_start_label (tree decl
)
16688 const char *fnname
;
16690 x
= DECL_RTL (decl
);
16691 gcc_assert (MEM_P (x
));
16694 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
16696 fnname
= XSTR (x
, 0);
16701 /* These routines generate the internal representation of the DIE's for
16702 the compilation unit. Debugging information is collected by walking
16703 the declaration trees passed in from dwarf2out_decl(). */
16706 gen_array_type_die (tree type
, dw_die_ref context_die
)
16708 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16709 dw_die_ref array_die
;
16711 /* GNU compilers represent multidimensional array types as sequences of one
16712 dimensional array types whose element types are themselves array types.
16713 We sometimes squish that down to a single array_type DIE with multiple
16714 subscripts in the Dwarf debugging info. The draft Dwarf specification
16715 say that we are allowed to do this kind of compression in C, because
16716 there is no difference between an array of arrays and a multidimensional
16717 array. We don't do this for Ada to remain as close as possible to the
16718 actual representation, which is especially important against the language
16719 flexibilty wrt arrays of variable size. */
16721 bool collapse_nested_arrays
= !is_ada ();
16724 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
16725 DW_TAG_string_type doesn't have DW_AT_type attribute). */
16726 if (TYPE_STRING_FLAG (type
)
16727 && TREE_CODE (type
) == ARRAY_TYPE
16729 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
16731 HOST_WIDE_INT size
;
16733 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
16734 add_name_attribute (array_die
, type_tag (type
));
16735 equate_type_number_to_die (type
, array_die
);
16736 size
= int_size_in_bytes (type
);
16738 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16739 else if (TYPE_DOMAIN (type
) != NULL_TREE
16740 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
16741 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
16743 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
16744 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
16746 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
16747 if (loc
&& size
> 0)
16749 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
16750 if (size
!= DWARF2_ADDR_SIZE
)
16751 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
16757 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16758 add_name_attribute (array_die
, type_tag (type
));
16759 equate_type_number_to_die (type
, array_die
);
16761 if (TREE_CODE (type
) == VECTOR_TYPE
)
16762 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
16764 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16766 && TREE_CODE (type
) == ARRAY_TYPE
16767 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
16768 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
16769 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16772 /* We default the array ordering. SDB will probably do
16773 the right things even if DW_AT_ordering is not present. It's not even
16774 an issue until we start to get into multidimensional arrays anyway. If
16775 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
16776 then we'll have to put the DW_AT_ordering attribute back in. (But if
16777 and when we find out that we need to put these in, we will only do so
16778 for multidimensional arrays. */
16779 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
16782 if (TREE_CODE (type
) == VECTOR_TYPE
)
16784 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
16785 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16786 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
16787 add_bound_info (subrange_die
, DW_AT_upper_bound
,
16788 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
16791 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
16793 /* Add representation of the type of the elements of this array type and
16794 emit the corresponding DIE if we haven't done it already. */
16795 element_type
= TREE_TYPE (type
);
16796 if (collapse_nested_arrays
)
16797 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
16799 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
16801 element_type
= TREE_TYPE (element_type
);
16804 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
16806 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
16807 if (TYPE_ARTIFICIAL (type
))
16808 add_AT_flag (array_die
, DW_AT_artificial
, 1);
16810 if (get_AT (array_die
, DW_AT_name
))
16811 add_pubtype (type
, array_die
);
16814 static dw_loc_descr_ref
16815 descr_info_loc (tree val
, tree base_decl
)
16817 HOST_WIDE_INT size
;
16818 dw_loc_descr_ref loc
, loc2
;
16819 enum dwarf_location_atom op
;
16821 if (val
== base_decl
)
16822 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
16824 switch (TREE_CODE (val
))
16827 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16829 return loc_descriptor_from_tree (val
, 0);
16831 if (host_integerp (val
, 0))
16832 return int_loc_descriptor (tree_low_cst (val
, 0));
16835 size
= int_size_in_bytes (TREE_TYPE (val
));
16838 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16841 if (size
== DWARF2_ADDR_SIZE
)
16842 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
16844 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
16846 case POINTER_PLUS_EXPR
:
16848 if (host_integerp (TREE_OPERAND (val
, 1), 1)
16849 && (unsigned HOST_WIDE_INT
) tree_low_cst (TREE_OPERAND (val
, 1), 1)
16852 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16855 loc_descr_plus_const (&loc
, tree_low_cst (TREE_OPERAND (val
, 1), 0));
16861 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
16864 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
16867 add_loc_descr (&loc
, loc2
);
16868 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
16890 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
16891 tree val
, tree base_decl
)
16893 dw_loc_descr_ref loc
;
16895 if (host_integerp (val
, 0))
16897 add_AT_unsigned (die
, attr
, tree_low_cst (val
, 0));
16901 loc
= descr_info_loc (val
, base_decl
);
16905 add_AT_loc (die
, attr
, loc
);
16908 /* This routine generates DIE for array with hidden descriptor, details
16909 are filled into *info by a langhook. */
16912 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
16913 dw_die_ref context_die
)
16915 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
16916 dw_die_ref array_die
;
16919 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
16920 add_name_attribute (array_die
, type_tag (type
));
16921 equate_type_number_to_die (type
, array_die
);
16923 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
16925 && info
->ndimensions
>= 2)
16926 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
16928 if (info
->data_location
)
16929 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
16931 if (info
->associated
)
16932 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
16934 if (info
->allocated
)
16935 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
16938 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
16940 dw_die_ref subrange_die
16941 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
16943 if (info
->dimen
[dim
].lower_bound
)
16945 /* If it is the default value, omit it. */
16948 if (host_integerp (info
->dimen
[dim
].lower_bound
, 0)
16949 && (dflt
= lower_bound_default ()) != -1
16950 && tree_low_cst (info
->dimen
[dim
].lower_bound
, 0) == dflt
)
16953 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
16954 info
->dimen
[dim
].lower_bound
,
16957 if (info
->dimen
[dim
].upper_bound
)
16958 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
16959 info
->dimen
[dim
].upper_bound
,
16961 if (info
->dimen
[dim
].stride
)
16962 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
16963 info
->dimen
[dim
].stride
,
16967 gen_type_die (info
->element_type
, context_die
);
16968 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
16970 if (get_AT (array_die
, DW_AT_name
))
16971 add_pubtype (type
, array_die
);
16976 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
16978 tree origin
= decl_ultimate_origin (decl
);
16979 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
16981 if (origin
!= NULL
)
16982 add_abstract_origin_attribute (decl_die
, origin
);
16985 add_name_and_src_coords_attributes (decl_die
, decl
);
16986 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
16987 0, 0, context_die
);
16990 if (DECL_ABSTRACT (decl
))
16991 equate_decl_number_to_die (decl
, decl_die
);
16993 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
16997 /* Walk through the list of incomplete types again, trying once more to
16998 emit full debugging info for them. */
17001 retry_incomplete_types (void)
17005 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17006 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17007 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17010 /* Determine what tag to use for a record type. */
17012 static enum dwarf_tag
17013 record_type_tag (tree type
)
17015 if (! lang_hooks
.types
.classify_record
)
17016 return DW_TAG_structure_type
;
17018 switch (lang_hooks
.types
.classify_record (type
))
17020 case RECORD_IS_STRUCT
:
17021 return DW_TAG_structure_type
;
17023 case RECORD_IS_CLASS
:
17024 return DW_TAG_class_type
;
17026 case RECORD_IS_INTERFACE
:
17027 if (dwarf_version
>= 3 || !dwarf_strict
)
17028 return DW_TAG_interface_type
;
17029 return DW_TAG_structure_type
;
17032 gcc_unreachable ();
17036 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17037 include all of the information about the enumeration values also. Each
17038 enumerated type name/value is listed as a child of the enumerated type
17042 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17044 dw_die_ref type_die
= lookup_type_die (type
);
17046 if (type_die
== NULL
)
17048 type_die
= new_die (DW_TAG_enumeration_type
,
17049 scope_die_for (type
, context_die
), type
);
17050 equate_type_number_to_die (type
, type_die
);
17051 add_name_attribute (type_die
, type_tag (type
));
17052 if (dwarf_version
>= 4 || !dwarf_strict
)
17054 if (ENUM_IS_SCOPED (type
))
17055 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17056 if (ENUM_IS_OPAQUE (type
))
17057 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17060 else if (! TYPE_SIZE (type
))
17063 remove_AT (type_die
, DW_AT_declaration
);
17065 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17066 given enum type is incomplete, do not generate the DW_AT_byte_size
17067 attribute or the DW_AT_element_list attribute. */
17068 if (TYPE_SIZE (type
))
17072 TREE_ASM_WRITTEN (type
) = 1;
17073 add_byte_size_attribute (type_die
, type
);
17074 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17076 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17077 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17080 /* If the first reference to this type was as the return type of an
17081 inline function, then it may not have a parent. Fix this now. */
17082 if (type_die
->die_parent
== NULL
)
17083 add_child_die (scope_die_for (type
, context_die
), type_die
);
17085 for (link
= TYPE_VALUES (type
);
17086 link
!= NULL
; link
= TREE_CHAIN (link
))
17088 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17089 tree value
= TREE_VALUE (link
);
17091 add_name_attribute (enum_die
,
17092 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17094 if (TREE_CODE (value
) == CONST_DECL
)
17095 value
= DECL_INITIAL (value
);
17097 if (host_integerp (value
, TYPE_UNSIGNED (TREE_TYPE (value
)))
17098 && (simple_type_size_in_bits (TREE_TYPE (value
))
17099 <= HOST_BITS_PER_WIDE_INT
|| host_integerp (value
, 0)))
17100 /* DWARF2 does not provide a way of indicating whether or
17101 not enumeration constants are signed or unsigned. GDB
17102 always assumes the values are signed, so we output all
17103 values as if they were signed. That means that
17104 enumeration constants with very large unsigned values
17105 will appear to have negative values in the debugger.
17107 TODO: the above comment is wrong, DWARF2 does provide
17108 DW_FORM_sdata/DW_FORM_udata to represent signed/unsigned data.
17109 This should be re-worked to use correct signed/unsigned
17110 int/double tags for all cases, instead of always treating as
17112 add_AT_int (enum_die
, DW_AT_const_value
, TREE_INT_CST_LOW (value
));
17114 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17116 add_AT_double (enum_die
, DW_AT_const_value
,
17117 TREE_INT_CST_HIGH (value
), TREE_INT_CST_LOW (value
));
17120 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17121 if (TYPE_ARTIFICIAL (type
))
17122 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17125 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17127 add_pubtype (type
, type_die
);
17132 /* Generate a DIE to represent either a real live formal parameter decl or to
17133 represent just the type of some formal parameter position in some function
17136 Note that this routine is a bit unusual because its argument may be a
17137 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17138 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17139 node. If it's the former then this function is being called to output a
17140 DIE to represent a formal parameter object (or some inlining thereof). If
17141 it's the latter, then this function is only being called to output a
17142 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17143 argument type of some subprogram type.
17144 If EMIT_NAME_P is true, name and source coordinate attributes
17148 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17149 dw_die_ref context_die
)
17151 tree node_or_origin
= node
? node
: origin
;
17152 tree ultimate_origin
;
17153 dw_die_ref parm_die
17154 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17156 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17158 case tcc_declaration
:
17159 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17160 if (node
|| ultimate_origin
)
17161 origin
= ultimate_origin
;
17162 if (origin
!= NULL
)
17163 add_abstract_origin_attribute (parm_die
, origin
);
17164 else if (emit_name_p
)
17165 add_name_and_src_coords_attributes (parm_die
, node
);
17167 || (! DECL_ABSTRACT (node_or_origin
)
17168 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17169 decl_function_context
17170 (node_or_origin
))))
17172 tree type
= TREE_TYPE (node_or_origin
);
17173 if (decl_by_reference_p (node_or_origin
))
17174 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17177 add_type_attribute (parm_die
, type
,
17178 TREE_READONLY (node_or_origin
),
17179 TREE_THIS_VOLATILE (node_or_origin
),
17182 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17183 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17185 if (node
&& node
!= origin
)
17186 equate_decl_number_to_die (node
, parm_die
);
17187 if (! DECL_ABSTRACT (node_or_origin
))
17188 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17189 node
== NULL
, DW_AT_location
);
17194 /* We were called with some kind of a ..._TYPE node. */
17195 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17199 gcc_unreachable ();
17205 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17206 children DW_TAG_formal_parameter DIEs representing the arguments of the
17209 PARM_PACK must be a function parameter pack.
17210 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17211 must point to the subsequent arguments of the function PACK_ARG belongs to.
17212 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17213 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17214 following the last one for which a DIE was generated. */
17217 gen_formal_parameter_pack_die (tree parm_pack
,
17219 dw_die_ref subr_die
,
17223 dw_die_ref parm_pack_die
;
17225 gcc_assert (parm_pack
17226 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17229 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17230 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17232 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17234 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17237 gen_formal_parameter_die (arg
, NULL
,
17238 false /* Don't emit name attribute. */,
17243 return parm_pack_die
;
17246 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17247 at the end of an (ANSI prototyped) formal parameters list. */
17250 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17252 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17255 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17256 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17257 parameters as specified in some function type specification (except for
17258 those which appear as part of a function *definition*). */
17261 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17264 tree formal_type
= NULL
;
17265 tree first_parm_type
;
17268 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17270 arg
= DECL_ARGUMENTS (function_or_method_type
);
17271 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17276 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17278 /* Make our first pass over the list of formal parameter types and output a
17279 DW_TAG_formal_parameter DIE for each one. */
17280 for (link
= first_parm_type
; link
; )
17282 dw_die_ref parm_die
;
17284 formal_type
= TREE_VALUE (link
);
17285 if (formal_type
== void_type_node
)
17288 /* Output a (nameless) DIE to represent the formal parameter itself. */
17289 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17290 true /* Emit name attribute. */,
17292 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17293 && link
== first_parm_type
)
17295 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17296 if (dwarf_version
>= 3 || !dwarf_strict
)
17297 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17299 else if (arg
&& DECL_ARTIFICIAL (arg
))
17300 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17302 link
= TREE_CHAIN (link
);
17304 arg
= DECL_CHAIN (arg
);
17307 /* If this function type has an ellipsis, add a
17308 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17309 if (formal_type
!= void_type_node
)
17310 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17312 /* Make our second (and final) pass over the list of formal parameter types
17313 and output DIEs to represent those types (as necessary). */
17314 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17315 link
&& TREE_VALUE (link
);
17316 link
= TREE_CHAIN (link
))
17317 gen_type_die (TREE_VALUE (link
), context_die
);
17320 /* We want to generate the DIE for TYPE so that we can generate the
17321 die for MEMBER, which has been defined; we will need to refer back
17322 to the member declaration nested within TYPE. If we're trying to
17323 generate minimal debug info for TYPE, processing TYPE won't do the
17324 trick; we need to attach the member declaration by hand. */
17327 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17329 gen_type_die (type
, context_die
);
17331 /* If we're trying to avoid duplicate debug info, we may not have
17332 emitted the member decl for this function. Emit it now. */
17333 if (TYPE_STUB_DECL (type
)
17334 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17335 && ! lookup_decl_die (member
))
17337 dw_die_ref type_die
;
17338 gcc_assert (!decl_ultimate_origin (member
));
17340 push_decl_scope (type
);
17341 type_die
= lookup_type_die_strip_naming_typedef (type
);
17342 if (TREE_CODE (member
) == FUNCTION_DECL
)
17343 gen_subprogram_die (member
, type_die
);
17344 else if (TREE_CODE (member
) == FIELD_DECL
)
17346 /* Ignore the nameless fields that are used to skip bits but handle
17347 C++ anonymous unions and structs. */
17348 if (DECL_NAME (member
) != NULL_TREE
17349 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17350 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17352 gen_type_die (member_declared_type (member
), type_die
);
17353 gen_field_die (member
, type_die
);
17357 gen_variable_die (member
, NULL_TREE
, type_die
);
17363 /* Forward declare these functions, because they are mutually recursive
17364 with their set_block_* pairing functions. */
17365 static void set_decl_origin_self (tree
);
17366 static void set_decl_abstract_flags (tree
, int);
17368 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17369 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17370 that it points to the node itself, thus indicating that the node is its
17371 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17372 the given node is NULL, recursively descend the decl/block tree which
17373 it is the root of, and for each other ..._DECL or BLOCK node contained
17374 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17375 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17376 values to point to themselves. */
17379 set_block_origin_self (tree stmt
)
17381 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17383 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17388 for (local_decl
= BLOCK_VARS (stmt
);
17389 local_decl
!= NULL_TREE
;
17390 local_decl
= DECL_CHAIN (local_decl
))
17391 if (! DECL_EXTERNAL (local_decl
))
17392 set_decl_origin_self (local_decl
); /* Potential recursion. */
17398 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17399 subblock
!= NULL_TREE
;
17400 subblock
= BLOCK_CHAIN (subblock
))
17401 set_block_origin_self (subblock
); /* Recurse. */
17406 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17407 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17408 node to so that it points to the node itself, thus indicating that the
17409 node represents its own (abstract) origin. Additionally, if the
17410 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17411 the decl/block tree of which the given node is the root of, and for
17412 each other ..._DECL or BLOCK node contained therein whose
17413 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17414 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17415 point to themselves. */
17418 set_decl_origin_self (tree decl
)
17420 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17422 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17423 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17427 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17428 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17429 if (DECL_INITIAL (decl
) != NULL_TREE
17430 && DECL_INITIAL (decl
) != error_mark_node
)
17431 set_block_origin_self (DECL_INITIAL (decl
));
17436 /* Given a pointer to some BLOCK node, and a boolean value to set the
17437 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17438 the given block, and for all local decls and all local sub-blocks
17439 (recursively) which are contained therein. */
17442 set_block_abstract_flags (tree stmt
, int setting
)
17448 BLOCK_ABSTRACT (stmt
) = setting
;
17450 for (local_decl
= BLOCK_VARS (stmt
);
17451 local_decl
!= NULL_TREE
;
17452 local_decl
= DECL_CHAIN (local_decl
))
17453 if (! DECL_EXTERNAL (local_decl
))
17454 set_decl_abstract_flags (local_decl
, setting
);
17456 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17458 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17459 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17460 || TREE_CODE (local_decl
) == PARM_DECL
)
17461 set_decl_abstract_flags (local_decl
, setting
);
17464 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17465 subblock
!= NULL_TREE
;
17466 subblock
= BLOCK_CHAIN (subblock
))
17467 set_block_abstract_flags (subblock
, setting
);
17470 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17471 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17472 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17473 set the abstract flags for all of the parameters, local vars, local
17474 blocks and sub-blocks (recursively) to the same setting. */
17477 set_decl_abstract_flags (tree decl
, int setting
)
17479 DECL_ABSTRACT (decl
) = setting
;
17480 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17484 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17485 DECL_ABSTRACT (arg
) = setting
;
17486 if (DECL_INITIAL (decl
) != NULL_TREE
17487 && DECL_INITIAL (decl
) != error_mark_node
)
17488 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17492 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17493 may later generate inlined and/or out-of-line instances of. */
17496 dwarf2out_abstract_function (tree decl
)
17498 dw_die_ref old_die
;
17502 htab_t old_decl_loc_table
;
17503 htab_t old_cached_dw_loc_list_table
;
17504 int old_call_site_count
, old_tail_call_site_count
;
17505 struct call_arg_loc_node
*old_call_arg_locations
;
17507 /* Make sure we have the actual abstract inline, not a clone. */
17508 decl
= DECL_ORIGIN (decl
);
17510 old_die
= lookup_decl_die (decl
);
17511 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17512 /* We've already generated the abstract instance. */
17515 /* We can be called while recursively when seeing block defining inlined subroutine
17516 DIE. Be sure to not clobber the outer location table nor use it or we would
17517 get locations in abstract instantces. */
17518 old_decl_loc_table
= decl_loc_table
;
17519 decl_loc_table
= NULL
;
17520 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17521 cached_dw_loc_list_table
= NULL
;
17522 old_call_arg_locations
= call_arg_locations
;
17523 call_arg_locations
= NULL
;
17524 old_call_site_count
= call_site_count
;
17525 call_site_count
= -1;
17526 old_tail_call_site_count
= tail_call_site_count
;
17527 tail_call_site_count
= -1;
17529 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17530 we don't get confused by DECL_ABSTRACT. */
17531 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17533 context
= decl_class_context (decl
);
17535 gen_type_die_for_member
17536 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17539 /* Pretend we've just finished compiling this function. */
17540 save_fn
= current_function_decl
;
17541 current_function_decl
= decl
;
17543 was_abstract
= DECL_ABSTRACT (decl
);
17544 set_decl_abstract_flags (decl
, 1);
17545 dwarf2out_decl (decl
);
17546 if (! was_abstract
)
17547 set_decl_abstract_flags (decl
, 0);
17549 current_function_decl
= save_fn
;
17550 decl_loc_table
= old_decl_loc_table
;
17551 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17552 call_arg_locations
= old_call_arg_locations
;
17553 call_site_count
= old_call_site_count
;
17554 tail_call_site_count
= old_tail_call_site_count
;
17557 /* Helper function of premark_used_types() which gets called through
17560 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17561 marked as unused by prune_unused_types. */
17564 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17569 type
= (tree
) *slot
;
17570 die
= lookup_type_die (type
);
17572 die
->die_perennial_p
= 1;
17576 /* Helper function of premark_types_used_by_global_vars which gets called
17577 through htab_traverse.
17579 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17580 marked as unused by prune_unused_types. The DIE of the type is marked
17581 only if the global variable using the type will actually be emitted. */
17584 premark_types_used_by_global_vars_helper (void **slot
,
17585 void *data ATTRIBUTE_UNUSED
)
17587 struct types_used_by_vars_entry
*entry
;
17590 entry
= (struct types_used_by_vars_entry
*) *slot
;
17591 gcc_assert (entry
->type
!= NULL
17592 && entry
->var_decl
!= NULL
);
17593 die
= lookup_type_die (entry
->type
);
17596 /* Ask cgraph if the global variable really is to be emitted.
17597 If yes, then we'll keep the DIE of ENTRY->TYPE. */
17598 struct varpool_node
*node
= varpool_get_node (entry
->var_decl
);
17599 if (node
&& node
->analyzed
)
17601 die
->die_perennial_p
= 1;
17602 /* Keep the parent DIEs as well. */
17603 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
17604 die
->die_perennial_p
= 1;
17610 /* Mark all members of used_types_hash as perennial. */
17613 premark_used_types (struct function
*fun
)
17615 if (fun
&& fun
->used_types_hash
)
17616 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
17619 /* Mark all members of types_used_by_vars_entry as perennial. */
17622 premark_types_used_by_global_vars (void)
17624 if (types_used_by_vars_hash
)
17625 htab_traverse (types_used_by_vars_hash
,
17626 premark_types_used_by_global_vars_helper
, NULL
);
17629 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
17630 for CA_LOC call arg loc node. */
17633 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
17634 struct call_arg_loc_node
*ca_loc
)
17636 dw_die_ref stmt_die
= NULL
, die
;
17637 tree block
= ca_loc
->block
;
17640 && block
!= DECL_INITIAL (decl
)
17641 && TREE_CODE (block
) == BLOCK
)
17643 if (block_map
.length () > BLOCK_NUMBER (block
))
17644 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
17647 block
= BLOCK_SUPERCONTEXT (block
);
17649 if (stmt_die
== NULL
)
17650 stmt_die
= subr_die
;
17651 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
17652 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
17653 if (ca_loc
->tail_call_p
)
17654 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
17655 if (ca_loc
->symbol_ref
)
17657 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
17659 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
17661 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
17666 /* Generate a DIE to represent a declared function (either file-scope or
17670 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
17672 tree origin
= decl_ultimate_origin (decl
);
17673 dw_die_ref subr_die
;
17675 dw_die_ref old_die
= lookup_decl_die (decl
);
17676 int declaration
= (current_function_decl
!= decl
17677 || class_or_namespace_scope_p (context_die
));
17679 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
17681 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
17682 started to generate the abstract instance of an inline, decided to output
17683 its containing class, and proceeded to emit the declaration of the inline
17684 from the member list for the class. If so, DECLARATION takes priority;
17685 we'll get back to the abstract instance when done with the class. */
17687 /* The class-scope declaration DIE must be the primary DIE. */
17688 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
17691 gcc_assert (!old_die
);
17694 /* Now that the C++ front end lazily declares artificial member fns, we
17695 might need to retrofit the declaration into its class. */
17696 if (!declaration
&& !origin
&& !old_die
17697 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
17698 && !class_or_namespace_scope_p (context_die
)
17699 && debug_info_level
> DINFO_LEVEL_TERSE
)
17700 old_die
= force_decl_die (decl
);
17702 if (origin
!= NULL
)
17704 gcc_assert (!declaration
|| local_scope_p (context_die
));
17706 /* Fixup die_parent for the abstract instance of a nested
17707 inline function. */
17708 if (old_die
&& old_die
->die_parent
== NULL
)
17709 add_child_die (context_die
, old_die
);
17711 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17712 add_abstract_origin_attribute (subr_die
, origin
);
17713 /* This is where the actual code for a cloned function is.
17714 Let's emit linkage name attribute for it. This helps
17715 debuggers to e.g, set breakpoints into
17716 constructors/destructors when the user asks "break
17718 add_linkage_name (subr_die
, decl
);
17722 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
17723 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
17725 if (!get_AT_flag (old_die
, DW_AT_declaration
)
17726 /* We can have a normal definition following an inline one in the
17727 case of redefinition of GNU C extern inlines.
17728 It seems reasonable to use AT_specification in this case. */
17729 && !get_AT (old_die
, DW_AT_inline
))
17731 /* Detect and ignore this case, where we are trying to output
17732 something we have already output. */
17736 /* If the definition comes from the same place as the declaration,
17737 maybe use the old DIE. We always want the DIE for this function
17738 that has the *_pc attributes to be under comp_unit_die so the
17739 debugger can find it. We also need to do this for abstract
17740 instances of inlines, since the spec requires the out-of-line copy
17741 to have the same parent. For local class methods, this doesn't
17742 apply; we just use the old DIE. */
17743 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
17744 && (DECL_ARTIFICIAL (decl
)
17745 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
17746 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
17747 == (unsigned) s
.line
))))
17749 subr_die
= old_die
;
17751 /* Clear out the declaration attribute and the formal parameters.
17752 Do not remove all children, because it is possible that this
17753 declaration die was forced using force_decl_die(). In such
17754 cases die that forced declaration die (e.g. TAG_imported_module)
17755 is one of the children that we do not want to remove. */
17756 remove_AT (subr_die
, DW_AT_declaration
);
17757 remove_AT (subr_die
, DW_AT_object_pointer
);
17758 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
17762 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17763 add_AT_specification (subr_die
, old_die
);
17764 add_pubname (decl
, subr_die
);
17765 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
17766 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
17767 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
17768 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
17773 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
17775 if (TREE_PUBLIC (decl
))
17776 add_AT_flag (subr_die
, DW_AT_external
, 1);
17778 add_name_and_src_coords_attributes (subr_die
, decl
);
17779 add_pubname (decl
, subr_die
);
17780 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17782 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
17783 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
17784 0, 0, context_die
);
17787 add_pure_or_virtual_attribute (subr_die
, decl
);
17788 if (DECL_ARTIFICIAL (decl
))
17789 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17791 add_accessibility_attribute (subr_die
, decl
);
17796 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17798 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
17800 /* If this is an explicit function declaration then generate
17801 a DW_AT_explicit attribute. */
17802 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
17803 && (dwarf_version
>= 3 || !dwarf_strict
))
17804 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
17806 /* The first time we see a member function, it is in the context of
17807 the class to which it belongs. We make sure of this by emitting
17808 the class first. The next time is the definition, which is
17809 handled above. The two may come from the same source text.
17811 Note that force_decl_die() forces function declaration die. It is
17812 later reused to represent definition. */
17813 equate_decl_number_to_die (decl
, subr_die
);
17816 else if (DECL_ABSTRACT (decl
))
17818 if (DECL_DECLARED_INLINE_P (decl
))
17820 if (cgraph_function_possibly_inlined_p (decl
))
17821 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
17823 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
17827 if (cgraph_function_possibly_inlined_p (decl
))
17828 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
17830 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
17833 if (DECL_DECLARED_INLINE_P (decl
)
17834 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
17835 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
17837 equate_decl_number_to_die (decl
, subr_die
);
17839 else if (!DECL_EXTERNAL (decl
))
17841 HOST_WIDE_INT cfa_fb_offset
;
17842 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
17844 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
17845 equate_decl_number_to_die (decl
, subr_die
);
17847 gcc_checking_assert (fun
);
17848 if (!flag_reorder_blocks_and_partition
)
17850 dw_fde_ref fde
= fun
->fde
;
17851 if (fde
->dw_fde_begin
)
17853 /* We have already generated the labels. */
17854 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17855 fde
->dw_fde_end
, false);
17859 /* Create start/end labels and add the range. */
17860 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
17861 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
17862 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
17863 current_function_funcdef_no
);
17864 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
17865 current_function_funcdef_no
);
17866 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
17870 #if VMS_DEBUGGING_INFO
17871 /* HP OpenVMS Industry Standard 64: DWARF Extensions
17872 Section 2.3 Prologue and Epilogue Attributes:
17873 When a breakpoint is set on entry to a function, it is generally
17874 desirable for execution to be suspended, not on the very first
17875 instruction of the function, but rather at a point after the
17876 function's frame has been set up, after any language defined local
17877 declaration processing has been completed, and before execution of
17878 the first statement of the function begins. Debuggers generally
17879 cannot properly determine where this point is. Similarly for a
17880 breakpoint set on exit from a function. The prologue and epilogue
17881 attributes allow a compiler to communicate the location(s) to use. */
17884 if (fde
->dw_fde_vms_end_prologue
)
17885 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
17886 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
17888 if (fde
->dw_fde_vms_begin_epilogue
)
17889 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
17890 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
17897 /* Generate pubnames entries for the split function code ranges. */
17898 dw_fde_ref fde
= fun
->fde
;
17900 if (fde
->dw_fde_second_begin
)
17902 if (dwarf_version
>= 3 || !dwarf_strict
)
17904 /* We should use ranges for non-contiguous code section
17905 addresses. Use the actual code range for the initial
17906 section, since the HOT/COLD labels might precede an
17907 alignment offset. */
17908 bool range_list_added
= false;
17909 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
17910 fde
->dw_fde_end
, &range_list_added
,
17912 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
17913 fde
->dw_fde_second_end
,
17914 &range_list_added
, false);
17915 if (range_list_added
)
17920 /* There is no real support in DW2 for this .. so we make
17921 a work-around. First, emit the pub name for the segment
17922 containing the function label. Then make and emit a
17923 simplified subprogram DIE for the second segment with the
17924 name pre-fixed by __hot/cold_sect_of_. We use the same
17925 linkage name for the second die so that gdb will find both
17926 sections when given "b foo". */
17927 const char *name
= NULL
;
17928 tree decl_name
= DECL_NAME (decl
);
17929 dw_die_ref seg_die
;
17931 /* Do the 'primary' section. */
17932 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
17933 fde
->dw_fde_end
, false);
17935 /* Build a minimal DIE for the secondary section. */
17936 seg_die
= new_die (DW_TAG_subprogram
,
17937 subr_die
->die_parent
, decl
);
17939 if (TREE_PUBLIC (decl
))
17940 add_AT_flag (seg_die
, DW_AT_external
, 1);
17942 if (decl_name
!= NULL
17943 && IDENTIFIER_POINTER (decl_name
) != NULL
)
17945 name
= dwarf2_name (decl
, 1);
17946 if (! DECL_ARTIFICIAL (decl
))
17947 add_src_coords_attributes (seg_die
, decl
);
17949 add_linkage_name (seg_die
, decl
);
17951 gcc_assert (name
!= NULL
);
17952 add_pure_or_virtual_attribute (seg_die
, decl
);
17953 if (DECL_ARTIFICIAL (decl
))
17954 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
17956 name
= concat ("__second_sect_of_", name
, NULL
);
17957 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
17958 fde
->dw_fde_second_end
, false);
17959 add_name_attribute (seg_die
, name
);
17960 if (want_pubnames ())
17961 add_pubname_string (name
, seg_die
);
17965 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
17969 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
17971 /* We define the "frame base" as the function's CFA. This is more
17972 convenient for several reasons: (1) It's stable across the prologue
17973 and epilogue, which makes it better than just a frame pointer,
17974 (2) With dwarf3, there exists a one-byte encoding that allows us
17975 to reference the .debug_frame data by proxy, but failing that,
17976 (3) We can at least reuse the code inspection and interpretation
17977 code that determines the CFA position at various points in the
17979 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
17981 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
17982 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
17986 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
17987 if (list
->dw_loc_next
)
17988 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
17990 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
17993 /* Compute a displacement from the "steady-state frame pointer" to
17994 the CFA. The former is what all stack slots and argument slots
17995 will reference in the rtl; the latter is what we've told the
17996 debugger about. We'll need to adjust all frame_base references
17997 by this displacement. */
17998 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18000 if (fun
->static_chain_decl
)
18001 add_AT_location_description (subr_die
, DW_AT_static_link
,
18002 loc_list_from_tree (fun
->static_chain_decl
, 2));
18005 /* Generate child dies for template paramaters. */
18006 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18007 gen_generic_params_dies (decl
);
18009 /* Now output descriptions of the arguments for this function. This gets
18010 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18011 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18012 `...' at the end of the formal parameter list. In order to find out if
18013 there was a trailing ellipsis or not, we must instead look at the type
18014 associated with the FUNCTION_DECL. This will be a node of type
18015 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18016 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18017 an ellipsis at the end. */
18019 /* In the case where we are describing a mere function declaration, all we
18020 need to do here (and all we *can* do here) is to describe the *types* of
18021 its formal parameters. */
18022 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18024 else if (declaration
)
18025 gen_formal_types_die (decl
, subr_die
);
18028 /* Generate DIEs to represent all known formal parameters. */
18029 tree parm
= DECL_ARGUMENTS (decl
);
18030 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18031 tree generic_decl_parm
= generic_decl
18032 ? DECL_ARGUMENTS (generic_decl
)
18035 /* Now we want to walk the list of parameters of the function and
18036 emit their relevant DIEs.
18038 We consider the case of DECL being an instance of a generic function
18039 as well as it being a normal function.
18041 If DECL is an instance of a generic function we walk the
18042 parameters of the generic function declaration _and_ the parameters of
18043 DECL itself. This is useful because we want to emit specific DIEs for
18044 function parameter packs and those are declared as part of the
18045 generic function declaration. In that particular case,
18046 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18047 That DIE has children DIEs representing the set of arguments
18048 of the pack. Note that the set of pack arguments can be empty.
18049 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18052 Otherwise, we just consider the parameters of DECL. */
18053 while (generic_decl_parm
|| parm
)
18055 if (generic_decl_parm
18056 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18057 gen_formal_parameter_pack_die (generic_decl_parm
,
18062 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18064 if (parm
== DECL_ARGUMENTS (decl
)
18065 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18067 && (dwarf_version
>= 3 || !dwarf_strict
))
18068 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18070 parm
= DECL_CHAIN (parm
);
18073 if (generic_decl_parm
)
18074 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18077 /* Decide whether we need an unspecified_parameters DIE at the end.
18078 There are 2 more cases to do this for: 1) the ansi ... declaration -
18079 this is detectable when the end of the arg list is not a
18080 void_type_node 2) an unprototyped function declaration (not a
18081 definition). This just means that we have no info about the
18082 parameters at all. */
18083 if (prototype_p (TREE_TYPE (decl
)))
18085 /* This is the prototyped case, check for.... */
18086 if (stdarg_p (TREE_TYPE (decl
)))
18087 gen_unspecified_parameters_die (decl
, subr_die
);
18089 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18090 gen_unspecified_parameters_die (decl
, subr_die
);
18093 /* Output Dwarf info for all of the stuff within the body of the function
18094 (if it has one - it may be just a declaration). */
18095 outer_scope
= DECL_INITIAL (decl
);
18097 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18098 a function. This BLOCK actually represents the outermost binding contour
18099 for the function, i.e. the contour in which the function's formal
18100 parameters and labels get declared. Curiously, it appears that the front
18101 end doesn't actually put the PARM_DECL nodes for the current function onto
18102 the BLOCK_VARS list for this outer scope, but are strung off of the
18103 DECL_ARGUMENTS list for the function instead.
18105 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18106 the LABEL_DECL nodes for the function however, and we output DWARF info
18107 for those in decls_for_scope. Just within the `outer_scope' there will be
18108 a BLOCK node representing the function's outermost pair of curly braces,
18109 and any blocks used for the base and member initializers of a C++
18110 constructor function. */
18111 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18113 int call_site_note_count
= 0;
18114 int tail_call_site_note_count
= 0;
18116 /* Emit a DW_TAG_variable DIE for a named return value. */
18117 if (DECL_NAME (DECL_RESULT (decl
)))
18118 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18120 current_function_has_inlines
= 0;
18121 decls_for_scope (outer_scope
, subr_die
, 0);
18123 if (call_arg_locations
&& !dwarf_strict
)
18125 struct call_arg_loc_node
*ca_loc
;
18126 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18128 dw_die_ref die
= NULL
;
18129 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18132 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18133 arg
; arg
= next_arg
)
18135 dw_loc_descr_ref reg
, val
;
18136 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18137 dw_die_ref cdie
, tdie
= NULL
;
18139 next_arg
= XEXP (arg
, 1);
18140 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18142 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18143 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18144 && REGNO (XEXP (XEXP (arg
, 0), 0))
18145 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18146 next_arg
= XEXP (next_arg
, 1);
18147 if (mode
== VOIDmode
)
18149 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18150 if (mode
== VOIDmode
)
18151 mode
= GET_MODE (XEXP (arg
, 0));
18153 if (mode
== VOIDmode
|| mode
== BLKmode
)
18155 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18157 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18158 tloc
= XEXP (XEXP (arg
, 0), 1);
18161 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18162 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18164 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18165 tlocc
= XEXP (XEXP (arg
, 0), 1);
18169 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18170 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18171 VAR_INIT_STATUS_INITIALIZED
);
18172 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18174 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18175 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18176 get_address_mode (mem
),
18178 VAR_INIT_STATUS_INITIALIZED
);
18180 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18181 == DEBUG_PARAMETER_REF
)
18184 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18185 tdie
= lookup_decl_die (tdecl
);
18192 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18193 != DEBUG_PARAMETER_REF
)
18195 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18197 VAR_INIT_STATUS_INITIALIZED
);
18201 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18202 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18205 add_AT_loc (cdie
, DW_AT_location
, reg
);
18206 else if (tdie
!= NULL
)
18207 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18208 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18209 if (next_arg
!= XEXP (arg
, 1))
18211 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18212 if (mode
== VOIDmode
)
18213 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18214 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18217 VAR_INIT_STATUS_INITIALIZED
);
18219 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18223 && (ca_loc
->symbol_ref
|| tloc
))
18224 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18225 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18227 dw_loc_descr_ref tval
= NULL
;
18229 if (tloc
!= NULL_RTX
)
18230 tval
= mem_loc_descriptor (tloc
,
18231 GET_MODE (tloc
) == VOIDmode
18232 ? Pmode
: GET_MODE (tloc
),
18234 VAR_INIT_STATUS_INITIALIZED
);
18236 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18237 else if (tlocc
!= NULL_RTX
)
18239 tval
= mem_loc_descriptor (tlocc
,
18240 GET_MODE (tlocc
) == VOIDmode
18241 ? Pmode
: GET_MODE (tlocc
),
18243 VAR_INIT_STATUS_INITIALIZED
);
18245 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18251 call_site_note_count
++;
18252 if (ca_loc
->tail_call_p
)
18253 tail_call_site_note_count
++;
18257 call_arg_locations
= NULL
;
18258 call_arg_loc_last
= NULL
;
18259 if (tail_call_site_count
>= 0
18260 && tail_call_site_count
== tail_call_site_note_count
18263 if (call_site_count
>= 0
18264 && call_site_count
== call_site_note_count
)
18265 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18267 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18269 call_site_count
= -1;
18270 tail_call_site_count
= -1;
18272 /* Add the calling convention attribute if requested. */
18273 add_calling_convention_attribute (subr_die
, decl
);
18277 /* Returns a hash value for X (which really is a die_struct). */
18280 common_block_die_table_hash (const void *x
)
18282 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18283 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18286 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18287 as decl_id and die_parent of die_struct Y. */
18290 common_block_die_table_eq (const void *x
, const void *y
)
18292 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18293 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18294 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18297 /* Generate a DIE to represent a declared data object.
18298 Either DECL or ORIGIN must be non-null. */
18301 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18303 HOST_WIDE_INT off
= 0;
18305 tree decl_or_origin
= decl
? decl
: origin
;
18306 tree ultimate_origin
;
18307 dw_die_ref var_die
;
18308 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18309 dw_die_ref origin_die
;
18310 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18311 || class_or_namespace_scope_p (context_die
));
18312 bool specialization_p
= false;
18314 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18315 if (decl
|| ultimate_origin
)
18316 origin
= ultimate_origin
;
18317 com_decl
= fortran_common (decl_or_origin
, &off
);
18319 /* Symbol in common gets emitted as a child of the common block, in the form
18320 of a data member. */
18323 dw_die_ref com_die
;
18324 dw_loc_list_ref loc
;
18325 die_node com_die_arg
;
18327 var_die
= lookup_decl_die (decl_or_origin
);
18330 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18332 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18337 /* Optimize the common case. */
18338 if (single_element_loc_list_p (loc
)
18339 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18340 && loc
->expr
->dw_loc_next
== NULL
18341 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18344 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18345 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18346 = plus_constant (GET_MODE (x
), x
, off
);
18349 loc_list_plus_const (loc
, off
);
18351 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18352 remove_AT (var_die
, DW_AT_declaration
);
18358 if (common_block_die_table
== NULL
)
18359 common_block_die_table
18360 = htab_create_ggc (10, common_block_die_table_hash
,
18361 common_block_die_table_eq
, NULL
);
18363 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18364 com_die_arg
.die_parent
= context_die
;
18365 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18366 loc
= loc_list_from_tree (com_decl
, 2);
18367 if (com_die
== NULL
)
18370 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18373 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18374 add_name_and_src_coords_attributes (com_die
, com_decl
);
18377 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18378 /* Avoid sharing the same loc descriptor between
18379 DW_TAG_common_block and DW_TAG_variable. */
18380 loc
= loc_list_from_tree (com_decl
, 2);
18382 else if (DECL_EXTERNAL (decl
))
18383 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18384 if (want_pubnames ())
18385 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18386 com_die
->decl_id
= DECL_UID (com_decl
);
18387 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18388 *slot
= (void *) com_die
;
18390 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18392 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18393 loc
= loc_list_from_tree (com_decl
, 2);
18394 remove_AT (com_die
, DW_AT_declaration
);
18396 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18397 add_name_and_src_coords_attributes (var_die
, decl
);
18398 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18399 TREE_THIS_VOLATILE (decl
), context_die
);
18400 add_AT_flag (var_die
, DW_AT_external
, 1);
18405 /* Optimize the common case. */
18406 if (single_element_loc_list_p (loc
)
18407 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18408 && loc
->expr
->dw_loc_next
== NULL
18409 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18411 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18412 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18413 = plus_constant (GET_MODE (x
), x
, off
);
18416 loc_list_plus_const (loc
, off
);
18418 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18420 else if (DECL_EXTERNAL (decl
))
18421 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18422 equate_decl_number_to_die (decl
, var_die
);
18426 /* If the compiler emitted a definition for the DECL declaration
18427 and if we already emitted a DIE for it, don't emit a second
18428 DIE for it again. Allow re-declarations of DECLs that are
18429 inside functions, though. */
18430 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18433 /* For static data members, the declaration in the class is supposed
18434 to have DW_TAG_member tag; the specification should still be
18435 DW_TAG_variable referencing the DW_TAG_member DIE. */
18436 if (declaration
&& class_scope_p (context_die
))
18437 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18439 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18442 if (origin
!= NULL
)
18443 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18445 /* Loop unrolling can create multiple blocks that refer to the same
18446 static variable, so we must test for the DW_AT_declaration flag.
18448 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18449 copy decls and set the DECL_ABSTRACT flag on them instead of
18452 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18454 ??? The declare_in_namespace support causes us to get two DIEs for one
18455 variable, both of which are declarations. We want to avoid considering
18456 one to be a specification, so we must test that this DIE is not a
18458 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18459 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18461 /* This is a definition of a C++ class level static. */
18462 add_AT_specification (var_die
, old_die
);
18463 specialization_p
= true;
18464 if (DECL_NAME (decl
))
18466 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18467 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18469 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18470 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18472 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18473 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18475 if (old_die
->die_tag
== DW_TAG_member
)
18476 add_linkage_name (var_die
, decl
);
18480 add_name_and_src_coords_attributes (var_die
, decl
);
18482 if ((origin
== NULL
&& !specialization_p
)
18484 && !DECL_ABSTRACT (decl_or_origin
)
18485 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18486 decl_function_context
18487 (decl_or_origin
))))
18489 tree type
= TREE_TYPE (decl_or_origin
);
18491 if (decl_by_reference_p (decl_or_origin
))
18492 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18494 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18495 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18498 if (origin
== NULL
&& !specialization_p
)
18500 if (TREE_PUBLIC (decl
))
18501 add_AT_flag (var_die
, DW_AT_external
, 1);
18503 if (DECL_ARTIFICIAL (decl
))
18504 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18506 add_accessibility_attribute (var_die
, decl
);
18510 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18512 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18513 equate_decl_number_to_die (decl
, var_die
);
18516 && (! DECL_ABSTRACT (decl_or_origin
)
18517 /* Local static vars are shared between all clones/inlines,
18518 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18520 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18521 && TREE_STATIC (decl_or_origin
)
18522 && DECL_RTL_SET_P (decl_or_origin
)))
18523 /* When abstract origin already has DW_AT_location attribute, no need
18524 to add it again. */
18525 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18527 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18528 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18529 defer_location (decl_or_origin
, var_die
);
18531 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18532 decl
== NULL
, DW_AT_location
);
18533 add_pubname (decl_or_origin
, var_die
);
18536 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18539 /* Generate a DIE to represent a named constant. */
18542 gen_const_die (tree decl
, dw_die_ref context_die
)
18544 dw_die_ref const_die
;
18545 tree type
= TREE_TYPE (decl
);
18547 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18548 add_name_and_src_coords_attributes (const_die
, decl
);
18549 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18550 if (TREE_PUBLIC (decl
))
18551 add_AT_flag (const_die
, DW_AT_external
, 1);
18552 if (DECL_ARTIFICIAL (decl
))
18553 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18554 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18557 /* Generate a DIE to represent a label identifier. */
18560 gen_label_die (tree decl
, dw_die_ref context_die
)
18562 tree origin
= decl_ultimate_origin (decl
);
18563 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
18565 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18567 if (origin
!= NULL
)
18568 add_abstract_origin_attribute (lbl_die
, origin
);
18570 add_name_and_src_coords_attributes (lbl_die
, decl
);
18572 if (DECL_ABSTRACT (decl
))
18573 equate_decl_number_to_die (decl
, lbl_die
);
18576 insn
= DECL_RTL_IF_SET (decl
);
18578 /* Deleted labels are programmer specified labels which have been
18579 eliminated because of various optimizations. We still emit them
18580 here so that it is possible to put breakpoints on them. */
18584 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
18586 /* When optimization is enabled (via -O) some parts of the compiler
18587 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
18588 represent source-level labels which were explicitly declared by
18589 the user. This really shouldn't be happening though, so catch
18590 it if it ever does happen. */
18591 gcc_assert (!INSN_DELETED_P (insn
));
18593 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
18594 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18598 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
18599 && CODE_LABEL_NUMBER (insn
) != -1)
18601 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
18602 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
18607 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
18608 attributes to the DIE for a block STMT, to describe where the inlined
18609 function was called from. This is similar to add_src_coords_attributes. */
18612 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
18614 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
18616 if (dwarf_version
>= 3 || !dwarf_strict
)
18618 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
18619 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
18624 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
18625 Add low_pc and high_pc attributes to the DIE for a block STMT. */
18628 add_high_low_attributes (tree stmt
, dw_die_ref die
)
18630 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
18632 if (BLOCK_FRAGMENT_CHAIN (stmt
)
18633 && (dwarf_version
>= 3 || !dwarf_strict
))
18635 tree chain
, superblock
= NULL_TREE
;
18637 dw_attr_ref attr
= NULL
;
18639 if (inlined_function_outer_scope_p (stmt
))
18641 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18642 BLOCK_NUMBER (stmt
));
18643 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
18646 /* Optimize duplicate .debug_ranges lists or even tails of
18647 lists. If this BLOCK has same ranges as its supercontext,
18648 lookup DW_AT_ranges attribute in the supercontext (and
18649 recursively so), verify that the ranges_table contains the
18650 right values and use it instead of adding a new .debug_range. */
18651 for (chain
= stmt
, pdie
= die
;
18652 BLOCK_SAME_RANGE (chain
);
18653 chain
= BLOCK_SUPERCONTEXT (chain
))
18655 dw_attr_ref new_attr
;
18657 pdie
= pdie
->die_parent
;
18660 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
18662 new_attr
= get_AT (pdie
, DW_AT_ranges
);
18663 if (new_attr
== NULL
18664 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
18667 superblock
= BLOCK_SUPERCONTEXT (chain
);
18670 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
18671 / 2 / DWARF2_ADDR_SIZE
].num
18672 == BLOCK_NUMBER (superblock
))
18673 && BLOCK_FRAGMENT_CHAIN (superblock
))
18675 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
18676 / 2 / DWARF2_ADDR_SIZE
;
18677 unsigned long supercnt
= 0, thiscnt
= 0;
18678 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
18679 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18682 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
18683 == BLOCK_NUMBER (chain
));
18685 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
18686 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18687 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
18689 gcc_assert (supercnt
>= thiscnt
);
18690 add_AT_range_list (die
, DW_AT_ranges
,
18691 ((off
+ supercnt
- thiscnt
)
18692 * 2 * DWARF2_ADDR_SIZE
),
18697 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
18699 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
18702 add_ranges (chain
);
18703 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
18710 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18711 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
18712 BLOCK_NUMBER (stmt
));
18713 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
18714 BLOCK_NUMBER (stmt
));
18715 add_AT_low_high_pc (die
, label
, label_high
, false);
18719 /* Generate a DIE for a lexical block. */
18722 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
18724 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
18726 if (call_arg_locations
)
18728 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18729 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18730 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
18733 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
18734 add_high_low_attributes (stmt
, stmt_die
);
18736 decls_for_scope (stmt
, stmt_die
, depth
);
18739 /* Generate a DIE for an inlined subprogram. */
18742 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
18746 /* The instance of function that is effectively being inlined shall not
18748 gcc_assert (! BLOCK_ABSTRACT (stmt
));
18750 decl
= block_ultimate_origin (stmt
);
18752 /* Emit info for the abstract instance first, if we haven't yet. We
18753 must emit this even if the block is abstract, otherwise when we
18754 emit the block below (or elsewhere), we may end up trying to emit
18755 a die whose origin die hasn't been emitted, and crashing. */
18756 dwarf2out_abstract_function (decl
);
18758 if (! BLOCK_ABSTRACT (stmt
))
18760 dw_die_ref subr_die
18761 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
18763 if (call_arg_locations
)
18765 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
18766 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
18767 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
18769 add_abstract_origin_attribute (subr_die
, decl
);
18770 if (TREE_ASM_WRITTEN (stmt
))
18771 add_high_low_attributes (stmt
, subr_die
);
18772 add_call_src_coords_attributes (stmt
, subr_die
);
18774 decls_for_scope (stmt
, subr_die
, depth
);
18775 current_function_has_inlines
= 1;
18779 /* Generate a DIE for a field in a record, or structure. */
18782 gen_field_die (tree decl
, dw_die_ref context_die
)
18784 dw_die_ref decl_die
;
18786 if (TREE_TYPE (decl
) == error_mark_node
)
18789 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
18790 add_name_and_src_coords_attributes (decl_die
, decl
);
18791 add_type_attribute (decl_die
, member_declared_type (decl
),
18792 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
18795 if (DECL_BIT_FIELD_TYPE (decl
))
18797 add_byte_size_attribute (decl_die
, decl
);
18798 add_bit_size_attribute (decl_die
, decl
);
18799 add_bit_offset_attribute (decl_die
, decl
);
18802 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
18803 add_data_member_location_attribute (decl_die
, decl
);
18805 if (DECL_ARTIFICIAL (decl
))
18806 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
18808 add_accessibility_attribute (decl_die
, decl
);
18810 /* Equate decl number to die, so that we can look up this decl later on. */
18811 equate_decl_number_to_die (decl
, decl_die
);
18815 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18816 Use modified_type_die instead.
18817 We keep this code here just in case these types of DIEs may be needed to
18818 represent certain things in other languages (e.g. Pascal) someday. */
18821 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
18824 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
18826 equate_type_number_to_die (type
, ptr_die
);
18827 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18828 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18831 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
18832 Use modified_type_die instead.
18833 We keep this code here just in case these types of DIEs may be needed to
18834 represent certain things in other languages (e.g. Pascal) someday. */
18837 gen_reference_type_die (tree type
, dw_die_ref context_die
)
18839 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
18841 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
18842 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
18844 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
18846 equate_type_number_to_die (type
, ref_die
);
18847 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
18848 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
18852 /* Generate a DIE for a pointer to a member type. */
18855 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
18858 = new_die (DW_TAG_ptr_to_member_type
,
18859 scope_die_for (type
, context_die
), type
);
18861 equate_type_number_to_die (type
, ptr_die
);
18862 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
18863 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
18864 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
18867 typedef const char *dchar_p
; /* For DEF_VEC_P. */
18869 static char *producer_string
;
18871 /* Return a heap allocated producer string including command line options
18872 if -grecord-gcc-switches. */
18875 gen_producer_string (void)
18878 vec
<dchar_p
> switches
= vNULL
;
18879 const char *language_string
= lang_hooks
.name
;
18880 char *producer
, *tail
;
18882 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
18883 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
18885 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
18886 switch (save_decoded_options
[j
].opt_index
)
18893 case OPT_auxbase_strip
:
18902 case OPT_SPECIAL_unknown
:
18903 case OPT_SPECIAL_ignore
:
18904 case OPT_SPECIAL_program_name
:
18905 case OPT_SPECIAL_input_file
:
18906 case OPT_grecord_gcc_switches
:
18907 case OPT_gno_record_gcc_switches
:
18908 case OPT__output_pch_
:
18909 case OPT_fdiagnostics_show_location_
:
18910 case OPT_fdiagnostics_show_option
:
18911 case OPT_fdiagnostics_show_caret
:
18912 case OPT_fdiagnostics_color_
:
18913 case OPT_fverbose_asm
:
18915 case OPT__sysroot_
:
18917 case OPT_nostdinc__
:
18918 /* Ignore these. */
18921 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
18922 & CL_NO_DWARF_RECORD
)
18924 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
18926 switch (save_decoded_options
[j
].canonical_option
[0][1])
18933 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
18940 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
18941 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
18945 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
18947 sprintf (tail
, "%s %s", language_string
, version_string
);
18950 FOR_EACH_VEC_ELT (switches
, j
, p
)
18954 memcpy (tail
+ 1, p
, len
);
18959 switches
.release ();
18963 /* Generate the DIE for the compilation unit. */
18966 gen_compile_unit_die (const char *filename
)
18969 const char *language_string
= lang_hooks
.name
;
18972 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
18976 add_name_attribute (die
, filename
);
18977 /* Don't add cwd for <built-in>. */
18978 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
18979 add_comp_dir_attribute (die
);
18982 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
18984 /* If our producer is LTO try to figure out a common language to use
18985 from the global list of translation units. */
18986 if (strcmp (language_string
, "GNU GIMPLE") == 0)
18990 const char *common_lang
= NULL
;
18992 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
18994 if (!TRANSLATION_UNIT_LANGUAGE (t
))
18997 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
18998 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19000 else if (strncmp (common_lang
, "GNU C", 5) == 0
19001 && strncmp(TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19002 /* Mixing C and C++ is ok, use C++ in that case. */
19003 common_lang
= "GNU C++";
19006 /* Fall back to C. */
19007 common_lang
= NULL
;
19013 language_string
= common_lang
;
19016 language
= DW_LANG_C89
;
19017 if (strcmp (language_string
, "GNU C++") == 0)
19018 language
= DW_LANG_C_plus_plus
;
19019 else if (strcmp (language_string
, "GNU F77") == 0)
19020 language
= DW_LANG_Fortran77
;
19021 else if (strcmp (language_string
, "GNU Pascal") == 0)
19022 language
= DW_LANG_Pascal83
;
19023 else if (dwarf_version
>= 3 || !dwarf_strict
)
19025 if (strcmp (language_string
, "GNU Ada") == 0)
19026 language
= DW_LANG_Ada95
;
19027 else if (strcmp (language_string
, "GNU Fortran") == 0)
19028 language
= DW_LANG_Fortran95
;
19029 else if (strcmp (language_string
, "GNU Java") == 0)
19030 language
= DW_LANG_Java
;
19031 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19032 language
= DW_LANG_ObjC
;
19033 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19034 language
= DW_LANG_ObjC_plus_plus
;
19035 else if (dwarf_version
>= 5 || !dwarf_strict
)
19037 if (strcmp (language_string
, "GNU Go") == 0)
19038 language
= DW_LANG_Go
;
19041 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19042 else if (strcmp (language_string
, "GNU Fortran") == 0)
19043 language
= DW_LANG_Fortran90
;
19045 add_AT_unsigned (die
, DW_AT_language
, language
);
19049 case DW_LANG_Fortran77
:
19050 case DW_LANG_Fortran90
:
19051 case DW_LANG_Fortran95
:
19052 /* Fortran has case insensitive identifiers and the front-end
19053 lowercases everything. */
19054 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19057 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19063 /* Generate the DIE for a base class. */
19066 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19068 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19070 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19071 add_data_member_location_attribute (die
, binfo
);
19073 if (BINFO_VIRTUAL_P (binfo
))
19074 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19076 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19077 children, otherwise the default is DW_ACCESS_public. In DWARF2
19078 the default has always been DW_ACCESS_private. */
19079 if (access
== access_public_node
)
19081 if (dwarf_version
== 2
19082 || context_die
->die_tag
== DW_TAG_class_type
)
19083 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19085 else if (access
== access_protected_node
)
19086 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19087 else if (dwarf_version
> 2
19088 && context_die
->die_tag
!= DW_TAG_class_type
)
19089 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19092 /* Generate a DIE for a class member. */
19095 gen_member_die (tree type
, dw_die_ref context_die
)
19098 tree binfo
= TYPE_BINFO (type
);
19101 /* If this is not an incomplete type, output descriptions of each of its
19102 members. Note that as we output the DIEs necessary to represent the
19103 members of this record or union type, we will also be trying to output
19104 DIEs to represent the *types* of those members. However the `type'
19105 function (above) will specifically avoid generating type DIEs for member
19106 types *within* the list of member DIEs for this (containing) type except
19107 for those types (of members) which are explicitly marked as also being
19108 members of this (containing) type themselves. The g++ front- end can
19109 force any given type to be treated as a member of some other (containing)
19110 type by setting the TYPE_CONTEXT of the given (member) type to point to
19111 the TREE node representing the appropriate (containing) type. */
19113 /* First output info about the base classes. */
19116 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19120 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19121 gen_inheritance_die (base
,
19122 (accesses
? (*accesses
)[i
] : access_public_node
),
19126 /* Now output info about the data members and type members. */
19127 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19129 /* If we thought we were generating minimal debug info for TYPE
19130 and then changed our minds, some of the member declarations
19131 may have already been defined. Don't define them again, but
19132 do put them in the right order. */
19134 child
= lookup_decl_die (member
);
19136 splice_child_die (context_die
, child
);
19138 gen_decl_die (member
, NULL
, context_die
);
19141 /* Now output info about the function members (if any). */
19142 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19144 /* Don't include clones in the member list. */
19145 if (DECL_ABSTRACT_ORIGIN (member
))
19148 child
= lookup_decl_die (member
);
19150 splice_child_die (context_die
, child
);
19152 gen_decl_die (member
, NULL
, context_die
);
19156 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19157 is set, we pretend that the type was never defined, so we only get the
19158 member DIEs needed by later specification DIEs. */
19161 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19162 enum debug_info_usage usage
)
19164 dw_die_ref type_die
= lookup_type_die (type
);
19165 dw_die_ref scope_die
= 0;
19167 int complete
= (TYPE_SIZE (type
)
19168 && (! TYPE_STUB_DECL (type
)
19169 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19170 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19171 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19173 if (type_die
&& ! complete
)
19176 if (TYPE_CONTEXT (type
) != NULL_TREE
19177 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19178 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19181 scope_die
= scope_die_for (type
, context_die
);
19183 /* Generate child dies for template paramaters. */
19184 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19185 schedule_generic_params_dies_gen (type
);
19187 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19188 /* First occurrence of type or toplevel definition of nested class. */
19190 dw_die_ref old_die
= type_die
;
19192 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19193 ? record_type_tag (type
) : DW_TAG_union_type
,
19195 equate_type_number_to_die (type
, type_die
);
19197 add_AT_specification (type_die
, old_die
);
19199 add_name_attribute (type_die
, type_tag (type
));
19202 remove_AT (type_die
, DW_AT_declaration
);
19204 /* If this type has been completed, then give it a byte_size attribute and
19205 then give a list of members. */
19206 if (complete
&& !ns_decl
)
19208 /* Prevent infinite recursion in cases where the type of some member of
19209 this type is expressed in terms of this type itself. */
19210 TREE_ASM_WRITTEN (type
) = 1;
19211 add_byte_size_attribute (type_die
, type
);
19212 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19214 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19215 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19218 /* If the first reference to this type was as the return type of an
19219 inline function, then it may not have a parent. Fix this now. */
19220 if (type_die
->die_parent
== NULL
)
19221 add_child_die (scope_die
, type_die
);
19223 push_decl_scope (type
);
19224 gen_member_die (type
, type_die
);
19227 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19228 if (TYPE_ARTIFICIAL (type
))
19229 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19231 /* GNU extension: Record what type our vtable lives in. */
19232 if (TYPE_VFIELD (type
))
19234 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19236 gen_type_die (vtype
, context_die
);
19237 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19238 lookup_type_die (vtype
));
19243 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19245 /* We don't need to do this for function-local types. */
19246 if (TYPE_STUB_DECL (type
)
19247 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19248 vec_safe_push (incomplete_types
, type
);
19251 if (get_AT (type_die
, DW_AT_name
))
19252 add_pubtype (type
, type_die
);
19255 /* Generate a DIE for a subroutine _type_. */
19258 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19260 tree return_type
= TREE_TYPE (type
);
19261 dw_die_ref subr_die
19262 = new_die (DW_TAG_subroutine_type
,
19263 scope_die_for (type
, context_die
), type
);
19265 equate_type_number_to_die (type
, subr_die
);
19266 add_prototyped_attribute (subr_die
, type
);
19267 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19268 gen_formal_types_die (type
, subr_die
);
19270 if (get_AT (subr_die
, DW_AT_name
))
19271 add_pubtype (type
, subr_die
);
19274 /* Generate a DIE for a type definition. */
19277 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19279 dw_die_ref type_die
;
19282 if (TREE_ASM_WRITTEN (decl
))
19285 TREE_ASM_WRITTEN (decl
) = 1;
19286 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19287 origin
= decl_ultimate_origin (decl
);
19288 if (origin
!= NULL
)
19289 add_abstract_origin_attribute (type_die
, origin
);
19294 add_name_and_src_coords_attributes (type_die
, decl
);
19295 if (DECL_ORIGINAL_TYPE (decl
))
19297 type
= DECL_ORIGINAL_TYPE (decl
);
19299 gcc_assert (type
!= TREE_TYPE (decl
));
19300 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19304 type
= TREE_TYPE (decl
);
19306 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19308 /* Here, we are in the case of decl being a typedef naming
19309 an anonymous type, e.g:
19310 typedef struct {...} foo;
19311 In that case TREE_TYPE (decl) is not a typedef variant
19312 type and TYPE_NAME of the anonymous type is set to the
19313 TYPE_DECL of the typedef. This construct is emitted by
19316 TYPE is the anonymous struct named by the typedef
19317 DECL. As we need the DW_AT_type attribute of the
19318 DW_TAG_typedef to point to the DIE of TYPE, let's
19319 generate that DIE right away. add_type_attribute
19320 called below will then pick (via lookup_type_die) that
19321 anonymous struct DIE. */
19322 if (!TREE_ASM_WRITTEN (type
))
19323 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19325 /* This is a GNU Extension. We are adding a
19326 DW_AT_linkage_name attribute to the DIE of the
19327 anonymous struct TYPE. The value of that attribute
19328 is the name of the typedef decl naming the anonymous
19329 struct. This greatly eases the work of consumers of
19330 this debug info. */
19331 add_linkage_attr (lookup_type_die (type
), decl
);
19335 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19336 TREE_THIS_VOLATILE (decl
), context_die
);
19338 if (is_naming_typedef_decl (decl
))
19339 /* We want that all subsequent calls to lookup_type_die with
19340 TYPE in argument yield the DW_TAG_typedef we have just
19342 equate_type_number_to_die (type
, type_die
);
19344 add_accessibility_attribute (type_die
, decl
);
19347 if (DECL_ABSTRACT (decl
))
19348 equate_decl_number_to_die (decl
, type_die
);
19350 if (get_AT (type_die
, DW_AT_name
))
19351 add_pubtype (decl
, type_die
);
19354 /* Generate a DIE for a struct, class, enum or union type. */
19357 gen_tagged_type_die (tree type
,
19358 dw_die_ref context_die
,
19359 enum debug_info_usage usage
)
19363 if (type
== NULL_TREE
19364 || !is_tagged_type (type
))
19367 /* If this is a nested type whose containing class hasn't been written
19368 out yet, writing it out will cover this one, too. This does not apply
19369 to instantiations of member class templates; they need to be added to
19370 the containing class as they are generated. FIXME: This hurts the
19371 idea of combining type decls from multiple TUs, since we can't predict
19372 what set of template instantiations we'll get. */
19373 if (TYPE_CONTEXT (type
)
19374 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19375 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19377 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19379 if (TREE_ASM_WRITTEN (type
))
19382 /* If that failed, attach ourselves to the stub. */
19383 push_decl_scope (TYPE_CONTEXT (type
));
19384 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19387 else if (TYPE_CONTEXT (type
) != NULL_TREE
19388 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19390 /* If this type is local to a function that hasn't been written
19391 out yet, use a NULL context for now; it will be fixed up in
19392 decls_for_scope. */
19393 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19394 /* A declaration DIE doesn't count; nested types need to go in the
19396 if (context_die
&& is_declaration_die (context_die
))
19397 context_die
= NULL
;
19402 context_die
= declare_in_namespace (type
, context_die
);
19406 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19408 /* This might have been written out by the call to
19409 declare_in_namespace. */
19410 if (!TREE_ASM_WRITTEN (type
))
19411 gen_enumeration_type_die (type
, context_die
);
19414 gen_struct_or_union_type_die (type
, context_die
, usage
);
19419 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19420 it up if it is ever completed. gen_*_type_die will set it for us
19421 when appropriate. */
19424 /* Generate a type description DIE. */
19427 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19428 enum debug_info_usage usage
)
19430 struct array_descr_info info
;
19432 if (type
== NULL_TREE
|| type
== error_mark_node
)
19435 if (TYPE_NAME (type
) != NULL_TREE
19436 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19437 && is_redundant_typedef (TYPE_NAME (type
))
19438 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19439 /* The DECL of this type is a typedef we don't want to emit debug
19440 info for but we want debug info for its underlying typedef.
19441 This can happen for e.g, the injected-class-name of a C++
19443 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19445 /* If TYPE is a typedef type variant, let's generate debug info
19446 for the parent typedef which TYPE is a type of. */
19447 if (typedef_variant_p (type
))
19449 if (TREE_ASM_WRITTEN (type
))
19452 /* Prevent broken recursion; we can't hand off to the same type. */
19453 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19455 /* Give typedefs the right scope. */
19456 context_die
= scope_die_for (type
, context_die
);
19458 TREE_ASM_WRITTEN (type
) = 1;
19460 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19464 /* If type is an anonymous tagged type named by a typedef, let's
19465 generate debug info for the typedef. */
19466 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19468 /* Use the DIE of the containing namespace as the parent DIE of
19469 the type description DIE we want to generate. */
19470 if (DECL_CONTEXT (TYPE_NAME (type
))
19471 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19472 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19474 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19478 /* If this is an array type with hidden descriptor, handle it first. */
19479 if (!TREE_ASM_WRITTEN (type
)
19480 && lang_hooks
.types
.get_array_descr_info
19481 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19482 && (dwarf_version
>= 3 || !dwarf_strict
))
19484 gen_descr_array_type_die (type
, &info
, context_die
);
19485 TREE_ASM_WRITTEN (type
) = 1;
19489 /* We are going to output a DIE to represent the unqualified version
19490 of this type (i.e. without any const or volatile qualifiers) so
19491 get the main variant (i.e. the unqualified version) of this type
19492 now. (Vectors are special because the debugging info is in the
19493 cloned type itself). */
19494 if (TREE_CODE (type
) != VECTOR_TYPE
)
19495 type
= type_main_variant (type
);
19497 if (TREE_ASM_WRITTEN (type
))
19500 switch (TREE_CODE (type
))
19506 case REFERENCE_TYPE
:
19507 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19508 ensures that the gen_type_die recursion will terminate even if the
19509 type is recursive. Recursive types are possible in Ada. */
19510 /* ??? We could perhaps do this for all types before the switch
19512 TREE_ASM_WRITTEN (type
) = 1;
19514 /* For these types, all that is required is that we output a DIE (or a
19515 set of DIEs) to represent the "basis" type. */
19516 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19517 DINFO_USAGE_IND_USE
);
19521 /* This code is used for C++ pointer-to-data-member types.
19522 Output a description of the relevant class type. */
19523 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19524 DINFO_USAGE_IND_USE
);
19526 /* Output a description of the type of the object pointed to. */
19527 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19528 DINFO_USAGE_IND_USE
);
19530 /* Now output a DIE to represent this pointer-to-data-member type
19532 gen_ptr_to_mbr_type_die (type
, context_die
);
19535 case FUNCTION_TYPE
:
19536 /* Force out return type (in case it wasn't forced out already). */
19537 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19538 DINFO_USAGE_DIR_USE
);
19539 gen_subroutine_type_die (type
, context_die
);
19543 /* Force out return type (in case it wasn't forced out already). */
19544 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19545 DINFO_USAGE_DIR_USE
);
19546 gen_subroutine_type_die (type
, context_die
);
19550 gen_array_type_die (type
, context_die
);
19554 gen_array_type_die (type
, context_die
);
19557 case ENUMERAL_TYPE
:
19560 case QUAL_UNION_TYPE
:
19561 gen_tagged_type_die (type
, context_die
, usage
);
19567 case FIXED_POINT_TYPE
:
19570 /* No DIEs needed for fundamental types. */
19575 /* Just use DW_TAG_unspecified_type. */
19577 dw_die_ref type_die
= lookup_type_die (type
);
19578 if (type_die
== NULL
)
19580 tree name
= TYPE_NAME (type
);
19581 if (TREE_CODE (name
) == TYPE_DECL
)
19582 name
= DECL_NAME (name
);
19583 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
19584 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
19585 equate_type_number_to_die (type
, type_die
);
19591 gcc_unreachable ();
19594 TREE_ASM_WRITTEN (type
) = 1;
19598 gen_type_die (tree type
, dw_die_ref context_die
)
19600 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
19603 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
19604 things which are local to the given block. */
19607 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19609 int must_output_die
= 0;
19612 /* Ignore blocks that are NULL. */
19613 if (stmt
== NULL_TREE
)
19616 inlined_func
= inlined_function_outer_scope_p (stmt
);
19618 /* If the block is one fragment of a non-contiguous block, do not
19619 process the variables, since they will have been done by the
19620 origin block. Do process subblocks. */
19621 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
19625 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
19626 gen_block_die (sub
, context_die
, depth
+ 1);
19631 /* Determine if we need to output any Dwarf DIEs at all to represent this
19634 /* The outer scopes for inlinings *must* always be represented. We
19635 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
19636 must_output_die
= 1;
19639 /* Determine if this block directly contains any "significant"
19640 local declarations which we will need to output DIEs for. */
19641 if (debug_info_level
> DINFO_LEVEL_TERSE
)
19642 /* We are not in terse mode so *any* local declaration counts
19643 as being a "significant" one. */
19644 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
19645 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
19646 && (TREE_USED (stmt
)
19647 || TREE_ASM_WRITTEN (stmt
)
19648 || BLOCK_ABSTRACT (stmt
)));
19649 else if ((TREE_USED (stmt
)
19650 || TREE_ASM_WRITTEN (stmt
)
19651 || BLOCK_ABSTRACT (stmt
))
19652 && !dwarf2out_ignore_block (stmt
))
19653 must_output_die
= 1;
19656 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
19657 DIE for any block which contains no significant local declarations at
19658 all. Rather, in such cases we just call `decls_for_scope' so that any
19659 needed Dwarf info for any sub-blocks will get properly generated. Note
19660 that in terse mode, our definition of what constitutes a "significant"
19661 local declaration gets restricted to include only inlined function
19662 instances and local (nested) function definitions. */
19663 if (must_output_die
)
19667 /* If STMT block is abstract, that means we have been called
19668 indirectly from dwarf2out_abstract_function.
19669 That function rightfully marks the descendent blocks (of
19670 the abstract function it is dealing with) as being abstract,
19671 precisely to prevent us from emitting any
19672 DW_TAG_inlined_subroutine DIE as a descendent
19673 of an abstract function instance. So in that case, we should
19674 not call gen_inlined_subroutine_die.
19676 Later though, when cgraph asks dwarf2out to emit info
19677 for the concrete instance of the function decl into which
19678 the concrete instance of STMT got inlined, the later will lead
19679 to the generation of a DW_TAG_inlined_subroutine DIE. */
19680 if (! BLOCK_ABSTRACT (stmt
))
19681 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
19684 gen_lexical_block_die (stmt
, context_die
, depth
);
19687 decls_for_scope (stmt
, context_die
, depth
);
19690 /* Process variable DECL (or variable with origin ORIGIN) within
19691 block STMT and add it to CONTEXT_DIE. */
19693 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
19696 tree decl_or_origin
= decl
? decl
: origin
;
19698 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
19699 die
= lookup_decl_die (decl_or_origin
);
19700 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
19701 && TYPE_DECL_IS_STUB (decl_or_origin
))
19702 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
19706 if (die
!= NULL
&& die
->die_parent
== NULL
)
19707 add_child_die (context_die
, die
);
19708 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
19709 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
19710 stmt
, context_die
);
19712 gen_decl_die (decl
, origin
, context_die
);
19715 /* Generate all of the decls declared within a given scope and (recursively)
19716 all of its sub-blocks. */
19719 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
19725 /* Ignore NULL blocks. */
19726 if (stmt
== NULL_TREE
)
19729 /* Output the DIEs to represent all of the data objects and typedefs
19730 declared directly within this block but not within any nested
19731 sub-blocks. Also, nested function and tag DIEs have been
19732 generated with a parent of NULL; fix that up now. */
19733 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
19734 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
19735 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
19736 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
19739 /* If we're at -g1, we're not interested in subblocks. */
19740 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19743 /* Output the DIEs to represent all sub-blocks (and the items declared
19744 therein) of this block. */
19745 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
19747 subblocks
= BLOCK_CHAIN (subblocks
))
19748 gen_block_die (subblocks
, context_die
, depth
+ 1);
19751 /* Is this a typedef we can avoid emitting? */
19754 is_redundant_typedef (const_tree decl
)
19756 if (TYPE_DECL_IS_STUB (decl
))
19759 if (DECL_ARTIFICIAL (decl
)
19760 && DECL_CONTEXT (decl
)
19761 && is_tagged_type (DECL_CONTEXT (decl
))
19762 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
19763 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
19764 /* Also ignore the artificial member typedef for the class name. */
19770 /* Return TRUE if TYPE is a typedef that names a type for linkage
19771 purposes. This kind of typedefs is produced by the C++ FE for
19774 typedef struct {...} foo;
19776 In that case, there is no typedef variant type produced for foo.
19777 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
19781 is_naming_typedef_decl (const_tree decl
)
19783 if (decl
== NULL_TREE
19784 || TREE_CODE (decl
) != TYPE_DECL
19785 || !is_tagged_type (TREE_TYPE (decl
))
19786 || DECL_IS_BUILTIN (decl
)
19787 || is_redundant_typedef (decl
)
19788 /* It looks like Ada produces TYPE_DECLs that are very similar
19789 to C++ naming typedefs but that have different
19790 semantics. Let's be specific to c++ for now. */
19794 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
19795 && TYPE_NAME (TREE_TYPE (decl
)) == decl
19796 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
19797 != TYPE_NAME (TREE_TYPE (decl
))));
19800 /* Returns the DIE for a context. */
19802 static inline dw_die_ref
19803 get_context_die (tree context
)
19807 /* Find die that represents this context. */
19808 if (TYPE_P (context
))
19810 context
= TYPE_MAIN_VARIANT (context
);
19811 return strip_naming_typedef (context
, force_type_die (context
));
19814 return force_decl_die (context
);
19816 return comp_unit_die ();
19819 /* Returns the DIE for decl. A DIE will always be returned. */
19822 force_decl_die (tree decl
)
19824 dw_die_ref decl_die
;
19825 unsigned saved_external_flag
;
19826 tree save_fn
= NULL_TREE
;
19827 decl_die
= lookup_decl_die (decl
);
19830 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
19832 decl_die
= lookup_decl_die (decl
);
19836 switch (TREE_CODE (decl
))
19838 case FUNCTION_DECL
:
19839 /* Clear current_function_decl, so that gen_subprogram_die thinks
19840 that this is a declaration. At this point, we just want to force
19841 declaration die. */
19842 save_fn
= current_function_decl
;
19843 current_function_decl
= NULL_TREE
;
19844 gen_subprogram_die (decl
, context_die
);
19845 current_function_decl
= save_fn
;
19849 /* Set external flag to force declaration die. Restore it after
19850 gen_decl_die() call. */
19851 saved_external_flag
= DECL_EXTERNAL (decl
);
19852 DECL_EXTERNAL (decl
) = 1;
19853 gen_decl_die (decl
, NULL
, context_die
);
19854 DECL_EXTERNAL (decl
) = saved_external_flag
;
19857 case NAMESPACE_DECL
:
19858 if (dwarf_version
>= 3 || !dwarf_strict
)
19859 dwarf2out_decl (decl
);
19861 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
19862 decl_die
= comp_unit_die ();
19865 case TRANSLATION_UNIT_DECL
:
19866 decl_die
= comp_unit_die ();
19870 gcc_unreachable ();
19873 /* We should be able to find the DIE now. */
19875 decl_die
= lookup_decl_die (decl
);
19876 gcc_assert (decl_die
);
19882 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
19883 always returned. */
19886 force_type_die (tree type
)
19888 dw_die_ref type_die
;
19890 type_die
= lookup_type_die (type
);
19893 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
19895 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
19896 TYPE_VOLATILE (type
), context_die
);
19897 gcc_assert (type_die
);
19902 /* Force out any required namespaces to be able to output DECL,
19903 and return the new context_die for it, if it's changed. */
19906 setup_namespace_context (tree thing
, dw_die_ref context_die
)
19908 tree context
= (DECL_P (thing
)
19909 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
19910 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
19911 /* Force out the namespace. */
19912 context_die
= force_decl_die (context
);
19914 return context_die
;
19917 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
19918 type) within its namespace, if appropriate.
19920 For compatibility with older debuggers, namespace DIEs only contain
19921 declarations; all definitions are emitted at CU scope. */
19924 declare_in_namespace (tree thing
, dw_die_ref context_die
)
19926 dw_die_ref ns_context
;
19928 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
19929 return context_die
;
19931 /* If this decl is from an inlined function, then don't try to emit it in its
19932 namespace, as we will get confused. It would have already been emitted
19933 when the abstract instance of the inline function was emitted anyways. */
19934 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
19935 return context_die
;
19937 ns_context
= setup_namespace_context (thing
, context_die
);
19939 if (ns_context
!= context_die
)
19943 if (DECL_P (thing
))
19944 gen_decl_die (thing
, NULL
, ns_context
);
19946 gen_type_die (thing
, ns_context
);
19948 return context_die
;
19951 /* Generate a DIE for a namespace or namespace alias. */
19954 gen_namespace_die (tree decl
, dw_die_ref context_die
)
19956 dw_die_ref namespace_die
;
19958 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
19959 they are an alias of. */
19960 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
19962 /* Output a real namespace or module. */
19963 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19964 namespace_die
= new_die (is_fortran ()
19965 ? DW_TAG_module
: DW_TAG_namespace
,
19966 context_die
, decl
);
19967 /* For Fortran modules defined in different CU don't add src coords. */
19968 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
19970 const char *name
= dwarf2_name (decl
, 0);
19972 add_name_attribute (namespace_die
, name
);
19975 add_name_and_src_coords_attributes (namespace_die
, decl
);
19976 if (DECL_EXTERNAL (decl
))
19977 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
19978 equate_decl_number_to_die (decl
, namespace_die
);
19982 /* Output a namespace alias. */
19984 /* Force out the namespace we are an alias of, if necessary. */
19985 dw_die_ref origin_die
19986 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
19988 if (DECL_FILE_SCOPE_P (decl
)
19989 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
19990 context_die
= setup_namespace_context (decl
, comp_unit_die ());
19991 /* Now create the namespace alias DIE. */
19992 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
19993 add_name_and_src_coords_attributes (namespace_die
, decl
);
19994 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
19995 equate_decl_number_to_die (decl
, namespace_die
);
19997 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
19998 if (want_pubnames ())
19999 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20002 /* Generate Dwarf debug information for a decl described by DECL.
20003 The return value is currently only meaningful for PARM_DECLs,
20004 for all other decls it returns NULL. */
20007 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20009 tree decl_or_origin
= decl
? decl
: origin
;
20010 tree class_origin
= NULL
, ultimate_origin
;
20012 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20015 switch (TREE_CODE (decl_or_origin
))
20021 if (!is_fortran () && !is_ada ())
20023 /* The individual enumerators of an enum type get output when we output
20024 the Dwarf representation of the relevant enum type itself. */
20028 /* Emit its type. */
20029 gen_type_die (TREE_TYPE (decl
), context_die
);
20031 /* And its containing namespace. */
20032 context_die
= declare_in_namespace (decl
, context_die
);
20034 gen_const_die (decl
, context_die
);
20037 case FUNCTION_DECL
:
20038 /* Don't output any DIEs to represent mere function declarations,
20039 unless they are class members or explicit block externs. */
20040 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20041 && DECL_FILE_SCOPE_P (decl_or_origin
)
20042 && (current_function_decl
== NULL_TREE
20043 || DECL_ARTIFICIAL (decl_or_origin
)))
20048 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20049 on local redeclarations of global functions. That seems broken. */
20050 if (current_function_decl
!= decl
)
20051 /* This is only a declaration. */;
20054 /* If we're emitting a clone, emit info for the abstract instance. */
20055 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20056 dwarf2out_abstract_function (origin
20057 ? DECL_ORIGIN (origin
)
20058 : DECL_ABSTRACT_ORIGIN (decl
));
20060 /* If we're emitting an out-of-line copy of an inline function,
20061 emit info for the abstract instance and set up to refer to it. */
20062 else if (cgraph_function_possibly_inlined_p (decl
)
20063 && ! DECL_ABSTRACT (decl
)
20064 && ! class_or_namespace_scope_p (context_die
)
20065 /* dwarf2out_abstract_function won't emit a die if this is just
20066 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20067 that case, because that works only if we have a die. */
20068 && DECL_INITIAL (decl
) != NULL_TREE
)
20070 dwarf2out_abstract_function (decl
);
20071 set_decl_origin_self (decl
);
20074 /* Otherwise we're emitting the primary DIE for this decl. */
20075 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20077 /* Before we describe the FUNCTION_DECL itself, make sure that we
20078 have its containing type. */
20080 origin
= decl_class_context (decl
);
20081 if (origin
!= NULL_TREE
)
20082 gen_type_die (origin
, context_die
);
20084 /* And its return type. */
20085 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20087 /* And its virtual context. */
20088 if (DECL_VINDEX (decl
) != NULL_TREE
)
20089 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20091 /* Make sure we have a member DIE for decl. */
20092 if (origin
!= NULL_TREE
)
20093 gen_type_die_for_member (origin
, decl
, context_die
);
20095 /* And its containing namespace. */
20096 context_die
= declare_in_namespace (decl
, context_die
);
20099 /* Now output a DIE to represent the function itself. */
20101 gen_subprogram_die (decl
, context_die
);
20105 /* If we are in terse mode, don't generate any DIEs to represent any
20106 actual typedefs. */
20107 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20110 /* In the special case of a TYPE_DECL node representing the declaration
20111 of some type tag, if the given TYPE_DECL is marked as having been
20112 instantiated from some other (original) TYPE_DECL node (e.g. one which
20113 was generated within the original definition of an inline function) we
20114 used to generate a special (abbreviated) DW_TAG_structure_type,
20115 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20116 should be actually referencing those DIEs, as variable DIEs with that
20117 type would be emitted already in the abstract origin, so it was always
20118 removed during unused type prunning. Don't add anything in this
20120 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20123 if (is_redundant_typedef (decl
))
20124 gen_type_die (TREE_TYPE (decl
), context_die
);
20126 /* Output a DIE to represent the typedef itself. */
20127 gen_typedef_die (decl
, context_die
);
20131 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20132 gen_label_die (decl
, context_die
);
20137 /* If we are in terse mode, don't generate any DIEs to represent any
20138 variable declarations or definitions. */
20139 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20142 /* Output any DIEs that are needed to specify the type of this data
20144 if (decl_by_reference_p (decl_or_origin
))
20145 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20147 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20149 /* And its containing type. */
20150 class_origin
= decl_class_context (decl_or_origin
);
20151 if (class_origin
!= NULL_TREE
)
20152 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20154 /* And its containing namespace. */
20155 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20157 /* Now output the DIE to represent the data object itself. This gets
20158 complicated because of the possibility that the VAR_DECL really
20159 represents an inlined instance of a formal parameter for an inline
20161 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20162 if (ultimate_origin
!= NULL_TREE
20163 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20164 gen_formal_parameter_die (decl
, origin
,
20165 true /* Emit name attribute. */,
20168 gen_variable_die (decl
, origin
, context_die
);
20172 /* Ignore the nameless fields that are used to skip bits but handle C++
20173 anonymous unions and structs. */
20174 if (DECL_NAME (decl
) != NULL_TREE
20175 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20176 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20178 gen_type_die (member_declared_type (decl
), context_die
);
20179 gen_field_die (decl
, context_die
);
20184 if (DECL_BY_REFERENCE (decl_or_origin
))
20185 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20187 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20188 return gen_formal_parameter_die (decl
, origin
,
20189 true /* Emit name attribute. */,
20192 case NAMESPACE_DECL
:
20193 case IMPORTED_DECL
:
20194 if (dwarf_version
>= 3 || !dwarf_strict
)
20195 gen_namespace_die (decl
, context_die
);
20199 /* Probably some frontend-internal decl. Assume we don't care. */
20200 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20207 /* Output debug information for global decl DECL. Called from toplev.c after
20208 compilation proper has finished. */
20211 dwarf2out_global_decl (tree decl
)
20213 /* Output DWARF2 information for file-scope tentative data object
20214 declarations, file-scope (extern) function declarations (which
20215 had no corresponding body) and file-scope tagged type declarations
20216 and definitions which have not yet been forced out. */
20217 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20218 dwarf2out_decl (decl
);
20221 /* Output debug information for type decl DECL. Called from toplev.c
20222 and from language front ends (to record built-in types). */
20224 dwarf2out_type_decl (tree decl
, int local
)
20227 dwarf2out_decl (decl
);
20230 /* Output debug information for imported module or decl DECL.
20231 NAME is non-NULL name in the lexical block if the decl has been renamed.
20232 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20233 that DECL belongs to.
20234 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20236 dwarf2out_imported_module_or_decl_1 (tree decl
,
20238 tree lexical_block
,
20239 dw_die_ref lexical_block_die
)
20241 expanded_location xloc
;
20242 dw_die_ref imported_die
= NULL
;
20243 dw_die_ref at_import_die
;
20245 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20247 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20248 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20252 xloc
= expand_location (input_location
);
20254 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20256 at_import_die
= force_type_die (TREE_TYPE (decl
));
20257 /* For namespace N { typedef void T; } using N::T; base_type_die
20258 returns NULL, but DW_TAG_imported_declaration requires
20259 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20260 if (!at_import_die
)
20262 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20263 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20264 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20265 gcc_assert (at_import_die
);
20270 at_import_die
= lookup_decl_die (decl
);
20271 if (!at_import_die
)
20273 /* If we're trying to avoid duplicate debug info, we may not have
20274 emitted the member decl for this field. Emit it now. */
20275 if (TREE_CODE (decl
) == FIELD_DECL
)
20277 tree type
= DECL_CONTEXT (decl
);
20279 if (TYPE_CONTEXT (type
)
20280 && TYPE_P (TYPE_CONTEXT (type
))
20281 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20282 DINFO_USAGE_DIR_USE
))
20284 gen_type_die_for_member (type
, decl
,
20285 get_context_die (TYPE_CONTEXT (type
)));
20287 at_import_die
= force_decl_die (decl
);
20291 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20293 if (dwarf_version
>= 3 || !dwarf_strict
)
20294 imported_die
= new_die (DW_TAG_imported_module
,
20301 imported_die
= new_die (DW_TAG_imported_declaration
,
20305 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20306 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20308 add_AT_string (imported_die
, DW_AT_name
,
20309 IDENTIFIER_POINTER (name
));
20310 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20313 /* Output debug information for imported module or decl DECL.
20314 NAME is non-NULL name in context if the decl has been renamed.
20315 CHILD is true if decl is one of the renamed decls as part of
20316 importing whole module. */
20319 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20322 /* dw_die_ref at_import_die; */
20323 dw_die_ref scope_die
;
20325 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20330 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20331 We need decl DIE for reference and scope die. First, get DIE for the decl
20334 /* Get the scope die for decl context. Use comp_unit_die for global module
20335 or decl. If die is not found for non globals, force new die. */
20337 && TYPE_P (context
)
20338 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20341 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20344 scope_die
= get_context_die (context
);
20348 gcc_assert (scope_die
->die_child
);
20349 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20350 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20351 scope_die
= scope_die
->die_child
;
20354 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20355 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20359 /* Write the debugging output for DECL. */
20362 dwarf2out_decl (tree decl
)
20364 dw_die_ref context_die
= comp_unit_die ();
20366 switch (TREE_CODE (decl
))
20371 case FUNCTION_DECL
:
20372 /* What we would really like to do here is to filter out all mere
20373 file-scope declarations of file-scope functions which are never
20374 referenced later within this translation unit (and keep all of ones
20375 that *are* referenced later on) but we aren't clairvoyant, so we have
20376 no idea which functions will be referenced in the future (i.e. later
20377 on within the current translation unit). So here we just ignore all
20378 file-scope function declarations which are not also definitions. If
20379 and when the debugger needs to know something about these functions,
20380 it will have to hunt around and find the DWARF information associated
20381 with the definition of the function.
20383 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20384 nodes represent definitions and which ones represent mere
20385 declarations. We have to check DECL_INITIAL instead. That's because
20386 the C front-end supports some weird semantics for "extern inline"
20387 function definitions. These can get inlined within the current
20388 translation unit (and thus, we need to generate Dwarf info for their
20389 abstract instances so that the Dwarf info for the concrete inlined
20390 instances can have something to refer to) but the compiler never
20391 generates any out-of-lines instances of such things (despite the fact
20392 that they *are* definitions).
20394 The important point is that the C front-end marks these "extern
20395 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20396 them anyway. Note that the C++ front-end also plays some similar games
20397 for inline function definitions appearing within include files which
20398 also contain `#pragma interface' pragmas.
20400 If we are called from dwarf2out_abstract_function output a DIE
20401 anyway. We can end up here this way with early inlining and LTO
20402 where the inlined function is output in a different LTRANS unit
20404 if (DECL_INITIAL (decl
) == NULL_TREE
20405 && ! DECL_ABSTRACT (decl
))
20408 /* If we're a nested function, initially use a parent of NULL; if we're
20409 a plain function, this will be fixed up in decls_for_scope. If
20410 we're a method, it will be ignored, since we already have a DIE. */
20411 if (decl_function_context (decl
)
20412 /* But if we're in terse mode, we don't care about scope. */
20413 && debug_info_level
> DINFO_LEVEL_TERSE
)
20414 context_die
= NULL
;
20418 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20419 declaration and if the declaration was never even referenced from
20420 within this entire compilation unit. We suppress these DIEs in
20421 order to save space in the .debug section (by eliminating entries
20422 which are probably useless). Note that we must not suppress
20423 block-local extern declarations (whether used or not) because that
20424 would screw-up the debugger's name lookup mechanism and cause it to
20425 miss things which really ought to be in scope at a given point. */
20426 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20429 /* For local statics lookup proper context die. */
20430 if (TREE_STATIC (decl
)
20431 && DECL_CONTEXT (decl
)
20432 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20433 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20435 /* If we are in terse mode, don't generate any DIEs to represent any
20436 variable declarations or definitions. */
20437 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20442 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20444 if (!is_fortran () && !is_ada ())
20446 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20447 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20450 case NAMESPACE_DECL
:
20451 case IMPORTED_DECL
:
20452 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20454 if (lookup_decl_die (decl
) != NULL
)
20459 /* Don't emit stubs for types unless they are needed by other DIEs. */
20460 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20463 /* Don't bother trying to generate any DIEs to represent any of the
20464 normal built-in types for the language we are compiling. */
20465 if (DECL_IS_BUILTIN (decl
))
20468 /* If we are in terse mode, don't generate any DIEs for types. */
20469 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20472 /* If we're a function-scope tag, initially use a parent of NULL;
20473 this will be fixed up in decls_for_scope. */
20474 if (decl_function_context (decl
))
20475 context_die
= NULL
;
20483 gen_decl_die (decl
, NULL
, context_die
);
20486 /* Write the debugging output for DECL. */
20489 dwarf2out_function_decl (tree decl
)
20491 dwarf2out_decl (decl
);
20492 call_arg_locations
= NULL
;
20493 call_arg_loc_last
= NULL
;
20494 call_site_count
= -1;
20495 tail_call_site_count
= -1;
20496 block_map
.release ();
20497 htab_empty (decl_loc_table
);
20498 htab_empty (cached_dw_loc_list_table
);
20501 /* Output a marker (i.e. a label) for the beginning of the generated code for
20502 a lexical block. */
20505 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
20506 unsigned int blocknum
)
20508 switch_to_section (current_function_section ());
20509 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
20512 /* Output a marker (i.e. a label) for the end of the generated code for a
20516 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
20518 switch_to_section (current_function_section ());
20519 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
20522 /* Returns nonzero if it is appropriate not to emit any debugging
20523 information for BLOCK, because it doesn't contain any instructions.
20525 Don't allow this for blocks with nested functions or local classes
20526 as we would end up with orphans, and in the presence of scheduling
20527 we may end up calling them anyway. */
20530 dwarf2out_ignore_block (const_tree block
)
20535 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
20536 if (TREE_CODE (decl
) == FUNCTION_DECL
20537 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20539 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
20541 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
20542 if (TREE_CODE (decl
) == FUNCTION_DECL
20543 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
20550 /* Hash table routines for file_hash. */
20553 file_table_eq (const void *p1_p
, const void *p2_p
)
20555 const struct dwarf_file_data
*const p1
=
20556 (const struct dwarf_file_data
*) p1_p
;
20557 const char *const p2
= (const char *) p2_p
;
20558 return filename_cmp (p1
->filename
, p2
) == 0;
20562 file_table_hash (const void *p_p
)
20564 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
20565 return htab_hash_string (p
->filename
);
20568 /* Lookup FILE_NAME (in the list of filenames that we know about here in
20569 dwarf2out.c) and return its "index". The index of each (known) filename is
20570 just a unique number which is associated with only that one filename. We
20571 need such numbers for the sake of generating labels (in the .debug_sfnames
20572 section) and references to those files numbers (in the .debug_srcinfo
20573 and.debug_macinfo sections). If the filename given as an argument is not
20574 found in our current list, add it to the list and assign it the next
20575 available unique index number. In order to speed up searches, we remember
20576 the index of the filename was looked up last. This handles the majority of
20579 static struct dwarf_file_data
*
20580 lookup_filename (const char *file_name
)
20583 struct dwarf_file_data
* created
;
20585 /* Check to see if the file name that was searched on the previous
20586 call matches this file name. If so, return the index. */
20587 if (file_table_last_lookup
20588 && (file_name
== file_table_last_lookup
->filename
20589 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
20590 return file_table_last_lookup
;
20592 /* Didn't match the previous lookup, search the table. */
20593 slot
= htab_find_slot_with_hash (file_table
, file_name
,
20594 htab_hash_string (file_name
), INSERT
);
20596 return (struct dwarf_file_data
*) *slot
;
20598 created
= ggc_alloc_dwarf_file_data ();
20599 created
->filename
= file_name
;
20600 created
->emitted_number
= 0;
20605 /* If the assembler will construct the file table, then translate the compiler
20606 internal file table number into the assembler file table number, and emit
20607 a .file directive if we haven't already emitted one yet. The file table
20608 numbers are different because we prune debug info for unused variables and
20609 types, which may include filenames. */
20612 maybe_emit_file (struct dwarf_file_data
* fd
)
20614 if (! fd
->emitted_number
)
20616 if (last_emitted_file
)
20617 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
20619 fd
->emitted_number
= 1;
20620 last_emitted_file
= fd
;
20622 if (DWARF2_ASM_LINE_DEBUG_INFO
)
20624 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
20625 output_quoted_string (asm_out_file
,
20626 remap_debug_filename (fd
->filename
));
20627 fputc ('\n', asm_out_file
);
20631 return fd
->emitted_number
;
20634 /* Schedule generation of a DW_AT_const_value attribute to DIE.
20635 That generation should happen after function debug info has been
20636 generated. The value of the attribute is the constant value of ARG. */
20639 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
20641 die_arg_entry entry
;
20646 if (!tmpl_value_parm_die_table
)
20647 vec_alloc (tmpl_value_parm_die_table
, 32);
20651 vec_safe_push (tmpl_value_parm_die_table
, entry
);
20654 /* Return TRUE if T is an instance of generic type, FALSE
20658 generic_type_p (tree t
)
20660 if (t
== NULL_TREE
|| !TYPE_P (t
))
20662 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
20665 /* Schedule the generation of the generic parameter dies for the
20666 instance of generic type T. The proper generation itself is later
20667 done by gen_scheduled_generic_parms_dies. */
20670 schedule_generic_params_dies_gen (tree t
)
20672 if (!generic_type_p (t
))
20675 if (!generic_type_instances
)
20676 vec_alloc (generic_type_instances
, 256);
20678 vec_safe_push (generic_type_instances
, t
);
20681 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
20682 by append_entry_to_tmpl_value_parm_die_table. This function must
20683 be called after function DIEs have been generated. */
20686 gen_remaining_tmpl_value_param_die_attribute (void)
20688 if (tmpl_value_parm_die_table
)
20693 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
20694 tree_add_const_value_attribute (e
->die
, e
->arg
);
20698 /* Generate generic parameters DIEs for instances of generic types
20699 that have been previously scheduled by
20700 schedule_generic_params_dies_gen. This function must be called
20701 after all the types of the CU have been laid out. */
20704 gen_scheduled_generic_parms_dies (void)
20709 if (!generic_type_instances
)
20712 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
20713 if (COMPLETE_TYPE_P (t
))
20714 gen_generic_params_dies (t
);
20718 /* Replace DW_AT_name for the decl with name. */
20721 dwarf2out_set_name (tree decl
, tree name
)
20727 die
= TYPE_SYMTAB_DIE (decl
);
20731 dname
= dwarf2_name (name
, 0);
20735 attr
= get_AT (die
, DW_AT_name
);
20738 struct indirect_string_node
*node
;
20740 node
= find_AT_string (dname
);
20741 /* replace the string. */
20742 attr
->dw_attr_val
.v
.val_str
= node
;
20746 add_name_attribute (die
, dname
);
20749 /* True if before or during processing of the first function being emitted. */
20750 static bool in_first_function_p
= true;
20751 /* True if loc_note during dwarf2out_var_location call might still be
20752 before first real instruction at address equal to .Ltext0. */
20753 static bool maybe_at_text_label_p
= true;
20754 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
20755 static unsigned int first_loclabel_num_not_at_text_label
;
20757 /* Called by the final INSN scan whenever we see a var location. We
20758 use it to drop labels in the right places, and throw the location in
20759 our lookup table. */
20762 dwarf2out_var_location (rtx loc_note
)
20764 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
20765 struct var_loc_node
*newloc
;
20766 rtx next_real
, next_note
;
20767 static const char *last_label
;
20768 static const char *last_postcall_label
;
20769 static bool last_in_cold_section_p
;
20770 static rtx expected_next_loc_note
;
20774 if (!NOTE_P (loc_note
))
20776 if (CALL_P (loc_note
))
20779 if (SIBLING_CALL_P (loc_note
))
20780 tail_call_site_count
++;
20785 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
20786 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
20789 /* Optimize processing a large consecutive sequence of location
20790 notes so we don't spend too much time in next_real_insn. If the
20791 next insn is another location note, remember the next_real_insn
20792 calculation for next time. */
20793 next_real
= cached_next_real_insn
;
20796 if (expected_next_loc_note
!= loc_note
)
20797 next_real
= NULL_RTX
;
20800 next_note
= NEXT_INSN (loc_note
);
20802 || INSN_DELETED_P (next_note
)
20803 || ! NOTE_P (next_note
)
20804 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
20805 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
20806 next_note
= NULL_RTX
;
20809 next_real
= next_real_insn (loc_note
);
20813 expected_next_loc_note
= next_note
;
20814 cached_next_real_insn
= next_real
;
20817 cached_next_real_insn
= NULL_RTX
;
20819 /* If there are no instructions which would be affected by this note,
20820 don't do anything. */
20822 && next_real
== NULL_RTX
20823 && !NOTE_DURING_CALL_P (loc_note
))
20826 if (next_real
== NULL_RTX
)
20827 next_real
= get_last_insn ();
20829 /* If there were any real insns between note we processed last time
20830 and this note (or if it is the first note), clear
20831 last_{,postcall_}label so that they are not reused this time. */
20832 if (last_var_location_insn
== NULL_RTX
20833 || last_var_location_insn
!= next_real
20834 || last_in_cold_section_p
!= in_cold_section_p
)
20837 last_postcall_label
= NULL
;
20842 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
20843 newloc
= add_var_loc_to_decl (decl
, loc_note
,
20844 NOTE_DURING_CALL_P (loc_note
)
20845 ? last_postcall_label
: last_label
);
20846 if (newloc
== NULL
)
20855 /* If there were no real insns between note we processed last time
20856 and this note, use the label we emitted last time. Otherwise
20857 create a new label and emit it. */
20858 if (last_label
== NULL
)
20860 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
20861 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
20863 last_label
= ggc_strdup (loclabel
);
20864 /* See if loclabel might be equal to .Ltext0. If yes,
20865 bump first_loclabel_num_not_at_text_label. */
20866 if (!have_multiple_function_sections
20867 && in_first_function_p
20868 && maybe_at_text_label_p
)
20870 static rtx last_start
;
20872 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
20873 if (insn
== last_start
)
20875 else if (!NONDEBUG_INSN_P (insn
))
20879 rtx body
= PATTERN (insn
);
20880 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
20882 /* Inline asm could occupy zero bytes. */
20883 else if (GET_CODE (body
) == ASM_INPUT
20884 || asm_noperands (body
) >= 0)
20886 #ifdef HAVE_attr_length
20887 else if (get_attr_min_length (insn
) == 0)
20892 /* Assume insn has non-zero length. */
20893 maybe_at_text_label_p
= false;
20897 if (maybe_at_text_label_p
)
20899 last_start
= loc_note
;
20900 first_loclabel_num_not_at_text_label
= loclabel_num
;
20907 struct call_arg_loc_node
*ca_loc
20908 = ggc_alloc_cleared_call_arg_loc_node ();
20909 rtx prev
= prev_real_insn (loc_note
), x
;
20910 ca_loc
->call_arg_loc_note
= loc_note
;
20911 ca_loc
->next
= NULL
;
20912 ca_loc
->label
= last_label
;
20915 || (NONJUMP_INSN_P (prev
)
20916 && GET_CODE (PATTERN (prev
)) == SEQUENCE
20917 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
20918 if (!CALL_P (prev
))
20919 prev
= XVECEXP (PATTERN (prev
), 0, 0);
20920 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
20921 x
= get_call_rtx_from (PATTERN (prev
));
20924 x
= XEXP (XEXP (x
, 0), 0);
20925 if (GET_CODE (x
) == SYMBOL_REF
20926 && SYMBOL_REF_DECL (x
)
20927 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
20928 ca_loc
->symbol_ref
= x
;
20930 ca_loc
->block
= insn_scope (prev
);
20931 if (call_arg_locations
)
20932 call_arg_loc_last
->next
= ca_loc
;
20934 call_arg_locations
= ca_loc
;
20935 call_arg_loc_last
= ca_loc
;
20937 else if (!NOTE_DURING_CALL_P (loc_note
))
20938 newloc
->label
= last_label
;
20941 if (!last_postcall_label
)
20943 sprintf (loclabel
, "%s-1", last_label
);
20944 last_postcall_label
= ggc_strdup (loclabel
);
20946 newloc
->label
= last_postcall_label
;
20949 last_var_location_insn
= next_real
;
20950 last_in_cold_section_p
= in_cold_section_p
;
20953 /* Note in one location list that text section has changed. */
20956 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
20958 var_loc_list
*list
= (var_loc_list
*) *slot
;
20960 list
->last_before_switch
20961 = list
->last
->next
? list
->last
->next
: list
->last
;
20965 /* Note in all location lists that text section has changed. */
20968 var_location_switch_text_section (void)
20970 if (decl_loc_table
== NULL
)
20973 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
20976 /* Create a new line number table. */
20978 static dw_line_info_table
*
20979 new_line_info_table (void)
20981 dw_line_info_table
*table
;
20983 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
20984 table
->file_num
= 1;
20985 table
->line_num
= 1;
20986 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
20991 /* Lookup the "current" table into which we emit line info, so
20992 that we don't have to do it for every source line. */
20995 set_cur_line_info_table (section
*sec
)
20997 dw_line_info_table
*table
;
20999 if (sec
== text_section
)
21000 table
= text_section_line_info
;
21001 else if (sec
== cold_text_section
)
21003 table
= cold_text_section_line_info
;
21006 cold_text_section_line_info
= table
= new_line_info_table ();
21007 table
->end_label
= cold_end_label
;
21012 const char *end_label
;
21014 if (flag_reorder_blocks_and_partition
)
21016 if (in_cold_section_p
)
21017 end_label
= crtl
->subsections
.cold_section_end_label
;
21019 end_label
= crtl
->subsections
.hot_section_end_label
;
21023 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21024 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21025 current_function_funcdef_no
);
21026 end_label
= ggc_strdup (label
);
21029 table
= new_line_info_table ();
21030 table
->end_label
= end_label
;
21032 vec_safe_push (separate_line_info
, table
);
21035 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21036 table
->is_stmt
= (cur_line_info_table
21037 ? cur_line_info_table
->is_stmt
21038 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21039 cur_line_info_table
= table
;
21043 /* We need to reset the locations at the beginning of each
21044 function. We can't do this in the end_function hook, because the
21045 declarations that use the locations won't have been output when
21046 that hook is called. Also compute have_multiple_function_sections here. */
21049 dwarf2out_begin_function (tree fun
)
21051 section
*sec
= function_section (fun
);
21053 if (sec
!= text_section
)
21054 have_multiple_function_sections
= true;
21056 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21058 gcc_assert (current_function_decl
== fun
);
21059 cold_text_section
= unlikely_text_section ();
21060 switch_to_section (cold_text_section
);
21061 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21062 switch_to_section (sec
);
21065 dwarf2out_note_section_used ();
21066 call_site_count
= 0;
21067 tail_call_site_count
= 0;
21069 set_cur_line_info_table (sec
);
21072 /* Helper function of dwarf2out_end_function, called only after emitting
21073 the very first function into assembly. Check if some .debug_loc range
21074 might end with a .LVL* label that could be equal to .Ltext0.
21075 In that case we must force using absolute addresses in .debug_loc ranges,
21076 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21077 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21079 Set have_multiple_function_sections to true in that case and
21080 terminate htab traversal. */
21083 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21085 var_loc_list
*entry
;
21086 struct var_loc_node
*node
;
21088 entry
= (var_loc_list
*) *slot
;
21089 node
= entry
->first
;
21090 if (node
&& node
->next
&& node
->next
->label
)
21093 const char *label
= node
->next
->label
;
21094 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21096 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21098 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21099 if (strcmp (label
, loclabel
) == 0)
21101 have_multiple_function_sections
= true;
21109 /* Hook called after emitting a function into assembly.
21110 This does something only for the very first function emitted. */
21113 dwarf2out_end_function (unsigned int)
21115 if (in_first_function_p
21116 && !have_multiple_function_sections
21117 && first_loclabel_num_not_at_text_label
21119 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21121 in_first_function_p
= false;
21122 maybe_at_text_label_p
= false;
21125 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21128 push_dw_line_info_entry (dw_line_info_table
*table
,
21129 enum dw_line_info_opcode opcode
, unsigned int val
)
21131 dw_line_info_entry e
;
21134 vec_safe_push (table
->entries
, e
);
21137 /* Output a label to mark the beginning of a source code line entry
21138 and record information relating to this source line, in
21139 'line_info_table' for later output of the .debug_line section. */
21140 /* ??? The discriminator parameter ought to be unsigned. */
21143 dwarf2out_source_line (unsigned int line
, const char *filename
,
21144 int discriminator
, bool is_stmt
)
21146 unsigned int file_num
;
21147 dw_line_info_table
*table
;
21149 if (debug_info_level
< DINFO_LEVEL_NORMAL
|| line
== 0)
21152 /* The discriminator column was added in dwarf4. Simplify the below
21153 by simply removing it if we're not supposed to output it. */
21154 if (dwarf_version
< 4 && dwarf_strict
)
21157 table
= cur_line_info_table
;
21158 file_num
= maybe_emit_file (lookup_filename (filename
));
21160 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21161 the debugger has used the second (possibly duplicate) line number
21162 at the beginning of the function to mark the end of the prologue.
21163 We could eliminate any other duplicates within the function. For
21164 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21165 that second line number entry. */
21166 /* Recall that this end-of-prologue indication is *not* the same thing
21167 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21168 to which the hook corresponds, follows the last insn that was
21169 emitted by gen_prologue. What we need is to precede the first insn
21170 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21171 insn that corresponds to something the user wrote. These may be
21172 very different locations once scheduling is enabled. */
21174 if (0 && file_num
== table
->file_num
21175 && line
== table
->line_num
21176 && discriminator
== table
->discrim_num
21177 && is_stmt
== table
->is_stmt
)
21180 switch_to_section (current_function_section ());
21182 /* If requested, emit something human-readable. */
21183 if (flag_debug_asm
)
21184 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21186 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21188 /* Emit the .loc directive understood by GNU as. */
21189 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21190 file_num, line, is_stmt, discriminator */
21191 fputs ("\t.loc ", asm_out_file
);
21192 fprint_ul (asm_out_file
, file_num
);
21193 putc (' ', asm_out_file
);
21194 fprint_ul (asm_out_file
, line
);
21195 putc (' ', asm_out_file
);
21196 putc ('0', asm_out_file
);
21198 if (is_stmt
!= table
->is_stmt
)
21200 fputs (" is_stmt ", asm_out_file
);
21201 putc (is_stmt
? '1' : '0', asm_out_file
);
21203 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21205 gcc_assert (discriminator
> 0);
21206 fputs (" discriminator ", asm_out_file
);
21207 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21209 putc ('\n', asm_out_file
);
21213 unsigned int label_num
= ++line_info_label_num
;
21215 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21217 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21218 if (file_num
!= table
->file_num
)
21219 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21220 if (discriminator
!= table
->discrim_num
)
21221 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21222 if (is_stmt
!= table
->is_stmt
)
21223 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21224 push_dw_line_info_entry (table
, LI_set_line
, line
);
21227 table
->file_num
= file_num
;
21228 table
->line_num
= line
;
21229 table
->discrim_num
= discriminator
;
21230 table
->is_stmt
= is_stmt
;
21231 table
->in_use
= true;
21234 /* Record the beginning of a new source file. */
21237 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21239 if (flag_eliminate_dwarf2_dups
)
21241 /* Record the beginning of the file for break_out_includes. */
21242 dw_die_ref bincl_die
;
21244 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21245 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21248 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21251 e
.code
= DW_MACINFO_start_file
;
21253 e
.info
= ggc_strdup (filename
);
21254 vec_safe_push (macinfo_table
, e
);
21258 /* Record the end of a source file. */
21261 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21263 if (flag_eliminate_dwarf2_dups
)
21264 /* Record the end of the file for break_out_includes. */
21265 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21267 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21270 e
.code
= DW_MACINFO_end_file
;
21273 vec_safe_push (macinfo_table
, e
);
21277 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21278 the tail part of the directive line, i.e. the part which is past the
21279 initial whitespace, #, whitespace, directive-name, whitespace part. */
21282 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21283 const char *buffer ATTRIBUTE_UNUSED
)
21285 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21288 /* Insert a dummy first entry to be able to optimize the whole
21289 predefined macro block using DW_MACRO_GNU_transparent_include. */
21290 if (macinfo_table
->is_empty () && lineno
<= 1)
21295 vec_safe_push (macinfo_table
, e
);
21297 e
.code
= DW_MACINFO_define
;
21299 e
.info
= ggc_strdup (buffer
);
21300 vec_safe_push (macinfo_table
, e
);
21304 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21305 the tail part of the directive line, i.e. the part which is past the
21306 initial whitespace, #, whitespace, directive-name, whitespace part. */
21309 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21310 const char *buffer ATTRIBUTE_UNUSED
)
21312 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21315 /* Insert a dummy first entry to be able to optimize the whole
21316 predefined macro block using DW_MACRO_GNU_transparent_include. */
21317 if (macinfo_table
->is_empty () && lineno
<= 1)
21322 vec_safe_push (macinfo_table
, e
);
21324 e
.code
= DW_MACINFO_undef
;
21326 e
.info
= ggc_strdup (buffer
);
21327 vec_safe_push (macinfo_table
, e
);
21331 /* Helpers to manipulate hash table of CUs. */
21333 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
21335 typedef macinfo_entry value_type
;
21336 typedef macinfo_entry compare_type
;
21337 static inline hashval_t
hash (const value_type
*);
21338 static inline bool equal (const value_type
*, const compare_type
*);
21342 macinfo_entry_hasher::hash (const value_type
*entry
)
21344 return htab_hash_string (entry
->info
);
21348 macinfo_entry_hasher::equal (const value_type
*entry1
,
21349 const compare_type
*entry2
)
21351 return !strcmp (entry1
->info
, entry2
->info
);
21354 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
21356 /* Output a single .debug_macinfo entry. */
21359 output_macinfo_op (macinfo_entry
*ref
)
21363 struct indirect_string_node
*node
;
21364 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21365 struct dwarf_file_data
*fd
;
21369 case DW_MACINFO_start_file
:
21370 fd
= lookup_filename (ref
->info
);
21371 file_num
= maybe_emit_file (fd
);
21372 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21373 dw2_asm_output_data_uleb128 (ref
->lineno
,
21374 "Included from line number %lu",
21375 (unsigned long) ref
->lineno
);
21376 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21378 case DW_MACINFO_end_file
:
21379 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21381 case DW_MACINFO_define
:
21382 case DW_MACINFO_undef
:
21383 len
= strlen (ref
->info
) + 1;
21385 && len
> DWARF_OFFSET_SIZE
21386 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21387 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21389 ref
->code
= ref
->code
== DW_MACINFO_define
21390 ? DW_MACRO_GNU_define_indirect
21391 : DW_MACRO_GNU_undef_indirect
;
21392 output_macinfo_op (ref
);
21395 dw2_asm_output_data (1, ref
->code
,
21396 ref
->code
== DW_MACINFO_define
21397 ? "Define macro" : "Undefine macro");
21398 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21399 (unsigned long) ref
->lineno
);
21400 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21402 case DW_MACRO_GNU_define_indirect
:
21403 case DW_MACRO_GNU_undef_indirect
:
21404 node
= find_AT_string (ref
->info
);
21406 && ((node
->form
== DW_FORM_strp
)
21407 || (node
->form
== DW_FORM_GNU_str_index
)));
21408 dw2_asm_output_data (1, ref
->code
,
21409 ref
->code
== DW_MACRO_GNU_define_indirect
21410 ? "Define macro indirect"
21411 : "Undefine macro indirect");
21412 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21413 (unsigned long) ref
->lineno
);
21414 if (node
->form
== DW_FORM_strp
)
21415 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21416 debug_str_section
, "The macro: \"%s\"",
21419 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21422 case DW_MACRO_GNU_transparent_include
:
21423 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21424 ASM_GENERATE_INTERNAL_LABEL (label
,
21425 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21426 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21429 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21430 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21435 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21436 other compilation unit .debug_macinfo sections. IDX is the first
21437 index of a define/undef, return the number of ops that should be
21438 emitted in a comdat .debug_macinfo section and emit
21439 a DW_MACRO_GNU_transparent_include entry referencing it.
21440 If the define/undef entry should be emitted normally, return 0. */
21443 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21444 macinfo_hash_type
*macinfo_htab
)
21446 macinfo_entry
*first
, *second
, *cur
, *inc
;
21447 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21448 unsigned char checksum
[16];
21449 struct md5_ctx ctx
;
21450 char *grp_name
, *tail
;
21452 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21453 macinfo_entry
**slot
;
21455 first
= &(*macinfo_table
)[idx
];
21456 second
= &(*macinfo_table
)[idx
+ 1];
21458 /* Optimize only if there are at least two consecutive define/undef ops,
21459 and either all of them are before first DW_MACINFO_start_file
21460 with lineno {0,1} (i.e. predefined macro block), or all of them are
21461 in some included header file. */
21462 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21464 if (vec_safe_is_empty (files
))
21466 if (first
->lineno
> 1 || second
->lineno
> 1)
21469 else if (first
->lineno
== 0)
21472 /* Find the last define/undef entry that can be grouped together
21473 with first and at the same time compute md5 checksum of their
21474 codes, linenumbers and strings. */
21475 md5_init_ctx (&ctx
);
21476 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21477 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21479 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21483 unsigned char code
= cur
->code
;
21484 md5_process_bytes (&code
, 1, &ctx
);
21485 checksum_uleb128 (cur
->lineno
, &ctx
);
21486 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21488 md5_finish_ctx (&ctx
, checksum
);
21491 /* From the containing include filename (if any) pick up just
21492 usable characters from its basename. */
21493 if (vec_safe_is_empty (files
))
21496 base
= lbasename (files
->last ().info
);
21497 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
21498 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21499 encoded_filename_len
++;
21500 /* Count . at the end. */
21501 if (encoded_filename_len
)
21502 encoded_filename_len
++;
21504 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
21505 linebuf_len
= strlen (linebuf
);
21507 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
21508 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
21510 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
21511 tail
= grp_name
+ 4;
21512 if (encoded_filename_len
)
21514 for (i
= 0; base
[i
]; i
++)
21515 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
21519 memcpy (tail
, linebuf
, linebuf_len
);
21520 tail
+= linebuf_len
;
21522 for (i
= 0; i
< 16; i
++)
21523 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
21525 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
21526 in the empty vector entry before the first define/undef. */
21527 inc
= &(*macinfo_table
)[idx
- 1];
21528 inc
->code
= DW_MACRO_GNU_transparent_include
;
21530 inc
->info
= ggc_strdup (grp_name
);
21531 if (!macinfo_htab
->is_created ())
21532 macinfo_htab
->create (10);
21533 /* Avoid emitting duplicates. */
21534 slot
= macinfo_htab
->find_slot (inc
, INSERT
);
21539 /* If such an entry has been used before, just emit
21540 a DW_MACRO_GNU_transparent_include op. */
21542 output_macinfo_op (inc
);
21543 /* And clear all macinfo_entry in the range to avoid emitting them
21544 in the second pass. */
21545 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
21554 inc
->lineno
= macinfo_htab
->elements ();
21555 output_macinfo_op (inc
);
21560 /* Save any strings needed by the macinfo table in the debug str
21561 table. All strings must be collected into the table by the time
21562 index_string is called. */
21565 save_macinfo_strings (void)
21569 macinfo_entry
*ref
;
21571 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
21575 /* Match the logic in output_macinfo_op to decide on
21576 indirect strings. */
21577 case DW_MACINFO_define
:
21578 case DW_MACINFO_undef
:
21579 len
= strlen (ref
->info
) + 1;
21581 && len
> DWARF_OFFSET_SIZE
21582 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21583 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21584 set_indirect_string (find_AT_string (ref
->info
));
21586 case DW_MACRO_GNU_define_indirect
:
21587 case DW_MACRO_GNU_undef_indirect
:
21588 set_indirect_string (find_AT_string (ref
->info
));
21596 /* Output macinfo section(s). */
21599 output_macinfo (void)
21602 unsigned long length
= vec_safe_length (macinfo_table
);
21603 macinfo_entry
*ref
;
21604 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
21605 macinfo_hash_type macinfo_htab
;
21610 /* output_macinfo* uses these interchangeably. */
21611 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
21612 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
21613 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
21614 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
21616 /* For .debug_macro emit the section header. */
21619 dw2_asm_output_data (2, 4, "DWARF macro version number");
21620 if (DWARF_OFFSET_SIZE
== 8)
21621 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
21623 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
21624 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
21625 (!dwarf_split_debug_info
? debug_line_section_label
21626 : debug_skeleton_line_section_label
),
21627 debug_line_section
, NULL
);
21630 /* In the first loop, it emits the primary .debug_macinfo section
21631 and after each emitted op the macinfo_entry is cleared.
21632 If a longer range of define/undef ops can be optimized using
21633 DW_MACRO_GNU_transparent_include, the
21634 DW_MACRO_GNU_transparent_include op is emitted and kept in
21635 the vector before the first define/undef in the range and the
21636 whole range of define/undef ops is not emitted and kept. */
21637 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21641 case DW_MACINFO_start_file
:
21642 vec_safe_push (files
, *ref
);
21644 case DW_MACINFO_end_file
:
21645 if (!vec_safe_is_empty (files
))
21648 case DW_MACINFO_define
:
21649 case DW_MACINFO_undef
:
21651 && HAVE_COMDAT_GROUP
21652 && vec_safe_length (files
) != 1
21655 && (*macinfo_table
)[i
- 1].code
== 0)
21657 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
21666 /* A dummy entry may be inserted at the beginning to be able
21667 to optimize the whole block of predefined macros. */
21673 output_macinfo_op (ref
);
21678 if (!macinfo_htab
.is_created ())
21681 macinfo_htab
.dispose ();
21683 /* If any DW_MACRO_GNU_transparent_include were used, on those
21684 DW_MACRO_GNU_transparent_include entries terminate the
21685 current chain and switch to a new comdat .debug_macinfo
21686 section and emit the define/undef entries within it. */
21687 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
21692 case DW_MACRO_GNU_transparent_include
:
21694 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21695 tree comdat_key
= get_identifier (ref
->info
);
21696 /* Terminate the previous .debug_macinfo section. */
21697 dw2_asm_output_data (1, 0, "End compilation unit");
21698 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
21700 | SECTION_LINKONCE
,
21702 ASM_GENERATE_INTERNAL_LABEL (label
,
21703 DEBUG_MACRO_SECTION_LABEL
,
21705 ASM_OUTPUT_LABEL (asm_out_file
, label
);
21708 dw2_asm_output_data (2, 4, "DWARF macro version number");
21709 if (DWARF_OFFSET_SIZE
== 8)
21710 dw2_asm_output_data (1, 1, "Flags: 64-bit");
21712 dw2_asm_output_data (1, 0, "Flags: 32-bit");
21715 case DW_MACINFO_define
:
21716 case DW_MACINFO_undef
:
21717 output_macinfo_op (ref
);
21722 gcc_unreachable ();
21726 /* Set up for Dwarf output at the start of compilation. */
21729 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
21731 /* Allocate the file_table. */
21732 file_table
= htab_create_ggc (50, file_table_hash
,
21733 file_table_eq
, NULL
);
21735 /* Allocate the decl_die_table. */
21736 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
21737 decl_die_table_eq
, NULL
);
21739 /* Allocate the decl_loc_table. */
21740 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
21741 decl_loc_table_eq
, NULL
);
21743 /* Allocate the cached_dw_loc_list_table. */
21744 cached_dw_loc_list_table
21745 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
21746 cached_dw_loc_list_table_eq
, NULL
);
21748 /* Allocate the initial hunk of the decl_scope_table. */
21749 vec_alloc (decl_scope_table
, 256);
21751 /* Allocate the initial hunk of the abbrev_die_table. */
21752 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
21753 (ABBREV_DIE_TABLE_INCREMENT
);
21754 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
21755 /* Zero-th entry is allocated, but unused. */
21756 abbrev_die_table_in_use
= 1;
21758 /* Allocate the pubtypes and pubnames vectors. */
21759 vec_alloc (pubname_table
, 32);
21760 vec_alloc (pubtype_table
, 32);
21762 vec_alloc (incomplete_types
, 64);
21764 vec_alloc (used_rtx_array
, 32);
21766 if (!dwarf_split_debug_info
)
21768 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
21769 SECTION_DEBUG
, NULL
);
21770 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21771 SECTION_DEBUG
, NULL
);
21772 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
21773 SECTION_DEBUG
, NULL
);
21777 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
21778 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21779 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
21780 SECTION_DEBUG
| SECTION_EXCLUDE
,
21782 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
21783 SECTION_DEBUG
, NULL
);
21784 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
21785 SECTION_DEBUG
, NULL
);
21786 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
21787 SECTION_DEBUG
, NULL
);
21788 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
21789 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
21791 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
21792 the main .o, but the skeleton_line goes into the split off dwo. */
21793 debug_skeleton_line_section
21794 = get_section (DEBUG_DWO_LINE_SECTION
,
21795 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21796 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
21797 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
21798 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
21799 SECTION_DEBUG
| SECTION_EXCLUDE
,
21801 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
21802 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
21803 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
21804 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
21805 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
21806 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
21808 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
21809 SECTION_DEBUG
, NULL
);
21810 debug_macinfo_section
= get_section (dwarf_strict
21811 ? DEBUG_MACINFO_SECTION
21812 : DEBUG_MACRO_SECTION
,
21813 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
21814 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
21815 SECTION_DEBUG
, NULL
);
21816 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
21817 SECTION_DEBUG
, NULL
);
21818 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
21819 SECTION_DEBUG
, NULL
);
21820 debug_str_section
= get_section (DEBUG_STR_SECTION
,
21821 DEBUG_STR_SECTION_FLAGS
, NULL
);
21822 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
21823 SECTION_DEBUG
, NULL
);
21824 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
21825 SECTION_DEBUG
, NULL
);
21827 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
21828 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
21829 DEBUG_ABBREV_SECTION_LABEL
, 0);
21830 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
21831 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
21832 COLD_TEXT_SECTION_LABEL
, 0);
21833 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
21835 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
21836 DEBUG_INFO_SECTION_LABEL
, 0);
21837 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
21838 DEBUG_LINE_SECTION_LABEL
, 0);
21839 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
21840 DEBUG_RANGES_SECTION_LABEL
, 0);
21841 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
21842 DEBUG_ADDR_SECTION_LABEL
, 0);
21843 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
21845 ? DEBUG_MACINFO_SECTION_LABEL
21846 : DEBUG_MACRO_SECTION_LABEL
, 0);
21847 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
21849 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21850 vec_alloc (macinfo_table
, 64);
21852 switch_to_section (text_section
);
21853 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
21855 /* Make sure the line number table for .text always exists. */
21856 text_section_line_info
= new_line_info_table ();
21857 text_section_line_info
->end_label
= text_end_label
;
21860 /* Called before compile () starts outputtting functions, variables
21861 and toplevel asms into assembly. */
21864 dwarf2out_assembly_start (void)
21866 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
21867 && dwarf2out_do_cfi_asm ()
21868 && (!(flag_unwind_tables
|| flag_exceptions
)
21869 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
21870 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
21873 /* A helper function for dwarf2out_finish called through
21874 htab_traverse. Assign a string its index. All strings must be
21875 collected into the table by the time index_string is called,
21876 because the indexing code relies on htab_traverse to traverse nodes
21877 in the same order for each run. */
21880 index_string (void **h
, void *v
)
21882 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21883 unsigned int *index
= (unsigned int *) v
;
21885 find_string_form (node
);
21886 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21888 gcc_assert(node
->index
== NO_INDEX_ASSIGNED
);
21889 node
->index
= *index
;
21895 /* A helper function for output_indirect_strings called through
21896 htab_traverse. Output the offset to a string and update the
21900 output_index_string_offset (void **h
, void *v
)
21902 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21903 unsigned int *offset
= (unsigned int *) v
;
21905 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21907 /* Assert that this node has been assigned an index. */
21908 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
21909 && node
->index
!= NOT_INDEXED
);
21910 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
21911 "indexed string 0x%x: %s", node
->index
, node
->str
);
21912 *offset
+= strlen (node
->str
) + 1;
21917 /* A helper function for dwarf2out_finish called through
21918 htab_traverse. Output the indexed string. */
21921 output_index_string (void **h
, void *v
)
21923 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21924 unsigned int *cur_idx
= (unsigned int *) v
;
21926 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
21928 /* Assert that the strings are output in the same order as their
21929 indexes were assigned. */
21930 gcc_assert (*cur_idx
== node
->index
);
21931 assemble_string (node
->str
, strlen (node
->str
) + 1);
21937 /* A helper function for dwarf2out_finish called through
21938 htab_traverse. Emit one queued .debug_str string. */
21941 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
21943 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
21945 node
->form
= find_string_form (node
);
21946 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
21948 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
21949 assemble_string (node
->str
, strlen (node
->str
) + 1);
21955 /* Output the indexed string table. */
21958 output_indirect_strings (void)
21960 switch_to_section (debug_str_section
);
21961 if (!dwarf_split_debug_info
)
21962 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
21965 unsigned int offset
= 0;
21966 unsigned int cur_idx
= 0;
21968 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
21970 switch_to_section (debug_str_offsets_section
);
21971 htab_traverse_noresize (debug_str_hash
,
21972 output_index_string_offset
,
21974 switch_to_section (debug_str_dwo_section
);
21975 htab_traverse_noresize (debug_str_hash
,
21976 output_index_string
,
21981 /* Callback for htab_traverse to assign an index to an entry in the
21982 table, and to write that entry to the .debug_addr section. */
21985 output_addr_table_entry (void **slot
, void *data
)
21987 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
21988 unsigned int *cur_index
= (unsigned int *)data
;
21990 if (entry
->refcount
== 0)
21992 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
21993 || entry
->index
== NOT_INDEXED
);
21997 gcc_assert (entry
->index
== *cur_index
);
22000 switch (entry
->kind
)
22003 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22004 "0x%x", entry
->index
);
22006 case ate_kind_rtx_dtprel
:
22007 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22008 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22011 fputc ('\n', asm_out_file
);
22013 case ate_kind_label
:
22014 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22015 "0x%x", entry
->index
);
22018 gcc_unreachable ();
22023 /* Produce the .debug_addr section. */
22026 output_addr_table (void)
22028 unsigned int index
= 0;
22029 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22032 switch_to_section (debug_addr_section
);
22033 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22036 #if ENABLE_ASSERT_CHECKING
22037 /* Verify that all marks are clear. */
22040 verify_marks_clear (dw_die_ref die
)
22044 gcc_assert (! die
->die_mark
);
22045 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22047 #endif /* ENABLE_ASSERT_CHECKING */
22049 /* Clear the marks for a die and its children.
22050 Be cool if the mark isn't set. */
22053 prune_unmark_dies (dw_die_ref die
)
22059 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22062 /* Given DIE that we're marking as used, find any other dies
22063 it references as attributes and mark them as used. */
22066 prune_unused_types_walk_attribs (dw_die_ref die
)
22071 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22073 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22075 /* A reference to another DIE.
22076 Make sure that it will get emitted.
22077 If it was broken out into a comdat group, don't follow it. */
22078 if (! AT_ref (a
)->comdat_type_p
22079 || a
->dw_attr
== DW_AT_specification
)
22080 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22082 /* Set the string's refcount to 0 so that prune_unused_types_mark
22083 accounts properly for it. */
22084 if (AT_class (a
) == dw_val_class_str
)
22085 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22089 /* Mark the generic parameters and arguments children DIEs of DIE. */
22092 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22096 if (die
== NULL
|| die
->die_child
== NULL
)
22098 c
= die
->die_child
;
22101 switch (c
->die_tag
)
22103 case DW_TAG_template_type_param
:
22104 case DW_TAG_template_value_param
:
22105 case DW_TAG_GNU_template_template_param
:
22106 case DW_TAG_GNU_template_parameter_pack
:
22107 prune_unused_types_mark (c
, 1);
22113 } while (c
&& c
!= die
->die_child
);
22116 /* Mark DIE as being used. If DOKIDS is true, then walk down
22117 to DIE's children. */
22120 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22124 if (die
->die_mark
== 0)
22126 /* We haven't done this node yet. Mark it as used. */
22128 /* If this is the DIE of a generic type instantiation,
22129 mark the children DIEs that describe its generic parms and
22131 prune_unused_types_mark_generic_parms_dies (die
);
22133 /* We also have to mark its parents as used.
22134 (But we don't want to mark our parent's kids due to this,
22135 unless it is a class.) */
22136 if (die
->die_parent
)
22137 prune_unused_types_mark (die
->die_parent
,
22138 class_scope_p (die
->die_parent
));
22140 /* Mark any referenced nodes. */
22141 prune_unused_types_walk_attribs (die
);
22143 /* If this node is a specification,
22144 also mark the definition, if it exists. */
22145 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22146 prune_unused_types_mark (die
->die_definition
, 1);
22149 if (dokids
&& die
->die_mark
!= 2)
22151 /* We need to walk the children, but haven't done so yet.
22152 Remember that we've walked the kids. */
22155 /* If this is an array type, we need to make sure our
22156 kids get marked, even if they're types. If we're
22157 breaking out types into comdat sections, do this
22158 for all type definitions. */
22159 if (die
->die_tag
== DW_TAG_array_type
22160 || (use_debug_types
22161 && is_type_die (die
) && ! is_declaration_die (die
)))
22162 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22164 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22168 /* For local classes, look if any static member functions were emitted
22169 and if so, mark them. */
22172 prune_unused_types_walk_local_classes (dw_die_ref die
)
22176 if (die
->die_mark
== 2)
22179 switch (die
->die_tag
)
22181 case DW_TAG_structure_type
:
22182 case DW_TAG_union_type
:
22183 case DW_TAG_class_type
:
22186 case DW_TAG_subprogram
:
22187 if (!get_AT_flag (die
, DW_AT_declaration
)
22188 || die
->die_definition
!= NULL
)
22189 prune_unused_types_mark (die
, 1);
22196 /* Mark children. */
22197 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22200 /* Walk the tree DIE and mark types that we actually use. */
22203 prune_unused_types_walk (dw_die_ref die
)
22207 /* Don't do anything if this node is already marked and
22208 children have been marked as well. */
22209 if (die
->die_mark
== 2)
22212 switch (die
->die_tag
)
22214 case DW_TAG_structure_type
:
22215 case DW_TAG_union_type
:
22216 case DW_TAG_class_type
:
22217 if (die
->die_perennial_p
)
22220 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22221 if (c
->die_tag
== DW_TAG_subprogram
)
22224 /* Finding used static member functions inside of classes
22225 is needed just for local classes, because for other classes
22226 static member function DIEs with DW_AT_specification
22227 are emitted outside of the DW_TAG_*_type. If we ever change
22228 it, we'd need to call this even for non-local classes. */
22230 prune_unused_types_walk_local_classes (die
);
22232 /* It's a type node --- don't mark it. */
22235 case DW_TAG_const_type
:
22236 case DW_TAG_packed_type
:
22237 case DW_TAG_pointer_type
:
22238 case DW_TAG_reference_type
:
22239 case DW_TAG_rvalue_reference_type
:
22240 case DW_TAG_volatile_type
:
22241 case DW_TAG_typedef
:
22242 case DW_TAG_array_type
:
22243 case DW_TAG_interface_type
:
22244 case DW_TAG_friend
:
22245 case DW_TAG_variant_part
:
22246 case DW_TAG_enumeration_type
:
22247 case DW_TAG_subroutine_type
:
22248 case DW_TAG_string_type
:
22249 case DW_TAG_set_type
:
22250 case DW_TAG_subrange_type
:
22251 case DW_TAG_ptr_to_member_type
:
22252 case DW_TAG_file_type
:
22253 if (die
->die_perennial_p
)
22256 /* It's a type node --- don't mark it. */
22260 /* Mark everything else. */
22264 if (die
->die_mark
== 0)
22268 /* Now, mark any dies referenced from here. */
22269 prune_unused_types_walk_attribs (die
);
22274 /* Mark children. */
22275 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22278 /* Increment the string counts on strings referred to from DIE's
22282 prune_unused_types_update_strings (dw_die_ref die
)
22287 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22288 if (AT_class (a
) == dw_val_class_str
)
22290 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22292 /* Avoid unnecessarily putting strings that are used less than
22293 twice in the hash table. */
22295 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22298 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22299 htab_hash_string (s
->str
),
22301 gcc_assert (*slot
== NULL
);
22307 /* Remove from the tree DIE any dies that aren't marked. */
22310 prune_unused_types_prune (dw_die_ref die
)
22314 gcc_assert (die
->die_mark
);
22315 prune_unused_types_update_strings (die
);
22317 if (! die
->die_child
)
22320 c
= die
->die_child
;
22322 dw_die_ref prev
= c
;
22323 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22324 if (c
== die
->die_child
)
22326 /* No marked children between 'prev' and the end of the list. */
22328 /* No marked children at all. */
22329 die
->die_child
= NULL
;
22332 prev
->die_sib
= c
->die_sib
;
22333 die
->die_child
= prev
;
22338 if (c
!= prev
->die_sib
)
22340 prune_unused_types_prune (c
);
22341 } while (c
!= die
->die_child
);
22344 /* Remove dies representing declarations that we never use. */
22347 prune_unused_types (void)
22350 limbo_die_node
*node
;
22351 comdat_type_node
*ctnode
;
22353 dw_die_ref base_type
;
22355 #if ENABLE_ASSERT_CHECKING
22356 /* All the marks should already be clear. */
22357 verify_marks_clear (comp_unit_die ());
22358 for (node
= limbo_die_list
; node
; node
= node
->next
)
22359 verify_marks_clear (node
->die
);
22360 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22361 verify_marks_clear (ctnode
->root_die
);
22362 #endif /* ENABLE_ASSERT_CHECKING */
22364 /* Mark types that are used in global variables. */
22365 premark_types_used_by_global_vars ();
22367 /* Set the mark on nodes that are actually used. */
22368 prune_unused_types_walk (comp_unit_die ());
22369 for (node
= limbo_die_list
; node
; node
= node
->next
)
22370 prune_unused_types_walk (node
->die
);
22371 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22373 prune_unused_types_walk (ctnode
->root_die
);
22374 prune_unused_types_mark (ctnode
->type_die
, 1);
22377 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22378 are unusual in that they are pubnames that are the children of pubtypes.
22379 They should only be marked via their parent DW_TAG_enumeration_type die,
22380 not as roots in themselves. */
22381 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22382 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22383 prune_unused_types_mark (pub
->die
, 1);
22384 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22385 prune_unused_types_mark (base_type
, 1);
22387 if (debug_str_hash
)
22388 htab_empty (debug_str_hash
);
22389 if (skeleton_debug_str_hash
)
22390 htab_empty (skeleton_debug_str_hash
);
22391 prune_unused_types_prune (comp_unit_die ());
22392 for (node
= limbo_die_list
; node
; node
= node
->next
)
22393 prune_unused_types_prune (node
->die
);
22394 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22395 prune_unused_types_prune (ctnode
->root_die
);
22397 /* Leave the marks clear. */
22398 prune_unmark_dies (comp_unit_die ());
22399 for (node
= limbo_die_list
; node
; node
= node
->next
)
22400 prune_unmark_dies (node
->die
);
22401 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22402 prune_unmark_dies (ctnode
->root_die
);
22405 /* Set the parameter to true if there are any relative pathnames in
22408 file_table_relative_p (void ** slot
, void *param
)
22410 bool *p
= (bool *) param
;
22411 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22412 if (!IS_ABSOLUTE_PATH (d
->filename
))
22420 /* Helpers to manipulate hash table of comdat type units. */
22422 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
22424 typedef comdat_type_node value_type
;
22425 typedef comdat_type_node compare_type
;
22426 static inline hashval_t
hash (const value_type
*);
22427 static inline bool equal (const value_type
*, const compare_type
*);
22431 comdat_type_hasher::hash (const value_type
*type_node
)
22434 memcpy (&h
, type_node
->signature
, sizeof (h
));
22439 comdat_type_hasher::equal (const value_type
*type_node_1
,
22440 const compare_type
*type_node_2
)
22442 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22443 DWARF_TYPE_SIGNATURE_SIZE
));
22446 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22447 to the location it would have been added, should we know its
22448 DECL_ASSEMBLER_NAME when we added other attributes. This will
22449 probably improve compactness of debug info, removing equivalent
22450 abbrevs, and hide any differences caused by deferring the
22451 computation of the assembler name, triggered by e.g. PCH. */
22454 move_linkage_attr (dw_die_ref die
)
22456 unsigned ix
= vec_safe_length (die
->die_attr
);
22457 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22459 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22460 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22464 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22466 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22470 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22472 die
->die_attr
->pop ();
22473 die
->die_attr
->quick_insert (ix
, linkage
);
22477 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22478 referenced from typed stack ops and count how often they are used. */
22481 mark_base_types (dw_loc_descr_ref loc
)
22483 dw_die_ref base_type
= NULL
;
22485 for (; loc
; loc
= loc
->dw_loc_next
)
22487 switch (loc
->dw_loc_opc
)
22489 case DW_OP_GNU_regval_type
:
22490 case DW_OP_GNU_deref_type
:
22491 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22493 case DW_OP_GNU_convert
:
22494 case DW_OP_GNU_reinterpret
:
22495 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22498 case DW_OP_GNU_const_type
:
22499 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22501 case DW_OP_GNU_entry_value
:
22502 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
22507 gcc_assert (base_type
->die_parent
== comp_unit_die ());
22508 if (base_type
->die_mark
)
22509 base_type
->die_mark
++;
22512 base_types
.safe_push (base_type
);
22513 base_type
->die_mark
= 1;
22518 /* Comparison function for sorting marked base types. */
22521 base_type_cmp (const void *x
, const void *y
)
22523 dw_die_ref dx
= *(const dw_die_ref
*) x
;
22524 dw_die_ref dy
= *(const dw_die_ref
*) y
;
22525 unsigned int byte_size1
, byte_size2
;
22526 unsigned int encoding1
, encoding2
;
22527 if (dx
->die_mark
> dy
->die_mark
)
22529 if (dx
->die_mark
< dy
->die_mark
)
22531 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
22532 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
22533 if (byte_size1
< byte_size2
)
22535 if (byte_size1
> byte_size2
)
22537 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
22538 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
22539 if (encoding1
< encoding2
)
22541 if (encoding1
> encoding2
)
22546 /* Move base types marked by mark_base_types as early as possible
22547 in the CU, sorted by decreasing usage count both to make the
22548 uleb128 references as small as possible and to make sure they
22549 will have die_offset already computed by calc_die_sizes when
22550 sizes of typed stack loc ops is computed. */
22553 move_marked_base_types (void)
22556 dw_die_ref base_type
, die
, c
;
22558 if (base_types
.is_empty ())
22561 /* Sort by decreasing usage count, they will be added again in that
22563 base_types
.qsort (base_type_cmp
);
22564 die
= comp_unit_die ();
22565 c
= die
->die_child
;
22568 dw_die_ref prev
= c
;
22570 while (c
->die_mark
)
22572 remove_child_with_prev (c
, prev
);
22573 /* As base types got marked, there must be at least
22574 one node other than DW_TAG_base_type. */
22575 gcc_assert (c
!= c
->die_sib
);
22579 while (c
!= die
->die_child
);
22580 gcc_assert (die
->die_child
);
22581 c
= die
->die_child
;
22582 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22584 base_type
->die_mark
= 0;
22585 base_type
->die_sib
= c
->die_sib
;
22586 c
->die_sib
= base_type
;
22591 /* Helper function for resolve_addr, attempt to resolve
22592 one CONST_STRING, return non-zero if not successful. Similarly verify that
22593 SYMBOL_REFs refer to variables emitted in the current CU. */
22596 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
22600 if (GET_CODE (rtl
) == CONST_STRING
)
22602 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22603 tree t
= build_string (len
, XSTR (rtl
, 0));
22604 tree tlen
= size_int (len
- 1);
22606 = build_array_type (char_type_node
, build_index_type (tlen
));
22607 rtl
= lookup_constant_def (t
);
22608 if (!rtl
|| !MEM_P (rtl
))
22610 rtl
= XEXP (rtl
, 0);
22611 if (GET_CODE (rtl
) == SYMBOL_REF
22612 && SYMBOL_REF_DECL (rtl
)
22613 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22615 vec_safe_push (used_rtx_array
, rtl
);
22620 if (GET_CODE (rtl
) == SYMBOL_REF
22621 && SYMBOL_REF_DECL (rtl
))
22623 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
22625 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
22628 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
22632 if (GET_CODE (rtl
) == CONST
22633 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
22639 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
22640 if possible, and create DW_TAG_dwarf_procedure that can be referenced
22641 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
22644 string_cst_pool_decl (tree t
)
22646 rtx rtl
= output_constant_def (t
, 1);
22647 unsigned char *array
;
22648 dw_loc_descr_ref l
;
22653 if (!rtl
|| !MEM_P (rtl
))
22655 rtl
= XEXP (rtl
, 0);
22656 if (GET_CODE (rtl
) != SYMBOL_REF
22657 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
22660 decl
= SYMBOL_REF_DECL (rtl
);
22661 if (!lookup_decl_die (decl
))
22663 len
= TREE_STRING_LENGTH (t
);
22664 vec_safe_push (used_rtx_array
, rtl
);
22665 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
22666 array
= (unsigned char *) ggc_alloc_atomic (len
);
22667 memcpy (array
, TREE_STRING_POINTER (t
), len
);
22668 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
22669 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
22670 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
22671 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
22672 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
22673 add_AT_loc (ref
, DW_AT_location
, l
);
22674 equate_decl_number_to_die (decl
, ref
);
22679 /* Helper function of resolve_addr_in_expr. LOC is
22680 a DW_OP_addr followed by DW_OP_stack_value, either at the start
22681 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
22682 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
22683 with DW_OP_GNU_implicit_pointer if possible
22684 and return true, if unsuccesful, return false. */
22687 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
22689 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
22690 HOST_WIDE_INT offset
= 0;
22691 dw_die_ref ref
= NULL
;
22694 if (GET_CODE (rtl
) == CONST
22695 && GET_CODE (XEXP (rtl
, 0)) == PLUS
22696 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
22698 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
22699 rtl
= XEXP (XEXP (rtl
, 0), 0);
22701 if (GET_CODE (rtl
) == CONST_STRING
)
22703 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
22704 tree t
= build_string (len
, XSTR (rtl
, 0));
22705 tree tlen
= size_int (len
- 1);
22708 = build_array_type (char_type_node
, build_index_type (tlen
));
22709 rtl
= string_cst_pool_decl (t
);
22713 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
22715 decl
= SYMBOL_REF_DECL (rtl
);
22716 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
22718 ref
= lookup_decl_die (decl
);
22719 if (ref
&& (get_AT (ref
, DW_AT_location
)
22720 || get_AT (ref
, DW_AT_const_value
)))
22722 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
22723 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22724 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
22725 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22726 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22727 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22728 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
22736 /* Helper function for resolve_addr, handle one location
22737 expression, return false if at least one CONST_STRING or SYMBOL_REF in
22738 the location list couldn't be resolved. */
22741 resolve_addr_in_expr (dw_loc_descr_ref loc
)
22743 dw_loc_descr_ref keep
= NULL
;
22744 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
22745 switch (loc
->dw_loc_opc
)
22748 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22751 || prev
->dw_loc_opc
== DW_OP_piece
22752 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
22753 && loc
->dw_loc_next
22754 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
22756 && optimize_one_addr_into_implicit_ptr (loc
))
22761 case DW_OP_GNU_addr_index
:
22762 case DW_OP_GNU_const_index
:
22763 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
22764 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
22765 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
22769 case DW_OP_const4u
:
22770 case DW_OP_const8u
:
22772 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
22775 case DW_OP_plus_uconst
:
22776 if (size_of_loc_descr (loc
)
22777 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
22779 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
22781 dw_loc_descr_ref repl
22782 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
22783 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
22784 add_loc_descr (&repl
, loc
->dw_loc_next
);
22788 case DW_OP_implicit_value
:
22789 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
22790 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
22793 case DW_OP_GNU_implicit_pointer
:
22794 case DW_OP_GNU_parameter_ref
:
22795 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
22798 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
22801 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22802 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22803 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22806 case DW_OP_GNU_const_type
:
22807 case DW_OP_GNU_regval_type
:
22808 case DW_OP_GNU_deref_type
:
22809 case DW_OP_GNU_convert
:
22810 case DW_OP_GNU_reinterpret
:
22811 while (loc
->dw_loc_next
22812 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
22814 dw_die_ref base1
, base2
;
22815 unsigned enc1
, enc2
, size1
, size2
;
22816 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22817 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22818 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22819 else if (loc
->dw_loc_oprnd1
.val_class
22820 == dw_val_class_unsigned_const
)
22823 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22824 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
22825 == dw_val_class_unsigned_const
)
22827 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
22828 gcc_assert (base1
->die_tag
== DW_TAG_base_type
22829 && base2
->die_tag
== DW_TAG_base_type
);
22830 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
22831 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
22832 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
22833 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
22835 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
22836 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
22840 /* Optimize away next DW_OP_GNU_convert after
22841 adjusting LOC's base type die reference. */
22842 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
22843 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
22844 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
22846 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
22847 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
22850 /* Don't change integer DW_OP_GNU_convert after e.g. floating
22851 point typed stack entry. */
22852 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
22853 keep
= loc
->dw_loc_next
;
22863 /* Helper function of resolve_addr. DIE had DW_AT_location of
22864 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
22865 and DW_OP_addr couldn't be resolved. resolve_addr has already
22866 removed the DW_AT_location attribute. This function attempts to
22867 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
22868 to it or DW_AT_const_value attribute, if possible. */
22871 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
22873 if (TREE_CODE (decl
) != VAR_DECL
22874 || lookup_decl_die (decl
) != die
22875 || DECL_EXTERNAL (decl
)
22876 || !TREE_STATIC (decl
)
22877 || DECL_INITIAL (decl
) == NULL_TREE
22878 || DECL_P (DECL_INITIAL (decl
))
22879 || get_AT (die
, DW_AT_const_value
))
22882 tree init
= DECL_INITIAL (decl
);
22883 HOST_WIDE_INT offset
= 0;
22884 /* For variables that have been optimized away and thus
22885 don't have a memory location, see if we can emit
22886 DW_AT_const_value instead. */
22887 if (tree_add_const_value_attribute (die
, init
))
22891 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
22892 and ADDR_EXPR refers to a decl that has DW_AT_location or
22893 DW_AT_const_value (but isn't addressable, otherwise
22894 resolving the original DW_OP_addr wouldn't fail), see if
22895 we can add DW_OP_GNU_implicit_pointer. */
22897 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
22898 && host_integerp (TREE_OPERAND (init
, 1), 0))
22900 offset
= tree_low_cst (TREE_OPERAND (init
, 1), 0);
22901 init
= TREE_OPERAND (init
, 0);
22904 if (TREE_CODE (init
) != ADDR_EXPR
)
22906 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
22907 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
22908 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
22909 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
22910 && TREE_OPERAND (init
, 0) != decl
))
22913 dw_loc_descr_ref l
;
22915 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
22917 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
22920 decl
= SYMBOL_REF_DECL (rtl
);
22923 decl
= TREE_OPERAND (init
, 0);
22924 ref
= lookup_decl_die (decl
);
22926 || (!get_AT (ref
, DW_AT_location
)
22927 && !get_AT (ref
, DW_AT_const_value
)))
22929 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
22930 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
22931 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
22932 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
22933 add_AT_loc (die
, DW_AT_location
, l
);
22937 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
22938 an address in .rodata section if the string literal is emitted there,
22939 or remove the containing location list or replace DW_AT_const_value
22940 with DW_AT_location and empty location expression, if it isn't found
22941 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
22942 to something that has been emitted in the current CU. */
22945 resolve_addr (dw_die_ref die
)
22949 dw_loc_list_ref
*curr
, *start
, loc
;
22952 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22953 switch (AT_class (a
))
22955 case dw_val_class_loc_list
:
22956 start
= curr
= AT_loc_list_ptr (a
);
22959 /* The same list can be referenced more than once. See if we have
22960 already recorded the result from a previous pass. */
22962 *curr
= loc
->dw_loc_next
;
22963 else if (!loc
->resolved_addr
)
22965 /* As things stand, we do not expect or allow one die to
22966 reference a suffix of another die's location list chain.
22967 References must be identical or completely separate.
22968 There is therefore no need to cache the result of this
22969 pass on any list other than the first; doing so
22970 would lead to unnecessary writes. */
22973 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
22974 if (!resolve_addr_in_expr ((*curr
)->expr
))
22976 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
22977 dw_loc_descr_ref l
= (*curr
)->expr
;
22979 if (next
&& (*curr
)->ll_symbol
)
22981 gcc_assert (!next
->ll_symbol
);
22982 next
->ll_symbol
= (*curr
)->ll_symbol
;
22984 if (dwarf_split_debug_info
)
22985 remove_loc_list_addr_table_entries (l
);
22990 mark_base_types ((*curr
)->expr
);
22991 curr
= &(*curr
)->dw_loc_next
;
22995 loc
->resolved_addr
= 1;
22999 loc
->dw_loc_next
= *start
;
23004 remove_AT (die
, a
->dw_attr
);
23008 case dw_val_class_loc
:
23010 dw_loc_descr_ref l
= AT_loc (a
);
23011 /* For -gdwarf-2 don't attempt to optimize
23012 DW_AT_data_member_location containing
23013 DW_OP_plus_uconst - older consumers might
23014 rely on it being that op instead of a more complex,
23015 but shorter, location description. */
23016 if ((dwarf_version
> 2
23017 || a
->dw_attr
!= DW_AT_data_member_location
23019 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23020 || l
->dw_loc_next
!= NULL
)
23021 && !resolve_addr_in_expr (l
))
23023 if (dwarf_split_debug_info
)
23024 remove_loc_list_addr_table_entries (l
);
23026 && l
->dw_loc_next
== NULL
23027 && l
->dw_loc_opc
== DW_OP_addr
23028 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
23029 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
23030 && a
->dw_attr
== DW_AT_location
)
23032 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
23033 remove_AT (die
, a
->dw_attr
);
23035 optimize_location_into_implicit_ptr (die
, decl
);
23038 remove_AT (die
, a
->dw_attr
);
23042 mark_base_types (l
);
23045 case dw_val_class_addr
:
23046 if (a
->dw_attr
== DW_AT_const_value
23047 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23049 if (AT_index (a
) != NOT_INDEXED
)
23050 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23051 remove_AT (die
, a
->dw_attr
);
23054 if (die
->die_tag
== DW_TAG_GNU_call_site
23055 && a
->dw_attr
== DW_AT_abstract_origin
)
23057 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23058 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23060 && DECL_EXTERNAL (tdecl
)
23061 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23063 force_decl_die (tdecl
);
23064 tdie
= lookup_decl_die (tdecl
);
23068 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23069 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23070 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23074 if (AT_index (a
) != NOT_INDEXED
)
23075 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23076 remove_AT (die
, a
->dw_attr
);
23085 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23088 /* Helper routines for optimize_location_lists.
23089 This pass tries to share identical local lists in .debug_loc
23092 /* Iteratively hash operands of LOC opcode. */
23094 static inline hashval_t
23095 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23097 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23098 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23100 switch (loc
->dw_loc_opc
)
23102 case DW_OP_const4u
:
23103 case DW_OP_const8u
:
23107 case DW_OP_const1u
:
23108 case DW_OP_const1s
:
23109 case DW_OP_const2u
:
23110 case DW_OP_const2s
:
23111 case DW_OP_const4s
:
23112 case DW_OP_const8s
:
23116 case DW_OP_plus_uconst
:
23152 case DW_OP_deref_size
:
23153 case DW_OP_xderef_size
:
23154 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23161 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23162 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23163 hash
= iterative_hash_object (offset
, hash
);
23166 case DW_OP_implicit_value
:
23167 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23168 switch (val2
->val_class
)
23170 case dw_val_class_const
:
23171 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23173 case dw_val_class_vec
:
23175 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23176 unsigned int len
= val2
->v
.val_vec
.length
;
23178 hash
= iterative_hash_object (elt_size
, hash
);
23179 hash
= iterative_hash_object (len
, hash
);
23180 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23181 len
* elt_size
, hash
);
23184 case dw_val_class_const_double
:
23185 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23186 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23188 case dw_val_class_addr
:
23189 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23192 gcc_unreachable ();
23196 case DW_OP_bit_piece
:
23197 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23198 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23204 unsigned char dtprel
= 0xd1;
23205 hash
= iterative_hash_object (dtprel
, hash
);
23207 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23209 case DW_OP_GNU_addr_index
:
23210 case DW_OP_GNU_const_index
:
23214 unsigned char dtprel
= 0xd1;
23215 hash
= iterative_hash_object (dtprel
, hash
);
23217 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23220 case DW_OP_GNU_implicit_pointer
:
23221 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23223 case DW_OP_GNU_entry_value
:
23224 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23226 case DW_OP_GNU_regval_type
:
23227 case DW_OP_GNU_deref_type
:
23229 unsigned int byte_size
23230 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23231 unsigned int encoding
23232 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23233 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23234 hash
= iterative_hash_object (byte_size
, hash
);
23235 hash
= iterative_hash_object (encoding
, hash
);
23238 case DW_OP_GNU_convert
:
23239 case DW_OP_GNU_reinterpret
:
23240 if (val1
->val_class
== dw_val_class_unsigned_const
)
23242 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23246 case DW_OP_GNU_const_type
:
23248 unsigned int byte_size
23249 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23250 unsigned int encoding
23251 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23252 hash
= iterative_hash_object (byte_size
, hash
);
23253 hash
= iterative_hash_object (encoding
, hash
);
23254 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23256 hash
= iterative_hash_object (val2
->val_class
, hash
);
23257 switch (val2
->val_class
)
23259 case dw_val_class_const
:
23260 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23262 case dw_val_class_vec
:
23264 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23265 unsigned int len
= val2
->v
.val_vec
.length
;
23267 hash
= iterative_hash_object (elt_size
, hash
);
23268 hash
= iterative_hash_object (len
, hash
);
23269 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23270 len
* elt_size
, hash
);
23273 case dw_val_class_const_double
:
23274 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23275 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23278 gcc_unreachable ();
23284 /* Other codes have no operands. */
23290 /* Iteratively hash the whole DWARF location expression LOC. */
23292 static inline hashval_t
23293 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23295 dw_loc_descr_ref l
;
23296 bool sizes_computed
= false;
23297 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23298 size_of_locs (loc
);
23300 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23302 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23303 hash
= iterative_hash_object (opc
, hash
);
23304 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23306 size_of_locs (loc
);
23307 sizes_computed
= true;
23309 hash
= hash_loc_operands (l
, hash
);
23314 /* Compute hash of the whole location list LIST_HEAD. */
23317 hash_loc_list (dw_loc_list_ref list_head
)
23319 dw_loc_list_ref curr
= list_head
;
23320 hashval_t hash
= 0;
23322 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23324 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23325 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23327 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23329 hash
= hash_locs (curr
->expr
, hash
);
23331 list_head
->hash
= hash
;
23334 /* Return true if X and Y opcodes have the same operands. */
23337 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23339 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23340 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23341 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23342 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23344 switch (x
->dw_loc_opc
)
23346 case DW_OP_const4u
:
23347 case DW_OP_const8u
:
23351 case DW_OP_const1u
:
23352 case DW_OP_const1s
:
23353 case DW_OP_const2u
:
23354 case DW_OP_const2s
:
23355 case DW_OP_const4s
:
23356 case DW_OP_const8s
:
23360 case DW_OP_plus_uconst
:
23396 case DW_OP_deref_size
:
23397 case DW_OP_xderef_size
:
23398 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23401 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23402 can cause irrelevant differences in dw_loc_addr. */
23403 gcc_assert (valx1
->val_class
== dw_val_class_loc
23404 && valy1
->val_class
== dw_val_class_loc
23405 && (dwarf_split_debug_info
23406 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23407 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23408 case DW_OP_implicit_value
:
23409 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23410 || valx2
->val_class
!= valy2
->val_class
)
23412 switch (valx2
->val_class
)
23414 case dw_val_class_const
:
23415 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23416 case dw_val_class_vec
:
23417 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23418 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23419 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23420 valx2
->v
.val_vec
.elt_size
23421 * valx2
->v
.val_vec
.length
) == 0;
23422 case dw_val_class_const_double
:
23423 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23424 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23425 case dw_val_class_addr
:
23426 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23428 gcc_unreachable ();
23431 case DW_OP_bit_piece
:
23432 return valx1
->v
.val_int
== valy1
->v
.val_int
23433 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23436 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23437 case DW_OP_GNU_addr_index
:
23438 case DW_OP_GNU_const_index
:
23440 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23441 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23442 return rtx_equal_p (ax1
, ay1
);
23444 case DW_OP_GNU_implicit_pointer
:
23445 return valx1
->val_class
== dw_val_class_die_ref
23446 && valx1
->val_class
== valy1
->val_class
23447 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23448 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23449 case DW_OP_GNU_entry_value
:
23450 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23451 case DW_OP_GNU_const_type
:
23452 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23453 || valx2
->val_class
!= valy2
->val_class
)
23455 switch (valx2
->val_class
)
23457 case dw_val_class_const
:
23458 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23459 case dw_val_class_vec
:
23460 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23461 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23462 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23463 valx2
->v
.val_vec
.elt_size
23464 * valx2
->v
.val_vec
.length
) == 0;
23465 case dw_val_class_const_double
:
23466 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23467 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23469 gcc_unreachable ();
23471 case DW_OP_GNU_regval_type
:
23472 case DW_OP_GNU_deref_type
:
23473 return valx1
->v
.val_int
== valy1
->v
.val_int
23474 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23475 case DW_OP_GNU_convert
:
23476 case DW_OP_GNU_reinterpret
:
23477 if (valx1
->val_class
!= valy1
->val_class
)
23479 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23480 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23481 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23482 case DW_OP_GNU_parameter_ref
:
23483 return valx1
->val_class
== dw_val_class_die_ref
23484 && valx1
->val_class
== valy1
->val_class
23485 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23487 /* Other codes have no operands. */
23492 /* Return true if DWARF location expressions X and Y are the same. */
23495 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23497 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
23498 if (x
->dw_loc_opc
!= y
->dw_loc_opc
23499 || x
->dtprel
!= y
->dtprel
23500 || !compare_loc_operands (x
, y
))
23502 return x
== NULL
&& y
== NULL
;
23505 /* Hashtable helpers. */
23507 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
23509 typedef dw_loc_list_struct value_type
;
23510 typedef dw_loc_list_struct compare_type
;
23511 static inline hashval_t
hash (const value_type
*);
23512 static inline bool equal (const value_type
*, const compare_type
*);
23515 /* Return precomputed hash of location list X. */
23518 loc_list_hasher::hash (const value_type
*x
)
23523 /* Return true if location lists A and B are the same. */
23526 loc_list_hasher::equal (const value_type
*a
, const compare_type
*b
)
23530 if (a
->hash
!= b
->hash
)
23532 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
23533 if (strcmp (a
->begin
, b
->begin
) != 0
23534 || strcmp (a
->end
, b
->end
) != 0
23535 || (a
->section
== NULL
) != (b
->section
== NULL
)
23536 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
23537 || !compare_locs (a
->expr
, b
->expr
))
23539 return a
== NULL
&& b
== NULL
;
23542 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
23545 /* Recursively optimize location lists referenced from DIE
23546 children and share them whenever possible. */
23549 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type htab
)
23554 dw_loc_list_struct
**slot
;
23556 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23557 if (AT_class (a
) == dw_val_class_loc_list
)
23559 dw_loc_list_ref list
= AT_loc_list (a
);
23560 /* TODO: perform some optimizations here, before hashing
23561 it and storing into the hash table. */
23562 hash_loc_list (list
);
23563 slot
= htab
.find_slot_with_hash (list
, list
->hash
, INSERT
);
23567 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
23570 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
23574 /* Recursively assign each location list a unique index into the debug_addr
23578 index_location_lists (dw_die_ref die
)
23584 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23585 if (AT_class (a
) == dw_val_class_loc_list
)
23587 dw_loc_list_ref list
= AT_loc_list (a
);
23588 dw_loc_list_ref curr
;
23589 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23591 /* Don't index an entry that has already been indexed
23592 or won't be output. */
23593 if (curr
->begin_entry
!= NULL
23594 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
23598 = add_addr_table_entry (xstrdup (curr
->begin
),
23603 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
23606 /* Optimize location lists referenced from DIE
23607 children and share them whenever possible. */
23610 optimize_location_lists (dw_die_ref die
)
23612 loc_list_hash_type htab
;
23614 optimize_location_lists_1 (die
, htab
);
23618 /* Output stuff that dwarf requires at the end of every file,
23619 and generate the DWARF-2 debugging info. */
23622 dwarf2out_finish (const char *filename
)
23624 limbo_die_node
*node
, *next_node
;
23625 comdat_type_node
*ctnode
;
23626 hash_table
<comdat_type_hasher
> comdat_type_table
;
23628 dw_die_ref main_comp_unit_die
;
23630 /* PCH might result in DW_AT_producer string being restored from the
23631 header compilation, so always fill it with empty string initially
23632 and overwrite only here. */
23633 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
23634 producer_string
= gen_producer_string ();
23635 producer
->dw_attr_val
.v
.val_str
->refcount
--;
23636 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
23638 gen_scheduled_generic_parms_dies ();
23639 gen_remaining_tmpl_value_param_die_attribute ();
23641 /* Add the name for the main input file now. We delayed this from
23642 dwarf2out_init to avoid complications with PCH. */
23643 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
23644 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
23645 add_comp_dir_attribute (comp_unit_die ());
23646 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
23649 htab_traverse (file_table
, file_table_relative_p
, &p
);
23651 add_comp_dir_attribute (comp_unit_die ());
23654 if (deferred_locations_list
)
23655 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
23657 add_location_or_const_value_attribute (
23658 (*deferred_locations_list
)[i
].die
,
23659 (*deferred_locations_list
)[i
].variable
,
23664 /* Traverse the limbo die list, and add parent/child links. The only
23665 dies without parents that should be here are concrete instances of
23666 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
23667 For concrete instances, we can get the parent die from the abstract
23669 for (node
= limbo_die_list
; node
; node
= next_node
)
23671 dw_die_ref die
= node
->die
;
23672 next_node
= node
->next
;
23674 if (die
->die_parent
== NULL
)
23676 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
23678 if (origin
&& origin
->die_parent
)
23679 add_child_die (origin
->die_parent
, die
);
23680 else if (is_cu_die (die
))
23682 else if (seen_error ())
23683 /* It's OK to be confused by errors in the input. */
23684 add_child_die (comp_unit_die (), die
);
23687 /* In certain situations, the lexical block containing a
23688 nested function can be optimized away, which results
23689 in the nested function die being orphaned. Likewise
23690 with the return type of that nested function. Force
23691 this to be a child of the containing function.
23693 It may happen that even the containing function got fully
23694 inlined and optimized out. In that case we are lost and
23695 assign the empty child. This should not be big issue as
23696 the function is likely unreachable too. */
23697 gcc_assert (node
->created_for
);
23699 if (DECL_P (node
->created_for
))
23700 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
23701 else if (TYPE_P (node
->created_for
))
23702 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
23704 origin
= comp_unit_die ();
23706 add_child_die (origin
, die
);
23711 limbo_die_list
= NULL
;
23713 #if ENABLE_ASSERT_CHECKING
23715 dw_die_ref die
= comp_unit_die (), c
;
23716 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
23719 resolve_addr (comp_unit_die ());
23720 move_marked_base_types ();
23722 for (node
= deferred_asm_name
; node
; node
= node
->next
)
23724 tree decl
= node
->created_for
;
23725 /* When generating LTO bytecode we can not generate new assembler
23726 names at this point and all important decls got theirs via
23728 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
23729 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
23731 add_linkage_attr (node
->die
, decl
);
23732 move_linkage_attr (node
->die
);
23736 deferred_asm_name
= NULL
;
23738 /* Walk through the list of incomplete types again, trying once more to
23739 emit full debugging info for them. */
23740 retry_incomplete_types ();
23742 if (flag_eliminate_unused_debug_types
)
23743 prune_unused_types ();
23745 /* Generate separate COMDAT sections for type DIEs. */
23746 if (use_debug_types
)
23748 break_out_comdat_types (comp_unit_die ());
23750 /* Each new type_unit DIE was added to the limbo die list when created.
23751 Since these have all been added to comdat_type_list, clear the
23753 limbo_die_list
= NULL
;
23755 /* For each new comdat type unit, copy declarations for incomplete
23756 types to make the new unit self-contained (i.e., no direct
23757 references to the main compile unit). */
23758 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23759 copy_decls_for_unworthy_types (ctnode
->root_die
);
23760 copy_decls_for_unworthy_types (comp_unit_die ());
23762 /* In the process of copying declarations from one unit to another,
23763 we may have left some declarations behind that are no longer
23764 referenced. Prune them. */
23765 prune_unused_types ();
23768 /* Generate separate CUs for each of the include files we've seen.
23769 They will go into limbo_die_list. */
23770 if (flag_eliminate_dwarf2_dups
)
23771 break_out_includes (comp_unit_die ());
23773 /* Traverse the DIE's and add add sibling attributes to those DIE's
23774 that have children. */
23775 add_sibling_attributes (comp_unit_die ());
23776 for (node
= limbo_die_list
; node
; node
= node
->next
)
23777 add_sibling_attributes (node
->die
);
23778 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23779 add_sibling_attributes (ctnode
->root_die
);
23781 /* When splitting DWARF info, we put some attributes in the
23782 skeleton compile_unit DIE that remains in the .o, while
23783 most attributes go in the DWO compile_unit_die. */
23784 if (dwarf_split_debug_info
)
23785 main_comp_unit_die
= gen_compile_unit_die (NULL
);
23787 main_comp_unit_die
= comp_unit_die ();
23789 /* Output a terminator label for the .text section. */
23790 switch_to_section (text_section
);
23791 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
23792 if (cold_text_section
)
23794 switch_to_section (cold_text_section
);
23795 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
23798 /* We can only use the low/high_pc attributes if all of the code was
23800 if (!have_multiple_function_sections
23801 || (dwarf_version
< 3 && dwarf_strict
))
23803 /* Don't add if the CU has no associated code. */
23804 if (text_section_used
)
23805 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
23806 text_end_label
, true);
23812 bool range_list_added
= false;
23814 if (text_section_used
)
23815 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
23816 text_end_label
, &range_list_added
, true);
23817 if (cold_text_section_used
)
23818 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
23819 cold_end_label
, &range_list_added
, true);
23821 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
23823 if (DECL_IGNORED_P (fde
->decl
))
23825 if (!fde
->in_std_section
)
23826 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
23827 fde
->dw_fde_end
, &range_list_added
,
23829 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
23830 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
23831 fde
->dw_fde_second_end
, &range_list_added
,
23835 if (range_list_added
)
23837 /* We need to give .debug_loc and .debug_ranges an appropriate
23838 "base address". Use zero so that these addresses become
23839 absolute. Historically, we've emitted the unexpected
23840 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
23841 Emit both to give time for other tools to adapt. */
23842 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
23843 if (! dwarf_strict
&& dwarf_version
< 4)
23844 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
23850 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23851 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
23852 debug_line_section_label
);
23855 add_AT_macptr (comp_unit_die (),
23856 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
23857 macinfo_section_label
);
23859 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
23861 /* optimize_location_lists calculates the size of the lists,
23862 so index them first, and assign indices to the entries.
23863 Although optimize_location_lists will remove entries from
23864 the table, it only does so for duplicates, and therefore
23865 only reduces ref_counts to 1. */
23866 unsigned int index
= 0;
23867 index_location_lists (comp_unit_die ());
23868 htab_traverse_noresize (addr_index_table
,
23869 index_addr_table_entry
, &index
);
23871 if (have_location_lists
)
23872 optimize_location_lists (comp_unit_die ());
23874 save_macinfo_strings ();
23876 if (dwarf_split_debug_info
)
23878 unsigned int index
= 0;
23880 /* Add attributes common to skeleton compile_units and
23881 type_units. Because these attributes include strings, it
23882 must be done before freezing the string table. Top-level
23883 skeleton die attrs are added when the skeleton type unit is
23884 created, so ensure it is created by this point. */
23885 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
23886 (void) get_skeleton_type_unit ();
23887 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
23890 /* Output all of the compilation units. We put the main one last so that
23891 the offsets are available to output_pubnames. */
23892 for (node
= limbo_die_list
; node
; node
= node
->next
)
23893 output_comp_unit (node
->die
, 0);
23895 comdat_type_table
.create (100);
23896 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
23898 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
23900 /* Don't output duplicate types. */
23901 if (*slot
!= HTAB_EMPTY_ENTRY
)
23904 /* Add a pointer to the line table for the main compilation unit
23905 so that the debugger can make sense of DW_AT_decl_file
23907 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
23908 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
23909 (!dwarf_split_debug_info
23910 ? debug_line_section_label
23911 : debug_skeleton_line_section_label
));
23913 output_comdat_type_unit (ctnode
);
23916 comdat_type_table
.dispose ();
23918 /* The AT_pubnames attribute needs to go in all skeleton dies, including
23919 both the main_cu and all skeleton TUs. Making this call unconditional
23920 would end up either adding a second copy of the AT_pubnames attribute, or
23921 requiring a special case in add_top_level_skeleton_die_attrs. */
23922 if (!dwarf_split_debug_info
)
23923 add_AT_pubnames (comp_unit_die ());
23925 if (dwarf_split_debug_info
)
23928 unsigned char checksum
[16];
23929 struct md5_ctx ctx
;
23931 /* Compute a checksum of the comp_unit to use as the dwo_id. */
23932 md5_init_ctx (&ctx
);
23934 die_checksum (comp_unit_die (), &ctx
, &mark
);
23935 unmark_all_dies (comp_unit_die ());
23936 md5_finish_ctx (&ctx
, checksum
);
23938 /* Use the first 8 bytes of the checksum as the dwo_id,
23939 and add it to both comp-unit DIEs. */
23940 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
23941 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
23943 /* Add the base offset of the ranges table to the skeleton
23945 if (ranges_table_in_use
)
23946 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
23947 ranges_section_label
);
23949 switch_to_section (debug_addr_section
);
23950 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
23951 output_addr_table ();
23954 /* Output the main compilation unit if non-empty or if .debug_macinfo
23955 or .debug_macro will be emitted. */
23956 output_comp_unit (comp_unit_die (), have_macinfo
);
23958 if (dwarf_split_debug_info
&& info_section_emitted
)
23959 output_skeleton_debug_sections (main_comp_unit_die
);
23961 /* Output the abbreviation table. */
23962 if (abbrev_die_table_in_use
!= 1)
23964 switch_to_section (debug_abbrev_section
);
23965 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
23966 output_abbrev_section ();
23969 /* Output location list section if necessary. */
23970 if (have_location_lists
)
23972 /* Output the location lists info. */
23973 switch_to_section (debug_loc_section
);
23974 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
23975 output_location_lists (comp_unit_die ());
23978 /* Output public names and types tables if necessary. */
23979 output_pubnames (pubname_table
);
23980 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
23981 It shouldn't hurt to emit it always, since pure DWARF2 consumers
23982 simply won't look for the section. */
23983 output_pubnames (pubtype_table
);
23985 /* Output the address range information if a CU (.debug_info section)
23986 was emitted. We output an empty table even if we had no functions
23987 to put in it. This because the consumer has no way to tell the
23988 difference between an empty table that we omitted and failure to
23989 generate a table that would have contained data. */
23990 if (info_section_emitted
)
23992 unsigned long aranges_length
= size_of_aranges ();
23994 switch_to_section (debug_aranges_section
);
23995 output_aranges (aranges_length
);
23998 /* Output ranges section if necessary. */
23999 if (ranges_table_in_use
)
24001 switch_to_section (debug_ranges_section
);
24002 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24006 /* Have to end the macro section. */
24009 switch_to_section (debug_macinfo_section
);
24010 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24012 dw2_asm_output_data (1, 0, "End compilation unit");
24015 /* Output the source line correspondence table. We must do this
24016 even if there is no line information. Otherwise, on an empty
24017 translation unit, we will generate a present, but empty,
24018 .debug_info section. IRIX 6.5 `nm' will then complain when
24019 examining the file. This is done late so that any filenames
24020 used by the debug_info section are marked as 'used'. */
24021 switch_to_section (debug_line_section
);
24022 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24023 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24024 output_line_info (false);
24026 if (dwarf_split_debug_info
&& info_section_emitted
)
24028 switch_to_section (debug_skeleton_line_section
);
24029 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24030 output_line_info (true);
24033 /* If we emitted any indirect strings, output the string table too. */
24034 if (debug_str_hash
|| skeleton_debug_str_hash
)
24035 output_indirect_strings ();
24038 #include "gt-dwarf2out.h"