1 /* Output Dwarf2 format symbol table information from GCC.
2 Copyright (C) 1992-2014 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"
64 #include "stringpool.h"
65 #include "stor-layout.h"
69 #include "hash-table.h"
72 #include "hard-reg-set.h"
74 #include "insn-config.h"
81 #include "dwarf2out.h"
82 #include "dwarf2asm.h"
86 #include "diagnostic.h"
87 #include "tree-pretty-print.h"
90 #include "common/common-target.h"
91 #include "langhooks.h"
99 #include "gdb/gdb-index.h"
101 static void dwarf2out_source_line (unsigned int, const char *, int, bool);
102 static rtx last_var_location_insn
;
103 static rtx cached_next_real_insn
;
105 #ifdef VMS_DEBUGGING_INFO
106 int vms_file_stats_name (const char *, long long *, long *, char *, int *);
108 /* Define this macro to be a nonzero value if the directory specifications
109 which are output in the debug info should end with a separator. */
110 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 1
111 /* Define this macro to evaluate to a nonzero value if GCC should refrain
112 from generating indirect strings in DWARF2 debug information, for instance
113 if your target is stuck with an old version of GDB that is unable to
114 process them properly or uses VMS Debug. */
115 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 1
117 #define DWARF2_DIR_SHOULD_END_WITH_SEPARATOR 0
118 #define DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET 0
121 /* ??? Poison these here until it can be done generically. They've been
122 totally replaced in this file; make sure it stays that way. */
123 #undef DWARF2_UNWIND_INFO
124 #undef DWARF2_FRAME_INFO
125 #if (GCC_VERSION >= 3000)
126 #pragma GCC poison DWARF2_UNWIND_INFO DWARF2_FRAME_INFO
129 /* The size of the target's pointer type. */
131 #define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT)
134 /* Array of RTXes referenced by the debugging information, which therefore
135 must be kept around forever. */
136 static GTY(()) vec
<rtx
, va_gc
> *used_rtx_array
;
138 /* A pointer to the base of a list of incomplete types which might be
139 completed at some later time. incomplete_types_list needs to be a
140 vec<tree, va_gc> *because we want to tell the garbage collector about
142 static GTY(()) vec
<tree
, va_gc
> *incomplete_types
;
144 /* A pointer to the base of a table of references to declaration
145 scopes. This table is a display which tracks the nesting
146 of declaration scopes at the current scope and containing
147 scopes. This table is used to find the proper place to
148 define type declaration DIE's. */
149 static GTY(()) vec
<tree
, va_gc
> *decl_scope_table
;
151 /* Pointers to various DWARF2 sections. */
152 static GTY(()) section
*debug_info_section
;
153 static GTY(()) section
*debug_skeleton_info_section
;
154 static GTY(()) section
*debug_abbrev_section
;
155 static GTY(()) section
*debug_skeleton_abbrev_section
;
156 static GTY(()) section
*debug_aranges_section
;
157 static GTY(()) section
*debug_addr_section
;
158 static GTY(()) section
*debug_macinfo_section
;
159 static GTY(()) section
*debug_line_section
;
160 static GTY(()) section
*debug_skeleton_line_section
;
161 static GTY(()) section
*debug_loc_section
;
162 static GTY(()) section
*debug_pubnames_section
;
163 static GTY(()) section
*debug_pubtypes_section
;
164 static GTY(()) section
*debug_str_section
;
165 static GTY(()) section
*debug_str_dwo_section
;
166 static GTY(()) section
*debug_str_offsets_section
;
167 static GTY(()) section
*debug_ranges_section
;
168 static GTY(()) section
*debug_frame_section
;
170 /* Maximum size (in bytes) of an artificially generated label. */
171 #define MAX_ARTIFICIAL_LABEL_BYTES 30
173 /* According to the (draft) DWARF 3 specification, the initial length
174 should either be 4 or 12 bytes. When it's 12 bytes, the first 4
175 bytes are 0xffffffff, followed by the length stored in the next 8
178 However, the SGI/MIPS ABI uses an initial length which is equal to
179 DWARF_OFFSET_SIZE. It is defined (elsewhere) accordingly. */
181 #ifndef DWARF_INITIAL_LENGTH_SIZE
182 #define DWARF_INITIAL_LENGTH_SIZE (DWARF_OFFSET_SIZE == 4 ? 4 : 12)
185 /* Round SIZE up to the nearest BOUNDARY. */
186 #define DWARF_ROUND(SIZE,BOUNDARY) \
187 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY))
189 /* CIE identifier. */
190 #if HOST_BITS_PER_WIDE_INT >= 64
191 #define DWARF_CIE_ID \
192 (unsigned HOST_WIDE_INT) (DWARF_OFFSET_SIZE == 4 ? DW_CIE_ID : DW64_CIE_ID)
194 #define DWARF_CIE_ID DW_CIE_ID
198 /* A vector for a table that contains frame description
199 information for each routine. */
200 #define NOT_INDEXED (-1U)
201 #define NO_INDEX_ASSIGNED (-2U)
203 static GTY(()) vec
<dw_fde_ref
, va_gc
> *fde_vec
;
205 struct GTY(()) indirect_string_node
{
207 unsigned int refcount
;
208 enum dwarf_form form
;
213 static GTY ((param_is (struct indirect_string_node
))) htab_t debug_str_hash
;
215 /* With split_debug_info, both the comp_dir and dwo_name go in the
216 main object file, rather than the dwo, similar to the force_direct
217 parameter elsewhere but with additional complications:
219 1) The string is needed in both the main object file and the dwo.
220 That is, the comp_dir and dwo_name will appear in both places.
222 2) Strings can use three forms: DW_FORM_string, DW_FORM_strp or
223 DW_FORM_GNU_str_index.
225 3) GCC chooses the form to use late, depending on the size and
228 Rather than forcing the all debug string handling functions and
229 callers to deal with these complications, simply use a separate,
230 special-cased string table for any attribute that should go in the
231 main object file. This limits the complexity to just the places
234 static GTY ((param_is (struct indirect_string_node
)))
235 htab_t skeleton_debug_str_hash
;
237 static GTY(()) int dw2_string_counter
;
239 /* True if the compilation unit places functions in more than one section. */
240 static GTY(()) bool have_multiple_function_sections
= false;
242 /* Whether the default text and cold text sections have been used at all. */
244 static GTY(()) bool text_section_used
= false;
245 static GTY(()) bool cold_text_section_used
= false;
247 /* The default cold text section. */
248 static GTY(()) section
*cold_text_section
;
250 /* The DIE for C++1y 'auto' in a function return type. */
251 static GTY(()) dw_die_ref auto_die
;
253 /* The DIE for C++1y 'decltype(auto)' in a function return type. */
254 static GTY(()) dw_die_ref decltype_auto_die
;
256 /* Forward declarations for functions defined in this file. */
258 static char *stripattributes (const char *);
259 static void output_call_frame_info (int);
260 static void dwarf2out_note_section_used (void);
262 /* Personality decl of current unit. Used only when assembler does not support
264 static GTY(()) rtx current_unit_personality
;
266 /* Data and reference forms for relocatable data. */
267 #define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4)
268 #define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4)
270 #ifndef DEBUG_FRAME_SECTION
271 #define DEBUG_FRAME_SECTION ".debug_frame"
274 #ifndef FUNC_BEGIN_LABEL
275 #define FUNC_BEGIN_LABEL "LFB"
278 #ifndef FUNC_END_LABEL
279 #define FUNC_END_LABEL "LFE"
282 #ifndef PROLOGUE_END_LABEL
283 #define PROLOGUE_END_LABEL "LPE"
286 #ifndef EPILOGUE_BEGIN_LABEL
287 #define EPILOGUE_BEGIN_LABEL "LEB"
290 #ifndef FRAME_BEGIN_LABEL
291 #define FRAME_BEGIN_LABEL "Lframe"
293 #define CIE_AFTER_SIZE_LABEL "LSCIE"
294 #define CIE_END_LABEL "LECIE"
295 #define FDE_LABEL "LSFDE"
296 #define FDE_AFTER_SIZE_LABEL "LASFDE"
297 #define FDE_END_LABEL "LEFDE"
298 #define LINE_NUMBER_BEGIN_LABEL "LSLT"
299 #define LINE_NUMBER_END_LABEL "LELT"
300 #define LN_PROLOG_AS_LABEL "LASLTP"
301 #define LN_PROLOG_END_LABEL "LELTP"
302 #define DIE_LABEL_PREFIX "DW"
304 /* Match the base name of a file to the base name of a compilation unit. */
307 matches_main_base (const char *path
)
309 /* Cache the last query. */
310 static const char *last_path
= NULL
;
311 static int last_match
= 0;
312 if (path
!= last_path
)
315 int length
= base_of_path (path
, &base
);
317 last_match
= (length
== main_input_baselength
318 && memcmp (base
, main_input_basename
, length
) == 0);
323 #ifdef DEBUG_DEBUG_STRUCT
326 dump_struct_debug (tree type
, enum debug_info_usage usage
,
327 enum debug_struct_file criterion
, int generic
,
328 int matches
, int result
)
330 /* Find the type name. */
331 tree type_decl
= TYPE_STUB_DECL (type
);
333 const char *name
= 0;
334 if (TREE_CODE (t
) == TYPE_DECL
)
337 name
= IDENTIFIER_POINTER (t
);
339 fprintf (stderr
, " struct %d %s %s %s %s %d %p %s\n",
341 DECL_IN_SYSTEM_HEADER (type_decl
) ? "sys" : "usr",
342 matches
? "bas" : "hdr",
343 generic
? "gen" : "ord",
344 usage
== DINFO_USAGE_DFN
? ";" :
345 usage
== DINFO_USAGE_DIR_USE
? "." : "*",
347 (void*) type_decl
, name
);
350 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
351 dump_struct_debug (type, usage, criterion, generic, matches, result)
355 #define DUMP_GSTRUCT(type, usage, criterion, generic, matches, result) \
360 /* Get the number of HOST_WIDE_INTs needed to represent the precision
364 get_full_len (const wide_int
&op
)
366 return ((op
.get_precision () + HOST_BITS_PER_WIDE_INT
- 1)
367 / HOST_BITS_PER_WIDE_INT
);
371 should_emit_struct_debug (tree type
, enum debug_info_usage usage
)
373 enum debug_struct_file criterion
;
375 bool generic
= lang_hooks
.types
.generic_p (type
);
378 criterion
= debug_struct_generic
[usage
];
380 criterion
= debug_struct_ordinary
[usage
];
382 if (criterion
== DINFO_STRUCT_FILE_NONE
)
383 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
384 if (criterion
== DINFO_STRUCT_FILE_ANY
)
385 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
387 type_decl
= TYPE_STUB_DECL (TYPE_MAIN_VARIANT (type
));
389 if (type_decl
!= NULL
)
391 if (criterion
== DINFO_STRUCT_FILE_SYS
&& DECL_IN_SYSTEM_HEADER (type_decl
))
392 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, true);
394 if (matches_main_base (DECL_SOURCE_FILE (type_decl
)))
395 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, true, true);
398 return DUMP_GSTRUCT (type
, usage
, criterion
, generic
, false, false);
401 /* Return a pointer to a copy of the section string name S with all
402 attributes stripped off, and an asterisk prepended (for assemble_name). */
405 stripattributes (const char *s
)
407 char *stripped
= XNEWVEC (char, strlen (s
) + 2);
412 while (*s
&& *s
!= ',')
419 /* Switch [BACK] to eh_frame_section. If we don't have an eh_frame_section,
420 switch to the data section instead, and write out a synthetic start label
421 for collect2 the first time around. */
424 switch_to_eh_frame_section (bool back
)
428 #ifdef EH_FRAME_SECTION_NAME
429 if (eh_frame_section
== 0)
433 if (EH_TABLES_CAN_BE_READ_ONLY
)
439 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1,
441 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2,
443 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0,
446 || ((fde_encoding
& 0x70) != DW_EH_PE_absptr
447 && (fde_encoding
& 0x70) != DW_EH_PE_aligned
448 && (per_encoding
& 0x70) != DW_EH_PE_absptr
449 && (per_encoding
& 0x70) != DW_EH_PE_aligned
450 && (lsda_encoding
& 0x70) != DW_EH_PE_absptr
451 && (lsda_encoding
& 0x70) != DW_EH_PE_aligned
))
452 ? 0 : SECTION_WRITE
);
455 flags
= SECTION_WRITE
;
456 eh_frame_section
= get_section (EH_FRAME_SECTION_NAME
, flags
, NULL
);
458 #endif /* EH_FRAME_SECTION_NAME */
460 if (eh_frame_section
)
461 switch_to_section (eh_frame_section
);
464 /* We have no special eh_frame section. Put the information in
465 the data section and emit special labels to guide collect2. */
466 switch_to_section (data_section
);
470 label
= get_file_function_name ("F");
471 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
472 targetm
.asm_out
.globalize_label (asm_out_file
,
473 IDENTIFIER_POINTER (label
));
474 ASM_OUTPUT_LABEL (asm_out_file
, IDENTIFIER_POINTER (label
));
479 /* Switch [BACK] to the eh or debug frame table section, depending on
483 switch_to_frame_table_section (int for_eh
, bool back
)
486 switch_to_eh_frame_section (back
);
489 if (!debug_frame_section
)
490 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
491 SECTION_DEBUG
, NULL
);
492 switch_to_section (debug_frame_section
);
496 /* Describe for the GTY machinery what parts of dw_cfi_oprnd1 are used. */
498 enum dw_cfi_oprnd_type
499 dw_cfi_oprnd1_desc (enum dwarf_call_frame_info cfi
)
504 case DW_CFA_GNU_window_save
:
505 case DW_CFA_remember_state
:
506 case DW_CFA_restore_state
:
507 return dw_cfi_oprnd_unused
;
510 case DW_CFA_advance_loc1
:
511 case DW_CFA_advance_loc2
:
512 case DW_CFA_advance_loc4
:
513 case DW_CFA_MIPS_advance_loc8
:
514 return dw_cfi_oprnd_addr
;
517 case DW_CFA_offset_extended
:
519 case DW_CFA_offset_extended_sf
:
520 case DW_CFA_def_cfa_sf
:
522 case DW_CFA_restore_extended
:
523 case DW_CFA_undefined
:
524 case DW_CFA_same_value
:
525 case DW_CFA_def_cfa_register
:
526 case DW_CFA_register
:
527 case DW_CFA_expression
:
528 return dw_cfi_oprnd_reg_num
;
530 case DW_CFA_def_cfa_offset
:
531 case DW_CFA_GNU_args_size
:
532 case DW_CFA_def_cfa_offset_sf
:
533 return dw_cfi_oprnd_offset
;
535 case DW_CFA_def_cfa_expression
:
536 return dw_cfi_oprnd_loc
;
543 /* Describe for the GTY machinery what parts of dw_cfi_oprnd2 are used. */
545 enum dw_cfi_oprnd_type
546 dw_cfi_oprnd2_desc (enum dwarf_call_frame_info cfi
)
551 case DW_CFA_def_cfa_sf
:
553 case DW_CFA_offset_extended_sf
:
554 case DW_CFA_offset_extended
:
555 return dw_cfi_oprnd_offset
;
557 case DW_CFA_register
:
558 return dw_cfi_oprnd_reg_num
;
560 case DW_CFA_expression
:
561 return dw_cfi_oprnd_loc
;
564 return dw_cfi_oprnd_unused
;
568 /* Output one FDE. */
571 output_fde (dw_fde_ref fde
, bool for_eh
, bool second
,
572 char *section_start_label
, int fde_encoding
, char *augmentation
,
573 bool any_lsda_needed
, int lsda_encoding
)
575 const char *begin
, *end
;
576 static unsigned int j
;
579 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, for_eh
,
581 targetm
.asm_out
.internal_label (asm_out_file
, FDE_LABEL
,
583 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_AFTER_SIZE_LABEL
, for_eh
+ j
);
584 ASM_GENERATE_INTERNAL_LABEL (l2
, FDE_END_LABEL
, for_eh
+ j
);
585 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
586 dw2_asm_output_data (4, 0xffffffff, "Initial length escape value"
587 " indicating 64-bit DWARF extension");
588 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
590 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
593 dw2_asm_output_delta (4, l1
, section_start_label
, "FDE CIE offset");
595 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, section_start_label
,
596 debug_frame_section
, "FDE CIE offset");
598 begin
= second
? fde
->dw_fde_second_begin
: fde
->dw_fde_begin
;
599 end
= second
? fde
->dw_fde_second_end
: fde
->dw_fde_end
;
603 rtx sym_ref
= gen_rtx_SYMBOL_REF (Pmode
, begin
);
604 SYMBOL_REF_FLAGS (sym_ref
) |= SYMBOL_FLAG_LOCAL
;
605 dw2_asm_output_encoded_addr_rtx (fde_encoding
, sym_ref
, false,
606 "FDE initial location");
607 dw2_asm_output_delta (size_of_encoded_value (fde_encoding
),
608 end
, begin
, "FDE address range");
612 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, begin
, "FDE initial location");
613 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, end
, begin
, "FDE address range");
620 int size
= size_of_encoded_value (lsda_encoding
);
622 if (lsda_encoding
== DW_EH_PE_aligned
)
624 int offset
= ( 4 /* Length */
626 + 2 * size_of_encoded_value (fde_encoding
)
627 + 1 /* Augmentation size */ );
628 int pad
= -offset
& (PTR_SIZE
- 1);
631 gcc_assert (size_of_uleb128 (size
) == 1);
634 dw2_asm_output_data_uleb128 (size
, "Augmentation size");
636 if (fde
->uses_eh_lsda
)
638 ASM_GENERATE_INTERNAL_LABEL (l1
, second
? "LLSDAC" : "LLSDA",
639 fde
->funcdef_number
);
640 dw2_asm_output_encoded_addr_rtx (lsda_encoding
,
641 gen_rtx_SYMBOL_REF (Pmode
, l1
),
643 "Language Specific Data Area");
647 if (lsda_encoding
== DW_EH_PE_aligned
)
648 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (PTR_SIZE
));
649 dw2_asm_output_data (size_of_encoded_value (lsda_encoding
), 0,
650 "Language Specific Data Area (none)");
654 dw2_asm_output_data_uleb128 (0, "Augmentation size");
657 /* Loop through the Call Frame Instructions associated with this FDE. */
658 fde
->dw_fde_current_label
= begin
;
660 size_t from
, until
, i
;
663 until
= vec_safe_length (fde
->dw_fde_cfi
);
665 if (fde
->dw_fde_second_begin
== NULL
)
668 until
= fde
->dw_fde_switch_cfi_index
;
670 from
= fde
->dw_fde_switch_cfi_index
;
672 for (i
= from
; i
< until
; i
++)
673 output_cfi ((*fde
->dw_fde_cfi
)[i
], fde
, for_eh
);
676 /* If we are to emit a ref/link from function bodies to their frame tables,
677 do it now. This is typically performed to make sure that tables
678 associated with functions are dragged with them and not discarded in
679 garbage collecting links. We need to do this on a per function basis to
680 cope with -ffunction-sections. */
682 #ifdef ASM_OUTPUT_DWARF_TABLE_REF
683 /* Switch to the function section, emit the ref to the tables, and
684 switch *back* into the table section. */
685 switch_to_section (function_section (fde
->decl
));
686 ASM_OUTPUT_DWARF_TABLE_REF (section_start_label
);
687 switch_to_frame_table_section (for_eh
, true);
690 /* Pad the FDE out to an address sized boundary. */
691 ASM_OUTPUT_ALIGN (asm_out_file
,
692 floor_log2 ((for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
)));
693 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
698 /* Return true if frame description entry FDE is needed for EH. */
701 fde_needed_for_eh_p (dw_fde_ref fde
)
703 if (flag_asynchronous_unwind_tables
)
706 if (TARGET_USES_WEAK_UNWIND_INFO
&& DECL_WEAK (fde
->decl
))
709 if (fde
->uses_eh_lsda
)
712 /* If exceptions are enabled, we have collected nothrow info. */
713 if (flag_exceptions
&& (fde
->all_throwers_are_sibcalls
|| fde
->nothrow
))
719 /* Output the call frame information used to record information
720 that relates to calculating the frame pointer, and records the
721 location of saved registers. */
724 output_call_frame_info (int for_eh
)
729 char l1
[20], l2
[20], section_start_label
[20];
730 bool any_lsda_needed
= false;
731 char augmentation
[6];
732 int augmentation_size
;
733 int fde_encoding
= DW_EH_PE_absptr
;
734 int per_encoding
= DW_EH_PE_absptr
;
735 int lsda_encoding
= DW_EH_PE_absptr
;
737 rtx personality
= NULL
;
740 /* Don't emit a CIE if there won't be any FDEs. */
744 /* Nothing to do if the assembler's doing it all. */
745 if (dwarf2out_do_cfi_asm ())
748 /* If we don't have any functions we'll want to unwind out of, don't emit
749 any EH unwind information. If we make FDEs linkonce, we may have to
750 emit an empty label for an FDE that wouldn't otherwise be emitted. We
751 want to avoid having an FDE kept around when the function it refers to
752 is discarded. Example where this matters: a primary function template
753 in C++ requires EH information, an explicit specialization doesn't. */
756 bool any_eh_needed
= false;
758 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
760 if (fde
->uses_eh_lsda
)
761 any_eh_needed
= any_lsda_needed
= true;
762 else if (fde_needed_for_eh_p (fde
))
763 any_eh_needed
= true;
764 else if (TARGET_USES_WEAK_UNWIND_INFO
)
765 targetm
.asm_out
.emit_unwind_label (asm_out_file
, fde
->decl
, 1, 1);
772 /* We're going to be generating comments, so turn on app. */
776 /* Switch to the proper frame section, first time. */
777 switch_to_frame_table_section (for_eh
, false);
779 ASM_GENERATE_INTERNAL_LABEL (section_start_label
, FRAME_BEGIN_LABEL
, for_eh
);
780 ASM_OUTPUT_LABEL (asm_out_file
, section_start_label
);
782 /* Output the CIE. */
783 ASM_GENERATE_INTERNAL_LABEL (l1
, CIE_AFTER_SIZE_LABEL
, for_eh
);
784 ASM_GENERATE_INTERNAL_LABEL (l2
, CIE_END_LABEL
, for_eh
);
785 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4 && !for_eh
)
786 dw2_asm_output_data (4, 0xffffffff,
787 "Initial length escape value indicating 64-bit DWARF extension");
788 dw2_asm_output_delta (for_eh
? 4 : DWARF_OFFSET_SIZE
, l2
, l1
,
789 "Length of Common Information Entry");
790 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
792 /* Now that the CIE pointer is PC-relative for EH,
793 use 0 to identify the CIE. */
794 dw2_asm_output_data ((for_eh
? 4 : DWARF_OFFSET_SIZE
),
795 (for_eh
? 0 : DWARF_CIE_ID
),
796 "CIE Identifier Tag");
798 /* Use the CIE version 3 for DWARF3; allow DWARF2 to continue to
799 use CIE version 1, unless that would produce incorrect results
800 due to overflowing the return register column. */
801 return_reg
= DWARF2_FRAME_REG_OUT (DWARF_FRAME_RETURN_COLUMN
, for_eh
);
803 if (return_reg
>= 256 || dwarf_version
> 2)
805 dw2_asm_output_data (1, dw_cie_version
, "CIE Version");
808 augmentation_size
= 0;
810 personality
= current_unit_personality
;
816 z Indicates that a uleb128 is present to size the
817 augmentation section.
818 L Indicates the encoding (and thus presence) of
819 an LSDA pointer in the FDE augmentation.
820 R Indicates a non-default pointer encoding for
822 P Indicates the presence of an encoding + language
823 personality routine in the CIE augmentation. */
825 fde_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0);
826 per_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
827 lsda_encoding
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
829 p
= augmentation
+ 1;
833 augmentation_size
+= 1 + size_of_encoded_value (per_encoding
);
834 assemble_external_libcall (personality
);
839 augmentation_size
+= 1;
841 if (fde_encoding
!= DW_EH_PE_absptr
)
844 augmentation_size
+= 1;
846 if (p
> augmentation
+ 1)
848 augmentation
[0] = 'z';
852 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */
853 if (personality
&& per_encoding
== DW_EH_PE_aligned
)
855 int offset
= ( 4 /* Length */
857 + 1 /* CIE version */
858 + strlen (augmentation
) + 1 /* Augmentation */
859 + size_of_uleb128 (1) /* Code alignment */
860 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT
)
862 + 1 /* Augmentation size */
863 + 1 /* Personality encoding */ );
864 int pad
= -offset
& (PTR_SIZE
- 1);
866 augmentation_size
+= pad
;
868 /* Augmentations should be small, so there's scarce need to
869 iterate for a solution. Die if we exceed one uleb128 byte. */
870 gcc_assert (size_of_uleb128 (augmentation_size
) == 1);
874 dw2_asm_output_nstring (augmentation
, -1, "CIE Augmentation");
875 if (dw_cie_version
>= 4)
877 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "CIE Address Size");
878 dw2_asm_output_data (1, 0, "CIE Segment Size");
880 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor");
881 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT
,
882 "CIE Data Alignment Factor");
884 if (dw_cie_version
== 1)
885 dw2_asm_output_data (1, return_reg
, "CIE RA Column");
887 dw2_asm_output_data_uleb128 (return_reg
, "CIE RA Column");
891 dw2_asm_output_data_uleb128 (augmentation_size
, "Augmentation size");
894 dw2_asm_output_data (1, per_encoding
, "Personality (%s)",
895 eh_data_format_name (per_encoding
));
896 dw2_asm_output_encoded_addr_rtx (per_encoding
,
902 dw2_asm_output_data (1, lsda_encoding
, "LSDA Encoding (%s)",
903 eh_data_format_name (lsda_encoding
));
905 if (fde_encoding
!= DW_EH_PE_absptr
)
906 dw2_asm_output_data (1, fde_encoding
, "FDE Encoding (%s)",
907 eh_data_format_name (fde_encoding
));
910 FOR_EACH_VEC_ELT (*cie_cfi_vec
, i
, cfi
)
911 output_cfi (cfi
, NULL
, for_eh
);
913 /* Pad the CIE out to an address sized boundary. */
914 ASM_OUTPUT_ALIGN (asm_out_file
,
915 floor_log2 (for_eh
? PTR_SIZE
: DWARF2_ADDR_SIZE
));
916 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
918 /* Loop through all of the FDE's. */
919 FOR_EACH_VEC_ELT (*fde_vec
, i
, fde
)
923 /* Don't emit EH unwind info for leaf functions that don't need it. */
924 if (for_eh
&& !fde_needed_for_eh_p (fde
))
927 for (k
= 0; k
< (fde
->dw_fde_second_begin
? 2 : 1); k
++)
928 output_fde (fde
, for_eh
, k
, section_start_label
, fde_encoding
,
929 augmentation
, any_lsda_needed
, lsda_encoding
);
932 if (for_eh
&& targetm
.terminate_dw2_eh_frame_info
)
933 dw2_asm_output_data (4, 0, "End of Table");
935 /* Turn off app to make assembly quicker. */
940 /* Emit .cfi_startproc and .cfi_personality/.cfi_lsda if needed. */
943 dwarf2out_do_cfi_startproc (bool second
)
947 rtx personality
= get_personality_function (current_function_decl
);
949 fprintf (asm_out_file
, "\t.cfi_startproc\n");
953 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1);
956 /* ??? The GAS support isn't entirely consistent. We have to
957 handle indirect support ourselves, but PC-relative is done
958 in the assembler. Further, the assembler can't handle any
959 of the weirder relocation types. */
960 if (enc
& DW_EH_PE_indirect
)
961 ref
= dw2_force_const_mem (ref
, true);
963 fprintf (asm_out_file
, "\t.cfi_personality %#x,", enc
);
964 output_addr_const (asm_out_file
, ref
);
965 fputc ('\n', asm_out_file
);
968 if (crtl
->uses_eh_lsda
)
972 enc
= ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0);
973 ASM_GENERATE_INTERNAL_LABEL (lab
, second
? "LLSDAC" : "LLSDA",
974 current_function_funcdef_no
);
975 ref
= gen_rtx_SYMBOL_REF (Pmode
, lab
);
976 SYMBOL_REF_FLAGS (ref
) = SYMBOL_FLAG_LOCAL
;
978 if (enc
& DW_EH_PE_indirect
)
979 ref
= dw2_force_const_mem (ref
, true);
981 fprintf (asm_out_file
, "\t.cfi_lsda %#x,", enc
);
982 output_addr_const (asm_out_file
, ref
);
983 fputc ('\n', asm_out_file
);
987 /* Allocate CURRENT_FDE. Immediately initialize all we can, noting that
988 this allocation may be done before pass_final. */
991 dwarf2out_alloc_current_fde (void)
995 fde
= ggc_alloc_cleared_dw_fde_node ();
996 fde
->decl
= current_function_decl
;
997 fde
->funcdef_number
= current_function_funcdef_no
;
998 fde
->fde_index
= vec_safe_length (fde_vec
);
999 fde
->all_throwers_are_sibcalls
= crtl
->all_throwers_are_sibcalls
;
1000 fde
->uses_eh_lsda
= crtl
->uses_eh_lsda
;
1001 fde
->nothrow
= crtl
->nothrow
;
1002 fde
->drap_reg
= INVALID_REGNUM
;
1003 fde
->vdrap_reg
= INVALID_REGNUM
;
1005 /* Record the FDE associated with this function. */
1007 vec_safe_push (fde_vec
, fde
);
1012 /* Output a marker (i.e. a label) for the beginning of a function, before
1016 dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1017 const char *file ATTRIBUTE_UNUSED
)
1019 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1025 current_function_func_begin_label
= NULL
;
1027 do_frame
= dwarf2out_do_frame ();
1029 /* ??? current_function_func_begin_label is also used by except.c for
1030 call-site information. We must emit this label if it might be used. */
1032 && (!flag_exceptions
1033 || targetm_common
.except_unwind_info (&global_options
) == UI_SJLJ
))
1036 fnsec
= function_section (current_function_decl
);
1037 switch_to_section (fnsec
);
1038 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_BEGIN_LABEL
,
1039 current_function_funcdef_no
);
1040 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, FUNC_BEGIN_LABEL
,
1041 current_function_funcdef_no
);
1042 dup_label
= xstrdup (label
);
1043 current_function_func_begin_label
= dup_label
;
1045 /* We can elide the fde allocation if we're not emitting debug info. */
1049 /* Cater to the various TARGET_ASM_OUTPUT_MI_THUNK implementations that
1050 emit insns as rtx but bypass the bulk of rest_of_compilation, which
1051 would include pass_dwarf2_frame. If we've not created the FDE yet,
1055 fde
= dwarf2out_alloc_current_fde ();
1057 /* Initialize the bits of CURRENT_FDE that were not available earlier. */
1058 fde
->dw_fde_begin
= dup_label
;
1059 fde
->dw_fde_current_label
= dup_label
;
1060 fde
->in_std_section
= (fnsec
== text_section
1061 || (cold_text_section
&& fnsec
== cold_text_section
));
1063 /* We only want to output line number information for the genuine dwarf2
1064 prologue case, not the eh frame case. */
1065 #ifdef DWARF2_DEBUGGING_INFO
1067 dwarf2out_source_line (line
, file
, 0, true);
1070 if (dwarf2out_do_cfi_asm ())
1071 dwarf2out_do_cfi_startproc (false);
1074 rtx personality
= get_personality_function (current_function_decl
);
1075 if (!current_unit_personality
)
1076 current_unit_personality
= personality
;
1078 /* We cannot keep a current personality per function as without CFI
1079 asm, at the point where we emit the CFI data, there is no current
1080 function anymore. */
1081 if (personality
&& current_unit_personality
!= personality
)
1082 sorry ("multiple EH personalities are supported only with assemblers "
1083 "supporting .cfi_personality directive");
1087 /* Output a marker (i.e. a label) for the end of the generated code
1088 for a function prologue. This gets called *after* the prologue code has
1092 dwarf2out_vms_end_prologue (unsigned int line ATTRIBUTE_UNUSED
,
1093 const char *file ATTRIBUTE_UNUSED
)
1095 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1097 /* Output a label to mark the endpoint of the code generated for this
1099 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
1100 current_function_funcdef_no
);
1101 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, PROLOGUE_END_LABEL
,
1102 current_function_funcdef_no
);
1103 cfun
->fde
->dw_fde_vms_end_prologue
= xstrdup (label
);
1106 /* Output a marker (i.e. a label) for the beginning of the generated code
1107 for a function epilogue. This gets called *before* the prologue code has
1111 dwarf2out_vms_begin_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1112 const char *file ATTRIBUTE_UNUSED
)
1114 dw_fde_ref fde
= cfun
->fde
;
1115 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1117 if (fde
->dw_fde_vms_begin_epilogue
)
1120 /* Output a label to mark the endpoint of the code generated for this
1122 ASM_GENERATE_INTERNAL_LABEL (label
, EPILOGUE_BEGIN_LABEL
,
1123 current_function_funcdef_no
);
1124 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, EPILOGUE_BEGIN_LABEL
,
1125 current_function_funcdef_no
);
1126 fde
->dw_fde_vms_begin_epilogue
= xstrdup (label
);
1129 /* Output a marker (i.e. a label) for the absolute end of the generated code
1130 for a function definition. This gets called *after* the epilogue code has
1134 dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1135 const char *file ATTRIBUTE_UNUSED
)
1138 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
1140 last_var_location_insn
= NULL_RTX
;
1141 cached_next_real_insn
= NULL_RTX
;
1143 if (dwarf2out_do_cfi_asm ())
1144 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1146 /* Output a label to mark the endpoint of the code generated for this
1148 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
1149 current_function_funcdef_no
);
1150 ASM_OUTPUT_LABEL (asm_out_file
, label
);
1152 gcc_assert (fde
!= NULL
);
1153 if (fde
->dw_fde_second_begin
== NULL
)
1154 fde
->dw_fde_end
= xstrdup (label
);
1158 dwarf2out_frame_finish (void)
1160 /* Output call frame information. */
1161 if (targetm
.debug_unwind_info () == UI_DWARF2
)
1162 output_call_frame_info (0);
1164 /* Output another copy for the unwinder. */
1165 if ((flag_unwind_tables
|| flag_exceptions
)
1166 && targetm_common
.except_unwind_info (&global_options
) == UI_DWARF2
)
1167 output_call_frame_info (1);
1170 /* Note that the current function section is being used for code. */
1173 dwarf2out_note_section_used (void)
1175 section
*sec
= current_function_section ();
1176 if (sec
== text_section
)
1177 text_section_used
= true;
1178 else if (sec
== cold_text_section
)
1179 cold_text_section_used
= true;
1182 static void var_location_switch_text_section (void);
1183 static void set_cur_line_info_table (section
*);
1186 dwarf2out_switch_text_section (void)
1189 dw_fde_ref fde
= cfun
->fde
;
1191 gcc_assert (cfun
&& fde
&& fde
->dw_fde_second_begin
== NULL
);
1193 if (!in_cold_section_p
)
1195 fde
->dw_fde_end
= crtl
->subsections
.cold_section_end_label
;
1196 fde
->dw_fde_second_begin
= crtl
->subsections
.hot_section_label
;
1197 fde
->dw_fde_second_end
= crtl
->subsections
.hot_section_end_label
;
1201 fde
->dw_fde_end
= crtl
->subsections
.hot_section_end_label
;
1202 fde
->dw_fde_second_begin
= crtl
->subsections
.cold_section_label
;
1203 fde
->dw_fde_second_end
= crtl
->subsections
.cold_section_end_label
;
1205 have_multiple_function_sections
= true;
1207 /* There is no need to mark used sections when not debugging. */
1208 if (cold_text_section
!= NULL
)
1209 dwarf2out_note_section_used ();
1211 if (dwarf2out_do_cfi_asm ())
1212 fprintf (asm_out_file
, "\t.cfi_endproc\n");
1214 /* Now do the real section switch. */
1215 sect
= current_function_section ();
1216 switch_to_section (sect
);
1218 fde
->second_in_std_section
1219 = (sect
== text_section
1220 || (cold_text_section
&& sect
== cold_text_section
));
1222 if (dwarf2out_do_cfi_asm ())
1223 dwarf2out_do_cfi_startproc (true);
1225 var_location_switch_text_section ();
1227 if (cold_text_section
!= NULL
)
1228 set_cur_line_info_table (sect
);
1231 /* And now, the subset of the debugging information support code necessary
1232 for emitting location expressions. */
1234 /* Data about a single source file. */
1235 struct GTY(()) dwarf_file_data
{
1236 const char * filename
;
1240 typedef struct GTY(()) deferred_locations_struct
1244 } deferred_locations
;
1247 static GTY(()) vec
<deferred_locations
, va_gc
> *deferred_locations_list
;
1250 /* Describe an entry into the .debug_addr section. */
1254 ate_kind_rtx_dtprel
,
1258 typedef struct GTY(()) addr_table_entry_struct
{
1260 unsigned int refcount
;
1262 union addr_table_entry_struct_union
1264 rtx
GTY ((tag ("0"))) rtl
;
1265 char * GTY ((tag ("1"))) label
;
1267 GTY ((desc ("%1.kind"))) addr
;
1271 /* Location lists are ranges + location descriptions for that range,
1272 so you can track variables that are in different places over
1273 their entire life. */
1274 typedef struct GTY(()) dw_loc_list_struct
{
1275 dw_loc_list_ref dw_loc_next
;
1276 const char *begin
; /* Label and addr_entry for start of range */
1277 addr_table_entry
*begin_entry
;
1278 const char *end
; /* Label for end of range */
1279 char *ll_symbol
; /* Label for beginning of location list.
1280 Only on head of list */
1281 const char *section
; /* Section this loclist is relative to */
1282 dw_loc_descr_ref expr
;
1284 /* True if all addresses in this and subsequent lists are known to be
1287 /* True if this list has been replaced by dw_loc_next. */
1290 /* True if the range should be emitted even if begin and end
1295 static dw_loc_descr_ref
int_loc_descriptor (HOST_WIDE_INT
);
1297 /* Convert a DWARF stack opcode into its string name. */
1300 dwarf_stack_op_name (unsigned int op
)
1302 const char *name
= get_DW_OP_name (op
);
1307 return "OP_<unknown>";
1310 /* Return a pointer to a newly allocated location description. Location
1311 descriptions are simple expression terms that can be strung
1312 together to form more complicated location (address) descriptions. */
1314 static inline dw_loc_descr_ref
1315 new_loc_descr (enum dwarf_location_atom op
, unsigned HOST_WIDE_INT oprnd1
,
1316 unsigned HOST_WIDE_INT oprnd2
)
1318 dw_loc_descr_ref descr
= ggc_alloc_cleared_dw_loc_descr_node ();
1320 descr
->dw_loc_opc
= op
;
1321 descr
->dw_loc_oprnd1
.val_class
= dw_val_class_unsigned_const
;
1322 descr
->dw_loc_oprnd1
.val_entry
= NULL
;
1323 descr
->dw_loc_oprnd1
.v
.val_unsigned
= oprnd1
;
1324 descr
->dw_loc_oprnd2
.val_class
= dw_val_class_unsigned_const
;
1325 descr
->dw_loc_oprnd2
.val_entry
= NULL
;
1326 descr
->dw_loc_oprnd2
.v
.val_unsigned
= oprnd2
;
1331 /* Return a pointer to a newly allocated location description for
1334 static inline dw_loc_descr_ref
1335 new_reg_loc_descr (unsigned int reg
, unsigned HOST_WIDE_INT offset
)
1338 return new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ reg
),
1341 return new_loc_descr (DW_OP_bregx
, reg
, offset
);
1344 /* Add a location description term to a location description expression. */
1347 add_loc_descr (dw_loc_descr_ref
*list_head
, dw_loc_descr_ref descr
)
1349 dw_loc_descr_ref
*d
;
1351 /* Find the end of the chain. */
1352 for (d
= list_head
; (*d
) != NULL
; d
= &(*d
)->dw_loc_next
)
1358 /* Compare two location operands for exact equality. */
1361 dw_val_equal_p (dw_val_node
*a
, dw_val_node
*b
)
1363 if (a
->val_class
!= b
->val_class
)
1365 switch (a
->val_class
)
1367 case dw_val_class_none
:
1369 case dw_val_class_addr
:
1370 return rtx_equal_p (a
->v
.val_addr
, b
->v
.val_addr
);
1372 case dw_val_class_offset
:
1373 case dw_val_class_unsigned_const
:
1374 case dw_val_class_const
:
1375 case dw_val_class_range_list
:
1376 case dw_val_class_lineptr
:
1377 case dw_val_class_macptr
:
1378 /* These are all HOST_WIDE_INT, signed or unsigned. */
1379 return a
->v
.val_unsigned
== b
->v
.val_unsigned
;
1381 case dw_val_class_loc
:
1382 return a
->v
.val_loc
== b
->v
.val_loc
;
1383 case dw_val_class_loc_list
:
1384 return a
->v
.val_loc_list
== b
->v
.val_loc_list
;
1385 case dw_val_class_die_ref
:
1386 return a
->v
.val_die_ref
.die
== b
->v
.val_die_ref
.die
;
1387 case dw_val_class_fde_ref
:
1388 return a
->v
.val_fde_index
== b
->v
.val_fde_index
;
1389 case dw_val_class_lbl_id
:
1390 case dw_val_class_high_pc
:
1391 return strcmp (a
->v
.val_lbl_id
, b
->v
.val_lbl_id
) == 0;
1392 case dw_val_class_str
:
1393 return a
->v
.val_str
== b
->v
.val_str
;
1394 case dw_val_class_flag
:
1395 return a
->v
.val_flag
== b
->v
.val_flag
;
1396 case dw_val_class_file
:
1397 return a
->v
.val_file
== b
->v
.val_file
;
1398 case dw_val_class_decl_ref
:
1399 return a
->v
.val_decl_ref
== b
->v
.val_decl_ref
;
1401 case dw_val_class_const_double
:
1402 return (a
->v
.val_double
.high
== b
->v
.val_double
.high
1403 && a
->v
.val_double
.low
== b
->v
.val_double
.low
);
1405 case dw_val_class_wide_int
:
1406 return *a
->v
.val_wide
== *b
->v
.val_wide
;
1408 case dw_val_class_vec
:
1410 size_t a_len
= a
->v
.val_vec
.elt_size
* a
->v
.val_vec
.length
;
1411 size_t b_len
= b
->v
.val_vec
.elt_size
* b
->v
.val_vec
.length
;
1413 return (a_len
== b_len
1414 && !memcmp (a
->v
.val_vec
.array
, b
->v
.val_vec
.array
, a_len
));
1417 case dw_val_class_data8
:
1418 return memcmp (a
->v
.val_data8
, b
->v
.val_data8
, 8) == 0;
1420 case dw_val_class_vms_delta
:
1421 return (!strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
)
1422 && !strcmp (a
->v
.val_vms_delta
.lbl1
, b
->v
.val_vms_delta
.lbl1
));
1427 /* Compare two location atoms for exact equality. */
1430 loc_descr_equal_p_1 (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1432 if (a
->dw_loc_opc
!= b
->dw_loc_opc
)
1435 /* ??? This is only ever set for DW_OP_constNu, for N equal to the
1436 address size, but since we always allocate cleared storage it
1437 should be zero for other types of locations. */
1438 if (a
->dtprel
!= b
->dtprel
)
1441 return (dw_val_equal_p (&a
->dw_loc_oprnd1
, &b
->dw_loc_oprnd1
)
1442 && dw_val_equal_p (&a
->dw_loc_oprnd2
, &b
->dw_loc_oprnd2
));
1445 /* Compare two complete location expressions for exact equality. */
1448 loc_descr_equal_p (dw_loc_descr_ref a
, dw_loc_descr_ref b
)
1454 if (a
== NULL
|| b
== NULL
)
1456 if (!loc_descr_equal_p_1 (a
, b
))
1465 /* Add a constant OFFSET to a location expression. */
1468 loc_descr_plus_const (dw_loc_descr_ref
*list_head
, HOST_WIDE_INT offset
)
1470 dw_loc_descr_ref loc
;
1473 gcc_assert (*list_head
!= NULL
);
1478 /* Find the end of the chain. */
1479 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
1483 if (loc
->dw_loc_opc
== DW_OP_fbreg
1484 || (loc
->dw_loc_opc
>= DW_OP_breg0
&& loc
->dw_loc_opc
<= DW_OP_breg31
))
1485 p
= &loc
->dw_loc_oprnd1
.v
.val_int
;
1486 else if (loc
->dw_loc_opc
== DW_OP_bregx
)
1487 p
= &loc
->dw_loc_oprnd2
.v
.val_int
;
1489 /* If the last operation is fbreg, breg{0..31,x}, optimize by adjusting its
1490 offset. Don't optimize if an signed integer overflow would happen. */
1492 && ((offset
> 0 && *p
<= INTTYPE_MAXIMUM (HOST_WIDE_INT
) - offset
)
1493 || (offset
< 0 && *p
>= INTTYPE_MINIMUM (HOST_WIDE_INT
) - offset
)))
1496 else if (offset
> 0)
1497 loc
->dw_loc_next
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
1501 loc
->dw_loc_next
= int_loc_descriptor (-offset
);
1502 add_loc_descr (&loc
->dw_loc_next
, new_loc_descr (DW_OP_minus
, 0, 0));
1506 /* Add a constant OFFSET to a location list. */
1509 loc_list_plus_const (dw_loc_list_ref list_head
, HOST_WIDE_INT offset
)
1512 for (d
= list_head
; d
!= NULL
; d
= d
->dw_loc_next
)
1513 loc_descr_plus_const (&d
->expr
, offset
);
1516 #define DWARF_REF_SIZE \
1517 (dwarf_version == 2 ? DWARF2_ADDR_SIZE : DWARF_OFFSET_SIZE)
1519 static unsigned long int get_base_type_offset (dw_die_ref
);
1521 /* Return the size of a location descriptor. */
1523 static unsigned long
1524 size_of_loc_descr (dw_loc_descr_ref loc
)
1526 unsigned long size
= 1;
1528 switch (loc
->dw_loc_opc
)
1531 size
+= DWARF2_ADDR_SIZE
;
1533 case DW_OP_GNU_addr_index
:
1534 case DW_OP_GNU_const_index
:
1535 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1536 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
);
1555 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1558 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1563 case DW_OP_plus_uconst
:
1564 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1602 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1605 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1608 size
+= size_of_sleb128 (loc
->dw_loc_oprnd1
.v
.val_int
);
1611 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1612 size
+= size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1615 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1617 case DW_OP_bit_piece
:
1618 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1619 size
+= size_of_uleb128 (loc
->dw_loc_oprnd2
.v
.val_unsigned
);
1621 case DW_OP_deref_size
:
1622 case DW_OP_xderef_size
:
1631 case DW_OP_call_ref
:
1632 size
+= DWARF_REF_SIZE
;
1634 case DW_OP_implicit_value
:
1635 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1636 + loc
->dw_loc_oprnd1
.v
.val_unsigned
;
1638 case DW_OP_GNU_implicit_pointer
:
1639 size
+= DWARF_REF_SIZE
+ size_of_sleb128 (loc
->dw_loc_oprnd2
.v
.val_int
);
1641 case DW_OP_GNU_entry_value
:
1643 unsigned long op_size
= size_of_locs (loc
->dw_loc_oprnd1
.v
.val_loc
);
1644 size
+= size_of_uleb128 (op_size
) + op_size
;
1647 case DW_OP_GNU_const_type
:
1650 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1651 size
+= size_of_uleb128 (o
) + 1;
1652 switch (loc
->dw_loc_oprnd2
.val_class
)
1654 case dw_val_class_vec
:
1655 size
+= loc
->dw_loc_oprnd2
.v
.val_vec
.length
1656 * loc
->dw_loc_oprnd2
.v
.val_vec
.elt_size
;
1658 case dw_val_class_const
:
1659 size
+= HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
;
1661 case dw_val_class_const_double
:
1662 size
+= HOST_BITS_PER_DOUBLE_INT
/ BITS_PER_UNIT
;
1664 case dw_val_class_wide_int
:
1665 size
+= (get_full_len (*loc
->dw_loc_oprnd2
.v
.val_wide
)
1666 * HOST_BITS_PER_WIDE_INT
/ BITS_PER_UNIT
);
1673 case DW_OP_GNU_regval_type
:
1676 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1677 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
1678 + size_of_uleb128 (o
);
1681 case DW_OP_GNU_deref_type
:
1684 = get_base_type_offset (loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
);
1685 size
+= 1 + size_of_uleb128 (o
);
1688 case DW_OP_GNU_convert
:
1689 case DW_OP_GNU_reinterpret
:
1690 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
1691 size
+= size_of_uleb128 (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
1695 = get_base_type_offset (loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
);
1696 size
+= size_of_uleb128 (o
);
1699 case DW_OP_GNU_parameter_ref
:
1709 /* Return the size of a series of location descriptors. */
1712 size_of_locs (dw_loc_descr_ref loc
)
1717 /* If there are no skip or bra opcodes, don't fill in the dw_loc_addr
1718 field, to avoid writing to a PCH file. */
1719 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1721 if (l
->dw_loc_opc
== DW_OP_skip
|| l
->dw_loc_opc
== DW_OP_bra
)
1723 size
+= size_of_loc_descr (l
);
1728 for (size
= 0, l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
1730 l
->dw_loc_addr
= size
;
1731 size
+= size_of_loc_descr (l
);
1737 static HOST_WIDE_INT
extract_int (const unsigned char *, unsigned);
1738 static void get_ref_die_offset_label (char *, dw_die_ref
);
1739 static unsigned long int get_ref_die_offset (dw_die_ref
);
1741 /* Output location description stack opcode's operands (if any).
1742 The for_eh_or_skip parameter controls whether register numbers are
1743 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
1744 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
1745 info). This should be suppressed for the cases that have not been converted
1746 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
1749 output_loc_operands (dw_loc_descr_ref loc
, int for_eh_or_skip
)
1751 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
1752 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
1754 switch (loc
->dw_loc_opc
)
1756 #ifdef DWARF2_DEBUGGING_INFO
1759 dw2_asm_output_data (2, val1
->v
.val_int
, NULL
);
1764 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1765 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 4,
1767 fputc ('\n', asm_out_file
);
1772 dw2_asm_output_data (4, val1
->v
.val_int
, NULL
);
1777 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
1778 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
, 8,
1780 fputc ('\n', asm_out_file
);
1785 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
1786 dw2_asm_output_data (8, val1
->v
.val_int
, NULL
);
1793 gcc_assert (val1
->val_class
== dw_val_class_loc
);
1794 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
1796 dw2_asm_output_data (2, offset
, NULL
);
1799 case DW_OP_implicit_value
:
1800 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1801 switch (val2
->val_class
)
1803 case dw_val_class_const
:
1804 dw2_asm_output_data (val1
->v
.val_unsigned
, val2
->v
.val_int
, NULL
);
1806 case dw_val_class_vec
:
1808 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
1809 unsigned int len
= val2
->v
.val_vec
.length
;
1813 if (elt_size
> sizeof (HOST_WIDE_INT
))
1818 for (i
= 0, p
= val2
->v
.val_vec
.array
;
1821 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
1822 "fp or vector constant word %u", i
);
1825 case dw_val_class_const_double
:
1827 unsigned HOST_WIDE_INT first
, second
;
1829 if (WORDS_BIG_ENDIAN
)
1831 first
= val2
->v
.val_double
.high
;
1832 second
= val2
->v
.val_double
.low
;
1836 first
= val2
->v
.val_double
.low
;
1837 second
= val2
->v
.val_double
.high
;
1839 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1841 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1845 case dw_val_class_wide_int
:
1848 int len
= get_full_len (*val2
->v
.val_wide
);
1849 if (WORDS_BIG_ENDIAN
)
1850 for (i
= len
; i
>= 0; --i
)
1851 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1852 val2
->v
.val_wide
->elt (i
), NULL
);
1854 for (i
= 0; i
< len
; ++i
)
1855 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
1856 val2
->v
.val_wide
->elt (i
), NULL
);
1859 case dw_val_class_addr
:
1860 gcc_assert (val1
->v
.val_unsigned
== DWARF2_ADDR_SIZE
);
1861 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val2
->v
.val_addr
, NULL
);
1876 case DW_OP_implicit_value
:
1877 /* We currently don't make any attempt to make sure these are
1878 aligned properly like we do for the main unwind info, so
1879 don't support emitting things larger than a byte if we're
1880 only doing unwinding. */
1885 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1888 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1891 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1894 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1896 case DW_OP_plus_uconst
:
1897 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1931 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1935 unsigned r
= val1
->v
.val_unsigned
;
1936 if (for_eh_or_skip
>= 0)
1937 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1938 gcc_assert (size_of_uleb128 (r
)
1939 == size_of_uleb128 (val1
->v
.val_unsigned
));
1940 dw2_asm_output_data_uleb128 (r
, NULL
);
1944 dw2_asm_output_data_sleb128 (val1
->v
.val_int
, NULL
);
1948 unsigned r
= val1
->v
.val_unsigned
;
1949 if (for_eh_or_skip
>= 0)
1950 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
1951 gcc_assert (size_of_uleb128 (r
)
1952 == size_of_uleb128 (val1
->v
.val_unsigned
));
1953 dw2_asm_output_data_uleb128 (r
, NULL
);
1954 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
1958 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1960 case DW_OP_bit_piece
:
1961 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
1962 dw2_asm_output_data_uleb128 (val2
->v
.val_unsigned
, NULL
);
1964 case DW_OP_deref_size
:
1965 case DW_OP_xderef_size
:
1966 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
1972 if (targetm
.asm_out
.output_dwarf_dtprel
)
1974 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
1977 fputc ('\n', asm_out_file
);
1984 #ifdef DWARF2_DEBUGGING_INFO
1985 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, val1
->v
.val_addr
, NULL
);
1992 case DW_OP_GNU_addr_index
:
1993 case DW_OP_GNU_const_index
:
1994 gcc_assert (loc
->dw_loc_oprnd1
.val_entry
->index
!= NO_INDEX_ASSIGNED
);
1995 dw2_asm_output_data_uleb128 (loc
->dw_loc_oprnd1
.val_entry
->index
,
1996 "(index into .debug_addr)");
1999 case DW_OP_GNU_implicit_pointer
:
2001 char label
[MAX_ARTIFICIAL_LABEL_BYTES
2002 + HOST_BITS_PER_WIDE_INT
/ 2 + 2];
2003 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2004 get_ref_die_offset_label (label
, val1
->v
.val_die_ref
.die
);
2005 dw2_asm_output_offset (DWARF_REF_SIZE
, label
, debug_info_section
, NULL
);
2006 dw2_asm_output_data_sleb128 (val2
->v
.val_int
, NULL
);
2010 case DW_OP_GNU_entry_value
:
2011 dw2_asm_output_data_uleb128 (size_of_locs (val1
->v
.val_loc
), NULL
);
2012 output_loc_sequence (val1
->v
.val_loc
, for_eh_or_skip
);
2015 case DW_OP_GNU_const_type
:
2017 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
), l
;
2019 dw2_asm_output_data_uleb128 (o
, NULL
);
2020 switch (val2
->val_class
)
2022 case dw_val_class_const
:
2023 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2024 dw2_asm_output_data (1, l
, NULL
);
2025 dw2_asm_output_data (l
, val2
->v
.val_int
, NULL
);
2027 case dw_val_class_vec
:
2029 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
2030 unsigned int len
= val2
->v
.val_vec
.length
;
2035 dw2_asm_output_data (1, l
, NULL
);
2036 if (elt_size
> sizeof (HOST_WIDE_INT
))
2041 for (i
= 0, p
= val2
->v
.val_vec
.array
;
2044 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
2045 "fp or vector constant word %u", i
);
2048 case dw_val_class_const_double
:
2050 unsigned HOST_WIDE_INT first
, second
;
2051 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2053 dw2_asm_output_data (1, 2 * l
, NULL
);
2054 if (WORDS_BIG_ENDIAN
)
2056 first
= val2
->v
.val_double
.high
;
2057 second
= val2
->v
.val_double
.low
;
2061 first
= val2
->v
.val_double
.low
;
2062 second
= val2
->v
.val_double
.high
;
2064 dw2_asm_output_data (l
, first
, NULL
);
2065 dw2_asm_output_data (l
, second
, NULL
);
2068 case dw_val_class_wide_int
:
2071 int len
= get_full_len (*val2
->v
.val_wide
);
2072 l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
2074 dw2_asm_output_data (1, len
* l
, NULL
);
2075 if (WORDS_BIG_ENDIAN
)
2076 for (i
= len
; i
>= 0; --i
)
2077 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2079 for (i
= 0; i
< len
; ++i
)
2080 dw2_asm_output_data (l
, val2
->v
.val_wide
->elt (i
), NULL
);
2088 case DW_OP_GNU_regval_type
:
2090 unsigned r
= val1
->v
.val_unsigned
;
2091 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2093 if (for_eh_or_skip
>= 0)
2095 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2096 gcc_assert (size_of_uleb128 (r
)
2097 == size_of_uleb128 (val1
->v
.val_unsigned
));
2099 dw2_asm_output_data_uleb128 (r
, NULL
);
2100 dw2_asm_output_data_uleb128 (o
, NULL
);
2103 case DW_OP_GNU_deref_type
:
2105 unsigned long o
= get_base_type_offset (val2
->v
.val_die_ref
.die
);
2107 dw2_asm_output_data (1, val1
->v
.val_int
, NULL
);
2108 dw2_asm_output_data_uleb128 (o
, NULL
);
2111 case DW_OP_GNU_convert
:
2112 case DW_OP_GNU_reinterpret
:
2113 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
2114 dw2_asm_output_data_uleb128 (val1
->v
.val_unsigned
, NULL
);
2117 unsigned long o
= get_base_type_offset (val1
->v
.val_die_ref
.die
);
2119 dw2_asm_output_data_uleb128 (o
, NULL
);
2123 case DW_OP_GNU_parameter_ref
:
2126 gcc_assert (val1
->val_class
== dw_val_class_die_ref
);
2127 o
= get_ref_die_offset (val1
->v
.val_die_ref
.die
);
2128 dw2_asm_output_data (4, o
, NULL
);
2133 /* Other codes have no operands. */
2138 /* Output a sequence of location operations.
2139 The for_eh_or_skip parameter controls whether register numbers are
2140 converted using DWARF2_FRAME_REG_OUT, which is needed in the case that
2141 hard reg numbers have been processed via DWARF_FRAME_REGNUM (i.e. for unwind
2142 info). This should be suppressed for the cases that have not been converted
2143 (i.e. symbolic debug info), by setting the parameter < 0. See PR47324. */
2146 output_loc_sequence (dw_loc_descr_ref loc
, int for_eh_or_skip
)
2148 for (; loc
!= NULL
; loc
= loc
->dw_loc_next
)
2150 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2151 /* Output the opcode. */
2152 if (for_eh_or_skip
>= 0
2153 && opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2155 unsigned r
= (opc
- DW_OP_breg0
);
2156 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2157 gcc_assert (r
<= 31);
2158 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2160 else if (for_eh_or_skip
>= 0
2161 && opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2163 unsigned r
= (opc
- DW_OP_reg0
);
2164 r
= DWARF2_FRAME_REG_OUT (r
, for_eh_or_skip
);
2165 gcc_assert (r
<= 31);
2166 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2169 dw2_asm_output_data (1, opc
,
2170 "%s", dwarf_stack_op_name (opc
));
2172 /* Output the operand(s) (if any). */
2173 output_loc_operands (loc
, for_eh_or_skip
);
2177 /* Output location description stack opcode's operands (if any).
2178 The output is single bytes on a line, suitable for .cfi_escape. */
2181 output_loc_operands_raw (dw_loc_descr_ref loc
)
2183 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
2184 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
2186 switch (loc
->dw_loc_opc
)
2189 case DW_OP_GNU_addr_index
:
2190 case DW_OP_GNU_const_index
:
2191 case DW_OP_implicit_value
:
2192 /* We cannot output addresses in .cfi_escape, only bytes. */
2198 case DW_OP_deref_size
:
2199 case DW_OP_xderef_size
:
2200 fputc (',', asm_out_file
);
2201 dw2_asm_output_data_raw (1, val1
->v
.val_int
);
2206 fputc (',', asm_out_file
);
2207 dw2_asm_output_data_raw (2, val1
->v
.val_int
);
2212 fputc (',', asm_out_file
);
2213 dw2_asm_output_data_raw (4, val1
->v
.val_int
);
2218 gcc_assert (HOST_BITS_PER_WIDE_INT
>= 64);
2219 fputc (',', asm_out_file
);
2220 dw2_asm_output_data_raw (8, val1
->v
.val_int
);
2228 gcc_assert (val1
->val_class
== dw_val_class_loc
);
2229 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
2231 fputc (',', asm_out_file
);
2232 dw2_asm_output_data_raw (2, offset
);
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
);
2247 case DW_OP_plus_uconst
:
2249 fputc (',', asm_out_file
);
2250 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2253 case DW_OP_bit_piece
:
2254 fputc (',', asm_out_file
);
2255 dw2_asm_output_data_uleb128_raw (val1
->v
.val_unsigned
);
2256 dw2_asm_output_data_uleb128_raw (val2
->v
.val_unsigned
);
2293 fputc (',', asm_out_file
);
2294 dw2_asm_output_data_sleb128_raw (val1
->v
.val_int
);
2299 unsigned r
= DWARF2_FRAME_REG_OUT (val1
->v
.val_unsigned
, 1);
2300 gcc_assert (size_of_uleb128 (r
)
2301 == size_of_uleb128 (val1
->v
.val_unsigned
));
2302 fputc (',', asm_out_file
);
2303 dw2_asm_output_data_uleb128_raw (r
);
2304 fputc (',', asm_out_file
);
2305 dw2_asm_output_data_sleb128_raw (val2
->v
.val_int
);
2309 case DW_OP_GNU_implicit_pointer
:
2310 case DW_OP_GNU_entry_value
:
2311 case DW_OP_GNU_const_type
:
2312 case DW_OP_GNU_regval_type
:
2313 case DW_OP_GNU_deref_type
:
2314 case DW_OP_GNU_convert
:
2315 case DW_OP_GNU_reinterpret
:
2316 case DW_OP_GNU_parameter_ref
:
2321 /* Other codes have no operands. */
2327 output_loc_sequence_raw (dw_loc_descr_ref loc
)
2331 enum dwarf_location_atom opc
= loc
->dw_loc_opc
;
2332 /* Output the opcode. */
2333 if (opc
>= DW_OP_breg0
&& opc
<= DW_OP_breg31
)
2335 unsigned r
= (opc
- DW_OP_breg0
);
2336 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2337 gcc_assert (r
<= 31);
2338 opc
= (enum dwarf_location_atom
) (DW_OP_breg0
+ r
);
2340 else if (opc
>= DW_OP_reg0
&& opc
<= DW_OP_reg31
)
2342 unsigned r
= (opc
- DW_OP_reg0
);
2343 r
= DWARF2_FRAME_REG_OUT (r
, 1);
2344 gcc_assert (r
<= 31);
2345 opc
= (enum dwarf_location_atom
) (DW_OP_reg0
+ r
);
2347 /* Output the opcode. */
2348 fprintf (asm_out_file
, "%#x", opc
);
2349 output_loc_operands_raw (loc
);
2351 if (!loc
->dw_loc_next
)
2353 loc
= loc
->dw_loc_next
;
2355 fputc (',', asm_out_file
);
2359 /* This function builds a dwarf location descriptor sequence from a
2360 dw_cfa_location, adding the given OFFSET to the result of the
2363 struct dw_loc_descr_node
*
2364 build_cfa_loc (dw_cfa_location
*cfa
, HOST_WIDE_INT offset
)
2366 struct dw_loc_descr_node
*head
, *tmp
;
2368 offset
+= cfa
->offset
;
2372 head
= new_reg_loc_descr (cfa
->reg
, cfa
->base_offset
);
2373 head
->dw_loc_oprnd1
.val_class
= dw_val_class_const
;
2374 head
->dw_loc_oprnd1
.val_entry
= NULL
;
2375 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
2376 add_loc_descr (&head
, tmp
);
2379 tmp
= new_loc_descr (DW_OP_plus_uconst
, offset
, 0);
2380 add_loc_descr (&head
, tmp
);
2384 head
= new_reg_loc_descr (cfa
->reg
, offset
);
2389 /* This function builds a dwarf location descriptor sequence for
2390 the address at OFFSET from the CFA when stack is aligned to
2393 struct dw_loc_descr_node
*
2394 build_cfa_aligned_loc (dw_cfa_location
*cfa
,
2395 HOST_WIDE_INT offset
, HOST_WIDE_INT alignment
)
2397 struct dw_loc_descr_node
*head
;
2398 unsigned int dwarf_fp
2399 = DWARF_FRAME_REGNUM (HARD_FRAME_POINTER_REGNUM
);
2401 /* When CFA is defined as FP+OFFSET, emulate stack alignment. */
2402 if (cfa
->reg
== HARD_FRAME_POINTER_REGNUM
&& cfa
->indirect
== 0)
2404 head
= new_reg_loc_descr (dwarf_fp
, 0);
2405 add_loc_descr (&head
, int_loc_descriptor (alignment
));
2406 add_loc_descr (&head
, new_loc_descr (DW_OP_and
, 0, 0));
2407 loc_descr_plus_const (&head
, offset
);
2410 head
= new_reg_loc_descr (dwarf_fp
, offset
);
2414 /* And now, the support for symbolic debugging information. */
2416 /* .debug_str support. */
2417 static int output_indirect_string (void **, void *);
2419 static void dwarf2out_init (const char *);
2420 static void dwarf2out_finish (const char *);
2421 static void dwarf2out_assembly_start (void);
2422 static void dwarf2out_define (unsigned int, const char *);
2423 static void dwarf2out_undef (unsigned int, const char *);
2424 static void dwarf2out_start_source_file (unsigned, const char *);
2425 static void dwarf2out_end_source_file (unsigned);
2426 static void dwarf2out_function_decl (tree
);
2427 static void dwarf2out_begin_block (unsigned, unsigned);
2428 static void dwarf2out_end_block (unsigned, unsigned);
2429 static bool dwarf2out_ignore_block (const_tree
);
2430 static void dwarf2out_global_decl (tree
);
2431 static void dwarf2out_type_decl (tree
, int);
2432 static void dwarf2out_imported_module_or_decl (tree
, tree
, tree
, bool);
2433 static void dwarf2out_imported_module_or_decl_1 (tree
, tree
, tree
,
2435 static void dwarf2out_abstract_function (tree
);
2436 static void dwarf2out_var_location (rtx
);
2437 static void dwarf2out_begin_function (tree
);
2438 static void dwarf2out_end_function (unsigned int);
2439 static void dwarf2out_set_name (tree
, tree
);
2441 /* The debug hooks structure. */
2443 const struct gcc_debug_hooks dwarf2_debug_hooks
=
2447 dwarf2out_assembly_start
,
2450 dwarf2out_start_source_file
,
2451 dwarf2out_end_source_file
,
2452 dwarf2out_begin_block
,
2453 dwarf2out_end_block
,
2454 dwarf2out_ignore_block
,
2455 dwarf2out_source_line
,
2456 dwarf2out_begin_prologue
,
2457 #if VMS_DEBUGGING_INFO
2458 dwarf2out_vms_end_prologue
,
2459 dwarf2out_vms_begin_epilogue
,
2461 debug_nothing_int_charstar
,
2462 debug_nothing_int_charstar
,
2464 dwarf2out_end_epilogue
,
2465 dwarf2out_begin_function
,
2466 dwarf2out_end_function
, /* end_function */
2467 dwarf2out_function_decl
, /* function_decl */
2468 dwarf2out_global_decl
,
2469 dwarf2out_type_decl
, /* type_decl */
2470 dwarf2out_imported_module_or_decl
,
2471 debug_nothing_tree
, /* deferred_inline_function */
2472 /* The DWARF 2 backend tries to reduce debugging bloat by not
2473 emitting the abstract description of inline functions until
2474 something tries to reference them. */
2475 dwarf2out_abstract_function
, /* outlining_inline_function */
2476 debug_nothing_rtx
, /* label */
2477 debug_nothing_int
, /* handle_pch */
2478 dwarf2out_var_location
,
2479 dwarf2out_switch_text_section
,
2481 1, /* start_end_main_source_file */
2482 TYPE_SYMTAB_IS_DIE
/* tree_type_symtab_field */
2485 /* NOTE: In the comments in this file, many references are made to
2486 "Debugging Information Entries". This term is abbreviated as `DIE'
2487 throughout the remainder of this file. */
2489 /* An internal representation of the DWARF output is built, and then
2490 walked to generate the DWARF debugging info. The walk of the internal
2491 representation is done after the entire program has been compiled.
2492 The types below are used to describe the internal representation. */
2494 /* Whether to put type DIEs into their own section .debug_types instead
2495 of making them part of the .debug_info section. Only supported for
2496 Dwarf V4 or higher and the user didn't disable them through
2497 -fno-debug-types-section. It is more efficient to put them in a
2498 separate comdat sections since the linker will then be able to
2499 remove duplicates. But not all tools support .debug_types sections
2502 #define use_debug_types (dwarf_version >= 4 && flag_debug_types_section)
2504 /* Various DIE's use offsets relative to the beginning of the
2505 .debug_info section to refer to each other. */
2507 typedef long int dw_offset
;
2509 /* Define typedefs here to avoid circular dependencies. */
2511 typedef struct dw_attr_struct
*dw_attr_ref
;
2512 typedef struct dw_line_info_struct
*dw_line_info_ref
;
2513 typedef struct pubname_struct
*pubname_ref
;
2514 typedef struct dw_ranges_struct
*dw_ranges_ref
;
2515 typedef struct dw_ranges_by_label_struct
*dw_ranges_by_label_ref
;
2516 typedef struct comdat_type_struct
*comdat_type_node_ref
;
2518 /* The entries in the line_info table more-or-less mirror the opcodes
2519 that are used in the real dwarf line table. Arrays of these entries
2520 are collected per section when DWARF2_ASM_LINE_DEBUG_INFO is not
2523 enum dw_line_info_opcode
{
2524 /* Emit DW_LNE_set_address; the operand is the label index. */
2527 /* Emit a row to the matrix with the given line. This may be done
2528 via any combination of DW_LNS_copy, DW_LNS_advance_line, and
2532 /* Emit a DW_LNS_set_file. */
2535 /* Emit a DW_LNS_set_column. */
2538 /* Emit a DW_LNS_negate_stmt; the operand is ignored. */
2541 /* Emit a DW_LNS_set_prologue_end/epilogue_begin; the operand is ignored. */
2542 LI_set_prologue_end
,
2543 LI_set_epilogue_begin
,
2545 /* Emit a DW_LNE_set_discriminator. */
2546 LI_set_discriminator
2549 typedef struct GTY(()) dw_line_info_struct
{
2550 enum dw_line_info_opcode opcode
;
2552 } dw_line_info_entry
;
2555 typedef struct GTY(()) dw_line_info_table_struct
{
2556 /* The label that marks the end of this section. */
2557 const char *end_label
;
2559 /* The values for the last row of the matrix, as collected in the table.
2560 These are used to minimize the changes to the next row. */
2561 unsigned int file_num
;
2562 unsigned int line_num
;
2563 unsigned int column_num
;
2568 vec
<dw_line_info_entry
, va_gc
> *entries
;
2569 } dw_line_info_table
;
2571 typedef dw_line_info_table
*dw_line_info_table_p
;
2574 /* Each DIE attribute has a field specifying the attribute kind,
2575 a link to the next attribute in the chain, and an attribute value.
2576 Attributes are typically linked below the DIE they modify. */
2578 typedef struct GTY(()) dw_attr_struct
{
2579 enum dwarf_attribute dw_attr
;
2580 dw_val_node dw_attr_val
;
2585 /* The Debugging Information Entry (DIE) structure. DIEs form a tree.
2586 The children of each node form a circular list linked by
2587 die_sib. die_child points to the node *before* the "first" child node. */
2589 typedef struct GTY((chain_circular ("%h.die_sib"))) die_struct
{
2590 union die_symbol_or_type_node
2592 const char * GTY ((tag ("0"))) die_symbol
;
2593 comdat_type_node_ref
GTY ((tag ("1"))) die_type_node
;
2595 GTY ((desc ("%0.comdat_type_p"))) die_id
;
2596 vec
<dw_attr_node
, va_gc
> *die_attr
;
2597 dw_die_ref die_parent
;
2598 dw_die_ref die_child
;
2600 dw_die_ref die_definition
; /* ref from a specification to its definition */
2601 dw_offset die_offset
;
2602 unsigned long die_abbrev
;
2604 unsigned int decl_id
;
2605 enum dwarf_tag die_tag
;
2606 /* Die is used and must not be pruned as unused. */
2607 BOOL_BITFIELD die_perennial_p
: 1;
2608 BOOL_BITFIELD comdat_type_p
: 1; /* DIE has a type signature */
2609 /* Lots of spare bits. */
2613 /* Evaluate 'expr' while 'c' is set to each child of DIE in order. */
2614 #define FOR_EACH_CHILD(die, c, expr) do { \
2615 c = die->die_child; \
2619 } while (c != die->die_child); \
2622 /* The pubname structure */
2624 typedef struct GTY(()) pubname_struct
{
2631 struct GTY(()) dw_ranges_struct
{
2632 /* If this is positive, it's a block number, otherwise it's a
2633 bitwise-negated index into dw_ranges_by_label. */
2637 /* A structure to hold a macinfo entry. */
2639 typedef struct GTY(()) macinfo_struct
{
2641 unsigned HOST_WIDE_INT lineno
;
2647 struct GTY(()) dw_ranges_by_label_struct
{
2652 /* The comdat type node structure. */
2653 typedef struct GTY(()) comdat_type_struct
2655 dw_die_ref root_die
;
2656 dw_die_ref type_die
;
2657 dw_die_ref skeleton_die
;
2658 char signature
[DWARF_TYPE_SIGNATURE_SIZE
];
2659 struct comdat_type_struct
*next
;
2663 /* The limbo die list structure. */
2664 typedef struct GTY(()) limbo_die_struct
{
2667 struct limbo_die_struct
*next
;
2671 typedef struct skeleton_chain_struct
2675 struct skeleton_chain_struct
*parent
;
2677 skeleton_chain_node
;
2679 /* Define a macro which returns nonzero for a TYPE_DECL which was
2680 implicitly generated for a type.
2682 Note that, unlike the C front-end (which generates a NULL named
2683 TYPE_DECL node for each complete tagged type, each array type,
2684 and each function type node created) the C++ front-end generates
2685 a _named_ TYPE_DECL node for each tagged type node created.
2686 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to
2687 generate a DW_TAG_typedef DIE for them. Likewise with the Ada
2688 front-end, but for each type, tagged or not. */
2690 #define TYPE_DECL_IS_STUB(decl) \
2691 (DECL_NAME (decl) == NULL_TREE \
2692 || (DECL_ARTIFICIAL (decl) \
2693 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \
2694 /* This is necessary for stub decls that \
2695 appear in nested inline functions. */ \
2696 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \
2697 && (decl_ultimate_origin (decl) \
2698 == TYPE_STUB_DECL (TREE_TYPE (decl)))))))
2700 /* Information concerning the compilation unit's programming
2701 language, and compiler version. */
2703 /* Fixed size portion of the DWARF compilation unit header. */
2704 #define DWARF_COMPILE_UNIT_HEADER_SIZE \
2705 (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 3)
2707 /* Fixed size portion of the DWARF comdat type unit header. */
2708 #define DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE \
2709 (DWARF_COMPILE_UNIT_HEADER_SIZE + DWARF_TYPE_SIGNATURE_SIZE \
2710 + DWARF_OFFSET_SIZE)
2712 /* Fixed size portion of public names info. */
2713 #define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2)
2715 /* Fixed size portion of the address range info. */
2716 #define DWARF_ARANGES_HEADER_SIZE \
2717 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2718 DWARF2_ADDR_SIZE * 2) \
2719 - DWARF_INITIAL_LENGTH_SIZE)
2721 /* Size of padding portion in the address range info. It must be
2722 aligned to twice the pointer size. */
2723 #define DWARF_ARANGES_PAD_SIZE \
2724 (DWARF_ROUND (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4, \
2725 DWARF2_ADDR_SIZE * 2) \
2726 - (DWARF_INITIAL_LENGTH_SIZE + DWARF_OFFSET_SIZE + 4))
2728 /* Use assembler line directives if available. */
2729 #ifndef DWARF2_ASM_LINE_DEBUG_INFO
2730 #ifdef HAVE_AS_DWARF2_DEBUG_LINE
2731 #define DWARF2_ASM_LINE_DEBUG_INFO 1
2733 #define DWARF2_ASM_LINE_DEBUG_INFO 0
2737 /* Minimum line offset in a special line info. opcode.
2738 This value was chosen to give a reasonable range of values. */
2739 #define DWARF_LINE_BASE -10
2741 /* First special line opcode - leave room for the standard opcodes. */
2742 #define DWARF_LINE_OPCODE_BASE ((int)DW_LNS_set_isa + 1)
2744 /* Range of line offsets in a special line info. opcode. */
2745 #define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1)
2747 /* Flag that indicates the initial value of the is_stmt_start flag.
2748 In the present implementation, we do not mark any lines as
2749 the beginning of a source statement, because that information
2750 is not made available by the GCC front-end. */
2751 #define DWARF_LINE_DEFAULT_IS_STMT_START 1
2753 /* Maximum number of operations per instruction bundle. */
2754 #ifndef DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
2755 #define DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN 1
2758 /* This location is used by calc_die_sizes() to keep track
2759 the offset of each DIE within the .debug_info section. */
2760 static unsigned long next_die_offset
;
2762 /* Record the root of the DIE's built for the current compilation unit. */
2763 static GTY(()) dw_die_ref single_comp_unit_die
;
2765 /* A list of type DIEs that have been separated into comdat sections. */
2766 static GTY(()) comdat_type_node
*comdat_type_list
;
2768 /* A list of DIEs with a NULL parent waiting to be relocated. */
2769 static GTY(()) limbo_die_node
*limbo_die_list
;
2771 /* A list of DIEs for which we may have to generate
2772 DW_AT_{,MIPS_}linkage_name once their DECL_ASSEMBLER_NAMEs are set. */
2773 static GTY(()) limbo_die_node
*deferred_asm_name
;
2775 /* Filenames referenced by this compilation unit. */
2776 static GTY((param_is (struct dwarf_file_data
))) htab_t file_table
;
2778 /* A hash table of references to DIE's that describe declarations.
2779 The key is a DECL_UID() which is a unique number identifying each decl. */
2780 static GTY ((param_is (struct die_struct
))) htab_t decl_die_table
;
2782 /* A hash table of references to DIE's that describe COMMON blocks.
2783 The key is DECL_UID() ^ die_parent. */
2784 static GTY ((param_is (struct die_struct
))) htab_t common_block_die_table
;
2786 typedef struct GTY(()) die_arg_entry_struct
{
2792 /* Node of the variable location list. */
2793 struct GTY ((chain_next ("%h.next"))) var_loc_node
{
2794 /* Either NOTE_INSN_VAR_LOCATION, or, for SRA optimized variables,
2795 EXPR_LIST chain. For small bitsizes, bitsize is encoded
2796 in mode of the EXPR_LIST node and first EXPR_LIST operand
2797 is either NOTE_INSN_VAR_LOCATION for a piece with a known
2798 location or NULL for padding. For larger bitsizes,
2799 mode is 0 and first operand is a CONCAT with bitsize
2800 as first CONCAT operand and NOTE_INSN_VAR_LOCATION resp.
2801 NULL as second operand. */
2803 const char * GTY (()) label
;
2804 struct var_loc_node
* GTY (()) next
;
2807 /* Variable location list. */
2808 struct GTY (()) var_loc_list_def
{
2809 struct var_loc_node
* GTY (()) first
;
2811 /* Pointer to the last but one or last element of the
2812 chained list. If the list is empty, both first and
2813 last are NULL, if the list contains just one node
2814 or the last node certainly is not redundant, it points
2815 to the last node, otherwise points to the last but one.
2816 Do not mark it for GC because it is marked through the chain. */
2817 struct var_loc_node
* GTY ((skip ("%h"))) last
;
2819 /* Pointer to the last element before section switch,
2820 if NULL, either sections weren't switched or first
2821 is after section switch. */
2822 struct var_loc_node
* GTY ((skip ("%h"))) last_before_switch
;
2824 /* DECL_UID of the variable decl. */
2825 unsigned int decl_id
;
2827 typedef struct var_loc_list_def var_loc_list
;
2829 /* Call argument location list. */
2830 struct GTY ((chain_next ("%h.next"))) call_arg_loc_node
{
2831 rtx
GTY (()) call_arg_loc_note
;
2832 const char * GTY (()) label
;
2833 tree
GTY (()) block
;
2835 rtx
GTY (()) symbol_ref
;
2836 struct call_arg_loc_node
* GTY (()) next
;
2840 /* Table of decl location linked lists. */
2841 static GTY ((param_is (var_loc_list
))) htab_t decl_loc_table
;
2843 /* Head and tail of call_arg_loc chain. */
2844 static GTY (()) struct call_arg_loc_node
*call_arg_locations
;
2845 static struct call_arg_loc_node
*call_arg_loc_last
;
2847 /* Number of call sites in the current function. */
2848 static int call_site_count
= -1;
2849 /* Number of tail call sites in the current function. */
2850 static int tail_call_site_count
= -1;
2852 /* Vector mapping block numbers to DW_TAG_{lexical_block,inlined_subroutine}
2854 static vec
<dw_die_ref
> block_map
;
2856 /* A cached location list. */
2857 struct GTY (()) cached_dw_loc_list_def
{
2858 /* The DECL_UID of the decl that this entry describes. */
2859 unsigned int decl_id
;
2861 /* The cached location list. */
2862 dw_loc_list_ref loc_list
;
2864 typedef struct cached_dw_loc_list_def cached_dw_loc_list
;
2866 /* Table of cached location lists. */
2867 static GTY ((param_is (cached_dw_loc_list
))) htab_t cached_dw_loc_list_table
;
2869 /* A pointer to the base of a list of references to DIE's that
2870 are uniquely identified by their tag, presence/absence of
2871 children DIE's, and list of attribute/value pairs. */
2872 static GTY((length ("abbrev_die_table_allocated")))
2873 dw_die_ref
*abbrev_die_table
;
2875 /* Number of elements currently allocated for abbrev_die_table. */
2876 static GTY(()) unsigned abbrev_die_table_allocated
;
2878 /* Number of elements in type_die_table currently in use. */
2879 static GTY(()) unsigned abbrev_die_table_in_use
;
2881 /* Size (in elements) of increments by which we may expand the
2882 abbrev_die_table. */
2883 #define ABBREV_DIE_TABLE_INCREMENT 256
2885 /* A global counter for generating labels for line number data. */
2886 static unsigned int line_info_label_num
;
2888 /* The current table to which we should emit line number information
2889 for the current function. This will be set up at the beginning of
2890 assembly for the function. */
2891 static dw_line_info_table
*cur_line_info_table
;
2893 /* The two default tables of line number info. */
2894 static GTY(()) dw_line_info_table
*text_section_line_info
;
2895 static GTY(()) dw_line_info_table
*cold_text_section_line_info
;
2897 /* The set of all non-default tables of line number info. */
2898 static GTY(()) vec
<dw_line_info_table_p
, va_gc
> *separate_line_info
;
2900 /* A flag to tell pubnames/types export if there is an info section to
2902 static bool info_section_emitted
;
2904 /* A pointer to the base of a table that contains a list of publicly
2905 accessible names. */
2906 static GTY (()) vec
<pubname_entry
, va_gc
> *pubname_table
;
2908 /* A pointer to the base of a table that contains a list of publicly
2909 accessible types. */
2910 static GTY (()) vec
<pubname_entry
, va_gc
> *pubtype_table
;
2912 /* A pointer to the base of a table that contains a list of macro
2913 defines/undefines (and file start/end markers). */
2914 static GTY (()) vec
<macinfo_entry
, va_gc
> *macinfo_table
;
2916 /* True if .debug_macinfo or .debug_macros section is going to be
2918 #define have_macinfo \
2919 (debug_info_level >= DINFO_LEVEL_VERBOSE \
2920 && !macinfo_table->is_empty ())
2922 /* Array of dies for which we should generate .debug_ranges info. */
2923 static GTY ((length ("ranges_table_allocated"))) dw_ranges_ref ranges_table
;
2925 /* Number of elements currently allocated for ranges_table. */
2926 static GTY(()) unsigned ranges_table_allocated
;
2928 /* Number of elements in ranges_table currently in use. */
2929 static GTY(()) unsigned ranges_table_in_use
;
2931 /* Array of pairs of labels referenced in ranges_table. */
2932 static GTY ((length ("ranges_by_label_allocated")))
2933 dw_ranges_by_label_ref ranges_by_label
;
2935 /* Number of elements currently allocated for ranges_by_label. */
2936 static GTY(()) unsigned ranges_by_label_allocated
;
2938 /* Number of elements in ranges_by_label currently in use. */
2939 static GTY(()) unsigned ranges_by_label_in_use
;
2941 /* Size (in elements) of increments by which we may expand the
2943 #define RANGES_TABLE_INCREMENT 64
2945 /* Whether we have location lists that need outputting */
2946 static GTY(()) bool have_location_lists
;
2948 /* Unique label counter. */
2949 static GTY(()) unsigned int loclabel_num
;
2951 /* Unique label counter for point-of-call tables. */
2952 static GTY(()) unsigned int poc_label_num
;
2954 /* Record whether the function being analyzed contains inlined functions. */
2955 static int current_function_has_inlines
;
2957 /* The last file entry emitted by maybe_emit_file(). */
2958 static GTY(()) struct dwarf_file_data
* last_emitted_file
;
2960 /* Number of internal labels generated by gen_internal_sym(). */
2961 static GTY(()) int label_num
;
2963 /* Cached result of previous call to lookup_filename. */
2964 static GTY(()) struct dwarf_file_data
* file_table_last_lookup
;
2966 static GTY(()) vec
<die_arg_entry
, va_gc
> *tmpl_value_parm_die_table
;
2968 /* Instances of generic types for which we need to generate debug
2969 info that describe their generic parameters and arguments. That
2970 generation needs to happen once all types are properly laid out so
2971 we do it at the end of compilation. */
2972 static GTY(()) vec
<tree
, va_gc
> *generic_type_instances
;
2974 /* Offset from the "steady-state frame pointer" to the frame base,
2975 within the current function. */
2976 static HOST_WIDE_INT frame_pointer_fb_offset
;
2977 static bool frame_pointer_fb_offset_valid
;
2979 static vec
<dw_die_ref
> base_types
;
2981 /* Forward declarations for functions defined in this file. */
2983 static int is_pseudo_reg (const_rtx
);
2984 static tree
type_main_variant (tree
);
2985 static int is_tagged_type (const_tree
);
2986 static const char *dwarf_tag_name (unsigned);
2987 static const char *dwarf_attr_name (unsigned);
2988 static const char *dwarf_form_name (unsigned);
2989 static tree
decl_ultimate_origin (const_tree
);
2990 static tree
decl_class_context (tree
);
2991 static void add_dwarf_attr (dw_die_ref
, dw_attr_ref
);
2992 static inline enum dw_val_class
AT_class (dw_attr_ref
);
2993 static inline unsigned int AT_index (dw_attr_ref
);
2994 static void add_AT_flag (dw_die_ref
, enum dwarf_attribute
, unsigned);
2995 static inline unsigned AT_flag (dw_attr_ref
);
2996 static void add_AT_int (dw_die_ref
, enum dwarf_attribute
, HOST_WIDE_INT
);
2997 static inline HOST_WIDE_INT
AT_int (dw_attr_ref
);
2998 static void add_AT_unsigned (dw_die_ref
, enum dwarf_attribute
, unsigned HOST_WIDE_INT
);
2999 static inline unsigned HOST_WIDE_INT
AT_unsigned (dw_attr_ref
);
3000 static void add_AT_double (dw_die_ref
, enum dwarf_attribute
,
3001 HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
3002 static inline void add_AT_vec (dw_die_ref
, enum dwarf_attribute
, unsigned int,
3003 unsigned int, unsigned char *);
3004 static void add_AT_data8 (dw_die_ref
, enum dwarf_attribute
, unsigned char *);
3005 static hashval_t
debug_str_do_hash (const void *);
3006 static int debug_str_eq (const void *, const void *);
3007 static void add_AT_string (dw_die_ref
, enum dwarf_attribute
, const char *);
3008 static inline const char *AT_string (dw_attr_ref
);
3009 static enum dwarf_form
AT_string_form (dw_attr_ref
);
3010 static void add_AT_die_ref (dw_die_ref
, enum dwarf_attribute
, dw_die_ref
);
3011 static void add_AT_specification (dw_die_ref
, dw_die_ref
);
3012 static inline dw_die_ref
AT_ref (dw_attr_ref
);
3013 static inline int AT_ref_external (dw_attr_ref
);
3014 static inline void set_AT_ref_external (dw_attr_ref
, int);
3015 static void add_AT_fde_ref (dw_die_ref
, enum dwarf_attribute
, unsigned);
3016 static void add_AT_loc (dw_die_ref
, enum dwarf_attribute
, dw_loc_descr_ref
);
3017 static inline dw_loc_descr_ref
AT_loc (dw_attr_ref
);
3018 static void add_AT_loc_list (dw_die_ref
, enum dwarf_attribute
,
3020 static inline dw_loc_list_ref
AT_loc_list (dw_attr_ref
);
3021 static addr_table_entry
*add_addr_table_entry (void *, enum ate_kind
);
3022 static void remove_addr_table_entry (addr_table_entry
*);
3023 static void add_AT_addr (dw_die_ref
, enum dwarf_attribute
, rtx
, bool);
3024 static inline rtx
AT_addr (dw_attr_ref
);
3025 static void add_AT_lbl_id (dw_die_ref
, enum dwarf_attribute
, const char *);
3026 static void add_AT_lineptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3027 static void add_AT_macptr (dw_die_ref
, enum dwarf_attribute
, const char *);
3028 static void add_AT_offset (dw_die_ref
, enum dwarf_attribute
,
3029 unsigned HOST_WIDE_INT
);
3030 static void add_AT_range_list (dw_die_ref
, enum dwarf_attribute
,
3031 unsigned long, bool);
3032 static inline const char *AT_lbl (dw_attr_ref
);
3033 static dw_attr_ref
get_AT (dw_die_ref
, enum dwarf_attribute
);
3034 static const char *get_AT_low_pc (dw_die_ref
);
3035 static const char *get_AT_hi_pc (dw_die_ref
);
3036 static const char *get_AT_string (dw_die_ref
, enum dwarf_attribute
);
3037 static int get_AT_flag (dw_die_ref
, enum dwarf_attribute
);
3038 static unsigned get_AT_unsigned (dw_die_ref
, enum dwarf_attribute
);
3039 static inline dw_die_ref
get_AT_ref (dw_die_ref
, enum dwarf_attribute
);
3040 static bool is_cxx (void);
3041 static bool is_fortran (void);
3042 static bool is_ada (void);
3043 static void remove_AT (dw_die_ref
, enum dwarf_attribute
);
3044 static void remove_child_TAG (dw_die_ref
, enum dwarf_tag
);
3045 static void add_child_die (dw_die_ref
, dw_die_ref
);
3046 static dw_die_ref
new_die (enum dwarf_tag
, dw_die_ref
, tree
);
3047 static dw_die_ref
lookup_type_die (tree
);
3048 static dw_die_ref
strip_naming_typedef (tree
, dw_die_ref
);
3049 static dw_die_ref
lookup_type_die_strip_naming_typedef (tree
);
3050 static void equate_type_number_to_die (tree
, dw_die_ref
);
3051 static hashval_t
decl_die_table_hash (const void *);
3052 static int decl_die_table_eq (const void *, const void *);
3053 static dw_die_ref
lookup_decl_die (tree
);
3054 static hashval_t
common_block_die_table_hash (const void *);
3055 static int common_block_die_table_eq (const void *, const void *);
3056 static hashval_t
decl_loc_table_hash (const void *);
3057 static int decl_loc_table_eq (const void *, const void *);
3058 static var_loc_list
*lookup_decl_loc (const_tree
);
3059 static void equate_decl_number_to_die (tree
, dw_die_ref
);
3060 static struct var_loc_node
*add_var_loc_to_decl (tree
, rtx
, const char *);
3061 static void print_spaces (FILE *);
3062 static void print_die (dw_die_ref
, FILE *);
3063 static dw_die_ref
push_new_compile_unit (dw_die_ref
, dw_die_ref
);
3064 static dw_die_ref
pop_compile_unit (dw_die_ref
);
3065 static void loc_checksum (dw_loc_descr_ref
, struct md5_ctx
*);
3066 static void attr_checksum (dw_attr_ref
, struct md5_ctx
*, int *);
3067 static void die_checksum (dw_die_ref
, struct md5_ctx
*, int *);
3068 static void checksum_sleb128 (HOST_WIDE_INT
, struct md5_ctx
*);
3069 static void checksum_uleb128 (unsigned HOST_WIDE_INT
, struct md5_ctx
*);
3070 static void loc_checksum_ordered (dw_loc_descr_ref
, struct md5_ctx
*);
3071 static void attr_checksum_ordered (enum dwarf_tag
, dw_attr_ref
,
3072 struct md5_ctx
*, int *);
3073 struct checksum_attributes
;
3074 static void collect_checksum_attributes (struct checksum_attributes
*, dw_die_ref
);
3075 static void die_checksum_ordered (dw_die_ref
, struct md5_ctx
*, int *);
3076 static void checksum_die_context (dw_die_ref
, struct md5_ctx
*);
3077 static void generate_type_signature (dw_die_ref
, comdat_type_node
*);
3078 static int same_loc_p (dw_loc_descr_ref
, dw_loc_descr_ref
, int *);
3079 static int same_dw_val_p (const dw_val_node
*, const dw_val_node
*, int *);
3080 static int same_attr_p (dw_attr_ref
, dw_attr_ref
, int *);
3081 static int same_die_p (dw_die_ref
, dw_die_ref
, int *);
3082 static int same_die_p_wrap (dw_die_ref
, dw_die_ref
);
3083 static void compute_section_prefix (dw_die_ref
);
3084 static int is_type_die (dw_die_ref
);
3085 static int is_comdat_die (dw_die_ref
);
3086 static int is_symbol_die (dw_die_ref
);
3087 static inline bool is_template_instantiation (dw_die_ref
);
3088 static void assign_symbol_names (dw_die_ref
);
3089 static void break_out_includes (dw_die_ref
);
3090 static int is_declaration_die (dw_die_ref
);
3091 static int should_move_die_to_comdat (dw_die_ref
);
3092 static dw_die_ref
clone_as_declaration (dw_die_ref
);
3093 static dw_die_ref
clone_die (dw_die_ref
);
3094 static dw_die_ref
clone_tree (dw_die_ref
);
3095 static dw_die_ref
copy_declaration_context (dw_die_ref
, dw_die_ref
);
3096 static void generate_skeleton_ancestor_tree (skeleton_chain_node
*);
3097 static void generate_skeleton_bottom_up (skeleton_chain_node
*);
3098 static dw_die_ref
generate_skeleton (dw_die_ref
);
3099 static dw_die_ref
remove_child_or_replace_with_skeleton (dw_die_ref
,
3102 static void break_out_comdat_types (dw_die_ref
);
3103 static void copy_decls_for_unworthy_types (dw_die_ref
);
3105 static void add_sibling_attributes (dw_die_ref
);
3106 static void output_location_lists (dw_die_ref
);
3107 static int constant_size (unsigned HOST_WIDE_INT
);
3108 static unsigned long size_of_die (dw_die_ref
);
3109 static void calc_die_sizes (dw_die_ref
);
3110 static void calc_base_type_die_sizes (void);
3111 static void mark_dies (dw_die_ref
);
3112 static void unmark_dies (dw_die_ref
);
3113 static void unmark_all_dies (dw_die_ref
);
3114 static unsigned long size_of_pubnames (vec
<pubname_entry
, va_gc
> *);
3115 static unsigned long size_of_aranges (void);
3116 static enum dwarf_form
value_format (dw_attr_ref
);
3117 static void output_value_format (dw_attr_ref
);
3118 static void output_abbrev_section (void);
3119 static void output_die_abbrevs (unsigned long, dw_die_ref
);
3120 static void output_die_symbol (dw_die_ref
);
3121 static void output_die (dw_die_ref
);
3122 static void output_compilation_unit_header (void);
3123 static void output_comp_unit (dw_die_ref
, int);
3124 static void output_comdat_type_unit (comdat_type_node
*);
3125 static const char *dwarf2_name (tree
, int);
3126 static void add_pubname (tree
, dw_die_ref
);
3127 static void add_enumerator_pubname (const char *, dw_die_ref
);
3128 static void add_pubname_string (const char *, dw_die_ref
);
3129 static void add_pubtype (tree
, dw_die_ref
);
3130 static void output_pubnames (vec
<pubname_entry
, va_gc
> *);
3131 static void output_aranges (unsigned long);
3132 static unsigned int add_ranges_num (int);
3133 static unsigned int add_ranges (const_tree
);
3134 static void add_ranges_by_labels (dw_die_ref
, const char *, const char *,
3136 static void output_ranges (void);
3137 static dw_line_info_table
*new_line_info_table (void);
3138 static void output_line_info (bool);
3139 static void output_file_names (void);
3140 static dw_die_ref
base_type_die (tree
);
3141 static int is_base_type (tree
);
3142 static dw_die_ref
subrange_type_die (tree
, tree
, tree
, dw_die_ref
);
3143 static dw_die_ref
modified_type_die (tree
, int, int, dw_die_ref
);
3144 static dw_die_ref
generic_parameter_die (tree
, tree
, bool, dw_die_ref
);
3145 static dw_die_ref
template_parameter_pack_die (tree
, tree
, dw_die_ref
);
3146 static int type_is_enum (const_tree
);
3147 static unsigned int dbx_reg_number (const_rtx
);
3148 static void add_loc_descr_op_piece (dw_loc_descr_ref
*, int);
3149 static dw_loc_descr_ref
reg_loc_descriptor (rtx
, enum var_init_status
);
3150 static dw_loc_descr_ref
one_reg_loc_descriptor (unsigned int,
3151 enum var_init_status
);
3152 static dw_loc_descr_ref
multiple_reg_loc_descriptor (rtx
, rtx
,
3153 enum var_init_status
);
3154 static dw_loc_descr_ref
based_loc_descr (rtx
, HOST_WIDE_INT
,
3155 enum var_init_status
);
3156 static int is_based_loc (const_rtx
);
3157 static int resolve_one_addr (rtx
*, void *);
3158 static dw_loc_descr_ref
concat_loc_descriptor (rtx
, rtx
,
3159 enum var_init_status
);
3160 static dw_loc_descr_ref
loc_descriptor (rtx
, enum machine_mode mode
,
3161 enum var_init_status
);
3162 static dw_loc_list_ref
loc_list_from_tree (tree
, int);
3163 static dw_loc_descr_ref
loc_descriptor_from_tree (tree
, int);
3164 static HOST_WIDE_INT
ceiling (HOST_WIDE_INT
, unsigned int);
3165 static tree
field_type (const_tree
);
3166 static unsigned int simple_type_align_in_bits (const_tree
);
3167 static unsigned int simple_decl_align_in_bits (const_tree
);
3168 static unsigned HOST_WIDE_INT
simple_type_size_in_bits (const_tree
);
3169 static HOST_WIDE_INT
field_byte_offset (const_tree
);
3170 static void add_AT_location_description (dw_die_ref
, enum dwarf_attribute
,
3172 static void add_data_member_location_attribute (dw_die_ref
, tree
);
3173 static bool add_const_value_attribute (dw_die_ref
, rtx
);
3174 static void insert_int (HOST_WIDE_INT
, unsigned, unsigned char *);
3175 static void insert_wide_int (const wide_int
&, unsigned char *, int);
3176 static void insert_float (const_rtx
, unsigned char *);
3177 static rtx
rtl_for_decl_location (tree
);
3178 static bool add_location_or_const_value_attribute (dw_die_ref
, tree
, bool,
3179 enum dwarf_attribute
);
3180 static bool tree_add_const_value_attribute (dw_die_ref
, tree
);
3181 static bool tree_add_const_value_attribute_for_decl (dw_die_ref
, tree
);
3182 static void add_name_attribute (dw_die_ref
, const char *);
3183 static void add_gnat_descriptive_type_attribute (dw_die_ref
, tree
, dw_die_ref
);
3184 static void add_comp_dir_attribute (dw_die_ref
);
3185 static void add_bound_info (dw_die_ref
, enum dwarf_attribute
, tree
);
3186 static void add_subscript_info (dw_die_ref
, tree
, bool);
3187 static void add_byte_size_attribute (dw_die_ref
, tree
);
3188 static void add_bit_offset_attribute (dw_die_ref
, tree
);
3189 static void add_bit_size_attribute (dw_die_ref
, tree
);
3190 static void add_prototyped_attribute (dw_die_ref
, tree
);
3191 static dw_die_ref
add_abstract_origin_attribute (dw_die_ref
, tree
);
3192 static void add_pure_or_virtual_attribute (dw_die_ref
, tree
);
3193 static void add_src_coords_attributes (dw_die_ref
, tree
);
3194 static void add_name_and_src_coords_attributes (dw_die_ref
, tree
);
3195 static void push_decl_scope (tree
);
3196 static void pop_decl_scope (void);
3197 static dw_die_ref
scope_die_for (tree
, dw_die_ref
);
3198 static inline int local_scope_p (dw_die_ref
);
3199 static inline int class_scope_p (dw_die_ref
);
3200 static inline int class_or_namespace_scope_p (dw_die_ref
);
3201 static void add_type_attribute (dw_die_ref
, tree
, int, int, dw_die_ref
);
3202 static void add_calling_convention_attribute (dw_die_ref
, tree
);
3203 static const char *type_tag (const_tree
);
3204 static tree
member_declared_type (const_tree
);
3206 static const char *decl_start_label (tree
);
3208 static void gen_array_type_die (tree
, dw_die_ref
);
3209 static void gen_descr_array_type_die (tree
, struct array_descr_info
*, dw_die_ref
);
3211 static void gen_entry_point_die (tree
, dw_die_ref
);
3213 static dw_die_ref
gen_enumeration_type_die (tree
, dw_die_ref
);
3214 static dw_die_ref
gen_formal_parameter_die (tree
, tree
, bool, dw_die_ref
);
3215 static dw_die_ref
gen_formal_parameter_pack_die (tree
, tree
, dw_die_ref
, tree
*);
3216 static void gen_unspecified_parameters_die (tree
, dw_die_ref
);
3217 static void gen_formal_types_die (tree
, dw_die_ref
);
3218 static void gen_subprogram_die (tree
, dw_die_ref
);
3219 static void gen_variable_die (tree
, tree
, dw_die_ref
);
3220 static void gen_const_die (tree
, dw_die_ref
);
3221 static void gen_label_die (tree
, dw_die_ref
);
3222 static void gen_lexical_block_die (tree
, dw_die_ref
, int);
3223 static void gen_inlined_subroutine_die (tree
, dw_die_ref
, int);
3224 static void gen_field_die (tree
, dw_die_ref
);
3225 static void gen_ptr_to_mbr_type_die (tree
, dw_die_ref
);
3226 static dw_die_ref
gen_compile_unit_die (const char *);
3227 static void gen_inheritance_die (tree
, tree
, dw_die_ref
);
3228 static void gen_member_die (tree
, dw_die_ref
);
3229 static void gen_struct_or_union_type_die (tree
, dw_die_ref
,
3230 enum debug_info_usage
);
3231 static void gen_subroutine_type_die (tree
, dw_die_ref
);
3232 static void gen_typedef_die (tree
, dw_die_ref
);
3233 static void gen_type_die (tree
, dw_die_ref
);
3234 static void gen_block_die (tree
, dw_die_ref
, int);
3235 static void decls_for_scope (tree
, dw_die_ref
, int);
3236 static inline int is_redundant_typedef (const_tree
);
3237 static bool is_naming_typedef_decl (const_tree
);
3238 static inline dw_die_ref
get_context_die (tree
);
3239 static void gen_namespace_die (tree
, dw_die_ref
);
3240 static dw_die_ref
gen_namelist_decl (tree
, dw_die_ref
, tree
);
3241 static dw_die_ref
gen_decl_die (tree
, tree
, dw_die_ref
);
3242 static dw_die_ref
force_decl_die (tree
);
3243 static dw_die_ref
force_type_die (tree
);
3244 static dw_die_ref
setup_namespace_context (tree
, dw_die_ref
);
3245 static dw_die_ref
declare_in_namespace (tree
, dw_die_ref
);
3246 static struct dwarf_file_data
* lookup_filename (const char *);
3247 static void retry_incomplete_types (void);
3248 static void gen_type_die_for_member (tree
, tree
, dw_die_ref
);
3249 static void gen_generic_params_dies (tree
);
3250 static void gen_tagged_type_die (tree
, dw_die_ref
, enum debug_info_usage
);
3251 static void gen_type_die_with_usage (tree
, dw_die_ref
, enum debug_info_usage
);
3252 static void splice_child_die (dw_die_ref
, dw_die_ref
);
3253 static int file_info_cmp (const void *, const void *);
3254 static dw_loc_list_ref
new_loc_list (dw_loc_descr_ref
, const char *,
3255 const char *, const char *);
3256 static void output_loc_list (dw_loc_list_ref
);
3257 static char *gen_internal_sym (const char *);
3258 static bool want_pubnames (void);
3260 static void prune_unmark_dies (dw_die_ref
);
3261 static void prune_unused_types_mark_generic_parms_dies (dw_die_ref
);
3262 static void prune_unused_types_mark (dw_die_ref
, int);
3263 static void prune_unused_types_walk (dw_die_ref
);
3264 static void prune_unused_types_walk_attribs (dw_die_ref
);
3265 static void prune_unused_types_prune (dw_die_ref
);
3266 static void prune_unused_types (void);
3267 static int maybe_emit_file (struct dwarf_file_data
*fd
);
3268 static inline const char *AT_vms_delta1 (dw_attr_ref
);
3269 static inline const char *AT_vms_delta2 (dw_attr_ref
);
3270 static inline void add_AT_vms_delta (dw_die_ref
, enum dwarf_attribute
,
3271 const char *, const char *);
3272 static void append_entry_to_tmpl_value_parm_die_table (dw_die_ref
, tree
);
3273 static void gen_remaining_tmpl_value_param_die_attribute (void);
3274 static bool generic_type_p (tree
);
3275 static void schedule_generic_params_dies_gen (tree t
);
3276 static void gen_scheduled_generic_parms_dies (void);
3278 static const char *comp_dir_string (void);
3280 static hashval_t
hash_loc_operands (dw_loc_descr_ref
, hashval_t
);
3282 /* enum for tracking thread-local variables whose address is really an offset
3283 relative to the TLS pointer, which will need link-time relocation, but will
3284 not need relocation by the DWARF consumer. */
3292 /* Return the operator to use for an address of a variable. For dtprel_true, we
3293 use DW_OP_const*. For regular variables, which need both link-time
3294 relocation and consumer-level relocation (e.g., to account for shared objects
3295 loaded at a random address), we use DW_OP_addr*. */
3297 static inline enum dwarf_location_atom
3298 dw_addr_op (enum dtprel_bool dtprel
)
3300 if (dtprel
== dtprel_true
)
3301 return (dwarf_split_debug_info
? DW_OP_GNU_const_index
3302 : (DWARF2_ADDR_SIZE
== 4 ? DW_OP_const4u
: DW_OP_const8u
));
3304 return dwarf_split_debug_info
? DW_OP_GNU_addr_index
: DW_OP_addr
;
3307 /* Return a pointer to a newly allocated address location description. If
3308 dwarf_split_debug_info is true, then record the address with the appropriate
3310 static inline dw_loc_descr_ref
3311 new_addr_loc_descr (rtx addr
, enum dtprel_bool dtprel
)
3313 dw_loc_descr_ref ref
= new_loc_descr (dw_addr_op (dtprel
), 0, 0);
3315 ref
->dw_loc_oprnd1
.val_class
= dw_val_class_addr
;
3316 ref
->dw_loc_oprnd1
.v
.val_addr
= addr
;
3317 ref
->dtprel
= dtprel
;
3318 if (dwarf_split_debug_info
)
3319 ref
->dw_loc_oprnd1
.val_entry
3320 = add_addr_table_entry (addr
,
3321 dtprel
? ate_kind_rtx_dtprel
: ate_kind_rtx
);
3323 ref
->dw_loc_oprnd1
.val_entry
= NULL
;
3328 /* Section names used to hold DWARF debugging information. */
3330 #ifndef DEBUG_INFO_SECTION
3331 #define DEBUG_INFO_SECTION ".debug_info"
3333 #ifndef DEBUG_DWO_INFO_SECTION
3334 #define DEBUG_DWO_INFO_SECTION ".debug_info.dwo"
3336 #ifndef DEBUG_ABBREV_SECTION
3337 #define DEBUG_ABBREV_SECTION ".debug_abbrev"
3339 #ifndef DEBUG_DWO_ABBREV_SECTION
3340 #define DEBUG_DWO_ABBREV_SECTION ".debug_abbrev.dwo"
3342 #ifndef DEBUG_ARANGES_SECTION
3343 #define DEBUG_ARANGES_SECTION ".debug_aranges"
3345 #ifndef DEBUG_ADDR_SECTION
3346 #define DEBUG_ADDR_SECTION ".debug_addr"
3348 #ifndef DEBUG_NORM_MACINFO_SECTION
3349 #define DEBUG_NORM_MACINFO_SECTION ".debug_macinfo"
3351 #ifndef DEBUG_DWO_MACINFO_SECTION
3352 #define DEBUG_DWO_MACINFO_SECTION ".debug_macinfo.dwo"
3354 #ifndef DEBUG_MACINFO_SECTION
3355 #define DEBUG_MACINFO_SECTION \
3356 (!dwarf_split_debug_info \
3357 ? (DEBUG_NORM_MACINFO_SECTION) : (DEBUG_DWO_MACINFO_SECTION))
3359 #ifndef DEBUG_NORM_MACRO_SECTION
3360 #define DEBUG_NORM_MACRO_SECTION ".debug_macro"
3362 #ifndef DEBUG_DWO_MACRO_SECTION
3363 #define DEBUG_DWO_MACRO_SECTION ".debug_macro.dwo"
3365 #ifndef DEBUG_MACRO_SECTION
3366 #define DEBUG_MACRO_SECTION \
3367 (!dwarf_split_debug_info \
3368 ? (DEBUG_NORM_MACRO_SECTION) : (DEBUG_DWO_MACRO_SECTION))
3370 #ifndef DEBUG_LINE_SECTION
3371 #define DEBUG_LINE_SECTION ".debug_line"
3373 #ifndef DEBUG_DWO_LINE_SECTION
3374 #define DEBUG_DWO_LINE_SECTION ".debug_line.dwo"
3376 #ifndef DEBUG_LOC_SECTION
3377 #define DEBUG_LOC_SECTION ".debug_loc"
3379 #ifndef DEBUG_DWO_LOC_SECTION
3380 #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo"
3382 #ifndef DEBUG_PUBNAMES_SECTION
3383 #define DEBUG_PUBNAMES_SECTION \
3384 ((debug_generate_pub_sections == 2) \
3385 ? ".debug_gnu_pubnames" : ".debug_pubnames")
3387 #ifndef DEBUG_PUBTYPES_SECTION
3388 #define DEBUG_PUBTYPES_SECTION \
3389 ((debug_generate_pub_sections == 2) \
3390 ? ".debug_gnu_pubtypes" : ".debug_pubtypes")
3392 #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets"
3393 #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo"
3394 #ifndef DEBUG_STR_OFFSETS_SECTION
3395 #define DEBUG_STR_OFFSETS_SECTION \
3396 (!dwarf_split_debug_info \
3397 ? (DEBUG_NORM_STR_OFFSETS_SECTION) : (DEBUG_DWO_STR_OFFSETS_SECTION))
3399 #ifndef DEBUG_STR_DWO_SECTION
3400 #define DEBUG_STR_DWO_SECTION ".debug_str.dwo"
3402 #ifndef DEBUG_STR_SECTION
3403 #define DEBUG_STR_SECTION ".debug_str"
3405 #ifndef DEBUG_RANGES_SECTION
3406 #define DEBUG_RANGES_SECTION ".debug_ranges"
3409 /* Standard ELF section names for compiled code and data. */
3410 #ifndef TEXT_SECTION_NAME
3411 #define TEXT_SECTION_NAME ".text"
3414 /* Section flags for .debug_macinfo/.debug_macro section. */
3415 #define DEBUG_MACRO_SECTION_FLAGS \
3416 (dwarf_split_debug_info ? SECTION_DEBUG | SECTION_EXCLUDE : SECTION_DEBUG)
3418 /* Section flags for .debug_str section. */
3419 #define DEBUG_STR_SECTION_FLAGS \
3420 (HAVE_GAS_SHF_MERGE && flag_merge_debug_strings \
3421 ? SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1 \
3424 /* Section flags for .debug_str.dwo section. */
3425 #define DEBUG_STR_DWO_SECTION_FLAGS (SECTION_DEBUG | SECTION_EXCLUDE)
3427 /* Labels we insert at beginning sections we can reference instead of
3428 the section names themselves. */
3430 #ifndef TEXT_SECTION_LABEL
3431 #define TEXT_SECTION_LABEL "Ltext"
3433 #ifndef COLD_TEXT_SECTION_LABEL
3434 #define COLD_TEXT_SECTION_LABEL "Ltext_cold"
3436 #ifndef DEBUG_LINE_SECTION_LABEL
3437 #define DEBUG_LINE_SECTION_LABEL "Ldebug_line"
3439 #ifndef DEBUG_SKELETON_LINE_SECTION_LABEL
3440 #define DEBUG_SKELETON_LINE_SECTION_LABEL "Lskeleton_debug_line"
3442 #ifndef DEBUG_INFO_SECTION_LABEL
3443 #define DEBUG_INFO_SECTION_LABEL "Ldebug_info"
3445 #ifndef DEBUG_SKELETON_INFO_SECTION_LABEL
3446 #define DEBUG_SKELETON_INFO_SECTION_LABEL "Lskeleton_debug_info"
3448 #ifndef DEBUG_ABBREV_SECTION_LABEL
3449 #define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev"
3451 #ifndef DEBUG_SKELETON_ABBREV_SECTION_LABEL
3452 #define DEBUG_SKELETON_ABBREV_SECTION_LABEL "Lskeleton_debug_abbrev"
3454 #ifndef DEBUG_ADDR_SECTION_LABEL
3455 #define DEBUG_ADDR_SECTION_LABEL "Ldebug_addr"
3457 #ifndef DEBUG_LOC_SECTION_LABEL
3458 #define DEBUG_LOC_SECTION_LABEL "Ldebug_loc"
3460 #ifndef DEBUG_RANGES_SECTION_LABEL
3461 #define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges"
3463 #ifndef DEBUG_MACINFO_SECTION_LABEL
3464 #define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo"
3466 #ifndef DEBUG_MACRO_SECTION_LABEL
3467 #define DEBUG_MACRO_SECTION_LABEL "Ldebug_macro"
3469 #define SKELETON_COMP_DIE_ABBREV 1
3470 #define SKELETON_TYPE_DIE_ABBREV 2
3472 /* Definitions of defaults for formats and names of various special
3473 (artificial) labels which may be generated within this file (when the -g
3474 options is used and DWARF2_DEBUGGING_INFO is in effect.
3475 If necessary, these may be overridden from within the tm.h file, but
3476 typically, overriding these defaults is unnecessary. */
3478 static char text_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3479 static char text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3480 static char cold_text_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3481 static char cold_end_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3482 static char abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3483 static char debug_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3484 static char debug_skeleton_info_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3485 static char debug_skeleton_abbrev_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3486 static char debug_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3487 static char debug_addr_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3488 static char debug_skeleton_line_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3489 static char macinfo_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3490 static char loc_section_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
3491 static char ranges_section_label
[2 * MAX_ARTIFICIAL_LABEL_BYTES
];
3493 #ifndef TEXT_END_LABEL
3494 #define TEXT_END_LABEL "Letext"
3496 #ifndef COLD_END_LABEL
3497 #define COLD_END_LABEL "Letext_cold"
3499 #ifndef BLOCK_BEGIN_LABEL
3500 #define BLOCK_BEGIN_LABEL "LBB"
3502 #ifndef BLOCK_END_LABEL
3503 #define BLOCK_END_LABEL "LBE"
3505 #ifndef LINE_CODE_LABEL
3506 #define LINE_CODE_LABEL "LM"
3510 /* Return the root of the DIE's built for the current compilation unit. */
3512 comp_unit_die (void)
3514 if (!single_comp_unit_die
)
3515 single_comp_unit_die
= gen_compile_unit_die (NULL
);
3516 return single_comp_unit_die
;
3519 /* We allow a language front-end to designate a function that is to be
3520 called to "demangle" any name before it is put into a DIE. */
3522 static const char *(*demangle_name_func
) (const char *);
3525 dwarf2out_set_demangle_name_func (const char *(*func
) (const char *))
3527 demangle_name_func
= func
;
3530 /* Test if rtl node points to a pseudo register. */
3533 is_pseudo_reg (const_rtx rtl
)
3535 return ((REG_P (rtl
) && REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
3536 || (GET_CODE (rtl
) == SUBREG
3537 && REGNO (SUBREG_REG (rtl
)) >= FIRST_PSEUDO_REGISTER
));
3540 /* Return a reference to a type, with its const and volatile qualifiers
3544 type_main_variant (tree type
)
3546 type
= TYPE_MAIN_VARIANT (type
);
3548 /* ??? There really should be only one main variant among any group of
3549 variants of a given type (and all of the MAIN_VARIANT values for all
3550 members of the group should point to that one type) but sometimes the C
3551 front-end messes this up for array types, so we work around that bug
3553 if (TREE_CODE (type
) == ARRAY_TYPE
)
3554 while (type
!= TYPE_MAIN_VARIANT (type
))
3555 type
= TYPE_MAIN_VARIANT (type
);
3560 /* Return nonzero if the given type node represents a tagged type. */
3563 is_tagged_type (const_tree type
)
3565 enum tree_code code
= TREE_CODE (type
);
3567 return (code
== RECORD_TYPE
|| code
== UNION_TYPE
3568 || code
== QUAL_UNION_TYPE
|| code
== ENUMERAL_TYPE
);
3571 /* Set label to debug_info_section_label + die_offset of a DIE reference. */
3574 get_ref_die_offset_label (char *label
, dw_die_ref ref
)
3576 sprintf (label
, "%s+%ld", debug_info_section_label
, ref
->die_offset
);
3579 /* Return die_offset of a DIE reference to a base type. */
3581 static unsigned long int
3582 get_base_type_offset (dw_die_ref ref
)
3584 if (ref
->die_offset
)
3585 return ref
->die_offset
;
3586 if (comp_unit_die ()->die_abbrev
)
3588 calc_base_type_die_sizes ();
3589 gcc_assert (ref
->die_offset
);
3591 return ref
->die_offset
;
3594 /* Return die_offset of a DIE reference other than base type. */
3596 static unsigned long int
3597 get_ref_die_offset (dw_die_ref ref
)
3599 gcc_assert (ref
->die_offset
);
3600 return ref
->die_offset
;
3603 /* Convert a DIE tag into its string name. */
3606 dwarf_tag_name (unsigned int tag
)
3608 const char *name
= get_DW_TAG_name (tag
);
3613 return "DW_TAG_<unknown>";
3616 /* Convert a DWARF attribute code into its string name. */
3619 dwarf_attr_name (unsigned int attr
)
3625 #if VMS_DEBUGGING_INFO
3626 case DW_AT_HP_prologue
:
3627 return "DW_AT_HP_prologue";
3629 case DW_AT_MIPS_loop_unroll_factor
:
3630 return "DW_AT_MIPS_loop_unroll_factor";
3633 #if VMS_DEBUGGING_INFO
3634 case DW_AT_HP_epilogue
:
3635 return "DW_AT_HP_epilogue";
3637 case DW_AT_MIPS_stride
:
3638 return "DW_AT_MIPS_stride";
3642 name
= get_DW_AT_name (attr
);
3647 return "DW_AT_<unknown>";
3650 /* Convert a DWARF value form code into its string name. */
3653 dwarf_form_name (unsigned int form
)
3655 const char *name
= get_DW_FORM_name (form
);
3660 return "DW_FORM_<unknown>";
3663 /* Determine the "ultimate origin" of a decl. The decl may be an inlined
3664 instance of an inlined instance of a decl which is local to an inline
3665 function, so we have to trace all of the way back through the origin chain
3666 to find out what sort of node actually served as the original seed for the
3670 decl_ultimate_origin (const_tree decl
)
3672 if (!CODE_CONTAINS_STRUCT (TREE_CODE (decl
), TS_DECL_COMMON
))
3675 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the
3676 nodes in the function to point to themselves; ignore that if
3677 we're trying to output the abstract instance of this function. */
3678 if (DECL_ABSTRACT (decl
) && DECL_ABSTRACT_ORIGIN (decl
) == decl
)
3681 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
3682 most distant ancestor, this should never happen. */
3683 gcc_assert (!DECL_FROM_INLINE (DECL_ORIGIN (decl
)));
3685 return DECL_ABSTRACT_ORIGIN (decl
);
3688 /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT
3689 of a virtual function may refer to a base class, so we check the 'this'
3693 decl_class_context (tree decl
)
3695 tree context
= NULL_TREE
;
3697 if (TREE_CODE (decl
) != FUNCTION_DECL
|| ! DECL_VINDEX (decl
))
3698 context
= DECL_CONTEXT (decl
);
3700 context
= TYPE_MAIN_VARIANT
3701 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl
)))));
3703 if (context
&& !TYPE_P (context
))
3704 context
= NULL_TREE
;
3709 /* Add an attribute/value pair to a DIE. */
3712 add_dwarf_attr (dw_die_ref die
, dw_attr_ref attr
)
3714 /* Maybe this should be an assert? */
3718 vec_safe_reserve (die
->die_attr
, 1);
3719 vec_safe_push (die
->die_attr
, *attr
);
3722 static inline enum dw_val_class
3723 AT_class (dw_attr_ref a
)
3725 return a
->dw_attr_val
.val_class
;
3728 /* Return the index for any attribute that will be referenced with a
3729 DW_FORM_GNU_addr_index or DW_FORM_GNU_str_index. String indices
3730 are stored in dw_attr_val.v.val_str for reference counting
3733 static inline unsigned int
3734 AT_index (dw_attr_ref a
)
3736 if (AT_class (a
) == dw_val_class_str
)
3737 return a
->dw_attr_val
.v
.val_str
->index
;
3738 else if (a
->dw_attr_val
.val_entry
!= NULL
)
3739 return a
->dw_attr_val
.val_entry
->index
;
3743 /* Add a flag value attribute to a DIE. */
3746 add_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int flag
)
3750 attr
.dw_attr
= attr_kind
;
3751 attr
.dw_attr_val
.val_class
= dw_val_class_flag
;
3752 attr
.dw_attr_val
.val_entry
= NULL
;
3753 attr
.dw_attr_val
.v
.val_flag
= flag
;
3754 add_dwarf_attr (die
, &attr
);
3757 static inline unsigned
3758 AT_flag (dw_attr_ref a
)
3760 gcc_assert (a
&& AT_class (a
) == dw_val_class_flag
);
3761 return a
->dw_attr_val
.v
.val_flag
;
3764 /* Add a signed integer attribute value to a DIE. */
3767 add_AT_int (dw_die_ref die
, enum dwarf_attribute attr_kind
, HOST_WIDE_INT int_val
)
3771 attr
.dw_attr
= attr_kind
;
3772 attr
.dw_attr_val
.val_class
= dw_val_class_const
;
3773 attr
.dw_attr_val
.val_entry
= NULL
;
3774 attr
.dw_attr_val
.v
.val_int
= int_val
;
3775 add_dwarf_attr (die
, &attr
);
3778 static inline HOST_WIDE_INT
3779 AT_int (dw_attr_ref a
)
3781 gcc_assert (a
&& AT_class (a
) == dw_val_class_const
);
3782 return a
->dw_attr_val
.v
.val_int
;
3785 /* Add an unsigned integer attribute value to a DIE. */
3788 add_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3789 unsigned HOST_WIDE_INT unsigned_val
)
3793 attr
.dw_attr
= attr_kind
;
3794 attr
.dw_attr_val
.val_class
= dw_val_class_unsigned_const
;
3795 attr
.dw_attr_val
.val_entry
= NULL
;
3796 attr
.dw_attr_val
.v
.val_unsigned
= unsigned_val
;
3797 add_dwarf_attr (die
, &attr
);
3800 static inline unsigned HOST_WIDE_INT
3801 AT_unsigned (dw_attr_ref a
)
3803 gcc_assert (a
&& AT_class (a
) == dw_val_class_unsigned_const
);
3804 return a
->dw_attr_val
.v
.val_unsigned
;
3807 /* Add an unsigned wide integer attribute value to a DIE. */
3810 add_AT_wide (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3815 attr
.dw_attr
= attr_kind
;
3816 attr
.dw_attr_val
.val_class
= dw_val_class_wide_int
;
3817 attr
.dw_attr_val
.v
.val_wide
= ggc_alloc_cleared_wide_int ();
3818 *attr
.dw_attr_val
.v
.val_wide
= w
;
3819 add_dwarf_attr (die
, &attr
);
3822 /* Add an unsigned double integer attribute value to a DIE. */
3825 add_AT_double (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3826 HOST_WIDE_INT high
, unsigned HOST_WIDE_INT low
)
3830 attr
.dw_attr
= attr_kind
;
3831 attr
.dw_attr_val
.val_class
= dw_val_class_const_double
;
3832 attr
.dw_attr_val
.val_entry
= NULL
;
3833 attr
.dw_attr_val
.v
.val_double
.high
= high
;
3834 attr
.dw_attr_val
.v
.val_double
.low
= low
;
3835 add_dwarf_attr (die
, &attr
);
3838 /* Add a floating point attribute value to a DIE and return it. */
3841 add_AT_vec (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3842 unsigned int length
, unsigned int elt_size
, unsigned char *array
)
3846 attr
.dw_attr
= attr_kind
;
3847 attr
.dw_attr_val
.val_class
= dw_val_class_vec
;
3848 attr
.dw_attr_val
.val_entry
= NULL
;
3849 attr
.dw_attr_val
.v
.val_vec
.length
= length
;
3850 attr
.dw_attr_val
.v
.val_vec
.elt_size
= elt_size
;
3851 attr
.dw_attr_val
.v
.val_vec
.array
= array
;
3852 add_dwarf_attr (die
, &attr
);
3855 /* Add an 8-byte data attribute value to a DIE. */
3858 add_AT_data8 (dw_die_ref die
, enum dwarf_attribute attr_kind
,
3859 unsigned char data8
[8])
3863 attr
.dw_attr
= attr_kind
;
3864 attr
.dw_attr_val
.val_class
= dw_val_class_data8
;
3865 attr
.dw_attr_val
.val_entry
= NULL
;
3866 memcpy (attr
.dw_attr_val
.v
.val_data8
, data8
, 8);
3867 add_dwarf_attr (die
, &attr
);
3870 /* Add DW_AT_low_pc and DW_AT_high_pc to a DIE. When using
3871 dwarf_split_debug_info, address attributes in dies destined for the
3872 final executable have force_direct set to avoid using indexed
3876 add_AT_low_high_pc (dw_die_ref die
, const char *lbl_low
, const char *lbl_high
,
3882 lbl_id
= xstrdup (lbl_low
);
3883 attr
.dw_attr
= DW_AT_low_pc
;
3884 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3885 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3886 if (dwarf_split_debug_info
&& !force_direct
)
3887 attr
.dw_attr_val
.val_entry
3888 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3890 attr
.dw_attr_val
.val_entry
= NULL
;
3891 add_dwarf_attr (die
, &attr
);
3893 attr
.dw_attr
= DW_AT_high_pc
;
3894 if (dwarf_version
< 4)
3895 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
3897 attr
.dw_attr_val
.val_class
= dw_val_class_high_pc
;
3898 lbl_id
= xstrdup (lbl_high
);
3899 attr
.dw_attr_val
.v
.val_lbl_id
= lbl_id
;
3900 if (attr
.dw_attr_val
.val_class
== dw_val_class_lbl_id
3901 && dwarf_split_debug_info
&& !force_direct
)
3902 attr
.dw_attr_val
.val_entry
3903 = add_addr_table_entry (lbl_id
, ate_kind_label
);
3905 attr
.dw_attr_val
.val_entry
= NULL
;
3906 add_dwarf_attr (die
, &attr
);
3909 /* Hash and equality functions for debug_str_hash. */
3912 debug_str_do_hash (const void *x
)
3914 return htab_hash_string (((const struct indirect_string_node
*)x
)->str
);
3918 debug_str_eq (const void *x1
, const void *x2
)
3920 return strcmp ((((const struct indirect_string_node
*)x1
)->str
),
3921 (const char *)x2
) == 0;
3924 /* Add STR to the given string hash table. */
3926 static struct indirect_string_node
*
3927 find_AT_string_in_table (const char *str
, htab_t table
)
3929 struct indirect_string_node
*node
;
3932 slot
= htab_find_slot_with_hash (table
, str
,
3933 htab_hash_string (str
), INSERT
);
3936 node
= ggc_alloc_cleared_indirect_string_node ();
3937 node
->str
= ggc_strdup (str
);
3941 node
= (struct indirect_string_node
*) *slot
;
3947 /* Add STR to the indirect string hash table. */
3949 static struct indirect_string_node
*
3950 find_AT_string (const char *str
)
3952 if (! debug_str_hash
)
3953 debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
3954 debug_str_eq
, NULL
);
3956 return find_AT_string_in_table (str
, debug_str_hash
);
3959 /* Add a string attribute value to a DIE. */
3962 add_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
, const char *str
)
3965 struct indirect_string_node
*node
;
3967 node
= find_AT_string (str
);
3969 attr
.dw_attr
= attr_kind
;
3970 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
3971 attr
.dw_attr_val
.val_entry
= NULL
;
3972 attr
.dw_attr_val
.v
.val_str
= node
;
3973 add_dwarf_attr (die
, &attr
);
3976 static inline const char *
3977 AT_string (dw_attr_ref a
)
3979 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
3980 return a
->dw_attr_val
.v
.val_str
->str
;
3983 /* Call this function directly to bypass AT_string_form's logic to put
3984 the string inline in the die. */
3987 set_indirect_string (struct indirect_string_node
*node
)
3990 /* Already indirect is a no op. */
3991 if (node
->form
== DW_FORM_strp
|| node
->form
== DW_FORM_GNU_str_index
)
3993 gcc_assert (node
->label
);
3996 ASM_GENERATE_INTERNAL_LABEL (label
, "LASF", dw2_string_counter
);
3997 ++dw2_string_counter
;
3998 node
->label
= xstrdup (label
);
4000 if (!dwarf_split_debug_info
)
4002 node
->form
= DW_FORM_strp
;
4003 node
->index
= NOT_INDEXED
;
4007 node
->form
= DW_FORM_GNU_str_index
;
4008 node
->index
= NO_INDEX_ASSIGNED
;
4012 /* Find out whether a string should be output inline in DIE
4013 or out-of-line in .debug_str section. */
4015 static enum dwarf_form
4016 find_string_form (struct indirect_string_node
*node
)
4023 len
= strlen (node
->str
) + 1;
4025 /* If the string is shorter or equal to the size of the reference, it is
4026 always better to put it inline. */
4027 if (len
<= DWARF_OFFSET_SIZE
|| node
->refcount
== 0)
4028 return node
->form
= DW_FORM_string
;
4030 /* If we cannot expect the linker to merge strings in .debug_str
4031 section, only put it into .debug_str if it is worth even in this
4033 if (DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
4034 || ((debug_str_section
->common
.flags
& SECTION_MERGE
) == 0
4035 && (len
- DWARF_OFFSET_SIZE
) * node
->refcount
<= len
))
4036 return node
->form
= DW_FORM_string
;
4038 set_indirect_string (node
);
4043 /* Find out whether the string referenced from the attribute should be
4044 output inline in DIE or out-of-line in .debug_str section. */
4046 static enum dwarf_form
4047 AT_string_form (dw_attr_ref a
)
4049 gcc_assert (a
&& AT_class (a
) == dw_val_class_str
);
4050 return find_string_form (a
->dw_attr_val
.v
.val_str
);
4053 /* Add a DIE reference attribute value to a DIE. */
4056 add_AT_die_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_die_ref targ_die
)
4060 #ifdef ENABLE_CHECKING
4061 gcc_assert (targ_die
!= NULL
);
4063 /* With LTO we can end up trying to reference something we didn't create
4064 a DIE for. Avoid crashing later on a NULL referenced DIE. */
4065 if (targ_die
== NULL
)
4069 attr
.dw_attr
= attr_kind
;
4070 attr
.dw_attr_val
.val_class
= dw_val_class_die_ref
;
4071 attr
.dw_attr_val
.val_entry
= NULL
;
4072 attr
.dw_attr_val
.v
.val_die_ref
.die
= targ_die
;
4073 attr
.dw_attr_val
.v
.val_die_ref
.external
= 0;
4074 add_dwarf_attr (die
, &attr
);
4077 /* Change DIE reference REF to point to NEW_DIE instead. */
4080 change_AT_die_ref (dw_attr_ref ref
, dw_die_ref new_die
)
4082 gcc_assert (ref
->dw_attr_val
.val_class
== dw_val_class_die_ref
);
4083 ref
->dw_attr_val
.v
.val_die_ref
.die
= new_die
;
4084 ref
->dw_attr_val
.v
.val_die_ref
.external
= 0;
4087 /* Add an AT_specification attribute to a DIE, and also make the back
4088 pointer from the specification to the definition. */
4091 add_AT_specification (dw_die_ref die
, dw_die_ref targ_die
)
4093 add_AT_die_ref (die
, DW_AT_specification
, targ_die
);
4094 gcc_assert (!targ_die
->die_definition
);
4095 targ_die
->die_definition
= die
;
4098 static inline dw_die_ref
4099 AT_ref (dw_attr_ref a
)
4101 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4102 return a
->dw_attr_val
.v
.val_die_ref
.die
;
4106 AT_ref_external (dw_attr_ref a
)
4108 if (a
&& AT_class (a
) == dw_val_class_die_ref
)
4109 return a
->dw_attr_val
.v
.val_die_ref
.external
;
4115 set_AT_ref_external (dw_attr_ref a
, int i
)
4117 gcc_assert (a
&& AT_class (a
) == dw_val_class_die_ref
);
4118 a
->dw_attr_val
.v
.val_die_ref
.external
= i
;
4121 /* Add an FDE reference attribute value to a DIE. */
4124 add_AT_fde_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
, unsigned int targ_fde
)
4128 attr
.dw_attr
= attr_kind
;
4129 attr
.dw_attr_val
.val_class
= dw_val_class_fde_ref
;
4130 attr
.dw_attr_val
.val_entry
= NULL
;
4131 attr
.dw_attr_val
.v
.val_fde_index
= targ_fde
;
4132 add_dwarf_attr (die
, &attr
);
4135 /* Add a location description attribute value to a DIE. */
4138 add_AT_loc (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_descr_ref loc
)
4142 attr
.dw_attr
= attr_kind
;
4143 attr
.dw_attr_val
.val_class
= dw_val_class_loc
;
4144 attr
.dw_attr_val
.val_entry
= NULL
;
4145 attr
.dw_attr_val
.v
.val_loc
= loc
;
4146 add_dwarf_attr (die
, &attr
);
4149 static inline dw_loc_descr_ref
4150 AT_loc (dw_attr_ref a
)
4152 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc
);
4153 return a
->dw_attr_val
.v
.val_loc
;
4157 add_AT_loc_list (dw_die_ref die
, enum dwarf_attribute attr_kind
, dw_loc_list_ref loc_list
)
4161 attr
.dw_attr
= attr_kind
;
4162 attr
.dw_attr_val
.val_class
= dw_val_class_loc_list
;
4163 attr
.dw_attr_val
.val_entry
= NULL
;
4164 attr
.dw_attr_val
.v
.val_loc_list
= loc_list
;
4165 add_dwarf_attr (die
, &attr
);
4166 have_location_lists
= true;
4169 static inline dw_loc_list_ref
4170 AT_loc_list (dw_attr_ref a
)
4172 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4173 return a
->dw_attr_val
.v
.val_loc_list
;
4176 static inline dw_loc_list_ref
*
4177 AT_loc_list_ptr (dw_attr_ref a
)
4179 gcc_assert (a
&& AT_class (a
) == dw_val_class_loc_list
);
4180 return &a
->dw_attr_val
.v
.val_loc_list
;
4183 /* Table of entries into the .debug_addr section. */
4185 static GTY ((param_is (addr_table_entry
))) htab_t addr_index_table
;
4187 /* Hash an address_table_entry. */
4190 addr_table_entry_do_hash (const void *x
)
4192 const addr_table_entry
*a
= (const addr_table_entry
*) x
;
4196 return iterative_hash_rtx (a
->addr
.rtl
, 0);
4197 case ate_kind_rtx_dtprel
:
4198 return iterative_hash_rtx (a
->addr
.rtl
, 1);
4199 case ate_kind_label
:
4200 return htab_hash_string (a
->addr
.label
);
4206 /* Determine equality for two address_table_entries. */
4209 addr_table_entry_eq (const void *x1
, const void *x2
)
4211 const addr_table_entry
*a1
= (const addr_table_entry
*) x1
;
4212 const addr_table_entry
*a2
= (const addr_table_entry
*) x2
;
4214 if (a1
->kind
!= a2
->kind
)
4219 case ate_kind_rtx_dtprel
:
4220 return rtx_equal_p (a1
->addr
.rtl
, a2
->addr
.rtl
);
4221 case ate_kind_label
:
4222 return strcmp (a1
->addr
.label
, a2
->addr
.label
) == 0;
4228 /* Initialize an addr_table_entry. */
4231 init_addr_table_entry (addr_table_entry
*e
, enum ate_kind kind
, void *addr
)
4237 case ate_kind_rtx_dtprel
:
4238 e
->addr
.rtl
= (rtx
) addr
;
4240 case ate_kind_label
:
4241 e
->addr
.label
= (char *) addr
;
4245 e
->index
= NO_INDEX_ASSIGNED
;
4248 /* Add attr to the address table entry to the table. Defer setting an
4249 index until output time. */
4251 static addr_table_entry
*
4252 add_addr_table_entry (void *addr
, enum ate_kind kind
)
4254 addr_table_entry
*node
;
4255 addr_table_entry finder
;
4258 gcc_assert (dwarf_split_debug_info
);
4259 if (! addr_index_table
)
4260 addr_index_table
= htab_create_ggc (10, addr_table_entry_do_hash
,
4261 addr_table_entry_eq
, NULL
);
4262 init_addr_table_entry (&finder
, kind
, addr
);
4263 slot
= htab_find_slot (addr_index_table
, &finder
, INSERT
);
4265 if (*slot
== HTAB_EMPTY_ENTRY
)
4267 node
= ggc_alloc_cleared_addr_table_entry ();
4268 init_addr_table_entry (node
, kind
, addr
);
4272 node
= (addr_table_entry
*) *slot
;
4278 /* Remove an entry from the addr table by decrementing its refcount.
4279 Strictly, decrementing the refcount would be enough, but the
4280 assertion that the entry is actually in the table has found
4284 remove_addr_table_entry (addr_table_entry
*entry
)
4286 addr_table_entry
*node
;
4288 gcc_assert (dwarf_split_debug_info
&& addr_index_table
);
4289 node
= (addr_table_entry
*) htab_find (addr_index_table
, entry
);
4290 /* After an index is assigned, the table is frozen. */
4291 gcc_assert (node
->refcount
> 0 && node
->index
== NO_INDEX_ASSIGNED
);
4295 /* Given a location list, remove all addresses it refers to from the
4299 remove_loc_list_addr_table_entries (dw_loc_descr_ref descr
)
4301 for (; descr
; descr
= descr
->dw_loc_next
)
4302 if (descr
->dw_loc_oprnd1
.val_entry
!= NULL
)
4304 gcc_assert (descr
->dw_loc_oprnd1
.val_entry
->index
== NO_INDEX_ASSIGNED
);
4305 remove_addr_table_entry (descr
->dw_loc_oprnd1
.val_entry
);
4309 /* A helper function for dwarf2out_finish called through
4310 htab_traverse. Assign an addr_table_entry its index. All entries
4311 must be collected into the table when this function is called,
4312 because the indexing code relies on htab_traverse to traverse nodes
4313 in the same order for each run. */
4316 index_addr_table_entry (void **h
, void *v
)
4318 addr_table_entry
*node
= (addr_table_entry
*) *h
;
4319 unsigned int *index
= (unsigned int *) v
;
4321 /* Don't index unreferenced nodes. */
4322 if (node
->refcount
== 0)
4325 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
4326 node
->index
= *index
;
4332 /* Add an address constant attribute value to a DIE. When using
4333 dwarf_split_debug_info, address attributes in dies destined for the
4334 final executable should be direct references--setting the parameter
4335 force_direct ensures this behavior. */
4338 add_AT_addr (dw_die_ref die
, enum dwarf_attribute attr_kind
, rtx addr
,
4343 attr
.dw_attr
= attr_kind
;
4344 attr
.dw_attr_val
.val_class
= dw_val_class_addr
;
4345 attr
.dw_attr_val
.v
.val_addr
= addr
;
4346 if (dwarf_split_debug_info
&& !force_direct
)
4347 attr
.dw_attr_val
.val_entry
= add_addr_table_entry (addr
, ate_kind_rtx
);
4349 attr
.dw_attr_val
.val_entry
= NULL
;
4350 add_dwarf_attr (die
, &attr
);
4353 /* Get the RTX from to an address DIE attribute. */
4356 AT_addr (dw_attr_ref a
)
4358 gcc_assert (a
&& AT_class (a
) == dw_val_class_addr
);
4359 return a
->dw_attr_val
.v
.val_addr
;
4362 /* Add a file attribute value to a DIE. */
4365 add_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4366 struct dwarf_file_data
*fd
)
4370 attr
.dw_attr
= attr_kind
;
4371 attr
.dw_attr_val
.val_class
= dw_val_class_file
;
4372 attr
.dw_attr_val
.val_entry
= NULL
;
4373 attr
.dw_attr_val
.v
.val_file
= fd
;
4374 add_dwarf_attr (die
, &attr
);
4377 /* Get the dwarf_file_data from a file DIE attribute. */
4379 static inline struct dwarf_file_data
*
4380 AT_file (dw_attr_ref a
)
4382 gcc_assert (a
&& AT_class (a
) == dw_val_class_file
);
4383 return a
->dw_attr_val
.v
.val_file
;
4386 /* Add a vms delta attribute value to a DIE. */
4389 add_AT_vms_delta (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4390 const char *lbl1
, const char *lbl2
)
4394 attr
.dw_attr
= attr_kind
;
4395 attr
.dw_attr_val
.val_class
= dw_val_class_vms_delta
;
4396 attr
.dw_attr_val
.val_entry
= NULL
;
4397 attr
.dw_attr_val
.v
.val_vms_delta
.lbl1
= xstrdup (lbl1
);
4398 attr
.dw_attr_val
.v
.val_vms_delta
.lbl2
= xstrdup (lbl2
);
4399 add_dwarf_attr (die
, &attr
);
4402 /* Add a label identifier attribute value to a DIE. */
4405 add_AT_lbl_id (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4410 attr
.dw_attr
= attr_kind
;
4411 attr
.dw_attr_val
.val_class
= dw_val_class_lbl_id
;
4412 attr
.dw_attr_val
.val_entry
= NULL
;
4413 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (lbl_id
);
4414 if (dwarf_split_debug_info
)
4415 attr
.dw_attr_val
.val_entry
4416 = add_addr_table_entry (attr
.dw_attr_val
.v
.val_lbl_id
,
4418 add_dwarf_attr (die
, &attr
);
4421 /* Add a section offset attribute value to a DIE, an offset into the
4422 debug_line section. */
4425 add_AT_lineptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4430 attr
.dw_attr
= attr_kind
;
4431 attr
.dw_attr_val
.val_class
= dw_val_class_lineptr
;
4432 attr
.dw_attr_val
.val_entry
= NULL
;
4433 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4434 add_dwarf_attr (die
, &attr
);
4437 /* Add a section offset attribute value to a DIE, an offset into the
4438 debug_macinfo section. */
4441 add_AT_macptr (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4446 attr
.dw_attr
= attr_kind
;
4447 attr
.dw_attr_val
.val_class
= dw_val_class_macptr
;
4448 attr
.dw_attr_val
.val_entry
= NULL
;
4449 attr
.dw_attr_val
.v
.val_lbl_id
= xstrdup (label
);
4450 add_dwarf_attr (die
, &attr
);
4453 /* Add an offset attribute value to a DIE. */
4456 add_AT_offset (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4457 unsigned HOST_WIDE_INT offset
)
4461 attr
.dw_attr
= attr_kind
;
4462 attr
.dw_attr_val
.val_class
= dw_val_class_offset
;
4463 attr
.dw_attr_val
.val_entry
= NULL
;
4464 attr
.dw_attr_val
.v
.val_offset
= offset
;
4465 add_dwarf_attr (die
, &attr
);
4468 /* Add a range_list attribute value to a DIE. When using
4469 dwarf_split_debug_info, address attributes in dies destined for the
4470 final executable should be direct references--setting the parameter
4471 force_direct ensures this behavior. */
4473 #define UNRELOCATED_OFFSET ((addr_table_entry *) 1)
4474 #define RELOCATED_OFFSET (NULL)
4477 add_AT_range_list (dw_die_ref die
, enum dwarf_attribute attr_kind
,
4478 long unsigned int offset
, bool force_direct
)
4482 attr
.dw_attr
= attr_kind
;
4483 attr
.dw_attr_val
.val_class
= dw_val_class_range_list
;
4484 /* For the range_list attribute, use val_entry to store whether the
4485 offset should follow split-debug-info or normal semantics. This
4486 value is read in output_range_list_offset. */
4487 if (dwarf_split_debug_info
&& !force_direct
)
4488 attr
.dw_attr_val
.val_entry
= UNRELOCATED_OFFSET
;
4490 attr
.dw_attr_val
.val_entry
= RELOCATED_OFFSET
;
4491 attr
.dw_attr_val
.v
.val_offset
= offset
;
4492 add_dwarf_attr (die
, &attr
);
4495 /* Return the start label of a delta attribute. */
4497 static inline const char *
4498 AT_vms_delta1 (dw_attr_ref a
)
4500 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4501 return a
->dw_attr_val
.v
.val_vms_delta
.lbl1
;
4504 /* Return the end label of a delta attribute. */
4506 static inline const char *
4507 AT_vms_delta2 (dw_attr_ref a
)
4509 gcc_assert (a
&& (AT_class (a
) == dw_val_class_vms_delta
));
4510 return a
->dw_attr_val
.v
.val_vms_delta
.lbl2
;
4513 static inline const char *
4514 AT_lbl (dw_attr_ref a
)
4516 gcc_assert (a
&& (AT_class (a
) == dw_val_class_lbl_id
4517 || AT_class (a
) == dw_val_class_lineptr
4518 || AT_class (a
) == dw_val_class_macptr
4519 || AT_class (a
) == dw_val_class_high_pc
));
4520 return a
->dw_attr_val
.v
.val_lbl_id
;
4523 /* Get the attribute of type attr_kind. */
4526 get_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4530 dw_die_ref spec
= NULL
;
4535 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4536 if (a
->dw_attr
== attr_kind
)
4538 else if (a
->dw_attr
== DW_AT_specification
4539 || a
->dw_attr
== DW_AT_abstract_origin
)
4543 return get_AT (spec
, attr_kind
);
4548 /* Returns the parent of the declaration of DIE. */
4551 get_die_parent (dw_die_ref die
)
4558 if ((t
= get_AT_ref (die
, DW_AT_abstract_origin
))
4559 || (t
= get_AT_ref (die
, DW_AT_specification
)))
4562 return die
->die_parent
;
4565 /* Return the "low pc" attribute value, typically associated with a subprogram
4566 DIE. Return null if the "low pc" attribute is either not present, or if it
4567 cannot be represented as an assembler label identifier. */
4569 static inline const char *
4570 get_AT_low_pc (dw_die_ref die
)
4572 dw_attr_ref a
= get_AT (die
, DW_AT_low_pc
);
4574 return a
? AT_lbl (a
) : NULL
;
4577 /* Return the "high pc" attribute value, typically associated with a subprogram
4578 DIE. Return null if the "high pc" attribute is either not present, or if it
4579 cannot be represented as an assembler label identifier. */
4581 static inline const char *
4582 get_AT_hi_pc (dw_die_ref die
)
4584 dw_attr_ref a
= get_AT (die
, DW_AT_high_pc
);
4586 return a
? AT_lbl (a
) : NULL
;
4589 /* Return the value of the string attribute designated by ATTR_KIND, or
4590 NULL if it is not present. */
4592 static inline const char *
4593 get_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4595 dw_attr_ref a
= get_AT (die
, attr_kind
);
4597 return a
? AT_string (a
) : NULL
;
4600 /* Return the value of the flag attribute designated by ATTR_KIND, or -1
4601 if it is not present. */
4604 get_AT_flag (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4606 dw_attr_ref a
= get_AT (die
, attr_kind
);
4608 return a
? AT_flag (a
) : 0;
4611 /* Return the value of the unsigned attribute designated by ATTR_KIND, or 0
4612 if it is not present. */
4614 static inline unsigned
4615 get_AT_unsigned (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4617 dw_attr_ref a
= get_AT (die
, attr_kind
);
4619 return a
? AT_unsigned (a
) : 0;
4622 static inline dw_die_ref
4623 get_AT_ref (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4625 dw_attr_ref a
= get_AT (die
, attr_kind
);
4627 return a
? AT_ref (a
) : NULL
;
4630 static inline struct dwarf_file_data
*
4631 get_AT_file (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4633 dw_attr_ref a
= get_AT (die
, attr_kind
);
4635 return a
? AT_file (a
) : NULL
;
4638 /* Return TRUE if the language is C++. */
4643 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4645 return lang
== DW_LANG_C_plus_plus
|| lang
== DW_LANG_ObjC_plus_plus
;
4648 /* Return TRUE if the language is Java. */
4653 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4655 return lang
== DW_LANG_Java
;
4658 /* Return TRUE if the language is Fortran. */
4663 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4665 return (lang
== DW_LANG_Fortran77
4666 || lang
== DW_LANG_Fortran90
4667 || lang
== DW_LANG_Fortran95
);
4670 /* Return TRUE if the language is Ada. */
4675 unsigned int lang
= get_AT_unsigned (comp_unit_die (), DW_AT_language
);
4677 return lang
== DW_LANG_Ada95
|| lang
== DW_LANG_Ada83
;
4680 /* Remove the specified attribute if present. */
4683 remove_AT (dw_die_ref die
, enum dwarf_attribute attr_kind
)
4691 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
4692 if (a
->dw_attr
== attr_kind
)
4694 if (AT_class (a
) == dw_val_class_str
)
4695 if (a
->dw_attr_val
.v
.val_str
->refcount
)
4696 a
->dw_attr_val
.v
.val_str
->refcount
--;
4698 /* vec::ordered_remove should help reduce the number of abbrevs
4700 die
->die_attr
->ordered_remove (ix
);
4705 /* Remove CHILD from its parent. PREV must have the property that
4706 PREV->DIE_SIB == CHILD. Does not alter CHILD. */
4709 remove_child_with_prev (dw_die_ref child
, dw_die_ref prev
)
4711 gcc_assert (child
->die_parent
== prev
->die_parent
);
4712 gcc_assert (prev
->die_sib
== child
);
4715 gcc_assert (child
->die_parent
->die_child
== child
);
4719 prev
->die_sib
= child
->die_sib
;
4720 if (child
->die_parent
->die_child
== child
)
4721 child
->die_parent
->die_child
= prev
;
4724 /* Replace OLD_CHILD with NEW_CHILD. PREV must have the property that
4725 PREV->DIE_SIB == OLD_CHILD. Does not alter OLD_CHILD. */
4728 replace_child (dw_die_ref old_child
, dw_die_ref new_child
, dw_die_ref prev
)
4730 dw_die_ref parent
= old_child
->die_parent
;
4732 gcc_assert (parent
== prev
->die_parent
);
4733 gcc_assert (prev
->die_sib
== old_child
);
4735 new_child
->die_parent
= parent
;
4736 if (prev
== old_child
)
4738 gcc_assert (parent
->die_child
== old_child
);
4739 new_child
->die_sib
= new_child
;
4743 prev
->die_sib
= new_child
;
4744 new_child
->die_sib
= old_child
->die_sib
;
4746 if (old_child
->die_parent
->die_child
== old_child
)
4747 old_child
->die_parent
->die_child
= new_child
;
4750 /* Move all children from OLD_PARENT to NEW_PARENT. */
4753 move_all_children (dw_die_ref old_parent
, dw_die_ref new_parent
)
4756 new_parent
->die_child
= old_parent
->die_child
;
4757 old_parent
->die_child
= NULL
;
4758 FOR_EACH_CHILD (new_parent
, c
, c
->die_parent
= new_parent
);
4761 /* Remove child DIE whose die_tag is TAG. Do nothing if no child
4765 remove_child_TAG (dw_die_ref die
, enum dwarf_tag tag
)
4771 dw_die_ref prev
= c
;
4773 while (c
->die_tag
== tag
)
4775 remove_child_with_prev (c
, prev
);
4776 /* Might have removed every child. */
4777 if (c
== c
->die_sib
)
4781 } while (c
!= die
->die_child
);
4784 /* Add a CHILD_DIE as the last child of DIE. */
4787 add_child_die (dw_die_ref die
, dw_die_ref child_die
)
4789 /* FIXME this should probably be an assert. */
4790 if (! die
|| ! child_die
)
4792 gcc_assert (die
!= child_die
);
4794 child_die
->die_parent
= die
;
4797 child_die
->die_sib
= die
->die_child
->die_sib
;
4798 die
->die_child
->die_sib
= child_die
;
4801 child_die
->die_sib
= child_die
;
4802 die
->die_child
= child_die
;
4805 /* Move CHILD, which must be a child of PARENT or the DIE for which PARENT
4806 is the specification, to the end of PARENT's list of children.
4807 This is done by removing and re-adding it. */
4810 splice_child_die (dw_die_ref parent
, dw_die_ref child
)
4814 /* We want the declaration DIE from inside the class, not the
4815 specification DIE at toplevel. */
4816 if (child
->die_parent
!= parent
)
4818 dw_die_ref tmp
= get_AT_ref (child
, DW_AT_specification
);
4824 gcc_assert (child
->die_parent
== parent
4825 || (child
->die_parent
4826 == get_AT_ref (parent
, DW_AT_specification
)));
4828 for (p
= child
->die_parent
->die_child
; ; p
= p
->die_sib
)
4829 if (p
->die_sib
== child
)
4831 remove_child_with_prev (child
, p
);
4835 add_child_die (parent
, child
);
4838 /* Return a pointer to a newly created DIE node. */
4840 static inline dw_die_ref
4841 new_die (enum dwarf_tag tag_value
, dw_die_ref parent_die
, tree t
)
4843 dw_die_ref die
= ggc_alloc_cleared_die_node ();
4845 die
->die_tag
= tag_value
;
4847 if (parent_die
!= NULL
)
4848 add_child_die (parent_die
, die
);
4851 limbo_die_node
*limbo_node
;
4853 limbo_node
= ggc_alloc_cleared_limbo_die_node ();
4854 limbo_node
->die
= die
;
4855 limbo_node
->created_for
= t
;
4856 limbo_node
->next
= limbo_die_list
;
4857 limbo_die_list
= limbo_node
;
4863 /* Return the DIE associated with the given type specifier. */
4865 static inline dw_die_ref
4866 lookup_type_die (tree type
)
4868 return TYPE_SYMTAB_DIE (type
);
4871 /* Given a TYPE_DIE representing the type TYPE, if TYPE is an
4872 anonymous type named by the typedef TYPE_DIE, return the DIE of the
4873 anonymous type instead the one of the naming typedef. */
4875 static inline dw_die_ref
4876 strip_naming_typedef (tree type
, dw_die_ref type_die
)
4879 && TREE_CODE (type
) == RECORD_TYPE
4881 && type_die
->die_tag
== DW_TAG_typedef
4882 && is_naming_typedef_decl (TYPE_NAME (type
)))
4883 type_die
= get_AT_ref (type_die
, DW_AT_type
);
4887 /* Like lookup_type_die, but if type is an anonymous type named by a
4888 typedef[1], return the DIE of the anonymous type instead the one of
4889 the naming typedef. This is because in gen_typedef_die, we did
4890 equate the anonymous struct named by the typedef with the DIE of
4891 the naming typedef. So by default, lookup_type_die on an anonymous
4892 struct yields the DIE of the naming typedef.
4894 [1]: Read the comment of is_naming_typedef_decl to learn about what
4895 a naming typedef is. */
4897 static inline dw_die_ref
4898 lookup_type_die_strip_naming_typedef (tree type
)
4900 dw_die_ref die
= lookup_type_die (type
);
4901 return strip_naming_typedef (type
, die
);
4904 /* Equate a DIE to a given type specifier. */
4907 equate_type_number_to_die (tree type
, dw_die_ref type_die
)
4909 TYPE_SYMTAB_DIE (type
) = type_die
;
4912 /* Returns a hash value for X (which really is a die_struct). */
4915 decl_die_table_hash (const void *x
)
4917 return (hashval_t
) ((const_dw_die_ref
) x
)->decl_id
;
4920 /* Return nonzero if decl_id of die_struct X is the same as UID of decl *Y. */
4923 decl_die_table_eq (const void *x
, const void *y
)
4925 return (((const_dw_die_ref
) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4928 /* Return the DIE associated with a given declaration. */
4930 static inline dw_die_ref
4931 lookup_decl_die (tree decl
)
4933 return (dw_die_ref
) htab_find_with_hash (decl_die_table
, decl
, DECL_UID (decl
));
4936 /* Returns a hash value for X (which really is a var_loc_list). */
4939 decl_loc_table_hash (const void *x
)
4941 return (hashval_t
) ((const var_loc_list
*) x
)->decl_id
;
4944 /* Return nonzero if decl_id of var_loc_list X is the same as
4948 decl_loc_table_eq (const void *x
, const void *y
)
4950 return (((const var_loc_list
*) x
)->decl_id
== DECL_UID ((const_tree
) y
));
4953 /* Return the var_loc list associated with a given declaration. */
4955 static inline var_loc_list
*
4956 lookup_decl_loc (const_tree decl
)
4958 if (!decl_loc_table
)
4960 return (var_loc_list
*)
4961 htab_find_with_hash (decl_loc_table
, decl
, DECL_UID (decl
));
4964 /* Returns a hash value for X (which really is a cached_dw_loc_list_list). */
4967 cached_dw_loc_list_table_hash (const void *x
)
4969 return (hashval_t
) ((const cached_dw_loc_list
*) x
)->decl_id
;
4972 /* Return nonzero if decl_id of cached_dw_loc_list X is the same as
4976 cached_dw_loc_list_table_eq (const void *x
, const void *y
)
4978 return (((const cached_dw_loc_list
*) x
)->decl_id
4979 == DECL_UID ((const_tree
) y
));
4982 /* Equate a DIE to a particular declaration. */
4985 equate_decl_number_to_die (tree decl
, dw_die_ref decl_die
)
4987 unsigned int decl_id
= DECL_UID (decl
);
4990 slot
= htab_find_slot_with_hash (decl_die_table
, decl
, decl_id
, INSERT
);
4992 decl_die
->decl_id
= decl_id
;
4995 /* Return how many bits covers PIECE EXPR_LIST. */
4998 decl_piece_bitsize (rtx piece
)
5000 int ret
= (int) GET_MODE (piece
);
5003 gcc_assert (GET_CODE (XEXP (piece
, 0)) == CONCAT
5004 && CONST_INT_P (XEXP (XEXP (piece
, 0), 0)));
5005 return INTVAL (XEXP (XEXP (piece
, 0), 0));
5008 /* Return pointer to the location of location note in PIECE EXPR_LIST. */
5011 decl_piece_varloc_ptr (rtx piece
)
5013 if ((int) GET_MODE (piece
))
5014 return &XEXP (piece
, 0);
5016 return &XEXP (XEXP (piece
, 0), 1);
5019 /* Create an EXPR_LIST for location note LOC_NOTE covering BITSIZE bits.
5020 Next is the chain of following piece nodes. */
5023 decl_piece_node (rtx loc_note
, HOST_WIDE_INT bitsize
, rtx next
)
5025 if (bitsize
<= (int) MAX_MACHINE_MODE
)
5026 return alloc_EXPR_LIST (bitsize
, loc_note
, next
);
5028 return alloc_EXPR_LIST (0, gen_rtx_CONCAT (VOIDmode
,
5033 /* Return rtx that should be stored into loc field for
5034 LOC_NOTE and BITPOS/BITSIZE. */
5037 construct_piece_list (rtx loc_note
, HOST_WIDE_INT bitpos
,
5038 HOST_WIDE_INT bitsize
)
5042 loc_note
= decl_piece_node (loc_note
, bitsize
, NULL_RTX
);
5044 loc_note
= decl_piece_node (NULL_RTX
, bitpos
, loc_note
);
5049 /* This function either modifies location piece list *DEST in
5050 place (if SRC and INNER is NULL), or copies location piece list
5051 *SRC to *DEST while modifying it. Location BITPOS is modified
5052 to contain LOC_NOTE, any pieces overlapping it are removed resp.
5053 not copied and if needed some padding around it is added.
5054 When modifying in place, DEST should point to EXPR_LIST where
5055 earlier pieces cover PIECE_BITPOS bits, when copying SRC points
5056 to the start of the whole list and INNER points to the EXPR_LIST
5057 where earlier pieces cover PIECE_BITPOS bits. */
5060 adjust_piece_list (rtx
*dest
, rtx
*src
, rtx
*inner
,
5061 HOST_WIDE_INT bitpos
, HOST_WIDE_INT piece_bitpos
,
5062 HOST_WIDE_INT bitsize
, rtx loc_note
)
5065 bool copy
= inner
!= NULL
;
5069 /* First copy all nodes preceding the current bitpos. */
5070 while (src
!= inner
)
5072 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5073 decl_piece_bitsize (*src
), NULL_RTX
);
5074 dest
= &XEXP (*dest
, 1);
5075 src
= &XEXP (*src
, 1);
5078 /* Add padding if needed. */
5079 if (bitpos
!= piece_bitpos
)
5081 *dest
= decl_piece_node (NULL_RTX
, bitpos
- piece_bitpos
,
5082 copy
? NULL_RTX
: *dest
);
5083 dest
= &XEXP (*dest
, 1);
5085 else if (*dest
&& decl_piece_bitsize (*dest
) == bitsize
)
5088 /* A piece with correct bitpos and bitsize already exist,
5089 just update the location for it and return. */
5090 *decl_piece_varloc_ptr (*dest
) = loc_note
;
5093 /* Add the piece that changed. */
5094 *dest
= decl_piece_node (loc_note
, bitsize
, copy
? NULL_RTX
: *dest
);
5095 dest
= &XEXP (*dest
, 1);
5096 /* Skip over pieces that overlap it. */
5097 diff
= bitpos
- piece_bitpos
+ bitsize
;
5100 while (diff
> 0 && *src
)
5103 diff
-= decl_piece_bitsize (piece
);
5105 src
= &XEXP (piece
, 1);
5108 *src
= XEXP (piece
, 1);
5109 free_EXPR_LIST_node (piece
);
5112 /* Add padding if needed. */
5113 if (diff
< 0 && *src
)
5117 *dest
= decl_piece_node (NULL_RTX
, -diff
, copy
? NULL_RTX
: *dest
);
5118 dest
= &XEXP (*dest
, 1);
5122 /* Finally copy all nodes following it. */
5125 *dest
= decl_piece_node (*decl_piece_varloc_ptr (*src
),
5126 decl_piece_bitsize (*src
), NULL_RTX
);
5127 dest
= &XEXP (*dest
, 1);
5128 src
= &XEXP (*src
, 1);
5132 /* Add a variable location node to the linked list for DECL. */
5134 static struct var_loc_node
*
5135 add_var_loc_to_decl (tree decl
, rtx loc_note
, const char *label
)
5137 unsigned int decl_id
;
5140 struct var_loc_node
*loc
= NULL
;
5141 HOST_WIDE_INT bitsize
= -1, bitpos
= -1;
5143 if (TREE_CODE (decl
) == VAR_DECL
5144 && DECL_HAS_DEBUG_EXPR_P (decl
))
5146 tree realdecl
= DECL_DEBUG_EXPR (decl
);
5147 if (handled_component_p (realdecl
)
5148 || (TREE_CODE (realdecl
) == MEM_REF
5149 && TREE_CODE (TREE_OPERAND (realdecl
, 0)) == ADDR_EXPR
))
5151 HOST_WIDE_INT maxsize
;
5154 = get_ref_base_and_extent (realdecl
, &bitpos
, &bitsize
, &maxsize
);
5155 if (!DECL_P (innerdecl
)
5156 || DECL_IGNORED_P (innerdecl
)
5157 || TREE_STATIC (innerdecl
)
5159 || bitpos
+ bitsize
> 256
5160 || bitsize
!= maxsize
)
5166 decl_id
= DECL_UID (decl
);
5167 slot
= htab_find_slot_with_hash (decl_loc_table
, decl
, decl_id
, INSERT
);
5170 temp
= ggc_alloc_cleared_var_loc_list ();
5171 temp
->decl_id
= decl_id
;
5175 temp
= (var_loc_list
*) *slot
;
5177 /* For PARM_DECLs try to keep around the original incoming value,
5178 even if that means we'll emit a zero-range .debug_loc entry. */
5180 && temp
->first
== temp
->last
5181 && TREE_CODE (decl
) == PARM_DECL
5182 && NOTE_P (temp
->first
->loc
)
5183 && NOTE_VAR_LOCATION_DECL (temp
->first
->loc
) == decl
5184 && DECL_INCOMING_RTL (decl
)
5185 && NOTE_VAR_LOCATION_LOC (temp
->first
->loc
)
5186 && GET_CODE (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
))
5187 == GET_CODE (DECL_INCOMING_RTL (decl
))
5188 && prev_real_insn (temp
->first
->loc
) == NULL_RTX
5190 || !rtx_equal_p (NOTE_VAR_LOCATION_LOC (temp
->first
->loc
),
5191 NOTE_VAR_LOCATION_LOC (loc_note
))
5192 || (NOTE_VAR_LOCATION_STATUS (temp
->first
->loc
)
5193 != NOTE_VAR_LOCATION_STATUS (loc_note
))))
5195 loc
= ggc_alloc_cleared_var_loc_node ();
5196 temp
->first
->next
= loc
;
5198 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5200 else if (temp
->last
)
5202 struct var_loc_node
*last
= temp
->last
, *unused
= NULL
;
5203 rtx
*piece_loc
= NULL
, last_loc_note
;
5204 int piece_bitpos
= 0;
5208 gcc_assert (last
->next
== NULL
);
5210 if (bitsize
!= -1 && GET_CODE (last
->loc
) == EXPR_LIST
)
5212 piece_loc
= &last
->loc
;
5215 int cur_bitsize
= decl_piece_bitsize (*piece_loc
);
5216 if (piece_bitpos
+ cur_bitsize
> bitpos
)
5218 piece_bitpos
+= cur_bitsize
;
5219 piece_loc
= &XEXP (*piece_loc
, 1);
5223 /* TEMP->LAST here is either pointer to the last but one or
5224 last element in the chained list, LAST is pointer to the
5226 if (label
&& strcmp (last
->label
, label
) == 0)
5228 /* For SRA optimized variables if there weren't any real
5229 insns since last note, just modify the last node. */
5230 if (piece_loc
!= NULL
)
5232 adjust_piece_list (piece_loc
, NULL
, NULL
,
5233 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5236 /* If the last note doesn't cover any instructions, remove it. */
5237 if (temp
->last
!= last
)
5239 temp
->last
->next
= NULL
;
5242 gcc_assert (strcmp (last
->label
, label
) != 0);
5246 gcc_assert (temp
->first
== temp
->last
5247 || (temp
->first
->next
== temp
->last
5248 && TREE_CODE (decl
) == PARM_DECL
));
5249 memset (temp
->last
, '\0', sizeof (*temp
->last
));
5250 temp
->last
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5254 if (bitsize
== -1 && NOTE_P (last
->loc
))
5255 last_loc_note
= last
->loc
;
5256 else if (piece_loc
!= NULL
5257 && *piece_loc
!= NULL_RTX
5258 && piece_bitpos
== bitpos
5259 && decl_piece_bitsize (*piece_loc
) == bitsize
)
5260 last_loc_note
= *decl_piece_varloc_ptr (*piece_loc
);
5262 last_loc_note
= NULL_RTX
;
5263 /* If the current location is the same as the end of the list,
5264 and either both or neither of the locations is uninitialized,
5265 we have nothing to do. */
5266 if (last_loc_note
== NULL_RTX
5267 || (!rtx_equal_p (NOTE_VAR_LOCATION_LOC (last_loc_note
),
5268 NOTE_VAR_LOCATION_LOC (loc_note
)))
5269 || ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5270 != NOTE_VAR_LOCATION_STATUS (loc_note
))
5271 && ((NOTE_VAR_LOCATION_STATUS (last_loc_note
)
5272 == VAR_INIT_STATUS_UNINITIALIZED
)
5273 || (NOTE_VAR_LOCATION_STATUS (loc_note
)
5274 == VAR_INIT_STATUS_UNINITIALIZED
))))
5276 /* Add LOC to the end of list and update LAST. If the last
5277 element of the list has been removed above, reuse its
5278 memory for the new node, otherwise allocate a new one. */
5282 memset (loc
, '\0', sizeof (*loc
));
5285 loc
= ggc_alloc_cleared_var_loc_node ();
5286 if (bitsize
== -1 || piece_loc
== NULL
)
5287 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5289 adjust_piece_list (&loc
->loc
, &last
->loc
, piece_loc
,
5290 bitpos
, piece_bitpos
, bitsize
, loc_note
);
5292 /* Ensure TEMP->LAST will point either to the new last but one
5293 element of the chain, or to the last element in it. */
5294 if (last
!= temp
->last
)
5302 loc
= ggc_alloc_cleared_var_loc_node ();
5305 loc
->loc
= construct_piece_list (loc_note
, bitpos
, bitsize
);
5310 /* Keep track of the number of spaces used to indent the
5311 output of the debugging routines that print the structure of
5312 the DIE internal representation. */
5313 static int print_indent
;
5315 /* Indent the line the number of spaces given by print_indent. */
5318 print_spaces (FILE *outfile
)
5320 fprintf (outfile
, "%*s", print_indent
, "");
5323 /* Print a type signature in hex. */
5326 print_signature (FILE *outfile
, char *sig
)
5330 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
5331 fprintf (outfile
, "%02x", sig
[i
] & 0xff);
5334 /* Print the information associated with a given DIE, and its children.
5335 This routine is a debugging aid only. */
5338 print_die (dw_die_ref die
, FILE *outfile
)
5344 print_spaces (outfile
);
5345 fprintf (outfile
, "DIE %4ld: %s (%p)\n",
5346 die
->die_offset
, dwarf_tag_name (die
->die_tag
),
5348 print_spaces (outfile
);
5349 fprintf (outfile
, " abbrev id: %lu", die
->die_abbrev
);
5350 fprintf (outfile
, " offset: %ld", die
->die_offset
);
5351 fprintf (outfile
, " mark: %d\n", die
->die_mark
);
5353 if (die
->comdat_type_p
)
5355 print_spaces (outfile
);
5356 fprintf (outfile
, " signature: ");
5357 print_signature (outfile
, die
->die_id
.die_type_node
->signature
);
5358 fprintf (outfile
, "\n");
5361 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5363 print_spaces (outfile
);
5364 fprintf (outfile
, " %s: ", dwarf_attr_name (a
->dw_attr
));
5366 switch (AT_class (a
))
5368 case dw_val_class_addr
:
5369 fprintf (outfile
, "address");
5371 case dw_val_class_offset
:
5372 fprintf (outfile
, "offset");
5374 case dw_val_class_loc
:
5375 fprintf (outfile
, "location descriptor");
5377 case dw_val_class_loc_list
:
5378 fprintf (outfile
, "location list -> label:%s",
5379 AT_loc_list (a
)->ll_symbol
);
5381 case dw_val_class_range_list
:
5382 fprintf (outfile
, "range list");
5384 case dw_val_class_const
:
5385 fprintf (outfile
, HOST_WIDE_INT_PRINT_DEC
, AT_int (a
));
5387 case dw_val_class_unsigned_const
:
5388 fprintf (outfile
, HOST_WIDE_INT_PRINT_UNSIGNED
, AT_unsigned (a
));
5390 case dw_val_class_const_double
:
5391 fprintf (outfile
, "constant ("HOST_WIDE_INT_PRINT_DEC
","\
5392 HOST_WIDE_INT_PRINT_UNSIGNED
")",
5393 a
->dw_attr_val
.v
.val_double
.high
,
5394 a
->dw_attr_val
.v
.val_double
.low
);
5396 case dw_val_class_wide_int
:
5398 int i
= a
->dw_attr_val
.v
.val_wide
->get_len ();
5399 fprintf (outfile
, "constant (");
5401 if (a
->dw_attr_val
.v
.val_wide
->elt (i
) == 0)
5402 fprintf (outfile
, "0x");
5403 fprintf (outfile
, HOST_WIDE_INT_PRINT_HEX
,
5404 a
->dw_attr_val
.v
.val_wide
->elt (--i
));
5406 fprintf (outfile
, HOST_WIDE_INT_PRINT_PADDED_HEX
,
5407 a
->dw_attr_val
.v
.val_wide
->elt (i
));
5408 fprintf (outfile
, ")");
5411 case dw_val_class_vec
:
5412 fprintf (outfile
, "floating-point or vector constant");
5414 case dw_val_class_flag
:
5415 fprintf (outfile
, "%u", AT_flag (a
));
5417 case dw_val_class_die_ref
:
5418 if (AT_ref (a
) != NULL
)
5420 if (AT_ref (a
)->comdat_type_p
)
5422 fprintf (outfile
, "die -> signature: ");
5423 print_signature (outfile
,
5424 AT_ref (a
)->die_id
.die_type_node
->signature
);
5426 else if (AT_ref (a
)->die_id
.die_symbol
)
5427 fprintf (outfile
, "die -> label: %s",
5428 AT_ref (a
)->die_id
.die_symbol
);
5430 fprintf (outfile
, "die -> %ld", AT_ref (a
)->die_offset
);
5431 fprintf (outfile
, " (%p)", (void *) AT_ref (a
));
5434 fprintf (outfile
, "die -> <null>");
5436 case dw_val_class_vms_delta
:
5437 fprintf (outfile
, "delta: @slotcount(%s-%s)",
5438 AT_vms_delta2 (a
), AT_vms_delta1 (a
));
5440 case dw_val_class_lbl_id
:
5441 case dw_val_class_lineptr
:
5442 case dw_val_class_macptr
:
5443 case dw_val_class_high_pc
:
5444 fprintf (outfile
, "label: %s", AT_lbl (a
));
5446 case dw_val_class_str
:
5447 if (AT_string (a
) != NULL
)
5448 fprintf (outfile
, "\"%s\"", AT_string (a
));
5450 fprintf (outfile
, "<null>");
5452 case dw_val_class_file
:
5453 fprintf (outfile
, "\"%s\" (%d)", AT_file (a
)->filename
,
5454 AT_file (a
)->emitted_number
);
5456 case dw_val_class_data8
:
5460 for (i
= 0; i
< 8; i
++)
5461 fprintf (outfile
, "%02x", a
->dw_attr_val
.v
.val_data8
[i
]);
5468 fprintf (outfile
, "\n");
5471 if (die
->die_child
!= NULL
)
5474 FOR_EACH_CHILD (die
, c
, print_die (c
, outfile
));
5477 if (print_indent
== 0)
5478 fprintf (outfile
, "\n");
5481 /* Print the information collected for a given DIE. */
5484 debug_dwarf_die (dw_die_ref die
)
5486 print_die (die
, stderr
);
5490 debug (die_struct
&ref
)
5492 print_die (&ref
, stderr
);
5496 debug (die_struct
*ptr
)
5501 fprintf (stderr
, "<nil>\n");
5505 /* Print all DWARF information collected for the compilation unit.
5506 This routine is a debugging aid only. */
5512 print_die (comp_unit_die (), stderr
);
5515 /* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU
5516 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL
5517 DIE that marks the start of the DIEs for this include file. */
5520 push_new_compile_unit (dw_die_ref old_unit
, dw_die_ref bincl_die
)
5522 const char *filename
= get_AT_string (bincl_die
, DW_AT_name
);
5523 dw_die_ref new_unit
= gen_compile_unit_die (filename
);
5525 new_unit
->die_sib
= old_unit
;
5529 /* Close an include-file CU and reopen the enclosing one. */
5532 pop_compile_unit (dw_die_ref old_unit
)
5534 dw_die_ref new_unit
= old_unit
->die_sib
;
5536 old_unit
->die_sib
= NULL
;
5540 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5541 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5542 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx)
5544 /* Calculate the checksum of a location expression. */
5547 loc_checksum (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5552 tem
= (loc
->dtprel
<< 8) | ((unsigned int) loc
->dw_loc_opc
);
5554 hash
= hash_loc_operands (loc
, hash
);
5558 /* Calculate the checksum of an attribute. */
5561 attr_checksum (dw_attr_ref at
, struct md5_ctx
*ctx
, int *mark
)
5563 dw_loc_descr_ref loc
;
5566 CHECKSUM (at
->dw_attr
);
5568 /* We don't care that this was compiled with a different compiler
5569 snapshot; if the output is the same, that's what matters. */
5570 if (at
->dw_attr
== DW_AT_producer
)
5573 switch (AT_class (at
))
5575 case dw_val_class_const
:
5576 CHECKSUM (at
->dw_attr_val
.v
.val_int
);
5578 case dw_val_class_unsigned_const
:
5579 CHECKSUM (at
->dw_attr_val
.v
.val_unsigned
);
5581 case dw_val_class_const_double
:
5582 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5584 case dw_val_class_wide_int
:
5585 CHECKSUM (*at
->dw_attr_val
.v
.val_wide
);
5587 case dw_val_class_vec
:
5588 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5589 (at
->dw_attr_val
.v
.val_vec
.length
5590 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5592 case dw_val_class_flag
:
5593 CHECKSUM (at
->dw_attr_val
.v
.val_flag
);
5595 case dw_val_class_str
:
5596 CHECKSUM_STRING (AT_string (at
));
5599 case dw_val_class_addr
:
5601 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5602 CHECKSUM_STRING (XSTR (r
, 0));
5605 case dw_val_class_offset
:
5606 CHECKSUM (at
->dw_attr_val
.v
.val_offset
);
5609 case dw_val_class_loc
:
5610 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5611 loc_checksum (loc
, ctx
);
5614 case dw_val_class_die_ref
:
5615 die_checksum (AT_ref (at
), ctx
, mark
);
5618 case dw_val_class_fde_ref
:
5619 case dw_val_class_vms_delta
:
5620 case dw_val_class_lbl_id
:
5621 case dw_val_class_lineptr
:
5622 case dw_val_class_macptr
:
5623 case dw_val_class_high_pc
:
5626 case dw_val_class_file
:
5627 CHECKSUM_STRING (AT_file (at
)->filename
);
5630 case dw_val_class_data8
:
5631 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5639 /* Calculate the checksum of a DIE. */
5642 die_checksum (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
5648 /* To avoid infinite recursion. */
5651 CHECKSUM (die
->die_mark
);
5654 die
->die_mark
= ++(*mark
);
5656 CHECKSUM (die
->die_tag
);
5658 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5659 attr_checksum (a
, ctx
, mark
);
5661 FOR_EACH_CHILD (die
, c
, die_checksum (c
, ctx
, mark
));
5665 #undef CHECKSUM_BLOCK
5666 #undef CHECKSUM_STRING
5668 /* For DWARF-4 types, include the trailing NULL when checksumming strings. */
5669 #define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx)
5670 #define CHECKSUM_BLOCK(FOO, SIZE) md5_process_bytes ((FOO), (SIZE), ctx)
5671 #define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO) + 1, ctx)
5672 #define CHECKSUM_SLEB128(FOO) checksum_sleb128 ((FOO), ctx)
5673 #define CHECKSUM_ULEB128(FOO) checksum_uleb128 ((FOO), ctx)
5674 #define CHECKSUM_ATTR(FOO) \
5675 if (FOO) attr_checksum_ordered (die->die_tag, (FOO), ctx, mark)
5677 /* Calculate the checksum of a number in signed LEB128 format. */
5680 checksum_sleb128 (HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5687 byte
= (value
& 0x7f);
5689 more
= !((value
== 0 && (byte
& 0x40) == 0)
5690 || (value
== -1 && (byte
& 0x40) != 0));
5699 /* Calculate the checksum of a number in unsigned LEB128 format. */
5702 checksum_uleb128 (unsigned HOST_WIDE_INT value
, struct md5_ctx
*ctx
)
5706 unsigned char byte
= (value
& 0x7f);
5709 /* More bytes to follow. */
5717 /* Checksum the context of the DIE. This adds the names of any
5718 surrounding namespaces or structures to the checksum. */
5721 checksum_die_context (dw_die_ref die
, struct md5_ctx
*ctx
)
5725 int tag
= die
->die_tag
;
5727 if (tag
!= DW_TAG_namespace
5728 && tag
!= DW_TAG_structure_type
5729 && tag
!= DW_TAG_class_type
)
5732 name
= get_AT_string (die
, DW_AT_name
);
5734 spec
= get_AT_ref (die
, DW_AT_specification
);
5738 if (die
->die_parent
!= NULL
)
5739 checksum_die_context (die
->die_parent
, ctx
);
5741 CHECKSUM_ULEB128 ('C');
5742 CHECKSUM_ULEB128 (tag
);
5744 CHECKSUM_STRING (name
);
5747 /* Calculate the checksum of a location expression. */
5750 loc_checksum_ordered (dw_loc_descr_ref loc
, struct md5_ctx
*ctx
)
5752 /* Special case for lone DW_OP_plus_uconst: checksum as if the location
5753 were emitted as a DW_FORM_sdata instead of a location expression. */
5754 if (loc
->dw_loc_opc
== DW_OP_plus_uconst
&& loc
->dw_loc_next
== NULL
)
5756 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5757 CHECKSUM_SLEB128 ((HOST_WIDE_INT
) loc
->dw_loc_oprnd1
.v
.val_unsigned
);
5761 /* Otherwise, just checksum the raw location expression. */
5766 CHECKSUM_ULEB128 (loc
->dtprel
);
5767 CHECKSUM_ULEB128 (loc
->dw_loc_opc
);
5768 hash
= hash_loc_operands (loc
, hash
);
5770 loc
= loc
->dw_loc_next
;
5774 /* Calculate the checksum of an attribute. */
5777 attr_checksum_ordered (enum dwarf_tag tag
, dw_attr_ref at
,
5778 struct md5_ctx
*ctx
, int *mark
)
5780 dw_loc_descr_ref loc
;
5783 if (AT_class (at
) == dw_val_class_die_ref
)
5785 dw_die_ref target_die
= AT_ref (at
);
5787 /* For pointer and reference types, we checksum only the (qualified)
5788 name of the target type (if there is a name). For friend entries,
5789 we checksum only the (qualified) name of the target type or function.
5790 This allows the checksum to remain the same whether the target type
5791 is complete or not. */
5792 if ((at
->dw_attr
== DW_AT_type
5793 && (tag
== DW_TAG_pointer_type
5794 || tag
== DW_TAG_reference_type
5795 || tag
== DW_TAG_rvalue_reference_type
5796 || tag
== DW_TAG_ptr_to_member_type
))
5797 || (at
->dw_attr
== DW_AT_friend
5798 && tag
== DW_TAG_friend
))
5800 dw_attr_ref name_attr
= get_AT (target_die
, DW_AT_name
);
5802 if (name_attr
!= NULL
)
5804 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5808 CHECKSUM_ULEB128 ('N');
5809 CHECKSUM_ULEB128 (at
->dw_attr
);
5810 if (decl
->die_parent
!= NULL
)
5811 checksum_die_context (decl
->die_parent
, ctx
);
5812 CHECKSUM_ULEB128 ('E');
5813 CHECKSUM_STRING (AT_string (name_attr
));
5818 /* For all other references to another DIE, we check to see if the
5819 target DIE has already been visited. If it has, we emit a
5820 backward reference; if not, we descend recursively. */
5821 if (target_die
->die_mark
> 0)
5823 CHECKSUM_ULEB128 ('R');
5824 CHECKSUM_ULEB128 (at
->dw_attr
);
5825 CHECKSUM_ULEB128 (target_die
->die_mark
);
5829 dw_die_ref decl
= get_AT_ref (target_die
, DW_AT_specification
);
5833 target_die
->die_mark
= ++(*mark
);
5834 CHECKSUM_ULEB128 ('T');
5835 CHECKSUM_ULEB128 (at
->dw_attr
);
5836 if (decl
->die_parent
!= NULL
)
5837 checksum_die_context (decl
->die_parent
, ctx
);
5838 die_checksum_ordered (target_die
, ctx
, mark
);
5843 CHECKSUM_ULEB128 ('A');
5844 CHECKSUM_ULEB128 (at
->dw_attr
);
5846 switch (AT_class (at
))
5848 case dw_val_class_const
:
5849 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5850 CHECKSUM_SLEB128 (at
->dw_attr_val
.v
.val_int
);
5853 case dw_val_class_unsigned_const
:
5854 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5855 CHECKSUM_SLEB128 ((int) at
->dw_attr_val
.v
.val_unsigned
);
5858 case dw_val_class_const_double
:
5859 CHECKSUM_ULEB128 (DW_FORM_block
);
5860 CHECKSUM_ULEB128 (sizeof (at
->dw_attr_val
.v
.val_double
));
5861 CHECKSUM (at
->dw_attr_val
.v
.val_double
);
5864 case dw_val_class_wide_int
:
5865 CHECKSUM_ULEB128 (DW_FORM_block
);
5866 CHECKSUM_ULEB128 (sizeof (*at
->dw_attr_val
.v
.val_wide
));
5867 CHECKSUM (*at
->dw_attr_val
.v
.val_wide
);
5870 case dw_val_class_vec
:
5871 CHECKSUM_ULEB128 (DW_FORM_block
);
5872 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_vec
.length
5873 * at
->dw_attr_val
.v
.val_vec
.elt_size
);
5874 CHECKSUM_BLOCK (at
->dw_attr_val
.v
.val_vec
.array
,
5875 (at
->dw_attr_val
.v
.val_vec
.length
5876 * at
->dw_attr_val
.v
.val_vec
.elt_size
));
5879 case dw_val_class_flag
:
5880 CHECKSUM_ULEB128 (DW_FORM_flag
);
5881 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_flag
? 1 : 0);
5884 case dw_val_class_str
:
5885 CHECKSUM_ULEB128 (DW_FORM_string
);
5886 CHECKSUM_STRING (AT_string (at
));
5889 case dw_val_class_addr
:
5891 gcc_assert (GET_CODE (r
) == SYMBOL_REF
);
5892 CHECKSUM_ULEB128 (DW_FORM_string
);
5893 CHECKSUM_STRING (XSTR (r
, 0));
5896 case dw_val_class_offset
:
5897 CHECKSUM_ULEB128 (DW_FORM_sdata
);
5898 CHECKSUM_ULEB128 (at
->dw_attr_val
.v
.val_offset
);
5901 case dw_val_class_loc
:
5902 for (loc
= AT_loc (at
); loc
; loc
= loc
->dw_loc_next
)
5903 loc_checksum_ordered (loc
, ctx
);
5906 case dw_val_class_fde_ref
:
5907 case dw_val_class_lbl_id
:
5908 case dw_val_class_lineptr
:
5909 case dw_val_class_macptr
:
5910 case dw_val_class_high_pc
:
5913 case dw_val_class_file
:
5914 CHECKSUM_ULEB128 (DW_FORM_string
);
5915 CHECKSUM_STRING (AT_file (at
)->filename
);
5918 case dw_val_class_data8
:
5919 CHECKSUM (at
->dw_attr_val
.v
.val_data8
);
5927 struct checksum_attributes
5929 dw_attr_ref at_name
;
5930 dw_attr_ref at_type
;
5931 dw_attr_ref at_friend
;
5932 dw_attr_ref at_accessibility
;
5933 dw_attr_ref at_address_class
;
5934 dw_attr_ref at_allocated
;
5935 dw_attr_ref at_artificial
;
5936 dw_attr_ref at_associated
;
5937 dw_attr_ref at_binary_scale
;
5938 dw_attr_ref at_bit_offset
;
5939 dw_attr_ref at_bit_size
;
5940 dw_attr_ref at_bit_stride
;
5941 dw_attr_ref at_byte_size
;
5942 dw_attr_ref at_byte_stride
;
5943 dw_attr_ref at_const_value
;
5944 dw_attr_ref at_containing_type
;
5945 dw_attr_ref at_count
;
5946 dw_attr_ref at_data_location
;
5947 dw_attr_ref at_data_member_location
;
5948 dw_attr_ref at_decimal_scale
;
5949 dw_attr_ref at_decimal_sign
;
5950 dw_attr_ref at_default_value
;
5951 dw_attr_ref at_digit_count
;
5952 dw_attr_ref at_discr
;
5953 dw_attr_ref at_discr_list
;
5954 dw_attr_ref at_discr_value
;
5955 dw_attr_ref at_encoding
;
5956 dw_attr_ref at_endianity
;
5957 dw_attr_ref at_explicit
;
5958 dw_attr_ref at_is_optional
;
5959 dw_attr_ref at_location
;
5960 dw_attr_ref at_lower_bound
;
5961 dw_attr_ref at_mutable
;
5962 dw_attr_ref at_ordering
;
5963 dw_attr_ref at_picture_string
;
5964 dw_attr_ref at_prototyped
;
5965 dw_attr_ref at_small
;
5966 dw_attr_ref at_segment
;
5967 dw_attr_ref at_string_length
;
5968 dw_attr_ref at_threads_scaled
;
5969 dw_attr_ref at_upper_bound
;
5970 dw_attr_ref at_use_location
;
5971 dw_attr_ref at_use_UTF8
;
5972 dw_attr_ref at_variable_parameter
;
5973 dw_attr_ref at_virtuality
;
5974 dw_attr_ref at_visibility
;
5975 dw_attr_ref at_vtable_elem_location
;
5978 /* Collect the attributes that we will want to use for the checksum. */
5981 collect_checksum_attributes (struct checksum_attributes
*attrs
, dw_die_ref die
)
5986 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
5997 attrs
->at_friend
= a
;
5999 case DW_AT_accessibility
:
6000 attrs
->at_accessibility
= a
;
6002 case DW_AT_address_class
:
6003 attrs
->at_address_class
= a
;
6005 case DW_AT_allocated
:
6006 attrs
->at_allocated
= a
;
6008 case DW_AT_artificial
:
6009 attrs
->at_artificial
= a
;
6011 case DW_AT_associated
:
6012 attrs
->at_associated
= a
;
6014 case DW_AT_binary_scale
:
6015 attrs
->at_binary_scale
= a
;
6017 case DW_AT_bit_offset
:
6018 attrs
->at_bit_offset
= a
;
6020 case DW_AT_bit_size
:
6021 attrs
->at_bit_size
= a
;
6023 case DW_AT_bit_stride
:
6024 attrs
->at_bit_stride
= a
;
6026 case DW_AT_byte_size
:
6027 attrs
->at_byte_size
= a
;
6029 case DW_AT_byte_stride
:
6030 attrs
->at_byte_stride
= a
;
6032 case DW_AT_const_value
:
6033 attrs
->at_const_value
= a
;
6035 case DW_AT_containing_type
:
6036 attrs
->at_containing_type
= a
;
6039 attrs
->at_count
= a
;
6041 case DW_AT_data_location
:
6042 attrs
->at_data_location
= a
;
6044 case DW_AT_data_member_location
:
6045 attrs
->at_data_member_location
= a
;
6047 case DW_AT_decimal_scale
:
6048 attrs
->at_decimal_scale
= a
;
6050 case DW_AT_decimal_sign
:
6051 attrs
->at_decimal_sign
= a
;
6053 case DW_AT_default_value
:
6054 attrs
->at_default_value
= a
;
6056 case DW_AT_digit_count
:
6057 attrs
->at_digit_count
= a
;
6060 attrs
->at_discr
= a
;
6062 case DW_AT_discr_list
:
6063 attrs
->at_discr_list
= a
;
6065 case DW_AT_discr_value
:
6066 attrs
->at_discr_value
= a
;
6068 case DW_AT_encoding
:
6069 attrs
->at_encoding
= a
;
6071 case DW_AT_endianity
:
6072 attrs
->at_endianity
= a
;
6074 case DW_AT_explicit
:
6075 attrs
->at_explicit
= a
;
6077 case DW_AT_is_optional
:
6078 attrs
->at_is_optional
= a
;
6080 case DW_AT_location
:
6081 attrs
->at_location
= a
;
6083 case DW_AT_lower_bound
:
6084 attrs
->at_lower_bound
= a
;
6087 attrs
->at_mutable
= a
;
6089 case DW_AT_ordering
:
6090 attrs
->at_ordering
= a
;
6092 case DW_AT_picture_string
:
6093 attrs
->at_picture_string
= a
;
6095 case DW_AT_prototyped
:
6096 attrs
->at_prototyped
= a
;
6099 attrs
->at_small
= a
;
6102 attrs
->at_segment
= a
;
6104 case DW_AT_string_length
:
6105 attrs
->at_string_length
= a
;
6107 case DW_AT_threads_scaled
:
6108 attrs
->at_threads_scaled
= a
;
6110 case DW_AT_upper_bound
:
6111 attrs
->at_upper_bound
= a
;
6113 case DW_AT_use_location
:
6114 attrs
->at_use_location
= a
;
6116 case DW_AT_use_UTF8
:
6117 attrs
->at_use_UTF8
= a
;
6119 case DW_AT_variable_parameter
:
6120 attrs
->at_variable_parameter
= a
;
6122 case DW_AT_virtuality
:
6123 attrs
->at_virtuality
= a
;
6125 case DW_AT_visibility
:
6126 attrs
->at_visibility
= a
;
6128 case DW_AT_vtable_elem_location
:
6129 attrs
->at_vtable_elem_location
= a
;
6137 /* Calculate the checksum of a DIE, using an ordered subset of attributes. */
6140 die_checksum_ordered (dw_die_ref die
, struct md5_ctx
*ctx
, int *mark
)
6144 struct checksum_attributes attrs
;
6146 CHECKSUM_ULEB128 ('D');
6147 CHECKSUM_ULEB128 (die
->die_tag
);
6149 memset (&attrs
, 0, sizeof (attrs
));
6151 decl
= get_AT_ref (die
, DW_AT_specification
);
6153 collect_checksum_attributes (&attrs
, decl
);
6154 collect_checksum_attributes (&attrs
, die
);
6156 CHECKSUM_ATTR (attrs
.at_name
);
6157 CHECKSUM_ATTR (attrs
.at_accessibility
);
6158 CHECKSUM_ATTR (attrs
.at_address_class
);
6159 CHECKSUM_ATTR (attrs
.at_allocated
);
6160 CHECKSUM_ATTR (attrs
.at_artificial
);
6161 CHECKSUM_ATTR (attrs
.at_associated
);
6162 CHECKSUM_ATTR (attrs
.at_binary_scale
);
6163 CHECKSUM_ATTR (attrs
.at_bit_offset
);
6164 CHECKSUM_ATTR (attrs
.at_bit_size
);
6165 CHECKSUM_ATTR (attrs
.at_bit_stride
);
6166 CHECKSUM_ATTR (attrs
.at_byte_size
);
6167 CHECKSUM_ATTR (attrs
.at_byte_stride
);
6168 CHECKSUM_ATTR (attrs
.at_const_value
);
6169 CHECKSUM_ATTR (attrs
.at_containing_type
);
6170 CHECKSUM_ATTR (attrs
.at_count
);
6171 CHECKSUM_ATTR (attrs
.at_data_location
);
6172 CHECKSUM_ATTR (attrs
.at_data_member_location
);
6173 CHECKSUM_ATTR (attrs
.at_decimal_scale
);
6174 CHECKSUM_ATTR (attrs
.at_decimal_sign
);
6175 CHECKSUM_ATTR (attrs
.at_default_value
);
6176 CHECKSUM_ATTR (attrs
.at_digit_count
);
6177 CHECKSUM_ATTR (attrs
.at_discr
);
6178 CHECKSUM_ATTR (attrs
.at_discr_list
);
6179 CHECKSUM_ATTR (attrs
.at_discr_value
);
6180 CHECKSUM_ATTR (attrs
.at_encoding
);
6181 CHECKSUM_ATTR (attrs
.at_endianity
);
6182 CHECKSUM_ATTR (attrs
.at_explicit
);
6183 CHECKSUM_ATTR (attrs
.at_is_optional
);
6184 CHECKSUM_ATTR (attrs
.at_location
);
6185 CHECKSUM_ATTR (attrs
.at_lower_bound
);
6186 CHECKSUM_ATTR (attrs
.at_mutable
);
6187 CHECKSUM_ATTR (attrs
.at_ordering
);
6188 CHECKSUM_ATTR (attrs
.at_picture_string
);
6189 CHECKSUM_ATTR (attrs
.at_prototyped
);
6190 CHECKSUM_ATTR (attrs
.at_small
);
6191 CHECKSUM_ATTR (attrs
.at_segment
);
6192 CHECKSUM_ATTR (attrs
.at_string_length
);
6193 CHECKSUM_ATTR (attrs
.at_threads_scaled
);
6194 CHECKSUM_ATTR (attrs
.at_upper_bound
);
6195 CHECKSUM_ATTR (attrs
.at_use_location
);
6196 CHECKSUM_ATTR (attrs
.at_use_UTF8
);
6197 CHECKSUM_ATTR (attrs
.at_variable_parameter
);
6198 CHECKSUM_ATTR (attrs
.at_virtuality
);
6199 CHECKSUM_ATTR (attrs
.at_visibility
);
6200 CHECKSUM_ATTR (attrs
.at_vtable_elem_location
);
6201 CHECKSUM_ATTR (attrs
.at_type
);
6202 CHECKSUM_ATTR (attrs
.at_friend
);
6204 /* Checksum the child DIEs. */
6207 dw_attr_ref name_attr
;
6210 name_attr
= get_AT (c
, DW_AT_name
);
6211 if (is_template_instantiation (c
))
6213 /* Ignore instantiations of member type and function templates. */
6215 else if (name_attr
!= NULL
6216 && (is_type_die (c
) || c
->die_tag
== DW_TAG_subprogram
))
6218 /* Use a shallow checksum for named nested types and member
6220 CHECKSUM_ULEB128 ('S');
6221 CHECKSUM_ULEB128 (c
->die_tag
);
6222 CHECKSUM_STRING (AT_string (name_attr
));
6226 /* Use a deep checksum for other children. */
6227 /* Mark this DIE so it gets processed when unmarking. */
6228 if (c
->die_mark
== 0)
6230 die_checksum_ordered (c
, ctx
, mark
);
6232 } while (c
!= die
->die_child
);
6234 CHECKSUM_ULEB128 (0);
6237 /* Add a type name and tag to a hash. */
6239 die_odr_checksum (int tag
, const char *name
, md5_ctx
*ctx
)
6241 CHECKSUM_ULEB128 (tag
);
6242 CHECKSUM_STRING (name
);
6246 #undef CHECKSUM_STRING
6247 #undef CHECKSUM_ATTR
6248 #undef CHECKSUM_LEB128
6249 #undef CHECKSUM_ULEB128
6251 /* Generate the type signature for DIE. This is computed by generating an
6252 MD5 checksum over the DIE's tag, its relevant attributes, and its
6253 children. Attributes that are references to other DIEs are processed
6254 by recursion, using the MARK field to prevent infinite recursion.
6255 If the DIE is nested inside a namespace or another type, we also
6256 need to include that context in the signature. The lower 64 bits
6257 of the resulting MD5 checksum comprise the signature. */
6260 generate_type_signature (dw_die_ref die
, comdat_type_node
*type_node
)
6264 unsigned char checksum
[16];
6269 name
= get_AT_string (die
, DW_AT_name
);
6270 decl
= get_AT_ref (die
, DW_AT_specification
);
6271 parent
= get_die_parent (die
);
6273 /* First, compute a signature for just the type name (and its surrounding
6274 context, if any. This is stored in the type unit DIE for link-time
6275 ODR (one-definition rule) checking. */
6277 if (is_cxx () && name
!= NULL
)
6279 md5_init_ctx (&ctx
);
6281 /* Checksum the names of surrounding namespaces and structures. */
6283 checksum_die_context (parent
, &ctx
);
6285 /* Checksum the current DIE. */
6286 die_odr_checksum (die
->die_tag
, name
, &ctx
);
6287 md5_finish_ctx (&ctx
, checksum
);
6289 add_AT_data8 (type_node
->root_die
, DW_AT_GNU_odr_signature
, &checksum
[8]);
6292 /* Next, compute the complete type signature. */
6294 md5_init_ctx (&ctx
);
6296 die
->die_mark
= mark
;
6298 /* Checksum the names of surrounding namespaces and structures. */
6300 checksum_die_context (parent
, &ctx
);
6302 /* Checksum the DIE and its children. */
6303 die_checksum_ordered (die
, &ctx
, &mark
);
6304 unmark_all_dies (die
);
6305 md5_finish_ctx (&ctx
, checksum
);
6307 /* Store the signature in the type node and link the type DIE and the
6308 type node together. */
6309 memcpy (type_node
->signature
, &checksum
[16 - DWARF_TYPE_SIGNATURE_SIZE
],
6310 DWARF_TYPE_SIGNATURE_SIZE
);
6311 die
->comdat_type_p
= true;
6312 die
->die_id
.die_type_node
= type_node
;
6313 type_node
->type_die
= die
;
6315 /* If the DIE is a specification, link its declaration to the type node
6319 decl
->comdat_type_p
= true;
6320 decl
->die_id
.die_type_node
= type_node
;
6324 /* Do the location expressions look same? */
6326 same_loc_p (dw_loc_descr_ref loc1
, dw_loc_descr_ref loc2
, int *mark
)
6328 return loc1
->dw_loc_opc
== loc2
->dw_loc_opc
6329 && same_dw_val_p (&loc1
->dw_loc_oprnd1
, &loc2
->dw_loc_oprnd1
, mark
)
6330 && same_dw_val_p (&loc1
->dw_loc_oprnd2
, &loc2
->dw_loc_oprnd2
, mark
);
6333 /* Do the values look the same? */
6335 same_dw_val_p (const dw_val_node
*v1
, const dw_val_node
*v2
, int *mark
)
6337 dw_loc_descr_ref loc1
, loc2
;
6340 if (v1
->val_class
!= v2
->val_class
)
6343 switch (v1
->val_class
)
6345 case dw_val_class_const
:
6346 return v1
->v
.val_int
== v2
->v
.val_int
;
6347 case dw_val_class_unsigned_const
:
6348 return v1
->v
.val_unsigned
== v2
->v
.val_unsigned
;
6349 case dw_val_class_const_double
:
6350 return v1
->v
.val_double
.high
== v2
->v
.val_double
.high
6351 && v1
->v
.val_double
.low
== v2
->v
.val_double
.low
;
6352 case dw_val_class_wide_int
:
6353 return *v1
->v
.val_wide
== *v2
->v
.val_wide
;
6354 case dw_val_class_vec
:
6355 if (v1
->v
.val_vec
.length
!= v2
->v
.val_vec
.length
6356 || v1
->v
.val_vec
.elt_size
!= v2
->v
.val_vec
.elt_size
)
6358 if (memcmp (v1
->v
.val_vec
.array
, v2
->v
.val_vec
.array
,
6359 v1
->v
.val_vec
.length
* v1
->v
.val_vec
.elt_size
))
6362 case dw_val_class_flag
:
6363 return v1
->v
.val_flag
== v2
->v
.val_flag
;
6364 case dw_val_class_str
:
6365 return !strcmp (v1
->v
.val_str
->str
, v2
->v
.val_str
->str
);
6367 case dw_val_class_addr
:
6368 r1
= v1
->v
.val_addr
;
6369 r2
= v2
->v
.val_addr
;
6370 if (GET_CODE (r1
) != GET_CODE (r2
))
6372 return !rtx_equal_p (r1
, r2
);
6374 case dw_val_class_offset
:
6375 return v1
->v
.val_offset
== v2
->v
.val_offset
;
6377 case dw_val_class_loc
:
6378 for (loc1
= v1
->v
.val_loc
, loc2
= v2
->v
.val_loc
;
6380 loc1
= loc1
->dw_loc_next
, loc2
= loc2
->dw_loc_next
)
6381 if (!same_loc_p (loc1
, loc2
, mark
))
6383 return !loc1
&& !loc2
;
6385 case dw_val_class_die_ref
:
6386 return same_die_p (v1
->v
.val_die_ref
.die
, v2
->v
.val_die_ref
.die
, mark
);
6388 case dw_val_class_fde_ref
:
6389 case dw_val_class_vms_delta
:
6390 case dw_val_class_lbl_id
:
6391 case dw_val_class_lineptr
:
6392 case dw_val_class_macptr
:
6393 case dw_val_class_high_pc
:
6396 case dw_val_class_file
:
6397 return v1
->v
.val_file
== v2
->v
.val_file
;
6399 case dw_val_class_data8
:
6400 return !memcmp (v1
->v
.val_data8
, v2
->v
.val_data8
, 8);
6407 /* Do the attributes look the same? */
6410 same_attr_p (dw_attr_ref at1
, dw_attr_ref at2
, int *mark
)
6412 if (at1
->dw_attr
!= at2
->dw_attr
)
6415 /* We don't care that this was compiled with a different compiler
6416 snapshot; if the output is the same, that's what matters. */
6417 if (at1
->dw_attr
== DW_AT_producer
)
6420 return same_dw_val_p (&at1
->dw_attr_val
, &at2
->dw_attr_val
, mark
);
6423 /* Do the dies look the same? */
6426 same_die_p (dw_die_ref die1
, dw_die_ref die2
, int *mark
)
6432 /* To avoid infinite recursion. */
6434 return die1
->die_mark
== die2
->die_mark
;
6435 die1
->die_mark
= die2
->die_mark
= ++(*mark
);
6437 if (die1
->die_tag
!= die2
->die_tag
)
6440 if (vec_safe_length (die1
->die_attr
) != vec_safe_length (die2
->die_attr
))
6443 FOR_EACH_VEC_SAFE_ELT (die1
->die_attr
, ix
, a1
)
6444 if (!same_attr_p (a1
, &(*die2
->die_attr
)[ix
], mark
))
6447 c1
= die1
->die_child
;
6448 c2
= die2
->die_child
;
6457 if (!same_die_p (c1
, c2
, mark
))
6461 if (c1
== die1
->die_child
)
6463 if (c2
== die2
->die_child
)
6473 /* Do the dies look the same? Wrapper around same_die_p. */
6476 same_die_p_wrap (dw_die_ref die1
, dw_die_ref die2
)
6479 int ret
= same_die_p (die1
, die2
, &mark
);
6481 unmark_all_dies (die1
);
6482 unmark_all_dies (die2
);
6487 /* The prefix to attach to symbols on DIEs in the current comdat debug
6489 static const char *comdat_symbol_id
;
6491 /* The index of the current symbol within the current comdat CU. */
6492 static unsigned int comdat_symbol_number
;
6494 /* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its
6495 children, and set comdat_symbol_id accordingly. */
6498 compute_section_prefix (dw_die_ref unit_die
)
6500 const char *die_name
= get_AT_string (unit_die
, DW_AT_name
);
6501 const char *base
= die_name
? lbasename (die_name
) : "anonymous";
6502 char *name
= XALLOCAVEC (char, strlen (base
) + 64);
6505 unsigned char checksum
[16];
6508 /* Compute the checksum of the DIE, then append part of it as hex digits to
6509 the name filename of the unit. */
6511 md5_init_ctx (&ctx
);
6513 die_checksum (unit_die
, &ctx
, &mark
);
6514 unmark_all_dies (unit_die
);
6515 md5_finish_ctx (&ctx
, checksum
);
6517 sprintf (name
, "%s.", base
);
6518 clean_symbol_name (name
);
6520 p
= name
+ strlen (name
);
6521 for (i
= 0; i
< 4; i
++)
6523 sprintf (p
, "%.2x", checksum
[i
]);
6527 comdat_symbol_id
= unit_die
->die_id
.die_symbol
= xstrdup (name
);
6528 comdat_symbol_number
= 0;
6531 /* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */
6534 is_type_die (dw_die_ref die
)
6536 switch (die
->die_tag
)
6538 case DW_TAG_array_type
:
6539 case DW_TAG_class_type
:
6540 case DW_TAG_interface_type
:
6541 case DW_TAG_enumeration_type
:
6542 case DW_TAG_pointer_type
:
6543 case DW_TAG_reference_type
:
6544 case DW_TAG_rvalue_reference_type
:
6545 case DW_TAG_string_type
:
6546 case DW_TAG_structure_type
:
6547 case DW_TAG_subroutine_type
:
6548 case DW_TAG_union_type
:
6549 case DW_TAG_ptr_to_member_type
:
6550 case DW_TAG_set_type
:
6551 case DW_TAG_subrange_type
:
6552 case DW_TAG_base_type
:
6553 case DW_TAG_const_type
:
6554 case DW_TAG_file_type
:
6555 case DW_TAG_packed_type
:
6556 case DW_TAG_volatile_type
:
6557 case DW_TAG_typedef
:
6564 /* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU.
6565 Basically, we want to choose the bits that are likely to be shared between
6566 compilations (types) and leave out the bits that are specific to individual
6567 compilations (functions). */
6570 is_comdat_die (dw_die_ref c
)
6572 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as
6573 we do for stabs. The advantage is a greater likelihood of sharing between
6574 objects that don't include headers in the same order (and therefore would
6575 put the base types in a different comdat). jason 8/28/00 */
6577 if (c
->die_tag
== DW_TAG_base_type
)
6580 if (c
->die_tag
== DW_TAG_pointer_type
6581 || c
->die_tag
== DW_TAG_reference_type
6582 || c
->die_tag
== DW_TAG_rvalue_reference_type
6583 || c
->die_tag
== DW_TAG_const_type
6584 || c
->die_tag
== DW_TAG_volatile_type
)
6586 dw_die_ref t
= get_AT_ref (c
, DW_AT_type
);
6588 return t
? is_comdat_die (t
) : 0;
6591 return is_type_die (c
);
6594 /* Returns 1 iff C is the sort of DIE that might be referred to from another
6595 compilation unit. */
6598 is_symbol_die (dw_die_ref c
)
6600 return (is_type_die (c
)
6601 || is_declaration_die (c
)
6602 || c
->die_tag
== DW_TAG_namespace
6603 || c
->die_tag
== DW_TAG_module
);
6606 /* Returns true iff C is a compile-unit DIE. */
6609 is_cu_die (dw_die_ref c
)
6611 return c
&& c
->die_tag
== DW_TAG_compile_unit
;
6614 /* Returns true iff C is a unit DIE of some sort. */
6617 is_unit_die (dw_die_ref c
)
6619 return c
&& (c
->die_tag
== DW_TAG_compile_unit
6620 || c
->die_tag
== DW_TAG_partial_unit
6621 || c
->die_tag
== DW_TAG_type_unit
);
6624 /* Returns true iff C is a namespace DIE. */
6627 is_namespace_die (dw_die_ref c
)
6629 return c
&& c
->die_tag
== DW_TAG_namespace
;
6632 /* Returns true iff C is a class or structure DIE. */
6635 is_class_die (dw_die_ref c
)
6637 return c
&& (c
->die_tag
== DW_TAG_class_type
6638 || c
->die_tag
== DW_TAG_structure_type
);
6641 /* Return non-zero if this DIE is a template parameter. */
6644 is_template_parameter (dw_die_ref die
)
6646 switch (die
->die_tag
)
6648 case DW_TAG_template_type_param
:
6649 case DW_TAG_template_value_param
:
6650 case DW_TAG_GNU_template_template_param
:
6651 case DW_TAG_GNU_template_parameter_pack
:
6658 /* Return non-zero if this DIE represents a template instantiation. */
6661 is_template_instantiation (dw_die_ref die
)
6665 if (!is_type_die (die
) && die
->die_tag
!= DW_TAG_subprogram
)
6667 FOR_EACH_CHILD (die
, c
, if (is_template_parameter (c
)) return true);
6672 gen_internal_sym (const char *prefix
)
6676 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, label_num
++);
6677 return xstrdup (buf
);
6680 /* Assign symbols to all worthy DIEs under DIE. */
6683 assign_symbol_names (dw_die_ref die
)
6687 if (is_symbol_die (die
) && !die
->comdat_type_p
)
6689 if (comdat_symbol_id
)
6691 char *p
= XALLOCAVEC (char, strlen (comdat_symbol_id
) + 64);
6693 sprintf (p
, "%s.%s.%x", DIE_LABEL_PREFIX
,
6694 comdat_symbol_id
, comdat_symbol_number
++);
6695 die
->die_id
.die_symbol
= xstrdup (p
);
6698 die
->die_id
.die_symbol
= gen_internal_sym ("LDIE");
6701 FOR_EACH_CHILD (die
, c
, assign_symbol_names (c
));
6704 struct cu_hash_table_entry
6707 unsigned min_comdat_num
, max_comdat_num
;
6708 struct cu_hash_table_entry
*next
;
6711 /* Helpers to manipulate hash table of CUs. */
6713 struct cu_hash_table_entry_hasher
6715 typedef cu_hash_table_entry value_type
;
6716 typedef die_struct compare_type
;
6717 static inline hashval_t
hash (const value_type
*);
6718 static inline bool equal (const value_type
*, const compare_type
*);
6719 static inline void remove (value_type
*);
6723 cu_hash_table_entry_hasher::hash (const value_type
*entry
)
6725 return htab_hash_string (entry
->cu
->die_id
.die_symbol
);
6729 cu_hash_table_entry_hasher::equal (const value_type
*entry1
,
6730 const compare_type
*entry2
)
6732 return !strcmp (entry1
->cu
->die_id
.die_symbol
, entry2
->die_id
.die_symbol
);
6736 cu_hash_table_entry_hasher::remove (value_type
*entry
)
6738 struct cu_hash_table_entry
*next
;
6748 typedef hash_table
<cu_hash_table_entry_hasher
> cu_hash_type
;
6750 /* Check whether we have already seen this CU and set up SYM_NUM
6753 check_duplicate_cu (dw_die_ref cu
, cu_hash_type htable
, unsigned int *sym_num
)
6755 struct cu_hash_table_entry dummy
;
6756 struct cu_hash_table_entry
**slot
, *entry
, *last
= &dummy
;
6758 dummy
.max_comdat_num
= 0;
6760 slot
= htable
.find_slot_with_hash (cu
,
6761 htab_hash_string (cu
->die_id
.die_symbol
),
6765 for (; entry
; last
= entry
, entry
= entry
->next
)
6767 if (same_die_p_wrap (cu
, entry
->cu
))
6773 *sym_num
= entry
->min_comdat_num
;
6777 entry
= XCNEW (struct cu_hash_table_entry
);
6779 entry
->min_comdat_num
= *sym_num
= last
->max_comdat_num
;
6780 entry
->next
= *slot
;
6786 /* Record SYM_NUM to record of CU in HTABLE. */
6788 record_comdat_symbol_number (dw_die_ref cu
, cu_hash_type htable
,
6789 unsigned int sym_num
)
6791 struct cu_hash_table_entry
**slot
, *entry
;
6793 slot
= htable
.find_slot_with_hash (cu
,
6794 htab_hash_string (cu
->die_id
.die_symbol
),
6798 entry
->max_comdat_num
= sym_num
;
6801 /* Traverse the DIE (which is always comp_unit_die), and set up
6802 additional compilation units for each of the include files we see
6803 bracketed by BINCL/EINCL. */
6806 break_out_includes (dw_die_ref die
)
6809 dw_die_ref unit
= NULL
;
6810 limbo_die_node
*node
, **pnode
;
6811 cu_hash_type cu_hash_table
;
6815 dw_die_ref prev
= c
;
6817 while (c
->die_tag
== DW_TAG_GNU_BINCL
|| c
->die_tag
== DW_TAG_GNU_EINCL
6818 || (unit
&& is_comdat_die (c
)))
6820 dw_die_ref next
= c
->die_sib
;
6822 /* This DIE is for a secondary CU; remove it from the main one. */
6823 remove_child_with_prev (c
, prev
);
6825 if (c
->die_tag
== DW_TAG_GNU_BINCL
)
6826 unit
= push_new_compile_unit (unit
, c
);
6827 else if (c
->die_tag
== DW_TAG_GNU_EINCL
)
6828 unit
= pop_compile_unit (unit
);
6830 add_child_die (unit
, c
);
6832 if (c
== die
->die_child
)
6835 } while (c
!= die
->die_child
);
6838 /* We can only use this in debugging, since the frontend doesn't check
6839 to make sure that we leave every include file we enter. */
6843 assign_symbol_names (die
);
6844 cu_hash_table
.create (10);
6845 for (node
= limbo_die_list
, pnode
= &limbo_die_list
;
6851 compute_section_prefix (node
->die
);
6852 is_dupl
= check_duplicate_cu (node
->die
, cu_hash_table
,
6853 &comdat_symbol_number
);
6854 assign_symbol_names (node
->die
);
6856 *pnode
= node
->next
;
6859 pnode
= &node
->next
;
6860 record_comdat_symbol_number (node
->die
, cu_hash_table
,
6861 comdat_symbol_number
);
6864 cu_hash_table
.dispose ();
6867 /* Return non-zero if this DIE is a declaration. */
6870 is_declaration_die (dw_die_ref die
)
6875 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6876 if (a
->dw_attr
== DW_AT_declaration
)
6882 /* Return non-zero if this DIE is nested inside a subprogram. */
6885 is_nested_in_subprogram (dw_die_ref die
)
6887 dw_die_ref decl
= get_AT_ref (die
, DW_AT_specification
);
6891 return local_scope_p (decl
);
6894 /* Return non-zero if this DIE contains a defining declaration of a
6898 contains_subprogram_definition (dw_die_ref die
)
6902 if (die
->die_tag
== DW_TAG_subprogram
&& ! is_declaration_die (die
))
6904 FOR_EACH_CHILD (die
, c
, if (contains_subprogram_definition (c
)) return 1);
6908 /* Return non-zero if this is a type DIE that should be moved to a
6909 COMDAT .debug_types section. */
6912 should_move_die_to_comdat (dw_die_ref die
)
6914 switch (die
->die_tag
)
6916 case DW_TAG_class_type
:
6917 case DW_TAG_structure_type
:
6918 case DW_TAG_enumeration_type
:
6919 case DW_TAG_union_type
:
6920 /* Don't move declarations, inlined instances, or types nested in a
6922 if (is_declaration_die (die
)
6923 || get_AT (die
, DW_AT_abstract_origin
)
6924 || is_nested_in_subprogram (die
))
6926 /* A type definition should never contain a subprogram definition. */
6927 gcc_assert (!contains_subprogram_definition (die
));
6929 case DW_TAG_array_type
:
6930 case DW_TAG_interface_type
:
6931 case DW_TAG_pointer_type
:
6932 case DW_TAG_reference_type
:
6933 case DW_TAG_rvalue_reference_type
:
6934 case DW_TAG_string_type
:
6935 case DW_TAG_subroutine_type
:
6936 case DW_TAG_ptr_to_member_type
:
6937 case DW_TAG_set_type
:
6938 case DW_TAG_subrange_type
:
6939 case DW_TAG_base_type
:
6940 case DW_TAG_const_type
:
6941 case DW_TAG_file_type
:
6942 case DW_TAG_packed_type
:
6943 case DW_TAG_volatile_type
:
6944 case DW_TAG_typedef
:
6950 /* Make a clone of DIE. */
6953 clone_die (dw_die_ref die
)
6959 clone
= ggc_alloc_cleared_die_node ();
6960 clone
->die_tag
= die
->die_tag
;
6962 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
6963 add_dwarf_attr (clone
, a
);
6968 /* Make a clone of the tree rooted at DIE. */
6971 clone_tree (dw_die_ref die
)
6974 dw_die_ref clone
= clone_die (die
);
6976 FOR_EACH_CHILD (die
, c
, add_child_die (clone
, clone_tree (c
)));
6981 /* Make a clone of DIE as a declaration. */
6984 clone_as_declaration (dw_die_ref die
)
6991 /* If the DIE is already a declaration, just clone it. */
6992 if (is_declaration_die (die
))
6993 return clone_die (die
);
6995 /* If the DIE is a specification, just clone its declaration DIE. */
6996 decl
= get_AT_ref (die
, DW_AT_specification
);
6999 clone
= clone_die (decl
);
7000 if (die
->comdat_type_p
)
7001 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7005 clone
= ggc_alloc_cleared_die_node ();
7006 clone
->die_tag
= die
->die_tag
;
7008 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7010 /* We don't want to copy over all attributes.
7011 For example we don't want DW_AT_byte_size because otherwise we will no
7012 longer have a declaration and GDB will treat it as a definition. */
7016 case DW_AT_artificial
:
7017 case DW_AT_containing_type
:
7018 case DW_AT_external
:
7021 case DW_AT_virtuality
:
7022 case DW_AT_linkage_name
:
7023 case DW_AT_MIPS_linkage_name
:
7024 add_dwarf_attr (clone
, a
);
7026 case DW_AT_byte_size
:
7032 if (die
->comdat_type_p
)
7033 add_AT_die_ref (clone
, DW_AT_signature
, die
);
7035 add_AT_flag (clone
, DW_AT_declaration
, 1);
7040 /* Structure to map a DIE in one CU to its copy in a comdat type unit. */
7042 struct decl_table_entry
7048 /* Helpers to manipulate hash table of copied declarations. */
7050 /* Hashtable helpers. */
7052 struct decl_table_entry_hasher
: typed_free_remove
<decl_table_entry
>
7054 typedef decl_table_entry value_type
;
7055 typedef die_struct compare_type
;
7056 static inline hashval_t
hash (const value_type
*);
7057 static inline bool equal (const value_type
*, const compare_type
*);
7061 decl_table_entry_hasher::hash (const value_type
*entry
)
7063 return htab_hash_pointer (entry
->orig
);
7067 decl_table_entry_hasher::equal (const value_type
*entry1
,
7068 const compare_type
*entry2
)
7070 return entry1
->orig
== entry2
;
7073 typedef hash_table
<decl_table_entry_hasher
> decl_hash_type
;
7075 /* Copy DIE and its ancestors, up to, but not including, the compile unit
7076 or type unit entry, to a new tree. Adds the new tree to UNIT and returns
7077 a pointer to the copy of DIE. If DECL_TABLE is provided, it is used
7078 to check if the ancestor has already been copied into UNIT. */
7081 copy_ancestor_tree (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
7083 dw_die_ref parent
= die
->die_parent
;
7084 dw_die_ref new_parent
= unit
;
7086 decl_table_entry
**slot
= NULL
;
7087 struct decl_table_entry
*entry
= NULL
;
7089 if (decl_table
.is_created ())
7091 /* Check if the entry has already been copied to UNIT. */
7092 slot
= decl_table
.find_slot_with_hash (die
, htab_hash_pointer (die
),
7094 if (*slot
!= HTAB_EMPTY_ENTRY
)
7100 /* Record in DECL_TABLE that DIE has been copied to UNIT. */
7101 entry
= XCNEW (struct decl_table_entry
);
7109 dw_die_ref spec
= get_AT_ref (parent
, DW_AT_specification
);
7112 if (!is_unit_die (parent
))
7113 new_parent
= copy_ancestor_tree (unit
, parent
, decl_table
);
7116 copy
= clone_as_declaration (die
);
7117 add_child_die (new_parent
, copy
);
7119 if (decl_table
.is_created ())
7121 /* Record the pointer to the copy. */
7127 /* Copy the declaration context to the new type unit DIE. This includes
7128 any surrounding namespace or type declarations. If the DIE has an
7129 AT_specification attribute, it also includes attributes and children
7130 attached to the specification, and returns a pointer to the original
7131 parent of the declaration DIE. Returns NULL otherwise. */
7134 copy_declaration_context (dw_die_ref unit
, dw_die_ref die
)
7137 dw_die_ref new_decl
;
7138 dw_die_ref orig_parent
= NULL
;
7140 decl
= get_AT_ref (die
, DW_AT_specification
);
7149 /* The original DIE will be changed to a declaration, and must
7150 be moved to be a child of the original declaration DIE. */
7151 orig_parent
= decl
->die_parent
;
7153 /* Copy the type node pointer from the new DIE to the original
7154 declaration DIE so we can forward references later. */
7155 decl
->comdat_type_p
= true;
7156 decl
->die_id
.die_type_node
= die
->die_id
.die_type_node
;
7158 remove_AT (die
, DW_AT_specification
);
7160 FOR_EACH_VEC_SAFE_ELT (decl
->die_attr
, ix
, a
)
7162 if (a
->dw_attr
!= DW_AT_name
7163 && a
->dw_attr
!= DW_AT_declaration
7164 && a
->dw_attr
!= DW_AT_external
)
7165 add_dwarf_attr (die
, a
);
7168 FOR_EACH_CHILD (decl
, c
, add_child_die (die
, clone_tree (c
)));
7171 if (decl
->die_parent
!= NULL
7172 && !is_unit_die (decl
->die_parent
))
7174 new_decl
= copy_ancestor_tree (unit
, decl
, decl_hash_type ());
7175 if (new_decl
!= NULL
)
7177 remove_AT (new_decl
, DW_AT_signature
);
7178 add_AT_specification (die
, new_decl
);
7185 /* Generate the skeleton ancestor tree for the given NODE, then clone
7186 the DIE and add the clone into the tree. */
7189 generate_skeleton_ancestor_tree (skeleton_chain_node
*node
)
7191 if (node
->new_die
!= NULL
)
7194 node
->new_die
= clone_as_declaration (node
->old_die
);
7196 if (node
->parent
!= NULL
)
7198 generate_skeleton_ancestor_tree (node
->parent
);
7199 add_child_die (node
->parent
->new_die
, node
->new_die
);
7203 /* Generate a skeleton tree of DIEs containing any declarations that are
7204 found in the original tree. We traverse the tree looking for declaration
7205 DIEs, and construct the skeleton from the bottom up whenever we find one. */
7208 generate_skeleton_bottom_up (skeleton_chain_node
*parent
)
7210 skeleton_chain_node node
;
7213 dw_die_ref prev
= NULL
;
7214 dw_die_ref next
= NULL
;
7216 node
.parent
= parent
;
7218 first
= c
= parent
->old_die
->die_child
;
7222 if (prev
== NULL
|| prev
->die_sib
== c
)
7225 next
= (c
== first
? NULL
: c
->die_sib
);
7227 node
.new_die
= NULL
;
7228 if (is_declaration_die (c
))
7230 if (is_template_instantiation (c
))
7232 /* Instantiated templates do not need to be cloned into the
7233 type unit. Just move the DIE and its children back to
7234 the skeleton tree (in the main CU). */
7235 remove_child_with_prev (c
, prev
);
7236 add_child_die (parent
->new_die
, c
);
7241 /* Clone the existing DIE, move the original to the skeleton
7242 tree (which is in the main CU), and put the clone, with
7243 all the original's children, where the original came from
7244 (which is about to be moved to the type unit). */
7245 dw_die_ref clone
= clone_die (c
);
7246 move_all_children (c
, clone
);
7248 replace_child (c
, clone
, prev
);
7249 generate_skeleton_ancestor_tree (parent
);
7250 add_child_die (parent
->new_die
, c
);
7255 generate_skeleton_bottom_up (&node
);
7256 } while (next
!= NULL
);
7259 /* Wrapper function for generate_skeleton_bottom_up. */
7262 generate_skeleton (dw_die_ref die
)
7264 skeleton_chain_node node
;
7267 node
.new_die
= NULL
;
7270 /* If this type definition is nested inside another type,
7271 and is not an instantiation of a template, always leave
7272 at least a declaration in its place. */
7273 if (die
->die_parent
!= NULL
7274 && is_type_die (die
->die_parent
)
7275 && !is_template_instantiation (die
))
7276 node
.new_die
= clone_as_declaration (die
);
7278 generate_skeleton_bottom_up (&node
);
7279 return node
.new_die
;
7282 /* Remove the CHILD DIE from its parent, possibly replacing it with a cloned
7283 declaration. The original DIE is moved to a new compile unit so that
7284 existing references to it follow it to the new location. If any of the
7285 original DIE's descendants is a declaration, we need to replace the
7286 original DIE with a skeleton tree and move the declarations back into the
7290 remove_child_or_replace_with_skeleton (dw_die_ref unit
, dw_die_ref child
,
7293 dw_die_ref skeleton
, orig_parent
;
7295 /* Copy the declaration context to the type unit DIE. If the returned
7296 ORIG_PARENT is not NULL, the skeleton needs to be added as a child of
7298 orig_parent
= copy_declaration_context (unit
, child
);
7300 skeleton
= generate_skeleton (child
);
7301 if (skeleton
== NULL
)
7302 remove_child_with_prev (child
, prev
);
7305 skeleton
->comdat_type_p
= true;
7306 skeleton
->die_id
.die_type_node
= child
->die_id
.die_type_node
;
7308 /* If the original DIE was a specification, we need to put
7309 the skeleton under the parent DIE of the declaration.
7310 This leaves the original declaration in the tree, but
7311 it will be pruned later since there are no longer any
7312 references to it. */
7313 if (orig_parent
!= NULL
)
7315 remove_child_with_prev (child
, prev
);
7316 add_child_die (orig_parent
, skeleton
);
7319 replace_child (child
, skeleton
, prev
);
7325 /* Traverse the DIE and set up additional .debug_types sections for each
7326 type worthy of being placed in a COMDAT section. */
7329 break_out_comdat_types (dw_die_ref die
)
7333 dw_die_ref prev
= NULL
;
7334 dw_die_ref next
= NULL
;
7335 dw_die_ref unit
= NULL
;
7337 first
= c
= die
->die_child
;
7341 if (prev
== NULL
|| prev
->die_sib
== c
)
7344 next
= (c
== first
? NULL
: c
->die_sib
);
7345 if (should_move_die_to_comdat (c
))
7347 dw_die_ref replacement
;
7348 comdat_type_node_ref type_node
;
7350 /* Break out nested types into their own type units. */
7351 break_out_comdat_types (c
);
7353 /* Create a new type unit DIE as the root for the new tree, and
7354 add it to the list of comdat types. */
7355 unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
7356 add_AT_unsigned (unit
, DW_AT_language
,
7357 get_AT_unsigned (comp_unit_die (), DW_AT_language
));
7358 type_node
= ggc_alloc_cleared_comdat_type_node ();
7359 type_node
->root_die
= unit
;
7360 type_node
->next
= comdat_type_list
;
7361 comdat_type_list
= type_node
;
7363 /* Generate the type signature. */
7364 generate_type_signature (c
, type_node
);
7366 /* Copy the declaration context, attributes, and children of the
7367 declaration into the new type unit DIE, then remove this DIE
7368 from the main CU (or replace it with a skeleton if necessary). */
7369 replacement
= remove_child_or_replace_with_skeleton (unit
, c
, prev
);
7370 type_node
->skeleton_die
= replacement
;
7372 /* Add the DIE to the new compunit. */
7373 add_child_die (unit
, c
);
7375 if (replacement
!= NULL
)
7378 else if (c
->die_tag
== DW_TAG_namespace
7379 || c
->die_tag
== DW_TAG_class_type
7380 || c
->die_tag
== DW_TAG_structure_type
7381 || c
->die_tag
== DW_TAG_union_type
)
7383 /* Look for nested types that can be broken out. */
7384 break_out_comdat_types (c
);
7386 } while (next
!= NULL
);
7389 /* Like clone_tree, but additionally enter all the children into
7390 the hash table decl_table. */
7393 clone_tree_hash (dw_die_ref die
, decl_hash_type decl_table
)
7396 dw_die_ref clone
= clone_die (die
);
7397 struct decl_table_entry
*entry
;
7398 decl_table_entry
**slot
= decl_table
.find_slot_with_hash (die
,
7399 htab_hash_pointer (die
), INSERT
);
7400 /* Assert that DIE isn't in the hash table yet. If it would be there
7401 before, the ancestors would be necessarily there as well, therefore
7402 clone_tree_hash wouldn't be called. */
7403 gcc_assert (*slot
== HTAB_EMPTY_ENTRY
);
7404 entry
= XCNEW (struct decl_table_entry
);
7406 entry
->copy
= clone
;
7409 FOR_EACH_CHILD (die
, c
,
7410 add_child_die (clone
, clone_tree_hash (c
, decl_table
)));
7415 /* Walk the DIE and its children, looking for references to incomplete
7416 or trivial types that are unmarked (i.e., that are not in the current
7420 copy_decls_walk (dw_die_ref unit
, dw_die_ref die
, decl_hash_type decl_table
)
7426 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7428 if (AT_class (a
) == dw_val_class_die_ref
)
7430 dw_die_ref targ
= AT_ref (a
);
7431 decl_table_entry
**slot
;
7432 struct decl_table_entry
*entry
;
7434 if (targ
->die_mark
!= 0 || targ
->comdat_type_p
)
7437 slot
= decl_table
.find_slot_with_hash (targ
, htab_hash_pointer (targ
),
7440 if (*slot
!= HTAB_EMPTY_ENTRY
)
7442 /* TARG has already been copied, so we just need to
7443 modify the reference to point to the copy. */
7445 a
->dw_attr_val
.v
.val_die_ref
.die
= entry
->copy
;
7449 dw_die_ref parent
= unit
;
7450 dw_die_ref copy
= clone_die (targ
);
7452 /* Record in DECL_TABLE that TARG has been copied.
7453 Need to do this now, before the recursive call,
7454 because DECL_TABLE may be expanded and SLOT
7455 would no longer be a valid pointer. */
7456 entry
= XCNEW (struct decl_table_entry
);
7461 FOR_EACH_CHILD (targ
, c
,
7462 add_child_die (copy
,
7463 clone_tree_hash (c
, decl_table
)));
7465 /* Make sure the cloned tree is marked as part of the
7469 /* If TARG has surrounding context, copy its ancestor tree
7470 into the new type unit. */
7471 if (targ
->die_parent
!= NULL
7472 && !is_unit_die (targ
->die_parent
))
7473 parent
= copy_ancestor_tree (unit
, targ
->die_parent
,
7476 add_child_die (parent
, copy
);
7477 a
->dw_attr_val
.v
.val_die_ref
.die
= copy
;
7479 /* Make sure the newly-copied DIE is walked. If it was
7480 installed in a previously-added context, it won't
7481 get visited otherwise. */
7484 /* Find the highest point of the newly-added tree,
7485 mark each node along the way, and walk from there. */
7486 parent
->die_mark
= 1;
7487 while (parent
->die_parent
7488 && parent
->die_parent
->die_mark
== 0)
7490 parent
= parent
->die_parent
;
7491 parent
->die_mark
= 1;
7493 copy_decls_walk (unit
, parent
, decl_table
);
7499 FOR_EACH_CHILD (die
, c
, copy_decls_walk (unit
, c
, decl_table
));
7502 /* Copy declarations for "unworthy" types into the new comdat section.
7503 Incomplete types, modified types, and certain other types aren't broken
7504 out into comdat sections of their own, so they don't have a signature,
7505 and we need to copy the declaration into the same section so that we
7506 don't have an external reference. */
7509 copy_decls_for_unworthy_types (dw_die_ref unit
)
7511 decl_hash_type decl_table
;
7514 decl_table
.create (10);
7515 copy_decls_walk (unit
, unit
, decl_table
);
7516 decl_table
.dispose ();
7520 /* Traverse the DIE and add a sibling attribute if it may have the
7521 effect of speeding up access to siblings. To save some space,
7522 avoid generating sibling attributes for DIE's without children. */
7525 add_sibling_attributes (dw_die_ref die
)
7529 if (! die
->die_child
)
7532 if (die
->die_parent
&& die
!= die
->die_parent
->die_child
)
7533 add_AT_die_ref (die
, DW_AT_sibling
, die
->die_sib
);
7535 FOR_EACH_CHILD (die
, c
, add_sibling_attributes (c
));
7538 /* Output all location lists for the DIE and its children. */
7541 output_location_lists (dw_die_ref die
)
7547 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7548 if (AT_class (a
) == dw_val_class_loc_list
)
7549 output_loc_list (AT_loc_list (a
));
7551 FOR_EACH_CHILD (die
, c
, output_location_lists (c
));
7554 /* We want to limit the number of external references, because they are
7555 larger than local references: a relocation takes multiple words, and
7556 even a sig8 reference is always eight bytes, whereas a local reference
7557 can be as small as one byte (though DW_FORM_ref is usually 4 in GCC).
7558 So if we encounter multiple external references to the same type DIE, we
7559 make a local typedef stub for it and redirect all references there.
7561 This is the element of the hash table for keeping track of these
7571 /* Hashtable helpers. */
7573 struct external_ref_hasher
: typed_free_remove
<external_ref
>
7575 typedef external_ref value_type
;
7576 typedef external_ref compare_type
;
7577 static inline hashval_t
hash (const value_type
*);
7578 static inline bool equal (const value_type
*, const compare_type
*);
7582 external_ref_hasher::hash (const value_type
*r
)
7584 dw_die_ref die
= r
->type
;
7587 /* We can't use the address of the DIE for hashing, because
7588 that will make the order of the stub DIEs non-deterministic. */
7589 if (! die
->comdat_type_p
)
7590 /* We have a symbol; use it to compute a hash. */
7591 h
= htab_hash_string (die
->die_id
.die_symbol
);
7594 /* We have a type signature; use a subset of the bits as the hash.
7595 The 8-byte signature is at least as large as hashval_t. */
7596 comdat_type_node_ref type_node
= die
->die_id
.die_type_node
;
7597 memcpy (&h
, type_node
->signature
, sizeof (h
));
7603 external_ref_hasher::equal (const value_type
*r1
, const compare_type
*r2
)
7605 return r1
->type
== r2
->type
;
7608 typedef hash_table
<external_ref_hasher
> external_ref_hash_type
;
7610 /* Return a pointer to the external_ref for references to DIE. */
7612 static struct external_ref
*
7613 lookup_external_ref (external_ref_hash_type map
, dw_die_ref die
)
7615 struct external_ref ref
, *ref_p
;
7616 external_ref
**slot
;
7619 slot
= map
.find_slot (&ref
, INSERT
);
7620 if (*slot
!= HTAB_EMPTY_ENTRY
)
7623 ref_p
= XCNEW (struct external_ref
);
7629 /* Subroutine of optimize_external_refs, below.
7631 If we see a type skeleton, record it as our stub. If we see external
7632 references, remember how many we've seen. */
7635 optimize_external_refs_1 (dw_die_ref die
, external_ref_hash_type map
)
7640 struct external_ref
*ref_p
;
7642 if (is_type_die (die
)
7643 && (c
= get_AT_ref (die
, DW_AT_signature
)))
7645 /* This is a local skeleton; use it for local references. */
7646 ref_p
= lookup_external_ref (map
, c
);
7650 /* Scan the DIE references, and remember any that refer to DIEs from
7651 other CUs (i.e. those which are not marked). */
7652 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7653 if (AT_class (a
) == dw_val_class_die_ref
7654 && (c
= AT_ref (a
))->die_mark
== 0
7657 ref_p
= lookup_external_ref (map
, c
);
7661 FOR_EACH_CHILD (die
, c
, optimize_external_refs_1 (c
, map
));
7664 /* htab_traverse callback function for optimize_external_refs, below. SLOT
7665 points to an external_ref, DATA is the CU we're processing. If we don't
7666 already have a local stub, and we have multiple refs, build a stub. */
7669 dwarf2_build_local_stub (external_ref
**slot
, dw_die_ref data
)
7671 struct external_ref
*ref_p
= *slot
;
7673 if (ref_p
->stub
== NULL
&& ref_p
->n_refs
> 1 && !dwarf_strict
)
7675 /* We have multiple references to this type, so build a small stub.
7676 Both of these forms are a bit dodgy from the perspective of the
7677 DWARF standard, since technically they should have names. */
7678 dw_die_ref cu
= data
;
7679 dw_die_ref type
= ref_p
->type
;
7680 dw_die_ref stub
= NULL
;
7682 if (type
->comdat_type_p
)
7684 /* If we refer to this type via sig8, use AT_signature. */
7685 stub
= new_die (type
->die_tag
, cu
, NULL_TREE
);
7686 add_AT_die_ref (stub
, DW_AT_signature
, type
);
7690 /* Otherwise, use a typedef with no name. */
7691 stub
= new_die (DW_TAG_typedef
, cu
, NULL_TREE
);
7692 add_AT_die_ref (stub
, DW_AT_type
, type
);
7701 /* DIE is a unit; look through all the DIE references to see if there are
7702 any external references to types, and if so, create local stubs for
7703 them which will be applied in build_abbrev_table. This is useful because
7704 references to local DIEs are smaller. */
7706 static external_ref_hash_type
7707 optimize_external_refs (dw_die_ref die
)
7709 external_ref_hash_type map
;
7711 optimize_external_refs_1 (die
, map
);
7712 map
.traverse
<dw_die_ref
, dwarf2_build_local_stub
> (die
);
7716 /* The format of each DIE (and its attribute value pairs) is encoded in an
7717 abbreviation table. This routine builds the abbreviation table and assigns
7718 a unique abbreviation id for each abbreviation entry. The children of each
7719 die are visited recursively. */
7722 build_abbrev_table (dw_die_ref die
, external_ref_hash_type extern_map
)
7724 unsigned long abbrev_id
;
7725 unsigned int n_alloc
;
7730 /* Scan the DIE references, and replace any that refer to
7731 DIEs from other CUs (i.e. those which are not marked) with
7732 the local stubs we built in optimize_external_refs. */
7733 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7734 if (AT_class (a
) == dw_val_class_die_ref
7735 && (c
= AT_ref (a
))->die_mark
== 0)
7737 struct external_ref
*ref_p
;
7738 gcc_assert (AT_ref (a
)->comdat_type_p
|| AT_ref (a
)->die_id
.die_symbol
);
7740 ref_p
= lookup_external_ref (extern_map
, c
);
7741 if (ref_p
->stub
&& ref_p
->stub
!= die
)
7742 change_AT_die_ref (a
, ref_p
->stub
);
7744 /* We aren't changing this reference, so mark it external. */
7745 set_AT_ref_external (a
, 1);
7748 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
7750 dw_die_ref abbrev
= abbrev_die_table
[abbrev_id
];
7751 dw_attr_ref die_a
, abbrev_a
;
7755 if (abbrev
->die_tag
!= die
->die_tag
)
7757 if ((abbrev
->die_child
!= NULL
) != (die
->die_child
!= NULL
))
7760 if (vec_safe_length (abbrev
->die_attr
) != vec_safe_length (die
->die_attr
))
7763 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, die_a
)
7765 abbrev_a
= &(*abbrev
->die_attr
)[ix
];
7766 if ((abbrev_a
->dw_attr
!= die_a
->dw_attr
)
7767 || (value_format (abbrev_a
) != value_format (die_a
)))
7777 if (abbrev_id
>= abbrev_die_table_in_use
)
7779 if (abbrev_die_table_in_use
>= abbrev_die_table_allocated
)
7781 n_alloc
= abbrev_die_table_allocated
+ ABBREV_DIE_TABLE_INCREMENT
;
7782 abbrev_die_table
= GGC_RESIZEVEC (dw_die_ref
, abbrev_die_table
,
7785 memset (&abbrev_die_table
[abbrev_die_table_allocated
], 0,
7786 (n_alloc
- abbrev_die_table_allocated
) * sizeof (dw_die_ref
));
7787 abbrev_die_table_allocated
= n_alloc
;
7790 ++abbrev_die_table_in_use
;
7791 abbrev_die_table
[abbrev_id
] = die
;
7794 die
->die_abbrev
= abbrev_id
;
7795 FOR_EACH_CHILD (die
, c
, build_abbrev_table (c
, extern_map
));
7798 /* Return the power-of-two number of bytes necessary to represent VALUE. */
7801 constant_size (unsigned HOST_WIDE_INT value
)
7808 log
= floor_log2 (value
);
7811 log
= 1 << (floor_log2 (log
) + 1);
7816 /* Return the size of a DIE as it is represented in the
7817 .debug_info section. */
7819 static unsigned long
7820 size_of_die (dw_die_ref die
)
7822 unsigned long size
= 0;
7825 enum dwarf_form form
;
7827 size
+= size_of_uleb128 (die
->die_abbrev
);
7828 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
7830 switch (AT_class (a
))
7832 case dw_val_class_addr
:
7833 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7835 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7836 size
+= size_of_uleb128 (AT_index (a
));
7839 size
+= DWARF2_ADDR_SIZE
;
7841 case dw_val_class_offset
:
7842 size
+= DWARF_OFFSET_SIZE
;
7844 case dw_val_class_loc
:
7846 unsigned long lsize
= size_of_locs (AT_loc (a
));
7849 if (dwarf_version
>= 4)
7850 size
+= size_of_uleb128 (lsize
);
7852 size
+= constant_size (lsize
);
7856 case dw_val_class_loc_list
:
7857 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7859 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7860 size
+= size_of_uleb128 (AT_index (a
));
7863 size
+= DWARF_OFFSET_SIZE
;
7865 case dw_val_class_range_list
:
7866 size
+= DWARF_OFFSET_SIZE
;
7868 case dw_val_class_const
:
7869 size
+= size_of_sleb128 (AT_int (a
));
7871 case dw_val_class_unsigned_const
:
7873 int csize
= constant_size (AT_unsigned (a
));
7874 if (dwarf_version
== 3
7875 && a
->dw_attr
== DW_AT_data_member_location
7877 size
+= size_of_uleb128 (AT_unsigned (a
));
7882 case dw_val_class_const_double
:
7883 size
+= HOST_BITS_PER_DOUBLE_INT
/ HOST_BITS_PER_CHAR
;
7884 if (HOST_BITS_PER_WIDE_INT
>= 64)
7887 case dw_val_class_wide_int
:
7888 size
+= (get_full_len (*a
->dw_attr_val
.v
.val_wide
)
7889 * HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
);
7890 if (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
7894 case dw_val_class_vec
:
7895 size
+= constant_size (a
->dw_attr_val
.v
.val_vec
.length
7896 * a
->dw_attr_val
.v
.val_vec
.elt_size
)
7897 + a
->dw_attr_val
.v
.val_vec
.length
7898 * a
->dw_attr_val
.v
.val_vec
.elt_size
; /* block */
7900 case dw_val_class_flag
:
7901 if (dwarf_version
>= 4)
7902 /* Currently all add_AT_flag calls pass in 1 as last argument,
7903 so DW_FORM_flag_present can be used. If that ever changes,
7904 we'll need to use DW_FORM_flag and have some optimization
7905 in build_abbrev_table that will change those to
7906 DW_FORM_flag_present if it is set to 1 in all DIEs using
7907 the same abbrev entry. */
7908 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
7912 case dw_val_class_die_ref
:
7913 if (AT_ref_external (a
))
7915 /* In DWARF4, we use DW_FORM_ref_sig8; for earlier versions
7916 we use DW_FORM_ref_addr. In DWARF2, DW_FORM_ref_addr
7917 is sized by target address length, whereas in DWARF3
7918 it's always sized as an offset. */
7919 if (use_debug_types
)
7920 size
+= DWARF_TYPE_SIGNATURE_SIZE
;
7921 else if (dwarf_version
== 2)
7922 size
+= DWARF2_ADDR_SIZE
;
7924 size
+= DWARF_OFFSET_SIZE
;
7927 size
+= DWARF_OFFSET_SIZE
;
7929 case dw_val_class_fde_ref
:
7930 size
+= DWARF_OFFSET_SIZE
;
7932 case dw_val_class_lbl_id
:
7933 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
7935 gcc_assert (AT_index (a
) != NO_INDEX_ASSIGNED
);
7936 size
+= size_of_uleb128 (AT_index (a
));
7939 size
+= DWARF2_ADDR_SIZE
;
7941 case dw_val_class_lineptr
:
7942 case dw_val_class_macptr
:
7943 size
+= DWARF_OFFSET_SIZE
;
7945 case dw_val_class_str
:
7946 form
= AT_string_form (a
);
7947 if (form
== DW_FORM_strp
)
7948 size
+= DWARF_OFFSET_SIZE
;
7949 else if (form
== DW_FORM_GNU_str_index
)
7950 size
+= size_of_uleb128 (AT_index (a
));
7952 size
+= strlen (a
->dw_attr_val
.v
.val_str
->str
) + 1;
7954 case dw_val_class_file
:
7955 size
+= constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
));
7957 case dw_val_class_data8
:
7960 case dw_val_class_vms_delta
:
7961 size
+= DWARF_OFFSET_SIZE
;
7963 case dw_val_class_high_pc
:
7964 size
+= DWARF2_ADDR_SIZE
;
7974 /* Size the debugging information associated with a given DIE. Visits the
7975 DIE's children recursively. Updates the global variable next_die_offset, on
7976 each time through. Uses the current value of next_die_offset to update the
7977 die_offset field in each DIE. */
7980 calc_die_sizes (dw_die_ref die
)
7984 gcc_assert (die
->die_offset
== 0
7985 || (unsigned long int) die
->die_offset
== next_die_offset
);
7986 die
->die_offset
= next_die_offset
;
7987 next_die_offset
+= size_of_die (die
);
7989 FOR_EACH_CHILD (die
, c
, calc_die_sizes (c
));
7991 if (die
->die_child
!= NULL
)
7992 /* Count the null byte used to terminate sibling lists. */
7993 next_die_offset
+= 1;
7996 /* Size just the base type children at the start of the CU.
7997 This is needed because build_abbrev needs to size locs
7998 and sizing of type based stack ops needs to know die_offset
7999 values for the base types. */
8002 calc_base_type_die_sizes (void)
8004 unsigned long die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8006 dw_die_ref base_type
;
8007 #if ENABLE_ASSERT_CHECKING
8008 dw_die_ref prev
= comp_unit_die ()->die_child
;
8011 die_offset
+= size_of_die (comp_unit_die ());
8012 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
8014 #if ENABLE_ASSERT_CHECKING
8015 gcc_assert (base_type
->die_offset
== 0
8016 && prev
->die_sib
== base_type
8017 && base_type
->die_child
== NULL
8018 && base_type
->die_abbrev
);
8021 base_type
->die_offset
= die_offset
;
8022 die_offset
+= size_of_die (base_type
);
8026 /* Set the marks for a die and its children. We do this so
8027 that we know whether or not a reference needs to use FORM_ref_addr; only
8028 DIEs in the same CU will be marked. We used to clear out the offset
8029 and use that as the flag, but ran into ordering problems. */
8032 mark_dies (dw_die_ref die
)
8036 gcc_assert (!die
->die_mark
);
8039 FOR_EACH_CHILD (die
, c
, mark_dies (c
));
8042 /* Clear the marks for a die and its children. */
8045 unmark_dies (dw_die_ref die
)
8049 if (! use_debug_types
)
8050 gcc_assert (die
->die_mark
);
8053 FOR_EACH_CHILD (die
, c
, unmark_dies (c
));
8056 /* Clear the marks for a die, its children and referred dies. */
8059 unmark_all_dies (dw_die_ref die
)
8069 FOR_EACH_CHILD (die
, c
, unmark_all_dies (c
));
8071 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8072 if (AT_class (a
) == dw_val_class_die_ref
)
8073 unmark_all_dies (AT_ref (a
));
8076 /* Calculate if the entry should appear in the final output file. It may be
8077 from a pruned a type. */
8080 include_pubname_in_output (vec
<pubname_entry
, va_gc
> *table
, pubname_entry
*p
)
8082 /* By limiting gnu pubnames to definitions only, gold can generate a
8083 gdb index without entries for declarations, which don't include
8084 enough information to be useful. */
8085 if (debug_generate_pub_sections
== 2 && is_declaration_die (p
->die
))
8088 if (table
== pubname_table
)
8090 /* Enumerator names are part of the pubname table, but the
8091 parent DW_TAG_enumeration_type die may have been pruned.
8092 Don't output them if that is the case. */
8093 if (p
->die
->die_tag
== DW_TAG_enumerator
&&
8094 (p
->die
->die_parent
== NULL
8095 || !p
->die
->die_parent
->die_perennial_p
))
8098 /* Everything else in the pubname table is included. */
8102 /* The pubtypes table shouldn't include types that have been
8104 return (p
->die
->die_offset
!= 0
8105 || !flag_eliminate_unused_debug_types
);
8108 /* Return the size of the .debug_pubnames or .debug_pubtypes table
8109 generated for the compilation unit. */
8111 static unsigned long
8112 size_of_pubnames (vec
<pubname_entry
, va_gc
> *names
)
8117 int space_for_flags
= (debug_generate_pub_sections
== 2) ? 1 : 0;
8119 size
= DWARF_PUBNAMES_HEADER_SIZE
;
8120 FOR_EACH_VEC_ELT (*names
, i
, p
)
8121 if (include_pubname_in_output (names
, p
))
8122 size
+= strlen (p
->name
) + DWARF_OFFSET_SIZE
+ 1 + space_for_flags
;
8124 size
+= DWARF_OFFSET_SIZE
;
8128 /* Return the size of the information in the .debug_aranges section. */
8130 static unsigned long
8131 size_of_aranges (void)
8135 size
= DWARF_ARANGES_HEADER_SIZE
;
8137 /* Count the address/length pair for this compilation unit. */
8138 if (text_section_used
)
8139 size
+= 2 * DWARF2_ADDR_SIZE
;
8140 if (cold_text_section_used
)
8141 size
+= 2 * DWARF2_ADDR_SIZE
;
8142 if (have_multiple_function_sections
)
8147 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
8149 if (DECL_IGNORED_P (fde
->decl
))
8151 if (!fde
->in_std_section
)
8152 size
+= 2 * DWARF2_ADDR_SIZE
;
8153 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
8154 size
+= 2 * DWARF2_ADDR_SIZE
;
8158 /* Count the two zero words used to terminated the address range table. */
8159 size
+= 2 * DWARF2_ADDR_SIZE
;
8163 /* Select the encoding of an attribute value. */
8165 static enum dwarf_form
8166 value_format (dw_attr_ref a
)
8168 switch (AT_class (a
))
8170 case dw_val_class_addr
:
8171 /* Only very few attributes allow DW_FORM_addr. */
8176 case DW_AT_entry_pc
:
8177 case DW_AT_trampoline
:
8178 return (AT_index (a
) == NOT_INDEXED
8179 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8183 switch (DWARF2_ADDR_SIZE
)
8186 return DW_FORM_data1
;
8188 return DW_FORM_data2
;
8190 return DW_FORM_data4
;
8192 return DW_FORM_data8
;
8196 case dw_val_class_range_list
:
8197 case dw_val_class_loc_list
:
8198 if (dwarf_version
>= 4)
8199 return DW_FORM_sec_offset
;
8201 case dw_val_class_vms_delta
:
8202 case dw_val_class_offset
:
8203 switch (DWARF_OFFSET_SIZE
)
8206 return DW_FORM_data4
;
8208 return DW_FORM_data8
;
8212 case dw_val_class_loc
:
8213 if (dwarf_version
>= 4)
8214 return DW_FORM_exprloc
;
8215 switch (constant_size (size_of_locs (AT_loc (a
))))
8218 return DW_FORM_block1
;
8220 return DW_FORM_block2
;
8222 return DW_FORM_block4
;
8226 case dw_val_class_const
:
8227 return DW_FORM_sdata
;
8228 case dw_val_class_unsigned_const
:
8229 switch (constant_size (AT_unsigned (a
)))
8232 return DW_FORM_data1
;
8234 return DW_FORM_data2
;
8236 /* In DWARF3 DW_AT_data_member_location with
8237 DW_FORM_data4 or DW_FORM_data8 is a loclistptr, not
8238 constant, so we need to use DW_FORM_udata if we need
8239 a large constant. */
8240 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8241 return DW_FORM_udata
;
8242 return DW_FORM_data4
;
8244 if (dwarf_version
== 3 && a
->dw_attr
== DW_AT_data_member_location
)
8245 return DW_FORM_udata
;
8246 return DW_FORM_data8
;
8250 case dw_val_class_const_double
:
8251 switch (HOST_BITS_PER_WIDE_INT
)
8254 return DW_FORM_data2
;
8256 return DW_FORM_data4
;
8258 return DW_FORM_data8
;
8261 return DW_FORM_block1
;
8263 case dw_val_class_wide_int
:
8264 switch (get_full_len (*a
->dw_attr_val
.v
.val_wide
) * HOST_BITS_PER_WIDE_INT
)
8267 return DW_FORM_data1
;
8269 return DW_FORM_data2
;
8271 return DW_FORM_data4
;
8273 return DW_FORM_data8
;
8275 return DW_FORM_block1
;
8277 case dw_val_class_vec
:
8278 switch (constant_size (a
->dw_attr_val
.v
.val_vec
.length
8279 * a
->dw_attr_val
.v
.val_vec
.elt_size
))
8282 return DW_FORM_block1
;
8284 return DW_FORM_block2
;
8286 return DW_FORM_block4
;
8290 case dw_val_class_flag
:
8291 if (dwarf_version
>= 4)
8293 /* Currently all add_AT_flag calls pass in 1 as last argument,
8294 so DW_FORM_flag_present can be used. If that ever changes,
8295 we'll need to use DW_FORM_flag and have some optimization
8296 in build_abbrev_table that will change those to
8297 DW_FORM_flag_present if it is set to 1 in all DIEs using
8298 the same abbrev entry. */
8299 gcc_assert (a
->dw_attr_val
.v
.val_flag
== 1);
8300 return DW_FORM_flag_present
;
8302 return DW_FORM_flag
;
8303 case dw_val_class_die_ref
:
8304 if (AT_ref_external (a
))
8305 return use_debug_types
? DW_FORM_ref_sig8
: DW_FORM_ref_addr
;
8308 case dw_val_class_fde_ref
:
8309 return DW_FORM_data
;
8310 case dw_val_class_lbl_id
:
8311 return (AT_index (a
) == NOT_INDEXED
8312 ? DW_FORM_addr
: DW_FORM_GNU_addr_index
);
8313 case dw_val_class_lineptr
:
8314 case dw_val_class_macptr
:
8315 return dwarf_version
>= 4 ? DW_FORM_sec_offset
: DW_FORM_data
;
8316 case dw_val_class_str
:
8317 return AT_string_form (a
);
8318 case dw_val_class_file
:
8319 switch (constant_size (maybe_emit_file (a
->dw_attr_val
.v
.val_file
)))
8322 return DW_FORM_data1
;
8324 return DW_FORM_data2
;
8326 return DW_FORM_data4
;
8331 case dw_val_class_data8
:
8332 return DW_FORM_data8
;
8334 case dw_val_class_high_pc
:
8335 switch (DWARF2_ADDR_SIZE
)
8338 return DW_FORM_data1
;
8340 return DW_FORM_data2
;
8342 return DW_FORM_data4
;
8344 return DW_FORM_data8
;
8354 /* Output the encoding of an attribute value. */
8357 output_value_format (dw_attr_ref a
)
8359 enum dwarf_form form
= value_format (a
);
8361 dw2_asm_output_data_uleb128 (form
, "(%s)", dwarf_form_name (form
));
8364 /* Given a die and id, produce the appropriate abbreviations. */
8367 output_die_abbrevs (unsigned long abbrev_id
, dw_die_ref abbrev
)
8372 dw2_asm_output_data_uleb128 (abbrev_id
, "(abbrev code)");
8373 dw2_asm_output_data_uleb128 (abbrev
->die_tag
, "(TAG: %s)",
8374 dwarf_tag_name (abbrev
->die_tag
));
8376 if (abbrev
->die_child
!= NULL
)
8377 dw2_asm_output_data (1, DW_children_yes
, "DW_children_yes");
8379 dw2_asm_output_data (1, DW_children_no
, "DW_children_no");
8381 for (ix
= 0; vec_safe_iterate (abbrev
->die_attr
, ix
, &a_attr
); ix
++)
8383 dw2_asm_output_data_uleb128 (a_attr
->dw_attr
, "(%s)",
8384 dwarf_attr_name (a_attr
->dw_attr
));
8385 output_value_format (a_attr
);
8388 dw2_asm_output_data (1, 0, NULL
);
8389 dw2_asm_output_data (1, 0, NULL
);
8393 /* Output the .debug_abbrev section which defines the DIE abbreviation
8397 output_abbrev_section (void)
8399 unsigned long abbrev_id
;
8401 for (abbrev_id
= 1; abbrev_id
< abbrev_die_table_in_use
; ++abbrev_id
)
8402 output_die_abbrevs (abbrev_id
, abbrev_die_table
[abbrev_id
]);
8404 /* Terminate the table. */
8405 dw2_asm_output_data (1, 0, NULL
);
8408 /* Output a symbol we can use to refer to this DIE from another CU. */
8411 output_die_symbol (dw_die_ref die
)
8413 const char *sym
= die
->die_id
.die_symbol
;
8415 gcc_assert (!die
->comdat_type_p
);
8420 if (strncmp (sym
, DIE_LABEL_PREFIX
, sizeof (DIE_LABEL_PREFIX
) - 1) == 0)
8421 /* We make these global, not weak; if the target doesn't support
8422 .linkonce, it doesn't support combining the sections, so debugging
8424 targetm
.asm_out
.globalize_label (asm_out_file
, sym
);
8426 ASM_OUTPUT_LABEL (asm_out_file
, sym
);
8429 /* Return a new location list, given the begin and end range, and the
8432 static inline dw_loc_list_ref
8433 new_loc_list (dw_loc_descr_ref expr
, const char *begin
, const char *end
,
8434 const char *section
)
8436 dw_loc_list_ref retlist
= ggc_alloc_cleared_dw_loc_list_node ();
8438 retlist
->begin
= begin
;
8439 retlist
->begin_entry
= NULL
;
8441 retlist
->expr
= expr
;
8442 retlist
->section
= section
;
8447 /* Generate a new internal symbol for this location list node, if it
8448 hasn't got one yet. */
8451 gen_llsym (dw_loc_list_ref list
)
8453 gcc_assert (!list
->ll_symbol
);
8454 list
->ll_symbol
= gen_internal_sym ("LLST");
8457 /* Output the location list given to us. */
8460 output_loc_list (dw_loc_list_ref list_head
)
8462 dw_loc_list_ref curr
= list_head
;
8464 if (list_head
->emitted
)
8466 list_head
->emitted
= true;
8468 ASM_OUTPUT_LABEL (asm_out_file
, list_head
->ll_symbol
);
8470 /* Walk the location list, and output each range + expression. */
8471 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
8474 /* Don't output an entry that starts and ends at the same address. */
8475 if (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
)
8477 size
= size_of_locs (curr
->expr
);
8478 /* If the expression is too large, drop it on the floor. We could
8479 perhaps put it into DW_TAG_dwarf_procedure and refer to that
8480 in the expression, but >= 64KB expressions for a single value
8481 in a single range are unlikely very useful. */
8484 if (dwarf_split_debug_info
)
8486 dw2_asm_output_data (1, DW_LLE_GNU_start_length_entry
,
8487 "Location list start/length entry (%s)",
8488 list_head
->ll_symbol
);
8489 dw2_asm_output_data_uleb128 (curr
->begin_entry
->index
,
8490 "Location list range start index (%s)",
8492 /* The length field is 4 bytes. If we ever need to support
8493 an 8-byte length, we can add a new DW_LLE code or fall back
8494 to DW_LLE_GNU_start_end_entry. */
8495 dw2_asm_output_delta (4, curr
->end
, curr
->begin
,
8496 "Location list range length (%s)",
8497 list_head
->ll_symbol
);
8499 else if (!have_multiple_function_sections
)
8501 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->begin
, curr
->section
,
8502 "Location list begin address (%s)",
8503 list_head
->ll_symbol
);
8504 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, curr
->end
, curr
->section
,
8505 "Location list end address (%s)",
8506 list_head
->ll_symbol
);
8510 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->begin
,
8511 "Location list begin address (%s)",
8512 list_head
->ll_symbol
);
8513 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, curr
->end
,
8514 "Location list end address (%s)",
8515 list_head
->ll_symbol
);
8518 /* Output the block length for this list of location operations. */
8519 gcc_assert (size
<= 0xffff);
8520 dw2_asm_output_data (2, size
, "%s", "Location expression size");
8522 output_loc_sequence (curr
->expr
, -1);
8525 if (dwarf_split_debug_info
)
8526 dw2_asm_output_data (1, DW_LLE_GNU_end_of_list_entry
,
8527 "Location list terminator (%s)",
8528 list_head
->ll_symbol
);
8531 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8532 "Location list terminator begin (%s)",
8533 list_head
->ll_symbol
);
8534 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0,
8535 "Location list terminator end (%s)",
8536 list_head
->ll_symbol
);
8540 /* Output a range_list offset into the debug_range section. Emit a
8541 relocated reference if val_entry is NULL, otherwise, emit an
8542 indirect reference. */
8545 output_range_list_offset (dw_attr_ref a
)
8547 const char *name
= dwarf_attr_name (a
->dw_attr
);
8549 if (a
->dw_attr_val
.val_entry
== RELOCATED_OFFSET
)
8551 char *p
= strchr (ranges_section_label
, '\0');
8552 sprintf (p
, "+" HOST_WIDE_INT_PRINT_HEX
, a
->dw_attr_val
.v
.val_offset
);
8553 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, ranges_section_label
,
8554 debug_ranges_section
, "%s", name
);
8558 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8559 "%s (offset from %s)", name
, ranges_section_label
);
8562 /* Output the offset into the debug_loc section. */
8565 output_loc_list_offset (dw_attr_ref a
)
8567 char *sym
= AT_loc_list (a
)->ll_symbol
;
8570 if (dwarf_split_debug_info
)
8571 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, sym
, loc_section_label
,
8572 "%s", dwarf_attr_name (a
->dw_attr
));
8574 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, sym
, debug_loc_section
,
8575 "%s", dwarf_attr_name (a
->dw_attr
));
8578 /* Output an attribute's index or value appropriately. */
8581 output_attr_index_or_value (dw_attr_ref a
)
8583 const char *name
= dwarf_attr_name (a
->dw_attr
);
8585 if (dwarf_split_debug_info
&& AT_index (a
) != NOT_INDEXED
)
8587 dw2_asm_output_data_uleb128 (AT_index (a
), "%s", name
);
8590 switch (AT_class (a
))
8592 case dw_val_class_addr
:
8593 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, AT_addr (a
), "%s", name
);
8595 case dw_val_class_high_pc
:
8596 case dw_val_class_lbl_id
:
8597 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, AT_lbl (a
), "%s", name
);
8599 case dw_val_class_loc_list
:
8600 output_loc_list_offset (a
);
8607 /* Output a type signature. */
8610 output_signature (const char *sig
, const char *name
)
8614 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
8615 dw2_asm_output_data (1, sig
[i
], i
== 0 ? "%s" : NULL
, name
);
8618 /* Output the DIE and its attributes. Called recursively to generate
8619 the definitions of each child DIE. */
8622 output_die (dw_die_ref die
)
8629 /* If someone in another CU might refer to us, set up a symbol for
8630 them to point to. */
8631 if (! die
->comdat_type_p
&& die
->die_id
.die_symbol
)
8632 output_die_symbol (die
);
8634 dw2_asm_output_data_uleb128 (die
->die_abbrev
, "(DIE (%#lx) %s)",
8635 (unsigned long)die
->die_offset
,
8636 dwarf_tag_name (die
->die_tag
));
8638 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
8640 const char *name
= dwarf_attr_name (a
->dw_attr
);
8642 switch (AT_class (a
))
8644 case dw_val_class_addr
:
8645 output_attr_index_or_value (a
);
8648 case dw_val_class_offset
:
8649 dw2_asm_output_data (DWARF_OFFSET_SIZE
, a
->dw_attr_val
.v
.val_offset
,
8653 case dw_val_class_range_list
:
8654 output_range_list_offset (a
);
8657 case dw_val_class_loc
:
8658 size
= size_of_locs (AT_loc (a
));
8660 /* Output the block length for this list of location operations. */
8661 if (dwarf_version
>= 4)
8662 dw2_asm_output_data_uleb128 (size
, "%s", name
);
8664 dw2_asm_output_data (constant_size (size
), size
, "%s", name
);
8666 output_loc_sequence (AT_loc (a
), -1);
8669 case dw_val_class_const
:
8670 /* ??? It would be slightly more efficient to use a scheme like is
8671 used for unsigned constants below, but gdb 4.x does not sign
8672 extend. Gdb 5.x does sign extend. */
8673 dw2_asm_output_data_sleb128 (AT_int (a
), "%s", name
);
8676 case dw_val_class_unsigned_const
:
8678 int csize
= constant_size (AT_unsigned (a
));
8679 if (dwarf_version
== 3
8680 && a
->dw_attr
== DW_AT_data_member_location
8682 dw2_asm_output_data_uleb128 (AT_unsigned (a
), "%s", name
);
8684 dw2_asm_output_data (csize
, AT_unsigned (a
), "%s", name
);
8688 case dw_val_class_const_double
:
8690 unsigned HOST_WIDE_INT first
, second
;
8692 if (HOST_BITS_PER_WIDE_INT
>= 64)
8693 dw2_asm_output_data (1,
8694 HOST_BITS_PER_DOUBLE_INT
8695 / HOST_BITS_PER_CHAR
,
8698 if (WORDS_BIG_ENDIAN
)
8700 first
= a
->dw_attr_val
.v
.val_double
.high
;
8701 second
= a
->dw_attr_val
.v
.val_double
.low
;
8705 first
= a
->dw_attr_val
.v
.val_double
.low
;
8706 second
= a
->dw_attr_val
.v
.val_double
.high
;
8709 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8711 dw2_asm_output_data (HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
,
8716 case dw_val_class_wide_int
:
8719 int len
= get_full_len (*a
->dw_attr_val
.v
.val_wide
);
8720 int l
= HOST_BITS_PER_WIDE_INT
/ HOST_BITS_PER_CHAR
;
8721 if (len
* HOST_BITS_PER_WIDE_INT
> 64)
8722 dw2_asm_output_data (1, get_full_len (*a
->dw_attr_val
.v
.val_wide
) * l
,
8725 if (WORDS_BIG_ENDIAN
)
8726 for (i
= len
; i
>= 0; --i
)
8728 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
8733 for (i
= 0; i
< len
; ++i
)
8735 dw2_asm_output_data (l
, a
->dw_attr_val
.v
.val_wide
->elt (i
),
8742 case dw_val_class_vec
:
8744 unsigned int elt_size
= a
->dw_attr_val
.v
.val_vec
.elt_size
;
8745 unsigned int len
= a
->dw_attr_val
.v
.val_vec
.length
;
8749 dw2_asm_output_data (constant_size (len
* elt_size
),
8750 len
* elt_size
, "%s", name
);
8751 if (elt_size
> sizeof (HOST_WIDE_INT
))
8756 for (i
= 0, p
= a
->dw_attr_val
.v
.val_vec
.array
;
8759 dw2_asm_output_data (elt_size
, extract_int (p
, elt_size
),
8760 "fp or vector constant word %u", i
);
8764 case dw_val_class_flag
:
8765 if (dwarf_version
>= 4)
8767 /* Currently all add_AT_flag calls pass in 1 as last argument,
8768 so DW_FORM_flag_present can be used. If that ever changes,
8769 we'll need to use DW_FORM_flag and have some optimization
8770 in build_abbrev_table that will change those to
8771 DW_FORM_flag_present if it is set to 1 in all DIEs using
8772 the same abbrev entry. */
8773 gcc_assert (AT_flag (a
) == 1);
8775 fprintf (asm_out_file
, "\t\t\t%s %s\n",
8776 ASM_COMMENT_START
, name
);
8779 dw2_asm_output_data (1, AT_flag (a
), "%s", name
);
8782 case dw_val_class_loc_list
:
8783 output_attr_index_or_value (a
);
8786 case dw_val_class_die_ref
:
8787 if (AT_ref_external (a
))
8789 if (AT_ref (a
)->comdat_type_p
)
8791 comdat_type_node_ref type_node
=
8792 AT_ref (a
)->die_id
.die_type_node
;
8794 gcc_assert (type_node
);
8795 output_signature (type_node
->signature
, name
);
8799 const char *sym
= AT_ref (a
)->die_id
.die_symbol
;
8803 /* In DWARF2, DW_FORM_ref_addr is sized by target address
8804 length, whereas in DWARF3 it's always sized as an
8806 if (dwarf_version
== 2)
8807 size
= DWARF2_ADDR_SIZE
;
8809 size
= DWARF_OFFSET_SIZE
;
8810 dw2_asm_output_offset (size
, sym
, debug_info_section
, "%s",
8816 gcc_assert (AT_ref (a
)->die_offset
);
8817 dw2_asm_output_data (DWARF_OFFSET_SIZE
, AT_ref (a
)->die_offset
,
8822 case dw_val_class_fde_ref
:
8826 ASM_GENERATE_INTERNAL_LABEL (l1
, FDE_LABEL
,
8827 a
->dw_attr_val
.v
.val_fde_index
* 2);
8828 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, l1
, debug_frame_section
,
8833 case dw_val_class_vms_delta
:
8834 dw2_asm_output_vms_delta (DWARF_OFFSET_SIZE
,
8835 AT_vms_delta2 (a
), AT_vms_delta1 (a
),
8839 case dw_val_class_lbl_id
:
8840 output_attr_index_or_value (a
);
8843 case dw_val_class_lineptr
:
8844 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8845 debug_line_section
, "%s", name
);
8848 case dw_val_class_macptr
:
8849 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, AT_lbl (a
),
8850 debug_macinfo_section
, "%s", name
);
8853 case dw_val_class_str
:
8854 if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_strp
)
8855 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
8856 a
->dw_attr_val
.v
.val_str
->label
,
8858 "%s: \"%s\"", name
, AT_string (a
));
8859 else if (a
->dw_attr_val
.v
.val_str
->form
== DW_FORM_GNU_str_index
)
8860 dw2_asm_output_data_uleb128 (AT_index (a
),
8861 "%s: \"%s\"", name
, AT_string (a
));
8863 dw2_asm_output_nstring (AT_string (a
), -1, "%s", name
);
8866 case dw_val_class_file
:
8868 int f
= maybe_emit_file (a
->dw_attr_val
.v
.val_file
);
8870 dw2_asm_output_data (constant_size (f
), f
, "%s (%s)", name
,
8871 a
->dw_attr_val
.v
.val_file
->filename
);
8875 case dw_val_class_data8
:
8879 for (i
= 0; i
< 8; i
++)
8880 dw2_asm_output_data (1, a
->dw_attr_val
.v
.val_data8
[i
],
8881 i
== 0 ? "%s" : NULL
, name
);
8885 case dw_val_class_high_pc
:
8886 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, AT_lbl (a
),
8887 get_AT_low_pc (die
), "DW_AT_high_pc");
8895 FOR_EACH_CHILD (die
, c
, output_die (c
));
8897 /* Add null byte to terminate sibling list. */
8898 if (die
->die_child
!= NULL
)
8899 dw2_asm_output_data (1, 0, "end of children of DIE %#lx",
8900 (unsigned long) die
->die_offset
);
8903 /* Output the compilation unit that appears at the beginning of the
8904 .debug_info section, and precedes the DIE descriptions. */
8907 output_compilation_unit_header (void)
8909 int ver
= dwarf_version
;
8911 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
8912 dw2_asm_output_data (4, 0xffffffff,
8913 "Initial length escape value indicating 64-bit DWARF extension");
8914 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
8915 next_die_offset
- DWARF_INITIAL_LENGTH_SIZE
,
8916 "Length of Compilation Unit Info");
8917 dw2_asm_output_data (2, ver
, "DWARF version number");
8918 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, abbrev_section_label
,
8919 debug_abbrev_section
,
8920 "Offset Into Abbrev. Section");
8921 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
8924 /* Output the compilation unit DIE and its children. */
8927 output_comp_unit (dw_die_ref die
, int output_if_empty
)
8929 const char *secname
, *oldsym
;
8931 external_ref_hash_type extern_map
;
8933 /* Unless we are outputting main CU, we may throw away empty ones. */
8934 if (!output_if_empty
&& die
->die_child
== NULL
)
8937 /* Even if there are no children of this DIE, we must output the information
8938 about the compilation unit. Otherwise, on an empty translation unit, we
8939 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm'
8940 will then complain when examining the file. First mark all the DIEs in
8941 this CU so we know which get local refs. */
8944 extern_map
= optimize_external_refs (die
);
8946 build_abbrev_table (die
, extern_map
);
8948 extern_map
.dispose ();
8950 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
8951 next_die_offset
= DWARF_COMPILE_UNIT_HEADER_SIZE
;
8952 calc_die_sizes (die
);
8954 oldsym
= die
->die_id
.die_symbol
;
8957 tmp
= XALLOCAVEC (char, strlen (oldsym
) + 24);
8959 sprintf (tmp
, ".gnu.linkonce.wi.%s", oldsym
);
8961 die
->die_id
.die_symbol
= NULL
;
8962 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
8966 switch_to_section (debug_info_section
);
8967 ASM_OUTPUT_LABEL (asm_out_file
, debug_info_section_label
);
8968 info_section_emitted
= true;
8971 /* Output debugging information. */
8972 output_compilation_unit_header ();
8975 /* Leave the marks on the main CU, so we can check them in
8980 die
->die_id
.die_symbol
= oldsym
;
8984 /* Whether to generate the DWARF accelerator tables in .debug_pubnames
8985 and .debug_pubtypes. This is configured per-target, but can be
8986 overridden by the -gpubnames or -gno-pubnames options. */
8989 want_pubnames (void)
8991 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
8993 if (debug_generate_pub_sections
!= -1)
8994 return debug_generate_pub_sections
;
8995 return targetm
.want_debug_pub_sections
;
8998 /* Add the DW_AT_GNU_pubnames and DW_AT_GNU_pubtypes attributes. */
9001 add_AT_pubnames (dw_die_ref die
)
9003 if (want_pubnames ())
9004 add_AT_flag (die
, DW_AT_GNU_pubnames
, 1);
9007 /* Add a string attribute value to a skeleton DIE. */
9010 add_skeleton_AT_string (dw_die_ref die
, enum dwarf_attribute attr_kind
,
9014 struct indirect_string_node
*node
;
9016 if (! skeleton_debug_str_hash
)
9017 skeleton_debug_str_hash
= htab_create_ggc (10, debug_str_do_hash
,
9018 debug_str_eq
, NULL
);
9020 node
= find_AT_string_in_table (str
, skeleton_debug_str_hash
);
9021 find_string_form (node
);
9022 if (node
->form
== DW_FORM_GNU_str_index
)
9023 node
->form
= DW_FORM_strp
;
9025 attr
.dw_attr
= attr_kind
;
9026 attr
.dw_attr_val
.val_class
= dw_val_class_str
;
9027 attr
.dw_attr_val
.val_entry
= NULL
;
9028 attr
.dw_attr_val
.v
.val_str
= node
;
9029 add_dwarf_attr (die
, &attr
);
9032 /* Helper function to generate top-level dies for skeleton debug_info and
9036 add_top_level_skeleton_die_attrs (dw_die_ref die
)
9038 const char *dwo_file_name
= concat (aux_base_name
, ".dwo", NULL
);
9039 const char *comp_dir
= comp_dir_string ();
9041 add_skeleton_AT_string (die
, DW_AT_GNU_dwo_name
, dwo_file_name
);
9042 if (comp_dir
!= NULL
)
9043 add_skeleton_AT_string (die
, DW_AT_comp_dir
, comp_dir
);
9044 add_AT_pubnames (die
);
9045 add_AT_lineptr (die
, DW_AT_GNU_addr_base
, debug_addr_section_label
);
9048 /* Return the single type-unit die for skeleton type units. */
9051 get_skeleton_type_unit (void)
9053 /* For dwarf_split_debug_sections with use_type info, all type units in the
9054 skeleton sections have identical dies (but different headers). This
9055 single die will be output many times. */
9057 static dw_die_ref skeleton_type_unit
= NULL
;
9059 if (skeleton_type_unit
== NULL
)
9061 skeleton_type_unit
= new_die (DW_TAG_type_unit
, NULL
, NULL
);
9062 add_top_level_skeleton_die_attrs (skeleton_type_unit
);
9063 skeleton_type_unit
->die_abbrev
= SKELETON_TYPE_DIE_ABBREV
;
9065 return skeleton_type_unit
;
9068 /* Output skeleton debug sections that point to the dwo file. */
9071 output_skeleton_debug_sections (dw_die_ref comp_unit
)
9073 /* These attributes will be found in the full debug_info section. */
9074 remove_AT (comp_unit
, DW_AT_producer
);
9075 remove_AT (comp_unit
, DW_AT_language
);
9077 switch_to_section (debug_skeleton_info_section
);
9078 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_info_section_label
);
9080 /* Produce the skeleton compilation-unit header. This one differs enough from
9081 a normal CU header that it's better not to call output_compilation_unit
9083 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9084 dw2_asm_output_data (4, 0xffffffff,
9085 "Initial length escape value indicating 64-bit DWARF extension");
9087 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9088 DWARF_COMPILE_UNIT_HEADER_SIZE
9089 - DWARF_INITIAL_LENGTH_SIZE
9090 + size_of_die (comp_unit
),
9091 "Length of Compilation Unit Info");
9092 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9093 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_abbrev_section_label
,
9094 debug_abbrev_section
,
9095 "Offset Into Abbrev. Section");
9096 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9098 comp_unit
->die_abbrev
= SKELETON_COMP_DIE_ABBREV
;
9099 output_die (comp_unit
);
9101 /* Build the skeleton debug_abbrev section. */
9102 switch_to_section (debug_skeleton_abbrev_section
);
9103 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_abbrev_section_label
);
9105 output_die_abbrevs (SKELETON_COMP_DIE_ABBREV
, comp_unit
);
9106 if (use_debug_types
)
9107 output_die_abbrevs (SKELETON_TYPE_DIE_ABBREV
, get_skeleton_type_unit ());
9109 dw2_asm_output_data (1, 0, "end of skeleton .debug_abbrev");
9112 /* Output a comdat type unit DIE and its children. */
9115 output_comdat_type_unit (comdat_type_node
*node
)
9117 const char *secname
;
9120 #if defined (OBJECT_FORMAT_ELF)
9123 external_ref_hash_type extern_map
;
9125 /* First mark all the DIEs in this CU so we know which get local refs. */
9126 mark_dies (node
->root_die
);
9128 extern_map
= optimize_external_refs (node
->root_die
);
9130 build_abbrev_table (node
->root_die
, extern_map
);
9132 extern_map
.dispose ();
9134 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */
9135 next_die_offset
= DWARF_COMDAT_TYPE_UNIT_HEADER_SIZE
;
9136 calc_die_sizes (node
->root_die
);
9138 #if defined (OBJECT_FORMAT_ELF)
9139 if (!dwarf_split_debug_info
)
9140 secname
= ".debug_types";
9142 secname
= ".debug_types.dwo";
9144 tmp
= XALLOCAVEC (char, 4 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9145 sprintf (tmp
, "wt.");
9146 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9147 sprintf (tmp
+ 3 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9148 comdat_key
= get_identifier (tmp
);
9149 targetm
.asm_out
.named_section (secname
,
9150 SECTION_DEBUG
| SECTION_LINKONCE
,
9153 tmp
= XALLOCAVEC (char, 18 + DWARF_TYPE_SIGNATURE_SIZE
* 2);
9154 sprintf (tmp
, ".gnu.linkonce.wt.");
9155 for (i
= 0; i
< DWARF_TYPE_SIGNATURE_SIZE
; i
++)
9156 sprintf (tmp
+ 17 + i
* 2, "%02x", node
->signature
[i
] & 0xff);
9158 switch_to_section (get_section (secname
, SECTION_DEBUG
, NULL
));
9161 /* Output debugging information. */
9162 output_compilation_unit_header ();
9163 output_signature (node
->signature
, "Type Signature");
9164 dw2_asm_output_data (DWARF_OFFSET_SIZE
, node
->type_die
->die_offset
,
9165 "Offset to Type DIE");
9166 output_die (node
->root_die
);
9168 unmark_dies (node
->root_die
);
9170 #if defined (OBJECT_FORMAT_ELF)
9171 if (dwarf_split_debug_info
)
9173 /* Produce the skeleton type-unit header. */
9174 const char *secname
= ".debug_types";
9176 targetm
.asm_out
.named_section (secname
,
9177 SECTION_DEBUG
| SECTION_LINKONCE
,
9179 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9180 dw2_asm_output_data (4, 0xffffffff,
9181 "Initial length escape value indicating 64-bit DWARF extension");
9183 dw2_asm_output_data (DWARF_OFFSET_SIZE
,
9184 DWARF_COMPILE_UNIT_HEADER_SIZE
9185 - DWARF_INITIAL_LENGTH_SIZE
9186 + size_of_die (get_skeleton_type_unit ())
9187 + DWARF_TYPE_SIGNATURE_SIZE
+ DWARF_OFFSET_SIZE
,
9188 "Length of Type Unit Info");
9189 dw2_asm_output_data (2, dwarf_version
, "DWARF version number");
9190 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
9191 debug_skeleton_abbrev_section_label
,
9192 debug_abbrev_section
,
9193 "Offset Into Abbrev. Section");
9194 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Pointer Size (in bytes)");
9195 output_signature (node
->signature
, "Type Signature");
9196 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, "Offset to Type DIE");
9198 output_die (get_skeleton_type_unit ());
9203 /* Return the DWARF2/3 pubname associated with a decl. */
9206 dwarf2_name (tree decl
, int scope
)
9208 if (DECL_NAMELESS (decl
))
9210 return lang_hooks
.dwarf_name (decl
, scope
? 1 : 0);
9213 /* Add a new entry to .debug_pubnames if appropriate. */
9216 add_pubname_string (const char *str
, dw_die_ref die
)
9221 e
.name
= xstrdup (str
);
9222 vec_safe_push (pubname_table
, e
);
9226 add_pubname (tree decl
, dw_die_ref die
)
9228 if (!want_pubnames ())
9231 /* Don't add items to the table when we expect that the consumer will have
9232 just read the enclosing die. For example, if the consumer is looking at a
9233 class_member, it will either be inside the class already, or will have just
9234 looked up the class to find the member. Either way, searching the class is
9235 faster than searching the index. */
9236 if ((TREE_PUBLIC (decl
) && !class_scope_p (die
->die_parent
))
9237 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9239 const char *name
= dwarf2_name (decl
, 1);
9242 add_pubname_string (name
, die
);
9246 /* Add an enumerator to the pubnames section. */
9249 add_enumerator_pubname (const char *scope_name
, dw_die_ref die
)
9253 gcc_assert (scope_name
);
9254 e
.name
= concat (scope_name
, get_AT_string (die
, DW_AT_name
), NULL
);
9256 vec_safe_push (pubname_table
, e
);
9259 /* Add a new entry to .debug_pubtypes if appropriate. */
9262 add_pubtype (tree decl
, dw_die_ref die
)
9266 if (!want_pubnames ())
9269 if ((TREE_PUBLIC (decl
)
9270 || is_cu_die (die
->die_parent
) || is_namespace_die (die
->die_parent
))
9271 && (die
->die_tag
== DW_TAG_typedef
|| COMPLETE_TYPE_P (decl
)))
9274 const char *scope_name
= "";
9275 const char *sep
= is_cxx () ? "::" : ".";
9278 scope
= TYPE_P (decl
) ? TYPE_CONTEXT (decl
) : NULL
;
9279 if (scope
&& TREE_CODE (scope
) == NAMESPACE_DECL
)
9281 scope_name
= lang_hooks
.dwarf_name (scope
, 1);
9282 if (scope_name
!= NULL
&& scope_name
[0] != '\0')
9283 scope_name
= concat (scope_name
, sep
, NULL
);
9289 name
= type_tag (decl
);
9291 name
= lang_hooks
.dwarf_name (decl
, 1);
9293 /* If we don't have a name for the type, there's no point in adding
9295 if (name
!= NULL
&& name
[0] != '\0')
9298 e
.name
= concat (scope_name
, name
, NULL
);
9299 vec_safe_push (pubtype_table
, e
);
9302 /* Although it might be more consistent to add the pubinfo for the
9303 enumerators as their dies are created, they should only be added if the
9304 enum type meets the criteria above. So rather than re-check the parent
9305 enum type whenever an enumerator die is created, just output them all
9306 here. This isn't protected by the name conditional because anonymous
9307 enums don't have names. */
9308 if (die
->die_tag
== DW_TAG_enumeration_type
)
9312 FOR_EACH_CHILD (die
, c
, add_enumerator_pubname (scope_name
, c
));
9317 /* Output a single entry in the pubnames table. */
9320 output_pubname (dw_offset die_offset
, pubname_entry
*entry
)
9322 dw_die_ref die
= entry
->die
;
9323 int is_static
= get_AT_flag (die
, DW_AT_external
) ? 0 : 1;
9325 dw2_asm_output_data (DWARF_OFFSET_SIZE
, die_offset
, "DIE offset");
9327 if (debug_generate_pub_sections
== 2)
9329 /* This logic follows gdb's method for determining the value of the flag
9331 uint32_t flags
= GDB_INDEX_SYMBOL_KIND_NONE
;
9332 switch (die
->die_tag
)
9334 case DW_TAG_typedef
:
9335 case DW_TAG_base_type
:
9336 case DW_TAG_subrange_type
:
9337 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9338 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9340 case DW_TAG_enumerator
:
9341 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9342 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9343 if (!is_cxx () && !is_java ())
9344 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9346 case DW_TAG_subprogram
:
9347 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9348 GDB_INDEX_SYMBOL_KIND_FUNCTION
);
9350 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9352 case DW_TAG_constant
:
9353 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9354 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9355 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9357 case DW_TAG_variable
:
9358 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
,
9359 GDB_INDEX_SYMBOL_KIND_VARIABLE
);
9360 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, is_static
);
9362 case DW_TAG_namespace
:
9363 case DW_TAG_imported_declaration
:
9364 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9366 case DW_TAG_class_type
:
9367 case DW_TAG_interface_type
:
9368 case DW_TAG_structure_type
:
9369 case DW_TAG_union_type
:
9370 case DW_TAG_enumeration_type
:
9371 GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags
, GDB_INDEX_SYMBOL_KIND_TYPE
);
9372 if (!is_cxx () && !is_java ())
9373 GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags
, 1);
9376 /* An unusual tag. Leave the flag-byte empty. */
9379 dw2_asm_output_data (1, flags
>> GDB_INDEX_CU_BITSIZE
,
9383 dw2_asm_output_nstring (entry
->name
, -1, "external name");
9387 /* Output the public names table used to speed up access to externally
9388 visible names; or the public types table used to find type definitions. */
9391 output_pubnames (vec
<pubname_entry
, va_gc
> *names
)
9394 unsigned long pubnames_length
= size_of_pubnames (names
);
9397 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9398 dw2_asm_output_data (4, 0xffffffff,
9399 "Initial length escape value indicating 64-bit DWARF extension");
9400 dw2_asm_output_data (DWARF_OFFSET_SIZE
, pubnames_length
, "Pub Info Length");
9402 /* Version number for pubnames/pubtypes is independent of dwarf version. */
9403 dw2_asm_output_data (2, 2, "DWARF Version");
9405 if (dwarf_split_debug_info
)
9406 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9407 debug_skeleton_info_section
,
9408 "Offset of Compilation Unit Info");
9410 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9412 "Offset of Compilation Unit Info");
9413 dw2_asm_output_data (DWARF_OFFSET_SIZE
, next_die_offset
,
9414 "Compilation Unit Length");
9416 FOR_EACH_VEC_ELT (*names
, i
, pub
)
9418 if (include_pubname_in_output (names
, pub
))
9420 dw_offset die_offset
= pub
->die
->die_offset
;
9422 /* We shouldn't see pubnames for DIEs outside of the main CU. */
9423 if (names
== pubname_table
&& pub
->die
->die_tag
!= DW_TAG_enumerator
)
9424 gcc_assert (pub
->die
->die_mark
);
9426 /* If we're putting types in their own .debug_types sections,
9427 the .debug_pubtypes table will still point to the compile
9428 unit (not the type unit), so we want to use the offset of
9429 the skeleton DIE (if there is one). */
9430 if (pub
->die
->comdat_type_p
&& names
== pubtype_table
)
9432 comdat_type_node_ref type_node
= pub
->die
->die_id
.die_type_node
;
9434 if (type_node
!= NULL
)
9435 die_offset
= (type_node
->skeleton_die
!= NULL
9436 ? type_node
->skeleton_die
->die_offset
9437 : comp_unit_die ()->die_offset
);
9440 output_pubname (die_offset
, pub
);
9444 dw2_asm_output_data (DWARF_OFFSET_SIZE
, 0, NULL
);
9447 /* Output public names and types tables if necessary. */
9450 output_pubtables (void)
9452 if (!want_pubnames () || !info_section_emitted
)
9455 switch_to_section (debug_pubnames_section
);
9456 output_pubnames (pubname_table
);
9457 /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2.
9458 It shouldn't hurt to emit it always, since pure DWARF2 consumers
9459 simply won't look for the section. */
9460 switch_to_section (debug_pubtypes_section
);
9461 output_pubnames (pubtype_table
);
9465 /* Output the information that goes into the .debug_aranges table.
9466 Namely, define the beginning and ending address range of the
9467 text section generated for this compilation unit. */
9470 output_aranges (unsigned long aranges_length
)
9474 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
9475 dw2_asm_output_data (4, 0xffffffff,
9476 "Initial length escape value indicating 64-bit DWARF extension");
9477 dw2_asm_output_data (DWARF_OFFSET_SIZE
, aranges_length
,
9478 "Length of Address Ranges Info");
9479 /* Version number for aranges is still 2, even in DWARF3. */
9480 dw2_asm_output_data (2, 2, "DWARF Version");
9481 if (dwarf_split_debug_info
)
9482 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_skeleton_info_section_label
,
9483 debug_skeleton_info_section
,
9484 "Offset of Compilation Unit Info");
9486 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, debug_info_section_label
,
9488 "Offset of Compilation Unit Info");
9489 dw2_asm_output_data (1, DWARF2_ADDR_SIZE
, "Size of Address");
9490 dw2_asm_output_data (1, 0, "Size of Segment Descriptor");
9492 /* We need to align to twice the pointer size here. */
9493 if (DWARF_ARANGES_PAD_SIZE
)
9495 /* Pad using a 2 byte words so that padding is correct for any
9497 dw2_asm_output_data (2, 0, "Pad to %d byte boundary",
9498 2 * DWARF2_ADDR_SIZE
);
9499 for (i
= 2; i
< (unsigned) DWARF_ARANGES_PAD_SIZE
; i
+= 2)
9500 dw2_asm_output_data (2, 0, NULL
);
9503 /* It is necessary not to output these entries if the sections were
9504 not used; if the sections were not used, the length will be 0 and
9505 the address may end up as 0 if the section is discarded by ld
9506 --gc-sections, leaving an invalid (0, 0) entry that can be
9507 confused with the terminator. */
9508 if (text_section_used
)
9510 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, text_section_label
, "Address");
9511 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, text_end_label
,
9512 text_section_label
, "Length");
9514 if (cold_text_section_used
)
9516 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, cold_text_section_label
,
9518 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, cold_end_label
,
9519 cold_text_section_label
, "Length");
9522 if (have_multiple_function_sections
)
9527 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
9529 if (DECL_IGNORED_P (fde
->decl
))
9531 if (!fde
->in_std_section
)
9533 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_begin
,
9535 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_end
,
9536 fde
->dw_fde_begin
, "Length");
9538 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
9540 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_begin
,
9542 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, fde
->dw_fde_second_end
,
9543 fde
->dw_fde_second_begin
, "Length");
9548 /* Output the terminator words. */
9549 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9550 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9553 /* Add a new entry to .debug_ranges. Return the offset at which it
9557 add_ranges_num (int num
)
9559 unsigned int in_use
= ranges_table_in_use
;
9561 if (in_use
== ranges_table_allocated
)
9563 ranges_table_allocated
+= RANGES_TABLE_INCREMENT
;
9564 ranges_table
= GGC_RESIZEVEC (struct dw_ranges_struct
, ranges_table
,
9565 ranges_table_allocated
);
9566 memset (ranges_table
+ ranges_table_in_use
, 0,
9567 RANGES_TABLE_INCREMENT
* sizeof (struct dw_ranges_struct
));
9570 ranges_table
[in_use
].num
= num
;
9571 ranges_table_in_use
= in_use
+ 1;
9573 return in_use
* 2 * DWARF2_ADDR_SIZE
;
9576 /* Add a new entry to .debug_ranges corresponding to a block, or a
9577 range terminator if BLOCK is NULL. */
9580 add_ranges (const_tree block
)
9582 return add_ranges_num (block
? BLOCK_NUMBER (block
) : 0);
9585 /* Add a new entry to .debug_ranges corresponding to a pair of labels.
9586 When using dwarf_split_debug_info, address attributes in dies destined
9587 for the final executable should be direct references--setting the
9588 parameter force_direct ensures this behavior. */
9591 add_ranges_by_labels (dw_die_ref die
, const char *begin
, const char *end
,
9592 bool *added
, bool force_direct
)
9594 unsigned int in_use
= ranges_by_label_in_use
;
9595 unsigned int offset
;
9597 if (in_use
== ranges_by_label_allocated
)
9599 ranges_by_label_allocated
+= RANGES_TABLE_INCREMENT
;
9600 ranges_by_label
= GGC_RESIZEVEC (struct dw_ranges_by_label_struct
,
9602 ranges_by_label_allocated
);
9603 memset (ranges_by_label
+ ranges_by_label_in_use
, 0,
9604 RANGES_TABLE_INCREMENT
9605 * sizeof (struct dw_ranges_by_label_struct
));
9608 ranges_by_label
[in_use
].begin
= begin
;
9609 ranges_by_label
[in_use
].end
= end
;
9610 ranges_by_label_in_use
= in_use
+ 1;
9612 offset
= add_ranges_num (-(int)in_use
- 1);
9615 add_AT_range_list (die
, DW_AT_ranges
, offset
, force_direct
);
9621 output_ranges (void)
9624 static const char *const start_fmt
= "Offset %#x";
9625 const char *fmt
= start_fmt
;
9627 for (i
= 0; i
< ranges_table_in_use
; i
++)
9629 int block_num
= ranges_table
[i
].num
;
9633 char blabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9634 char elabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
9636 ASM_GENERATE_INTERNAL_LABEL (blabel
, BLOCK_BEGIN_LABEL
, block_num
);
9637 ASM_GENERATE_INTERNAL_LABEL (elabel
, BLOCK_END_LABEL
, block_num
);
9639 /* If all code is in the text section, then the compilation
9640 unit base address defaults to DW_AT_low_pc, which is the
9641 base of the text section. */
9642 if (!have_multiple_function_sections
)
9644 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, blabel
,
9646 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9647 dw2_asm_output_delta (DWARF2_ADDR_SIZE
, elabel
,
9648 text_section_label
, NULL
);
9651 /* Otherwise, the compilation unit base address is zero,
9652 which allows us to use absolute addresses, and not worry
9653 about whether the target supports cross-section
9657 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, blabel
,
9658 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9659 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, elabel
, NULL
);
9665 /* Negative block_num stands for an index into ranges_by_label. */
9666 else if (block_num
< 0)
9668 int lab_idx
= - block_num
- 1;
9670 if (!have_multiple_function_sections
)
9674 /* If we ever use add_ranges_by_labels () for a single
9675 function section, all we have to do is to take out
9677 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9678 ranges_by_label
[lab_idx
].begin
,
9680 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9681 dw2_asm_output_delta (DWARF2_ADDR_SIZE
,
9682 ranges_by_label
[lab_idx
].end
,
9683 text_section_label
, NULL
);
9688 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9689 ranges_by_label
[lab_idx
].begin
,
9690 fmt
, i
* 2 * DWARF2_ADDR_SIZE
);
9691 dw2_asm_output_addr (DWARF2_ADDR_SIZE
,
9692 ranges_by_label
[lab_idx
].end
,
9698 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9699 dw2_asm_output_data (DWARF2_ADDR_SIZE
, 0, NULL
);
9705 /* Data structure containing information about input files. */
9708 const char *path
; /* Complete file name. */
9709 const char *fname
; /* File name part. */
9710 int length
; /* Length of entire string. */
9711 struct dwarf_file_data
* file_idx
; /* Index in input file table. */
9712 int dir_idx
; /* Index in directory table. */
9715 /* Data structure containing information about directories with source
9719 const char *path
; /* Path including directory name. */
9720 int length
; /* Path length. */
9721 int prefix
; /* Index of directory entry which is a prefix. */
9722 int count
; /* Number of files in this directory. */
9723 int dir_idx
; /* Index of directory used as base. */
9726 /* Callback function for file_info comparison. We sort by looking at
9727 the directories in the path. */
9730 file_info_cmp (const void *p1
, const void *p2
)
9732 const struct file_info
*const s1
= (const struct file_info
*) p1
;
9733 const struct file_info
*const s2
= (const struct file_info
*) p2
;
9734 const unsigned char *cp1
;
9735 const unsigned char *cp2
;
9737 /* Take care of file names without directories. We need to make sure that
9738 we return consistent values to qsort since some will get confused if
9739 we return the same value when identical operands are passed in opposite
9740 orders. So if neither has a directory, return 0 and otherwise return
9741 1 or -1 depending on which one has the directory. */
9742 if ((s1
->path
== s1
->fname
|| s2
->path
== s2
->fname
))
9743 return (s2
->path
== s2
->fname
) - (s1
->path
== s1
->fname
);
9745 cp1
= (const unsigned char *) s1
->path
;
9746 cp2
= (const unsigned char *) s2
->path
;
9752 /* Reached the end of the first path? If so, handle like above. */
9753 if ((cp1
== (const unsigned char *) s1
->fname
)
9754 || (cp2
== (const unsigned char *) s2
->fname
))
9755 return ((cp2
== (const unsigned char *) s2
->fname
)
9756 - (cp1
== (const unsigned char *) s1
->fname
));
9758 /* Character of current path component the same? */
9759 else if (*cp1
!= *cp2
)
9764 struct file_name_acquire_data
9766 struct file_info
*files
;
9771 /* Traversal function for the hash table. */
9774 file_name_acquire (void ** slot
, void *data
)
9776 struct file_name_acquire_data
*fnad
= (struct file_name_acquire_data
*) data
;
9777 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
9778 struct file_info
*fi
;
9781 gcc_assert (fnad
->max_files
>= d
->emitted_number
);
9783 if (! d
->emitted_number
)
9786 gcc_assert (fnad
->max_files
!= fnad
->used_files
);
9788 fi
= fnad
->files
+ fnad
->used_files
++;
9790 /* Skip all leading "./". */
9792 while (f
[0] == '.' && IS_DIR_SEPARATOR (f
[1]))
9795 /* Create a new array entry. */
9797 fi
->length
= strlen (f
);
9800 /* Search for the file name part. */
9801 f
= strrchr (f
, DIR_SEPARATOR
);
9802 #if defined (DIR_SEPARATOR_2)
9804 char *g
= strrchr (fi
->path
, DIR_SEPARATOR_2
);
9808 if (f
== NULL
|| f
< g
)
9814 fi
->fname
= f
== NULL
? fi
->path
: f
+ 1;
9818 /* Output the directory table and the file name table. We try to minimize
9819 the total amount of memory needed. A heuristic is used to avoid large
9820 slowdowns with many input files. */
9823 output_file_names (void)
9825 struct file_name_acquire_data fnad
;
9827 struct file_info
*files
;
9828 struct dir_info
*dirs
;
9836 if (!last_emitted_file
)
9838 dw2_asm_output_data (1, 0, "End directory table");
9839 dw2_asm_output_data (1, 0, "End file name table");
9843 numfiles
= last_emitted_file
->emitted_number
;
9845 /* Allocate the various arrays we need. */
9846 files
= XALLOCAVEC (struct file_info
, numfiles
);
9847 dirs
= XALLOCAVEC (struct dir_info
, numfiles
);
9850 fnad
.used_files
= 0;
9851 fnad
.max_files
= numfiles
;
9852 htab_traverse (file_table
, file_name_acquire
, &fnad
);
9853 gcc_assert (fnad
.used_files
== fnad
.max_files
);
9855 qsort (files
, numfiles
, sizeof (files
[0]), file_info_cmp
);
9857 /* Find all the different directories used. */
9858 dirs
[0].path
= files
[0].path
;
9859 dirs
[0].length
= files
[0].fname
- files
[0].path
;
9860 dirs
[0].prefix
= -1;
9862 dirs
[0].dir_idx
= 0;
9863 files
[0].dir_idx
= 0;
9866 for (i
= 1; i
< numfiles
; i
++)
9867 if (files
[i
].fname
- files
[i
].path
== dirs
[ndirs
- 1].length
9868 && memcmp (dirs
[ndirs
- 1].path
, files
[i
].path
,
9869 dirs
[ndirs
- 1].length
) == 0)
9871 /* Same directory as last entry. */
9872 files
[i
].dir_idx
= ndirs
- 1;
9873 ++dirs
[ndirs
- 1].count
;
9879 /* This is a new directory. */
9880 dirs
[ndirs
].path
= files
[i
].path
;
9881 dirs
[ndirs
].length
= files
[i
].fname
- files
[i
].path
;
9882 dirs
[ndirs
].count
= 1;
9883 dirs
[ndirs
].dir_idx
= ndirs
;
9884 files
[i
].dir_idx
= ndirs
;
9886 /* Search for a prefix. */
9887 dirs
[ndirs
].prefix
= -1;
9888 for (j
= 0; j
< ndirs
; j
++)
9889 if (dirs
[j
].length
< dirs
[ndirs
].length
9890 && dirs
[j
].length
> 1
9891 && (dirs
[ndirs
].prefix
== -1
9892 || dirs
[j
].length
> dirs
[dirs
[ndirs
].prefix
].length
)
9893 && memcmp (dirs
[j
].path
, dirs
[ndirs
].path
, dirs
[j
].length
) == 0)
9894 dirs
[ndirs
].prefix
= j
;
9899 /* Now to the actual work. We have to find a subset of the directories which
9900 allow expressing the file name using references to the directory table
9901 with the least amount of characters. We do not do an exhaustive search
9902 where we would have to check out every combination of every single
9903 possible prefix. Instead we use a heuristic which provides nearly optimal
9904 results in most cases and never is much off. */
9905 saved
= XALLOCAVEC (int, ndirs
);
9906 savehere
= XALLOCAVEC (int, ndirs
);
9908 memset (saved
, '\0', ndirs
* sizeof (saved
[0]));
9909 for (i
= 0; i
< ndirs
; i
++)
9914 /* We can always save some space for the current directory. But this
9915 does not mean it will be enough to justify adding the directory. */
9916 savehere
[i
] = dirs
[i
].length
;
9917 total
= (savehere
[i
] - saved
[i
]) * dirs
[i
].count
;
9919 for (j
= i
+ 1; j
< ndirs
; j
++)
9922 if (saved
[j
] < dirs
[i
].length
)
9924 /* Determine whether the dirs[i] path is a prefix of the
9929 while (k
!= -1 && k
!= (int) i
)
9934 /* Yes it is. We can possibly save some memory by
9935 writing the filenames in dirs[j] relative to
9937 savehere
[j
] = dirs
[i
].length
;
9938 total
+= (savehere
[j
] - saved
[j
]) * dirs
[j
].count
;
9943 /* Check whether we can save enough to justify adding the dirs[i]
9945 if (total
> dirs
[i
].length
+ 1)
9947 /* It's worthwhile adding. */
9948 for (j
= i
; j
< ndirs
; j
++)
9949 if (savehere
[j
] > 0)
9951 /* Remember how much we saved for this directory so far. */
9952 saved
[j
] = savehere
[j
];
9954 /* Remember the prefix directory. */
9955 dirs
[j
].dir_idx
= i
;
9960 /* Emit the directory name table. */
9961 idx_offset
= dirs
[0].length
> 0 ? 1 : 0;
9962 for (i
= 1 - idx_offset
; i
< ndirs
; i
++)
9963 dw2_asm_output_nstring (dirs
[i
].path
,
9965 - !DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
,
9966 "Directory Entry: %#x", i
+ idx_offset
);
9968 dw2_asm_output_data (1, 0, "End directory table");
9970 /* We have to emit them in the order of emitted_number since that's
9971 used in the debug info generation. To do this efficiently we
9972 generate a back-mapping of the indices first. */
9973 backmap
= XALLOCAVEC (int, numfiles
);
9974 for (i
= 0; i
< numfiles
; i
++)
9975 backmap
[files
[i
].file_idx
->emitted_number
- 1] = i
;
9977 /* Now write all the file names. */
9978 for (i
= 0; i
< numfiles
; i
++)
9980 int file_idx
= backmap
[i
];
9981 int dir_idx
= dirs
[files
[file_idx
].dir_idx
].dir_idx
;
9983 #ifdef VMS_DEBUGGING_INFO
9984 #define MAX_VMS_VERSION_LEN 6 /* ";32768" */
9986 /* Setting these fields can lead to debugger miscomparisons,
9987 but VMS Debug requires them to be set correctly. */
9992 int maxfilelen
= strlen (files
[file_idx
].path
)
9993 + dirs
[dir_idx
].length
9994 + MAX_VMS_VERSION_LEN
+ 1;
9995 char *filebuf
= XALLOCAVEC (char, maxfilelen
);
9997 vms_file_stats_name (files
[file_idx
].path
, 0, 0, 0, &ver
);
9998 snprintf (filebuf
, maxfilelen
, "%s;%d",
9999 files
[file_idx
].path
+ dirs
[dir_idx
].length
, ver
);
10001 dw2_asm_output_nstring
10002 (filebuf
, -1, "File Entry: %#x", (unsigned) i
+ 1);
10004 /* Include directory index. */
10005 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10007 /* Modification time. */
10008 dw2_asm_output_data_uleb128
10009 ((vms_file_stats_name (files
[file_idx
].path
, &cdt
, 0, 0, 0) == 0)
10013 /* File length in bytes. */
10014 dw2_asm_output_data_uleb128
10015 ((vms_file_stats_name (files
[file_idx
].path
, 0, &siz
, 0, 0) == 0)
10019 dw2_asm_output_nstring (files
[file_idx
].path
+ dirs
[dir_idx
].length
, -1,
10020 "File Entry: %#x", (unsigned) i
+ 1);
10022 /* Include directory index. */
10023 dw2_asm_output_data_uleb128 (dir_idx
+ idx_offset
, NULL
);
10025 /* Modification time. */
10026 dw2_asm_output_data_uleb128 (0, NULL
);
10028 /* File length in bytes. */
10029 dw2_asm_output_data_uleb128 (0, NULL
);
10030 #endif /* VMS_DEBUGGING_INFO */
10033 dw2_asm_output_data (1, 0, "End file name table");
10037 /* Output one line number table into the .debug_line section. */
10040 output_one_line_info_table (dw_line_info_table
*table
)
10042 char line_label
[MAX_ARTIFICIAL_LABEL_BYTES
];
10043 unsigned int current_line
= 1;
10044 bool current_is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
10045 dw_line_info_entry
*ent
;
10048 FOR_EACH_VEC_SAFE_ELT (table
->entries
, i
, ent
)
10050 switch (ent
->opcode
)
10052 case LI_set_address
:
10053 /* ??? Unfortunately, we have little choice here currently, and
10054 must always use the most general form. GCC does not know the
10055 address delta itself, so we can't use DW_LNS_advance_pc. Many
10056 ports do have length attributes which will give an upper bound
10057 on the address range. We could perhaps use length attributes
10058 to determine when it is safe to use DW_LNS_fixed_advance_pc. */
10059 ASM_GENERATE_INTERNAL_LABEL (line_label
, LINE_CODE_LABEL
, ent
->val
);
10061 /* This can handle any delta. This takes
10062 4+DWARF2_ADDR_SIZE bytes. */
10063 dw2_asm_output_data (1, 0, "set address %s", line_label
);
10064 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10065 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10066 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, line_label
, NULL
);
10070 if (ent
->val
== current_line
)
10072 /* We still need to start a new row, so output a copy insn. */
10073 dw2_asm_output_data (1, DW_LNS_copy
,
10074 "copy line %u", current_line
);
10078 int line_offset
= ent
->val
- current_line
;
10079 int line_delta
= line_offset
- DWARF_LINE_BASE
;
10081 current_line
= ent
->val
;
10082 if (line_delta
>= 0 && line_delta
< (DWARF_LINE_RANGE
- 1))
10084 /* This can handle deltas from -10 to 234, using the current
10085 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE.
10086 This takes 1 byte. */
10087 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
+ line_delta
,
10088 "line %u", current_line
);
10092 /* This can handle any delta. This takes at least 4 bytes,
10093 depending on the value being encoded. */
10094 dw2_asm_output_data (1, DW_LNS_advance_line
,
10095 "advance to line %u", current_line
);
10096 dw2_asm_output_data_sleb128 (line_offset
, NULL
);
10097 dw2_asm_output_data (1, DW_LNS_copy
, NULL
);
10103 dw2_asm_output_data (1, DW_LNS_set_file
, "set file %u", ent
->val
);
10104 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10107 case LI_set_column
:
10108 dw2_asm_output_data (1, DW_LNS_set_column
, "column %u", ent
->val
);
10109 dw2_asm_output_data_uleb128 (ent
->val
, "%u", ent
->val
);
10112 case LI_negate_stmt
:
10113 current_is_stmt
= !current_is_stmt
;
10114 dw2_asm_output_data (1, DW_LNS_negate_stmt
,
10115 "is_stmt %d", current_is_stmt
);
10118 case LI_set_prologue_end
:
10119 dw2_asm_output_data (1, DW_LNS_set_prologue_end
,
10120 "set prologue end");
10123 case LI_set_epilogue_begin
:
10124 dw2_asm_output_data (1, DW_LNS_set_epilogue_begin
,
10125 "set epilogue begin");
10128 case LI_set_discriminator
:
10129 dw2_asm_output_data (1, 0, "discriminator %u", ent
->val
);
10130 dw2_asm_output_data_uleb128 (1 + size_of_uleb128 (ent
->val
), NULL
);
10131 dw2_asm_output_data (1, DW_LNE_set_discriminator
, NULL
);
10132 dw2_asm_output_data_uleb128 (ent
->val
, NULL
);
10137 /* Emit debug info for the address of the end of the table. */
10138 dw2_asm_output_data (1, 0, "set address %s", table
->end_label
);
10139 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE
, NULL
);
10140 dw2_asm_output_data (1, DW_LNE_set_address
, NULL
);
10141 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, table
->end_label
, NULL
);
10143 dw2_asm_output_data (1, 0, "end sequence");
10144 dw2_asm_output_data_uleb128 (1, NULL
);
10145 dw2_asm_output_data (1, DW_LNE_end_sequence
, NULL
);
10148 /* Output the source line number correspondence information. This
10149 information goes into the .debug_line section. */
10152 output_line_info (bool prologue_only
)
10154 char l1
[20], l2
[20], p1
[20], p2
[20];
10155 int ver
= dwarf_version
;
10156 bool saw_one
= false;
10159 ASM_GENERATE_INTERNAL_LABEL (l1
, LINE_NUMBER_BEGIN_LABEL
, 0);
10160 ASM_GENERATE_INTERNAL_LABEL (l2
, LINE_NUMBER_END_LABEL
, 0);
10161 ASM_GENERATE_INTERNAL_LABEL (p1
, LN_PROLOG_AS_LABEL
, 0);
10162 ASM_GENERATE_INTERNAL_LABEL (p2
, LN_PROLOG_END_LABEL
, 0);
10164 if (DWARF_INITIAL_LENGTH_SIZE
- DWARF_OFFSET_SIZE
== 4)
10165 dw2_asm_output_data (4, 0xffffffff,
10166 "Initial length escape value indicating 64-bit DWARF extension");
10167 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, l2
, l1
,
10168 "Length of Source Line Info");
10169 ASM_OUTPUT_LABEL (asm_out_file
, l1
);
10171 dw2_asm_output_data (2, ver
, "DWARF Version");
10172 dw2_asm_output_delta (DWARF_OFFSET_SIZE
, p2
, p1
, "Prolog Length");
10173 ASM_OUTPUT_LABEL (asm_out_file
, p1
);
10175 /* Define the architecture-dependent minimum instruction length (in bytes).
10176 In this implementation of DWARF, this field is used for information
10177 purposes only. Since GCC generates assembly language, we have no
10178 a priori knowledge of how many instruction bytes are generated for each
10179 source line, and therefore can use only the DW_LNE_set_address and
10180 DW_LNS_fixed_advance_pc line information commands. Accordingly, we fix
10181 this as '1', which is "correct enough" for all architectures,
10182 and don't let the target override. */
10183 dw2_asm_output_data (1, 1, "Minimum Instruction Length");
10186 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_MAX_OPS_PER_INSN
,
10187 "Maximum Operations Per Instruction");
10188 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START
,
10189 "Default is_stmt_start flag");
10190 dw2_asm_output_data (1, DWARF_LINE_BASE
,
10191 "Line Base Value (Special Opcodes)");
10192 dw2_asm_output_data (1, DWARF_LINE_RANGE
,
10193 "Line Range Value (Special Opcodes)");
10194 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE
,
10195 "Special Opcode Base");
10197 for (opc
= 1; opc
< DWARF_LINE_OPCODE_BASE
; opc
++)
10202 case DW_LNS_advance_pc
:
10203 case DW_LNS_advance_line
:
10204 case DW_LNS_set_file
:
10205 case DW_LNS_set_column
:
10206 case DW_LNS_fixed_advance_pc
:
10207 case DW_LNS_set_isa
:
10215 dw2_asm_output_data (1, n_op_args
, "opcode: %#x has %d args",
10219 /* Write out the information about the files we use. */
10220 output_file_names ();
10221 ASM_OUTPUT_LABEL (asm_out_file
, p2
);
10224 /* Output the marker for the end of the line number info. */
10225 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10229 if (separate_line_info
)
10231 dw_line_info_table
*table
;
10234 FOR_EACH_VEC_ELT (*separate_line_info
, i
, table
)
10237 output_one_line_info_table (table
);
10241 if (cold_text_section_line_info
&& cold_text_section_line_info
->in_use
)
10243 output_one_line_info_table (cold_text_section_line_info
);
10247 /* ??? Some Darwin linkers crash on a .debug_line section with no
10248 sequences. Further, merely a DW_LNE_end_sequence entry is not
10249 sufficient -- the address column must also be initialized.
10250 Make sure to output at least one set_address/end_sequence pair,
10251 choosing .text since that section is always present. */
10252 if (text_section_line_info
->in_use
|| !saw_one
)
10253 output_one_line_info_table (text_section_line_info
);
10255 /* Output the marker for the end of the line number info. */
10256 ASM_OUTPUT_LABEL (asm_out_file
, l2
);
10259 /* Given a pointer to a tree node for some base type, return a pointer to
10260 a DIE that describes the given type.
10262 This routine must only be called for GCC type nodes that correspond to
10263 Dwarf base (fundamental) types. */
10266 base_type_die (tree type
)
10268 dw_die_ref base_type_result
;
10269 enum dwarf_type encoding
;
10271 if (TREE_CODE (type
) == ERROR_MARK
|| TREE_CODE (type
) == VOID_TYPE
)
10274 /* If this is a subtype that should not be emitted as a subrange type,
10275 use the base type. See subrange_type_for_debug_p. */
10276 if (TREE_CODE (type
) == INTEGER_TYPE
&& TREE_TYPE (type
) != NULL_TREE
)
10277 type
= TREE_TYPE (type
);
10279 switch (TREE_CODE (type
))
10282 if ((dwarf_version
>= 4 || !dwarf_strict
)
10283 && TYPE_NAME (type
)
10284 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
10285 && DECL_IS_BUILTIN (TYPE_NAME (type
))
10286 && DECL_NAME (TYPE_NAME (type
)))
10288 const char *name
= IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
10289 if (strcmp (name
, "char16_t") == 0
10290 || strcmp (name
, "char32_t") == 0)
10292 encoding
= DW_ATE_UTF
;
10296 if (TYPE_STRING_FLAG (type
))
10298 if (TYPE_UNSIGNED (type
))
10299 encoding
= DW_ATE_unsigned_char
;
10301 encoding
= DW_ATE_signed_char
;
10303 else if (TYPE_UNSIGNED (type
))
10304 encoding
= DW_ATE_unsigned
;
10306 encoding
= DW_ATE_signed
;
10310 if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type
)))
10312 if (dwarf_version
>= 3 || !dwarf_strict
)
10313 encoding
= DW_ATE_decimal_float
;
10315 encoding
= DW_ATE_lo_user
;
10318 encoding
= DW_ATE_float
;
10321 case FIXED_POINT_TYPE
:
10322 if (!(dwarf_version
>= 3 || !dwarf_strict
))
10323 encoding
= DW_ATE_lo_user
;
10324 else if (TYPE_UNSIGNED (type
))
10325 encoding
= DW_ATE_unsigned_fixed
;
10327 encoding
= DW_ATE_signed_fixed
;
10330 /* Dwarf2 doesn't know anything about complex ints, so use
10331 a user defined type for it. */
10333 if (TREE_CODE (TREE_TYPE (type
)) == REAL_TYPE
)
10334 encoding
= DW_ATE_complex_float
;
10336 encoding
= DW_ATE_lo_user
;
10340 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */
10341 encoding
= DW_ATE_boolean
;
10345 /* No other TREE_CODEs are Dwarf fundamental types. */
10346 gcc_unreachable ();
10349 base_type_result
= new_die (DW_TAG_base_type
, comp_unit_die (), type
);
10351 add_AT_unsigned (base_type_result
, DW_AT_byte_size
,
10352 int_size_in_bytes (type
));
10353 add_AT_unsigned (base_type_result
, DW_AT_encoding
, encoding
);
10354 add_pubtype (type
, base_type_result
);
10356 return base_type_result
;
10359 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM
10360 named 'auto' in its type: return true for it, false otherwise. */
10363 is_cxx_auto (tree type
)
10367 tree name
= TYPE_NAME (type
);
10368 if (TREE_CODE (name
) == TYPE_DECL
)
10369 name
= DECL_NAME (name
);
10370 if (name
== get_identifier ("auto")
10371 || name
== get_identifier ("decltype(auto)"))
10377 /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the
10378 given input type is a Dwarf "fundamental" type. Otherwise return null. */
10381 is_base_type (tree type
)
10383 switch (TREE_CODE (type
))
10389 case FIXED_POINT_TYPE
:
10397 case QUAL_UNION_TYPE
:
10398 case ENUMERAL_TYPE
:
10399 case FUNCTION_TYPE
:
10402 case REFERENCE_TYPE
:
10410 if (is_cxx_auto (type
))
10412 gcc_unreachable ();
10418 /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE
10419 node, return the size in bits for the type if it is a constant, or else
10420 return the alignment for the type if the type's size is not constant, or
10421 else return BITS_PER_WORD if the type actually turns out to be an
10422 ERROR_MARK node. */
10424 static inline unsigned HOST_WIDE_INT
10425 simple_type_size_in_bits (const_tree type
)
10427 if (TREE_CODE (type
) == ERROR_MARK
)
10428 return BITS_PER_WORD
;
10429 else if (TYPE_SIZE (type
) == NULL_TREE
)
10431 else if (tree_fits_uhwi_p (TYPE_SIZE (type
)))
10432 return tree_to_uhwi (TYPE_SIZE (type
));
10434 return TYPE_ALIGN (type
);
10437 /* Similarly, but return an offset_int instead of UHWI. */
10439 static inline offset_int
10440 offset_int_type_size_in_bits (const_tree type
)
10442 if (TREE_CODE (type
) == ERROR_MARK
)
10443 return BITS_PER_WORD
;
10444 else if (TYPE_SIZE (type
) == NULL_TREE
)
10446 else if (TREE_CODE (TYPE_SIZE (type
)) == INTEGER_CST
)
10447 return wi::to_offset (TYPE_SIZE (type
));
10449 return TYPE_ALIGN (type
);
10452 /* Given a pointer to a tree node for a subrange type, return a pointer
10453 to a DIE that describes the given type. */
10456 subrange_type_die (tree type
, tree low
, tree high
, dw_die_ref context_die
)
10458 dw_die_ref subrange_die
;
10459 const HOST_WIDE_INT size_in_bytes
= int_size_in_bytes (type
);
10461 if (context_die
== NULL
)
10462 context_die
= comp_unit_die ();
10464 subrange_die
= new_die (DW_TAG_subrange_type
, context_die
, type
);
10466 if (int_size_in_bytes (TREE_TYPE (type
)) != size_in_bytes
)
10468 /* The size of the subrange type and its base type do not match,
10469 so we need to generate a size attribute for the subrange type. */
10470 add_AT_unsigned (subrange_die
, DW_AT_byte_size
, size_in_bytes
);
10474 add_bound_info (subrange_die
, DW_AT_lower_bound
, low
);
10476 add_bound_info (subrange_die
, DW_AT_upper_bound
, high
);
10478 return subrange_die
;
10481 /* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging
10482 entry that chains various modifiers in front of the given type. */
10485 modified_type_die (tree type
, int is_const_type
, int is_volatile_type
,
10486 dw_die_ref context_die
)
10488 enum tree_code code
= TREE_CODE (type
);
10489 dw_die_ref mod_type_die
;
10490 dw_die_ref sub_die
= NULL
;
10491 tree item_type
= NULL
;
10492 tree qualified_type
;
10493 tree name
, low
, high
;
10494 dw_die_ref mod_scope
;
10496 if (code
== ERROR_MARK
)
10499 /* See if we already have the appropriately qualified variant of
10502 = get_qualified_type (type
,
10503 ((is_const_type
? TYPE_QUAL_CONST
: 0)
10504 | (is_volatile_type
? TYPE_QUAL_VOLATILE
: 0)));
10506 if (qualified_type
== sizetype
10507 && TYPE_NAME (qualified_type
)
10508 && TREE_CODE (TYPE_NAME (qualified_type
)) == TYPE_DECL
)
10510 tree t
= TREE_TYPE (TYPE_NAME (qualified_type
));
10512 gcc_checking_assert (TREE_CODE (t
) == INTEGER_TYPE
10513 && TYPE_PRECISION (t
)
10514 == TYPE_PRECISION (qualified_type
)
10515 && TYPE_UNSIGNED (t
)
10516 == TYPE_UNSIGNED (qualified_type
));
10517 qualified_type
= t
;
10520 /* If we do, then we can just use its DIE, if it exists. */
10521 if (qualified_type
)
10523 mod_type_die
= lookup_type_die (qualified_type
);
10525 return mod_type_die
;
10528 name
= qualified_type
? TYPE_NAME (qualified_type
) : NULL
;
10530 /* Handle C typedef types. */
10531 if (name
&& TREE_CODE (name
) == TYPE_DECL
&& DECL_ORIGINAL_TYPE (name
)
10532 && !DECL_ARTIFICIAL (name
))
10534 tree dtype
= TREE_TYPE (name
);
10536 if (qualified_type
== dtype
)
10538 /* For a named type, use the typedef. */
10539 gen_type_die (qualified_type
, context_die
);
10540 return lookup_type_die (qualified_type
);
10542 else if (is_const_type
< TYPE_READONLY (dtype
)
10543 || is_volatile_type
< TYPE_VOLATILE (dtype
)
10544 || (is_const_type
<= TYPE_READONLY (dtype
)
10545 && is_volatile_type
<= TYPE_VOLATILE (dtype
)
10546 && DECL_ORIGINAL_TYPE (name
) != type
))
10547 /* cv-unqualified version of named type. Just use the unnamed
10548 type to which it refers. */
10549 return modified_type_die (DECL_ORIGINAL_TYPE (name
),
10550 is_const_type
, is_volatile_type
,
10552 /* Else cv-qualified version of named type; fall through. */
10555 mod_scope
= scope_die_for (type
, context_die
);
10558 /* If both is_const_type and is_volatile_type, prefer the path
10559 which leads to a qualified type. */
10560 && (!is_volatile_type
10561 || get_qualified_type (type
, TYPE_QUAL_CONST
) == NULL_TREE
10562 || get_qualified_type (type
, TYPE_QUAL_VOLATILE
) != NULL_TREE
))
10564 mod_type_die
= new_die (DW_TAG_const_type
, mod_scope
, type
);
10565 sub_die
= modified_type_die (type
, 0, is_volatile_type
, context_die
);
10567 else if (is_volatile_type
)
10569 mod_type_die
= new_die (DW_TAG_volatile_type
, mod_scope
, type
);
10570 sub_die
= modified_type_die (type
, is_const_type
, 0, context_die
);
10572 else if (code
== POINTER_TYPE
)
10574 mod_type_die
= new_die (DW_TAG_pointer_type
, mod_scope
, type
);
10575 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10576 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10577 item_type
= TREE_TYPE (type
);
10578 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10579 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10580 TYPE_ADDR_SPACE (item_type
));
10582 else if (code
== REFERENCE_TYPE
)
10584 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
10585 mod_type_die
= new_die (DW_TAG_rvalue_reference_type
, mod_scope
,
10588 mod_type_die
= new_die (DW_TAG_reference_type
, mod_scope
, type
);
10589 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
,
10590 simple_type_size_in_bits (type
) / BITS_PER_UNIT
);
10591 item_type
= TREE_TYPE (type
);
10592 if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (item_type
)))
10593 add_AT_unsigned (mod_type_die
, DW_AT_address_class
,
10594 TYPE_ADDR_SPACE (item_type
));
10596 else if (code
== INTEGER_TYPE
10597 && TREE_TYPE (type
) != NULL_TREE
10598 && subrange_type_for_debug_p (type
, &low
, &high
))
10600 mod_type_die
= subrange_type_die (type
, low
, high
, context_die
);
10601 item_type
= TREE_TYPE (type
);
10603 else if (is_base_type (type
))
10604 mod_type_die
= base_type_die (type
);
10607 gen_type_die (type
, context_die
);
10609 /* We have to get the type_main_variant here (and pass that to the
10610 `lookup_type_die' routine) because the ..._TYPE node we have
10611 might simply be a *copy* of some original type node (where the
10612 copy was created to help us keep track of typedef names) and
10613 that copy might have a different TYPE_UID from the original
10615 if (TREE_CODE (type
) != VECTOR_TYPE
)
10616 return lookup_type_die (type_main_variant (type
));
10618 /* Vectors have the debugging information in the type,
10619 not the main variant. */
10620 return lookup_type_die (type
);
10623 /* Builtin types don't have a DECL_ORIGINAL_TYPE. For those,
10624 don't output a DW_TAG_typedef, since there isn't one in the
10625 user's program; just attach a DW_AT_name to the type.
10626 Don't attach a DW_AT_name to DW_TAG_const_type or DW_TAG_volatile_type
10627 if the base type already has the same name. */
10629 && ((TREE_CODE (name
) != TYPE_DECL
10630 && (qualified_type
== TYPE_MAIN_VARIANT (type
)
10631 || (!is_const_type
&& !is_volatile_type
)))
10632 || (TREE_CODE (name
) == TYPE_DECL
10633 && TREE_TYPE (name
) == qualified_type
10634 && DECL_NAME (name
))))
10636 if (TREE_CODE (name
) == TYPE_DECL
)
10637 /* Could just call add_name_and_src_coords_attributes here,
10638 but since this is a builtin type it doesn't have any
10639 useful source coordinates anyway. */
10640 name
= DECL_NAME (name
);
10641 add_name_attribute (mod_type_die
, IDENTIFIER_POINTER (name
));
10643 /* This probably indicates a bug. */
10644 else if (mod_type_die
&& mod_type_die
->die_tag
== DW_TAG_base_type
)
10646 name
= TYPE_NAME (type
);
10648 && TREE_CODE (name
) == TYPE_DECL
)
10649 name
= DECL_NAME (name
);
10650 add_name_attribute (mod_type_die
,
10651 name
? IDENTIFIER_POINTER (name
) : "__unknown__");
10654 if (qualified_type
)
10655 equate_type_number_to_die (qualified_type
, mod_type_die
);
10658 /* We must do this after the equate_type_number_to_die call, in case
10659 this is a recursive type. This ensures that the modified_type_die
10660 recursion will terminate even if the type is recursive. Recursive
10661 types are possible in Ada. */
10662 sub_die
= modified_type_die (item_type
,
10663 TYPE_READONLY (item_type
),
10664 TYPE_VOLATILE (item_type
),
10667 if (sub_die
!= NULL
)
10668 add_AT_die_ref (mod_type_die
, DW_AT_type
, sub_die
);
10670 add_gnat_descriptive_type_attribute (mod_type_die
, type
, context_die
);
10671 if (TYPE_ARTIFICIAL (type
))
10672 add_AT_flag (mod_type_die
, DW_AT_artificial
, 1);
10674 return mod_type_die
;
10677 /* Generate DIEs for the generic parameters of T.
10678 T must be either a generic type or a generic function.
10679 See http://gcc.gnu.org/wiki/TemplateParmsDwarf for more. */
10682 gen_generic_params_dies (tree t
)
10686 dw_die_ref die
= NULL
;
10689 if (!t
|| (TYPE_P (t
) && !COMPLETE_TYPE_P (t
)))
10693 die
= lookup_type_die (t
);
10694 else if (DECL_P (t
))
10695 die
= lookup_decl_die (t
);
10699 parms
= lang_hooks
.get_innermost_generic_parms (t
);
10701 /* T has no generic parameter. It means T is neither a generic type
10702 or function. End of story. */
10705 parms_num
= TREE_VEC_LENGTH (parms
);
10706 args
= lang_hooks
.get_innermost_generic_args (t
);
10707 if (TREE_CHAIN (args
) && TREE_CODE (TREE_CHAIN (args
)) == INTEGER_CST
)
10708 non_default
= int_cst_value (TREE_CHAIN (args
));
10710 non_default
= TREE_VEC_LENGTH (args
);
10711 for (i
= 0; i
< parms_num
; i
++)
10713 tree parm
, arg
, arg_pack_elems
;
10714 dw_die_ref parm_die
;
10716 parm
= TREE_VEC_ELT (parms
, i
);
10717 arg
= TREE_VEC_ELT (args
, i
);
10718 arg_pack_elems
= lang_hooks
.types
.get_argument_pack_elems (arg
);
10719 gcc_assert (parm
&& TREE_VALUE (parm
) && arg
);
10721 if (parm
&& TREE_VALUE (parm
) && arg
)
10723 /* If PARM represents a template parameter pack,
10724 emit a DW_TAG_GNU_template_parameter_pack DIE, followed
10725 by DW_TAG_template_*_parameter DIEs for the argument
10726 pack elements of ARG. Note that ARG would then be
10727 an argument pack. */
10728 if (arg_pack_elems
)
10729 parm_die
= template_parameter_pack_die (TREE_VALUE (parm
),
10733 parm_die
= generic_parameter_die (TREE_VALUE (parm
), arg
,
10734 true /* emit name */, die
);
10735 if (i
>= non_default
)
10736 add_AT_flag (parm_die
, DW_AT_default_value
, 1);
10741 /* Create and return a DIE for PARM which should be
10742 the representation of a generic type parameter.
10743 For instance, in the C++ front end, PARM would be a template parameter.
10744 ARG is the argument to PARM.
10745 EMIT_NAME_P if tree, the DIE will have DW_AT_name attribute set to the
10747 PARENT_DIE is the parent DIE which the new created DIE should be added to,
10748 as a child node. */
10751 generic_parameter_die (tree parm
, tree arg
,
10753 dw_die_ref parent_die
)
10755 dw_die_ref tmpl_die
= NULL
;
10756 const char *name
= NULL
;
10758 if (!parm
|| !DECL_NAME (parm
) || !arg
)
10761 /* We support non-type generic parameters and arguments,
10762 type generic parameters and arguments, as well as
10763 generic generic parameters (a.k.a. template template parameters in C++)
10765 if (TREE_CODE (parm
) == PARM_DECL
)
10766 /* PARM is a nontype generic parameter */
10767 tmpl_die
= new_die (DW_TAG_template_value_param
, parent_die
, parm
);
10768 else if (TREE_CODE (parm
) == TYPE_DECL
)
10769 /* PARM is a type generic parameter. */
10770 tmpl_die
= new_die (DW_TAG_template_type_param
, parent_die
, parm
);
10771 else if (lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10772 /* PARM is a generic generic parameter.
10773 Its DIE is a GNU extension. It shall have a
10774 DW_AT_name attribute to represent the name of the template template
10775 parameter, and a DW_AT_GNU_template_name attribute to represent the
10776 name of the template template argument. */
10777 tmpl_die
= new_die (DW_TAG_GNU_template_template_param
,
10780 gcc_unreachable ();
10786 /* If PARM is a generic parameter pack, it means we are
10787 emitting debug info for a template argument pack element.
10788 In other terms, ARG is a template argument pack element.
10789 In that case, we don't emit any DW_AT_name attribute for
10793 name
= IDENTIFIER_POINTER (DECL_NAME (parm
));
10795 add_AT_string (tmpl_die
, DW_AT_name
, name
);
10798 if (!lang_hooks
.decls
.generic_generic_parameter_decl_p (parm
))
10800 /* DWARF3, 5.6.8 says if PARM is a non-type generic parameter
10801 TMPL_DIE should have a child DW_AT_type attribute that is set
10802 to the type of the argument to PARM, which is ARG.
10803 If PARM is a type generic parameter, TMPL_DIE should have a
10804 child DW_AT_type that is set to ARG. */
10805 tmpl_type
= TYPE_P (arg
) ? arg
: TREE_TYPE (arg
);
10806 add_type_attribute (tmpl_die
, tmpl_type
, 0,
10807 TREE_THIS_VOLATILE (tmpl_type
),
10812 /* So TMPL_DIE is a DIE representing a
10813 a generic generic template parameter, a.k.a template template
10814 parameter in C++ and arg is a template. */
10816 /* The DW_AT_GNU_template_name attribute of the DIE must be set
10817 to the name of the argument. */
10818 name
= dwarf2_name (TYPE_P (arg
) ? TYPE_NAME (arg
) : arg
, 1);
10820 add_AT_string (tmpl_die
, DW_AT_GNU_template_name
, name
);
10823 if (TREE_CODE (parm
) == PARM_DECL
)
10824 /* So PARM is a non-type generic parameter.
10825 DWARF3 5.6.8 says we must set a DW_AT_const_value child
10826 attribute of TMPL_DIE which value represents the value
10828 We must be careful here:
10829 The value of ARG might reference some function decls.
10830 We might currently be emitting debug info for a generic
10831 type and types are emitted before function decls, we don't
10832 know if the function decls referenced by ARG will actually be
10833 emitted after cgraph computations.
10834 So must defer the generation of the DW_AT_const_value to
10835 after cgraph is ready. */
10836 append_entry_to_tmpl_value_parm_die_table (tmpl_die
, arg
);
10842 /* Generate and return a DW_TAG_GNU_template_parameter_pack DIE representing.
10843 PARM_PACK must be a template parameter pack. The returned DIE
10844 will be child DIE of PARENT_DIE. */
10847 template_parameter_pack_die (tree parm_pack
,
10848 tree parm_pack_args
,
10849 dw_die_ref parent_die
)
10854 gcc_assert (parent_die
&& parm_pack
);
10856 die
= new_die (DW_TAG_GNU_template_parameter_pack
, parent_die
, parm_pack
);
10857 add_name_and_src_coords_attributes (die
, parm_pack
);
10858 for (j
= 0; j
< TREE_VEC_LENGTH (parm_pack_args
); j
++)
10859 generic_parameter_die (parm_pack
,
10860 TREE_VEC_ELT (parm_pack_args
, j
),
10861 false /* Don't emit DW_AT_name */,
10866 /* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is
10867 an enumerated type. */
10870 type_is_enum (const_tree type
)
10872 return TREE_CODE (type
) == ENUMERAL_TYPE
;
10875 /* Return the DBX register number described by a given RTL node. */
10877 static unsigned int
10878 dbx_reg_number (const_rtx rtl
)
10880 unsigned regno
= REGNO (rtl
);
10882 gcc_assert (regno
< FIRST_PSEUDO_REGISTER
);
10884 #ifdef LEAF_REG_REMAP
10885 if (crtl
->uses_only_leaf_regs
)
10887 int leaf_reg
= LEAF_REG_REMAP (regno
);
10888 if (leaf_reg
!= -1)
10889 regno
= (unsigned) leaf_reg
;
10893 regno
= DBX_REGISTER_NUMBER (regno
);
10894 gcc_assert (regno
!= INVALID_REGNUM
);
10898 /* Optionally add a DW_OP_piece term to a location description expression.
10899 DW_OP_piece is only added if the location description expression already
10900 doesn't end with DW_OP_piece. */
10903 add_loc_descr_op_piece (dw_loc_descr_ref
*list_head
, int size
)
10905 dw_loc_descr_ref loc
;
10907 if (*list_head
!= NULL
)
10909 /* Find the end of the chain. */
10910 for (loc
= *list_head
; loc
->dw_loc_next
!= NULL
; loc
= loc
->dw_loc_next
)
10913 if (loc
->dw_loc_opc
!= DW_OP_piece
)
10914 loc
->dw_loc_next
= new_loc_descr (DW_OP_piece
, size
, 0);
10918 /* Return a location descriptor that designates a machine register or
10919 zero if there is none. */
10921 static dw_loc_descr_ref
10922 reg_loc_descriptor (rtx rtl
, enum var_init_status initialized
)
10926 if (REGNO (rtl
) >= FIRST_PSEUDO_REGISTER
)
10929 /* We only use "frame base" when we're sure we're talking about the
10930 post-prologue local stack frame. We do this by *not* running
10931 register elimination until this point, and recognizing the special
10932 argument pointer and soft frame pointer rtx's.
10933 Use DW_OP_fbreg offset DW_OP_stack_value in this case. */
10934 if ((rtl
== arg_pointer_rtx
|| rtl
== frame_pointer_rtx
)
10935 && eliminate_regs (rtl
, VOIDmode
, NULL_RTX
) != rtl
)
10937 dw_loc_descr_ref result
= NULL
;
10939 if (dwarf_version
>= 4 || !dwarf_strict
)
10941 result
= mem_loc_descriptor (rtl
, GET_MODE (rtl
), VOIDmode
,
10944 add_loc_descr (&result
,
10945 new_loc_descr (DW_OP_stack_value
, 0, 0));
10950 regs
= targetm
.dwarf_register_span (rtl
);
10952 if (hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)] > 1 || regs
)
10953 return multiple_reg_loc_descriptor (rtl
, regs
, initialized
);
10956 unsigned int dbx_regnum
= dbx_reg_number (rtl
);
10957 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
10959 return one_reg_loc_descriptor (dbx_regnum
, initialized
);
10963 /* Return a location descriptor that designates a machine register for
10964 a given hard register number. */
10966 static dw_loc_descr_ref
10967 one_reg_loc_descriptor (unsigned int regno
, enum var_init_status initialized
)
10969 dw_loc_descr_ref reg_loc_descr
;
10973 = new_loc_descr ((enum dwarf_location_atom
) (DW_OP_reg0
+ regno
), 0, 0);
10975 reg_loc_descr
= new_loc_descr (DW_OP_regx
, regno
, 0);
10977 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
10978 add_loc_descr (®_loc_descr
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
10980 return reg_loc_descr
;
10983 /* Given an RTL of a register, return a location descriptor that
10984 designates a value that spans more than one register. */
10986 static dw_loc_descr_ref
10987 multiple_reg_loc_descriptor (rtx rtl
, rtx regs
,
10988 enum var_init_status initialized
)
10991 dw_loc_descr_ref loc_result
= NULL
;
10993 /* Simple, contiguous registers. */
10994 if (regs
== NULL_RTX
)
10996 unsigned reg
= REGNO (rtl
);
10999 #ifdef LEAF_REG_REMAP
11000 if (crtl
->uses_only_leaf_regs
)
11002 int leaf_reg
= LEAF_REG_REMAP (reg
);
11003 if (leaf_reg
!= -1)
11004 reg
= (unsigned) leaf_reg
;
11008 gcc_assert ((unsigned) DBX_REGISTER_NUMBER (reg
) == dbx_reg_number (rtl
));
11009 nregs
= hard_regno_nregs
[REGNO (rtl
)][GET_MODE (rtl
)];
11011 size
= GET_MODE_SIZE (GET_MODE (rtl
)) / nregs
;
11016 dw_loc_descr_ref t
;
11018 t
= one_reg_loc_descriptor (DBX_REGISTER_NUMBER (reg
),
11019 VAR_INIT_STATUS_INITIALIZED
);
11020 add_loc_descr (&loc_result
, t
);
11021 add_loc_descr_op_piece (&loc_result
, size
);
11027 /* Now onto stupid register sets in non contiguous locations. */
11029 gcc_assert (GET_CODE (regs
) == PARALLEL
);
11031 size
= GET_MODE_SIZE (GET_MODE (XVECEXP (regs
, 0, 0)));
11034 for (i
= 0; i
< XVECLEN (regs
, 0); ++i
)
11036 dw_loc_descr_ref t
;
11038 t
= one_reg_loc_descriptor (dbx_reg_number (XVECEXP (regs
, 0, i
)),
11039 VAR_INIT_STATUS_INITIALIZED
);
11040 add_loc_descr (&loc_result
, t
);
11041 add_loc_descr_op_piece (&loc_result
, size
);
11044 if (loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11045 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11049 static unsigned long size_of_int_loc_descriptor (HOST_WIDE_INT
);
11051 /* Return a location descriptor that designates a constant i,
11052 as a compound operation from constant (i >> shift), constant shift
11055 static dw_loc_descr_ref
11056 int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11058 dw_loc_descr_ref ret
= int_loc_descriptor (i
>> shift
);
11059 add_loc_descr (&ret
, int_loc_descriptor (shift
));
11060 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
11064 /* Return a location descriptor that designates a constant. */
11066 static dw_loc_descr_ref
11067 int_loc_descriptor (HOST_WIDE_INT i
)
11069 enum dwarf_location_atom op
;
11071 /* Pick the smallest representation of a constant, rather than just
11072 defaulting to the LEB encoding. */
11075 int clz
= clz_hwi (i
);
11076 int ctz
= ctz_hwi (i
);
11078 op
= (enum dwarf_location_atom
) (DW_OP_lit0
+ i
);
11079 else if (i
<= 0xff)
11080 op
= DW_OP_const1u
;
11081 else if (i
<= 0xffff)
11082 op
= DW_OP_const2u
;
11083 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11084 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11085 /* DW_OP_litX DW_OP_litY DW_OP_shl takes just 3 bytes and
11086 DW_OP_litX DW_OP_const1u Y DW_OP_shl takes just 4 bytes,
11087 while DW_OP_const4u is 5 bytes. */
11088 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 5);
11089 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11090 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11091 /* DW_OP_const1u X DW_OP_litY DW_OP_shl takes just 4 bytes,
11092 while DW_OP_const4u is 5 bytes. */
11093 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11094 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11095 op
= DW_OP_const4u
;
11096 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11097 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11098 /* DW_OP_const1u X DW_OP_const1u Y DW_OP_shl takes just 5 bytes,
11099 while DW_OP_constu of constant >= 0x100000000 takes at least
11101 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 8);
11102 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11103 && clz
+ 16 + (size_of_uleb128 (i
) > 5 ? 255 : 31)
11104 >= HOST_BITS_PER_WIDE_INT
)
11105 /* DW_OP_const2u X DW_OP_litY DW_OP_shl takes just 5 bytes,
11106 DW_OP_const2u X DW_OP_const1u Y DW_OP_shl takes 6 bytes,
11107 while DW_OP_constu takes in this case at least 6 bytes. */
11108 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 16);
11109 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11110 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11111 && size_of_uleb128 (i
) > 6)
11112 /* DW_OP_const4u X DW_OP_litY DW_OP_shl takes just 7 bytes. */
11113 return int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
- clz
- 32);
11120 op
= DW_OP_const1s
;
11121 else if (i
>= -0x8000)
11122 op
= DW_OP_const2s
;
11123 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11125 if (size_of_int_loc_descriptor (i
) < 5)
11127 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11128 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11131 op
= DW_OP_const4s
;
11135 if (size_of_int_loc_descriptor (i
)
11136 < (unsigned long) 1 + size_of_sleb128 (i
))
11138 dw_loc_descr_ref ret
= int_loc_descriptor (-i
);
11139 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
11146 return new_loc_descr (op
, i
, 0);
11149 /* Return size_of_locs (int_shift_loc_descriptor (i, shift))
11150 without actually allocating it. */
11152 static unsigned long
11153 size_of_int_shift_loc_descriptor (HOST_WIDE_INT i
, int shift
)
11155 return size_of_int_loc_descriptor (i
>> shift
)
11156 + size_of_int_loc_descriptor (shift
)
11160 /* Return size_of_locs (int_loc_descriptor (i)) without
11161 actually allocating it. */
11163 static unsigned long
11164 size_of_int_loc_descriptor (HOST_WIDE_INT i
)
11173 else if (i
<= 0xff)
11175 else if (i
<= 0xffff)
11179 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 5
11180 && clz
+ 5 + 255 >= HOST_BITS_PER_WIDE_INT
)
11181 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11183 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11184 && clz
+ 8 + 31 >= HOST_BITS_PER_WIDE_INT
)
11185 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11187 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
<= 0xffffffff)
11189 s
= size_of_uleb128 ((unsigned HOST_WIDE_INT
) i
);
11190 if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 8
11191 && clz
+ 8 + 255 >= HOST_BITS_PER_WIDE_INT
)
11192 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11194 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 16
11195 && clz
+ 16 + (s
> 5 ? 255 : 31) >= HOST_BITS_PER_WIDE_INT
)
11196 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11198 else if (clz
+ ctz
>= HOST_BITS_PER_WIDE_INT
- 32
11199 && clz
+ 32 + 31 >= HOST_BITS_PER_WIDE_INT
11201 return size_of_int_shift_loc_descriptor (i
, HOST_BITS_PER_WIDE_INT
11210 else if (i
>= -0x8000)
11212 else if (HOST_BITS_PER_WIDE_INT
== 32 || i
>= -0x80000000)
11214 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11216 s
= size_of_int_loc_descriptor (-i
) + 1;
11224 unsigned long r
= 1 + size_of_sleb128 (i
);
11225 if (-(unsigned HOST_WIDE_INT
) i
!= (unsigned HOST_WIDE_INT
) i
)
11227 s
= size_of_int_loc_descriptor (-i
) + 1;
11236 /* Return loc description representing "address" of integer value.
11237 This can appear only as toplevel expression. */
11239 static dw_loc_descr_ref
11240 address_of_int_loc_descriptor (int size
, HOST_WIDE_INT i
)
11243 dw_loc_descr_ref loc_result
= NULL
;
11245 if (!(dwarf_version
>= 4 || !dwarf_strict
))
11248 litsize
= size_of_int_loc_descriptor (i
);
11249 /* Determine if DW_OP_stack_value or DW_OP_implicit_value
11250 is more compact. For DW_OP_stack_value we need:
11251 litsize + 1 (DW_OP_stack_value)
11252 and for DW_OP_implicit_value:
11253 1 (DW_OP_implicit_value) + 1 (length) + size. */
11254 if ((int) DWARF2_ADDR_SIZE
>= size
&& litsize
+ 1 <= 1 + 1 + size
)
11256 loc_result
= int_loc_descriptor (i
);
11257 add_loc_descr (&loc_result
,
11258 new_loc_descr (DW_OP_stack_value
, 0, 0));
11262 loc_result
= new_loc_descr (DW_OP_implicit_value
,
11264 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
11265 loc_result
->dw_loc_oprnd2
.v
.val_int
= i
;
11269 /* Return a location descriptor that designates a base+offset location. */
11271 static dw_loc_descr_ref
11272 based_loc_descr (rtx reg
, HOST_WIDE_INT offset
,
11273 enum var_init_status initialized
)
11275 unsigned int regno
;
11276 dw_loc_descr_ref result
;
11277 dw_fde_ref fde
= cfun
->fde
;
11279 /* We only use "frame base" when we're sure we're talking about the
11280 post-prologue local stack frame. We do this by *not* running
11281 register elimination until this point, and recognizing the special
11282 argument pointer and soft frame pointer rtx's. */
11283 if (reg
== arg_pointer_rtx
|| reg
== frame_pointer_rtx
)
11285 rtx elim
= (ira_use_lra_p
11286 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
11287 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
11291 if (GET_CODE (elim
) == PLUS
)
11293 offset
+= INTVAL (XEXP (elim
, 1));
11294 elim
= XEXP (elim
, 0);
11296 gcc_assert ((SUPPORTS_STACK_ALIGNMENT
11297 && (elim
== hard_frame_pointer_rtx
11298 || elim
== stack_pointer_rtx
))
11299 || elim
== (frame_pointer_needed
11300 ? hard_frame_pointer_rtx
11301 : stack_pointer_rtx
));
11303 /* If drap register is used to align stack, use frame
11304 pointer + offset to access stack variables. If stack
11305 is aligned without drap, use stack pointer + offset to
11306 access stack variables. */
11307 if (crtl
->stack_realign_tried
11308 && reg
== frame_pointer_rtx
)
11311 = DWARF_FRAME_REGNUM ((fde
&& fde
->drap_reg
!= INVALID_REGNUM
)
11312 ? HARD_FRAME_POINTER_REGNUM
11314 return new_reg_loc_descr (base_reg
, offset
);
11317 gcc_assert (frame_pointer_fb_offset_valid
);
11318 offset
+= frame_pointer_fb_offset
;
11319 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11323 regno
= REGNO (reg
);
11324 #ifdef LEAF_REG_REMAP
11325 if (crtl
->uses_only_leaf_regs
)
11327 int leaf_reg
= LEAF_REG_REMAP (regno
);
11328 if (leaf_reg
!= -1)
11329 regno
= (unsigned) leaf_reg
;
11332 regno
= DWARF_FRAME_REGNUM (regno
);
11334 if (!optimize
&& fde
11335 && (fde
->drap_reg
== regno
|| fde
->vdrap_reg
== regno
))
11337 /* Use cfa+offset to represent the location of arguments passed
11338 on the stack when drap is used to align stack.
11339 Only do this when not optimizing, for optimized code var-tracking
11340 is supposed to track where the arguments live and the register
11341 used as vdrap or drap in some spot might be used for something
11342 else in other part of the routine. */
11343 return new_loc_descr (DW_OP_fbreg
, offset
, 0);
11347 result
= new_loc_descr ((enum dwarf_location_atom
) (DW_OP_breg0
+ regno
),
11350 result
= new_loc_descr (DW_OP_bregx
, regno
, offset
);
11352 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
11353 add_loc_descr (&result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
11358 /* Return true if this RTL expression describes a base+offset calculation. */
11361 is_based_loc (const_rtx rtl
)
11363 return (GET_CODE (rtl
) == PLUS
11364 && ((REG_P (XEXP (rtl
, 0))
11365 && REGNO (XEXP (rtl
, 0)) < FIRST_PSEUDO_REGISTER
11366 && CONST_INT_P (XEXP (rtl
, 1)))));
11369 /* Try to handle TLS MEMs, for which mem_loc_descriptor on XEXP (mem, 0)
11372 static dw_loc_descr_ref
11373 tls_mem_loc_descriptor (rtx mem
)
11376 dw_loc_descr_ref loc_result
;
11378 if (MEM_EXPR (mem
) == NULL_TREE
|| !MEM_OFFSET_KNOWN_P (mem
))
11381 base
= get_base_address (MEM_EXPR (mem
));
11383 || TREE_CODE (base
) != VAR_DECL
11384 || !DECL_THREAD_LOCAL_P (base
))
11387 loc_result
= loc_descriptor_from_tree (MEM_EXPR (mem
), 1);
11388 if (loc_result
== NULL
)
11391 if (MEM_OFFSET (mem
))
11392 loc_descr_plus_const (&loc_result
, MEM_OFFSET (mem
));
11397 /* Output debug info about reason why we failed to expand expression as dwarf
11401 expansion_failed (tree expr
, rtx rtl
, char const *reason
)
11403 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
11405 fprintf (dump_file
, "Failed to expand as dwarf: ");
11407 print_generic_expr (dump_file
, expr
, dump_flags
);
11410 fprintf (dump_file
, "\n");
11411 print_rtl (dump_file
, rtl
);
11413 fprintf (dump_file
, "\nReason: %s\n", reason
);
11417 /* Helper function for const_ok_for_output, called either directly
11418 or via for_each_rtx. */
11421 const_ok_for_output_1 (rtx
*rtlp
, void *data ATTRIBUTE_UNUSED
)
11425 if (GET_CODE (rtl
) == UNSPEC
)
11427 /* If delegitimize_address couldn't do anything with the UNSPEC, assume
11428 we can't express it in the debug info. */
11429 #ifdef ENABLE_CHECKING
11430 /* Don't complain about TLS UNSPECs, those are just too hard to
11431 delegitimize. Note this could be a non-decl SYMBOL_REF such as
11432 one in a constant pool entry, so testing SYMBOL_REF_TLS_MODEL
11433 rather than DECL_THREAD_LOCAL_P is not just an optimization. */
11434 if (XVECLEN (rtl
, 0) == 0
11435 || GET_CODE (XVECEXP (rtl
, 0, 0)) != SYMBOL_REF
11436 || SYMBOL_REF_TLS_MODEL (XVECEXP (rtl
, 0, 0)) == TLS_MODEL_NONE
)
11437 inform (current_function_decl
11438 ? DECL_SOURCE_LOCATION (current_function_decl
)
11439 : UNKNOWN_LOCATION
,
11440 #if NUM_UNSPEC_VALUES > 0
11441 "non-delegitimized UNSPEC %s (%d) found in variable location",
11442 ((XINT (rtl
, 1) >= 0 && XINT (rtl
, 1) < NUM_UNSPEC_VALUES
)
11443 ? unspec_strings
[XINT (rtl
, 1)] : "unknown"),
11446 "non-delegitimized UNSPEC %d found in variable location",
11450 expansion_failed (NULL_TREE
, rtl
,
11451 "UNSPEC hasn't been delegitimized.\n");
11455 if (targetm
.const_not_ok_for_debug_p (rtl
))
11457 expansion_failed (NULL_TREE
, rtl
,
11458 "Expression rejected for debug by the backend.\n");
11462 if (GET_CODE (rtl
) != SYMBOL_REF
)
11465 if (CONSTANT_POOL_ADDRESS_P (rtl
))
11468 get_pool_constant_mark (rtl
, &marked
);
11469 /* If all references to this pool constant were optimized away,
11470 it was not output and thus we can't represent it. */
11473 expansion_failed (NULL_TREE
, rtl
,
11474 "Constant was removed from constant pool.\n");
11479 if (SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
11482 /* Avoid references to external symbols in debug info, on several targets
11483 the linker might even refuse to link when linking a shared library,
11484 and in many other cases the relocations for .debug_info/.debug_loc are
11485 dropped, so the address becomes zero anyway. Hidden symbols, guaranteed
11486 to be defined within the same shared library or executable are fine. */
11487 if (SYMBOL_REF_EXTERNAL_P (rtl
))
11489 tree decl
= SYMBOL_REF_DECL (rtl
);
11491 if (decl
== NULL
|| !targetm
.binds_local_p (decl
))
11493 expansion_failed (NULL_TREE
, rtl
,
11494 "Symbol not defined in current TU.\n");
11502 /* Return true if constant RTL can be emitted in DW_OP_addr or
11503 DW_AT_const_value. TLS SYMBOL_REFs, external SYMBOL_REFs or
11504 non-marked constant pool SYMBOL_REFs can't be referenced in it. */
11507 const_ok_for_output (rtx rtl
)
11509 if (GET_CODE (rtl
) == SYMBOL_REF
)
11510 return const_ok_for_output_1 (&rtl
, NULL
) == 0;
11512 if (GET_CODE (rtl
) == CONST
)
11513 return for_each_rtx (&XEXP (rtl
, 0), const_ok_for_output_1
, NULL
) == 0;
11518 /* Return a reference to DW_TAG_base_type corresponding to MODE and UNSIGNEDP
11519 if possible, NULL otherwise. */
11522 base_type_for_mode (enum machine_mode mode
, bool unsignedp
)
11524 dw_die_ref type_die
;
11525 tree type
= lang_hooks
.types
.type_for_mode (mode
, unsignedp
);
11529 switch (TREE_CODE (type
))
11537 type_die
= lookup_type_die (type
);
11539 type_die
= modified_type_die (type
, false, false, comp_unit_die ());
11540 if (type_die
== NULL
|| type_die
->die_tag
!= DW_TAG_base_type
)
11545 /* For OP descriptor assumed to be in unsigned MODE, convert it to a unsigned
11546 type matching MODE, or, if MODE is narrower than or as wide as
11547 DWARF2_ADDR_SIZE, untyped. Return NULL if the conversion is not
11550 static dw_loc_descr_ref
11551 convert_descriptor_to_mode (enum machine_mode mode
, dw_loc_descr_ref op
)
11553 enum machine_mode outer_mode
= mode
;
11554 dw_die_ref type_die
;
11555 dw_loc_descr_ref cvt
;
11557 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
11559 add_loc_descr (&op
, new_loc_descr (DW_OP_GNU_convert
, 0, 0));
11562 type_die
= base_type_for_mode (outer_mode
, 1);
11563 if (type_die
== NULL
)
11565 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11566 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11567 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11568 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11569 add_loc_descr (&op
, cvt
);
11573 /* Return location descriptor for comparison OP with operands OP0 and OP1. */
11575 static dw_loc_descr_ref
11576 compare_loc_descriptor (enum dwarf_location_atom op
, dw_loc_descr_ref op0
,
11577 dw_loc_descr_ref op1
)
11579 dw_loc_descr_ref ret
= op0
;
11580 add_loc_descr (&ret
, op1
);
11581 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11582 if (STORE_FLAG_VALUE
!= 1)
11584 add_loc_descr (&ret
, int_loc_descriptor (STORE_FLAG_VALUE
));
11585 add_loc_descr (&ret
, new_loc_descr (DW_OP_mul
, 0, 0));
11590 /* Return location descriptor for signed comparison OP RTL. */
11592 static dw_loc_descr_ref
11593 scompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11594 enum machine_mode mem_mode
)
11596 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11597 dw_loc_descr_ref op0
, op1
;
11600 if (op_mode
== VOIDmode
)
11601 op_mode
= GET_MODE (XEXP (rtl
, 1));
11602 if (op_mode
== VOIDmode
)
11606 && (GET_MODE_CLASS (op_mode
) != MODE_INT
11607 || GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
))
11610 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11611 VAR_INIT_STATUS_INITIALIZED
);
11612 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11613 VAR_INIT_STATUS_INITIALIZED
);
11615 if (op0
== NULL
|| op1
== NULL
)
11618 if (GET_MODE_CLASS (op_mode
) != MODE_INT
11619 || GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11620 return compare_loc_descriptor (op
, op0
, op1
);
11622 if (GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11624 dw_die_ref type_die
= base_type_for_mode (op_mode
, 0);
11625 dw_loc_descr_ref cvt
;
11627 if (type_die
== NULL
)
11629 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11630 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11631 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11632 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11633 add_loc_descr (&op0
, cvt
);
11634 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11635 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11636 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11637 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11638 add_loc_descr (&op1
, cvt
);
11639 return compare_loc_descriptor (op
, op0
, op1
);
11642 shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (op_mode
)) * BITS_PER_UNIT
;
11643 /* For eq/ne, if the operands are known to be zero-extended,
11644 there is no need to do the fancy shifting up. */
11645 if (op
== DW_OP_eq
|| op
== DW_OP_ne
)
11647 dw_loc_descr_ref last0
, last1
;
11648 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11650 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11652 /* deref_size zero extends, and for constants we can check
11653 whether they are zero extended or not. */
11654 if (((last0
->dw_loc_opc
== DW_OP_deref_size
11655 && last0
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11656 || (CONST_INT_P (XEXP (rtl
, 0))
11657 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 0))
11658 == (INTVAL (XEXP (rtl
, 0)) & GET_MODE_MASK (op_mode
))))
11659 && ((last1
->dw_loc_opc
== DW_OP_deref_size
11660 && last1
->dw_loc_oprnd1
.v
.val_int
<= GET_MODE_SIZE (op_mode
))
11661 || (CONST_INT_P (XEXP (rtl
, 1))
11662 && (unsigned HOST_WIDE_INT
) INTVAL (XEXP (rtl
, 1))
11663 == (INTVAL (XEXP (rtl
, 1)) & GET_MODE_MASK (op_mode
)))))
11664 return compare_loc_descriptor (op
, op0
, op1
);
11666 /* EQ/NE comparison against constant in narrower type than
11667 DWARF2_ADDR_SIZE can be performed either as
11668 DW_OP_const1u <shift> DW_OP_shl DW_OP_const* <cst << shift>
11671 DW_OP_const*u <mode_mask> DW_OP_and DW_OP_const* <cst & mode_mask>
11672 DW_OP_{eq,ne}. Pick whatever is shorter. */
11673 if (CONST_INT_P (XEXP (rtl
, 1))
11674 && GET_MODE_BITSIZE (op_mode
) < HOST_BITS_PER_WIDE_INT
11675 && (size_of_int_loc_descriptor (shift
) + 1
11676 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
)
11677 >= size_of_int_loc_descriptor (GET_MODE_MASK (op_mode
)) + 1
11678 + size_of_int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11679 & GET_MODE_MASK (op_mode
))))
11681 add_loc_descr (&op0
, int_loc_descriptor (GET_MODE_MASK (op_mode
)));
11682 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11683 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1))
11684 & GET_MODE_MASK (op_mode
));
11685 return compare_loc_descriptor (op
, op0
, op1
);
11688 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11689 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11690 if (CONST_INT_P (XEXP (rtl
, 1)))
11691 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) << shift
);
11694 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11695 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11697 return compare_loc_descriptor (op
, op0
, op1
);
11700 /* Return location descriptor for unsigned comparison OP RTL. */
11702 static dw_loc_descr_ref
11703 ucompare_loc_descriptor (enum dwarf_location_atom op
, rtx rtl
,
11704 enum machine_mode mem_mode
)
11706 enum machine_mode op_mode
= GET_MODE (XEXP (rtl
, 0));
11707 dw_loc_descr_ref op0
, op1
;
11709 if (op_mode
== VOIDmode
)
11710 op_mode
= GET_MODE (XEXP (rtl
, 1));
11711 if (op_mode
== VOIDmode
)
11713 if (GET_MODE_CLASS (op_mode
) != MODE_INT
)
11716 if (dwarf_strict
&& GET_MODE_SIZE (op_mode
) > DWARF2_ADDR_SIZE
)
11719 op0
= mem_loc_descriptor (XEXP (rtl
, 0), op_mode
, mem_mode
,
11720 VAR_INIT_STATUS_INITIALIZED
);
11721 op1
= mem_loc_descriptor (XEXP (rtl
, 1), op_mode
, mem_mode
,
11722 VAR_INIT_STATUS_INITIALIZED
);
11724 if (op0
== NULL
|| op1
== NULL
)
11727 if (GET_MODE_SIZE (op_mode
) < DWARF2_ADDR_SIZE
)
11729 HOST_WIDE_INT mask
= GET_MODE_MASK (op_mode
);
11730 dw_loc_descr_ref last0
, last1
;
11731 for (last0
= op0
; last0
->dw_loc_next
!= NULL
; last0
= last0
->dw_loc_next
)
11733 for (last1
= op1
; last1
->dw_loc_next
!= NULL
; last1
= last1
->dw_loc_next
)
11735 if (CONST_INT_P (XEXP (rtl
, 0)))
11736 op0
= int_loc_descriptor (INTVAL (XEXP (rtl
, 0)) & mask
);
11737 /* deref_size zero extends, so no need to mask it again. */
11738 else if (last0
->dw_loc_opc
!= DW_OP_deref_size
11739 || last0
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11741 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11742 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11744 if (CONST_INT_P (XEXP (rtl
, 1)))
11745 op1
= int_loc_descriptor (INTVAL (XEXP (rtl
, 1)) & mask
);
11746 /* deref_size zero extends, so no need to mask it again. */
11747 else if (last1
->dw_loc_opc
!= DW_OP_deref_size
11748 || last1
->dw_loc_oprnd1
.v
.val_int
> GET_MODE_SIZE (op_mode
))
11750 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11751 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11754 else if (GET_MODE_SIZE (op_mode
) == DWARF2_ADDR_SIZE
)
11756 HOST_WIDE_INT bias
= 1;
11757 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11758 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11759 if (CONST_INT_P (XEXP (rtl
, 1)))
11760 op1
= int_loc_descriptor ((unsigned HOST_WIDE_INT
) bias
11761 + INTVAL (XEXP (rtl
, 1)));
11763 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
,
11766 return compare_loc_descriptor (op
, op0
, op1
);
11769 /* Return location descriptor for {U,S}{MIN,MAX}. */
11771 static dw_loc_descr_ref
11772 minmax_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11773 enum machine_mode mem_mode
)
11775 enum dwarf_location_atom op
;
11776 dw_loc_descr_ref op0
, op1
, ret
;
11777 dw_loc_descr_ref bra_node
, drop_node
;
11780 && (GET_MODE_CLASS (mode
) != MODE_INT
11781 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
))
11784 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11785 VAR_INIT_STATUS_INITIALIZED
);
11786 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11787 VAR_INIT_STATUS_INITIALIZED
);
11789 if (op0
== NULL
|| op1
== NULL
)
11792 add_loc_descr (&op0
, new_loc_descr (DW_OP_dup
, 0, 0));
11793 add_loc_descr (&op1
, new_loc_descr (DW_OP_swap
, 0, 0));
11794 add_loc_descr (&op1
, new_loc_descr (DW_OP_over
, 0, 0));
11795 if (GET_CODE (rtl
) == UMIN
|| GET_CODE (rtl
) == UMAX
)
11797 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11799 HOST_WIDE_INT mask
= GET_MODE_MASK (mode
);
11800 add_loc_descr (&op0
, int_loc_descriptor (mask
));
11801 add_loc_descr (&op0
, new_loc_descr (DW_OP_and
, 0, 0));
11802 add_loc_descr (&op1
, int_loc_descriptor (mask
));
11803 add_loc_descr (&op1
, new_loc_descr (DW_OP_and
, 0, 0));
11805 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
11807 HOST_WIDE_INT bias
= 1;
11808 bias
<<= (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
- 1);
11809 add_loc_descr (&op0
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11810 add_loc_descr (&op1
, new_loc_descr (DW_OP_plus_uconst
, bias
, 0));
11813 else if (GET_MODE_CLASS (mode
) == MODE_INT
11814 && GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
11816 int shift
= (DWARF2_ADDR_SIZE
- GET_MODE_SIZE (mode
)) * BITS_PER_UNIT
;
11817 add_loc_descr (&op0
, int_loc_descriptor (shift
));
11818 add_loc_descr (&op0
, new_loc_descr (DW_OP_shl
, 0, 0));
11819 add_loc_descr (&op1
, int_loc_descriptor (shift
));
11820 add_loc_descr (&op1
, new_loc_descr (DW_OP_shl
, 0, 0));
11822 else if (GET_MODE_CLASS (mode
) == MODE_INT
11823 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11825 dw_die_ref type_die
= base_type_for_mode (mode
, 0);
11826 dw_loc_descr_ref cvt
;
11827 if (type_die
== NULL
)
11829 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11830 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11831 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11832 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11833 add_loc_descr (&op0
, cvt
);
11834 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11835 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11836 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11837 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11838 add_loc_descr (&op1
, cvt
);
11841 if (GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == UMIN
)
11846 add_loc_descr (&ret
, op1
);
11847 add_loc_descr (&ret
, new_loc_descr (op
, 0, 0));
11848 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
11849 add_loc_descr (&ret
, bra_node
);
11850 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11851 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
11852 add_loc_descr (&ret
, drop_node
);
11853 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
11854 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
11855 if ((GET_CODE (rtl
) == SMIN
|| GET_CODE (rtl
) == SMAX
)
11856 && GET_MODE_CLASS (mode
) == MODE_INT
11857 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
11858 ret
= convert_descriptor_to_mode (mode
, ret
);
11862 /* Helper function for mem_loc_descriptor. Perform OP binary op,
11863 but after converting arguments to type_die, afterwards
11864 convert back to unsigned. */
11866 static dw_loc_descr_ref
11867 typed_binop (enum dwarf_location_atom op
, rtx rtl
, dw_die_ref type_die
,
11868 enum machine_mode mode
, enum machine_mode mem_mode
)
11870 dw_loc_descr_ref cvt
, op0
, op1
;
11872 if (type_die
== NULL
)
11874 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11875 VAR_INIT_STATUS_INITIALIZED
);
11876 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
11877 VAR_INIT_STATUS_INITIALIZED
);
11878 if (op0
== NULL
|| op1
== NULL
)
11880 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11881 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11882 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11883 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11884 add_loc_descr (&op0
, cvt
);
11885 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
11886 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
11887 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
11888 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
11889 add_loc_descr (&op1
, cvt
);
11890 add_loc_descr (&op0
, op1
);
11891 add_loc_descr (&op0
, new_loc_descr (op
, 0, 0));
11892 return convert_descriptor_to_mode (mode
, op0
);
11895 /* CLZ (where constV is CLZ_DEFINED_VALUE_AT_ZERO computed value,
11896 const0 is DW_OP_lit0 or corresponding typed constant,
11897 const1 is DW_OP_lit1 or corresponding typed constant
11898 and constMSB is constant with just the MSB bit set
11900 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11901 L1: const0 DW_OP_swap
11902 L2: DW_OP_dup constMSB DW_OP_and DW_OP_bra <L3> const1 DW_OP_shl
11903 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11908 DW_OP_dup DW_OP_bra <L1> DW_OP_drop constV DW_OP_skip <L4>
11909 L1: const0 DW_OP_swap
11910 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11911 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11916 DW_OP_dup DW_OP_bra <L1> DW_OP_drop const0 DW_OP_skip <L4>
11917 L1: const1 DW_OP_swap
11918 L2: DW_OP_dup const1 DW_OP_and DW_OP_bra <L3> const1 DW_OP_shr
11919 DW_OP_swap DW_OP_plus_uconst <1> DW_OP_swap DW_OP_skip <L2>
11923 static dw_loc_descr_ref
11924 clz_loc_descriptor (rtx rtl
, enum machine_mode mode
,
11925 enum machine_mode mem_mode
)
11927 dw_loc_descr_ref op0
, ret
, tmp
;
11928 HOST_WIDE_INT valv
;
11929 dw_loc_descr_ref l1jump
, l1label
;
11930 dw_loc_descr_ref l2jump
, l2label
;
11931 dw_loc_descr_ref l3jump
, l3label
;
11932 dw_loc_descr_ref l4jump
, l4label
;
11935 if (GET_MODE_CLASS (mode
) != MODE_INT
11936 || GET_MODE (XEXP (rtl
, 0)) != mode
)
11939 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
11940 VAR_INIT_STATUS_INITIALIZED
);
11944 if (GET_CODE (rtl
) == CLZ
)
11946 if (!CLZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11947 valv
= GET_MODE_BITSIZE (mode
);
11949 else if (GET_CODE (rtl
) == FFS
)
11951 else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode
, valv
))
11952 valv
= GET_MODE_BITSIZE (mode
);
11953 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
11954 l1jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11955 add_loc_descr (&ret
, l1jump
);
11956 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
11957 tmp
= mem_loc_descriptor (GEN_INT (valv
), mode
, mem_mode
,
11958 VAR_INIT_STATUS_INITIALIZED
);
11961 add_loc_descr (&ret
, tmp
);
11962 l4jump
= new_loc_descr (DW_OP_skip
, 0, 0);
11963 add_loc_descr (&ret
, l4jump
);
11964 l1label
= mem_loc_descriptor (GET_CODE (rtl
) == FFS
11965 ? const1_rtx
: const0_rtx
,
11967 VAR_INIT_STATUS_INITIALIZED
);
11968 if (l1label
== NULL
)
11970 add_loc_descr (&ret
, l1label
);
11971 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
11972 l2label
= new_loc_descr (DW_OP_dup
, 0, 0);
11973 add_loc_descr (&ret
, l2label
);
11974 if (GET_CODE (rtl
) != CLZ
)
11976 else if (GET_MODE_BITSIZE (mode
) <= HOST_BITS_PER_WIDE_INT
)
11977 msb
= GEN_INT ((unsigned HOST_WIDE_INT
) 1
11978 << (GET_MODE_BITSIZE (mode
) - 1));
11980 msb
= immed_wide_int_const
11981 (wi::set_bit_in_zero (GET_MODE_PRECISION (mode
) - 1,
11982 GET_MODE_PRECISION (mode
)), mode
);
11983 if (GET_CODE (msb
) == CONST_INT
&& INTVAL (msb
) < 0)
11984 tmp
= new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
11985 ? DW_OP_const4u
: HOST_BITS_PER_WIDE_INT
== 64
11986 ? DW_OP_const8u
: DW_OP_constu
, INTVAL (msb
), 0);
11988 tmp
= mem_loc_descriptor (msb
, mode
, mem_mode
,
11989 VAR_INIT_STATUS_INITIALIZED
);
11992 add_loc_descr (&ret
, tmp
);
11993 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
11994 l3jump
= new_loc_descr (DW_OP_bra
, 0, 0);
11995 add_loc_descr (&ret
, l3jump
);
11996 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
11997 VAR_INIT_STATUS_INITIALIZED
);
12000 add_loc_descr (&ret
, tmp
);
12001 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == CLZ
12002 ? DW_OP_shl
: DW_OP_shr
, 0, 0));
12003 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12004 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
, 1, 0));
12005 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12006 l2jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12007 add_loc_descr (&ret
, l2jump
);
12008 l3label
= new_loc_descr (DW_OP_drop
, 0, 0);
12009 add_loc_descr (&ret
, l3label
);
12010 l4label
= new_loc_descr (DW_OP_nop
, 0, 0);
12011 add_loc_descr (&ret
, l4label
);
12012 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12013 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12014 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12015 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12016 l3jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12017 l3jump
->dw_loc_oprnd1
.v
.val_loc
= l3label
;
12018 l4jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12019 l4jump
->dw_loc_oprnd1
.v
.val_loc
= l4label
;
12023 /* POPCOUNT (const0 is DW_OP_lit0 or corresponding typed constant,
12024 const1 is DW_OP_lit1 or corresponding typed constant):
12026 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12027 DW_OP_plus DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12031 L1: DW_OP_dup DW_OP_bra <L2> DW_OP_dup DW_OP_rot const1 DW_OP_and
12032 DW_OP_xor DW_OP_swap const1 DW_OP_shr DW_OP_skip <L1>
12035 static dw_loc_descr_ref
12036 popcount_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12037 enum machine_mode mem_mode
)
12039 dw_loc_descr_ref op0
, ret
, tmp
;
12040 dw_loc_descr_ref l1jump
, l1label
;
12041 dw_loc_descr_ref l2jump
, l2label
;
12043 if (GET_MODE_CLASS (mode
) != MODE_INT
12044 || GET_MODE (XEXP (rtl
, 0)) != mode
)
12047 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12048 VAR_INIT_STATUS_INITIALIZED
);
12052 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12053 VAR_INIT_STATUS_INITIALIZED
);
12056 add_loc_descr (&ret
, tmp
);
12057 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12058 l1label
= new_loc_descr (DW_OP_dup
, 0, 0);
12059 add_loc_descr (&ret
, l1label
);
12060 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12061 add_loc_descr (&ret
, l2jump
);
12062 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12063 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12064 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12065 VAR_INIT_STATUS_INITIALIZED
);
12068 add_loc_descr (&ret
, tmp
);
12069 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12070 add_loc_descr (&ret
, new_loc_descr (GET_CODE (rtl
) == POPCOUNT
12071 ? DW_OP_plus
: DW_OP_xor
, 0, 0));
12072 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12073 tmp
= mem_loc_descriptor (const1_rtx
, mode
, mem_mode
,
12074 VAR_INIT_STATUS_INITIALIZED
);
12075 add_loc_descr (&ret
, tmp
);
12076 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12077 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12078 add_loc_descr (&ret
, l1jump
);
12079 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12080 add_loc_descr (&ret
, l2label
);
12081 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12082 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12083 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12084 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12088 /* BSWAP (constS is initial shift count, either 56 or 24):
12090 L1: DW_OP_pick <2> constS DW_OP_pick <3> DW_OP_minus DW_OP_shr
12091 const255 DW_OP_and DW_OP_pick <2> DW_OP_shl DW_OP_or
12092 DW_OP_swap DW_OP_dup const0 DW_OP_eq DW_OP_bra <L2> const8
12093 DW_OP_minus DW_OP_swap DW_OP_skip <L1>
12094 L2: DW_OP_drop DW_OP_swap DW_OP_drop */
12096 static dw_loc_descr_ref
12097 bswap_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12098 enum machine_mode mem_mode
)
12100 dw_loc_descr_ref op0
, ret
, tmp
;
12101 dw_loc_descr_ref l1jump
, l1label
;
12102 dw_loc_descr_ref l2jump
, l2label
;
12104 if (GET_MODE_CLASS (mode
) != MODE_INT
12105 || BITS_PER_UNIT
!= 8
12106 || (GET_MODE_BITSIZE (mode
) != 32
12107 && GET_MODE_BITSIZE (mode
) != 64))
12110 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12111 VAR_INIT_STATUS_INITIALIZED
);
12116 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12118 VAR_INIT_STATUS_INITIALIZED
);
12121 add_loc_descr (&ret
, tmp
);
12122 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12123 VAR_INIT_STATUS_INITIALIZED
);
12126 add_loc_descr (&ret
, tmp
);
12127 l1label
= new_loc_descr (DW_OP_pick
, 2, 0);
12128 add_loc_descr (&ret
, l1label
);
12129 tmp
= mem_loc_descriptor (GEN_INT (GET_MODE_BITSIZE (mode
) - 8),
12131 VAR_INIT_STATUS_INITIALIZED
);
12132 add_loc_descr (&ret
, tmp
);
12133 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 3, 0));
12134 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12135 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12136 tmp
= mem_loc_descriptor (GEN_INT (255), mode
, mem_mode
,
12137 VAR_INIT_STATUS_INITIALIZED
);
12140 add_loc_descr (&ret
, tmp
);
12141 add_loc_descr (&ret
, new_loc_descr (DW_OP_and
, 0, 0));
12142 add_loc_descr (&ret
, new_loc_descr (DW_OP_pick
, 2, 0));
12143 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12144 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12145 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12146 add_loc_descr (&ret
, new_loc_descr (DW_OP_dup
, 0, 0));
12147 tmp
= mem_loc_descriptor (const0_rtx
, mode
, mem_mode
,
12148 VAR_INIT_STATUS_INITIALIZED
);
12149 add_loc_descr (&ret
, tmp
);
12150 add_loc_descr (&ret
, new_loc_descr (DW_OP_eq
, 0, 0));
12151 l2jump
= new_loc_descr (DW_OP_bra
, 0, 0);
12152 add_loc_descr (&ret
, l2jump
);
12153 tmp
= mem_loc_descriptor (GEN_INT (8), mode
, mem_mode
,
12154 VAR_INIT_STATUS_INITIALIZED
);
12155 add_loc_descr (&ret
, tmp
);
12156 add_loc_descr (&ret
, new_loc_descr (DW_OP_minus
, 0, 0));
12157 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12158 l1jump
= new_loc_descr (DW_OP_skip
, 0, 0);
12159 add_loc_descr (&ret
, l1jump
);
12160 l2label
= new_loc_descr (DW_OP_drop
, 0, 0);
12161 add_loc_descr (&ret
, l2label
);
12162 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12163 add_loc_descr (&ret
, new_loc_descr (DW_OP_drop
, 0, 0));
12164 l1jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12165 l1jump
->dw_loc_oprnd1
.v
.val_loc
= l1label
;
12166 l2jump
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12167 l2jump
->dw_loc_oprnd1
.v
.val_loc
= l2label
;
12171 /* ROTATE (constMASK is mode mask, BITSIZE is bitsize of mode):
12172 DW_OP_over DW_OP_over DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12173 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_neg
12174 DW_OP_plus_uconst <BITSIZE> DW_OP_shr DW_OP_or
12176 ROTATERT is similar:
12177 DW_OP_over DW_OP_over DW_OP_neg DW_OP_plus_uconst <BITSIZE>
12178 DW_OP_shl [ constMASK DW_OP_and ] DW_OP_rot
12179 [ DW_OP_swap constMASK DW_OP_and DW_OP_swap ] DW_OP_shr DW_OP_or */
12181 static dw_loc_descr_ref
12182 rotate_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12183 enum machine_mode mem_mode
)
12185 rtx rtlop1
= XEXP (rtl
, 1);
12186 dw_loc_descr_ref op0
, op1
, ret
, mask
[2] = { NULL
, NULL
};
12189 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12192 if (GET_MODE (rtlop1
) != VOIDmode
12193 && GET_MODE_BITSIZE (GET_MODE (rtlop1
)) < GET_MODE_BITSIZE (mode
))
12194 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12195 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12196 VAR_INIT_STATUS_INITIALIZED
);
12197 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12198 VAR_INIT_STATUS_INITIALIZED
);
12199 if (op0
== NULL
|| op1
== NULL
)
12201 if (GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
)
12202 for (i
= 0; i
< 2; i
++)
12204 if (GET_MODE_BITSIZE (mode
) < HOST_BITS_PER_WIDE_INT
)
12205 mask
[i
] = mem_loc_descriptor (GEN_INT (GET_MODE_MASK (mode
)),
12207 VAR_INIT_STATUS_INITIALIZED
);
12208 else if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12209 mask
[i
] = new_loc_descr (HOST_BITS_PER_WIDE_INT
== 32
12211 : HOST_BITS_PER_WIDE_INT
== 64
12212 ? DW_OP_const8u
: DW_OP_constu
,
12213 GET_MODE_MASK (mode
), 0);
12216 if (mask
[i
] == NULL
)
12218 add_loc_descr (&mask
[i
], new_loc_descr (DW_OP_and
, 0, 0));
12221 add_loc_descr (&ret
, op1
);
12222 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12223 add_loc_descr (&ret
, new_loc_descr (DW_OP_over
, 0, 0));
12224 if (GET_CODE (rtl
) == ROTATERT
)
12226 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12227 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12228 GET_MODE_BITSIZE (mode
), 0));
12230 add_loc_descr (&ret
, new_loc_descr (DW_OP_shl
, 0, 0));
12231 if (mask
[0] != NULL
)
12232 add_loc_descr (&ret
, mask
[0]);
12233 add_loc_descr (&ret
, new_loc_descr (DW_OP_rot
, 0, 0));
12234 if (mask
[1] != NULL
)
12236 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12237 add_loc_descr (&ret
, mask
[1]);
12238 add_loc_descr (&ret
, new_loc_descr (DW_OP_swap
, 0, 0));
12240 if (GET_CODE (rtl
) == ROTATE
)
12242 add_loc_descr (&ret
, new_loc_descr (DW_OP_neg
, 0, 0));
12243 add_loc_descr (&ret
, new_loc_descr (DW_OP_plus_uconst
,
12244 GET_MODE_BITSIZE (mode
), 0));
12246 add_loc_descr (&ret
, new_loc_descr (DW_OP_shr
, 0, 0));
12247 add_loc_descr (&ret
, new_loc_descr (DW_OP_or
, 0, 0));
12251 /* Helper function for mem_loc_descriptor. Return DW_OP_GNU_parameter_ref
12252 for DEBUG_PARAMETER_REF RTL. */
12254 static dw_loc_descr_ref
12255 parameter_ref_descriptor (rtx rtl
)
12257 dw_loc_descr_ref ret
;
12262 gcc_assert (TREE_CODE (DEBUG_PARAMETER_REF_DECL (rtl
)) == PARM_DECL
);
12263 ref
= lookup_decl_die (DEBUG_PARAMETER_REF_DECL (rtl
));
12264 ret
= new_loc_descr (DW_OP_GNU_parameter_ref
, 0, 0);
12267 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12268 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
12269 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12273 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
12274 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_PARAMETER_REF_DECL (rtl
);
12279 /* The following routine converts the RTL for a variable or parameter
12280 (resident in memory) into an equivalent Dwarf representation of a
12281 mechanism for getting the address of that same variable onto the top of a
12282 hypothetical "address evaluation" stack.
12284 When creating memory location descriptors, we are effectively transforming
12285 the RTL for a memory-resident object into its Dwarf postfix expression
12286 equivalent. This routine recursively descends an RTL tree, turning
12287 it into Dwarf postfix code as it goes.
12289 MODE is the mode that should be assumed for the rtl if it is VOIDmode.
12291 MEM_MODE is the mode of the memory reference, needed to handle some
12292 autoincrement addressing modes.
12294 Return 0 if we can't represent the location. */
12297 mem_loc_descriptor (rtx rtl
, enum machine_mode mode
,
12298 enum machine_mode mem_mode
,
12299 enum var_init_status initialized
)
12301 dw_loc_descr_ref mem_loc_result
= NULL
;
12302 enum dwarf_location_atom op
;
12303 dw_loc_descr_ref op0
, op1
;
12304 rtx inner
= NULL_RTX
;
12306 if (mode
== VOIDmode
)
12307 mode
= GET_MODE (rtl
);
12309 /* Note that for a dynamically sized array, the location we will generate a
12310 description of here will be the lowest numbered location which is
12311 actually within the array. That's *not* necessarily the same as the
12312 zeroth element of the array. */
12314 rtl
= targetm
.delegitimize_address (rtl
);
12316 if (mode
!= GET_MODE (rtl
) && GET_MODE (rtl
) != VOIDmode
)
12319 switch (GET_CODE (rtl
))
12324 return mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
, initialized
);
12327 /* The case of a subreg may arise when we have a local (register)
12328 variable or a formal (register) parameter which doesn't quite fill
12329 up an entire register. For now, just assume that it is
12330 legitimate to make the Dwarf info refer to the whole register which
12331 contains the given subreg. */
12332 if (!subreg_lowpart_p (rtl
))
12334 inner
= SUBREG_REG (rtl
);
12336 if (inner
== NULL_RTX
)
12337 inner
= XEXP (rtl
, 0);
12338 if (GET_MODE_CLASS (mode
) == MODE_INT
12339 && GET_MODE_CLASS (GET_MODE (inner
)) == MODE_INT
12340 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12341 #ifdef POINTERS_EXTEND_UNSIGNED
12342 || (mode
== Pmode
&& mem_mode
!= VOIDmode
)
12345 && GET_MODE_SIZE (GET_MODE (inner
)) <= DWARF2_ADDR_SIZE
)
12347 mem_loc_result
= mem_loc_descriptor (inner
,
12349 mem_mode
, initialized
);
12354 if (GET_MODE_SIZE (mode
) > GET_MODE_SIZE (GET_MODE (inner
)))
12356 if (GET_MODE_SIZE (mode
) != GET_MODE_SIZE (GET_MODE (inner
))
12357 && (GET_MODE_CLASS (mode
) != MODE_INT
12358 || GET_MODE_CLASS (GET_MODE (inner
)) != MODE_INT
))
12362 dw_die_ref type_die
;
12363 dw_loc_descr_ref cvt
;
12365 mem_loc_result
= mem_loc_descriptor (inner
,
12367 mem_mode
, initialized
);
12368 if (mem_loc_result
== NULL
)
12370 type_die
= base_type_for_mode (mode
,
12371 GET_MODE_CLASS (mode
) == MODE_INT
);
12372 if (type_die
== NULL
)
12374 mem_loc_result
= NULL
;
12377 if (GET_MODE_SIZE (mode
)
12378 != GET_MODE_SIZE (GET_MODE (inner
)))
12379 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12381 cvt
= new_loc_descr (DW_OP_GNU_reinterpret
, 0, 0);
12382 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12383 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12384 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12385 add_loc_descr (&mem_loc_result
, cvt
);
12390 if (GET_MODE_CLASS (mode
) != MODE_INT
12391 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12392 && rtl
!= arg_pointer_rtx
12393 && rtl
!= frame_pointer_rtx
12394 #ifdef POINTERS_EXTEND_UNSIGNED
12395 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12399 dw_die_ref type_die
;
12400 unsigned int dbx_regnum
;
12404 if (REGNO (rtl
) > FIRST_PSEUDO_REGISTER
)
12406 type_die
= base_type_for_mode (mode
,
12407 GET_MODE_CLASS (mode
) == MODE_INT
);
12408 if (type_die
== NULL
)
12411 dbx_regnum
= dbx_reg_number (rtl
);
12412 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12414 mem_loc_result
= new_loc_descr (DW_OP_GNU_regval_type
,
12416 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12417 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12418 mem_loc_result
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12421 /* Whenever a register number forms a part of the description of the
12422 method for calculating the (dynamic) address of a memory resident
12423 object, DWARF rules require the register number be referred to as
12424 a "base register". This distinction is not based in any way upon
12425 what category of register the hardware believes the given register
12426 belongs to. This is strictly DWARF terminology we're dealing with
12427 here. Note that in cases where the location of a memory-resident
12428 data object could be expressed as: OP_ADD (OP_BASEREG (basereg),
12429 OP_CONST (0)) the actual DWARF location descriptor that we generate
12430 may just be OP_BASEREG (basereg). This may look deceptively like
12431 the object in question was allocated to a register (rather than in
12432 memory) so DWARF consumers need to be aware of the subtle
12433 distinction between OP_REG and OP_BASEREG. */
12434 if (REGNO (rtl
) < FIRST_PSEUDO_REGISTER
)
12435 mem_loc_result
= based_loc_descr (rtl
, 0, VAR_INIT_STATUS_INITIALIZED
);
12436 else if (stack_realign_drap
12438 && crtl
->args
.internal_arg_pointer
== rtl
12439 && REGNO (crtl
->drap_reg
) < FIRST_PSEUDO_REGISTER
)
12441 /* If RTL is internal_arg_pointer, which has been optimized
12442 out, use DRAP instead. */
12443 mem_loc_result
= based_loc_descr (crtl
->drap_reg
, 0,
12444 VAR_INIT_STATUS_INITIALIZED
);
12450 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12452 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
12453 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
12456 else if (GET_CODE (rtl
) == ZERO_EXTEND
12457 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12458 && GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
12459 < HOST_BITS_PER_WIDE_INT
12460 /* If DW_OP_const{1,2,4}u won't be used, it is shorter
12461 to expand zero extend as two shifts instead of
12463 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= 4)
12465 enum machine_mode imode
= GET_MODE (XEXP (rtl
, 0));
12466 mem_loc_result
= op0
;
12467 add_loc_descr (&mem_loc_result
,
12468 int_loc_descriptor (GET_MODE_MASK (imode
)));
12469 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_and
, 0, 0));
12471 else if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12473 int shift
= DWARF2_ADDR_SIZE
12474 - GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)));
12475 shift
*= BITS_PER_UNIT
;
12476 if (GET_CODE (rtl
) == SIGN_EXTEND
)
12480 mem_loc_result
= op0
;
12481 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12482 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
12483 add_loc_descr (&mem_loc_result
, int_loc_descriptor (shift
));
12484 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12486 else if (!dwarf_strict
)
12488 dw_die_ref type_die1
, type_die2
;
12489 dw_loc_descr_ref cvt
;
12491 type_die1
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
12492 GET_CODE (rtl
) == ZERO_EXTEND
);
12493 if (type_die1
== NULL
)
12495 type_die2
= base_type_for_mode (mode
, 1);
12496 if (type_die2
== NULL
)
12498 mem_loc_result
= op0
;
12499 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12500 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12501 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die1
;
12502 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12503 add_loc_descr (&mem_loc_result
, cvt
);
12504 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12505 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12506 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die2
;
12507 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12508 add_loc_descr (&mem_loc_result
, cvt
);
12514 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
12515 if (new_rtl
!= rtl
)
12517 mem_loc_result
= mem_loc_descriptor (new_rtl
, mode
, mem_mode
,
12519 if (mem_loc_result
!= NULL
)
12520 return mem_loc_result
;
12523 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0),
12524 get_address_mode (rtl
), mode
,
12525 VAR_INIT_STATUS_INITIALIZED
);
12526 if (mem_loc_result
== NULL
)
12527 mem_loc_result
= tls_mem_loc_descriptor (rtl
);
12528 if (mem_loc_result
!= NULL
)
12530 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12531 || GET_MODE_CLASS (mode
) != MODE_INT
)
12533 dw_die_ref type_die
;
12534 dw_loc_descr_ref deref
;
12539 = base_type_for_mode (mode
, GET_MODE_CLASS (mode
) == MODE_INT
);
12540 if (type_die
== NULL
)
12542 deref
= new_loc_descr (DW_OP_GNU_deref_type
,
12543 GET_MODE_SIZE (mode
), 0);
12544 deref
->dw_loc_oprnd2
.val_class
= dw_val_class_die_ref
;
12545 deref
->dw_loc_oprnd2
.v
.val_die_ref
.die
= type_die
;
12546 deref
->dw_loc_oprnd2
.v
.val_die_ref
.external
= 0;
12547 add_loc_descr (&mem_loc_result
, deref
);
12549 else if (GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
)
12550 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_deref
, 0, 0));
12552 add_loc_descr (&mem_loc_result
,
12553 new_loc_descr (DW_OP_deref_size
,
12554 GET_MODE_SIZE (mode
), 0));
12559 return mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
, initialized
);
12562 /* Some ports can transform a symbol ref into a label ref, because
12563 the symbol ref is too far away and has to be dumped into a constant
12567 if (GET_MODE_CLASS (mode
) != MODE_INT
12568 || (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
12569 #ifdef POINTERS_EXTEND_UNSIGNED
12570 && (mode
!= Pmode
|| mem_mode
== VOIDmode
)
12574 if (GET_CODE (rtl
) == SYMBOL_REF
12575 && SYMBOL_REF_TLS_MODEL (rtl
) != TLS_MODEL_NONE
)
12577 dw_loc_descr_ref temp
;
12579 /* If this is not defined, we have no way to emit the data. */
12580 if (!targetm
.have_tls
|| !targetm
.asm_out
.output_dwarf_dtprel
)
12583 temp
= new_addr_loc_descr (rtl
, dtprel_true
);
12585 mem_loc_result
= new_loc_descr (DW_OP_GNU_push_tls_address
, 0, 0);
12586 add_loc_descr (&mem_loc_result
, temp
);
12591 if (!const_ok_for_output (rtl
))
12595 mem_loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
12596 vec_safe_push (used_rtx_array
, rtl
);
12602 case DEBUG_IMPLICIT_PTR
:
12603 expansion_failed (NULL_TREE
, rtl
,
12604 "CONCAT/CONCATN/VAR_LOCATION is handled only by loc_descriptor");
12610 if (REG_P (ENTRY_VALUE_EXP (rtl
)))
12612 if (GET_MODE_CLASS (mode
) != MODE_INT
12613 || GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12614 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12615 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12618 unsigned int dbx_regnum
= dbx_reg_number (ENTRY_VALUE_EXP (rtl
));
12619 if (dbx_regnum
== IGNORED_DWARF_REGNUM
)
12621 op0
= one_reg_loc_descriptor (dbx_regnum
,
12622 VAR_INIT_STATUS_INITIALIZED
);
12625 else if (MEM_P (ENTRY_VALUE_EXP (rtl
))
12626 && REG_P (XEXP (ENTRY_VALUE_EXP (rtl
), 0)))
12628 op0
= mem_loc_descriptor (ENTRY_VALUE_EXP (rtl
), mode
,
12629 VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
12630 if (op0
&& op0
->dw_loc_opc
== DW_OP_fbreg
)
12634 gcc_unreachable ();
12637 mem_loc_result
= new_loc_descr (DW_OP_GNU_entry_value
, 0, 0);
12638 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
12639 mem_loc_result
->dw_loc_oprnd1
.v
.val_loc
= op0
;
12642 case DEBUG_PARAMETER_REF
:
12643 mem_loc_result
= parameter_ref_descriptor (rtl
);
12647 /* Extract the PLUS expression nested inside and fall into
12648 PLUS code below. */
12649 rtl
= XEXP (rtl
, 1);
12654 /* Turn these into a PLUS expression and fall into the PLUS code
12656 rtl
= gen_rtx_PLUS (mode
, XEXP (rtl
, 0),
12657 gen_int_mode (GET_CODE (rtl
) == PRE_INC
12658 ? GET_MODE_UNIT_SIZE (mem_mode
)
12659 : -GET_MODE_UNIT_SIZE (mem_mode
),
12662 /* ... fall through ... */
12666 if (is_based_loc (rtl
)
12667 && (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12668 || XEXP (rtl
, 0) == arg_pointer_rtx
12669 || XEXP (rtl
, 0) == frame_pointer_rtx
)
12670 && GET_MODE_CLASS (mode
) == MODE_INT
)
12671 mem_loc_result
= based_loc_descr (XEXP (rtl
, 0),
12672 INTVAL (XEXP (rtl
, 1)),
12673 VAR_INIT_STATUS_INITIALIZED
);
12676 mem_loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12677 VAR_INIT_STATUS_INITIALIZED
);
12678 if (mem_loc_result
== 0)
12681 if (CONST_INT_P (XEXP (rtl
, 1))
12682 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
)
12683 loc_descr_plus_const (&mem_loc_result
, INTVAL (XEXP (rtl
, 1)));
12686 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12687 VAR_INIT_STATUS_INITIALIZED
);
12690 add_loc_descr (&mem_loc_result
, op1
);
12691 add_loc_descr (&mem_loc_result
,
12692 new_loc_descr (DW_OP_plus
, 0, 0));
12697 /* If a pseudo-reg is optimized away, it is possible for it to
12698 be replaced with a MEM containing a multiply or shift. */
12709 && GET_MODE_CLASS (mode
) == MODE_INT
12710 && GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
)
12712 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12713 base_type_for_mode (mode
, 0),
12737 if (GET_MODE_CLASS (mode
) != MODE_INT
)
12739 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12740 VAR_INIT_STATUS_INITIALIZED
);
12742 rtx rtlop1
= XEXP (rtl
, 1);
12743 if (GET_MODE (rtlop1
) != VOIDmode
12744 && GET_MODE_BITSIZE (GET_MODE (rtlop1
))
12745 < GET_MODE_BITSIZE (mode
))
12746 rtlop1
= gen_rtx_ZERO_EXTEND (mode
, rtlop1
);
12747 op1
= mem_loc_descriptor (rtlop1
, mode
, mem_mode
,
12748 VAR_INIT_STATUS_INITIALIZED
);
12751 if (op0
== 0 || op1
== 0)
12754 mem_loc_result
= op0
;
12755 add_loc_descr (&mem_loc_result
, op1
);
12756 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12772 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12773 VAR_INIT_STATUS_INITIALIZED
);
12774 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12775 VAR_INIT_STATUS_INITIALIZED
);
12777 if (op0
== 0 || op1
== 0)
12780 mem_loc_result
= op0
;
12781 add_loc_descr (&mem_loc_result
, op1
);
12782 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12786 if (GET_MODE_SIZE (mode
) > DWARF2_ADDR_SIZE
&& !dwarf_strict
)
12788 mem_loc_result
= typed_binop (DW_OP_mod
, rtl
,
12789 base_type_for_mode (mode
, 0),
12794 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12795 VAR_INIT_STATUS_INITIALIZED
);
12796 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
12797 VAR_INIT_STATUS_INITIALIZED
);
12799 if (op0
== 0 || op1
== 0)
12802 mem_loc_result
= op0
;
12803 add_loc_descr (&mem_loc_result
, op1
);
12804 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12805 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_over
, 0, 0));
12806 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_div
, 0, 0));
12807 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_mul
, 0, 0));
12808 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_minus
, 0, 0));
12812 if (!dwarf_strict
&& GET_MODE_CLASS (mode
) == MODE_INT
)
12814 if (GET_MODE_CLASS (mode
) > DWARF2_ADDR_SIZE
)
12819 mem_loc_result
= typed_binop (DW_OP_div
, rtl
,
12820 base_type_for_mode (mode
, 1),
12838 op0
= mem_loc_descriptor (XEXP (rtl
, 0), mode
, mem_mode
,
12839 VAR_INIT_STATUS_INITIALIZED
);
12844 mem_loc_result
= op0
;
12845 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
12849 if (GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
12850 #ifdef POINTERS_EXTEND_UNSIGNED
12852 && mem_mode
!= VOIDmode
12853 && trunc_int_for_mode (INTVAL (rtl
), ptr_mode
) == INTVAL (rtl
))
12857 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12861 && (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
12862 || GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_DOUBLE_INT
))
12864 dw_die_ref type_die
= base_type_for_mode (mode
, 1);
12865 enum machine_mode amode
;
12866 if (type_die
== NULL
)
12868 amode
= mode_for_size (DWARF2_ADDR_SIZE
* BITS_PER_UNIT
,
12870 if (INTVAL (rtl
) >= 0
12871 && amode
!= BLKmode
12872 && trunc_int_for_mode (INTVAL (rtl
), amode
) == INTVAL (rtl
)
12873 /* const DW_OP_GNU_convert <XXX> vs.
12874 DW_OP_GNU_const_type <XXX, 1, const>. */
12875 && size_of_int_loc_descriptor (INTVAL (rtl
)) + 1 + 1
12876 < (unsigned long) 1 + 1 + 1 + GET_MODE_SIZE (mode
))
12878 mem_loc_result
= int_loc_descriptor (INTVAL (rtl
));
12879 op0
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
12880 op0
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12881 op0
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12882 op0
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12883 add_loc_descr (&mem_loc_result
, op0
);
12884 return mem_loc_result
;
12886 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0,
12888 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12889 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12890 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12891 if (GET_MODE_BITSIZE (mode
) == HOST_BITS_PER_WIDE_INT
)
12892 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
12895 mem_loc_result
->dw_loc_oprnd2
.val_class
12896 = dw_val_class_const_double
;
12897 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12898 = double_int::from_shwi (INTVAL (rtl
));
12906 dw_die_ref type_die
;
12908 /* Note that if TARGET_SUPPORTS_WIDE_INT == 0, a
12909 CONST_DOUBLE rtx could represent either an large integer
12910 or a floating-point constant. If
12911 TARGET_SUPPORTS_WIDE_INT != 0, the value is always a
12912 floating point constant.
12914 When it is an integer, a CONST_DOUBLE is used whenever
12915 the constant requires 2 HWIs to be adequately
12916 represented. We output CONST_DOUBLEs as blocks. */
12917 if (mode
== VOIDmode
12918 || (GET_MODE (rtl
) == VOIDmode
12919 && GET_MODE_BITSIZE (mode
) != HOST_BITS_PER_DOUBLE_INT
))
12921 type_die
= base_type_for_mode (mode
,
12922 GET_MODE_CLASS (mode
) == MODE_INT
);
12923 if (type_die
== NULL
)
12925 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12926 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12927 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12928 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12929 #if TARGET_SUPPORTS_WIDE_INT == 0
12930 if (!SCALAR_FLOAT_MODE_P (mode
))
12932 mem_loc_result
->dw_loc_oprnd2
.val_class
12933 = dw_val_class_const_double
;
12934 mem_loc_result
->dw_loc_oprnd2
.v
.val_double
12935 = rtx_to_double_int (rtl
);
12940 unsigned int length
= GET_MODE_SIZE (mode
);
12941 unsigned char *array
12942 = (unsigned char*) ggc_alloc_atomic (length
);
12944 insert_float (rtl
, array
);
12945 mem_loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
12946 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
12947 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
12948 mem_loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
12953 case CONST_WIDE_INT
:
12956 dw_die_ref type_die
;
12958 type_die
= base_type_for_mode (mode
,
12959 GET_MODE_CLASS (mode
) == MODE_INT
);
12960 if (type_die
== NULL
)
12962 mem_loc_result
= new_loc_descr (DW_OP_GNU_const_type
, 0, 0);
12963 mem_loc_result
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
12964 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
12965 mem_loc_result
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
12966 mem_loc_result
->dw_loc_oprnd2
.val_class
12967 = dw_val_class_wide_int
;
12968 mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc_cleared_wide_int ();
12969 *mem_loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
12974 mem_loc_result
= scompare_loc_descriptor (DW_OP_eq
, rtl
, mem_mode
);
12978 mem_loc_result
= scompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
12982 mem_loc_result
= scompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
12986 mem_loc_result
= scompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
12990 mem_loc_result
= scompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
12994 mem_loc_result
= scompare_loc_descriptor (DW_OP_ne
, rtl
, mem_mode
);
12998 mem_loc_result
= ucompare_loc_descriptor (DW_OP_ge
, rtl
, mem_mode
);
13002 mem_loc_result
= ucompare_loc_descriptor (DW_OP_gt
, rtl
, mem_mode
);
13006 mem_loc_result
= ucompare_loc_descriptor (DW_OP_le
, rtl
, mem_mode
);
13010 mem_loc_result
= ucompare_loc_descriptor (DW_OP_lt
, rtl
, mem_mode
);
13015 if (GET_MODE_CLASS (mode
) != MODE_INT
)
13020 mem_loc_result
= minmax_loc_descriptor (rtl
, mode
, mem_mode
);
13025 if (CONST_INT_P (XEXP (rtl
, 1))
13026 && CONST_INT_P (XEXP (rtl
, 2))
13027 && ((unsigned) INTVAL (XEXP (rtl
, 1))
13028 + (unsigned) INTVAL (XEXP (rtl
, 2))
13029 <= GET_MODE_BITSIZE (mode
))
13030 && GET_MODE_CLASS (mode
) == MODE_INT
13031 && GET_MODE_SIZE (mode
) <= DWARF2_ADDR_SIZE
13032 && GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0))) <= DWARF2_ADDR_SIZE
)
13035 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13036 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13039 if (GET_CODE (rtl
) == SIGN_EXTRACT
)
13043 mem_loc_result
= op0
;
13044 size
= INTVAL (XEXP (rtl
, 1));
13045 shift
= INTVAL (XEXP (rtl
, 2));
13046 if (BITS_BIG_ENDIAN
)
13047 shift
= GET_MODE_BITSIZE (GET_MODE (XEXP (rtl
, 0)))
13049 if (shift
+ size
!= (int) DWARF2_ADDR_SIZE
)
13051 add_loc_descr (&mem_loc_result
,
13052 int_loc_descriptor (DWARF2_ADDR_SIZE
13054 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_shl
, 0, 0));
13056 if (size
!= (int) DWARF2_ADDR_SIZE
)
13058 add_loc_descr (&mem_loc_result
,
13059 int_loc_descriptor (DWARF2_ADDR_SIZE
- size
));
13060 add_loc_descr (&mem_loc_result
, new_loc_descr (op
, 0, 0));
13067 dw_loc_descr_ref op2
, bra_node
, drop_node
;
13068 op0
= mem_loc_descriptor (XEXP (rtl
, 0),
13069 GET_MODE (XEXP (rtl
, 0)) == VOIDmode
13070 ? word_mode
: GET_MODE (XEXP (rtl
, 0)),
13071 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13072 op1
= mem_loc_descriptor (XEXP (rtl
, 1), mode
, mem_mode
,
13073 VAR_INIT_STATUS_INITIALIZED
);
13074 op2
= mem_loc_descriptor (XEXP (rtl
, 2), mode
, mem_mode
,
13075 VAR_INIT_STATUS_INITIALIZED
);
13076 if (op0
== NULL
|| op1
== NULL
|| op2
== NULL
)
13079 mem_loc_result
= op1
;
13080 add_loc_descr (&mem_loc_result
, op2
);
13081 add_loc_descr (&mem_loc_result
, op0
);
13082 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
13083 add_loc_descr (&mem_loc_result
, bra_node
);
13084 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_swap
, 0, 0));
13085 drop_node
= new_loc_descr (DW_OP_drop
, 0, 0);
13086 add_loc_descr (&mem_loc_result
, drop_node
);
13087 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
13088 bra_node
->dw_loc_oprnd1
.v
.val_loc
= drop_node
;
13093 case FLOAT_TRUNCATE
:
13095 case UNSIGNED_FLOAT
:
13100 dw_die_ref type_die
;
13101 dw_loc_descr_ref cvt
;
13103 op0
= mem_loc_descriptor (XEXP (rtl
, 0), GET_MODE (XEXP (rtl
, 0)),
13104 mem_mode
, VAR_INIT_STATUS_INITIALIZED
);
13107 if (GET_MODE_CLASS (GET_MODE (XEXP (rtl
, 0))) == MODE_INT
13108 && (GET_CODE (rtl
) == FLOAT
13109 || GET_MODE_SIZE (GET_MODE (XEXP (rtl
, 0)))
13110 <= DWARF2_ADDR_SIZE
))
13112 type_die
= base_type_for_mode (GET_MODE (XEXP (rtl
, 0)),
13113 GET_CODE (rtl
) == UNSIGNED_FLOAT
);
13114 if (type_die
== NULL
)
13116 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13117 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13118 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13119 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13120 add_loc_descr (&op0
, cvt
);
13122 type_die
= base_type_for_mode (mode
, GET_CODE (rtl
) == UNSIGNED_FIX
);
13123 if (type_die
== NULL
)
13125 cvt
= new_loc_descr (DW_OP_GNU_convert
, 0, 0);
13126 cvt
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13127 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.die
= type_die
;
13128 cvt
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13129 add_loc_descr (&op0
, cvt
);
13130 if (GET_MODE_CLASS (mode
) == MODE_INT
13131 && (GET_CODE (rtl
) == FIX
13132 || GET_MODE_SIZE (mode
) < DWARF2_ADDR_SIZE
))
13134 op0
= convert_descriptor_to_mode (mode
, op0
);
13138 mem_loc_result
= op0
;
13145 mem_loc_result
= clz_loc_descriptor (rtl
, mode
, mem_mode
);
13150 mem_loc_result
= popcount_loc_descriptor (rtl
, mode
, mem_mode
);
13154 mem_loc_result
= bswap_loc_descriptor (rtl
, mode
, mem_mode
);
13159 mem_loc_result
= rotate_loc_descriptor (rtl
, mode
, mem_mode
);
13163 /* In theory, we could implement the above. */
13164 /* DWARF cannot represent the unsigned compare operations
13189 case FRACT_CONVERT
:
13190 case UNSIGNED_FRACT_CONVERT
:
13192 case UNSIGNED_SAT_FRACT
:
13198 case VEC_DUPLICATE
:
13202 case STRICT_LOW_PART
:
13207 /* If delegitimize_address couldn't do anything with the UNSPEC, we
13208 can't express it in the debug info. This can happen e.g. with some
13213 resolve_one_addr (&rtl
, NULL
);
13217 #ifdef ENABLE_CHECKING
13218 print_rtl (stderr
, rtl
);
13219 gcc_unreachable ();
13225 if (mem_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13226 add_loc_descr (&mem_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13228 return mem_loc_result
;
13231 /* Return a descriptor that describes the concatenation of two locations.
13232 This is typically a complex variable. */
13234 static dw_loc_descr_ref
13235 concat_loc_descriptor (rtx x0
, rtx x1
, enum var_init_status initialized
)
13237 dw_loc_descr_ref cc_loc_result
= NULL
;
13238 dw_loc_descr_ref x0_ref
13239 = loc_descriptor (x0
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13240 dw_loc_descr_ref x1_ref
13241 = loc_descriptor (x1
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13243 if (x0_ref
== 0 || x1_ref
== 0)
13246 cc_loc_result
= x0_ref
;
13247 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x0
)));
13249 add_loc_descr (&cc_loc_result
, x1_ref
);
13250 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x1
)));
13252 if (initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13253 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13255 return cc_loc_result
;
13258 /* Return a descriptor that describes the concatenation of N
13261 static dw_loc_descr_ref
13262 concatn_loc_descriptor (rtx concatn
, enum var_init_status initialized
)
13265 dw_loc_descr_ref cc_loc_result
= NULL
;
13266 unsigned int n
= XVECLEN (concatn
, 0);
13268 for (i
= 0; i
< n
; ++i
)
13270 dw_loc_descr_ref ref
;
13271 rtx x
= XVECEXP (concatn
, 0, i
);
13273 ref
= loc_descriptor (x
, VOIDmode
, VAR_INIT_STATUS_INITIALIZED
);
13277 add_loc_descr (&cc_loc_result
, ref
);
13278 add_loc_descr_op_piece (&cc_loc_result
, GET_MODE_SIZE (GET_MODE (x
)));
13281 if (cc_loc_result
&& initialized
== VAR_INIT_STATUS_UNINITIALIZED
)
13282 add_loc_descr (&cc_loc_result
, new_loc_descr (DW_OP_GNU_uninit
, 0, 0));
13284 return cc_loc_result
;
13287 /* Helper function for loc_descriptor. Return DW_OP_GNU_implicit_pointer
13288 for DEBUG_IMPLICIT_PTR RTL. */
13290 static dw_loc_descr_ref
13291 implicit_ptr_descriptor (rtx rtl
, HOST_WIDE_INT offset
)
13293 dw_loc_descr_ref ret
;
13298 gcc_assert (TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == VAR_DECL
13299 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == PARM_DECL
13300 || TREE_CODE (DEBUG_IMPLICIT_PTR_DECL (rtl
)) == RESULT_DECL
);
13301 ref
= lookup_decl_die (DEBUG_IMPLICIT_PTR_DECL (rtl
));
13302 ret
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
13303 ret
->dw_loc_oprnd2
.val_class
= dw_val_class_const
;
13306 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
13307 ret
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
13308 ret
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
13312 ret
->dw_loc_oprnd1
.val_class
= dw_val_class_decl_ref
;
13313 ret
->dw_loc_oprnd1
.v
.val_decl_ref
= DEBUG_IMPLICIT_PTR_DECL (rtl
);
13318 /* Output a proper Dwarf location descriptor for a variable or parameter
13319 which is either allocated in a register or in a memory location. For a
13320 register, we just generate an OP_REG and the register number. For a
13321 memory location we provide a Dwarf postfix expression describing how to
13322 generate the (dynamic) address of the object onto the address stack.
13324 MODE is mode of the decl if this loc_descriptor is going to be used in
13325 .debug_loc section where DW_OP_stack_value and DW_OP_implicit_value are
13326 allowed, VOIDmode otherwise.
13328 If we don't know how to describe it, return 0. */
13330 static dw_loc_descr_ref
13331 loc_descriptor (rtx rtl
, enum machine_mode mode
,
13332 enum var_init_status initialized
)
13334 dw_loc_descr_ref loc_result
= NULL
;
13336 switch (GET_CODE (rtl
))
13339 /* The case of a subreg may arise when we have a local (register)
13340 variable or a formal (register) parameter which doesn't quite fill
13341 up an entire register. For now, just assume that it is
13342 legitimate to make the Dwarf info refer to the whole register which
13343 contains the given subreg. */
13344 if (REG_P (SUBREG_REG (rtl
)) && subreg_lowpart_p (rtl
))
13345 loc_result
= loc_descriptor (SUBREG_REG (rtl
),
13346 GET_MODE (SUBREG_REG (rtl
)), initialized
);
13352 loc_result
= reg_loc_descriptor (rtl
, initialized
);
13356 loc_result
= mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
13357 GET_MODE (rtl
), initialized
);
13358 if (loc_result
== NULL
)
13359 loc_result
= tls_mem_loc_descriptor (rtl
);
13360 if (loc_result
== NULL
)
13362 rtx new_rtl
= avoid_constant_pool_reference (rtl
);
13363 if (new_rtl
!= rtl
)
13364 loc_result
= loc_descriptor (new_rtl
, mode
, initialized
);
13369 loc_result
= concat_loc_descriptor (XEXP (rtl
, 0), XEXP (rtl
, 1),
13374 loc_result
= concatn_loc_descriptor (rtl
, initialized
);
13379 if (GET_CODE (PAT_VAR_LOCATION_LOC (rtl
)) != PARALLEL
)
13381 rtx loc
= PAT_VAR_LOCATION_LOC (rtl
);
13382 if (GET_CODE (loc
) == EXPR_LIST
)
13383 loc
= XEXP (loc
, 0);
13384 loc_result
= loc_descriptor (loc
, mode
, initialized
);
13388 rtl
= XEXP (rtl
, 1);
13393 rtvec par_elems
= XVEC (rtl
, 0);
13394 int num_elem
= GET_NUM_ELEM (par_elems
);
13395 enum machine_mode mode
;
13398 /* Create the first one, so we have something to add to. */
13399 loc_result
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, 0), 0),
13400 VOIDmode
, initialized
);
13401 if (loc_result
== NULL
)
13403 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, 0), 0));
13404 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13405 for (i
= 1; i
< num_elem
; i
++)
13407 dw_loc_descr_ref temp
;
13409 temp
= loc_descriptor (XEXP (RTVEC_ELT (par_elems
, i
), 0),
13410 VOIDmode
, initialized
);
13413 add_loc_descr (&loc_result
, temp
);
13414 mode
= GET_MODE (XEXP (RTVEC_ELT (par_elems
, i
), 0));
13415 add_loc_descr_op_piece (&loc_result
, GET_MODE_SIZE (mode
));
13421 if (mode
!= VOIDmode
&& mode
!= BLKmode
)
13422 loc_result
= address_of_int_loc_descriptor (GET_MODE_SIZE (mode
),
13427 if (mode
== VOIDmode
)
13428 mode
= GET_MODE (rtl
);
13430 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13432 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13434 /* Note that a CONST_DOUBLE rtx could represent either an integer
13435 or a floating-point constant. A CONST_DOUBLE is used whenever
13436 the constant requires more than one word in order to be
13437 adequately represented. We output CONST_DOUBLEs as blocks. */
13438 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13439 GET_MODE_SIZE (mode
), 0);
13440 #if TARGET_SUPPORTS_WIDE_INT == 0
13441 if (!SCALAR_FLOAT_MODE_P (mode
))
13443 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_const_double
;
13444 loc_result
->dw_loc_oprnd2
.v
.val_double
13445 = rtx_to_double_int (rtl
);
13450 unsigned int length
= GET_MODE_SIZE (mode
);
13451 unsigned char *array
13452 = (unsigned char*) ggc_alloc_atomic (length
);
13454 insert_float (rtl
, array
);
13455 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13456 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
/ 4;
13457 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 4;
13458 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13463 case CONST_WIDE_INT
:
13464 if (mode
== VOIDmode
)
13465 mode
= GET_MODE (rtl
);
13467 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13469 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13470 GET_MODE_SIZE (mode
), 0);
13471 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_wide_int
;
13472 loc_result
->dw_loc_oprnd2
.v
.val_wide
= ggc_alloc_cleared_wide_int ();
13473 *loc_result
->dw_loc_oprnd2
.v
.val_wide
= std::make_pair (rtl
, mode
);
13478 if (mode
== VOIDmode
)
13479 mode
= GET_MODE (rtl
);
13481 if (mode
!= VOIDmode
&& (dwarf_version
>= 4 || !dwarf_strict
))
13483 unsigned int elt_size
= GET_MODE_UNIT_SIZE (GET_MODE (rtl
));
13484 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
13485 unsigned char *array
= (unsigned char *)
13486 ggc_alloc_atomic (length
* elt_size
);
13489 enum machine_mode imode
= GET_MODE_INNER (mode
);
13491 gcc_assert (mode
== GET_MODE (rtl
) || VOIDmode
== GET_MODE (rtl
));
13492 switch (GET_MODE_CLASS (mode
))
13494 case MODE_VECTOR_INT
:
13495 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13497 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13498 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
13502 case MODE_VECTOR_FLOAT
:
13503 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
13505 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
13506 insert_float (elt
, p
);
13511 gcc_unreachable ();
13514 loc_result
= new_loc_descr (DW_OP_implicit_value
,
13515 length
* elt_size
, 0);
13516 loc_result
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
13517 loc_result
->dw_loc_oprnd2
.v
.val_vec
.length
= length
;
13518 loc_result
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= elt_size
;
13519 loc_result
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
13524 if (mode
== VOIDmode
13525 || CONST_SCALAR_INT_P (XEXP (rtl
, 0))
13526 || CONST_DOUBLE_AS_FLOAT_P (XEXP (rtl
, 0))
13527 || GET_CODE (XEXP (rtl
, 0)) == CONST_VECTOR
)
13529 loc_result
= loc_descriptor (XEXP (rtl
, 0), mode
, initialized
);
13534 if (!const_ok_for_output (rtl
))
13537 if (mode
!= VOIDmode
&& GET_MODE_SIZE (mode
) == DWARF2_ADDR_SIZE
13538 && (dwarf_version
>= 4 || !dwarf_strict
))
13540 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
13541 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13542 vec_safe_push (used_rtx_array
, rtl
);
13546 case DEBUG_IMPLICIT_PTR
:
13547 loc_result
= implicit_ptr_descriptor (rtl
, 0);
13551 if (GET_CODE (XEXP (rtl
, 0)) == DEBUG_IMPLICIT_PTR
13552 && CONST_INT_P (XEXP (rtl
, 1)))
13555 = implicit_ptr_descriptor (XEXP (rtl
, 0), INTVAL (XEXP (rtl
, 1)));
13561 if ((GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE (rtl
) == mode
13562 && GET_MODE_SIZE (GET_MODE (rtl
)) <= DWARF2_ADDR_SIZE
13563 && dwarf_version
>= 4)
13564 || (!dwarf_strict
&& mode
!= VOIDmode
&& mode
!= BLKmode
))
13566 /* Value expression. */
13567 loc_result
= mem_loc_descriptor (rtl
, mode
, VOIDmode
, initialized
);
13569 add_loc_descr (&loc_result
,
13570 new_loc_descr (DW_OP_stack_value
, 0, 0));
13578 /* We need to figure out what section we should use as the base for the
13579 address ranges where a given location is valid.
13580 1. If this particular DECL has a section associated with it, use that.
13581 2. If this function has a section associated with it, use that.
13582 3. Otherwise, use the text section.
13583 XXX: If you split a variable across multiple sections, we won't notice. */
13585 static const char *
13586 secname_for_decl (const_tree decl
)
13588 const char *secname
;
13590 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_SECTION_NAME (decl
))
13592 tree sectree
= DECL_SECTION_NAME (decl
);
13593 secname
= TREE_STRING_POINTER (sectree
);
13595 else if (current_function_decl
&& DECL_SECTION_NAME (current_function_decl
))
13597 tree sectree
= DECL_SECTION_NAME (current_function_decl
);
13598 secname
= TREE_STRING_POINTER (sectree
);
13600 else if (cfun
&& in_cold_section_p
)
13601 secname
= crtl
->subsections
.cold_section_label
;
13603 secname
= text_section_label
;
13608 /* Return true when DECL_BY_REFERENCE is defined and set for DECL. */
13611 decl_by_reference_p (tree decl
)
13613 return ((TREE_CODE (decl
) == PARM_DECL
|| TREE_CODE (decl
) == RESULT_DECL
13614 || TREE_CODE (decl
) == VAR_DECL
)
13615 && DECL_BY_REFERENCE (decl
));
13618 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13621 static dw_loc_descr_ref
13622 dw_loc_list_1 (tree loc
, rtx varloc
, int want_address
,
13623 enum var_init_status initialized
)
13625 int have_address
= 0;
13626 dw_loc_descr_ref descr
;
13627 enum machine_mode mode
;
13629 if (want_address
!= 2)
13631 gcc_assert (GET_CODE (varloc
) == VAR_LOCATION
);
13633 if (GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13635 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13636 if (GET_CODE (varloc
) == EXPR_LIST
)
13637 varloc
= XEXP (varloc
, 0);
13638 mode
= GET_MODE (varloc
);
13639 if (MEM_P (varloc
))
13641 rtx addr
= XEXP (varloc
, 0);
13642 descr
= mem_loc_descriptor (addr
, get_address_mode (varloc
),
13643 mode
, initialized
);
13648 rtx x
= avoid_constant_pool_reference (varloc
);
13650 descr
= mem_loc_descriptor (x
, mode
, VOIDmode
,
13655 descr
= mem_loc_descriptor (varloc
, mode
, VOIDmode
, initialized
);
13662 if (GET_CODE (varloc
) == VAR_LOCATION
)
13663 mode
= DECL_MODE (PAT_VAR_LOCATION_DECL (varloc
));
13665 mode
= DECL_MODE (loc
);
13666 descr
= loc_descriptor (varloc
, mode
, initialized
);
13673 if (want_address
== 2 && !have_address
13674 && (dwarf_version
>= 4 || !dwarf_strict
))
13676 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
13678 expansion_failed (loc
, NULL_RTX
,
13679 "DWARF address size mismatch");
13682 add_loc_descr (&descr
, new_loc_descr (DW_OP_stack_value
, 0, 0));
13685 /* Show if we can't fill the request for an address. */
13686 if (want_address
&& !have_address
)
13688 expansion_failed (loc
, NULL_RTX
,
13689 "Want address and only have value");
13693 /* If we've got an address and don't want one, dereference. */
13694 if (!want_address
&& have_address
)
13696 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
13697 enum dwarf_location_atom op
;
13699 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
13701 expansion_failed (loc
, NULL_RTX
,
13702 "DWARF address size mismatch");
13705 else if (size
== DWARF2_ADDR_SIZE
)
13708 op
= DW_OP_deref_size
;
13710 add_loc_descr (&descr
, new_loc_descr (op
, size
, 0));
13716 /* Create a DW_OP_piece or DW_OP_bit_piece for bitsize, or return NULL
13717 if it is not possible. */
13719 static dw_loc_descr_ref
13720 new_loc_descr_op_bit_piece (HOST_WIDE_INT bitsize
, HOST_WIDE_INT offset
)
13722 if ((bitsize
% BITS_PER_UNIT
) == 0 && offset
== 0)
13723 return new_loc_descr (DW_OP_piece
, bitsize
/ BITS_PER_UNIT
, 0);
13724 else if (dwarf_version
>= 3 || !dwarf_strict
)
13725 return new_loc_descr (DW_OP_bit_piece
, bitsize
, offset
);
13730 /* Helper function for dw_loc_list. Compute proper Dwarf location descriptor
13731 for VAR_LOC_NOTE for variable DECL that has been optimized by SRA. */
13733 static dw_loc_descr_ref
13734 dw_sra_loc_expr (tree decl
, rtx loc
)
13737 unsigned int padsize
= 0;
13738 dw_loc_descr_ref descr
, *descr_tail
;
13739 unsigned HOST_WIDE_INT decl_size
;
13741 enum var_init_status initialized
;
13743 if (DECL_SIZE (decl
) == NULL
13744 || !tree_fits_uhwi_p (DECL_SIZE (decl
)))
13747 decl_size
= tree_to_uhwi (DECL_SIZE (decl
));
13749 descr_tail
= &descr
;
13751 for (p
= loc
; p
; p
= XEXP (p
, 1))
13753 unsigned int bitsize
= decl_piece_bitsize (p
);
13754 rtx loc_note
= *decl_piece_varloc_ptr (p
);
13755 dw_loc_descr_ref cur_descr
;
13756 dw_loc_descr_ref
*tail
, last
= NULL
;
13757 unsigned int opsize
= 0;
13759 if (loc_note
== NULL_RTX
13760 || NOTE_VAR_LOCATION_LOC (loc_note
) == NULL_RTX
)
13762 padsize
+= bitsize
;
13765 initialized
= NOTE_VAR_LOCATION_STATUS (loc_note
);
13766 varloc
= NOTE_VAR_LOCATION (loc_note
);
13767 cur_descr
= dw_loc_list_1 (decl
, varloc
, 2, initialized
);
13768 if (cur_descr
== NULL
)
13770 padsize
+= bitsize
;
13774 /* Check that cur_descr either doesn't use
13775 DW_OP_*piece operations, or their sum is equal
13776 to bitsize. Otherwise we can't embed it. */
13777 for (tail
= &cur_descr
; *tail
!= NULL
;
13778 tail
= &(*tail
)->dw_loc_next
)
13779 if ((*tail
)->dw_loc_opc
== DW_OP_piece
)
13781 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
13785 else if ((*tail
)->dw_loc_opc
== DW_OP_bit_piece
)
13787 opsize
+= (*tail
)->dw_loc_oprnd1
.v
.val_unsigned
;
13791 if (last
!= NULL
&& opsize
!= bitsize
)
13793 padsize
+= bitsize
;
13794 /* Discard the current piece of the descriptor and release any
13795 addr_table entries it uses. */
13796 remove_loc_list_addr_table_entries (cur_descr
);
13800 /* If there is a hole, add DW_OP_*piece after empty DWARF
13801 expression, which means that those bits are optimized out. */
13804 if (padsize
> decl_size
)
13806 remove_loc_list_addr_table_entries (cur_descr
);
13807 goto discard_descr
;
13809 decl_size
-= padsize
;
13810 *descr_tail
= new_loc_descr_op_bit_piece (padsize
, 0);
13811 if (*descr_tail
== NULL
)
13813 remove_loc_list_addr_table_entries (cur_descr
);
13814 goto discard_descr
;
13816 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13819 *descr_tail
= cur_descr
;
13821 if (bitsize
> decl_size
)
13822 goto discard_descr
;
13823 decl_size
-= bitsize
;
13826 HOST_WIDE_INT offset
= 0;
13827 if (GET_CODE (varloc
) == VAR_LOCATION
13828 && GET_CODE (PAT_VAR_LOCATION_LOC (varloc
)) != PARALLEL
)
13830 varloc
= PAT_VAR_LOCATION_LOC (varloc
);
13831 if (GET_CODE (varloc
) == EXPR_LIST
)
13832 varloc
= XEXP (varloc
, 0);
13836 if (GET_CODE (varloc
) == CONST
13837 || GET_CODE (varloc
) == SIGN_EXTEND
13838 || GET_CODE (varloc
) == ZERO_EXTEND
)
13839 varloc
= XEXP (varloc
, 0);
13840 else if (GET_CODE (varloc
) == SUBREG
)
13841 varloc
= SUBREG_REG (varloc
);
13846 /* DW_OP_bit_size offset should be zero for register
13847 or implicit location descriptions and empty location
13848 descriptions, but for memory addresses needs big endian
13850 if (MEM_P (varloc
))
13852 unsigned HOST_WIDE_INT memsize
13853 = MEM_SIZE (varloc
) * BITS_PER_UNIT
;
13854 if (memsize
!= bitsize
)
13856 if (BYTES_BIG_ENDIAN
!= WORDS_BIG_ENDIAN
13857 && (memsize
> BITS_PER_WORD
|| bitsize
> BITS_PER_WORD
))
13858 goto discard_descr
;
13859 if (memsize
< bitsize
)
13860 goto discard_descr
;
13861 if (BITS_BIG_ENDIAN
)
13862 offset
= memsize
- bitsize
;
13866 *descr_tail
= new_loc_descr_op_bit_piece (bitsize
, offset
);
13867 if (*descr_tail
== NULL
)
13868 goto discard_descr
;
13869 descr_tail
= &(*descr_tail
)->dw_loc_next
;
13873 /* If there were any non-empty expressions, add padding till the end of
13875 if (descr
!= NULL
&& decl_size
!= 0)
13877 *descr_tail
= new_loc_descr_op_bit_piece (decl_size
, 0);
13878 if (*descr_tail
== NULL
)
13879 goto discard_descr
;
13884 /* Discard the descriptor and release any addr_table entries it uses. */
13885 remove_loc_list_addr_table_entries (descr
);
13889 /* Return the dwarf representation of the location list LOC_LIST of
13890 DECL. WANT_ADDRESS has the same meaning as in loc_list_from_tree
13893 static dw_loc_list_ref
13894 dw_loc_list (var_loc_list
*loc_list
, tree decl
, int want_address
)
13896 const char *endname
, *secname
;
13898 enum var_init_status initialized
;
13899 struct var_loc_node
*node
;
13900 dw_loc_descr_ref descr
;
13901 char label_id
[MAX_ARTIFICIAL_LABEL_BYTES
];
13902 dw_loc_list_ref list
= NULL
;
13903 dw_loc_list_ref
*listp
= &list
;
13905 /* Now that we know what section we are using for a base,
13906 actually construct the list of locations.
13907 The first location information is what is passed to the
13908 function that creates the location list, and the remaining
13909 locations just get added on to that list.
13910 Note that we only know the start address for a location
13911 (IE location changes), so to build the range, we use
13912 the range [current location start, next location start].
13913 This means we have to special case the last node, and generate
13914 a range of [last location start, end of function label]. */
13916 secname
= secname_for_decl (decl
);
13918 for (node
= loc_list
->first
; node
; node
= node
->next
)
13919 if (GET_CODE (node
->loc
) == EXPR_LIST
13920 || NOTE_VAR_LOCATION_LOC (node
->loc
) != NULL_RTX
)
13922 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13924 /* This requires DW_OP_{,bit_}piece, which is not usable
13925 inside DWARF expressions. */
13926 if (want_address
!= 2)
13928 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13934 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13935 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13936 descr
= dw_loc_list_1 (decl
, varloc
, want_address
, initialized
);
13940 bool range_across_switch
= false;
13941 /* If section switch happens in between node->label
13942 and node->next->label (or end of function) and
13943 we can't emit it as a single entry list,
13944 emit two ranges, first one ending at the end
13945 of first partition and second one starting at the
13946 beginning of second partition. */
13947 if (node
== loc_list
->last_before_switch
13948 && (node
!= loc_list
->first
|| loc_list
->first
->next
)
13949 && current_function_decl
)
13951 endname
= cfun
->fde
->dw_fde_end
;
13952 range_across_switch
= true;
13954 /* The variable has a location between NODE->LABEL and
13955 NODE->NEXT->LABEL. */
13956 else if (node
->next
)
13957 endname
= node
->next
->label
;
13958 /* If the variable has a location at the last label
13959 it keeps its location until the end of function. */
13960 else if (!current_function_decl
)
13961 endname
= text_end_label
;
13964 ASM_GENERATE_INTERNAL_LABEL (label_id
, FUNC_END_LABEL
,
13965 current_function_funcdef_no
);
13966 endname
= ggc_strdup (label_id
);
13969 *listp
= new_loc_list (descr
, node
->label
, endname
, secname
);
13970 if (TREE_CODE (decl
) == PARM_DECL
13971 && node
== loc_list
->first
13972 && NOTE_P (node
->loc
)
13973 && strcmp (node
->label
, endname
) == 0)
13974 (*listp
)->force
= true;
13975 listp
= &(*listp
)->dw_loc_next
;
13977 if (range_across_switch
)
13979 if (GET_CODE (node
->loc
) == EXPR_LIST
)
13980 descr
= dw_sra_loc_expr (decl
, node
->loc
);
13983 initialized
= NOTE_VAR_LOCATION_STATUS (node
->loc
);
13984 varloc
= NOTE_VAR_LOCATION (node
->loc
);
13985 descr
= dw_loc_list_1 (decl
, varloc
, want_address
,
13988 gcc_assert (descr
);
13989 /* The variable has a location between NODE->LABEL and
13990 NODE->NEXT->LABEL. */
13992 endname
= node
->next
->label
;
13994 endname
= cfun
->fde
->dw_fde_second_end
;
13995 *listp
= new_loc_list (descr
,
13996 cfun
->fde
->dw_fde_second_begin
,
13998 listp
= &(*listp
)->dw_loc_next
;
14003 /* Try to avoid the overhead of a location list emitting a location
14004 expression instead, but only if we didn't have more than one
14005 location entry in the first place. If some entries were not
14006 representable, we don't want to pretend a single entry that was
14007 applies to the entire scope in which the variable is
14009 if (list
&& loc_list
->first
->next
)
14015 /* Return if the loc_list has only single element and thus can be represented
14016 as location description. */
14019 single_element_loc_list_p (dw_loc_list_ref list
)
14021 gcc_assert (!list
->dw_loc_next
|| list
->ll_symbol
);
14022 return !list
->ll_symbol
;
14025 /* To each location in list LIST add loc descr REF. */
14028 add_loc_descr_to_each (dw_loc_list_ref list
, dw_loc_descr_ref ref
)
14030 dw_loc_descr_ref copy
;
14031 add_loc_descr (&list
->expr
, ref
);
14032 list
= list
->dw_loc_next
;
14035 copy
= ggc_alloc_dw_loc_descr_node ();
14036 memcpy (copy
, ref
, sizeof (dw_loc_descr_node
));
14037 add_loc_descr (&list
->expr
, copy
);
14038 while (copy
->dw_loc_next
)
14040 dw_loc_descr_ref new_copy
= ggc_alloc_dw_loc_descr_node ();
14041 memcpy (new_copy
, copy
->dw_loc_next
, sizeof (dw_loc_descr_node
));
14042 copy
->dw_loc_next
= new_copy
;
14045 list
= list
->dw_loc_next
;
14049 /* Given two lists RET and LIST
14050 produce location list that is result of adding expression in LIST
14051 to expression in RET on each position in program.
14052 Might be destructive on both RET and LIST.
14054 TODO: We handle only simple cases of RET or LIST having at most one
14055 element. General case would inolve sorting the lists in program order
14056 and merging them that will need some additional work.
14057 Adding that will improve quality of debug info especially for SRA-ed
14061 add_loc_list (dw_loc_list_ref
*ret
, dw_loc_list_ref list
)
14070 if (!list
->dw_loc_next
)
14072 add_loc_descr_to_each (*ret
, list
->expr
);
14075 if (!(*ret
)->dw_loc_next
)
14077 add_loc_descr_to_each (list
, (*ret
)->expr
);
14081 expansion_failed (NULL_TREE
, NULL_RTX
,
14082 "Don't know how to merge two non-trivial"
14083 " location lists.\n");
14088 /* LOC is constant expression. Try a luck, look it up in constant
14089 pool and return its loc_descr of its address. */
14091 static dw_loc_descr_ref
14092 cst_pool_loc_descr (tree loc
)
14094 /* Get an RTL for this, if something has been emitted. */
14095 rtx rtl
= lookup_constant_def (loc
);
14097 if (!rtl
|| !MEM_P (rtl
))
14102 gcc_assert (GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
);
14104 /* TODO: We might get more coverage if we was actually delaying expansion
14105 of all expressions till end of compilation when constant pools are fully
14107 if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (XEXP (rtl
, 0))))
14109 expansion_failed (loc
, NULL_RTX
,
14110 "CST value in contant pool but not marked.");
14113 return mem_loc_descriptor (XEXP (rtl
, 0), get_address_mode (rtl
),
14114 GET_MODE (rtl
), VAR_INIT_STATUS_INITIALIZED
);
14117 /* Return dw_loc_list representing address of addr_expr LOC
14118 by looking for inner INDIRECT_REF expression and turning
14119 it into simple arithmetics. */
14121 static dw_loc_list_ref
14122 loc_list_for_address_of_addr_expr_of_indirect_ref (tree loc
, bool toplev
)
14125 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14126 enum machine_mode mode
;
14127 int unsignedp
, volatilep
= 0;
14128 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14130 obj
= get_inner_reference (TREE_OPERAND (loc
, 0),
14131 &bitsize
, &bitpos
, &offset
, &mode
,
14132 &unsignedp
, &volatilep
, false);
14134 if (bitpos
% BITS_PER_UNIT
)
14136 expansion_failed (loc
, NULL_RTX
, "bitfield access");
14139 if (!INDIRECT_REF_P (obj
))
14141 expansion_failed (obj
,
14142 NULL_RTX
, "no indirect ref in inner refrence");
14145 if (!offset
&& !bitpos
)
14146 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), toplev
? 2 : 1);
14148 && int_size_in_bytes (TREE_TYPE (loc
)) <= DWARF2_ADDR_SIZE
14149 && (dwarf_version
>= 4 || !dwarf_strict
))
14151 list_ret
= loc_list_from_tree (TREE_OPERAND (obj
, 0), 0);
14156 /* Variable offset. */
14157 list_ret1
= loc_list_from_tree (offset
, 0);
14158 if (list_ret1
== 0)
14160 add_loc_list (&list_ret
, list_ret1
);
14163 add_loc_descr_to_each (list_ret
,
14164 new_loc_descr (DW_OP_plus
, 0, 0));
14166 bytepos
= bitpos
/ BITS_PER_UNIT
;
14168 add_loc_descr_to_each (list_ret
,
14169 new_loc_descr (DW_OP_plus_uconst
,
14171 else if (bytepos
< 0)
14172 loc_list_plus_const (list_ret
, bytepos
);
14173 add_loc_descr_to_each (list_ret
,
14174 new_loc_descr (DW_OP_stack_value
, 0, 0));
14180 /* Generate Dwarf location list representing LOC.
14181 If WANT_ADDRESS is false, expression computing LOC will be computed
14182 If WANT_ADDRESS is 1, expression computing address of LOC will be returned
14183 if WANT_ADDRESS is 2, expression computing address useable in location
14184 will be returned (i.e. DW_OP_reg can be used
14185 to refer to register values). */
14187 static dw_loc_list_ref
14188 loc_list_from_tree (tree loc
, int want_address
)
14190 dw_loc_descr_ref ret
= NULL
, ret1
= NULL
;
14191 dw_loc_list_ref list_ret
= NULL
, list_ret1
= NULL
;
14192 int have_address
= 0;
14193 enum dwarf_location_atom op
;
14195 /* ??? Most of the time we do not take proper care for sign/zero
14196 extending the values properly. Hopefully this won't be a real
14199 switch (TREE_CODE (loc
))
14202 expansion_failed (loc
, NULL_RTX
, "ERROR_MARK");
14205 case PLACEHOLDER_EXPR
:
14206 /* This case involves extracting fields from an object to determine the
14207 position of other fields. We don't try to encode this here. The
14208 only user of this is Ada, which encodes the needed information using
14209 the names of types. */
14210 expansion_failed (loc
, NULL_RTX
, "PLACEHOLDER_EXPR");
14214 expansion_failed (loc
, NULL_RTX
, "CALL_EXPR");
14215 /* There are no opcodes for these operations. */
14218 case PREINCREMENT_EXPR
:
14219 case PREDECREMENT_EXPR
:
14220 case POSTINCREMENT_EXPR
:
14221 case POSTDECREMENT_EXPR
:
14222 expansion_failed (loc
, NULL_RTX
, "PRE/POST INDCREMENT/DECREMENT");
14223 /* There are no opcodes for these operations. */
14227 /* If we already want an address, see if there is INDIRECT_REF inside
14228 e.g. for &this->field. */
14231 list_ret
= loc_list_for_address_of_addr_expr_of_indirect_ref
14232 (loc
, want_address
== 2);
14235 else if (decl_address_ip_invariant_p (TREE_OPERAND (loc
, 0))
14236 && (ret
= cst_pool_loc_descr (loc
)))
14239 /* Otherwise, process the argument and look for the address. */
14240 if (!list_ret
&& !ret
)
14241 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 1);
14245 expansion_failed (loc
, NULL_RTX
, "need address of ADDR_EXPR");
14251 if (DECL_THREAD_LOCAL_P (loc
))
14254 enum dwarf_location_atom tls_op
;
14255 enum dtprel_bool dtprel
= dtprel_false
;
14257 if (targetm
.have_tls
)
14259 /* If this is not defined, we have no way to emit the
14261 if (!targetm
.asm_out
.output_dwarf_dtprel
)
14264 /* The way DW_OP_GNU_push_tls_address is specified, we
14265 can only look up addresses of objects in the current
14266 module. We used DW_OP_addr as first op, but that's
14267 wrong, because DW_OP_addr is relocated by the debug
14268 info consumer, while DW_OP_GNU_push_tls_address
14269 operand shouldn't be. */
14270 if (DECL_EXTERNAL (loc
) && !targetm
.binds_local_p (loc
))
14272 dtprel
= dtprel_true
;
14273 tls_op
= DW_OP_GNU_push_tls_address
;
14277 if (!targetm
.emutls
.debug_form_tls_address
14278 || !(dwarf_version
>= 3 || !dwarf_strict
))
14280 /* We stuffed the control variable into the DECL_VALUE_EXPR
14281 to signal (via DECL_HAS_VALUE_EXPR_P) that the decl should
14282 no longer appear in gimple code. We used the control
14283 variable in specific so that we could pick it up here. */
14284 loc
= DECL_VALUE_EXPR (loc
);
14285 tls_op
= DW_OP_form_tls_address
;
14288 rtl
= rtl_for_decl_location (loc
);
14289 if (rtl
== NULL_RTX
)
14294 rtl
= XEXP (rtl
, 0);
14295 if (! CONSTANT_P (rtl
))
14298 ret
= new_addr_loc_descr (rtl
, dtprel
);
14299 ret1
= new_loc_descr (tls_op
, 0, 0);
14300 add_loc_descr (&ret
, ret1
);
14309 if (DECL_HAS_VALUE_EXPR_P (loc
))
14310 return loc_list_from_tree (DECL_VALUE_EXPR (loc
),
14314 case FUNCTION_DECL
:
14317 var_loc_list
*loc_list
= lookup_decl_loc (loc
);
14319 if (loc_list
&& loc_list
->first
)
14321 list_ret
= dw_loc_list (loc_list
, loc
, want_address
);
14322 have_address
= want_address
!= 0;
14325 rtl
= rtl_for_decl_location (loc
);
14326 if (rtl
== NULL_RTX
)
14328 expansion_failed (loc
, NULL_RTX
, "DECL has no RTL");
14331 else if (CONST_INT_P (rtl
))
14333 HOST_WIDE_INT val
= INTVAL (rtl
);
14334 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14335 val
&= GET_MODE_MASK (DECL_MODE (loc
));
14336 ret
= int_loc_descriptor (val
);
14338 else if (GET_CODE (rtl
) == CONST_STRING
)
14340 expansion_failed (loc
, NULL_RTX
, "CONST_STRING");
14343 else if (CONSTANT_P (rtl
) && const_ok_for_output (rtl
))
14344 ret
= new_addr_loc_descr (rtl
, dtprel_false
);
14347 enum machine_mode mode
, mem_mode
;
14349 /* Certain constructs can only be represented at top-level. */
14350 if (want_address
== 2)
14352 ret
= loc_descriptor (rtl
, VOIDmode
,
14353 VAR_INIT_STATUS_INITIALIZED
);
14358 mode
= GET_MODE (rtl
);
14359 mem_mode
= VOIDmode
;
14363 mode
= get_address_mode (rtl
);
14364 rtl
= XEXP (rtl
, 0);
14367 ret
= mem_loc_descriptor (rtl
, mode
, mem_mode
,
14368 VAR_INIT_STATUS_INITIALIZED
);
14371 expansion_failed (loc
, rtl
,
14372 "failed to produce loc descriptor for rtl");
14379 if (!integer_zerop (TREE_OPERAND (loc
, 1)))
14383 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14387 case COMPOUND_EXPR
:
14388 return loc_list_from_tree (TREE_OPERAND (loc
, 1), want_address
);
14391 case VIEW_CONVERT_EXPR
:
14394 return loc_list_from_tree (TREE_OPERAND (loc
, 0), want_address
);
14396 case COMPONENT_REF
:
14397 case BIT_FIELD_REF
:
14399 case ARRAY_RANGE_REF
:
14400 case REALPART_EXPR
:
14401 case IMAGPART_EXPR
:
14404 HOST_WIDE_INT bitsize
, bitpos
, bytepos
;
14405 enum machine_mode mode
;
14406 int unsignedp
, volatilep
= 0;
14408 obj
= get_inner_reference (loc
, &bitsize
, &bitpos
, &offset
, &mode
,
14409 &unsignedp
, &volatilep
, false);
14411 gcc_assert (obj
!= loc
);
14413 list_ret
= loc_list_from_tree (obj
,
14415 && !bitpos
&& !offset
? 2 : 1);
14416 /* TODO: We can extract value of the small expression via shifting even
14417 for nonzero bitpos. */
14420 if (bitpos
% BITS_PER_UNIT
!= 0 || bitsize
% BITS_PER_UNIT
!= 0)
14422 expansion_failed (loc
, NULL_RTX
,
14423 "bitfield access");
14427 if (offset
!= NULL_TREE
)
14429 /* Variable offset. */
14430 list_ret1
= loc_list_from_tree (offset
, 0);
14431 if (list_ret1
== 0)
14433 add_loc_list (&list_ret
, list_ret1
);
14436 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus
, 0, 0));
14439 bytepos
= bitpos
/ BITS_PER_UNIT
;
14441 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_plus_uconst
, bytepos
, 0));
14442 else if (bytepos
< 0)
14443 loc_list_plus_const (list_ret
, bytepos
);
14450 if ((want_address
|| !tree_fits_shwi_p (loc
))
14451 && (ret
= cst_pool_loc_descr (loc
)))
14453 else if (want_address
== 2
14454 && tree_fits_shwi_p (loc
)
14455 && (ret
= address_of_int_loc_descriptor
14456 (int_size_in_bytes (TREE_TYPE (loc
)),
14457 tree_to_shwi (loc
))))
14459 else if (tree_fits_shwi_p (loc
))
14460 ret
= int_loc_descriptor (tree_to_shwi (loc
));
14463 expansion_failed (loc
, NULL_RTX
,
14464 "Integer operand is not host integer");
14473 if ((ret
= cst_pool_loc_descr (loc
)))
14476 /* We can construct small constants here using int_loc_descriptor. */
14477 expansion_failed (loc
, NULL_RTX
,
14478 "constructor or constant not in constant pool");
14481 case TRUTH_AND_EXPR
:
14482 case TRUTH_ANDIF_EXPR
:
14487 case TRUTH_XOR_EXPR
:
14492 case TRUTH_OR_EXPR
:
14493 case TRUTH_ORIF_EXPR
:
14498 case FLOOR_DIV_EXPR
:
14499 case CEIL_DIV_EXPR
:
14500 case ROUND_DIV_EXPR
:
14501 case TRUNC_DIV_EXPR
:
14502 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14511 case FLOOR_MOD_EXPR
:
14512 case CEIL_MOD_EXPR
:
14513 case ROUND_MOD_EXPR
:
14514 case TRUNC_MOD_EXPR
:
14515 if (TYPE_UNSIGNED (TREE_TYPE (loc
)))
14520 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14521 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14522 if (list_ret
== 0 || list_ret1
== 0)
14525 add_loc_list (&list_ret
, list_ret1
);
14528 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14529 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_over
, 0, 0));
14530 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_div
, 0, 0));
14531 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_mul
, 0, 0));
14532 add_loc_descr_to_each (list_ret
, new_loc_descr (DW_OP_minus
, 0, 0));
14544 op
= (TYPE_UNSIGNED (TREE_TYPE (loc
)) ? DW_OP_shr
: DW_OP_shra
);
14547 case POINTER_PLUS_EXPR
:
14549 if (tree_fits_shwi_p (TREE_OPERAND (loc
, 1)))
14551 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14555 loc_list_plus_const (list_ret
, tree_to_shwi (TREE_OPERAND (loc
, 1)));
14563 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14570 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14577 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14584 if (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc
, 0))))
14599 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14600 list_ret1
= loc_list_from_tree (TREE_OPERAND (loc
, 1), 0);
14601 if (list_ret
== 0 || list_ret1
== 0)
14604 add_loc_list (&list_ret
, list_ret1
);
14607 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14610 case TRUTH_NOT_EXPR
:
14624 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14628 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, 0, 0));
14634 const enum tree_code code
=
14635 TREE_CODE (loc
) == MIN_EXPR
? GT_EXPR
: LT_EXPR
;
14637 loc
= build3 (COND_EXPR
, TREE_TYPE (loc
),
14638 build2 (code
, integer_type_node
,
14639 TREE_OPERAND (loc
, 0), TREE_OPERAND (loc
, 1)),
14640 TREE_OPERAND (loc
, 1), TREE_OPERAND (loc
, 0));
14643 /* ... fall through ... */
14647 dw_loc_descr_ref lhs
14648 = loc_descriptor_from_tree (TREE_OPERAND (loc
, 1), 0);
14649 dw_loc_list_ref rhs
14650 = loc_list_from_tree (TREE_OPERAND (loc
, 2), 0);
14651 dw_loc_descr_ref bra_node
, jump_node
, tmp
;
14653 list_ret
= loc_list_from_tree (TREE_OPERAND (loc
, 0), 0);
14654 if (list_ret
== 0 || lhs
== 0 || rhs
== 0)
14657 bra_node
= new_loc_descr (DW_OP_bra
, 0, 0);
14658 add_loc_descr_to_each (list_ret
, bra_node
);
14660 add_loc_list (&list_ret
, rhs
);
14661 jump_node
= new_loc_descr (DW_OP_skip
, 0, 0);
14662 add_loc_descr_to_each (list_ret
, jump_node
);
14664 add_loc_descr_to_each (list_ret
, lhs
);
14665 bra_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14666 bra_node
->dw_loc_oprnd1
.v
.val_loc
= lhs
;
14668 /* ??? Need a node to point the skip at. Use a nop. */
14669 tmp
= new_loc_descr (DW_OP_nop
, 0, 0);
14670 add_loc_descr_to_each (list_ret
, tmp
);
14671 jump_node
->dw_loc_oprnd1
.val_class
= dw_val_class_loc
;
14672 jump_node
->dw_loc_oprnd1
.v
.val_loc
= tmp
;
14676 case FIX_TRUNC_EXPR
:
14680 /* Leave front-end specific codes as simply unknown. This comes
14681 up, for instance, with the C STMT_EXPR. */
14682 if ((unsigned int) TREE_CODE (loc
)
14683 >= (unsigned int) LAST_AND_UNUSED_TREE_CODE
)
14685 expansion_failed (loc
, NULL_RTX
,
14686 "language specific tree node");
14690 #ifdef ENABLE_CHECKING
14691 /* Otherwise this is a generic code; we should just lists all of
14692 these explicitly. We forgot one. */
14693 gcc_unreachable ();
14695 /* In a release build, we want to degrade gracefully: better to
14696 generate incomplete debugging information than to crash. */
14701 if (!ret
&& !list_ret
)
14704 if (want_address
== 2 && !have_address
14705 && (dwarf_version
>= 4 || !dwarf_strict
))
14707 if (int_size_in_bytes (TREE_TYPE (loc
)) > DWARF2_ADDR_SIZE
)
14709 expansion_failed (loc
, NULL_RTX
,
14710 "DWARF address size mismatch");
14714 add_loc_descr (&ret
, new_loc_descr (DW_OP_stack_value
, 0, 0));
14716 add_loc_descr_to_each (list_ret
,
14717 new_loc_descr (DW_OP_stack_value
, 0, 0));
14720 /* Show if we can't fill the request for an address. */
14721 if (want_address
&& !have_address
)
14723 expansion_failed (loc
, NULL_RTX
,
14724 "Want address and only have value");
14728 gcc_assert (!ret
|| !list_ret
);
14730 /* If we've got an address and don't want one, dereference. */
14731 if (!want_address
&& have_address
)
14733 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (loc
));
14735 if (size
> DWARF2_ADDR_SIZE
|| size
== -1)
14737 expansion_failed (loc
, NULL_RTX
,
14738 "DWARF address size mismatch");
14741 else if (size
== DWARF2_ADDR_SIZE
)
14744 op
= DW_OP_deref_size
;
14747 add_loc_descr (&ret
, new_loc_descr (op
, size
, 0));
14749 add_loc_descr_to_each (list_ret
, new_loc_descr (op
, size
, 0));
14752 list_ret
= new_loc_list (ret
, NULL
, NULL
, NULL
);
14757 /* Same as above but return only single location expression. */
14758 static dw_loc_descr_ref
14759 loc_descriptor_from_tree (tree loc
, int want_address
)
14761 dw_loc_list_ref ret
= loc_list_from_tree (loc
, want_address
);
14764 if (ret
->dw_loc_next
)
14766 expansion_failed (loc
, NULL_RTX
,
14767 "Location list where only loc descriptor needed");
14773 /* Given a value, round it up to the lowest multiple of `boundary'
14774 which is not less than the value itself. */
14776 static inline HOST_WIDE_INT
14777 ceiling (HOST_WIDE_INT value
, unsigned int boundary
)
14779 return (((value
+ boundary
- 1) / boundary
) * boundary
);
14782 /* Given a pointer to what is assumed to be a FIELD_DECL node, return a
14783 pointer to the declared type for the relevant field variable, or return
14784 `integer_type_node' if the given node turns out to be an
14785 ERROR_MARK node. */
14788 field_type (const_tree decl
)
14792 if (TREE_CODE (decl
) == ERROR_MARK
)
14793 return integer_type_node
;
14795 type
= DECL_BIT_FIELD_TYPE (decl
);
14796 if (type
== NULL_TREE
)
14797 type
= TREE_TYPE (decl
);
14802 /* Given a pointer to a tree node, return the alignment in bits for
14803 it, or else return BITS_PER_WORD if the node actually turns out to
14804 be an ERROR_MARK node. */
14806 static inline unsigned
14807 simple_type_align_in_bits (const_tree type
)
14809 return (TREE_CODE (type
) != ERROR_MARK
) ? TYPE_ALIGN (type
) : BITS_PER_WORD
;
14812 static inline unsigned
14813 simple_decl_align_in_bits (const_tree decl
)
14815 return (TREE_CODE (decl
) != ERROR_MARK
) ? DECL_ALIGN (decl
) : BITS_PER_WORD
;
14818 /* Return the result of rounding T up to ALIGN. */
14820 static inline offset_int
14821 round_up_to_align (const offset_int
&t
, unsigned int align
)
14823 return wi::udiv_trunc (t
+ align
- 1, align
) * align
;
14826 /* Given a pointer to a FIELD_DECL, compute and return the byte offset of the
14827 lowest addressed byte of the "containing object" for the given FIELD_DECL,
14828 or return 0 if we are unable to determine what that offset is, either
14829 because the argument turns out to be a pointer to an ERROR_MARK node, or
14830 because the offset is actually variable. (We can't handle the latter case
14833 static HOST_WIDE_INT
14834 field_byte_offset (const_tree decl
)
14836 offset_int object_offset_in_bits
;
14837 offset_int object_offset_in_bytes
;
14838 offset_int bitpos_int
;
14840 if (TREE_CODE (decl
) == ERROR_MARK
)
14843 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
14845 /* We cannot yet cope with fields whose positions are variable, so
14846 for now, when we see such things, we simply return 0. Someday, we may
14847 be able to handle such cases, but it will be damn difficult. */
14848 if (TREE_CODE (bit_position (decl
)) != INTEGER_CST
)
14851 bitpos_int
= wi::to_offset (bit_position (decl
));
14853 #ifdef PCC_BITFIELD_TYPE_MATTERS
14854 if (PCC_BITFIELD_TYPE_MATTERS
)
14857 tree field_size_tree
;
14858 offset_int deepest_bitpos
;
14859 offset_int field_size_in_bits
;
14860 unsigned int type_align_in_bits
;
14861 unsigned int decl_align_in_bits
;
14862 offset_int type_size_in_bits
;
14864 type
= field_type (decl
);
14865 type_size_in_bits
= offset_int_type_size_in_bits (type
);
14866 type_align_in_bits
= simple_type_align_in_bits (type
);
14868 field_size_tree
= DECL_SIZE (decl
);
14870 /* The size could be unspecified if there was an error, or for
14871 a flexible array member. */
14872 if (!field_size_tree
)
14873 field_size_tree
= bitsize_zero_node
;
14875 /* If the size of the field is not constant, use the type size. */
14876 if (TREE_CODE (field_size_tree
) == INTEGER_CST
)
14877 field_size_in_bits
= wi::to_offset (field_size_tree
);
14879 field_size_in_bits
= type_size_in_bits
;
14881 decl_align_in_bits
= simple_decl_align_in_bits (decl
);
14883 /* The GCC front-end doesn't make any attempt to keep track of the
14884 starting bit offset (relative to the start of the containing
14885 structure type) of the hypothetical "containing object" for a
14886 bit-field. Thus, when computing the byte offset value for the
14887 start of the "containing object" of a bit-field, we must deduce
14888 this information on our own. This can be rather tricky to do in
14889 some cases. For example, handling the following structure type
14890 definition when compiling for an i386/i486 target (which only
14891 aligns long long's to 32-bit boundaries) can be very tricky:
14893 struct S { int field1; long long field2:31; };
14895 Fortunately, there is a simple rule-of-thumb which can be used
14896 in such cases. When compiling for an i386/i486, GCC will
14897 allocate 8 bytes for the structure shown above. It decides to
14898 do this based upon one simple rule for bit-field allocation.
14899 GCC allocates each "containing object" for each bit-field at
14900 the first (i.e. lowest addressed) legitimate alignment boundary
14901 (based upon the required minimum alignment for the declared
14902 type of the field) which it can possibly use, subject to the
14903 condition that there is still enough available space remaining
14904 in the containing object (when allocated at the selected point)
14905 to fully accommodate all of the bits of the bit-field itself.
14907 This simple rule makes it obvious why GCC allocates 8 bytes for
14908 each object of the structure type shown above. When looking
14909 for a place to allocate the "containing object" for `field2',
14910 the compiler simply tries to allocate a 64-bit "containing
14911 object" at each successive 32-bit boundary (starting at zero)
14912 until it finds a place to allocate that 64- bit field such that
14913 at least 31 contiguous (and previously unallocated) bits remain
14914 within that selected 64 bit field. (As it turns out, for the
14915 example above, the compiler finds it is OK to allocate the
14916 "containing object" 64-bit field at bit-offset zero within the
14919 Here we attempt to work backwards from the limited set of facts
14920 we're given, and we try to deduce from those facts, where GCC
14921 must have believed that the containing object started (within
14922 the structure type). The value we deduce is then used (by the
14923 callers of this routine) to generate DW_AT_location and
14924 DW_AT_bit_offset attributes for fields (both bit-fields and, in
14925 the case of DW_AT_location, regular fields as well). */
14927 /* Figure out the bit-distance from the start of the structure to
14928 the "deepest" bit of the bit-field. */
14929 deepest_bitpos
= bitpos_int
+ field_size_in_bits
;
14931 /* This is the tricky part. Use some fancy footwork to deduce
14932 where the lowest addressed bit of the containing object must
14934 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14936 /* Round up to type_align by default. This works best for
14938 object_offset_in_bits
14939 = round_up_to_align (object_offset_in_bits
, type_align_in_bits
);
14941 if (wi::gtu_p (object_offset_in_bits
, bitpos_int
))
14943 object_offset_in_bits
= deepest_bitpos
- type_size_in_bits
;
14945 /* Round up to decl_align instead. */
14946 object_offset_in_bits
14947 = round_up_to_align (object_offset_in_bits
, decl_align_in_bits
);
14951 #endif /* PCC_BITFIELD_TYPE_MATTERS */
14952 object_offset_in_bits
= bitpos_int
;
14954 object_offset_in_bytes
14955 = wi::lrshift (object_offset_in_bits
, LOG2_BITS_PER_UNIT
);
14956 return object_offset_in_bytes
.to_shwi ();
14959 /* The following routines define various Dwarf attributes and any data
14960 associated with them. */
14962 /* Add a location description attribute value to a DIE.
14964 This emits location attributes suitable for whole variables and
14965 whole parameters. Note that the location attributes for struct fields are
14966 generated by the routine `data_member_location_attribute' below. */
14969 add_AT_location_description (dw_die_ref die
, enum dwarf_attribute attr_kind
,
14970 dw_loc_list_ref descr
)
14974 if (single_element_loc_list_p (descr
))
14975 add_AT_loc (die
, attr_kind
, descr
->expr
);
14977 add_AT_loc_list (die
, attr_kind
, descr
);
14980 /* Add DW_AT_accessibility attribute to DIE if needed. */
14983 add_accessibility_attribute (dw_die_ref die
, tree decl
)
14985 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
14986 children, otherwise the default is DW_ACCESS_public. In DWARF2
14987 the default has always been DW_ACCESS_public. */
14988 if (TREE_PROTECTED (decl
))
14989 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
14990 else if (TREE_PRIVATE (decl
))
14992 if (dwarf_version
== 2
14993 || die
->die_parent
== NULL
14994 || die
->die_parent
->die_tag
!= DW_TAG_class_type
)
14995 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
14997 else if (dwarf_version
> 2
14999 && die
->die_parent
->die_tag
== DW_TAG_class_type
)
15000 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
15003 /* Attach the specialized form of location attribute used for data members of
15004 struct and union types. In the special case of a FIELD_DECL node which
15005 represents a bit-field, the "offset" part of this special location
15006 descriptor must indicate the distance in bytes from the lowest-addressed
15007 byte of the containing struct or union type to the lowest-addressed byte of
15008 the "containing object" for the bit-field. (See the `field_byte_offset'
15011 For any given bit-field, the "containing object" is a hypothetical object
15012 (of some integral or enum type) within which the given bit-field lives. The
15013 type of this hypothetical "containing object" is always the same as the
15014 declared type of the individual bit-field itself (for GCC anyway... the
15015 DWARF spec doesn't actually mandate this). Note that it is the size (in
15016 bytes) of the hypothetical "containing object" which will be given in the
15017 DW_AT_byte_size attribute for this bit-field. (See the
15018 `byte_size_attribute' function below.) It is also used when calculating the
15019 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute'
15020 function below.) */
15023 add_data_member_location_attribute (dw_die_ref die
, tree decl
)
15025 HOST_WIDE_INT offset
;
15026 dw_loc_descr_ref loc_descr
= 0;
15028 if (TREE_CODE (decl
) == TREE_BINFO
)
15030 /* We're working on the TAG_inheritance for a base class. */
15031 if (BINFO_VIRTUAL_P (decl
) && is_cxx ())
15033 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they
15034 aren't at a fixed offset from all (sub)objects of the same
15035 type. We need to extract the appropriate offset from our
15036 vtable. The following dwarf expression means
15038 BaseAddr = ObAddr + *((*ObAddr) - Offset)
15040 This is specific to the V3 ABI, of course. */
15042 dw_loc_descr_ref tmp
;
15044 /* Make a copy of the object address. */
15045 tmp
= new_loc_descr (DW_OP_dup
, 0, 0);
15046 add_loc_descr (&loc_descr
, tmp
);
15048 /* Extract the vtable address. */
15049 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15050 add_loc_descr (&loc_descr
, tmp
);
15052 /* Calculate the address of the offset. */
15053 offset
= tree_to_shwi (BINFO_VPTR_FIELD (decl
));
15054 gcc_assert (offset
< 0);
15056 tmp
= int_loc_descriptor (-offset
);
15057 add_loc_descr (&loc_descr
, tmp
);
15058 tmp
= new_loc_descr (DW_OP_minus
, 0, 0);
15059 add_loc_descr (&loc_descr
, tmp
);
15061 /* Extract the offset. */
15062 tmp
= new_loc_descr (DW_OP_deref
, 0, 0);
15063 add_loc_descr (&loc_descr
, tmp
);
15065 /* Add it to the object address. */
15066 tmp
= new_loc_descr (DW_OP_plus
, 0, 0);
15067 add_loc_descr (&loc_descr
, tmp
);
15070 offset
= tree_to_shwi (BINFO_OFFSET (decl
));
15073 offset
= field_byte_offset (decl
);
15077 if (dwarf_version
> 2)
15079 /* Don't need to output a location expression, just the constant. */
15081 add_AT_int (die
, DW_AT_data_member_location
, offset
);
15083 add_AT_unsigned (die
, DW_AT_data_member_location
, offset
);
15088 enum dwarf_location_atom op
;
15090 /* The DWARF2 standard says that we should assume that the structure
15091 address is already on the stack, so we can specify a structure
15092 field address by using DW_OP_plus_uconst. */
15093 op
= DW_OP_plus_uconst
;
15094 loc_descr
= new_loc_descr (op
, offset
, 0);
15098 add_AT_loc (die
, DW_AT_data_member_location
, loc_descr
);
15101 /* Writes integer values to dw_vec_const array. */
15104 insert_int (HOST_WIDE_INT val
, unsigned int size
, unsigned char *dest
)
15108 *dest
++ = val
& 0xff;
15114 /* Reads integers from dw_vec_const array. Inverse of insert_int. */
15116 static HOST_WIDE_INT
15117 extract_int (const unsigned char *src
, unsigned int size
)
15119 HOST_WIDE_INT val
= 0;
15125 val
|= *--src
& 0xff;
15131 /* Writes wide_int values to dw_vec_const array. */
15134 insert_wide_int (const wide_int
&val
, unsigned char *dest
, int elt_size
)
15138 if (elt_size
<= HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
)
15140 insert_int ((HOST_WIDE_INT
) val
.elt (0), elt_size
, dest
);
15144 /* We'd have to extend this code to support odd sizes. */
15145 gcc_assert (elt_size
% (HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
) == 0);
15147 int n
= elt_size
/ (HOST_BITS_PER_WIDE_INT
/BITS_PER_UNIT
);
15149 if (WORDS_BIG_ENDIAN
)
15150 for (i
= n
- 1; i
>= 0; i
--)
15152 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15153 dest
+= sizeof (HOST_WIDE_INT
);
15156 for (i
= 0; i
< n
; i
++)
15158 insert_int ((HOST_WIDE_INT
) val
.elt (i
), sizeof (HOST_WIDE_INT
), dest
);
15159 dest
+= sizeof (HOST_WIDE_INT
);
15163 /* Writes floating point values to dw_vec_const array. */
15166 insert_float (const_rtx rtl
, unsigned char *array
)
15168 REAL_VALUE_TYPE rv
;
15172 REAL_VALUE_FROM_CONST_DOUBLE (rv
, rtl
);
15173 real_to_target (val
, &rv
, GET_MODE (rtl
));
15175 /* real_to_target puts 32-bit pieces in each long. Pack them. */
15176 for (i
= 0; i
< GET_MODE_SIZE (GET_MODE (rtl
)) / 4; i
++)
15178 insert_int (val
[i
], 4, array
);
15183 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
15184 does not have a "location" either in memory or in a register. These
15185 things can arise in GNU C when a constant is passed as an actual parameter
15186 to an inlined function. They can also arise in C++ where declared
15187 constants do not necessarily get memory "homes". */
15190 add_const_value_attribute (dw_die_ref die
, rtx rtl
)
15192 switch (GET_CODE (rtl
))
15196 HOST_WIDE_INT val
= INTVAL (rtl
);
15199 add_AT_int (die
, DW_AT_const_value
, val
);
15201 add_AT_unsigned (die
, DW_AT_const_value
, (unsigned HOST_WIDE_INT
) val
);
15205 case CONST_WIDE_INT
:
15206 add_AT_wide (die
, DW_AT_const_value
,
15207 std::make_pair (rtl
, GET_MODE (rtl
)));
15211 /* Note that a CONST_DOUBLE rtx could represent either an integer or a
15212 floating-point constant. A CONST_DOUBLE is used whenever the
15213 constant requires more than one word in order to be adequately
15216 enum machine_mode mode
= GET_MODE (rtl
);
15218 if (TARGET_SUPPORTS_WIDE_INT
== 0 && !SCALAR_FLOAT_MODE_P (mode
))
15219 add_AT_double (die
, DW_AT_const_value
,
15220 CONST_DOUBLE_HIGH (rtl
), CONST_DOUBLE_LOW (rtl
));
15223 unsigned int length
= GET_MODE_SIZE (mode
);
15224 unsigned char *array
= (unsigned char *) ggc_alloc_atomic (length
);
15226 insert_float (rtl
, array
);
15227 add_AT_vec (die
, DW_AT_const_value
, length
/ 4, 4, array
);
15234 enum machine_mode mode
= GET_MODE (rtl
);
15235 unsigned int elt_size
= GET_MODE_UNIT_SIZE (mode
);
15236 unsigned int length
= CONST_VECTOR_NUNITS (rtl
);
15237 unsigned char *array
= (unsigned char *) ggc_alloc_atomic
15238 (length
* elt_size
);
15241 enum machine_mode imode
= GET_MODE_INNER (mode
);
15243 switch (GET_MODE_CLASS (mode
))
15245 case MODE_VECTOR_INT
:
15246 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15248 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15249 insert_wide_int (std::make_pair (elt
, imode
), p
, elt_size
);
15253 case MODE_VECTOR_FLOAT
:
15254 for (i
= 0, p
= array
; i
< length
; i
++, p
+= elt_size
)
15256 rtx elt
= CONST_VECTOR_ELT (rtl
, i
);
15257 insert_float (elt
, p
);
15262 gcc_unreachable ();
15265 add_AT_vec (die
, DW_AT_const_value
, length
, elt_size
, array
);
15270 if (dwarf_version
>= 4 || !dwarf_strict
)
15272 dw_loc_descr_ref loc_result
;
15273 resolve_one_addr (&rtl
, NULL
);
15275 loc_result
= new_addr_loc_descr (rtl
, dtprel_false
);
15276 add_loc_descr (&loc_result
, new_loc_descr (DW_OP_stack_value
, 0, 0));
15277 add_AT_loc (die
, DW_AT_location
, loc_result
);
15278 vec_safe_push (used_rtx_array
, rtl
);
15284 if (CONSTANT_P (XEXP (rtl
, 0)))
15285 return add_const_value_attribute (die
, XEXP (rtl
, 0));
15288 if (!const_ok_for_output (rtl
))
15291 if (dwarf_version
>= 4 || !dwarf_strict
)
15296 /* In cases where an inlined instance of an inline function is passed
15297 the address of an `auto' variable (which is local to the caller) we
15298 can get a situation where the DECL_RTL of the artificial local
15299 variable (for the inlining) which acts as a stand-in for the
15300 corresponding formal parameter (of the inline function) will look
15301 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not
15302 exactly a compile-time constant expression, but it isn't the address
15303 of the (artificial) local variable either. Rather, it represents the
15304 *value* which the artificial local variable always has during its
15305 lifetime. We currently have no way to represent such quasi-constant
15306 values in Dwarf, so for now we just punt and generate nothing. */
15314 if (GET_CODE (XEXP (rtl
, 0)) == CONST_STRING
15315 && MEM_READONLY_P (rtl
)
15316 && GET_MODE (rtl
) == BLKmode
)
15318 add_AT_string (die
, DW_AT_const_value
, XSTR (XEXP (rtl
, 0), 0));
15324 /* No other kinds of rtx should be possible here. */
15325 gcc_unreachable ();
15330 /* Determine whether the evaluation of EXPR references any variables
15331 or functions which aren't otherwise used (and therefore may not be
15334 reference_to_unused (tree
* tp
, int * walk_subtrees
,
15335 void * data ATTRIBUTE_UNUSED
)
15337 if (! EXPR_P (*tp
) && ! CONSTANT_CLASS_P (*tp
))
15338 *walk_subtrees
= 0;
15340 if (DECL_P (*tp
) && ! TREE_PUBLIC (*tp
) && ! TREE_USED (*tp
)
15341 && ! TREE_ASM_WRITTEN (*tp
))
15343 /* ??? The C++ FE emits debug information for using decls, so
15344 putting gcc_unreachable here falls over. See PR31899. For now
15345 be conservative. */
15346 else if (!cgraph_global_info_ready
15347 && (TREE_CODE (*tp
) == VAR_DECL
|| TREE_CODE (*tp
) == FUNCTION_DECL
))
15349 else if (TREE_CODE (*tp
) == VAR_DECL
)
15351 varpool_node
*node
= varpool_get_node (*tp
);
15352 if (!node
|| !node
->definition
)
15355 else if (TREE_CODE (*tp
) == FUNCTION_DECL
15356 && (!DECL_EXTERNAL (*tp
) || DECL_DECLARED_INLINE_P (*tp
)))
15358 /* The call graph machinery must have finished analyzing,
15359 optimizing and gimplifying the CU by now.
15360 So if *TP has no call graph node associated
15361 to it, it means *TP will not be emitted. */
15362 if (!cgraph_get_node (*tp
))
15365 else if (TREE_CODE (*tp
) == STRING_CST
&& !TREE_ASM_WRITTEN (*tp
))
15371 /* Generate an RTL constant from a decl initializer INIT with decl type TYPE,
15372 for use in a later add_const_value_attribute call. */
15375 rtl_for_decl_init (tree init
, tree type
)
15377 rtx rtl
= NULL_RTX
;
15381 /* If a variable is initialized with a string constant without embedded
15382 zeros, build CONST_STRING. */
15383 if (TREE_CODE (init
) == STRING_CST
&& TREE_CODE (type
) == ARRAY_TYPE
)
15385 tree enttype
= TREE_TYPE (type
);
15386 tree domain
= TYPE_DOMAIN (type
);
15387 enum machine_mode mode
= TYPE_MODE (enttype
);
15389 if (GET_MODE_CLASS (mode
) == MODE_INT
&& GET_MODE_SIZE (mode
) == 1
15391 && integer_zerop (TYPE_MIN_VALUE (domain
))
15392 && compare_tree_int (TYPE_MAX_VALUE (domain
),
15393 TREE_STRING_LENGTH (init
) - 1) == 0
15394 && ((size_t) TREE_STRING_LENGTH (init
)
15395 == strlen (TREE_STRING_POINTER (init
)) + 1))
15397 rtl
= gen_rtx_CONST_STRING (VOIDmode
,
15398 ggc_strdup (TREE_STRING_POINTER (init
)));
15399 rtl
= gen_rtx_MEM (BLKmode
, rtl
);
15400 MEM_READONLY_P (rtl
) = 1;
15403 /* Other aggregates, and complex values, could be represented using
15405 else if (AGGREGATE_TYPE_P (type
)
15406 || (TREE_CODE (init
) == VIEW_CONVERT_EXPR
15407 && AGGREGATE_TYPE_P (TREE_TYPE (TREE_OPERAND (init
, 0))))
15408 || TREE_CODE (type
) == COMPLEX_TYPE
)
15410 /* Vectors only work if their mode is supported by the target.
15411 FIXME: generic vectors ought to work too. */
15412 else if (TREE_CODE (type
) == VECTOR_TYPE
15413 && !VECTOR_MODE_P (TYPE_MODE (type
)))
15415 /* If the initializer is something that we know will expand into an
15416 immediate RTL constant, expand it now. We must be careful not to
15417 reference variables which won't be output. */
15418 else if (initializer_constant_valid_p (init
, type
)
15419 && ! walk_tree (&init
, reference_to_unused
, NULL
, NULL
))
15421 /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if
15423 if (TREE_CODE (type
) == VECTOR_TYPE
)
15424 switch (TREE_CODE (init
))
15429 if (TREE_CONSTANT (init
))
15431 vec
<constructor_elt
, va_gc
> *elts
= CONSTRUCTOR_ELTS (init
);
15432 bool constant_p
= true;
15434 unsigned HOST_WIDE_INT ix
;
15436 /* Even when ctor is constant, it might contain non-*_CST
15437 elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
15438 belong into VECTOR_CST nodes. */
15439 FOR_EACH_CONSTRUCTOR_VALUE (elts
, ix
, value
)
15440 if (!CONSTANT_CLASS_P (value
))
15442 constant_p
= false;
15448 init
= build_vector_from_ctor (type
, elts
);
15458 rtl
= expand_expr (init
, NULL_RTX
, VOIDmode
, EXPAND_INITIALIZER
);
15460 /* If expand_expr returns a MEM, it wasn't immediate. */
15461 gcc_assert (!rtl
|| !MEM_P (rtl
));
15467 /* Generate RTL for the variable DECL to represent its location. */
15470 rtl_for_decl_location (tree decl
)
15474 /* Here we have to decide where we are going to say the parameter "lives"
15475 (as far as the debugger is concerned). We only have a couple of
15476 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL.
15478 DECL_RTL normally indicates where the parameter lives during most of the
15479 activation of the function. If optimization is enabled however, this
15480 could be either NULL or else a pseudo-reg. Both of those cases indicate
15481 that the parameter doesn't really live anywhere (as far as the code
15482 generation parts of GCC are concerned) during most of the function's
15483 activation. That will happen (for example) if the parameter is never
15484 referenced within the function.
15486 We could just generate a location descriptor here for all non-NULL
15487 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be
15488 a little nicer than that if we also consider DECL_INCOMING_RTL in cases
15489 where DECL_RTL is NULL or is a pseudo-reg.
15491 Note however that we can only get away with using DECL_INCOMING_RTL as
15492 a backup substitute for DECL_RTL in certain limited cases. In cases
15493 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl),
15494 we can be sure that the parameter was passed using the same type as it is
15495 declared to have within the function, and that its DECL_INCOMING_RTL
15496 points us to a place where a value of that type is passed.
15498 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different,
15499 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL
15500 because in these cases DECL_INCOMING_RTL points us to a value of some
15501 type which is *different* from the type of the parameter itself. Thus,
15502 if we tried to use DECL_INCOMING_RTL to generate a location attribute in
15503 such cases, the debugger would end up (for example) trying to fetch a
15504 `float' from a place which actually contains the first part of a
15505 `double'. That would lead to really incorrect and confusing
15506 output at debug-time.
15508 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL
15509 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There
15510 are a couple of exceptions however. On little-endian machines we can
15511 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is
15512 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is
15513 an integral type that is smaller than TREE_TYPE (decl). These cases arise
15514 when (on a little-endian machine) a non-prototyped function has a
15515 parameter declared to be of type `short' or `char'. In such cases,
15516 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will
15517 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the
15518 passed `int' value. If the debugger then uses that address to fetch
15519 a `short' or a `char' (on a little-endian machine) the result will be
15520 the correct data, so we allow for such exceptional cases below.
15522 Note that our goal here is to describe the place where the given formal
15523 parameter lives during most of the function's activation (i.e. between the
15524 end of the prologue and the start of the epilogue). We'll do that as best
15525 as we can. Note however that if the given formal parameter is modified
15526 sometime during the execution of the function, then a stack backtrace (at
15527 debug-time) will show the function as having been called with the *new*
15528 value rather than the value which was originally passed in. This happens
15529 rarely enough that it is not a major problem, but it *is* a problem, and
15530 I'd like to fix it.
15532 A future version of dwarf2out.c may generate two additional attributes for
15533 any given DW_TAG_formal_parameter DIE which will describe the "passed
15534 type" and the "passed location" for the given formal parameter in addition
15535 to the attributes we now generate to indicate the "declared type" and the
15536 "active location" for each parameter. This additional set of attributes
15537 could be used by debuggers for stack backtraces. Separately, note that
15538 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also.
15539 This happens (for example) for inlined-instances of inline function formal
15540 parameters which are never referenced. This really shouldn't be
15541 happening. All PARM_DECL nodes should get valid non-NULL
15542 DECL_INCOMING_RTL values. FIXME. */
15544 /* Use DECL_RTL as the "location" unless we find something better. */
15545 rtl
= DECL_RTL_IF_SET (decl
);
15547 /* When generating abstract instances, ignore everything except
15548 constants, symbols living in memory, and symbols living in
15549 fixed registers. */
15550 if (! reload_completed
)
15553 && (CONSTANT_P (rtl
)
15555 && CONSTANT_P (XEXP (rtl
, 0)))
15557 && TREE_CODE (decl
) == VAR_DECL
15558 && TREE_STATIC (decl
))))
15560 rtl
= targetm
.delegitimize_address (rtl
);
15565 else if (TREE_CODE (decl
) == PARM_DECL
)
15567 if (rtl
== NULL_RTX
15568 || is_pseudo_reg (rtl
)
15570 && is_pseudo_reg (XEXP (rtl
, 0))
15571 && DECL_INCOMING_RTL (decl
)
15572 && MEM_P (DECL_INCOMING_RTL (decl
))
15573 && GET_MODE (rtl
) == GET_MODE (DECL_INCOMING_RTL (decl
))))
15575 tree declared_type
= TREE_TYPE (decl
);
15576 tree passed_type
= DECL_ARG_TYPE (decl
);
15577 enum machine_mode dmode
= TYPE_MODE (declared_type
);
15578 enum machine_mode pmode
= TYPE_MODE (passed_type
);
15580 /* This decl represents a formal parameter which was optimized out.
15581 Note that DECL_INCOMING_RTL may be NULL in here, but we handle
15582 all cases where (rtl == NULL_RTX) just below. */
15583 if (dmode
== pmode
)
15584 rtl
= DECL_INCOMING_RTL (decl
);
15585 else if ((rtl
== NULL_RTX
|| is_pseudo_reg (rtl
))
15586 && SCALAR_INT_MODE_P (dmode
)
15587 && GET_MODE_SIZE (dmode
) <= GET_MODE_SIZE (pmode
)
15588 && DECL_INCOMING_RTL (decl
))
15590 rtx inc
= DECL_INCOMING_RTL (decl
);
15593 else if (MEM_P (inc
))
15595 if (BYTES_BIG_ENDIAN
)
15596 rtl
= adjust_address_nv (inc
, dmode
,
15597 GET_MODE_SIZE (pmode
)
15598 - GET_MODE_SIZE (dmode
));
15605 /* If the parm was passed in registers, but lives on the stack, then
15606 make a big endian correction if the mode of the type of the
15607 parameter is not the same as the mode of the rtl. */
15608 /* ??? This is the same series of checks that are made in dbxout.c before
15609 we reach the big endian correction code there. It isn't clear if all
15610 of these checks are necessary here, but keeping them all is the safe
15612 else if (MEM_P (rtl
)
15613 && XEXP (rtl
, 0) != const0_rtx
15614 && ! CONSTANT_P (XEXP (rtl
, 0))
15615 /* Not passed in memory. */
15616 && !MEM_P (DECL_INCOMING_RTL (decl
))
15617 /* Not passed by invisible reference. */
15618 && (!REG_P (XEXP (rtl
, 0))
15619 || REGNO (XEXP (rtl
, 0)) == HARD_FRAME_POINTER_REGNUM
15620 || REGNO (XEXP (rtl
, 0)) == STACK_POINTER_REGNUM
15621 #if !HARD_FRAME_POINTER_IS_ARG_POINTER
15622 || REGNO (XEXP (rtl
, 0)) == ARG_POINTER_REGNUM
15625 /* Big endian correction check. */
15626 && BYTES_BIG_ENDIAN
15627 && TYPE_MODE (TREE_TYPE (decl
)) != GET_MODE (rtl
)
15628 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)))
15631 enum machine_mode addr_mode
= get_address_mode (rtl
);
15632 int offset
= (UNITS_PER_WORD
15633 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
))));
15635 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15636 plus_constant (addr_mode
, XEXP (rtl
, 0), offset
));
15639 else if (TREE_CODE (decl
) == VAR_DECL
15642 && GET_MODE (rtl
) != TYPE_MODE (TREE_TYPE (decl
))
15643 && BYTES_BIG_ENDIAN
)
15645 enum machine_mode addr_mode
= get_address_mode (rtl
);
15646 int rsize
= GET_MODE_SIZE (GET_MODE (rtl
));
15647 int dsize
= GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl
)));
15649 /* If a variable is declared "register" yet is smaller than
15650 a register, then if we store the variable to memory, it
15651 looks like we're storing a register-sized value, when in
15652 fact we are not. We need to adjust the offset of the
15653 storage location to reflect the actual value's bytes,
15654 else gdb will not be able to display it. */
15656 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl
)),
15657 plus_constant (addr_mode
, XEXP (rtl
, 0),
15661 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant,
15662 and will have been substituted directly into all expressions that use it.
15663 C does not have such a concept, but C++ and other languages do. */
15664 if (!rtl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_INITIAL (decl
))
15665 rtl
= rtl_for_decl_init (DECL_INITIAL (decl
), TREE_TYPE (decl
));
15668 rtl
= targetm
.delegitimize_address (rtl
);
15670 /* If we don't look past the constant pool, we risk emitting a
15671 reference to a constant pool entry that isn't referenced from
15672 code, and thus is not emitted. */
15674 rtl
= avoid_constant_pool_reference (rtl
);
15676 /* Try harder to get a rtl. If this symbol ends up not being emitted
15677 in the current CU, resolve_addr will remove the expression referencing
15679 if (rtl
== NULL_RTX
15680 && TREE_CODE (decl
) == VAR_DECL
15681 && !DECL_EXTERNAL (decl
)
15682 && TREE_STATIC (decl
)
15683 && DECL_NAME (decl
)
15684 && !DECL_HARD_REGISTER (decl
)
15685 && DECL_MODE (decl
) != VOIDmode
)
15687 rtl
= make_decl_rtl_for_debug (decl
);
15689 || GET_CODE (XEXP (rtl
, 0)) != SYMBOL_REF
15690 || SYMBOL_REF_DECL (XEXP (rtl
, 0)) != decl
)
15697 /* Check whether decl is a Fortran COMMON symbol. If not, NULL_TREE is
15698 returned. If so, the decl for the COMMON block is returned, and the
15699 value is the offset into the common block for the symbol. */
15702 fortran_common (tree decl
, HOST_WIDE_INT
*value
)
15704 tree val_expr
, cvar
;
15705 enum machine_mode mode
;
15706 HOST_WIDE_INT bitsize
, bitpos
;
15708 int unsignedp
, volatilep
= 0;
15710 /* If the decl isn't a VAR_DECL, or if it isn't static, or if
15711 it does not have a value (the offset into the common area), or if it
15712 is thread local (as opposed to global) then it isn't common, and shouldn't
15713 be handled as such. */
15714 if (TREE_CODE (decl
) != VAR_DECL
15715 || !TREE_STATIC (decl
)
15716 || !DECL_HAS_VALUE_EXPR_P (decl
)
15720 val_expr
= DECL_VALUE_EXPR (decl
);
15721 if (TREE_CODE (val_expr
) != COMPONENT_REF
)
15724 cvar
= get_inner_reference (val_expr
, &bitsize
, &bitpos
, &offset
,
15725 &mode
, &unsignedp
, &volatilep
, true);
15727 if (cvar
== NULL_TREE
15728 || TREE_CODE (cvar
) != VAR_DECL
15729 || DECL_ARTIFICIAL (cvar
)
15730 || !TREE_PUBLIC (cvar
))
15734 if (offset
!= NULL
)
15736 if (!tree_fits_shwi_p (offset
))
15738 *value
= tree_to_shwi (offset
);
15741 *value
+= bitpos
/ BITS_PER_UNIT
;
15746 /* Generate *either* a DW_AT_location attribute or else a DW_AT_const_value
15747 data attribute for a variable or a parameter. We generate the
15748 DW_AT_const_value attribute only in those cases where the given variable
15749 or parameter does not have a true "location" either in memory or in a
15750 register. This can happen (for example) when a constant is passed as an
15751 actual argument in a call to an inline function. (It's possible that
15752 these things can crop up in other ways also.) Note that one type of
15753 constant value which can be passed into an inlined function is a constant
15754 pointer. This can happen for example if an actual argument in an inlined
15755 function call evaluates to a compile-time constant address.
15757 CACHE_P is true if it is worth caching the location list for DECL,
15758 so that future calls can reuse it rather than regenerate it from scratch.
15759 This is true for BLOCK_NONLOCALIZED_VARS in inlined subroutines,
15760 since we will need to refer to them each time the function is inlined. */
15763 add_location_or_const_value_attribute (dw_die_ref die
, tree decl
, bool cache_p
,
15764 enum dwarf_attribute attr
)
15767 dw_loc_list_ref list
;
15768 var_loc_list
*loc_list
;
15769 cached_dw_loc_list
*cache
;
15772 if (TREE_CODE (decl
) == ERROR_MARK
)
15775 gcc_assert (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
15776 || TREE_CODE (decl
) == RESULT_DECL
);
15778 /* Try to get some constant RTL for this decl, and use that as the value of
15781 rtl
= rtl_for_decl_location (decl
);
15782 if (rtl
&& (CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15783 && add_const_value_attribute (die
, rtl
))
15786 /* See if we have single element location list that is equivalent to
15787 a constant value. That way we are better to use add_const_value_attribute
15788 rather than expanding constant value equivalent. */
15789 loc_list
= lookup_decl_loc (decl
);
15792 && loc_list
->first
->next
== NULL
15793 && NOTE_P (loc_list
->first
->loc
)
15794 && NOTE_VAR_LOCATION (loc_list
->first
->loc
)
15795 && NOTE_VAR_LOCATION_LOC (loc_list
->first
->loc
))
15797 struct var_loc_node
*node
;
15799 node
= loc_list
->first
;
15800 rtl
= NOTE_VAR_LOCATION_LOC (node
->loc
);
15801 if (GET_CODE (rtl
) == EXPR_LIST
)
15802 rtl
= XEXP (rtl
, 0);
15803 if ((CONSTANT_P (rtl
) || GET_CODE (rtl
) == CONST_STRING
)
15804 && add_const_value_attribute (die
, rtl
))
15807 /* If this decl is from BLOCK_NONLOCALIZED_VARS, we might need its
15808 list several times. See if we've already cached the contents. */
15810 if (loc_list
== NULL
|| cached_dw_loc_list_table
== NULL
)
15814 cache
= (cached_dw_loc_list
*)
15815 htab_find_with_hash (cached_dw_loc_list_table
, decl
, DECL_UID (decl
));
15817 list
= cache
->loc_list
;
15821 list
= loc_list_from_tree (decl
, decl_by_reference_p (decl
) ? 0 : 2);
15822 /* It is usually worth caching this result if the decl is from
15823 BLOCK_NONLOCALIZED_VARS and if the list has at least two elements. */
15824 if (cache_p
&& list
&& list
->dw_loc_next
)
15826 slot
= htab_find_slot_with_hash (cached_dw_loc_list_table
, decl
,
15827 DECL_UID (decl
), INSERT
);
15828 cache
= ggc_alloc_cleared_cached_dw_loc_list ();
15829 cache
->decl_id
= DECL_UID (decl
);
15830 cache
->loc_list
= list
;
15836 add_AT_location_description (die
, attr
, list
);
15839 /* None of that worked, so it must not really have a location;
15840 try adding a constant value attribute from the DECL_INITIAL. */
15841 return tree_add_const_value_attribute_for_decl (die
, decl
);
15844 /* Add VARIABLE and DIE into deferred locations list. */
15847 defer_location (tree variable
, dw_die_ref die
)
15849 deferred_locations entry
;
15850 entry
.variable
= variable
;
15852 vec_safe_push (deferred_locations_list
, entry
);
15855 /* Helper function for tree_add_const_value_attribute. Natively encode
15856 initializer INIT into an array. Return true if successful. */
15859 native_encode_initializer (tree init
, unsigned char *array
, int size
)
15863 if (init
== NULL_TREE
)
15867 switch (TREE_CODE (init
))
15870 type
= TREE_TYPE (init
);
15871 if (TREE_CODE (type
) == ARRAY_TYPE
)
15873 tree enttype
= TREE_TYPE (type
);
15874 enum machine_mode mode
= TYPE_MODE (enttype
);
15876 if (GET_MODE_CLASS (mode
) != MODE_INT
|| GET_MODE_SIZE (mode
) != 1)
15878 if (int_size_in_bytes (type
) != size
)
15880 if (size
> TREE_STRING_LENGTH (init
))
15882 memcpy (array
, TREE_STRING_POINTER (init
),
15883 TREE_STRING_LENGTH (init
));
15884 memset (array
+ TREE_STRING_LENGTH (init
),
15885 '\0', size
- TREE_STRING_LENGTH (init
));
15888 memcpy (array
, TREE_STRING_POINTER (init
), size
);
15893 type
= TREE_TYPE (init
);
15894 if (int_size_in_bytes (type
) != size
)
15896 if (TREE_CODE (type
) == ARRAY_TYPE
)
15898 HOST_WIDE_INT min_index
;
15899 unsigned HOST_WIDE_INT cnt
;
15900 int curpos
= 0, fieldsize
;
15901 constructor_elt
*ce
;
15903 if (TYPE_DOMAIN (type
) == NULL_TREE
15904 || !tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))))
15907 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
15908 if (fieldsize
<= 0)
15911 min_index
= tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)));
15912 memset (array
, '\0', size
);
15913 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15915 tree val
= ce
->value
;
15916 tree index
= ce
->index
;
15918 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15919 pos
= (tree_to_shwi (TREE_OPERAND (index
, 0)) - min_index
)
15922 pos
= (tree_to_shwi (index
) - min_index
) * fieldsize
;
15927 if (!native_encode_initializer (val
, array
+ pos
, fieldsize
))
15930 curpos
= pos
+ fieldsize
;
15931 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
15933 int count
= tree_to_shwi (TREE_OPERAND (index
, 1))
15934 - tree_to_shwi (TREE_OPERAND (index
, 0));
15935 while (count
-- > 0)
15938 memcpy (array
+ curpos
, array
+ pos
, fieldsize
);
15939 curpos
+= fieldsize
;
15942 gcc_assert (curpos
<= size
);
15946 else if (TREE_CODE (type
) == RECORD_TYPE
15947 || TREE_CODE (type
) == UNION_TYPE
)
15949 tree field
= NULL_TREE
;
15950 unsigned HOST_WIDE_INT cnt
;
15951 constructor_elt
*ce
;
15953 if (int_size_in_bytes (type
) != size
)
15956 if (TREE_CODE (type
) == RECORD_TYPE
)
15957 field
= TYPE_FIELDS (type
);
15959 FOR_EACH_VEC_SAFE_ELT (CONSTRUCTOR_ELTS (init
), cnt
, ce
)
15961 tree val
= ce
->value
;
15962 int pos
, fieldsize
;
15964 if (ce
->index
!= 0)
15970 if (field
== NULL_TREE
|| DECL_BIT_FIELD (field
))
15973 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
15974 && TYPE_DOMAIN (TREE_TYPE (field
))
15975 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
15977 else if (DECL_SIZE_UNIT (field
) == NULL_TREE
15978 || !tree_fits_shwi_p (DECL_SIZE_UNIT (field
)))
15980 fieldsize
= tree_to_shwi (DECL_SIZE_UNIT (field
));
15981 pos
= int_byte_position (field
);
15982 gcc_assert (pos
+ fieldsize
<= size
);
15984 && !native_encode_initializer (val
, array
+ pos
, fieldsize
))
15990 case VIEW_CONVERT_EXPR
:
15991 case NON_LVALUE_EXPR
:
15992 return native_encode_initializer (TREE_OPERAND (init
, 0), array
, size
);
15994 return native_encode_expr (init
, array
, size
) == size
;
15998 /* Attach a DW_AT_const_value attribute to DIE. The value of the
15999 attribute is the const value T. */
16002 tree_add_const_value_attribute (dw_die_ref die
, tree t
)
16005 tree type
= TREE_TYPE (t
);
16008 if (!t
|| !TREE_TYPE (t
) || TREE_TYPE (t
) == error_mark_node
)
16012 gcc_assert (!DECL_P (init
));
16014 rtl
= rtl_for_decl_init (init
, type
);
16016 return add_const_value_attribute (die
, rtl
);
16017 /* If the host and target are sane, try harder. */
16018 else if (CHAR_BIT
== 8 && BITS_PER_UNIT
== 8
16019 && initializer_constant_valid_p (init
, type
))
16021 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (init
));
16022 if (size
> 0 && (int) size
== size
)
16024 unsigned char *array
= (unsigned char *)
16025 ggc_alloc_cleared_atomic (size
);
16027 if (native_encode_initializer (init
, array
, size
))
16029 add_AT_vec (die
, DW_AT_const_value
, size
, 1, array
);
16038 /* Attach a DW_AT_const_value attribute to VAR_DIE. The value of the
16039 attribute is the const value of T, where T is an integral constant
16040 variable with static storage duration
16041 (so it can't be a PARM_DECL or a RESULT_DECL). */
16044 tree_add_const_value_attribute_for_decl (dw_die_ref var_die
, tree decl
)
16048 || (TREE_CODE (decl
) != VAR_DECL
16049 && TREE_CODE (decl
) != CONST_DECL
)
16050 || (TREE_CODE (decl
) == VAR_DECL
16051 && !TREE_STATIC (decl
)))
16054 if (TREE_READONLY (decl
)
16055 && ! TREE_THIS_VOLATILE (decl
)
16056 && DECL_INITIAL (decl
))
16061 /* Don't add DW_AT_const_value if abstract origin already has one. */
16062 if (get_AT (var_die
, DW_AT_const_value
))
16065 return tree_add_const_value_attribute (var_die
, DECL_INITIAL (decl
));
16068 /* Convert the CFI instructions for the current function into a
16069 location list. This is used for DW_AT_frame_base when we targeting
16070 a dwarf2 consumer that does not support the dwarf3
16071 DW_OP_call_frame_cfa. OFFSET is a constant to be added to all CFA
16074 static dw_loc_list_ref
16075 convert_cfa_to_fb_loc_list (HOST_WIDE_INT offset
)
16079 dw_loc_list_ref list
, *list_tail
;
16081 dw_cfa_location last_cfa
, next_cfa
;
16082 const char *start_label
, *last_label
, *section
;
16083 dw_cfa_location remember
;
16086 gcc_assert (fde
!= NULL
);
16088 section
= secname_for_decl (current_function_decl
);
16092 memset (&next_cfa
, 0, sizeof (next_cfa
));
16093 next_cfa
.reg
= INVALID_REGNUM
;
16094 remember
= next_cfa
;
16096 start_label
= fde
->dw_fde_begin
;
16098 /* ??? Bald assumption that the CIE opcode list does not contain
16099 advance opcodes. */
16100 FOR_EACH_VEC_ELT (*cie_cfi_vec
, ix
, cfi
)
16101 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16103 last_cfa
= next_cfa
;
16104 last_label
= start_label
;
16106 if (fde
->dw_fde_second_begin
&& fde
->dw_fde_switch_cfi_index
== 0)
16108 /* If the first partition contained no CFI adjustments, the
16109 CIE opcodes apply to the whole first partition. */
16110 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16111 fde
->dw_fde_begin
, fde
->dw_fde_end
, section
);
16112 list_tail
=&(*list_tail
)->dw_loc_next
;
16113 start_label
= last_label
= fde
->dw_fde_second_begin
;
16116 FOR_EACH_VEC_SAFE_ELT (fde
->dw_fde_cfi
, ix
, cfi
)
16118 switch (cfi
->dw_cfi_opc
)
16120 case DW_CFA_set_loc
:
16121 case DW_CFA_advance_loc1
:
16122 case DW_CFA_advance_loc2
:
16123 case DW_CFA_advance_loc4
:
16124 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16126 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16127 start_label
, last_label
, section
);
16129 list_tail
= &(*list_tail
)->dw_loc_next
;
16130 last_cfa
= next_cfa
;
16131 start_label
= last_label
;
16133 last_label
= cfi
->dw_cfi_oprnd1
.dw_cfi_addr
;
16136 case DW_CFA_advance_loc
:
16137 /* The encoding is complex enough that we should never emit this. */
16138 gcc_unreachable ();
16141 lookup_cfa_1 (cfi
, &next_cfa
, &remember
);
16144 if (ix
+ 1 == fde
->dw_fde_switch_cfi_index
)
16146 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16148 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16149 start_label
, last_label
, section
);
16151 list_tail
= &(*list_tail
)->dw_loc_next
;
16152 last_cfa
= next_cfa
;
16153 start_label
= last_label
;
16155 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16156 start_label
, fde
->dw_fde_end
, section
);
16157 list_tail
= &(*list_tail
)->dw_loc_next
;
16158 start_label
= last_label
= fde
->dw_fde_second_begin
;
16162 if (!cfa_equal_p (&last_cfa
, &next_cfa
))
16164 *list_tail
= new_loc_list (build_cfa_loc (&last_cfa
, offset
),
16165 start_label
, last_label
, section
);
16166 list_tail
= &(*list_tail
)->dw_loc_next
;
16167 start_label
= last_label
;
16170 *list_tail
= new_loc_list (build_cfa_loc (&next_cfa
, offset
),
16172 fde
->dw_fde_second_begin
16173 ? fde
->dw_fde_second_end
: fde
->dw_fde_end
,
16176 if (list
&& list
->dw_loc_next
)
16182 /* Compute a displacement from the "steady-state frame pointer" to the
16183 frame base (often the same as the CFA), and store it in
16184 frame_pointer_fb_offset. OFFSET is added to the displacement
16185 before the latter is negated. */
16188 compute_frame_pointer_to_fb_displacement (HOST_WIDE_INT offset
)
16192 #ifdef FRAME_POINTER_CFA_OFFSET
16193 reg
= frame_pointer_rtx
;
16194 offset
+= FRAME_POINTER_CFA_OFFSET (current_function_decl
);
16196 reg
= arg_pointer_rtx
;
16197 offset
+= ARG_POINTER_CFA_OFFSET (current_function_decl
);
16200 elim
= (ira_use_lra_p
16201 ? lra_eliminate_regs (reg
, VOIDmode
, NULL_RTX
)
16202 : eliminate_regs (reg
, VOIDmode
, NULL_RTX
));
16203 if (GET_CODE (elim
) == PLUS
)
16205 offset
+= INTVAL (XEXP (elim
, 1));
16206 elim
= XEXP (elim
, 0);
16209 frame_pointer_fb_offset
= -offset
;
16211 /* ??? AVR doesn't set up valid eliminations when there is no stack frame
16212 in which to eliminate. This is because it's stack pointer isn't
16213 directly accessible as a register within the ISA. To work around
16214 this, assume that while we cannot provide a proper value for
16215 frame_pointer_fb_offset, we won't need one either. */
16216 frame_pointer_fb_offset_valid
16217 = ((SUPPORTS_STACK_ALIGNMENT
16218 && (elim
== hard_frame_pointer_rtx
16219 || elim
== stack_pointer_rtx
))
16220 || elim
== (frame_pointer_needed
16221 ? hard_frame_pointer_rtx
16222 : stack_pointer_rtx
));
16225 /* Generate a DW_AT_name attribute given some string value to be included as
16226 the value of the attribute. */
16229 add_name_attribute (dw_die_ref die
, const char *name_string
)
16231 if (name_string
!= NULL
&& *name_string
!= 0)
16233 if (demangle_name_func
)
16234 name_string
= (*demangle_name_func
) (name_string
);
16236 add_AT_string (die
, DW_AT_name
, name_string
);
16240 /* Retrieve the descriptive type of TYPE, if any, make sure it has a
16241 DIE and attach a DW_AT_GNAT_descriptive_type attribute to the DIE
16242 of TYPE accordingly.
16244 ??? This is a temporary measure until after we're able to generate
16245 regular DWARF for the complex Ada type system. */
16248 add_gnat_descriptive_type_attribute (dw_die_ref die
, tree type
,
16249 dw_die_ref context_die
)
16252 dw_die_ref dtype_die
;
16254 if (!lang_hooks
.types
.descriptive_type
)
16257 dtype
= lang_hooks
.types
.descriptive_type (type
);
16261 dtype_die
= lookup_type_die (dtype
);
16264 gen_type_die (dtype
, context_die
);
16265 dtype_die
= lookup_type_die (dtype
);
16266 gcc_assert (dtype_die
);
16269 add_AT_die_ref (die
, DW_AT_GNAT_descriptive_type
, dtype_die
);
16272 /* Retrieve the comp_dir string suitable for use with DW_AT_comp_dir. */
16274 static const char *
16275 comp_dir_string (void)
16279 static const char *cached_wd
= NULL
;
16281 if (cached_wd
!= NULL
)
16284 wd
= get_src_pwd ();
16288 if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR
)
16292 wdlen
= strlen (wd
);
16293 wd1
= (char *) ggc_alloc_atomic (wdlen
+ 2);
16295 wd1
[wdlen
] = DIR_SEPARATOR
;
16296 wd1
[wdlen
+ 1] = 0;
16300 cached_wd
= remap_debug_filename (wd
);
16304 /* Generate a DW_AT_comp_dir attribute for DIE. */
16307 add_comp_dir_attribute (dw_die_ref die
)
16309 const char * wd
= comp_dir_string ();
16311 add_AT_string (die
, DW_AT_comp_dir
, wd
);
16314 /* Return the default for DW_AT_lower_bound, or -1 if there is not any
16318 lower_bound_default (void)
16320 switch (get_AT_unsigned (comp_unit_die (), DW_AT_language
))
16325 case DW_LANG_C_plus_plus
:
16327 case DW_LANG_ObjC_plus_plus
:
16330 case DW_LANG_Fortran77
:
16331 case DW_LANG_Fortran90
:
16332 case DW_LANG_Fortran95
:
16336 case DW_LANG_Python
:
16337 return dwarf_version
>= 4 ? 0 : -1;
16338 case DW_LANG_Ada95
:
16339 case DW_LANG_Ada83
:
16340 case DW_LANG_Cobol74
:
16341 case DW_LANG_Cobol85
:
16342 case DW_LANG_Pascal83
:
16343 case DW_LANG_Modula2
:
16345 return dwarf_version
>= 4 ? 1 : -1;
16351 /* Given a tree node describing an array bound (either lower or upper) output
16352 a representation for that bound. */
16355 add_bound_info (dw_die_ref subrange_die
, enum dwarf_attribute bound_attr
, tree bound
)
16357 switch (TREE_CODE (bound
))
16362 /* All fixed-bounds are represented by INTEGER_CST nodes. */
16365 unsigned int prec
= simple_type_size_in_bits (TREE_TYPE (bound
));
16368 /* Use the default if possible. */
16369 if (bound_attr
== DW_AT_lower_bound
16370 && tree_fits_shwi_p (bound
)
16371 && (dflt
= lower_bound_default ()) != -1
16372 && tree_to_shwi (bound
) == dflt
)
16375 /* Otherwise represent the bound as an unsigned value with the
16376 precision of its type. The precision and signedness of the
16377 type will be necessary to re-interpret it unambiguously. */
16378 else if (prec
< HOST_BITS_PER_WIDE_INT
)
16380 unsigned HOST_WIDE_INT mask
16381 = ((unsigned HOST_WIDE_INT
) 1 << prec
) - 1;
16382 add_AT_unsigned (subrange_die
, bound_attr
,
16383 TREE_INT_CST_LOW (bound
) & mask
);
16385 else if (prec
== HOST_BITS_PER_WIDE_INT
|| tree_fits_uhwi_p (bound
))
16386 add_AT_unsigned (subrange_die
, bound_attr
,
16387 TREE_INT_CST_LOW (bound
));
16389 add_AT_wide (subrange_die
, bound_attr
, bound
);
16394 case VIEW_CONVERT_EXPR
:
16395 add_bound_info (subrange_die
, bound_attr
, TREE_OPERAND (bound
, 0));
16405 dw_die_ref decl_die
= lookup_decl_die (bound
);
16407 /* ??? Can this happen, or should the variable have been bound
16408 first? Probably it can, since I imagine that we try to create
16409 the types of parameters in the order in which they exist in
16410 the list, and won't have created a forward reference to a
16411 later parameter. */
16412 if (decl_die
!= NULL
)
16414 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16422 /* Otherwise try to create a stack operation procedure to
16423 evaluate the value of the array bound. */
16425 dw_die_ref ctx
, decl_die
;
16426 dw_loc_list_ref list
;
16428 list
= loc_list_from_tree (bound
, 2);
16429 if (list
== NULL
|| single_element_loc_list_p (list
))
16431 /* If DW_AT_*bound is not a reference nor constant, it is
16432 a DWARF expression rather than location description.
16433 For that loc_list_from_tree (bound, 0) is needed.
16434 If that fails to give a single element list,
16435 fall back to outputting this as a reference anyway. */
16436 dw_loc_list_ref list2
= loc_list_from_tree (bound
, 0);
16437 if (list2
&& single_element_loc_list_p (list2
))
16439 add_AT_loc (subrange_die
, bound_attr
, list2
->expr
);
16446 if (current_function_decl
== 0)
16447 ctx
= comp_unit_die ();
16449 ctx
= lookup_decl_die (current_function_decl
);
16451 decl_die
= new_die (DW_TAG_variable
, ctx
, bound
);
16452 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
16453 add_type_attribute (decl_die
, TREE_TYPE (bound
), 1, 0, ctx
);
16454 add_AT_location_description (decl_die
, DW_AT_location
, list
);
16455 add_AT_die_ref (subrange_die
, bound_attr
, decl_die
);
16461 /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing
16462 possibly nested array subscripts in a flat sequence if COLLAPSE_P is true.
16463 Note that the block of subscript information for an array type also
16464 includes information about the element type of the given array type. */
16467 add_subscript_info (dw_die_ref type_die
, tree type
, bool collapse_p
)
16469 unsigned dimension_number
;
16471 dw_die_ref subrange_die
;
16473 for (dimension_number
= 0;
16474 TREE_CODE (type
) == ARRAY_TYPE
&& (dimension_number
== 0 || collapse_p
);
16475 type
= TREE_TYPE (type
), dimension_number
++)
16477 tree domain
= TYPE_DOMAIN (type
);
16479 if (TYPE_STRING_FLAG (type
) && is_fortran () && dimension_number
> 0)
16482 /* Arrays come in three flavors: Unspecified bounds, fixed bounds,
16483 and (in GNU C only) variable bounds. Handle all three forms
16485 subrange_die
= new_die (DW_TAG_subrange_type
, type_die
, NULL
);
16488 /* We have an array type with specified bounds. */
16489 lower
= TYPE_MIN_VALUE (domain
);
16490 upper
= TYPE_MAX_VALUE (domain
);
16492 /* Define the index type. */
16493 if (TREE_TYPE (domain
))
16495 /* ??? This is probably an Ada unnamed subrange type. Ignore the
16496 TREE_TYPE field. We can't emit debug info for this
16497 because it is an unnamed integral type. */
16498 if (TREE_CODE (domain
) == INTEGER_TYPE
16499 && TYPE_NAME (domain
) == NULL_TREE
16500 && TREE_CODE (TREE_TYPE (domain
)) == INTEGER_TYPE
16501 && TYPE_NAME (TREE_TYPE (domain
)) == NULL_TREE
)
16504 add_type_attribute (subrange_die
, TREE_TYPE (domain
), 0, 0,
16508 /* ??? If upper is NULL, the array has unspecified length,
16509 but it does have a lower bound. This happens with Fortran
16511 Since the debugger is definitely going to need to know N
16512 to produce useful results, go ahead and output the lower
16513 bound solo, and hope the debugger can cope. */
16515 add_bound_info (subrange_die
, DW_AT_lower_bound
, lower
);
16517 add_bound_info (subrange_die
, DW_AT_upper_bound
, upper
);
16520 /* Otherwise we have an array type with an unspecified length. The
16521 DWARF-2 spec does not say how to handle this; let's just leave out the
16526 /* Add a DW_AT_byte_size attribute to DIE with TREE_NODE's size. */
16529 add_byte_size_attribute (dw_die_ref die
, tree tree_node
)
16531 dw_die_ref decl_die
;
16532 HOST_WIDE_INT size
;
16534 switch (TREE_CODE (tree_node
))
16539 case ENUMERAL_TYPE
:
16542 case QUAL_UNION_TYPE
:
16543 if (TREE_CODE (TYPE_SIZE_UNIT (tree_node
)) == VAR_DECL
16544 && (decl_die
= lookup_decl_die (TYPE_SIZE_UNIT (tree_node
))))
16546 add_AT_die_ref (die
, DW_AT_byte_size
, decl_die
);
16549 size
= int_size_in_bytes (tree_node
);
16552 /* For a data member of a struct or union, the DW_AT_byte_size is
16553 generally given as the number of bytes normally allocated for an
16554 object of the *declared* type of the member itself. This is true
16555 even for bit-fields. */
16556 size
= int_size_in_bytes (field_type (tree_node
));
16559 gcc_unreachable ();
16562 /* Note that `size' might be -1 when we get to this point. If it is, that
16563 indicates that the byte size of the entity in question is variable. We
16564 have no good way of expressing this fact in Dwarf at the present time,
16565 when location description was not used by the caller code instead. */
16567 add_AT_unsigned (die
, DW_AT_byte_size
, size
);
16570 /* For a FIELD_DECL node which represents a bit-field, output an attribute
16571 which specifies the distance in bits from the highest order bit of the
16572 "containing object" for the bit-field to the highest order bit of the
16575 For any given bit-field, the "containing object" is a hypothetical object
16576 (of some integral or enum type) within which the given bit-field lives. The
16577 type of this hypothetical "containing object" is always the same as the
16578 declared type of the individual bit-field itself. The determination of the
16579 exact location of the "containing object" for a bit-field is rather
16580 complicated. It's handled by the `field_byte_offset' function (above).
16582 Note that it is the size (in bytes) of the hypothetical "containing object"
16583 which will be given in the DW_AT_byte_size attribute for this bit-field.
16584 (See `byte_size_attribute' above). */
16587 add_bit_offset_attribute (dw_die_ref die
, tree decl
)
16589 HOST_WIDE_INT object_offset_in_bytes
= field_byte_offset (decl
);
16590 tree type
= DECL_BIT_FIELD_TYPE (decl
);
16591 HOST_WIDE_INT bitpos_int
;
16592 HOST_WIDE_INT highest_order_object_bit_offset
;
16593 HOST_WIDE_INT highest_order_field_bit_offset
;
16594 HOST_WIDE_INT bit_offset
;
16596 /* Must be a field and a bit field. */
16597 gcc_assert (type
&& TREE_CODE (decl
) == FIELD_DECL
);
16599 /* We can't yet handle bit-fields whose offsets are variable, so if we
16600 encounter such things, just return without generating any attribute
16601 whatsoever. Likewise for variable or too large size. */
16602 if (! tree_fits_shwi_p (bit_position (decl
))
16603 || ! tree_fits_uhwi_p (DECL_SIZE (decl
)))
16606 bitpos_int
= int_bit_position (decl
);
16608 /* Note that the bit offset is always the distance (in bits) from the
16609 highest-order bit of the "containing object" to the highest-order bit of
16610 the bit-field itself. Since the "high-order end" of any object or field
16611 is different on big-endian and little-endian machines, the computation
16612 below must take account of these differences. */
16613 highest_order_object_bit_offset
= object_offset_in_bytes
* BITS_PER_UNIT
;
16614 highest_order_field_bit_offset
= bitpos_int
;
16616 if (! BYTES_BIG_ENDIAN
)
16618 highest_order_field_bit_offset
+= tree_to_shwi (DECL_SIZE (decl
));
16619 highest_order_object_bit_offset
+= simple_type_size_in_bits (type
);
16623 = (! BYTES_BIG_ENDIAN
16624 ? highest_order_object_bit_offset
- highest_order_field_bit_offset
16625 : highest_order_field_bit_offset
- highest_order_object_bit_offset
);
16627 if (bit_offset
< 0)
16628 add_AT_int (die
, DW_AT_bit_offset
, bit_offset
);
16630 add_AT_unsigned (die
, DW_AT_bit_offset
, (unsigned HOST_WIDE_INT
) bit_offset
);
16633 /* For a FIELD_DECL node which represents a bit field, output an attribute
16634 which specifies the length in bits of the given field. */
16637 add_bit_size_attribute (dw_die_ref die
, tree decl
)
16639 /* Must be a field and a bit field. */
16640 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
16641 && DECL_BIT_FIELD_TYPE (decl
));
16643 if (tree_fits_uhwi_p (DECL_SIZE (decl
)))
16644 add_AT_unsigned (die
, DW_AT_bit_size
, tree_to_uhwi (DECL_SIZE (decl
)));
16647 /* If the compiled language is ANSI C, then add a 'prototyped'
16648 attribute, if arg types are given for the parameters of a function. */
16651 add_prototyped_attribute (dw_die_ref die
, tree func_type
)
16653 if (get_AT_unsigned (comp_unit_die (), DW_AT_language
) == DW_LANG_C89
16654 && prototype_p (func_type
))
16655 add_AT_flag (die
, DW_AT_prototyped
, 1);
16658 /* Add an 'abstract_origin' attribute below a given DIE. The DIE is found
16659 by looking in either the type declaration or object declaration
16662 static inline dw_die_ref
16663 add_abstract_origin_attribute (dw_die_ref die
, tree origin
)
16665 dw_die_ref origin_die
= NULL
;
16667 if (TREE_CODE (origin
) != FUNCTION_DECL
)
16669 /* We may have gotten separated from the block for the inlined
16670 function, if we're in an exception handler or some such; make
16671 sure that the abstract function has been written out.
16673 Doing this for nested functions is wrong, however; functions are
16674 distinct units, and our context might not even be inline. */
16678 fn
= TYPE_STUB_DECL (fn
);
16680 fn
= decl_function_context (fn
);
16682 dwarf2out_abstract_function (fn
);
16685 if (DECL_P (origin
))
16686 origin_die
= lookup_decl_die (origin
);
16687 else if (TYPE_P (origin
))
16688 origin_die
= lookup_type_die (origin
);
16690 /* XXX: Functions that are never lowered don't always have correct block
16691 trees (in the case of java, they simply have no block tree, in some other
16692 languages). For these functions, there is nothing we can really do to
16693 output correct debug info for inlined functions in all cases. Rather
16694 than die, we'll just produce deficient debug info now, in that we will
16695 have variables without a proper abstract origin. In the future, when all
16696 functions are lowered, we should re-add a gcc_assert (origin_die)
16700 add_AT_die_ref (die
, DW_AT_abstract_origin
, origin_die
);
16704 /* We do not currently support the pure_virtual attribute. */
16707 add_pure_or_virtual_attribute (dw_die_ref die
, tree func_decl
)
16709 if (DECL_VINDEX (func_decl
))
16711 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
16713 if (tree_fits_shwi_p (DECL_VINDEX (func_decl
)))
16714 add_AT_loc (die
, DW_AT_vtable_elem_location
,
16715 new_loc_descr (DW_OP_constu
,
16716 tree_to_shwi (DECL_VINDEX (func_decl
)),
16719 /* GNU extension: Record what type this method came from originally. */
16720 if (debug_info_level
> DINFO_LEVEL_TERSE
16721 && DECL_CONTEXT (func_decl
))
16722 add_AT_die_ref (die
, DW_AT_containing_type
,
16723 lookup_type_die (DECL_CONTEXT (func_decl
)));
16727 /* Add a DW_AT_linkage_name or DW_AT_MIPS_linkage_name attribute for the
16728 given decl. This used to be a vendor extension until after DWARF 4
16729 standardized it. */
16732 add_linkage_attr (dw_die_ref die
, tree decl
)
16734 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
16736 /* Mimic what assemble_name_raw does with a leading '*'. */
16737 if (name
[0] == '*')
16740 if (dwarf_version
>= 4)
16741 add_AT_string (die
, DW_AT_linkage_name
, name
);
16743 add_AT_string (die
, DW_AT_MIPS_linkage_name
, name
);
16746 /* Add source coordinate attributes for the given decl. */
16749 add_src_coords_attributes (dw_die_ref die
, tree decl
)
16751 expanded_location s
;
16753 if (LOCATION_LOCUS (DECL_SOURCE_LOCATION (decl
)) == UNKNOWN_LOCATION
)
16755 s
= expand_location (DECL_SOURCE_LOCATION (decl
));
16756 add_AT_file (die
, DW_AT_decl_file
, lookup_filename (s
.file
));
16757 add_AT_unsigned (die
, DW_AT_decl_line
, s
.line
);
16760 /* Add DW_AT_{,MIPS_}linkage_name attribute for the given decl. */
16763 add_linkage_name (dw_die_ref die
, tree decl
)
16765 if (debug_info_level
> DINFO_LEVEL_TERSE
16766 && (TREE_CODE (decl
) == FUNCTION_DECL
|| TREE_CODE (decl
) == VAR_DECL
)
16767 && TREE_PUBLIC (decl
)
16768 && !DECL_ABSTRACT (decl
)
16769 && !(TREE_CODE (decl
) == VAR_DECL
&& DECL_REGISTER (decl
))
16770 && die
->die_tag
!= DW_TAG_member
)
16772 /* Defer until we have an assembler name set. */
16773 if (!DECL_ASSEMBLER_NAME_SET_P (decl
))
16775 limbo_die_node
*asm_name
;
16777 asm_name
= ggc_alloc_cleared_limbo_die_node ();
16778 asm_name
->die
= die
;
16779 asm_name
->created_for
= decl
;
16780 asm_name
->next
= deferred_asm_name
;
16781 deferred_asm_name
= asm_name
;
16783 else if (DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
16784 add_linkage_attr (die
, decl
);
16788 /* Add a DW_AT_name attribute and source coordinate attribute for the
16789 given decl, but only if it actually has a name. */
16792 add_name_and_src_coords_attributes (dw_die_ref die
, tree decl
)
16796 decl_name
= DECL_NAME (decl
);
16797 if (decl_name
!= NULL
&& IDENTIFIER_POINTER (decl_name
) != NULL
)
16799 const char *name
= dwarf2_name (decl
, 0);
16801 add_name_attribute (die
, name
);
16802 if (! DECL_ARTIFICIAL (decl
))
16803 add_src_coords_attributes (die
, decl
);
16805 add_linkage_name (die
, decl
);
16808 #ifdef VMS_DEBUGGING_INFO
16809 /* Get the function's name, as described by its RTL. This may be different
16810 from the DECL_NAME name used in the source file. */
16811 if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
16813 add_AT_addr (die
, DW_AT_VMS_rtnbeg_pd_address
,
16814 XEXP (DECL_RTL (decl
), 0), false);
16815 vec_safe_push (used_rtx_array
, XEXP (DECL_RTL (decl
), 0));
16817 #endif /* VMS_DEBUGGING_INFO */
16820 #ifdef VMS_DEBUGGING_INFO
16821 /* Output the debug main pointer die for VMS */
16824 dwarf2out_vms_debug_main_pointer (void)
16826 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
16829 /* Allocate the VMS debug main subprogram die. */
16830 die
= ggc_alloc_cleared_die_node ();
16831 die
->die_tag
= DW_TAG_subprogram
;
16832 add_name_attribute (die
, VMS_DEBUG_MAIN_POINTER
);
16833 ASM_GENERATE_INTERNAL_LABEL (label
, PROLOGUE_END_LABEL
,
16834 current_function_funcdef_no
);
16835 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
16837 /* Make it the first child of comp_unit_die (). */
16838 die
->die_parent
= comp_unit_die ();
16839 if (comp_unit_die ()->die_child
)
16841 die
->die_sib
= comp_unit_die ()->die_child
->die_sib
;
16842 comp_unit_die ()->die_child
->die_sib
= die
;
16846 die
->die_sib
= die
;
16847 comp_unit_die ()->die_child
= die
;
16850 #endif /* VMS_DEBUGGING_INFO */
16852 /* Push a new declaration scope. */
16855 push_decl_scope (tree scope
)
16857 vec_safe_push (decl_scope_table
, scope
);
16860 /* Pop a declaration scope. */
16863 pop_decl_scope (void)
16865 decl_scope_table
->pop ();
16868 /* walk_tree helper function for uses_local_type, below. */
16871 uses_local_type_r (tree
*tp
, int *walk_subtrees
, void *data ATTRIBUTE_UNUSED
)
16874 *walk_subtrees
= 0;
16877 tree name
= TYPE_NAME (*tp
);
16878 if (name
&& DECL_P (name
) && decl_function_context (name
))
16884 /* If TYPE involves a function-local type (including a local typedef to a
16885 non-local type), returns that type; otherwise returns NULL_TREE. */
16888 uses_local_type (tree type
)
16890 tree used
= walk_tree_without_duplicates (&type
, uses_local_type_r
, NULL
);
16894 /* Return the DIE for the scope that immediately contains this type.
16895 Non-named types that do not involve a function-local type get global
16896 scope. Named types nested in namespaces or other types get their
16897 containing scope. All other types (i.e. function-local named types) get
16898 the current active scope. */
16901 scope_die_for (tree t
, dw_die_ref context_die
)
16903 dw_die_ref scope_die
= NULL
;
16904 tree containing_scope
;
16906 /* Non-types always go in the current scope. */
16907 gcc_assert (TYPE_P (t
));
16909 /* Use the scope of the typedef, rather than the scope of the type
16911 if (TYPE_NAME (t
) && DECL_P (TYPE_NAME (t
)))
16912 containing_scope
= DECL_CONTEXT (TYPE_NAME (t
));
16914 containing_scope
= TYPE_CONTEXT (t
);
16916 /* Use the containing namespace if there is one. */
16917 if (containing_scope
&& TREE_CODE (containing_scope
) == NAMESPACE_DECL
)
16919 if (context_die
== lookup_decl_die (containing_scope
))
16921 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
16922 context_die
= get_context_die (containing_scope
);
16924 containing_scope
= NULL_TREE
;
16927 /* Ignore function type "scopes" from the C frontend. They mean that
16928 a tagged type is local to a parmlist of a function declarator, but
16929 that isn't useful to DWARF. */
16930 if (containing_scope
&& TREE_CODE (containing_scope
) == FUNCTION_TYPE
)
16931 containing_scope
= NULL_TREE
;
16933 if (SCOPE_FILE_SCOPE_P (containing_scope
))
16935 /* If T uses a local type keep it local as well, to avoid references
16936 to function-local DIEs from outside the function. */
16937 if (current_function_decl
&& uses_local_type (t
))
16938 scope_die
= context_die
;
16940 scope_die
= comp_unit_die ();
16942 else if (TYPE_P (containing_scope
))
16944 /* For types, we can just look up the appropriate DIE. */
16945 if (debug_info_level
> DINFO_LEVEL_TERSE
)
16946 scope_die
= get_context_die (containing_scope
);
16949 scope_die
= lookup_type_die_strip_naming_typedef (containing_scope
);
16950 if (scope_die
== NULL
)
16951 scope_die
= comp_unit_die ();
16955 scope_die
= context_die
;
16960 /* Returns nonzero if CONTEXT_DIE is internal to a function. */
16963 local_scope_p (dw_die_ref context_die
)
16965 for (; context_die
; context_die
= context_die
->die_parent
)
16966 if (context_die
->die_tag
== DW_TAG_inlined_subroutine
16967 || context_die
->die_tag
== DW_TAG_subprogram
)
16973 /* Returns nonzero if CONTEXT_DIE is a class. */
16976 class_scope_p (dw_die_ref context_die
)
16978 return (context_die
16979 && (context_die
->die_tag
== DW_TAG_structure_type
16980 || context_die
->die_tag
== DW_TAG_class_type
16981 || context_die
->die_tag
== DW_TAG_interface_type
16982 || context_die
->die_tag
== DW_TAG_union_type
));
16985 /* Returns nonzero if CONTEXT_DIE is a class or namespace, for deciding
16986 whether or not to treat a DIE in this context as a declaration. */
16989 class_or_namespace_scope_p (dw_die_ref context_die
)
16991 return (class_scope_p (context_die
)
16992 || (context_die
&& context_die
->die_tag
== DW_TAG_namespace
));
16995 /* Many forms of DIEs require a "type description" attribute. This
16996 routine locates the proper "type descriptor" die for the type given
16997 by 'type', and adds a DW_AT_type attribute below the given die. */
17000 add_type_attribute (dw_die_ref object_die
, tree type
, int decl_const
,
17001 int decl_volatile
, dw_die_ref context_die
)
17003 enum tree_code code
= TREE_CODE (type
);
17004 dw_die_ref type_die
= NULL
;
17006 /* ??? If this type is an unnamed subrange type of an integral, floating-point
17007 or fixed-point type, use the inner type. This is because we have no
17008 support for unnamed types in base_type_die. This can happen if this is
17009 an Ada subrange type. Correct solution is emit a subrange type die. */
17010 if ((code
== INTEGER_TYPE
|| code
== REAL_TYPE
|| code
== FIXED_POINT_TYPE
)
17011 && TREE_TYPE (type
) != 0 && TYPE_NAME (type
) == 0)
17012 type
= TREE_TYPE (type
), code
= TREE_CODE (type
);
17014 if (code
== ERROR_MARK
17015 /* Handle a special case. For functions whose return type is void, we
17016 generate *no* type attribute. (Note that no object may have type
17017 `void', so this only applies to function return types). */
17018 || code
== VOID_TYPE
)
17021 type_die
= modified_type_die (type
,
17022 decl_const
|| TYPE_READONLY (type
),
17023 decl_volatile
|| TYPE_VOLATILE (type
),
17026 if (type_die
!= NULL
)
17027 add_AT_die_ref (object_die
, DW_AT_type
, type_die
);
17030 /* Given an object die, add the calling convention attribute for the
17031 function call type. */
17033 add_calling_convention_attribute (dw_die_ref subr_die
, tree decl
)
17035 enum dwarf_calling_convention value
= DW_CC_normal
;
17037 value
= ((enum dwarf_calling_convention
)
17038 targetm
.dwarf_calling_convention (TREE_TYPE (decl
)));
17041 && !strcmp (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)), "MAIN__"))
17043 /* DWARF 2 doesn't provide a way to identify a program's source-level
17044 entry point. DW_AT_calling_convention attributes are only meant
17045 to describe functions' calling conventions. However, lacking a
17046 better way to signal the Fortran main program, we used this for
17047 a long time, following existing custom. Now, DWARF 4 has
17048 DW_AT_main_subprogram, which we add below, but some tools still
17049 rely on the old way, which we thus keep. */
17050 value
= DW_CC_program
;
17052 if (dwarf_version
>= 4 || !dwarf_strict
)
17053 add_AT_flag (subr_die
, DW_AT_main_subprogram
, 1);
17056 /* Only add the attribute if the backend requests it, and
17057 is not DW_CC_normal. */
17058 if (value
&& (value
!= DW_CC_normal
))
17059 add_AT_unsigned (subr_die
, DW_AT_calling_convention
, value
);
17062 /* Given a tree pointer to a struct, class, union, or enum type node, return
17063 a pointer to the (string) tag name for the given type, or zero if the type
17064 was declared without a tag. */
17066 static const char *
17067 type_tag (const_tree type
)
17069 const char *name
= 0;
17071 if (TYPE_NAME (type
) != 0)
17075 /* Find the IDENTIFIER_NODE for the type name. */
17076 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
17077 && !TYPE_NAMELESS (type
))
17078 t
= TYPE_NAME (type
);
17080 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to
17081 a TYPE_DECL node, regardless of whether or not a `typedef' was
17083 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
17084 && ! DECL_IGNORED_P (TYPE_NAME (type
)))
17086 /* We want to be extra verbose. Don't call dwarf_name if
17087 DECL_NAME isn't set. The default hook for decl_printable_name
17088 doesn't like that, and in this context it's correct to return
17089 0, instead of "<anonymous>" or the like. */
17090 if (DECL_NAME (TYPE_NAME (type
))
17091 && !DECL_NAMELESS (TYPE_NAME (type
)))
17092 name
= lang_hooks
.dwarf_name (TYPE_NAME (type
), 2);
17095 /* Now get the name as a string, or invent one. */
17096 if (!name
&& t
!= 0)
17097 name
= IDENTIFIER_POINTER (t
);
17100 return (name
== 0 || *name
== '\0') ? 0 : name
;
17103 /* Return the type associated with a data member, make a special check
17104 for bit field types. */
17107 member_declared_type (const_tree member
)
17109 return (DECL_BIT_FIELD_TYPE (member
)
17110 ? DECL_BIT_FIELD_TYPE (member
) : TREE_TYPE (member
));
17113 /* Get the decl's label, as described by its RTL. This may be different
17114 from the DECL_NAME name used in the source file. */
17117 static const char *
17118 decl_start_label (tree decl
)
17121 const char *fnname
;
17123 x
= DECL_RTL (decl
);
17124 gcc_assert (MEM_P (x
));
17127 gcc_assert (GET_CODE (x
) == SYMBOL_REF
);
17129 fnname
= XSTR (x
, 0);
17134 /* These routines generate the internal representation of the DIE's for
17135 the compilation unit. Debugging information is collected by walking
17136 the declaration trees passed in from dwarf2out_decl(). */
17139 gen_array_type_die (tree type
, dw_die_ref context_die
)
17141 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17142 dw_die_ref array_die
;
17144 /* GNU compilers represent multidimensional array types as sequences of one
17145 dimensional array types whose element types are themselves array types.
17146 We sometimes squish that down to a single array_type DIE with multiple
17147 subscripts in the Dwarf debugging info. The draft Dwarf specification
17148 say that we are allowed to do this kind of compression in C, because
17149 there is no difference between an array of arrays and a multidimensional
17150 array. We don't do this for Ada to remain as close as possible to the
17151 actual representation, which is especially important against the language
17152 flexibilty wrt arrays of variable size. */
17154 bool collapse_nested_arrays
= !is_ada ();
17157 /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
17158 DW_TAG_string_type doesn't have DW_AT_type attribute). */
17159 if (TYPE_STRING_FLAG (type
)
17160 && TREE_CODE (type
) == ARRAY_TYPE
17162 && TYPE_MODE (TREE_TYPE (type
)) == TYPE_MODE (char_type_node
))
17164 HOST_WIDE_INT size
;
17166 array_die
= new_die (DW_TAG_string_type
, scope_die
, type
);
17167 add_name_attribute (array_die
, type_tag (type
));
17168 equate_type_number_to_die (type
, array_die
);
17169 size
= int_size_in_bytes (type
);
17171 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17172 else if (TYPE_DOMAIN (type
) != NULL_TREE
17173 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
17174 && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))))
17176 tree szdecl
= TYPE_MAX_VALUE (TYPE_DOMAIN (type
));
17177 dw_loc_list_ref loc
= loc_list_from_tree (szdecl
, 2);
17179 size
= int_size_in_bytes (TREE_TYPE (szdecl
));
17180 if (loc
&& size
> 0)
17182 add_AT_location_description (array_die
, DW_AT_string_length
, loc
);
17183 if (size
!= DWARF2_ADDR_SIZE
)
17184 add_AT_unsigned (array_die
, DW_AT_byte_size
, size
);
17190 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17191 add_name_attribute (array_die
, type_tag (type
));
17192 equate_type_number_to_die (type
, array_die
);
17194 if (TREE_CODE (type
) == VECTOR_TYPE
)
17195 add_AT_flag (array_die
, DW_AT_GNU_vector
, 1);
17197 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17199 && TREE_CODE (type
) == ARRAY_TYPE
17200 && TREE_CODE (TREE_TYPE (type
)) == ARRAY_TYPE
17201 && !TYPE_STRING_FLAG (TREE_TYPE (type
)))
17202 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17205 /* We default the array ordering. SDB will probably do
17206 the right things even if DW_AT_ordering is not present. It's not even
17207 an issue until we start to get into multidimensional arrays anyway. If
17208 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays,
17209 then we'll have to put the DW_AT_ordering attribute back in. (But if
17210 and when we find out that we need to put these in, we will only do so
17211 for multidimensional arrays. */
17212 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_row_major
);
17215 if (TREE_CODE (type
) == VECTOR_TYPE
)
17217 /* For VECTOR_TYPEs we use an array die with appropriate bounds. */
17218 dw_die_ref subrange_die
= new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17219 add_bound_info (subrange_die
, DW_AT_lower_bound
, size_zero_node
);
17220 add_bound_info (subrange_die
, DW_AT_upper_bound
,
17221 size_int (TYPE_VECTOR_SUBPARTS (type
) - 1));
17224 add_subscript_info (array_die
, type
, collapse_nested_arrays
);
17226 /* Add representation of the type of the elements of this array type and
17227 emit the corresponding DIE if we haven't done it already. */
17228 element_type
= TREE_TYPE (type
);
17229 if (collapse_nested_arrays
)
17230 while (TREE_CODE (element_type
) == ARRAY_TYPE
)
17232 if (TYPE_STRING_FLAG (element_type
) && is_fortran ())
17234 element_type
= TREE_TYPE (element_type
);
17237 add_type_attribute (array_die
, element_type
, 0, 0, context_die
);
17239 add_gnat_descriptive_type_attribute (array_die
, type
, context_die
);
17240 if (TYPE_ARTIFICIAL (type
))
17241 add_AT_flag (array_die
, DW_AT_artificial
, 1);
17243 if (get_AT (array_die
, DW_AT_name
))
17244 add_pubtype (type
, array_die
);
17247 static dw_loc_descr_ref
17248 descr_info_loc (tree val
, tree base_decl
)
17250 HOST_WIDE_INT size
;
17251 dw_loc_descr_ref loc
, loc2
;
17252 enum dwarf_location_atom op
;
17254 if (val
== base_decl
)
17255 return new_loc_descr (DW_OP_push_object_address
, 0, 0);
17257 switch (TREE_CODE (val
))
17260 return descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17262 return loc_descriptor_from_tree (val
, 0);
17264 if (tree_fits_shwi_p (val
))
17265 return int_loc_descriptor (tree_to_shwi (val
));
17268 size
= int_size_in_bytes (TREE_TYPE (val
));
17271 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17274 if (size
== DWARF2_ADDR_SIZE
)
17275 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref
, 0, 0));
17277 add_loc_descr (&loc
, new_loc_descr (DW_OP_deref_size
, size
, 0));
17279 case POINTER_PLUS_EXPR
:
17281 if (tree_fits_uhwi_p (TREE_OPERAND (val
, 1))
17282 && tree_to_uhwi (TREE_OPERAND (val
, 1)) < 16384)
17284 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17287 loc_descr_plus_const (&loc
, tree_to_shwi (TREE_OPERAND (val
, 1)));
17293 loc
= descr_info_loc (TREE_OPERAND (val
, 0), base_decl
);
17296 loc2
= descr_info_loc (TREE_OPERAND (val
, 1), base_decl
);
17299 add_loc_descr (&loc
, loc2
);
17300 add_loc_descr (&loc2
, new_loc_descr (op
, 0, 0));
17322 add_descr_info_field (dw_die_ref die
, enum dwarf_attribute attr
,
17323 tree val
, tree base_decl
)
17325 dw_loc_descr_ref loc
;
17327 if (tree_fits_shwi_p (val
))
17329 add_AT_unsigned (die
, attr
, tree_to_shwi (val
));
17333 loc
= descr_info_loc (val
, base_decl
);
17337 add_AT_loc (die
, attr
, loc
);
17340 /* This routine generates DIE for array with hidden descriptor, details
17341 are filled into *info by a langhook. */
17344 gen_descr_array_type_die (tree type
, struct array_descr_info
*info
,
17345 dw_die_ref context_die
)
17347 dw_die_ref scope_die
= scope_die_for (type
, context_die
);
17348 dw_die_ref array_die
;
17351 array_die
= new_die (DW_TAG_array_type
, scope_die
, type
);
17352 add_name_attribute (array_die
, type_tag (type
));
17353 equate_type_number_to_die (type
, array_die
);
17355 /* For Fortran multidimensional arrays use DW_ORD_col_major ordering. */
17357 && info
->ndimensions
>= 2)
17358 add_AT_unsigned (array_die
, DW_AT_ordering
, DW_ORD_col_major
);
17360 if (info
->data_location
)
17361 add_descr_info_field (array_die
, DW_AT_data_location
, info
->data_location
,
17363 if (info
->associated
)
17364 add_descr_info_field (array_die
, DW_AT_associated
, info
->associated
,
17366 if (info
->allocated
)
17367 add_descr_info_field (array_die
, DW_AT_allocated
, info
->allocated
,
17370 for (dim
= 0; dim
< info
->ndimensions
; dim
++)
17372 dw_die_ref subrange_die
17373 = new_die (DW_TAG_subrange_type
, array_die
, NULL
);
17375 if (info
->dimen
[dim
].lower_bound
)
17377 /* If it is the default value, omit it. */
17380 if (tree_fits_shwi_p (info
->dimen
[dim
].lower_bound
)
17381 && (dflt
= lower_bound_default ()) != -1
17382 && tree_to_shwi (info
->dimen
[dim
].lower_bound
) == dflt
)
17385 add_descr_info_field (subrange_die
, DW_AT_lower_bound
,
17386 info
->dimen
[dim
].lower_bound
,
17389 if (info
->dimen
[dim
].upper_bound
)
17390 add_descr_info_field (subrange_die
, DW_AT_upper_bound
,
17391 info
->dimen
[dim
].upper_bound
,
17393 if (info
->dimen
[dim
].stride
)
17394 add_descr_info_field (subrange_die
, DW_AT_byte_stride
,
17395 info
->dimen
[dim
].stride
,
17399 gen_type_die (info
->element_type
, context_die
);
17400 add_type_attribute (array_die
, info
->element_type
, 0, 0, context_die
);
17402 if (get_AT (array_die
, DW_AT_name
))
17403 add_pubtype (type
, array_die
);
17408 gen_entry_point_die (tree decl
, dw_die_ref context_die
)
17410 tree origin
= decl_ultimate_origin (decl
);
17411 dw_die_ref decl_die
= new_die (DW_TAG_entry_point
, context_die
, decl
);
17413 if (origin
!= NULL
)
17414 add_abstract_origin_attribute (decl_die
, origin
);
17417 add_name_and_src_coords_attributes (decl_die
, decl
);
17418 add_type_attribute (decl_die
, TREE_TYPE (TREE_TYPE (decl
)),
17419 0, 0, context_die
);
17422 if (DECL_ABSTRACT (decl
))
17423 equate_decl_number_to_die (decl
, decl_die
);
17425 add_AT_lbl_id (decl_die
, DW_AT_low_pc
, decl_start_label (decl
));
17429 /* Walk through the list of incomplete types again, trying once more to
17430 emit full debugging info for them. */
17433 retry_incomplete_types (void)
17437 for (i
= vec_safe_length (incomplete_types
) - 1; i
>= 0; i
--)
17438 if (should_emit_struct_debug ((*incomplete_types
)[i
], DINFO_USAGE_DIR_USE
))
17439 gen_type_die ((*incomplete_types
)[i
], comp_unit_die ());
17442 /* Determine what tag to use for a record type. */
17444 static enum dwarf_tag
17445 record_type_tag (tree type
)
17447 if (! lang_hooks
.types
.classify_record
)
17448 return DW_TAG_structure_type
;
17450 switch (lang_hooks
.types
.classify_record (type
))
17452 case RECORD_IS_STRUCT
:
17453 return DW_TAG_structure_type
;
17455 case RECORD_IS_CLASS
:
17456 return DW_TAG_class_type
;
17458 case RECORD_IS_INTERFACE
:
17459 if (dwarf_version
>= 3 || !dwarf_strict
)
17460 return DW_TAG_interface_type
;
17461 return DW_TAG_structure_type
;
17464 gcc_unreachable ();
17468 /* Generate a DIE to represent an enumeration type. Note that these DIEs
17469 include all of the information about the enumeration values also. Each
17470 enumerated type name/value is listed as a child of the enumerated type
17474 gen_enumeration_type_die (tree type
, dw_die_ref context_die
)
17476 dw_die_ref type_die
= lookup_type_die (type
);
17478 if (type_die
== NULL
)
17480 type_die
= new_die (DW_TAG_enumeration_type
,
17481 scope_die_for (type
, context_die
), type
);
17482 equate_type_number_to_die (type
, type_die
);
17483 add_name_attribute (type_die
, type_tag (type
));
17484 if (dwarf_version
>= 4 || !dwarf_strict
)
17486 if (ENUM_IS_SCOPED (type
))
17487 add_AT_flag (type_die
, DW_AT_enum_class
, 1);
17488 if (ENUM_IS_OPAQUE (type
))
17489 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17492 else if (! TYPE_SIZE (type
))
17495 remove_AT (type_die
, DW_AT_declaration
);
17497 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the
17498 given enum type is incomplete, do not generate the DW_AT_byte_size
17499 attribute or the DW_AT_element_list attribute. */
17500 if (TYPE_SIZE (type
))
17504 TREE_ASM_WRITTEN (type
) = 1;
17505 add_byte_size_attribute (type_die
, type
);
17506 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
17508 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
17509 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
17512 /* If the first reference to this type was as the return type of an
17513 inline function, then it may not have a parent. Fix this now. */
17514 if (type_die
->die_parent
== NULL
)
17515 add_child_die (scope_die_for (type
, context_die
), type_die
);
17517 for (link
= TYPE_VALUES (type
);
17518 link
!= NULL
; link
= TREE_CHAIN (link
))
17520 dw_die_ref enum_die
= new_die (DW_TAG_enumerator
, type_die
, link
);
17521 tree value
= TREE_VALUE (link
);
17523 add_name_attribute (enum_die
,
17524 IDENTIFIER_POINTER (TREE_PURPOSE (link
)));
17526 if (TREE_CODE (value
) == CONST_DECL
)
17527 value
= DECL_INITIAL (value
);
17529 if (simple_type_size_in_bits (TREE_TYPE (value
))
17530 <= HOST_BITS_PER_WIDE_INT
|| tree_fits_shwi_p (value
))
17531 /* DWARF2 does not provide a way of indicating whether or
17532 not enumeration constants are signed or unsigned. GDB
17533 always assumes the values are signed, so we output all
17534 values as if they were signed. That means that
17535 enumeration constants with very large unsigned values
17536 will appear to have negative values in the debugger.
17538 TODO: the above comment is wrong, DWARF2 does provide
17539 DW_FORM_sdata/DW_FORM_udata to represent signed/unsigned data.
17540 This should be re-worked to use correct signed/unsigned
17541 int/double tags for all cases, instead of always treating as
17543 add_AT_int (enum_die
, DW_AT_const_value
, TREE_INT_CST_LOW (value
));
17545 /* Enumeration constants may be wider than HOST_WIDE_INT. Handle
17547 add_AT_wide (enum_die
, DW_AT_const_value
, value
);
17550 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
17551 if (TYPE_ARTIFICIAL (type
))
17552 add_AT_flag (type_die
, DW_AT_artificial
, 1);
17555 add_AT_flag (type_die
, DW_AT_declaration
, 1);
17557 add_pubtype (type
, type_die
);
17562 /* Generate a DIE to represent either a real live formal parameter decl or to
17563 represent just the type of some formal parameter position in some function
17566 Note that this routine is a bit unusual because its argument may be a
17567 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which
17568 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE
17569 node. If it's the former then this function is being called to output a
17570 DIE to represent a formal parameter object (or some inlining thereof). If
17571 it's the latter, then this function is only being called to output a
17572 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal
17573 argument type of some subprogram type.
17574 If EMIT_NAME_P is true, name and source coordinate attributes
17578 gen_formal_parameter_die (tree node
, tree origin
, bool emit_name_p
,
17579 dw_die_ref context_die
)
17581 tree node_or_origin
= node
? node
: origin
;
17582 tree ultimate_origin
;
17583 dw_die_ref parm_die
17584 = new_die (DW_TAG_formal_parameter
, context_die
, node
);
17586 switch (TREE_CODE_CLASS (TREE_CODE (node_or_origin
)))
17588 case tcc_declaration
:
17589 ultimate_origin
= decl_ultimate_origin (node_or_origin
);
17590 if (node
|| ultimate_origin
)
17591 origin
= ultimate_origin
;
17592 if (origin
!= NULL
)
17593 add_abstract_origin_attribute (parm_die
, origin
);
17594 else if (emit_name_p
)
17595 add_name_and_src_coords_attributes (parm_die
, node
);
17597 || (! DECL_ABSTRACT (node_or_origin
)
17598 && variably_modified_type_p (TREE_TYPE (node_or_origin
),
17599 decl_function_context
17600 (node_or_origin
))))
17602 tree type
= TREE_TYPE (node_or_origin
);
17603 if (decl_by_reference_p (node_or_origin
))
17604 add_type_attribute (parm_die
, TREE_TYPE (type
), 0, 0,
17607 add_type_attribute (parm_die
, type
,
17608 TREE_READONLY (node_or_origin
),
17609 TREE_THIS_VOLATILE (node_or_origin
),
17612 if (origin
== NULL
&& DECL_ARTIFICIAL (node
))
17613 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17615 if (node
&& node
!= origin
)
17616 equate_decl_number_to_die (node
, parm_die
);
17617 if (! DECL_ABSTRACT (node_or_origin
))
17618 add_location_or_const_value_attribute (parm_die
, node_or_origin
,
17619 node
== NULL
, DW_AT_location
);
17624 /* We were called with some kind of a ..._TYPE node. */
17625 add_type_attribute (parm_die
, node_or_origin
, 0, 0, context_die
);
17629 gcc_unreachable ();
17635 /* Generate and return a DW_TAG_GNU_formal_parameter_pack. Also generate
17636 children DW_TAG_formal_parameter DIEs representing the arguments of the
17639 PARM_PACK must be a function parameter pack.
17640 PACK_ARG is the first argument of the parameter pack. Its TREE_CHAIN
17641 must point to the subsequent arguments of the function PACK_ARG belongs to.
17642 SUBR_DIE is the DIE of the function PACK_ARG belongs to.
17643 If NEXT_ARG is non NULL, *NEXT_ARG is set to the function argument
17644 following the last one for which a DIE was generated. */
17647 gen_formal_parameter_pack_die (tree parm_pack
,
17649 dw_die_ref subr_die
,
17653 dw_die_ref parm_pack_die
;
17655 gcc_assert (parm_pack
17656 && lang_hooks
.function_parameter_pack_p (parm_pack
)
17659 parm_pack_die
= new_die (DW_TAG_GNU_formal_parameter_pack
, subr_die
, parm_pack
);
17660 add_src_coords_attributes (parm_pack_die
, parm_pack
);
17662 for (arg
= pack_arg
; arg
; arg
= DECL_CHAIN (arg
))
17664 if (! lang_hooks
.decls
.function_parm_expanded_from_pack_p (arg
,
17667 gen_formal_parameter_die (arg
, NULL
,
17668 false /* Don't emit name attribute. */,
17673 return parm_pack_die
;
17676 /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
17677 at the end of an (ANSI prototyped) formal parameters list. */
17680 gen_unspecified_parameters_die (tree decl_or_type
, dw_die_ref context_die
)
17682 new_die (DW_TAG_unspecified_parameters
, context_die
, decl_or_type
);
17685 /* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a
17686 DW_TAG_unspecified_parameters DIE) to represent the types of the formal
17687 parameters as specified in some function type specification (except for
17688 those which appear as part of a function *definition*). */
17691 gen_formal_types_die (tree function_or_method_type
, dw_die_ref context_die
)
17694 tree formal_type
= NULL
;
17695 tree first_parm_type
;
17698 if (TREE_CODE (function_or_method_type
) == FUNCTION_DECL
)
17700 arg
= DECL_ARGUMENTS (function_or_method_type
);
17701 function_or_method_type
= TREE_TYPE (function_or_method_type
);
17706 first_parm_type
= TYPE_ARG_TYPES (function_or_method_type
);
17708 /* Make our first pass over the list of formal parameter types and output a
17709 DW_TAG_formal_parameter DIE for each one. */
17710 for (link
= first_parm_type
; link
; )
17712 dw_die_ref parm_die
;
17714 formal_type
= TREE_VALUE (link
);
17715 if (formal_type
== void_type_node
)
17718 /* Output a (nameless) DIE to represent the formal parameter itself. */
17719 parm_die
= gen_formal_parameter_die (formal_type
, NULL
,
17720 true /* Emit name attribute. */,
17722 if (TREE_CODE (function_or_method_type
) == METHOD_TYPE
17723 && link
== first_parm_type
)
17725 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17726 if (dwarf_version
>= 3 || !dwarf_strict
)
17727 add_AT_die_ref (context_die
, DW_AT_object_pointer
, parm_die
);
17729 else if (arg
&& DECL_ARTIFICIAL (arg
))
17730 add_AT_flag (parm_die
, DW_AT_artificial
, 1);
17732 link
= TREE_CHAIN (link
);
17734 arg
= DECL_CHAIN (arg
);
17737 /* If this function type has an ellipsis, add a
17738 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */
17739 if (formal_type
!= void_type_node
)
17740 gen_unspecified_parameters_die (function_or_method_type
, context_die
);
17742 /* Make our second (and final) pass over the list of formal parameter types
17743 and output DIEs to represent those types (as necessary). */
17744 for (link
= TYPE_ARG_TYPES (function_or_method_type
);
17745 link
&& TREE_VALUE (link
);
17746 link
= TREE_CHAIN (link
))
17747 gen_type_die (TREE_VALUE (link
), context_die
);
17750 /* We want to generate the DIE for TYPE so that we can generate the
17751 die for MEMBER, which has been defined; we will need to refer back
17752 to the member declaration nested within TYPE. If we're trying to
17753 generate minimal debug info for TYPE, processing TYPE won't do the
17754 trick; we need to attach the member declaration by hand. */
17757 gen_type_die_for_member (tree type
, tree member
, dw_die_ref context_die
)
17759 gen_type_die (type
, context_die
);
17761 /* If we're trying to avoid duplicate debug info, we may not have
17762 emitted the member decl for this function. Emit it now. */
17763 if (TYPE_STUB_DECL (type
)
17764 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))
17765 && ! lookup_decl_die (member
))
17767 dw_die_ref type_die
;
17768 gcc_assert (!decl_ultimate_origin (member
));
17770 push_decl_scope (type
);
17771 type_die
= lookup_type_die_strip_naming_typedef (type
);
17772 if (TREE_CODE (member
) == FUNCTION_DECL
)
17773 gen_subprogram_die (member
, type_die
);
17774 else if (TREE_CODE (member
) == FIELD_DECL
)
17776 /* Ignore the nameless fields that are used to skip bits but handle
17777 C++ anonymous unions and structs. */
17778 if (DECL_NAME (member
) != NULL_TREE
17779 || TREE_CODE (TREE_TYPE (member
)) == UNION_TYPE
17780 || TREE_CODE (TREE_TYPE (member
)) == RECORD_TYPE
)
17782 gen_type_die (member_declared_type (member
), type_die
);
17783 gen_field_die (member
, type_die
);
17787 gen_variable_die (member
, NULL_TREE
, type_die
);
17793 /* Forward declare these functions, because they are mutually recursive
17794 with their set_block_* pairing functions. */
17795 static void set_decl_origin_self (tree
);
17796 static void set_decl_abstract_flags (tree
, int);
17798 /* Given a pointer to some BLOCK node, if the BLOCK_ABSTRACT_ORIGIN for the
17799 given BLOCK node is NULL, set the BLOCK_ABSTRACT_ORIGIN for the node so
17800 that it points to the node itself, thus indicating that the node is its
17801 own (abstract) origin. Additionally, if the BLOCK_ABSTRACT_ORIGIN for
17802 the given node is NULL, recursively descend the decl/block tree which
17803 it is the root of, and for each other ..._DECL or BLOCK node contained
17804 therein whose DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also
17805 still NULL, set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN
17806 values to point to themselves. */
17809 set_block_origin_self (tree stmt
)
17811 if (BLOCK_ABSTRACT_ORIGIN (stmt
) == NULL_TREE
)
17813 BLOCK_ABSTRACT_ORIGIN (stmt
) = stmt
;
17818 for (local_decl
= BLOCK_VARS (stmt
);
17819 local_decl
!= NULL_TREE
;
17820 local_decl
= DECL_CHAIN (local_decl
))
17821 if (! DECL_EXTERNAL (local_decl
))
17822 set_decl_origin_self (local_decl
); /* Potential recursion. */
17828 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17829 subblock
!= NULL_TREE
;
17830 subblock
= BLOCK_CHAIN (subblock
))
17831 set_block_origin_self (subblock
); /* Recurse. */
17836 /* Given a pointer to some ..._DECL node, if the DECL_ABSTRACT_ORIGIN for
17837 the given ..._DECL node is NULL, set the DECL_ABSTRACT_ORIGIN for the
17838 node to so that it points to the node itself, thus indicating that the
17839 node represents its own (abstract) origin. Additionally, if the
17840 DECL_ABSTRACT_ORIGIN for the given node is NULL, recursively descend
17841 the decl/block tree of which the given node is the root of, and for
17842 each other ..._DECL or BLOCK node contained therein whose
17843 DECL_ABSTRACT_ORIGINs or BLOCK_ABSTRACT_ORIGINs are also still NULL,
17844 set *their* DECL_ABSTRACT_ORIGIN or BLOCK_ABSTRACT_ORIGIN values to
17845 point to themselves. */
17848 set_decl_origin_self (tree decl
)
17850 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL_TREE
)
17852 DECL_ABSTRACT_ORIGIN (decl
) = decl
;
17853 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17857 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17858 DECL_ABSTRACT_ORIGIN (arg
) = arg
;
17859 if (DECL_INITIAL (decl
) != NULL_TREE
17860 && DECL_INITIAL (decl
) != error_mark_node
)
17861 set_block_origin_self (DECL_INITIAL (decl
));
17866 /* Given a pointer to some BLOCK node, and a boolean value to set the
17867 "abstract" flags to, set that value into the BLOCK_ABSTRACT flag for
17868 the given block, and for all local decls and all local sub-blocks
17869 (recursively) which are contained therein. */
17872 set_block_abstract_flags (tree stmt
, int setting
)
17878 BLOCK_ABSTRACT (stmt
) = setting
;
17880 for (local_decl
= BLOCK_VARS (stmt
);
17881 local_decl
!= NULL_TREE
;
17882 local_decl
= DECL_CHAIN (local_decl
))
17883 if (! DECL_EXTERNAL (local_decl
))
17884 set_decl_abstract_flags (local_decl
, setting
);
17886 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
17888 local_decl
= BLOCK_NONLOCALIZED_VAR (stmt
, i
);
17889 if ((TREE_CODE (local_decl
) == VAR_DECL
&& !TREE_STATIC (local_decl
))
17890 || TREE_CODE (local_decl
) == PARM_DECL
)
17891 set_decl_abstract_flags (local_decl
, setting
);
17894 for (subblock
= BLOCK_SUBBLOCKS (stmt
);
17895 subblock
!= NULL_TREE
;
17896 subblock
= BLOCK_CHAIN (subblock
))
17897 set_block_abstract_flags (subblock
, setting
);
17900 /* Given a pointer to some ..._DECL node, and a boolean value to set the
17901 "abstract" flags to, set that value into the DECL_ABSTRACT flag for the
17902 given decl, and (in the case where the decl is a FUNCTION_DECL) also
17903 set the abstract flags for all of the parameters, local vars, local
17904 blocks and sub-blocks (recursively) to the same setting. */
17907 set_decl_abstract_flags (tree decl
, int setting
)
17909 DECL_ABSTRACT (decl
) = setting
;
17910 if (TREE_CODE (decl
) == FUNCTION_DECL
)
17914 for (arg
= DECL_ARGUMENTS (decl
); arg
; arg
= DECL_CHAIN (arg
))
17915 DECL_ABSTRACT (arg
) = setting
;
17916 if (DECL_INITIAL (decl
) != NULL_TREE
17917 && DECL_INITIAL (decl
) != error_mark_node
)
17918 set_block_abstract_flags (DECL_INITIAL (decl
), setting
);
17922 /* Generate the DWARF2 info for the "abstract" instance of a function which we
17923 may later generate inlined and/or out-of-line instances of. */
17926 dwarf2out_abstract_function (tree decl
)
17928 dw_die_ref old_die
;
17932 htab_t old_decl_loc_table
;
17933 htab_t old_cached_dw_loc_list_table
;
17934 int old_call_site_count
, old_tail_call_site_count
;
17935 struct call_arg_loc_node
*old_call_arg_locations
;
17937 /* Make sure we have the actual abstract inline, not a clone. */
17938 decl
= DECL_ORIGIN (decl
);
17940 old_die
= lookup_decl_die (decl
);
17941 if (old_die
&& get_AT (old_die
, DW_AT_inline
))
17942 /* We've already generated the abstract instance. */
17945 /* We can be called while recursively when seeing block defining inlined subroutine
17946 DIE. Be sure to not clobber the outer location table nor use it or we would
17947 get locations in abstract instantces. */
17948 old_decl_loc_table
= decl_loc_table
;
17949 decl_loc_table
= NULL
;
17950 old_cached_dw_loc_list_table
= cached_dw_loc_list_table
;
17951 cached_dw_loc_list_table
= NULL
;
17952 old_call_arg_locations
= call_arg_locations
;
17953 call_arg_locations
= NULL
;
17954 old_call_site_count
= call_site_count
;
17955 call_site_count
= -1;
17956 old_tail_call_site_count
= tail_call_site_count
;
17957 tail_call_site_count
= -1;
17959 /* Be sure we've emitted the in-class declaration DIE (if any) first, so
17960 we don't get confused by DECL_ABSTRACT. */
17961 if (debug_info_level
> DINFO_LEVEL_TERSE
)
17963 context
= decl_class_context (decl
);
17965 gen_type_die_for_member
17966 (context
, decl
, decl_function_context (decl
) ? NULL
: comp_unit_die ());
17969 /* Pretend we've just finished compiling this function. */
17970 save_fn
= current_function_decl
;
17971 current_function_decl
= decl
;
17973 was_abstract
= DECL_ABSTRACT (decl
);
17974 set_decl_abstract_flags (decl
, 1);
17975 dwarf2out_decl (decl
);
17976 if (! was_abstract
)
17977 set_decl_abstract_flags (decl
, 0);
17979 current_function_decl
= save_fn
;
17980 decl_loc_table
= old_decl_loc_table
;
17981 cached_dw_loc_list_table
= old_cached_dw_loc_list_table
;
17982 call_arg_locations
= old_call_arg_locations
;
17983 call_site_count
= old_call_site_count
;
17984 tail_call_site_count
= old_tail_call_site_count
;
17987 /* Helper function of premark_used_types() which gets called through
17990 Marks the DIE of a given type in *SLOT as perennial, so it never gets
17991 marked as unused by prune_unused_types. */
17994 premark_used_types_helper (void **slot
, void *data ATTRIBUTE_UNUSED
)
17999 type
= (tree
) *slot
;
18000 die
= lookup_type_die (type
);
18002 die
->die_perennial_p
= 1;
18006 /* Helper function of premark_types_used_by_global_vars which gets called
18007 through htab_traverse.
18009 Marks the DIE of a given type in *SLOT as perennial, so it never gets
18010 marked as unused by prune_unused_types. The DIE of the type is marked
18011 only if the global variable using the type will actually be emitted. */
18014 premark_types_used_by_global_vars_helper (void **slot
,
18015 void *data ATTRIBUTE_UNUSED
)
18017 struct types_used_by_vars_entry
*entry
;
18020 entry
= (struct types_used_by_vars_entry
*) *slot
;
18021 gcc_assert (entry
->type
!= NULL
18022 && entry
->var_decl
!= NULL
);
18023 die
= lookup_type_die (entry
->type
);
18026 /* Ask cgraph if the global variable really is to be emitted.
18027 If yes, then we'll keep the DIE of ENTRY->TYPE. */
18028 varpool_node
*node
= varpool_get_node (entry
->var_decl
);
18029 if (node
&& node
->definition
)
18031 die
->die_perennial_p
= 1;
18032 /* Keep the parent DIEs as well. */
18033 while ((die
= die
->die_parent
) && die
->die_perennial_p
== 0)
18034 die
->die_perennial_p
= 1;
18040 /* Mark all members of used_types_hash as perennial. */
18043 premark_used_types (struct function
*fun
)
18045 if (fun
&& fun
->used_types_hash
)
18046 htab_traverse (fun
->used_types_hash
, premark_used_types_helper
, NULL
);
18049 /* Mark all members of types_used_by_vars_entry as perennial. */
18052 premark_types_used_by_global_vars (void)
18054 if (types_used_by_vars_hash
)
18055 htab_traverse (types_used_by_vars_hash
,
18056 premark_types_used_by_global_vars_helper
, NULL
);
18059 /* Generate a DW_TAG_GNU_call_site DIE in function DECL under SUBR_DIE
18060 for CA_LOC call arg loc node. */
18063 gen_call_site_die (tree decl
, dw_die_ref subr_die
,
18064 struct call_arg_loc_node
*ca_loc
)
18066 dw_die_ref stmt_die
= NULL
, die
;
18067 tree block
= ca_loc
->block
;
18070 && block
!= DECL_INITIAL (decl
)
18071 && TREE_CODE (block
) == BLOCK
)
18073 if (block_map
.length () > BLOCK_NUMBER (block
))
18074 stmt_die
= block_map
[BLOCK_NUMBER (block
)];
18077 block
= BLOCK_SUPERCONTEXT (block
);
18079 if (stmt_die
== NULL
)
18080 stmt_die
= subr_die
;
18081 die
= new_die (DW_TAG_GNU_call_site
, stmt_die
, NULL_TREE
);
18082 add_AT_lbl_id (die
, DW_AT_low_pc
, ca_loc
->label
);
18083 if (ca_loc
->tail_call_p
)
18084 add_AT_flag (die
, DW_AT_GNU_tail_call
, 1);
18085 if (ca_loc
->symbol_ref
)
18087 dw_die_ref tdie
= lookup_decl_die (SYMBOL_REF_DECL (ca_loc
->symbol_ref
));
18089 add_AT_die_ref (die
, DW_AT_abstract_origin
, tdie
);
18091 add_AT_addr (die
, DW_AT_abstract_origin
, ca_loc
->symbol_ref
, false);
18096 /* Generate a DIE to represent a declared function (either file-scope or
18100 gen_subprogram_die (tree decl
, dw_die_ref context_die
)
18102 tree origin
= decl_ultimate_origin (decl
);
18103 dw_die_ref subr_die
;
18105 dw_die_ref old_die
= lookup_decl_die (decl
);
18106 int declaration
= (current_function_decl
!= decl
18107 || class_or_namespace_scope_p (context_die
));
18109 premark_used_types (DECL_STRUCT_FUNCTION (decl
));
18111 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we
18112 started to generate the abstract instance of an inline, decided to output
18113 its containing class, and proceeded to emit the declaration of the inline
18114 from the member list for the class. If so, DECLARATION takes priority;
18115 we'll get back to the abstract instance when done with the class. */
18117 /* The class-scope declaration DIE must be the primary DIE. */
18118 if (origin
&& declaration
&& class_or_namespace_scope_p (context_die
))
18121 gcc_assert (!old_die
);
18124 /* Now that the C++ front end lazily declares artificial member fns, we
18125 might need to retrofit the declaration into its class. */
18126 if (!declaration
&& !origin
&& !old_die
18127 && DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
))
18128 && !class_or_namespace_scope_p (context_die
)
18129 && debug_info_level
> DINFO_LEVEL_TERSE
)
18130 old_die
= force_decl_die (decl
);
18132 if (origin
!= NULL
)
18134 gcc_assert (!declaration
|| local_scope_p (context_die
));
18136 /* Fixup die_parent for the abstract instance of a nested
18137 inline function. */
18138 if (old_die
&& old_die
->die_parent
== NULL
)
18139 add_child_die (context_die
, old_die
);
18141 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18142 add_abstract_origin_attribute (subr_die
, origin
);
18143 /* This is where the actual code for a cloned function is.
18144 Let's emit linkage name attribute for it. This helps
18145 debuggers to e.g, set breakpoints into
18146 constructors/destructors when the user asks "break
18148 add_linkage_name (subr_die
, decl
);
18152 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18153 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18155 if (!get_AT_flag (old_die
, DW_AT_declaration
)
18156 /* We can have a normal definition following an inline one in the
18157 case of redefinition of GNU C extern inlines.
18158 It seems reasonable to use AT_specification in this case. */
18159 && !get_AT (old_die
, DW_AT_inline
))
18161 /* Detect and ignore this case, where we are trying to output
18162 something we have already output. */
18166 /* If the definition comes from the same place as the declaration,
18167 maybe use the old DIE. We always want the DIE for this function
18168 that has the *_pc attributes to be under comp_unit_die so the
18169 debugger can find it. We also need to do this for abstract
18170 instances of inlines, since the spec requires the out-of-line copy
18171 to have the same parent. For local class methods, this doesn't
18172 apply; we just use the old DIE. */
18173 if ((is_cu_die (old_die
->die_parent
) || context_die
== NULL
)
18174 && (DECL_ARTIFICIAL (decl
)
18175 || (get_AT_file (old_die
, DW_AT_decl_file
) == file_index
18176 && (get_AT_unsigned (old_die
, DW_AT_decl_line
)
18177 == (unsigned) s
.line
))))
18179 subr_die
= old_die
;
18181 /* Clear out the declaration attribute and the formal parameters.
18182 Do not remove all children, because it is possible that this
18183 declaration die was forced using force_decl_die(). In such
18184 cases die that forced declaration die (e.g. TAG_imported_module)
18185 is one of the children that we do not want to remove. */
18186 remove_AT (subr_die
, DW_AT_declaration
);
18187 remove_AT (subr_die
, DW_AT_object_pointer
);
18188 remove_child_TAG (subr_die
, DW_TAG_formal_parameter
);
18192 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18193 add_AT_specification (subr_die
, old_die
);
18194 add_pubname (decl
, subr_die
);
18195 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18196 add_AT_file (subr_die
, DW_AT_decl_file
, file_index
);
18197 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18198 add_AT_unsigned (subr_die
, DW_AT_decl_line
, s
.line
);
18200 /* If the prototype had an 'auto' or 'decltype(auto)' return type,
18201 emit the real type on the definition die. */
18202 if (is_cxx() && debug_info_level
> DINFO_LEVEL_TERSE
)
18204 dw_die_ref die
= get_AT_ref (old_die
, DW_AT_type
);
18205 if (die
== auto_die
|| die
== decltype_auto_die
)
18206 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18207 0, 0, context_die
);
18213 subr_die
= new_die (DW_TAG_subprogram
, context_die
, decl
);
18215 if (TREE_PUBLIC (decl
))
18216 add_AT_flag (subr_die
, DW_AT_external
, 1);
18218 add_name_and_src_coords_attributes (subr_die
, decl
);
18219 add_pubname (decl
, subr_die
);
18220 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18222 add_prototyped_attribute (subr_die
, TREE_TYPE (decl
));
18223 add_type_attribute (subr_die
, TREE_TYPE (TREE_TYPE (decl
)),
18224 0, 0, context_die
);
18227 add_pure_or_virtual_attribute (subr_die
, decl
);
18228 if (DECL_ARTIFICIAL (decl
))
18229 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18231 add_accessibility_attribute (subr_die
, decl
);
18236 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18238 add_AT_flag (subr_die
, DW_AT_declaration
, 1);
18240 /* If this is an explicit function declaration then generate
18241 a DW_AT_explicit attribute. */
18242 if (lang_hooks
.decls
.function_decl_explicit_p (decl
)
18243 && (dwarf_version
>= 3 || !dwarf_strict
))
18244 add_AT_flag (subr_die
, DW_AT_explicit
, 1);
18246 /* The first time we see a member function, it is in the context of
18247 the class to which it belongs. We make sure of this by emitting
18248 the class first. The next time is the definition, which is
18249 handled above. The two may come from the same source text.
18251 Note that force_decl_die() forces function declaration die. It is
18252 later reused to represent definition. */
18253 equate_decl_number_to_die (decl
, subr_die
);
18256 else if (DECL_ABSTRACT (decl
))
18258 if (DECL_DECLARED_INLINE_P (decl
))
18260 if (cgraph_function_possibly_inlined_p (decl
))
18261 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_inlined
);
18263 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_declared_not_inlined
);
18267 if (cgraph_function_possibly_inlined_p (decl
))
18268 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_inlined
);
18270 add_AT_unsigned (subr_die
, DW_AT_inline
, DW_INL_not_inlined
);
18273 if (DECL_DECLARED_INLINE_P (decl
)
18274 && lookup_attribute ("artificial", DECL_ATTRIBUTES (decl
)))
18275 add_AT_flag (subr_die
, DW_AT_artificial
, 1);
18277 equate_decl_number_to_die (decl
, subr_die
);
18279 else if (!DECL_EXTERNAL (decl
))
18281 HOST_WIDE_INT cfa_fb_offset
;
18282 struct function
*fun
= DECL_STRUCT_FUNCTION (decl
);
18284 if (!old_die
|| !get_AT (old_die
, DW_AT_inline
))
18285 equate_decl_number_to_die (decl
, subr_die
);
18287 gcc_checking_assert (fun
);
18288 if (!flag_reorder_blocks_and_partition
)
18290 dw_fde_ref fde
= fun
->fde
;
18291 if (fde
->dw_fde_begin
)
18293 /* We have already generated the labels. */
18294 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18295 fde
->dw_fde_end
, false);
18299 /* Create start/end labels and add the range. */
18300 char label_id_low
[MAX_ARTIFICIAL_LABEL_BYTES
];
18301 char label_id_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
18302 ASM_GENERATE_INTERNAL_LABEL (label_id_low
, FUNC_BEGIN_LABEL
,
18303 current_function_funcdef_no
);
18304 ASM_GENERATE_INTERNAL_LABEL (label_id_high
, FUNC_END_LABEL
,
18305 current_function_funcdef_no
);
18306 add_AT_low_high_pc (subr_die
, label_id_low
, label_id_high
,
18310 #if VMS_DEBUGGING_INFO
18311 /* HP OpenVMS Industry Standard 64: DWARF Extensions
18312 Section 2.3 Prologue and Epilogue Attributes:
18313 When a breakpoint is set on entry to a function, it is generally
18314 desirable for execution to be suspended, not on the very first
18315 instruction of the function, but rather at a point after the
18316 function's frame has been set up, after any language defined local
18317 declaration processing has been completed, and before execution of
18318 the first statement of the function begins. Debuggers generally
18319 cannot properly determine where this point is. Similarly for a
18320 breakpoint set on exit from a function. The prologue and epilogue
18321 attributes allow a compiler to communicate the location(s) to use. */
18324 if (fde
->dw_fde_vms_end_prologue
)
18325 add_AT_vms_delta (subr_die
, DW_AT_HP_prologue
,
18326 fde
->dw_fde_begin
, fde
->dw_fde_vms_end_prologue
);
18328 if (fde
->dw_fde_vms_begin_epilogue
)
18329 add_AT_vms_delta (subr_die
, DW_AT_HP_epilogue
,
18330 fde
->dw_fde_begin
, fde
->dw_fde_vms_begin_epilogue
);
18337 /* Generate pubnames entries for the split function code ranges. */
18338 dw_fde_ref fde
= fun
->fde
;
18340 if (fde
->dw_fde_second_begin
)
18342 if (dwarf_version
>= 3 || !dwarf_strict
)
18344 /* We should use ranges for non-contiguous code section
18345 addresses. Use the actual code range for the initial
18346 section, since the HOT/COLD labels might precede an
18347 alignment offset. */
18348 bool range_list_added
= false;
18349 add_ranges_by_labels (subr_die
, fde
->dw_fde_begin
,
18350 fde
->dw_fde_end
, &range_list_added
,
18352 add_ranges_by_labels (subr_die
, fde
->dw_fde_second_begin
,
18353 fde
->dw_fde_second_end
,
18354 &range_list_added
, false);
18355 if (range_list_added
)
18360 /* There is no real support in DW2 for this .. so we make
18361 a work-around. First, emit the pub name for the segment
18362 containing the function label. Then make and emit a
18363 simplified subprogram DIE for the second segment with the
18364 name pre-fixed by __hot/cold_sect_of_. We use the same
18365 linkage name for the second die so that gdb will find both
18366 sections when given "b foo". */
18367 const char *name
= NULL
;
18368 tree decl_name
= DECL_NAME (decl
);
18369 dw_die_ref seg_die
;
18371 /* Do the 'primary' section. */
18372 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
,
18373 fde
->dw_fde_end
, false);
18375 /* Build a minimal DIE for the secondary section. */
18376 seg_die
= new_die (DW_TAG_subprogram
,
18377 subr_die
->die_parent
, decl
);
18379 if (TREE_PUBLIC (decl
))
18380 add_AT_flag (seg_die
, DW_AT_external
, 1);
18382 if (decl_name
!= NULL
18383 && IDENTIFIER_POINTER (decl_name
) != NULL
)
18385 name
= dwarf2_name (decl
, 1);
18386 if (! DECL_ARTIFICIAL (decl
))
18387 add_src_coords_attributes (seg_die
, decl
);
18389 add_linkage_name (seg_die
, decl
);
18391 gcc_assert (name
!= NULL
);
18392 add_pure_or_virtual_attribute (seg_die
, decl
);
18393 if (DECL_ARTIFICIAL (decl
))
18394 add_AT_flag (seg_die
, DW_AT_artificial
, 1);
18396 name
= concat ("__second_sect_of_", name
, NULL
);
18397 add_AT_low_high_pc (seg_die
, fde
->dw_fde_second_begin
,
18398 fde
->dw_fde_second_end
, false);
18399 add_name_attribute (seg_die
, name
);
18400 if (want_pubnames ())
18401 add_pubname_string (name
, seg_die
);
18405 add_AT_low_high_pc (subr_die
, fde
->dw_fde_begin
, fde
->dw_fde_end
,
18409 cfa_fb_offset
= CFA_FRAME_BASE_OFFSET (decl
);
18411 /* We define the "frame base" as the function's CFA. This is more
18412 convenient for several reasons: (1) It's stable across the prologue
18413 and epilogue, which makes it better than just a frame pointer,
18414 (2) With dwarf3, there exists a one-byte encoding that allows us
18415 to reference the .debug_frame data by proxy, but failing that,
18416 (3) We can at least reuse the code inspection and interpretation
18417 code that determines the CFA position at various points in the
18419 if (dwarf_version
>= 3 && targetm
.debug_unwind_info () == UI_DWARF2
)
18421 dw_loc_descr_ref op
= new_loc_descr (DW_OP_call_frame_cfa
, 0, 0);
18422 add_AT_loc (subr_die
, DW_AT_frame_base
, op
);
18426 dw_loc_list_ref list
= convert_cfa_to_fb_loc_list (cfa_fb_offset
);
18427 if (list
->dw_loc_next
)
18428 add_AT_loc_list (subr_die
, DW_AT_frame_base
, list
);
18430 add_AT_loc (subr_die
, DW_AT_frame_base
, list
->expr
);
18433 /* Compute a displacement from the "steady-state frame pointer" to
18434 the CFA. The former is what all stack slots and argument slots
18435 will reference in the rtl; the latter is what we've told the
18436 debugger about. We'll need to adjust all frame_base references
18437 by this displacement. */
18438 compute_frame_pointer_to_fb_displacement (cfa_fb_offset
);
18440 if (fun
->static_chain_decl
)
18441 add_AT_location_description (subr_die
, DW_AT_static_link
,
18442 loc_list_from_tree (fun
->static_chain_decl
, 2));
18445 /* Generate child dies for template paramaters. */
18446 if (debug_info_level
> DINFO_LEVEL_TERSE
)
18447 gen_generic_params_dies (decl
);
18449 /* Now output descriptions of the arguments for this function. This gets
18450 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list
18451 for a FUNCTION_DECL doesn't indicate cases where there was a trailing
18452 `...' at the end of the formal parameter list. In order to find out if
18453 there was a trailing ellipsis or not, we must instead look at the type
18454 associated with the FUNCTION_DECL. This will be a node of type
18455 FUNCTION_TYPE. If the chain of type nodes hanging off of this
18456 FUNCTION_TYPE node ends with a void_type_node then there should *not* be
18457 an ellipsis at the end. */
18459 /* In the case where we are describing a mere function declaration, all we
18460 need to do here (and all we *can* do here) is to describe the *types* of
18461 its formal parameters. */
18462 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
18464 else if (declaration
)
18465 gen_formal_types_die (decl
, subr_die
);
18468 /* Generate DIEs to represent all known formal parameters. */
18469 tree parm
= DECL_ARGUMENTS (decl
);
18470 tree generic_decl
= lang_hooks
.decls
.get_generic_function_decl (decl
);
18471 tree generic_decl_parm
= generic_decl
18472 ? DECL_ARGUMENTS (generic_decl
)
18475 /* Now we want to walk the list of parameters of the function and
18476 emit their relevant DIEs.
18478 We consider the case of DECL being an instance of a generic function
18479 as well as it being a normal function.
18481 If DECL is an instance of a generic function we walk the
18482 parameters of the generic function declaration _and_ the parameters of
18483 DECL itself. This is useful because we want to emit specific DIEs for
18484 function parameter packs and those are declared as part of the
18485 generic function declaration. In that particular case,
18486 the parameter pack yields a DW_TAG_GNU_formal_parameter_pack DIE.
18487 That DIE has children DIEs representing the set of arguments
18488 of the pack. Note that the set of pack arguments can be empty.
18489 In that case, the DW_TAG_GNU_formal_parameter_pack DIE will not have any
18492 Otherwise, we just consider the parameters of DECL. */
18493 while (generic_decl_parm
|| parm
)
18495 if (generic_decl_parm
18496 && lang_hooks
.function_parameter_pack_p (generic_decl_parm
))
18497 gen_formal_parameter_pack_die (generic_decl_parm
,
18502 dw_die_ref parm_die
= gen_decl_die (parm
, NULL
, subr_die
);
18504 if (parm
== DECL_ARGUMENTS (decl
)
18505 && TREE_CODE (TREE_TYPE (decl
)) == METHOD_TYPE
18507 && (dwarf_version
>= 3 || !dwarf_strict
))
18508 add_AT_die_ref (subr_die
, DW_AT_object_pointer
, parm_die
);
18510 parm
= DECL_CHAIN (parm
);
18513 if (generic_decl_parm
)
18514 generic_decl_parm
= DECL_CHAIN (generic_decl_parm
);
18517 /* Decide whether we need an unspecified_parameters DIE at the end.
18518 There are 2 more cases to do this for: 1) the ansi ... declaration -
18519 this is detectable when the end of the arg list is not a
18520 void_type_node 2) an unprototyped function declaration (not a
18521 definition). This just means that we have no info about the
18522 parameters at all. */
18523 if (prototype_p (TREE_TYPE (decl
)))
18525 /* This is the prototyped case, check for.... */
18526 if (stdarg_p (TREE_TYPE (decl
)))
18527 gen_unspecified_parameters_die (decl
, subr_die
);
18529 else if (DECL_INITIAL (decl
) == NULL_TREE
)
18530 gen_unspecified_parameters_die (decl
, subr_die
);
18533 /* Output Dwarf info for all of the stuff within the body of the function
18534 (if it has one - it may be just a declaration). */
18535 outer_scope
= DECL_INITIAL (decl
);
18537 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent
18538 a function. This BLOCK actually represents the outermost binding contour
18539 for the function, i.e. the contour in which the function's formal
18540 parameters and labels get declared. Curiously, it appears that the front
18541 end doesn't actually put the PARM_DECL nodes for the current function onto
18542 the BLOCK_VARS list for this outer scope, but are strung off of the
18543 DECL_ARGUMENTS list for the function instead.
18545 The BLOCK_VARS list for the `outer_scope' does provide us with a list of
18546 the LABEL_DECL nodes for the function however, and we output DWARF info
18547 for those in decls_for_scope. Just within the `outer_scope' there will be
18548 a BLOCK node representing the function's outermost pair of curly braces,
18549 and any blocks used for the base and member initializers of a C++
18550 constructor function. */
18551 if (! declaration
&& outer_scope
&& TREE_CODE (outer_scope
) != ERROR_MARK
)
18553 int call_site_note_count
= 0;
18554 int tail_call_site_note_count
= 0;
18556 /* Emit a DW_TAG_variable DIE for a named return value. */
18557 if (DECL_NAME (DECL_RESULT (decl
)))
18558 gen_decl_die (DECL_RESULT (decl
), NULL
, subr_die
);
18560 current_function_has_inlines
= 0;
18561 decls_for_scope (outer_scope
, subr_die
, 0);
18563 if (call_arg_locations
&& !dwarf_strict
)
18565 struct call_arg_loc_node
*ca_loc
;
18566 for (ca_loc
= call_arg_locations
; ca_loc
; ca_loc
= ca_loc
->next
)
18568 dw_die_ref die
= NULL
;
18569 rtx tloc
= NULL_RTX
, tlocc
= NULL_RTX
;
18572 for (arg
= NOTE_VAR_LOCATION (ca_loc
->call_arg_loc_note
);
18573 arg
; arg
= next_arg
)
18575 dw_loc_descr_ref reg
, val
;
18576 enum machine_mode mode
= GET_MODE (XEXP (XEXP (arg
, 0), 1));
18577 dw_die_ref cdie
, tdie
= NULL
;
18579 next_arg
= XEXP (arg
, 1);
18580 if (REG_P (XEXP (XEXP (arg
, 0), 0))
18582 && MEM_P (XEXP (XEXP (next_arg
, 0), 0))
18583 && REG_P (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0))
18584 && REGNO (XEXP (XEXP (arg
, 0), 0))
18585 == REGNO (XEXP (XEXP (XEXP (next_arg
, 0), 0), 0)))
18586 next_arg
= XEXP (next_arg
, 1);
18587 if (mode
== VOIDmode
)
18589 mode
= GET_MODE (XEXP (XEXP (arg
, 0), 0));
18590 if (mode
== VOIDmode
)
18591 mode
= GET_MODE (XEXP (arg
, 0));
18593 if (mode
== VOIDmode
|| mode
== BLKmode
)
18595 if (XEXP (XEXP (arg
, 0), 0) == pc_rtx
)
18597 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18598 tloc
= XEXP (XEXP (arg
, 0), 1);
18601 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0)) == CLOBBER
18602 && XEXP (XEXP (XEXP (arg
, 0), 0), 0) == pc_rtx
)
18604 gcc_assert (ca_loc
->symbol_ref
== NULL_RTX
);
18605 tlocc
= XEXP (XEXP (arg
, 0), 1);
18609 if (REG_P (XEXP (XEXP (arg
, 0), 0)))
18610 reg
= reg_loc_descriptor (XEXP (XEXP (arg
, 0), 0),
18611 VAR_INIT_STATUS_INITIALIZED
);
18612 else if (MEM_P (XEXP (XEXP (arg
, 0), 0)))
18614 rtx mem
= XEXP (XEXP (arg
, 0), 0);
18615 reg
= mem_loc_descriptor (XEXP (mem
, 0),
18616 get_address_mode (mem
),
18618 VAR_INIT_STATUS_INITIALIZED
);
18620 else if (GET_CODE (XEXP (XEXP (arg
, 0), 0))
18621 == DEBUG_PARAMETER_REF
)
18624 = DEBUG_PARAMETER_REF_DECL (XEXP (XEXP (arg
, 0), 0));
18625 tdie
= lookup_decl_die (tdecl
);
18632 && GET_CODE (XEXP (XEXP (arg
, 0), 0))
18633 != DEBUG_PARAMETER_REF
)
18635 val
= mem_loc_descriptor (XEXP (XEXP (arg
, 0), 1), mode
,
18637 VAR_INIT_STATUS_INITIALIZED
);
18641 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18642 cdie
= new_die (DW_TAG_GNU_call_site_parameter
, die
,
18645 add_AT_loc (cdie
, DW_AT_location
, reg
);
18646 else if (tdie
!= NULL
)
18647 add_AT_die_ref (cdie
, DW_AT_abstract_origin
, tdie
);
18648 add_AT_loc (cdie
, DW_AT_GNU_call_site_value
, val
);
18649 if (next_arg
!= XEXP (arg
, 1))
18651 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 1));
18652 if (mode
== VOIDmode
)
18653 mode
= GET_MODE (XEXP (XEXP (XEXP (arg
, 1), 0), 0));
18654 val
= mem_loc_descriptor (XEXP (XEXP (XEXP (arg
, 1),
18657 VAR_INIT_STATUS_INITIALIZED
);
18659 add_AT_loc (cdie
, DW_AT_GNU_call_site_data_value
, val
);
18663 && (ca_loc
->symbol_ref
|| tloc
))
18664 die
= gen_call_site_die (decl
, subr_die
, ca_loc
);
18665 if (die
!= NULL
&& (tloc
!= NULL_RTX
|| tlocc
!= NULL_RTX
))
18667 dw_loc_descr_ref tval
= NULL
;
18669 if (tloc
!= NULL_RTX
)
18670 tval
= mem_loc_descriptor (tloc
,
18671 GET_MODE (tloc
) == VOIDmode
18672 ? Pmode
: GET_MODE (tloc
),
18674 VAR_INIT_STATUS_INITIALIZED
);
18676 add_AT_loc (die
, DW_AT_GNU_call_site_target
, tval
);
18677 else if (tlocc
!= NULL_RTX
)
18679 tval
= mem_loc_descriptor (tlocc
,
18680 GET_MODE (tlocc
) == VOIDmode
18681 ? Pmode
: GET_MODE (tlocc
),
18683 VAR_INIT_STATUS_INITIALIZED
);
18685 add_AT_loc (die
, DW_AT_GNU_call_site_target_clobbered
,
18691 call_site_note_count
++;
18692 if (ca_loc
->tail_call_p
)
18693 tail_call_site_note_count
++;
18697 call_arg_locations
= NULL
;
18698 call_arg_loc_last
= NULL
;
18699 if (tail_call_site_count
>= 0
18700 && tail_call_site_count
== tail_call_site_note_count
18703 if (call_site_count
>= 0
18704 && call_site_count
== call_site_note_count
)
18705 add_AT_flag (subr_die
, DW_AT_GNU_all_call_sites
, 1);
18707 add_AT_flag (subr_die
, DW_AT_GNU_all_tail_call_sites
, 1);
18709 call_site_count
= -1;
18710 tail_call_site_count
= -1;
18713 if (subr_die
!= old_die
)
18714 /* Add the calling convention attribute if requested. */
18715 add_calling_convention_attribute (subr_die
, decl
);
18718 /* Returns a hash value for X (which really is a die_struct). */
18721 common_block_die_table_hash (const void *x
)
18723 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18724 return (hashval_t
) d
->decl_id
^ htab_hash_pointer (d
->die_parent
);
18727 /* Return nonzero if decl_id and die_parent of die_struct X is the same
18728 as decl_id and die_parent of die_struct Y. */
18731 common_block_die_table_eq (const void *x
, const void *y
)
18733 const_dw_die_ref d
= (const_dw_die_ref
) x
;
18734 const_dw_die_ref e
= (const_dw_die_ref
) y
;
18735 return d
->decl_id
== e
->decl_id
&& d
->die_parent
== e
->die_parent
;
18738 /* Generate a DIE to represent a declared data object.
18739 Either DECL or ORIGIN must be non-null. */
18742 gen_variable_die (tree decl
, tree origin
, dw_die_ref context_die
)
18744 HOST_WIDE_INT off
= 0;
18746 tree decl_or_origin
= decl
? decl
: origin
;
18747 tree ultimate_origin
;
18748 dw_die_ref var_die
;
18749 dw_die_ref old_die
= decl
? lookup_decl_die (decl
) : NULL
;
18750 dw_die_ref origin_die
;
18751 bool declaration
= (DECL_EXTERNAL (decl_or_origin
)
18752 || class_or_namespace_scope_p (context_die
));
18753 bool specialization_p
= false;
18755 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
18756 if (decl
|| ultimate_origin
)
18757 origin
= ultimate_origin
;
18758 com_decl
= fortran_common (decl_or_origin
, &off
);
18760 /* Symbol in common gets emitted as a child of the common block, in the form
18761 of a data member. */
18764 dw_die_ref com_die
;
18765 dw_loc_list_ref loc
;
18766 die_node com_die_arg
;
18768 var_die
= lookup_decl_die (decl_or_origin
);
18771 if (get_AT (var_die
, DW_AT_location
) == NULL
)
18773 loc
= loc_list_from_tree (com_decl
, off
? 1 : 2);
18778 /* Optimize the common case. */
18779 if (single_element_loc_list_p (loc
)
18780 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18781 && loc
->expr
->dw_loc_next
== NULL
18782 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
)
18785 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18786 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18787 = plus_constant (GET_MODE (x
), x
, off
);
18790 loc_list_plus_const (loc
, off
);
18792 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18793 remove_AT (var_die
, DW_AT_declaration
);
18799 if (common_block_die_table
== NULL
)
18800 common_block_die_table
18801 = htab_create_ggc (10, common_block_die_table_hash
,
18802 common_block_die_table_eq
, NULL
);
18804 com_die_arg
.decl_id
= DECL_UID (com_decl
);
18805 com_die_arg
.die_parent
= context_die
;
18806 com_die
= (dw_die_ref
) htab_find (common_block_die_table
, &com_die_arg
);
18807 loc
= loc_list_from_tree (com_decl
, 2);
18808 if (com_die
== NULL
)
18811 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (com_decl
));
18814 com_die
= new_die (DW_TAG_common_block
, context_die
, decl
);
18815 add_name_and_src_coords_attributes (com_die
, com_decl
);
18818 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18819 /* Avoid sharing the same loc descriptor between
18820 DW_TAG_common_block and DW_TAG_variable. */
18821 loc
= loc_list_from_tree (com_decl
, 2);
18823 else if (DECL_EXTERNAL (decl
))
18824 add_AT_flag (com_die
, DW_AT_declaration
, 1);
18825 if (want_pubnames ())
18826 add_pubname_string (cnam
, com_die
); /* ??? needed? */
18827 com_die
->decl_id
= DECL_UID (com_decl
);
18828 slot
= htab_find_slot (common_block_die_table
, com_die
, INSERT
);
18829 *slot
= (void *) com_die
;
18831 else if (get_AT (com_die
, DW_AT_location
) == NULL
&& loc
)
18833 add_AT_location_description (com_die
, DW_AT_location
, loc
);
18834 loc
= loc_list_from_tree (com_decl
, 2);
18835 remove_AT (com_die
, DW_AT_declaration
);
18837 var_die
= new_die (DW_TAG_variable
, com_die
, decl
);
18838 add_name_and_src_coords_attributes (var_die
, decl
);
18839 add_type_attribute (var_die
, TREE_TYPE (decl
), TREE_READONLY (decl
),
18840 TREE_THIS_VOLATILE (decl
), context_die
);
18841 add_AT_flag (var_die
, DW_AT_external
, 1);
18846 /* Optimize the common case. */
18847 if (single_element_loc_list_p (loc
)
18848 && loc
->expr
->dw_loc_opc
== DW_OP_addr
18849 && loc
->expr
->dw_loc_next
== NULL
18850 && GET_CODE (loc
->expr
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
)
18852 rtx x
= loc
->expr
->dw_loc_oprnd1
.v
.val_addr
;
18853 loc
->expr
->dw_loc_oprnd1
.v
.val_addr
18854 = plus_constant (GET_MODE (x
), x
, off
);
18857 loc_list_plus_const (loc
, off
);
18859 add_AT_location_description (var_die
, DW_AT_location
, loc
);
18861 else if (DECL_EXTERNAL (decl
))
18862 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18863 equate_decl_number_to_die (decl
, var_die
);
18867 /* If the compiler emitted a definition for the DECL declaration
18868 and if we already emitted a DIE for it, don't emit a second
18869 DIE for it again. Allow re-declarations of DECLs that are
18870 inside functions, though. */
18871 if (old_die
&& declaration
&& !local_scope_p (context_die
))
18874 /* For static data members, the declaration in the class is supposed
18875 to have DW_TAG_member tag; the specification should still be
18876 DW_TAG_variable referencing the DW_TAG_member DIE. */
18877 if (declaration
&& class_scope_p (context_die
))
18878 var_die
= new_die (DW_TAG_member
, context_die
, decl
);
18880 var_die
= new_die (DW_TAG_variable
, context_die
, decl
);
18883 if (origin
!= NULL
)
18884 origin_die
= add_abstract_origin_attribute (var_die
, origin
);
18886 /* Loop unrolling can create multiple blocks that refer to the same
18887 static variable, so we must test for the DW_AT_declaration flag.
18889 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to
18890 copy decls and set the DECL_ABSTRACT flag on them instead of
18893 ??? Duplicated blocks have been rewritten to use .debug_ranges.
18895 ??? The declare_in_namespace support causes us to get two DIEs for one
18896 variable, both of which are declarations. We want to avoid considering
18897 one to be a specification, so we must test that this DIE is not a
18899 else if (old_die
&& TREE_STATIC (decl
) && ! declaration
18900 && get_AT_flag (old_die
, DW_AT_declaration
) == 1)
18902 /* This is a definition of a C++ class level static. */
18903 add_AT_specification (var_die
, old_die
);
18904 specialization_p
= true;
18905 if (DECL_NAME (decl
))
18907 expanded_location s
= expand_location (DECL_SOURCE_LOCATION (decl
));
18908 struct dwarf_file_data
* file_index
= lookup_filename (s
.file
);
18910 if (get_AT_file (old_die
, DW_AT_decl_file
) != file_index
)
18911 add_AT_file (var_die
, DW_AT_decl_file
, file_index
);
18913 if (get_AT_unsigned (old_die
, DW_AT_decl_line
) != (unsigned) s
.line
)
18914 add_AT_unsigned (var_die
, DW_AT_decl_line
, s
.line
);
18916 if (old_die
->die_tag
== DW_TAG_member
)
18917 add_linkage_name (var_die
, decl
);
18921 add_name_and_src_coords_attributes (var_die
, decl
);
18923 if ((origin
== NULL
&& !specialization_p
)
18925 && !DECL_ABSTRACT (decl_or_origin
)
18926 && variably_modified_type_p (TREE_TYPE (decl_or_origin
),
18927 decl_function_context
18928 (decl_or_origin
))))
18930 tree type
= TREE_TYPE (decl_or_origin
);
18932 if (decl_by_reference_p (decl_or_origin
))
18933 add_type_attribute (var_die
, TREE_TYPE (type
), 0, 0, context_die
);
18935 add_type_attribute (var_die
, type
, TREE_READONLY (decl_or_origin
),
18936 TREE_THIS_VOLATILE (decl_or_origin
), context_die
);
18939 if (origin
== NULL
&& !specialization_p
)
18941 if (TREE_PUBLIC (decl
))
18942 add_AT_flag (var_die
, DW_AT_external
, 1);
18944 if (DECL_ARTIFICIAL (decl
))
18945 add_AT_flag (var_die
, DW_AT_artificial
, 1);
18947 add_accessibility_attribute (var_die
, decl
);
18951 add_AT_flag (var_die
, DW_AT_declaration
, 1);
18953 if (decl
&& (DECL_ABSTRACT (decl
) || declaration
|| old_die
== NULL
))
18954 equate_decl_number_to_die (decl
, var_die
);
18957 && (! DECL_ABSTRACT (decl_or_origin
)
18958 /* Local static vars are shared between all clones/inlines,
18959 so emit DW_AT_location on the abstract DIE if DECL_RTL is
18961 || (TREE_CODE (decl_or_origin
) == VAR_DECL
18962 && TREE_STATIC (decl_or_origin
)
18963 && DECL_RTL_SET_P (decl_or_origin
)))
18964 /* When abstract origin already has DW_AT_location attribute, no need
18965 to add it again. */
18966 && (origin_die
== NULL
|| get_AT (origin_die
, DW_AT_location
) == NULL
))
18968 if (TREE_CODE (decl_or_origin
) == VAR_DECL
&& TREE_STATIC (decl_or_origin
)
18969 && !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl_or_origin
)))
18970 defer_location (decl_or_origin
, var_die
);
18972 add_location_or_const_value_attribute (var_die
, decl_or_origin
,
18973 decl
== NULL
, DW_AT_location
);
18974 add_pubname (decl_or_origin
, var_die
);
18977 tree_add_const_value_attribute_for_decl (var_die
, decl_or_origin
);
18980 /* Generate a DIE to represent a named constant. */
18983 gen_const_die (tree decl
, dw_die_ref context_die
)
18985 dw_die_ref const_die
;
18986 tree type
= TREE_TYPE (decl
);
18988 const_die
= new_die (DW_TAG_constant
, context_die
, decl
);
18989 add_name_and_src_coords_attributes (const_die
, decl
);
18990 add_type_attribute (const_die
, type
, 1, 0, context_die
);
18991 if (TREE_PUBLIC (decl
))
18992 add_AT_flag (const_die
, DW_AT_external
, 1);
18993 if (DECL_ARTIFICIAL (decl
))
18994 add_AT_flag (const_die
, DW_AT_artificial
, 1);
18995 tree_add_const_value_attribute_for_decl (const_die
, decl
);
18998 /* Generate a DIE to represent a label identifier. */
19001 gen_label_die (tree decl
, dw_die_ref context_die
)
19003 tree origin
= decl_ultimate_origin (decl
);
19004 dw_die_ref lbl_die
= new_die (DW_TAG_label
, context_die
, decl
);
19006 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19008 if (origin
!= NULL
)
19009 add_abstract_origin_attribute (lbl_die
, origin
);
19011 add_name_and_src_coords_attributes (lbl_die
, decl
);
19013 if (DECL_ABSTRACT (decl
))
19014 equate_decl_number_to_die (decl
, lbl_die
);
19017 insn
= DECL_RTL_IF_SET (decl
);
19019 /* Deleted labels are programmer specified labels which have been
19020 eliminated because of various optimizations. We still emit them
19021 here so that it is possible to put breakpoints on them. */
19025 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_LABEL
))))
19027 /* When optimization is enabled (via -O) some parts of the compiler
19028 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which
19029 represent source-level labels which were explicitly declared by
19030 the user. This really shouldn't be happening though, so catch
19031 it if it ever does happen. */
19032 gcc_assert (!INSN_DELETED_P (insn
));
19034 ASM_GENERATE_INTERNAL_LABEL (label
, "L", CODE_LABEL_NUMBER (insn
));
19035 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19039 && NOTE_KIND (insn
) == NOTE_INSN_DELETED_DEBUG_LABEL
19040 && CODE_LABEL_NUMBER (insn
) != -1)
19042 ASM_GENERATE_INTERNAL_LABEL (label
, "LDL", CODE_LABEL_NUMBER (insn
));
19043 add_AT_lbl_id (lbl_die
, DW_AT_low_pc
, label
);
19048 /* A helper function for gen_inlined_subroutine_die. Add source coordinate
19049 attributes to the DIE for a block STMT, to describe where the inlined
19050 function was called from. This is similar to add_src_coords_attributes. */
19053 add_call_src_coords_attributes (tree stmt
, dw_die_ref die
)
19055 expanded_location s
= expand_location (BLOCK_SOURCE_LOCATION (stmt
));
19057 if (dwarf_version
>= 3 || !dwarf_strict
)
19059 add_AT_file (die
, DW_AT_call_file
, lookup_filename (s
.file
));
19060 add_AT_unsigned (die
, DW_AT_call_line
, s
.line
);
19065 /* A helper function for gen_lexical_block_die and gen_inlined_subroutine_die.
19066 Add low_pc and high_pc attributes to the DIE for a block STMT. */
19069 add_high_low_attributes (tree stmt
, dw_die_ref die
)
19071 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
19073 if (BLOCK_FRAGMENT_CHAIN (stmt
)
19074 && (dwarf_version
>= 3 || !dwarf_strict
))
19076 tree chain
, superblock
= NULL_TREE
;
19078 dw_attr_ref attr
= NULL
;
19080 if (inlined_function_outer_scope_p (stmt
))
19082 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19083 BLOCK_NUMBER (stmt
));
19084 add_AT_lbl_id (die
, DW_AT_entry_pc
, label
);
19087 /* Optimize duplicate .debug_ranges lists or even tails of
19088 lists. If this BLOCK has same ranges as its supercontext,
19089 lookup DW_AT_ranges attribute in the supercontext (and
19090 recursively so), verify that the ranges_table contains the
19091 right values and use it instead of adding a new .debug_range. */
19092 for (chain
= stmt
, pdie
= die
;
19093 BLOCK_SAME_RANGE (chain
);
19094 chain
= BLOCK_SUPERCONTEXT (chain
))
19096 dw_attr_ref new_attr
;
19098 pdie
= pdie
->die_parent
;
19101 if (BLOCK_SUPERCONTEXT (chain
) == NULL_TREE
)
19103 new_attr
= get_AT (pdie
, DW_AT_ranges
);
19104 if (new_attr
== NULL
19105 || new_attr
->dw_attr_val
.val_class
!= dw_val_class_range_list
)
19108 superblock
= BLOCK_SUPERCONTEXT (chain
);
19111 && (ranges_table
[attr
->dw_attr_val
.v
.val_offset
19112 / 2 / DWARF2_ADDR_SIZE
].num
19113 == BLOCK_NUMBER (superblock
))
19114 && BLOCK_FRAGMENT_CHAIN (superblock
))
19116 unsigned long off
= attr
->dw_attr_val
.v
.val_offset
19117 / 2 / DWARF2_ADDR_SIZE
;
19118 unsigned long supercnt
= 0, thiscnt
= 0;
19119 for (chain
= BLOCK_FRAGMENT_CHAIN (superblock
);
19120 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19123 gcc_checking_assert (ranges_table
[off
+ supercnt
].num
19124 == BLOCK_NUMBER (chain
));
19126 gcc_checking_assert (ranges_table
[off
+ supercnt
+ 1].num
== 0);
19127 for (chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19128 chain
; chain
= BLOCK_FRAGMENT_CHAIN (chain
))
19130 gcc_assert (supercnt
>= thiscnt
);
19131 add_AT_range_list (die
, DW_AT_ranges
,
19132 ((off
+ supercnt
- thiscnt
)
19133 * 2 * DWARF2_ADDR_SIZE
),
19138 add_AT_range_list (die
, DW_AT_ranges
, add_ranges (stmt
), false);
19140 chain
= BLOCK_FRAGMENT_CHAIN (stmt
);
19143 add_ranges (chain
);
19144 chain
= BLOCK_FRAGMENT_CHAIN (chain
);
19151 char label_high
[MAX_ARTIFICIAL_LABEL_BYTES
];
19152 ASM_GENERATE_INTERNAL_LABEL (label
, BLOCK_BEGIN_LABEL
,
19153 BLOCK_NUMBER (stmt
));
19154 ASM_GENERATE_INTERNAL_LABEL (label_high
, BLOCK_END_LABEL
,
19155 BLOCK_NUMBER (stmt
));
19156 add_AT_low_high_pc (die
, label
, label_high
, false);
19160 /* Generate a DIE for a lexical block. */
19163 gen_lexical_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
19165 dw_die_ref stmt_die
= new_die (DW_TAG_lexical_block
, context_die
, stmt
);
19167 if (call_arg_locations
)
19169 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
19170 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
19171 block_map
[BLOCK_NUMBER (stmt
)] = stmt_die
;
19174 if (! BLOCK_ABSTRACT (stmt
) && TREE_ASM_WRITTEN (stmt
))
19175 add_high_low_attributes (stmt
, stmt_die
);
19177 decls_for_scope (stmt
, stmt_die
, depth
);
19180 /* Generate a DIE for an inlined subprogram. */
19183 gen_inlined_subroutine_die (tree stmt
, dw_die_ref context_die
, int depth
)
19187 /* The instance of function that is effectively being inlined shall not
19189 gcc_assert (! BLOCK_ABSTRACT (stmt
));
19191 decl
= block_ultimate_origin (stmt
);
19193 /* Emit info for the abstract instance first, if we haven't yet. We
19194 must emit this even if the block is abstract, otherwise when we
19195 emit the block below (or elsewhere), we may end up trying to emit
19196 a die whose origin die hasn't been emitted, and crashing. */
19197 dwarf2out_abstract_function (decl
);
19199 if (! BLOCK_ABSTRACT (stmt
))
19201 dw_die_ref subr_die
19202 = new_die (DW_TAG_inlined_subroutine
, context_die
, stmt
);
19204 if (call_arg_locations
)
19206 if (block_map
.length () <= BLOCK_NUMBER (stmt
))
19207 block_map
.safe_grow_cleared (BLOCK_NUMBER (stmt
) + 1);
19208 block_map
[BLOCK_NUMBER (stmt
)] = subr_die
;
19210 add_abstract_origin_attribute (subr_die
, decl
);
19211 if (TREE_ASM_WRITTEN (stmt
))
19212 add_high_low_attributes (stmt
, subr_die
);
19213 add_call_src_coords_attributes (stmt
, subr_die
);
19215 decls_for_scope (stmt
, subr_die
, depth
);
19216 current_function_has_inlines
= 1;
19220 /* Generate a DIE for a field in a record, or structure. */
19223 gen_field_die (tree decl
, dw_die_ref context_die
)
19225 dw_die_ref decl_die
;
19227 if (TREE_TYPE (decl
) == error_mark_node
)
19230 decl_die
= new_die (DW_TAG_member
, context_die
, decl
);
19231 add_name_and_src_coords_attributes (decl_die
, decl
);
19232 add_type_attribute (decl_die
, member_declared_type (decl
),
19233 TREE_READONLY (decl
), TREE_THIS_VOLATILE (decl
),
19236 if (DECL_BIT_FIELD_TYPE (decl
))
19238 add_byte_size_attribute (decl_die
, decl
);
19239 add_bit_size_attribute (decl_die
, decl
);
19240 add_bit_offset_attribute (decl_die
, decl
);
19243 if (TREE_CODE (DECL_FIELD_CONTEXT (decl
)) != UNION_TYPE
)
19244 add_data_member_location_attribute (decl_die
, decl
);
19246 if (DECL_ARTIFICIAL (decl
))
19247 add_AT_flag (decl_die
, DW_AT_artificial
, 1);
19249 add_accessibility_attribute (decl_die
, decl
);
19251 /* Equate decl number to die, so that we can look up this decl later on. */
19252 equate_decl_number_to_die (decl
, decl_die
);
19256 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19257 Use modified_type_die instead.
19258 We keep this code here just in case these types of DIEs may be needed to
19259 represent certain things in other languages (e.g. Pascal) someday. */
19262 gen_pointer_type_die (tree type
, dw_die_ref context_die
)
19265 = new_die (DW_TAG_pointer_type
, scope_die_for (type
, context_die
), type
);
19267 equate_type_number_to_die (type
, ptr_die
);
19268 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19269 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19272 /* Don't generate either pointer_type DIEs or reference_type DIEs here.
19273 Use modified_type_die instead.
19274 We keep this code here just in case these types of DIEs may be needed to
19275 represent certain things in other languages (e.g. Pascal) someday. */
19278 gen_reference_type_die (tree type
, dw_die_ref context_die
)
19280 dw_die_ref ref_die
, scope_die
= scope_die_for (type
, context_die
);
19282 if (TYPE_REF_IS_RVALUE (type
) && dwarf_version
>= 4)
19283 ref_die
= new_die (DW_TAG_rvalue_reference_type
, scope_die
, type
);
19285 ref_die
= new_die (DW_TAG_reference_type
, scope_die
, type
);
19287 equate_type_number_to_die (type
, ref_die
);
19288 add_type_attribute (ref_die
, TREE_TYPE (type
), 0, 0, context_die
);
19289 add_AT_unsigned (mod_type_die
, DW_AT_byte_size
, PTR_SIZE
);
19293 /* Generate a DIE for a pointer to a member type. */
19296 gen_ptr_to_mbr_type_die (tree type
, dw_die_ref context_die
)
19299 = new_die (DW_TAG_ptr_to_member_type
,
19300 scope_die_for (type
, context_die
), type
);
19302 equate_type_number_to_die (type
, ptr_die
);
19303 add_AT_die_ref (ptr_die
, DW_AT_containing_type
,
19304 lookup_type_die (TYPE_OFFSET_BASETYPE (type
)));
19305 add_type_attribute (ptr_die
, TREE_TYPE (type
), 0, 0, context_die
);
19308 typedef const char *dchar_p
; /* For DEF_VEC_P. */
19310 static char *producer_string
;
19312 /* Return a heap allocated producer string including command line options
19313 if -grecord-gcc-switches. */
19316 gen_producer_string (void)
19319 auto_vec
<dchar_p
> switches
;
19320 const char *language_string
= lang_hooks
.name
;
19321 char *producer
, *tail
;
19323 size_t len
= dwarf_record_gcc_switches
? 0 : 3;
19324 size_t plen
= strlen (language_string
) + 1 + strlen (version_string
);
19326 for (j
= 1; dwarf_record_gcc_switches
&& j
< save_decoded_options_count
; j
++)
19327 switch (save_decoded_options
[j
].opt_index
)
19334 case OPT_auxbase_strip
:
19343 case OPT_SPECIAL_unknown
:
19344 case OPT_SPECIAL_ignore
:
19345 case OPT_SPECIAL_program_name
:
19346 case OPT_SPECIAL_input_file
:
19347 case OPT_grecord_gcc_switches
:
19348 case OPT_gno_record_gcc_switches
:
19349 case OPT__output_pch_
:
19350 case OPT_fdiagnostics_show_location_
:
19351 case OPT_fdiagnostics_show_option
:
19352 case OPT_fdiagnostics_show_caret
:
19353 case OPT_fdiagnostics_color_
:
19354 case OPT_fverbose_asm
:
19356 case OPT__sysroot_
:
19358 case OPT_nostdinc__
:
19359 /* Ignore these. */
19362 if (cl_options
[save_decoded_options
[j
].opt_index
].flags
19363 & CL_NO_DWARF_RECORD
)
19365 gcc_checking_assert (save_decoded_options
[j
].canonical_option
[0][0]
19367 switch (save_decoded_options
[j
].canonical_option
[0][1])
19374 if (strncmp (save_decoded_options
[j
].canonical_option
[0] + 2,
19381 switches
.safe_push (save_decoded_options
[j
].orig_option_with_args_text
);
19382 len
+= strlen (save_decoded_options
[j
].orig_option_with_args_text
) + 1;
19386 producer
= XNEWVEC (char, plen
+ 1 + len
+ 1);
19388 sprintf (tail
, "%s %s", language_string
, version_string
);
19391 FOR_EACH_VEC_ELT (switches
, j
, p
)
19395 memcpy (tail
+ 1, p
, len
);
19403 /* Generate the DIE for the compilation unit. */
19406 gen_compile_unit_die (const char *filename
)
19409 const char *language_string
= lang_hooks
.name
;
19412 die
= new_die (DW_TAG_compile_unit
, NULL
, NULL
);
19416 add_name_attribute (die
, filename
);
19417 /* Don't add cwd for <built-in>. */
19418 if (!IS_ABSOLUTE_PATH (filename
) && filename
[0] != '<')
19419 add_comp_dir_attribute (die
);
19422 add_AT_string (die
, DW_AT_producer
, producer_string
? producer_string
: "");
19424 /* If our producer is LTO try to figure out a common language to use
19425 from the global list of translation units. */
19426 if (strcmp (language_string
, "GNU GIMPLE") == 0)
19430 const char *common_lang
= NULL
;
19432 FOR_EACH_VEC_SAFE_ELT (all_translation_units
, i
, t
)
19434 if (!TRANSLATION_UNIT_LANGUAGE (t
))
19437 common_lang
= TRANSLATION_UNIT_LANGUAGE (t
);
19438 else if (strcmp (common_lang
, TRANSLATION_UNIT_LANGUAGE (t
)) == 0)
19440 else if (strncmp (common_lang
, "GNU C", 5) == 0
19441 && strncmp (TRANSLATION_UNIT_LANGUAGE (t
), "GNU C", 5) == 0)
19442 /* Mixing C and C++ is ok, use C++ in that case. */
19443 common_lang
= "GNU C++";
19446 /* Fall back to C. */
19447 common_lang
= NULL
;
19453 language_string
= common_lang
;
19456 language
= DW_LANG_C89
;
19457 if (strcmp (language_string
, "GNU C++") == 0)
19458 language
= DW_LANG_C_plus_plus
;
19459 else if (strcmp (language_string
, "GNU F77") == 0)
19460 language
= DW_LANG_Fortran77
;
19461 else if (strcmp (language_string
, "GNU Pascal") == 0)
19462 language
= DW_LANG_Pascal83
;
19463 else if (dwarf_version
>= 3 || !dwarf_strict
)
19465 if (strcmp (language_string
, "GNU Ada") == 0)
19466 language
= DW_LANG_Ada95
;
19467 else if (strcmp (language_string
, "GNU Fortran") == 0)
19468 language
= DW_LANG_Fortran95
;
19469 else if (strcmp (language_string
, "GNU Java") == 0)
19470 language
= DW_LANG_Java
;
19471 else if (strcmp (language_string
, "GNU Objective-C") == 0)
19472 language
= DW_LANG_ObjC
;
19473 else if (strcmp (language_string
, "GNU Objective-C++") == 0)
19474 language
= DW_LANG_ObjC_plus_plus
;
19475 else if (dwarf_version
>= 5 || !dwarf_strict
)
19477 if (strcmp (language_string
, "GNU Go") == 0)
19478 language
= DW_LANG_Go
;
19481 /* Use a degraded Fortran setting in strict DWARF2 so is_fortran works. */
19482 else if (strcmp (language_string
, "GNU Fortran") == 0)
19483 language
= DW_LANG_Fortran90
;
19485 add_AT_unsigned (die
, DW_AT_language
, language
);
19489 case DW_LANG_Fortran77
:
19490 case DW_LANG_Fortran90
:
19491 case DW_LANG_Fortran95
:
19492 /* Fortran has case insensitive identifiers and the front-end
19493 lowercases everything. */
19494 add_AT_unsigned (die
, DW_AT_identifier_case
, DW_ID_down_case
);
19497 /* The default DW_ID_case_sensitive doesn't need to be specified. */
19503 /* Generate the DIE for a base class. */
19506 gen_inheritance_die (tree binfo
, tree access
, dw_die_ref context_die
)
19508 dw_die_ref die
= new_die (DW_TAG_inheritance
, context_die
, binfo
);
19510 add_type_attribute (die
, BINFO_TYPE (binfo
), 0, 0, context_die
);
19511 add_data_member_location_attribute (die
, binfo
);
19513 if (BINFO_VIRTUAL_P (binfo
))
19514 add_AT_unsigned (die
, DW_AT_virtuality
, DW_VIRTUALITY_virtual
);
19516 /* In DWARF3+ the default is DW_ACCESS_private only in DW_TAG_class_type
19517 children, otherwise the default is DW_ACCESS_public. In DWARF2
19518 the default has always been DW_ACCESS_private. */
19519 if (access
== access_public_node
)
19521 if (dwarf_version
== 2
19522 || context_die
->die_tag
== DW_TAG_class_type
)
19523 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_public
);
19525 else if (access
== access_protected_node
)
19526 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_protected
);
19527 else if (dwarf_version
> 2
19528 && context_die
->die_tag
!= DW_TAG_class_type
)
19529 add_AT_unsigned (die
, DW_AT_accessibility
, DW_ACCESS_private
);
19532 /* Generate a DIE for a class member. */
19535 gen_member_die (tree type
, dw_die_ref context_die
)
19538 tree binfo
= TYPE_BINFO (type
);
19541 /* If this is not an incomplete type, output descriptions of each of its
19542 members. Note that as we output the DIEs necessary to represent the
19543 members of this record or union type, we will also be trying to output
19544 DIEs to represent the *types* of those members. However the `type'
19545 function (above) will specifically avoid generating type DIEs for member
19546 types *within* the list of member DIEs for this (containing) type except
19547 for those types (of members) which are explicitly marked as also being
19548 members of this (containing) type themselves. The g++ front- end can
19549 force any given type to be treated as a member of some other (containing)
19550 type by setting the TYPE_CONTEXT of the given (member) type to point to
19551 the TREE node representing the appropriate (containing) type. */
19553 /* First output info about the base classes. */
19556 vec
<tree
, va_gc
> *accesses
= BINFO_BASE_ACCESSES (binfo
);
19560 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base
); i
++)
19561 gen_inheritance_die (base
,
19562 (accesses
? (*accesses
)[i
] : access_public_node
),
19566 /* Now output info about the data members and type members. */
19567 for (member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
19569 /* If we thought we were generating minimal debug info for TYPE
19570 and then changed our minds, some of the member declarations
19571 may have already been defined. Don't define them again, but
19572 do put them in the right order. */
19574 child
= lookup_decl_die (member
);
19576 splice_child_die (context_die
, child
);
19578 gen_decl_die (member
, NULL
, context_die
);
19581 /* Now output info about the function members (if any). */
19582 for (member
= TYPE_METHODS (type
); member
; member
= DECL_CHAIN (member
))
19584 /* Don't include clones in the member list. */
19585 if (DECL_ABSTRACT_ORIGIN (member
))
19588 child
= lookup_decl_die (member
);
19590 splice_child_die (context_die
, child
);
19592 gen_decl_die (member
, NULL
, context_die
);
19596 /* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG
19597 is set, we pretend that the type was never defined, so we only get the
19598 member DIEs needed by later specification DIEs. */
19601 gen_struct_or_union_type_die (tree type
, dw_die_ref context_die
,
19602 enum debug_info_usage usage
)
19604 dw_die_ref type_die
= lookup_type_die (type
);
19605 dw_die_ref scope_die
= 0;
19607 int complete
= (TYPE_SIZE (type
)
19608 && (! TYPE_STUB_DECL (type
)
19609 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type
))));
19610 int ns_decl
= (context_die
&& context_die
->die_tag
== DW_TAG_namespace
);
19611 complete
= complete
&& should_emit_struct_debug (type
, usage
);
19613 if (type_die
&& ! complete
)
19616 if (TYPE_CONTEXT (type
) != NULL_TREE
19617 && (AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19618 || TREE_CODE (TYPE_CONTEXT (type
)) == NAMESPACE_DECL
))
19621 scope_die
= scope_die_for (type
, context_die
);
19623 /* Generate child dies for template paramaters. */
19624 if (!type_die
&& debug_info_level
> DINFO_LEVEL_TERSE
)
19625 schedule_generic_params_dies_gen (type
);
19627 if (! type_die
|| (nested
&& is_cu_die (scope_die
)))
19628 /* First occurrence of type or toplevel definition of nested class. */
19630 dw_die_ref old_die
= type_die
;
19632 type_die
= new_die (TREE_CODE (type
) == RECORD_TYPE
19633 ? record_type_tag (type
) : DW_TAG_union_type
,
19635 equate_type_number_to_die (type
, type_die
);
19637 add_AT_specification (type_die
, old_die
);
19639 add_name_attribute (type_die
, type_tag (type
));
19642 remove_AT (type_die
, DW_AT_declaration
);
19644 /* If this type has been completed, then give it a byte_size attribute and
19645 then give a list of members. */
19646 if (complete
&& !ns_decl
)
19648 /* Prevent infinite recursion in cases where the type of some member of
19649 this type is expressed in terms of this type itself. */
19650 TREE_ASM_WRITTEN (type
) = 1;
19651 add_byte_size_attribute (type_die
, type
);
19652 if (TYPE_STUB_DECL (type
) != NULL_TREE
)
19654 add_src_coords_attributes (type_die
, TYPE_STUB_DECL (type
));
19655 add_accessibility_attribute (type_die
, TYPE_STUB_DECL (type
));
19658 /* If the first reference to this type was as the return type of an
19659 inline function, then it may not have a parent. Fix this now. */
19660 if (type_die
->die_parent
== NULL
)
19661 add_child_die (scope_die
, type_die
);
19663 push_decl_scope (type
);
19664 gen_member_die (type
, type_die
);
19667 add_gnat_descriptive_type_attribute (type_die
, type
, context_die
);
19668 if (TYPE_ARTIFICIAL (type
))
19669 add_AT_flag (type_die
, DW_AT_artificial
, 1);
19671 /* GNU extension: Record what type our vtable lives in. */
19672 if (TYPE_VFIELD (type
))
19674 tree vtype
= DECL_FCONTEXT (TYPE_VFIELD (type
));
19676 gen_type_die (vtype
, context_die
);
19677 add_AT_die_ref (type_die
, DW_AT_containing_type
,
19678 lookup_type_die (vtype
));
19683 add_AT_flag (type_die
, DW_AT_declaration
, 1);
19685 /* We don't need to do this for function-local types. */
19686 if (TYPE_STUB_DECL (type
)
19687 && ! decl_function_context (TYPE_STUB_DECL (type
)))
19688 vec_safe_push (incomplete_types
, type
);
19691 if (get_AT (type_die
, DW_AT_name
))
19692 add_pubtype (type
, type_die
);
19695 /* Generate a DIE for a subroutine _type_. */
19698 gen_subroutine_type_die (tree type
, dw_die_ref context_die
)
19700 tree return_type
= TREE_TYPE (type
);
19701 dw_die_ref subr_die
19702 = new_die (DW_TAG_subroutine_type
,
19703 scope_die_for (type
, context_die
), type
);
19705 equate_type_number_to_die (type
, subr_die
);
19706 add_prototyped_attribute (subr_die
, type
);
19707 add_type_attribute (subr_die
, return_type
, 0, 0, context_die
);
19708 gen_formal_types_die (type
, subr_die
);
19710 if (get_AT (subr_die
, DW_AT_name
))
19711 add_pubtype (type
, subr_die
);
19714 /* Generate a DIE for a type definition. */
19717 gen_typedef_die (tree decl
, dw_die_ref context_die
)
19719 dw_die_ref type_die
;
19722 if (TREE_ASM_WRITTEN (decl
))
19725 TREE_ASM_WRITTEN (decl
) = 1;
19726 type_die
= new_die (DW_TAG_typedef
, context_die
, decl
);
19727 origin
= decl_ultimate_origin (decl
);
19728 if (origin
!= NULL
)
19729 add_abstract_origin_attribute (type_die
, origin
);
19734 add_name_and_src_coords_attributes (type_die
, decl
);
19735 if (DECL_ORIGINAL_TYPE (decl
))
19737 type
= DECL_ORIGINAL_TYPE (decl
);
19739 gcc_assert (type
!= TREE_TYPE (decl
));
19740 equate_type_number_to_die (TREE_TYPE (decl
), type_die
);
19744 type
= TREE_TYPE (decl
);
19746 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19748 /* Here, we are in the case of decl being a typedef naming
19749 an anonymous type, e.g:
19750 typedef struct {...} foo;
19751 In that case TREE_TYPE (decl) is not a typedef variant
19752 type and TYPE_NAME of the anonymous type is set to the
19753 TYPE_DECL of the typedef. This construct is emitted by
19756 TYPE is the anonymous struct named by the typedef
19757 DECL. As we need the DW_AT_type attribute of the
19758 DW_TAG_typedef to point to the DIE of TYPE, let's
19759 generate that DIE right away. add_type_attribute
19760 called below will then pick (via lookup_type_die) that
19761 anonymous struct DIE. */
19762 if (!TREE_ASM_WRITTEN (type
))
19763 gen_tagged_type_die (type
, context_die
, DINFO_USAGE_DIR_USE
);
19765 /* This is a GNU Extension. We are adding a
19766 DW_AT_linkage_name attribute to the DIE of the
19767 anonymous struct TYPE. The value of that attribute
19768 is the name of the typedef decl naming the anonymous
19769 struct. This greatly eases the work of consumers of
19770 this debug info. */
19771 add_linkage_attr (lookup_type_die (type
), decl
);
19775 add_type_attribute (type_die
, type
, TREE_READONLY (decl
),
19776 TREE_THIS_VOLATILE (decl
), context_die
);
19778 if (is_naming_typedef_decl (decl
))
19779 /* We want that all subsequent calls to lookup_type_die with
19780 TYPE in argument yield the DW_TAG_typedef we have just
19782 equate_type_number_to_die (type
, type_die
);
19784 add_accessibility_attribute (type_die
, decl
);
19787 if (DECL_ABSTRACT (decl
))
19788 equate_decl_number_to_die (decl
, type_die
);
19790 if (get_AT (type_die
, DW_AT_name
))
19791 add_pubtype (decl
, type_die
);
19794 /* Generate a DIE for a struct, class, enum or union type. */
19797 gen_tagged_type_die (tree type
,
19798 dw_die_ref context_die
,
19799 enum debug_info_usage usage
)
19803 if (type
== NULL_TREE
19804 || !is_tagged_type (type
))
19807 /* If this is a nested type whose containing class hasn't been written
19808 out yet, writing it out will cover this one, too. This does not apply
19809 to instantiations of member class templates; they need to be added to
19810 the containing class as they are generated. FIXME: This hurts the
19811 idea of combining type decls from multiple TUs, since we can't predict
19812 what set of template instantiations we'll get. */
19813 if (TYPE_CONTEXT (type
)
19814 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type
))
19815 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type
)))
19817 gen_type_die_with_usage (TYPE_CONTEXT (type
), context_die
, usage
);
19819 if (TREE_ASM_WRITTEN (type
))
19822 /* If that failed, attach ourselves to the stub. */
19823 push_decl_scope (TYPE_CONTEXT (type
));
19824 context_die
= lookup_type_die (TYPE_CONTEXT (type
));
19827 else if (TYPE_CONTEXT (type
) != NULL_TREE
19828 && (TREE_CODE (TYPE_CONTEXT (type
)) == FUNCTION_DECL
))
19830 /* If this type is local to a function that hasn't been written
19831 out yet, use a NULL context for now; it will be fixed up in
19832 decls_for_scope. */
19833 context_die
= lookup_decl_die (TYPE_CONTEXT (type
));
19834 /* A declaration DIE doesn't count; nested types need to go in the
19836 if (context_die
&& is_declaration_die (context_die
))
19837 context_die
= NULL
;
19842 context_die
= declare_in_namespace (type
, context_die
);
19846 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
19848 /* This might have been written out by the call to
19849 declare_in_namespace. */
19850 if (!TREE_ASM_WRITTEN (type
))
19851 gen_enumeration_type_die (type
, context_die
);
19854 gen_struct_or_union_type_die (type
, context_die
, usage
);
19859 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix
19860 it up if it is ever completed. gen_*_type_die will set it for us
19861 when appropriate. */
19864 /* Generate a type description DIE. */
19867 gen_type_die_with_usage (tree type
, dw_die_ref context_die
,
19868 enum debug_info_usage usage
)
19870 struct array_descr_info info
;
19872 if (type
== NULL_TREE
|| type
== error_mark_node
)
19875 if (TYPE_NAME (type
) != NULL_TREE
19876 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
19877 && is_redundant_typedef (TYPE_NAME (type
))
19878 && DECL_ORIGINAL_TYPE (TYPE_NAME (type
)))
19879 /* The DECL of this type is a typedef we don't want to emit debug
19880 info for but we want debug info for its underlying typedef.
19881 This can happen for e.g, the injected-class-name of a C++
19883 type
= DECL_ORIGINAL_TYPE (TYPE_NAME (type
));
19885 /* If TYPE is a typedef type variant, let's generate debug info
19886 for the parent typedef which TYPE is a type of. */
19887 if (typedef_variant_p (type
))
19889 if (TREE_ASM_WRITTEN (type
))
19892 /* Prevent broken recursion; we can't hand off to the same type. */
19893 gcc_assert (DECL_ORIGINAL_TYPE (TYPE_NAME (type
)) != type
);
19895 /* Give typedefs the right scope. */
19896 context_die
= scope_die_for (type
, context_die
);
19898 TREE_ASM_WRITTEN (type
) = 1;
19900 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19904 /* If type is an anonymous tagged type named by a typedef, let's
19905 generate debug info for the typedef. */
19906 if (is_naming_typedef_decl (TYPE_NAME (type
)))
19908 /* Use the DIE of the containing namespace as the parent DIE of
19909 the type description DIE we want to generate. */
19910 if (DECL_CONTEXT (TYPE_NAME (type
))
19911 && TREE_CODE (DECL_CONTEXT (TYPE_NAME (type
))) == NAMESPACE_DECL
)
19912 context_die
= get_context_die (DECL_CONTEXT (TYPE_NAME (type
)));
19914 gen_decl_die (TYPE_NAME (type
), NULL
, context_die
);
19918 /* If this is an array type with hidden descriptor, handle it first. */
19919 if (!TREE_ASM_WRITTEN (type
)
19920 && lang_hooks
.types
.get_array_descr_info
19921 && lang_hooks
.types
.get_array_descr_info (type
, &info
)
19922 && (dwarf_version
>= 3 || !dwarf_strict
))
19924 gen_descr_array_type_die (type
, &info
, context_die
);
19925 TREE_ASM_WRITTEN (type
) = 1;
19929 /* We are going to output a DIE to represent the unqualified version
19930 of this type (i.e. without any const or volatile qualifiers) so
19931 get the main variant (i.e. the unqualified version) of this type
19932 now. (Vectors are special because the debugging info is in the
19933 cloned type itself). */
19934 if (TREE_CODE (type
) != VECTOR_TYPE
)
19935 type
= type_main_variant (type
);
19937 if (TREE_ASM_WRITTEN (type
))
19940 switch (TREE_CODE (type
))
19946 case REFERENCE_TYPE
:
19947 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This
19948 ensures that the gen_type_die recursion will terminate even if the
19949 type is recursive. Recursive types are possible in Ada. */
19950 /* ??? We could perhaps do this for all types before the switch
19952 TREE_ASM_WRITTEN (type
) = 1;
19954 /* For these types, all that is required is that we output a DIE (or a
19955 set of DIEs) to represent the "basis" type. */
19956 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19957 DINFO_USAGE_IND_USE
);
19961 /* This code is used for C++ pointer-to-data-member types.
19962 Output a description of the relevant class type. */
19963 gen_type_die_with_usage (TYPE_OFFSET_BASETYPE (type
), context_die
,
19964 DINFO_USAGE_IND_USE
);
19966 /* Output a description of the type of the object pointed to. */
19967 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19968 DINFO_USAGE_IND_USE
);
19970 /* Now output a DIE to represent this pointer-to-data-member type
19972 gen_ptr_to_mbr_type_die (type
, context_die
);
19975 case FUNCTION_TYPE
:
19976 /* Force out return type (in case it wasn't forced out already). */
19977 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19978 DINFO_USAGE_DIR_USE
);
19979 gen_subroutine_type_die (type
, context_die
);
19983 /* Force out return type (in case it wasn't forced out already). */
19984 gen_type_die_with_usage (TREE_TYPE (type
), context_die
,
19985 DINFO_USAGE_DIR_USE
);
19986 gen_subroutine_type_die (type
, context_die
);
19990 gen_array_type_die (type
, context_die
);
19994 gen_array_type_die (type
, context_die
);
19997 case ENUMERAL_TYPE
:
20000 case QUAL_UNION_TYPE
:
20001 gen_tagged_type_die (type
, context_die
, usage
);
20007 case FIXED_POINT_TYPE
:
20010 /* No DIEs needed for fundamental types. */
20015 /* Just use DW_TAG_unspecified_type. */
20017 dw_die_ref type_die
= lookup_type_die (type
);
20018 if (type_die
== NULL
)
20020 tree name
= TYPE_NAME (type
);
20021 if (TREE_CODE (name
) == TYPE_DECL
)
20022 name
= DECL_NAME (name
);
20023 type_die
= new_die (DW_TAG_unspecified_type
, comp_unit_die (), type
);
20024 add_name_attribute (type_die
, IDENTIFIER_POINTER (name
));
20025 equate_type_number_to_die (type
, type_die
);
20031 if (is_cxx_auto (type
))
20033 tree name
= TYPE_NAME (type
);
20034 if (TREE_CODE (name
) == TYPE_DECL
)
20035 name
= DECL_NAME (name
);
20036 dw_die_ref
*die
= (name
== get_identifier ("auto")
20037 ? &auto_die
: &decltype_auto_die
);
20040 *die
= new_die (DW_TAG_unspecified_type
,
20041 comp_unit_die (), NULL_TREE
);
20042 add_name_attribute (*die
, IDENTIFIER_POINTER (name
));
20044 equate_type_number_to_die (type
, *die
);
20047 gcc_unreachable ();
20050 TREE_ASM_WRITTEN (type
) = 1;
20054 gen_type_die (tree type
, dw_die_ref context_die
)
20056 gen_type_die_with_usage (type
, context_die
, DINFO_USAGE_DIR_USE
);
20059 /* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the
20060 things which are local to the given block. */
20063 gen_block_die (tree stmt
, dw_die_ref context_die
, int depth
)
20065 int must_output_die
= 0;
20068 /* Ignore blocks that are NULL. */
20069 if (stmt
== NULL_TREE
)
20072 inlined_func
= inlined_function_outer_scope_p (stmt
);
20074 /* If the block is one fragment of a non-contiguous block, do not
20075 process the variables, since they will have been done by the
20076 origin block. Do process subblocks. */
20077 if (BLOCK_FRAGMENT_ORIGIN (stmt
))
20081 for (sub
= BLOCK_SUBBLOCKS (stmt
); sub
; sub
= BLOCK_CHAIN (sub
))
20082 gen_block_die (sub
, context_die
, depth
+ 1);
20087 /* Determine if we need to output any Dwarf DIEs at all to represent this
20090 /* The outer scopes for inlinings *must* always be represented. We
20091 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */
20092 must_output_die
= 1;
20095 /* Determine if this block directly contains any "significant"
20096 local declarations which we will need to output DIEs for. */
20097 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20098 /* We are not in terse mode so *any* local declaration counts
20099 as being a "significant" one. */
20100 must_output_die
= ((BLOCK_VARS (stmt
) != NULL
20101 || BLOCK_NUM_NONLOCALIZED_VARS (stmt
))
20102 && (TREE_USED (stmt
)
20103 || TREE_ASM_WRITTEN (stmt
)
20104 || BLOCK_ABSTRACT (stmt
)));
20105 else if ((TREE_USED (stmt
)
20106 || TREE_ASM_WRITTEN (stmt
)
20107 || BLOCK_ABSTRACT (stmt
))
20108 && !dwarf2out_ignore_block (stmt
))
20109 must_output_die
= 1;
20112 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block
20113 DIE for any block which contains no significant local declarations at
20114 all. Rather, in such cases we just call `decls_for_scope' so that any
20115 needed Dwarf info for any sub-blocks will get properly generated. Note
20116 that in terse mode, our definition of what constitutes a "significant"
20117 local declaration gets restricted to include only inlined function
20118 instances and local (nested) function definitions. */
20119 if (must_output_die
)
20123 /* If STMT block is abstract, that means we have been called
20124 indirectly from dwarf2out_abstract_function.
20125 That function rightfully marks the descendent blocks (of
20126 the abstract function it is dealing with) as being abstract,
20127 precisely to prevent us from emitting any
20128 DW_TAG_inlined_subroutine DIE as a descendent
20129 of an abstract function instance. So in that case, we should
20130 not call gen_inlined_subroutine_die.
20132 Later though, when cgraph asks dwarf2out to emit info
20133 for the concrete instance of the function decl into which
20134 the concrete instance of STMT got inlined, the later will lead
20135 to the generation of a DW_TAG_inlined_subroutine DIE. */
20136 if (! BLOCK_ABSTRACT (stmt
))
20137 gen_inlined_subroutine_die (stmt
, context_die
, depth
);
20140 gen_lexical_block_die (stmt
, context_die
, depth
);
20143 decls_for_scope (stmt
, context_die
, depth
);
20146 /* Process variable DECL (or variable with origin ORIGIN) within
20147 block STMT and add it to CONTEXT_DIE. */
20149 process_scope_var (tree stmt
, tree decl
, tree origin
, dw_die_ref context_die
)
20152 tree decl_or_origin
= decl
? decl
: origin
;
20154 if (TREE_CODE (decl_or_origin
) == FUNCTION_DECL
)
20155 die
= lookup_decl_die (decl_or_origin
);
20156 else if (TREE_CODE (decl_or_origin
) == TYPE_DECL
20157 && TYPE_DECL_IS_STUB (decl_or_origin
))
20158 die
= lookup_type_die (TREE_TYPE (decl_or_origin
));
20162 if (die
!= NULL
&& die
->die_parent
== NULL
)
20163 add_child_die (context_die
, die
);
20164 else if (TREE_CODE (decl_or_origin
) == IMPORTED_DECL
)
20165 dwarf2out_imported_module_or_decl_1 (decl_or_origin
, DECL_NAME (decl_or_origin
),
20166 stmt
, context_die
);
20168 gen_decl_die (decl
, origin
, context_die
);
20171 /* Generate all of the decls declared within a given scope and (recursively)
20172 all of its sub-blocks. */
20175 decls_for_scope (tree stmt
, dw_die_ref context_die
, int depth
)
20181 /* Ignore NULL blocks. */
20182 if (stmt
== NULL_TREE
)
20185 /* Output the DIEs to represent all of the data objects and typedefs
20186 declared directly within this block but not within any nested
20187 sub-blocks. Also, nested function and tag DIEs have been
20188 generated with a parent of NULL; fix that up now. We don't
20189 have to do this if we're at -g1. */
20190 if (debug_info_level
> DINFO_LEVEL_TERSE
)
20192 for (decl
= BLOCK_VARS (stmt
); decl
!= NULL
; decl
= DECL_CHAIN (decl
))
20193 process_scope_var (stmt
, decl
, NULL_TREE
, context_die
);
20194 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (stmt
); i
++)
20195 process_scope_var (stmt
, NULL
, BLOCK_NONLOCALIZED_VAR (stmt
, i
),
20199 /* Even if we're at -g1, we need to process the subblocks in order to get
20200 inlined call information. */
20202 /* Output the DIEs to represent all sub-blocks (and the items declared
20203 therein) of this block. */
20204 for (subblocks
= BLOCK_SUBBLOCKS (stmt
);
20206 subblocks
= BLOCK_CHAIN (subblocks
))
20207 gen_block_die (subblocks
, context_die
, depth
+ 1);
20210 /* Is this a typedef we can avoid emitting? */
20213 is_redundant_typedef (const_tree decl
)
20215 if (TYPE_DECL_IS_STUB (decl
))
20218 if (DECL_ARTIFICIAL (decl
)
20219 && DECL_CONTEXT (decl
)
20220 && is_tagged_type (DECL_CONTEXT (decl
))
20221 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl
))) == TYPE_DECL
20222 && DECL_NAME (decl
) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl
))))
20223 /* Also ignore the artificial member typedef for the class name. */
20229 /* Return TRUE if TYPE is a typedef that names a type for linkage
20230 purposes. This kind of typedefs is produced by the C++ FE for
20233 typedef struct {...} foo;
20235 In that case, there is no typedef variant type produced for foo.
20236 Rather, the TREE_TYPE of the TYPE_DECL of foo is the anonymous
20240 is_naming_typedef_decl (const_tree decl
)
20242 if (decl
== NULL_TREE
20243 || TREE_CODE (decl
) != TYPE_DECL
20244 || !is_tagged_type (TREE_TYPE (decl
))
20245 || DECL_IS_BUILTIN (decl
)
20246 || is_redundant_typedef (decl
)
20247 /* It looks like Ada produces TYPE_DECLs that are very similar
20248 to C++ naming typedefs but that have different
20249 semantics. Let's be specific to c++ for now. */
20253 return (DECL_ORIGINAL_TYPE (decl
) == NULL_TREE
20254 && TYPE_NAME (TREE_TYPE (decl
)) == decl
20255 && (TYPE_STUB_DECL (TREE_TYPE (decl
))
20256 != TYPE_NAME (TREE_TYPE (decl
))));
20259 /* Returns the DIE for a context. */
20261 static inline dw_die_ref
20262 get_context_die (tree context
)
20266 /* Find die that represents this context. */
20267 if (TYPE_P (context
))
20269 context
= TYPE_MAIN_VARIANT (context
);
20270 return strip_naming_typedef (context
, force_type_die (context
));
20273 return force_decl_die (context
);
20275 return comp_unit_die ();
20278 /* Returns the DIE for decl. A DIE will always be returned. */
20281 force_decl_die (tree decl
)
20283 dw_die_ref decl_die
;
20284 unsigned saved_external_flag
;
20285 tree save_fn
= NULL_TREE
;
20286 decl_die
= lookup_decl_die (decl
);
20289 dw_die_ref context_die
= get_context_die (DECL_CONTEXT (decl
));
20291 decl_die
= lookup_decl_die (decl
);
20295 switch (TREE_CODE (decl
))
20297 case FUNCTION_DECL
:
20298 /* Clear current_function_decl, so that gen_subprogram_die thinks
20299 that this is a declaration. At this point, we just want to force
20300 declaration die. */
20301 save_fn
= current_function_decl
;
20302 current_function_decl
= NULL_TREE
;
20303 gen_subprogram_die (decl
, context_die
);
20304 current_function_decl
= save_fn
;
20308 /* Set external flag to force declaration die. Restore it after
20309 gen_decl_die() call. */
20310 saved_external_flag
= DECL_EXTERNAL (decl
);
20311 DECL_EXTERNAL (decl
) = 1;
20312 gen_decl_die (decl
, NULL
, context_die
);
20313 DECL_EXTERNAL (decl
) = saved_external_flag
;
20316 case NAMESPACE_DECL
:
20317 if (dwarf_version
>= 3 || !dwarf_strict
)
20318 dwarf2out_decl (decl
);
20320 /* DWARF2 has neither DW_TAG_module, nor DW_TAG_namespace. */
20321 decl_die
= comp_unit_die ();
20324 case TRANSLATION_UNIT_DECL
:
20325 decl_die
= comp_unit_die ();
20329 gcc_unreachable ();
20332 /* We should be able to find the DIE now. */
20334 decl_die
= lookup_decl_die (decl
);
20335 gcc_assert (decl_die
);
20341 /* Returns the DIE for TYPE, that must not be a base type. A DIE is
20342 always returned. */
20345 force_type_die (tree type
)
20347 dw_die_ref type_die
;
20349 type_die
= lookup_type_die (type
);
20352 dw_die_ref context_die
= get_context_die (TYPE_CONTEXT (type
));
20354 type_die
= modified_type_die (type
, TYPE_READONLY (type
),
20355 TYPE_VOLATILE (type
), context_die
);
20356 gcc_assert (type_die
);
20361 /* Force out any required namespaces to be able to output DECL,
20362 and return the new context_die for it, if it's changed. */
20365 setup_namespace_context (tree thing
, dw_die_ref context_die
)
20367 tree context
= (DECL_P (thing
)
20368 ? DECL_CONTEXT (thing
) : TYPE_CONTEXT (thing
));
20369 if (context
&& TREE_CODE (context
) == NAMESPACE_DECL
)
20370 /* Force out the namespace. */
20371 context_die
= force_decl_die (context
);
20373 return context_die
;
20376 /* Emit a declaration DIE for THING (which is either a DECL or a tagged
20377 type) within its namespace, if appropriate.
20379 For compatibility with older debuggers, namespace DIEs only contain
20380 declarations; all definitions are emitted at CU scope. */
20383 declare_in_namespace (tree thing
, dw_die_ref context_die
)
20385 dw_die_ref ns_context
;
20387 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20388 return context_die
;
20390 /* If this decl is from an inlined function, then don't try to emit it in its
20391 namespace, as we will get confused. It would have already been emitted
20392 when the abstract instance of the inline function was emitted anyways. */
20393 if (DECL_P (thing
) && DECL_ABSTRACT_ORIGIN (thing
))
20394 return context_die
;
20396 ns_context
= setup_namespace_context (thing
, context_die
);
20398 if (ns_context
!= context_die
)
20402 if (DECL_P (thing
))
20403 gen_decl_die (thing
, NULL
, ns_context
);
20405 gen_type_die (thing
, ns_context
);
20407 return context_die
;
20410 /* Generate a DIE for a namespace or namespace alias. */
20413 gen_namespace_die (tree decl
, dw_die_ref context_die
)
20415 dw_die_ref namespace_die
;
20417 /* Namespace aliases have a DECL_ABSTRACT_ORIGIN of the namespace
20418 they are an alias of. */
20419 if (DECL_ABSTRACT_ORIGIN (decl
) == NULL
)
20421 /* Output a real namespace or module. */
20422 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20423 namespace_die
= new_die (is_fortran ()
20424 ? DW_TAG_module
: DW_TAG_namespace
,
20425 context_die
, decl
);
20426 /* For Fortran modules defined in different CU don't add src coords. */
20427 if (namespace_die
->die_tag
== DW_TAG_module
&& DECL_EXTERNAL (decl
))
20429 const char *name
= dwarf2_name (decl
, 0);
20431 add_name_attribute (namespace_die
, name
);
20434 add_name_and_src_coords_attributes (namespace_die
, decl
);
20435 if (DECL_EXTERNAL (decl
))
20436 add_AT_flag (namespace_die
, DW_AT_declaration
, 1);
20437 equate_decl_number_to_die (decl
, namespace_die
);
20441 /* Output a namespace alias. */
20443 /* Force out the namespace we are an alias of, if necessary. */
20444 dw_die_ref origin_die
20445 = force_decl_die (DECL_ABSTRACT_ORIGIN (decl
));
20447 if (DECL_FILE_SCOPE_P (decl
)
20448 || TREE_CODE (DECL_CONTEXT (decl
)) == NAMESPACE_DECL
)
20449 context_die
= setup_namespace_context (decl
, comp_unit_die ());
20450 /* Now create the namespace alias DIE. */
20451 namespace_die
= new_die (DW_TAG_imported_declaration
, context_die
, decl
);
20452 add_name_and_src_coords_attributes (namespace_die
, decl
);
20453 add_AT_die_ref (namespace_die
, DW_AT_import
, origin_die
);
20454 equate_decl_number_to_die (decl
, namespace_die
);
20456 /* Bypass dwarf2_name's check for DECL_NAMELESS. */
20457 if (want_pubnames ())
20458 add_pubname_string (lang_hooks
.dwarf_name (decl
, 1), namespace_die
);
20461 /* Generate Dwarf debug information for a decl described by DECL.
20462 The return value is currently only meaningful for PARM_DECLs,
20463 for all other decls it returns NULL. */
20466 gen_decl_die (tree decl
, tree origin
, dw_die_ref context_die
)
20468 tree decl_or_origin
= decl
? decl
: origin
;
20469 tree class_origin
= NULL
, ultimate_origin
;
20471 if (DECL_P (decl_or_origin
) && DECL_IGNORED_P (decl_or_origin
))
20474 switch (TREE_CODE (decl_or_origin
))
20480 if (!is_fortran () && !is_ada ())
20482 /* The individual enumerators of an enum type get output when we output
20483 the Dwarf representation of the relevant enum type itself. */
20487 /* Emit its type. */
20488 gen_type_die (TREE_TYPE (decl
), context_die
);
20490 /* And its containing namespace. */
20491 context_die
= declare_in_namespace (decl
, context_die
);
20493 gen_const_die (decl
, context_die
);
20496 case FUNCTION_DECL
:
20497 /* Don't output any DIEs to represent mere function declarations,
20498 unless they are class members or explicit block externs. */
20499 if (DECL_INITIAL (decl_or_origin
) == NULL_TREE
20500 && DECL_FILE_SCOPE_P (decl_or_origin
)
20501 && (current_function_decl
== NULL_TREE
20502 || DECL_ARTIFICIAL (decl_or_origin
)))
20507 /* This doesn't work because the C frontend sets DECL_ABSTRACT_ORIGIN
20508 on local redeclarations of global functions. That seems broken. */
20509 if (current_function_decl
!= decl
)
20510 /* This is only a declaration. */;
20513 /* If we're emitting a clone, emit info for the abstract instance. */
20514 if (origin
|| DECL_ORIGIN (decl
) != decl
)
20515 dwarf2out_abstract_function (origin
20516 ? DECL_ORIGIN (origin
)
20517 : DECL_ABSTRACT_ORIGIN (decl
));
20519 /* If we're emitting an out-of-line copy of an inline function,
20520 emit info for the abstract instance and set up to refer to it. */
20521 else if (cgraph_function_possibly_inlined_p (decl
)
20522 && ! DECL_ABSTRACT (decl
)
20523 && ! class_or_namespace_scope_p (context_die
)
20524 /* dwarf2out_abstract_function won't emit a die if this is just
20525 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in
20526 that case, because that works only if we have a die. */
20527 && DECL_INITIAL (decl
) != NULL_TREE
)
20529 dwarf2out_abstract_function (decl
);
20530 set_decl_origin_self (decl
);
20533 /* Otherwise we're emitting the primary DIE for this decl. */
20534 else if (debug_info_level
> DINFO_LEVEL_TERSE
)
20536 /* Before we describe the FUNCTION_DECL itself, make sure that we
20537 have its containing type. */
20539 origin
= decl_class_context (decl
);
20540 if (origin
!= NULL_TREE
)
20541 gen_type_die (origin
, context_die
);
20543 /* And its return type. */
20544 gen_type_die (TREE_TYPE (TREE_TYPE (decl
)), context_die
);
20546 /* And its virtual context. */
20547 if (DECL_VINDEX (decl
) != NULL_TREE
)
20548 gen_type_die (DECL_CONTEXT (decl
), context_die
);
20550 /* Make sure we have a member DIE for decl. */
20551 if (origin
!= NULL_TREE
)
20552 gen_type_die_for_member (origin
, decl
, context_die
);
20554 /* And its containing namespace. */
20555 context_die
= declare_in_namespace (decl
, context_die
);
20558 /* Now output a DIE to represent the function itself. */
20560 gen_subprogram_die (decl
, context_die
);
20564 /* If we are in terse mode, don't generate any DIEs to represent any
20565 actual typedefs. */
20566 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20569 /* In the special case of a TYPE_DECL node representing the declaration
20570 of some type tag, if the given TYPE_DECL is marked as having been
20571 instantiated from some other (original) TYPE_DECL node (e.g. one which
20572 was generated within the original definition of an inline function) we
20573 used to generate a special (abbreviated) DW_TAG_structure_type,
20574 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. But nothing
20575 should be actually referencing those DIEs, as variable DIEs with that
20576 type would be emitted already in the abstract origin, so it was always
20577 removed during unused type prunning. Don't add anything in this
20579 if (TYPE_DECL_IS_STUB (decl
) && decl_ultimate_origin (decl
) != NULL_TREE
)
20582 if (is_redundant_typedef (decl
))
20583 gen_type_die (TREE_TYPE (decl
), context_die
);
20585 /* Output a DIE to represent the typedef itself. */
20586 gen_typedef_die (decl
, context_die
);
20590 if (debug_info_level
>= DINFO_LEVEL_NORMAL
)
20591 gen_label_die (decl
, context_die
);
20596 /* If we are in terse mode, don't generate any DIEs to represent any
20597 variable declarations or definitions. */
20598 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20601 /* Output any DIEs that are needed to specify the type of this data
20603 if (decl_by_reference_p (decl_or_origin
))
20604 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20606 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20608 /* And its containing type. */
20609 class_origin
= decl_class_context (decl_or_origin
);
20610 if (class_origin
!= NULL_TREE
)
20611 gen_type_die_for_member (class_origin
, decl_or_origin
, context_die
);
20613 /* And its containing namespace. */
20614 context_die
= declare_in_namespace (decl_or_origin
, context_die
);
20616 /* Now output the DIE to represent the data object itself. This gets
20617 complicated because of the possibility that the VAR_DECL really
20618 represents an inlined instance of a formal parameter for an inline
20620 ultimate_origin
= decl_ultimate_origin (decl_or_origin
);
20621 if (ultimate_origin
!= NULL_TREE
20622 && TREE_CODE (ultimate_origin
) == PARM_DECL
)
20623 gen_formal_parameter_die (decl
, origin
,
20624 true /* Emit name attribute. */,
20627 gen_variable_die (decl
, origin
, context_die
);
20631 /* Ignore the nameless fields that are used to skip bits but handle C++
20632 anonymous unions and structs. */
20633 if (DECL_NAME (decl
) != NULL_TREE
20634 || TREE_CODE (TREE_TYPE (decl
)) == UNION_TYPE
20635 || TREE_CODE (TREE_TYPE (decl
)) == RECORD_TYPE
)
20637 gen_type_die (member_declared_type (decl
), context_die
);
20638 gen_field_die (decl
, context_die
);
20643 if (DECL_BY_REFERENCE (decl_or_origin
))
20644 gen_type_die (TREE_TYPE (TREE_TYPE (decl_or_origin
)), context_die
);
20646 gen_type_die (TREE_TYPE (decl_or_origin
), context_die
);
20647 return gen_formal_parameter_die (decl
, origin
,
20648 true /* Emit name attribute. */,
20651 case NAMESPACE_DECL
:
20652 case IMPORTED_DECL
:
20653 if (dwarf_version
>= 3 || !dwarf_strict
)
20654 gen_namespace_die (decl
, context_die
);
20657 case NAMELIST_DECL
:
20658 gen_namelist_decl (DECL_NAME (decl
), context_die
,
20659 NAMELIST_DECL_ASSOCIATED_DECL (decl
));
20663 /* Probably some frontend-internal decl. Assume we don't care. */
20664 gcc_assert ((int)TREE_CODE (decl
) > NUM_TREE_CODES
);
20671 /* Output debug information for global decl DECL. Called from toplev.c after
20672 compilation proper has finished. */
20675 dwarf2out_global_decl (tree decl
)
20677 /* Output DWARF2 information for file-scope tentative data object
20678 declarations, file-scope (extern) function declarations (which
20679 had no corresponding body) and file-scope tagged type declarations
20680 and definitions which have not yet been forced out. */
20681 if (TREE_CODE (decl
) != FUNCTION_DECL
|| !DECL_INITIAL (decl
))
20682 dwarf2out_decl (decl
);
20685 /* Output debug information for type decl DECL. Called from toplev.c
20686 and from language front ends (to record built-in types). */
20688 dwarf2out_type_decl (tree decl
, int local
)
20691 dwarf2out_decl (decl
);
20694 /* Output debug information for imported module or decl DECL.
20695 NAME is non-NULL name in the lexical block if the decl has been renamed.
20696 LEXICAL_BLOCK is the lexical block (which TREE_CODE is a BLOCK)
20697 that DECL belongs to.
20698 LEXICAL_BLOCK_DIE is the DIE of LEXICAL_BLOCK. */
20700 dwarf2out_imported_module_or_decl_1 (tree decl
,
20702 tree lexical_block
,
20703 dw_die_ref lexical_block_die
)
20705 expanded_location xloc
;
20706 dw_die_ref imported_die
= NULL
;
20707 dw_die_ref at_import_die
;
20709 if (TREE_CODE (decl
) == IMPORTED_DECL
)
20711 xloc
= expand_location (DECL_SOURCE_LOCATION (decl
));
20712 decl
= IMPORTED_DECL_ASSOCIATED_DECL (decl
);
20716 xloc
= expand_location (input_location
);
20718 if (TREE_CODE (decl
) == TYPE_DECL
|| TREE_CODE (decl
) == CONST_DECL
)
20720 at_import_die
= force_type_die (TREE_TYPE (decl
));
20721 /* For namespace N { typedef void T; } using N::T; base_type_die
20722 returns NULL, but DW_TAG_imported_declaration requires
20723 the DW_AT_import tag. Force creation of DW_TAG_typedef. */
20724 if (!at_import_die
)
20726 gcc_assert (TREE_CODE (decl
) == TYPE_DECL
);
20727 gen_typedef_die (decl
, get_context_die (DECL_CONTEXT (decl
)));
20728 at_import_die
= lookup_type_die (TREE_TYPE (decl
));
20729 gcc_assert (at_import_die
);
20734 at_import_die
= lookup_decl_die (decl
);
20735 if (!at_import_die
)
20737 /* If we're trying to avoid duplicate debug info, we may not have
20738 emitted the member decl for this field. Emit it now. */
20739 if (TREE_CODE (decl
) == FIELD_DECL
)
20741 tree type
= DECL_CONTEXT (decl
);
20743 if (TYPE_CONTEXT (type
)
20744 && TYPE_P (TYPE_CONTEXT (type
))
20745 && !should_emit_struct_debug (TYPE_CONTEXT (type
),
20746 DINFO_USAGE_DIR_USE
))
20748 gen_type_die_for_member (type
, decl
,
20749 get_context_die (TYPE_CONTEXT (type
)));
20751 if (TREE_CODE (decl
) == NAMELIST_DECL
)
20752 at_import_die
= gen_namelist_decl (DECL_NAME (decl
),
20753 get_context_die (DECL_CONTEXT (decl
)),
20756 at_import_die
= force_decl_die (decl
);
20760 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
20762 if (dwarf_version
>= 3 || !dwarf_strict
)
20763 imported_die
= new_die (DW_TAG_imported_module
,
20770 imported_die
= new_die (DW_TAG_imported_declaration
,
20774 add_AT_file (imported_die
, DW_AT_decl_file
, lookup_filename (xloc
.file
));
20775 add_AT_unsigned (imported_die
, DW_AT_decl_line
, xloc
.line
);
20777 add_AT_string (imported_die
, DW_AT_name
,
20778 IDENTIFIER_POINTER (name
));
20779 add_AT_die_ref (imported_die
, DW_AT_import
, at_import_die
);
20782 /* Output debug information for imported module or decl DECL.
20783 NAME is non-NULL name in context if the decl has been renamed.
20784 CHILD is true if decl is one of the renamed decls as part of
20785 importing whole module. */
20788 dwarf2out_imported_module_or_decl (tree decl
, tree name
, tree context
,
20791 /* dw_die_ref at_import_die; */
20792 dw_die_ref scope_die
;
20794 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20799 /* To emit DW_TAG_imported_module or DW_TAG_imported_decl, we need two DIEs.
20800 We need decl DIE for reference and scope die. First, get DIE for the decl
20803 /* Get the scope die for decl context. Use comp_unit_die for global module
20804 or decl. If die is not found for non globals, force new die. */
20806 && TYPE_P (context
)
20807 && !should_emit_struct_debug (context
, DINFO_USAGE_DIR_USE
))
20810 if (!(dwarf_version
>= 3 || !dwarf_strict
))
20813 scope_die
= get_context_die (context
);
20817 gcc_assert (scope_die
->die_child
);
20818 gcc_assert (scope_die
->die_child
->die_tag
== DW_TAG_imported_module
);
20819 gcc_assert (TREE_CODE (decl
) != NAMESPACE_DECL
);
20820 scope_die
= scope_die
->die_child
;
20823 /* OK, now we have DIEs for decl as well as scope. Emit imported die. */
20824 dwarf2out_imported_module_or_decl_1 (decl
, name
, context
, scope_die
);
20828 /* Output debug information for namelists. */
20831 gen_namelist_decl (tree name
, dw_die_ref scope_die
, tree item_decls
)
20833 dw_die_ref nml_die
, nml_item_die
, nml_item_ref_die
;
20837 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20840 gcc_assert (scope_die
!= NULL
);
20841 nml_die
= new_die (DW_TAG_namelist
, scope_die
, NULL
);
20842 add_AT_string (nml_die
, DW_AT_name
, IDENTIFIER_POINTER (name
));
20844 /* If there are no item_decls, we have a nondefining namelist, e.g.
20845 with USE association; hence, set DW_AT_declaration. */
20846 if (item_decls
== NULL_TREE
)
20848 add_AT_flag (nml_die
, DW_AT_declaration
, 1);
20852 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (item_decls
), i
, value
)
20854 nml_item_ref_die
= lookup_decl_die (value
);
20855 if (!nml_item_ref_die
)
20856 nml_item_ref_die
= force_decl_die (value
);
20858 nml_item_die
= new_die (DW_TAG_namelist_item
, nml_die
, NULL
);
20859 add_AT_die_ref (nml_item_die
, DW_AT_namelist_items
, nml_item_ref_die
);
20865 /* Write the debugging output for DECL. */
20868 dwarf2out_decl (tree decl
)
20870 dw_die_ref context_die
= comp_unit_die ();
20872 switch (TREE_CODE (decl
))
20877 case FUNCTION_DECL
:
20878 /* What we would really like to do here is to filter out all mere
20879 file-scope declarations of file-scope functions which are never
20880 referenced later within this translation unit (and keep all of ones
20881 that *are* referenced later on) but we aren't clairvoyant, so we have
20882 no idea which functions will be referenced in the future (i.e. later
20883 on within the current translation unit). So here we just ignore all
20884 file-scope function declarations which are not also definitions. If
20885 and when the debugger needs to know something about these functions,
20886 it will have to hunt around and find the DWARF information associated
20887 with the definition of the function.
20889 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL
20890 nodes represent definitions and which ones represent mere
20891 declarations. We have to check DECL_INITIAL instead. That's because
20892 the C front-end supports some weird semantics for "extern inline"
20893 function definitions. These can get inlined within the current
20894 translation unit (and thus, we need to generate Dwarf info for their
20895 abstract instances so that the Dwarf info for the concrete inlined
20896 instances can have something to refer to) but the compiler never
20897 generates any out-of-lines instances of such things (despite the fact
20898 that they *are* definitions).
20900 The important point is that the C front-end marks these "extern
20901 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for
20902 them anyway. Note that the C++ front-end also plays some similar games
20903 for inline function definitions appearing within include files which
20904 also contain `#pragma interface' pragmas.
20906 If we are called from dwarf2out_abstract_function output a DIE
20907 anyway. We can end up here this way with early inlining and LTO
20908 where the inlined function is output in a different LTRANS unit
20910 if (DECL_INITIAL (decl
) == NULL_TREE
20911 && ! DECL_ABSTRACT (decl
))
20914 /* If we're a nested function, initially use a parent of NULL; if we're
20915 a plain function, this will be fixed up in decls_for_scope. If
20916 we're a method, it will be ignored, since we already have a DIE. */
20917 if (decl_function_context (decl
)
20918 /* But if we're in terse mode, we don't care about scope. */
20919 && debug_info_level
> DINFO_LEVEL_TERSE
)
20920 context_die
= NULL
;
20924 /* Ignore this VAR_DECL if it refers to a file-scope extern data object
20925 declaration and if the declaration was never even referenced from
20926 within this entire compilation unit. We suppress these DIEs in
20927 order to save space in the .debug section (by eliminating entries
20928 which are probably useless). Note that we must not suppress
20929 block-local extern declarations (whether used or not) because that
20930 would screw-up the debugger's name lookup mechanism and cause it to
20931 miss things which really ought to be in scope at a given point. */
20932 if (DECL_EXTERNAL (decl
) && !TREE_USED (decl
))
20935 /* For local statics lookup proper context die. */
20936 if (TREE_STATIC (decl
)
20937 && DECL_CONTEXT (decl
)
20938 && TREE_CODE (DECL_CONTEXT (decl
)) == FUNCTION_DECL
)
20939 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20941 /* If we are in terse mode, don't generate any DIEs to represent any
20942 variable declarations or definitions. */
20943 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20948 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20950 if (!is_fortran () && !is_ada ())
20952 if (TREE_STATIC (decl
) && decl_function_context (decl
))
20953 context_die
= lookup_decl_die (DECL_CONTEXT (decl
));
20956 case NAMESPACE_DECL
:
20957 case IMPORTED_DECL
:
20958 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20960 if (lookup_decl_die (decl
) != NULL
)
20965 /* Don't emit stubs for types unless they are needed by other DIEs. */
20966 if (TYPE_DECL_SUPPRESS_DEBUG (decl
))
20969 /* Don't bother trying to generate any DIEs to represent any of the
20970 normal built-in types for the language we are compiling. */
20971 if (DECL_IS_BUILTIN (decl
))
20974 /* If we are in terse mode, don't generate any DIEs for types. */
20975 if (debug_info_level
<= DINFO_LEVEL_TERSE
)
20978 /* If we're a function-scope tag, initially use a parent of NULL;
20979 this will be fixed up in decls_for_scope. */
20980 if (decl_function_context (decl
))
20981 context_die
= NULL
;
20985 case NAMELIST_DECL
:
20992 gen_decl_die (decl
, NULL
, context_die
);
20995 /* Write the debugging output for DECL. */
20998 dwarf2out_function_decl (tree decl
)
21000 dwarf2out_decl (decl
);
21001 call_arg_locations
= NULL
;
21002 call_arg_loc_last
= NULL
;
21003 call_site_count
= -1;
21004 tail_call_site_count
= -1;
21005 block_map
.release ();
21006 htab_empty (decl_loc_table
);
21007 htab_empty (cached_dw_loc_list_table
);
21010 /* Output a marker (i.e. a label) for the beginning of the generated code for
21011 a lexical block. */
21014 dwarf2out_begin_block (unsigned int line ATTRIBUTE_UNUSED
,
21015 unsigned int blocknum
)
21017 switch_to_section (current_function_section ());
21018 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_BEGIN_LABEL
, blocknum
);
21021 /* Output a marker (i.e. a label) for the end of the generated code for a
21025 dwarf2out_end_block (unsigned int line ATTRIBUTE_UNUSED
, unsigned int blocknum
)
21027 switch_to_section (current_function_section ());
21028 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, BLOCK_END_LABEL
, blocknum
);
21031 /* Returns nonzero if it is appropriate not to emit any debugging
21032 information for BLOCK, because it doesn't contain any instructions.
21034 Don't allow this for blocks with nested functions or local classes
21035 as we would end up with orphans, and in the presence of scheduling
21036 we may end up calling them anyway. */
21039 dwarf2out_ignore_block (const_tree block
)
21044 for (decl
= BLOCK_VARS (block
); decl
; decl
= DECL_CHAIN (decl
))
21045 if (TREE_CODE (decl
) == FUNCTION_DECL
21046 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21048 for (i
= 0; i
< BLOCK_NUM_NONLOCALIZED_VARS (block
); i
++)
21050 decl
= BLOCK_NONLOCALIZED_VAR (block
, i
);
21051 if (TREE_CODE (decl
) == FUNCTION_DECL
21052 || (TREE_CODE (decl
) == TYPE_DECL
&& TYPE_DECL_IS_STUB (decl
)))
21059 /* Hash table routines for file_hash. */
21062 file_table_eq (const void *p1_p
, const void *p2_p
)
21064 const struct dwarf_file_data
*const p1
=
21065 (const struct dwarf_file_data
*) p1_p
;
21066 const char *const p2
= (const char *) p2_p
;
21067 return filename_cmp (p1
->filename
, p2
) == 0;
21071 file_table_hash (const void *p_p
)
21073 const struct dwarf_file_data
*const p
= (const struct dwarf_file_data
*) p_p
;
21074 return htab_hash_string (p
->filename
);
21077 /* Lookup FILE_NAME (in the list of filenames that we know about here in
21078 dwarf2out.c) and return its "index". The index of each (known) filename is
21079 just a unique number which is associated with only that one filename. We
21080 need such numbers for the sake of generating labels (in the .debug_sfnames
21081 section) and references to those files numbers (in the .debug_srcinfo
21082 and.debug_macinfo sections). If the filename given as an argument is not
21083 found in our current list, add it to the list and assign it the next
21084 available unique index number. In order to speed up searches, we remember
21085 the index of the filename was looked up last. This handles the majority of
21088 static struct dwarf_file_data
*
21089 lookup_filename (const char *file_name
)
21092 struct dwarf_file_data
* created
;
21094 /* Check to see if the file name that was searched on the previous
21095 call matches this file name. If so, return the index. */
21096 if (file_table_last_lookup
21097 && (file_name
== file_table_last_lookup
->filename
21098 || filename_cmp (file_table_last_lookup
->filename
, file_name
) == 0))
21099 return file_table_last_lookup
;
21101 /* Didn't match the previous lookup, search the table. */
21102 slot
= htab_find_slot_with_hash (file_table
, file_name
,
21103 htab_hash_string (file_name
), INSERT
);
21105 return (struct dwarf_file_data
*) *slot
;
21107 created
= ggc_alloc_dwarf_file_data ();
21108 created
->filename
= file_name
;
21109 created
->emitted_number
= 0;
21114 /* If the assembler will construct the file table, then translate the compiler
21115 internal file table number into the assembler file table number, and emit
21116 a .file directive if we haven't already emitted one yet. The file table
21117 numbers are different because we prune debug info for unused variables and
21118 types, which may include filenames. */
21121 maybe_emit_file (struct dwarf_file_data
* fd
)
21123 if (! fd
->emitted_number
)
21125 if (last_emitted_file
)
21126 fd
->emitted_number
= last_emitted_file
->emitted_number
+ 1;
21128 fd
->emitted_number
= 1;
21129 last_emitted_file
= fd
;
21131 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21133 fprintf (asm_out_file
, "\t.file %u ", fd
->emitted_number
);
21134 output_quoted_string (asm_out_file
,
21135 remap_debug_filename (fd
->filename
));
21136 fputc ('\n', asm_out_file
);
21140 return fd
->emitted_number
;
21143 /* Schedule generation of a DW_AT_const_value attribute to DIE.
21144 That generation should happen after function debug info has been
21145 generated. The value of the attribute is the constant value of ARG. */
21148 append_entry_to_tmpl_value_parm_die_table (dw_die_ref die
, tree arg
)
21150 die_arg_entry entry
;
21155 if (!tmpl_value_parm_die_table
)
21156 vec_alloc (tmpl_value_parm_die_table
, 32);
21160 vec_safe_push (tmpl_value_parm_die_table
, entry
);
21163 /* Return TRUE if T is an instance of generic type, FALSE
21167 generic_type_p (tree t
)
21169 if (t
== NULL_TREE
|| !TYPE_P (t
))
21171 return lang_hooks
.get_innermost_generic_parms (t
) != NULL_TREE
;
21174 /* Schedule the generation of the generic parameter dies for the
21175 instance of generic type T. The proper generation itself is later
21176 done by gen_scheduled_generic_parms_dies. */
21179 schedule_generic_params_dies_gen (tree t
)
21181 if (!generic_type_p (t
))
21184 if (!generic_type_instances
)
21185 vec_alloc (generic_type_instances
, 256);
21187 vec_safe_push (generic_type_instances
, t
);
21190 /* Add a DW_AT_const_value attribute to DIEs that were scheduled
21191 by append_entry_to_tmpl_value_parm_die_table. This function must
21192 be called after function DIEs have been generated. */
21195 gen_remaining_tmpl_value_param_die_attribute (void)
21197 if (tmpl_value_parm_die_table
)
21202 FOR_EACH_VEC_ELT (*tmpl_value_parm_die_table
, i
, e
)
21203 tree_add_const_value_attribute (e
->die
, e
->arg
);
21207 /* Generate generic parameters DIEs for instances of generic types
21208 that have been previously scheduled by
21209 schedule_generic_params_dies_gen. This function must be called
21210 after all the types of the CU have been laid out. */
21213 gen_scheduled_generic_parms_dies (void)
21218 if (!generic_type_instances
)
21221 FOR_EACH_VEC_ELT (*generic_type_instances
, i
, t
)
21222 if (COMPLETE_TYPE_P (t
))
21223 gen_generic_params_dies (t
);
21227 /* Replace DW_AT_name for the decl with name. */
21230 dwarf2out_set_name (tree decl
, tree name
)
21236 die
= TYPE_SYMTAB_DIE (decl
);
21240 dname
= dwarf2_name (name
, 0);
21244 attr
= get_AT (die
, DW_AT_name
);
21247 struct indirect_string_node
*node
;
21249 node
= find_AT_string (dname
);
21250 /* replace the string. */
21251 attr
->dw_attr_val
.v
.val_str
= node
;
21255 add_name_attribute (die
, dname
);
21258 /* True if before or during processing of the first function being emitted. */
21259 static bool in_first_function_p
= true;
21260 /* True if loc_note during dwarf2out_var_location call might still be
21261 before first real instruction at address equal to .Ltext0. */
21262 static bool maybe_at_text_label_p
= true;
21263 /* One above highest N where .LVLN label might be equal to .Ltext0 label. */
21264 static unsigned int first_loclabel_num_not_at_text_label
;
21266 /* Called by the final INSN scan whenever we see a var location. We
21267 use it to drop labels in the right places, and throw the location in
21268 our lookup table. */
21271 dwarf2out_var_location (rtx loc_note
)
21273 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
+ 2];
21274 struct var_loc_node
*newloc
;
21275 rtx next_real
, next_note
;
21276 static const char *last_label
;
21277 static const char *last_postcall_label
;
21278 static bool last_in_cold_section_p
;
21279 static rtx expected_next_loc_note
;
21283 if (!NOTE_P (loc_note
))
21285 if (CALL_P (loc_note
))
21288 if (SIBLING_CALL_P (loc_note
))
21289 tail_call_site_count
++;
21294 var_loc_p
= NOTE_KIND (loc_note
) == NOTE_INSN_VAR_LOCATION
;
21295 if (var_loc_p
&& !DECL_P (NOTE_VAR_LOCATION_DECL (loc_note
)))
21298 /* Optimize processing a large consecutive sequence of location
21299 notes so we don't spend too much time in next_real_insn. If the
21300 next insn is another location note, remember the next_real_insn
21301 calculation for next time. */
21302 next_real
= cached_next_real_insn
;
21305 if (expected_next_loc_note
!= loc_note
)
21306 next_real
= NULL_RTX
;
21309 next_note
= NEXT_INSN (loc_note
);
21311 || INSN_DELETED_P (next_note
)
21312 || ! NOTE_P (next_note
)
21313 || (NOTE_KIND (next_note
) != NOTE_INSN_VAR_LOCATION
21314 && NOTE_KIND (next_note
) != NOTE_INSN_CALL_ARG_LOCATION
))
21315 next_note
= NULL_RTX
;
21318 next_real
= next_real_insn (loc_note
);
21322 expected_next_loc_note
= next_note
;
21323 cached_next_real_insn
= next_real
;
21326 cached_next_real_insn
= NULL_RTX
;
21328 /* If there are no instructions which would be affected by this note,
21329 don't do anything. */
21331 && next_real
== NULL_RTX
21332 && !NOTE_DURING_CALL_P (loc_note
))
21335 if (next_real
== NULL_RTX
)
21336 next_real
= get_last_insn ();
21338 /* If there were any real insns between note we processed last time
21339 and this note (or if it is the first note), clear
21340 last_{,postcall_}label so that they are not reused this time. */
21341 if (last_var_location_insn
== NULL_RTX
21342 || last_var_location_insn
!= next_real
21343 || last_in_cold_section_p
!= in_cold_section_p
)
21346 last_postcall_label
= NULL
;
21351 decl
= NOTE_VAR_LOCATION_DECL (loc_note
);
21352 newloc
= add_var_loc_to_decl (decl
, loc_note
,
21353 NOTE_DURING_CALL_P (loc_note
)
21354 ? last_postcall_label
: last_label
);
21355 if (newloc
== NULL
)
21364 /* If there were no real insns between note we processed last time
21365 and this note, use the label we emitted last time. Otherwise
21366 create a new label and emit it. */
21367 if (last_label
== NULL
)
21369 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", loclabel_num
);
21370 ASM_OUTPUT_DEBUG_LABEL (asm_out_file
, "LVL", loclabel_num
);
21372 last_label
= ggc_strdup (loclabel
);
21373 /* See if loclabel might be equal to .Ltext0. If yes,
21374 bump first_loclabel_num_not_at_text_label. */
21375 if (!have_multiple_function_sections
21376 && in_first_function_p
21377 && maybe_at_text_label_p
)
21379 static rtx last_start
;
21381 for (insn
= loc_note
; insn
; insn
= previous_insn (insn
))
21382 if (insn
== last_start
)
21384 else if (!NONDEBUG_INSN_P (insn
))
21388 rtx body
= PATTERN (insn
);
21389 if (GET_CODE (body
) == USE
|| GET_CODE (body
) == CLOBBER
)
21391 /* Inline asm could occupy zero bytes. */
21392 else if (GET_CODE (body
) == ASM_INPUT
21393 || asm_noperands (body
) >= 0)
21395 #ifdef HAVE_attr_length
21396 else if (get_attr_min_length (insn
) == 0)
21401 /* Assume insn has non-zero length. */
21402 maybe_at_text_label_p
= false;
21406 if (maybe_at_text_label_p
)
21408 last_start
= loc_note
;
21409 first_loclabel_num_not_at_text_label
= loclabel_num
;
21416 struct call_arg_loc_node
*ca_loc
21417 = ggc_alloc_cleared_call_arg_loc_node ();
21418 rtx prev
= prev_real_insn (loc_note
), x
;
21419 ca_loc
->call_arg_loc_note
= loc_note
;
21420 ca_loc
->next
= NULL
;
21421 ca_loc
->label
= last_label
;
21424 || (NONJUMP_INSN_P (prev
)
21425 && GET_CODE (PATTERN (prev
)) == SEQUENCE
21426 && CALL_P (XVECEXP (PATTERN (prev
), 0, 0)))));
21427 if (!CALL_P (prev
))
21428 prev
= XVECEXP (PATTERN (prev
), 0, 0);
21429 ca_loc
->tail_call_p
= SIBLING_CALL_P (prev
);
21430 x
= get_call_rtx_from (PATTERN (prev
));
21433 x
= XEXP (XEXP (x
, 0), 0);
21434 if (GET_CODE (x
) == SYMBOL_REF
21435 && SYMBOL_REF_DECL (x
)
21436 && TREE_CODE (SYMBOL_REF_DECL (x
)) == FUNCTION_DECL
)
21437 ca_loc
->symbol_ref
= x
;
21439 ca_loc
->block
= insn_scope (prev
);
21440 if (call_arg_locations
)
21441 call_arg_loc_last
->next
= ca_loc
;
21443 call_arg_locations
= ca_loc
;
21444 call_arg_loc_last
= ca_loc
;
21446 else if (!NOTE_DURING_CALL_P (loc_note
))
21447 newloc
->label
= last_label
;
21450 if (!last_postcall_label
)
21452 sprintf (loclabel
, "%s-1", last_label
);
21453 last_postcall_label
= ggc_strdup (loclabel
);
21455 newloc
->label
= last_postcall_label
;
21458 last_var_location_insn
= next_real
;
21459 last_in_cold_section_p
= in_cold_section_p
;
21462 /* Note in one location list that text section has changed. */
21465 var_location_switch_text_section_1 (void **slot
, void *data ATTRIBUTE_UNUSED
)
21467 var_loc_list
*list
= (var_loc_list
*) *slot
;
21469 list
->last_before_switch
21470 = list
->last
->next
? list
->last
->next
: list
->last
;
21474 /* Note in all location lists that text section has changed. */
21477 var_location_switch_text_section (void)
21479 if (decl_loc_table
== NULL
)
21482 htab_traverse (decl_loc_table
, var_location_switch_text_section_1
, NULL
);
21485 /* Create a new line number table. */
21487 static dw_line_info_table
*
21488 new_line_info_table (void)
21490 dw_line_info_table
*table
;
21492 table
= ggc_alloc_cleared_dw_line_info_table_struct ();
21493 table
->file_num
= 1;
21494 table
->line_num
= 1;
21495 table
->is_stmt
= DWARF_LINE_DEFAULT_IS_STMT_START
;
21500 /* Lookup the "current" table into which we emit line info, so
21501 that we don't have to do it for every source line. */
21504 set_cur_line_info_table (section
*sec
)
21506 dw_line_info_table
*table
;
21508 if (sec
== text_section
)
21509 table
= text_section_line_info
;
21510 else if (sec
== cold_text_section
)
21512 table
= cold_text_section_line_info
;
21515 cold_text_section_line_info
= table
= new_line_info_table ();
21516 table
->end_label
= cold_end_label
;
21521 const char *end_label
;
21523 if (flag_reorder_blocks_and_partition
)
21525 if (in_cold_section_p
)
21526 end_label
= crtl
->subsections
.cold_section_end_label
;
21528 end_label
= crtl
->subsections
.hot_section_end_label
;
21532 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21533 ASM_GENERATE_INTERNAL_LABEL (label
, FUNC_END_LABEL
,
21534 current_function_funcdef_no
);
21535 end_label
= ggc_strdup (label
);
21538 table
= new_line_info_table ();
21539 table
->end_label
= end_label
;
21541 vec_safe_push (separate_line_info
, table
);
21544 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21545 table
->is_stmt
= (cur_line_info_table
21546 ? cur_line_info_table
->is_stmt
21547 : DWARF_LINE_DEFAULT_IS_STMT_START
);
21548 cur_line_info_table
= table
;
21552 /* We need to reset the locations at the beginning of each
21553 function. We can't do this in the end_function hook, because the
21554 declarations that use the locations won't have been output when
21555 that hook is called. Also compute have_multiple_function_sections here. */
21558 dwarf2out_begin_function (tree fun
)
21560 section
*sec
= function_section (fun
);
21562 if (sec
!= text_section
)
21563 have_multiple_function_sections
= true;
21565 if (flag_reorder_blocks_and_partition
&& !cold_text_section
)
21567 gcc_assert (current_function_decl
== fun
);
21568 cold_text_section
= unlikely_text_section ();
21569 switch_to_section (cold_text_section
);
21570 ASM_OUTPUT_LABEL (asm_out_file
, cold_text_section_label
);
21571 switch_to_section (sec
);
21574 dwarf2out_note_section_used ();
21575 call_site_count
= 0;
21576 tail_call_site_count
= 0;
21578 set_cur_line_info_table (sec
);
21581 /* Helper function of dwarf2out_end_function, called only after emitting
21582 the very first function into assembly. Check if some .debug_loc range
21583 might end with a .LVL* label that could be equal to .Ltext0.
21584 In that case we must force using absolute addresses in .debug_loc ranges,
21585 because this range could be .LVLN-.Ltext0 .. .LVLM-.Ltext0 for
21586 .LVLN == .LVLM == .Ltext0, thus 0 .. 0, which is a .debug_loc
21588 Set have_multiple_function_sections to true in that case and
21589 terminate htab traversal. */
21592 find_empty_loc_ranges_at_text_label (void **slot
, void *)
21594 var_loc_list
*entry
;
21595 struct var_loc_node
*node
;
21597 entry
= (var_loc_list
*) *slot
;
21598 node
= entry
->first
;
21599 if (node
&& node
->next
&& node
->next
->label
)
21602 const char *label
= node
->next
->label
;
21603 char loclabel
[MAX_ARTIFICIAL_LABEL_BYTES
];
21605 for (i
= 0; i
< first_loclabel_num_not_at_text_label
; i
++)
21607 ASM_GENERATE_INTERNAL_LABEL (loclabel
, "LVL", i
);
21608 if (strcmp (label
, loclabel
) == 0)
21610 have_multiple_function_sections
= true;
21618 /* Hook called after emitting a function into assembly.
21619 This does something only for the very first function emitted. */
21622 dwarf2out_end_function (unsigned int)
21624 if (in_first_function_p
21625 && !have_multiple_function_sections
21626 && first_loclabel_num_not_at_text_label
21628 htab_traverse (decl_loc_table
, find_empty_loc_ranges_at_text_label
,
21630 in_first_function_p
= false;
21631 maybe_at_text_label_p
= false;
21634 /* Add OPCODE+VAL as an entry at the end of the opcode array in TABLE. */
21637 push_dw_line_info_entry (dw_line_info_table
*table
,
21638 enum dw_line_info_opcode opcode
, unsigned int val
)
21640 dw_line_info_entry e
;
21643 vec_safe_push (table
->entries
, e
);
21646 /* Output a label to mark the beginning of a source code line entry
21647 and record information relating to this source line, in
21648 'line_info_table' for later output of the .debug_line section. */
21649 /* ??? The discriminator parameter ought to be unsigned. */
21652 dwarf2out_source_line (unsigned int line
, const char *filename
,
21653 int discriminator
, bool is_stmt
)
21655 unsigned int file_num
;
21656 dw_line_info_table
*table
;
21658 if (debug_info_level
< DINFO_LEVEL_TERSE
|| line
== 0)
21661 /* The discriminator column was added in dwarf4. Simplify the below
21662 by simply removing it if we're not supposed to output it. */
21663 if (dwarf_version
< 4 && dwarf_strict
)
21666 table
= cur_line_info_table
;
21667 file_num
= maybe_emit_file (lookup_filename (filename
));
21669 /* ??? TODO: Elide duplicate line number entries. Traditionally,
21670 the debugger has used the second (possibly duplicate) line number
21671 at the beginning of the function to mark the end of the prologue.
21672 We could eliminate any other duplicates within the function. For
21673 Dwarf3, we ought to include the DW_LNS_set_prologue_end mark in
21674 that second line number entry. */
21675 /* Recall that this end-of-prologue indication is *not* the same thing
21676 as the end_prologue debug hook. The NOTE_INSN_PROLOGUE_END note,
21677 to which the hook corresponds, follows the last insn that was
21678 emitted by gen_prologue. What we need is to precede the first insn
21679 that had been emitted after NOTE_INSN_FUNCTION_BEG, i.e. the first
21680 insn that corresponds to something the user wrote. These may be
21681 very different locations once scheduling is enabled. */
21683 if (0 && file_num
== table
->file_num
21684 && line
== table
->line_num
21685 && discriminator
== table
->discrim_num
21686 && is_stmt
== table
->is_stmt
)
21689 switch_to_section (current_function_section ());
21691 /* If requested, emit something human-readable. */
21692 if (flag_debug_asm
)
21693 fprintf (asm_out_file
, "\t%s %s:%d\n", ASM_COMMENT_START
, filename
, line
);
21695 if (DWARF2_ASM_LINE_DEBUG_INFO
)
21697 /* Emit the .loc directive understood by GNU as. */
21698 /* "\t.loc %u %u 0 is_stmt %u discriminator %u",
21699 file_num, line, is_stmt, discriminator */
21700 fputs ("\t.loc ", asm_out_file
);
21701 fprint_ul (asm_out_file
, file_num
);
21702 putc (' ', asm_out_file
);
21703 fprint_ul (asm_out_file
, line
);
21704 putc (' ', asm_out_file
);
21705 putc ('0', asm_out_file
);
21707 if (is_stmt
!= table
->is_stmt
)
21709 fputs (" is_stmt ", asm_out_file
);
21710 putc (is_stmt
? '1' : '0', asm_out_file
);
21712 if (SUPPORTS_DISCRIMINATOR
&& discriminator
!= 0)
21714 gcc_assert (discriminator
> 0);
21715 fputs (" discriminator ", asm_out_file
);
21716 fprint_ul (asm_out_file
, (unsigned long) discriminator
);
21718 putc ('\n', asm_out_file
);
21722 unsigned int label_num
= ++line_info_label_num
;
21724 targetm
.asm_out
.internal_label (asm_out_file
, LINE_CODE_LABEL
, label_num
);
21726 push_dw_line_info_entry (table
, LI_set_address
, label_num
);
21727 if (file_num
!= table
->file_num
)
21728 push_dw_line_info_entry (table
, LI_set_file
, file_num
);
21729 if (discriminator
!= table
->discrim_num
)
21730 push_dw_line_info_entry (table
, LI_set_discriminator
, discriminator
);
21731 if (is_stmt
!= table
->is_stmt
)
21732 push_dw_line_info_entry (table
, LI_negate_stmt
, 0);
21733 push_dw_line_info_entry (table
, LI_set_line
, line
);
21736 table
->file_num
= file_num
;
21737 table
->line_num
= line
;
21738 table
->discrim_num
= discriminator
;
21739 table
->is_stmt
= is_stmt
;
21740 table
->in_use
= true;
21743 /* Record the beginning of a new source file. */
21746 dwarf2out_start_source_file (unsigned int lineno
, const char *filename
)
21748 if (flag_eliminate_dwarf2_dups
)
21750 /* Record the beginning of the file for break_out_includes. */
21751 dw_die_ref bincl_die
;
21753 bincl_die
= new_die (DW_TAG_GNU_BINCL
, comp_unit_die (), NULL
);
21754 add_AT_string (bincl_die
, DW_AT_name
, remap_debug_filename (filename
));
21757 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21760 e
.code
= DW_MACINFO_start_file
;
21762 e
.info
= ggc_strdup (filename
);
21763 vec_safe_push (macinfo_table
, e
);
21767 /* Record the end of a source file. */
21770 dwarf2out_end_source_file (unsigned int lineno ATTRIBUTE_UNUSED
)
21772 if (flag_eliminate_dwarf2_dups
)
21773 /* Record the end of the file for break_out_includes. */
21774 new_die (DW_TAG_GNU_EINCL
, comp_unit_die (), NULL
);
21776 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21779 e
.code
= DW_MACINFO_end_file
;
21782 vec_safe_push (macinfo_table
, e
);
21786 /* Called from debug_define in toplev.c. The `buffer' parameter contains
21787 the tail part of the directive line, i.e. the part which is past the
21788 initial whitespace, #, whitespace, directive-name, whitespace part. */
21791 dwarf2out_define (unsigned int lineno ATTRIBUTE_UNUSED
,
21792 const char *buffer ATTRIBUTE_UNUSED
)
21794 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21797 /* Insert a dummy first entry to be able to optimize the whole
21798 predefined macro block using DW_MACRO_GNU_transparent_include. */
21799 if (macinfo_table
->is_empty () && lineno
<= 1)
21804 vec_safe_push (macinfo_table
, e
);
21806 e
.code
= DW_MACINFO_define
;
21808 e
.info
= ggc_strdup (buffer
);
21809 vec_safe_push (macinfo_table
, e
);
21813 /* Called from debug_undef in toplev.c. The `buffer' parameter contains
21814 the tail part of the directive line, i.e. the part which is past the
21815 initial whitespace, #, whitespace, directive-name, whitespace part. */
21818 dwarf2out_undef (unsigned int lineno ATTRIBUTE_UNUSED
,
21819 const char *buffer ATTRIBUTE_UNUSED
)
21821 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
21824 /* Insert a dummy first entry to be able to optimize the whole
21825 predefined macro block using DW_MACRO_GNU_transparent_include. */
21826 if (macinfo_table
->is_empty () && lineno
<= 1)
21831 vec_safe_push (macinfo_table
, e
);
21833 e
.code
= DW_MACINFO_undef
;
21835 e
.info
= ggc_strdup (buffer
);
21836 vec_safe_push (macinfo_table
, e
);
21840 /* Helpers to manipulate hash table of CUs. */
21842 struct macinfo_entry_hasher
: typed_noop_remove
<macinfo_entry
>
21844 typedef macinfo_entry value_type
;
21845 typedef macinfo_entry compare_type
;
21846 static inline hashval_t
hash (const value_type
*);
21847 static inline bool equal (const value_type
*, const compare_type
*);
21851 macinfo_entry_hasher::hash (const value_type
*entry
)
21853 return htab_hash_string (entry
->info
);
21857 macinfo_entry_hasher::equal (const value_type
*entry1
,
21858 const compare_type
*entry2
)
21860 return !strcmp (entry1
->info
, entry2
->info
);
21863 typedef hash_table
<macinfo_entry_hasher
> macinfo_hash_type
;
21865 /* Output a single .debug_macinfo entry. */
21868 output_macinfo_op (macinfo_entry
*ref
)
21872 struct indirect_string_node
*node
;
21873 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
21874 struct dwarf_file_data
*fd
;
21878 case DW_MACINFO_start_file
:
21879 fd
= lookup_filename (ref
->info
);
21880 file_num
= maybe_emit_file (fd
);
21881 dw2_asm_output_data (1, DW_MACINFO_start_file
, "Start new file");
21882 dw2_asm_output_data_uleb128 (ref
->lineno
,
21883 "Included from line number %lu",
21884 (unsigned long) ref
->lineno
);
21885 dw2_asm_output_data_uleb128 (file_num
, "file %s", ref
->info
);
21887 case DW_MACINFO_end_file
:
21888 dw2_asm_output_data (1, DW_MACINFO_end_file
, "End file");
21890 case DW_MACINFO_define
:
21891 case DW_MACINFO_undef
:
21892 len
= strlen (ref
->info
) + 1;
21894 && len
> DWARF_OFFSET_SIZE
21895 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
21896 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
21898 ref
->code
= ref
->code
== DW_MACINFO_define
21899 ? DW_MACRO_GNU_define_indirect
21900 : DW_MACRO_GNU_undef_indirect
;
21901 output_macinfo_op (ref
);
21904 dw2_asm_output_data (1, ref
->code
,
21905 ref
->code
== DW_MACINFO_define
21906 ? "Define macro" : "Undefine macro");
21907 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21908 (unsigned long) ref
->lineno
);
21909 dw2_asm_output_nstring (ref
->info
, -1, "The macro");
21911 case DW_MACRO_GNU_define_indirect
:
21912 case DW_MACRO_GNU_undef_indirect
:
21913 node
= find_AT_string (ref
->info
);
21915 && ((node
->form
== DW_FORM_strp
)
21916 || (node
->form
== DW_FORM_GNU_str_index
)));
21917 dw2_asm_output_data (1, ref
->code
,
21918 ref
->code
== DW_MACRO_GNU_define_indirect
21919 ? "Define macro indirect"
21920 : "Undefine macro indirect");
21921 dw2_asm_output_data_uleb128 (ref
->lineno
, "At line number %lu",
21922 (unsigned long) ref
->lineno
);
21923 if (node
->form
== DW_FORM_strp
)
21924 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, node
->label
,
21925 debug_str_section
, "The macro: \"%s\"",
21928 dw2_asm_output_data_uleb128 (node
->index
, "The macro: \"%s\"",
21931 case DW_MACRO_GNU_transparent_include
:
21932 dw2_asm_output_data (1, ref
->code
, "Transparent include");
21933 ASM_GENERATE_INTERNAL_LABEL (label
,
21934 DEBUG_MACRO_SECTION_LABEL
, ref
->lineno
);
21935 dw2_asm_output_offset (DWARF_OFFSET_SIZE
, label
, NULL
, NULL
);
21938 fprintf (asm_out_file
, "%s unrecognized macinfo code %lu\n",
21939 ASM_COMMENT_START
, (unsigned long) ref
->code
);
21944 /* Attempt to make a sequence of define/undef macinfo ops shareable with
21945 other compilation unit .debug_macinfo sections. IDX is the first
21946 index of a define/undef, return the number of ops that should be
21947 emitted in a comdat .debug_macinfo section and emit
21948 a DW_MACRO_GNU_transparent_include entry referencing it.
21949 If the define/undef entry should be emitted normally, return 0. */
21952 optimize_macinfo_range (unsigned int idx
, vec
<macinfo_entry
, va_gc
> *files
,
21953 macinfo_hash_type
*macinfo_htab
)
21955 macinfo_entry
*first
, *second
, *cur
, *inc
;
21956 char linebuf
[sizeof (HOST_WIDE_INT
) * 3 + 1];
21957 unsigned char checksum
[16];
21958 struct md5_ctx ctx
;
21959 char *grp_name
, *tail
;
21961 unsigned int i
, count
, encoded_filename_len
, linebuf_len
;
21962 macinfo_entry
**slot
;
21964 first
= &(*macinfo_table
)[idx
];
21965 second
= &(*macinfo_table
)[idx
+ 1];
21967 /* Optimize only if there are at least two consecutive define/undef ops,
21968 and either all of them are before first DW_MACINFO_start_file
21969 with lineno {0,1} (i.e. predefined macro block), or all of them are
21970 in some included header file. */
21971 if (second
->code
!= DW_MACINFO_define
&& second
->code
!= DW_MACINFO_undef
)
21973 if (vec_safe_is_empty (files
))
21975 if (first
->lineno
> 1 || second
->lineno
> 1)
21978 else if (first
->lineno
== 0)
21981 /* Find the last define/undef entry that can be grouped together
21982 with first and at the same time compute md5 checksum of their
21983 codes, linenumbers and strings. */
21984 md5_init_ctx (&ctx
);
21985 for (i
= idx
; macinfo_table
->iterate (i
, &cur
); i
++)
21986 if (cur
->code
!= DW_MACINFO_define
&& cur
->code
!= DW_MACINFO_undef
)
21988 else if (vec_safe_is_empty (files
) && cur
->lineno
> 1)
21992 unsigned char code
= cur
->code
;
21993 md5_process_bytes (&code
, 1, &ctx
);
21994 checksum_uleb128 (cur
->lineno
, &ctx
);
21995 md5_process_bytes (cur
->info
, strlen (cur
->info
) + 1, &ctx
);
21997 md5_finish_ctx (&ctx
, checksum
);
22000 /* From the containing include filename (if any) pick up just
22001 usable characters from its basename. */
22002 if (vec_safe_is_empty (files
))
22005 base
= lbasename (files
->last ().info
);
22006 for (encoded_filename_len
= 0, i
= 0; base
[i
]; i
++)
22007 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22008 encoded_filename_len
++;
22009 /* Count . at the end. */
22010 if (encoded_filename_len
)
22011 encoded_filename_len
++;
22013 sprintf (linebuf
, HOST_WIDE_INT_PRINT_UNSIGNED
, first
->lineno
);
22014 linebuf_len
= strlen (linebuf
);
22016 /* The group name format is: wmN.[<encoded filename>.]<lineno>.<md5sum> */
22017 grp_name
= XALLOCAVEC (char, 4 + encoded_filename_len
+ linebuf_len
+ 1
22019 memcpy (grp_name
, DWARF_OFFSET_SIZE
== 4 ? "wm4." : "wm8.", 4);
22020 tail
= grp_name
+ 4;
22021 if (encoded_filename_len
)
22023 for (i
= 0; base
[i
]; i
++)
22024 if (ISIDNUM (base
[i
]) || base
[i
] == '.')
22028 memcpy (tail
, linebuf
, linebuf_len
);
22029 tail
+= linebuf_len
;
22031 for (i
= 0; i
< 16; i
++)
22032 sprintf (tail
+ i
* 2, "%02x", checksum
[i
] & 0xff);
22034 /* Construct a macinfo_entry for DW_MACRO_GNU_transparent_include
22035 in the empty vector entry before the first define/undef. */
22036 inc
= &(*macinfo_table
)[idx
- 1];
22037 inc
->code
= DW_MACRO_GNU_transparent_include
;
22039 inc
->info
= ggc_strdup (grp_name
);
22040 if (!macinfo_htab
->is_created ())
22041 macinfo_htab
->create (10);
22042 /* Avoid emitting duplicates. */
22043 slot
= macinfo_htab
->find_slot (inc
, INSERT
);
22048 /* If such an entry has been used before, just emit
22049 a DW_MACRO_GNU_transparent_include op. */
22051 output_macinfo_op (inc
);
22052 /* And clear all macinfo_entry in the range to avoid emitting them
22053 in the second pass. */
22054 for (i
= idx
; macinfo_table
->iterate (i
, &cur
) && i
< idx
+ count
; i
++)
22063 inc
->lineno
= macinfo_htab
->elements ();
22064 output_macinfo_op (inc
);
22069 /* Save any strings needed by the macinfo table in the debug str
22070 table. All strings must be collected into the table by the time
22071 index_string is called. */
22074 save_macinfo_strings (void)
22078 macinfo_entry
*ref
;
22080 for (i
= 0; macinfo_table
&& macinfo_table
->iterate (i
, &ref
); i
++)
22084 /* Match the logic in output_macinfo_op to decide on
22085 indirect strings. */
22086 case DW_MACINFO_define
:
22087 case DW_MACINFO_undef
:
22088 len
= strlen (ref
->info
) + 1;
22090 && len
> DWARF_OFFSET_SIZE
22091 && !DWARF2_INDIRECT_STRING_SUPPORT_MISSING_ON_TARGET
22092 && (debug_str_section
->common
.flags
& SECTION_MERGE
) != 0)
22093 set_indirect_string (find_AT_string (ref
->info
));
22095 case DW_MACRO_GNU_define_indirect
:
22096 case DW_MACRO_GNU_undef_indirect
:
22097 set_indirect_string (find_AT_string (ref
->info
));
22105 /* Output macinfo section(s). */
22108 output_macinfo (void)
22111 unsigned long length
= vec_safe_length (macinfo_table
);
22112 macinfo_entry
*ref
;
22113 vec
<macinfo_entry
, va_gc
> *files
= NULL
;
22114 macinfo_hash_type macinfo_htab
;
22119 /* output_macinfo* uses these interchangeably. */
22120 gcc_assert ((int) DW_MACINFO_define
== (int) DW_MACRO_GNU_define
22121 && (int) DW_MACINFO_undef
== (int) DW_MACRO_GNU_undef
22122 && (int) DW_MACINFO_start_file
== (int) DW_MACRO_GNU_start_file
22123 && (int) DW_MACINFO_end_file
== (int) DW_MACRO_GNU_end_file
);
22125 /* For .debug_macro emit the section header. */
22128 dw2_asm_output_data (2, 4, "DWARF macro version number");
22129 if (DWARF_OFFSET_SIZE
== 8)
22130 dw2_asm_output_data (1, 3, "Flags: 64-bit, lineptr present");
22132 dw2_asm_output_data (1, 2, "Flags: 32-bit, lineptr present");
22133 dw2_asm_output_offset (DWARF_OFFSET_SIZE
,
22134 (!dwarf_split_debug_info
? debug_line_section_label
22135 : debug_skeleton_line_section_label
),
22136 debug_line_section
, NULL
);
22139 /* In the first loop, it emits the primary .debug_macinfo section
22140 and after each emitted op the macinfo_entry is cleared.
22141 If a longer range of define/undef ops can be optimized using
22142 DW_MACRO_GNU_transparent_include, the
22143 DW_MACRO_GNU_transparent_include op is emitted and kept in
22144 the vector before the first define/undef in the range and the
22145 whole range of define/undef ops is not emitted and kept. */
22146 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
22150 case DW_MACINFO_start_file
:
22151 vec_safe_push (files
, *ref
);
22153 case DW_MACINFO_end_file
:
22154 if (!vec_safe_is_empty (files
))
22157 case DW_MACINFO_define
:
22158 case DW_MACINFO_undef
:
22160 && HAVE_COMDAT_GROUP
22161 && vec_safe_length (files
) != 1
22164 && (*macinfo_table
)[i
- 1].code
== 0)
22166 unsigned count
= optimize_macinfo_range (i
, files
, &macinfo_htab
);
22175 /* A dummy entry may be inserted at the beginning to be able
22176 to optimize the whole block of predefined macros. */
22182 output_macinfo_op (ref
);
22187 if (!macinfo_htab
.is_created ())
22190 macinfo_htab
.dispose ();
22192 /* If any DW_MACRO_GNU_transparent_include were used, on those
22193 DW_MACRO_GNU_transparent_include entries terminate the
22194 current chain and switch to a new comdat .debug_macinfo
22195 section and emit the define/undef entries within it. */
22196 for (i
= 0; macinfo_table
->iterate (i
, &ref
); i
++)
22201 case DW_MACRO_GNU_transparent_include
:
22203 char label
[MAX_ARTIFICIAL_LABEL_BYTES
];
22204 tree comdat_key
= get_identifier (ref
->info
);
22205 /* Terminate the previous .debug_macinfo section. */
22206 dw2_asm_output_data (1, 0, "End compilation unit");
22207 targetm
.asm_out
.named_section (DEBUG_MACRO_SECTION
,
22209 | SECTION_LINKONCE
,
22211 ASM_GENERATE_INTERNAL_LABEL (label
,
22212 DEBUG_MACRO_SECTION_LABEL
,
22214 ASM_OUTPUT_LABEL (asm_out_file
, label
);
22217 dw2_asm_output_data (2, 4, "DWARF macro version number");
22218 if (DWARF_OFFSET_SIZE
== 8)
22219 dw2_asm_output_data (1, 1, "Flags: 64-bit");
22221 dw2_asm_output_data (1, 0, "Flags: 32-bit");
22224 case DW_MACINFO_define
:
22225 case DW_MACINFO_undef
:
22226 output_macinfo_op (ref
);
22231 gcc_unreachable ();
22235 /* Set up for Dwarf output at the start of compilation. */
22238 dwarf2out_init (const char *filename ATTRIBUTE_UNUSED
)
22240 /* Allocate the file_table. */
22241 file_table
= htab_create_ggc (50, file_table_hash
,
22242 file_table_eq
, NULL
);
22244 /* Allocate the decl_die_table. */
22245 decl_die_table
= htab_create_ggc (10, decl_die_table_hash
,
22246 decl_die_table_eq
, NULL
);
22248 /* Allocate the decl_loc_table. */
22249 decl_loc_table
= htab_create_ggc (10, decl_loc_table_hash
,
22250 decl_loc_table_eq
, NULL
);
22252 /* Allocate the cached_dw_loc_list_table. */
22253 cached_dw_loc_list_table
22254 = htab_create_ggc (10, cached_dw_loc_list_table_hash
,
22255 cached_dw_loc_list_table_eq
, NULL
);
22257 /* Allocate the initial hunk of the decl_scope_table. */
22258 vec_alloc (decl_scope_table
, 256);
22260 /* Allocate the initial hunk of the abbrev_die_table. */
22261 abbrev_die_table
= ggc_alloc_cleared_vec_dw_die_ref
22262 (ABBREV_DIE_TABLE_INCREMENT
);
22263 abbrev_die_table_allocated
= ABBREV_DIE_TABLE_INCREMENT
;
22264 /* Zero-th entry is allocated, but unused. */
22265 abbrev_die_table_in_use
= 1;
22267 /* Allocate the pubtypes and pubnames vectors. */
22268 vec_alloc (pubname_table
, 32);
22269 vec_alloc (pubtype_table
, 32);
22271 vec_alloc (incomplete_types
, 64);
22273 vec_alloc (used_rtx_array
, 32);
22275 if (!dwarf_split_debug_info
)
22277 debug_info_section
= get_section (DEBUG_INFO_SECTION
,
22278 SECTION_DEBUG
, NULL
);
22279 debug_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22280 SECTION_DEBUG
, NULL
);
22281 debug_loc_section
= get_section (DEBUG_LOC_SECTION
,
22282 SECTION_DEBUG
, NULL
);
22286 debug_info_section
= get_section (DEBUG_DWO_INFO_SECTION
,
22287 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22288 debug_abbrev_section
= get_section (DEBUG_DWO_ABBREV_SECTION
,
22289 SECTION_DEBUG
| SECTION_EXCLUDE
,
22291 debug_addr_section
= get_section (DEBUG_ADDR_SECTION
,
22292 SECTION_DEBUG
, NULL
);
22293 debug_skeleton_info_section
= get_section (DEBUG_INFO_SECTION
,
22294 SECTION_DEBUG
, NULL
);
22295 debug_skeleton_abbrev_section
= get_section (DEBUG_ABBREV_SECTION
,
22296 SECTION_DEBUG
, NULL
);
22297 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_abbrev_section_label
,
22298 DEBUG_SKELETON_ABBREV_SECTION_LABEL
, 0);
22300 /* Somewhat confusing detail: The skeleton_[abbrev|info] sections stay in
22301 the main .o, but the skeleton_line goes into the split off dwo. */
22302 debug_skeleton_line_section
22303 = get_section (DEBUG_DWO_LINE_SECTION
,
22304 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22305 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_line_section_label
,
22306 DEBUG_SKELETON_LINE_SECTION_LABEL
, 0);
22307 debug_str_offsets_section
= get_section (DEBUG_STR_OFFSETS_SECTION
,
22308 SECTION_DEBUG
| SECTION_EXCLUDE
,
22310 ASM_GENERATE_INTERNAL_LABEL (debug_skeleton_info_section_label
,
22311 DEBUG_SKELETON_INFO_SECTION_LABEL
, 0);
22312 debug_loc_section
= get_section (DEBUG_DWO_LOC_SECTION
,
22313 SECTION_DEBUG
| SECTION_EXCLUDE
, NULL
);
22314 debug_str_dwo_section
= get_section (DEBUG_STR_DWO_SECTION
,
22315 DEBUG_STR_DWO_SECTION_FLAGS
, NULL
);
22317 debug_aranges_section
= get_section (DEBUG_ARANGES_SECTION
,
22318 SECTION_DEBUG
, NULL
);
22319 debug_macinfo_section
= get_section (dwarf_strict
22320 ? DEBUG_MACINFO_SECTION
22321 : DEBUG_MACRO_SECTION
,
22322 DEBUG_MACRO_SECTION_FLAGS
, NULL
);
22323 debug_line_section
= get_section (DEBUG_LINE_SECTION
,
22324 SECTION_DEBUG
, NULL
);
22325 debug_pubnames_section
= get_section (DEBUG_PUBNAMES_SECTION
,
22326 SECTION_DEBUG
, NULL
);
22327 debug_pubtypes_section
= get_section (DEBUG_PUBTYPES_SECTION
,
22328 SECTION_DEBUG
, NULL
);
22329 debug_str_section
= get_section (DEBUG_STR_SECTION
,
22330 DEBUG_STR_SECTION_FLAGS
, NULL
);
22331 debug_ranges_section
= get_section (DEBUG_RANGES_SECTION
,
22332 SECTION_DEBUG
, NULL
);
22333 debug_frame_section
= get_section (DEBUG_FRAME_SECTION
,
22334 SECTION_DEBUG
, NULL
);
22336 ASM_GENERATE_INTERNAL_LABEL (text_end_label
, TEXT_END_LABEL
, 0);
22337 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label
,
22338 DEBUG_ABBREV_SECTION_LABEL
, 0);
22339 ASM_GENERATE_INTERNAL_LABEL (text_section_label
, TEXT_SECTION_LABEL
, 0);
22340 ASM_GENERATE_INTERNAL_LABEL (cold_text_section_label
,
22341 COLD_TEXT_SECTION_LABEL
, 0);
22342 ASM_GENERATE_INTERNAL_LABEL (cold_end_label
, COLD_END_LABEL
, 0);
22344 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label
,
22345 DEBUG_INFO_SECTION_LABEL
, 0);
22346 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label
,
22347 DEBUG_LINE_SECTION_LABEL
, 0);
22348 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label
,
22349 DEBUG_RANGES_SECTION_LABEL
, 0);
22350 ASM_GENERATE_INTERNAL_LABEL (debug_addr_section_label
,
22351 DEBUG_ADDR_SECTION_LABEL
, 0);
22352 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label
,
22354 ? DEBUG_MACINFO_SECTION_LABEL
22355 : DEBUG_MACRO_SECTION_LABEL
, 0);
22356 ASM_GENERATE_INTERNAL_LABEL (loc_section_label
, DEBUG_LOC_SECTION_LABEL
, 0);
22358 if (debug_info_level
>= DINFO_LEVEL_VERBOSE
)
22359 vec_alloc (macinfo_table
, 64);
22361 switch_to_section (text_section
);
22362 ASM_OUTPUT_LABEL (asm_out_file
, text_section_label
);
22364 /* Make sure the line number table for .text always exists. */
22365 text_section_line_info
= new_line_info_table ();
22366 text_section_line_info
->end_label
= text_end_label
;
22369 /* Called before compile () starts outputtting functions, variables
22370 and toplevel asms into assembly. */
22373 dwarf2out_assembly_start (void)
22375 if (HAVE_GAS_CFI_SECTIONS_DIRECTIVE
22376 && dwarf2out_do_cfi_asm ()
22377 && (!(flag_unwind_tables
|| flag_exceptions
)
22378 || targetm_common
.except_unwind_info (&global_options
) != UI_DWARF2
))
22379 fprintf (asm_out_file
, "\t.cfi_sections\t.debug_frame\n");
22382 /* A helper function for dwarf2out_finish called through
22383 htab_traverse. Assign a string its index. All strings must be
22384 collected into the table by the time index_string is called,
22385 because the indexing code relies on htab_traverse to traverse nodes
22386 in the same order for each run. */
22389 index_string (void **h
, void *v
)
22391 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22392 unsigned int *index
= (unsigned int *) v
;
22394 find_string_form (node
);
22395 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22397 gcc_assert (node
->index
== NO_INDEX_ASSIGNED
);
22398 node
->index
= *index
;
22404 /* A helper function for output_indirect_strings called through
22405 htab_traverse. Output the offset to a string and update the
22409 output_index_string_offset (void **h
, void *v
)
22411 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22412 unsigned int *offset
= (unsigned int *) v
;
22414 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22416 /* Assert that this node has been assigned an index. */
22417 gcc_assert (node
->index
!= NO_INDEX_ASSIGNED
22418 && node
->index
!= NOT_INDEXED
);
22419 dw2_asm_output_data (DWARF_OFFSET_SIZE
, *offset
,
22420 "indexed string 0x%x: %s", node
->index
, node
->str
);
22421 *offset
+= strlen (node
->str
) + 1;
22426 /* A helper function for dwarf2out_finish called through
22427 htab_traverse. Output the indexed string. */
22430 output_index_string (void **h
, void *v
)
22432 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22433 unsigned int *cur_idx
= (unsigned int *) v
;
22435 if (node
->form
== DW_FORM_GNU_str_index
&& node
->refcount
> 0)
22437 /* Assert that the strings are output in the same order as their
22438 indexes were assigned. */
22439 gcc_assert (*cur_idx
== node
->index
);
22440 assemble_string (node
->str
, strlen (node
->str
) + 1);
22446 /* A helper function for dwarf2out_finish called through
22447 htab_traverse. Emit one queued .debug_str string. */
22450 output_indirect_string (void **h
, void *v ATTRIBUTE_UNUSED
)
22452 struct indirect_string_node
*node
= (struct indirect_string_node
*) *h
;
22454 node
->form
= find_string_form (node
);
22455 if (node
->form
== DW_FORM_strp
&& node
->refcount
> 0)
22457 ASM_OUTPUT_LABEL (asm_out_file
, node
->label
);
22458 assemble_string (node
->str
, strlen (node
->str
) + 1);
22464 /* Output the indexed string table. */
22467 output_indirect_strings (void)
22469 switch_to_section (debug_str_section
);
22470 if (!dwarf_split_debug_info
)
22471 htab_traverse (debug_str_hash
, output_indirect_string
, NULL
);
22474 unsigned int offset
= 0;
22475 unsigned int cur_idx
= 0;
22477 htab_traverse (skeleton_debug_str_hash
, output_indirect_string
, NULL
);
22479 switch_to_section (debug_str_offsets_section
);
22480 htab_traverse_noresize (debug_str_hash
,
22481 output_index_string_offset
,
22483 switch_to_section (debug_str_dwo_section
);
22484 htab_traverse_noresize (debug_str_hash
,
22485 output_index_string
,
22490 /* Callback for htab_traverse to assign an index to an entry in the
22491 table, and to write that entry to the .debug_addr section. */
22494 output_addr_table_entry (void **slot
, void *data
)
22496 addr_table_entry
*entry
= (addr_table_entry
*) *slot
;
22497 unsigned int *cur_index
= (unsigned int *)data
;
22499 if (entry
->refcount
== 0)
22501 gcc_assert (entry
->index
== NO_INDEX_ASSIGNED
22502 || entry
->index
== NOT_INDEXED
);
22506 gcc_assert (entry
->index
== *cur_index
);
22509 switch (entry
->kind
)
22512 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE
, entry
->addr
.rtl
,
22513 "0x%x", entry
->index
);
22515 case ate_kind_rtx_dtprel
:
22516 gcc_assert (targetm
.asm_out
.output_dwarf_dtprel
);
22517 targetm
.asm_out
.output_dwarf_dtprel (asm_out_file
,
22520 fputc ('\n', asm_out_file
);
22522 case ate_kind_label
:
22523 dw2_asm_output_addr (DWARF2_ADDR_SIZE
, entry
->addr
.label
,
22524 "0x%x", entry
->index
);
22527 gcc_unreachable ();
22532 /* Produce the .debug_addr section. */
22535 output_addr_table (void)
22537 unsigned int index
= 0;
22538 if (addr_index_table
== NULL
|| htab_size (addr_index_table
) == 0)
22541 switch_to_section (debug_addr_section
);
22542 htab_traverse_noresize (addr_index_table
, output_addr_table_entry
, &index
);
22545 #if ENABLE_ASSERT_CHECKING
22546 /* Verify that all marks are clear. */
22549 verify_marks_clear (dw_die_ref die
)
22553 gcc_assert (! die
->die_mark
);
22554 FOR_EACH_CHILD (die
, c
, verify_marks_clear (c
));
22556 #endif /* ENABLE_ASSERT_CHECKING */
22558 /* Clear the marks for a die and its children.
22559 Be cool if the mark isn't set. */
22562 prune_unmark_dies (dw_die_ref die
)
22568 FOR_EACH_CHILD (die
, c
, prune_unmark_dies (c
));
22571 /* Given DIE that we're marking as used, find any other dies
22572 it references as attributes and mark them as used. */
22575 prune_unused_types_walk_attribs (dw_die_ref die
)
22580 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22582 if (a
->dw_attr_val
.val_class
== dw_val_class_die_ref
)
22584 /* A reference to another DIE.
22585 Make sure that it will get emitted.
22586 If it was broken out into a comdat group, don't follow it. */
22587 if (! AT_ref (a
)->comdat_type_p
22588 || a
->dw_attr
== DW_AT_specification
)
22589 prune_unused_types_mark (a
->dw_attr_val
.v
.val_die_ref
.die
, 1);
22591 /* Set the string's refcount to 0 so that prune_unused_types_mark
22592 accounts properly for it. */
22593 if (AT_class (a
) == dw_val_class_str
)
22594 a
->dw_attr_val
.v
.val_str
->refcount
= 0;
22598 /* Mark the generic parameters and arguments children DIEs of DIE. */
22601 prune_unused_types_mark_generic_parms_dies (dw_die_ref die
)
22605 if (die
== NULL
|| die
->die_child
== NULL
)
22607 c
= die
->die_child
;
22610 if (is_template_parameter (c
))
22611 prune_unused_types_mark (c
, 1);
22613 } while (c
&& c
!= die
->die_child
);
22616 /* Mark DIE as being used. If DOKIDS is true, then walk down
22617 to DIE's children. */
22620 prune_unused_types_mark (dw_die_ref die
, int dokids
)
22624 if (die
->die_mark
== 0)
22626 /* We haven't done this node yet. Mark it as used. */
22628 /* If this is the DIE of a generic type instantiation,
22629 mark the children DIEs that describe its generic parms and
22631 prune_unused_types_mark_generic_parms_dies (die
);
22633 /* We also have to mark its parents as used.
22634 (But we don't want to mark our parent's kids due to this,
22635 unless it is a class.) */
22636 if (die
->die_parent
)
22637 prune_unused_types_mark (die
->die_parent
,
22638 class_scope_p (die
->die_parent
));
22640 /* Mark any referenced nodes. */
22641 prune_unused_types_walk_attribs (die
);
22643 /* If this node is a specification,
22644 also mark the definition, if it exists. */
22645 if (get_AT_flag (die
, DW_AT_declaration
) && die
->die_definition
)
22646 prune_unused_types_mark (die
->die_definition
, 1);
22649 if (dokids
&& die
->die_mark
!= 2)
22651 /* We need to walk the children, but haven't done so yet.
22652 Remember that we've walked the kids. */
22655 /* If this is an array type, we need to make sure our
22656 kids get marked, even if they're types. If we're
22657 breaking out types into comdat sections, do this
22658 for all type definitions. */
22659 if (die
->die_tag
== DW_TAG_array_type
22660 || (use_debug_types
22661 && is_type_die (die
) && ! is_declaration_die (die
)))
22662 FOR_EACH_CHILD (die
, c
, prune_unused_types_mark (c
, 1));
22664 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22668 /* For local classes, look if any static member functions were emitted
22669 and if so, mark them. */
22672 prune_unused_types_walk_local_classes (dw_die_ref die
)
22676 if (die
->die_mark
== 2)
22679 switch (die
->die_tag
)
22681 case DW_TAG_structure_type
:
22682 case DW_TAG_union_type
:
22683 case DW_TAG_class_type
:
22686 case DW_TAG_subprogram
:
22687 if (!get_AT_flag (die
, DW_AT_declaration
)
22688 || die
->die_definition
!= NULL
)
22689 prune_unused_types_mark (die
, 1);
22696 /* Mark children. */
22697 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk_local_classes (c
));
22700 /* Walk the tree DIE and mark types that we actually use. */
22703 prune_unused_types_walk (dw_die_ref die
)
22707 /* Don't do anything if this node is already marked and
22708 children have been marked as well. */
22709 if (die
->die_mark
== 2)
22712 switch (die
->die_tag
)
22714 case DW_TAG_structure_type
:
22715 case DW_TAG_union_type
:
22716 case DW_TAG_class_type
:
22717 if (die
->die_perennial_p
)
22720 for (c
= die
->die_parent
; c
; c
= c
->die_parent
)
22721 if (c
->die_tag
== DW_TAG_subprogram
)
22724 /* Finding used static member functions inside of classes
22725 is needed just for local classes, because for other classes
22726 static member function DIEs with DW_AT_specification
22727 are emitted outside of the DW_TAG_*_type. If we ever change
22728 it, we'd need to call this even for non-local classes. */
22730 prune_unused_types_walk_local_classes (die
);
22732 /* It's a type node --- don't mark it. */
22735 case DW_TAG_const_type
:
22736 case DW_TAG_packed_type
:
22737 case DW_TAG_pointer_type
:
22738 case DW_TAG_reference_type
:
22739 case DW_TAG_rvalue_reference_type
:
22740 case DW_TAG_volatile_type
:
22741 case DW_TAG_typedef
:
22742 case DW_TAG_array_type
:
22743 case DW_TAG_interface_type
:
22744 case DW_TAG_friend
:
22745 case DW_TAG_variant_part
:
22746 case DW_TAG_enumeration_type
:
22747 case DW_TAG_subroutine_type
:
22748 case DW_TAG_string_type
:
22749 case DW_TAG_set_type
:
22750 case DW_TAG_subrange_type
:
22751 case DW_TAG_ptr_to_member_type
:
22752 case DW_TAG_file_type
:
22753 if (die
->die_perennial_p
)
22756 /* It's a type node --- don't mark it. */
22760 /* Mark everything else. */
22764 if (die
->die_mark
== 0)
22768 /* Now, mark any dies referenced from here. */
22769 prune_unused_types_walk_attribs (die
);
22774 /* Mark children. */
22775 FOR_EACH_CHILD (die
, c
, prune_unused_types_walk (c
));
22778 /* Increment the string counts on strings referred to from DIE's
22782 prune_unused_types_update_strings (dw_die_ref die
)
22787 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
22788 if (AT_class (a
) == dw_val_class_str
)
22790 struct indirect_string_node
*s
= a
->dw_attr_val
.v
.val_str
;
22792 /* Avoid unnecessarily putting strings that are used less than
22793 twice in the hash table. */
22795 == ((DEBUG_STR_SECTION_FLAGS
& SECTION_MERGE
) ? 1 : 2))
22798 slot
= htab_find_slot_with_hash (debug_str_hash
, s
->str
,
22799 htab_hash_string (s
->str
),
22801 gcc_assert (*slot
== NULL
);
22807 /* Remove from the tree DIE any dies that aren't marked. */
22810 prune_unused_types_prune (dw_die_ref die
)
22814 gcc_assert (die
->die_mark
);
22815 prune_unused_types_update_strings (die
);
22817 if (! die
->die_child
)
22820 c
= die
->die_child
;
22822 dw_die_ref prev
= c
;
22823 for (c
= c
->die_sib
; ! c
->die_mark
; c
= c
->die_sib
)
22824 if (c
== die
->die_child
)
22826 /* No marked children between 'prev' and the end of the list. */
22828 /* No marked children at all. */
22829 die
->die_child
= NULL
;
22832 prev
->die_sib
= c
->die_sib
;
22833 die
->die_child
= prev
;
22838 if (c
!= prev
->die_sib
)
22840 prune_unused_types_prune (c
);
22841 } while (c
!= die
->die_child
);
22844 /* Remove dies representing declarations that we never use. */
22847 prune_unused_types (void)
22850 limbo_die_node
*node
;
22851 comdat_type_node
*ctnode
;
22853 dw_die_ref base_type
;
22855 #if ENABLE_ASSERT_CHECKING
22856 /* All the marks should already be clear. */
22857 verify_marks_clear (comp_unit_die ());
22858 for (node
= limbo_die_list
; node
; node
= node
->next
)
22859 verify_marks_clear (node
->die
);
22860 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22861 verify_marks_clear (ctnode
->root_die
);
22862 #endif /* ENABLE_ASSERT_CHECKING */
22864 /* Mark types that are used in global variables. */
22865 premark_types_used_by_global_vars ();
22867 /* Set the mark on nodes that are actually used. */
22868 prune_unused_types_walk (comp_unit_die ());
22869 for (node
= limbo_die_list
; node
; node
= node
->next
)
22870 prune_unused_types_walk (node
->die
);
22871 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22873 prune_unused_types_walk (ctnode
->root_die
);
22874 prune_unused_types_mark (ctnode
->type_die
, 1);
22877 /* Also set the mark on nodes referenced from the pubname_table. Enumerators
22878 are unusual in that they are pubnames that are the children of pubtypes.
22879 They should only be marked via their parent DW_TAG_enumeration_type die,
22880 not as roots in themselves. */
22881 FOR_EACH_VEC_ELT (*pubname_table
, i
, pub
)
22882 if (pub
->die
->die_tag
!= DW_TAG_enumerator
)
22883 prune_unused_types_mark (pub
->die
, 1);
22884 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
22885 prune_unused_types_mark (base_type
, 1);
22887 if (debug_str_hash
)
22888 htab_empty (debug_str_hash
);
22889 if (skeleton_debug_str_hash
)
22890 htab_empty (skeleton_debug_str_hash
);
22891 prune_unused_types_prune (comp_unit_die ());
22892 for (node
= limbo_die_list
; node
; node
= node
->next
)
22893 prune_unused_types_prune (node
->die
);
22894 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22895 prune_unused_types_prune (ctnode
->root_die
);
22897 /* Leave the marks clear. */
22898 prune_unmark_dies (comp_unit_die ());
22899 for (node
= limbo_die_list
; node
; node
= node
->next
)
22900 prune_unmark_dies (node
->die
);
22901 for (ctnode
= comdat_type_list
; ctnode
; ctnode
= ctnode
->next
)
22902 prune_unmark_dies (ctnode
->root_die
);
22905 /* Set the parameter to true if there are any relative pathnames in
22908 file_table_relative_p (void ** slot
, void *param
)
22910 bool *p
= (bool *) param
;
22911 struct dwarf_file_data
*d
= (struct dwarf_file_data
*) *slot
;
22912 if (!IS_ABSOLUTE_PATH (d
->filename
))
22920 /* Helpers to manipulate hash table of comdat type units. */
22922 struct comdat_type_hasher
: typed_noop_remove
<comdat_type_node
>
22924 typedef comdat_type_node value_type
;
22925 typedef comdat_type_node compare_type
;
22926 static inline hashval_t
hash (const value_type
*);
22927 static inline bool equal (const value_type
*, const compare_type
*);
22931 comdat_type_hasher::hash (const value_type
*type_node
)
22934 memcpy (&h
, type_node
->signature
, sizeof (h
));
22939 comdat_type_hasher::equal (const value_type
*type_node_1
,
22940 const compare_type
*type_node_2
)
22942 return (! memcmp (type_node_1
->signature
, type_node_2
->signature
,
22943 DWARF_TYPE_SIGNATURE_SIZE
));
22946 /* Move a DW_AT_{,MIPS_}linkage_name attribute just added to dw_die_ref
22947 to the location it would have been added, should we know its
22948 DECL_ASSEMBLER_NAME when we added other attributes. This will
22949 probably improve compactness of debug info, removing equivalent
22950 abbrevs, and hide any differences caused by deferring the
22951 computation of the assembler name, triggered by e.g. PCH. */
22954 move_linkage_attr (dw_die_ref die
)
22956 unsigned ix
= vec_safe_length (die
->die_attr
);
22957 dw_attr_node linkage
= (*die
->die_attr
)[ix
- 1];
22959 gcc_assert (linkage
.dw_attr
== DW_AT_linkage_name
22960 || linkage
.dw_attr
== DW_AT_MIPS_linkage_name
);
22964 dw_attr_node
*prev
= &(*die
->die_attr
)[ix
- 1];
22966 if (prev
->dw_attr
== DW_AT_decl_line
|| prev
->dw_attr
== DW_AT_name
)
22970 if (ix
!= vec_safe_length (die
->die_attr
) - 1)
22972 die
->die_attr
->pop ();
22973 die
->die_attr
->quick_insert (ix
, linkage
);
22977 /* Helper function for resolve_addr, mark DW_TAG_base_type nodes
22978 referenced from typed stack ops and count how often they are used. */
22981 mark_base_types (dw_loc_descr_ref loc
)
22983 dw_die_ref base_type
= NULL
;
22985 for (; loc
; loc
= loc
->dw_loc_next
)
22987 switch (loc
->dw_loc_opc
)
22989 case DW_OP_GNU_regval_type
:
22990 case DW_OP_GNU_deref_type
:
22991 base_type
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
22993 case DW_OP_GNU_convert
:
22994 case DW_OP_GNU_reinterpret
:
22995 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_unsigned_const
)
22998 case DW_OP_GNU_const_type
:
22999 base_type
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23001 case DW_OP_GNU_entry_value
:
23002 mark_base_types (loc
->dw_loc_oprnd1
.v
.val_loc
);
23007 gcc_assert (base_type
->die_parent
== comp_unit_die ());
23008 if (base_type
->die_mark
)
23009 base_type
->die_mark
++;
23012 base_types
.safe_push (base_type
);
23013 base_type
->die_mark
= 1;
23018 /* Comparison function for sorting marked base types. */
23021 base_type_cmp (const void *x
, const void *y
)
23023 dw_die_ref dx
= *(const dw_die_ref
*) x
;
23024 dw_die_ref dy
= *(const dw_die_ref
*) y
;
23025 unsigned int byte_size1
, byte_size2
;
23026 unsigned int encoding1
, encoding2
;
23027 if (dx
->die_mark
> dy
->die_mark
)
23029 if (dx
->die_mark
< dy
->die_mark
)
23031 byte_size1
= get_AT_unsigned (dx
, DW_AT_byte_size
);
23032 byte_size2
= get_AT_unsigned (dy
, DW_AT_byte_size
);
23033 if (byte_size1
< byte_size2
)
23035 if (byte_size1
> byte_size2
)
23037 encoding1
= get_AT_unsigned (dx
, DW_AT_encoding
);
23038 encoding2
= get_AT_unsigned (dy
, DW_AT_encoding
);
23039 if (encoding1
< encoding2
)
23041 if (encoding1
> encoding2
)
23046 /* Move base types marked by mark_base_types as early as possible
23047 in the CU, sorted by decreasing usage count both to make the
23048 uleb128 references as small as possible and to make sure they
23049 will have die_offset already computed by calc_die_sizes when
23050 sizes of typed stack loc ops is computed. */
23053 move_marked_base_types (void)
23056 dw_die_ref base_type
, die
, c
;
23058 if (base_types
.is_empty ())
23061 /* Sort by decreasing usage count, they will be added again in that
23063 base_types
.qsort (base_type_cmp
);
23064 die
= comp_unit_die ();
23065 c
= die
->die_child
;
23068 dw_die_ref prev
= c
;
23070 while (c
->die_mark
)
23072 remove_child_with_prev (c
, prev
);
23073 /* As base types got marked, there must be at least
23074 one node other than DW_TAG_base_type. */
23075 gcc_assert (c
!= c
->die_sib
);
23079 while (c
!= die
->die_child
);
23080 gcc_assert (die
->die_child
);
23081 c
= die
->die_child
;
23082 for (i
= 0; base_types
.iterate (i
, &base_type
); i
++)
23084 base_type
->die_mark
= 0;
23085 base_type
->die_sib
= c
->die_sib
;
23086 c
->die_sib
= base_type
;
23091 /* Helper function for resolve_addr, attempt to resolve
23092 one CONST_STRING, return non-zero if not successful. Similarly verify that
23093 SYMBOL_REFs refer to variables emitted in the current CU. */
23096 resolve_one_addr (rtx
*addr
, void *data ATTRIBUTE_UNUSED
)
23100 if (GET_CODE (rtl
) == CONST_STRING
)
23102 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
23103 tree t
= build_string (len
, XSTR (rtl
, 0));
23104 tree tlen
= size_int (len
- 1);
23106 = build_array_type (char_type_node
, build_index_type (tlen
));
23107 rtl
= lookup_constant_def (t
);
23108 if (!rtl
|| !MEM_P (rtl
))
23110 rtl
= XEXP (rtl
, 0);
23111 if (GET_CODE (rtl
) == SYMBOL_REF
23112 && SYMBOL_REF_DECL (rtl
)
23113 && !TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
23115 vec_safe_push (used_rtx_array
, rtl
);
23120 if (GET_CODE (rtl
) == SYMBOL_REF
23121 && SYMBOL_REF_DECL (rtl
))
23123 if (TREE_CONSTANT_POOL_ADDRESS_P (rtl
))
23125 if (!TREE_ASM_WRITTEN (DECL_INITIAL (SYMBOL_REF_DECL (rtl
))))
23128 else if (!TREE_ASM_WRITTEN (SYMBOL_REF_DECL (rtl
)))
23132 if (GET_CODE (rtl
) == CONST
23133 && for_each_rtx (&XEXP (rtl
, 0), resolve_one_addr
, NULL
))
23139 /* For STRING_CST, return SYMBOL_REF of its constant pool entry,
23140 if possible, and create DW_TAG_dwarf_procedure that can be referenced
23141 from DW_OP_GNU_implicit_pointer if the string hasn't been seen yet. */
23144 string_cst_pool_decl (tree t
)
23146 rtx rtl
= output_constant_def (t
, 1);
23147 unsigned char *array
;
23148 dw_loc_descr_ref l
;
23153 if (!rtl
|| !MEM_P (rtl
))
23155 rtl
= XEXP (rtl
, 0);
23156 if (GET_CODE (rtl
) != SYMBOL_REF
23157 || SYMBOL_REF_DECL (rtl
) == NULL_TREE
)
23160 decl
= SYMBOL_REF_DECL (rtl
);
23161 if (!lookup_decl_die (decl
))
23163 len
= TREE_STRING_LENGTH (t
);
23164 vec_safe_push (used_rtx_array
, rtl
);
23165 ref
= new_die (DW_TAG_dwarf_procedure
, comp_unit_die (), decl
);
23166 array
= (unsigned char *) ggc_alloc_atomic (len
);
23167 memcpy (array
, TREE_STRING_POINTER (t
), len
);
23168 l
= new_loc_descr (DW_OP_implicit_value
, len
, 0);
23169 l
->dw_loc_oprnd2
.val_class
= dw_val_class_vec
;
23170 l
->dw_loc_oprnd2
.v
.val_vec
.length
= len
;
23171 l
->dw_loc_oprnd2
.v
.val_vec
.elt_size
= 1;
23172 l
->dw_loc_oprnd2
.v
.val_vec
.array
= array
;
23173 add_AT_loc (ref
, DW_AT_location
, l
);
23174 equate_decl_number_to_die (decl
, ref
);
23179 /* Helper function of resolve_addr_in_expr. LOC is
23180 a DW_OP_addr followed by DW_OP_stack_value, either at the start
23181 of exprloc or after DW_OP_{,bit_}piece, and val_addr can't be
23182 resolved. Replace it (both DW_OP_addr and DW_OP_stack_value)
23183 with DW_OP_GNU_implicit_pointer if possible
23184 and return true, if unsuccessful, return false. */
23187 optimize_one_addr_into_implicit_ptr (dw_loc_descr_ref loc
)
23189 rtx rtl
= loc
->dw_loc_oprnd1
.v
.val_addr
;
23190 HOST_WIDE_INT offset
= 0;
23191 dw_die_ref ref
= NULL
;
23194 if (GET_CODE (rtl
) == CONST
23195 && GET_CODE (XEXP (rtl
, 0)) == PLUS
23196 && CONST_INT_P (XEXP (XEXP (rtl
, 0), 1)))
23198 offset
= INTVAL (XEXP (XEXP (rtl
, 0), 1));
23199 rtl
= XEXP (XEXP (rtl
, 0), 0);
23201 if (GET_CODE (rtl
) == CONST_STRING
)
23203 size_t len
= strlen (XSTR (rtl
, 0)) + 1;
23204 tree t
= build_string (len
, XSTR (rtl
, 0));
23205 tree tlen
= size_int (len
- 1);
23208 = build_array_type (char_type_node
, build_index_type (tlen
));
23209 rtl
= string_cst_pool_decl (t
);
23213 if (GET_CODE (rtl
) == SYMBOL_REF
&& SYMBOL_REF_DECL (rtl
))
23215 decl
= SYMBOL_REF_DECL (rtl
);
23216 if (TREE_CODE (decl
) == VAR_DECL
&& !DECL_EXTERNAL (decl
))
23218 ref
= lookup_decl_die (decl
);
23219 if (ref
&& (get_AT (ref
, DW_AT_location
)
23220 || get_AT (ref
, DW_AT_const_value
)))
23222 loc
->dw_loc_opc
= DW_OP_GNU_implicit_pointer
;
23223 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23224 loc
->dw_loc_oprnd1
.val_entry
= NULL
;
23225 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23226 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23227 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23228 loc
->dw_loc_oprnd2
.v
.val_int
= offset
;
23236 /* Helper function for resolve_addr, handle one location
23237 expression, return false if at least one CONST_STRING or SYMBOL_REF in
23238 the location list couldn't be resolved. */
23241 resolve_addr_in_expr (dw_loc_descr_ref loc
)
23243 dw_loc_descr_ref keep
= NULL
;
23244 for (dw_loc_descr_ref prev
= NULL
; loc
; prev
= loc
, loc
= loc
->dw_loc_next
)
23245 switch (loc
->dw_loc_opc
)
23248 if (resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
23251 || prev
->dw_loc_opc
== DW_OP_piece
23252 || prev
->dw_loc_opc
== DW_OP_bit_piece
)
23253 && loc
->dw_loc_next
23254 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_stack_value
23256 && optimize_one_addr_into_implicit_ptr (loc
))
23261 case DW_OP_GNU_addr_index
:
23262 case DW_OP_GNU_const_index
:
23263 if ((loc
->dw_loc_opc
== DW_OP_GNU_addr_index
23264 || (loc
->dw_loc_opc
== DW_OP_GNU_const_index
&& loc
->dtprel
))
23265 && resolve_one_addr (&loc
->dw_loc_oprnd1
.val_entry
->addr
.rtl
,
23269 case DW_OP_const4u
:
23270 case DW_OP_const8u
:
23272 && resolve_one_addr (&loc
->dw_loc_oprnd1
.v
.val_addr
, NULL
))
23275 case DW_OP_plus_uconst
:
23276 if (size_of_loc_descr (loc
)
23277 > size_of_int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
)
23279 && loc
->dw_loc_oprnd1
.v
.val_unsigned
> 0)
23281 dw_loc_descr_ref repl
23282 = int_loc_descriptor (loc
->dw_loc_oprnd1
.v
.val_unsigned
);
23283 add_loc_descr (&repl
, new_loc_descr (DW_OP_plus
, 0, 0));
23284 add_loc_descr (&repl
, loc
->dw_loc_next
);
23288 case DW_OP_implicit_value
:
23289 if (loc
->dw_loc_oprnd2
.val_class
== dw_val_class_addr
23290 && resolve_one_addr (&loc
->dw_loc_oprnd2
.v
.val_addr
, NULL
))
23293 case DW_OP_GNU_implicit_pointer
:
23294 case DW_OP_GNU_parameter_ref
:
23295 if (loc
->dw_loc_oprnd1
.val_class
== dw_val_class_decl_ref
)
23298 = lookup_decl_die (loc
->dw_loc_oprnd1
.v
.val_decl_ref
);
23301 loc
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23302 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23303 loc
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23306 case DW_OP_GNU_const_type
:
23307 case DW_OP_GNU_regval_type
:
23308 case DW_OP_GNU_deref_type
:
23309 case DW_OP_GNU_convert
:
23310 case DW_OP_GNU_reinterpret
:
23311 while (loc
->dw_loc_next
23312 && loc
->dw_loc_next
->dw_loc_opc
== DW_OP_GNU_convert
)
23314 dw_die_ref base1
, base2
;
23315 unsigned enc1
, enc2
, size1
, size2
;
23316 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23317 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23318 base1
= loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
;
23319 else if (loc
->dw_loc_oprnd1
.val_class
23320 == dw_val_class_unsigned_const
)
23323 base1
= loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23324 if (loc
->dw_loc_next
->dw_loc_oprnd1
.val_class
23325 == dw_val_class_unsigned_const
)
23327 base2
= loc
->dw_loc_next
->dw_loc_oprnd1
.v
.val_die_ref
.die
;
23328 gcc_assert (base1
->die_tag
== DW_TAG_base_type
23329 && base2
->die_tag
== DW_TAG_base_type
);
23330 enc1
= get_AT_unsigned (base1
, DW_AT_encoding
);
23331 enc2
= get_AT_unsigned (base2
, DW_AT_encoding
);
23332 size1
= get_AT_unsigned (base1
, DW_AT_byte_size
);
23333 size2
= get_AT_unsigned (base2
, DW_AT_byte_size
);
23335 && (((enc1
== DW_ATE_unsigned
|| enc1
== DW_ATE_signed
)
23336 && (enc2
== DW_ATE_unsigned
|| enc2
== DW_ATE_signed
)
23340 /* Optimize away next DW_OP_GNU_convert after
23341 adjusting LOC's base type die reference. */
23342 if (loc
->dw_loc_opc
== DW_OP_GNU_regval_type
23343 || loc
->dw_loc_opc
== DW_OP_GNU_deref_type
)
23344 loc
->dw_loc_oprnd2
.v
.val_die_ref
.die
= base2
;
23346 loc
->dw_loc_oprnd1
.v
.val_die_ref
.die
= base2
;
23347 loc
->dw_loc_next
= loc
->dw_loc_next
->dw_loc_next
;
23350 /* Don't change integer DW_OP_GNU_convert after e.g. floating
23351 point typed stack entry. */
23352 else if (enc1
!= DW_ATE_unsigned
&& enc1
!= DW_ATE_signed
)
23353 keep
= loc
->dw_loc_next
;
23363 /* Helper function of resolve_addr. DIE had DW_AT_location of
23364 DW_OP_addr alone, which referred to DECL in DW_OP_addr's operand
23365 and DW_OP_addr couldn't be resolved. resolve_addr has already
23366 removed the DW_AT_location attribute. This function attempts to
23367 add a new DW_AT_location attribute with DW_OP_GNU_implicit_pointer
23368 to it or DW_AT_const_value attribute, if possible. */
23371 optimize_location_into_implicit_ptr (dw_die_ref die
, tree decl
)
23373 if (TREE_CODE (decl
) != VAR_DECL
23374 || lookup_decl_die (decl
) != die
23375 || DECL_EXTERNAL (decl
)
23376 || !TREE_STATIC (decl
)
23377 || DECL_INITIAL (decl
) == NULL_TREE
23378 || DECL_P (DECL_INITIAL (decl
))
23379 || get_AT (die
, DW_AT_const_value
))
23382 tree init
= DECL_INITIAL (decl
);
23383 HOST_WIDE_INT offset
= 0;
23384 /* For variables that have been optimized away and thus
23385 don't have a memory location, see if we can emit
23386 DW_AT_const_value instead. */
23387 if (tree_add_const_value_attribute (die
, init
))
23391 /* If init is ADDR_EXPR or POINTER_PLUS_EXPR of ADDR_EXPR,
23392 and ADDR_EXPR refers to a decl that has DW_AT_location or
23393 DW_AT_const_value (but isn't addressable, otherwise
23394 resolving the original DW_OP_addr wouldn't fail), see if
23395 we can add DW_OP_GNU_implicit_pointer. */
23397 if (TREE_CODE (init
) == POINTER_PLUS_EXPR
23398 && tree_fits_shwi_p (TREE_OPERAND (init
, 1)))
23400 offset
= tree_to_shwi (TREE_OPERAND (init
, 1));
23401 init
= TREE_OPERAND (init
, 0);
23404 if (TREE_CODE (init
) != ADDR_EXPR
)
23406 if ((TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
23407 && !TREE_ASM_WRITTEN (TREE_OPERAND (init
, 0)))
23408 || (TREE_CODE (TREE_OPERAND (init
, 0)) == VAR_DECL
23409 && !DECL_EXTERNAL (TREE_OPERAND (init
, 0))
23410 && TREE_OPERAND (init
, 0) != decl
))
23413 dw_loc_descr_ref l
;
23415 if (TREE_CODE (TREE_OPERAND (init
, 0)) == STRING_CST
)
23417 rtx rtl
= string_cst_pool_decl (TREE_OPERAND (init
, 0));
23420 decl
= SYMBOL_REF_DECL (rtl
);
23423 decl
= TREE_OPERAND (init
, 0);
23424 ref
= lookup_decl_die (decl
);
23426 || (!get_AT (ref
, DW_AT_location
)
23427 && !get_AT (ref
, DW_AT_const_value
)))
23429 l
= new_loc_descr (DW_OP_GNU_implicit_pointer
, 0, offset
);
23430 l
->dw_loc_oprnd1
.val_class
= dw_val_class_die_ref
;
23431 l
->dw_loc_oprnd1
.v
.val_die_ref
.die
= ref
;
23432 l
->dw_loc_oprnd1
.v
.val_die_ref
.external
= 0;
23433 add_AT_loc (die
, DW_AT_location
, l
);
23437 /* Resolve DW_OP_addr and DW_AT_const_value CONST_STRING arguments to
23438 an address in .rodata section if the string literal is emitted there,
23439 or remove the containing location list or replace DW_AT_const_value
23440 with DW_AT_location and empty location expression, if it isn't found
23441 in .rodata. Similarly for SYMBOL_REFs, keep only those that refer
23442 to something that has been emitted in the current CU. */
23445 resolve_addr (dw_die_ref die
)
23449 dw_loc_list_ref
*curr
, *start
, loc
;
23452 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
23453 switch (AT_class (a
))
23455 case dw_val_class_loc_list
:
23456 start
= curr
= AT_loc_list_ptr (a
);
23459 /* The same list can be referenced more than once. See if we have
23460 already recorded the result from a previous pass. */
23462 *curr
= loc
->dw_loc_next
;
23463 else if (!loc
->resolved_addr
)
23465 /* As things stand, we do not expect or allow one die to
23466 reference a suffix of another die's location list chain.
23467 References must be identical or completely separate.
23468 There is therefore no need to cache the result of this
23469 pass on any list other than the first; doing so
23470 would lead to unnecessary writes. */
23473 gcc_assert (!(*curr
)->replaced
&& !(*curr
)->resolved_addr
);
23474 if (!resolve_addr_in_expr ((*curr
)->expr
))
23476 dw_loc_list_ref next
= (*curr
)->dw_loc_next
;
23477 dw_loc_descr_ref l
= (*curr
)->expr
;
23479 if (next
&& (*curr
)->ll_symbol
)
23481 gcc_assert (!next
->ll_symbol
);
23482 next
->ll_symbol
= (*curr
)->ll_symbol
;
23484 if (dwarf_split_debug_info
)
23485 remove_loc_list_addr_table_entries (l
);
23490 mark_base_types ((*curr
)->expr
);
23491 curr
= &(*curr
)->dw_loc_next
;
23495 loc
->resolved_addr
= 1;
23499 loc
->dw_loc_next
= *start
;
23504 remove_AT (die
, a
->dw_attr
);
23508 case dw_val_class_loc
:
23510 dw_loc_descr_ref l
= AT_loc (a
);
23511 /* For -gdwarf-2 don't attempt to optimize
23512 DW_AT_data_member_location containing
23513 DW_OP_plus_uconst - older consumers might
23514 rely on it being that op instead of a more complex,
23515 but shorter, location description. */
23516 if ((dwarf_version
> 2
23517 || a
->dw_attr
!= DW_AT_data_member_location
23519 || l
->dw_loc_opc
!= DW_OP_plus_uconst
23520 || l
->dw_loc_next
!= NULL
)
23521 && !resolve_addr_in_expr (l
))
23523 if (dwarf_split_debug_info
)
23524 remove_loc_list_addr_table_entries (l
);
23526 && l
->dw_loc_next
== NULL
23527 && l
->dw_loc_opc
== DW_OP_addr
23528 && GET_CODE (l
->dw_loc_oprnd1
.v
.val_addr
) == SYMBOL_REF
23529 && SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
)
23530 && a
->dw_attr
== DW_AT_location
)
23532 tree decl
= SYMBOL_REF_DECL (l
->dw_loc_oprnd1
.v
.val_addr
);
23533 remove_AT (die
, a
->dw_attr
);
23535 optimize_location_into_implicit_ptr (die
, decl
);
23538 remove_AT (die
, a
->dw_attr
);
23542 mark_base_types (l
);
23545 case dw_val_class_addr
:
23546 if (a
->dw_attr
== DW_AT_const_value
23547 && resolve_one_addr (&a
->dw_attr_val
.v
.val_addr
, NULL
))
23549 if (AT_index (a
) != NOT_INDEXED
)
23550 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23551 remove_AT (die
, a
->dw_attr
);
23554 if (die
->die_tag
== DW_TAG_GNU_call_site
23555 && a
->dw_attr
== DW_AT_abstract_origin
)
23557 tree tdecl
= SYMBOL_REF_DECL (a
->dw_attr_val
.v
.val_addr
);
23558 dw_die_ref tdie
= lookup_decl_die (tdecl
);
23560 && DECL_EXTERNAL (tdecl
)
23561 && DECL_ABSTRACT_ORIGIN (tdecl
) == NULL_TREE
)
23563 force_decl_die (tdecl
);
23564 tdie
= lookup_decl_die (tdecl
);
23568 a
->dw_attr_val
.val_class
= dw_val_class_die_ref
;
23569 a
->dw_attr_val
.v
.val_die_ref
.die
= tdie
;
23570 a
->dw_attr_val
.v
.val_die_ref
.external
= 0;
23574 if (AT_index (a
) != NOT_INDEXED
)
23575 remove_addr_table_entry (a
->dw_attr_val
.val_entry
);
23576 remove_AT (die
, a
->dw_attr
);
23585 FOR_EACH_CHILD (die
, c
, resolve_addr (c
));
23588 /* Helper routines for optimize_location_lists.
23589 This pass tries to share identical local lists in .debug_loc
23592 /* Iteratively hash operands of LOC opcode. */
23595 hash_loc_operands (dw_loc_descr_ref loc
, hashval_t hash
)
23597 dw_val_ref val1
= &loc
->dw_loc_oprnd1
;
23598 dw_val_ref val2
= &loc
->dw_loc_oprnd2
;
23600 switch (loc
->dw_loc_opc
)
23602 case DW_OP_const4u
:
23603 case DW_OP_const8u
:
23607 case DW_OP_const1u
:
23608 case DW_OP_const1s
:
23609 case DW_OP_const2u
:
23610 case DW_OP_const2s
:
23611 case DW_OP_const4s
:
23612 case DW_OP_const8s
:
23616 case DW_OP_plus_uconst
:
23652 case DW_OP_deref_size
:
23653 case DW_OP_xderef_size
:
23654 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23661 gcc_assert (val1
->val_class
== dw_val_class_loc
);
23662 offset
= val1
->v
.val_loc
->dw_loc_addr
- (loc
->dw_loc_addr
+ 3);
23663 hash
= iterative_hash_object (offset
, hash
);
23666 case DW_OP_implicit_value
:
23667 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23668 switch (val2
->val_class
)
23670 case dw_val_class_const
:
23671 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23673 case dw_val_class_vec
:
23675 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23676 unsigned int len
= val2
->v
.val_vec
.length
;
23678 hash
= iterative_hash_object (elt_size
, hash
);
23679 hash
= iterative_hash_object (len
, hash
);
23680 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23681 len
* elt_size
, hash
);
23684 case dw_val_class_const_double
:
23685 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23686 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23688 case dw_val_class_wide_int
:
23689 hash
= iterative_hash_object (*val2
->v
.val_wide
, hash
);
23691 case dw_val_class_addr
:
23692 hash
= iterative_hash_rtx (val2
->v
.val_addr
, hash
);
23695 gcc_unreachable ();
23699 case DW_OP_bit_piece
:
23700 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23701 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23707 unsigned char dtprel
= 0xd1;
23708 hash
= iterative_hash_object (dtprel
, hash
);
23710 hash
= iterative_hash_rtx (val1
->v
.val_addr
, hash
);
23712 case DW_OP_GNU_addr_index
:
23713 case DW_OP_GNU_const_index
:
23717 unsigned char dtprel
= 0xd1;
23718 hash
= iterative_hash_object (dtprel
, hash
);
23720 hash
= iterative_hash_rtx (val1
->val_entry
->addr
.rtl
, hash
);
23723 case DW_OP_GNU_implicit_pointer
:
23724 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23726 case DW_OP_GNU_entry_value
:
23727 hash
= hash_loc_operands (val1
->v
.val_loc
, hash
);
23729 case DW_OP_GNU_regval_type
:
23730 case DW_OP_GNU_deref_type
:
23732 unsigned int byte_size
23733 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23734 unsigned int encoding
23735 = get_AT_unsigned (val2
->v
.val_die_ref
.die
, DW_AT_encoding
);
23736 hash
= iterative_hash_object (val1
->v
.val_int
, hash
);
23737 hash
= iterative_hash_object (byte_size
, hash
);
23738 hash
= iterative_hash_object (encoding
, hash
);
23741 case DW_OP_GNU_convert
:
23742 case DW_OP_GNU_reinterpret
:
23743 if (val1
->val_class
== dw_val_class_unsigned_const
)
23745 hash
= iterative_hash_object (val1
->v
.val_unsigned
, hash
);
23749 case DW_OP_GNU_const_type
:
23751 unsigned int byte_size
23752 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_byte_size
);
23753 unsigned int encoding
23754 = get_AT_unsigned (val1
->v
.val_die_ref
.die
, DW_AT_encoding
);
23755 hash
= iterative_hash_object (byte_size
, hash
);
23756 hash
= iterative_hash_object (encoding
, hash
);
23757 if (loc
->dw_loc_opc
!= DW_OP_GNU_const_type
)
23759 hash
= iterative_hash_object (val2
->val_class
, hash
);
23760 switch (val2
->val_class
)
23762 case dw_val_class_const
:
23763 hash
= iterative_hash_object (val2
->v
.val_int
, hash
);
23765 case dw_val_class_vec
:
23767 unsigned int elt_size
= val2
->v
.val_vec
.elt_size
;
23768 unsigned int len
= val2
->v
.val_vec
.length
;
23770 hash
= iterative_hash_object (elt_size
, hash
);
23771 hash
= iterative_hash_object (len
, hash
);
23772 hash
= iterative_hash (val2
->v
.val_vec
.array
,
23773 len
* elt_size
, hash
);
23776 case dw_val_class_const_double
:
23777 hash
= iterative_hash_object (val2
->v
.val_double
.low
, hash
);
23778 hash
= iterative_hash_object (val2
->v
.val_double
.high
, hash
);
23780 case dw_val_class_wide_int
:
23781 hash
= iterative_hash_object (*val2
->v
.val_wide
, hash
);
23784 gcc_unreachable ();
23790 /* Other codes have no operands. */
23796 /* Iteratively hash the whole DWARF location expression LOC. */
23798 static inline hashval_t
23799 hash_locs (dw_loc_descr_ref loc
, hashval_t hash
)
23801 dw_loc_descr_ref l
;
23802 bool sizes_computed
= false;
23803 /* Compute sizes, so that DW_OP_skip/DW_OP_bra can be checksummed. */
23804 size_of_locs (loc
);
23806 for (l
= loc
; l
!= NULL
; l
= l
->dw_loc_next
)
23808 enum dwarf_location_atom opc
= l
->dw_loc_opc
;
23809 hash
= iterative_hash_object (opc
, hash
);
23810 if ((opc
== DW_OP_skip
|| opc
== DW_OP_bra
) && !sizes_computed
)
23812 size_of_locs (loc
);
23813 sizes_computed
= true;
23815 hash
= hash_loc_operands (l
, hash
);
23820 /* Compute hash of the whole location list LIST_HEAD. */
23823 hash_loc_list (dw_loc_list_ref list_head
)
23825 dw_loc_list_ref curr
= list_head
;
23826 hashval_t hash
= 0;
23828 for (curr
= list_head
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
23830 hash
= iterative_hash (curr
->begin
, strlen (curr
->begin
) + 1, hash
);
23831 hash
= iterative_hash (curr
->end
, strlen (curr
->end
) + 1, hash
);
23833 hash
= iterative_hash (curr
->section
, strlen (curr
->section
) + 1,
23835 hash
= hash_locs (curr
->expr
, hash
);
23837 list_head
->hash
= hash
;
23840 /* Return true if X and Y opcodes have the same operands. */
23843 compare_loc_operands (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
23845 dw_val_ref valx1
= &x
->dw_loc_oprnd1
;
23846 dw_val_ref valx2
= &x
->dw_loc_oprnd2
;
23847 dw_val_ref valy1
= &y
->dw_loc_oprnd1
;
23848 dw_val_ref valy2
= &y
->dw_loc_oprnd2
;
23850 switch (x
->dw_loc_opc
)
23852 case DW_OP_const4u
:
23853 case DW_OP_const8u
:
23857 case DW_OP_const1u
:
23858 case DW_OP_const1s
:
23859 case DW_OP_const2u
:
23860 case DW_OP_const2s
:
23861 case DW_OP_const4s
:
23862 case DW_OP_const8s
:
23866 case DW_OP_plus_uconst
:
23902 case DW_OP_deref_size
:
23903 case DW_OP_xderef_size
:
23904 return valx1
->v
.val_int
== valy1
->v
.val_int
;
23907 /* If splitting debug info, the use of DW_OP_GNU_addr_index
23908 can cause irrelevant differences in dw_loc_addr. */
23909 gcc_assert (valx1
->val_class
== dw_val_class_loc
23910 && valy1
->val_class
== dw_val_class_loc
23911 && (dwarf_split_debug_info
23912 || x
->dw_loc_addr
== y
->dw_loc_addr
));
23913 return valx1
->v
.val_loc
->dw_loc_addr
== valy1
->v
.val_loc
->dw_loc_addr
;
23914 case DW_OP_implicit_value
:
23915 if (valx1
->v
.val_unsigned
!= valy1
->v
.val_unsigned
23916 || valx2
->val_class
!= valy2
->val_class
)
23918 switch (valx2
->val_class
)
23920 case dw_val_class_const
:
23921 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23922 case dw_val_class_vec
:
23923 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23924 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23925 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23926 valx2
->v
.val_vec
.elt_size
23927 * valx2
->v
.val_vec
.length
) == 0;
23928 case dw_val_class_const_double
:
23929 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23930 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23931 case dw_val_class_wide_int
:
23932 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
23933 case dw_val_class_addr
:
23934 return rtx_equal_p (valx2
->v
.val_addr
, valy2
->v
.val_addr
);
23936 gcc_unreachable ();
23939 case DW_OP_bit_piece
:
23940 return valx1
->v
.val_int
== valy1
->v
.val_int
23941 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23944 return rtx_equal_p (valx1
->v
.val_addr
, valy1
->v
.val_addr
);
23945 case DW_OP_GNU_addr_index
:
23946 case DW_OP_GNU_const_index
:
23948 rtx ax1
= valx1
->val_entry
->addr
.rtl
;
23949 rtx ay1
= valy1
->val_entry
->addr
.rtl
;
23950 return rtx_equal_p (ax1
, ay1
);
23952 case DW_OP_GNU_implicit_pointer
:
23953 return valx1
->val_class
== dw_val_class_die_ref
23954 && valx1
->val_class
== valy1
->val_class
23955 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
23956 && valx2
->v
.val_int
== valy2
->v
.val_int
;
23957 case DW_OP_GNU_entry_value
:
23958 return compare_loc_operands (valx1
->v
.val_loc
, valy1
->v
.val_loc
);
23959 case DW_OP_GNU_const_type
:
23960 if (valx1
->v
.val_die_ref
.die
!= valy1
->v
.val_die_ref
.die
23961 || valx2
->val_class
!= valy2
->val_class
)
23963 switch (valx2
->val_class
)
23965 case dw_val_class_const
:
23966 return valx2
->v
.val_int
== valy2
->v
.val_int
;
23967 case dw_val_class_vec
:
23968 return valx2
->v
.val_vec
.elt_size
== valy2
->v
.val_vec
.elt_size
23969 && valx2
->v
.val_vec
.length
== valy2
->v
.val_vec
.length
23970 && memcmp (valx2
->v
.val_vec
.array
, valy2
->v
.val_vec
.array
,
23971 valx2
->v
.val_vec
.elt_size
23972 * valx2
->v
.val_vec
.length
) == 0;
23973 case dw_val_class_const_double
:
23974 return valx2
->v
.val_double
.low
== valy2
->v
.val_double
.low
23975 && valx2
->v
.val_double
.high
== valy2
->v
.val_double
.high
;
23976 case dw_val_class_wide_int
:
23977 return *valx2
->v
.val_wide
== *valy2
->v
.val_wide
;
23979 gcc_unreachable ();
23981 case DW_OP_GNU_regval_type
:
23982 case DW_OP_GNU_deref_type
:
23983 return valx1
->v
.val_int
== valy1
->v
.val_int
23984 && valx2
->v
.val_die_ref
.die
== valy2
->v
.val_die_ref
.die
;
23985 case DW_OP_GNU_convert
:
23986 case DW_OP_GNU_reinterpret
:
23987 if (valx1
->val_class
!= valy1
->val_class
)
23989 if (valx1
->val_class
== dw_val_class_unsigned_const
)
23990 return valx1
->v
.val_unsigned
== valy1
->v
.val_unsigned
;
23991 return valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23992 case DW_OP_GNU_parameter_ref
:
23993 return valx1
->val_class
== dw_val_class_die_ref
23994 && valx1
->val_class
== valy1
->val_class
23995 && valx1
->v
.val_die_ref
.die
== valy1
->v
.val_die_ref
.die
;
23997 /* Other codes have no operands. */
24002 /* Return true if DWARF location expressions X and Y are the same. */
24005 compare_locs (dw_loc_descr_ref x
, dw_loc_descr_ref y
)
24007 for (; x
!= NULL
&& y
!= NULL
; x
= x
->dw_loc_next
, y
= y
->dw_loc_next
)
24008 if (x
->dw_loc_opc
!= y
->dw_loc_opc
24009 || x
->dtprel
!= y
->dtprel
24010 || !compare_loc_operands (x
, y
))
24012 return x
== NULL
&& y
== NULL
;
24015 /* Hashtable helpers. */
24017 struct loc_list_hasher
: typed_noop_remove
<dw_loc_list_struct
>
24019 typedef dw_loc_list_struct value_type
;
24020 typedef dw_loc_list_struct compare_type
;
24021 static inline hashval_t
hash (const value_type
*);
24022 static inline bool equal (const value_type
*, const compare_type
*);
24025 /* Return precomputed hash of location list X. */
24028 loc_list_hasher::hash (const value_type
*x
)
24033 /* Return true if location lists A and B are the same. */
24036 loc_list_hasher::equal (const value_type
*a
, const compare_type
*b
)
24040 if (a
->hash
!= b
->hash
)
24042 for (; a
!= NULL
&& b
!= NULL
; a
= a
->dw_loc_next
, b
= b
->dw_loc_next
)
24043 if (strcmp (a
->begin
, b
->begin
) != 0
24044 || strcmp (a
->end
, b
->end
) != 0
24045 || (a
->section
== NULL
) != (b
->section
== NULL
)
24046 || (a
->section
&& strcmp (a
->section
, b
->section
) != 0)
24047 || !compare_locs (a
->expr
, b
->expr
))
24049 return a
== NULL
&& b
== NULL
;
24052 typedef hash_table
<loc_list_hasher
> loc_list_hash_type
;
24055 /* Recursively optimize location lists referenced from DIE
24056 children and share them whenever possible. */
24059 optimize_location_lists_1 (dw_die_ref die
, loc_list_hash_type htab
)
24064 dw_loc_list_struct
**slot
;
24066 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
24067 if (AT_class (a
) == dw_val_class_loc_list
)
24069 dw_loc_list_ref list
= AT_loc_list (a
);
24070 /* TODO: perform some optimizations here, before hashing
24071 it and storing into the hash table. */
24072 hash_loc_list (list
);
24073 slot
= htab
.find_slot_with_hash (list
, list
->hash
, INSERT
);
24077 a
->dw_attr_val
.v
.val_loc_list
= *slot
;
24080 FOR_EACH_CHILD (die
, c
, optimize_location_lists_1 (c
, htab
));
24084 /* Recursively assign each location list a unique index into the debug_addr
24088 index_location_lists (dw_die_ref die
)
24094 FOR_EACH_VEC_SAFE_ELT (die
->die_attr
, ix
, a
)
24095 if (AT_class (a
) == dw_val_class_loc_list
)
24097 dw_loc_list_ref list
= AT_loc_list (a
);
24098 dw_loc_list_ref curr
;
24099 for (curr
= list
; curr
!= NULL
; curr
= curr
->dw_loc_next
)
24101 /* Don't index an entry that has already been indexed
24102 or won't be output. */
24103 if (curr
->begin_entry
!= NULL
24104 || (strcmp (curr
->begin
, curr
->end
) == 0 && !curr
->force
))
24108 = add_addr_table_entry (xstrdup (curr
->begin
),
24113 FOR_EACH_CHILD (die
, c
, index_location_lists (c
));
24116 /* Optimize location lists referenced from DIE
24117 children and share them whenever possible. */
24120 optimize_location_lists (dw_die_ref die
)
24122 loc_list_hash_type htab
;
24124 optimize_location_lists_1 (die
, htab
);
24128 /* Output stuff that dwarf requires at the end of every file,
24129 and generate the DWARF-2 debugging info. */
24132 dwarf2out_finish (const char *filename
)
24134 limbo_die_node
*node
, *next_node
;
24135 comdat_type_node
*ctnode
;
24136 hash_table
<comdat_type_hasher
> comdat_type_table
;
24138 dw_die_ref main_comp_unit_die
;
24140 /* PCH might result in DW_AT_producer string being restored from the
24141 header compilation, so always fill it with empty string initially
24142 and overwrite only here. */
24143 dw_attr_ref producer
= get_AT (comp_unit_die (), DW_AT_producer
);
24144 producer_string
= gen_producer_string ();
24145 producer
->dw_attr_val
.v
.val_str
->refcount
--;
24146 producer
->dw_attr_val
.v
.val_str
= find_AT_string (producer_string
);
24148 gen_scheduled_generic_parms_dies ();
24149 gen_remaining_tmpl_value_param_die_attribute ();
24151 /* Add the name for the main input file now. We delayed this from
24152 dwarf2out_init to avoid complications with PCH. */
24153 add_name_attribute (comp_unit_die (), remap_debug_filename (filename
));
24154 if (!IS_ABSOLUTE_PATH (filename
) || targetm
.force_at_comp_dir
)
24155 add_comp_dir_attribute (comp_unit_die ());
24156 else if (get_AT (comp_unit_die (), DW_AT_comp_dir
) == NULL
)
24159 htab_traverse (file_table
, file_table_relative_p
, &p
);
24161 add_comp_dir_attribute (comp_unit_die ());
24164 if (deferred_locations_list
)
24165 for (i
= 0; i
< deferred_locations_list
->length (); i
++)
24167 add_location_or_const_value_attribute (
24168 (*deferred_locations_list
)[i
].die
,
24169 (*deferred_locations_list
)[i
].variable
,
24174 /* Traverse the limbo die list, and add parent/child links. The only
24175 dies without parents that should be here are concrete instances of
24176 inline functions, and the comp_unit_die. We can ignore the comp_unit_die.
24177 For concrete instances, we can get the parent die from the abstract
24179 for (node
= limbo_die_list
; node
; node
= next_node
)
24181 dw_die_ref die
= node
->die
;
24182 next_node
= node
->next
;
24184 if (die
->die_parent
== NULL
)
24186 dw_die_ref origin
= get_AT_ref (die
, DW_AT_abstract_origin
);
24188 if (origin
&& origin
->die_parent
)
24189 add_child_die (origin
->die_parent
, die
);
24190 else if (is_cu_die (die
))
24192 else if (seen_error ())
24193 /* It's OK to be confused by errors in the input. */
24194 add_child_die (comp_unit_die (), die
);
24197 /* In certain situations, the lexical block containing a
24198 nested function can be optimized away, which results
24199 in the nested function die being orphaned. Likewise
24200 with the return type of that nested function. Force
24201 this to be a child of the containing function.
24203 It may happen that even the containing function got fully
24204 inlined and optimized out. In that case we are lost and
24205 assign the empty child. This should not be big issue as
24206 the function is likely unreachable too. */
24207 gcc_assert (node
->created_for
);
24209 if (DECL_P (node
->created_for
))
24210 origin
= get_context_die (DECL_CONTEXT (node
->created_for
));
24211 else if (TYPE_P (node
->created_for
))
24212 origin
= scope_die_for (node
->created_for
, comp_unit_die ());
24214 origin
= comp_unit_die ();
24216 add_child_die (origin
, die
);
24221 limbo_die_list
= NULL
;
24223 #if ENABLE_ASSERT_CHECKING
24225 dw_die_ref die
= comp_unit_die (), c
;
24226 FOR_EACH_CHILD (die
, c
, gcc_assert (! c
->die_mark
));
24229 resolve_addr (comp_unit_die ());
24230 move_marked_base_types ();
24232 for (node
= deferred_asm_name
; node
; node
= node
->next
)
24234 tree decl
= node
->created_for
;
24235 /* When generating LTO bytecode we can not generate new assembler
24236 names at this point and all important decls got theirs via
24238 if ((!flag_generate_lto
|| DECL_ASSEMBLER_NAME_SET_P (decl
))
24239 && DECL_ASSEMBLER_NAME (decl
) != DECL_NAME (decl
))
24241 add_linkage_attr (node
->die
, decl
);
24242 move_linkage_attr (node
->die
);
24246 deferred_asm_name
= NULL
;
24248 /* Walk through the list of incomplete types again, trying once more to
24249 emit full debugging info for them. */
24250 retry_incomplete_types ();
24252 if (flag_eliminate_unused_debug_types
)
24253 prune_unused_types ();
24255 /* Generate separate COMDAT sections for type DIEs. */
24256 if (use_debug_types
)
24258 break_out_comdat_types (comp_unit_die ());
24260 /* Each new type_unit DIE was added to the limbo die list when created.
24261 Since these have all been added to comdat_type_list, clear the
24263 limbo_die_list
= NULL
;
24265 /* For each new comdat type unit, copy declarations for incomplete
24266 types to make the new unit self-contained (i.e., no direct
24267 references to the main compile unit). */
24268 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24269 copy_decls_for_unworthy_types (ctnode
->root_die
);
24270 copy_decls_for_unworthy_types (comp_unit_die ());
24272 /* In the process of copying declarations from one unit to another,
24273 we may have left some declarations behind that are no longer
24274 referenced. Prune them. */
24275 prune_unused_types ();
24278 /* Generate separate CUs for each of the include files we've seen.
24279 They will go into limbo_die_list. */
24280 if (flag_eliminate_dwarf2_dups
)
24281 break_out_includes (comp_unit_die ());
24283 /* Traverse the DIE's and add add sibling attributes to those DIE's
24284 that have children. */
24285 add_sibling_attributes (comp_unit_die ());
24286 for (node
= limbo_die_list
; node
; node
= node
->next
)
24287 add_sibling_attributes (node
->die
);
24288 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24289 add_sibling_attributes (ctnode
->root_die
);
24291 /* When splitting DWARF info, we put some attributes in the
24292 skeleton compile_unit DIE that remains in the .o, while
24293 most attributes go in the DWO compile_unit_die. */
24294 if (dwarf_split_debug_info
)
24295 main_comp_unit_die
= gen_compile_unit_die (NULL
);
24297 main_comp_unit_die
= comp_unit_die ();
24299 /* Output a terminator label for the .text section. */
24300 switch_to_section (text_section
);
24301 targetm
.asm_out
.internal_label (asm_out_file
, TEXT_END_LABEL
, 0);
24302 if (cold_text_section
)
24304 switch_to_section (cold_text_section
);
24305 targetm
.asm_out
.internal_label (asm_out_file
, COLD_END_LABEL
, 0);
24308 /* We can only use the low/high_pc attributes if all of the code was
24310 if (!have_multiple_function_sections
24311 || (dwarf_version
< 3 && dwarf_strict
))
24313 /* Don't add if the CU has no associated code. */
24314 if (text_section_used
)
24315 add_AT_low_high_pc (main_comp_unit_die
, text_section_label
,
24316 text_end_label
, true);
24322 bool range_list_added
= false;
24324 if (text_section_used
)
24325 add_ranges_by_labels (main_comp_unit_die
, text_section_label
,
24326 text_end_label
, &range_list_added
, true);
24327 if (cold_text_section_used
)
24328 add_ranges_by_labels (main_comp_unit_die
, cold_text_section_label
,
24329 cold_end_label
, &range_list_added
, true);
24331 FOR_EACH_VEC_ELT (*fde_vec
, fde_idx
, fde
)
24333 if (DECL_IGNORED_P (fde
->decl
))
24335 if (!fde
->in_std_section
)
24336 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_begin
,
24337 fde
->dw_fde_end
, &range_list_added
,
24339 if (fde
->dw_fde_second_begin
&& !fde
->second_in_std_section
)
24340 add_ranges_by_labels (main_comp_unit_die
, fde
->dw_fde_second_begin
,
24341 fde
->dw_fde_second_end
, &range_list_added
,
24345 if (range_list_added
)
24347 /* We need to give .debug_loc and .debug_ranges an appropriate
24348 "base address". Use zero so that these addresses become
24349 absolute. Historically, we've emitted the unexpected
24350 DW_AT_entry_pc instead of DW_AT_low_pc for this purpose.
24351 Emit both to give time for other tools to adapt. */
24352 add_AT_addr (main_comp_unit_die
, DW_AT_low_pc
, const0_rtx
, true);
24353 if (! dwarf_strict
&& dwarf_version
< 4)
24354 add_AT_addr (main_comp_unit_die
, DW_AT_entry_pc
, const0_rtx
, true);
24360 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
24361 add_AT_lineptr (main_comp_unit_die
, DW_AT_stmt_list
,
24362 debug_line_section_label
);
24365 add_AT_macptr (comp_unit_die (),
24366 dwarf_strict
? DW_AT_macro_info
: DW_AT_GNU_macros
,
24367 macinfo_section_label
);
24369 if (dwarf_split_debug_info
&& addr_index_table
!= NULL
)
24371 /* optimize_location_lists calculates the size of the lists,
24372 so index them first, and assign indices to the entries.
24373 Although optimize_location_lists will remove entries from
24374 the table, it only does so for duplicates, and therefore
24375 only reduces ref_counts to 1. */
24376 unsigned int index
= 0;
24377 index_location_lists (comp_unit_die ());
24378 htab_traverse_noresize (addr_index_table
,
24379 index_addr_table_entry
, &index
);
24381 if (have_location_lists
)
24382 optimize_location_lists (comp_unit_die ());
24384 save_macinfo_strings ();
24386 if (dwarf_split_debug_info
)
24388 unsigned int index
= 0;
24390 /* Add attributes common to skeleton compile_units and
24391 type_units. Because these attributes include strings, it
24392 must be done before freezing the string table. Top-level
24393 skeleton die attrs are added when the skeleton type unit is
24394 created, so ensure it is created by this point. */
24395 add_top_level_skeleton_die_attrs (main_comp_unit_die
);
24396 (void) get_skeleton_type_unit ();
24397 htab_traverse_noresize (debug_str_hash
, index_string
, &index
);
24400 /* Output all of the compilation units. We put the main one last so that
24401 the offsets are available to output_pubnames. */
24402 for (node
= limbo_die_list
; node
; node
= node
->next
)
24403 output_comp_unit (node
->die
, 0);
24405 comdat_type_table
.create (100);
24406 for (ctnode
= comdat_type_list
; ctnode
!= NULL
; ctnode
= ctnode
->next
)
24408 comdat_type_node
**slot
= comdat_type_table
.find_slot (ctnode
, INSERT
);
24410 /* Don't output duplicate types. */
24411 if (*slot
!= HTAB_EMPTY_ENTRY
)
24414 /* Add a pointer to the line table for the main compilation unit
24415 so that the debugger can make sense of DW_AT_decl_file
24417 if (debug_info_level
>= DINFO_LEVEL_TERSE
)
24418 add_AT_lineptr (ctnode
->root_die
, DW_AT_stmt_list
,
24419 (!dwarf_split_debug_info
24420 ? debug_line_section_label
24421 : debug_skeleton_line_section_label
));
24423 output_comdat_type_unit (ctnode
);
24426 comdat_type_table
.dispose ();
24428 /* The AT_pubnames attribute needs to go in all skeleton dies, including
24429 both the main_cu and all skeleton TUs. Making this call unconditional
24430 would end up either adding a second copy of the AT_pubnames attribute, or
24431 requiring a special case in add_top_level_skeleton_die_attrs. */
24432 if (!dwarf_split_debug_info
)
24433 add_AT_pubnames (comp_unit_die ());
24435 if (dwarf_split_debug_info
)
24438 unsigned char checksum
[16];
24439 struct md5_ctx ctx
;
24441 /* Compute a checksum of the comp_unit to use as the dwo_id. */
24442 md5_init_ctx (&ctx
);
24444 die_checksum (comp_unit_die (), &ctx
, &mark
);
24445 unmark_all_dies (comp_unit_die ());
24446 md5_finish_ctx (&ctx
, checksum
);
24448 /* Use the first 8 bytes of the checksum as the dwo_id,
24449 and add it to both comp-unit DIEs. */
24450 add_AT_data8 (main_comp_unit_die
, DW_AT_GNU_dwo_id
, checksum
);
24451 add_AT_data8 (comp_unit_die (), DW_AT_GNU_dwo_id
, checksum
);
24453 /* Add the base offset of the ranges table to the skeleton
24455 if (ranges_table_in_use
)
24456 add_AT_lineptr (main_comp_unit_die
, DW_AT_GNU_ranges_base
,
24457 ranges_section_label
);
24459 switch_to_section (debug_addr_section
);
24460 ASM_OUTPUT_LABEL (asm_out_file
, debug_addr_section_label
);
24461 output_addr_table ();
24464 /* Output the main compilation unit if non-empty or if .debug_macinfo
24465 or .debug_macro will be emitted. */
24466 output_comp_unit (comp_unit_die (), have_macinfo
);
24468 if (dwarf_split_debug_info
&& info_section_emitted
)
24469 output_skeleton_debug_sections (main_comp_unit_die
);
24471 /* Output the abbreviation table. */
24472 if (abbrev_die_table_in_use
!= 1)
24474 switch_to_section (debug_abbrev_section
);
24475 ASM_OUTPUT_LABEL (asm_out_file
, abbrev_section_label
);
24476 output_abbrev_section ();
24479 /* Output location list section if necessary. */
24480 if (have_location_lists
)
24482 /* Output the location lists info. */
24483 switch_to_section (debug_loc_section
);
24484 ASM_OUTPUT_LABEL (asm_out_file
, loc_section_label
);
24485 output_location_lists (comp_unit_die ());
24488 output_pubtables ();
24490 /* Output the address range information if a CU (.debug_info section)
24491 was emitted. We output an empty table even if we had no functions
24492 to put in it. This because the consumer has no way to tell the
24493 difference between an empty table that we omitted and failure to
24494 generate a table that would have contained data. */
24495 if (info_section_emitted
)
24497 unsigned long aranges_length
= size_of_aranges ();
24499 switch_to_section (debug_aranges_section
);
24500 output_aranges (aranges_length
);
24503 /* Output ranges section if necessary. */
24504 if (ranges_table_in_use
)
24506 switch_to_section (debug_ranges_section
);
24507 ASM_OUTPUT_LABEL (asm_out_file
, ranges_section_label
);
24511 /* Have to end the macro section. */
24514 switch_to_section (debug_macinfo_section
);
24515 ASM_OUTPUT_LABEL (asm_out_file
, macinfo_section_label
);
24517 dw2_asm_output_data (1, 0, "End compilation unit");
24520 /* Output the source line correspondence table. We must do this
24521 even if there is no line information. Otherwise, on an empty
24522 translation unit, we will generate a present, but empty,
24523 .debug_info section. IRIX 6.5 `nm' will then complain when
24524 examining the file. This is done late so that any filenames
24525 used by the debug_info section are marked as 'used'. */
24526 switch_to_section (debug_line_section
);
24527 ASM_OUTPUT_LABEL (asm_out_file
, debug_line_section_label
);
24528 if (! DWARF2_ASM_LINE_DEBUG_INFO
)
24529 output_line_info (false);
24531 if (dwarf_split_debug_info
&& info_section_emitted
)
24533 switch_to_section (debug_skeleton_line_section
);
24534 ASM_OUTPUT_LABEL (asm_out_file
, debug_skeleton_line_section_label
);
24535 output_line_info (true);
24538 /* If we emitted any indirect strings, output the string table too. */
24539 if (debug_str_hash
|| skeleton_debug_str_hash
)
24540 output_indirect_strings ();
24543 #include "gt-dwarf2out.h"